From cad5927150e7e966c0dc0aebd861c1624af23dc7 Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Sun, 13 Jan 2013 06:47:28 +0000 Subject: [PATCH] Fix the voicemail download from the gui. Add message delete to the voicemail PHP class. --- .../resources/classes/voicemail.php | 93 +++++++++++++------ app/voicemails/voicemail_edit.php | 6 +- app/voicemails/voicemail_message_delete.php | 37 +++----- app/voicemails/voicemail_messages.php | 19 +++- 4 files changed, 96 insertions(+), 59 deletions(-) diff --git a/app/voicemails/resources/classes/voicemail.php b/app/voicemails/resources/classes/voicemail.php index 0c1a17ba22..9c4f6c1b8c 100644 --- a/app/voicemails/resources/classes/voicemail.php +++ b/app/voicemails/resources/classes/voicemail.php @@ -107,41 +107,77 @@ return $num_rows; } - public function download() { - //get the voicemail_id - $sql = "select * from v_voicemails "; - $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + public function message_waiting() { + //send the message waiting status + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + if ($fp) { + $switch_cmd .= "luarun voicemail.lua mwi ".$this->voicemail_id."@".$_SESSION['domain_name']; + $switch_result = event_socket_request($fp, 'api '.$switch_cmd); + } + } + + public function message_delete() { + + //delete voicemail_message + $sql = "delete from v_voicemail_messages "; + $sql .= "where domain_uuid = '$this->domain_uuid' "; $sql .= "and voicemail_uuid = '$this->voicemail_uuid' "; - $prep_statement = $db->prepare(check_sql($sql)); + $sql .= "and voicemail_message_uuid = '$this->voicemail_message_uuid' "; + $prep_statement = $this->db->prepare(check_sql($sql)); $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($result as &$row) { - $voicemail_id = $row["voicemail_id"]; + unset($sql); + + //get the voicemail_id + if (!isset($this->voicemail_id)) { + $sql = "select * 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); + foreach ($result as &$row) { + $this->voicemail_id = $row["voicemail_id"]; + } + unset ($prep_statement); } - unset ($prep_statement); + + //delete the recording + $file_path = $_SESSION['switch']['storage']['dir']."/voicemail/default/".$_SESSION['domain_name']."/".$this->voicemail_id."/msg_".$this->voicemail_message_uuid.".wav"; + unlink($file_path); + + //check the message waiting status + $this->message_waiting(); + + } + + public function message_saved() { + //set the voicemail status to saved + $sql = "update v_voicemail_messages set "; + $sql .= "message_status = 'saved' "; + $sql .= "where domain_uuid = '$this->domain_uuid' "; + $sql .= "and voicemail_uuid = '$this->voicemail_uuid' "; + $sql .= "and voicemail_message_uuid = '$this->voicemail_message_uuid'"; + $this->db->exec($sql); + unset($sql); + //check the message waiting status + $this->message_waiting(); + } + + public function message_download() { + + //check the message waiting status + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + if ($fp) { + $switch_cmd .= "luarun voicemail.lua mwi ".$this->voicemail_id."@".$_SESSION['domain_name']; + $switch_result = event_socket_request($fp, 'api '.$switch_cmd); + } + + //change the message status + $this->message_saved(); //clear the cache session_cache_limiter('public'); - //get the voicemail message meta data - $sql = "select * from v_voicemail_messages "; - $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; - $sql .= "and voicemail_message_uuid = '$this->voicemail_message_uuid' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($result as &$row) { - $voicemail_uuid = $row["voicemail_uuid"]; - $created_epoch = $row["created_epoch"]; - $read_epoch = $row["read_epoch"]; - $caller_id_name = $row["caller_id_name"]; - $caller_id_number = $row["caller_id_number"]; - $message_length = $row["message_length"]; - $message_status = $row["message_status"]; - $message_priority = $row["message_priority"]; - } - unset ($prep_statement); - //prepare and stream the file $file_path = $_SESSION['switch']['storage']['dir']."/voicemail/default/".$_SESSION['domain_name']."/".$this->voicemail_id."/msg_".$this->voicemail_message_uuid.".wav"; if (file_exists($file_path)) { @@ -174,7 +210,6 @@ fpassthru($fd); } } // download - } //example voicemail messages diff --git a/app/voicemails/voicemail_edit.php b/app/voicemails/voicemail_edit.php index 6cde746ddf..e3235a5d00 100644 --- a/app/voicemails/voicemail_edit.php +++ b/app/voicemails/voicemail_edit.php @@ -271,7 +271,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo "\n"; echo "\n"; echo " \n"; - //echo " \n"; + echo " \n"; if ($voicemail_local_after_email == "true") { echo " \n"; } @@ -321,7 +321,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo "\n"; echo "\n"; echo "