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