Portions created by the Initial Developer are Copyright (C) 2008-2016 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('dialplan_add')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //additional includes require_once "resources/header.php"; $document['title'] = $text['title-dialplan_add']; require_once "resources/paging.php"; //set the variables if (count($_POST) > 0) { $dialplan_name = check_str($_POST["dialplan_name"]); $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"]); $dialplan_context = check_str($_POST["dialplan_context"]); $dialplan_order = check_str($_POST["dialplan_order"]); $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 } //set the default if (strlen($dialplan_context) == 0) { $dialplan_context = $_SESSION['context']; } //add or update data from http post if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { //check for all required data if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']."domain_uuid
\n"; } if (strlen($dialplan_name) == 0) { $msg .= $text['message-required'].$text['label-name']."
\n"; } if (strlen($condition_field_1) == 0) { $msg .= $text['message-required'].$text['label-condition_1']." ".$text['label-field']."
\n"; } if (strlen($condition_expression_1) == 0) { $msg .= $text['message-required'].$text['label-condition_1']." ".$text['label-expression']."
\n"; } if (strlen($action_application_1) == 0) { $msg .= $text['message-required'].$text['label-action_1']."
\n"; } //if (strlen($dialplan_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."
\n"; } //if (strlen($dialplan_description) == 0) { $msg .= $text['message-required'].$text['label-description']."
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "
\n"; echo "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/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 $db->exec("BEGIN;"); //returns affected rows //add the main dialplan include 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_continue, "; $sql .= "dialplan_context, "; $sql .= "dialplan_enabled, "; $sql .= "dialplan_description "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$dialplan_uuid', "; $sql .= "'742714e5-8cdf-32fd-462c-cbe7e3d655db', "; $sql .= "'$dialplan_name', "; $sql .= "'$dialplan_order', "; $sql .= "'false', "; $sql .= "'$dialplan_context', "; $sql .= "'$dialplan_enabled', "; $sql .= "'$dialplan_description' "; $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 .= "'1' "; $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 .= "'2' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //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 .= "'3' "; $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 .= "'4' "; $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(); //delete the dialplan context from memcache $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); if ($fp) { $switch_cmd = "memcache delete dialplan:".$dialplan_context; $switch_result = event_socket_request($fp, 'api '.$switch_cmd); } $_SESSION["message"] = $text['message-update']; header("Location: ".PROJECT_PATH."/app/dialplan/dialplans.php"); return; } //end if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //initialize the destinations object $destination = new destinations; //javascript type on change ?> \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['header-dialplan-add']."\n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo "
".$text['description-dialplan_manager-superadmin']."\n"; echo "
"; 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 " ".$text['label-name']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo "\n"; echo "
\n"; //echo " Continue\n"; //echo "\n"; //echo " \n"; //echo "
\n"; //echo "Extension Continue in most cases this is false. default: false\n"; //echo "
\n"; echo " ".$text['label-condition_1']."\n"; echo "\n"; ?> \n"; echo "
".$text['label-field']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo "
   ".$text['label-expression']."\n"; echo "  \n"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " ".$text['label-condition_2']."\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; //echo " \n"; echo " \n"; //echo " \n"; echo " \n"; echo " \n"; echo "
".$text['label-field']."\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 " \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 "
   ".$text['label-expression']."\n"; echo "  \n"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " ".$text['label-action_1']."\n"; echo "\n"; echo "\n"; echo $destination->select('dialplan', 'action_1', $action_1); echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " ".$text['label-action_2']."\n"; echo "\n"; echo "\n"; echo $destination->select('dialplan', 'action_2', $action_2); echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " ".$text['label-context']."\n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " \n"; echo "\n"; echo "\n"; echo "\n"; echo " ".$text['label-order']."\n"; echo "\n"; echo "\n"; echo " \n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " ".$text['label-enabled']."\n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " ".$text['label-description']."\n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; if ($action == "update") { echo " \n"; } echo "
"; echo " \n"; echo " \n"; echo ""; echo ""; echo "

"; echo ""; //include the footer require_once "resources/footer.php"; ?>