Ticket #2565: voicemail.module

File voicemail.module, 22.9 kB (added by sasargen, 8 months ago)

Patched to encrypt all file paths in html output and function arguments.

Line 
1 <?php
2
3 /**
4  * @file
5  * Functions for the interface to the voicemail recordings
6  */
7
8 /**
9   * Class for voicemail
10   */
11 class Voicemail {
12
13   /*
14    * rank (for prioritizing modules)
15    */
16   function rank() {
17
18     $rank = 1;
19     return $rank;
20   }
21
22   /*
23    * init
24    */
25   function init() {
26   }
27
28   /*
29    * Adds menu item to nav menu
30    *
31    * @param $args
32    *   Common arguments
33    */
34   function navMenu($args) {
35
36     global $ARI_NO_LOGIN;
37
38     // check logout
39     if ($_SESSION['ari_user'] && !$ARI_NO_LOGIN) {
40       $logout = 1;
41     }
42
43     if ($logout!='') {
44       $ret .= "<p><small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=Voicemail&f=display'>" . _("Voicemail") . "</a></small></small></p>";
45     }
46
47     return $ret;
48   }
49
50   /*
51    * Deletes selected voicemails and updates page
52    *
53    * @param $args
54    *   Common arguments
55    */
56   function navSubMenu($args) {
57
58     global $ASTERISK_VOICEMAIL_PATH;
59     global $ASTERISK_VOICEMAIL_FOLDERS;
60
61     // args
62     $m = getArgument($args,'m');
63     $q = getArgument($args,'q');
64     $current_folder = getArgument($args,'folder');
65
66     $context = $_SESSION['ari_user']['context'];
67     $extension = $_SESSION['ari_user']['extension'];
68
69     // check for voicemail enabled or admin
70     if ($_SESSION['ari_user']['voicemail_enabled']!=1 ||
71           $extension=='admin') {
72       return;
73     }
74
75     // make folder list
76     $paths = split(';',$ASTERISK_VOICEMAIL_PATH);
77     $i = 0;
78     while ($ASTERISK_VOICEMAIL_FOLDERS[$i]) {
79
80       $f = $ASTERISK_VOICEMAIL_FOLDERS[$i]['folder'];
81       $fn = $ASTERISK_VOICEMAIL_FOLDERS[$i]['name'];
82
83       foreach($paths as $key => $path) {
84
85         $path = appendPath($path,$context);
86         $path = appendPath($path,$extension);
87  
88         if (is_dir($path) && is_readable($path)) {
89           $dh = opendir($path);
90           while (false!== ($folder = readdir($dh))) {
91
92             $folder_path = AppendPath($path,$folder);
93
94             if($folder!="." && $folder!=".." &&
95                  filetype($folder_path)=='dir') {
96
97               if ($f==$folder) {
98
99                 // get message count
100                 $indexes = $this->getVoicemailIndex($folder_path,$q,$order,$sort);
101                 $record_count = 0;
102                 $record_count += $this->getVoicemailCount($indexes);
103
104                 // set current folder color
105                 $class='';
106                 if ($current_folder==$folder ||
107                      ($current_folder=='' && $ASTERISK_VOICEMAIL_FOLDERS[0]['folder']==$folder)) {
108                   $class = "class='current'";
109                 }
110
111                 // add folder to list
112                 $ret .= "<p><small><small>
113                            <a " . $class . " href='" . $_SESSION['ARI_ROOT'] . "?m=Voicemail&q=" . $q . "&folder=" . $f. "'>
114                            " . $fn . " (" . $record_count . ")" . "
115                            </a>
116                          </small></small></p>";
117               }
118             }
119           }
120         }
121       }
122       $i++;
123     }
124
125     return $ret;
126   }
127
128   /*
129    * Acts on the selected voicemails in the method indicated by the action and updates page
130    *
131    * @param $args
132    *   Common arguments
133    */
134   function msgAction($args) {
135
136     global $ASTERISK_VOICEMAIL_FOLDERS;
137
138     // args
139     $m = getArgument($args,'m');
140     $a = getArgument($args,'a');
141     $folder = getArgument($args,'folder');
142     $q = getArgument($args,'q');
143     $start = getArgument($args,'start');
144     $span = getArgument($args,'span');
145     $order = getArgument($args,'order');
146     $sort = getArgument($args,'sort');
147
148     // get files
149     $files = array();
150     foreach($_REQUEST as $key => $value) {
151       if (preg_match('/selected/',$key)) {
152         array_push($files, $value);
153       }
154     }
155
156     if ($a=='delete') {
157       $this->deleteVoicemailData($files);
158     }
159     else if ($a=='move_to') {
160       $folder_rx = getArgument($args,'folder_rx');
161       if ($folder_rx=='') {
162         $_SESSION['ari_error']
163           = _("A folder must be selected before the message can be moved.");
164       }
165       else {
166         $context = $_SESSION['ari_user']['context'];
167         $extension = $_SESSION['ari_user']['extension'];
168         $this->moveVoicemailData($files, $context, $extension, $folder_rx);
169       }
170     }
171     else if ($a=='forward_to') {
172
173       $mailbox_rx = getArgument($args,'mailbox_rx');
174       list($context_rx,$extension_rx) = split('/',$mailbox_rx);
175       if ($extension_rx=='') {
176         $_SESSION['ari_error']
177           = _("An extension must be selected before the message can be forwarded.");
178       }
179       else {
180         $folder_rx = $ASTERISK_VOICEMAIL_FOLDERS[0]['folder'];
181         $this->moveVoicemailData($files, $context_rx, $extension_rx, $folder_rx);
182       }
183     }
184
185     // redirect to see updated page
186     $ret .= "
187       <head>
188         <script>
189         <!--
190           window.location = \"" . $_SESSION['ARI_ROOT'] . "?m=" . $m . "&folder=" . $folder . "&q=" . $q . "&start=" . $start . "&span=" . $span . "&order=" . $order . "&sort=" . $sort . "\"
191         // -->
192         </script>
193       </head>";
194
195     return $ret;
196   }
197
198   /*
199    * Displays stats page
200    *
201    * @param $args
202    *   Common arguments
203    */
204   function display($args) {
205
206     global $ASTERISK_VOICEMAIL_CONF;
207     global $ASTERISK_VOICEMAIL_PATH;
208     global $ASTERISK_VOICEMAIL_FOLDERS;
209     global $AJAX_PAGE_REFRESH_ENABLE;
210     global $ARI_CRYPT_PASSWORD;
211
212     $voicemail_audio_format = $_COOKIE['ari_voicemail_audio_format'];
213
214     $display = new DisplaySearch();
215     $crypt = new Crypt();
216
217     // args
218     $m = getArgument($args,'m');
219     $f = getArgument($args,'f');
220     $q = getArgument($args,'q');
221     $start = getArgument($args,'start');
222     $span = getArgument($args,'span');
223     $order = getArgument($args,'order');
224     $sort = getArgument($args,'sort');
225
226     $start = $start=='' ? 0 : $start;
227     $span = $span=='' ? 15 : $span;
228     $order = $order=='' ? 'calldate' : $order;
229     $sort = $sort=='' ? 'desc' : $sort;
230
231     $paths = split(';',$ASTERISK_VOICEMAIL_PATH);
232
233     $displayname = $_SESSION['ari_user']['displayname'];
234     $extension = $_SESSION['ari_user']['extension'];
235     $context = $_SESSION['ari_user']['context'];
236     $folder = getArgument($args,'folder');
237     if (!$folder) {
238       $folder = $ASTERISK_VOICEMAIL_FOLDERS[0]['folder'];
239     }
240
241     // get data
242     $data = array();
243     foreach($paths as $key => $path) {
244       $path = fixPathSlash($path);
245       $vm_path = $path . "$context/$extension/$folder";
246       $indexes = $this->getVoicemailIndex($vm_path,$q,$order,$sort);
247       $record_count += $this->getVoicemailCount($indexes);
248       $data = array_merge($data,$this->getVoicemailData($indexes,$start,$span));
249     }
250
251     // build controls
252
253     // get the recordings from the asterisk server
254     $filter = '';
255     $recursiveMax = 1;
256     $recursiveCount = 0;
257     $files = array();
258     foreach($paths as $key => $path) {
259       $path_files = GetFiles($path,$filter,$recursiveMax,$recursiveCount);
260       $files = array_merge($files,$path_files);
261     }
262
263     // move options
264     $i=0;
265     while ($ASTERISK_VOICEMAIL_FOLDERS[$i]) {
266       $cf = $ASTERISK_VOICEMAIL_FOLDERS[$i]['folder'];
267       $fn = $ASTERISK_VOICEMAIL_FOLDERS[$i]['name'];
268       if ($cf!=$folder) {
269         $move_options .= "<option VALUE='" . $cf . "'>&nbsp;&nbsp;&nbsp;&nbsp;" .  $fn;
270       }
271       $i++;
272     }
273
274     // forward options
275     if (is_readable($ASTERISK_VOICEMAIL_CONF)) {
276       $lines = file($ASTERISK_VOICEMAIL_CONF);
277       $ext_array = array();
278       foreach ($lines as $key => $line) {
279
280         // get context for forward to mailbox
281         if (preg_match("/\[.*\]/i",$line)) {
282           $forwardContext = trim(preg_replace('/\[|\]/', '', $line));
283         }
284
285         // get username and add to options
286         if (preg_match("/\=\>/i",$line)) {
287           list($username,$value) = split('=>',$line);
288           $username = trim($username);
289           if ($username!=$_SESSION['ari_user']['extension']) {
290             //$ext_array[] = $username . "|" . $forwardContext;
291             list(,$real_name,) = split(",",$value,3);
292             $ext_array[] = $real_name . "|" . $username . "|" . $forwardContext;
293           }
294         }
295       } //foreach
296       //sort the array
297       sort($ext_array);
298
299       //get the size of the array
300       $array_size = count($ext_array) - 1;
301
302       //loop through the array and build the drop down list
303       foreach ($ext_array as $item)
304       {
305          //split the values apart
306          list($real_name,$username,$context) = explode("|",$item);
307
308          //add it to the drop down
309          $forward_options .= "<option VALUE='" . $context . "/" . $username . "'>" . substr($real_name,0,15) . " <" . $username . ">";
310       }
311     }
312     else {
313       $_SESSION['ari_error'] = "File not readable: " . $ASTERISK_VOICEMAIL_CONF;
314       return;
315     }
316
317     // table controls
318     $controls = "
319           <button class='infobar' type='submit' onclick=\"document.voicemail_form.a.value='delete'\">
320           " . _("delete") . "
321           </button>
322           <button class='infobar' type='submit' onclick=\"document.voicemail_form.a.value='move_to'\">
323           " . _("move_to") . "
324           </button>
325           <select name='folder_rx' style='width:124px;'>
326             <option VALUE=''>" . _("Folder") . "
327             " . $move_options . "
328           </select>
329           <button class='infobar' type='submit' onclick=\"document.voicemail_form.a.value='forward_to'\">
330           " . _("forward_to") . "
331           </button>
332           <select name='mailbox_rx'>
333             <option VALUE=''>
334             " . $forward_options . "
335           </select>";
336
337     // table header
338     $recording_delete_header = "<th></th>";
339
340     $fields[0]['field'] = "calldate";
341     $fields[0]['text'] = _("Date");
342     $fields[1]['field'] = "calldate";
343     $fields[1]['text'] = _("Time");
344     $fields[2]['field'] = "clid";
345     $fields[2]['text'] = _("Caller ID");
346     $fields[3]['field'] = "priority";
347     $fields[3]['text'] = _("Priority");
348     $fields[4]['field'] = "origmailbox";
349     $fields[4]['text'] = _("Orig Mailbox");
350     $fields[5]['field'] = "duration";
351     $fields[5]['text'] = _("Duration");
352     $i = 0;
353     while ($fields[$i]) {
354
355       $field = $fields[$i]['field'];
356       $text = $fields[$i]['text'];
357       if ($order==$field) {
358         if ($sort=='asc') {
359           $currentSort = 'desc';
360           $arrowImg = "<img src='theme/images/arrow-asc.gif' alt='sort'>";
361         }
362         else {
363           $currentSort = 'asc';
364           $arrowImg = "<img src='theme/images/arrow-desc.gif' alt='sort'>";
365         }   
366
367         if ($i==1) {
368           $arrowImg = '';
369         }   
370       }
371       else {
372         $arrowImg = '';
373         $currentSort = 'desc';
374       }
375
376       $unicode_q = urlencode($q);
377       $recording_header .= "<th><a href=" .  $_SESSION['ARI_ROOT'] . "?m=" . $m . "&f=" . $f . "&q=" . $unicode_q . "&order=" . $field . "&sort=" . $currentSort . ">" . $text . $arrowImg . "</a></th>";
378
379       $i++;
380     }
381     $recording_header .= "<th>" . _("Message") . "</th>";
382
383     // table body
384     if (isset($data)) {
385       foreach($data as $file=>$value) {
386
387         // recording popup link
388         $voicemail_audio_format = $voicemail_audio_format=='' ? '.wav' : $voicemail_audio_format;
389         $recording = preg_replace('/.txt/', $voicemail_audio_format, $file);
390         $date = GetDateFormat($value['origtime']);
391         $time = GetTimeFormat($value['origtime']);
392         $from = $value[callerid];
393         $priority = $value[priority];
394         $to = $value[origmailbox];
395         $duration = $value[duration];
396         if (is_file($recording)) {
397           $recordingCrypt = $crypt->encrypt($recording,$ARI_CRYPT_PASSWORD);
398           $recordingLink = "<a href='#' onClick=\"javascript:popUp('misc/recording_popup.php?recording=" . $recordingCrypt . "&date=" . $date . "&time=" . $time . "'); return false;\">
399             " . _("play") . "
400           </a>";
401         }
402         else {
403           $_SESSION['ari_error'] = _("Voicemail recording(s) was not found.") . "<br>" .
404                                    sprintf(_("On settings page, change voicemail audio format.  It is currently set to %s"),$voicemail_audio_format);
405         }
406
407         $fileCrypt = $crypt->encrypt($file,$ARI_CRYPT_PASSWORD);
408
409         $tableText .= "
410           <tr>
411             <td class='checkbox'><input type=checkbox name='selected" . ++$i . "' value=" . $fileCrypt . "></td>
412             <td width=68>" . $date . "</td>
413             <td>" . $time . "</td>
414             <td width=100>" . $from . "</td>
415             <td>" . $value[priority] . "</td>
416             <td width=90>" . $to . "</td>
417             <td>" . $duration . " sec</td>
418             <td>" . $recordingLink .  "</td>
419           </tr>";
420       }
421     }
422
423     // options
424     $url_opts = array();
425     $url_opts['folder'] = $folder;
426     $url_opts['sort'] = $sort;
427     $url_opts['order'] = $order;
428
429     $error = 0;
430
431     // check for voicemail enabled
432     if ($_SESSION['ari_user']['voicemail_enabled']!=1) {
433       $_SESSION['ari_error'] = _("Voicemail Login not found.") . "<br>" .
434                                _("No access to voicemail");
435       $error = 1;
436     }
437
438     // check admin
439     if ($extension=='admin') {
440       $_SESSION['ari_error'] = _("No Voicemail Recordings for Admin");
441       $error = 1;
442     }
443
444     // build page content
445     $ret .= checkErrorMessage();
446     if ($error) {
447       return $ret;
448     }
449
450     // ajax page refresh script
451     if ($AJAX_PAGE_REFRESH_ENABLE) {
452 //      $ret .= ajaxRefreshScript($args);
453     }
454
455     // header
456     $ret .= $display->displayHeaderText(sprintf(_("Voicemail for %s (%s)"),$displayname,$extension));
457     $ret .= $display->displaySearchBlock('left',$m,$q,$url_opts,true);
458
459     // start form
460     $ret .= "
461       <form name='voicemail_form' action='" . $_SESSION['ARI_ROOT'] . "' method='GET'>
462         <input type=hidden name=m value=" . $m . ">     
463         <input type=hidden name=f value=msgAction>
464         <input type=hidden name=a value=''>
465         <input type=hidden name=q value=" . $q . ">
466         <input type=hidden name=folder value=" . $folder . ">
467         <input type=hidden name=start value=" . $start . ">
468         <input type=hidden name=span value=" . $span . ">
469         <input type=hidden name=order value=" . $order . ">
470         <input type=hidden name=sort value=" . $sort . ">";
471
472     $ret .= $display->displayInfoBarBlock($controls,$q,$start,$span,$record_count);
473
474     // add javascript for popup and message actions
475     $ret .= "
476       <SCRIPT LANGUAGE='JavaScript'>
477       <!-- Begin
478       function popUp(URL) {
479         popup = window.open(URL, 'play', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=324,height=110');
480       }
481
482       function checkAll(form,set) {
483         var elem = 0;
484         var i = 0;
485         while (elem = form.elements[i]) {
486           if (set) {
487             elem.checked = true;
488           } else {
489             elem.checked = false;
490           }
491           i++;
492         }
493         return true;
494       }
495       // End -->
496       </script>";
497
498     // voicemail delete recording controls
499     $ret .= "
500       <table>
501         <tr>
502           <td>
503             <small>" . _("select") . ": </small>
504             <small><a href='' OnClick=\"checkAll(document.voicemail_form,true); return false;\">" . _("all") . "</a></small>
505             <small><a href='' OnClick=\"checkAll(document.voicemail_form,false); return false;\">" . _("none") . "</a></small>
506           </td>
507         </tr>
508       </table>";
509
510     // table
511     $ret .= "
512       <table class='voicemail'>
513         <tr>
514            " . $recording_delete_header . "
515            " . $recording_header . "
516         </tr>
517         " . $tableText . "
518       </table>";
519
520     // end form
521     $ret .= "</form>";
522
523     $ret .= $display->displaySearchBlock('center',$m,$q,$url_opts,false);
524     $ret .= $display->displayNavigationBlock($m,$q,$url_opts,$start,$span,$record_count);
525
526     return $ret;
527   }
528
529   /*
530    * Gets voicemail data
531    *
532    * @param $data
533    *   Reference to the variable to store the data in
534    * @param $q
535    *   search string
536    */
537   function getVoicemailIndex($path,$q,$order,$sort) {
538
539     $indexes = array();
540
541     $filter = '.txt';
542     $recursiveMax = 0;
543     $recursiveCount = 0;
544     $files = getFiles($path,$filter,$recursiveMax,$recursiveCount);
545
546     if (isset($files)) {
547
548       // ugly, but sorts array by time stamp
549       foreach ($files as $file) {
550
551         if (is_file($file)) {
552
553           $lines = file($file);
554           foreach ($lines as $key => $line) {
555             unset($value);
556             list($key,$value) = split('=',$line);
557             if ($value) {
558
559               if ($key=="origtime") {
560                 $calldate = $value;
561                 $date = GetDateFormat($value);
562                 $time = GetTimeFormat($value);
563               }
564               if ($key=="callerid") {
565                 $callerid = $value;
566               }
567               if ($key=="priority") {
568                 $priority = $value;
569               }
570               if ($key=="origmailbox") {
571                 $origmailbox = $value;
572               }
573               if ($key=="duration") {
574                 $duration = (int)$value;
575               }
576             }
577           }
578
579           // search filter
580           $found = 1;
581           if ($q) {
582
583             $found = 0;
584
585             if (preg_match("/" . $q . "/", $origmailbox) ||
586                   preg_match("/" . $q . "/", $callerid) ||
587                   preg_match("/" . $q . "/", $date) ||
588                   preg_match("/" . $q . "/", $time)) {
589               $found = 1;
590             }
591           }
592         }
593
594         // add to index
595         if ($found) {
596           $indexes[$file] = $$order;
597         }
598       }
599
600       if (count($indexes)) {
601         if ($sort=='desc') {
602           arsort($indexes);
603         }
604         else {
605           asort($indexes);
606         }
607       }
608     }
609
610     return $indexes;
611   }
612
613   /*
614    * Deletes selected voicemails
615    *
616    * @param $files
617    *   Array of files to delete
618    */
619   function deleteVoicemailData($files) {
620
621     global $ARI_CRYPT_PASSWORD;
622
623     $crypt = new Crypt();
624
625     foreach($files as $key => $pathCrypt) {
626
627       // decrypt path
628       $path = $crypt->decrypt($pathCrypt,$ARI_CRYPT_PASSWORD);
629
630       // get file parts for search
631       $path_parts = pathinfo($path);
632       $path = fixPathSlash($path_parts['dirname']);
633
634       list($name,$ext) = split("\.",$path_parts['basename']);
635
636       // delete all related files using a wildcard
637       if (is_dir($path)) {
638         $hdl = opendir($path);
639         while ($fn = readdir($hdl)) {
640           if (preg_match("/" . $name ."/",$fn)) {
641             $file = $path . $fn;
642             unlink($file);
643           }
644         }
645         closedir($hdl);
646       }
647     }
648   }
649
650   /*
651    * Moves selected voicemails to a specified folder
652    *
653    * @param $files
654    *   Array of files to delete
655    * @param $extension_rx
656    *   Mailbox to move message to
657    * @param $folder_rx
658    *   Folder to move the messages to
659    */
660   function moveVoicemailData($files,$context_rx,$extension_rx,$folder_rx) {
661
662     global $ASTERISK_VOICEMAIL_PATH;
663     global $ARI_CRYPT_PASSWORD;
664
665     $crypt = new Crypt();
666
667     $perm = fileperms($ASTERISK_VOICEMAIL_PATH);
668     $uid = fileowner($ASTERISK_VOICEMAIL_PATH);
669     $gid = filegroup($ASTERISK_VOICEMAIL_PATH);
670
671     // recieving path
672     $paths = split(';',$ASTERISK_VOICEMAIL_PATH);
673     $path_rx = appendPath($paths[0],$context_rx);
674     if (!is_dir($path_rx)) {
675       mkdir($path_rx, $perm);
676       chown($path_rx,intval($uid));
677       chgrp($path_rx,intval($gid));
678     }
679     $path_rx = appendPath($path_rx,$extension_rx);
680     if (!is_dir($path_rx)) {
681       mkdir($path_rx, $perm);
682       chown($path_rx,intval($uid));
683       chgrp($path_rx,intval($gid));
684     }
685     $path_rx = appendPath($path_rx,$folder_rx);
686     if (!is_dir($path_rx)) {
687       mkdir($path_rx, $perm);
688       chown($path_rx,intval($uid));
689       chgrp($path_rx,intval($gid));
690     }
691
692     // get recieving folder last message number
693     if (is_dir($path_rx)) {
694
695       $lastNum = -1;
696       $lastNumLen = 4;
697
698       $dh = opendir($path_rx);
699       while (false != ($filename = readdir($dh))) {
700         if($filename!="." && $filename!="..") {
701
702           $msg_path = $path_rx;
703           $msg_path = appendPath($msg_path,$filename);
704           if (is_file($msg_path)) {
705             $path_parts = pathinfo($msg_path);
706             $num = preg_replace("/[a-zA-Z]|\./",'', $path_parts['basename']);
707             if ($num > $lastNum) {
708               $lastNum = $num;
709               $lastNumLen = strlen($lastNum);
710             }
711           }
712         }
713       }
714     }
715     else {
716       $_SESSION['ari_error'] = sprintf(_("Could not create mailbox folder %s on the server"),$folder_rx);
717       return;
718     }
719
720     foreach($files as $key => $pathCrypt) {
721       // decrypt path
722       $pathPlain = $crypt->decrypt($pathCrypt,$ARI_CRYPT_PASSWORD);
723       // add plain path to new array
724       $filesPlain[] = $pathPlain;
725     }
726
727     // copy files to new location, incrementing each message number
728     asort($filesPlain);
729     foreach($filesPlain as $key => $path) {
730
731       // get file parts for search
732       $path_parts = pathinfo($path);
733       $path = $path_parts['dirname'];
734       $path = fixPathSlash($path);
735       list($name,$ext) = split("\.",$path_parts['basename']);
736       if (is_dir($path)) {
737
738         $lastNum++;
739         $hdl = opendir($path);
740         while ($fn = readdir($hdl)) {
741           if (preg_match("/" . $name . "/",$fn)) {
742             $src = $path . $fn;
743             $path_parts = pathinfo($src);
744             $folder_rx = preg_replace("/\d+/",sprintf("%0" . $lastNumLen . "d",$lastNum),$path_parts['basename']);
745             $dst = appendPath($path_rx,$folder_rx);
746             if (is_writable($src) && is_writable($path_rx)) {
747
748               $perm = fileperms($src);
749               $uid = fileowner($src);
750               $gid = filegroup($src);
751
752               copy($src,$dst);
753
754               if (is_writable($dst)) {
755                 chmod($dst, $perm);
756                 chown($dst,intval($uid));
757                 chgrp($dst,intval($gid));
758               }
759
760               unlink($src);
761             }
762             else {
763               $_SESSION['ari_error'] = sprintf(_("Permission denied on folder %s or %s"),$src,$path_rx);
764               return;
765             }
766           }
767         }
768         closedir($hdl);
769       }
770     }
771   }
772
773   /*
774    * Gets voicemail record count
775    *
776    * @param $indexes
777    *   array of files to be counted
778    * @return $count
779    *   number of cdr records counted
780    */
781   function getVoicemailCount($indexes) {
782
783     $count = count($indexes);
784
785     return $count;
786   }
787
788   /*
789    * Gets voicemail data
790    *
791    * @param $indexes
792    *   array of voicemail files
793    * @param $start
794    *   message number to start page with
795    * @param $span
796    *   number of messages to display on page
797    * @param $data
798    *   Reference to the variable to store the data in
799    */
800   function getVoicemailData($indexes,$start,$span) {
801
802     $data = array();
803
804     if (!isset($indexes)) {
805       return;
806     }
807
808     // populate array
809     $i = 0;
810     foreach ($indexes as $file => $index) {
811       if ($i>$start-1+$span) {
812         return $data;
813       }
814       elseif ($i>$start-1 && $i<$start+$span) {
815         $lines = file($file);
816         foreach ($lines as $key => $line) {
817           unset($value);
818           list($key,$value) = split('=',$line);
819           if ($value) {
820             $data[$file][$key] = $value;
821           }
822         }
823       }
824       $i++;
825     }
826
827     return $data;
828   }
829
830 }
831
832
833 ?>
Donate



Support
Download
Develop
Forums
News
Documentation
Paid Support
About

Paid Ads