Copyright (C) 2005 Ron Hartmann (rhartmann@vercomsystems.com) // Asterisk Management Portal Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca) // //This program is free software; you can redistribute it and/or //modify it under the terms of the GNU General Public License //as published by the Free Software Foundation; either version 2 //of the License, or (at your option) any later version. // //This program is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //GNU General Public License for more details. $display='routing'; $extdisplay=isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:''; $action = isset($_REQUEST['action'])?$_REQUEST['action']:''; $repotrunkdirection = isset($_REQUEST['repotrunkdirection'])?$_REQUEST['repotrunkdirection']:''; $repotrunkkey = isset($_REQUEST['repotrunkkey'])?$_REQUEST['repotrunkkey']:''; $dialpattern = array(); if (isset($_REQUEST["dialpattern"])) { //$dialpattern = $_REQUEST["dialpattern"]; $dialpattern = explode("\n",$_REQUEST["dialpattern"]); if (!$dialpattern) { $dialpattern = array(); } foreach (array_keys($dialpattern) as $key) { //trim it $dialpattern[$key] = trim($dialpattern[$key]); // remove blanks if ($dialpattern[$key] == "") unset($dialpattern[$key]); // remove leading underscores (we do that on backend) if ($dialpattern[$key][0] == "_") $dialpattern[$key] = substr($dialpattern[$key],1); } // check for duplicates, and re-sequence $dialpattern = array_values(array_unique($dialpattern)); } if ( (isset($_REQUEST['reporoutedirection'])) && (isset($_REQUEST['reporoutekey']))) { $routepriority = core_routing_getroutenames(); $routepriority = core_routing_setroutepriority($routepriority, $_REQUEST['reporoutedirection'], $_REQUEST['reporoutekey']); } $trunkpriority = array(); if (isset($_REQUEST["trunkpriority"])) { $trunkpriority = $_REQUEST["trunkpriority"]; if (!$trunkpriority) { $trunkpriority = array(); } // delete blank entries and reorder foreach (array_keys($trunkpriority) as $key) { if (empty($trunkpriority[$key])) { // delete this empty unset($trunkpriority[$key]); } else if (($key==($repotrunkkey-1)) && ($repotrunkdirection=="up")) { // swap this one with the one before (move up) $temptrunk = $trunkpriority[$key]; $trunkpriority[ $key ] = $trunkpriority[ $key+1 ]; $trunkpriority[ $key+1 ] = $temptrunk; } else if (($key==($repotrunkkey)) && ($repotrunkdirection=="down")) { // swap this one with the one after (move down) $temptrunk = $trunkpriority[ $key+1 ]; $trunkpriority[ $key+1 ] = $trunkpriority[ $key ]; $trunkpriority[ $key ] = $temptrunk; } } unset($temptrunk); $trunkpriority = array_values($trunkpriority); // resequence our numbers } $routename = isset($_REQUEST["routename"]) ? $_REQUEST["routename"] : ""; $routepass = isset($_REQUEST["routepass"]) ? $_REQUEST["routepass"] : ""; $emergency = isset($_REQUEST["emergency"]) ? $_REQUEST["emergency"] : ""; $intracompany = isset($_REQUEST["intracompany"]) ? $_REQUEST["intracompany"] : ""; $mohsilence = isset($_REQUEST["mohsilence"]) ? $_REQUEST["mohsilence"] : ""; //if submitting form, update database switch ($action) { case "addroute": core_routing_add($routename, $dialpattern, $trunkpriority,"new", $routepass, $emergency, $intracompany, $mohsilence); needreload(); redirect_standard(); break; case "editroute": core_routing_edit($routename, $dialpattern, $trunkpriority, $routepass, $emergency, $intracompany, $mohsilence); needreload(); redirect_standard('extdisplay'); break; case "delroute": core_routing_del($extdisplay); // re-order the routes to make sure that there are no skipped numbers. // example if we have 001-test1, 002-test2, and 003-test3 then delete 002-test2 // we do not want to have our routes as 001-test1, 003-test3 we need to reorder them // so we are left with 001-test1, 002-test3 $routepriority = core_routing_getroutenames(); $routepriority = core_routing_setroutepriority($routepriority, '',''); needreload(); redirect_standard(); break; case 'renameroute': if (core_routing_rename($routename, $_REQUEST["newroutename"])) { needreload(); } else { echo ""; } $route_prefix=substr($routename,0,4); $extdisplay=$route_prefix.$_REQUEST["newroutename"]; break; case 'prioritizeroute': needreload(); break; case 'populatenpanxx': if (preg_match("/^([2-9]\d\d)-?([2-9]\d\d)$/", $_REQUEST["npanxx"], $matches)) { // first thing we do is grab the exch: $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, "http://www.localcallingguide.com/xmllocalprefix.php?npa=".$matches[1]."&nxx=".$matches[2]); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; FreePBX Local Trunks Configuration)"); $str = curl_exec($ch); curl_close($ch); // quick 'n dirty - nabbed from PEAR require_once($amp_conf['AMPWEBROOT'] . '/admin/modules/core/XML_Parser.php'); require_once($amp_conf['AMPWEBROOT'] . '/admin/modules/core/XML_Unserializer.php'); $xml = new xml_unserializer; $xml->unserialize($str); $xmldata = $xml->getUnserializedData(); if (isset($xmldata['lca-data']['prefix'])) { // we do the loops separately so patterns are grouped together // match 1+NPA+NXX (dropping 1) foreach ($xmldata['lca-data']['prefix'] as $prefix) { $dialpattern[] = '1|'.$prefix['npa'].$prefix['nxx'].'XXXX'; } // match NPA+NXX foreach ($xmldata['lca-data']['prefix'] as $prefix) { $dialpattern[] = $prefix['npa'].$prefix['nxx'].'XXXX'; } // match 7-digits foreach ($xmldata['lca-data']['prefix'] as $prefix) { $dialpattern[] = $prefix['nxx'].'XXXX'; } // check for duplicates, and re-sequence $dialpattern = array_values(array_unique($dialpattern)); } else { $errormsg = _("Error fetching prefix list for: "). $_REQUEST["npanxx"]; } } else { // what a horrible error message... :p $errormsg = _("Invalid format for NPA-NXX code (must be format: NXXNXX)"); } if (isset($errormsg)) { echo ""; unset($errormsg); } break; } //get all rows from globals $sql = "SELECT * FROM globals"; $globals = $db->getAll($sql); if(DB::IsError($globals)) { die_freepbx($globals->getMessage()); } //create a set of variables that match the items in global[0] foreach ($globals as $global) { ${trim($global[0])} = htmlentities($global[1]); } ?>
','down')\" alt='" . _("Move Down") .
"' style='float:none; margin-left:0px; margin-bottom:0px;' width='9' height='11'>\n";
else
echo "\t\t