Portions created by the Initial Developer are Copyright (C) 2008-2012 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ include "root.php"; require_once "includes/require.php"; require_once "includes/checkauth.php"; if (permission_exists('inbound_route_add')) { //access granted } else { echo "access denied"; exit; } require_once "includes/header.php"; require_once "includes/paging.php"; //get the http get values and set them as php variables $order_by = $_GET["order_by"]; $order = $_GET["order"]; $action = $_GET["action"]; //get the http post values and set them as php variables if (count($_POST)>0) { $dialplan_name = check_str($_POST["dialplan_name"]); $limit = check_str($_POST["limit"]); $public_order = check_str($_POST["public_order"]); $condition_field_1 = check_str($_POST["condition_field_1"]); $condition_expression_1 = check_str($_POST["condition_expression_1"]); $condition_field_2 = check_str($_POST["condition_field_2"]); $condition_expression_2 = check_str($_POST["condition_expression_2"]); $action_1 = check_str($_POST["action_1"]); //$action_1 = "transfer:1001 XML default"; $action_1_array = explode(":", $action_1); $action_application_1 = array_shift($action_1_array); $action_data_1 = join(':', $action_1_array); $action_2 = check_str($_POST["action_2"]); //$action_2 = "transfer:1001 XML default"; $action_2_array = explode(":", $action_2); $action_application_2 = array_shift($action_2_array); $action_data_2 = join(':', $action_2_array); //$action_application_1 = check_str($_POST["action_application_1"]); //$action_data_1 = check_str($_POST["action_data_1"]); //$action_application_2 = check_str($_POST["action_application_2"]); //$action_data_2 = check_str($_POST["action_data_2"]); if (if_group("superadmin") && $action == "advanced") { //allow users in the superadmin group advanced control } else { if (strlen($condition_field_1) == 0) { $condition_field_1 = "destination_number"; } if (strlen($condition_expression_1) < 6) { $msg .= "The destination number must be 5 or more digits.
\n"; } if (is_numeric($condition_expression_1)) { //the number is numeric $condition_expression_1 = '^'.$condition_expression_1.'$'; } else { $msg .= "The destination number must be numeric.
\n"; } } $dialplan_enabled = check_str($_POST["dialplan_enabled"]); $dialplan_description = check_str($_POST["dialplan_description"]); if (strlen($dialplan_enabled) == 0) { $dialplan_enabled = "true"; } //set default to enabled } if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { //check for all required data if (strlen($domain_uuid) == 0) { $msg .= "Please provide: domain_uuid
\n"; } if (strlen($dialplan_name) == 0) { $msg .= "Please provide: Extension Name
\n"; } if (strlen($condition_field_1) == 0) { $msg .= "Please provide: Condition Field
\n"; } if (strlen($condition_expression_1) == 0) { $msg .= "Please provide: Condition Expression
\n"; } if (strlen($action_application_1) == 0) { $msg .= "Please provide: Action Application
\n"; } //if (strlen($limit) == 0) { $msg .= "Please provide: Limit
\n"; } //if (strlen($dialplan_enabled) == 0) { $msg .= "Please provide: Enabled True or False
\n"; } //if (strlen($dialplan_description) == 0) { $msg .= "Please provide: Description
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "includes/header.php"; require_once "includes/persistformvar.php"; echo "
\n"; echo "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "includes/footer.php"; return; } //remove the invalid characters from the extension name $dialplan_name = str_replace(" ", "_", $dialplan_name); $dialplan_name = str_replace("/", "", $dialplan_name); //start the atomic transaction $count = $db->exec("BEGIN;"); //returns affected rows //add the main dialplan entry $dialplan_uuid = uuid(); $sql = "insert into v_dialplans "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_uuid, "; $sql .= "app_uuid, "; $sql .= "dialplan_name, "; $sql .= "dialplan_order , "; $sql .= "dialplan_context, "; $sql .= "dialplan_enabled, "; $sql .= "dialplan_description "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$dialplan_uuid', "; $sql .= "'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4', "; $sql .= "'$dialplan_name', "; $sql .= "'$public_order', "; $sql .= "'public', "; $sql .= "'$dialplan_enabled', "; $sql .= "'$dialplan_description' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); //add condition public context $dialplan_detail_uuid = uuid(); $sql = "insert into v_dialplan_details "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_uuid, "; $sql .= "dialplan_detail_uuid, "; $sql .= "dialplan_detail_tag, "; $sql .= "dialplan_detail_type, "; $sql .= "dialplan_detail_data, "; $sql .= "dialplan_detail_order "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$dialplan_uuid', "; $sql .= "'$dialplan_detail_uuid', "; $sql .= "'condition', "; $sql .= "'context', "; $sql .= "'public', "; $sql .= "'10' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); //add condition 1 $dialplan_detail_uuid = uuid(); $sql = "insert into v_dialplan_details "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_uuid, "; $sql .= "dialplan_detail_uuid, "; $sql .= "dialplan_detail_tag, "; $sql .= "dialplan_detail_type, "; $sql .= "dialplan_detail_data, "; $sql .= "dialplan_detail_order "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$dialplan_uuid', "; $sql .= "'$dialplan_detail_uuid', "; $sql .= "'condition', "; $sql .= "'$condition_field_1', "; $sql .= "'$condition_expression_1', "; $sql .= "'20' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); //add condition 2 if (strlen($condition_field_2) > 0) { $dialplan_detail_uuid = uuid(); $sql = "insert into v_dialplan_details "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_uuid, "; $sql .= "dialplan_detail_uuid, "; $sql .= "dialplan_detail_tag, "; $sql .= "dialplan_detail_type, "; $sql .= "dialplan_detail_data, "; $sql .= "dialplan_detail_order "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$dialplan_uuid', "; $sql .= "'$dialplan_detail_uuid', "; $sql .= "'condition', "; $sql .= "'$condition_field_2', "; $sql .= "'$condition_expression_2', "; $sql .= "'30' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //set domain if (count($_SESSION["domains"]) > 1) { $dialplan_detail_uuid = uuid(); $sql = "insert into v_dialplan_details "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_uuid, "; $sql .= "dialplan_detail_uuid, "; $sql .= "dialplan_detail_tag, "; $sql .= "dialplan_detail_type, "; $sql .= "dialplan_detail_data, "; $sql .= "dialplan_detail_order "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$dialplan_uuid', "; $sql .= "'$dialplan_detail_uuid', "; $sql .= "'action', "; $sql .= "'set', "; $sql .= "'domain=".$_SESSION['domain_name']."', "; $sql .= "'40' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //set domain_name if (count($_SESSION["domains"]) > 1) { $dialplan_detail_uuid = uuid(); $sql = "insert into v_dialplan_details "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_uuid, "; $sql .= "dialplan_detail_uuid, "; $sql .= "dialplan_detail_tag, "; $sql .= "dialplan_detail_type, "; $sql .= "dialplan_detail_data, "; $sql .= "dialplan_detail_order "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$dialplan_uuid', "; $sql .= "'$dialplan_detail_uuid', "; $sql .= "'action', "; $sql .= "'set', "; $sql .= "'domain_name=".$_SESSION['domain_name']."', "; $sql .= "'50' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //set call_direction if (count($_SESSION["domains"]) > 1) { $dialplan_detail_uuid = uuid(); $sql = "insert into v_dialplan_details "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_uuid, "; $sql .= "dialplan_detail_uuid, "; $sql .= "dialplan_detail_tag, "; $sql .= "dialplan_detail_type, "; $sql .= "dialplan_detail_data, "; $sql .= "dialplan_detail_order "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$dialplan_uuid', "; $sql .= "'$dialplan_detail_uuid', "; $sql .= "'action', "; $sql .= "'set', "; $sql .= "'call_direction=inbound', "; $sql .= "'60' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //set limit if (strlen($limit) > 0) { $dialplan_detail_uuid = uuid(); $sql = "insert into v_dialplan_details "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_uuid, "; $sql .= "dialplan_detail_uuid, "; $sql .= "dialplan_detail_tag, "; $sql .= "dialplan_detail_type, "; $sql .= "dialplan_detail_data, "; $sql .= "dialplan_detail_order "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$dialplan_uuid', "; $sql .= "'$dialplan_detail_uuid', "; $sql .= "'action', "; $sql .= "'limit', "; $sql .= "'db \${domain} inbound ".$limit." !USER_BUSY', "; $sql .= "'70' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //set answer $tmp_app = false; if ($action_application_1 == "ivr") { $tmp_app = true; } if ($action_application_2 == "ivr") { $tmp_app = true; } if ($action_application_1 == "conference") { $tmp_app = true; } if ($action_application_2 == "conference") { $tmp_app = true; } if ($tmp_app) { $dialplan_detail_uuid = uuid(); $sql = "insert into v_dialplan_details "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_uuid, "; $sql .= "dialplan_detail_uuid, "; $sql .= "dialplan_detail_tag, "; $sql .= "dialplan_detail_type, "; $sql .= "dialplan_detail_data, "; $sql .= "dialplan_detail_order "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$dialplan_uuid', "; $sql .= "'$dialplan_detail_uuid', "; $sql .= "'action', "; $sql .= "'answer', "; $sql .= "'', "; $sql .= "'80' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } unset($tmp_app); //add action 1 $dialplan_detail_uuid = uuid(); $sql = "insert into v_dialplan_details "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_uuid, "; $sql .= "dialplan_detail_uuid, "; $sql .= "dialplan_detail_tag, "; $sql .= "dialplan_detail_type, "; $sql .= "dialplan_detail_data, "; $sql .= "dialplan_detail_order "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$dialplan_uuid', "; $sql .= "'$dialplan_detail_uuid', "; $sql .= "'action', "; $sql .= "'$action_application_1', "; $sql .= "'$action_data_1', "; $sql .= "'90' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); //add action 2 if (strlen($action_application_2) > 0) { $dialplan_detail_uuid = uuid(); $sql = "insert into v_dialplan_details "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_uuid, "; $sql .= "dialplan_detail_uuid, "; $sql .= "dialplan_detail_tag, "; $sql .= "dialplan_detail_type, "; $sql .= "dialplan_detail_data, "; $sql .= "dialplan_detail_order "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$dialplan_uuid', "; $sql .= "'$dialplan_detail_uuid', "; $sql .= "'action', "; $sql .= "'$action_application_2', "; $sql .= "'$action_data_2', "; $sql .= "'100' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //commit the atomic transaction $count = $db->exec("COMMIT;"); //returns affected rows //synchronize the xml config save_dialplan_xml(); //redirect the user require_once "includes/header.php"; echo "\n"; echo "
\n"; echo "Update Complete\n"; echo "
\n"; require_once "includes/footer.php"; return; } //end if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) ?> "; echo "\n"; echo "\n"; echo " \n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; } else { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists("inbound_route_edit") && $action=="advanced") { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo ""; echo "
\n"; echo "
"; echo "
\n"; echo "
\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
Inbound Call Routing\n"; echo " \n"; echo " \n"; if (permission_exists("inbound_route_edit") && $action == "advanced") { echo " \n"; } else { echo " \n"; } echo " \n"; echo "
\n"; echo " \n"; echo " The public dialplan is used to route incoming calls to destinations based on one or more conditions and context. It can send incoming calls to an auto attendant, huntgroup, extension, external number, or a script.\n"; echo " \n"; echo "
\n"; echo " \n"; echo "
"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists("inbound_route_edit") && $action == "advanced") { echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " Name:\n"; echo "\n"; echo " \n"; echo "
\n"; echo "Please enter an inbound route name.
\n"; echo "
\n"; echo " Condition 1:\n"; echo "\n"; ?> \n"; echo "
Field:\n"; echo " \n"; echo " \n"; echo "
\n"; echo "
  Expression:\n"; echo " \n"; echo "
\n"; echo "
\n"; echo "
\n"; echo " Condition 2:\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " Field:\n"; echo " \n"; ?> \n"; echo " \n"; if (strlen($condition_field_2) > 0) { echo " \n"; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo "
\n"; echo "   Expression:\n"; echo " \n"; echo " \n"; echo "
\n"; echo "
\n"; echo "
\n"; echo " Destination Number:\n"; echo "\n"; echo " \n"; echo "
\n"; echo "Please enter the destination number. In North America this is usually a 10 or 11 digit number.\n"; echo "
\n"; if (permission_exists("inbound_route_edit") && $action=="advanced") { echo " Action 1:\n"; } else { echo " Action:\n"; } echo "\n"; //switch_select_destination(select_type, select_label, select_name, select_value, select_style, action); switch_select_destination("dialplan", "", "action_1", $action_1, "width: 60%;", ""); echo "
\n"; echo " Action 2:\n"; echo "\n"; //switch_select_destination(select_type, select_label, select_name, select_value, select_style, action); switch_select_destination("dialplan", "", "action_2", $action_2, "width: 60%;", ""); echo "
\n"; echo " Limit:\n"; echo "\n"; echo " \n"; echo "
\n"; echo "\n"; echo "
\n"; echo " Order:\n"; echo "\n"; echo " \n"; echo "
\n"; echo "\n"; echo "
\n"; echo " Enabled:\n"; echo "\n"; echo " \n"; echo "
\n"; echo "\n"; echo "
\n"; echo " Description:\n"; echo "\n"; echo " \n"; echo "
\n"; echo "\n"; echo "
\n"; if ($action == "update") { echo " \n"; } echo " \n"; echo "
"; echo ""; echo ""; echo "\n"; echo ""; echo ""; echo ""; echo "

"; //include the footer require_once "includes/footer.php"; ?>