4 ? 4 : count($row); for ($i=0;$i<$count;$i++) { switch (strtolower($row[$i])) { case 'prepend': case 'prefix': case 'match pattern': case 'callerid': $index[strtolower($row[$i])] = $i; break; default: break; } } // If no headers then assume standard order if (count($index) == 0) { $index['prepend'] = 0; $index['prefix'] = 1; $index['match pattern'] = 2; $index['callerid'] = 3; if ($count == 4) { $csv_file[] = $row; } } break; } } $row_count = count($index); while (($row = fgetcsv($fh, 5000, ",", "\"")) !== false) { if (count($row) == $row_count) { $csv_file[] = $row; } } } } // // Use a hash of the value inserted to get rid of duplicates $dialpattern_insert = array(); $p_idx = 0; $n_idx = 0; // If we have a CSV file it replaces any existing patterns // if (!empty($csv_file)) { foreach ($csv_file as $row) { $this_prepend = isset($index['prepend']) ? htmlspecialchars(trim($row[$index['prepend']])) : ''; $this_prefix = isset($index['prefix']) ? htmlspecialchars(trim($row[$index['prefix']])) : ''; $this_match_pattern = isset($index['match pattern']) ? htmlspecialchars(trim($row[$index['match pattern']])) : ''; $this_callerid = isset($index['callerid']) ? htmlspecialchars(trim($row[$index['callerid']])) : ''; if ($this_prepend != '' || $this_prefix != '' || $this_match_pattern != '' || $this_callerid != '') { $dialpattern_insert[] = array( 'prepend_digits' => $this_prepend, 'match_pattern_prefix' => $this_prefix, 'match_pattern_pass' => $this_match_pattern, 'match_cid' => $this_callerid, ); } } } else if (isset($_POST["prepend_digit"])) { $prepend_digit = $_POST["prepend_digit"]; $pattern_prefix = $_POST["pattern_prefix"]; $pattern_pass = $_POST["pattern_pass"]; $match_cid = $_POST["match_cid"]; foreach (array_keys($prepend_digit) as $key) { if ($prepend_digit[$key]!='' || $pattern_prefix[$key]!='' || $pattern_pass[$key]!='' || $match_cid[$key]!='') { $dialpattern_insert[] = array( 'prepend_digits' => htmlspecialchars(trim($prepend_digit[$key])), 'match_pattern_prefix' => htmlspecialchars(trim($pattern_prefix[$key])), 'match_pattern_pass' => htmlspecialchars(trim($pattern_pass[$key])), 'match_cid' => htmlspecialchars(trim($match_cid[$key])), ); } } } if ( isset($_REQUEST['reporoutedirection']) && $_REQUEST['reporoutedirection'] != '' && isset($_REQUEST['reporoutekey']) && $_REQUEST['reporoutekey'] != '') { $_REQUEST['route_seq'] = core_routing_setrouteorder($_REQUEST['reporoutekey'], $_REQUEST['reporoutedirection']); } $trunkpriority = array(); if (isset($_REQUEST["trunkpriority"])) { $trunkpriority = $_REQUEST["trunkpriority"]; if (!$trunkpriority) { $trunkpriority = array(); } // delete blank entries and reorder if($repotrunkkey=="") $repotrunkkey=0; foreach (array_keys($trunkpriority) as $key) { if ($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_unique(array_values($trunkpriority)); // resequence our numbers if ($action == '') { $action = "updatetrunks"; } } $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'] : ''; $outcid = isset($_REQUEST['outcid']) ? $_REQUEST['outcid'] : ''; $outcid_mode = isset($_REQUEST['outcid_mode']) ? $_REQUEST['outcid_mode'] : ''; $time_group_id = isset($_REQUEST['time_group_id']) ? $_REQUEST['time_group_id'] : ''; $route_seq = isset($_REQUEST['route_seq']) ? $_REQUEST['route_seq'] : ''; $goto = isset($_REQUEST['goto0'])?$_REQUEST['goto0']:''; $dest = $goto ? $_REQUEST[$goto . '0'] : ''; //if submitting form, update database switch ($action) { case 'ajaxroutepos': core_routing_setrouteorder($repotrunkkey, $repotrunkdirection); needreload(); header("Content-type: application/json"); echo json_encode($json_array); exit; break; case "copyroute": $routename .= "_copy_$extdisplay"; $extdisplay=''; $route_seq++; // Fallthrough to addtrunk now... // case "addroute": $extdisplay = core_routing_addbyid($routename, $outcid, $outcid_mode, $routepass, $emergency, $intracompany, $mohsilence, $time_group_id, $dialpattern_insert, $trunkpriority, $route_seq, $dest); $_REQUEST['extdisplay'] = $extdisplay; //have not idea if this is needed or useful needreload(); $_SESSION['msg']=base64_encode(_dgettext('amp','Item has been added')); $_SESSION['msgtype']='success'; $_SESSION['msgtstamp']=time(); redirect_standard('extdisplay'); break; case "editroute": core_routing_editbyid($extdisplay, $routename, $outcid, $outcid_mode, $routepass, $emergency, $intracompany, $mohsilence, $time_group_id, $dialpattern_insert, $trunkpriority, $route_seq, $dest); needreload(); $_SESSION['msg']=base64_encode(_dgettext('amp','Item has been saved')); $_SESSION['msgtype']='success'; $_SESSION['msgtstamp']=time(); redirect_standard('extdisplay'); break; case "updatetrunks": core_routing_updatetrunks($extdisplay, $trunkpriority, true); needreload(); break; case "delete": core_routing_delbyid($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 needreload(); $_SESSION['msg']=base64_encode(_dgettext('amp','Item has been deleted')); $_SESSION['msgtype']='warning'; $_SESSION['msgtstamp']=time(); redirect_standard(); break; case 'prioritizeroute': needreload(); break; case 'populatenpanxx': $dialpattern_array = $dialpattern_insert; 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; IssabelPBX 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(); $hash_filter = array(); //avoid duplicates 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) { if (isset($hash_filter['1'.$prefix['npa'].$prefix['nxx']])) { continue; } else { $hash_filter['1'.$prefix['npa'].$prefix['nxx']] = true; } $dialpattern_array[] = array( 'prepend_digits' => '', 'match_pattern_prefix' => '1', 'match_pattern_pass' => htmlspecialchars($prefix['npa'].$prefix['nxx']).'XXXX', 'match_cid' => '', ); } // match NPA+NXX foreach ($xmldata['lca-data']['prefix'] as $prefix) { if (isset($hash_filter[$prefix['npa'].$prefix['nxx']])) { continue; } else { $hash_filter[$prefix['npa'].$prefix['nxx']] = true; } $dialpattern_array[] = array( 'prepend_digits' => '', 'match_pattern_prefix' => '', 'match_pattern_pass' => htmlspecialchars($prefix['npa'].$prefix['nxx']).'XXXX', 'match_cid' => '', ); } // match 7-digits foreach ($xmldata['lca-data']['prefix'] as $prefix) { if (isset($hash_filter[$prefix['nxx']])) { continue; } else { $hash_filter[$prefix['nxx']] = true; } $dialpattern_array[] = array( 'prepend_digits' => '', 'match_pattern_prefix' => '', 'match_pattern_pass' => htmlspecialchars($prefix['nxx']).'XXXX', 'match_cid' => '', ); } unset($hash_filter); } 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; } ?> $tresult) { $rnaventries[] = array($tresult['route_id'],' '.$tresult['name'],'',''); } drawListMenu($rnaventries, $type, $display, $extdisplay); ?>