Sofia global settings PHP 8.1

This commit is contained in:
markjcrane 2023-05-25 22:04:33 -06:00
parent 29008867d0
commit 9083885b75
3 changed files with 54 additions and 41 deletions

View File

@ -17,7 +17,7 @@
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2019 - 2021 Portions created by the Initial Developer are Copyright (C) 2019 - 2023
the Initial Developer. All Rights Reserved. the Initial Developer. All Rights Reserved.
Contributor(s): Contributor(s):
@ -80,12 +80,12 @@ if (!class_exists('sofia_global_settings')) {
} }
//delete multiple records //delete multiple records
if (is_array($records) && @sizeof($records) != 0) { if (!empty($records) && @sizeof($records) != 0) {
//build the delete array //build the delete array
$x = 0; $x = 0;
foreach ($records as $record) { foreach ($records as $record) {
//add to the array //add to the array
if ($record['checked'] == 'true' && is_uuid($record['sofia_global_setting_uuid'])) { if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['sofia_global_setting_uuid'])) {
$array[$this->table][$x]['sofia_global_setting_uuid'] = $record['sofia_global_setting_uuid']; $array[$this->table][$x]['sofia_global_setting_uuid'] = $record['sofia_global_setting_uuid'];
} }
@ -94,7 +94,7 @@ if (!class_exists('sofia_global_settings')) {
} }
//delete the checked rows //delete the checked rows
if (is_array($array) && @sizeof($array) != 0) { if (!empty($array) && @sizeof($array) != 0) {
//execute delete //execute delete
$database = new database; $database = new database;
$database->app_name = $this->app_name; $database->app_name = $this->app_name;
@ -129,19 +129,19 @@ if (!class_exists('sofia_global_settings')) {
} }
//toggle the checked records //toggle the checked records
if (is_array($records) && @sizeof($records) != 0) { if (!empty($records) && @sizeof($records) != 0) {
//get current toggle state //get current toggle state
foreach($records as $record) { foreach($records as $record) {
if ($record['checked'] == 'true' && is_uuid($record['sofia_global_setting_uuid'])) { if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['sofia_global_setting_uuid'])) {
$uuids[] = "'".$record['sofia_global_setting_uuid']."'"; $uuids[] = "'".$record['sofia_global_setting_uuid']."'";
} }
} }
if (is_array($uuids) && @sizeof($uuids) != 0) { if (!empty($uuids) && @sizeof($uuids) != 0) {
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." "; $sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") "; $sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
$database = new database; $database = new database;
$rows = $database->select($sql, $parameters, 'all'); $rows = $database->select($sql, null, 'all');
if (is_array($rows) && @sizeof($rows) != 0) { if (!empty($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) { foreach ($rows as $row) {
$states[$row['uuid']] = $row['toggle']; $states[$row['uuid']] = $row['toggle'];
} }
@ -161,7 +161,7 @@ if (!class_exists('sofia_global_settings')) {
} }
//save the changes //save the changes
if (is_array($array) && @sizeof($array) != 0) { if (!empty($array) && @sizeof($array) != 0) {
//save the array //save the array
$database = new database; $database = new database;
$database->app_name = $this->app_name; $database->app_name = $this->app_name;
@ -196,29 +196,30 @@ if (!class_exists('sofia_global_settings')) {
} }
//copy the checked records //copy the checked records
if (is_array($records) && @sizeof($records) != 0) { if (!empty($records) && @sizeof($records) != 0) {
//get checked records //get checked records
foreach($records as $record) { foreach($records as $record) {
if ($record['checked'] == 'true' && is_uuid($record['sofia_global_setting_uuid'])) { if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['sofia_global_setting_uuid'])) {
$uuids[] = "'".$record['sofia_global_setting_uuid']."'"; $uuids[] = "'".$record['sofia_global_setting_uuid']."'";
} }
} }
//create the array from existing data //create the array from existing data
if (is_array($uuids) && @sizeof($uuids) != 0) { if (!empty($uuids) && @sizeof($uuids) != 0) {
$sql = "select * from v_".$this->table." "; $sql = "select * from v_".$this->table." ";
$sql .= "where sofia_global_setting_uuid in (".implode(', ', $uuids).") "; $sql .= "where sofia_global_setting_uuid in (".implode(', ', $uuids).") ";
$database = new database; $database = new database;
$rows = $database->select($sql, $parameters, 'all'); $rows = $database->select($sql, null, 'all');
if (is_array($rows) && @sizeof($rows) != 0) { if (!empty($rows) && @sizeof($rows) != 0) {
$x = 0; $x = 0;
foreach ($rows as $row) { foreach ($rows as $row) {
//copy data //copy data
$array[$this->table][$x] = $row; $array[$this->table][$x] = $row;
//add copy to the description //add copy to the description
$array[$this->table][$x][sofia_global_setting.'_uuid'] = uuid(); $array[$this->table][$x][$this->name.'_uuid'] = uuid();
$array[$this->table][$x]['global_setting_enabled'] = $row['global_setting_enabled'];
$array[$this->table][$x][$this->description_field] = trim($row[$this->description_field]).' ('.$text['label-copy'].')'; $array[$this->table][$x][$this->description_field] = trim($row[$this->description_field]).' ('.$text['label-copy'].')';
//increment the id //increment the id
@ -229,7 +230,8 @@ if (!class_exists('sofia_global_settings')) {
} }
//save the changes and set the message //save the changes and set the message
if (is_array($array) && @sizeof($array) != 0) { if (!empty($array) && @sizeof($array) != 0) {
//view_array($array);
//save the array //save the array
$database = new database; $database = new database;
$database->app_name = $this->app_name; $database->app_name = $this->app_name;

View File

@ -21,18 +21,24 @@
$language = new text; $language = new text;
$text = $language->get(); $text = $language->get();
//set the defaults
$global_setting_name = '';
$global_setting_value = '';
$global_setting_description = '';
//action add or update //action add or update
if (is_uuid($_REQUEST["id"])) { if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$action = "update"; $action = "update";
$sofia_global_setting_uuid = $_REQUEST["id"]; $sofia_global_setting_uuid = $_REQUEST["id"];
$id = $_REQUEST["id"]; $id = $_REQUEST["id"];
} }
else { else {
$action = "add"; $action = "add";
$sofia_global_setting_uuid = uuid();
} }
//get http post variables and set them to php variables //get http post variables and set them to php variables
if (is_array($_POST)) { if (!empty($_POST)) {
$global_setting_name = $_POST["global_setting_name"]; $global_setting_name = $_POST["global_setting_name"];
$global_setting_value = $_POST["global_setting_value"]; $global_setting_value = $_POST["global_setting_value"];
$global_setting_enabled = $_POST["global_setting_enabled"]; $global_setting_enabled = $_POST["global_setting_enabled"];
@ -40,7 +46,7 @@
} }
//process the user data and save it to the database //process the user data and save it to the database
if (count($_POST) > 0 && empty($_POST["persistformvar"])) { if (!empty($_POST) && empty($_POST["persistformvar"])) {
//validate the token //validate the token
$token = new token; $token = new token;
@ -51,7 +57,7 @@
} }
//process the http post data by submitted action //process the http post data by submitted action
if ($_POST['action'] != '' && !empty($_POST['action'])) { if (!empty($_POST['action']) && !empty($_POST['action'])) {
//prepare the array(s) //prepare the array(s)
//send the array to the database class //send the array to the database class
@ -102,11 +108,6 @@
return; return;
} }
//add the sofia_global_setting_uuid
if (!is_uuid($_POST["sofia_global_setting_uuid"])) {
$sofia_global_setting_uuid = uuid();
}
//prepare the array //prepare the array
$array['sofia_global_settings'][0]['sofia_global_setting_uuid'] = $sofia_global_setting_uuid; $array['sofia_global_settings'][0]['sofia_global_setting_uuid'] = $sofia_global_setting_uuid;
$array['sofia_global_settings'][0]['global_setting_name'] = $global_setting_name; $array['sofia_global_settings'][0]['global_setting_name'] = $global_setting_name;
@ -135,7 +136,7 @@
} }
//pre-populate the form //pre-populate the form
if (is_array($_GET) && $_POST["persistformvar"] != "true") { if (!empty($_GET) && empty($_POST["persistformvar"])) {
$sql = "select "; $sql = "select ";
$sql .= " sofia_global_setting_uuid, "; $sql .= " sofia_global_setting_uuid, ";
$sql .= " global_setting_name, "; $sql .= " global_setting_name, ";

View File

@ -17,7 +17,7 @@
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2018 - 2021 Portions created by the Initial Developer are Copyright (C) 2018 - 2023
the Initial Developer. All Rights Reserved. the Initial Developer. All Rights Reserved.
*/ */
@ -43,15 +43,22 @@
$language = new text; $language = new text;
$text = $language->get(); $text = $language->get();
//set the defaults
$action = '';
$search = '';
//set from session variables
$list_row_edit_button = !empty($_SESSION['theme']['list_row_edit_button']['boolean']) ? $_SESSION['theme']['list_row_edit_button']['boolean'] : 'false';
//get the http post data //get the http post data
if (is_array($_POST['sofia_global_settings'])) { if (!empty($_POST['sofia_global_settings'])) {
$action = $_POST['action']; $action = $_POST['action'];
$search = $_POST['search']; $search = $_POST['search'];
$sofia_global_settings = $_POST['sofia_global_settings']; $sofia_global_settings = $_POST['sofia_global_settings'];
} }
//process the http post data by action //process the http post data by action
if ($action != '' && is_array($sofia_global_settings) && @sizeof($sofia_global_settings) != 0) { if (!empty($action) && !empty($sofia_global_settings) && @sizeof($sofia_global_settings) != 0) {
switch ($action) { switch ($action) {
case 'copy': case 'copy':
@ -80,8 +87,8 @@
} }
//get order and order by //get order and order by
$order_by = $_GET["order_by"]; $order_by = $_GET["order_by"] ?? '';
$order = $_GET["order"]; $order = $_GET["order"] ?? '';
//add the search //add the search
if (isset($_GET["search"])) { if (isset($_GET["search"])) {
@ -93,17 +100,20 @@
$sql .= "from v_sofia_global_settings "; $sql .= "from v_sofia_global_settings ";
if (isset($search)) { if (isset($search)) {
$sql .= "where ("; $sql .= "where (";
$sql .= " global_setting_name like :search ";
$sql .= " or global_setting_value like :search ";
$sql .= " or global_setting_description like :search ";
$sql .= ") "; $sql .= ") ";
$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 ?? '', '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 = !empty($search) ? "&search=".$search : null;
$page = is_numeric($_GET['page']) ? $_GET['page'] : 0; $page = !empty($_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;
@ -116,7 +126,7 @@
$sql .= "cast(global_setting_enabled as text), "; $sql .= "cast(global_setting_enabled as text), ";
$sql .= "global_setting_description "; $sql .= "global_setting_description ";
$sql .= "from v_sofia_global_settings "; $sql .= "from v_sofia_global_settings ";
if (isset($_GET["search"])) { if (isset($search)) {
$sql .= "where ("; $sql .= "where (";
$sql .= " global_setting_name like :search "; $sql .= " global_setting_name like :search ";
$sql .= " or global_setting_value like :search "; $sql .= " or global_setting_value like :search ";
@ -127,7 +137,7 @@
$sql .= order_by($order_by, $order, 'global_setting_name', 'asc'); $sql .= order_by($order_by, $order, 'global_setting_name', 'asc');
$sql .= limit_offset($rows_per_page, $offset); $sql .= limit_offset($rows_per_page, $offset);
$database = new database; $database = new database;
$sofia_global_settings = $database->select($sql, $parameters, 'all'); $sofia_global_settings = $database->select($sql, $parameters ?? '', 'all');
unset($sql, $parameters); unset($sql, $parameters);
//create token //create token
@ -187,19 +197,19 @@
echo "<tr class='list-header'>\n"; echo "<tr class='list-header'>\n";
if (permission_exists('sofia_global_setting_add') || permission_exists('sofia_global_setting_edit') || permission_exists('sofia_global_setting_delete')) { if (permission_exists('sofia_global_setting_add') || permission_exists('sofia_global_setting_edit') || permission_exists('sofia_global_setting_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);' ".($sofia_global_settings ?: "style='visibility: hidden;'").">\n"; echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(!empty($sofia_global_settings) ?: "style='visibility: hidden;'").">\n";
echo " </th>\n"; echo " </th>\n";
} }
echo th_order_by('global_setting_name', $text['label-global_setting_name'], $order_by, $order); echo th_order_by('global_setting_name', $text['label-global_setting_name'], $order_by, $order);
echo th_order_by('global_setting_value', $text['label-global_setting_value'], $order_by, $order); echo th_order_by('global_setting_value', $text['label-global_setting_value'], $order_by, $order);
echo th_order_by('global_setting_enabled', $text['label-global_setting_enabled'], $order_by, $order, null, "class='center'"); echo th_order_by('global_setting_enabled', $text['label-global_setting_enabled'], $order_by, $order, null, "class='center'");
echo " <th class='hide-sm-dn'>".$text['label-global_setting_description']."</th>\n"; echo " <th class='hide-sm-dn'>".$text['label-global_setting_description']."</th>\n";
if (permission_exists('sofia_global_setting_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { if (permission_exists('sofia_global_setting_edit') && $list_row_edit_button == 'true') {
echo " <td class='action-button'>&nbsp;</td>\n"; echo " <td class='action-button'>&nbsp;</td>\n";
} }
echo "</tr>\n"; echo "</tr>\n";
if (is_array($sofia_global_settings) && @sizeof($sofia_global_settings) != 0) { if (!empty($sofia_global_settings) && @sizeof($sofia_global_settings) != 0) {
$x = 0; $x = 0;
foreach ($sofia_global_settings as $row) { foreach ($sofia_global_settings as $row) {
if (permission_exists('sofia_global_setting_edit')) { if (permission_exists('sofia_global_setting_edit')) {
@ -232,7 +242,7 @@
} }
echo " </td>\n"; echo " </td>\n";
echo " <td class='description overflow hide-sm-dn'>".escape($row['global_setting_description'])."</td>\n"; echo " <td class='description overflow hide-sm-dn'>".escape($row['global_setting_description'])."</td>\n";
if (permission_exists('sofia_global_setting_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { if (permission_exists('sofia_global_setting_edit') && $list_row_edit_button == '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";