root/freepbx/trunk/amp_conf/htdocs/recordings/modules/voicemail.module

Revision 6492, 23.1 kB (checked in by p_lindheimer, 5 years ago)

Merged revisions 6458-6459,6461-6490 via svnmerge from
http://svn.freepbx.org/freepbx/branches/2.5

........

r6462 | p_lindheimer | 2008-08-24 20:37:24 -0700 (Sun, 24 Aug 2008) | 1 line


Creating release 2.5.0rc2

........

r6474 | p_lindheimer | 2008-08-25 12:06:13 -0700 (Mon, 25 Aug 2008) | 1 line


fixes #3104 - looks like some of the code paths do extra urlencodes/decodes - this looks like it does it

........

r6477 | p_lindheimer | 2008-08-25 15:26:43 -0700 (Mon, 25 Aug 2008) | 1 line


fixes #3107 don't include module specific css/js files twice in some circumstances

........

r6478 | sasargen | 2008-08-26 05:30:34 -0700 (Tue, 26 Aug 2008) | 1 line


fixes #3104 - removes manual urlencode of checkbox values because they are form fields and are automatically urlencoded by the browser when the form is submitted

........

r6483 | p_lindheimer | 2008-08-26 12:15:04 -0700 (Tue, 26 Aug 2008) | 1 line


closes #3093 reset the execution time limit to the system configured limit before each module download and install so downloading many modules at once does not result in a timeout failure, this still counts on a reasonable php.ini setting for any given installation of which the default is typically adeqaute

........

r6484 | p_lindheimer | 2008-08-26 19:06:13 -0700 (Tue, 26 Aug 2008) | 1 line


closes #3113 and ref #3090 - puts error in notification panel if magic_quotes_gpc is enabled

........

r6486 | p_lindheimer | 2008-08-27 11:40:19 -0700 (Wed, 27 Aug 2008) | 1 line


improve the symlink failure message to provide feedback on what can be done to resolve the issue

........

r6490 | p_lindheimer | 2008-08-27 22:29:03 -0700 (Wed, 27 Aug 2008) | 1 line


updated CHANGES

........

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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, false);
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         if ($forwardContext!=$_SESSION['ari_user']['context']) {
285           continue;
286         }
287
288         // get username and add to options
289         if (preg_match("/\=\>/i",$line)) {
290           list($username,$value) = split('=>',$line);
291           $username = trim($username);
292           if ($username!=$_SESSION['ari_user']['extension']) {
293             //$ext_array[] = $username . "|" . $forwardContext;
294             list(,$real_name,) = split(",",$value,3);
295             $ext_array[] = $real_name . "|" . $username . "|" . $forwardContext;
296           }
297         }
298       } //foreach
299       //sort the array
300       sort($ext_array);
301
302       //get the size of the array
303       $array_size = count($ext_array) - 1;
304
305       //loop through the array and build the drop down list
306       foreach ($ext_array as $item)
307       {
308          //split the values apart
309          list($real_name,$username,$context) = explode("|",$item);
310
311          //add it to the drop down
312          $forward_options .= "<option VALUE='" . $context . "/" . $username . "'>" . substr($real_name,0,15) . " <" . $username . ">";
313       }
314     }
315     else {
316       $_SESSION['ari_error'] = "File not readable: " . $ASTERISK_VOICEMAIL_CONF;
317       return;
318     }
319
320     // table controls
321     $controls = "
322           <button class='infobar' type='submit' onclick=\"document.voicemail_form.a.value='delete'\">
323           " . _("delete") . "
324           </button>
325           <button class='infobar' type='submit' onclick=\"document.voicemail_form.a.value='move_to'\">
326           " . _("move_to") . "
327           </button>
328           <select name='folder_rx' style='width:124px;'>
329             <option VALUE=''>" . _("Folder") . "
330             " . $move_options . "
331           </select>
332           <button class='infobar' type='submit' onclick=\"document.voicemail_form.a.value='forward_to'\">
333           " . _("forward_to") . "
334           </button>
335           <select name='mailbox_rx'>
336             <option VALUE=''>
337             " . $forward_options . "
338           </select>";
339
340     // table header
341     $recording_delete_header = "<th></th>";
342
343     $fields[0]['field'] = "calldate";
344     $fields[0]['text'] = _("Date");
345     $fields[1]['field'] = "calldate";
346     $fields[1]['text'] = _("Time");
347     $fields[2]['field'] = "clid";
348     $fields[2]['text'] = _("Caller ID");
349     $fields[3]['field'] = "priority";
350     $fields[3]['text'] = _("Priority");
351     $fields[4]['field'] = "origmailbox";
352     $fields[4]['text'] = _("Orig Mailbox");
353     $fields[5]['field'] = "duration";
354     $fields[5]['text'] = _("Duration");
355     $i = 0;
356     while ($fields[$i]) {
357
358       $field = $fields[$i]['field'];
359       $text = $fields[$i]['text'];
360       if ($order==$field) {
361         if ($sort=='asc') {
362           $currentSort = 'desc';
363           $arrowImg = "<img src='theme/images/arrow-asc.gif' alt='sort'>";
364         }
365         else {
366           $currentSort = 'asc';
367           $arrowImg = "<img src='theme/images/arrow-desc.gif' alt='sort'>";
368         }   
369
370         if ($i==1) {
371           $arrowImg = '';
372         }   
373       }
374       else {
375         $arrowImg = '';
376         $currentSort = 'desc';
377       }
378
379       $unicode_q = urlencode($q);
380       $recording_header .= "<th><a href=" .  $_SESSION['ARI_ROOT'] . "?m=" . $m . "&f=" . $f . "&q=" . $unicode_q . "&order=" . $field . "&sort=" . $currentSort . ">" . $text . $arrowImg . "</a></th>";
381
382       $i++;
383     }
384     $recording_header .= "<th>" . _("Message") . "</th>";
385
386     // table body
387     if (isset($data)) {
388       foreach($data as $file=>$value) {
389
390         // recording popup link
391         $voicemail_audio_format = $voicemail_audio_format=='' ? '.wav' : $voicemail_audio_format;
392         $recording = preg_replace('/.txt/', $voicemail_audio_format, $file);
393         $date = GetDateFormat($value['origtime']);
394         $time = GetTimeFormat($value['origtime']);
395         $from = $value[callerid];
396         $priority = $value[priority];
397         $to = $value[origmailbox];
398         $duration = $value[duration];
399         if (is_file($recording)) {
400           $recordingCrypt = urlencode($crypt->encrypt($recording,$ARI_CRYPT_PASSWORD));
401     $recordingLink = "<a href='#' onClick=\"javascript:popUp('misc/recording_popup.php?recording=" . $recordingCrypt . "&date=" . $date . "&time=" . $time . "'); return false;\">
402             " . _("play") . "
403           </a>";
404         }
405         else {
406           $_SESSION['ari_error'] = _("Voicemail recording(s) was not found.") . "<br>" .
407                                    sprintf(_("On settings page, change voicemail audio format.  It is currently set to %s"),$voicemail_audio_format);
408         }
409
410         $fileCrypt = $crypt->encrypt($file,$ARI_CRYPT_PASSWORD);
411
412         $tableText .= "
413           <tr>
414             <td class='checkbox'><input type=checkbox name='selected" . ++$i . "' value=" . $fileCrypt . "></td>
415             <td width=68>" . $date . "</td>
416             <td>" . $time . "</td>
417             <td width=100>" . $from . "</td>
418             <td>" . $value[priority] . "</td>
419             <td width=90>" . $to . "</td>
420             <td>" . $duration . " sec</td>
421             <td>" . $recordingLink . "</td>
422           </tr>";
423       }
424     }
425
426     // options
427     $url_opts = array();
428     $url_opts['folder'] = $folder;
429     $url_opts['sort'] = $sort;
430     $url_opts['order'] = $order;
431
432     $error = 0;
433
434     // check for voicemail enabled
435     if ($_SESSION['ari_user']['voicemail_enabled']!=1) {
436       $_SESSION['ari_error'] = _("Voicemail Login not found.") . "<br>" .
437                                _("No access to voicemail");
438       $error = 1;
439     }
440
441     // check admin
442     if ($extension=='admin') {
443       $_SESSION['ari_error'] = _("No Voicemail Recordings for Admin");
444       $error = 1;
445     }
446
447     // build page content
448     $ret .= checkErrorMessage();
449     if ($error) {
450       return $ret;
451     }
452
453     // ajax page refresh script
454     if ($AJAX_PAGE_REFRESH_ENABLE) {
455 //      $ret .= ajaxRefreshScript($args);
456     }
457
458     // header
459     $ret .= $display->displayHeaderText(sprintf(_("Voicemail for %s (%s)"),$displayname,$extension));
460     $ret .= $display->displaySearchBlock('left',$m,$q,$url_opts,true);
461
462     // start form
463     $ret .= "
464       <form name='voicemail_form' action='" . $_SESSION['ARI_ROOT'] . "' method='GET'>
465         <input type=hidden name=m value=" . $m . ">
466         <input type=hidden name=f value=msgAction>
467         <input type=hidden name=a value=''>
468         <input type=hidden name=q value=" . $q . ">
469         <input type=hidden name=folder value=" . $folder . ">
470         <input type=hidden name=start value=" . $start . ">
471         <input type=hidden name=span value=" . $span . ">
472         <input type=hidden name=order value=" . $order . ">
473         <input type=hidden name=sort value=" . $sort . ">";
474
475     $ret .= $display->displayInfoBarBlock($controls,$q,$start,$span,$record_count);
476
477     // add javascript for popup and message actions
478     $ret .= "
479       <SCRIPT LANGUAGE='JavaScript'>
480       <!-- Begin
481       function popUp(URL) {
482         popup = window.open(URL, 'play', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=324,height=110');
483       }
484
485       function checkAll(form,set) {
486         var elem = 0;
487         var i = 0;
488         while (elem = form.elements[i]) {
489           if (set) {
490             elem.checked = true;
491           } else {
492             elem.checked = false;
493           }
494           i++;
495         }
496         return true;
497       }
498       // End -->
499       </script>";
500
501     // voicemail delete recording controls
502     $ret .= "
503       <table>
504         <tr>
505           <td>
506             <small>" . _("select") . ": </small>
507             <small><a href='' OnClick=\"checkAll(document.voicemail_form,true); return false;\">" . _("all") . "</a></small>
508             <small><a href='' OnClick=\"checkAll(document.voicemail_form,false); return false;\">" . _("none") . "</a></small>
509           </td>
510         </tr>
511       </table>";
512
513     // table
514     $ret .= "
515       <table class='voicemail'>
516         <tr>
517            " . $recording_delete_header . "
518            " . $recording_header . "
519         </tr>
520         " . $tableText . "
521       </table>";
522
523     // end form
524     $ret .= "</form>";
525
526     $ret .= $display->displaySearchBlock('center',$m,$q,$url_opts,false);
527     $ret .= $display->displayNavigationBlock($m,$q,$url_opts,$start,$span,$record_count);
528
529     return $ret;
530   }
531
532   /*
533    * Gets voicemail data
534    *
535    * @param $data
536    *   Reference to the variable to store the data in
537    * @param $q
538    *   search string
539    */
540   function getVoicemailIndex($path,$q,$order,$sort) {
541
542     $indexes = array();
543
544     $filter = '.txt';
545     $recursiveMax = 0;
546     $recursiveCount = 0;
547     $files = getFiles($path,$filter,$recursiveMax,$recursiveCount);
548
549     if (isset($files)) {
550
551       // ugly, but sorts array by time stamp
552       foreach ($files as $file) {
553
554         if (is_file($file)) {
555
556           $lines = file($file);
557           foreach ($lines as $key => $line) {
558             unset($value);
559             list($key,$value) = split('=',$line);
560             if ($value) {
561
562               if ($key=="origtime") {
563                 $calldate = $value;
564                 $date = GetDateFormat($value);
565                 $time = GetTimeFormat($value);
566               }
567               if ($key=="callerid") {
568                 $callerid = $value;
569               }
570               if ($key=="priority") {
571                 $priority = $value;
572               }
573               if ($key=="origmailbox") {
574                 $origmailbox = $value;
575               }
576               if ($key=="duration") {
577                 $duration = (int)$value;
578               }
579             }
580           }
581
582           // search filter
583           $found = 1;
584           if ($q) {
585
586             $found = 0;
587
588             if (preg_match("/" . $q . "/", $origmailbox) ||
589                   preg_match("/" . $q . "/", $callerid) ||
590                   preg_match("/" . $q . "/", $date) ||
591                   preg_match("/" . $q . "/", $time)) {
592               $found = 1;
593             }
594           }
595         }
596
597         // add to index
598         if ($found) {
599           $indexes[$file] = $$order;
600         }
601       }
602
603       if (count($indexes)) {
604         if ($sort=='desc') {
605           arsort($indexes);
606         }
607         else {
608           asort($indexes);
609         }
610       }
611     }
612
613     return $indexes;
614   }
615
616   /*
617    * Deletes selected voicemails
618    *
619    * @param $files
620    *   Array of files to delete
621    */
622   function deleteVoicemailData($files) {
623
624     global $ARI_CRYPT_PASSWORD;
625
626     $crypt = new Crypt();
627
628     foreach($files as $key => $pathCrypt) {
629
630       // decrypt path
631       $path = $crypt->decrypt($pathCrypt,$ARI_CRYPT_PASSWORD);
632
633       // get file parts for search
634       $path_parts = pathinfo($path);
635       $path = fixPathSlash($path_parts['dirname']);
636
637       list($name,$ext) = split("\.",$path_parts['basename']);
638
639       // delete all related files using a wildcard
640       if (is_dir($path)) {
641         $hdl = opendir($path);
642         while ($fn = readdir($hdl)) {
643           if (preg_match("/" . $name ."/",$fn)) {
644             $file = $path . $fn;
645             unlink($file);
646           }
647         }
648         closedir($hdl);
649       }
650     }
651   }
652
653   /*
654    * Moves selected voicemails to a specified folder
655    *
656    * @param $files
657    *   Array of files to delete
658    * @param $extension_rx
659    *   Mailbox to move message to
660    * @param $folder_rx
661    *   Folder to move the messages to
662    * @param $delete_moved
663    *   If original should be deleted, default true (otherwise it is a copy)
664    */
665   function moveVoicemailData($files,$context_rx,$extension_rx,$folder_rx,$delete_moved=true) {
666
667     global $ASTERISK_VOICEMAIL_PATH;
668     global $ARI_CRYPT_PASSWORD;
669
670     $crypt = new Crypt();
671
672     $perm = fileperms($ASTERISK_VOICEMAIL_PATH);
673     $uid = fileowner($ASTERISK_VOICEMAIL_PATH);
674     $gid = filegroup($ASTERISK_VOICEMAIL_PATH);
675
676     // recieving path
677     $paths = split(';',$ASTERISK_VOICEMAIL_PATH);
678     $path_rx = appendPath($paths[0],$context_rx);
679     if (!is_dir($path_rx)) {
680       mkdir($path_rx, $perm);
681       chown($path_rx,intval($uid));
682       chgrp($path_rx,intval($gid));
683     }
684     $path_rx = appendPath($path_rx,$extension_rx);
685     if (!is_dir($path_rx)) {
686       mkdir($path_rx, $perm);
687       chown($path_rx,intval($uid));
688       chgrp($path_rx,intval($gid));
689     }
690     $path_rx = appendPath($path_rx,$folder_rx);
691     if (!is_dir($path_rx)) {
692       mkdir($path_rx, $perm);
693       chown($path_rx,intval($uid));
694       chgrp($path_rx,intval($gid));
695     }
696
697     // get recieving folder last message number
698     if (is_dir($path_rx)) {
699
700       $lastNum = -1;
701       $lastNumLen = 4;
702
703       $dh = opendir($path_rx);
704       while (false != ($filename = readdir($dh))) {
705         if($filename!="." && $filename!="..") {
706
707           $msg_path = $path_rx;
708           $msg_path = appendPath($msg_path,$filename);
709           if (is_file($msg_path)) {
710             $path_parts = pathinfo($msg_path);
711             $num = preg_replace("/[a-zA-Z]|\./",'', $path_parts['basename']);
712             if ($num > $lastNum) {
713               $lastNum = $num;
714               $lastNumLen = strlen($lastNum);
715             }
716           }
717         }
718       }
719     }
720     else {
721       $_SESSION['ari_error'] = sprintf(_("Could not create mailbox folder %s on the server"),$folder_rx);
722       return;
723     }
724
725     foreach($files as $key => $pathCrypt) {
726       // decrypt path
727       $pathPlain = $crypt->decrypt($pathCrypt,$ARI_CRYPT_PASSWORD);
728       // add plain path to new array
729       $filesPlain[] = $pathPlain;
730     }
731
732     // copy files to new location, incrementing each message number
733     asort($filesPlain);
734     foreach($filesPlain as $key => $path) {
735
736       // get file parts for search
737       $path_parts = pathinfo($path);
738       $path = $path_parts['dirname'];
739       $path = fixPathSlash($path);
740       list($name,$ext) = split("\.",$path_parts['basename']);
741       if (is_dir($path)) {
742
743         $lastNum++;
744         $hdl = opendir($path);
745         while ($fn = readdir($hdl)) {
746           if (preg_match("/" . $name . "/",$fn)) {
747             $src = $path . $fn;
748             $path_parts = pathinfo($src);
749             $folder_rx = preg_replace("/\d+/",sprintf("%0" . $lastNumLen . "d",$lastNum),$path_parts['basename']);
750             $dst = appendPath($path_rx,$folder_rx);
751             if (is_writable($src) && is_writable($path_rx)) {
752
753               $perm = fileperms($src);
754               $uid = fileowner($src);
755               $gid = filegroup($src);
756
757               copy($src,$dst);
758
759               if (is_writable($dst)) {
760                 chmod($dst, $perm);
761                 chown($dst,intval($uid));
762                 chgrp($dst,intval($gid));
763               }
764
765               if ($delete_moved) {
766                 unlink($src);
767               }
768             }
769             else {
770               $_SESSION['ari_error'] = sprintf(_("Permission denied on folder %s or %s"),$src,$path_rx);
771               return;
772             }
773           }
774         }
775         closedir($hdl);
776       }
777     }
778   }
779
780   /*
781    * Gets voicemail record count
782    *
783    * @param $indexes
784    *   array of files to be counted
785    * @return $count
786    *   number of cdr records counted
787    */
788   function getVoicemailCount($indexes) {
789
790     $count = count($indexes);
791
792     return $count;
793   }
794
795   /*
796    * Gets voicemail data
797    *
798    * @param $indexes
799    *   array of voicemail files
800    * @param $start
801    *   message number to start page with
802    * @param $span
803    *   number of messages to display on page
804    * @param $data
805    *   Reference to the variable to store the data in
806    */
807   function getVoicemailData($indexes,$start,$span) {
808
809     $data = array();
810
811     if (!isset($indexes)) {
812       return;
813     }
814
815     // populate array
816     $i = 0;
817     foreach ($indexes as $file => $index) {
818       if ($i>$start-1+$span) {
819         return $data;
820       }
821       elseif ($i>$start-1 && $i<$start+$span) {
822         $lines = file($file);
823         foreach ($lines as $key => $line) {
824           unset($value);
825           list($key,$value) = split('=',$line);
826           if ($value) {
827             $data[$file][$key] = $value;
828           }
829         }
830       }
831       $i++;
832     }
833
834     return $data;
835   }
836
837 }
838
839
840 ?>
Note: See TracBrowser for help on using the browser.