Portions created by the Initial Developer are Copyright (C) 2008-2019 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"; require_once "resources/paging.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(); //initialize the destinations object $destination = new destinations; //set the variables if (count($_POST) > 0) { $dialplan_name = $_POST["dialplan_name"]; $condition_field_1 = $_POST["condition_field_1"]; $condition_expression_1 = $_POST["condition_expression_1"]; $condition_field_2 = $_POST["condition_field_2"]; $condition_expression_2 = $_POST["condition_expression_2"]; $action_1 = $_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 = $_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 = $_POST["action_application_1"]; //$action_data_1 = $_POST["action_data_1"]; //$action_application_2 = $_POST["action_application_2"]; //$action_data_2 = $_POST["action_data_2"]; $dialplan_context = $_POST["dialplan_context"]; $dialplan_order = $_POST["dialplan_order"]; $dialplan_enabled = $_POST["dialplan_enabled"]; $dialplan_description = $_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['domain_name']; } //add or update data from http post if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); header('Location: dialplans.php'); exit; } //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); //add the main dialplan include entry $dialplan_uuid = uuid(); $array['dialplans'][0]['domain_uuid'] = $domain_uuid; $array['dialplans'][0]['dialplan_uuid'] = $dialplan_uuid; $array['dialplans'][0]['app_uuid'] = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; $array['dialplans'][0]['dialplan_name'] = $dialplan_name; $array['dialplans'][0]['dialplan_order'] = $dialplan_order; $array['dialplans'][0]['dialplan_continue'] = 'false'; $array['dialplans'][0]['dialplan_context'] = $dialplan_context; $array['dialplans'][0]['dialplan_enabled'] = $dialplan_enabled; $array['dialplans'][0]['dialplan_description'] = $dialplan_description; //add condition 1 $dialplan_detail_uuid = uuid(); $array['dialplan_details'][0]['domain_uuid'] = $domain_uuid; $array['dialplan_details'][0]['dialplan_uuid'] = $dialplan_uuid; $array['dialplan_details'][0]['dialplan_detail_uuid'] = $dialplan_detail_uuid; $array['dialplan_details'][0]['dialplan_detail_tag'] = 'condition'; $array['dialplan_details'][0]['dialplan_detail_type'] = $condition_field_1; $array['dialplan_details'][0]['dialplan_detail_data'] = $condition_expression_1; $array['dialplan_details'][0]['dialplan_detail_order'] = '1'; //add condition 2 if (strlen($condition_field_2) > 0) { $dialplan_detail_uuid = uuid(); $array['dialplan_details'][1]['domain_uuid'] = $domain_uuid; $array['dialplan_details'][1]['dialplan_uuid'] = $dialplan_uuid; $array['dialplan_details'][1]['dialplan_detail_uuid'] = $dialplan_detail_uuid; $array['dialplan_details'][1]['dialplan_detail_tag'] = 'condition'; $array['dialplan_details'][1]['dialplan_detail_type'] = $condition_field_2; $array['dialplan_details'][1]['dialplan_detail_data'] = $condition_expression_2; $array['dialplan_details'][1]['dialplan_detail_order'] = '2'; } //add action 1 $dialplan_detail_uuid = uuid(); $array['dialplan_details'][2]['domain_uuid'] = $domain_uuid; $array['dialplan_details'][2]['dialplan_uuid'] = $dialplan_uuid; $array['dialplan_details'][2]['dialplan_detail_uuid'] = $dialplan_detail_uuid; $array['dialplan_details'][2]['dialplan_detail_tag'] = 'action'; if ($destination->valid($action_application_1.':'.$action_data_1)) { $array['dialplan_details'][2]['dialplan_detail_type'] = $action_application_1; $array['dialplan_details'][2]['dialplan_detail_data'] = $action_data_1; } $array['dialplan_details'][2]['dialplan_detail_order'] = '3'; //add action 2 if (strlen($action_application_2) > 0) { $dialplan_detail_uuid = uuid(); $array['dialplan_details'][3]['domain_uuid'] = $domain_uuid; $array['dialplan_details'][3]['dialplan_uuid'] = $dialplan_uuid; $array['dialplan_details'][3]['dialplan_detail_uuid'] = $dialplan_detail_uuid; $array['dialplan_details'][3]['dialplan_detail_tag'] = 'action'; if ($destination->valid($action_application_2.':'.$action_data_2)) { $array['dialplan_details'][3]['dialplan_detail_type'] = $action_application_2; $array['dialplan_details'][3]['dialplan_detail_data'] = $action_data_2; } $array['dialplan_details'][3]['dialplan_detail_order'] = '4'; } //execute inserts $database = new database; $database->app_name = 'dialplans'; $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; $database->save($array); unset($array); //clear the cache $cache = new cache; $cache->delete("dialplan:".$_SESSION["context"]); //send a message and redirect the user message::add($text['message-update']); header("Location: ".PROJECT_PATH."/app/dialplans/dialplans.php"); exit; } //javascript type on change ?> create($_SERVER['PHP_SELF']); //include the header $document['title'] = $text['title-dialplan_add']; require_once "resources/header.php"; //show the content echo "
\n"; echo "
\n"; echo "
".$text['header-dialplan-add']."
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','link'=>'dialplans.php']); echo button::create(['type'=>'button','label'=>$text['button-advanced'],'icon'=>'tools','style'=>'margin-left: 15px;','link'=>'dialplan_edit.php']); echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','style'=>'margin-left: 15px;']); echo "
\n"; echo "
\n"; echo "
\n"; echo $text['description-dialplan_manager-superadmin']."\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-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', escape($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', escape($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 ""; echo "

"; if ($action == "update") { echo "\n"; } echo "\n"; echo "
"; //include the footer require_once "resources/footer.php"; ?>