Add destination number regex and string_to_regex function.

This commit is contained in:
markjcrane 2016-03-17 13:22:03 -06:00
parent 39bfec7aa2
commit 08b4e3138c
3 changed files with 69 additions and 14 deletions

View File

@ -109,6 +109,10 @@
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; $apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the number."; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the number.";
$z++; $z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "destination_number_regex";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Regular Expression version of destination number";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "destination_caller_id_name"; $apps[$x]['db'][$y]['fields'][$z]['name'] = "destination_caller_id_name";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; $apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the caller id name."; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the caller id name.";

View File

@ -17,7 +17,7 @@
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2013-2015 Portions created by the Initial Developer are Copyright (C) 2013-2016
the Initial Developer. All Rights Reserved. the Initial Developer. All Rights Reserved.
Contributor(s): Contributor(s):
@ -83,7 +83,6 @@ if (file_exists($_SERVER["PROJECT_ROOT"]."/app/billing/app_config.php")) {
$destination_type = check_str($_POST["destination_type"]); $destination_type = check_str($_POST["destination_type"]);
$destination_number = check_str($_POST["destination_number"]); $destination_number = check_str($_POST["destination_number"]);
$db_destination_number = check_str($_POST["db_destination_number"]); $db_destination_number = check_str($_POST["db_destination_number"]);
$regex_destination_number = str_replace("+", "\\+", $destination_number);
$destination_caller_id_name = check_str($_POST["destination_caller_id_name"]); $destination_caller_id_name = check_str($_POST["destination_caller_id_name"]);
$destination_caller_id_number = check_str($_POST["destination_caller_id_number"]); $destination_caller_id_number = check_str($_POST["destination_caller_id_number"]);
$destination_cid_name_prefix = check_str($_POST["destination_cid_name_prefix"]); $destination_cid_name_prefix = check_str($_POST["destination_cid_name_prefix"]);
@ -97,6 +96,9 @@ if (file_exists($_SERVER["PROJECT_ROOT"]."/app/billing/app_config.php")) {
$currency_buy = check_str($_POST["currency_buy"]); $currency_buy = check_str($_POST["currency_buy"]);
$destination_accountcode = check_str($_POST["destination_accountcode"]); $destination_accountcode = check_str($_POST["destination_accountcode"]);
$destination_carrier = check_str($_POST["destination_carrier"]); $destination_carrier = check_str($_POST["destination_carrier"]);
//convert the number to a regular expression
$destination_number_regex = string_to_regex($destination_number);
$_POST["destination_number_regex"] = $destination_number_regex;
} }
//unset the db_destination_number //unset the db_destination_number
@ -221,7 +223,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "condition"; $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "condition";
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number"; $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number";
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "(".$regex_destination_number.")"; $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $destination_number_regex;
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++; $y++;

View File

@ -1381,16 +1381,65 @@ function number_pad($number,$n) {
//email validate //email validate
function email_validate($strEmail){ function email_validate($strEmail){
$validRegExp = '/^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z]{2,3}$/'; $validRegExp = '/^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z]{2,3}$/';
// search email text for regular exp matches // search email text for regular exp matches
preg_match($validRegExp, $strEmail, $matches, PREG_OFFSET_CAPTURE); preg_match($validRegExp, $strEmail, $matches, PREG_OFFSET_CAPTURE);
if (count($matches) == 0) {
return 0;
}
else {
return 1;
}
}
if (count($matches) == 0) { //converts a string to a regular expression
return 0; function string_to_regex($string) {
} //escape the plus
else { if (substr($string, 0, 1) == "+") {
return 1; $string = "^\\+(".substr($string, 1).")$";
} }
} //convert N,X,Z syntax to regex
$string = str_ireplace("N", "[2-9]", $string);
$string = str_ireplace("X", "[0-9]", $string);
$string = str_ireplace("Z", "[1-9]", $string);
//add ^ to the start of the string if missing
if (substr($string, 0, 1) != "^") {
$string = "^".$string;
}
//add $ to the end of the string if missing
if (substr($string, -1) != "$") {
$string = $string."$";
}
//add the round brackgets ( and )
if (!strstr($string, '(')) {
if (strstr($string, '^')) {
$string = str_replace("^", "^(", $string);
}
else {
$string = '^('.$string;
}
}
if (!strstr($string, ')')) {
if (strstr($string, '$')) {
$string = str_replace("$", ")$", $string);
}
else {
$string = $string.')$';
}
}
//return the result
return $string;
}
//$string = "+12089068227"; echo $string." ".string_to_regex($string)."\n";
//$string = "12089068227"; echo $string." ".string_to_regex($string)."\n";
//$string = "2089068227"; echo $string." ".string_to_regex($string)."\n";
//$string = "^(20890682[0-9][0-9])$"; echo $string." ".string_to_regex($string)."\n";
//$string = "1208906xxxx"; echo $string." ".string_to_regex($string)."\n";
//$string = "nxxnxxxxxxx"; echo $string." ".string_to_regex($string)."\n";
//$string = "208906xxxx"; echo $string." ".string_to_regex($string)."\n";
//$string = "^(2089068227"; echo $string." ".string_to_regex($string)."\n";
//$string = "^2089068227)"; echo $string." ".string_to_regex($string)."\n";
//$string = "2089068227$"; echo $string." ".string_to_regex($string)."\n";
//$string = "2089068227)$"; echo $string." ".string_to_regex($string)."\n";
?> ?>