| 1 |
<?php |
|---|
| 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 |
|
|---|
| 27 |
$dialpattern = explode("\n",$_REQUEST["dialpattern"]); |
|---|
| 28 |
|
|---|
| 29 |
if (!$dialpattern) { |
|---|
| 30 |
$dialpattern = array(); |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
foreach (array_keys($dialpattern) as $key) { |
|---|
| 34 |
|
|---|
| 35 |
$dialpattern[$key] = trim($dialpattern[$key]); |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
if ($dialpattern[$key] == "") unset($dialpattern[$key]); |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
if ($dialpattern[$key][0] == "_") $dialpattern[$key] = substr($dialpattern[$key],1); |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 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 |
|
|---|
| 62 |
foreach (array_keys($trunkpriority) as $key) { |
|---|
| 63 |
if (empty($trunkpriority[$key])) { |
|---|
| 64 |
|
|---|
| 65 |
unset($trunkpriority[$key]); |
|---|
| 66 |
|
|---|
| 67 |
} else if (($key==($repotrunkkey-1)) && ($repotrunkdirection=="up")) { |
|---|
| 68 |
|
|---|
| 69 |
$temptrunk = $trunkpriority[$key]; |
|---|
| 70 |
$trunkpriority[ $key ] = $trunkpriority[ $key+1 ]; |
|---|
| 71 |
$trunkpriority[ $key+1 ] = $temptrunk; |
|---|
| 72 |
|
|---|
| 73 |
} else if (($key==($repotrunkkey)) && ($repotrunkdirection=="down")) { |
|---|
| 74 |
|
|---|
| 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); |
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 146 |
|
|---|
| 147 |
// always drop 1 prefix |
|---|
| 148 |
$dialpattern[] = '1|NXXNXXXXXX'; |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
foreach ($xmldata['lca-data']['prefix'] as $prefix) { |
|---|
| 152 |
$dialpattern[] = $prefix['npa'].$prefix['nxx'].'XXXX'; |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
foreach ($xmldata['lca-data']['prefix'] as $prefix) { |
|---|
| 156 |
$dialpattern[] = $prefix['npa'].'+'.$prefix['nxx'].'XXXX'; |
|---|
| 157 |
} |
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
$dialpattern = array_values(array_unique($dialpattern)); |
|---|
| 161 |
} else { |
|---|
| 162 |
$errormsg = _("Error fetching prefix list for: "). $_REQUEST["npanxx"]; |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
} else { |
|---|
| 166 |
|
|---|
| 167 |
$errormsg = _("Invalid format for NPA-NXX code (must be format: NXXNXX)"); |
|---|
| 168 |
} |
|---|
| 169 |
|
|---|
| 170 |
if (isset($errormsg)) { |
|---|
| 171 |
echo "<script language=\"javascript\">alert('".addslashes($errormsg)."');</script>"; |
|---|
| 172 |
unset($errormsg); |
|---|
| 173 |
} |
|---|
| 174 |
break; |
|---|
| 175 |
} |
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
$sql = "SELECT * FROM globals"; |
|---|
| 181 |
$globals = $db->getAll($sql); |
|---|
| 182 |
if(DB::IsError($globals)) { |
|---|
| 183 |
die($globals->getMessage()); |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
foreach ($globals as $global) { |
|---|
| 188 |
${trim($global[0])} = htmlentities($global[1]); |
|---|
| 189 |
} |
|---|
| 190 |
|
|---|
| 191 |
?> |
|---|
| 192 |
</div> |
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
<div class="rnav"> |
|---|
| 197 |
<ul> |
|---|
| 198 |
<li><a <?php echo ($extdisplay=='' ? 'class="current"':'') ?> href="config.php?display=<?php echo urlencode($display)?>"><?php echo _("Add Route")?></a></li> |
|---|
| 199 |
<?php |
|---|
| 200 |
$reporoutedirection = isset($_REQUEST['reporoutedirection'])?$_REQUEST['reporoutedirection']:''; |
|---|
| 201 |
$reporoutekey = isset($_REQUEST['reporoutekey'])?$_REQUEST['reporoutekey']:''; |
|---|
| 202 |
$key = -1; |
|---|
| 203 |
$routepriority = core_routing_getroutenames(); |
|---|
| 204 |
$positions=count($routepriority); |
|---|
| 205 |
foreach ($routepriority as $tresult) { |
|---|
| 206 |
$key++; |
|---|
| 207 |
echo "\t<li>\n\t\t<a " . ($extdisplay==$tresult[0] ? 'class="current"':'') . |
|---|
| 208 |
" href=\"config.php?display=" . |
|---|
| 209 |
urlencode($display)."&extdisplay=" . |
|---|
| 210 |
urlencode($tresult[0]) . "\">$key " . substr($tresult[0],4)."</a>\n"; |
|---|
| 211 |
|
|---|
| 212 |
if ($key > 0) |
|---|
| 213 |
echo "\t\t<img src=\"images/scrollup.gif\" onclick=\"repositionRoute('$key','up')\" alt='" . _("Move Up") . |
|---|
| 214 |
"' style='float:none; margin-left:0px; margin-bottom:0px;' width='9' height='11'>\n"; |
|---|
| 215 |
else |
|---|
| 216 |
echo "\t\t<img src='images/blank.gif' style='float:none; margin-left:0px; margin-bottom:0px;' width='9' height='11'>\n"; |
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
if ($key < ($positions-1)) |
|---|
| 220 |
echo "\t\t<img src='images/scrolldown.gif' onclick=\"repositionRoute('$key>','down')\" alt='" . _("Move Down") . |
|---|
| 221 |
"' style='float:none; margin-left:0px; margin-bottom:0px;' width='9' height='11'>\n"; |
|---|
| 222 |
else |
|---|
| 223 |
echo "\t\t<img src='images/blank.gif' style='loat:none; margin-left:0px; margin-bottom:0px;' width='9' height='11'>\n"; |
|---|
| 224 |
echo "\t</li>\n"; |
|---|
| 225 |
} |
|---|
| 226 |
?> |
|---|
| 227 |
</ul> |
|---|
| 228 |
</div> |
|---|
| 229 |
|
|---|
| 230 |
<div class="content"> |
|---|
| 231 |
|
|---|
| 232 |
<?php |
|---|
| 233 |
if ($extdisplay) { |
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
if (!isset($_REQUEST["dialpattern"])) { |
|---|
| 238 |
$dialpattern = core_routing_getroutepatterns($extdisplay); |
|---|
| 239 |
} |
|---|
| 240 |
|
|---|
| 241 |
if (!isset($_REQUEST["trunkpriority"])) { |
|---|
| 242 |
$trunkpriority = core_routing_getroutetrunks($extdisplay); |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
if (!isset($_REQUEST["routepass"])) { |
|---|
| 246 |
$routepass = core_routing_getroutepassword($extdisplay); |
|---|
| 247 |
} |
|---|
| 248 |
|
|---|
| 249 |
if (!isset($_REQUEST["emergency"])) { |
|---|
| 250 |
$emergency = core_routing_getrouteemergency($extdisplay); |
|---|
| 251 |
} |
|---|
| 252 |
|
|---|
| 253 |
if (!isset($_REQUEST["intracompany"])) { |
|---|
| 254 |
$intracompany = core_routing_getrouteintracompany($extdisplay); |
|---|
| 255 |
} |
|---|
| 256 |
|
|---|
| 257 |
if (!isset($_REQUEST["mohsilence"])) { |
|---|
| 258 |
$mohsilence = core_routing_getroutemohsilence($extdisplay); |
|---|
| 259 |
} |
|---|
| 260 |
|
|---|
| 261 |
echo "<h2>"._("Edit Route")."</h2>"; |
|---|
| 262 |
} else { |
|---|
| 263 |
echo "<h2>"._("Add Route")."</h2>"; |
|---|
| 264 |
} |
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
foreach (core_trunks_list() as $temp) { |
|---|
| 268 |
$trunks[$temp[0]] = $temp[1]; |
|---|
| 269 |
} |
|---|
| 270 |
|
|---|
| 271 |
if ($extdisplay) { |
|---|
| 272 |
?> |
|---|
| 273 |
<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> |
|---|
| 274 |
<?php } ?> |
|---|
| 275 |
|
|---|
| 276 |
<form autocomplete="off" id="routeEdit" name="routeEdit" action="config.php" method="POST" onsubmit="return routeEdit_onsubmit('<?php echo ($extdisplay ? "editroute" : "addroute") ?>');"> |
|---|
| 277 |
<input type="hidden" name="display" value="<?php echo $display?>"/> |
|---|
| 278 |
<input type="hidden" name="extdisplay" value="<?php echo $extdisplay ?>"/> |
|---|
| 279 |
<input type="hidden" id="action" name="action" value=""/> |
|---|
| 280 |
<table> |
|---|
| 281 |
<tr> |
|---|
| 282 |
<td> |
|---|
| 283 |
<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>: |
|---|
| 284 |
</td> |
|---|
| 285 |
<?php if ($extdisplay) { ?> |
|---|
| 286 |
<td> |
|---|
| 287 |
<?php echo substr($extdisplay,4);?> |
|---|
| 288 |
<input type="hidden" id="routename" name="routename" value="<?php echo $extdisplay;?>"/> |
|---|
| 289 |
<input type="button" onClick="renameRoute();" value="<?php echo _("Rename")?>" style="font-size:10px;" /> |
|---|
| 290 |
<input type="hidden" id="newroutename" name="newroutename" value=""/> |
|---|
| 291 |
<script language="javascript"> |
|---|
| 292 |
function renameRoute() { |
|---|
| 293 |
do { |
|---|
| 294 |
var newname = prompt("<?php echo _("Rename route")?> " + document.getElementById('routename').value + " <?php echo _("to:")?>"); |
|---|
| 295 |
if (newname == null) return; |
|---|
| 296 |
} while (!newname.match('^[a-zA-Z0-9][a-zA-Z0-9]+$') && !alert("<?php echo _("Route name is invalid...please try again")?>")); |
|---|
| 297 |
|
|---|
| 298 |
document.getElementById('newroutename').value = newname; |
|---|
| 299 |
document.getElementById('routeEdit').action.value = 'renameroute'; |
|---|
| 300 |
document.getElementById('routeEdit').submit(); |
|---|
| 301 |
} |
|---|
| 302 |
</script> |
|---|
| 303 |
</td> |
|---|
| 304 |
<?php } else { ?> |
|---|
| 305 |
<td> |
|---|
| 306 |
<input type="text" size="20" name="routename" value="<?php echo htmlspecialchars($routename);?>"/> |
|---|
| 307 |
</td> |
|---|
| 308 |
<?php } ?> |
|---|
| 309 |
</tr> |
|---|
| 310 |
<tr> |
|---|
| 311 |
<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> |
|---|
| 312 |
<td><input type="text" size="20" name="routepass" value="<?php echo $routepass;?>"/></td> |
|---|
| 313 |
</tr> |
|---|
| 314 |
<?php |
|---|
| 315 |
|
|---|
| 316 |
// object was initialized in config.php |
|---|
| 317 |
echo $module_hook->hookHtml; |
|---|
| 318 |
?> |
|---|
| 319 |
<tr> |
|---|
| 320 |
<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> |
|---|
| 321 |
<td><input type="checkbox" name="emergency" value="yes" <?php echo ($emergency ? "CHECKED" : "") ?> /></td> |
|---|
| 322 |
</tr> |
|---|
| 323 |
<tr> |
|---|
| 324 |
<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> |
|---|
| 325 |
<td><input type="checkbox" name="intracompany" value="yes" <?php echo ($intracompany ? "CHECKED" : "") ?> /></td> |
|---|
| 326 |
</tr> |
|---|
| 327 |
<?php if (function_exists('music_list')) { ?> |
|---|
| 328 |
<tr> |
|---|
| 329 |
<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> |
|---|
| 330 |
<td> |
|---|
| 331 |
<select name="mohsilence"/> |
|---|
| 332 |
<?php |
|---|
| 333 |
$tresults = music_list("/var/lib/asterisk/mohmp3"); |
|---|
| 334 |
$cur = (isset($mohsilence) && $mohsilence != "" ? $mohsilence : 'default'); |
|---|
| 335 |
if (isset($tresults[0])) { |
|---|
| 336 |
foreach ($tresults as $tresult) { |
|---|
| 337 |
echo '<option value="'.$tresult.'"'.($tresult == $cur ? ' SELECTED' : '').'>'.$tresult."</option>\n"; |
|---|
| 338 |
} |
|---|
| 339 |
} |
|---|
| 340 |
?> |
|---|
| 341 |
</select> |
|---|
| 342 |
</td> |
|---|
| 343 |
</tr> |
|---|
| 344 |
<?php } ?> |
|---|
| 345 |
<tr> |
|---|
| 346 |
<td colspan="2"> |
|---|
| 347 |
<br> |
|---|
| 348 |
<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> |
|---|
| 349 |
<strong>X</strong> <?php echo _("matches any digit from 0-9")?><br> |
|---|
| 350 |
<strong>Z</strong> <?php echo _("matches any digit from 1-9")?><br> |
|---|
| 351 |
<strong>N</strong> <?php echo _("matches any digit from 2-9")?><br> |
|---|
| 352 |
<strong>[1237-9]</strong> <?php echo _("matches any digit or letter in the brackets (in this example, 1,2,3,7,8,9)")?><br> |
|---|
| 353 |
<strong>.</strong> <?php echo _("wildcard, matches one or more characters")?> <br> |
|---|
| 354 |
<strong>|</strong> <?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)")?> |
|---|
| 355 |
</span></a><br><br> |
|---|
| 356 |
</td> |
|---|
| 357 |
</tr> |
|---|
| 358 |
<?php |
|---|
| 359 |
$key = -1; |
|---|
| 360 |
foreach ($dialpattern as $key=>$pattern) { |
|---|
| 361 |
?> |
|---|
| 362 |
<tr> |
|---|
| 363 |
<td><?php echo $key ?> |
|---|
| 364 |
</td><td> |
|---|
| 365 |
<input type="text" size="20" name="dialpattern[<?php echo $key ?>]" value="<?php echo $dialpattern[$key] ?>"/> |
|---|
| 366 |
</td> |
|---|
| 367 |
</tr> |
|---|
| 368 |
<?php |
|---|
| 369 |
} // foreach |
|---|
| 370 |
|
|---|
| 371 |
$key += 1; // this will be the next key value |
|---|
| 372 |
?> |
|---|
| 373 |
<tr> |
|---|
| 374 |
<td><?php echo $key ?> |
|---|
| 375 |
</td><td> |
|---|
| 376 |
<input type="text" size="20" name="dialpattern[<?php echo $key ?>]" value="<?php echo $dialpattern[$key] ?>"/> |
|---|
| 377 |
</td> |
|---|
| 378 |
</tr> |
|---|
| 379 |
<tr> |
|---|
| 380 |
<td> </td> |
|---|
| 381 |
<td> |
|---|
| 382 |
<br><input type="submit" value="<?php echo _("Add"); ?>"> |
|---|
| 383 |
</td> |
|---|
| 384 |
</tr> |
|---|
| 385 |
<?php */ ?> |
|---|
| 386 |
<tr> |
|---|
| 387 |
<td> |
|---|
| 388 |
</td><td> |
|---|
| 389 |
<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> |
|---|
| 390 |
|
|---|
| 391 |
<input type="submit" style="font-size:10px;" value="<?php echo _("Clean & Remove duplicates")?>" /> |
|---|
| 392 |
</td> |
|---|
| 393 |
</tr> |
|---|
| 394 |
<tr> |
|---|
| 395 |
<td><?php echo _("Insert:")?></td> |
|---|
| 396 |
<input id="npanxx" name="npanxx" type="hidden" /> |
|---|
| 397 |
<script language="javascript"> |
|---|
| 398 |
|
|---|
| 399 |
function populateLookup() { |
|---|
| 400 |
<?php |
|---|
| 401 |
if (function_exists("curl_init")) { |
|---|
| 402 |
?> |
|---|
| 403 |
//var npanxx = prompt("What is your areacode + prefix (NPA-NXX)?", document.getElementById('areacode').value); |
|---|
| 404 |
do { |
|---|
| 405 |
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.").'")'?>; |
|---|
| 406 |
if (npanxx == null) return; |
|---|
| 407 |
} 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\'").'")'?>); |
|---|
| 408 |
|
|---|
| 409 |
document.getElementById('npanxx').value = npanxx; |
|---|
| 410 |
document.getElementById('routeEdit').action.value = "populatenpanxx"; |
|---|
| 411 |
document.getElementById('routeEdit').submit(); |
|---|
| 412 |
<?php |
|---|
| 413 |
} else { |
|---|
| 414 |
?> |
|---|
| 415 |
<?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.")."')"?>; |
|---|
| 416 |
<?php |
|---|
| 417 |
} |
|---|
| 418 |
?> |
|---|
| 419 |
} |
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
function insertCode() { |
|---|
| 423 |
code = document.getElementById('inscode').value; |
|---|
| 424 |
insert = ''; |
|---|
| 425 |
switch(code) { |
|---|
| 426 |
case "local": |
|---|
| 427 |
insert = 'NXXXXXX\n'; |
|---|
| 428 |
break; |
|---|
| 429 |
case "local10": |
|---|
| 430 |
insert = 'NXXXXXX\n'+ |
|---|
| 431 |
'NXXNXXXXXX\n'; |
|---|
| 432 |
break; |
|---|
| 433 |
case 'tollfree': |
|---|
| 434 |
insert = '1800NXXXXXX\n'+ |
|---|
| 435 |
'1888NXXXXXX\n'+ |
|---|
| 436 |
'1877NXXXXXX\n'+ |
|---|
| 437 |
'1866NXXXXXX\n'; |
|---|
| 438 |
break; |
|---|
| 439 |
case "ld": |
|---|
| 440 |
insert = '1NXXNXXXXXX\n'; |
|---|
| 441 |
break; |
|---|
| 442 |
case "int": |
|---|
| 443 |
insert = '011.\n'; |
|---|
| 444 |
break; |
|---|
| 445 |
case 'info': |
|---|
| 446 |
insert = '411\n'+ |
|---|
| 447 |
'311\n'; |
|---|
| 448 |
break; |
|---|
| 449 |
case 'emerg': |
|---|
| 450 |
insert = '911\n'; |
|---|
| 451 |
break; |
|---|
| 452 |
case 'lookup': |
|---|
| 453 |
populateLookup(); |
|---|
| 454 |
insert = ''; |
|---|
| 455 |
break; |
|---|
| 456 |
|
|---|
| 457 |
} |
|---|
| 458 |
dialPattern=document.getElementById('dialpattern'); |
|---|
| 459 |
if (dialPattern.value[ dialPattern.value.length - 1 ] == "\n") { |
|---|
| 460 |
dialPattern.value = dialPattern.value + insert; |
|---|
| 461 |
} else { |
|---|
| 462 |
dialPattern.value = dialPattern.value + '\n' + insert; |
|---|
| 463 |
} |
|---|
| 464 |
|
|---|
| 465 |
// reset element |
|---|
| 466 |
document.getElementById('inscode').value = ''; |
|---|
| 467 |
} |
|---|
| 468 |
|
|---|
| 469 |
--></script> |
|---|
| 470 |
<td> |
|---|
| 471 |
<select onChange="insertCode();" id="inscode"> |
|---|
| 472 |
<option value=""><?php echo _("Pick pre-defined patterns")?></option> |
|---|
| 473 |
<option value="local"><?php echo _("Local 7 digit")?></option> |
|---|
| 474 |
<option value="local10"><?php echo _("Local 7/10 digit")?></option> |
|---|
| 475 |
<option value="tollfree"><?php echo _("Toll-free")?></option> |
|---|
| 476 |
<option value="ld"><?php echo _("Long-distance")?></option> |
|---|
| 477 |
<option value="int"><?php echo _("International")?></option> |
|---|
| 478 |
<option value="info"><?php echo _("Information")?></option> |
|---|
| 479 |
<option value="emerg"><?php echo _("Emergency")?></option> |
|---|
| 480 |
<option value="lookup"><?php echo _("Lookup local prefixes")?></option> |
|---|
| 481 |
</select> |
|---|
| 482 |
</td> |
|---|
| 483 |
</tr> |
|---|
| 484 |
<tr> |
|---|
| 485 |
<td colspan="2"> |
|---|
| 486 |
<br><br> |
|---|
| 487 |
<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> |
|---|
| 488 |
</td> |
|---|
| 489 |
</tr> |
|---|
| 490 |
<input type="hidden" id="repotrunkdirection" name="repotrunkdirection" value=""> |
|---|
| 491 |
<input type="hidden" id="repotrunkkey" name="repotrunkkey" value=""> |
|---|
| 492 |
<input type="hidden" id="reporoutedirection" name="reporoutedirection" value=""> |
|---|
| 493 |
<input type="hidden" id="reporoutekey" name="reporoutekey" value=""> |
|---|
| 494 |
<?php |
|---|
| 495 |
$key = -1; |
|---|
| 496 |
$positions=count($trunkpriority); |
|---|
| 497 |
foreach ($trunkpriority as $key=>$trunk) { |
|---|
| 498 |
?> |
|---|
| 499 |
<tr> |
|---|
| 500 |
<td align="right"><?php echo $key; ?> |
|---|
| 501 |
</td> |
|---|
| 502 |
<td> |
|---|
| 503 |
<select id='trunkpri<?php echo $key ?>' name="trunkpriority[<?php echo $key ?>]"> |
|---|
| 504 |
<option value=""></option> |
|---|
| 505 |
<?php |
|---|
| 506 |
foreach ($trunks as $name=>$display) { |
|---|
| 507 |
echo "<option id=\"trunk".$key."\" value=\"".$name."\" ".($name == $trunk ? "selected" : "").">".$display."</option>"; |
|---|
| 508 |
} |
|---|
| 509 |
?> |
|---|
| 510 |
</select> |
|---|
| 511 |
|
|---|
| 512 |
<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 ?>)"> |
|---|
| 513 |
<?php |
|---|
| 514 |
if ($key > 0) {?> |
|---|
| 515 |
<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"> |
|---|
| 516 |
<?php } else { ?> |
|---|
| 517 |
<img src="images/blank.gif" style="float:none; margin-left:0px; margin-bottom:0px;" width="9" height="11"> |
|---|
| 518 |
<?php } |
|---|
| 519 |
|
|---|
| 520 |
|
|---|
| 521 |
|
|---|
| 522 |
if ($key < ($positions-1)) {?> |
|---|
| 523 |
<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"> |
|---|
| 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 |
</td> |
|---|
| 528 |
</tr> |
|---|
| 529 |
<?php |
|---|
| 530 |
} |
|---|
| 531 |
|
|---|
| 532 |
$key += 1; |
|---|
| 533 |
$name = ""; |
|---|
| 534 |
|
|---|
| 535 |
|
|---|
| 536 |
$num_new_boxes = ($extdisplay ? 1 : ((count($trunks) > 3) ? 3 : count($trunks))); |
|---|
| 537 |
|
|---|
| 538 |
for ($i=0; $i < $num_new_boxes; $i++) { |
|---|
| 539 |
?> |
|---|
| 540 |
<tr> |
|---|
| 541 |
<td>   </td> |
|---|
| 542 |
<td> |
|---|
| 543 |
<select id='trunkpri<?php echo $key ?>' name="trunkpriority[<?php echo $key ?>]"> |
|---|
| 544 |
<option value="" SELECTED></option> |
|---|
| 545 |
<?php |
|---|
| 546 |
foreach ($trunks as $name=>$display) { |
|---|
| 547 |
echo "<option value=\"".$name."\">".ltrim($display,"AMP:")."</option>"; |
|---|
| 548 |
} |
|---|
| 549 |
?> |
|---|
| 550 |
</select> |
|---|
| 551 |
</td> |
|---|
| 552 |
</tr> |
|---|
| 553 |
<?php |
|---|
| 554 |
$key++; |
|---|
| 555 |
} ?> |
|---|
| 556 |
|
|---|
| 557 |
<?php if ($extdisplay): ?> |
|---|
| 558 |
<tr> |
|---|
| 559 |
<td></td> |
|---|
| 560 |
<td> |
|---|
| 561 |
<input type="submit" value="<?php echo _("Add")?>"> |
|---|
| 562 |
</td> |
|---|
| 563 |
</tr> |
|---|
| 564 |
<?php endif; ?> |
|---|
| 565 |
<tr> |
|---|
| 566 |
<td colspan="2"> |
|---|
| 567 |
<br> |
|---|
| 568 |
<h6><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>"> |
|---|
| 569 |
</h6> |
|---|
| 570 |
</td> |
|---|
| 571 |
</tr> |
|---|
| 572 |
</table> |
|---|
| 573 |
|
|---|
| 574 |
<script language="javascript"> |
|---|
| 575 |
<!-- |
|---|
| 576 |
|
|---|
| 577 |
var theForm = document.routeEdit; |
|---|
| 578 |
|
|---|
| 579 |
if (theForm.routename.value == "") { |
|---|
| 580 |
theForm.routename.focus(); |
|---|
| 581 |
} else { |
|---|
| 582 |
theForm.routepass.focus(); |
|---|
| 583 |
} |
|---|
| 584 |
|
|---|
| 585 |
function routeEdit_onsubmit(act) { |
|---|
| 586 |
var msgInvalidRouteName = "<?php echo _('Route name is invalid, please try again'); ?>"; |
|---|
| 587 |
var msgInvalidRoutePwd = "<?php echo _('Route password must be numberic or leave blank to disable'); ?>"; |
|---|
| 588 |
var msgInvalidDialPattern = "<?php echo _('Dial pattern is invalid'); ?>"; |
|---|
| 589 |
var msgInvalidTrunkSelection = "<?php echo _('At least one trunk must be picked'); ?>"; |
|---|
| 590 |
|
|---|
| 591 |
defaultEmptyOK = false; |
|---|
| 592 |
if (isEmpty(theForm.routename.value)) |
|---|
| 593 |
return warnInvalid(theForm.routename, msgInvalidRouteName); |
|---|
| 594 |
|
|---|
| 595 |
defaultEmptyOK = true; |
|---|
| 596 |
if (!isInteger(theForm.routepass.value)) |
|---|
| 597 |
return warnInvalid(theForm.routepass, msgInvalidRoutePwd); |
|---|
| 598 |
|
|---|
| 599 |
defaultEmptyOK = false; |
|---|
| 600 |
if (!isDialpattern(theForm.dialpattern.value)) |
|---|
| 601 |
return warnInvalid(theForm.dialpattern, msgInvalidDialPattern); |
|---|
| 602 |
|
|---|
| 603 |
if (theForm.trunkpri0.value == "") { // should they all be checked ? |
|---|
| 604 |
theForm.trunkpri0.focus(); |
|---|
| 605 |
alert(msgInvalidTrunkSelection); |
|---|
| 606 |
return false; |
|---|
| 607 |
} |
|---|
| 608 |
|
|---|
| 609 |
theForm.action.value = act; |
|---|
| 610 |
return true; |
|---|
| 611 |
} |
|---|
| 612 |
|
|---|
| 613 |
function repositionTrunk(key,direction) { |
|---|
| 614 |
if(direction == "up"){ |
|---|
| 615 |
document.getElementById('repotrunkdirection').value=direction; |
|---|
| 616 |
document.getElementById('repotrunkkey').value=key; |
|---|
| 617 |
}else if(direction == "down" ){ |
|---|
| 618 |
document.getElementById('repotrunkdirection').value=direction; |
|---|
| 619 |
document.getElementById('repotrunkkey').value=key; |
|---|
| 620 |
} |
|---|
| 621 |
document.getElementById('routeEdit').submit(); |
|---|
| 622 |
} |
|---|
| 623 |
|
|---|
| 624 |
function deleteTrunk(key) { |
|---|
| 625 |
document.getElementById('trunkpri'+key).value = ''; |
|---|
| 626 |
document.getElementById('routeEdit').submit(); |
|---|
| 627 |
} |
|---|
| 628 |
|
|---|
| 629 |
function repositionRoute(key,direction){ |
|---|
| 630 |
if(direction == "up"){ |
|---|
| 631 |
document.getElementById('reporoutedirection').value=direction; |
|---|
| 632 |
document.getElementById('reporoutekey').value=key; |
|---|
| 633 |
}else if(direction == "down" ){ |
|---|
| 634 |
document.getElementById('reporoutedirection').value=direction; |
|---|
| 635 |
document.getElementById('reporoutekey').value=key; |
|---|
| 636 |
} |
|---|
| 637 |
document.getElementById('action').value='prioritizeroute'; |
|---|
| 638 |
document.getElementById('routeEdit').submit(); |
|---|
| 639 |
} |
|---|
| 640 |
|
|---|
| 641 |
//--> |
|---|
| 642 |
</script> |
|---|
| 643 |
|
|---|
| 644 |
</form> |
|---|
| 645 |
|
|---|
| 646 |
|
|---|