Update the new native voicemail code.

This commit is contained in:
Mark Crane
2013-01-01 23:22:07 +00:00
parent a1fe967a3a
commit 4f63bab3f6
5 changed files with 301 additions and 151 deletions

View File

@@ -76,15 +76,21 @@
$text['label-view']['en-us'] = 'View';
$text['label-view']['pt-pt'] = '';
$text['label-greetings']['en-us'] = 'Greetings';
$text['label-greetings']['pt-pt'] = '';
$text['label-true']['en-us'] = 'true';
$text['label-true']['pt-pt'] = '';
$text['label-false']['en-us'] = 'false';
$text['label-false']['pt-pt'] = 'falso';
$text['label-greetings']['en-us'] = 'Greetings';
$text['label-greetings']['pt-pt'] = '';
$text['button-greetings']['en-us'] = 'Greetings';
$text['button-greetings']['pt-pt'] = '';
$text['button-settings']['en-us'] = 'Settings';
$text['button-settings']['pt-pt'] = '';
$text['button-add']['en-us'] = 'Add';
$text['button-add']['pt-pt'] = '';
@@ -125,9 +131,12 @@
$text['title-voicemail_message']['en-us'] = 'Voicemail Message';
$text['title-voicemail_message']['pt-pt'] = '';
$text['description-voicemail_message']['en-us'] = 'Voicemail Messages.';
$text['description-voicemail_message']['en-us'] = 'A list of recorded voice messages which shows when the message was created, caller ID information, length, file size and download or delete the message.';
$text['description-voicemail_message']['pt-pt'] = '';
$text['label-mailbox']['en-us'] = 'Mailbox';
$text['label-mailbox']['pt-pt'] = '';
$text['label-voicemail_uuid']['en-us'] = 'Voicemail UUID';
$text['label-voicemail_uuid']['pt-pt'] = '';

View File

@@ -0,0 +1,215 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2013
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//define the voicemail class
class voicemail {
public $db;
public $domain_uuid;
public $domain_name;
public $voicemail_uuid;
public $voicemail_id;
public $voicemail_message_uuid;
public $order_by;
public $order;
public function 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 ";
if (is_array($this->voicemail_id)) {
$sql .= "and (";
$x = 0;
foreach($this->voicemail_id as $row) {
if ($x > 0) {
$sql .= "or ";
}
$sql .= "v.voicemail_id = '".$row['voicemail_id']."' ";
$x++;
}
$sql .= ") ";
}
else {
$sql .= "and v.voicemail_id = '$this->voicemail_id' ";
}
if (strlen($this->order_by) == 0) {
$sql .= "order by v.voicemail_id, m.created_epoch desc ";
}
else {
$sql .= "order by v.voicemail_id, m.$this->order_by $this->order ";
}
//$sql .= "limit $this->rows_per_page offset $this->offset ";
$prep_statement = $this->db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll();
$result_count = count($result);
unset ($prep_statement, $sql);
if ($result_count > 0) {
foreach($result as &$row) {
//set the greeting directory
$row['file_path'] = $_SESSION['switch']['storage']['dir'].'/voicemail/default/'.$_SESSION['domain_name'].'/'.$row['voicemail_id'].'/msg_'.$row['voicemail_message_uuid'].'.wav';
$row['file_size'] = filesize($row['file_path']);
$row['file_size_label'] = byte_convert($row['file_size']);
$row['file_ext'] = substr($row['file_path'], -3);
$message_length = $row['message_length'];
if ($message_length < 60 ) {
$message_length = $message_length. " sec";
}
else {
$message_length = round(($message_length/60), 2). " min";
}
$row['message_length_label'] = $message_length;
$row['created_date'] = date("j M Y g:i a",$row['created_epoch']);
}
}
return $result;
}
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' ";
$prep_statement = $this->db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] > 0) {
$num_rows = $row['num_rows'];
}
else {
$num_rows = '0';
}
}
return $num_rows;
}
public function download() {
//get the voicemail_id
$sql = "select * from v_voicemails ";
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "and voicemail_uuid = '$this->voicemail_uuid' ";
$prep_statement = $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 ($prep_statement);
//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)) {
$fd = fopen($file_path, "rb");
if ($_GET['t'] == "bin") {
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
$file_ext = substr($file_path, -3);
if ($file_ext == "wav") {
header('Content-Disposition: attachment; filename="voicemail.wav"');
}
if ($file_ext == "mp3") {
header('Content-Disposition: attachment; filename="voicemail.mp3"');
}
}
else {
$file_ext = substr($file_path, -3);
if ($file_ext == "wav") {
header("Content-Type: audio/x-wav");
}
if ($file_ext == "mp3") {
header("Content-Type: audio/mp3");
}
}
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // date in the past
header("Content-Length: " . filesize($file_path));
fpassthru($fd);
}
} // download
}
//example 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 = $voicemail_uuid;
//$voicemail->voicemail_id = $voicemail_id;
//$voicemail->order_by = $order_by;
//$voicemail->order = $order;
//$result = $voicemail->messages();
//$result_count = count($result);
/*
Array
(
[user] => 1002
[extension_uuid] => e163fc03-f180-459b-aa12-7ed87fcb6e2c
[outbound_caller_id_name] => FusionPBX
[outbound_caller_id_number] => 12084024632
)
Array
(
[user] => 1020
[extension_uuid] => ecfb23df-7c59-4286-891e-2abdc48856ac
[outbound_caller_id_name] => Mark J Crane
[outbound_caller_id_number] => 12084024632
)
foreach ($_SESSION['user']['extension'] as $value) {
if (strlen($value['user']) > 0) {
}
}
*/
?>

View File

@@ -49,7 +49,9 @@ else {
$action = "add";
}
//get http post variables and set them to php variables
//get http variables and set them to php variables
$referer_path = check_str($_REQUEST["referer_path"]);
$referer_query = check_str($_REQUEST["referer_query"]);
if (count($_POST)>0) {
$voicemail_id = check_str($_POST["voicemail_id"]);
$voicemail_password = check_str($_POST["voicemail_password"]);
@@ -158,7 +160,12 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
unset($sql);
require_once "includes/header.php";
echo "<meta http-equiv=\"refresh\" content=\"2;url=voicemails.php\">\n";
if ($referer_path == "/app/voicemails/voicemail_messages.php") {
echo "<meta http-equiv=\"refresh\" content=\"2;url=voicemail_messages.php?".$referer_query."\">\n";
}
else {
echo "<meta http-equiv=\"refresh\" content=\"2;url=voicemails.php\">\n";
}
echo "<div align='center'>\n";
echo " ".$text['message-update']."\n";
echo "</div>\n";
@@ -343,6 +350,9 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
if ($action == "update") {
echo " <input type='hidden' name='voicemail_uuid' value='$voicemail_uuid'>\n";
}
$http_referer = parse_url($_SERVER["HTTP_REFERER"]);
echo " <input type='hidden' name='referer_path' value='".$http_referer['path']."'>\n";
echo " <input type='hidden' name='referer_query' value='".$http_referer['query']."'>\n";
echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
echo " </td>\n";
echo " </tr>";

View File

@@ -40,86 +40,31 @@ else {
$text[$key] = $value[$_SESSION['domain']['language']['code']];
}
//get the uuid
$voicemail_uuid = check_str($_REQUEST["id"]);
//get the voicemail_id
$sql = "select * from v_voicemails ";
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "and voicemail_uuid = '$voicemail_uuid' ";
$prep_statement = $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 ($prep_statement);
//download the voicemail
if ($_GET['a'] == "download") {
session_cache_limiter('public');
$voicemail_message_uuid = check_str($_GET["uuid"]);
$sql = "select * from v_voicemail_messages ";
//get the uuid and voicemail_id
if (strlen($_REQUEST["id"]) > 0) {
$voicemail_uuid = check_str($_REQUEST["id"]);
$sql = "select * from v_voicemails ";
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "and voicemail_message_uuid = '$voicemail_message_uuid' ";
$sql .= "and voicemail_uuid = '$voicemail_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"];
$voicemail_id = $row["voicemail_id"];
}
unset ($prep_statement);
}
if ($_GET['type'] = "vm") {
$file_path = $_SESSION['switch']['storage']['dir']."/voicemail/default/".$_SESSION['domain_name']."/".$voicemail_id."/msg_".$voicemail_message_uuid.".wav";
if (file_exists($file_path)) {
$fd = fopen($file_path, "rb");
if ($_GET['t'] == "bin") {
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
$file_ext = substr($file_path, -3);
if ($file_ext == "wav") {
header('Content-Disposition: attachment; filename="voicemail.wav"');
}
if ($file_ext == "mp3") {
header('Content-Disposition: attachment; filename="voicemail.mp3"');
}
}
else {
$file_ext = substr($file_path, -3);
if ($file_ext == "wav") {
header("Content-Type: audio/x-wav");
}
if ($file_ext == "mp3") {
header("Content-Type: audio/mp3");
}
}
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // date in the past
header("Content-Length: " . filesize($file_path));
fpassthru($fd);
}
return;
//set the voicemail_id array
if (strlen($_REQUEST["id"]) == 0) {
foreach ($_SESSION['user']['extension'] as $value) {
$voicemail_id[]['voicemail_id'] = $value['user'];
}
}
//get the html values and set them as variables
$order_by = check_str($_GET["order_by"]);
$order = check_str($_GET["order"]);
if (strlen($_GET["id"]) > 0) {
$voicemail_uuid = check_str($_GET["id"]);
}
//additional includes
require_once "includes/header.php";
@@ -139,104 +84,73 @@ else {
echo " </tr>\n";
echo " <tr>\n";
echo " <td align='left' colspan='2'>\n";
echo " ".$text['description-voicemail_message']."<br /><br />\n";
echo " ".$text['description-voicemail_message']."<br />\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
//prepare to page the results
$sql = "select count(*) as num_rows from v_voicemail_messages ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql .= "and voicemail_uuid = '$voicemail_uuid' ";
if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] > 0) {
$num_rows = $row['num_rows'];
}
else {
$num_rows = '0';
}
}
//prepare to page the results
$rows_per_page = 150;
$param = "";
$page = $_GET['page'];
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page);
$offset = $rows_per_page * $page;
//get the list
$sql = "select * from v_voicemail_messages ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql .= "and voicemail_uuid = '$voicemail_uuid' ";
if (strlen($order_by) == 0) {
$sql .= "order by created_epoch desc ";
}
else {
$sql .= "order by $order_by $order ";
}
$sql .= "limit $rows_per_page offset $offset ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll();
$result_count = count($result);
unset ($prep_statement, $sql);
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
echo "<div align='center'>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
//echo th_order_by('voicemail_uuid', $text['label-voicemail_uuid'], $order_by, $order);
echo th_order_by('created_epoch', $text['label-created_epoch'], $order_by, $order);
//echo th_order_by('read_epoch', $text['label-read_epoch'], $order_by, $order);
echo th_order_by('caller_id_name', $text['label-caller_id_name'], $order_by, $order);
echo th_order_by('caller_id_number', $text['label-caller_id_number'], $order_by, $order);
echo th_order_by('message_length', $text['label-message_length'], $order_by, $order);
echo "<th>".$text['label-message_size']."</th>\n";
echo "<th>".$text['label-tools']."</th>\n";
//echo th_order_by('message_priority', $text['label-message_priority'], $order_by, $order);
echo "<td align='right' width='21'>\n";
echo " &nbsp;\n";
echo "</td>\n";
echo "<tr>\n";
$table_header = "<tr>\n";
$table_header .= th_order_by('created_epoch', $text['label-created_epoch'], $order_by, $order);
//$table_header .= th_order_by('read_epoch', $text['label-read_epoch'], $order_by, $order);
$table_header .= th_order_by('caller_id_name', $text['label-caller_id_name'], $order_by, $order);
$table_header .= th_order_by('caller_id_number', $text['label-caller_id_number'], $order_by, $order);
$table_header .= th_order_by('message_length', $text['label-message_length'], $order_by, $order);
$table_header .= "<th>".$text['label-message_size']."</th>\n";
$table_header .= "<th>".$text['label-tools']."</th>\n";
//$table_header .= th_order_by('message_priority', $text['label-message_priority'], $order_by, $order);
$table_header .= "<td align='right' width='21'>\n";
$table_header .= " &nbsp;\n";
$table_header .= "</td>\n";
$table_header .= "<tr>\n";
//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 = $voicemail_uuid;
$voicemail->voicemail_id = $voicemail_id;
$voicemail->order_by = $order_by;
$voicemail->order = $order;
$result = $voicemail->messages();
$result_count = count($result);
//loop throug the voicemail messages
if ($result_count > 0) {
$previous_voicemail_id = '';
foreach($result as $row) {
//set the greeting directory
$file_path = $_SESSION['switch']['storage']['dir'].'/voicemail/default/'.$_SESSION['domain_name'].'/'.$voicemail_id.'/msg_'.$row['voicemail_message_uuid'].'.wav';
$file_size = filesize($file_path);
$file_size = byte_convert($file_size);
$file_ext = substr($row['file_path'], -3);
$message_length = $row['message_length'];
if ($message_length < 60 ) {
$message_length = $message_length. " sec";
if ($previous_voicemail_id != $row['voicemail_id']) {
echo "<tr><td colspan='5' align='left'>\n";
echo " <br /><br />\n";
echo " <b>".$text['label-mailbox'].": ".$row['voicemail_id']."</b>&nbsp;\n";
echo " \n";
echo "</td>\n";
echo "<td valign='bottom' align='right'>\n";
echo " <input type='button' class='btn' name='' alt='greetings' onclick=\"window.location='".PROJECT_PATH."/app/voicemail_greetings/voicemail_greetings.php?id=".$row['voicemail_id']."'\" value='".$text['button-greetings']."'>\n";
echo " <input type='button' class='btn' name='' alt='settings' onclick=\"window.location='".PROJECT_PATH."/app/voicemails/voicemail_edit.php?id=".$row['voicemail_uuid']."'\" value='".$text['button-settings']."'>\n";
echo "</td>\n";
echo "</tr>\n";
echo $table_header;
}
else {
$message_length = round(($message_length/60), 2). " min";
}
if ($row['message_status'] == '') { $style = "style=\"font-weight:bold;\""; } else { $style = ''; }
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['voicemail_uuid']."&nbsp;</td>\n";
echo "<td valign='top' class='".$row_style[$c]."' $style nowrap=\"nowrap\">";
echo " ".date("j M Y g:i a",$row['created_epoch']);
echo " ".$row['created_date'];
echo "</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['read_epoch']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' $style>".$row['caller_id_name']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' $style>".$row['caller_id_number']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' $style>".$message_length."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' $style>".$row['message_length_label']."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."' $style>".$row['message_status']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' $style>".$file_size."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' $style>".$row['file_size_label']."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' $style>\n";
//echo " <a href=\"javascript:void(0);\" onclick=\"window.open('voicemail_msgs_play.php?a=download&type=vm&uuid=".$row['voicemail_message_uuid']."&id=".$row['voicemail_id']."&ext=".$file_ext."&desc=".urlencode($row['cid_name']." ".$row['cid_number'])."', 'play',' width=420,height=40,menubar=no,status=no,toolbar=no')\">\n";
//echo " <a href=\"javascript:void(0);\" onclick=\"window.open('voicemail_msgs_play.php?a=download&type=vm&uuid=".$row['voicemail_message_uuid']."&id=".$row['voicemail_id']."&ext=".$row['file_ext']."&desc=".urlencode($row['cid_name']." ".$row['cid_number'])."', 'play',' width=420,height=40,menubar=no,status=no,toolbar=no')\">\n";
//echo " ".$text['label-play']."\n";
//echo " </a>\n";
echo " &nbsp;&nbsp;\n";
@@ -251,9 +165,11 @@ else {
}
echo " </td>\n";
echo "</tr>\n";
$previous_voicemail_id = $row['voicemail_id'];
if ($c==0) { $c=1; } else { $c=0; }
} //end foreach
unset($sql, $result, $row_count);
unset($sql, $result, $result_count);
} //end if results
echo "<tr>\n";
@@ -261,7 +177,7 @@ else {
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td width='33.3%' nowrap='nowrap'>&nbsp;</td>\n";
echo " <td width='33.3%' align='center' nowrap='nowrap'>$paging_controls</td>\n";
echo " <td width='33.3%' align='center' nowrap='nowrap'>&nbsp;</td>\n";
echo " <td width='33.3%' align='right'>\n";
echo " &nbsp;\n";
echo " </td>\n";

View File

@@ -145,7 +145,7 @@ else {
//echo " <td valign='top' class='".$row_style[$c]."'>&nbsp;</td>\n";
echo " <td valign='middle' class='".$row_style[$c]."'>\n";
echo " <a href='voicemail_messages.php?id=".$row['voicemail_uuid']."'>".$text['label-view']."</a>&nbsp;&nbsp;\n";
echo " <a href='/app/voicemail_greetings/voicemail_greetings.php?id=".$row['voicemail_id']."'>".$text['label-greetings']."</a>\n";
echo " <a href='".PROJECT_PATH."/app/voicemail_greetings/voicemail_greetings.php?id=".$row['voicemail_id']."'>".$text['label-greetings']."</a>\n";
echo " </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['voicemail_enabled']."&nbsp;</td>\n";
echo " <td valign='top' class='row_stylebg' width='30%'>".$row['voicemail_description']."&nbsp;</td>\n";