diff --git a/app/time_conditions/time_condition_edit.php b/app/time_conditions/time_condition_edit.php index 45b674651f..52009a830a 100644 --- a/app/time_conditions/time_condition_edit.php +++ b/app/time_conditions/time_condition_edit.php @@ -84,253 +84,273 @@ } 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 .= "("; - 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); - - //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; - - //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]); - unset($_REQUEST['value'][$group_id]); - unset($_REQUEST['dialplan_action'][$group_id]); - continue; - } - $_REQUEST['variable'][$group_id] = $conditions; + //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; } - } - 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]); - unset($_REQUEST['value'][$group_id][$condition_id]); - } + //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 .= "("; + if (strlen($domain_uuid) == 0) { + $sql .= "null, "; } - } - } - } - - //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'] == '') { - unset($_REQUEST['variable'][$group_id][$value_id]); - unset($_REQUEST['value'][$group_id][$value_id]); + else { + $sql .= "'".$domain_uuid."', "; } - } - } - } - - //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]); - unset($_REQUEST['value'][$group_id]); - 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'] == '') || - (!in_array($group_id, $_REQUEST['preset']) && $_REQUEST['dialplan_action'][$group_id] == '') - ) { - 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]); } - } + $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); - //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 "; - - //add conditions - if (is_array($_REQUEST['variable'])) foreach ($_REQUEST['variable'] as $group_id => $conditions) { - - $group_conditions_exist[$group_id] = false; - - //determine if preset - $is_preset = (in_array($group_id, $_REQUEST['preset'])) ? true : false; - - //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; + //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; - 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']; + //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]); + unset($_REQUEST['value'][$group_id]); + unset($_REQUEST['dialplan_action'][$group_id]); + continue; + } + $_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']); - //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]; + //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]); + unset($_REQUEST['value'][$group_id][$condition_id]); + } } } + } + } - $cond_value = $cond_start; - if ($cond_stop != '') { - $range_indicator = ($cond_var == 'date-time') ? '~' : '-'; - $cond_value .= $range_indicator.$cond_stop; + //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'] == '') { + unset($_REQUEST['variable'][$group_id][$value_id]); + unset($_REQUEST['value'][$group_id][$value_id]); + } } + } + } - if (!$group_conditions_exist[$group_id]) { - //add destination number condition + //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]); + unset($_REQUEST['value'][$group_id]); + 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'] == '') || + (!in_array($group_id, $_REQUEST['preset']) && $_REQUEST['dialplan_action'][$group_id] == '') + ) { + 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; + + //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 + if (is_array($_REQUEST['variable'])) foreach ($_REQUEST['variable'] as $group_id => $conditions) { + + $group_conditions_exist[$group_id] = false; + + //determine if preset + $is_preset = (in_array($group_id, $_REQUEST['preset'])) ? true : false; + + //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_order = 0; + + 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; + if ($cond_stop != '') { + $range_indicator = ($cond_var == 'date-time') ? '~' : '-'; + $cond_value .= $range_indicator.$cond_stop; + } + + 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 .= ") "; + } + + //add condition to query string $dialplan_detail_order += 10; - $sql .= ($conditions_exist) ? ", ( " : "( "; + $sql .= ", ( "; if (strlen($domain_uuid) == 0) { $sql .= "null, "; } @@ -340,196 +360,180 @@ $sql .= "'".$dialplan_uuid."', "; $sql .= "'".uuid()."', "; $sql .= "'condition', "; - $sql .= "'destination_number', "; - $sql .= "'^".$dialplan_number."$', "; + $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 .= ", ( "; + if (strlen($domain_uuid) == 0) { + $sql .= "null, "; + } + else { + $sql .= "'".$domain_uuid."', "; + } + $sql .= "'".$dialplan_uuid."', "; + $sql .= "'".uuid()."', "; + $sql .= "'action', "; + $sql .= "'set', "; + $sql .= "'preset=".$available_preset_name."', "; + $sql .= "null, "; + $sql .= "'true', "; + $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 = ''; + } + + //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 .= ") "; } - - //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 + //add to query for default anti-action (if defined) + if (strlen($dialplan_anti_action_app) > 0) { - //continue adding to query only if conditions exist in current group - if ($group_conditions_exist[$group_id]) { + //increment group number, reset order number + $dialplan_detail_group = 999; + $dialplan_detail_order = 0; - //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 .= ", ( "; - if (strlen($domain_uuid) == 0) { - $sql .= "null, "; - } - else { - $sql .= "'".$domain_uuid."', "; - } - $sql .= "'".$dialplan_uuid."', "; - $sql .= "'".uuid()."', "; - $sql .= "'action', "; - $sql .= "'set', "; - $sql .= "'preset=".$available_preset_name."', "; - $sql .= "null, "; - $sql .= "'true', "; - $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 = ''; - } - - //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."', "; + //add destination number condition + $dialplan_detail_order += 10; + $sql .= ", ( "; + if (strlen($domain_uuid) == 0) { $sql .= "null, "; - $sql .= "null, "; - $sql .= "'".$dialplan_detail_group."', "; - $sql .= "'".$dialplan_detail_order."' "; - $sql .= ") "; } - } - } //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) { + else { + $sql .= "'".$domain_uuid."', "; + } + $sql .= "'".$dialplan_uuid."', "; + $sql .= "'".uuid()."', "; + $sql .= "'condition', "; + $sql .= "'destination_number', "; + $sql .= "'^".$dialplan_number."$', "; $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 .= ") "; + + //add anti-action + $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_anti_action_app."', "; + $sql .= "'".$dialplan_anti_action_data."', "; + $sql .= "null, "; + $sql .= "null, "; + $sql .= "'".$dialplan_detail_group."', "; + $sql .= "'".$dialplan_detail_order."' "; + $sql .= ") "; } - else { - $sql .= "'".$domain_uuid."', "; + + //execute query + if ($conditions_exist) { + $db->exec(check_sql($sql)); + unset($sql); } - $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 .= ") "; - } - //execute query - if ($conditions_exist) { - $db->exec(check_sql($sql)); - unset($sql); - } + //commit the atomic transaction + $count = $db->exec("COMMIT;"); - //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"]); + //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)