Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @file
- * Functions for the interface to the voicemail recordings
- */
- /**
- * Class for voicemail
- */
- class Voicemail {
- var $callme_num = "";
- /*
- * rank (for prioritizing modules)
- */
- function rank() {
- $rank = 2;
- return $rank;
- }
- /*
- * init
- */
- function init() {
- $extension = $_SESSION['ari_user']['extension'];
- $this->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 .= "<small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=Voicemail&f=display'>" . _("Voicemail") . "</a></small></small>";
- }
- 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 .= "<p><small><small>
- <a " . $class . " href='" . $_SESSION['ARI_ROOT'] . "?m=Voicemail&q=" . urlencode($q) . "&folder=" . $f. "'>
- " . $fn . " (" . $record_count . ")" . "
- </a>
- </small></small></p>";
- }
- }
- }
- }
- }
- $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 .= "
- <head>
- <script>
- <!--
- window.location = \"" . $_SESSION['ARI_ROOT'] . "?m=" . $m . "&folder=" . $folder . "&q=" . urlencode($q) . "&start=" . $start . "&span=" . $span . "&order=" . $order . "&sort=" . $sort .
- "\"
- // -->
- </script>
- </head>";
- 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 .= "<option VALUE='" . $cf . "'> " . $fn;
- }
- $i++;
- }
- // forward options
- if (is_readable($ASTERISK_VOICEMAIL_CONF)) {
- $lines = file($ASTERISK_VOICEMAIL_CONF);
- $ext_array = array();
- foreach ($lines as $key => $line) {
- // get context for forward to mailbox
- if (preg_match("/\[.*\]/i",$line)) {
- $forwardContext = trim(preg_replace('/\[|\]/', '', $line));
- }
- if ($forwardContext!=$_SESSION['ari_user']['context']) {
- continue;
- }
- // get username and add to options
- if (preg_match("/\=\>/i",$line)) {
- list($username,$value) = preg_split('/=>/',$line);
- $username = trim($username);
- if ($username!=$_SESSION['ari_user']['extension']) {
- //$ext_array[] = $username . "|" . $forwardContext;
- list(,$real_name,) = preg_split("/,/",$value,3);
- $ext_array[] = $real_name . "|" . $username . "|" . $forwardContext;
- }
- }
- } //foreach
- //sort the array
- sort($ext_array);
- //get the size of the array
- $array_size = count($ext_array) - 1;
- //loop through the array and build the drop down list
- foreach ($ext_array as $item)
- {
- //split the values apart
- list($real_name,$username,$context) = explode("|",$item);
- //add it to the drop down
- $forward_options .= "<option VALUE='" . $context . "/" . $username . "'>" . substr($real_name,0,15) . " <" . $username . ">";
- }
- }
- else {
- $_SESSION['ari_error'] = "File not readable: " . $ASTERISK_VOICEMAIL_CONF;
- return;
- }
- // table controls
- $controls = "
- <button class='infobar' type='submit' onclick=\"document.voicemail_form.a.value='delete'\">
- " . _("delete") . "
- </button>
- <button class='infobar' type='submit' onclick=\"document.voicemail_form.a.value='move_to'\">
- " . _("move_to") . "
- </button>
- <select name='folder_rx' style='width:124px;'>
- <option VALUE=''>" . _("Folder") . "
- " . $move_options . "
- </select>
- <button class='infobar' type='submit' onclick=\"document.voicemail_form.a.value='forward_to'\">
- " . _("forward_to") . "
- </button>
- <select name='mailbox_rx'>
- <option VALUE=''>
- " . $forward_options . "
- </select>
- <button class='infobar' type='submit' onclick=\"document.voicemail_form.a.value='email_to'\">
- " . _("email_to") . "
- </button>
- <input type='text' name='email_to_addr'/>";
- // table header
- $recording_delete_header = "<th></th>";
- $fields[0]['field'] = "calldate";
- $fields[0]['text'] = _("Date");
- $fields[1]['field'] = "calldate";
- $fields[1]['text'] = _("Time");
- $fields[2]['field'] = "clid";
- $fields[2]['text'] = _("Caller ID");
- $fields[3]['field'] = "priority";
- $fields[3]['text'] = _("Priority");
- $fields[4]['field'] = "origmailbox";
- $fields[4]['text'] = _("Orig Mailbox");
- $fields[5]['field'] = "duration";
- $fields[5]['text'] = _("Duration");
- $i = 0;
- while ($fields[$i]) {
- $field = $fields[$i]['field'];
- $text = $fields[$i]['text'];
- if ($order==$field) {
- if ($sort=='asc') {
- $currentSort = 'desc';
- $arrowImg = "<img src='theme/images/arrow-asc.gif' alt='sort'>";
- }
- else {
- $currentSort = 'asc';
- $arrowImg = "<img src='theme/images/arrow-desc.gif' alt='sort'>";
- }
- if ($i==1) {
- $arrowImg = '';
- }
- }
- else {
- $arrowImg = '';
- $currentSort = 'desc';
- }
- $unicode_q = urlencode($q);
- $recording_header .= "<th><a href=" . $_SESSION['ARI_ROOT'] . "?m=" . $m . "&f=" . $f . "&q=" . $unicode_q . "&folder=" . $folder . "&order=" . $field . "&sort=" . $currentSort . ">" . $text . $arrowImg . "</a></th>";
- $i++;
- }
- $recording_header .= "<th>" . _("Playback") . "</th>";
- // Column to provide a download link for each message in voicemail.
- $download_header .= "<th>" . _("Download"). "</th>";
- // table body
- unset($_SESSION['ari_user']['recfiles']);
- if (isset($data)) {
- $playbackRow = 2; // Index for where playback control rows used by javascript playback() should appear in the table.
- // First control row would appear below row 1 (hence $playbackRow starts at 2); control rows are inserted/deleted as needed.
- foreach($data as $file=>$value) {
- $i++;
- // Playback links
- $voicemail_audio_format = $voicemail_audio_format=='' ? '.wav' : $voicemail_audio_format;
- $recording = preg_replace('/.txt/', $voicemail_audio_format, $file);
- $date = GetDateFormat($value['origtime']);
- $time = GetTimeFormat($value['origtime']);
- $from = $value[callerid];
- $priority = $value[priority];
- $to = $value[origmailbox];
- $duration = $value[duration];
- if (is_file($recording)) {
- $_SESSION['ari_user']['recfiles'][$i] = $recording;
- $recordingLink = "<a href='#' onClick=\"javascript:playback('play', $playbackRow, 'misc/play_page.php?recindex=$i'); return false;\"><img src='theme/images/sound.png' title=". _("Play") ."></img></a>";
- $callmePage = "'misc/callme_page.php?recindex=$i&action=c'";
- $callme_tooltip = _("Play message at: ") . $this->callme_num;
- $callmeLink = "<a href='#' onClick=\"javascript:playback('callme', $playbackRow, $callmePage); return false;\"><img src='theme/images/telephone.png' title='$callme_tooltip'></img></a>";
- $downloadLink = "<a href=misc/audio.php?recindex=$i><img src='theme/images/drive_go.png' title=" . _("Download") . "></img></a>";
- }
- else {
- $_SESSION['ari_error'] = _("Voicemail recording(s) was not found.") . "<br>" .
- sprintf(_("On settings page, change voicemail audio format. It is currently set to %s"), $voicemail_audio_format);
- }
- $tableText .= "
- <tr>
- <td class='checkbox'><input type=checkbox name='selected" . $i . "' value=" . $i . "></td>
- <td width=68>" . $date . "</td>
- <td>" . $time . "</td>
- <td width=100>" . $from . "</td>
- <td>" . $value[priority] . "</td>
- <td width=90>" . $to . "</td>
- <td>" . $duration . " sec</td>
- <td>" . $recordingLink . " " . $callmeLink . "</td>
- <td>" . $downloadLink . "</td>
- </tr>";
- $playbackRow++;
- }
- }
- // options
- $url_opts = array();
- $url_opts['folder'] = $folder;
- $url_opts['sort'] = $sort;
- $url_opts['order'] = $order;
- $error = 0;
- // check for voicemail enabled
- if ($_SESSION['ari_user']['voicemail_enabled']!=1) {
- $_SESSION['ari_error'] = _("Voicemail Login not found.") . "<br>" .
- _("No access to voicemail");
- $error = 1;
- }
- // check admin
- if ($extension=='admin') {
- $_SESSION['ari_error'] = _("No Voicemail Recordings for Admin");
- $error = 1;
- }
- // build page content
- $ret .= checkErrorMessage();
- if ($error) {
- return $ret;
- }
- // ajax page refresh script
- if ($AJAX_PAGE_REFRESH_ENABLE) {
- // $ret .= ajaxRefreshScript($args);
- }
- // header
- $ret .= $display->displayHeaderText(sprintf(_("Voicemail for %s (%s)"),$displayname,$extension));
- $ret .= $display->displaySearchBlock('left',$m,$q,$url_opts,true);
- // pb_load_inprogress is a hidden element that is used by the javascript playback()
- // as a boolean to keep track of whether or not a Playback (Call Me or Computer Play) from this page is in progress ("loading").
- // start form
- $ret .= "
- <form name='voicemail_form' action='" . $_SESSION['ARI_ROOT'] . "' method='GET'>
- <input type=hidden id='pb_load_inprogress' value='false'>
- <input type=hidden name=m value=" . $m . ">
- <input type=hidden name=f value=msgAction>
- <input type=hidden name=a value=''>
- <input type=hidden name=q value=" . urlencode($q) . ">
- <input type=hidden name=folder value=" . $folder . ">
- <input type=hidden name=start value=" . $start . ">
- <input type=hidden name=span value=" . $span . ">
- <input type=hidden name=order value=" . $order . ">
- <input type=hidden name=sort value=" . $sort . ">";
- $ret .= $display->displayInfoBarBlock($controls,$q,$start,$span,$record_count);
- // Variables used in generating playback() javascript.
- $callme_status_msg0 = _("Calling: ");
- $callme_status_msg1 = _(". Please wait patiently...");
- // add javascript for playback and message actions
- $ret .= "
- <SCRIPT LANGUAGE='JavaScript'>
- <!-- Begin
- function checkAll(form,set) {
- var elem = 0;
- var i = 0;
- while (elem = form.elements[i]) {
- if (set) {
- elem.checked = true;
- } else {
- elem.checked = false;
- }
- i++;
- }
- return true;
- }
- // Playback function
- function playback(mode, row_num, link) {
- var playbackId = \"CURRENT__MSG\";
- var i = 0;
- var vmTable = document.getElementById('vmail_table');
- var inprogress = document.getElementById('pb_load_inprogress').value;
- // Only start a Playback control if another one is NOT in progress.
- if (inprogress == \"false\") {
- // Only one Playback control row can be open at a time.
- // If one is already open (e.g. a call that is now over or a message already loaded for playback), close it.
- for (i = 0; i < vmTable.rows.length; i++) {
- if (vmTable.rows[i].id == playbackId) {
- // Delete the row; it's a Playback control row.
- vmTable.deleteRow(vmTable.rows[i].rowIndex);
- }
- }
- // Make our Playback row.
- playback_src = \"<iframe width='100%' height='25px' marginheight='0' marginwidth='0' frameborder='0' scrolling='no' src=\" + link + \"></iframe>\";
- document.getElementById('pb_load_inprogress').value = \"true\";
- newRow = vmTable.insertRow(row_num);
- newRow.id = playbackId;
- cell_left = newRow.insertCell(0);
- if (mode == 'callme') {
- cell_left.colSpan = 4;
- cell_left.innerHTML = \"<div id='callme_status'>" . $callme_status_msg0 . $this->callme_num . $callme_status_msg1 . "</div>\";
- cell_right = newRow.insertCell(1);
- cell_right.colSpan = 5;
- cell_right.innerHTML = playback_src;
- } else {
- cell_left.colSpan = 9;
- cell_left.innerHTML = playback_src;
- }
- } else {
- // Change background color of status cell to alert user that the playback is still loading.
- document.getElementById(\"callme_status\").parentNode.style.backgroundColor = 'yellow';
- }
- }
- // End -->
- </script>";
- // voicemail delete recording controls
- $ret .= "
- <table>
- <tr>
- <td>
- <small>" . _("select") . ": </small>
- <small><a href='' OnClick=\"checkAll(document.voicemail_form,true); return false;\">" . _("all") . "</a></small>
- <small><a href='' OnClick=\"checkAll(document.voicemail_form,false); return false;\">" . _("none") . "</a></small>
- </td>
- </tr>
- </table>";
- // table
- $ret .= "
- <table id='vmail_table' class='voicemail'>
- <tr>
- " . $recording_delete_header . "
- " . $recording_header . "
- " . $download_header . "
- </tr>
- " . $tableText . "
- </table>";
- // end form
- $ret .= "</form>";
- $ret .= $display->displaySearchBlock('center',$m,$q,$url_opts,false);
- $ret .= $display->displayNavigationBlock($m,$q,$url_opts,$start,$span,$record_count);
- return $ret;
- }
- /*
- * Gets voicemail data
- *
- * @param $data
- * Reference to the variable to store the data in
- * @param $q
- * search string
- */
- function getVoicemailIndex($path,$q,$order,$sort) {
- $indexes = array();
- $filter = '.txt';
- $recursiveMax = 0;
- $recursiveCount = 0;
- $files = getFiles($path,$filter,$recursiveMax,$recursiveCount);
- if (isset($files)) {
- // ugly, but sorts array by time stamp
- foreach ($files as $file) {
- if (is_file($file)) {
- $lines = file($file);
- foreach ($lines as $key => $line) {
- unset($value);
- list($key,$value) = preg_split('/=/',$line);
- if ($value) {
- if ($key=="origtime") {
- $calldate = $value;
- $date = GetDateFormat($value);
- $time = GetTimeFormat($value);
- }
- if ($key=="callerid") {
- $callerid = $value;
- }
- if ($key=="priority") {
- $priority = $value;
- }
- if ($key=="origmailbox") {
- $origmailbox = $value;
- }
- if ($key=="duration") {
- $duration = (int)$value;
- }
- }
- }
- // search filter
- $found = 1;
- if ($q) {
- $found = 0;
- if (preg_match("/" . $q . "/", $origmailbox) ||
- preg_match("/" . $q . "/", $callerid) ||
- preg_match("/" . $q . "/", $date) ||
- preg_match("/" . $q . "/", $time)) {
- $found = 1;
- }
- }
- }
- // add to index
- if ($found) {
- $indexes[$file] = $$order;
- }
- }
- if (count($indexes)) {
- if ($sort=='desc') {
- arsort($indexes);
- }
- else {
- asort($indexes);
- }
- }
- }
- return $indexes;
- }
- /*
- * Deletes selected voicemails
- *
- * @param $files
- * Array of files to delete
- */
- function deleteVoicemailData($files) {
- foreach($files as $key => $path) {
- // get file parts for search
- $path_parts = pathinfo($path);
- $path = fixPathSlash($path_parts['dirname']);
- list($name,$ext) = preg_split("/\./",$path_parts['basename']);
- // delete all related files using a wildcard
- if (is_dir($path)) {
- $hdl = opendir($path);
- while ($fn = readdir($hdl)) {
- if (preg_match("/" . $name ."/",$fn)) {
- $file = $path . $fn;
- unlink($file);
- }
- }
- closedir($hdl);
- }
- }
- }
- /*
- * Moves selected voicemails to a specified folder
- *
- * @param $files
- * Array of files to delete
- * @param $extension_rx
- * Mailbox to move message to
- * @param $folder_rx
- * Folder to move the messages to
- * @param $delete_moved
- * If original should be deleted, default true (otherwise it is a copy)
- */
- function moveVoicemailData($files,$context_rx,$extension_rx,$folder_rx,$delete_moved=true) {
- global $ASTERISK_VOICEMAIL_PATH;
- $perm = fileperms($ASTERISK_VOICEMAIL_PATH);
- $uid = fileowner($ASTERISK_VOICEMAIL_PATH);
- $gid = filegroup($ASTERISK_VOICEMAIL_PATH);
- // recieving path
- $paths = preg_split('/;/',$ASTERISK_VOICEMAIL_PATH);
- $path_rx = appendPath($paths[0],$context_rx);
- if (!is_dir($path_rx)) {
- mkdir($path_rx, $perm);
- chown($path_rx,intval($uid));
- chgrp($path_rx,intval($gid));
- }
- $path_rx = appendPath($path_rx,$extension_rx);
- if (!is_dir($path_rx)) {
- mkdir($path_rx, $perm);
- chown($path_rx,intval($uid));
- chgrp($path_rx,intval($gid));
- }
- $path_rx = appendPath($path_rx,$folder_rx);
- if (!is_dir($path_rx)) {
- mkdir($path_rx, $perm);
- chown($path_rx,intval($uid));
- chgrp($path_rx,intval($gid));
- }
- // get recieving folder last message number
- if (is_dir($path_rx)) {
- $lastNum = -1;
- $lastNumLen = 4;
- $dh = opendir($path_rx);
- while (false != ($filename = readdir($dh))) {
- if($filename!="." && $filename!="..") {
- $msg_path = $path_rx;
- $msg_path = appendPath($msg_path,$filename);
- if (is_file($msg_path)) {
- $path_parts = pathinfo($msg_path);
- //fix for Serge Mankovski's "Voicemail RSS"
- //split file basename into two pieces at the first '.'
- //so that files like msg0000.7025f35d463ebbafa101db8a88c71b681aa8443d.mp3
- //don't interfere with finding the true last file number
- list($name,$ext) = preg_split("/\./",$path_parts['basename'],2);
- $num = preg_replace("/[a-zA-Z]/",'', $name);
- if ($num > $lastNum) {
- $lastNum = $num;
- $lastNumLen = strlen($lastNum);
- }
- }
- }
- }
- }
- else {
- $_SESSION['ari_error'] = sprintf(_("Could not create mailbox folder %s on the server"),$folder_rx);
- return;
- }
- foreach($files as $key => $pathPlain) {
- // add plain path to new array
- $filesPlain[] = $pathPlain;
- }
- // copy files to new location, incrementing each message number
- asort($files);
- foreach($files as $key => $path) {
- // get file parts for search
- $path_parts = pathinfo($path);
- $path = $path_parts['dirname'];
- $path = fixPathSlash($path);
- list($name,$ext) = preg_split("/\./",$path_parts['basename']);
- if (is_dir($path)) {
- $lastNum++;
- $hdl = opendir($path);
- while ($fn = readdir($hdl)) {
- if (preg_match("/" . $name . "/",$fn)) {
- $src = $path . $fn;
- $path_parts = pathinfo($src);
- //fix for Serge Mankovski's "Voicemail RSS"
- //split file basename into two pieces at the first '.'
- //so that files like msg0000.7025f35d463ebbafa101db8a88c71b681aa8443d.mp3
- //don't get clobbered by preg_replace() of digits
- list($name,$ext) = preg_split("/\./",$path_parts['basename'],2);
- $folder_rx = preg_replace("/\d+/",sprintf("%0" . $lastNumLen . "d",$lastNum),$name) . "." . $ext;
- $dst = appendPath($path_rx,$folder_rx);
- if (is_writable($src) && is_writable($path_rx)) {
- $perm = fileperms($src);
- $uid = fileowner($src);
- $gid = filegroup($src);
- copy($src,$dst);
- if (is_writable($dst)) {
- chmod($dst, $perm);
- chown($dst,intval($uid));
- chgrp($dst,intval($gid));
- }
- if ($delete_moved) {
- unlink($src);
- }
- }
- else {
- $_SESSION['ari_error'] = sprintf(_("Permission denied on folder %s or %s"),$src,$path_rx);
- return;
- }
- }
- }
- closedir($hdl);
- }
- }
- }
- /*
- * Gets voicemail record count
- *
- * @param $indexes
- * array of files to be counted
- * @return $count
- * number of cdr records counted
- */
- function getVoicemailCount($indexes) {
- $count = count($indexes);
- return $count;
- }
- /*
- * Gets voicemail data
- *
- * @param $indexes
- * array of voicemail files
- * @param $start
- * message number to start page with
- * @param $span
- * number of messages to display on page
- * @param $data
- * Reference to the variable to store the data in
- */
- function getVoicemailData($indexes,$start,$span) {
- $data = array();
- if (!isset($indexes)) {
- return;
- }
- // populate array
- $i = 0;
- foreach ($indexes as $file => $index) {
- if ($i>$start-1+$span) {
- return $data;
- }
- elseif ($i>$start-1 && $i<$start+$span) {
- $lines = file($file);
- foreach ($lines as $key => $line) {
- unset($value);
- list($key,$value) = preg_split('/=/',$line);
- $key = trim($key);
- $value = trim($value);
- if ($value) {
- $data[$file][$key] = $value;
- }
- }
- }
- $i++;
- }
- return $data;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement