Time Conditions - Edit: Updates for PHP 8.1

This commit is contained in:
fusionate 2023-05-24 00:28:55 +00:00
parent 66a0d61ad6
commit 7276160030
No known key found for this signature in database
1 changed files with 27 additions and 27 deletions

View File

@ -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 += \" <option value='".$var_name."' ".(($custom_conditions[$c]['var'] == $var_name) ? "selected='selected'" : null).">".$var_label."</option>\";";
echo "html += \" <option value='".$var_name."'>".$var_label."</option>\";";
}
}
?>
@ -963,7 +963,7 @@ echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap>\n";
echo " ".$text['label-name']."\n";
echo "</td>\n";
echo "<td width='70%' class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='dialplan_name' maxlength='255' value=\"".escape($dialplan_name)."\">\n";
echo " <input class='formfld' type='text' name='dialplan_name' maxlength='255' value=\"".escape($dialplan_name ?? null)."\">\n";
echo " <br />\n";
echo " ".$text['description-name']."\n";
echo "<br />\n";
@ -976,7 +976,7 @@ echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
echo " ".$text['label-extension']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='dialplan_number' id='dialplan_number' maxlength='255' value=\"".escape($dialplan_number)."\">\n";
echo " <input class='formfld' type='text' name='dialplan_number' id='dialplan_number' maxlength='255' value=\"".escape($dialplan_number ?? null)."\">\n";
echo " <br />\n";
echo " ".$text['description-extension']."<br />\n";
echo "</td>\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 " </tr>";
echo " <tr>";
echo " <td colspan='4' style='padding-top: 10px;'>";
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 " </td>";
echo " </tr>";
echo " </table>";
echo " <br />";
echo "</div>";
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 "<script>\n";
echo " condition_id = add_condition(".$preset_group_id.",'preset');\n";
@ -1190,7 +1190,7 @@ if ($action == 'update') {
echo " <td>";
echo button::create(['type'=>'button','label'=>$text['button-advanced'],'icon'=>'tools','onclick'=>"$(this).fadeOut(400, function() { $('#default_preset_destination').fadeIn(400); document.getElementById('default_preset_destination_description').innerHTML += '<br>".$text['description-presets_advanced']."'; });"]);
echo " <span id='default_preset_destination' style='display: none;'>";
echo $destination->select('dialplan', 'default_preset_action', $dialplan_action);
echo $destination->select('dialplan', 'default_preset_action', $dialplan_action ?? null);
echo " </span>";
echo " </td>";
echo " </tr>";
@ -1206,7 +1206,7 @@ if ($action == 'update') {
echo " ".$text['label-alternate-destination']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " ".$destination->select('dialplan', 'dialplan_anti_action', $dialplan_anti_action);
echo " ".$destination->select('dialplan', 'dialplan_anti_action', $dialplan_anti_action ?? null);
echo "</td>\n";
echo "</tr>\n";
@ -1293,7 +1293,7 @@ if ($action == 'update') {
echo " ".$text['label-description']."\n";
echo "</td>\n";
echo "<td colspan='4' class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='dialplan_description' maxlength='255' value=\"".escape($dialplan_description)."\">\n";
echo " <input class='formfld' type='text' name='dialplan_description' maxlength='255' value=\"".escape($dialplan_description ?? null)."\">\n";
echo "<br />\n";
echo "</td>\n";
echo "</tr>\n";
@ -1311,4 +1311,4 @@ if ($action == 'update') {
//include the footer
require_once "resources/footer.php";
?>
?>