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

Revision 2588, 15.3 kB (checked in by p_lindheimer, 7 years ago)

Added javascript validation that ringall strategy is chosen if Call Confirmation is used since that is how it is implemented currently

  • 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
30
31 if (isset($_REQUEST['goto0']) && isset($_REQUEST[$_REQUEST['goto0']."0"])) {
32         $goto = $_REQUEST[$_REQUEST['goto0']."0"];
33 } else {
34         $goto = '';
35 }
36
37
38 if (isset($_REQUEST["grplist"])) {
39   $grplist = explode("\n",$_REQUEST["grplist"]);
40
41   if (!$grplist) {
42     $grplist = null;
43   }
44  
45   foreach (array_keys($grplist) as $key) {
46     //trim it
47     $grplist[$key] = trim($grplist[$key]);
48     
49     // remove invalid chars
50     $grplist[$key] = preg_replace("/[^0-9#*]/", "", $grplist[$key]);
51     
52     // remove blanks
53     if ($grplist[$key] == "") unset($grplist[$key]);
54   }
55  
56   // check for duplicates, and re-sequence
57   $grplist = array_values(array_unique($grplist));
58 }
59
60 // do if we are submitting a form
61 if(isset($_POST['action'])){
62   //check if the extension is within range for this user
63   if (isset($account) && !checkRange($account)){
64     echo "<script>javascript:alert('". _("Warning! Extension")." ".$account." "._("is not allowed for your account").".');</script>";
65   } else {
66     //add group
67     if ($action == 'addGRP') {
68       findmefollow_add($account,$strategy,$grptime,implode("-",$grplist),$goto,$grppre,$annmsg,$dring,$needsconf,$remotealert,$toolate,$ringing);
69
70       needreload();
71     }
72     
73     //del group
74     if ($action == 'delGRP') {
75       findmefollow_del($account);
76       needreload();
77     }
78     
79     //edit group - just delete and then re-add the extension
80     if ($action == 'edtGRP') {
81       findmefollow_del($account);
82       findmefollow_add($account,$strategy,$grptime,implode("-",$grplist),$goto,$grppre,$annmsg,$dring,$needsconf,$remotealert,$toolate,$ringing);
83
84       needreload();
85     }
86   }
87 }
88 ?>
89 </div>
90
91 <div class="rnav">
92 <?php
93 //get unique ring groups
94 $gresults = findmefollow_allusers();
95 $set_users = findmefollow_list();
96
97 if (isset($gresults)) {
98   foreach ($gresults as $gresult) {
99     $defined = is_array($set_users) ? (in_array($gresult[0], $set_users) ? "(edit)" : "(add)") : "add";
100                 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>";
101
102   }
103 }
104 ?>
105 </div>
106
107 <div class="content">
108 <?php
109
110 if (!$extdisplay) {
111   echo '<br><h2>'._("Follow Me").'</h2><br><h3>'._('Choose a user/extension:').'</h3><br><br><br><br><br><br><br>';
112   }
113 elseif ($action == 'delGRP') {
114   echo '<br><h3>'._("Follow Me").' '.$account.' '._("deleted").'!</h3><br><br><br><br><br><br><br><br>';
115 } else {
116   if ($extdisplay) {
117     // We need to populate grplist with the existing extension list.
118     $thisgrp = findmefollow_get(ltrim($extdisplay,'GRP-'));
119     $grpliststr = $thisgrp['grplist'];
120     $grplist = explode("-", $grpliststr);
121     $strategy = $thisgrp['strategy'];
122     $grppre = $thisgrp['grppre'];
123     $grptime = $thisgrp['grptime'];
124     $goto = $thisgrp['postdest'];
125     $annmsg = $thisgrp['annmsg'];
126     $dring = $thisgrp['dring'];
127     $remotealert = $thisgrp['remotealert'];
128     $needsconf = $thisgrp['needsconf'];
129     $toolate = $thisgrp['toolate'];
130     $ringing = $thisgrp['ringing'];
131     unset($grpliststr);
132     unset($thisgrp);
133     
134     $delButton = "
135       <form name=delete action=\"{$_SERVER['PHP_SELF']}\" method=POST>
136         <input type=\"hidden\" name=\"display\" value=\"{$dispnum}\">
137         <input type=\"hidden\" name=\"account\" value=\"".ltrim($extdisplay,'GRP-')."\">
138         <input type=\"hidden\" name=\"action\" value=\"delGRP\">
139         <input type=submit value=\""._("Delete Entries")."\">
140       </form>";
141       
142     echo "<h2>"._("Follow Me").": ".ltrim($extdisplay,'GRP-')."</h2>";
143
144
145     // Copied straight out of old code,let's see if it works?
146     //
147     if (isset($amp_conf["AMPEXTENSIONS"]) && ($amp_conf["AMPEXTENSIONS"] == "deviceanduser")) {
148       $editURL = $_SERVER['PHP_SELF'].'?display=users&extdisplay='.ltrim($extdisplay,'GRP-');
149       $EXTorUSER = "User";
150     }
151     else {
152       $editURL = $_SERVER['PHP_SELF'].'?display=extensions&extdisplay='.ltrim($extdisplay,'GRP-');
153       $EXTorUSER = "Extension";
154     }
155
156     echo "<p><a href=".$editURL."> Edit ".$EXTorUSER." ".ltrim($extdisplay,'GRP-')."</a></p>";
157     echo "<p>".$delButton."</p>";
158   }
159   ?>
160       <form name="editGRP" action="<?php  $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return checkGRP(editGRP);">
161       <input type="hidden" name="display" value="<?php echo $dispnum?>">
162       <input type="hidden" name="action" value="<?php echo ($extdisplay ? 'edtGRP' : 'addGRP'); ?>">
163       <table>
164       <tr><td colspan="2"><h5><?php  echo ($extdisplay ? _("Edit Follow Me") : _("Add Follow Me")) ?><hr></h5></td></tr>
165       <tr>
166 <?php
167   if ($extdisplay) {
168
169 ?>
170         <input size="5" type="hidden" name="account" value="<?php  echo ltrim($extdisplay,'GRP-'); ?>">
171 <?php     } else { ?>
172         <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>
173         <td><input size="5" type="text" name="account" value="<?php  echo $gresult[0] + 1; ?>"></td>
174 <?php     } ?>
175       </tr>
176       <tr>
177         <td> <a href="#" class="info"><?php echo _("ring strategy:")?>
178         <span>
179           <b><?php echo _("ringall")?></b><?php echo _("ring all available channels until one answers (default)")?><br>
180           <b><?php echo _("hunt")?></b>: <?php echo _("take turns ringing each available extension")?><br>
181           <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>
182                                         <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>
183         </span>
184         </a></td>
185         <td>
186           &nbsp;&nbsp;<select name="strategy"/>
187           <?php
188             $default = (isset($strategy) ? $strategy : 'ringall');
189                                                 $items = array('ringall','ringall-prim','hunt','hunt-prim','memoryhunt','memoryhunt-prim');
190             foreach ($items as $item) {
191               echo '<option value="'.$item.'" '.($default == $item ? 'SELECTED' : '').'>'._($item);
192             }
193           ?>   
194           </select>
195         </td>
196       </tr>
197       <tr>
198         <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>
199         <td><input size="18" type="text" name="dring" value="<?php  echo $dring ?>"></td>
200       </tr>
201   <tr>
202     <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 ring strategy')?></span></a>:</td>
203     <td> <?php if (!function_exists('recordings_list')) { echo _("System Recordings not installed. Option Disabled"); } else { ?>
204       <input type="checkbox" name="needsconf" value="CHECKED" <?php echo $needsconf ?>  /></td>
205 <?php } ?>
206   </tr>
207 <?php if(function_exists('recordings_list')) { //only include if recordings is enabled?>
208   <tr>
209     <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>
210     <td>
211       &nbsp;&nbsp;<select name="remotealert"/>
212       <?php
213         $tresults = recordings_list();
214         $default = (isset($remotealert) ? $remotealert : '');
215         echo '<option value="">'._("None")."</option>";
216         if (isset($tresults[0])) {
217           foreach ($tresults as $tresult) {
218             echo '<option value="'.$tresult[2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n";
219           }
220         }
221       ?>
222       </select>
223     </td>
224   </tr>
225   <tr>
226     <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>
227     <td>
228     &nbsp;&nbsp;<select name="toolate"/>
229       <?php
230         $tresults = recordings_list();
231         $default = (isset($toolate) ? $toolate : '');
232         echo '<option value="">'._("None")."</option>";
233         if (isset($tresults[0])) {
234           foreach ($tresults as $tresult) {
235             echo '<option value="'.$tresult[2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n";
236           }
237         }
238       ?>
239       </select>
240     </td>
241   </tr>
242 <?php } ?>
243       <tr>
244         <td valign="top"><a href="#" class="info"><?php echo _("extension 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>
245         <td valign="top">&nbsp;
246 <?php
247     $rows = count($grplist)+1;
248     ($rows < 5) ? 5 : (($rows > 20) ? 20 : $rows);
249 ?>
250           <textarea id="grplist" cols="15" rows="<?php  echo $rows ?>" name="grplist"><?php echo implode("\n",$grplist);?></textarea><br>
251          
252           <input type="submit" style="font-size:10px;" value="<?php echo _("Clean & Remove duplicates")?>" />
253         </td>
254       </tr>
255       <tr>
256         <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>
257         <td><input size="4" type="text" name="grppre" value="<?php  echo $grppre ?>"></td>
258       </tr>
259
260
261       <tr>
262         <td><?php echo _("ring time (max 60 sec)")?>:</td>
263         <td><input size="4" type="text" name="grptime" value="<?php  echo $grptime?$grptime:20 ?>"></td>
264       </tr>
265 <?php if(function_exists('recordings_list')) { //only include if recordings is enabled?>
266   <tr>
267     <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>
268     <td>
269       &nbsp;&nbsp;<select name="annmsg"/>
270       <?php
271         $tresults = recordings_list();
272         $default = (isset($annmsg) ? $annmsg : '');
273         echo '<option value="">'._("None");
274         if (isset($tresults)) {
275           foreach ($tresults as $tresult) {
276             echo '<option value="'.$tresult[2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1];
277           }
278         }
279       ?>   
280       </select>   
281     </td>
282   </tr>
283 <?php } else { ?>
284   <tr>
285     <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>
286     <td>
287       <?php
288         $default = (isset($annmsg) ? $annmsg : '');
289       ?>
290       <input type="hidden" name="annmsg" value="<?php echo $default; ?>"><?php echo ($default != '' ? $default : 'None'); ?>
291     </td>
292   </tr>
293 <?php } if (function_exists('music_list')) { ?>
294   <tr>
295     <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. Note this DOES NOT WORK with call confirmation, due to limitations of Asterisk")?></span></a></td>
296     <td>
297       &nbsp;&nbsp;<select name="ringing"/>
298       <?php
299         $tresults = music_list("/var/lib/asterisk/mohmp3");
300         $cur = (isset($ringing) ? $ringing : 'Ring');
301         echo '<option value="Ring">'._("Ring")."</option>";
302         if (isset($tresults[0])) {
303           foreach ($tresults as $tresult) {
304             echo '<option value="'.$tresult.'"'.($tresult == $cur ? ' SELECTED' : '').'>'.$tresult."</option>\n";
305           }
306         }
307       ?>
308       </select>
309       </td>
310     </tr>
311 <?php } ?>
312      
313       <tr><td colspan="2"><br><h5><?php echo _("Destination if no answer")?>:<hr></h5></td></tr>
314
315 <?php
316 //draw goto selects
317 echo drawselects($goto,0);
318 ?>
319      
320       <tr>
321       <td colspan="2"><br><h6><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>"></h6></td>   
322      
323       </tr>
324       </table>
325       </form>
326 <?php     
327     } //end if action == delGRP
328     
329 ?>
330 <script language="javascript">
331 <!--
332
333 function checkGRP(theForm) {
334   var msgInvalidGrpNum = "<?php echo _('Invalid Group Number specified'); ?>";
335   var msgInvalidGrpNumStartWithZero = "<?php echo _('Group numbers with more than one digit cannot begin with 0'); ?>";
336   var msgInvalidExtList = "<?php echo _('Please enter an extension list.'); ?>";
337   var msgInvalidGrpPrefix = "<?php echo _('Invalid prefix. Valid characters: a-z A-Z 0-9 : _ -'); ?>";
338   var msgInvalidTime = "<?php echo _('Invalid time specified'); ?>";
339   var msgInvalidGrpTimeRange = "<?php echo _('Time must be between 1 and 60 seconds'); ?>";
340   var msgInvalidRingStrategy = "<?php echo _('You must choose ringall ring strategy when using Confirm Calls'); ?>";
341
342   // set up the Destination stuff
343   setDestinations(theForm, 1);
344
345   // form validation
346   defaultEmptyOK = false;
347   if (isEmpty(theForm.grplist.value))
348     return warnInvalid(theForm.grplist, msgInvalidExtList);
349
350   defaultEmptyOK = false;
351   if (!isInteger(theForm.grptime.value)) {
352     return warnInvalid(theForm.grptime, msgInvalidTime);
353   } else {
354     var grptimeVal = theForm.grptime.value;
355     if (grptimeVal < 1 || grptimeVal > 60)
356       return warnInvalid(theForm.grptime, msgInvalidGrpTimeRange);
357   }
358
359   if (theForm.needsconf.checked && theForm.strategy.value != "ringall") {
360     return warnInvalid(theForm.needsconf, msgInvalidRingStrategy);
361   }
362
363   defaultEmptyOK = true;
364   if (!isPrefix(theForm.grppre.value))
365     return warnInvalid(theForm.grppre, msgInvalidGrpPrefix);
366
367   if (!validateDestinations(theForm, 1, true))
368     return false;
369
370   return true;
371 }
372 //-->
373 </script>
Note: See TracBrowser for help on using the browser.