📄 voicemail.module
字号:
// 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); // start form $ret .= " <form name='voicemail_form' action='" . $_SESSION['ARI_ROOT'] . "' method='GET'> <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=" . $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); // add javascript for popup and message actions $ret .= " <SCRIPT LANGUAGE='JavaScript'> <!-- Begin function popUp(URL) { popup = window.open(URL, 'play', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=324,height=110'); } 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; } // 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 class='voicemail'> <tr> " . $recording_delete_header . " " . $recording_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) = 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) = 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 */ function moveVoicemailData($files,$context_rx,$extension_rx,$folder_rx) { global $ASTERISK_VOICEMAIL_PATH; $perm = fileperms($ASTERISK_VOICEMAIL_PATH); $uid = fileowner($ASTERISK_VOICEMAIL_PATH); $gid = filegroup($ASTERISK_VOICEMAIL_PATH); // recieving path $paths = 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); $num = preg_replace("/[a-zA-Z]|\./",'', $path_parts['basename']); 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; } // 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) = 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); $folder_rx = preg_replace("/\d+/",sprintf("%0" . $lastNumLen . "d",$lastNum),$path_parts['basename']); $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)); } 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) = split('=',$line); if ($value) { $data[$file][$key] = $value; } } } $i++; } return $data; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -