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

Revision 3423, 16.3 kB (checked in by p_lindheimer, 6 years ago)

remove # on nnn# included in group list where nnn is the extention of the list itself, which gives an infinite loop

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php /* $Id$ */
2 //Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)
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 = 'ringgroups'; //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['description'])?$description = $_REQUEST['description']:$description='';
25 isset($_REQUEST['alertinfo'])?$alertinfo = $_REQUEST['alertinfo']:$alertinfo='';
26 isset($_REQUEST['needsconf'])?$needsconf = $_REQUEST['needsconf']:$needsconf='';
27 isset($_REQUEST['remotealert'])?$remotealert = $_REQUEST['remotealert']:$remotealert='';
28 isset($_REQUEST['toolate'])?$toolate = $_REQUEST['toolate']:$toolate='';
29 isset($_REQUEST['ringing'])?$ringing = $_REQUEST['ringing']:$ringing='';
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         if ($grplist[$key] == ltrim($extdisplay,'GRP-').'#')
53             $grplist[$key] = rtrim($grplist[$key],'#');
54         
55         // remove blanks
56         if ($grplist[$key] == "") unset($grplist[$key]);
57     }
58     
59     // check for duplicates, and re-sequence
60     $grplist = array_values(array_unique($grplist));
61 }
62
63 // do if we are submitting a form
64 if(isset($_POST['action'])){
65     //check if the extension is within range for this user
66     if (isset($account) && !checkRange($account)){
67         echo "<script>javascript:alert('". _("Warning! Extension")." ".$account." "._("is not allowed for your account").".');</script>";
68     } else {
69         //add group
70         if ($action == 'addGRP') {
71             //ringgroups_add($account,implode("-",$grplist),$strategy,$grptime,$grppre,$goto);
72             ringgroups_add($account,$strategy,$grptime,implode("-",$grplist),$goto,$description,$grppre,$annmsg,$alertinfo,$needsconf,$remotealert,$toolate,$ringing);
73             needreload();
74             redirect_standard();
75         }
76         
77         //del group
78         if ($action == 'delGRP') {
79             ringgroups_del($account);
80             needreload();
81             redirect_standard();
82         }
83         
84         //edit group - just delete and then re-add the extension
85         if ($action == 'edtGRP') {
86             ringgroups_del($account);   
87             ringgroups_add($account,$strategy,$grptime,implode("-",$grplist),$goto,$description,$grppre,$annmsg,$alertinfo,$needsconf,$remotealert,$toolate,$ringing);
88             needreload();
89             redirect_standard('extdisplay');
90         }
91     }
92 }
93 ?>
94 </div>
95
96 <div class="rnav"><ul>
97     <li><a id="<?php  echo ($extdisplay=='' ? 'current':'') ?>" href="config.php?display=<?php echo urlencode($dispnum)?>"><?php echo _("Add Ring Group")?></a></li>
98 <?php
99 //get unique ring groups
100 $gresults = ringgroups_list();
101
102 if (isset($gresults)) {
103     foreach ($gresults as $gresult) {
104         echo "<li><a id=\"".($extdisplay=='GRP-'.$gresult[0] ? 'current':'')."\" href=\"config.php?display=".urlencode($dispnum)."&extdisplay=".urlencode("GRP-".$gresult[0])."\">".$gresult[1]." ({$gresult[0]})</a></li>";
105     }
106 }
107 ?>
108 </ul></div>
109
110 <div class="content">
111 <?php
112 if ($action == 'delGRP') {
113     echo '<br><h3>'._("Ring Group").' '.$account.' '._("deleted").'!</h3><br><br><br><br><br><br><br><br>';
114 } else {
115     if ($extdisplay) {
116         // We need to populate grplist with the existing extension list.
117         $thisgrp = ringgroups_get(ltrim($extdisplay,'GRP-'));
118         $grpliststr = $thisgrp['grplist'];
119         $grplist = explode("-", $grpliststr);
120         $strategy = $thisgrp['strategy'];
121         $grppre = $thisgrp['grppre'];
122         $grptime = $thisgrp['grptime'];
123         $goto = $thisgrp['postdest'];
124         $annmsg = $thisgrp['annmsg'];
125         $description = $thisgrp['description'];
126         $alertinfo = $thisgrp['alertinfo'];
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 Group")."\">
140             </form>";
141             
142         echo "<h2>"._("Ring Group").": ".ltrim($extdisplay,'GRP-')."</h2>";
143         echo "<p>".$delButton."</p>";
144     } else {
145         $grplist = explode("-", '');;
146         $strategy = '';
147         $grppre = '';
148         $grptime = '';
149         $goto = '';
150         $annmsg = '';
151         $alertinfo = '';
152         $remotealert = '';
153         $needsconf = '';
154         $toolate = '';
155         $ringing = '';
156
157         echo "<h2>"._("Add Ring Group")."</h2>";
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 Ring Group") : _("Add Ring Group")) ?><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 _("Ring-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  if ($gresult[0]==0) { echo "600"; } else { echo $gresult[0] + 1; } ?>"></td>
174 <?php         } ?>
175             </tr>
176             <tr>
177             <td> <a href="#" class="info"><?php echo _("Group Description:")?>:<span><?php echo _("Provide a descriptive title for this Ring Group.")?></span></a></td>
178                 <td><input size="20" maxlength="35" type="text" name="description" value="<?php echo htmlspecialchars($description); ?>"></td>
179             </tr>
180             <tr>
181                 <td> <a href="#" class="info"><?php echo _("Ring strategy:")?>
182                 <span>
183                     <b><?php echo _("ringall")?></b>:  <?php echo _("Ring all available channels until one answers (default)")?><br>
184                     <b><?php echo _("hunt")?></b>: <?php echo _("Take turns ringing each available extension")?><br>
185                     <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>
186                                         <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 rung. If the primary is freePBX CF unconditional, then all will be rung")?><br>
187                 </span>
188                 </a></td>
189                 <td>
190                     <select name="strategy"/>
191                     <?php
192                         $default = (isset($strategy) ? $strategy : 'ringall');
193                                                 $items = array('ringall','ringall-prim','hunt','hunt-prim','memoryhunt','memoryhunt-prim');
194                         foreach ($items as $item) {
195                             echo '<option value="'.$item.'" '.($default == $item ? 'SELECTED' : '').'>'._($item);
196                         }
197                     ?>       
198                     </select>
199                 </td>
200             </tr>
201             <tr>
202                 <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>Extensions will ring the actual extension. If you want them to be sent down channel local (to ring follow-me, other ringgroups, queues, etc. then put a pound (#) at the end. Be careful!")?><br><br></span></a></td>
203                 <td valign="top">
204 <?php
205         $rows = count($grplist)+1;
206         ($rows < 5) ? 5 : (($rows > 20) ? 20 : $rows);
207 ?>
208                     <textarea id="grplist" cols="15" rows="<?php  echo $rows ?>" name="grplist"><?php echo implode("\n",$grplist);?></textarea><br>
209                    
210                     <input type="submit" style="font-size:10px;" value="<?php echo _("Clean & Remove duplicates")?>" />
211                 </td>
212             </tr>
213             <tr>
214                 <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>
215                 <td><input size="4" type="text" name="grppre" value="<?php  echo $grppre ?>"></td>
216             </tr>
217
218
219             <tr>
220                 <td><?php echo _("Ring time (max 60 sec)")?>:</td>
221                 <td><input size="4" type="text" name="grptime" value="<?php  echo $grptime?$grptime:20 ?>"></td>
222             </tr>
223 <?php if(function_exists('recordings_list')) { //only include if recordings is enabled?>
224     <tr>
225         <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>
226         <td>
227             <select name="annmsg"/>
228             <?php
229                 $tresults = recordings_list();
230                 $default = (isset($annmsg) ? $annmsg : '');
231                 echo '<option value="">'._("None")."</option>";
232                 if (isset($tresults[0])) {
233                     foreach ($tresults as $tresult) {
234                         echo '<option value="'.$tresult[2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n";
235                     }
236                 }
237             ?>       
238             </select>       
239         </td>
240     </tr>
241 <?php }    else { ?>
242     <tr>
243         <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>
244         <td>
245             <?php
246                 $default = (isset($annmsg) ? $annmsg : '');
247             ?>
248             <input type="hidden" name="annmsg" value="<?php echo $default; ?>"><?php echo ($default != '' ? $default : 'None'); ?>
249         </td>
250     </tr>
251 <?php } if (function_exists('music_list')) { ?>
252     <tr>
253         <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>
254         <td>
255             <select name="ringing"/>
256             <?php
257                 $tresults = music_list("/var/lib/asterisk/mohmp3");
258                 $cur = (isset($ringing) ? $ringing : 'Ring');
259                 echo '<option value="Ring">'._("Ring")."</option>";
260                 if (isset($tresults[0])) {
261                     foreach ($tresults as $tresult) {
262                         echo '<option value="'.$tresult.'"'.($tresult == $cur ? ' SELECTED' : '').'>'.$tresult."</option>\n";
263                     }
264                 }
265             ?>       
266             </select>       
267         </td>
268     </tr>
269 <?php } ?>
270            
271     <tr>
272         <td><a href="#" class="info"><?php echo _("Alert Info")?><span><?php echo _('ALERT_INFO can be used for distinctive ring with SIP devices.')?></span></a>:</td>
273         <td><input type="text" name="alertinfo" size="10" value="<?php echo ($alertinfo)?$alertinfo:'' ?>"></td>
274     </tr>
275     <tr>
276         <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>
277         <td> <?php if (!function_exists('recordings_list')) { echo _("System Recordings not installed. Option Disabled"); } else { ?>
278             <input type="checkbox" name="needsconf" value="CHECKED" <?php echo $needsconf ?>  /></td>
279 <?php } ?>
280     </tr>
281 <?php if(function_exists('recordings_list')) { //only include if recordings is enabled?>
282     <tr>
283         <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>
284         <td>
285             <select name="remotealert"/>
286             <?php
287                 $tresults = recordings_list();
288                 $default = (isset($remotealert) ? $remotealert : '');
289                 echo '<option value="">'._("Default")."</option>";
290                 if (isset($tresults[0])) {
291                     foreach ($tresults as $tresult) {
292                         echo '<option value="'.$tresult[2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n";
293                     }
294                 }
295             ?>       
296             </select>       
297         </td>
298     </tr>
299     <tr>
300         <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>
301         <td>
302             <select name="toolate"/>
303             <?php
304                 $tresults = recordings_list();
305                 $default = (isset($toolate) ? $toolate : '');
306                 echo '<option value="">'._("Default")."</option>";
307                 if (isset($tresults[0])) {
308                     foreach ($tresults as $tresult) {
309                         echo '<option value="'.$tresult[2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n";
310                     }
311                 }
312             ?>       
313             </select>       
314         </td>
315     </tr>
316 <?php } ?>
317             <tr><td colspan="2"><br><h5><?php echo _("Destination if no answer")?>:<hr></h5></td></tr>
318
319 <?php
320 //draw goto selects
321 echo drawselects($goto,0);
322 ?>
323            
324             <tr>
325             <td colspan="2"><br><h6><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>"></h6></td>       
326            
327             </tr>
328             </table>
329             </form>
330 <?php         
331         } //end if action == delGRP
332         
333
334 ?>
335 <script language="javascript">
336 <!--
337
338 function checkGRP(theForm) {
339     var msgInvalidGrpNum = "<?php echo _('Invalid Group Number specified'); ?>";
340     var msgInvalidGrpNumStartWithZero = "<?php echo _('Group numbers with more than one digit cannot begin with 0'); ?>";
341     var msgInvalidExtList = "<?php echo _('Please enter an extension list.'); ?>";
342     var msgInvalidGrpPrefix = "<?php echo _('Invalid Caller ID prefix.'); ?>";
343     var msgInvalidTime = "<?php echo _('Invalid time specified'); ?>";
344     var msgInvalidGrpTimeRange = "<?php echo _('Time must be between 1 and 60 seconds'); ?>";
345     var msgInvalidDescription = "<?php echo _('Please enter a valid Group Description'); ?>";
346     var msgInvalidRingStrategy = "<?php echo _('You must choose ringall or ringall-prim ring strategy when using Confirm Calls'); ?>";
347
348     // set up the Destination stuff
349     setDestinations(theForm, 1);
350
351     // form validation
352     defaultEmptyOK = false;
353     if (!isInteger(theForm.account.value)) {
354         return warnInvalid(theForm.account, msgInvalidGrpNum);
355     } else if (theForm.account.value.indexOf('0') == 0 && theForm.account.value.length > 1) {
356         return warnInvalid(theForm.account, msgInvalidGrpNumStartWithZero);
357     }
358    
359     defaultEmptyOK = false;   
360     if (!isAlphanumeric(theForm.description.value))
361         return warnInvalid(theForm.description, msgInvalidDescription);
362    
363     if (isEmpty(theForm.grplist.value))
364         return warnInvalid(theForm.grplist, msgInvalidExtList);
365
366     defaultEmptyOK = true;
367     if (!isCallerID(theForm.grppre.value))
368         return warnInvalid(theForm.grppre, msgInvalidGrpPrefix);
369    
370     defaultEmptyOK = false;
371     if (!isInteger(theForm.grptime.value)) {
372         return warnInvalid(theForm.grptime, msgInvalidTime);
373     } else {
374         var grptimeVal = theForm.grptime.value;
375         if (grptimeVal < 1 || grptimeVal > 60)
376             return warnInvalid(theForm.grptime, msgInvalidGrpTimeRange);
377     }
378
379     if (theForm.needsconf.checked && theForm.strategy.value.substring(0,7) != "ringall") {
380         return warnInvalid(theForm.needsconf, msgInvalidRingStrategy);
381     }
382
383     if (!validateDestinations(theForm, 1, true))
384         return false;
385        
386     return true;
387 }
388 //-->
389 </script>
390
391
Note: See TracBrowser for help on using the browser.