diff --git a/app/time_conditions/time_condition_edit.php b/app/time_conditions/time_condition_edit.php index 690694aa7d..cf6b1e3013 100644 --- a/app/time_conditions/time_condition_edit.php +++ b/app/time_conditions/time_condition_edit.php @@ -47,7 +47,7 @@ require_once "resources/paging.php"; //get the post form variables and se them to php variables $action = 'add'; - if (count($_POST)>0) { + 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"]); @@ -66,390 +66,489 @@ require_once "resources/paging.php"; $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($action_1) == 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; - } +//process submitted data + 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($action_1) == 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; + } - //start the atomic transaction - $count = $db->exec("BEGIN;"); //returns affected rows + //add the time condition + if (strlen($_GET['id']) == 0) { + //start the atomic transaction + $count = $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_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 .= ")"; + //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_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); + //execute query + $db->exec(check_sql($sql)); + unset($sql); + //initialize dialplan detail group and order numbers + $dialplan_detail_group = 0; + $dialplan_detail_order = 0; - //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) { - //check if custom conditions defined - $custom_conditions_defined = false; - foreach ($_REQUEST['variable'] as $cond_var) { - if ($cond_var != '') { $custom_conditions_defined = true; } - } + //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 "; - if ($custom_conditions_defined) { + //add destination number condition + $dialplan_detail_group++; + $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 .= ")"; - //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 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']; - //add destination number condition - $dialplan_detail_group++; - $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 .= ")"; + //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; - //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']; + //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); + } - //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']; + $cond_value = $cond_start.(($cond_stop != '') ? '-'.$cond_stop : null); } - else if ($cond_stop['notation'] == 'AM') { - $cond_stop_hour = ($cond_stop['hour'] == 12) ? $cond_stop['hour'] -= 12 : $cond_stop['hour']; + //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; + } + } } - $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 to query string + //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 "; + + //get preset condition variables + foreach ($_SESSION['time_conditions']['preset'] as $json) { + $presets[] = json_decode($json, true); + } + + foreach ($_REQUEST['preset'] as $index => $preset_number) { + + //increment group and order number + $dialplan_detail_group++; + $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 ($presets[$preset_number] as $preset_name => $preset) { + 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 = 100; + $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 .= "'".$cond_var."', "; - $sql .= "'".$cond_value."', "; - $sql .= "'never', "; + $sql .= "'".'${time_condition}'."', "; + $sql .= "'^true$', "; + $sql .= "null, "; $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 .= ") "; + //add main action + $dialplan_detail_order += 10; + $sql .= ", ( "; + $sql .= "'".$domain_uuid."', "; + $sql .= "'".$dialplan_uuid."', "; + $sql .= "'".uuid()."', "; + $sql .= "'action', "; + $sql .= "'".$action_application_1."', "; + $sql .= "'".$action_data_1."', "; + $sql .= "null, "; + $sql .= "null, "; + $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 "; - - //get preset condition variables - foreach ($_SESSION['time_conditions']['preset'] as $json) { - $presets[] = json_decode($json, true); - } - - foreach ($_REQUEST['preset'] as $index => $preset_number) { - - //increment group and order number - $dialplan_detail_group++; - $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 ($presets[$preset_number] as $preset_name => $preset) { - foreach ($preset['variables'] as $cond_var => $cond_value) { - //add preset condition to query string + //add anti-action (if defined) + if (strlen($anti_action_application_1) > 0) { $dialplan_detail_order += 10; $sql .= ", ( "; $sql .= "'".$domain_uuid."', "; $sql .= "'".$dialplan_uuid."', "; $sql .= "'".uuid()."', "; - $sql .= "'condition', "; - $sql .= "'".$cond_var."', "; - $sql .= "'".$cond_value."', "; - $sql .= "'never', "; + $sql .= "'anti-action', "; + $sql .= "'".$anti_action_application_1."', "; + $sql .= "'".$anti_action_data_1."', "; + $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 + + //synchronize the xml config + save_dialplan_xml(); + + //clear the cache + $cache = new cache; + $cache->delete("dialplan:".$_SESSION["context"]); + + //redirect the browser + $_SESSION["message"] = $text['message-add']; + header("Location: ".PROJECT_PATH."/app/dialplan/dialplans.php?app_uuid=4b821450-926b-175a-af93-a03c441818b1"); + return; + } //end - add the time condition + } //end if (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"]; } - - //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 .= ") "; - + unset ($prep_statement); } - //execute query - $db->exec(check_sql($sql)); - unset($sql); + //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); - } - - - //increment group number, reset order number - $dialplan_detail_group = 100; - $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 .= "'".$action_application_1."', "; - $sql .= "'".$action_data_1."', "; - $sql .= "null, "; - $sql .= "null, "; - $sql .= "'".$dialplan_detail_group."', "; - $sql .= "'".$dialplan_detail_order."' "; - $sql .= ") "; - - //add anti-action (if defined) - if (strlen($anti_action_application_1) > 0) { - $dialplan_detail_order += 10; - $sql .= ", ( "; - $sql .= "'".$domain_uuid."', "; - $sql .= "'".$dialplan_uuid."', "; - $sql .= "'".uuid()."', "; - $sql .= "'anti-action', "; - $sql .= "'".$anti_action_application_1."', "; - $sql .= "'".$anti_action_data_1."', "; - $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 - - //synchronize the xml config - save_dialplan_xml(); - - //clear the cache - $cache = new cache; - $cache->delete("dialplan:".$_SESSION["context"]); - - //redirect the browser - $_SESSION["message"] = $text['message-add']; - header("Location: ".PROJECT_PATH."/app/dialplan/dialplans.php?app_uuid=4b821450-926b-175a-af93-a03c441818b1"); - return; - -} //end if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) + //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); + //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; + } + } ?> @@ -491,323 +590,325 @@ require_once "resources/paging.php"; \n"; -echo "\n"; -echo " \n"; -echo " \n"; -echo " \n"; -echo " \n"; -echo " \n"; -echo " \n"; -echo " \n"; -echo "
\n"; -echo " ".$text['title-time-condition-add']."
\n"; -echo "
\n"; -echo " \n"; -echo " \n"; -echo "
\n"; -echo " \n"; -echo " ".$text['description-time-condition-add']."\n"; -echo " \n"; -echo "
"; +//show the content + 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-name']."\n"; -echo "\n"; -echo " \n"; -echo "
\n"; -echo " ".$text['description-name']."\n"; -echo "
\n"; -echo "\n"; -echo "
\n"; -echo " ".$text['label-extension']."\n"; -echo "\n"; -echo " \n"; -echo "
\n"; -echo " ".$text['description-extension']."
\n"; -echo "
\n"; -echo " ".$text['label-conditions']."\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"; -echo " \n"; -echo " \n"; -echo " \n"; -echo " \n"; -echo " \n"; -echo " \n"; -for ($c = 1; $c <= 3; $c++) { + echo "
".$text['label-condition_parameter']."".$text['label-condition_scope']."".$text['label-condition_values']."
\n"; echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; echo " \n"; -} -echo "
\n"; - echo " \n"; + echo " \n"; + echo " ".$text['title-time-condition-add']."
\n"; echo "
\n"; - echo " \n"; - echo " \n"; - - foreach ($time_condition_vars as $var_name => $var_label) { - switch ($var_name) { - case "minute-of-day" : - echo "\n"; - break; - case "time-of-day" : - echo "\n"; - break; - case "date-time" : - echo "\n"; - break; - default: - echo "\n"; - } - } - + echo " \n"; + echo " \n"; + echo " \n"; echo "
\n"; -if ($action == 'add') { - echo "\n"; -} -echo " ".$text['description-conditions']."
\n"; -echo "
\n"; + echo " \n"; + echo " ".$text['description-time-condition-add']."\n"; + echo " \n"; + echo "
"; -echo "\n"; -echo "\n"; -echo " ".$text['label-presets']."\n"; -echo "\n"; -echo "\n"; -foreach ($_SESSION['time_conditions']['preset'] as $json) { - $presets[] = json_decode($json, true); -} -//echo "
"; print_r($presets); echo "


"; -echo " \n"; -echo " \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 "\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"; -$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) { - echo "
\n"; - $p++; - if ($p == $presets_per_column) { - echo "
\n"; - $p = 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 " ".$text['label-name']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo " ".$text['description-name']."\n"; + echo "
\n"; + echo "\n"; + echo "
\n"; + echo " ".$text['label-extension']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo " ".$text['description-extension']."
\n"; + echo "
\n"; + echo " ".$text['label-conditions']."\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"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + for ($c = 1; $c <= 3; $c++) { + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + } + echo "
".$text['label-condition_parameter']."".$text['label-condition_scope']."".$text['label-condition_values']."
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + + foreach ($time_condition_vars as $var_name => $var_label) { + switch ($var_name) { + case "minute-of-day" : + echo "\n"; + break; + case "time-of-day" : + echo "\n"; + break; + case "date-time" : + echo "\n"; + break; + default: + echo "\n"; + } + } + + echo "
\n"; + if ($action == 'add') { + echo "\n"; + } + echo " ".$text['description-conditions']."
\n"; + echo "
\n"; + echo " ".$text['label-presets']."\n"; + echo "\n"; + foreach ($_SESSION['time_conditions']['preset'] as $json) { + $presets[] = json_decode($json, true); + } + //echo "
"; print_r($presets); echo "


"; + echo " \n"; + echo " \n"; + 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) { + echo "
\n"; + $p++; + if ($p == $presets_per_column) { + echo "
\n"; + $p = 0; + } } } -} -echo "
\n"; -echo "
\n"; -echo " ".$text['description-presets']."
\n"; -echo "
\n"; + echo "
\n"; + echo " ".$text['description-presets']."
\n"; + echo "
\n"; -echo " ".$text['label-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", $action_1, "", ""); -echo "
\n"; + echo " ".$text['label-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", $action_1, "", ""); + echo "
\n"; -echo " ".$text['label-action-alternate']."\n"; -echo "\n"; -//switch_select_destination(select_type, select_label, select_name, select_value, select_style, $action); -switch_select_destination("dialplan", $anti_action_1, "anti_action_1", $anti_action_1, "", ""); -echo "
\n"; -echo "
\n"; + echo " ".$text['label-action-alternate']."\n"; + echo "\n"; + //switch_select_destination(select_type, select_label, select_name, select_value, select_style, $action); + switch_select_destination("dialplan", $anti_action_1, "anti_action_1", $anti_action_1, "", ""); + echo "
\n"; + echo "
\n"; -echo " ".$text['label-order']."\n"; -echo "\n"; -echo " \n"; -echo "
\n"; -echo "
\n"; + echo " ".$text['label-order']."\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 " ".$text['label-enabled']."\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 " ".$text['label-description']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo "\n"; + echo "
\n"; -echo "

"; + echo "\n"; + echo "

"; -echo "
\n"; -if ($action == "update") { - echo " \n"; -} -echo " \n"; -echo "
"; + echo "
\n"; + if ($action == "update") { + echo " \n"; + } + echo " \n"; + echo "
"; -echo ""; -echo "

"; + echo ""; + echo "

"; //include the footer require_once "resources/footer.php";