From 7276160030cd506cbf2f24ebe7c11623f3b0e34b Mon Sep 17 00:00:00 2001 From: fusionate Date: Wed, 24 May 2023 00:28:55 +0000 Subject: [PATCH] Time Conditions - Edit: Updates for PHP 8.1 --- app/time_conditions/time_condition_edit.php | 54 ++++++++++----------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/app/time_conditions/time_condition_edit.php b/app/time_conditions/time_condition_edit.php index 41e0201dcb..0b2649273b 100644 --- a/app/time_conditions/time_condition_edit.php +++ b/app/time_conditions/time_condition_edit.php @@ -62,7 +62,7 @@ unset($preset_region); //set the action as an add or an update - if (is_uuid($_REQUEST["id"])) { + if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { $action = "update"; $dialplan_uuid = $_REQUEST["id"]; } @@ -84,7 +84,7 @@ if (permission_exists('time_condition_context')) { $dialplan_context = $_POST["dialplan_context"]; } - $dialplan_enabled = $_POST["dialplan_enabled"] ?: 'false'; + $dialplan_enabled = $_POST["dialplan_enabled"] ?? 'false'; $dialplan_description = $_POST["dialplan_description"]; if (!permission_exists('time_condition_domain')) { @@ -218,7 +218,7 @@ //remove presets not checked, restructure variable array if (is_array($_REQUEST['variable']['preset'])) { foreach ($_REQUEST['variable']['preset'] as $group_id => $conditions) { - if (!is_array($_REQUEST['preset']) || !in_array($group_id, $_REQUEST['preset'])) { + if (empty($_REQUEST['preset']) || !is_array($_REQUEST['preset']) || !in_array($group_id, $_REQUEST['preset'])) { unset($_REQUEST['variable']['preset'][$group_id]); unset($_REQUEST['value'][$group_id]); unset($_REQUEST['dialplan_action'][$group_id]); @@ -275,8 +275,8 @@ if (is_array($_REQUEST['variable'])) { foreach ($_REQUEST['variable'] as $group_id => $meh) { if ( - (is_array($_REQUEST['preset']) && in_array($group_id, $_REQUEST['preset']) && $_REQUEST['dialplan_action'][$group_id] == '' && $_REQUEST['default_preset_action'] == '' && $_REQUEST['dialplan_anti_action'] == '') || - ((!is_array($_REQUEST['preset']) || !in_array($group_id, $_REQUEST['preset'])) && $_REQUEST['dialplan_action'][$group_id] == '') + (!empty($_REQUEST['preset']) && is_array($_REQUEST['preset']) && in_array($group_id, $_REQUEST['preset']) && $_REQUEST['dialplan_action'][$group_id] == '' && $_REQUEST['default_preset_action'] == '' && $_REQUEST['dialplan_anti_action'] == '') || + ((empty($_REQUEST['preset']) || !is_array($_REQUEST['preset']) || !in_array($group_id, $_REQUEST['preset'])) && $_REQUEST['dialplan_action'][$group_id] == '') ) { unset($_REQUEST['variable'][$group_id]); unset($_REQUEST['value'][$group_id]); @@ -298,10 +298,10 @@ $group_conditions_exist[$group_id] = false; //determine if preset - $is_preset = (is_array($_REQUEST['preset']) && in_array($group_id, $_REQUEST['preset'])) ? true : false; + $is_preset = !empty($_REQUEST['preset']) && is_array($_REQUEST['preset']) && in_array($group_id, $_REQUEST['preset']) ? true : false; //set group and order number - $dialplan_detail_group_user = $_POST["group_$group_id"]; + $dialplan_detail_group_user = $_POST['group_'.$group_id] ?? null; if ($dialplan_detail_group_user != '') { $dialplan_detail_group = $dialplan_detail_group_user; } @@ -524,13 +524,13 @@ } //redirect the browser - header("Location: time_condition_edit.php?id=".$dialplan_uuid.($app_uuid != '' ? "&app_uuid=".$app_uuid : null)); + header("Location: time_condition_edit.php?id=".$dialplan_uuid.(!empty($app_uuid) && is_uuid($app_uuid) ? "&app_uuid=".$app_uuid : null)); exit; } //get existing data to pre-populate form - if (is_uuid($dialplan_uuid) && $_POST["persistformvar"] != "true") { + if (!empty($dialplan_uuid) && is_uuid($dialplan_uuid) && (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true")) { //get main dialplan entry $sql = "select * from v_dialplans "; @@ -595,7 +595,7 @@ if ($row['dialplan_detail_group'] > $dialplan_detail_group_max) { $dialplan_detail_group_max = $row['dialplan_detail_group']; } } //reorder any invalid preset dialplan detail groups - if (is_array($invalid_presets_dialplan_detail_groups) && @sizeof($invalid_presets_dialplan_detail_groups) != 0) { + if (isset($invalid_presets_dialplan_detail_groups) && is_array($invalid_presets_dialplan_detail_groups) && @sizeof($invalid_presets_dialplan_detail_groups) != 0) { foreach ($dialplan_details as $i => $row) { if (in_array($row['dialplan_detail_group'], $invalid_presets_dialplan_detail_groups)) { $dialplan_details[$i]['dialplan_detail_group'] = $dialplan_detail_group_max + 5; @@ -609,12 +609,12 @@ $dialplan_anti_action = $row['dialplan_detail_type'].($row['dialplan_detail_data'] != '' || $row['dialplan_detail_type'] == 'hangup' ? ':'.$row['dialplan_detail_data'] : null); } else { - $dialplan_detail_group = $dialplan_detail_group_preset[$row['dialplan_detail_group']] ?: $row['dialplan_detail_group']; + $dialplan_detail_group = $dialplan_detail_group_preset[$row['dialplan_detail_group']] ?? $row['dialplan_detail_group']; $dialplan_actions[$dialplan_detail_group] = $row['dialplan_detail_type'].($row['dialplan_detail_data'] != '' || $row['dialplan_detail_type'] == 'hangup' ? ':'.$row['dialplan_detail_data'] : null); } } else if ($row['dialplan_detail_tag'] == 'condition') { - $dialplan_detail_group = $dialplan_detail_group_preset[$row['dialplan_detail_group']] ?: $row['dialplan_detail_group']; + $dialplan_detail_group = $dialplan_detail_group_preset[$row['dialplan_detail_group']] ?? $row['dialplan_detail_group']; $current_conditions[$dialplan_detail_group][$row['dialplan_detail_type']] = $row['dialplan_detail_data']; } } @@ -632,7 +632,7 @@ 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 (isset($preset_variables[$condition_variable_name]) && $preset_variables[$condition_variable_name] == $condition_variable_value) { $matches++; } } } //if all preset variables found, then condition is a preset @@ -710,7 +710,7 @@ $time_condition_vars["date-time"] = $text['label-date-and-time']; if (is_array($time_condition_vars)) { foreach ($time_condition_vars as $var_name => $var_label) { - echo "html += \" \";"; + echo "html += \" \";"; } } ?> @@ -963,7 +963,7 @@ echo "\n"; echo " ".$text['label-name']."\n"; echo "\n"; echo "\n"; -echo " \n"; +echo " \n"; echo "
\n"; echo " ".$text['description-name']."\n"; echo "
\n"; @@ -976,7 +976,7 @@ echo "\n"; echo " ".$text['label-extension']."\n"; echo "\n"; echo "\n"; -echo " \n"; +echo " \n"; echo "
\n"; echo " ".$text['description-extension']."
\n"; echo "\n"; @@ -1024,14 +1024,14 @@ 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))) { + if (empty($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]; + $cond_val_stop = $tmp[1] ?? null; unset($tmp); //convert minute-of-day to time-of-day values @@ -1093,7 +1093,7 @@ if ($action == 'update') { foreach ($available_presets as $preset_number => $preset) { if (is_array($preset)) { foreach ($preset as $preset_name => $preset_variables) { - $checked = is_array($current_presets) && in_array($preset_name, $current_presets) ? "checked='checked'" : null; + $checked = !empty($current_presets) && is_array($current_presets) && in_array($preset_name, $current_presets) ? "checked='checked'" : null; $preset_group_id = $preset_number * 5 + 100; if (!empty($text['label-preset_'.$preset_name])) { $label_preset_name = $text['label-preset_'.$preset_name]; @@ -1115,21 +1115,21 @@ if ($action == 'update') { echo " "; echo " "; echo " "; - echo $destination->select('dialplan', 'dialplan_action['.$preset_group_id.']', $dialplan_actions[$preset_name]); + echo $destination->select('dialplan', 'dialplan_action['.$preset_group_id.']', $dialplan_actions[$preset_name] ?? null); echo " "; echo " "; echo " "; echo "
"; echo ""; - if ($action == 'update' && is_array($current_presets) && in_array($preset_name, $current_presets)) { + if (!empty($action) && $action == 'update' && !empty($current_presets) && is_array($current_presets) && in_array($preset_name, $current_presets)) { //add (potentially customized) preset conditions and populate if (is_array($current_conditions[$preset_name])) { foreach ($current_conditions[$preset_name] 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]; + $cond_val_stop = $tmp[1] ?? null; unset($tmp); //convert minute-of-day to time-of-day values @@ -1166,7 +1166,7 @@ if ($action == 'update') { $range_indicator = ($preset_variable == 'date-time') ? '~' : '-'; $tmp = explode($range_indicator, $preset_value); $preset_value_start = $tmp[0]; - $preset_value_stop = $tmp[1]; + $preset_value_stop = $tmp[1] ?? null; unset($tmp); echo "