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

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

Merged revisions 5572 via svnmerge from
http://svn.freepbx.org/modules/branches/2.4

........

r5572 | pnlarsson | 2008-01-12 08:48:07 -0800 (Sat, 12 Jan 2008) | 1 line


Fixes #2607, Custom trunks stripped of starting A or M or P

........

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