Browse Source

Bulk Account Settings - Devices: Updates for PHP 8.1

fusionate 2 years ago
parent
commit
44f1b6df7b

+ 23 - 11
bulk_account_settings/app_languages.php

@@ -192,6 +192,18 @@ $text['description-enabled']['de-at'] = "Select the new enabled status for the s
 $text['description-enabled']['it-it'] = "Select the new enabled status for the selected extensions.";
 $text['description-enabled']['ru-ru'] = "Выберите новый статус для выбранных extensions.";
 
+$text['description-device_enabled']['en-us'] = "Select the new enabled status for the selected devices.";
+$text['description-device_enabled']['es-cl'] = "Select the new enabled status for the selected devices.";
+$text['description-device_enabled']['pt-pt'] = "Select the new enabled status for the selected devices.";
+$text['description-device_enabled']['fr-fr'] = "Select the new enabled status for the selected devices.";
+$text['description-device_enabled']['pt-br'] = "Select the new enabled status for the selected devices.";
+$text['description-device_enabled']['pl'] = "Select the new enabled status for the selected devices.";
+$text['description-device_enabled']['sv-se'] = "Select the new enabled status for the selected devices.";
+$text['description-device_enabled']['uk'] = "Select the new enabled status for the selected devices.";
+$text['description-device_enabled']['de-at'] = "Select the new enabled status for the selected devices.";
+$text['description-device_enabled']['it-it'] = "Select the new enabled status for the selected devices.";
+$text['description-device_enabled']['ru-ru'] = "Выберите новый статус для выбранных devices.";
+
 $text['description-directory_visible']['en-us'] = "Select whether to hide the name from the directory.";
 $text['description-directory_visible']['es-cl'] = "";
 $text['description-directory_visible']['pt-pt'] = "";
@@ -1009,17 +1021,17 @@ $text['label-device_description']['de-at'] = "Description";
 $text['label-device_description']['it-it'] = "Description";
 $text['label-device_description']['ru-ru'] = "Описание";
 
-$text['label-device_mac_address']['en-us'] = "MAC Address";
-$text['label-device_mac_address']['es-cl'] = "MAC Address";
-$text['label-device_mac_address']['pt-pt'] = "MAC Address";
-$text['label-device_mac_address']['fr-fr'] = "MAC Address";
-$text['label-device_mac_address']['pt-br'] = "MAC Address";
-$text['label-device_mac_address']['pl'] = "MAC Address";
-$text['label-device_mac_address']['sv-se'] = "MAC Address";
-$text['label-device_mac_address']['uk'] = "MAC Address";
-$text['label-device_mac_address']['de-at'] = "MAC Address";
-$text['label-device_mac_address']['it-it'] = "MAC Address";
-$text['label-device_mac_address']['ru-ru'] = "MAC адрес";
+$text['label-device_address']['en-us'] = "Address";
+$text['label-device_address']['es-cl'] = "Address";
+$text['label-device_address']['pt-pt'] = "Address";
+$text['label-device_address']['fr-fr'] = "Address";
+$text['label-device_address']['pt-br'] = "Address";
+$text['label-device_address']['pl'] = "Address";
+$text['label-device_address']['sv-se'] = "Address";
+$text['label-device_address']['uk'] = "Address";
+$text['label-device_address']['de-at'] = "Address";
+$text['label-device_address']['it-it'] = "Address";
+$text['label-device_address']['ru-ru'] = "адрес";
 
 $text['label-voicemail_file']['en-us'] = "Voicemail File";
 $text['label-voicemail_file']['es-cl'] = "Voicemail File";

+ 68 - 67
bulk_account_settings/bulk_account_settings_devices.php

@@ -44,19 +44,19 @@
 	$text = $language->get();
 
 //get the http values and set them as variables
-	$order_by = check_str($_GET["order_by"]);
-	$order = check_str($_GET["order"]);
-	$option_selected = check_str($_GET["option_selected"]);
+	$order_by = $_GET["order_by"] ?? null;
+	$order = $_GET["order"] ?? null;
+	$option_selected = $_GET["option_selected"] ?? null;
 	
 //	if (count($_POST)>0) {
-//		$option_selected = check_str($_POST["option_selected"]);
+//		$option_selected = $_POST["option_selected"];
 //	}
 
 //handle search term
-	$search = check_str($_GET["search"]);
-	if (strlen($search) > 0) {
+	$search = $_GET["search"] ?? null;
+	if (!empty($search)) {
 		$sql_mod = "and ( ";
-		$sql_mod .= "device_mac_address ILIKE '%".$search."%' ";
+		$sql_mod .= "device_address ILIKE '%".$search."%' ";
 		$sql_mod .= "or device_label ILIKE '%".$search."%' ";		
 		$sql_mod .= "or device_vendor ILIKE '%".$search."%' ";
 		$sql_mod .= "or device_model ILIKE '%".$search."%' ";
@@ -64,7 +64,7 @@
 		$sql_mod .= "or device_template ILIKE '%".$search."%' ";		
 		$sql_mod .= ") ";
 	}
-	if (strlen($order_by) < 1) {
+	if (empty($order_by)) {
 		$order_by = "device_label";
 		$order = "ASC";
 	}
@@ -72,7 +72,7 @@
 	$domain_uuid = $_SESSION['domain_uuid'];
 
 //get total device count from the database
-	$sql = "select count(*) as num_rows from v_devices where domain_uuid = '".$_SESSION['domain_uuid']."' ".$sql_mod." ";
+	$sql = "select count(*) as num_rows from v_devices where domain_uuid = '".$_SESSION['domain_uuid']."' ".($sql_mod ?? '')." ";
 	$prep_statement = $db->prepare($sql);
 	if ($prep_statement) {
 		$prep_statement->execute();
@@ -86,18 +86,17 @@
 
 //prepare to page the results
 	$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
-	$param = "&search=".$search."&option_selected=".$option_selected;
-	if (!isset($_GET['page'])) { $_GET['page'] = 0; }
-	$_GET['page'] = check_str($_GET['page']);
-	list($paging_controls_mini, $rows_per_page, $var_3) = paging($total_devices, $param, $rows_per_page, true); //top
-	list($paging_controls, $rows_per_page, $var_3) = paging($total_devices, $param, $rows_per_page); //bottom
-	$offset = $rows_per_page * $_GET['page'];
+	$param = (!empty($search) ? "&search=".$search : null).(!empty($option_selected) ? "&option_selected=".$option_selected : null);
+	$page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 0;
+	list($paging_controls, $rows_per_page) = paging($total_devices, $param, $rows_per_page);
+	list($paging_controls_mini, $rows_per_page) = paging($total_devices, $param, $rows_per_page, true);
+	$offset = $rows_per_page * $page;
 
 //get all the devices from the database
 	$sql = "SELECT \n";
 	$sql .= "d.device_uuid, \n";
 	$sql .= "d.device_label, \n";
-	$sql .= "d.device_mac_address, \n";
+	$sql .= "d.device_address, \n";
 	$sql .= "d.device_vendor, \n";
 	$sql .= "d.device_template, \n";
 	$sql .= "d.device_enabled, \n";
@@ -108,7 +107,7 @@
 	$sql .= ") as device_profile_name \n";
 	$sql .= "FROM v_devices as d \n";
 	$sql .= "WHERE domain_uuid = '".$_SESSION['domain_uuid']."' \n";
-	$sql .= $sql_mod; //add search mod from above
+	$sql .= $sql_mod ?? ''; //add search mod from above
 	$sql .= "ORDER BY ".$order_by." ".$order." \n";
 	$sql .= "limit $rows_per_page offset $offset ";
 	$database = new database;
@@ -117,26 +116,28 @@
 
 //lookup the lines
 	$x = 0;
-	foreach ($directory as $key => $row) {
-		$sql = "SELECT * \n";
-		$sql .= "FROM v_device_lines \n";
-		$sql .= "WHERE domain_uuid = '$domain_uuid' \n";
-		$sql .= "and device_uuid = '".$row['device_uuid']."' ";
-		$sql .= "and line_number = '1' ";
-		$database = new database;
-		$sqlview1 = $sql;
-		$result = $database->select($sql, 'all');
-		$directory[$key]['line_1_server_address'] = $result[0]['server_address'];
-		$directory[$key]['line_1_server_address_primary'] = $result[0]['server_address_primary'];
-		$directory[$key]['line_1_server_address_secondary'] = $result[0]['server_address_secondary'];
-		$directory[$key]['line_1_outbound_proxy_primary'] = $result[0]['outbound_proxy_primary'];
-		$directory[$key]['line_1_outbound_proxy_secondary'] = $result[0]['outbound_proxy_secondary'];
-		$directory[$key]['line_1_sip_port'] = $result[0]['sip_port'];
-		$directory[$key]['line_1_sip_transport'] = $result[0]['sip_transport'];
-		$directory[$key]['line_1_register_expires'] = $result[0]['register_expires'];
-
-		unset($result, $database);
-		$x++;
+	if (!empty($directory)) {
+		foreach ($directory as $key => $row) {
+			$sql = "SELECT * \n";
+			$sql .= "FROM v_device_lines \n";
+			$sql .= "WHERE domain_uuid = '$domain_uuid' \n";
+			$sql .= "and device_uuid = '".$row['device_uuid']."' ";
+			$sql .= "and line_number = '1' ";
+			$database = new database;
+			$sqlview1 = $sql;
+			$result = $database->select($sql, 'all');
+			$directory[$key]['line_1_server_address'] = $result[0]['server_address'];
+			$directory[$key]['line_1_server_address_primary'] = $result[0]['server_address_primary'];
+			$directory[$key]['line_1_server_address_secondary'] = $result[0]['server_address_secondary'];
+			$directory[$key]['line_1_outbound_proxy_primary'] = $result[0]['outbound_proxy_primary'];
+			$directory[$key]['line_1_outbound_proxy_secondary'] = $result[0]['outbound_proxy_secondary'];
+			$directory[$key]['line_1_sip_port'] = $result[0]['sip_port'];
+			$directory[$key]['line_1_sip_transport'] = $result[0]['sip_transport'];
+			$directory[$key]['line_1_register_expires'] = $result[0]['register_expires'];
+
+			unset($result, $database);
+			$x++;
+		}
 	}
 
 //additional includes
@@ -157,7 +158,7 @@
 //options list
 	echo "<form name='frm' method='get' id=option_selected>\n";
 	echo "    <select class='formfld' name='option_selected'  onchange=\"this.form.submit();\">\n";
-	echo "    <option value=''>".$text['label-devices_null']."</option>\n";
+	echo "    <option value=''></option>\n";
 //Enabled		
 	if ($option_selected == "device_enabled") {
 		echo "    <option value='device_enabled' selected='selected'>".$text['label-enabled']."</option>\n";
@@ -241,7 +242,7 @@
 	echo "    </select>\n";
 	echo "    </form>\n";
 	echo "<br />\n";
-	echo $text['description-device_settings_description']."\n";
+	echo ($text['description-device_settings_description'] ?? '')."\n";
 	echo "</td>\n";
 
 	echo "		<td align='right' width='100%' style='vertical-align: top;'>";
@@ -251,7 +252,7 @@
 	echo "				<input type='text' class='txt' style='width: 150px' name='search' id='search' value='".$search."'>";
 	echo "				<input type='hidden' class='txt' style='width: 150px' name='option_selected' id='option_selected' value='".$option_selected."'>";
 	echo "				<input type='submit' class='btn' name='submit' value='".$text['button-search']."'>";
-	if ($paging_controls_mini != '') {
+	if (!empty($paging_controls_mini)) {
 		echo 			"<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
 	}
 	echo "			</td>\n";
@@ -266,13 +267,13 @@
 	echo "</table>\n";
 	echo "<br />";
 
-	if (strlen($option_selected) > 0) {
+	if (!empty($option_selected)) {
 		echo "<form name='devices' method='post' action='bulk_account_settings_devices_update.php'>\n";
 		echo "<input class='formfld' type='hidden' name='option_selected' maxlength='255' value=\"".escape($option_selected)."\">\n";
 		echo "<table width='auto' border='0' cellpadding='0' cellspacing='0'>\n";
 		echo "<tr>\n";
 		//option is Enabled
-		if($option_selected == 'device_enabled') {
+		if ($option_selected == 'device_enabled') {
 			echo "<td class='vtable' align='left'>\n";
 			echo "    <select class='formfld' name='new_setting'>\n";
 			echo "    <option value='true'>".$text['label-true']."</option>\n";
@@ -284,7 +285,7 @@
 		}
 
 		//option is Device Profile
-		if($option_selected == 'device_profile_uuid' && permission_exists('device_profile_edit')) {
+		if ($option_selected == 'device_profile_uuid' && permission_exists('device_profile_edit')) {
 			$sql = "select * from v_device_profiles ";
 			$sql .= "where (domain_uuid = '".$domain_uuid."' or domain_uuid is null) ";
 			$sql .= "order by device_profile_name asc ";
@@ -297,7 +298,7 @@
 				echo "<td class='vtable' align='left'>\n";
 				echo "    <select class='formfld' name='new_setting'>\n";
 				echo "				<option value=''></option>\n";
-				foreach($result as $row) {
+				foreach ($result as $row) {
 					echo "			<option value='".escape($row['device_profile_uuid'])."' ".(($row['device_profile_uuid'] == $device_profile_uuid) ? "selected='selected'" : null).">".escape($row['device_profile_name'])." ".(($row['domain_uuid'] == '') ? "&nbsp;&nbsp;(".$text['select-global'].")" : null)."</option>\n";
 				}
 				//echo "			</select>\n";
@@ -309,7 +310,7 @@
 		}
 
 		//option is Device Templates
-		if($option_selected == 'device_template' && permission_exists('device_template')) {
+		if ($option_selected == 'device_template' && permission_exists('device_template')) {
 			$device = new device;
 			$template_dir = $device->get_template_dir();
 			
@@ -318,16 +319,16 @@
 			echo "<option value=''></option>\n";
 			if (is_dir($template_dir)) {
 					$templates = scandir($template_dir);
-					foreach($templates as $dir) {
-						if($file != "." && $dir != ".." && $dir[0] != '.') {
-							if(is_dir($template_dir . "/" . $dir)) {
+					foreach ($templates as $dir) {
+						if (!empty($file) && $file != "." && !empty($dir) && $dir != ".." && $dir[0] != '.') {
+							if (is_dir($template_dir . "/" . $dir)) {
 								echo "<optgroup label='$dir'>";
 								$dh_sub=$template_dir . "/" . $dir;
-								if(is_dir($dh_sub)) {
+								if (is_dir($dh_sub)) {
 									$templates_sub = scandir($dh_sub);
-									foreach($templates_sub as $dir_sub) {
-										if($file_sub != '.' && $dir_sub != '..' && $dir_sub[0] != '.') {
-											if(is_dir($template_dir . '/' . $dir .'/'. $dir_sub)) {
+									foreach ($templates_sub as $dir_sub) {
+										if ($file_sub != '.' && $dir_sub != '..' && $dir_sub[0] != '.') {
+											if (is_dir($template_dir . '/' . $dir .'/'. $dir_sub)) {
 												if ($device_template == $dir."/".$dir_sub) {
 													echo "<option value='".$dir."/".$dir_sub."' selected='selected'>".$dir."/".$dir_sub."</option>\n";
 												}
@@ -350,16 +351,16 @@
 		}
 
 		//options with a free form input
-		if($option_selected == 'line_1_server_address' || $option_selected == 'line_1_server_address_primary' || $option_selected == 'line_1_server_address_secondary' || $option_selected == 'line_1_outbound_proxy_primary' || $option_selected == 'line_1_outbound_proxy_secondary' || $option_selected == 'line_1_sip_port' || $option_selected == 'line_1_register_expires') {
+		if ($option_selected == 'line_1_server_address' || $option_selected == 'line_1_server_address_primary' || $option_selected == 'line_1_server_address_secondary' || $option_selected == 'line_1_outbound_proxy_primary' || $option_selected == 'line_1_outbound_proxy_secondary' || $option_selected == 'line_1_sip_port' || $option_selected == 'line_1_register_expires') {
 			echo "<td class='vtable' align='left'>\n";
-			echo "    <input class='formfld' type='text' name='new_setting' maxlength='255' value=\"".escape($new_setting)."\">\n";
+			echo "    <input class='formfld' type='text' name='new_setting' maxlength='255' value=\"".escape($new_setting ?? '')."\">\n";
 			echo "<br />\n";
-			echo $text["description-".escape($option_selected).""]."\n";
+			echo ($text["description-".escape($option_selected)] ?? '')."\n";
 			echo "</td>\n";
 		}
 		
 		//option is transport
-		if($option_selected == 'line_1_sip_transport') {
+		if ($option_selected == 'line_1_sip_transport') {
 			echo "<td class='vtable' align='left'>\n";
 			echo "    <select class='formfld' name='new_setting'>\n";
 			echo "    <option value='tcp'>TCP</option>\n";
@@ -368,7 +369,7 @@
 			echo "    <option value='dns srv'>DNS SRV</option>\n";
 			echo "    </select>\n";
 			echo "    <br />\n";
-			echo $text["description-".escape($option_selected).""]."\n";
+			echo ($text["description-".escape($option_selected)] ?? '')."\n";
 			echo "</td>\n";
 		}
 
@@ -384,9 +385,9 @@
 	if (is_array($directory)) {
 		echo "<th style='width: 30px; text-align: center; padding: 0px;'><input type='checkbox' id='chk_all' onchange=\"(this.checked) ? check('all') : check('none');\"></th>";
 	}
-	echo th_order_by('device_mac_address', $text['label-device_mac_address'], $order_by,$order,'','',"option_selected=".$option_selected."&search=".$search."");
+	echo th_order_by('device_address', $text['label-device_address'], $order_by,$order,'','',"option_selected=".$option_selected."&search=".$search."");
 	echo th_order_by('device_label', $text['label-device_label'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
-	if (preg_match ('/line_(.)/',$option_selected)) {
+	if (preg_match('/line_(.)/',($option_selected ?? ''))) {
 			echo th_order_by($option_selected, $text["label-".$option_selected.""], $order_by,$order,'','',"option_selected=".$option_selected."&search=".$search."");
 		}
 	echo th_order_by('device_vendor', $text['label-device_vendor'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
@@ -397,7 +398,7 @@
 	echo "</tr>\n";
 
 	if (is_array($directory)) {
-		foreach($directory as $key => $row) {
+		foreach ($directory as $key => $row) {
 			$tr_link = (permission_exists('device_edit')) ? " href='/app/devices/device_edit.php?id=".$row['device_uuid']."'" : null;
 			echo "<tr ".$tr_link.">\n";
 
@@ -405,9 +406,9 @@
 			echo "		<input type='checkbox' name='id[]' id='checkbox_".escape($row['device_uuid'])."' value='".escape($row['device_uuid'])."' onclick=\"if (!this.checked) { document.getElementById('chk_all').checked = false; }\">";
 			echo "	</td>";
 			$device_ids[] = 'checkbox_'.$row['device_uuid'];
-			echo "	<td valign='top' class='".$row_style[$c]."'> ".escape($row['device_mac_address'])."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'> ".escape(format_device_address($row['device_address']))."&nbsp;</td>\n";
 			echo "	<td valign='top' class='".$row_style[$c]."'> ".escape($row['device_label'])."&nbsp;</td>\n";
-			if (preg_match ('/line_/',$option_selected)) {
+			if (preg_match ('/line_/',($option_selected ?? ''))) {
 				echo "	<td valign='top' class='".$row_style[$c]."'> ".$row[$option_selected]."&nbsp;</td>\n";	
 			}
 			echo "	<td valign='top' class='".$row_style[$c]."'> ".escape($row['device_vendor'])."&nbsp;</td>\n";
@@ -424,15 +425,15 @@
 	echo "</table>";
 	echo "</form>";
 
-	if (strlen($paging_controls) > 0) {
+	if (!empty($paging_controls)) {
 		echo "<br />";
 		echo $paging_controls."\n";
 	}
 
-	echo "<br /><br />".((is_array($directory)) ? "<br /><br />" : null);
+	echo "<br /><br />".(!empty($directory) && is_array($directory) ? "<br /><br />" : null);
 
 	// check or uncheck all checkboxes
-	if (sizeof($device_ids) > 0) {
+	if (!empty($device_ids) && is_array($device_ids) && @sizeof($device_ids) != 0) {
 		echo "<script>\n";
 		echo "	function check(what) {\n";
 		echo "		document.getElementById('chk_all').checked = (what == 'all') ? true : false;\n";
@@ -443,7 +444,7 @@
 		echo "</script>\n";
 	}
 
-	if (is_array($directory)) {
+	if (!empty($directory) && is_array($directory)) {
 		// check all checkboxes
 		key_press('ctrl+a', 'down', 'document', null, null, "check('all');", true);
 
@@ -454,4 +455,4 @@
 //show the footer
 	require_once "resources/footer.php";
 
-?>
+?>