Update time_condition_edit.php
This commit is contained in:
parent
69a3561d3b
commit
a6612c1e25
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2016
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2017
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
|
|
@ -47,9 +47,11 @@
|
|||
|
||||
//load available presets
|
||||
$preset_region = "preset_".$_SESSION['time_conditions']['region']['text'];
|
||||
if (is_array($_SESSION['time_conditions'][$preset_region])) {
|
||||
foreach ($_SESSION['time_conditions'][$preset_region] as $json) {
|
||||
$available_presets[] = json_decode($json, true);
|
||||
}
|
||||
}
|
||||
unset($preset_region);
|
||||
|
||||
//set the action as an add or an update
|
||||
|
|
@ -81,9 +83,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
//process the http post values
|
||||
if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
|
||||
|
||||
//check for all required data
|
||||
//if (strlen($domain_uuid) == 0) { $msg .= $text['label-required-domain_uuid']."<br>\n"; }
|
||||
if (strlen($dialplan_name) == 0) { $msg .= $text['label-required-dialplan_name']."<br>\n"; }
|
||||
|
|
@ -193,6 +193,7 @@
|
|||
|
||||
//clean up array
|
||||
//remove presets not checked, restructure variable array
|
||||
if (is_array($_REQUEST['variable']['preset'])) {
|
||||
foreach ($_REQUEST['variable']['preset'] as $group_id => $conditions) {
|
||||
if (!in_array($group_id, $_REQUEST['preset'])) {
|
||||
unset($_REQUEST['variable']['preset'][$group_id]);
|
||||
|
|
@ -202,13 +203,18 @@
|
|||
}
|
||||
$_REQUEST['variable'][$group_id] = $conditions;
|
||||
}
|
||||
}
|
||||
if (is_array($_REQUEST['variable']['custom'])) {
|
||||
foreach ($_REQUEST['variable']['custom'] as $group_id => $conditions) {
|
||||
$_REQUEST['variable'][$group_id] = $conditions;
|
||||
}
|
||||
}
|
||||
unset($_REQUEST['variable']['custom'], $_REQUEST['variable']['preset']);
|
||||
|
||||
//remove invalid conditions and values by checking conditions
|
||||
if (is_array($_REQUEST['variable'])) {
|
||||
foreach ($_REQUEST['variable'] as $group_id => $conditions) {
|
||||
if (is_array($conditions)) {
|
||||
foreach ($conditions as $condition_id => $condition_variable) {
|
||||
if ($condition_variable == '') {
|
||||
unset($_REQUEST['variable'][$group_id][$condition_id]);
|
||||
|
|
@ -216,8 +222,11 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//remove invalid conditions and values by checking start value
|
||||
if (is_array($_REQUEST['value'])) {
|
||||
foreach ($_REQUEST['value'] as $group_id => $values) {
|
||||
foreach ($values as $value_id => $value_range) {
|
||||
if ($value_range['start'] == '') {
|
||||
|
|
@ -226,8 +235,10 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//remove any empty groups (where conditions no longer exist)
|
||||
if (is_array($_REQUEST['variable'])) {
|
||||
foreach ($_REQUEST['variable'] as $group_id => $conditions) {
|
||||
if (sizeof($conditions) == 0) {
|
||||
unset($_REQUEST['variable'][$group_id]);
|
||||
|
|
@ -235,8 +246,10 @@
|
|||
unset($_REQUEST['dialplan_action'][$group_id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//remove groups where an action (or default_preset_action - if a preset group - or dialplan_anti_action) isn't defined
|
||||
if (is_array($_REQUEST['variable'])) {
|
||||
foreach ($_REQUEST['variable'] as $group_id => $meh) {
|
||||
if (
|
||||
(in_array($group_id, $_REQUEST['preset']) && $_REQUEST['dialplan_action'][$group_id] == '' && $_REQUEST['default_preset_action'] == '' && $_REQUEST['dialplan_anti_action'] == '') ||
|
||||
|
|
@ -245,11 +258,14 @@
|
|||
unset($_REQUEST['variable'][$group_id]);
|
||||
unset($_REQUEST['value'][$group_id]);
|
||||
unset($_REQUEST['dialplan_action'][$group_id]);
|
||||
if (is_array($_REQUEST['preset'])) {
|
||||
foreach ($_REQUEST['preset'] as $preset_id => $preset_group_id) {
|
||||
if ($group_id == $preset_group_id) { unset($_REQUEST['preset'][$preset_id]); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//process conditions
|
||||
$conditions_exist = false;
|
||||
|
|
@ -271,7 +287,7 @@
|
|||
$sql .= "values ";
|
||||
|
||||
//add conditions
|
||||
foreach ($_REQUEST['variable'] as $group_id => $conditions) {
|
||||
if (is_array($_REQUEST['variable'])) foreach ($_REQUEST['variable'] as $group_id => $conditions) {
|
||||
|
||||
$group_conditions_exist[$group_id] = false;
|
||||
|
||||
|
|
@ -289,7 +305,7 @@
|
|||
|
||||
$dialplan_detail_order = 0;
|
||||
|
||||
foreach ($conditions as $cond_num => $cond_var) {
|
||||
if (is_array($conditions)) foreach ($conditions as $cond_num => $cond_var) {
|
||||
if ($cond_var != '') {
|
||||
$cond_start = $_REQUEST['value'][$group_id][$cond_num]['start'];
|
||||
$cond_stop = $_REQUEST['value'][$group_id][$cond_num]['stop'];
|
||||
|
|
@ -358,6 +374,7 @@
|
|||
} //if
|
||||
} //for each
|
||||
|
||||
|
||||
//continue adding to query only if conditions exist in current group
|
||||
if ($group_conditions_exist[$group_id]) {
|
||||
|
||||
|
|
@ -376,9 +393,10 @@
|
|||
|
||||
if ($dialplan_action != '') {
|
||||
//if preset, set log variable
|
||||
if ($is_preset) {
|
||||
if ($is_preset && is_array($_REQUEST['preset'])) {
|
||||
foreach ($_REQUEST['preset'] as $preset_number => $preset_group_id) {
|
||||
if ($group_id == $preset_group_id) {
|
||||
if (is_array($available_presets[$preset_number])) {
|
||||
foreach ($available_presets[$preset_number] as $available_preset_name => $meh) {
|
||||
$dialplan_detail_order += 10;
|
||||
$sql .= ", ( ";
|
||||
|
|
@ -402,6 +420,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//parse group app and data
|
||||
if (substr_count($dialplan_action, ":") > 0) {
|
||||
|
|
@ -434,11 +453,10 @@
|
|||
$sql .= "'".$dialplan_detail_order."' ";
|
||||
$sql .= ") ";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} //for each
|
||||
|
||||
|
||||
//add to query for default anti-action (if defined)
|
||||
if (strlen($dialplan_anti_action_app) > 0) {
|
||||
|
||||
|
|
@ -496,13 +514,6 @@
|
|||
//commit the atomic transaction
|
||||
$count = $db->exec("COMMIT;"); //returns affected rows
|
||||
|
||||
//update the dialplan xml
|
||||
$dialplans = new dialplan;
|
||||
$dialplans->source = "details";
|
||||
$dialplans->destination = "database";
|
||||
$dialplans->uuid = $dialplan_uuid;
|
||||
$dialplans->xml();
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$_SESSION["context"]);
|
||||
|
|
@ -522,7 +533,6 @@
|
|||
|
||||
} //end if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
|
||||
|
||||
|
||||
//get existing data to pre-populate form
|
||||
if ($dialplan_uuid != '' && $_POST["persistformvar"] != "true") {
|
||||
|
||||
|
|
@ -534,11 +544,12 @@
|
|||
$p->add("dialplan_detail_edit", 'temp');
|
||||
|
||||
//get main dialplan entry
|
||||
$sql = "select * from v_dialplans ";
|
||||
$sql .= "where dialplan_uuid = '$dialplan_uuid' ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
$orm = new orm;
|
||||
$orm->name('dialplans');
|
||||
$orm->uuid($dialplan_uuid);
|
||||
$result = $orm->find()->get();
|
||||
//$message = $orm->message;
|
||||
if (is_array($result)) {
|
||||
foreach ($result as &$row) {
|
||||
$domain_uuid = $row["domain_uuid"];
|
||||
//$app_uuid = $row["app_uuid"];
|
||||
|
|
@ -550,6 +561,7 @@
|
|||
$dialplan_enabled = $row["dialplan_enabled"];
|
||||
$dialplan_description = $row["dialplan_description"];
|
||||
}
|
||||
}
|
||||
unset ($prep_statement);
|
||||
|
||||
//remove the temporary permission
|
||||
|
|
@ -581,6 +593,7 @@
|
|||
|
||||
//load current conditions into array (combined by group), and retrieve action and anti-action
|
||||
$c = 0;
|
||||
if (is_array($result)) {
|
||||
foreach ($result as $row) {
|
||||
if ($row['dialplan_detail_tag'] == 'action') {
|
||||
if ($row['dialplan_detail_group'] == '999') {
|
||||
|
|
@ -594,18 +607,22 @@
|
|||
$current_conditions[$row['dialplan_detail_group']][$row['dialplan_detail_type']] = $row['dialplan_detail_data'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//loop through available presets (if any)
|
||||
if (isset($available_presets) && sizeof($available_presets) > 0) {
|
||||
if (is_array($available_presets)) {
|
||||
foreach ($available_presets as $preset_number => $preset) {
|
||||
foreach ($preset as $preset_name => $preset_variables) {
|
||||
if (is_array($preset)) foreach ($preset as $preset_name => $preset_variables) {
|
||||
//loop through each condition group
|
||||
if (is_array($current_conditions)) {
|
||||
foreach ($current_conditions as $group_id => $condition_variables) {
|
||||
$matches = 0;
|
||||
if (is_array($condition_variables)) {
|
||||
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 preset variables found, then condition is a preset
|
||||
if ($matches == sizeof($preset_variables)) {
|
||||
$current_presets[$preset_number] = $group_id;
|
||||
|
|
@ -614,6 +631,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -644,9 +662,11 @@
|
|||
//$time_condition_vars["minute-of-day"] = $text['label-minute-of-day'];
|
||||
$time_condition_vars["time-of-day"] = $text['label-time-of-day'];
|
||||
$time_condition_vars["date-time"] = $text['label-date-and-time'];
|
||||
if (is_array($time_condition_vars)) {
|
||||
foreach ($time_condition_vars as $var_name => $var_label) {
|
||||
echo "html += \" <option value='".$var_name."' ".(($custom_conditions[$c]['var'] == $var_name) ? "selected='selected'" : null).">".$var_label."</option>\";";
|
||||
}
|
||||
}
|
||||
?>
|
||||
html += " </select>";
|
||||
html += " <select class='formfld' style='width: 120px;' name='value[" + group_id + "][" + condition_id + "][start]' id='value_" + group_id + "_" + condition_id + "_start'></select>";
|
||||
|
|
@ -824,7 +844,7 @@
|
|||
|
||||
function alternate_destination_required() {
|
||||
require_default_or_alt_destination = false;
|
||||
<?php foreach ($available_presets as $preset_number => $meh) { ?>
|
||||
<?php if (is_array($available_presets)) foreach ($available_presets as $preset_number => $meh) { ?>
|
||||
if (document.getElementById('preset_<?php echo $preset_number; ?>').checked) {
|
||||
preset_group_id = document.getElementById('preset_<?php echo $preset_number; ?>').value;
|
||||
preset_destination = $('#dialplan_action_' + preset_group_id).val();
|
||||
|
|
@ -954,9 +974,11 @@ function add_custom_condition($destination, $group_id, $dialplan_action = '') {
|
|||
|
||||
if ($action == 'update') {
|
||||
$largest_group_id = 0;
|
||||
if (is_array($current_conditions)) {
|
||||
foreach ($current_conditions as $group_id => $conditions) {
|
||||
if (!is_array($current_presets) || (is_array($current_presets) && !in_array($group_id, $current_presets))) {
|
||||
add_custom_condition($destination, $group_id, $dialplan_actions[$group_id]);
|
||||
if (is_array($conditions)) {
|
||||
foreach ($conditions as $cond_var => $cond_val) {
|
||||
$range_indicator = ($cond_var == 'date-time') ? '~' : '-';
|
||||
$tmp = explode($range_indicator, $cond_val);
|
||||
|
|
@ -989,11 +1011,13 @@ if ($action == 'update') {
|
|||
}
|
||||
echo "</script>";
|
||||
}
|
||||
}
|
||||
//used to determine largest custom group id in use
|
||||
$largest_group_id = ($group_id > $largest_group_id) ? $group_id : $largest_group_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//add first/new set of custom condition fields
|
||||
if ($action != 'update' || ($action == 'update' && $largest_group_id == 0)) {
|
||||
|
|
@ -1018,7 +1042,9 @@ if ($action == 'update') {
|
|||
echo "</td>\n";
|
||||
echo "<td class='vtable' align='left'>\n";
|
||||
|
||||
if (is_array($available_presets)) {
|
||||
foreach ($available_presets as $preset_number => $preset) {
|
||||
if (is_array($preset)) {
|
||||
foreach ($preset as $preset_name => $preset_variables) {
|
||||
$checked = (is_array($current_presets) && $current_presets[$preset_number] != '') ? "checked='checked'" : null;
|
||||
$preset_group_id = ($checked) ? $current_presets[$preset_number] : $preset_group_id = $preset_number * 5 + 100;
|
||||
|
|
@ -1050,6 +1076,7 @@ if ($action == 'update') {
|
|||
echo "</div>";
|
||||
if ($action == 'update' && is_array($current_presets) && $current_presets[$preset_number] != '') {
|
||||
//add (potentially customized) preset conditions and populate
|
||||
if (is_array($current_conditions[$preset_group_id])) {
|
||||
foreach ($current_conditions[$preset_group_id] as $cond_var => $cond_val) {
|
||||
$range_indicator = ($cond_var == 'date-time') ? '~' : '-';
|
||||
$tmp = explode($range_indicator, $cond_val);
|
||||
|
|
@ -1084,8 +1111,10 @@ if ($action == 'update') {
|
|||
echo "</script>";
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
//add default preset conditions and populate
|
||||
if (is_array($preset_variables)) {
|
||||
foreach ($preset_variables as $preset_variable => $preset_value) {
|
||||
$range_indicator = ($preset_variable == 'date-time') ? '~' : '-';
|
||||
$tmp = explode($range_indicator, $preset_value);
|
||||
|
|
@ -1103,6 +1132,9 @@ if ($action == 'update') {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo " <br />\n";
|
||||
echo " <table border='0' cellpadding='2' cellspacing='0' style='margin: -2px;'>\n";
|
||||
|
|
|
|||
Loading…
Reference in New Issue