Browse Source

Dialplan Tools - List: Updates for PHP 8.1

fusionate 2 years ago
parent
commit
cc8de6f205
1 changed files with 30 additions and 29 deletions
  1. 30 29
      dialplan_tools.php

+ 30 - 29
dialplan_tools.php

@@ -1,14 +1,14 @@
 <?php
 <?php
 /*
 /*
-	Copyright (c) 2019-2022 Mark J Crane <[email protected]>
-	
+	Copyright (c) 2019-2023 Mark J Crane <[email protected]>
+
 	Redistribution and use in source and binary forms, with or without
 	Redistribution and use in source and binary forms, with or without
 	modification, are permitted provided that the following conditions
 	modification, are permitted provided that the following conditions
 	are met:
 	are met:
 
 
 		1. Redistributions of source code must retain the above copyright
 		1. Redistributions of source code must retain the above copyright
 		notice, this list of conditions and the following disclaimer.
 		notice, this list of conditions and the following disclaimer.
-	
+
 		2. Redistributions in binary form must reproduce the above copyright
 		2. Redistributions in binary form must reproduce the above copyright
 		notice, this list of conditions and the following disclaimer in the
 		notice, this list of conditions and the following disclaimer in the
 		documentation and/or other materials provided with the distribution.
 		documentation and/or other materials provided with the distribution.
@@ -49,14 +49,14 @@
 	$text = $language->get();
 	$text = $language->get();
 
 
 //get the http post data
 //get the http post data
-	if (is_array($_POST['dialplan_tools'])) {
+	if (!empty($_POST['dialplan_tools']) && is_array($_POST['dialplan_tools'])) {
 		$action = $_POST['action'];
 		$action = $_POST['action'];
-		$search = $_POST['search'];
+		$search = $_POST['search'] ?? null;
 		$dialplan_tools = $_POST['dialplan_tools'];
 		$dialplan_tools = $_POST['dialplan_tools'];
 	}
 	}
 
 
 //process the http post data by action
 //process the http post data by action
-	if ($action != '' && is_array($dialplan_tools) && @sizeof($dialplan_tools) != 0) {
+	if (!empty($action) && is_array($dialplan_tools) && @sizeof($dialplan_tools) != 0) {
 
 
 		//validate the token
 		//validate the token
 		$token = new token;
 		$token = new token;
@@ -67,10 +67,11 @@
 		}
 		}
 
 
 		//prepare the array
 		//prepare the array
-		foreach($dialplan_tools as $row) {
-			$array['dialplan_tools'][$x]['checked'] = $row['checked'];
+		$x = 0;
+		foreach ($dialplan_tools as $row) {
+			$array['dialplan_tools'][$x]['checked'] = $row['checked'] ?? null;
 			$array['dialplan_tools'][$x]['dialplan_tool_uuid'] = $row['dialplan_tool_uuid'];
 			$array['dialplan_tools'][$x]['dialplan_tool_uuid'] = $row['dialplan_tool_uuid'];
-			$array['dialplan_tools'][$x]['enabled'] = $row['enabled'];
+			$array['dialplan_tools'][$x]['enabled'] = $row['enabled'] ?? null;
 			$x++;
 			$x++;
 		}
 		}
 
 
@@ -104,8 +105,8 @@
 	}
 	}
 
 
 //get order and order by
 //get order and order by
-	$order_by = $_GET["order_by"];
-	$order = $_GET["order"];
+	$order_by = $_GET["order_by"] ?? null;
+	$order = $_GET["order"] ?? null;
 
 
 //add the search
 //add the search
 	if (isset($_GET["search"])) {
 	if (isset($_GET["search"])) {
@@ -132,14 +133,14 @@
 		$parameters['search'] = '%'.$search.'%';
 		$parameters['search'] = '%'.$search.'%';
 	}
 	}
 	$database = new database;
 	$database = new database;
-	$num_rows = $database->select($sql, $parameters, 'column');
+	$num_rows = $database->select($sql, $parameters ?? null, 'column');
 	unset($sql, $parameters);
 	unset($sql, $parameters);
 
 
 //prepare to page the results
 //prepare to page the results
 	$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
 	$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
-	$param = $search ? "&search=".$search : null;
-	$param = ($_GET['show'] == 'all' && permission_exists('dialplan_tool_all')) ? "&show=all" : null;
-	$page = is_numeric($_GET['page']) ? $_GET['page'] : 0;
+	$param = !empty($search) ? "&search=".$search : null;
+	$param = !empty($_GET['show']) && $_GET['show'] == 'all' && permission_exists('dialplan_tool_all') ? "&show=all" : null;
+	$page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 0;
 	list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
 	list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
 	list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
 	list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
 	$offset = $rows_per_page * $page;
 	$offset = $rows_per_page * $page;
@@ -174,7 +175,7 @@
 	$sql .= order_by($order_by, $order, 'name', 'asc');
 	$sql .= order_by($order_by, $order, 'name', 'asc');
 	$sql .= limit_offset($rows_per_page, $offset);
 	$sql .= limit_offset($rows_per_page, $offset);
 	$database = new database;
 	$database = new database;
-	$dialplan_tools = $database->select($sql, $parameters, 'all');
+	$dialplan_tools = $database->select($sql, $parameters ?? null, 'all');
 	unset($sql, $parameters);
 	unset($sql, $parameters);
 
 
 //create token
 //create token
@@ -203,16 +204,16 @@
 	}
 	}
 	echo 		"<form id='form_search' class='inline' method='get'>\n";
 	echo 		"<form id='form_search' class='inline' method='get'>\n";
 	if (permission_exists('dialplan_tool_all')) {
 	if (permission_exists('dialplan_tool_all')) {
-		if ($_GET['show'] == 'all') {
+		if (!empty($_GET['show']) && $_GET['show'] == 'all') {
 			echo "		<input type='hidden' name='show' value='all'>\n";
 			echo "		<input type='hidden' name='show' value='all'>\n";
 		}
 		}
 		else {
 		else {
 			echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
 			echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
 		}
 		}
 	}
 	}
-	echo 		"<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
-	echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]);
-	echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'dialplan_tools.php','style'=>($search == '' ? 'display: none;' : null)]);
+	echo 		"<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search ?? null)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
+	echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>(!empty($search) ? 'display: none;' : null)]);
+	echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'dialplan_tools.php','style'=>(!empty($search) ? 'display: none;' : null)]);
 	if ($paging_controls_mini != '') {
 	if ($paging_controls_mini != '') {
 		echo 	"<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
 		echo 	"<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
 	}
 	}
@@ -236,16 +237,16 @@
 
 
 	echo "<form id='form_list' method='post'>\n";
 	echo "<form id='form_list' method='post'>\n";
 	echo "<input type='hidden' id='action' name='action' value=''>\n";
 	echo "<input type='hidden' id='action' name='action' value=''>\n";
-	echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
+	echo "<input type='hidden' name='search' value=\"".escape($search ?? null)."\">\n";
 
 
 	echo "<table class='list'>\n";
 	echo "<table class='list'>\n";
 	echo "<tr class='list-header'>\n";
 	echo "<tr class='list-header'>\n";
 	if (permission_exists('dialplan_tool_add') || permission_exists('dialplan_tool_edit') || permission_exists('dialplan_tool_delete')) {
 	if (permission_exists('dialplan_tool_add') || permission_exists('dialplan_tool_edit') || permission_exists('dialplan_tool_delete')) {
 		echo "	<th class='checkbox'>\n";
 		echo "	<th class='checkbox'>\n";
-		echo "		<input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".($dialplan_tools ?: "style='visibility: hidden;'").">\n";
+		echo "		<input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(empty($dialplan_tools) ? "style='visibility: hidden;'" : null).">\n";
 		echo "	</th>\n";
 		echo "	</th>\n";
 	}
 	}
-	if ($_GET['show'] == 'all' && permission_exists('dialplan_tool_all')) {
+	if (!empty($_GET['show']) && $_GET['show'] == 'all' && permission_exists('dialplan_tool_all')) {
 		echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
 		echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
 	}
 	}
 	echo th_order_by('name', $text['label-name'], $order_by, $order);
 	echo th_order_by('name', $text['label-name'], $order_by, $order);
@@ -253,7 +254,7 @@
 	echo th_order_by('data', $text['label-data'], $order_by, $order);
 	echo th_order_by('data', $text['label-data'], $order_by, $order);
 	echo th_order_by('enabled', $text['label-enabled'], $order_by, $order, null, "class='center'");
 	echo th_order_by('enabled', $text['label-enabled'], $order_by, $order, null, "class='center'");
 	echo th_order_by('description', $text['label-description'], $order_by, $order);
 	echo th_order_by('description', $text['label-description'], $order_by, $order);
-	if (permission_exists('dialplan_tool_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
+	if (permission_exists('dialplan_tool_edit') && !empty($_SESSION['theme']['list_row_edit_button']['boolean']) && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
 		echo "	<td class='action-button'>&nbsp;</td>\n";
 		echo "	<td class='action-button'>&nbsp;</td>\n";
 	}
 	}
 	echo "</tr>\n";
 	echo "</tr>\n";
@@ -271,7 +272,7 @@
 				echo "		<input type='hidden' name='dialplan_tools[$x][dialplan_tool_uuid]' value='".escape($row['dialplan_tool_uuid'])."' />\n";
 				echo "		<input type='hidden' name='dialplan_tools[$x][dialplan_tool_uuid]' value='".escape($row['dialplan_tool_uuid'])."' />\n";
 				echo "	</td>\n";
 				echo "	</td>\n";
 			}
 			}
-			if ($_GET['show'] == 'all' && permission_exists('dialplan_tool_all')) {
+			if (!empty($_GET['show']) && $_GET['show'] == 'all' && permission_exists('dialplan_tool_all')) {
 				echo "	<td>".(isset($row['domain_name']) ? escape($row['domain_name']) : $text['label-global'])."</td>\n";
 				echo "	<td>".(isset($row['domain_name']) ? escape($row['domain_name']) : $text['label-global'])."</td>\n";
 			}
 			}
 			echo "	<td>\n";
 			echo "	<td>\n";
@@ -286,16 +287,16 @@
 			echo "	<td>".escape($row['data'])."</td>\n";
 			echo "	<td>".escape($row['data'])."</td>\n";
 			if (permission_exists('dialplan_tool_edit')) {
 			if (permission_exists('dialplan_tool_edit')) {
 				echo "	<td class='no-link center'>\n";
 				echo "	<td class='no-link center'>\n";
-				echo "		<input type='hidden' name='number_translations[$x][enabled]' value='".escape($row['enabled'])."' />\n";
-				echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
+				echo "		<input type='hidden' name='dialplan_tools[$x][enabled]' value='".escape($row['enabled'] ?? 'false')."' />\n";
+				echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.($row['enabled'] ?? 'false')],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
 			}
 			}
 			else {
 			else {
 				echo "	<td class='center'>\n";
 				echo "	<td class='center'>\n";
 				echo $text['label-'.$row['enabled']];
 				echo $text['label-'.$row['enabled']];
 			}
 			}
 			echo "	</td>\n";
 			echo "	</td>\n";
-			echo "	<td>".escape($row['description'])."</td>\n";
-			if (permission_exists('dialplan_tool_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
+			echo "	<td class='description overflow hide-sm-dn'>".escape($row['description'])."</td>\n";
+			if (permission_exists('dialplan_tool_edit') && !empty($_SESSION['theme']['list_row_edit_button']['boolean']) && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
 				echo "	<td class='action-button'>\n";
 				echo "	<td class='action-button'>\n";
 				echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
 				echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
 				echo "	</td>\n";
 				echo "	</td>\n";