Portions created by the Initial Developer are Copyright (C) 2008-2019 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('time_condition_add') || permission_exists('time_condition_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //initialize the destinations object $destination = new destinations; //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 if (is_uuid($_REQUEST["id"])) { $action = "update"; $dialplan_uuid = $_REQUEST["id"]; } else { $action = "add"; } //get the post variables if (count($_POST) > 0) { $domain_uuid = $_POST["domain_uuid"]; $dialplan_name = $_POST["dialplan_name"]; $dialplan_number = $_POST["dialplan_number"]; $dialplan_order = $_POST["dialplan_order"]; $dialplan_anti_action = $_POST["dialplan_anti_action"]; $dialplan_anti_action_array = explode(":", $dialplan_anti_action); $dialplan_anti_action_app = array_shift($dialplan_anti_action_array); $dialplan_anti_action_data = join(':', $dialplan_anti_action_array); if (permission_exists('time_condition_context')) { $dialplan_context = $_POST["dialplan_context"]; } $dialplan_enabled = $_POST["dialplan_enabled"]; $dialplan_description = $_POST["dialplan_description"]; if (!permission_exists('time_condition_domain')) { $domain_uuid = $_SESSION['domain_uuid']; } } if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); header('Location: time_conditions.php'); exit; } //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); //set the context for users that do not have the permission if (permission_exists('time_condition_context')) { $dialplan_context = $_POST["dialplan_context"]; } else { if ($action == 'add') { $dialplan_context = $_SESSION['domain_name']; } if ($action == 'update') { $sql = "select * from v_dialplans "; $sql .= "where dialplan_uuid = :dialplan_uuid "; $parameters['dialplan_uuid'] = $dialplan_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $domain_uuid = $row["domain_uuid"]; $dialplan_context = $row["dialplan_context"]; } unset($sql, $parameters, $row); } } //process main dialplan entry if ($action == "add") { //build insert array $dialplan_uuid = uuid(); $array['dialplans'][0]['dialplan_uuid'] = $dialplan_uuid; $array['dialplans'][0]['app_uuid'] = '4b821450-926b-175a-af93-a03c441818b1'; $array['dialplans'][0]['dialplan_continue'] = 'false'; $array['dialplans'][0]['dialplan_context'] = $dialplan_context; //grant temporary permissions $p = new permissions; $p->add('dialplan_add', 'temp'); } else if ($action == "update") { //build delete array $array['dialplan_details'][0]['dialplan_uuid'] = $dialplan_uuid; //grant temporary permissions $p = new permissions; $p->add('dialplan_detail_delete', 'temp'); //execute delete $database = new database; $database->app_name = 'time_conditions'; $database->app_uuid = '4b821450-926b-175a-af93-a03c441818b1'; $database->delete($array); unset($array); //revoke temporary permissions $p->delete('dialplan_detail_delete', 'temp'); //build update array $array['dialplans'][0]['dialplan_uuid'] = $dialplan_uuid; $array['dialplans'][0]['dialplan_continue'] = 'true'; if (strlen($dialplan_context) > 0) { $array['dialplans'][0]['dialplan_context'] = $dialplan_context; } //grant temporary permissions $p = new permissions; $p->add('dialplan_edit', 'temp'); } if (is_array($array) && @sizeof($array) != 0) { //add common fields to insert/update array $array['dialplans'][0]['domain_uuid'] = is_uuid($domain_uuid) ? $domain_uuid : null; $array['dialplans'][0]['dialplan_name'] = $dialplan_name; $array['dialplans'][0]['dialplan_number'] = $dialplan_number; $array['dialplans'][0]['dialplan_order'] = $dialplan_order; $array['dialplans'][0]['dialplan_enabled'] = $dialplan_enabled; $array['dialplans'][0]['dialplan_description'] = $dialplan_description; //execute insert/update $database = new database; $database->app_name = 'time_conditions'; $database->app_uuid = '4b821450-926b-175a-af93-a03c441818b1'; $database->save($array); unset($array); //revoke temporary permissions $p->delete('dialplan_add', 'temp'); $p->delete('dialplan_edit', 'temp'); } //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; } } 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 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]); } } } } //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]); } } } } } } //add conditions to insert array for custom and preset conditions if (is_array($_REQUEST['variable'])) { $x = 0; 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 = $_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; $array['dialplan_details'][$x]['domain_uuid'] = is_uuid($domain_uuid) ? $domain_uuid : null; $array['dialplan_details'][$x]['dialplan_uuid'] = $dialplan_uuid; $array['dialplan_details'][$x]['dialplan_detail_uuid'] = uuid(); $array['dialplan_details'][$x]['dialplan_detail_tag'] = 'condition'; $array['dialplan_details'][$x]['dialplan_detail_type'] = 'destination_number'; $array['dialplan_details'][$x]['dialplan_detail_data'] = '^'.$dialplan_number.'$'; $array['dialplan_details'][$x]['dialplan_detail_break'] = null; $array['dialplan_details'][$x]['dialplan_detail_inline'] = null; $array['dialplan_details'][$x]['dialplan_detail_group'] = $dialplan_detail_group; $array['dialplan_details'][$x]['dialplan_detail_order'] = $dialplan_detail_order; $x++; } //add condition to query string $dialplan_detail_order += 10; $array['dialplan_details'][$x]['domain_uuid'] = is_uuid($domain_uuid) ? $domain_uuid : null; $array['dialplan_details'][$x]['dialplan_uuid'] = $dialplan_uuid; $array['dialplan_details'][$x]['dialplan_detail_uuid'] = uuid(); $array['dialplan_details'][$x]['dialplan_detail_tag'] = 'condition'; $array['dialplan_details'][$x]['dialplan_detail_type'] = $cond_var; $array['dialplan_details'][$x]['dialplan_detail_data'] = $cond_value; $array['dialplan_details'][$x]['dialplan_detail_break'] = 'never'; $array['dialplan_details'][$x]['dialplan_detail_inline'] = null; $array['dialplan_details'][$x]['dialplan_detail_group'] = $dialplan_detail_group; $array['dialplan_details'][$x]['dialplan_detail_order'] = $dialplan_detail_order; $x++; $group_conditions_exist[$group_id] = true; } //if } //foreach } //if //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 = $_REQUEST["dialplan_action"][$group_id]; if ($dialplan_action == '') { if ($is_preset) { if ($_REQUEST['default_preset_action'] != '') { $dialplan_action = $_REQUEST['default_preset_action']; } else if ($_REQUEST['dialplan_anti_action'] != '') { $dialplan_action = $_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; $array['dialplan_details'][$x]['domain_uuid'] = is_uuid($domain_uuid) ? $domain_uuid : null; $array['dialplan_details'][$x]['dialplan_uuid'] = $dialplan_uuid; $array['dialplan_details'][$x]['dialplan_detail_uuid'] = uuid(); $array['dialplan_details'][$x]['dialplan_detail_tag'] = 'action'; $array['dialplan_details'][$x]['dialplan_detail_type'] = 'set'; $array['dialplan_details'][$x]['dialplan_detail_data'] = 'preset='.$available_preset_name; $array['dialplan_details'][$x]['dialplan_detail_break'] = null; $array['dialplan_details'][$x]['dialplan_detail_inline'] = 'true'; $array['dialplan_details'][$x]['dialplan_detail_group'] = $dialplan_detail_group; $array['dialplan_details'][$x]['dialplan_detail_order'] = $dialplan_detail_order; $x++; } } } } } //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; $array['dialplan_details'][$x]['domain_uuid'] = is_uuid($domain_uuid) ? $domain_uuid : null; $array['dialplan_details'][$x]['dialplan_uuid'] = $dialplan_uuid; $array['dialplan_details'][$x]['dialplan_detail_uuid'] = uuid(); $array['dialplan_details'][$x]['dialplan_detail_tag'] = 'action'; $array['dialplan_details'][$x]['dialplan_detail_type'] = $dialplan_action_app; $array['dialplan_details'][$x]['dialplan_detail_data'] = $dialplan_action_data; $array['dialplan_details'][$x]['dialplan_detail_break'] = null; $array['dialplan_details'][$x]['dialplan_detail_inline'] = null; $array['dialplan_details'][$x]['dialplan_detail_group'] = $dialplan_detail_group; $array['dialplan_details'][$x]['dialplan_detail_order'] = $dialplan_detail_order; $x++; } } } //foreach } //if //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; $array['dialplan_details'][$x]['domain_uuid'] = is_uuid($domain_uuid) ? $domain_uuid : null; $array['dialplan_details'][$x]['dialplan_uuid'] = $dialplan_uuid; $array['dialplan_details'][$x]['dialplan_detail_uuid'] = uuid(); $array['dialplan_details'][$x]['dialplan_detail_tag'] = 'condition'; $array['dialplan_details'][$x]['dialplan_detail_type'] = 'destination_number'; $array['dialplan_details'][$x]['dialplan_detail_data'] = '^'.$dialplan_number.'$'; $array['dialplan_details'][$x]['dialplan_detail_break'] = null; $array['dialplan_details'][$x]['dialplan_detail_inline'] = null; $array['dialplan_details'][$x]['dialplan_detail_group'] = $dialplan_detail_group; $array['dialplan_details'][$x]['dialplan_detail_order'] = $dialplan_detail_order; $x++; //add anti-action $dialplan_detail_order += 10; $array['dialplan_details'][$x]['domain_uuid'] = is_uuid($domain_uuid) ? $domain_uuid : null; $array['dialplan_details'][$x]['dialplan_uuid'] = $dialplan_uuid; $array['dialplan_details'][$x]['dialplan_detail_uuid'] = uuid(); $array['dialplan_details'][$x]['dialplan_detail_tag'] = 'action'; $array['dialplan_details'][$x]['dialplan_detail_type'] = $dialplan_anti_action_app; $array['dialplan_details'][$x]['dialplan_detail_data'] = $dialplan_anti_action_data; $array['dialplan_details'][$x]['dialplan_detail_break'] = null; $array['dialplan_details'][$x]['dialplan_detail_inline'] = null; $array['dialplan_details'][$x]['dialplan_detail_group'] = $dialplan_detail_group; $array['dialplan_details'][$x]['dialplan_detail_order'] = $dialplan_detail_order; $x++; } //execute query if (is_array($array) && @sizeof($array) != 0) { //grant temporary permissions $p = new permissions; $p->add('dialplan_detail_add', 'temp'); $p->add('dialplan_detail_edit', 'temp'); //execute insert $database = new database; $database->app_name = 'time_conditions'; $database->app_uuid = '4b821450-926b-175a-af93-a03c441818b1'; $database->save($array); unset($array); //revoke temporary permissions $p->delete('dialplan_detail_add', 'temp'); $p->delete('dialplan_detail_edit', 'temp'); } //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"]); //synchronize the xml config save_dialplan_xml(); //set the message if ($action == "add") { message::add($text['message-add']); } else if ($action == "update") { message::add($text['message-update']); } //redirect the browser if (is_uuid($dialplan_uuid)) { header("Location: time_condition_edit.php?id=".$dialplan_uuid.($app_uuid != '' ? "&app_uuid=".$app_uuid : null)); exit; } } //get existing data to pre-populate form if (is_uuid($dialplan_uuid) && $_POST["persistformvar"] != "true") { //get main dialplan entry $sql = "select * from v_dialplans "; $sql .= "where dialplan_uuid = :dialplan_uuid "; $parameters['dialplan_uuid'] = $dialplan_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $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($sql, $parameters, $row); //remove the underscore in the time condition name $dialplan_name = str_replace('_', ' ', $dialplan_name); //get dialplan detail conditions $sql = "select dialplan_detail_group, dialplan_detail_tag, dialplan_detail_type, dialplan_detail_data "; $sql .= "from v_dialplan_details "; $sql .= "where dialplan_uuid = :dialplan_uuid "; $sql .= "and "; $sql .= "( "; $sql .= " ( "; $sql .= " dialplan_detail_tag = 'condition' "; $sql .= " and dialplan_detail_type in ('year','mon','mday','wday','yday','week','mweek','hour','minute','minute-of-day','time-of-day','date-time') "; $sql .= " ) "; $sql .= " or ( "; $sql .= " dialplan_detail_tag = 'action' "; //$sql .= " and dialplan_detail_data not like 'preset=%' "; $sql .= " ) "; $sql .= ") "; $sql .= "order by dialplan_detail_group asc, dialplan_detail_order asc"; $parameters['dialplan_uuid'] = $dialplan_uuid; $database = new database; $dialplan_details = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //load current conditions into array (combined by group), and retrieve action and anti-action $c = 0; if (is_array($dialplan_details)) { foreach ($dialplan_details 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 if ($row['dialplan_detail_tag'] == 'condition') { $current_conditions[$row['dialplan_detail_group']][$row['dialplan_detail_type']] = $row['dialplan_detail_data']; } } } //find the selected presets if (is_array($available_presets)) { foreach ($available_presets as $preset_number => &$preset) { if (is_array($preset)) { foreach ($preset as $preset_name => $preset_variables) { $preset_checked[$preset_name] = 'false'; if (is_array($dialplan_details)) { foreach ($dialplan_details as $row) { if ($row['dialplan_detail_tag'] == 'action') { if ($row['dialplan_detail_data'] == 'preset='.$preset_name) { $preset_checked[$preset_name] = 'true'; } } } } } } } } //loop through available presets (if any) if (is_array($available_presets)) { foreach ($available_presets as $preset_number => $preset) { 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; } } } } } } } } //set the defaults if (strlen($dialplan_context) == 0) { $dialplan_context = $_SESSION['domain_name']; } //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //include the header $document['title'] = $text['title-time_condition']; require_once "resources/header.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'].""; echo "

\n"; echo "
\n"; echo " \n"; if (if_group("superadmin") && $action == 'update') { echo " \n"; } echo " \n"; echo "
\n"; echo " ".$text['description-time_conditions']."\n"; echo "
"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; function add_custom_condition($destination, $group_id, $dialplan_action = '') { global $text, $v_link_label_add; echo "\n"; echo "\n"; echo "\n"; echo "\n"; } 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); $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 ""; } } //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)) { $group_id = 500; } else { $group_id = $largest_group_id += 5; } add_custom_condition($destination, $group_id); echo ""; //if presets exist, show the preset section if (isset($available_presets) && sizeof($available_presets) > 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"; if (permission_exists('time_condition_domain')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('time_condition_context')) { 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-settings']; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " "; echo " "; echo " "; echo " "; echo " \n"; echo " \n"; echo "
".$text['label-condition']."".$text['label-condition_value']."".$text['label-condition_range']."".$v_link_label_add."
"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " "; echo "
\n"; //$destination = new destinations; echo $destination->select('dialplan', 'dialplan_action['.$group_id.']', $dialplan_action); echo "
\n"; echo "
"; echo "
"; echo " ".$text['description-settings']; echo "
\n"; echo " ".$text['label-presets']."\n"; echo "\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) && $preset_checked[$preset_name] == 'true') ? "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 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); $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 "
\n"; echo " \n"; echo " "; echo " "; echo " "; echo "
"; echo " \n"; echo " "; echo $destination->select('dialplan', 'default_preset_action', $dialplan_action); echo " "; echo "
"; echo "
"; echo " ".$text['description-presets']."
\n"; echo "
\n"; echo " ".$text['label-alternate-destination']."\n"; echo "\n"; echo " ".$destination->select('dialplan', 'dialplan_anti_action', $dialplan_anti_action); echo "
\n"; echo " ".$text['label-order']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo "
\n"; echo " ".$text['label-domain']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-domain_name']."\n"; echo "
\n"; echo " ".$text['label-context']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-enter-context']."\n"; echo "
\n"; echo " ".$text['label-enabled']."\n"; echo "\n"; echo "\n"; echo "
\n"; echo "
\n"; echo " ".$text['label-description']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo "
\n"; echo "
"; echo "
\n"; if ($action == "update") { echo " \n"; } echo " \n"; echo " \n"; echo "
"; echo ""; echo "
"; //include the footer require_once "resources/footer.php"; ?>