Update voicemail.php
Improve the voicemail class by using construct and destruct. Reduce the use of session variables in the class.
This commit is contained in:
parent
21a414d31e
commit
c2bbc9e525
|
|
@ -34,12 +34,47 @@
|
|||
public $voicemail_message_uuid;
|
||||
public $order_by;
|
||||
public $order;
|
||||
public $app_uuid;
|
||||
|
||||
public function __construct() {
|
||||
//connect to the database if not connected
|
||||
if (!$this->db) {
|
||||
require_once "resources/classes/database.php";
|
||||
$database = new database;
|
||||
$database->connect();
|
||||
$this->db = $database->db;
|
||||
}
|
||||
|
||||
//set the application specific uuid
|
||||
$this->app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044';
|
||||
|
||||
//set the domain_uuid if not provided
|
||||
if (strlen($this->domain_uuid) == 0) {
|
||||
$this->domain_uuid = $_SESSION['domain_uuid'];
|
||||
}
|
||||
|
||||
//get the voicemail_id
|
||||
if (!isset($this->voicemail_id)) {
|
||||
$sql = "select voicemail_id from v_voicemails ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
if (is_array($result)) foreach ($result as &$row) {
|
||||
$this->voicemail_id = $row["voicemail_id"];
|
||||
}
|
||||
unset ($prep_statement);
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
public function voicemails() {
|
||||
//set the voicemail_uuid
|
||||
if (strlen($_REQUEST["id"]) > 0) {
|
||||
$voicemail_uuid = check_str($_REQUEST["id"]);
|
||||
}
|
||||
|
||||
//set the voicemail id and voicemail uuid arrays
|
||||
if (isset($_SESSION['user']['extension'])) foreach ($_SESSION['user']['extension'] as $index => $row) {
|
||||
|
|
@ -58,7 +93,7 @@
|
|||
|
||||
//get the uuid and voicemail_id
|
||||
$sql = "select * from v_voicemails ";
|
||||
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
if (strlen($this->voicemail_uuid) > 0) {
|
||||
if (permission_exists('voicemail_delete')) {
|
||||
//view specific voicemail box usually reserved for an admin or superadmin
|
||||
|
|
@ -199,7 +234,7 @@
|
|||
|
||||
//delete voicemail destinations
|
||||
$sql = "delete from v_voicemail_destinations ";
|
||||
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
|
|
@ -207,7 +242,7 @@
|
|||
|
||||
//delete voicemail greetings
|
||||
$sql = "delete from v_voicemail_greetings ";
|
||||
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_id = '".$this->voicemail_id."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
|
|
@ -215,7 +250,7 @@
|
|||
|
||||
//delete voicemail options
|
||||
$sql = "delete from v_voicemail_options ";
|
||||
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
|
|
@ -223,7 +258,7 @@
|
|||
|
||||
//delete voicemail
|
||||
$sql = "delete from v_voicemails ";
|
||||
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
|
|
@ -231,9 +266,10 @@
|
|||
}
|
||||
|
||||
public function message_count() {
|
||||
|
||||
$sql = "select count(*) as num_rows from v_voicemail_messages ";
|
||||
$sql .= "where domain_uuid = '$this->domain_uuid' ";
|
||||
$sql .= "and voicemail_uuid = '$this->voicemail_uuid' ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
|
|
@ -258,19 +294,6 @@
|
|||
}
|
||||
|
||||
public function message_delete() {
|
||||
//get the voicemail_id
|
||||
if (!isset($this->voicemail_id)) {
|
||||
$sql = "select voicemail_id from v_voicemails ";
|
||||
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
if (is_array($result)) foreach ($result as &$row) {
|
||||
$this->voicemail_id = $row["voicemail_id"];
|
||||
}
|
||||
unset ($prep_statement);
|
||||
}
|
||||
|
||||
//delete the recording
|
||||
$file_path = $_SESSION['switch']['voicemail']['dir']."/default/".$_SESSION['domain_name']."/".$this->voicemail_id;
|
||||
|
|
@ -301,19 +324,6 @@
|
|||
}
|
||||
|
||||
public function message_toggle() {
|
||||
//get the voicemail_id
|
||||
if (!isset($this->voicemail_id)) {
|
||||
$sql = "select voicemail_id from v_voicemails ";
|
||||
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
if (is_array($result)) foreach ($result as &$row) {
|
||||
$this->voicemail_id = $row["voicemail_id"];
|
||||
}
|
||||
unset ($prep_statement);
|
||||
}
|
||||
|
||||
//get message status
|
||||
$sql = "select message_status from v_voicemail_messages ";
|
||||
|
|
@ -342,6 +352,7 @@
|
|||
|
||||
|
||||
public function message_saved() {
|
||||
|
||||
//set the voicemail status to saved
|
||||
$sql = "update v_voicemail_messages set ";
|
||||
$sql .= "message_status = 'saved' ";
|
||||
|
|
@ -457,9 +468,7 @@
|
|||
//require_once "app/voicemails/resources/classes/voicemail.php";
|
||||
//$voicemail = new voicemail;
|
||||
//$voicemail->db = $db;
|
||||
//$voicemail->domain_uuid = $_SESSION['domain_uuid'];
|
||||
//$voicemail->voicemail_uuid = $voicemail_uuid;
|
||||
//$voicemail->voicemail_id = $voicemail_id;
|
||||
//$voicemail->order_by = $order_by;
|
||||
//$voicemail->order = $order;
|
||||
//$result = $voicemail->messages();
|
||||
|
|
@ -471,14 +480,14 @@ Array
|
|||
[user] => 1002
|
||||
[extension_uuid] => e163fc03-f180-459b-aa12-7ed87fcb6e2c
|
||||
[outbound_caller_id_name] => FusionPBX
|
||||
[outbound_caller_id_number] => 12084024632
|
||||
[outbound_caller_id_number] => 12089068227
|
||||
)
|
||||
Array
|
||||
(
|
||||
[user] => 1020
|
||||
[extension_uuid] => ecfb23df-7c59-4286-891e-2abdc48856ac
|
||||
[outbound_caller_id_name] => Mark J Crane
|
||||
[outbound_caller_id_number] => 12084024632
|
||||
[outbound_caller_id_number] => 12089068227
|
||||
)
|
||||
|
||||
foreach ($_SESSION['user']['extension'] as $value) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue