root/modules/branches/2.5/core/page.routing.php

Revision 5953, 25.7 kB (checked in by p_lindheimer, 5 years ago)

added delete and edit icons, moved devices and users next to each other in lnav bar, added links between devices and users

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php /* $Id$ */
2 // routing.php Copyright (C) 2004 Greg MacLellan (greg@mtechsolutions.ca)
3 // routing.php <trunk & roting priority additions> Copyright (C) 2005 Ron Hartmann (rhartmann@vercomsystems.com)
4 // Asterisk Management Portal Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)
5 //
6 //This program is free software; you can redistribute it and/or
7 //modify it under the terms of the GNU General Public License
8 //as published by the Free Software Foundation; either version 2
9 //of the License, or (at your option) any later version.
10 //
11 //This program is distributed in the hope that it will be useful,
12 //but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //GNU General Public License for more details.
15
16 $display='routing';
17 $extdisplay=isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:'';
18 $action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
19
20 $repotrunkdirection = isset($_REQUEST['repotrunkdirection'])?$_REQUEST['repotrunkdirection']:'';
21 $repotrunkkey = isset($_REQUEST['repotrunkkey'])?$_REQUEST['repotrunkkey']:'';
22
23
24 $dialpattern = array();
25 if (isset($_REQUEST["dialpattern"])) {
26     //$dialpattern = $_REQUEST["dialpattern"];
27     $dialpattern = explode("\n",$_REQUEST["dialpattern"]);
28
29     if (!$dialpattern) {
30         $dialpattern = array();
31     }
32     
33     foreach (array_keys($dialpattern) as $key) {
34         //trim it
35         $dialpattern[$key] = trim($dialpattern[$key]);
36         
37         // remove blanks
38         if ($dialpattern[$key] == "") unset($dialpattern[$key]);
39         
40         // remove leading underscores (we do that on backend)
41         if ($dialpattern[$key][0] == "_") $dialpattern[$key] = substr($dialpattern[$key],1);
42     }
43     
44     // check for duplicates, and re-sequence
45     $dialpattern = array_values(array_unique($dialpattern));
46 }
47     
48 if ( (isset($_REQUEST['reporoutedirection'])) && (isset($_REQUEST['reporoutekey']))) {
49     $routepriority = core_routing_getroutenames();
50     $routepriority = core_routing_setroutepriority($routepriority, $_REQUEST['reporoutedirection'], $_REQUEST['reporoutekey']);
51 }
52
53 $trunkpriority = array();
54 if (isset($_REQUEST["trunkpriority"])) {
55     $trunkpriority = $_REQUEST["trunkpriority"];
56
57     if (!$trunkpriority) {
58         $trunkpriority = array();
59     }
60     
61     // delete blank entries and reorder
62     foreach (array_keys($trunkpriority) as $key) {
63         if (empty($trunkpriority[$key])) {
64             // delete this empty
65             unset($trunkpriority[$key]);
66             
67         } else if (($key==($repotrunkkey-1)) && ($repotrunkdirection=="up")) {
68             // swap this one with the one before (move up)
69             $temptrunk = $trunkpriority[$key];
70             $trunkpriority[ $key ] = $trunkpriority[ $key+1 ];
71             $trunkpriority[ $key+1 ] = $temptrunk;
72             
73         } else if (($key==($repotrunkkey)) && ($repotrunkdirection=="down")) {
74             // swap this one with the one after (move down)
75             $temptrunk = $trunkpriority[ $key+1 ];
76             $trunkpriority[ $key+1 ] = $trunkpriority[ $key ];
77             $trunkpriority[ $key ] = $temptrunk;
78         }
79     }
80     unset($temptrunk);
81     $trunkpriority = array_values($trunkpriority); // resequence our numbers
82 }
83
84 $routename = isset($_REQUEST["routename"]) ? $_REQUEST["routename"] : "";
85 $routepass = isset($_REQUEST["routepass"]) ? $_REQUEST["routepass"] : "";
86 $emergency = isset($_REQUEST["emergency"]) ? $_REQUEST["emergency"] : "";
87 $intracompany = isset($_REQUEST["intracompany"]) ? $_REQUEST["intracompany"] : "";
88 $mohsilence = isset($_REQUEST["mohsilence"]) ? $_REQUEST["mohsilence"] : "";
89
90 //if submitting form, update database
91 switch ($action) {
92     case "addroute":
93         core_routing_add($routename, $dialpattern, $trunkpriority,"new", $routepass, $emergency, $intracompany, $mohsilence);
94         needreload();
95         redirect_standard();
96     break;
97     case "editroute":
98         core_routing_edit($routename, $dialpattern, $trunkpriority, $routepass, $emergency, $intracompany, $mohsilence);
99         needreload();
100         redirect_standard('extdisplay');
101     break;
102     case "delroute":
103         core_routing_del($extdisplay);
104         // re-order the routes to make sure that there are no skipped numbers.
105         // example if we have 001-test1, 002-test2, and 003-test3 then delete 002-test2
106         // we do not want to have our routes as 001-test1, 003-test3 we need to reorder them
107         // so we are left with 001-test1, 002-test3
108         $routepriority = core_routing_getroutenames();
109         $routepriority = core_routing_setroutepriority($routepriority, '','');
110         needreload();
111         redirect_standard();
112     break;
113     case 'renameroute':
114         if (core_routing_rename($routename, $_REQUEST["newroutename"])) {
115             needreload();
116         } else {
117             echo "<script language=\"javascript\">alert('"._("Error renaming route: duplicate name")."');</script>";
118         }
119         $route_prefix=substr($routename,0,4);
120         $extdisplay=$route_prefix.$_REQUEST["newroutename"];
121
122     break;
123     case 'prioritizeroute':
124         needreload();
125     break;
126     case 'populatenpanxx':
127         if (preg_match("/^([2-9]\d\d)-?([2-9]\d\d)$/", $_REQUEST["npanxx"], $matches)) {
128             // first thing we do is grab the exch:
129             $ch = curl_init();
130             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
131             curl_setopt($ch, CURLOPT_URL, "http://www.localcallingguide.com/xmllocalprefix.php?npa=".$matches[1]."&nxx=".$matches[2]);
132             curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; FreePBX Local Trunks Configuration)");
133             $str = curl_exec($ch);
134             curl_close($ch);
135
136             // quick 'n dirty - nabbed from PEAR
137             require_once($amp_conf['AMPWEBROOT'] . '/admin/modules/core/XML_Parser.php');
138             require_once($amp_conf['AMPWEBROOT'] . '/admin/modules/core/XML_Unserializer.php');
139
140             $xml = new xml_unserializer;
141             $xml->unserialize($str);
142             $xmldata = $xml->getUnserializedData();
143
144             if (isset($xmldata['lca-data']['prefix'])) {
145                 // we do the loops separately so patterns are grouped together
146                 
147                 // match 1+NPA+NXX (dropping 1)
148                 foreach ($xmldata['lca-data']['prefix'] as $prefix) {
149                     $dialpattern[] = '1|'.$prefix['npa'].$prefix['nxx'].'XXXX';
150                 }
151                 // match NPA+NXX
152                 foreach ($xmldata['lca-data']['prefix'] as $prefix) {
153                     $dialpattern[] = $prefix['npa'].$prefix['nxx'].'XXXX';
154                 }
155                 // match 7-digits
156                 foreach ($xmldata['lca-data']['prefix'] as $prefix) {
157                     $dialpattern[] = $prefix['nxx'].'XXXX';
158                 }
159
160                 // check for duplicates, and re-sequence
161                 $dialpattern = array_values(array_unique($dialpattern));
162             } else {
163                 $errormsg = _("Error fetching prefix list for: "). $_REQUEST["npanxx"];
164             }
165             
166         } else {
167             // what a horrible error message... :p
168             $errormsg = _("Invalid format for NPA-NXX code (must be format: NXXNXX)");
169         }
170         
171         if (isset($errormsg)) {
172             echo "<script language=\"javascript\">alert('".addslashes($errormsg)."');</script>";
173             unset($errormsg);
174         }
175     break;
176 }
177     
178
179     
180 //get all rows from globals
181 $sql = "SELECT * FROM globals";
182 $globals = $db->getAll($sql);
183 if(DB::IsError($globals)) {
184 die_freepbx($globals->getMessage());
185 }
186
187 //create a set of variables that match the items in global[0]
188 foreach ($globals as $global) {
189     ${trim($global[0])} = htmlentities($global[1]);   
190 }
191
192 ?>
193 </div>
194
195
196
197 <div class="rnav">
198 <ul>
199     <li><a <?php  echo ($extdisplay=='' ? 'class="current"':'') ?> href="config.php?display=<?php echo urlencode($display)?>"><?php echo _("Add Route")?></a></li>
200 <?php
201 $reporoutedirection = isset($_REQUEST['reporoutedirection'])?$_REQUEST['reporoutedirection']:'';
202 $reporoutekey = isset($_REQUEST['reporoutekey'])?$_REQUEST['reporoutekey']:'';
203 $key = -1;
204 $routepriority = core_routing_getroutenames();
205 $positions=count($routepriority);
206 foreach ($routepriority as $tresult) {
207     $key++;
208         echo "\t<li>\n\t\t<a " . ($extdisplay==$tresult[0] ? 'class="current"':'') .
209             " href=\"config.php?display=" .
210             urlencode($display)."&amp;extdisplay=" .
211             urlencode($tresult[0]) . "\">$key " . substr($tresult[0],4)."</a>\n";
212
213         if ($key > 0)
214             echo "\t\t<img src=\"images/scrollup.gif\" onclick=\"repositionRoute('$key','up')\" alt='" _("Move Up") .
215                 "' style='float:none; margin-left:0px; margin-bottom:0px;' width='9' height='11'>\n";
216         else
217             echo "\t\t<img src='images/blank.gif' style='float:none; margin-left:0px; margin-bottom:0px;' width='9' height='11'>\n";
218
219         // move down
220         if ($key < ($positions-1))
221             echo "\t\t<img src='images/scrolldown.gif' onclick=\"repositionRoute('$key>','down')\" alt='" . _("Move Down") .
222                 "'  style='float:none; margin-left:0px; margin-bottom:0px;' width='9' height='11'>\n";
223         else
224             echo "\t\t<img src='images/blank.gif' style='loat:none; margin-left:0px; margin-bottom:0px;' width='9' height='11'>\n";
225             echo "\t</li>\n";
226 } // foreach
227 ?>
228 </ul>
229 </div>
230
231 <div class="content">
232
233 <?php
234 if ($extdisplay) {
235     
236     // load from db
237     
238     if (!isset($_REQUEST["dialpattern"])) {
239         $dialpattern = core_routing_getroutepatterns($extdisplay);
240     }
241     
242     if (!isset($_REQUEST["trunkpriority"])) {
243         $trunkpriority = core_routing_getroutetrunks($extdisplay);
244     }
245     
246     if (!isset($_REQUEST["routepass"])) {
247         $routepass = core_routing_getroutepassword($extdisplay);
248     }
249     
250     if (!isset($_REQUEST["emergency"])) {
251         $emergency = core_routing_getrouteemergency($extdisplay);
252     }
253     
254     if (!isset($_REQUEST["intracompany"])) {
255         $intracompany = core_routing_getrouteintracompany($extdisplay);
256     }
257
258     if (!isset($_REQUEST["mohsilence"])) {
259         $mohsilence = core_routing_getroutemohsilence($extdisplay);
260     }
261     
262     echo "<h2>"._("Edit Route")."</h2>";
263 } else {   
264     echo "<h2>"._("Add Route")."</h2>";
265 }
266
267 // build trunks associative array
268 foreach (core_trunks_list() as $temp) {
269     $trunks[$temp[0]] = $temp[1];
270     $trunkstate[$temp[0]] = $temp[2];
271 }
272
273 if ($extdisplay) { // editing
274     $tlabel = sprintf(_("Delete Route %s"),substr($extdisplay,4));
275     $label = '<span><img width="16" height="16" border="0" title="'.$tlabel.'" alt="" src="images/core_delete.png"/>&nbsp;'.$tlabel.'</span>';
276 ?>
277     <p><a href="config.php?display=<?php echo urlencode($display) ?>&extdisplay=<?php echo urlencode($extdisplay) ?>&action=delroute"><?php echo $label ?></a></p>
278 <?php 
279 }
280 ?>
281
282     <form autocomplete="off" id="routeEdit" name="routeEdit" action="config.php" method="POST" onsubmit="return routeEdit_onsubmit('<?php echo ($extdisplay ? "editroute" : "addroute") ?>');">
283         <input type="hidden" name="display" value="<?php echo $display?>"/>
284         <input type="hidden" name="extdisplay" value="<?php echo $extdisplay ?>"/>
285         <input type="hidden" id="action" name="action" value=""/>
286         <table>
287         <tr>
288             <td>
289                 <a href=# class="info"><?php echo _("Route Name")?><span><br><?php echo _("Name of this route. Should be used to describe what type of calls this route matches (for example, 'local' or 'longdistance').")?><br><br></span></a>:
290             </td>
291 <?php  if ($extdisplay) { // editing?>
292             <td>
293                 <?php echo substr($extdisplay,4);?>
294                 <input type="hidden" id="routename" name="routename" value="<?php echo $extdisplay;?>"/>
295                 <input type="button" onClick="renameRoute();" value="<?php echo _("Rename")?>" style="font-size:10px;"  />
296                 <input type="hidden" id="newroutename" name="newroutename" value=""/>
297                 <script language="javascript">
298                 function renameRoute() {
299                     do {
300                         var newname = prompt("<?php echo _("Rename route")?> " + document.getElementById('routename').value + " <?php echo _("to:")?>");
301                         if (newname == null) return;
302                     } while (!newname.match('^[a-zA-Z0-9][a-zA-Z0-9_]+$') && !alert("<?php echo _("Route name is invalid...please try again")?>"));
303                    
304                     document.getElementById('newroutename').value = newname;
305                     document.getElementById('routeEdit').action.value = 'renameroute';
306                     document.getElementById('routeEdit').submit();
307                 }
308                 </script>
309             </td>
310 <?php  } else { // new ?>
311             <td>
312                 <input type="text" size="20" name="routename" value="<?php echo htmlspecialchars($routename);?>" tabindex="<?php echo ++$tabindex;?>"/>
313             </td>
314 <?php  } ?>
315         </tr>
316         <tr>
317             <td><a href=# class="info"><?php echo _("Route Password")?>:<span><?php echo _("Optional: A route can prompt users for a password before allowing calls to progress.  This is useful for restricting calls to international destinations or 1-900 numbers.<br><br>A numerical password, or the path to an Authenticate password file can be used.<br><br>Leave this field blank to not prompt for password.</span>")?></a></td>
318             <td><input type="text" size="20" name="routepass" value="<?php echo $routepass;?>" tabindex="<?php echo ++$tabindex;?>"/></td>
319         </tr>
320 <?php
321     // implementation of module hook
322     // object was initialized in config.php
323     echo $module_hook->hookHtml;
324 ?>
325         <tr>
326             <td><a href=# class="info"><?php echo _("Emergency Dialing")?><span><?php echo _("Optional: Selecting this option will enforce the use of a device's Emergency CID setting (if set).  Select this option if this set of routes is used for emergency dialing (ie: 911).</span>")?></a>:</td>
327             <td><input type="checkbox" name="emergency" value="yes" <?php echo ($emergency ? "CHECKED" : "") ?>  tabindex="<?php echo ++$tabindex;?>"/></td>
328         </tr>
329         <tr>
330             <td><a href=# class="info"><?php echo _("Intra Company Route")?><span><?php echo _("Optional: Selecting this option will treat this route as a intra-company connection, preserving the internal Caller ID information and not use the outbound CID of either the extension or trunk.</span>")?></a>:</td>
331             <td><input type="checkbox" name="intracompany" value="yes" <?php echo ($intracompany ? "CHECKED" : "") ?>  tabindex="<?php echo ++$tabindex;?>"/></td>
332         </tr>
333 <?php   if (function_exists('music_list')) { ?>
334         <tr>
335             <td><a href="#" class="info"><?php echo _("Music On Hold?")?><span><?php echo _("You can choose which music category to use. For example, choose a type appropriate for a destination country which may have announcements in the appropriate language.")?></span></a></td>
336             <td>
337                 <select name="mohsilence" tabindex="<?php echo ++$tabindex;?>">
338                 <?php
339                     $tresults = music_list($amp_conf['ASTVARLIBDIR']."/mohmp3");
340                     $cur = (isset($mohsilence) && $mohsilence != "" ? $mohsilence : 'default');
341                     if (isset($tresults[0])) {
342                         foreach ($tresults as $tresult) {
343                             echo '<option value="'.$tresult.'"'.($tresult == $cur ? ' SELECTED' : '').'>'.$tresult."</option>\n";
344                         }
345                     }
346                 ?>       
347                 </select>       
348             </td>
349         </tr>
350 <?php } ?>
351         <tr>
352             <td colspan="2">
353                 <a href=# class="info"><?php echo _("Dial Patterns")?><span><?php echo _("A Dial Pattern is a unique set of digits that will select this trunk. Enter one dial pattern per line.")?><br><br><b><?php echo _("Rules:")?></b><br>
354    <strong>X</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 0-9")?><br>
355    <strong>Z</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 1-9")?><br>
356    <strong>N</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 2-9")?><br>
357    <strong>[1237-9]</strong>&nbsp;   <?php echo _("matches any digit or letter in the brackets (in this example, 1,2,3,7,8,9)")?><br>
358    <strong>.</strong>&nbsp;&nbsp;&nbsp; <?php echo _("wildcard, matches one or more characters")?> <br>
359    <strong>|</strong>&nbsp;&nbsp;&nbsp; <?php echo _("seperates a dialing prefix from the number (for example, 9|NXXXXXX would match when some dialed \"95551234\" but would only pass \"5551234\" to the trunks)")?>
360                 </span></a>
361             </td>
362         </tr>
363 <?php  /* old code for using textboxes -- replaced by textarea code
364 $key = -1;
365 foreach ($dialpattern as $key=>$pattern) {
366 ?>
367         <tr>
368             <td><?php echo $key ?>
369             </td><td>
370                 <input type="text" size="20" name="dialpattern[<?php echo $key ?>]" value="<?php echo $dialpattern[$key] ?>" tabindex="<?php echo ++$tabindex;?>"/>
371             </td>
372         </tr>
373 <?php
374 } // foreach
375
376 $key += 1; // this will be the next key value
377 ?>
378         <tr>
379             <td><?php echo $key ?>
380             </td><td>
381                 <input type="text" size="20" name="dialpattern[<?php echo $key ?>]" value="<?php echo $dialpattern[$key] ?>"/>
382             </td>
383         </tr>
384         <tr>
385             <td>&nbsp;</td>
386             <td>
387                 <br><input type="submit" value="<?php echo _("Add"); ?>">
388             </td>
389         </tr>
390 <?php  */ ?>
391         <tr>
392             <td>
393             </td><td>
394                 <textarea cols="20" rows="<?php  $rows = count($dialpattern)+1; echo (($rows < 5) ? 5 : (($rows > 20) ? 20 : $rows) ); ?>" id="dialpattern" name="dialpattern"><?php echo  implode("\n",$dialpattern);?></textarea><br>
395                
396                 <input type="submit" style="font-size:10px;" value="<?php echo _("Clean & Remove duplicates")?>" />
397             </td>
398         </tr>
399         <tr>
400             <td>
401             <a href=# class="info"><?php echo _("Dial patterns wizards")?><span>
402                     <strong><?php echo _("These options provide a quick way to add outbound dialing rules. Follow the prompts for each.")?><br>
403                     <strong><?php echo _("Lookup local prefixes")?></strong> <?php echo _("This looks up your local number on www.localcallingguide.com (NA-only), and sets up so you can dial either 7, 10 or 11 digits (5551234, 6135551234, 16135551234) to access this route.")?><br>
404                     </span></a>:
405             <input id="npanxx" name="npanxx" type="hidden" />
406             <script language="javascript">
407            
408             function populateLookup() {
409 <?php
410     if (function_exists("curl_init")) { // curl is installed
411 ?>                
412                 //var npanxx = prompt("What is your areacode + prefix (NPA-NXX)?", document.getElementById('areacode').value);
413                 do {
414                     var npanxx = <?php echo 'prompt("'._("What is your areacode + prefix (NPA-NXX)?\\n\\n(Note: this database contains North American numbers only, and is not guaranteed to be 100% accurate. You will still have the option of modifying results.)\\n\\nThis may take a few seconds.").'")' ?>;
415                     if (npanxx == null) return;
416                 } while (!npanxx.match("^[2-9][0-9][0-9][-]?[2-9][0-9][0-9]$") && <?php echo '!alert("'._("Invalid NPA-NXX. Must be of the format \'NXX-NXX\'").'")'?>);
417                
418                 document.getElementById('npanxx').value = npanxx;
419                 document.getElementById('routeEdit').action.value = "populatenpanxx";
420                 document.getElementById('routeEdit').submit();
421 <?php 
422     } else { // curl is not installed
423 ?>
424                 <?php echo "alert('"._("Error: Cannot continue!\\n\\nPrefix lookup requires cURL support in PHP on the server. Please install or enable cURL support in your PHP installation to use this function. See http://www.php.net/curl for more information.")."')"?>;
425 <?php
426     }
427 ?>
428             }
429            
430                        
431             function insertCode() {
432                 code = document.getElementById('inscode').value;
433                 insert = '';
434                 switch(code) {
435                     case "local":
436                         insert = 'NXXXXXX\n';
437                     break;
438                     case "local10":
439                         insert = 'NXXXXXX\n'+
440                             'NXXNXXXXXX\n';
441                     break;
442                     case 'tollfree':
443                         insert = '1800NXXXXXX\n'+
444                             '1888NXXXXXX\n'+
445                             '1877NXXXXXX\n'+
446                             '1866NXXXXXX\n';
447                     break;
448                     case "ld":
449                         insert = '1NXXNXXXXXX\n';
450                     break;
451                     case "int":
452                         insert = '011.\n';
453                     break;
454                     case 'info':
455                         insert = '411\n'+
456                             '311\n';
457                     break;
458                     case 'emerg':
459                         insert = '911\n';
460                     break;
461                     case 'lookup':
462                         populateLookup();
463                         insert = '';
464                     break;
465                    
466                 }
467                 dialPattern=document.getElementById('dialpattern');
468                 if (dialPattern.value[ dialPattern.value.length - 1 ] == "\n") {
469                     dialPattern.value = dialPattern.value + insert;
470                 } else {
471                     dialPattern.value = dialPattern.value + '\n' + insert;
472                 }
473                
474                 // reset element
475                 document.getElementById('inscode').value = '';
476             }
477            
478             --></script>
479             <td>
480                 <select onChange="insertCode();" id="inscode">
481             <option value=""><?php echo _("(pick one)")?></option>
482             <option value="local"><?php echo _("Local 7 digit")?></option>
483             <option value="local10"><?php echo _("Local 7/10 digit")?></option>
484             <option value="tollfree"><?php echo _("Toll-free")?></option>
485             <option value="ld"><?php echo _("Long-distance")?></option>
486             <option value="int"><?php echo _("International")?></option>
487             <option value="info"><?php echo _("Information")?></option>
488             <option value="emerg"><?php echo _("Emergency")?></option>
489             <option value="lookup"><?php echo _("Lookup local prefixes")?></option>
490                 </select>
491             </td>
492         </tr>
493         <tr>
494             <td colspan="2">
495                 <a href=# class="info"><?php echo _("Trunk Sequence")?><span><?php echo _("The Trunk Sequence controls the order of trunks that will be used when the above Dial Patterns are matched. <br><br>For Dial Patterns that match long distance numbers, for example, you'd want to pick the cheapest routes for long distance (ie, VoIP trunks first) followed by more expensive routes (POTS lines).")?><br></span></a>
496             </td>
497         </tr>
498         <input type="hidden" id="repotrunkdirection" name="repotrunkdirection" value="">
499         <input type="hidden" id="repotrunkkey" name="repotrunkkey" value="">
500         <input type="hidden" id="reporoutedirection" name="reporoutedirection" value="">
501         <input type="hidden" id="reporoutekey" name="reporoutekey" value="">
502 <?php
503 $key = -1;
504 $positions=count($trunkpriority);
505 foreach ($trunkpriority as $key=>$trunk) {
506 ?>
507         <tr>
508             <td align="right"><?php echo $key; ?>&nbsp;&nbsp;
509             </td>
510             <td>
511         <select id='trunkpri<?php echo $key ?>' name="trunkpriority[<?php echo $key ?>]" style="background: <?php echo $trunkstate[$trunk]=="off"?"#FFF":"#DDD" ?> ;" onChange="showDisable(<?php echo $key ?>); return true;">
512                 <option value="" style="background: #FFF;"></option>
513                 <?php
514                 foreach ($trunks as $name=>$display_description) {
515                     if ($trunkstate[$name] == 'off') {
516                         echo "<option id=\"trunk".$key."\" name=\"trunk".$key."\" value=\"".$name."\" style=\"background: #FFF;\" ".($name == $trunk ? "selected" : "").">".str_replace('AMP:', '', $display_description)."</option>";
517                     } else {
518                         echo "<option id=\"trunk".$key."\" name=\"trunk".$key."\" value=\"".$name."\" style=\"background: #DDD;\" ".($name == $trunk ? "selected" : "").">".str_replace('AMP:', '', $display_description)."</option>";
519                     }
520                 }
521                 ?>
522                 </select>
523                
524                 <img src="images/trash.png" style="float:none; margin-left:0px; margin-bottom:0px;" title="Click here to remove this trunk" onclick="deleteTrunk(<?php echo $key ?>)">
525             <?php   // move up
526             if ($key > 0) {?>
527                 <img src="images/scrollup.gif" onclick="repositionTrunk('<?php echo $key ?>','up')" alt="<?php echo _("Move Up")?>" style="float:none; margin-left:0px; margin-bottom:0px;" width="9" height="11">
528             <?php  } else { ?>
529                 <img src="images/blank.gif" style="float:none; margin-left:0px; margin-bottom:0px;" width="9" height="11">
530             <?php  }
531             
532             // move down
533             
534             if ($key < ($positions-1)) {?>
535                 <img src="images/scrolldown.gif" onclick="repositionTrunk('<?php echo $key ?>','down')" alt="<?php echo _("Move Down")?>"  style="float:none; margin-left:0px; margin-bottom:0px;" width="9" height="11">
536             <?php  } else { ?>
537                 <img src="images/blank.gif" style="float:none; margin-left:0px; margin-bottom:0px;" width="9" height="11">
538             <?php  } ?>
539             </td>
540         </tr>
541 <?php
542 } // foreach
543
544 $key += 1; // this will be the next key value
545 $name = "";
546
547 // display 1 additional box if editing, or one for each trunk (to a max of 3)
548 $num_new_boxes = ($extdisplay ? 1 : ((count($trunks) > 3) ? 3 : count($trunks)));
549
550 for ($i=0; $i < $num_new_boxes; $i++) {
551 ?>
552         <tr>
553             <td> &nbsp </td>
554             <td>
555                 <select id='trunkpri<?php echo $key ?>' name="trunkpriority[<?php echo $key ?>]">
556                 <option value="" SELECTED></option>
557                 <?php
558                 foreach ($trunks as $name=>$display_description) {
559                     if ($trunkstate[$name] == 'off') {
560                     echo "<option value=\"".$name."\">".str_replace('AMP:', '', $display_description)."</option>";
561                     } else {
562                     echo "<option value=\"".$name."\" style=\"background: #DDD;\" >*".ltrim($display_description,"AMP:")."*</option>";
563                     }
564                 }
565                 ?>
566                 </select>
567             </td>
568         </tr>
569 <?php
570     $key++;
571 } //for 0..$num_new_boxes ?>
572
573 <?php if ($extdisplay): // editing ?>
574         <tr>
575             <td></td>
576             <td>
577                 <input type="submit" value="<?php echo _("Add")?>">
578             </td>
579         </tr>
580 <?php endif; // if $extdisplay ?>
581         <tr>
582             <td colspan="2">
583                 <h6><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>">
584                 </h6>
585             </td>
586         </tr>
587         </table>
588  
589 <script language="javascript">
590 <!--
591
592 var theForm = document.routeEdit;
593
594 if (theForm.routename.value == "") {
595     theForm.routename.focus();
596 } else {
597     theForm.routepass.focus();
598 }
599
600 function showDisable(key) {
601 <?php
602     $bgmap = 'bgc = {';
603     foreach ($trunks as $name=>$display_description) {
604         $bgmap .= " \"$name\":";
605         $bgmap .= ($trunkstate[$name] == 'off')?'"#FFF",':'"#DDD",';
606     }
607     echo rtrim($bgmap,',')." };\n";
608 ?>
609     if (document.getElementById('trunkpri'+key).value =='') {
610         document.getElementById('trunkpri'+key).style.background = '#FFF';
611     } else {
612         document.getElementById('trunkpri'+key).style.background = bgc[document.getElementById('trunkpri'+key).value];
613     }
614 }
615
616 function routeEdit_onsubmit(act) {
617     var msgInvalidRouteName = "<?php echo _('Route name is invalid, please try again'); ?>";
618     var msgInvalidRoutePwd = "<?php echo _('Route password must be numberic or leave blank to disable'); ?>";
619     var msgInvalidDialPattern = "<?php echo _('Dial pattern is invalid'); ?>";
620     var msgInvalidTrunkSelection = "<?php echo _('At least one trunk must be picked'); ?>";
621    
622     defaultEmptyOK = false;
623     if (isEmpty(theForm.routename.value))
624         return warnInvalid(theForm.routename, msgInvalidRouteName);
625    
626     defaultEmptyOK = true;
627     if (!isInteger(theForm.routepass.value))
628         return warnInvalid(theForm.routepass, msgInvalidRoutePwd);
629    
630     defaultEmptyOK = false;
631     if (!isDialpattern(theForm.dialpattern.value))
632         return warnInvalid(theForm.dialpattern, msgInvalidDialPattern);
633        
634     if (theForm.trunkpri0.value == "") { // should they all be checked ?
635         theForm.trunkpri0.focus();
636         alert(msgInvalidTrunkSelection);
637         return false;
638     }
639    
640     theForm.action.value = act;
641     return true;
642 }
643
644 function repositionTrunk(key,direction) {
645     if(direction == "up"){
646         document.getElementById('repotrunkdirection').value=direction;
647         document.getElementById('repotrunkkey').value=key;
648     }else if(direction == "down" ){
649         document.getElementById('repotrunkdirection').value=direction;
650         document.getElementById('repotrunkkey').value=key;
651     }
652     document.getElementById('routeEdit').submit();
653 }
654
655 function deleteTrunk(key) {
656     document.getElementById('trunkpri'+key).value = '';
657     document.getElementById('routeEdit').submit();
658 }
659
660 function repositionRoute(key,direction){
661     if(direction == "up"){
662         document.getElementById('reporoutedirection').value=direction;
663         document.getElementById('reporoutekey').value=key;
664     }else if(direction == "down" ){
665         document.getElementById('reporoutedirection').value=direction;
666         document.getElementById('reporoutekey').value=key;
667     }
668     document.getElementById('action').value='prioritizeroute';
669     document.getElementById('routeEdit').submit();
670 }
671
672 //-->
673 </script>
674
675 </form>
676
677
Note: See TracBrowser for help on using the browser.