$val) { $temp2[] = $val; // for later comparison // extract all ruleXX keys if (preg_match("/^rule\d+$/",$key)) { if (!preg_match("/^1[\d]{3}\+NXXXXXX$/",$val)) { $dialrules[] = $val; } } } } else { $temp = array(); } array_unshift($dialrules,$areacode); if ($temp2 != $dialrules) { core_trunks_addDialRules($trunk, $dialrules); $need_reload = true; } unset($temp); unset($temp2); unset($dialrules); } } else { $json_array['areacode_status'] = sprintf(_("The prefix you entered, %s, is not a proper prefix or the wrong length. It should be a 3 digit prefix."),$_POST['areacode']); } } $routes = core_routing_getroutenames(); foreach($routes as $route) { $route_name = substr($route[0],4); $trunks = core_routing_getroutetrunks($route[0]); $gw1 = array_search($globalvar1,$trunks); $gw2 = array_search($globalvar2,$trunks); $gw1_change = ($gw1 !== false XOR $_POST[$route_name.'_id1'] == 'yes'); $gw2_change = ($gw2 !== false XOR $_POST[$route_name.'_id2'] == 'yes'); if ($gw1_change || $gw2_change) { /* Determine which one or both need to change then do them at the same time. They should all be created at this point from above, gw1 should be last so that trunk always ends up first. */ $cnt++; if ($gw2_change) { if ($gw2===false) { array_unshift($trunks,$globalvar2); } else { unset($trunks[$gw2]); } } if ($gw1_change) { if ($gw1===false) { array_unshift($trunks,$globalvar1); } else { unset($trunks[$gw1]); } } foreach ($trunks as $trunk) { $new_trunks[] = $trunk; } // Now get all the route settings, then update with these new trunks // $dialpattern = core_routing_getroutepatterns($route[0]); $routepass = core_routing_getroutepassword($route[0]); $emergency = core_routing_getrouteemergency($route[0]); $intracompany = core_routing_getrouteintracompany($route[0]); $mohsilence = core_routing_getroutemohsilence($route[0]); core_routing_edit($route[0], $dialpattern, $new_trunks, $routepass, $emergency, $intracompany, $mohsilence); unset($new_trunks); } } $json_array['update_count'] = $cnt; if ($cnt) { $json_array['status_message'] = sprintf(_("Successfully configured %s routes to use your SIP trunks"),$cnt); } elseif ($need_reload) { $json_array['status_message'] = _("Your Area Code was updated"); } else { $json_array['status_message'] = _("No updates were required, nothing was changed in"); } } else { $json_array['update_count'] = 0; $json_array['status_message'] = sprintf(_("Your trunks are not configured. Click on the Get Account Info button in order to re-pull your account information and generate the required trunks and then try again.")); } /* if we made changes then we have to set the needsreload status and send back the reload bar to be inserted */ if ($cnt || $need_reload) { needreload(); if ($_POST['send_reload'] == 'yes') { ob_start(); if (!@include ('views/freepbx_reloadbar.php')) { @include ('../../views/freepbx_reloadbar.php'); //TODO for debugging } $json_array['reload_bar'] = ob_get_clean(); ob_start(); if (!@include ('views/freepbx_reload.php')) { @include ('../../views/freepbx_reload.php'); //TODO for debugging } $json_array['reload_header'] = ob_get_clean(); } $json_array['show_reload'] = 'yes'; } else { $json_array['show_reload'] = 'no'; } $json = new Services_JSON(); $value = $json->decode($_POST); header("Content-type: application/json"); echo $json->encode($json_array);