function transform_mapping($number, $dialplan, $array_mapping, $type) { # Not found yet $found = False; $complement = ''; # Check if number is in mapping file. if (count($array_mapping) > 0) { # Local variables $len_outgoing = strlen($dialplan['outgoing']); $len_international = strlen($dialplan['international']); # Process each entry foreach ($array_mapping as $keys => $values) { # Get all entries $array_keys = explode(',', $keys); # Get number $array_values = explode(',', $values, 2); $value = $array_values[0]; # Process all entries foreach ($array_keys as $key) { # Not a prefix if (substr($key, 0, 1) != 'p') { # Return mapped number as found in mapping file. if ($type == '1') { if ($number == $key || $number == $dialplan['outgoing'] . $key || $number == $dialplan['outgoing'] . $dialplan['international'] . $key || $number == $dialplan['international'] . $key) { $found = True; $number = $value; $complement = $array_values[1]; break; } } } else { # Return mapped number as found in mapping file. if ($type == '2') { # Remove the P $compare = substr($key, 1); $array_pattern = array(); $array_pattern[] = $compare; if (!in_array($dialplan['outgoing'] . $compare, $array_pattern)) { $array_pattern[] = $dialplan['outgoing'] . $compare; } if (!in_array($dialplan['outgoing'] . $dialplan['international'] . $compare, $array_pattern)) { $array_pattern[] = $dialplan['outgoing'] . $dialplan['international'] . $compare; } if (!in_array($dialplan['international'] . $compare, $array_pattern)) { $array_pattern[] = $dialplan['international'] . $compare; } # Return mapped number as found in mapping file. if (check_pattern($number, $array_pattern)) { $found = True; $number = $value; $complement = $array_values[1]; break; } } } # Break the loop if found if ($found) { break; } } } } # Return mapping number return array($number, $complement); }
<?php if ($_POST['add']) { //validate $pat = "^[a-z]{2}\$"; if (!check_pattern($_POST['lang_code'], $pat)) { echo htmlspecialchars(xl("Code must be two letter lowercase"), ENT_NOQUOTES) . '<br>'; $err = 'y'; } $sql = "SELECT * FROM lang_languages WHERE lang_code LIKE ? or lang_description LIKE ? limit 1"; $res = SqlQuery($sql, array("%" . $_POST['lang_code'] . "%", "%" . $_POST['lang_name'])); if ($res) { echo htmlspecialchars(xl("Data Alike is already in database, please change code and/or description"), ENT_NOQUOTES) . '<br>'; $err = 'y'; } if ($err == 'y') { $val_lang_code = $_POST['lang_code']; $val_lang_name = $_POST['lang_name']; } else { //insert into the main table $sql = "INSERT INTO lang_languages SET lang_code=?, lang_description=?"; SqlStatement($sql, array($_POST['lang_code'], $_POST['lang_name'])); //insert into the log table - to allow persistant customizations insert_language_log($_POST['lang_name'], $_POST['lang_code'], '', ''); echo htmlspecialchars(xl('Language definition added'), ENT_NOQUOTES) . '<br>'; } } ?> <TABLE> <FORM name="lang_form" METHOD=POST ACTION="?m=language" onsubmit="return top.restoreSession()">