diff --git a/app/dialplan/dialplans.php b/app/dialplan/dialplans.php
index b8db853e90..0907ac2fe6 100644
--- a/app/dialplan/dialplans.php
+++ b/app/dialplan/dialplans.php
@@ -280,11 +280,13 @@ else {
unset($app_uuid);
}
- if (
+ if ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_edit')) {
+ $tr_link = "href='".PROJECT_PATH."/app/time_conditions/time_condition_edit.php?id=".$row['dialplan_uuid'].(($app_uuid != '') ? "&app_uuid=".$app_uuid : null)."'";
+ }
+ elseif (
($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_edit')) ||
($app_uuid == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_edit')) ||
($app_uuid == "16589224-c876-aeb3-f59f-523a1c0801f7" && permission_exists('fifo_edit')) ||
- ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_edit')) ||
permission_exists('dialplan_edit')
) {
$tr_link = "href='dialplan_edit.php?id=".$row['dialplan_uuid'].(($app_uuid != '') ? "&app_uuid=".$app_uuid : null)."'";
@@ -295,11 +297,13 @@ else {
$dialplan_ids[] = 'checkbox_'.$row['dialplan_uuid'];
}
echo "
";
- if (
+ if ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_edit')) {
+ echo "".$row['dialplan_name']." ";
+ }
+ elseif (
($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_edit')) ||
($app_uuid == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_edit')) ||
($app_uuid == "16589224-c876-aeb3-f59f-523a1c0801f7" && permission_exists('fifo_edit')) ||
- ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_edit')) ||
permission_exists('dialplan_edit')
) {
echo "".$row['dialplan_name']." ";
@@ -316,11 +320,13 @@ else {
echo " \n";
echo " ".((strlen($row['dialplan_description']) > 0) ? $row['dialplan_description'] : " ")." \n";
echo " \n";
- if (
+ if ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_edit')) {
+ echo "$v_link_label_edit ";
+ }
+ elseif (
($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_edit')) ||
($app_uuid == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_edit')) ||
($app_uuid == "16589224-c876-aeb3-f59f-523a1c0801f7" && permission_exists('fifo_edit')) ||
- ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_edit')) ||
permission_exists('dialplan_edit')
) {
echo "$v_link_label_edit ";
diff --git a/app/time_conditions/app_defaults.php b/app/time_conditions/app_defaults.php
index 33f933a6f7..249ed0f0f5 100644
--- a/app/time_conditions/app_defaults.php
+++ b/app/time_conditions/app_defaults.php
@@ -3,16 +3,16 @@
if ($domains_processed == 1) {
//define holiday presets
- $preset[] = json_encode(array("new_years_day" => array("variables" => array("mday" => "1", "mon" => "1"))));
- $preset[] = json_encode(array("martin_luther_king_jr_day" => array("variables" => array("wday" => "2", "mon" => "1", "mweek" => "3"))));
- $preset[] = json_encode(array("presidents_day" => array("variables" => array("wday" => "2", "mon" => "2", "mweek" => "3"))));
- $preset[] = json_encode(array("memorial_day" => array("variables" => array("mday" => "25-31", "wday" => "2", "mon" => "5"))));
- $preset[] = json_encode(array("independence_day" => array("variables" => array("mday" => "4", "mon" => "7"))));
- $preset[] = json_encode(array("labor_day" => array("variables" => array("wday" => "2", "mon" => "9", "mweek" => "1"))));
- $preset[] = json_encode(array("columbus_day" => array("variables" => array("wday" => "2", "mon" => "10", "mweek" => "2"))));
- $preset[] = json_encode(array("veterans_day" => array("variables" => array("mday" => "11", "mon" => "11"))));
- $preset[] = json_encode(array("thanksgiving_day" => array("variables" => array("wday" => "5-6", "mon" => "11", "mweek" => "4"))));
- $preset[] = json_encode(array("christmas_day" => array("variables" => array("mday" => "25", "mon" => "12"))));
+ $preset[] = json_encode(array("new_years_day" => array("mday" => "1", "mon" => "1")));
+ $preset[] = json_encode(array("martin_luther_king_jr_day" => array("wday" => "2", "mon" => "1", "mweek" => "3")));
+ $preset[] = json_encode(array("presidents_day" => array("wday" => "2", "mon" => "2", "mweek" => "3")));
+ $preset[] = json_encode(array("memorial_day" => array("mday" => "25-31", "wday" => "2", "mon" => "5")));
+ $preset[] = json_encode(array("independence_day" => array("mday" => "4", "mon" => "7")));
+ $preset[] = json_encode(array("labor_day" => array("wday" => "2", "mon" => "9", "mweek" => "1")));
+ $preset[] = json_encode(array("columbus_day" => array("wday" => "2", "mon" => "10", "mweek" => "2")));
+ $preset[] = json_encode(array("veterans_day" => array("mday" => "11", "mon" => "11")));
+ $preset[] = json_encode(array("thanksgiving_day" => array("wday" => "5-6", "mon" => "11", "mweek" => "4")));
+ $preset[] = json_encode(array("christmas_day" => array("mday" => "25", "mon" => "12")));
//define array of settings
$x = 0;
diff --git a/app/time_conditions/app_languages.php b/app/time_conditions/app_languages.php
index 4e4b7a4d12..02ad6c9854 100644
--- a/app/time_conditions/app_languages.php
+++ b/app/time_conditions/app_languages.php
@@ -1,14 +1,14 @@
- Portions created by the Initial Developer are Copyright (C) 2008-2015
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Mark J Crane
-*/
-include "root.php";
-require_once "resources/require.php";
-require_once "resources/check_auth.php";
-if (permission_exists('time_condition_add') || permission_exists('time_condition_edit')) {
- //access granted
-}
-else {
- echo "access denied";
- exit;
-}
-require_once "resources/header.php";
-require_once "resources/paging.php";
-
-//add multi-lingual support
- $language = new text;
- $text = $language->get();
-
-//set the action as an add or an update
- if (isset($_REQUEST["id"])) {
- $action = "update";
- $dialplan_uuid = check_str($_REQUEST["id"]);
- }
- else {
- $action = "add";
- }
-
-//get the app uuid
- $app_uuid = check_str($_REQUEST["app_uuid"]);
-
-//get the http post values and set them as php variables
- if (count($_POST) > 0) {
- $dialplan_name = check_str($_POST["dialplan_name"]);
- $dialplan_number = check_str($_POST["dialplan_number"]);
- $dialplan_order = check_str($_POST["dialplan_order"]);
- $dialplan_continue = check_str($_POST["dialplan_continue"]);
- $dialplan_details = $_POST["dialplan_details"];
- if (strlen($dialplan_continue) == 0) { $dialplan_continue = "false"; }
- $dialplan_context = check_str($_POST["dialplan_context"]);
- $dialplan_enabled = check_str($_POST["dialplan_enabled"]);
- $dialplan_description = check_str($_POST["dialplan_description"]);
- }
-
-//set the default_context
- $dialplan_context = $_SESSION['context'];
-
-//prcoess the HTTP POST
- if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
-
- if ($action == "update") {
- $dialplan_uuid = check_str($_POST["dialplan_uuid"]);
- }
-
- //check for all required data
- $msg = '';
- 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";
- 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 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);
- $dialplan_name = str_replace("/", "", $dialplan_name);
-
- //build the array
- if (strlen($row["dialplan_uuid"]) > 0) {
- $array['dialplan_uuid'] = $_POST["dialplan_uuid"];
- }
- if (isset($_POST["domain_uuid"])) {
- $array['domain_uuid'] = $_POST['domain_uuid'];
- }
- else {
- $array['domain_uuid'] = $_SESSION['domain_uuid'];
- }
- $array['dialplan_name'] = $dialplan_name;
- $array['dialplan_number'] = $_POST["dialplan_number"];
- $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) {
- if (strlen($row["dialplan_detail_uuid"]) > 0) {
- $array['dialplan_details'][$x]['dialplan_detail_uuid'] = $row["dialplan_detail_uuid"];
- }
- $array['dialplan_details'][$x]['domain_uuid'] = $array['domain_uuid'];
- $array['dialplan_details'][$x]['dialplan_detail_tag'] = $row["dialplan_detail_tag"];
- $array['dialplan_details'][$x]['dialplan_detail_type'] = $row["dialplan_detail_type"];
- $array['dialplan_details'][$x]['dialplan_detail_data'] = $row["dialplan_detail_data"];
- $array['dialplan_details'][$x]['dialplan_detail_break'] = $row["dialplan_detail_break"];
- $array['dialplan_details'][$x]['dialplan_detail_inline'] = $row["dialplan_detail_inline"];
- $array['dialplan_details'][$x]['dialplan_detail_group'] = $row["dialplan_detail_group"];
- $array['dialplan_details'][$x]['dialplan_detail_order'] = $row["dialplan_detail_order"];
- }
- $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;
-echo "\n";
-print_r($message);
-echo " \n";
-
- }
-exit;
-
- //clear the cache
- $cache = new cache;
- //$cache->delete("dialplan:".$dialplan_context);
- $cache->delete("dialplan:".$_SESSION["context"]);
-
- //synchronize the xml config
- save_dialplan_xml();
-
- //set the message
- if ($action == "add") {
- $_SESSION['message'] = $text['message-add'];
- }
- else if ($action == "update") {
- $_SESSION['message'] = $text['message-update'];
- }
- header("Location: time_condition_edit.php?id=".$dialplan_uuid.(($app_uuid != '') ? "&app_uuid=".$app_uuid : null));
- return;
-
- } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
-
-//get the information to pre-populate the form
- if (strlen($_GET['id']) > 0) {
- //get the dialplan
- if (count($_GET) > 0 && $_POST["persistformvar"] != "true") {
- $dialplan_uuid = $_GET["id"];
- $orm = new orm;
- $orm->name('dialplans');
- $orm->uuid($dialplan_uuid);
- $result = $orm->find()->get();
- //$message = $orm->message;
- foreach ($result as &$row) {
- $domain_uuid = $row["domain_uuid"];
- //$app_uuid = $row["app_uuid"];
- $dialplan_name = $row["dialplan_name"];
- $dialplan_number = $row["dialplan_number"];
- $dialplan_order = $row["dialplan_order"];
- $dialplan_continue = $row["dialplan_continue"];
- $dialplan_context = $row["dialplan_context"];
- $dialplan_enabled = $row["dialplan_enabled"];
- $dialplan_description = $row["dialplan_description"];
- }
- unset ($prep_statement);
- }
-
- //get the dialplan details in an array
- $sql = "select * from v_dialplan_details ";
- $sql .= "where dialplan_uuid = '$dialplan_uuid' ";
- $sql .= "order by dialplan_detail_group asc, dialplan_detail_order asc";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- $result_count = count($result);
- unset ($prep_statement, $sql);
-
- //create a new array that is sorted into groups and put the tags in order conditions, actions, anti-actions
- $x = 0;
- $details = '';
- //conditions
- foreach($result as $row) {
- if ($row['dialplan_detail_tag'] == "condition") {
- $group = $row['dialplan_detail_group'];
- foreach ($row as $key => $val) {
- $details[$group][$x][$key] = $val;
- }
- }
- $x++;
- }
- //regex
- foreach($result as $row) {
- if ($row['dialplan_detail_tag'] == "regex") {
- $group = $row['dialplan_detail_group'];
- foreach ($row as $key => $val) {
- $details[$group][$x][$key] = $val;
- }
- }
- $x++;
- }
- //actions
- foreach($result as $row) {
- if ($row['dialplan_detail_tag'] == "action") {
- $group = $row['dialplan_detail_group'];
- foreach ($row as $key => $val) {
- $details[$group][$x][$key] = $val;
- }
- }
- $x++;
- }
- //anti-actions
- foreach($result as $row) {
- if ($row['dialplan_detail_tag'] == "anti-action") {
- $group = $row['dialplan_detail_group'];
- foreach ($row as $key => $val) {
- $details[$group][$x][$key] = $val;
- }
- }
- $x++;
- }
- unset($result);
-
- //get the last action and anti-action
- foreach($details as $group) {
- foreach ($group as $row) {
- if ($row['dialplan_detail_tag'] == 'action') {
- //echo $row['dialplan_detail_tag']." ".$row['dialplan_detail_type'].":".$row['dialplan_detail_data']."\n";
- $detail_action = $row['dialplan_detail_type'].':'.$row['dialplan_detail_data'];
- }
- if ($row['dialplan_detail_tag'] == 'anti-action') {
- //echo $row['dialplan_detail_tag']." ".$row['dialplan_detail_type'].":".$row['dialplan_detail_data']."\n";
- $detail_anti_action = $row['dialplan_detail_type'].':'.$row['dialplan_detail_data'];
- }
- }
- }
-
- //blank row
- foreach($details as $group => $row) {
- //set the array key for the empty row
- $x = "999";
- //get the highest dialplan_detail_order
- foreach ($row as $key => $field) {
- $dialplan_detail_order = 0;
- if ($dialplan_detail_order < $field['dialplan_detail_order']) {
- $dialplan_detail_order = $field['dialplan_detail_order'];
- }
- }
- //increment the highest order by 5
- $dialplan_detail_order = $dialplan_detail_order + 10;
- //set the rest of the empty array
- //$details[$group][$x]['domain_uuid'] = '';
- //$details[$group][$x]['dialplan_uuid'] = '';
- $details[$group][$x]['dialplan_detail_tag'] = '';
- $details[$group][$x]['dialplan_detail_type'] = '';
- $details[$group][$x]['dialplan_detail_data'] = '';
- $details[$group][$x]['dialplan_detail_break'] = '';
- $details[$group][$x]['dialplan_detail_inline'] = '';
- $details[$group][$x]['dialplan_detail_group'] = $group;
- $details[$group][$x]['dialplan_detail_order'] = $dialplan_detail_order;
- $details[$group][$x]['preset'] = 'false';
- }
- }
-
-//get the presets
- foreach ($_SESSION['time_conditions']['preset'] as $json) {
- $presets[] = json_decode($json, true);
- }
-
-//get the time array from the dialplan set it as array dialplan_times
- $x = 0;
- foreach($details as $detail_group) {
- foreach ($detail_group as $row) {
- if ($row['dialplan_detail_tag'] == 'condition') {
- $type = $row['dialplan_detail_type'];
- $data = $row['dialplan_detail_data'];
- $group = $row['dialplan_detail_group'];
- //echo "type: ".$type. " data: ".$data." \n";
- $array = explode(',', 'year,mon,mday,wday,yday,week,mweek,hour,minute,minute-of-day,time-of-day,date-time');
- if (in_array($type, $array)) {
- $dialplan_times[$group][$type] = $data;
- $dialplan_times[$group]['group'] = $group;
- }
- }
- }
- $x++;
- }
-
-//get the preset_times
- $p = 0;
- foreach ($presets as $preset_number => $preset) {
- foreach ($preset as $preset_name => $preset_variables) {
- $preset_times[] = $preset_variables['variables'];
- }
- }
-
-//add a function to check the time to see if its is a preset time
- function is_preset($presets, $times) {
- if ($_GET['debug'] == 'true') {
- echo "\n";
- echo " \n";
- echo " \n";
- }
- $preset_keys = array();
- foreach ($presets as $row) {
- if ($_GET['debug'] == 'true') {
- echo "
\n";
- }
- $match = true;
- foreach ($row as $k => $v) {
- if ($_GET['debug'] == 'true') {
- echo "\n";
- echo "".$k." ".$row[$k]." ".$k." ".$times[$k]." ";
- }
- if ($row[$k] == $times[$k]) {
- if ($_GET['debug'] == 'true') { echo "match "; }
- }
- else {
- if ($_GET['debug'] == 'true') { echo "no match "; }
- $match = false;
- }
- if ($_GET['debug'] == 'true') {
- echo " \n";
- }
- }
- if ($_GET['debug'] == 'true') {
- echo "
\n";
- echo " \n";
- }
- if ($match) { return true; }
- }
- return false;
- }
-
-//set preset to true or false on dialplan_times array
- $x = 0;
- foreach ($dialplan_times as $times) {
- if ($_GET['debug'] == 'true') {
- echo "\n";
- print_r($times);
- echo " \n";
- echo " \n";
- }
- $g = $times['group'];
- if (is_preset($preset_times, $times)) {
- $dialplan_times[$g]['preset'] = 'true';
- }
- else {
- $dialplan_times[$g]['preset'] = 'false';
- }
- $x++;
- }
-
-//show the results
- if ($_GET['debug'] == 'true') {
- echo "\n";
- print_r($dialplan_times);
- 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);
- }
-
-?>
-
-
-
-\n";
-
- echo "";
-
- echo " \n";
- echo " \n";
-
- echo "\n";
-
- echo "\n";
- echo "\n";
- echo " ".$text['label-name']."\n";
- echo " \n";
- echo "\n";
- echo " \n";
- echo " \n";
- echo " ".$text['description-name']."\n";
- echo " \n";
- echo "\n";
- echo " \n";
- echo " \n";
-
- echo "\n";
- echo "\n";
- echo " ".$text['label-extension']."\n";
- echo " \n";
- echo "\n";
- echo " \n";
- echo " \n";
- echo " ".$text['description-extension']." \n";
- echo " \n";
- echo " \n";
-
- echo "\n";
- echo "\n";
- echo " ".$text['label-conditions']."\n";
- echo " \n";
- echo "\n";
- //define select box options for each time condition variable (where appropriate)
- for ($y = date('Y'); $y <= (date('Y') + 10); $y++) { $var_option_select['year'][$y] = $y; } //years
- for ($m = 1; $m <= 12; $m++) { $var_option_select['mon'][$m] = date('F', strtotime('2015-'.number_pad($m,2).'-01')); } //month names
- for ($d = 1; $d <= 366; $d++) { $var_option_select['yday'][$d] = $d; } //days of year
- for ($d = 1; $d <= 31; $d++) { $var_option_select['mday'][$d] = $d; } //days of month
- for ($d = 1; $d <= 7; $d++) { $var_option_select['wday'][$d] = date('l', strtotime('Sunday +'.($d-1).' days')); } //week days
- for ($w = 1; $w <= 53; $w++) { $var_option_select['week'][$w] = $w; } //weeks of year
- for ($w = 1; $w <= 5; $w++) { $var_option_select['mweek'][$w] = $w; } //weeks of month
- for ($h = 0; $h <= 23; $h++) { $var_option_select['hour'][$h] = (($h) ? (($h >= 12) ? (($h == 12) ? $h : ($h-12)).' PM' : $h.' AM') : '12 AM'); } //hours of day
- for ($m = 0; $m <= 59; $m++) { $var_option_select['minute'][$m] = number_pad($m,2); } //minutes of hour
- //output condition fields
- echo " \n";
- if ($action == 'add') {
- echo "\n";
- }
- echo " ".$text['description-conditions']." \n";
- echo " \n";
- echo " \n";
-
- //show the presets
- echo "\n";
- echo "\n";
- echo " ".$text['label-presets']."\n";
- echo " \n";
- echo "\n";
-
- //echo ""; print_r($presets); echo " ";
- echo " \n";
- echo " \n";
- echo " \n";
- $preset_count = sizeof($presets);
- $presets_per_column = ceil($preset_count / 3);
- $p = 0;
- foreach ($presets as $preset_number => $preset) {
- foreach ($preset as $preset_name => $preset_variables) {
- $preset_times = $preset_variables['variables'];
- foreach ($dialplan_times as $row) {
- $array = explode(',', 'year,mon,mday,wday,yday,week,mweek,hour,minute,minute-of-day,time-of-day,date-time');
- if ($_GET['debug'] == 'true') {
- echo "\n";
- echo "\n";
- echo " database \n";
- echo " value \n";
- echo " presets \n";
- echo " value \n";
- echo " match \n";
- echo " \n";
- }
- $y = 0;
- $match = true;
- foreach ($array as $k) {
- if (strlen($preset_times[$k]) > 0) {
- if ($_GET['debug'] == 'true') {
- echo "\n";
- echo "$k ".$row[$k]." $k ".$preset_times[$k]." ";
- }
- if ($row[$k] == $preset_times[$k]) {
- if ($_GET['debug'] == 'true') {
- echo "true \n";
- }
- }
- else {
- if ($_GET['debug'] == 'true') {
- echo "false \n";
- }
- $match = false;
- }
- if ($_GET['debug'] == 'true') {
- echo " \n";
- }
- $y++;
- }
- }
- if ($_GET['debug'] == 'true') {
- echo "
";
- }
- if ($match) {
- break;
- }
- }
-
- if ($match) { $checked = "checked='checked'"; } else { $checked = ''; }
- echo " ".$text['label-preset_'.$preset_name]." \n";
- $p++;
- if ($p == $presets_per_column) {
- echo " ";
- echo " \n";
- $p = 0;
- }
- }
- }
- echo " \n";
- echo " \n";
- echo "
\n";
- echo " \n";
- echo " ".$text['description-presets']." \n";
- echo " \n";
- echo " \n";
-
- //add destinations
- if (strlen($_GET['id']) == 0) {
- echo "\n";
- echo "\n";
- echo " ".$text['label-action']."\n";
- echo " \n";
- echo "\n";
- //switch_select_destination(select_type, select_label, select_name, select_value, select_style, $action);
- switch_select_destination("dialplan", $action_1, "dialplan_details[100][action]", "$detail_action", "", "");
- echo " \n";
- echo " \n";
-
- echo "\n";
- echo "\n";
- echo " ".$text['label-action-alternate']."\n";
- echo " \n";
- echo "\n";
- //switch_select_destination(select_type, select_label, select_name, select_value, select_style, $action);
- switch_select_destination("dialplan", $anti_action_1, "dialplan_details[110][anti_action]", "$detail_anti_action ", "", "");
- echo " \n";
- echo " \n";
- }
-
- //edit destinations
- $action_exists = false;
- $x = 0;
- foreach($details as $group) {
- foreach ($group as $row) {
- if ($row['dialplan_detail_tag'] == 'action' && $row['dialplan_detail_type'] != 'set') {
- echo "\n";
- echo "\n";
- echo " ".$text['label-action']."\n";
- echo " \n";
- echo "\n";
- //switch_select_destination(select_type, select_label, select_name, select_value, select_style, $action);
- $data = $row['dialplan_detail_data'];
- $label = explode("XML", $data);
- $divider = ($row['dialplan_detail_type'] != '') ? ":" : null;
- $detail_action = $row['dialplan_detail_type'].$divider.$row['dialplan_detail_data'];
- switch_select_destination("dialplan", $label[0], "dialplan_details[".$x."]['action']", $detail_action, "width: 60%;", 'action');
- echo " \n";
- echo " \n";
- $action_exists = true;
- }
- if ($row['dialplan_detail_tag'] == 'anti-action' && $row['dialplan_detail_type'] != 'set') {
- echo "\n";
- echo "\n";
- echo " ".$text['label-action-alternate']."\n";
- echo " \n";
- echo "\n";
- //switch_select_destination(select_type, select_label, select_name, select_value, select_style, $action);
- $label = explode("XML", $row['dialplan_detail_data']);
- $divider = ($row['dialplan_detail_type'] != '') ? ":" : null;
- $detail_action = $row['dialplan_detail_type'].$divider.$row['dialplan_detail_data'];
- switch_select_destination("dialplan", $label[0], "dialplan_details[".$x."]['anti_action']", $detail_anti_action, "width: 60%;", 'action');
- echo " \n";
- echo " \n";
- $action_exists = true;
- }
- }
- $x++;
- }
-
- echo "\n";
- echo "\n";
- echo " ".$text['label-order']."\n";
- echo " \n";
- echo "\n";
- echo " \n";
- $i = 300;
- while($i <= 999) {
- $selected = ($dialplan_order == $i) ? "selected" : null;
- if (strlen($i) == 1) { echo "00$i \n"; }
- if (strlen($i) == 2) { echo "0$i \n"; }
- if (strlen($i) == 3) { echo "$i \n"; }
- $i = $i + 10;
- }
- echo " \n";
- echo " \n";
- echo " \n";
- echo " \n";
-
- echo "\n";
- echo "\n";
- echo " ".$text['label-enabled']."\n";
- echo " \n";
- echo "\n";
- echo " \n";
- if ($dialplan_enabled == "true") {
- echo " ".$text['label-true']." \n";
- }
- else {
- echo " ".$text['label-true']." \n";
- }
- if ($dialplan_enabled == "false") {
- echo " ".$text['label-false']." \n";
- }
- else {
- echo " ".$text['label-false']." \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";
- echo " ";
-
- echo "\n";
- if ($action == "update") {
- echo " \n";
- }
- echo " \n";
- echo "
";
-
- echo "";
- echo " ";
-
-//include the footer
- require_once "resources/footer.php";
-
+
+ Portions created by the Initial Developer are Copyright (C) 2008-2015
+ the Initial Developer. All Rights Reserved.
+
+ Contributor(s):
+ Mark J Crane
+*/
+include "root.php";
+require_once "resources/require.php";
+require_once "resources/check_auth.php";
+if (permission_exists('time_condition_add') || permission_exists('time_condition_edit')) {
+ //access granted
+}
+else {
+ echo "access denied";
+ exit;
+}
+require_once "resources/header.php";
+require_once "resources/paging.php";
+
+
+//add multi-lingual support
+ $language = new text;
+ $text = $language->get();
+
+//load available presets
+ foreach ($_SESSION['time_conditions']['preset'] as $json) {
+ $available_presets[] = json_decode($json, true);
+ }
+
+//set the action as an add or an update
+ if (isset($_REQUEST["id"])) {
+ $action = "update";
+ $dialplan_uuid = check_str($_REQUEST["id"]);
+ }
+ else {
+ $action = "add";
+ }
+
+//get the post variables
+ if (count($_POST) > 0) {
+ $dialplan_name = check_str($_POST["dialplan_name"]);
+ $dialplan_number = check_str($_POST["dialplan_number"]);
+ $dialplan_order = check_str($_POST["dialplan_order"]);
+
+ $dialplan_action = check_str($_POST["dialplan_action"]);
+ $dialplan_action_array = explode(":", $dialplan_action);
+ $dialplan_action_app = array_shift($dialplan_action_array);
+ $dialplan_action_data = join(':', $dialplan_action_array);
+
+ $dialplan_anti_action = check_str($_POST["dialplan_anti_action"]);
+ $dialplan_anti_action_array = explode(":", $dialplan_anti_action);
+ $dialplan_anti_action_app = array_shift($dialplan_anti_action_array);
+ $dialplan_anti_action_data = join(':', $dialplan_anti_action_array);
+
+ $dialplan_enabled = check_str($_POST["dialplan_enabled"]);
+ $dialplan_description = check_str($_POST["dialplan_description"]);
+ }
+
+ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
+ //check for all required data
+ if (strlen($domain_uuid) == 0) { $msg .= $text['label-required-domain_uuid']." \n"; }
+ if (strlen($dialplan_name) == 0) { $msg .= $text['label-required-dialplan_name']." \n"; }
+ if (strlen($dialplan_number) == 0) { $msg .= $text['label-required-dialplan_number']." \n"; }
+ if (strlen($dialplan_action) == 0) { $msg .= $text['label-required-action']." \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 dialplan name
+ $dialplan_name = str_replace(' ', '_', $dialplan_name);
+ $dialplan_name = str_replace('/', '', $dialplan_name);
+
+
+ //start the atomic transaction
+ $count = $db->exec("BEGIN;"); //returns affected rows
+
+ //process main dialplan entry
+ if ($action == "add") {
+
+ //add 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_number, ";
+ $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 .= "'4b821450-926b-175a-af93-a03c441818b1', ";
+ $sql .= "'".$dialplan_name."', ";
+ $sql .= "'".$dialplan_number."', ";
+ $sql .= "'".$dialplan_order."', ";
+ $sql .= "'true', ";
+ $sql .= "'".$_SESSION['context']."', ";
+ $sql .= "'".$dialplan_enabled."', ";
+ $sql .= "'".$dialplan_description."' ";
+ $sql .= ")";
+
+ //execute query
+ $db->exec(check_sql($sql));
+ unset($sql);
+
+ }
+ else if ($action == "update") {
+
+ //update main dialplan entry
+ $sql = "update v_dialplans set ";
+ $sql .= "dialplan_name = '".$dialplan_name."', ";
+ $sql .= "dialplan_number = '".$dialplan_number."', ";
+ $sql .= "dialplan_order = '".$dialplan_order."', ";
+ $sql .= "dialplan_continue = 'true', ";
+ $sql .= "dialplan_context = '".$_SESSION['context']."', ";
+ $sql .= "dialplan_enabled = '".$dialplan_enabled."', ";
+ $sql .= "dialplan_description = '".$dialplan_description."' ";
+ $sql .= "where domain_uuid = '".$domain_uuid."' ";
+ $sql .= "and dialplan_uuid = '".$dialplan_uuid."' ";
+ $db->exec(check_sql($sql));
+ unset($sql);
+
+ //delete existing dialplan details
+ $sql = "delete from v_dialplan_details ";
+ $sql .= "where dialplan_uuid = '".$dialplan_uuid."'; ";
+ $db->query($sql);
+ unset($sql);
+
+ }
+
+
+ //initialize dialplan detail group and order numbers
+ $dialplan_detail_group = 0;
+ $dialplan_detail_order = 0;
+
+
+ //check if custom conditions defined
+ $custom_conditions_defined = false;
+ foreach ($_REQUEST['variable'] as $cond_var) {
+ if ($cond_var != '') { $custom_conditions_defined = true; }
+ }
+
+ if ($custom_conditions_defined) {
+
+ //build insert query for custom conditions
+ $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_break, ";
+ $sql .= "dialplan_detail_inline, ";
+ $sql .= "dialplan_detail_group, ";
+ $sql .= "dialplan_detail_order ";
+ $sql .= ") ";
+ $sql .= "values ";
+
+ //add destination number condition
+ $dialplan_detail_order += 10;
+ $sql .= "( ";
+ $sql .= "'".$domain_uuid."', ";
+ $sql .= "'".$dialplan_uuid."', ";
+ $sql .= "'".uuid()."', ";
+ $sql .= "'condition', ";
+ $sql .= "'destination_number', ";
+ $sql .= "'^".$dialplan_number."$', ";
+ $sql .= "'never', ";
+ $sql .= "null, ";
+ $sql .= "'".$dialplan_detail_group."', ";
+ $sql .= "'".$dialplan_detail_order."' ";
+ $sql .= ")";
+
+ //add custom conditions
+ foreach ($_REQUEST['variable'] as $cond_num => $cond_var) {
+ if ($cond_var != '') {
+ $scope = $_REQUEST['scope'][$cond_num];
+ $cond_start = $_REQUEST[$cond_var][$cond_num]['start'];
+ $cond_stop = $_REQUEST[$cond_var][$cond_num]['stop'];
+
+ //handle time of day
+ if ($cond_var == 'time-of-day' && $cond_start['hour'] != '') {
+ //format condition start
+ if ($cond_start['notation'] == 'PM') {
+ $cond_start_hour = ($cond_start['hour'] != 12) ? $cond_start['hour'] += 12 : $cond_start['hour'];
+ }
+ else if ($cond_start['notation'] == 'AM') {
+ $cond_start_hour = ($cond_start['hour'] == 12) ? $cond_start['hour'] -= 12 : $cond_start['hour'];
+ }
+ $cond_start_hour = number_pad($cond_start_hour,2);
+ $cond_start_minute = $cond_start['minute'];
+ $cond_start = $cond_start_hour.':'.$cond_start_minute;
+
+ //format condition stop
+ if ($cond_start != '' && $scope == 'range') {
+ if ($cond_stop['notation'] == 'PM') {
+ $cond_stop_hour = ($cond_stop['hour'] != 12) ? $cond_stop['hour'] += 12 : $cond_stop['hour'];
+ }
+ else if ($cond_stop['notation'] == 'AM') {
+ $cond_stop_hour = ($cond_stop['hour'] == 12) ? $cond_stop['hour'] -= 12 : $cond_stop['hour'];
+ }
+ $cond_stop_hour = number_pad($cond_stop_hour,2);
+ $cond_stop_minute = $cond_stop['minute'];
+ $cond_stop = $cond_stop_hour.':'.$cond_stop_minute;
+ }
+ else {
+ unset($cond_stop);
+ }
+
+ $cond_value = $cond_start.(($cond_stop != '') ? '-'.$cond_stop : null);
+ }
+ //handle all other variables
+ else {
+ if ($cond_start != '') {
+ $cond_value = $cond_start;
+ if ($scope == 'range' && $cond_stop != '') {
+ $range_indicator = ($cond_var == 'date-time') ? '~' : '-';
+ $cond_value .= $range_indicator.$cond_stop;
+ }
+ }
+ }
+
+ //add condition to query string
+ $dialplan_detail_order += 10;
+ $sql .= ", ( ";
+ $sql .= "'".$domain_uuid."', ";
+ $sql .= "'".$dialplan_uuid."', ";
+ $sql .= "'".uuid()."', ";
+ $sql .= "'condition', ";
+ $sql .= "'".$cond_var."', ";
+ $sql .= "'".$cond_value."', ";
+ $sql .= "'never', ";
+ $sql .= "null, ";
+ $sql .= "'".$dialplan_detail_group."', ";
+ $sql .= "'".$dialplan_detail_order."' ";
+ $sql .= ") ";
+ }
+ }
+
+ //add condition action
+ $dialplan_detail_order += 10;
+ $sql .= ", ( ";
+ $sql .= "'".$domain_uuid."', ";
+ $sql .= "'".$dialplan_uuid."', ";
+ $sql .= "'".uuid()."', ";
+ $sql .= "'action', ";
+ $sql .= "'set', ";
+ $sql .= "'time_condition=true', ";
+ $sql .= "null, ";
+ $sql .= "'true', ";
+ $sql .= "'".$dialplan_detail_group."', ";
+ $sql .= "'".$dialplan_detail_order."' ";
+ $sql .= ") ";
+
+ //execute query
+ $db->exec(check_sql($sql));
+ unset($sql);
+
+ }
+
+
+ //add to query for preset conditions (if any)
+ if (sizeof($_REQUEST['preset']) > 0) {
+
+ //build insert query for preset conditions
+ $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_break, ";
+ $sql .= "dialplan_detail_inline, ";
+ $sql .= "dialplan_detail_group, ";
+ $sql .= "dialplan_detail_order ";
+ $sql .= ") ";
+ $sql .= "values ";
+
+ foreach ($_REQUEST['preset'] as $index => $preset_number) {
+
+ //increment group and order number
+ $dialplan_detail_group += 10;
+ $dialplan_detail_order = 0;
+
+ //add destination number condition
+ $dialplan_detail_order += 10;
+ $sql .= ($index != 0) ? "," : null;
+ $sql .= " ( ";
+ $sql .= "'".$domain_uuid."', ";
+ $sql .= "'".$dialplan_uuid."', ";
+ $sql .= "'".uuid()."', ";
+ $sql .= "'condition', ";
+ $sql .= "'destination_number', ";
+ $sql .= "'^".$dialplan_number."$', ";
+ $sql .= "'never', ";
+ $sql .= "null, ";
+ $sql .= "'".$dialplan_detail_group."', ";
+ $sql .= "'".$dialplan_detail_order."' ";
+ $sql .= ") ";
+
+ foreach ($available_presets[$preset_number] as $preset_name => $preset_variables) {
+ foreach ($preset_variables as $cond_var => $cond_value) {
+ //add preset condition to query string
+ $dialplan_detail_order += 10;
+ $sql .= ", ( ";
+ $sql .= "'".$domain_uuid."', ";
+ $sql .= "'".$dialplan_uuid."', ";
+ $sql .= "'".uuid()."', ";
+ $sql .= "'condition', ";
+ $sql .= "'".$cond_var."', ";
+ $sql .= "'".$cond_value."', ";
+ $sql .= "'never', ";
+ $sql .= "null, ";
+ $sql .= "'".$dialplan_detail_group."', ";
+ $sql .= "'".$dialplan_detail_order."' ";
+ $sql .= ") ";
+ }
+ }
+
+ //add condition action
+ $dialplan_detail_order += 10;
+ $sql .= ", ( ";
+ $sql .= "'".$domain_uuid."', ";
+ $sql .= "'".$dialplan_uuid."', ";
+ $sql .= "'".uuid()."', ";
+ $sql .= "'action', ";
+ $sql .= "'set', ";
+ $sql .= "'time_condition=true', ";
+ $sql .= "null, ";
+ $sql .= "'true', ";
+ $sql .= "'".$dialplan_detail_group."', ";
+ $sql .= "'".$dialplan_detail_order."' ";
+ $sql .= ") ";
+
+ }
+
+ //execute query
+ $db->exec(check_sql($sql));
+ unset($sql);
+
+ }
+
+
+ //increment group number, reset order number
+ $dialplan_detail_group = 999;
+ $dialplan_detail_order = 0;
+
+ //add to query for main action and anti-action condition
+
+ //build insert query for custom conditions
+ $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_break, ";
+ $sql .= "dialplan_detail_inline, ";
+ $sql .= "dialplan_detail_group, ";
+ $sql .= "dialplan_detail_order ";
+ $sql .= ") ";
+ $sql .= "values ";
+
+ //add destination number condition
+ $dialplan_detail_order += 10;
+ $sql .= "( ";
+ $sql .= "'".$domain_uuid."', ";
+ $sql .= "'".$dialplan_uuid."', ";
+ $sql .= "'".uuid()."', ";
+ $sql .= "'condition', ";
+ $sql .= "'destination_number', ";
+ $sql .= "'^".$dialplan_number."$', ";
+ $sql .= "null, ";
+ $sql .= "null, ";
+ $sql .= "'".$dialplan_detail_group."', ";
+ $sql .= "'".$dialplan_detail_order."' ";
+ $sql .= ") ";
+
+ //add time condition met check
+ $dialplan_detail_order += 10;
+ $sql .= ", ( ";
+ $sql .= "'".$domain_uuid."', ";
+ $sql .= "'".$dialplan_uuid."', ";
+ $sql .= "'".uuid()."', ";
+ $sql .= "'condition', ";
+ $sql .= "'".'${time_condition}'."', ";
+ $sql .= "'^true$', ";
+ $sql .= "null, ";
+ $sql .= "null, ";
+ $sql .= "'".$dialplan_detail_group."', ";
+ $sql .= "'".$dialplan_detail_order."' ";
+ $sql .= ") ";
+
+ //add main action
+ $dialplan_detail_order += 10;
+ $sql .= ", ( ";
+ $sql .= "'".$domain_uuid."', ";
+ $sql .= "'".$dialplan_uuid."', ";
+ $sql .= "'".uuid()."', ";
+ $sql .= "'action', ";
+ $sql .= "'".$dialplan_action_app."', ";
+ $sql .= "'".$dialplan_action_data."', ";
+ $sql .= "null, ";
+ $sql .= "null, ";
+ $sql .= "'".$dialplan_detail_group."', ";
+ $sql .= "'".$dialplan_detail_order."' ";
+ $sql .= ") ";
+
+ //add anti-action (if defined)
+ if (strlen($dialplan_anti_action_app) > 0) {
+ $dialplan_detail_order += 10;
+ $sql .= ", ( ";
+ $sql .= "'".$domain_uuid."', ";
+ $sql .= "'".$dialplan_uuid."', ";
+ $sql .= "'".uuid()."', ";
+ $sql .= "'anti-action', ";
+ $sql .= "'".$dialplan_anti_action_app."', ";
+ $sql .= "'".$dialplan_anti_action_data."', ";
+ $sql .= "null, ";
+ $sql .= "null, ";
+ $sql .= "'".$dialplan_detail_group."', ";
+ $sql .= "'".$dialplan_detail_order."' ";
+ $sql .= ") ";
+ }
+
+ //execute query
+ $db->exec(check_sql($sql));
+ unset($sql);
+
+
+
+ //commit the atomic transaction
+ $count = $db->exec("COMMIT;"); //returns affected rows
+
+ //clear the cache
+ $cache = new cache;
+ $cache->delete("dialplan:".$_SESSION["context"]);
+
+ //synchronize the xml config
+ save_dialplan_xml();
+
+ //set the message
+ if ($action == "add") {
+ $_SESSION['message'] = $text['message-add'];
+ }
+ else if ($action == "update") {
+ $_SESSION['message'] = $text['message-update'];
+ }
+ header("Location: time_condition_edit.php?id=".$dialplan_uuid.(($app_uuid != '') ? "&app_uuid=".$app_uuid : null));
+ return;
+
+ } //end if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
+
+
+//get existing data to pre-populate form
+ if ($dialplan_uuid != '' && $_POST["persistformvar"] != "true") {
+
+
+ //get main dialplan entry
+ $orm = new orm;
+ $orm->name('dialplans');
+ $orm->uuid($dialplan_uuid);
+ $result = $orm->find()->get();
+ //$message = $orm->message;
+ foreach ($result as &$row) {
+ $domain_uuid = $row["domain_uuid"];
+ //$app_uuid = $row["app_uuid"];
+ $dialplan_name = $row["dialplan_name"];
+ $dialplan_number = $row["dialplan_number"];
+ $dialplan_order = $row["dialplan_order"];
+ $dialplan_continue = $row["dialplan_continue"];
+ $dialplan_context = $row["dialplan_context"];
+ $dialplan_enabled = $row["dialplan_enabled"];
+ $dialplan_description = $row["dialplan_description"];
+ }
+ unset ($prep_statement);
+
+
+ //get dialplan detail conditions
+ $sql = "select dialplan_detail_group, dialplan_detail_tag, dialplan_detail_type, dialplan_detail_data from v_dialplan_details ";
+ $sql .= "where dialplan_uuid = '".$dialplan_uuid."' ";
+ $sql .= "and ";
+ $sql .= "( ";
+ $sql .= " ( ";
+ $sql .= " dialplan_detail_tag = 'condition' ";
+ $sql .= " and dialplan_detail_type in ('year','mon','mday','wday','yday','week','mweek','hour','minute','minute-of-day','time-of-day','date-time') ";
+ $sql .= " ) ";
+ $sql .= " or ( ";
+ $sql .= " dialplan_detail_tag = 'action' ";
+ $sql .= " and dialplan_detail_group = '999' ";
+ $sql .= " ) ";
+ $sql .= " or ( ";
+ $sql .= " dialplan_detail_tag = 'anti-action' ";
+ $sql .= " and dialplan_detail_group = '999' ";
+ $sql .= " ) ";
+ $sql .= ") ";
+ $sql .= "order by dialplan_detail_group asc, dialplan_detail_order asc";
+ $prep_statement = $db->prepare(check_sql($sql));
+ $prep_statement->execute();
+ $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+ $result_count = count($result);
+ unset ($prep_statement, $sql);
+
+ $debug_output .= "Select Query... ";
+ $debug_output .= '$result ='."\n\n";
+ $debug_output .= print_r($result, true);
+ $debug_output .= " ";
+
+
+ //load current conditions into array (combined by group), and retrieve action and anti-action
+ $c = 0;
+ foreach ($result as $row) {
+ switch ($row['dialplan_detail_tag']) {
+ case 'condition': $current_conditions[$row['dialplan_detail_group']][$row['dialplan_detail_type']] = $row['dialplan_detail_data']; break;
+ case 'action': $dialplan_action = $row['dialplan_detail_type'].':'.$row['dialplan_detail_data']; break;
+ case 'anti-action': $dialplan_anti_action = $row['dialplan_detail_type'].':'.$row['dialplan_detail_data']; break;
+ }
+ }
+
+ $debug_output .= "Rebuild array... ";
+ $debug_output .= '$current_conditions ='."\n\n";
+ $debug_output .= print_r($current_conditions, true);
+ $debug_output .= " ";
+
+ $debug_output .= "Load available presets... ";
+ $debug_output .= '$available_presets ='."\n\n";
+ $debug_output .= print_r($available_presets, true);
+ $debug_output .= " ";
+
+
+ //loop through available presets
+ $debug_output .= 'Loop through $avaialble_presets array, compare variable count and values with $current_conditions array... ';
+
+ foreach ($available_presets as $preset_number => $preset) {
+ foreach ($preset as $preset_name => $preset_variables) {
+ //loop through each condition group
+ foreach ($current_conditions as $group_number => $condition_variables) {
+ //compare variable count
+ if (sizeof($preset_variables) == sizeof($condition_variables)) {
+ $matches = 0;
+ foreach ($condition_variables as $condition_variable_name => $condition_variable_value) {
+ //count matching variable values
+ if ($preset_variables[$condition_variable_name] == $condition_variable_value) { $matches++; }
+ }
+ //if all variables match, then condition is a preset
+ if ($matches == sizeof($preset_variables)) {
+ $current_presets[] = $preset_number;
+ //drop group from array of current conditions
+ unset($current_conditions[$group_number]);
+
+ $debug_output .= "Found! Group ".$group_number." is ".$preset_name."... noted, group unset. ";
+ }
+ }
+ }
+ }
+ }
+
+
+ //load remaining conditions as custom conditions
+ $debug_output .= " Current conditions... ";
+ $debug_output .= '$current_conditions ='."\n\n";
+ $debug_output .= print_r($current_conditions, true);
+ $debug_output .= " ";
+
+ $c = 0;
+ foreach ($current_conditions as $conditions) {
+ foreach ($conditions as $condition_variable => $condition_value) {
+ $custom_conditions[$c]['var'] = $condition_variable;
+ $custom_conditions[$c]['val'] = $condition_value;
+ $c++;
+ }
+ }
+ unset($current_conditions);
+
+ $debug_output .= 'Restructure array into remaining conditions... ';
+ $debug_output .= '$custom_conditions ='."\n\n";
+ $debug_output .= print_r($custom_conditions, true);
+ $debug_output .= " ";
+
+ if (isset($_REQUEST['debug'])) { echo $debug_output; }
+ }
+
+?>
+
+
+
+\n";
+
+echo "";
+echo " \n";
+
+echo "\n";
+
+echo "\n";
+echo "\n";
+echo " ".$text['label-name']."\n";
+echo " \n";
+echo "\n";
+echo " \n";
+echo " \n";
+echo " ".$text['description-name']."\n";
+echo " \n";
+echo "\n";
+echo " \n";
+echo " \n";
+
+echo "\n";
+echo "\n";
+echo " ".$text['label-extension']."\n";
+echo " \n";
+echo "\n";
+echo " \n";
+echo " \n";
+echo " ".$text['description-extension']." \n";
+echo " \n";
+echo " \n";
+
+echo "\n";
+echo "\n";
+echo " ".$text['label-conditions']."\n";
+echo " \n";
+echo "\n";
+//define select box options for each time condition variable (where appropriate)
+for ($y = date('Y'); $y <= (date('Y') + 10); $y++) { $var_option_select['year'][$y] = $y; } //years
+for ($m = 1; $m <= 12; $m++) { $var_option_select['mon'][$m] = date('F', strtotime('2015-'.number_pad($m,2).'-01')); } //month names
+for ($d = 1; $d <= 366; $d++) { $var_option_select['yday'][$d] = $d; } //days of year
+for ($d = 1; $d <= 31; $d++) { $var_option_select['mday'][$d] = $d; } //days of month
+for ($d = 1; $d <= 7; $d++) { $var_option_select['wday'][$d] = date('l', strtotime('Sunday +'.($d-1).' days')); } //week days
+for ($w = 1; $w <= 53; $w++) { $var_option_select['week'][$w] = $w; } //weeks of year
+for ($w = 1; $w <= 5; $w++) { $var_option_select['mweek'][$w] = $w; } //weeks of month
+for ($h = 0; $h <= 23; $h++) { $var_option_select['hour'][$h] = (($h) ? (($h >= 12) ? (($h == 12) ? $h : ($h-12)).' PM' : $h.' AM') : '12 AM'); } //hours of day
+for ($m = 0; $m <= 59; $m++) { $var_option_select['minute'][$m] = number_pad($m,2); } //minutes of hour
+//output condition fields
+echo " \n";
+if ($action == 'add') {
+ echo "\n";
+}
+echo " ";
+echo " ".$text['description-conditions']." \n";
+echo " \n";
+echo " \n";
+
+echo "\n";
+echo "\n";
+echo " ".$text['label-presets']."\n";
+echo " \n";
+echo "\n";
+echo " \n";
+echo " \n";
+echo " ".$text['description-presets']." \n";
+echo " \n";
+echo " \n";
+
+echo "\n";
+echo "\n";
+echo " ".$text['label-action']."\n";
+echo " \n";
+echo "\n";
+switch_select_destination("dialplan", $dialplan_action, "dialplan_action", $dialplan_action, '', '');
+echo " \n";
+echo " \n";
+
+echo "\n";
+echo "\n";
+echo " ".$text['label-action-alternate']."\n";
+echo " \n";
+echo "\n";
+switch_select_destination("dialplan", $dialplan_anti_action, "dialplan_anti_action", $dialplan_anti_action, '', '');
+echo "
\n";
+echo " \n";
+echo " \n";
+
+echo "\n";
+echo "\n";
+echo " ".$text['label-order']."\n";
+echo " \n";
+echo "\n";
+echo " \n";
+for ($i = 300; $i <= 999; $i += 10) {
+ $padded_i = str_pad($i, 3, '0', STR_PAD_LEFT);
+ $selected = ($dialplan_order == $i) ? "selected='selected'" : null;
+ echo "".$padded_i." \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 " ".$text['label-true']." \n";
+echo " ".$text['label-false']." \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 " ";
+
+echo "\n";
+if ($action == "update") {
+ echo " \n";
+}
+echo " \n";
+echo "
";
+
+echo "";
+echo " ";
+
+//include the footer
+ require_once "resources/footer.php";
+
?>
\ No newline at end of file