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

Revision 5762, 25.4 kB (checked in by p_lindheimer, 4 years ago)

#2604: fix mal-formed html select tags causing problems with some browsers or proxies

  • 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 ?>
275   <p><a href="config.php?display=<?php echo urlencode($display) ?>&extdisplay=<?php echo urlencode($extdisplay) ?>&action=delroute"><?php echo _("Delete Route")?> <?php  echo substr($extdisplay,4); ?></a></p>
276 <?php  } ?>
277
278   <form autocomplete="off" id="routeEdit" name="routeEdit" action="config.php" method="POST" onsubmit="return routeEdit_onsubmit('<?php echo ($extdisplay ? "editroute" : "addroute") ?>');">
279     <input type="hidden" name="display" value="<?php echo $display?>"/>
280     <input type="hidden" name="extdisplay" value="<?php echo $extdisplay ?>"/>
281     <input type="hidden" id="action" name="action" value=""/>
282     <table>
283     <tr>
284       <td>
285         <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>:
286       </td>
287 <?php  if ($extdisplay) { // editing?>
288       <td>
289         <?php echo substr($extdisplay,4);?>
290         <input type="hidden" id="routename" name="routename" value="<?php echo $extdisplay;?>"/>
291         <input type="button" onClick="renameRoute();" value="<?php echo _("Rename")?>" style="font-size:10px;"  />
292         <input type="hidden" id="newroutename" name="newroutename" value=""/>
293         <script language="javascript">
294         function renameRoute() {
295           do {
296             var newname = prompt("<?php echo _("Rename route")?> " + document.getElementById('routename').value + " <?php echo _("to:")?>");
297             if (newname == null) return;
298           } while (!newname.match('^[a-zA-Z0-9][a-zA-Z0-9_]+$') && !alert("<?php echo _("Route name is invalid...please try again")?>"));
299           
300           document.getElementById('newroutename').value = newname;
301           document.getElementById('routeEdit').action.value = 'renameroute';
302           document.getElementById('routeEdit').submit();
303         }
304         </script>
305       </td>
306 <?php  } else { // new ?>
307       <td>
308         <input type="text" size="20" name="routename" value="<?php echo htmlspecialchars($routename);?>"/>
309       </td>
310 <?php  } ?>
311     </tr>
312     <tr>
313       <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>
314       <td><input type="text" size="20" name="routepass" value="<?php echo $routepass;?>"/></td>
315     </tr>
316 <?php
317   // implementation of module hook
318   // object was initialized in config.php
319   echo $module_hook->hookHtml;
320 ?>
321     <tr>
322       <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>
323       <td><input type="checkbox" name="emergency" value="yes" <?php echo ($emergency ? "CHECKED" : "") ?> /></td>
324     </tr>
325     <tr>
326       <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>
327       <td><input type="checkbox" name="intracompany" value="yes" <?php echo ($intracompany ? "CHECKED" : "") ?> /></td>
328     </tr>
329 <?php   if (function_exists('music_list')) { ?>
330     <tr>
331       <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>
332       <td>
333         <select name="mohsilence">
334         <?php
335           $tresults = music_list($amp_conf['ASTVARLIBDIR']."/mohmp3");
336           $cur = (isset($mohsilence) && $mohsilence != "" ? $mohsilence : 'default');
337           if (isset($tresults[0])) {
338             foreach ($tresults as $tresult) {
339               echo '<option value="'.$tresult.'"'.($tresult == $cur ? ' SELECTED' : '').'>'.$tresult."</option>\n";
340             }
341           }
342         ?>   
343         </select>   
344       </td>
345     </tr>
346 <?php } ?>
347     <tr>
348       <td colspan="2">
349         <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>
350    <strong>X</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 0-9")?><br>
351    <strong>Z</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 1-9")?><br>
352    <strong>N</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 2-9")?><br>
353    <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>
354    <strong>.</strong>&nbsp;&nbsp;&nbsp; <?php echo _("wildcard, matches one or more characters")?> <br>
355    <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)")?>
356         </span></a>
357       </td>
358     </tr>
359 <?php  /* old code for using textboxes -- replaced by textarea code
360 $key = -1;
361 foreach ($dialpattern as $key=>$pattern) {
362 ?>
363     <tr>
364       <td><?php echo $key ?>
365       </td><td>
366         <input type="text" size="20" name="dialpattern[<?php echo $key ?>]" value="<?php echo $dialpattern[$key] ?>"/>
367       </td>
368     </tr>
369 <?php
370 } // foreach
371
372 $key += 1; // this will be the next key value
373 ?>
374     <tr>
375       <td><?php echo $key ?>
376       </td><td>
377         <input type="text" size="20" name="dialpattern[<?php echo $key ?>]" value="<?php echo $dialpattern[$key] ?>"/>
378       </td>
379     </tr>
380     <tr>
381       <td>&nbsp;</td>
382       <td>
383         <br><input type="submit" value="<?php echo _("Add"); ?>">
384       </td>
385     </tr>
386 <?php */ ?>
387     <tr>
388       <td>
389       </td><td>
390         <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>
391         
392         <input type="submit" style="font-size:10px;" value="<?php echo _("Clean & Remove duplicates")?>" />
393       </td>
394     </tr>
395     <tr>
396       <td>
397       <a href=# class="info"><?php echo _("Dial patterns wizards")?><span>
398           <strong><?php echo _("These options provide a quick way to add outbound dialing rules. Follow the prompts for each.")?><br>
399           <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>
400           </span></a>:
401       <input id="npanxx" name="npanxx" type="hidden" />
402       <script language="javascript">
403       
404       function populateLookup() {
405 <?php 
406   if (function_exists("curl_init")) { // curl is installed
407 ?>        
408         //var npanxx = prompt("What is your areacode + prefix (NPA-NXX)?", document.getElementById('areacode').value);
409         do {
410           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.").'")' ?>;
411           if (npanxx == null) return;
412         } 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\'").'")'?>);
413         
414         document.getElementById('npanxx').value = npanxx;
415         document.getElementById('routeEdit').action.value = "populatenpanxx";
416         document.getElementById('routeEdit').submit();
417 <?php 
418   } else { // curl is not installed
419 ?>
420         <?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.")."')"?>;
421 <?php 
422   }
423 ?>
424       }
425       
426             
427       function insertCode() {
428         code = document.getElementById('inscode').value;
429         insert = '';
430         switch(code) {
431           case "local":
432             insert = 'NXXXXXX\n';
433           break;
434           case "local10":
435             insert = 'NXXXXXX\n'+
436               'NXXNXXXXXX\n';
437           break;
438           case 'tollfree':
439             insert = '1800NXXXXXX\n'+
440               '1888NXXXXXX\n'+
441               '1877NXXXXXX\n'+
442               '1866NXXXXXX\n';
443           break;
444           case "ld":
445             insert = '1NXXNXXXXXX\n';
446           break;
447           case "int":
448             insert = '011.\n';
449           break;
450           case 'info':
451             insert = '411\n'+
452               '311\n';
453           break;
454           case 'emerg':
455             insert = '911\n';
456           break;
457           case 'lookup':
458             populateLookup();
459             insert = '';
460           break;
461           
462         }
463         dialPattern=document.getElementById('dialpattern');
464         if (dialPattern.value[ dialPattern.value.length - 1 ] == "\n") {
465           dialPattern.value = dialPattern.value + insert;
466         } else {
467           dialPattern.value = dialPattern.value + '\n' + insert;
468         }
469         
470         // reset element
471         document.getElementById('inscode').value = '';
472       }
473       
474       --></script>
475       <td>
476         <select onChange="insertCode();" id="inscode">
477       <option value=""><?php echo _("(pick one)")?></option>
478       <option value="local"><?php echo _("Local 7 digit")?></option>
479       <option value="local10"><?php echo _("Local 7/10 digit")?></option>
480       <option value="tollfree"><?php echo _("Toll-free")?></option>
481       <option value="ld"><?php echo _("Long-distance")?></option>
482       <option value="int"><?php echo _("International")?></option>
483       <option value="info"><?php echo _("Information")?></option>
484       <option value="emerg"><?php echo _("Emergency")?></option>
485       <option value="lookup"><?php echo _("Lookup local prefixes")?></option>
486         </select>
487       </td>
488     </tr>
489     <tr>
490       <td colspan="2">
491         <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>
492       </td>
493     </tr>
494     <input type="hidden" id="repotrunkdirection" name="repotrunkdirection" value="">
495     <input type="hidden" id="repotrunkkey" name="repotrunkkey" value="">
496     <input type="hidden" id="reporoutedirection" name="reporoutedirection" value="">
497     <input type="hidden" id="reporoutekey" name="reporoutekey" value="">
498 <?php 
499 $key = -1;
500 $positions=count($trunkpriority);
501 foreach ($trunkpriority as $key=>$trunk) {
502 ?>
503     <tr>
504       <td align="right"><?php echo $key; ?>&nbsp;&nbsp;
505       </td>
506       <td>
507     <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;">
508         <option value="" style="background: #FFF;"></option>
509         <?php
510         foreach ($trunks as $name=>$display_description) {
511           if ($trunkstate[$name] == 'off') {
512             echo "<option id=\"trunk".$key."\" name=\"trunk".$key."\" value=\"".$name."\" style=\"background: #FFF;\" ".($name == $trunk ? "selected" : "").">".str_replace('AMP:', '', $display_description)."</option>";
513           } else {
514             echo "<option id=\"trunk".$key."\" name=\"trunk".$key."\" value=\"".$name."\" style=\"background: #DDD;\" ".($name == $trunk ? "selected" : "").">".str_replace('AMP:', '', $display_description)."</option>";
515           }
516         }
517         ?>
518         </select>
519         
520         <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 ?>)">
521       <?php   // move up
522       if ($key > 0) {?>
523         <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">
524       <?php  } else { ?>
525         <img src="images/blank.gif" style="float:none; margin-left:0px; margin-bottom:0px;" width="9" height="11">
526       <?php  }
527      
528       // move down
529      
530       if ($key < ($positions-1)) {?>
531         <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">
532       <?php  } else { ?>
533         <img src="images/blank.gif" style="float:none; margin-left:0px; margin-bottom:0px;" width="9" height="11">
534       <?php  } ?>
535       </td>
536     </tr>
537 <?php 
538 } // foreach
539
540 $key += 1; // this will be the next key value
541 $name = "";
542
543 // display 1 additional box if editing, or one for each trunk (to a max of 3)
544 $num_new_boxes = ($extdisplay ? 1 : ((count($trunks) > 3) ? 3 : count($trunks)));
545
546 for ($i=0; $i < $num_new_boxes; $i++) {
547 ?>
548     <tr>
549       <td> &nbsp </td>
550       <td>
551         <select id='trunkpri<?php echo $key ?>' name="trunkpriority[<?php echo $key ?>]">
552         <option value="" SELECTED></option>
553         <?php
554         foreach ($trunks as $name=>$display_description) {
555           if ($trunkstate[$name] == 'off') {
556           echo "<option value=\"".$name."\">".str_replace('AMP:', '', $display_description)."</option>";
557           } else {
558           echo "<option value=\"".$name."\" style=\"background: #DDD;\" >*".ltrim($display_description,"AMP:")."*</option>";
559           }
560         }
561         ?>
562         </select>
563       </td>
564     </tr>
565 <?php 
566   $key++;
567 } //for 0..$num_new_boxes ?>
568
569 <?php if ($extdisplay): // editing ?>
570     <tr>
571       <td></td>
572       <td>
573         <input type="submit" value="<?php echo _("Add")?>">
574       </td>
575     </tr>
576 <?php endif; // if $extdisplay ?>
577     <tr>
578       <td colspan="2">
579         <h6><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>">
580         </h6>
581       </td>
582     </tr>
583     </table>
584  
585 <script language="javascript">
586 <!--
587
588 var theForm = document.routeEdit;
589
590 if (theForm.routename.value == "") {
591   theForm.routename.focus();
592 } else {
593   theForm.routepass.focus();
594 }
595
596 function showDisable(key) {
597 <?php
598   $bgmap = 'bgc = {';
599   foreach ($trunks as $name=>$display_description) {
600     $bgmap .= " \"$name\":";
601     $bgmap .= ($trunkstate[$name] == 'off')?'"#FFF",':'"#DDD",';
602   }
603   echo rtrim($bgmap,',')." };\n";
604 ?>
605   if (document.getElementById('trunkpri'+key).value =='') {
606     document.getElementById('trunkpri'+key).style.background = '#FFF';
607   } else {
608     document.getElementById('trunkpri'+key).style.background = bgc[document.getElementById('trunkpri'+key).value];
609   }
610 }
611
612 function routeEdit_onsubmit(act) {
613   var msgInvalidRouteName = "<?php echo _('Route name is invalid, please try again'); ?>";
614   var msgInvalidRoutePwd = "<?php echo _('Route password must be numberic or leave blank to disable'); ?>";
615   var msgInvalidDialPattern = "<?php echo _('Dial pattern is invalid'); ?>";
616   var msgInvalidTrunkSelection = "<?php echo _('At least one trunk must be picked'); ?>";
617  
618   defaultEmptyOK = false;
619   if (isEmpty(theForm.routename.value))
620     return warnInvalid(theForm.routename, msgInvalidRouteName);
621  
622   defaultEmptyOK = true;
623   if (!isInteger(theForm.routepass.value))
624     return warnInvalid(theForm.routepass, msgInvalidRoutePwd);
625  
626   defaultEmptyOK = false;
627   if (!isDialpattern(theForm.dialpattern.value))
628     return warnInvalid(theForm.dialpattern, msgInvalidDialPattern);
629     
630   if (theForm.trunkpri0.value == "") { // should they all be checked ?
631     theForm.trunkpri0.focus();
632     alert(msgInvalidTrunkSelection);
633     return false;
634   }
635  
636   theForm.action.value = act;
637   return true;
638 }
639
640 function repositionTrunk(key,direction) {
641   if(direction == "up"){
642     document.getElementById('repotrunkdirection').value=direction;
643     document.getElementById('repotrunkkey').value=key;
644   }else if(direction == "down" ){
645     document.getElementById('repotrunkdirection').value=direction;
646     document.getElementById('repotrunkkey').value=key;
647   }
648   document.getElementById('routeEdit').submit();
649 }
650
651 function deleteTrunk(key) {
652   document.getElementById('trunkpri'+key).value = '';
653   document.getElementById('routeEdit').submit();
654 }
655
656 function repositionRoute(key,direction){
657   if(direction == "up"){
658     document.getElementById('reporoutedirection').value=direction;
659     document.getElementById('reporoutekey').value=key;
660   }else if(direction == "down" ){
661     document.getElementById('reporoutedirection').value=direction;
662     document.getElementById('reporoutekey').value=key;
663   }
664   document.getElementById('action').value='prioritizeroute';
665   document.getElementById('routeEdit').submit();
666 }
667
668 //-->
669 </script>
670
671 </form>
Note: See TracBrowser for help on using the browser.