📄 voicemail.module
字号:
<?php/** * @file * Functions for the interface to the voicemail recordings *//** * Class for voicemail */class Voicemail { /* * rank (for prioritizing modules) */ function rank() { $rank = 1; return $rank; } /* * init */ function init() { } /* * 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 .= " <p><small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=Voicemail&f=display'>" . _("Voicemail") . "</a></small></small></p>"; } 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 = 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=" . $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)) { array_push($files, $value); } } if ($a=='delete') { $this->deleteVoicemailData($files); } 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 { $context = $_SESSION['ari_user']['context']; $extension = $_SESSION['ari_user']['extension']; $this->moveVoicemailData($files, $context, $extension, $folder_rx); } } else if ($a=='forward_to') { $mailbox_rx = getArgument($args,'mailbox_rx'); list($context_rx,$extension_rx) = split('/',$mailbox_rx); if ($extension_rx=='') { $_SESSION['ari_error'] = _("An extension must be selected before the message can be forwarded."); } else { $folder_rx = $ASTERISK_VOICEMAIL_FOLDERS[0]['folder']; $this->moveVoicemailData($files, $context_rx, $extension_rx, $folder_rx); } } // redirect to see updated page $ret .= " <head> <script> <!-- window.location = \"" . $_SESSION['ARI_ROOT'] . "?m=" . $m . "&folder=" . $folder . "&q=" . $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=='' ? 'desc' : $sort; $paths = 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); foreach ($lines as $key => $line) { // get context for forward to mailbox if (preg_match("/\[.*\]/i",$line)) { $forwardContext = trim(preg_replace('/\[|\]/', '', $line)); } // get username and add to options if (preg_match("/\=\>/i",$line)) { list($username,$value) = split('=>',$line); $username = trim($username); if ($username!=$_SESSION['ari_user']['extension']) { $forward_options .= "<option VALUE='" . $forwardContext . "/" . $username . "'>" . $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>"; // 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 . "&order=" . $field . "&sort=" . $currentSort . ">" . $text . $arrowImg . "</a></th>"; $i++; } $recording_header .= "<th>" . _("Message") . "</th>"; // table body if (isset($data)) { foreach($data as $file=>$value) { // recording popup link $voicemail_audio_format = $voicemail_audio_format=='' ? '.wav' : $voicemail_audio_format; $recording = preg_replace('/.txt/', $voicemail_audio_format, $file); if (is_file($recording)) { $recordingLink = "<a href='#' onClick=\"javascript:popUp('misc/recording_popup.php?recording=" . $recording . "&date=" . $date . "&time=" . $time . "'); return false;\"> " . _("play") . " </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=" . $file . "></td> <td width=68>" . GetDateFormat($value['origtime']) . "</td> <td>" . GetTimeFormat($value['origtime']) . "</td> <td width=100>" . $value[callerid] . "</td> <td>" . $value[priority] . "</td> <td width=90>" . $value[origmailbox] . "</td> <td>" . $value[duration] . " sec</td> <td>" . $recordingLink . "</td> </tr>"; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -