소스 검색

Merge pull request #4 from fusionate/main

Dialplan Tools - Updates for PHP 8.1
FusionPBX 2 년 전
부모
커밋
f904affba6
2개의 변경된 파일48개의 추가작업 그리고 45개의 파일을 삭제
  1. 18 16
      dialplan_tool_edit.php
  2. 30 29
      dialplan_tools.php

+ 18 - 16
dialplan_tool_edit.php

@@ -1,16 +1,18 @@
 <?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
 	modification, are permitted provided that the following conditions
 	are met:
+
 		1. Redistributions of source code must retain the above copyright
 		notice, this list of conditions and the following disclaimer.
 	
 		2. Redistributions in binary form must reproduce the above copyright
 		notice, this list of conditions and the following disclaimer in the
 		documentation and/or other materials provided with the distribution.
+
 	THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
 	ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -46,7 +48,7 @@
 	$text = $language->get();
 
 //action add or update
-	if (is_uuid($_REQUEST["id"])) {
+	if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
 		$action = "update";
 		$dialplan_tool_uuid = $_REQUEST["id"];
 	}
@@ -55,7 +57,7 @@
 	}
 
 //get http post variables and set them to php variables
-	if (is_array($_POST)) {
+	if (!empty($_POST) && is_array($_POST)) {
 		$name = $_POST["name"];
 		$application = $_POST["application"];
 		$data = $_POST["data"];
@@ -64,7 +66,7 @@
 	}
 
 //process the user data and save it to the database
-	if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
+	if (!empty($_POST) && count($_POST) > 0 && (empty($_POST["persistformvar"]) || strlen($_POST["persistformvar"]) == 0)) {
 
 		//validate the token
 			$token = new token;
@@ -75,7 +77,7 @@
 			}
 
 		//process the http post data by submitted action
-			if ($_POST['action'] != '' && strlen($_POST['action']) > 0) {
+			if (!empty($_POST['action']) && strlen($_POST['action']) > 0) {
 
 				//prepare the array(s)
 				//send the array to the database class
@@ -114,7 +116,7 @@
 			//if (strlen($data) == 0) { $msg .= $text['message-required']." ".$text['label-data']."<br>\n"; }
 			if (strlen($enabled) == 0) { $msg .= $text['message-required']." ".$text['label-enabled']."<br>\n"; }
 			//if (strlen($description) == 0) { $msg .= $text['message-required']." ".$text['label-description']."<br>\n"; }
-			if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
+			if (!empty($msg) && strlen($msg) > 0 && (empty($_POST["persistformvar"]) || strlen($_POST["persistformvar"]) == 0)) {
 				require_once "resources/header.php";
 				require_once "resources/persist_form_var.php";
 				echo "<div align='center'>\n";
@@ -188,7 +190,7 @@
 	}
 
 //pre-populate the form
-	if (is_array($_GET) && $_POST["persistformvar"] != "true") {
+	if (!empty($_GET) && is_array($_GET) && (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true")) {
 		$sql = "select ";
 		$sql .= "domain_uuid, ";
 		$sql .= "dialplan_tool_uuid, ";
@@ -203,7 +205,7 @@
 		//$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
 		$parameters['dialplan_tool_uuid'] = $dialplan_tool_uuid;
 		$database = new database;
-		$row = $database->select($sql, $parameters, 'row');
+		$row = $database->select($sql, $parameters ?? null, 'row');
 		if (is_array($row) && @sizeof($row) != 0) {
 			$domain_uuid = $row["domain_uuid"];
 			$name = $row["name"];
@@ -225,7 +227,7 @@
 
 //show the content
 	echo "<form name='frm' id='frm' method='post' action=''>\n";
-	echo "<input class='formfld' type='hidden' name='dialplan_tool_uuid' value='".escape($dialplan_tool_uuid)."'>\n";
+	echo "<input class='formfld' type='hidden' name='dialplan_tool_uuid' value='".escape($dialplan_tool_uuid ?? '')."'>\n";
 
 	echo "<div class='action_bar' id='action_bar'>\n";
 	echo "	<div class='heading'><b>".$text['title-dialplan_tool']."</b></div>\n";
@@ -263,7 +265,7 @@
 	echo "	".$text['label-name']."\n";
 	echo "</td>\n";
 	echo "<td class='vtable' style='position: relative;' align='left'>\n";
-	echo "	<input class='formfld' type='text' name='name' maxlength='255' value='".escape($name)."'>\n";
+	echo "	<input class='formfld' type='text' name='name' maxlength='255' value='".escape($name ?? '')."'>\n";
 	echo "<br />\n";
 	echo $text['description-name']."\n";
 	echo "</td>\n";
@@ -274,8 +276,8 @@
 	echo "	".$text['label-application']."\n";
 	echo "</td>\n";
 	echo "<td class='vtable' style='position: relative;' align='left'>\n";
-	echo "	<select name='application' class='formfld' style='width: auto; ".$element['visibility']."' onchange='change_to_input(this);'>\n";
-	if (strlen($application) > 0) {
+	echo "	<select name='application' class='formfld' style='width: auto; ".($element['visibility'] ?? '')."' onchange='change_to_input(this);'>\n";
+	if (!empty($application) && strlen($application) > 0) {
 		echo "		<option value=\"".escape($application)."\" selected=\"selected\">".escape($application)."</option>\n";
 	}
 	else {
@@ -299,7 +301,7 @@
 	echo "	".$text['label-data']."\n";
 	echo "</td>\n";
 	echo "<td class='vtable' style='position: relative;' align='left'>\n";
-	echo "	<input class='formfld' type='text' name='data' maxlength='255' value='".escape($data)."'>\n";
+	echo "	<input class='formfld' type='text' name='data' maxlength='255' value='".escape($data ?? '')."'>\n";
 	echo "<br />\n";
 	echo $text['description-data']."\n";
 	echo "</td>\n";
@@ -341,13 +343,13 @@
 	echo "</td>\n";
 	echo "<td class='vtable' style='position: relative;' align='left'>\n";
 	echo "	<select class='formfld' name='enabled'>\n";
-	if ($enabled == "true") {
+	if (!empty($enabled) && $enabled == "true") {
 		echo "		<option value='true' selected='selected'>".$text['label-true']."</option>\n";
 	}
 	else {
 		echo "		<option value='true'>".$text['label-true']."</option>\n";
 	}
-	if ($enabled == "false") {
+	if (!empty($enabled) && $enabled == "false") {
 		echo "		<option value='false' selected='selected'>".$text['label-false']."</option>\n";
 	}
 	else {
@@ -364,7 +366,7 @@
 	echo "	".$text['label-description']."\n";
 	echo "</td>\n";
 	echo "<td class='vtable' style='position: relative;' align='left'>\n";
-	echo "	<input class='formfld' type='text' name='description' maxlength='255' value='".escape($description)."'>\n";
+	echo "	<input class='formfld' type='text' name='description' maxlength='255' value='".escape($description ?? '')."'>\n";
 	echo "<br />\n";
 	echo $text['description-description']."\n";
 	echo "</td>\n";

+ 30 - 29
dialplan_tools.php

@@ -1,14 +1,14 @@
 <?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
 	modification, are permitted provided that the following conditions
 	are met:
 
 		1. Redistributions of source code must retain the above copyright
 		notice, this list of conditions and the following disclaimer.
-	
+
 		2. Redistributions in binary form must reproduce the above copyright
 		notice, this list of conditions and the following disclaimer in the
 		documentation and/or other materials provided with the distribution.
@@ -49,14 +49,14 @@
 	$text = $language->get();
 
 //get the http post data
-	if (is_array($_POST['dialplan_tools'])) {
+	if (!empty($_POST['dialplan_tools']) && is_array($_POST['dialplan_tools'])) {
 		$action = $_POST['action'];
-		$search = $_POST['search'];
+		$search = $_POST['search'] ?? null;
 		$dialplan_tools = $_POST['dialplan_tools'];
 	}
 
 //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
 		$token = new token;
@@ -67,10 +67,11 @@
 		}
 
 		//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]['enabled'] = $row['enabled'];
+			$array['dialplan_tools'][$x]['enabled'] = $row['enabled'] ?? null;
 			$x++;
 		}
 
@@ -104,8 +105,8 @@
 	}
 
 //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
 	if (isset($_GET["search"])) {
@@ -132,14 +133,14 @@
 		$parameters['search'] = '%'.$search.'%';
 	}
 	$database = new database;
-	$num_rows = $database->select($sql, $parameters, 'column');
+	$num_rows = $database->select($sql, $parameters ?? null, 'column');
 	unset($sql, $parameters);
 
 //prepare to page the results
 	$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_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
 	$offset = $rows_per_page * $page;
@@ -174,7 +175,7 @@
 	$sql .= order_by($order_by, $order, 'name', 'asc');
 	$sql .= limit_offset($rows_per_page, $offset);
 	$database = new database;
-	$dialplan_tools = $database->select($sql, $parameters, 'all');
+	$dialplan_tools = $database->select($sql, $parameters ?? null, 'all');
 	unset($sql, $parameters);
 
 //create token
@@ -203,16 +204,16 @@
 	}
 	echo 		"<form id='form_search' class='inline' method='get'>\n";
 	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";
 		}
 		else {
 			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 != '') {
 		echo 	"<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
 	}
@@ -236,16 +237,16 @@
 
 	echo "<form id='form_list' method='post'>\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 "<tr class='list-header'>\n";
 	if (permission_exists('dialplan_tool_add') || permission_exists('dialplan_tool_edit') || permission_exists('dialplan_tool_delete')) {
 		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";
 	}
-	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('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('enabled', $text['label-enabled'], $order_by, $order, null, "class='center'");
 	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 "</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 "	</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>\n";
@@ -286,16 +287,16 @@
 			echo "	<td>".escape($row['data'])."</td>\n";
 			if (permission_exists('dialplan_tool_edit')) {
 				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 {
 				echo "	<td class='center'>\n";
 				echo $text['label-'.$row['enabled']];
 			}
 			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 button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
 				echo "	</td>\n";