From def55290abb54995df39d26e5f79388ab5232ef9 Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Sat, 23 Nov 2013 04:19:37 +0000 Subject: [PATCH] Fix a few more voicemail gui issues: make sure the back button returns to the correct page, fix the redirect after deleting a voicemail. Fix the voicemail delete mp3 files or other sounds files other than wav or mp3. --- .../resources/classes/voicemail.php | 88 ++++++++++++++++++- app/voicemails/voicemail_edit.php | 6 +- app/voicemails/voicemail_message_delete.php | 15 +++- app/voicemails/voicemail_messages.php | 84 +++--------------- 4 files changed, 111 insertions(+), 82 deletions(-) diff --git a/app/voicemails/resources/classes/voicemail.php b/app/voicemails/resources/classes/voicemail.php index 9c4f6c1b8c..f35ba5210c 100644 --- a/app/voicemails/resources/classes/voicemail.php +++ b/app/voicemails/resources/classes/voicemail.php @@ -35,8 +35,88 @@ public $order_by; public $order; - public function messages() { + public function voicemails() { + //set the voicemail_uuid + if (strlen($_REQUEST["id"]) > 0) { + $voicemail_uuid = check_str($_REQUEST["id"]); + } + //set the voicemail_id array + foreach ($_SESSION['user']['extension'] as $value) { + $voicemail_ids[]['voicemail_id'] = $value['user']; + } + + //get the uuid and voicemail_id + $sql = "select * from v_voicemails "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + if (strlen($this->voicemail_uuid) > 0) { + if (permission_exists('voicemail_delete')) { + //view specific voicemail box usually reserved for an admin or superadmin + $sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' "; + } + else { + //ensure that the requested voicemail id is assigned to this user + $found = false; + foreach($voicemail_ids as $row) { + if ($voicemail_uuid == $row['voicemail_id']) { + $sql .= "and voicemail_id = '".$row['voicemail_id']."' "; + $found = true; + } + $x++; + } + //id requested is not owned by the user return no results + if (!$found) { + $sql .= "and voicemail_uuid = '' "; + } + } + } + else { + $x = 0; + if (count($voicemail_ids) > 0) { + //show only the assigned voicemail ids + $sql .= "and ("; + foreach($voicemail_ids as $row) { + if ($x == 0) { + $sql .= "voicemail_id = '".$row['voicemail_id']."' "; + } + else { + $sql .= " or voicemail_id = '".$row['voicemail_id']."'"; + } + $x++; + } + $sql .= ")"; + } + else { + //no assigned voicemail ids so return no results + $sql .= "and voicemail_uuid = '' "; + } + } + $prep_statement = $this->db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + unset ($prep_statement); + return $result; + } + + public function messages() { + //get the voicemails + $voicemails = $this->voicemails(); + + //add the voicemail messages to the array + foreach ($voicemails as &$row) { + //get the voicemail messages + $this->voicemail_uuid = $row['voicemail_uuid']; + $this->voicemail_id = $row['voicemail_id']; + $result = $this->voicemail_messages(); + $voicemail_count = count($result); + $row['messages'] = $result; + } + + //return the array + return $voicemails; + } + + public function voicemail_messages() { $sql = "select * from v_voicemail_messages as m, v_voicemails as v "; $sql .= "where m.domain_uuid = '$this->domain_uuid' "; $sql .= "and m.voicemail_uuid = v.voicemail_uuid "; @@ -142,8 +222,10 @@ } //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); + $file_path = $_SESSION['switch']['storage']['dir']."/voicemail/default/".$_SESSION['domain_name']."/".$this->voicemail_id; + foreach (glob($file_path."/msg_".$this->voicemail_message_uuid.".*") as $file_name) { + unlink($file_name); + } //check the message waiting status $this->message_waiting(); diff --git a/app/voicemails/voicemail_edit.php b/app/voicemails/voicemail_edit.php index b57bfc1e4b..557a5a82d6 100644 --- a/app/voicemails/voicemail_edit.php +++ b/app/voicemails/voicemail_edit.php @@ -223,8 +223,10 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo "
\n"; echo "\n"; echo "\n"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; echo "\n"; diff --git a/app/voicemails/voicemail_message_delete.php b/app/voicemails/voicemail_message_delete.php index f5aea8e160..65efe89c36 100644 --- a/app/voicemails/voicemail_message_delete.php +++ b/app/voicemails/voicemail_message_delete.php @@ -40,12 +40,17 @@ else { $text[$key] = $value[$_SESSION['domain']['language']['code']]; } -//get the id +//get the HTTP values and set them as variables if (count($_GET)>0) { $id = check_str($_GET["id"]); $voicemail_uuid = check_str($_GET["voicemail_uuid"]); } +//set the referrer + $http_referer = parse_url($_SERVER["HTTP_REFERER"]); + $referer_path = $http_referer['path']; + $referer_query = $http_referer['query']; + //delete the voicemail message if (strlen($id)>0) { require_once "resources/classes/voicemail.php"; @@ -53,7 +58,6 @@ else { $voicemail->db = $db; $voicemail->domain_uuid = $_SESSION['domain_uuid']; $voicemail->voicemail_uuid = $voicemail_uuid; - $voicemail->voicemail_id = $voicemail_id; $voicemail->voicemail_message_uuid = $id; $result = $voicemail->message_delete(); unset($voicemail); @@ -61,7 +65,12 @@ else { //redirect the user require_once "resources/header.php"; - echo "\n"; + if ($referer_path == "/app/voicemails/voicemail_messages.php") { + echo "\n"; + } + else { + echo "\n"; + } echo "
\n"; echo "Delete Complete\n"; echo "
\n"; diff --git a/app/voicemails/voicemail_messages.php b/app/voicemails/voicemail_messages.php index 903a656135..38a2469f1f 100644 --- a/app/voicemails/voicemail_messages.php +++ b/app/voicemails/voicemail_messages.php @@ -45,80 +45,6 @@ else { $voicemail_uuid = check_str($_REQUEST["id"]); } -//set the voicemail_id array - foreach ($_SESSION['user']['extension'] as $value) { - $voicemail_ids[]['voicemail_id'] = $value['user']; - } - -//get the uuid and voicemail_id - $sql = "select * from v_voicemails "; - $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; - if (strlen($voicemail_uuid) > 0) { - if (permission_exists('voicemail_delete')) { - //view specific voicemail box usually reserved for an admin or superadmin - $sql .= "and voicemail_uuid = '$voicemail_uuid' "; - } - else { - //ensure that the requested voicemail id is assigned to this user - $found = false; - foreach($voicemail_ids as $row) { - if ($voicemail_uuid == $row['voicemail_id']) { - $sql .= "and voicemail_id = '".$row['voicemail_id']."' "; - $found = true; - } - $x++; - } - //id requested is not owned by the user return no results - if (!$found) { - $sql .= "and voicemail_uuid = '' "; - } - } - } - else { - $x = 0; - if (count($voicemail_ids) > 0) { - //show only the assigned voicemail ids - $sql .= "and ("; - foreach($voicemail_ids as $row) { - if ($x == 0) { - $sql .= "voicemail_id = '".$row['voicemail_id']."' "; - } - else { - $sql .= " or voicemail_id = '".$row['voicemail_id']."'"; - } - $x++; - } - $sql .= ")"; - } - else { - //no assigned voicemail ids so return no results - $sql .= "and voicemail_uuid = '' "; - } - } - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $voicemails = $prep_statement->fetchAll(PDO::FETCH_NAMED); - unset ($prep_statement); - -//add the voicemail messages to the array - foreach ($voicemails as &$row) { - //get the voicemail messages - require_once "app/voicemails/resources/classes/voicemail.php"; - $voicemail = new voicemail; - $voicemail->db = $db; - $voicemail->domain_uuid = $_SESSION['domain_uuid']; - $voicemail->voicemail_uuid = $row['voicemail_uuid']; - $voicemail->voicemail_id = $row['voicemail_id']; - $voicemail->order_by = $order_by; - $voicemail->order = $order; - $result = $voicemail->messages(); - $voicemail_count = count($result); - $row['messages'] = $result; - } - //echo "
\n";
-	//print_r($voicemails);
-	//echo "
\n"; - //download the message if (check_str($_REQUEST["action"]) == "download") { $voicemail_message_uuid = check_str($_REQUEST["uuid"]); @@ -138,6 +64,16 @@ else { $order_by = check_str($_GET["order_by"]); $order = check_str($_GET["order"]); +//get the voicemail + require_once "app/voicemails/resources/classes/voicemail.php"; + $vm = new voicemail; + $vm->db = $db; + $vm->domain_uuid = $_SESSION['domain_uuid']; + $vm->voicemail_uuid = $voicemail_uuid; + $vm->order_by = $order_by; + $vm->order = $order; + $voicemails = $vm->messages(); + //additional includes require_once "resources/header.php"; require_once "resources/paging.php";
".$text['title-voicemail']."".$text['title-voicemail']."\n"; + echo " \n"; + echo "