callme_num = callme_getnum($extension);
if (empty($this->callme_num)) {
$this->callme_num = $extension; // callme_num defaults to user's extension.
callme_setnum($extension, $extension);
}
}
/*
* Adds menu item to nav menu
*
* @param $args
* Common arguments
*/
function navMenu($args) {
global $ARI_NO_LOGIN;
// check logout
if ($_SESSION['ari_user'] && !$ARI_NO_LOGIN) {
$logout = 1;
}
if ($logout!='') {
$ret .= "" . _("Voicemail") . "";
}
return $ret;
}
/*
* Deletes selected voicemails and updates page
*
* @param $args
* Common arguments
*/
function navSubMenu($args) {
global $ASTERISK_VOICEMAIL_PATH;
global $ASTERISK_VOICEMAIL_FOLDERS;
// args
$m = getArgument($args,'m');
$q = getArgument($args,'q');
$current_folder = getArgument($args,'folder');
$context = $_SESSION['ari_user']['context'];
$extension = $_SESSION['ari_user']['extension'];
// check for voicemail enabled or admin
if ($_SESSION['ari_user']['voicemail_enabled']!=1 ||
$extension=='admin') {
return;
}
// make folder list
$paths = preg_split('/;/',$ASTERISK_VOICEMAIL_PATH);
$i = 0;
while ($ASTERISK_VOICEMAIL_FOLDERS[$i]) {
$f = $ASTERISK_VOICEMAIL_FOLDERS[$i]['folder'];
$fn = $ASTERISK_VOICEMAIL_FOLDERS[$i]['name'];
foreach($paths as $key => $path) {
$path = appendPath($path,$context);
$path = appendPath($path,$extension);
if (is_dir($path) && is_readable($path)) {
$dh = opendir($path);
while (false!== ($folder = readdir($dh))) {
$folder_path = AppendPath($path,$folder);
if($folder!="." && $folder!=".." &&
filetype($folder_path)=='dir') {
if ($f==$folder) {
// get message count
$indexes = $this->getVoicemailIndex($folder_path,$q,$order,$sort);
$record_count = 0;
$record_count += $this->getVoicemailCount($indexes);
// set current folder color
$class='';
if ($current_folder==$folder ||
($current_folder=='' && $ASTERISK_VOICEMAIL_FOLDERS[0]['folder']==$folder)) {
$class = "class='current'";
}
// add folder to list
$ret .= "
" . $fn . " (" . $record_count . ")" . "
";
}
}
}
}
}
$i++;
}
return $ret;
}
/*
* Acts on the selected voicemails in the method indicated by the action and updates page
*
* @param $args
* Common arguments
*/
function msgAction($args) {
global $ASTERISK_VOICEMAIL_FOLDERS;
// args
$m = getArgument($args,'m');
$a = getArgument($args,'a');
$folder = getArgument($args,'folder');
$q = getArgument($args,'q');
$start = getArgument($args,'start');
$span = getArgument($args,'span');
$order = getArgument($args,'order');
$sort = getArgument($args,'sort');
// get files
$files = array();
foreach($_REQUEST as $key => $value) {
if (preg_match('/selected/',$key) && isset($_SESSION['ari_user']['recfiles'][$value])) {
array_push($files, $_SESSION['ari_user']['recfiles'][$value]);
}
}
if ($a=='delete') {
if (count($files) > 0) {
$this->deleteVoicemailData($files);
}
else {
$_SESSION['ari_error']
= _("One or more messages must be selected before clicking delete.");
}
}
else if ($a=='move_to') {
$folder_rx = getArgument($args,'folder_rx');
if ($folder_rx=='') {
$_SESSION['ari_error']
= _("A folder must be selected before the message can be moved.");
}
else if (count($files) > 0) {
$context = $_SESSION['ari_user']['context'];
$extension = $_SESSION['ari_user']['extension'];
$this->moveVoicemailData($files, $context, $extension, $folder_rx);
}
else {
$_SESSION['ari_error']
= _("One or more messages must be selected before clicking move_to.");
}
}
else if ($a=='forward_to') {
$mailbox_rx = getArgument($args,'mailbox_rx');
list($context_rx,$extension_rx) = preg_split('/\//',$mailbox_rx);
if ($extension_rx=='') {
$_SESSION['ari_error']
= _("An extension must be selected before the message can be forwarded.");
}
else if (count($files) > 0) {
$folder_rx = $ASTERISK_VOICEMAIL_FOLDERS[0]['folder'];
$this->moveVoicemailData($files, $context_rx, $extension_rx, $folder_rx, false);
}
else {
$_SESSION['ari_error']
= _("One or more messages must be selected before clicking forward_to.");
}
}
else if ($a=='email_to') {
$em_to = getArgument($args,'email_to_addr');
if ($em_to=='') {
$_SESSION['ari_error']
= _("You must enter one or more email addresses (comma-separated) before clicking email_to.");
}
else if (count($files) > 0) {
$_SESSION['ari_error'] = "";
$line_end = "\n";
// Check email address(es) and construct address list for TO field.
// TO
$email_list = preg_split("/,/", $em_to);
foreach ($email_list as $list_elem) {
$list_elem = trim($list_elem);
if (preg_match("/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i", $list_elem)) {
$email_to .= $list_elem . ",";
} else {
$_SESSION['ari_error'] .= _("Warning: ") . $list_elem . _("is not a valid email address");
}
}
$email_to = trim($email_to, ","); // remove trailing comma
if ($email_to != "") {
$email_to = "To: " . $email_to;
// SUBJECT
$email_subject = "Subject: Voicemail forwarded from mailbox " . $_SESSION['ari_user']['extension'];
// DATE
$email_date = "Date: " . date("Y-m-d");
// MIME VERSION
$email_mime_ver = "MIME-Version: 1.0";
// HEADERS
$headers = $email_to . $line_end . $email_subject . $line_end . $email_date . $line_end;
$headers .= $email_mime_ver . $line_end;
$semi_rand = md5(time());
$boundary = "==VMAIL_MSG_Multipart_Boundary_x{$semi_rand}x";
$headers .= "Content-Type: multipart/mixed; boundary=\"{$boundary}\"" . $line_end;
$headers .= $line_end; // end of headers
$body = "This is a MIME message. Please use a MIME-capable email client." . $line_end;
$body .= "--{$boundary}" . $line_end;
$body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $line_end;
$body .= $line_end;
if (count($files) == 1) {
$body .= "You have been forwarded a voicemail message from mailbox " . $_SESSION['ari_user']['extension'] . "." . $line_end;
$body .= "Please listen to the attached recording. Thank you." . $line_end;
} else {
$body .= "You have been forwarded " . count($files) . " voicemail messages from mailbox " . $_SESSION['ari_user']['extension'] . "." . $line_end;
$body .= "Please listen to the attached recordings. Thank you." . $line_end;
}
$body .= $line_end;
$wav_pat = '/wav$/i';
$gsm_pat = '/gsm$/i';
$att_counter = -1;
foreach ($files as $f) {
if (preg_match($wav_pat, $f)) {
$content_type_audio = "Content-Type: audio/x-wav";
} else if (preg_match($gsm_pat, $f)) {
$content_type_audio = "Content-Type: audio/gsm";
} else {
$content_type_audio = "Content-Type: application/octet-stream"; // binary file attachment
$_SESSION['ari_error'] .= $f . ": " . _("The file type was not recognized.");
}
// Read in the attachment(s)
$file = fopen($f, "rb");
$file_data = fread($file, filesize($f));
fclose($file);
$body .= "--" . $boundary . $line_end;
$body .= $content_type_audio . $line_end;
preg_match("/msg[\d]*\.[A-Za-z]*/", $f, $fname_matches);
$email_fname = $fname_matches[0];
$body .= "Content-Disposition: attachment; filename=\"$email_fname\"" . $line_end;
$body .= "Content-Transfer-Encoding: base64" . $line_end;
$body .= $line_end;
$body .= chunk_split(base64_encode($file_data));
$body .= $line_end;
}
$body .= $line_end;
$body .= "--{$boundary}--";
$email_message = $headers . $body;
// If alternate mailer is defined in voicemail.conf, use it.
if (function_exists("parse_voicemailconf")) {
global $amp_conf;
$vmconf = null;
$section = null;
$vmail_path = rtrim($amp_conf["ASTETCDIR"],"/") . "/voicemail.conf";
parse_voicemailconf($vmail_path, $vmconf, $section);
} else {
$_SESSION['ari_error'] .= _("Warning: Could not access voicemail.conf. Using default mailer.");
}
if (isset($vmconf["general"]["mailcmd"]) && $vmconf["general"]["mailcmd"] != "") {
$email_mailcmd = $vmconf["general"]["mailcmd"];
} else {
$email_mailcmd = "/usr/sbin/sendmail -t";
}
// Mail it!
if (($sendmail_pipe = popen($email_mailcmd, "w"))) {
fputs($sendmail_pipe, $email_message);
fclose($sendmail_pipe);
} else {
$_SESSION['ari_error'] .= _("Mail operation failed");
}
} else {
$_SESSION['ari_error'] = _("No valid email address given. Please try again.");
}
}
else {
$_SESSION['ari_error'] = _("One or more messages must be selected before clicking email_to.");
}
}
// redirect to see updated page
$ret .= "
";
return $ret;
}
/*
* Displays stats page
*
* @param $args
* Common arguments
*/
function display($args) {
global $ASTERISK_VOICEMAIL_CONF;
global $ASTERISK_VOICEMAIL_PATH;
global $ASTERISK_VOICEMAIL_FOLDERS;
global $AJAX_PAGE_REFRESH_ENABLE;
$voicemail_audio_format = $_COOKIE['ari_voicemail_audio_format'];
$display = new DisplaySearch();
// args
$m = getArgument($args,'m');
$f = getArgument($args,'f');
$q = getArgument($args,'q');
$start = getArgument($args,'start');
$span = getArgument($args,'span');
$order = getArgument($args,'order');
$sort = getArgument($args,'sort');
$start = $start=='' ? 0 : $start;
$span = $span=='' ? 15 : $span;
$order = $order=='' ? 'calldate' : $order;
$sort = ($sort=='' || strtolower($sort) == 'desc') ? 'desc' : 'asc';
$paths = preg_split('/;/',$ASTERISK_VOICEMAIL_PATH);
$displayname = $_SESSION['ari_user']['displayname'];
$extension = $_SESSION['ari_user']['extension'];
$context = $_SESSION['ari_user']['context'];
$folder = getArgument($args,'folder');
if (!$folder) {
$folder = $ASTERISK_VOICEMAIL_FOLDERS[0]['folder'];
}
// get data
$data = array();
foreach($paths as $key => $path) {
$path = fixPathSlash($path);
$vm_path = $path . "$context/$extension/$folder";
$indexes = $this->getVoicemailIndex($vm_path,$q,$order,$sort);
$record_count += $this->getVoicemailCount($indexes);
$data = array_merge($data,$this->getVoicemailData($indexes,$start,$span));
}
// build controls
// get the recordings from the asterisk server
$filter = '';
$recursiveMax = 1;
$recursiveCount = 0;
$files = array();
foreach($paths as $key => $path) {
$path_files = GetFiles($path,$filter,$recursiveMax,$recursiveCount);
$files = array_merge($files,$path_files);
}
// move options
$i=0;
while ($ASTERISK_VOICEMAIL_FOLDERS[$i]) {
$cf = $ASTERISK_VOICEMAIL_FOLDERS[$i]['folder'];
$fn = $ASTERISK_VOICEMAIL_FOLDERS[$i]['name'];
if ($cf!=$folder) {
$move_options .= "