root/modules/branches/2.3/findmefollow/page.findmefollow.php

Revision 4909, 18.0 kB (checked in by p_lindheimer, 5 years ago)

#2193 moh path hardcoded

  • Property svn:mime-type set to text/html
  • Property svn:eol-style set to native
Line 
1 <?php /* $Id: page.findmefollow.php 1197 2006-03-19 17:59:02Z mheydon1973 $ */
2 //Copyright (C) 2006 Philippe Lindheimer (p_lindheimer at yahoo dot com)
3 //
4 //This program is free software; you can redistribute it and/or
5 //modify it under the terms of the GNU General Public License
6 //as published by the Free Software Foundation; either version 2
7 //of the License, or (at your option) any later version.
8 //
9 //This program is distributed in the hope that it will be useful,
10 //but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //GNU General Public License for more details.
13
14 $dispnum = 'findmefollow'; //used for switch on config.php
15
16 isset($_REQUEST['action'])?$action = $_REQUEST['action']:$action='';
17 //the extension we are currently displaying
18 isset($_REQUEST['extdisplay'])?$extdisplay=$_REQUEST['extdisplay']:$extdisplay='';
19 isset($_REQUEST['account'])?$account = $_REQUEST['account']:$account='';
20 isset($_REQUEST['grptime'])?$grptime = $_REQUEST['grptime']:$grptime='';
21 isset($_REQUEST['grppre'])?$grppre = $_REQUEST['grppre']:$grppre='';
22 isset($_REQUEST['strategy'])?$strategy = $_REQUEST['strategy']:$strategy='';
23 isset($_REQUEST['annmsg'])?$annmsg = $_REQUEST['annmsg']:$annmsg='';
24 isset($_REQUEST['dring'])?$dring = $_REQUEST['dring']:$dring='';
25 isset($_REQUEST['needsconf'])?$needsconf = $_REQUEST['needsconf']:$needsconf='';
26 isset($_REQUEST['remotealert'])?$remotealert = $_REQUEST['remotealert']:$remotealert='';
27 isset($_REQUEST['toolate'])?$toolate = $_REQUEST['toolate']:$toolate='';
28 isset($_REQUEST['ringing'])?$ringing = $_REQUEST['ringing']:$ringing='';
29 isset($_REQUEST['pre_ring'])?$pre_ring = $_REQUEST['pre_ring']:$pre_ring='0';
30 isset($_REQUEST['ddial'])?$ddial = $_REQUEST['ddial']:$ddial='';
31
32
33 if (isset($_REQUEST['goto0']) && isset($_REQUEST[$_REQUEST['goto0']."0"])) {
34         $goto = $_REQUEST[$_REQUEST['goto0']."0"];
35 } else {
36         $goto = '';
37 }
38
39
40 if (isset($_REQUEST["grplist"])) {
41   $grplist = explode("\n",$_REQUEST["grplist"]);
42
43   if (!$grplist) {
44     $grplist = null;
45   }
46  
47   foreach (array_keys($grplist) as $key) {
48     //trim it
49     $grplist[$key] = trim($grplist[$key]);
50     
51     // remove invalid chars
52     $grplist[$key] = preg_replace("/[^0-9#*]/", "", $grplist[$key]);
53
54     if ($grplist[$key] == ltrim($extdisplay,'GRP-').'#')
55       $grplist[$key] = rtrim($grplist[$key],'#');
56     
57     // remove blanks
58     if ($grplist[$key] == "") unset($grplist[$key]);
59   }
60  
61   // check for duplicates, and re-sequence
62   $grplist = array_values(array_unique($grplist));
63 }
64
65 // do if we are submitting a form
66 if(isset($_POST['action'])){
67   //check if the extension is within range for this user
68   if (isset($account) && !checkRange($account)){
69     echo "<script>javascript:alert('". _("Warning! Extension")." ".$account." "._("is not allowed for your account").".');</script>";
70   } else {
71     //add group
72     if ($action == 'addGRP') {
73       findmefollow_add($account,$strategy,$grptime,implode("-",$grplist),$goto,$grppre,$annmsg,$dring,$needsconf,$remotealert,$toolate,$ringing,$pre_ring,$ddial);
74
75       needreload();
76       redirect_standard();
77     }
78     
79     //del group
80     if ($action == 'delGRP') {
81       findmefollow_del($account);
82       needreload();
83       redirect_standard();
84     }
85     
86     //edit group - just delete and then re-add the extension
87     if ($action == 'edtGRP') {
88       findmefollow_del($account);
89       findmefollow_add($account,$strategy,$grptime,implode("-",$grplist),$goto,$grppre,$annmsg,$dring,$needsconf,$remotealert,$toolate,$ringing,$pre_ring,$ddial);
90
91       needreload();
92       redirect_standard('extdisplay');
93     }
94   }
95 }
96 ?>
97 </div>
98
99 <div class="rnav"><ul>
100 <?php
101 //get unique ring groups
102 $gresults = findmefollow_allusers();
103 $set_users = findmefollow_list();
104
105 if (isset($gresults)) {
106   foreach ($gresults as $gresult) {
107     $defined = is_array($set_users) ? (in_array($gresult[0], $set_users) ? "(edit)" : "(add)") : "add";
108                 echo "<li><a id=\"".($extdisplay=='GRP-'.$gresult[0] ? 'current':'')."\" href=\"config.php?display=".urlencode($dispnum)."&extdisplay=".urlencode("GRP-".$gresult[0])."\">"._("$gresult[1]")." <{$gresult[0]}> $defined  </a></li>";
109
110   }
111 }
112 ?>
113 </ul></div>
114
115 <div class="content">
116 <?php
117
118 if (!$extdisplay) {
119   echo '<br><h2>'._("Follow Me").'</h2><br><h3>'._('Choose a user/extension:').'</h3><br><br><br><br><br><br><br>';
120   }
121 elseif ($action == 'delGRP') {
122   echo '<br><h3>'._("Follow Me").' '.$account.' '._("deleted").'!</h3><br><br><br><br><br><br><br><br>';
123 } else {
124   if ($extdisplay) {
125     // We need to populate grplist with the existing extension list.
126     $thisgrp = findmefollow_get(ltrim($extdisplay,'GRP-'), 1);
127     $grpliststr = isset($thisgrp['grplist']) ? $thisgrp['grplist'] : '';
128     $grplist = explode("-", $grpliststr);
129
130     $strategy    = isset($thisgrp['strategy'])    ? $thisgrp['strategy']    : '';
131     $grppre      = isset($thisgrp['grppre'])      ? $thisgrp['grppre']      : '';
132     $grptime     = isset($thisgrp['grptime'])     ? $thisgrp['grptime']     : '';
133     $goto        = isset($thisgrp['postdest'])    ? $thisgrp['postdest']    : '';
134     $annmsg      = isset($thisgrp['annmsg'])      ? $thisgrp['annmsg']      : '';
135     $dring       = isset($thisgrp['dring'])       ? $thisgrp['dring']       : '';
136     $remotealert = isset($thisgrp['remotealert']) ? $thisgrp['remotealert'] : '';
137     $needsconf   = isset($thisgrp['needsconf'])   ? $thisgrp['needsconf']   : '';
138     $toolate     = isset($thisgrp['toolate'])     ? $thisgrp['toolate']     : '';
139     $ringing     = isset($thisgrp['ringing'])     ? $thisgrp['ringing']     : '';
140     $pre_ring    = isset($thisgrp['pre_ring'])    ? $thisgrp['pre_ring']    : '';
141     $ddial       = isset($thisgrp['ddial'])       ? $thisgrp['ddial']       : '';
142     unset($grpliststr);
143     unset($thisgrp);
144     
145     $delButton = "
146       <form name=delete action=\"{$_SERVER['PHP_SELF']}\" method=POST>
147         <input type=\"hidden\" name=\"display\" value=\"{$dispnum}\">
148         <input type=\"hidden\" name=\"account\" value=\"".ltrim($extdisplay,'GRP-')."\">
149         <input type=\"hidden\" name=\"action\" value=\"delGRP\">
150         <input type=submit value=\""._("Delete Entries")."\">
151       </form>";
152       
153     echo "<h2>"._("Follow Me").": ".ltrim($extdisplay,'GRP-')."</h2>";
154
155
156     // Copied straight out of old code,let's see if it works?
157     //
158     if (isset($amp_conf["AMPEXTENSIONS"]) && ($amp_conf["AMPEXTENSIONS"] == "deviceanduser")) {
159       $editURL = $_SERVER['PHP_SELF'].'?display=users&extdisplay='.ltrim($extdisplay,'GRP-');
160       $EXTorUSER = "User";
161     }
162     else {
163       $editURL = $_SERVER['PHP_SELF'].'?display=extensions&extdisplay='.ltrim($extdisplay,'GRP-');
164       $EXTorUSER = "Extension";
165     }
166
167     echo "<p><a href=".$editURL."> Edit ".$EXTorUSER." ".ltrim($extdisplay,'GRP-')."</a></p>";
168     echo "<p>".$delButton."</p>";
169   }
170   ?>
171       <form name="editGRP" action="<?php  $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return checkGRP(editGRP);">
172       <input type="hidden" name="display" value="<?php echo $dispnum?>">
173       <input type="hidden" name="action" value="<?php echo ($extdisplay ? 'edtGRP' : 'addGRP'); ?>">
174       <table>
175       <tr><td colspan="2"><h5><?php  echo ($extdisplay ? _("Edit Follow Me") : _("Add Follow Me")) ?><hr></h5></td></tr>
176       <tr>
177 <?php
178   if ($extdisplay) {
179
180 ?>
181         <input size="5" type="hidden" name="account" value="<?php  echo ltrim($extdisplay,'GRP-'); ?>">
182 <?php     } else { ?>
183         <td><a href="#" class="info"><?php echo _("group number")?>:<span><?php echo _("The number users will dial to ring extensions in this ring group")?></span></a></td>
184         <td><input size="5" type="text" name="account" value="<?php  echo $gresult[0] + 1; ?>"></td>
185 <?php     } ?>
186       </tr>
187
188       <tr>
189         <td><a href="#" class="info"><?php echo _("Disable as Default")?><span><?php echo _('By default (not checked) any call to this extension will go to this FollowMe instead, including directory calls by name from IVRs. If checked, calls will go only to the extension.<BR>However, destinations that specify FollowMe will come here.<BR>Checking this box is often used in conjunction with VmX Locater, where you want a call to ring the extension, and then only if the caller chooses to find you do you want it to come here.')?></span></a>:</td>
190         <td><input type="checkbox" name="ddial" value="CHECKED" <?php echo $ddial ?>  /></td>
191       </tr>
192
193       <tr>
194         <td><a href="#" class="info"><?php echo _("Initial Ring Time:")?>
195         <span><?php echo _("This is the number of seconds to ring the primary extension prior to proceeding to the follow-me list. The extension can also be included in the follow-me list. A 0 setting will bypass this.")?>
196         </span></a>
197         </td>
198         <td>
199           &nbsp;
200           <select name="pre_ring"/>
201           <?php
202             $default = (isset($pre_ring) ? $pre_ring : 0);
203             for ($i=0; $i <= 60; $i++) {
204               echo '<option value="'.$i.'" '.($i == $default ? 'SELECTED' : '').'>'.$i.'</option>';
205             }
206           ?>
207           </select>
208         </td>
209       </tr>
210
211
212       <tr>
213         <td> <a href="#" class="info"><?php echo _("Ring Strategy:")?>
214         <span>
215           <b><?php echo _("ringallv2")?></b><?php echo _("ring primary extension for initial ring time followed by all additional extensions until one answers")?><br>
216           <b><?php echo _("ringall")?></b><?php echo _("ring all available channels until one answers (default)")?><br>
217           <b><?php echo _("hunt")?></b>: <?php echo _("take turns ringing each available extension")?><br>
218           <b><?php echo _("memoryhunt")?></b>: <?php echo _("ring first extension in the list, then ring the 1st and 2nd extension, then ring 1st 2nd and 3rd extension in the list.... etc.")?><br>
219           <b><?php echo _("*-prim")?></b><?php echo _("these modes act as described above. However, if the primary extension (first in list) is occupied, the other extensions will not be rung. If the primary is freepbx DND, it won't be run. If the primary is freepbx CF unconditional, then all will be rung")?><br>
220           <b><?php echo _("firstavailable")?></b><?php echo _("ring only the first available channel")?><br>
221           <b><?php echo _("firstnotonphone")?></b><?php echo _("ring only the first channel which is not offhook - ignore CW")?><br>
222         </span>
223         </a></td>
224         <td>
225           &nbsp;&nbsp;<select name="strategy"/>
226           <?php
227             $default = (isset($strategy) ? $strategy : 'ringall');
228                                                 $items = array('ringallv2','ringallv2-prim','ringall','ringall-prim','hunt','hunt-prim','memoryhunt','memoryhunt-prim','firstavailable','firstnotonphone');
229             foreach ($items as $item) {
230               echo '<option value="'.$item.'" '.($default == $item ? 'SELECTED' : '').'>'._($item);
231             }
232           ?>   
233           </select>
234         </td>
235       </tr>
236       <tr>
237         <td><a href="#" class="info"><?php echo _("Alert Info")?>:<span><?php echo _('You can optionally include an Alert Info which can create distinctive rings on SIP phones.')?></span></a></td>
238         <td><input size="18" type="text" name="dring" value="<?php  echo $dring ?>"></td>
239       </tr>
240   <tr>
241     <td><a href="#" class="info"><?php echo _("Confirm Calls")?><span><?php echo _('Enable this if you\'re calling external numbers that need confirmation - eg, a mobile phone may go to voicemail which will pick up the call. Enabling this requires the remote side push 1 on their phone before the call is put through. This feature only works with the ringall/ringall-prim  ring strategy')?></span></a>:</td>
242     <td> <?php if (!function_exists('recordings_list')) { echo _("System Recordings not installed. Option Disabled"); } else { ?>
243       <input type="checkbox" name="needsconf" value="CHECKED" <?php echo $needsconf ?>  /></td>
244 <?php } ?>
245   </tr>
246 <?php if(function_exists('recordings_list')) { //only include if recordings is enabled?>
247   <tr>
248     <td><a href="#" class="info"><?php echo _("Remote Announce:")?><span><?php echo _("Message to be played to the person RECEIVING the call, if 'Confirm Calls' is enabled.<br><br>To add additional recordings use the \"System Recordings\" MENU to the left")?></span></a></td>
249     <td>
250       &nbsp;&nbsp;<select name="remotealert"/>
251       <?php
252         $tresults = recordings_list();
253         $default = (isset($remotealert) ? $remotealert : '');
254         echo '<option value="">'._("Default")."</option>";
255         if (isset($tresults[0])) {
256           foreach ($tresults as $tresult) {
257             echo '<option value="'.$tresult[2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n";
258           }
259         }
260       ?>
261       </select>
262     </td>
263   </tr>
264   <tr>
265     <td><a href="#" class="info"><?php echo _("Too-Late Announce:")?><span><?php echo _("Message to be played to the person RECEIVING the call, if the call has already been accepted before they push 1.<br><br>To add additional recordings use the \"System Recordings\" MENU to the left")?></span></a></td>
266     <td>
267     &nbsp;&nbsp;<select name="toolate"/>
268       <?php
269         $tresults = recordings_list();
270         $default = (isset($toolate) ? $toolate : '');
271         echo '<option value="">'._("Default")."</option>";
272         if (isset($tresults[0])) {
273           foreach ($tresults as $tresult) {
274             echo '<option value="'.$tresult[2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n";
275           }
276         }
277       ?>
278       </select>
279     </td>
280   </tr>
281 <?php } ?>
282       <tr>
283         <td valign="top"><a href="#" class="info"><?php echo _("Follow-Me List")?>:<span><br><?php echo _("List extensions to ring, one per line.<br><br>You can include an extension on a remote system, or an external number by suffixing a number with a pound (#).  ex:  2448089# would dial 2448089 on the appropriate trunk (see Outbound Routing).")?><br><br></span></a></td>
284         <td valign="top">&nbsp;
285 <?php
286     $rows = count($grplist)+1;
287     if ($rows <= 2 && trim($grplist[0]) == "") {
288       $grplist[0] = ltrim($extdisplay,'GRP-');
289     }
290     ($rows < 5) ? 5 : (($rows > 20) ? 20 : $rows);
291 ?>
292           <textarea id="grplist" cols="15" rows="<?php  echo $rows ?>" name="grplist"><?php echo implode("\n",$grplist);?></textarea><br>
293          
294           <input type="submit" style="font-size:10px;" value="<?php echo _("Clean & Remove duplicates")?>" />
295         </td>
296       </tr>
297       <tr>
298         <td><a href="#" class="info"><?php echo _("CID Name Prefix")?>:<span><?php echo _('You can optionally prefix the Caller ID name when ringing extensions in this group. ie: If you prefix with "Sales:", a call from John Doe would display as "Sales:John Doe" on the extensions that ring.')?></span></a></td>
299         <td><input size="4" type="text" name="grppre" value="<?php  echo $grppre ?>"></td>
300       </tr>
301
302
303       <tr>
304         <td><?php echo _("Ring Time (max 60 sec)")?>:</td>
305         <td><input size="4" type="text" name="grptime" value="<?php  echo $grptime?$grptime:20 ?>"></td>
306       </tr>
307 <?php if(function_exists('recordings_list')) { //only include if recordings is enabled?>
308   <tr>
309     <td><a href="#" class="info"><?php echo _("Announcement:")?><span><?php echo _("Message to be played to the caller before dialing this group.<br><br>To add additional recordings please use the \"System Recordings\" MENU to the left")?></span></a></td>
310     <td>
311       &nbsp;&nbsp;<select name="annmsg"/>
312       <?php
313         $tresults = recordings_list();
314         $default = (isset($annmsg) ? $annmsg : '');
315         echo '<option value="">'._("None");
316         if (isset($tresults)) {
317           foreach ($tresults as $tresult) {
318             echo '<option value="'.$tresult[2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1];
319           }
320         }
321       ?>   
322       </select>   
323     </td>
324   </tr>
325 <?php } else { ?>
326   <tr>
327     <td><a href="#" class="info"><?php echo _("Announcement:")?><span><?php echo _("Message to be played to the caller before dialing this group.<br><br>You must install and enable the \"Systems Recordings\" Module to edit this option")?></span></a></td>
328     <td>
329       <?php
330         $default = (isset($annmsg) ? $annmsg : '');
331       ?>
332       <input type="hidden" name="annmsg" value="<?php echo $default; ?>"><?php echo ($default != '' ? $default : 'None'); ?>
333     </td>
334   </tr>
335 <?php } if (function_exists('music_list')) { ?>
336   <tr>
337     <td><a href="#" class="info"><?php echo _("Play Music On Hold?")?><span><?php echo _("If you select a Music on Hold class to play, instead of 'Ring', they will hear that instead of Ringing while they are waiting for someone to pick up.")?></span></a></td>
338     <td>
339       &nbsp;&nbsp;<select name="ringing"/>
340       <?php
341         $tresults = music_list($amp_conf['ASTVARLIBDIR']."/mohmp3");
342         $cur = (isset($ringing) ? $ringing : 'Ring');
343         echo '<option value="Ring">'._("Ring")."</option>";
344         if (isset($tresults[0])) {
345           foreach ($tresults as $tresult) {
346             echo '<option value="'.$tresult.'"'.($tresult == $cur ? ' SELECTED' : '').'>'.$tresult."</option>\n";
347           }
348         }
349       ?>
350       </select>
351       </td>
352     </tr>
353 <?php } ?>
354      
355       <tr><td colspan="2"><br><h5><?php echo _("Destination if no answer")?>:<hr></h5></td></tr>
356
357 <?php
358 //draw goto selects
359 echo drawselects($goto,0);
360 ?>
361      
362       <tr>
363       <td colspan="2"><br><h6><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>"></h6></td>   
364      
365       </tr>
366       </table>
367       </form>
368 <?php     
369     } //end if action == delGRP
370     
371 ?>
372 <script language="javascript">
373 <!--
374
375 function checkGRP(theForm) {
376   var msgInvalidGrpNum = "<?php echo _('Invalid Group Number specified'); ?>";
377   var msgInvalidExtList = "<?php echo _('Please enter an extension list.'); ?>";
378   var msgInvalidGrpPrefix = "<?php echo _('Invalid prefix. Valid characters: a-z A-Z 0-9 : _ -'); ?>";
379   var msgInvalidTime = "<?php echo _('Invalid time specified'); ?>";
380   var msgInvalidGrpTimeRange = "<?php echo _('Time must be between 1 and 60 seconds'); ?>";
381   var msgInvalidRingStrategy = "<?php echo _('You must choose ringall, ringall-prim, ringallv2 or ringallv2-prim ring strategy when using Confirm Calls'); ?>";
382
383
384
385   // set up the Destination stuff
386   setDestinations(theForm, 1);
387
388   // form validation
389   defaultEmptyOK = false;
390   if (isEmpty(theForm.grplist.value))
391     return warnInvalid(theForm.grplist, msgInvalidExtList);
392
393   defaultEmptyOK = false;
394   if (!isInteger(theForm.grptime.value)) {
395     return warnInvalid(theForm.grptime, msgInvalidTime);
396   } else {
397     var grptimeVal = theForm.grptime.value;
398     if (grptimeVal < 1 || grptimeVal > 60)
399       return warnInvalid(theForm.grptime, msgInvalidGrpTimeRange);
400   }
401
402   if (theForm.needsconf.checked && theForm.strategy.value.substring(0,7) != "ringall") {
403     return warnInvalid(theForm.needsconf, msgInvalidRingStrategy);
404   }
405
406   defaultEmptyOK = true;
407   if (!isPrefix(theForm.grppre.value))
408     return warnInvalid(theForm.grppre, msgInvalidGrpPrefix);
409
410   if (!validateDestinations(theForm, 1, true))
411     return false;
412
413   return true;
414 }
415 //-->
416 </script>
Note: See TracBrowser for help on using the browser.