diff --git a/app/time_conditions/time_condition_edit.php b/app/time_conditions/time_condition_edit.php index 86c0f3fc9a..f94dadfcd5 100644 --- a/app/time_conditions/time_condition_edit.php +++ b/app/time_conditions/time_condition_edit.php @@ -63,18 +63,11 @@ require_once "resources/paging.php"; $dialplan_context = check_str($_POST["dialplan_context"]); $dialplan_enabled = check_str($_POST["dialplan_enabled"]); $dialplan_description = check_str($_POST["dialplan_description"]); - - $action_1 = check_str($_POST["action_1"]); - $action_1_array = explode(":", $action_1); - $action_application_1 = array_shift($action_1_array); - $action_data_1 = join(':', $action_1_array); - - $anti_action_1 = check_str($_POST["anti_action_1"]); - $anti_action_1_array = explode(":", $anti_action_1); - $anti_action_application_1 = array_shift($anti_action_1_array); - $anti_action_data_1 = join(':', $anti_action_1_array); } +//set the default_context + $dialplan_context = $_SESSION['context']; + //prcoess the HTTP POST if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { @@ -84,11 +77,11 @@ require_once "resources/paging.php"; //check for all required data $msg = ''; - if (strlen($dialplan_name) == 0) { $msg .= $text['message-required'].$text['label-name']."
\n"; } - if (strlen($dialplan_order) == 0) { $msg .= $text['message-required'].$text['label-order']."
\n"; } - if (strlen($dialplan_continue) == 0) { $msg .= $text['message-required'].$text['label-continue']."
\n"; } - if (strlen($dialplan_context) == 0) { $msg .= $text['message-required'].$text['label-context']."
\n"; } - if (strlen($dialplan_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."
\n"; } + if (strlen($dialplan_name) == 0) { $msg .= $text['message-required'].$text['label-name']." ".__line__."
\n"; } + if (strlen($dialplan_order) == 0) { $msg .= $text['message-required'].$text['label-order']." ".__line__."
\n"; } + if (strlen($dialplan_continue) == 0) { $msg .= $text['message-required'].$text['label-continue']." ".__line__."
\n"; } + if (strlen($dialplan_context) == 0) { $msg .= $text['message-required'].$text['label-context']." ".__line__."
\n"; } + if (strlen($dialplan_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']." ".__line__."
\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"; @@ -103,6 +96,128 @@ require_once "resources/paging.php"; return; } + //remove submit from the post array + unset($_POST["submit"]); + + //get the detail_type and detail_data + $x = 0; + $action_exists = false; + //foreach ($dialplan_details as $row) { + $first_time = true; + foreach ($_POST["dialplan_details"] as $row) { + $time_array = explode(',', 'year,mon,mday,wday,yday,week,mweek,hour,minute,minute-of-day,time-of-day,date-time'); + if (in_array($row["dialplan_detail_type"], $time_array)) { + //$dialplan_times[$group][$type] = $data; + //$dialplan_times[$group]['group'] = $group; + if (strlen($row["dialplan_detail_data"]) == 0) { + if ($first_time) { + $_POST["dialplan_details"][$x]['dialplan_detail_tag'] = 'condition'; + $_POST["dialplan_details"][$x]['dialplan_detail_type'] = 'destination_number'; + $_POST["dialplan_details"][$x]['dialplan_detail_data'] = '^'.$_POST["dialplan_number"].'$'; + $_POST["dialplan_details"][$x]['dialplan_detail_group'] = '0'; + $_POST["dialplan_details"][$x]['dialplan_detail_order'] = '10'; + $_POST["dialplan_details"][$x]['dialplan_detail_break'] = 'never'; + $x++; + $_POST["dialplan_details"][$x]['dialplan_detail_tag'] = 'action'; + $_POST["dialplan_details"][$x]['dialplan_detail_type'] = 'set'; + $_POST["dialplan_details"][$x]['dialplan_detail_data'] = 'time_condition=true'; + $_POST["dialplan_details"][$x]['dialplan_detail_inline'] = 'true'; + $_POST["dialplan_details"][$x]['dialplan_detail_group'] = '0'; + $_POST["dialplan_details"][$x]['dialplan_detail_order'] = '30'; + $x++; + + } + $first_time = false; + + if ($row["scope"] == 'range') { + $data = $row[$row["dialplan_detail_type"]][stop]; + } + else { + $data = $row[$row["dialplan_detail_type"]][start]; + } + $_POST["dialplan_details"][$x]['dialplan_detail_type'] = $row["dialplan_detail_type"]; + $_POST["dialplan_details"][$x]['dialplan_detail_data'] = $data; + $_POST["dialplan_details"][$x]['dialplan_detail_tag'] = 'condition'; + $_POST["dialplan_details"][$x]['dialplan_detail_group'] = '0'; + $_POST["dialplan_details"][$x]['dialplan_detail_order'] = '20'; + $_POST["dialplan_details"][$x]['dialplan_detail_break'] = 'never'; + $x++; + unset($data); + + + //unset rows scope and the array with start and stop + unset($_POST["dialplan_details"][$x]['scope']); + unset($_POST["dialplan_details"][$x][$row["dialplan_detail_type"]]); + } + } + if (strlen($row['action']) > 0) { + //get the application and data + $action_array = explode(":", $row['action']); + $action_application = array_shift($action_array); + $action_data = join(':', $action_array); + + //add the action + $_POST["dialplan_details"][$x]['dialplan_detail_type'] = $action_application; + $_POST["dialplan_details"][$x]['dialplan_detail_data'] = $action_data; + $_POST["dialplan_details"][$x]['dialplan_detail_tag'] = 'action'; + $_POST["dialplan_details"][$x]['dialplan_detail_group'] = '100'; + $_POST["dialplan_details"][$x]['dialplan_detail_order'] = '30'; + + //unset the empty row + if (strlen($row["dialplan_detail_data"]) == 0) { + unset($_POST["dialplan_details"][100]); + } + + //set to true if the action exists + $action_exists = true; + + } + if (strlen($row['anti_action']) > 0) { + //get the application and data + $anti_action_array = explode(":", $row['anti_action']); + $anti_action_application = array_shift($anti_action_array); + $anti_action_data = join(':', $anti_action_array); + + //add the action + $_POST["dialplan_details"][$x]['dialplan_detail_type'] = $anti_action_application; + $_POST["dialplan_details"][$x]['dialplan_detail_data'] = $anti_action_data; + $_POST["dialplan_details"][$x]['dialplan_detail_tag'] = 'anti-action'; + $_POST["dialplan_details"][$x]['dialplan_detail_group'] = '100'; + $_POST["dialplan_details"][$x]['dialplan_detail_order'] = '40'; + + //unset the empty row + if (strlen($row["dialplan_detail_data"]) == 0) { + unset($_POST["dialplan_details"][110]); + } + + //set to true if the action exists + $action_exists = true; + + } + + //increment the row + $x++; + } + + //if the action exists then + if ($action_exists) { + $_POST["dialplan_details"][$x]['dialplan_detail_tag'] = 'condition'; + $_POST["dialplan_details"][$x]['dialplan_detail_type'] = 'destination_number'; + $_POST["dialplan_details"][$x]['dialplan_detail_data'] = '^'.$_POST["dialplan_number"].'$'; + $_POST["dialplan_details"][$x]['dialplan_detail_group'] = '100'; + $_POST["dialplan_details"][$x]['dialplan_detail_order'] = '10'; + $x++; + $_POST["dialplan_details"][$x]['dialplan_detail_tag'] = 'condition'; + $_POST["dialplan_details"][$x]['dialplan_detail_type'] = '${time_condition}'; + $_POST["dialplan_details"][$x]['dialplan_detail_data'] = '^true$'; + $_POST["dialplan_details"][$x]['dialplan_detail_group'] = '100'; + $_POST["dialplan_details"][$x]['dialplan_detail_order'] = '20'; + } + +//echo "
\n";
+//print_r($_POST);
+//echo __line__."
\n"; + //remove the invalid characters from the dialplan name $dialplan_name = $_POST["dialplan_name"]; $dialplan_name = str_replace(" ", "_", $dialplan_name); @@ -120,11 +235,12 @@ require_once "resources/paging.php"; } $array['dialplan_name'] = $dialplan_name; $array['dialplan_number'] = $_POST["dialplan_number"]; - $array['dialplan_context'] = $_POST["dialplan_context"]; + $array['dialplan_context'] = $dialplan_context; $array['dialplan_continue'] = $_POST["dialplan_continue"]; $array['dialplan_order'] = $_POST["dialplan_order"]; $array['dialplan_enabled'] = $_POST["dialplan_enabled"]; $array['dialplan_description'] = $_POST["dialplan_description"]; + $array['app_uuid'] = '4b821450-926b-175a-af93-a03c441818b1'; $x = 0; foreach ($_POST["dialplan_details"] as $row) { if (strlen($row["dialplan_detail_tag"]) > 0) { @@ -142,15 +258,22 @@ require_once "resources/paging.php"; } $x++; } - +echo "
\n";
+print_r($array);
+echo __line__."
\n"; //add or update the database if ($_POST["persistformvar"] != "true") { $orm = new orm; $orm->name('dialplans'); $orm->uuid($dialplan_uuid); $orm->save($array); - //$message = $orm->message; +$message = $orm->message; +echo "
\n";
+print_r($message);
+echo "
\n"; + } +exit; //clear the cache $cache = new cache; @@ -388,6 +511,30 @@ require_once "resources/paging.php"; echo "\n"; } +//set default values when adding a time condition + if (count($details) == 0) { + //$details[0]['domain_uuid'] = $domain_uuid; + $group = 0; + $details[$group][0]['dialplan_detail_tag'] = 'condition'; + $details[$group][0]['dialplan_detail_type'] = 'wday'; + $details[$group][0]['wday']['start'] = '2'; + $details[$group][0]['wday']['stop'] = '6'; + $details[$group][0]['dialplan_detail_data'] = '2-6'; + $details[$group][0]['dialplan_detail_group'] = '0'; + $details[$group][0]['dialplan_detail_order'] = '10'; + $dialplan_times[$group]['preset'] = 'false'; + $group++; + $details[$group][0]['dialplan_detail_tag'] = 'condition'; + $details[$group][0]['dialplan_detail_type'] = 'hour'; + $details[$group][0]['hour']['start'] = '8'; + $details[$group][0]['hour']['stop'] = '17'; + $details[$group][0]['dialplan_detail_data'] = '8-17'; + $details[$group][0]['dialplan_detail_group'] = '1'; + $details[$group][0]['dialplan_detail_order'] = '20'; + $dialplan_times[$group]['preset'] = 'false'; + unset($group); + } + ?>