diff --git a/app/time_conditions/time_condition_edit.php b/app/time_conditions/time_condition_edit.php index 9d85004540..45b674651f 100644 --- a/app/time_conditions/time_condition_edit.php +++ b/app/time_conditions/time_condition_edit.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - 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,8 +47,10 @@ //load available presets $preset_region = "preset_".$_SESSION['time_conditions']['region']['text']; - foreach ($_SESSION['time_conditions'][$preset_region] as $json) { - $available_presets[] = json_decode($json, true); + 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); @@ -81,118 +83,117 @@ } } -//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']."
\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; + } - //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); - //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 - //start the atomic transaction - $count = $db->exec("BEGIN;"); //returns affected rows + //process main dialplan entry + if ($action == "add") { - //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 .= "("; + if (strlen($domain_uuid) == 0) { + $sql .= "null, "; + } + else { + $sql .= "'".$domain_uuid."', "; + } + $sql .= "'".$dialplan_uuid."', "; + $sql .= "'4b821450-926b-175a-af93-a03c441818b1', "; + $sql .= "'".$dialplan_name."', "; + $sql .= "'".$dialplan_number."', "; + $sql .= "'".$dialplan_order."', "; + $sql .= "'true', "; + if (strlen($domain_uuid) == 0) { + $sql .= "'\${domain_name}', "; + } + else { + $sql .= "'".$_SESSION['context']."', "; + } + $sql .= "'".$dialplan_enabled."', "; + $sql .= "'".$dialplan_description."' "; + $sql .= ")"; - //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 .= "("; - if (strlen($domain_uuid) == 0) { - $sql .= "null, "; - } - else { - $sql .= "'".$domain_uuid."', "; - } - $sql .= "'".$dialplan_uuid."', "; - $sql .= "'4b821450-926b-175a-af93-a03c441818b1', "; - $sql .= "'".$dialplan_name."', "; - $sql .= "'".$dialplan_number."', "; - $sql .= "'".$dialplan_order."', "; - $sql .= "'true', "; - if (strlen($domain_uuid) == 0) { - $sql .= "'\${domain_name}', "; - } - else { - $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 "; + if (strlen($domain_uuid) == 0) { + $sql .= "domain_uuid = null, "; + } + else { + $sql .= "domain_uuid = '".$domain_uuid."', "; + } + $sql .= "dialplan_name = '".$dialplan_name."', "; + $sql .= "dialplan_number = '".$dialplan_number."', "; + $sql .= "dialplan_order = '".$dialplan_order."', "; + $sql .= "dialplan_continue = 'true', "; + if (strlen($domain_uuid) == 0) { + $sql .= "dialplan_context = '\${domain_name}', "; + } + else { + $sql .= "dialplan_context = '".$_SESSION['context']."', "; + } + $sql .= "dialplan_enabled = '".$dialplan_enabled."', "; + $sql .= "dialplan_description = '".$dialplan_description."' "; + $sql .= "where dialplan_uuid = '".$dialplan_uuid."' "; + $db->exec(check_sql($sql)); + unset($sql); - //execute query - $db->exec(check_sql($sql)); - unset($sql); - } - else if ($action == "update") { - //update main dialplan entry - $sql = "update v_dialplans set "; - if (strlen($domain_uuid) == 0) { - $sql .= "domain_uuid = null, "; - } - else { - $sql .= "domain_uuid = '".$domain_uuid."', "; - } - $sql .= "dialplan_name = '".$dialplan_name."', "; - $sql .= "dialplan_number = '".$dialplan_number."', "; - $sql .= "dialplan_order = '".$dialplan_order."', "; - $sql .= "dialplan_continue = 'true', "; - if (strlen($domain_uuid) == 0) { - $sql .= "dialplan_context = '\${domain_name}', "; - } - else { - $sql .= "dialplan_context = '".$_SESSION['context']."', "; - } - $sql .= "dialplan_enabled = '".$dialplan_enabled."', "; - $sql .= "dialplan_description = '".$dialplan_description."' "; - $sql .= "where 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); + } - //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; - //initialize dialplan detail group and order numbers - $dialplan_detail_group = 0; - $dialplan_detail_order = 0; - - //clean up array - //remove presets not checked, restructure variable array + //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,22 +203,30 @@ } $_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']); + } + unset($_REQUEST['variable']['custom'], $_REQUEST['variable']['preset']); - //remove invalid conditions and values by checking conditions + //remove invalid conditions and values by checking conditions + if (is_array($_REQUEST['variable'])) { foreach ($_REQUEST['variable'] as $group_id => $conditions) { - foreach ($conditions as $condition_id => $condition_variable) { - if ($condition_variable == '') { - unset($_REQUEST['variable'][$group_id][$condition_id]); - unset($_REQUEST['value'][$group_id][$condition_id]); + if (is_array($conditions)) { + foreach ($conditions as $condition_id => $condition_variable) { + if ($condition_variable == '') { + unset($_REQUEST['variable'][$group_id][$condition_id]); + unset($_REQUEST['value'][$group_id][$condition_id]); + } } } } + } - //remove invalid conditions and values by checking start value + //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) + //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 + //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,97 +258,79 @@ unset($_REQUEST['variable'][$group_id]); unset($_REQUEST['value'][$group_id]); unset($_REQUEST['dialplan_action'][$group_id]); - foreach ($_REQUEST['preset'] as $preset_id => $preset_group_id) { - if ($group_id == $preset_group_id) { unset($_REQUEST['preset'][$preset_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; + //process conditions + $conditions_exist = false; - //begin insert query for custom and 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 "; + //begin insert query for custom and 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 "; - //add conditions - foreach ($_REQUEST['variable'] as $group_id => $conditions) { + //add conditions + if (is_array($_REQUEST['variable'])) foreach ($_REQUEST['variable'] as $group_id => $conditions) { - $group_conditions_exist[$group_id] = false; + $group_conditions_exist[$group_id] = false; - //determine if preset - $is_preset = (in_array($group_id, $_REQUEST['preset'])) ? true : false; + //determine if preset + $is_preset = (in_array($group_id, $_REQUEST['preset'])) ? true : false; - //set group and order number + //set group and order number - $dialplan_detail_group_user = check_str($_POST["group_$group_id"]); - if($dialplan_detail_group_user!='') { - $dialplan_detail_group = $dialplan_detail_group_user; - } else { - $dialplan_detail_group = $group_id; - } + $dialplan_detail_group_user = check_str($_POST["group_$group_id"]); + if($dialplan_detail_group_user!='') { + $dialplan_detail_group = $dialplan_detail_group_user; + } else { + $dialplan_detail_group = $group_id; + } - $dialplan_detail_order = 0; + $dialplan_detail_order = 0; - 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']; + 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']; - //convert time-of-day to minute-of-day (due to inconsistencies with time-of-day on some systems) - if ($cond_var == 'time-of-day') { - $cond_var = 'minute-of-day'; - $array_cond_start = explode(':', $cond_start); - $cond_start = ($array_cond_start[0] * 60) + $array_cond_start[1]; - if ($cond_stop != '') { - $array_cond_stop = explode(':', $cond_stop); - $cond_stop = ($array_cond_stop[0] * 60) + $array_cond_stop[1]; - } - } - - $cond_value = $cond_start; + //convert time-of-day to minute-of-day (due to inconsistencies with time-of-day on some systems) + if ($cond_var == 'time-of-day') { + $cond_var = 'minute-of-day'; + $array_cond_start = explode(':', $cond_start); + $cond_start = ($array_cond_start[0] * 60) + $array_cond_start[1]; if ($cond_stop != '') { - $range_indicator = ($cond_var == 'date-time') ? '~' : '-'; - $cond_value .= $range_indicator.$cond_stop; + $array_cond_stop = explode(':', $cond_stop); + $cond_stop = ($array_cond_stop[0] * 60) + $array_cond_stop[1]; } + } - if (!$group_conditions_exist[$group_id]) { - //add destination number condition - $dialplan_detail_order += 10; - $sql .= ($conditions_exist) ? ", ( " : "( "; - if (strlen($domain_uuid) == 0) { - $sql .= "null, "; - } - else { - $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 .= ") "; - } + $cond_value = $cond_start; + if ($cond_stop != '') { + $range_indicator = ($cond_var == 'date-time') ? '~' : '-'; + $cond_value .= $range_indicator.$cond_stop; + } - //add condition to query string + if (!$group_conditions_exist[$group_id]) { + //add destination number condition $dialplan_detail_order += 10; - $sql .= ", ( "; + $sql .= ($conditions_exist) ? ", ( " : "( "; if (strlen($domain_uuid) == 0) { $sql .= "null, "; } @@ -345,40 +340,63 @@ $sql .= "'".$dialplan_uuid."', "; $sql .= "'".uuid()."', "; $sql .= "'condition', "; - $sql .= "'".$cond_var."', "; - $sql .= "'".$cond_value."', "; - $sql .= "'never', "; + $sql .= "'destination_number', "; + $sql .= "'^".$dialplan_number."$', "; + $sql .= "null, "; $sql .= "null, "; $sql .= "'".$dialplan_detail_group."', "; $sql .= "'".$dialplan_detail_order."' "; $sql .= ") "; - - $conditions_exist = true; - $group_conditions_exist[$group_id] = true; - } //if - } //for each - - //continue adding to query only if conditions exist in current group - if ($group_conditions_exist[$group_id]) { - - //determine group action app and data - $dialplan_action = check_str($_REQUEST["dialplan_action"][$group_id]); - if ($dialplan_action == '') { - if ($is_preset) { - if (check_str($_REQUEST['default_preset_action']) != '') { - $dialplan_action = check_str($_REQUEST['default_preset_action']); - } - else if (check_str($_REQUEST['dialplan_anti_action']) != '') { - $dialplan_action = check_str($_REQUEST['dialplan_anti_action']); - } - } } - if ($dialplan_action != '') { - //if preset, set log variable - if ($is_preset) { - foreach ($_REQUEST['preset'] as $preset_number => $preset_group_id) { - if ($group_id == $preset_group_id) { + //add condition to query string + $dialplan_detail_order += 10; + $sql .= ", ( "; + if (strlen($domain_uuid) == 0) { + $sql .= "null, "; + } + else { + $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 .= ") "; + + $conditions_exist = true; + $group_conditions_exist[$group_id] = true; + } //if + } //for each + + + //continue adding to query only if conditions exist in current group + if ($group_conditions_exist[$group_id]) { + + //determine group action app and data + $dialplan_action = check_str($_REQUEST["dialplan_action"][$group_id]); + if ($dialplan_action == '') { + if ($is_preset) { + if (check_str($_REQUEST['default_preset_action']) != '') { + $dialplan_action = check_str($_REQUEST['default_preset_action']); + } + else if (check_str($_REQUEST['dialplan_anti_action']) != '') { + $dialplan_action = check_str($_REQUEST['dialplan_anti_action']); + } + } + } + + if ($dialplan_action != '') { + //if preset, set log variable + 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,127 +420,119 @@ } } } - - //parse group app and data - if (substr_count($dialplan_action, ":") > 0) { - $dialplan_action_array = explode(":", $dialplan_action); - $dialplan_action_app = array_shift($dialplan_action_array); - $dialplan_action_data = join(':', $dialplan_action_array); - } - else { - $dialplan_action_app = $dialplan_action; - $dialplan_action_data = ''; - } - - //add group action to query - $dialplan_detail_order += 10; - $sql .= ", ( "; - if (strlen($domain_uuid) == 0) { - $sql .= "null, "; - } - else { - $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 .= ") "; } - } + //parse group app and data + if (substr_count($dialplan_action, ":") > 0) { + $dialplan_action_array = explode(":", $dialplan_action); + $dialplan_action_app = array_shift($dialplan_action_array); + $dialplan_action_data = join(':', $dialplan_action_array); + } + else { + $dialplan_action_app = $dialplan_action; + $dialplan_action_data = ''; + } - } //for each - - //add to query for default anti-action (if defined) - if (strlen($dialplan_anti_action_app) > 0) { - - //increment group number, reset order number - $dialplan_detail_group = 999; - $dialplan_detail_order = 0; - - //add destination number condition - $dialplan_detail_order += 10; - $sql .= ", ( "; - if (strlen($domain_uuid) == 0) { + //add group action to query + $dialplan_detail_order += 10; + $sql .= ", ( "; + if (strlen($domain_uuid) == 0) { + $sql .= "null, "; + } + else { + $sql .= "'".$domain_uuid."', "; + } + $sql .= "'".$dialplan_uuid."', "; + $sql .= "'".uuid()."', "; + $sql .= "'action', "; + $sql .= "'".$dialplan_action_app."', "; + $sql .= "'".$dialplan_action_data."', "; $sql .= "null, "; - } - else { - $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 anti-action - $dialplan_detail_order += 10; - $sql .= ", ( "; - if (strlen($domain_uuid) == 0) { $sql .= "null, "; + $sql .= "'".$dialplan_detail_group."', "; + $sql .= "'".$dialplan_detail_order."' "; + $sql .= ") "; } - else { - $sql .= "'".$domain_uuid."', "; - } - $sql .= "'".$dialplan_uuid."', "; - $sql .= "'".uuid()."', "; - $sql .= "'action', "; - $sql .= "'".$dialplan_anti_action_app."', "; - $sql .= "'".$dialplan_anti_action_data."', "; + } + } //for each + + + //add to query for default anti-action (if defined) + if (strlen($dialplan_anti_action_app) > 0) { + + //increment group number, reset order number + $dialplan_detail_group = 999; + $dialplan_detail_order = 0; + + //add destination number condition + $dialplan_detail_order += 10; + $sql .= ", ( "; + if (strlen($domain_uuid) == 0) { $sql .= "null, "; + } + else { + $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 anti-action + $dialplan_detail_order += 10; + $sql .= ", ( "; + if (strlen($domain_uuid) == 0) { $sql .= "null, "; - $sql .= "'".$dialplan_detail_group."', "; - $sql .= "'".$dialplan_detail_order."' "; - $sql .= ") "; } - - //execute query - if ($conditions_exist) { - $db->exec(check_sql($sql)); - unset($sql); + else { + $sql .= "'".$domain_uuid."', "; } + $sql .= "'".$dialplan_uuid."', "; + $sql .= "'".uuid()."', "; + $sql .= "'action', "; + $sql .= "'".$dialplan_anti_action_app."', "; + $sql .= "'".$dialplan_anti_action_data."', "; + $sql .= "null, "; + $sql .= "null, "; + $sql .= "'".$dialplan_detail_group."', "; + $sql .= "'".$dialplan_detail_order."' "; + $sql .= ") "; + } - //commit the atomic transaction - $count = $db->exec("COMMIT;"); //returns affected rows + //execute query + if ($conditions_exist) { + $db->exec(check_sql($sql)); + unset($sql); + } - //update the dialplan xml - $dialplans = new dialplan; - $dialplans->source = "details"; - $dialplans->destination = "database"; - $dialplans->uuid = $dialplan_uuid; - $dialplans->xml(); + //commit the atomic transaction + $count = $db->exec("COMMIT;"); //returns affected rows - //clear the cache - $cache = new cache; - $cache->delete("dialplan:".$_SESSION["context"]); + //clear the cache + $cache = new cache; + $cache->delete("dialplan:".$_SESSION["context"]); - //synchronize the xml config - save_dialplan_xml(); + //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; + //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") { @@ -534,21 +544,23 @@ $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); - 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"]; + $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"]; + $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); @@ -581,34 +593,40 @@ //load current conditions into array (combined by group), and retrieve action and anti-action $c = 0; - foreach ($result as $row) { - if ($row['dialplan_detail_tag'] == 'action') { - if ($row['dialplan_detail_group'] == '999') { - $dialplan_anti_action = $row['dialplan_detail_type'].(($row['dialplan_detail_data'] != '') ? ':'.$row['dialplan_detail_data'] : null); + if (is_array($result)) { + foreach ($result as $row) { + if ($row['dialplan_detail_tag'] == 'action') { + if ($row['dialplan_detail_group'] == '999') { + $dialplan_anti_action = $row['dialplan_detail_type'].(($row['dialplan_detail_data'] != '') ? ':'.$row['dialplan_detail_data'] : null); + } + else { + $dialplan_actions[$row['dialplan_detail_group']] = $row['dialplan_detail_type'].(($row['dialplan_detail_data'] != '') ? ':'.$row['dialplan_detail_data'] : null); + } } - else { - $dialplan_actions[$row['dialplan_detail_group']] = $row['dialplan_detail_type'].(($row['dialplan_detail_data'] != '') ? ':'.$row['dialplan_detail_data'] : null); + else if ($row['dialplan_detail_tag'] == 'condition') { + $current_conditions[$row['dialplan_detail_group']][$row['dialplan_detail_type']] = $row['dialplan_detail_data']; } } - else if ($row['dialplan_detail_tag'] == 'condition') { - $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 - foreach ($current_conditions as $group_id => $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 preset variables found, then condition is a preset - if ($matches == sizeof($preset_variables)) { - $current_presets[$preset_number] = $group_id; + 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; + } } } } @@ -644,8 +662,10 @@ //$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']; - foreach ($time_condition_vars as $var_name => $var_label) { - echo "html += \" \";"; + if (is_array($time_condition_vars)) { + foreach ($time_condition_vars as $var_name => $var_label) { + echo "html += \" \";"; + } } ?> html += " "; @@ -824,7 +844,7 @@ function alternate_destination_required() { require_default_or_alt_destination = false; - $meh) { ?> + $meh) { ?> if (document.getElementById('preset_').checked) { preset_group_id = document.getElementById('preset_').value; preset_destination = $('#dialplan_action_' + preset_group_id).val(); @@ -954,43 +974,47 @@ function add_custom_condition($destination, $group_id, $dialplan_action = '') { if ($action == 'update') { $largest_group_id = 0; - 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]); - foreach ($conditions as $cond_var => $cond_val) { - $range_indicator = ($cond_var == 'date-time') ? '~' : '-'; - $tmp = explode($range_indicator, $cond_val); - $cond_val_start = $tmp[0]; - $cond_val_stop = $tmp[1]; - unset($tmp); + 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); + $cond_val_start = $tmp[0]; + $cond_val_stop = $tmp[1]; + unset($tmp); - //convert minute-of-day to time-of-day values - if ($cond_var == 'minute-of-day') { - $cond_var = 'time-of-day'; - $cond_val_start = number_pad(floor($cond_val_start / 60),2).":".number_pad(fmod($cond_val_start, 60),2); - if ($cond_val_stop != '') { - $cond_val_stop = number_pad(floor($cond_val_stop / 60),2).":".number_pad(fmod($cond_val_stop, 60),2); + //convert minute-of-day to time-of-day values + if ($cond_var == 'minute-of-day') { + $cond_var = 'time-of-day'; + $cond_val_start = number_pad(floor($cond_val_start / 60),2).":".number_pad(fmod($cond_val_start, 60),2); + if ($cond_val_stop != '') { + $cond_val_stop = number_pad(floor($cond_val_stop / 60),2).":".number_pad(fmod($cond_val_stop, 60),2); + } + } + + echo ""; } } - - echo ""; + //used to determine largest custom group id in use + $largest_group_id = ($group_id > $largest_group_id) ? $group_id : $largest_group_id; } - //used to determine largest custom group id in use - $largest_group_id = ($group_id > $largest_group_id) ? $group_id : $largest_group_id; } } } @@ -1018,87 +1042,95 @@ if ($action == 'update') { echo "\n"; echo "\n"; - foreach ($available_presets as $preset_number => $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; - if (strlen($text['label-preset_'.$preset_name]) > 0) { - $label_preset_name = $text['label-preset_'.$preset_name]; - } - else { - $label_preset_name = ucwords(str_replace(array("-", "_"), " ", $preset_name)); - } - echo "
\n"; - echo ""; - if ($action == 'update' && is_array($current_presets) && $current_presets[$preset_number] != '') { - //add (potentially customized) preset conditions and populate - foreach ($current_conditions[$preset_group_id] as $cond_var => $cond_val) { - $range_indicator = ($cond_var == 'date-time') ? '~' : '-'; - $tmp = explode($range_indicator, $cond_val); - $cond_val_start = $tmp[0]; - $cond_val_stop = $tmp[1]; - unset($tmp); - - //convert minute-of-day to time-of-day values - if ($cond_var == 'minute-of-day') { - $cond_var = 'time-of-day'; - $cond_val_start = number_pad(floor($cond_val_start / 60),2).":".number_pad(fmod($cond_val_start, 60),2); - if ($cond_val_stop != '') { - $cond_val_stop = number_pad(floor($cond_val_stop / 60),2).":".number_pad(fmod($cond_val_stop, 60),2); - } - } - - echo ""; + } + } + } + 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); + $preset_value_start = $tmp[0]; + $preset_value_stop = $tmp[1]; + unset($tmp); + echo "\n\n"; + } + } } - echo " $('#dialplan_action_".$preset_group_id." option[value=\"".$dialplan_actions[$preset_group_id]."\"]').prop('selected', true);\n\n"; - echo ""; - } - } - else { - //add default preset conditions and populate - foreach ($preset_variables as $preset_variable => $preset_value) { - $range_indicator = ($preset_variable == 'date-time') ? '~' : '-'; - $tmp = explode($range_indicator, $preset_value); - $preset_value_start = $tmp[0]; - $preset_value_stop = $tmp[1]; - unset($tmp); - echo "\n\n"; } } }