diff --git a/app/time_conditions/app_languages.php b/app/time_conditions/app_languages.php
index 02ad6c9854..fe4a5bdb54 100644
--- a/app/time_conditions/app_languages.php
+++ b/app/time_conditions/app_languages.php
@@ -10,6 +10,11 @@
$text['description-time-conditions']['pt-pt'] = "Rota dinamicamente as chamadas para um menu IVR, números externos, scripts ou outros destinos com base nas condições de tempo.";
$text['description-time-conditions']['fr-fr'] = "Dynamiquement acheminer les appels à un menu IVR, numéros externes, scripts, ou d'autres destinations en fonction des conditions de temps.";
+ $text['button-advanced']['en-us'] = "Advanced";
+ $text['button-advanced']['es-cl'] = "Avanzado";
+ $text['button-advanced']['pt-pt'] = "Avancé";
+ $text['button-advanced']['fr-fr'] = "Avançado";
+
$text['button-back']['en-us'] = "Back";
$text['button-back']['es-cl'] = "Volver";
$text['button-back']['pt-pt'] = "Voltar";
@@ -45,47 +50,52 @@
$text['description-template']['pt-pt'] = "Os templates oferecem uma lista condições temporais.";
$text['description-template']['fr-fr'] = "Le modèle fourni une liste de présélection.";
- $text['label-conditions']['en-us'] = "Conditions";
- $text['label-conditions']['es-cl'] = "Condiciones";
- $text['label-conditions']['pt-pt'] = "Condições";
- $text['label-conditions']['fr-fr'] = "Conditions";
+ $text['label-custom']['en-us'] = "Custom";
+ $text['label-custom']['es-cl'] = "Costumbre";
+ $text['label-custom']['pt-pt'] = "Personalizado";
+ $text['label-custom']['fr-fr'] = "Coutume";
- $text['description-conditions']['en-us'] = "Define conditions for the Action.";
- $text['description-conditions']['es-cl'] = "Definir condiciones para la Acción.";
- $text['description-conditions']['pt-pt'] = "Definir condições para a ação.";
- $text['description-conditions']['fr-fr'] = "Définir les conditions pour l'action.";
+ $text['label-conditions']['en-us'] = "Conditions";
+ $text['label-conditions']['es-cl'] = "Condición";
+ $text['label-conditions']['pt-pt'] = "Condição";
+ $text['label-conditions']['fr-fr'] = "état";
+
+ $text['label-condition']['en-us'] = "Condition";
+ $text['label-condition']['es-cl'] = "Condiciones";
+ $text['label-condition']['pt-pt'] = "Condições";
+ $text['label-condition']['fr-fr'] = "état";
+
+ $text['label-label']['en-us'] = "Label";
+ $text['label-label']['es-cl'] = "Etiqueta";
+ $text['label-label']['pt-pt'] = "Etiqueta";
+ $text['label-label']['fr-fr'] = "étiquette";
+
+ $text['description-conditions']['en-us'] = "Define custom conditions necessary to execute the destination selected above.";
+ $text['description-conditions']['es-cl'] = "Definir las condiciones personalizados necesarios para ejecutar el destino seleccionado anteriormente.";
+ $text['description-conditions']['pt-pt'] = "Definir condições personalizadas necessárias para executar o destino selecionado acima.";
+ $text['description-conditions']['fr-fr'] = "Définir les conditions nécessaires pour exécuter la destination sélectionnée ci-dessus personnalisés.";
$text['label-condition_parameter']['en-us'] = "Parameter";
$text['label-condition_parameter']['es-cl'] = "Parámetro";
$text['label-condition_parameter']['pt-pt'] = "Parâmetro";
$text['label-condition_parameter']['fr-fr'] = "Paramètre";
- $text['label-condition_scope']['en-us'] = "Scope";
- $text['label-condition_scope']['es-cl'] = "Alcance";
- $text['label-condition_scope']['pt-pt'] = "Escopo";
- $text['label-condition_scope']['fr-fr'] = "Portée";
+ $text['label-condition_value']['en-us'] = "Value";
+ $text['label-condition_value']['es-cl'] = "Valor";
+ $text['label-condition_value']['pt-pt'] = "Valor";
+ $text['label-condition_value']['fr-fr'] = "Valeur";
- $text['option-condition_scope_specific']['en-us'] = "Specific";
- $text['option-condition_scope_specific']['es-cl'] = "Específico";
- $text['option-condition_scope_specific']['pt-pt'] = "Específico";
- $text['option-condition_scope_specific']['fr-fr'] = "Spécifique";
-
- $text['option-condition_scope_range']['en-us'] = "Range";
- $text['option-condition_scope_range']['es-cl'] = "Alcance";
- $text['option-condition_scope_range']['pt-pt'] = "Alcance";
- $text['option-condition_scope_range']['fr-fr'] = "Gamme";
-
- $text['label-condition_values']['en-us'] = "Value(s)";
- $text['label-condition_values']['es-cl'] = "";
- $text['label-condition_values']['pt-pt'] = "";
- $text['label-condition_values']['fr-fr'] = "";
+ $text['label-condition_range']['en-us'] = "Range";
+ $text['label-condition_range']['es-cl'] = "Rango";
+ $text['label-condition_range']['pt-pt'] = "Range";
+ $text['label-condition_range']['fr-fr'] = "Range";
$text['label-presets']['en-us'] = "Presets";
- $text['label-presets']['es-cl'] = "Valor(s)";
- $text['label-presets']['pt-pt'] = "Preço(s)";
- $text['label-presets']['fr-fr'] = "Valeur (s)";
+ $text['label-presets']['es-cl'] = "Presets";
+ $text['label-presets']['pt-pt'] = "Presets";
+ $text['label-presets']['fr-fr'] = "Présélections";
- $text['description-presets']['en-us'] = "Pre-defined conditions.";
+ $text['description-presets']['en-us'] = "Select or customize pre-defined conditions necessary to execute the selected destination(s).";
$text['description-presets']['es-cl'] = "Las condiciones pre-definida.";
$text['description-presets']['pt-pt'] = "Condições pré-definidas.";
$text['description-presets']['fr-fr'] = "Conditions pré-définies.";
@@ -220,15 +230,15 @@
$text['label-false']['pt-pt'] = "Não";
$text['label-false']['fr-fr'] = "Non";
- $text['label-action']['en-us'] = "Action";
- $text['label-action']['es-cl'] = "Acción cuando sea Verdadeo";
- $text['label-action']['pt-pt'] = "Acção quando Verdadeiro";
- $text['label-action']['fr-fr'] = "Action quand Vrai";
+ $text['label-select_destination']['en-us'] = "Select Destination";
+ $text['label-select_destination']['es-cl'] = "Seleccione Destino";
+ $text['label-select_destination']['pt-pt'] = "Selecione um Destino";
+ $text['label-select_destination']['fr-fr'] = "Choisissez une Destination";
- $text['label-action-alternate']['en-us'] = "Alternate Action";
- $text['label-action-alternate']['es-cl'] = "Acción cuando sea Falso";
- $text['label-action-alternate']['pt-pt'] = "Acção quando Falso";
- $text['label-action-alternate']['fr-fr'] = "Action quand Faux";
+ $text['label-alternate-destination']['en-us'] = "Alternate Destination";
+ $text['label-alternate-destination']['es-cl'] = "Destino Alternativo";
+ $text['label-alternate-destination']['pt-pt'] = "Destino Alternativo";
+ $text['label-alternate-destination']['fr-fr'] = "Autre Destinations";
$text['label-order']['en-us'] = "Order";
$text['label-order']['es-cl'] = "Orden";
@@ -260,7 +270,7 @@
$text['label-required-dialplan_number']['pt-pt'] = "Por favor indique: Número da Extensão";
$text['label-required-dialplan_number']['fr-fr'] = "Merci d'indiquer: Numéro de l'extension";
- $text['label-required-action']['en-us'] = "Please provide: Action";
+ $text['label-required-action']['en-us'] = "Please provide: Destination";
$text['label-required-action']['es-cl'] = "Por favor indique: Acción cuando sea Verdadeo";
$text['label-required-action']['pt-pt'] = "Por favor indique: Acção quando Verdadeiro";
$text['label-required-action']['fr-fr'] = "Merci d'indiquer: Action quand Vrai";
diff --git a/app/time_conditions/time_condition_edit.php b/app/time_conditions/time_condition_edit.php
index 1d05841851..293fb5194a 100644
--- a/app/time_conditions/time_condition_edit.php
+++ b/app/time_conditions/time_condition_edit.php
@@ -34,7 +34,6 @@ else {
exit;
}
require_once "resources/header.php";
-require_once "resources/paging.php";
//add multi-lingual support
@@ -61,11 +60,6 @@ require_once "resources/paging.php";
$dialplan_number = check_str($_POST["dialplan_number"]);
$dialplan_order = check_str($_POST["dialplan_order"]);
- $dialplan_action = check_str($_POST["dialplan_action"]);
- $dialplan_action_array = explode(":", $dialplan_action);
- $dialplan_action_app = array_shift($dialplan_action_array);
- $dialplan_action_data = join(':', $dialplan_action_array);
-
$dialplan_anti_action = check_str($_POST["dialplan_anti_action"]);
$dialplan_anti_action_array = explode(":", $dialplan_anti_action);
$dialplan_anti_action_app = array_shift($dialplan_anti_action_array);
@@ -78,9 +72,9 @@ require_once "resources/paging.php";
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($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";
@@ -102,6 +96,7 @@ require_once "resources/paging.php";
//start the atomic transaction
$count = $db->exec("BEGIN;"); //returns affected rows
+
//process main dialplan entry
if ($action == "add") {
@@ -169,224 +164,55 @@ require_once "resources/paging.php";
$dialplan_detail_order = 0;
- //check if custom conditions defined
- $custom_conditions_defined = false;
- foreach ($_REQUEST['variable'] as $cond_var) {
- if ($cond_var != '') { $custom_conditions_defined = true; }
+ //clean up array
+ //remove presets not checked, restructure variable array
+ 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;
}
+ foreach ($_REQUEST['variable']['custom'] as $group_id => $conditions) {
+ $_REQUEST['variable'][$group_id] = $conditions;
+ }
+ unset($_REQUEST['variable']['custom'], $_REQUEST['variable']['preset']);
- if ($custom_conditions_defined) {
-
- //build insert query for custom conditions
- $sql = "insert into v_dialplan_details ";
- $sql .= "( ";
- $sql .= "domain_uuid, ";
- $sql .= "dialplan_uuid, ";
- $sql .= "dialplan_detail_uuid, ";
- $sql .= "dialplan_detail_tag, ";
- $sql .= "dialplan_detail_type, ";
- $sql .= "dialplan_detail_data, ";
- $sql .= "dialplan_detail_break, ";
- $sql .= "dialplan_detail_inline, ";
- $sql .= "dialplan_detail_group, ";
- $sql .= "dialplan_detail_order ";
- $sql .= ") ";
- $sql .= "values ";
-
- //add destination number condition
- $dialplan_detail_order += 10;
- $sql .= "( ";
- $sql .= "'".$domain_uuid."', ";
- $sql .= "'".$dialplan_uuid."', ";
- $sql .= "'".uuid()."', ";
- $sql .= "'condition', ";
- $sql .= "'destination_number', ";
- $sql .= "'^".$dialplan_number."$', ";
- $sql .= "'never', ";
- $sql .= "null, ";
- $sql .= "'".$dialplan_detail_group."', ";
- $sql .= "'".$dialplan_detail_order."' ";
- $sql .= ")";
-
- //add custom conditions
- foreach ($_REQUEST['variable'] as $cond_num => $cond_var) {
- if ($cond_var != '') {
- $scope = $_REQUEST['scope'][$cond_num];
- $cond_start = $_REQUEST[$cond_var][$cond_num]['start'];
- $cond_stop = $_REQUEST[$cond_var][$cond_num]['stop'];
-
- //handle time of day
- if ($cond_var == 'time-of-day' && $cond_start['hour'] != '') {
- //format condition start
- if ($cond_start['notation'] == 'PM') {
- $cond_start_hour = ($cond_start['hour'] != 12) ? $cond_start['hour'] += 12 : $cond_start['hour'];
- }
- else if ($cond_start['notation'] == 'AM') {
- $cond_start_hour = ($cond_start['hour'] == 12) ? $cond_start['hour'] -= 12 : $cond_start['hour'];
- }
- $cond_start_hour = number_pad($cond_start_hour,2);
- $cond_start_minute = $cond_start['minute'];
- $cond_start = $cond_start_hour.':'.$cond_start_minute;
-
- //format condition stop
- if ($cond_start != '' && $scope == 'range') {
- if ($cond_stop['notation'] == 'PM') {
- $cond_stop_hour = ($cond_stop['hour'] != 12) ? $cond_stop['hour'] += 12 : $cond_stop['hour'];
- }
- else if ($cond_stop['notation'] == 'AM') {
- $cond_stop_hour = ($cond_stop['hour'] == 12) ? $cond_stop['hour'] -= 12 : $cond_stop['hour'];
- }
- $cond_stop_hour = number_pad($cond_stop_hour,2);
- $cond_stop_minute = $cond_stop['minute'];
- $cond_stop = $cond_stop_hour.':'.$cond_stop_minute;
- }
- else {
- unset($cond_stop);
- }
-
- $cond_value = $cond_start.(($cond_stop != '') ? '-'.$cond_stop : null);
- }
- //handle all other variables
- else {
- if ($cond_start != '') {
- $cond_value = $cond_start;
- if ($scope == 'range' && $cond_stop != '') {
- $range_indicator = ($cond_var == 'date-time') ? '~' : '-';
- $cond_value .= $range_indicator.$cond_stop;
- }
- }
- }
-
- //add condition to query string
- $dialplan_detail_order += 10;
- $sql .= ", ( ";
- $sql .= "'".$domain_uuid."', ";
- $sql .= "'".$dialplan_uuid."', ";
- $sql .= "'".uuid()."', ";
- $sql .= "'condition', ";
- $sql .= "'".$cond_var."', ";
- $sql .= "'".$cond_value."', ";
- $sql .= "'never', ";
- $sql .= "null, ";
- $sql .= "'".$dialplan_detail_group."', ";
- $sql .= "'".$dialplan_detail_order."' ";
- $sql .= ") ";
+ //remove invalid conditions and values by checking conditions
+ foreach ($_REQUEST['variable'] as $group_id => $conditions) {
+ foreach ($conditions as $condition_id => $condition_variable) {
+ if ($condition_variable == '' || $_REQUEST['value'][$group_id][$condition_id] == '') {
+ unset($_REQUEST['variable'][$group_id][$condition_id]);
+ unset($_REQUEST['value'][$group_id][$condition_id]);
}
}
-
- //add condition action
- $dialplan_detail_order += 10;
- $sql .= ", ( ";
- $sql .= "'".$domain_uuid."', ";
- $sql .= "'".$dialplan_uuid."', ";
- $sql .= "'".uuid()."', ";
- $sql .= "'action', ";
- $sql .= "'set', ";
- $sql .= "'time_condition=true', ";
- $sql .= "null, ";
- $sql .= "'true', ";
- $sql .= "'".$dialplan_detail_group."', ";
- $sql .= "'".$dialplan_detail_order."' ";
- $sql .= ") ";
-
- //execute query
- $db->exec(check_sql($sql));
- unset($sql);
-
}
-
- //add to query for preset conditions (if any)
- if (sizeof($_REQUEST['preset']) > 0) {
-
- //build insert query for preset conditions
- $sql = "insert into v_dialplan_details ";
- $sql .= "( ";
- $sql .= "domain_uuid, ";
- $sql .= "dialplan_uuid, ";
- $sql .= "dialplan_detail_uuid, ";
- $sql .= "dialplan_detail_tag, ";
- $sql .= "dialplan_detail_type, ";
- $sql .= "dialplan_detail_data, ";
- $sql .= "dialplan_detail_break, ";
- $sql .= "dialplan_detail_inline, ";
- $sql .= "dialplan_detail_group, ";
- $sql .= "dialplan_detail_order ";
- $sql .= ") ";
- $sql .= "values ";
-
- foreach ($_REQUEST['preset'] as $index => $preset_number) {
-
- //increment group and order number
- $dialplan_detail_group += 10;
- $dialplan_detail_order = 0;
-
- //add destination number condition
- $dialplan_detail_order += 10;
- $sql .= ($index != 0) ? "," : null;
- $sql .= " ( ";
- $sql .= "'".$domain_uuid."', ";
- $sql .= "'".$dialplan_uuid."', ";
- $sql .= "'".uuid()."', ";
- $sql .= "'condition', ";
- $sql .= "'destination_number', ";
- $sql .= "'^".$dialplan_number."$', ";
- $sql .= "'never', ";
- $sql .= "null, ";
- $sql .= "'".$dialplan_detail_group."', ";
- $sql .= "'".$dialplan_detail_order."' ";
- $sql .= ") ";
-
- foreach ($available_presets[$preset_number] as $preset_name => $preset_variables) {
- foreach ($preset_variables as $cond_var => $cond_value) {
- //add preset condition to query string
- $dialplan_detail_order += 10;
- $sql .= ", ( ";
- $sql .= "'".$domain_uuid."', ";
- $sql .= "'".$dialplan_uuid."', ";
- $sql .= "'".uuid()."', ";
- $sql .= "'condition', ";
- $sql .= "'".$cond_var."', ";
- $sql .= "'".$cond_value."', ";
- $sql .= "'never', ";
- $sql .= "null, ";
- $sql .= "'".$dialplan_detail_group."', ";
- $sql .= "'".$dialplan_detail_order."' ";
- $sql .= ") ";
- }
+ //remove invalid conditions and values by checking start value
+ foreach ($_REQUEST['value'] as $group_id => $values) {
+ foreach ($values as $value_id => $value_range) {
+ if ($value_range['start'] == '') {
+ unset($_REQUEST['value'][$group_id][$value_id]);
+ unset($_REQUEST['variable'][$group_id][$condition_id]);
}
-
- //add condition action
- $dialplan_detail_order += 10;
- $sql .= ", ( ";
- $sql .= "'".$domain_uuid."', ";
- $sql .= "'".$dialplan_uuid."', ";
- $sql .= "'".uuid()."', ";
- $sql .= "'action', ";
- $sql .= "'set', ";
- $sql .= "'time_condition=true', ";
- $sql .= "null, ";
- $sql .= "'true', ";
- $sql .= "'".$dialplan_detail_group."', ";
- $sql .= "'".$dialplan_detail_order."' ";
- $sql .= ") ";
-
}
+ }
- //execute query
- $db->exec(check_sql($sql));
- unset($sql);
-
+ //remove any empty groups (where conditions no longer exist)
+ foreach ($_REQUEST['variable'] as $group_id => $conditions) {
+ if (sizeof($conditions) == 0) {
+ unset($_REQUEST['variable'][$group_id]);
+ unset($_REQUEST['dialplan_action'][$group_id]);
+ }
}
- //increment group number, reset order number
- $dialplan_detail_group = 999;
- $dialplan_detail_order = 0;
+ //process conditions
+ $conditions_exist = false;
- //add to query for main action and anti-action condition
-
- //build insert query for custom conditions
+ //begin insert query for custom and preset conditions
$sql = "insert into v_dialplan_details ";
$sql .= "( ";
$sql .= "domain_uuid, ";
@@ -402,53 +228,186 @@ require_once "resources/paging.php";
$sql .= ") ";
$sql .= "values ";
- //add destination number condition
- $dialplan_detail_order += 10;
- $sql .= "( ";
- $sql .= "'".$domain_uuid."', ";
- $sql .= "'".$dialplan_uuid."', ";
- $sql .= "'".uuid()."', ";
- $sql .= "'condition', ";
- $sql .= "'destination_number', ";
- $sql .= "'^".$dialplan_number."$', ";
- $sql .= "null, ";
- $sql .= "null, ";
- $sql .= "'".$dialplan_detail_group."', ";
- $sql .= "'".$dialplan_detail_order."' ";
- $sql .= ") ";
+ //add conditions
+ foreach ($_REQUEST['variable'] as $group_id => $conditions) {
- //add time condition met check
- $dialplan_detail_order += 10;
- $sql .= ", ( ";
- $sql .= "'".$domain_uuid."', ";
- $sql .= "'".$dialplan_uuid."', ";
- $sql .= "'".uuid()."', ";
- $sql .= "'condition', ";
- $sql .= "'".'${time_condition}'."', ";
- $sql .= "'^true$', ";
- $sql .= "null, ";
- $sql .= "null, ";
- $sql .= "'".$dialplan_detail_group."', ";
- $sql .= "'".$dialplan_detail_order."' ";
- $sql .= ") ";
+ $group_conditions_exist[$group_id] = false;
- //add main action
- $dialplan_detail_order += 10;
- $sql .= ", ( ";
- $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 .= ") ";
+ //determine if preset
+ $is_preset = (in_array($group_id, $_REQUEST['preset'])) ? true : false;
- //add anti-action (if defined)
+ //set group and order number
+ $dialplan_detail_group = $group_id;
+ $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'];
+
+ //handle time of day
+ if ($cond_var == 'time-of-day' && $cond_start['hour'] != '') {
+// //format condition start
+// if ($cond_start['notation'] == 'PM') {
+// $cond_start_hour = ($cond_start['hour'] != 12) ? $cond_start['hour'] += 12 : $cond_start['hour'];
+// }
+// else if ($cond_start['notation'] == 'AM') {
+// $cond_start_hour = ($cond_start['hour'] == 12) ? $cond_start['hour'] -= 12 : $cond_start['hour'];
+// }
+// $cond_start_hour = number_pad($cond_start_hour,2);
+// $cond_start_minute = $cond_start['minute'];
+// $cond_start = $cond_start_hour.':'.$cond_start_minute;
+
+// //format condition stop
+// if ($cond_start != '' && $scope == 'range') {
+// if ($cond_stop['notation'] == 'PM') {
+// $cond_stop_hour = ($cond_stop['hour'] != 12) ? $cond_stop['hour'] += 12 : $cond_stop['hour'];
+// }
+// else if ($cond_stop['notation'] == 'AM') {
+// $cond_stop_hour = ($cond_stop['hour'] == 12) ? $cond_stop['hour'] -= 12 : $cond_stop['hour'];
+// }
+// $cond_stop_hour = number_pad($cond_stop_hour,2);
+// $cond_stop_minute = $cond_stop['minute'];
+// $cond_stop = $cond_stop_hour.':'.$cond_stop_minute;
+// }
+// else {
+// unset($cond_stop);
+// }
+
+// $cond_value = $cond_start.(($cond_stop != '') ? '-'.$cond_stop : null);
+ }
+
+ //handle all other variables
+ else {
+ $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) ? ", ( " : "( ";
+ $sql .= "'".$domain_uuid."', ";
+ $sql .= "'".$dialplan_uuid."', ";
+ $sql .= "'".uuid()."', ";
+ $sql .= "'condition', ";
+ $sql .= "'destination_number', ";
+ $sql .= "'^".$dialplan_number."$', ";
+ $sql .= "'never', ";
+ $sql .= "null, ";
+ $sql .= "'".$dialplan_detail_group."', ";
+ $sql .= "'".$dialplan_detail_order."' ";
+ $sql .= ") ";
+ }
+
+ //add condition to query string
+ $dialplan_detail_order += 10;
+ $sql .= ", ( ";
+ $sql .= "'".$domain_uuid."', ";
+ $sql .= "'".$dialplan_uuid."', ";
+ $sql .= "'".uuid()."', ";
+ $sql .= "'condition', ";
+ $sql .= "'".$cond_var."', ";
+ $sql .= "'".$cond_value."', ";
+ $sql .= "'never', ";
+ $sql .= "null, ";
+ $sql .= "'".$dialplan_detail_group."', ";
+ $sql .= "'".$dialplan_detail_order."' ";
+ $sql .= ") ";
+
+ $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) {
+ $dialplan_action = check_str($_REQUEST['default_preset_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) {
+ foreach ($available_presets[$preset_number] as $available_preset_name => $meh) {
+ $dialplan_detail_order += 10;
+ $sql .= ", ( ";
+ $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
+ $dialplan_action_array = explode(":", $dialplan_action);
+ $dialplan_action_app = array_shift($dialplan_action_array);
+ $dialplan_action_data = join(':', $dialplan_action_array);
+
+ //add group action to query
+ $dialplan_detail_order += 10;
+ $sql .= ", ( ";
+ $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 .= ") ";
+ }
+
+ }
+
+ } //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 .= ", ( ";
+ $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 .= ", ( ";
$sql .= "'".$domain_uuid."', ";
@@ -462,13 +421,14 @@ require_once "resources/paging.php";
$sql .= "'".$dialplan_detail_group."', ";
$sql .= "'".$dialplan_detail_order."' ";
$sql .= ") ";
+
}
- //execute query
- $db->exec(check_sql($sql));
- unset($sql);
-
-
+ //execute query
+ if ($conditions_exist) {
+ $db->exec(check_sql($sql));
+ unset($sql);
+ }
//commit the atomic transaction
$count = $db->exec("COMMIT;"); //returns affected rows
@@ -528,7 +488,7 @@ require_once "resources/paging.php";
$sql .= " ) ";
$sql .= " or ( ";
$sql .= " dialplan_detail_tag = 'action' ";
- $sql .= " and dialplan_detail_group = '999' ";
+ $sql .= " and dialplan_detail_data not like 'preset=%' ";
$sql .= " ) ";
$sql .= " or ( ";
$sql .= " dialplan_detail_tag = 'anti-action' ";
@@ -548,7 +508,7 @@ require_once "resources/paging.php";
foreach ($result as $row) {
switch ($row['dialplan_detail_tag']) {
case 'condition': $current_conditions[$row['dialplan_detail_group']][$row['dialplan_detail_type']] = $row['dialplan_detail_data']; break;
- case 'action': $dialplan_action = $row['dialplan_detail_type'].':'.$row['dialplan_detail_data']; break;
+ case 'action': $dialplan_actions[$row['dialplan_detail_group']] = $row['dialplan_detail_type'].':'.$row['dialplan_detail_data']; break;
case 'anti-action': $dialplan_anti_action = $row['dialplan_detail_type'].':'.$row['dialplan_detail_data']; break;
}
}
@@ -558,84 +518,220 @@ require_once "resources/paging.php";
foreach ($available_presets as $preset_number => $preset) {
foreach ($preset as $preset_name => $preset_variables) {
//loop through each condition group
- foreach ($current_conditions as $group_number => $condition_variables) {
- //compare variable count
- if (sizeof($preset_variables) == sizeof($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 variables match, then condition is a preset
- if ($matches == sizeof($preset_variables)) {
- $current_presets[] = $preset_number;
- //drop group from array of current conditions
- unset($current_conditions[$group_number]);
- }
+ 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;
}
}
}
}
-
- //load remaining conditions as custom conditions
- $c = 0;
- foreach ($current_conditions as $conditions) {
- foreach ($conditions as $condition_variable => $condition_value) {
- $custom_conditions[$c]['var'] = $condition_variable;
- $custom_conditions[$c]['val'] = $condition_value;
- $c++;
- }
- }
- unset($current_conditions);
-
-
}
+
?>
\n";
echo " ".$text['description-time-conditions']."\n";
echo " \n";
echo "
| ".$text['label-condition_parameter']." | \n"; -echo "".$text['label-condition_scope']." | \n"; -echo "".$text['label-condition_values']." | \n"; -echo "\n"; -echo " | ||||||||||
| \n"; + echo " ".$text['label-custom']; + echo " | \n"; + echo "\n";
+ echo "
"; + echo " ".$text['description-conditions']; + echo " | \n";
+ echo "||||||||||||
| \n"; - echo " \n"; - echo " | \n"; - - //specific or range - $range_indicator = ($custom_conditions[$c]['var'] == 'date-time') ? '~' : '-'; - $detail_data = explode($range_indicator, $custom_conditions[$c]['val']); - echo "\n"; - echo " \n"; - echo " | \n"; - - echo "\n"; - - //variables and values - foreach ($time_condition_vars as $var_name => $var_label) { - switch ($var_name) { - case "minute-of-day" : - echo "\n"; - echo " \n"; - echo " \n"; - echo " ~ \n"; - echo " \n"; - echo " \n"; - echo "\n"; - break; - case "time-of-day" : - //split out hours and minutes, determine am/pm value, then adjust hours accordingly - if ($custom_conditions[$c]['var'] == $var_name && $detail_data[0] != '') { - $detail_data_tmp = explode(':', $detail_data[0]); - $detail_data_tmp[0] = (int) $detail_data_tmp[0]; - if ($detail_data_tmp[0] != 0) { - if ($detail_data_tmp[0] >= 12) { - $detail_data['start_hour'] = ($detail_data_tmp[0] > 12) ? $detail_data_tmp[0] - 12 : $detail_data_tmp[0]; - $detail_data['start_notation'] = 'PM'; - } - else { - $detail_data['start_hour'] = $detail_data_tmp[0]; - $detail_data['start_notation'] = 'AM'; - } - } - else { - $detail_data['start_hour'] = '12'; - $detail_data['start_notation'] = 'AM'; - } - $detail_data['start_minute'] = (int) $detail_data_tmp[1]; - unset($detail_data_tmp); +$largest_group_id = 0; +if ($action == 'update') { + foreach ($current_conditions as $group_id => $conditions) { + if (is_array($current_presets) && !in_array($group_id, $current_presets)) { + add_custom_condition($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); + echo ""; + } } + //used to determine largest custom group id in use + $largest_group_id = ($group_id > $largest_group_id) ? $group_id : $largest_group_id; } +} - echo " | \n"; - echo "|||||||||||
| \n"; echo " ".$text['label-presets']."\n"; echo " | \n"; echo "\n";
-echo "
\n"; +echo "
"; echo " ".$text['description-presets']." \n"; echo " | \n";
echo "||||||||||||
| \n"; -echo " ".$text['label-action']."\n"; -echo " | \n"; -echo "\n"; -switch_select_destination("dialplan", $dialplan_action, "dialplan_action", $dialplan_action, '', ''); -echo " | \n"; -echo "||||||||||||
| \n"; -echo " ".$text['label-action-alternate']."\n"; +echo " ".$text['label-alternate-destination']."\n"; echo " | \n"; echo "\n"; -switch_select_destination("dialplan", $dialplan_anti_action, "dialplan_anti_action", $dialplan_anti_action, '', ''); +switch_select_destination("dialplan", $dialplan_anti_action, "dialplan_anti_action", $dialplan_anti_action, 'width: 300px;', ''); echo " \n"; echo " | \n"; echo "\n"; echo " ".$text['label-enabled']."\n"; echo " | \n"; echo "\n";
-echo " \n";
+echo "\n";
echo " \n"; echo " | \n";
echo "\n";
echo "||||||||||
| \n"; -echo " ".$text['label-description']."\n"; +echo " ".$text['label-description']."\n"; echo " | \n"; echo "\n";
-echo " \n";
+echo " \n";
echo " \n"; echo " | \n";
echo "||||||||||||