Ticket #1206: page.ringgroups.php

File page.ringgroups.php, 11.8 kB (added by ubanov, 6 years ago)

My modified version of the file page.ringgroups.php

Line 
1 <?php /* $Id: page.ringgroups.php 1762 2006-04-28 19:15:31Z p_lindheimer $ */
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
27 if (isset($_REQUEST['goto0']) && isset($_REQUEST[$_REQUEST['goto0']."0"])) {
28         $goto = $_REQUEST[$_REQUEST['goto0']."0"];
29 } else {
30         $goto = '';
31 }
32
33
34 if (isset($_REQUEST["grplist"])) {
35   $grplist = explode("\n",$_REQUEST["grplist"]);
36
37   if (!$grplist) {
38     $grplist = null;
39   }
40  
41   foreach (array_keys($grplist) as $key) {
42     //trim it
43     $grplist[$key] = trim($grplist[$key]);
44    
45     // remove invalid chars
46     $grplist[$key] = preg_replace("/[^0-9#*]/", "", $grplist[$key]);
47    
48     // remove blanks
49     if ($grplist[$key] == "") unset($grplist[$key]);
50   }
51  
52   // check for duplicates, and re-sequence
53   $grplist = array_values(array_unique($grplist));
54 }
55
56 // do if we are submitting a form
57 if(isset($_POST['action'])){
58   //check if the extension is within range for this user
59   if (isset($account) && !checkRange($account)){
60     echo "<script>javascript:alert('". _("Warning! Extension")." ".$account." "._("is not allowed for your account").".');</script>";
61   } else {
62     //add group
63     if ($action == 'addGRP') {
64       //ringgroups_add($account,implode("-",$grplist),$strategy,$grptime,$grppre,$goto);
65       ringgroups_add($account,$strategy,$grptime,implode("-",$grplist),$goto,$description,$grppre,$annmsg,$alertinfo);
66       needreload();
67     }
68    
69     //del group
70     if ($action == 'delGRP') {
71       ringgroups_del($account);
72       needreload();
73     }
74    
75     //edit group - just delete and then re-add the extension
76     if ($action == 'edtGRP') {
77       ringgroups_del($account);
78       ringgroups_add($account,$strategy,$grptime,implode("-",$grplist),$goto,$description,$grppre,$annmsg,$alertinfo);
79       needreload();
80     }
81   }
82 }
83 ?>
84 </div>
85
86 <div class="rnav">
87     <li><a id="<?php  echo ($extdisplay=='' ? 'current':'') ?>" href="config.php?display=<?php echo urlencode($dispnum)?>"><?php echo _("Add Ring Group")?></a></li>
88 <?php 
89 //get unique ring groups
90 $gresults = ringgroups_list();
91
92 if (isset($gresults)) {
93   foreach ($gresults as $gresult) {
94     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>";
95   }
96 }
97 ?>
98 </div>
99
100 <div class="content">
101 <?php 
102 if ($action == 'delGRP') {
103   echo '<br><h3>'._("Ring Group").' '.$account.' '._("deleted").'!</h3><br><br><br><br><br><br><br><br>';
104 } else {
105   if ($extdisplay) {
106     // We need to populate grplist with the existing extension list.
107     $thisgrp = ringgroups_get(ltrim($extdisplay,'GRP-'));
108     $grpliststr = $thisgrp['grplist'];
109     $grplist = explode("-", $grpliststr);
110     $strategy = $thisgrp['strategy'];
111     $grppre = $thisgrp['grppre'];
112     $grptime = $thisgrp['grptime'];
113     $goto = $thisgrp['postdest'];
114     $annmsg = $thisgrp['annmsg'];
115     $description = $thisgrp['description'];
116     $alertinfo = $thisgrp['alertinfo'];
117     unset($grpliststr);
118     unset($thisgrp);
119    
120     $delButton = "
121       <form name=delete action=\"{$_SERVER['PHP_SELF']}\" method=POST>
122         <input type=\"hidden\" name=\"display\" value=\"{$dispnum}\">
123         <input type=\"hidden\" name=\"account\" value=\"".ltrim($extdisplay,'GRP-')."\">
124         <input type=\"hidden\" name=\"action\" value=\"delGRP\">
125         <input type=submit value=\""._("Delete Group")."\">
126       </form>";
127      
128     echo "<h2>"._("Ring Group").": ".ltrim($extdisplay,'GRP-')."</h2>";
129     echo "<p>".$delButton."</p>";
130   } else {
131     $grplist = explode("-", '');;
132     $strategy = '';
133     $grppre = '';
134     $grptime = '';
135     $goto = '';
136     $annmsg = '';
137     $alertinfo = '';
138
139     echo "<h2>"._("Add Ring Group")."</h2>";
140   }
141   ?>
142       <form name="editGRP" action="<?php  $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return checkGRP(editGRP);">
143       <input type="hidden" name="display" value="<?php echo $dispnum?>">
144       <input type="hidden" name="action" value="<?php echo ($extdisplay ? 'edtGRP' : 'addGRP'); ?>">
145       <table>
146       <tr><td colspan="2"><h5><?php  echo ($extdisplay ? _("Edit Ring Group") : _("Add Ring Group")) ?><hr></h5></td></tr>
147       <tr>
148 <?php
149   if ($extdisplay) {
150
151 ?>
152         <input size="5" type="hidden" name="account" value="<?php  echo ltrim($extdisplay,'GRP-'); ?>">
153 <?php     } else { ?>
154         <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>
155         <td><input size="5" type="text" name="account" value="<?php  echo $gresult[0] + 1; ?>"></td>
156 <?php     } ?>
157       </tr>
158       <tr>
159         <td> <a href="#" class="info"><?php echo _("group description:")?></td>
160         <td><input size="20" maxlength="35" type="text" name="description" value="<?php echo htmlspecialchars($description); ?>"></td>
161       </tr>
162       <tr>
163         <td> <a href="#" class="info"><?php echo _("ring strategy:")?>
164         <span>
165           <b><?php echo _("ringall")?></b>:  <?php echo _("ring all available channels until one answers (default)")?><br>
166           <b><?php echo _("hunt")?></b>: <?php echo _("take turns ringing each available extension")?><br>
167           <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>
168           <b>-rand</b>: <?php echo _("The same as the previous ring strategy, but before applying the strategy resort the extension list randomly")?><br>
169         </span>
170         </a></td>
171         <td>
172           <select name="strategy"/>
173           <?php
174             $default = (isset($strategy) ? $strategy : 'ringall');
175             $items = array('ringall','hunt','hunt-rand','memoryhunt','memoryhunt-rand');
176             foreach ($items as $item) {
177               echo '<option value="'.$item.'" '.($default == $item ? 'SELECTED' : '').'>'._($item);
178             }
179           ?>   
180           </select>
181         </td>
182       </tr>
183       <tr>
184         <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>
185         <td valign="top">&nbsp;
186 <?php
187     $rows = count($grplist)+1;
188     ($rows < 5) ? 5 : (($rows > 20) ? 20 : $rows);
189 ?>
190           <textarea id="grplist" cols="15" rows="<?php  echo $rows ?>" name="grplist"><?php echo implode("\n",$grplist);?></textarea><br>
191           
192           <input type="submit" style="font-size:10px;" value="<?php echo _("Clean & Remove duplicates")?>" />
193         </td>
194       </tr>
195       <tr>
196         <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>
197         <td><input size="4" type="text" name="grppre" value="<?php  echo $grppre ?>"></td>
198       </tr>
199
200
201       <tr>
202         <td><?php echo _("ring time (max 60 sec)")?>:</td>
203         <td><input size="4" type="text" name="grptime" value="<?php  echo $grptime?$grptime:20 ?>"></td>
204       </tr>
205 <?php if(function_exists('recordings_list')) { //only include if recordings is enabled?>
206   <tr>
207     <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>
208     <td>
209       <select name="annmsg"/>
210       <?php
211         $tresults = recordings_list();
212         $default = (isset($annmsg) ? $annmsg : '');
213         echo '<option value="">'._("None")."</option>";
214         if (isset($tresults[0])) {
215           foreach ($tresults as $tresult) {
216             echo '<option value="'.$tresult[2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n";
217           }
218         }
219       ?>   
220       </select>   
221     </td>
222   </tr>
223 <?php } else { ?>
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>You must install and enable the \"Systems Recordings\" Module to edit this option")?></span></a></td>
226     <td>
227       <?php
228         $default = (isset($annmsg) ? $annmsg : '');
229       ?>
230       <input type="hidden" name="annmsg" value="<?php echo $default; ?>"><?php echo ($default != '' ? $default : 'None'); ?>
231     </td>
232   </tr>
233 <?php } ?>
234       
235   <tr>
236     <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>
237     <td><input type="text" name="alertinfo" size="10" value="<?php echo ($alertinfo)?$alertinfo:'' ?>"></td>
238   </tr>
239       <tr><td colspan="2"><br><h5><?php echo _("Destination if no answer")?>:<hr></h5></td></tr>
240
241 <?php 
242 //draw goto selects
243 echo drawselects($goto,0);
244 ?>
245       
246       <tr>
247       <td colspan="2"><br><h6><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>"></h6></td>   
248       
249       </tr>
250       </table>
251       </form>
252 <?php    
253     } //end if action == delGRP
254    
255
256 ?>
257 <script language="javascript">
258 <!--
259
260 function checkGRP(theForm) {
261   var msgInvalidGrpNum = "<?php echo _('Invalid Group Number specified'); ?>";
262   var msgInvalidGrpNumStartWithZero = "<?php echo _('Group numbers with more than one digit cannot begin with 0'); ?>";
263   var msgInvalidExtList = "<?php echo _('Please enter an extension list.'); ?>";
264   var msgInvalidGrpPrefix = "<?php echo _('Invalid Caller ID prefix.'); ?>";
265   var msgInvalidTime = "<?php echo _('Invalid time specified'); ?>";
266   var msgInvalidGrpTimeRange = "<?php echo _('Time must be between 1 and 60 seconds'); ?>";
267   var msgInvalidDescription = "<?php echo _('Please enter a valid Group Description'); ?>";
268
269   // set up the Destination stuff
270   setDestinations(theForm, 1);
271
272   // form validation
273   defaultEmptyOK = false;
274   if (!isInteger(theForm.account.value)) {
275     return warnInvalid(theForm.account, msgInvalidGrpNum);
276   } else if (theForm.account.value.indexOf('0') == 0 && theForm.account.value.length > 1) {
277     return warnInvalid(theForm.account, msgInvalidGrpNumStartWithZero);
278   }
279  
280   defaultEmptyOK = false;
281   if (!isAlphanumeric(theForm.description.value))
282     return warnInvalid(theForm.description, msgInvalidDescription);
283  
284   if (isEmpty(theForm.grplist.value))
285     return warnInvalid(theForm.grplist, msgInvalidExtList);
286
287   defaultEmptyOK = true;
288   if (!isCallerID(theForm.grppre.value))
289     return warnInvalid(theForm.grppre, msgInvalidGrpPrefix);
290  
291   defaultEmptyOK = false;
292   if (!isInteger(theForm.grptime.value)) {
293     return warnInvalid(theForm.grptime, msgInvalidTime);
294   } else {
295     var grptimeVal = theForm.grptime.value;
296     if (grptimeVal < 1 || grptimeVal > 60)
297       return warnInvalid(theForm.grptime, msgInvalidGrpTimeRange);
298   }
299
300   if (!validateDestinations(theForm, 1, true))
301     return false;
302     
303   return true;
304 }
305 //-->
306 </script>