Sofia global settings PHP 8.1
This commit is contained in:
parent
29008867d0
commit
9083885b75
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
The Initial Developer of the Original Code is
|
||||
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.
|
||||
|
||||
Contributor(s):
|
||||
|
|
@ -80,12 +80,12 @@ if (!class_exists('sofia_global_settings')) {
|
|||
}
|
||||
|
||||
//delete multiple records
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
if (!empty($records) && @sizeof($records) != 0) {
|
||||
//build the delete array
|
||||
$x = 0;
|
||||
foreach ($records as $record) {
|
||||
//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'];
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ if (!class_exists('sofia_global_settings')) {
|
|||
}
|
||||
|
||||
//delete the checked rows
|
||||
if (is_array($array) && @sizeof($array) != 0) {
|
||||
if (!empty($array) && @sizeof($array) != 0) {
|
||||
//execute delete
|
||||
$database = new database;
|
||||
$database->app_name = $this->app_name;
|
||||
|
|
@ -129,19 +129,19 @@ if (!class_exists('sofia_global_settings')) {
|
|||
}
|
||||
|
||||
//toggle the checked records
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
if (!empty($records) && @sizeof($records) != 0) {
|
||||
//get current toggle state
|
||||
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']."'";
|
||||
}
|
||||
}
|
||||
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 .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$database = new database;
|
||||
$rows = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
$rows = $database->select($sql, null, 'all');
|
||||
if (!empty($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
$states[$row['uuid']] = $row['toggle'];
|
||||
}
|
||||
|
|
@ -161,7 +161,7 @@ if (!class_exists('sofia_global_settings')) {
|
|||
}
|
||||
|
||||
//save the changes
|
||||
if (is_array($array) && @sizeof($array) != 0) {
|
||||
if (!empty($array) && @sizeof($array) != 0) {
|
||||
//save the array
|
||||
$database = new database;
|
||||
$database->app_name = $this->app_name;
|
||||
|
|
@ -196,29 +196,30 @@ if (!class_exists('sofia_global_settings')) {
|
|||
}
|
||||
|
||||
//copy the checked records
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
if (!empty($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get checked records
|
||||
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']."'";
|
||||
}
|
||||
}
|
||||
|
||||
//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 .= "where sofia_global_setting_uuid in (".implode(', ', $uuids).") ";
|
||||
$database = new database;
|
||||
$rows = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
$rows = $database->select($sql, null, 'all');
|
||||
if (!empty($rows) && @sizeof($rows) != 0) {
|
||||
$x = 0;
|
||||
foreach ($rows as $row) {
|
||||
//copy data
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//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'].')';
|
||||
|
||||
//increment the id
|
||||
|
|
@ -229,7 +230,8 @@ if (!class_exists('sofia_global_settings')) {
|
|||
}
|
||||
|
||||
//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
|
||||
$database = new database;
|
||||
$database->app_name = $this->app_name;
|
||||
|
|
|
|||
|
|
@ -21,18 +21,24 @@
|
|||
$language = new text;
|
||||
$text = $language->get();
|
||||
|
||||
//set the defaults
|
||||
$global_setting_name = '';
|
||||
$global_setting_value = '';
|
||||
$global_setting_description = '';
|
||||
|
||||
//action add or update
|
||||
if (is_uuid($_REQUEST["id"])) {
|
||||
if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
|
||||
$action = "update";
|
||||
$sofia_global_setting_uuid = $_REQUEST["id"];
|
||||
$id = $_REQUEST["id"];
|
||||
}
|
||||
else {
|
||||
$action = "add";
|
||||
$sofia_global_setting_uuid = uuid();
|
||||
}
|
||||
|
||||
//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_value = $_POST["global_setting_value"];
|
||||
$global_setting_enabled = $_POST["global_setting_enabled"];
|
||||
|
|
@ -40,7 +46,7 @@
|
|||
}
|
||||
|
||||
//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
|
||||
$token = new token;
|
||||
|
|
@ -51,7 +57,7 @@
|
|||
}
|
||||
|
||||
//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)
|
||||
//send the array to the database class
|
||||
|
|
@ -102,11 +108,6 @@
|
|||
return;
|
||||
}
|
||||
|
||||
//add the sofia_global_setting_uuid
|
||||
if (!is_uuid($_POST["sofia_global_setting_uuid"])) {
|
||||
$sofia_global_setting_uuid = uuid();
|
||||
}
|
||||
|
||||
//prepare the array
|
||||
$array['sofia_global_settings'][0]['sofia_global_setting_uuid'] = $sofia_global_setting_uuid;
|
||||
$array['sofia_global_settings'][0]['global_setting_name'] = $global_setting_name;
|
||||
|
|
@ -135,7 +136,7 @@
|
|||
}
|
||||
|
||||
//pre-populate the form
|
||||
if (is_array($_GET) && $_POST["persistformvar"] != "true") {
|
||||
if (!empty($_GET) && empty($_POST["persistformvar"])) {
|
||||
$sql = "select ";
|
||||
$sql .= " sofia_global_setting_uuid, ";
|
||||
$sql .= " global_setting_name, ";
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
The Initial Developer of the Original Code is
|
||||
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.
|
||||
*/
|
||||
|
||||
|
|
@ -43,15 +43,22 @@
|
|||
$language = new text;
|
||||
$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
|
||||
if (is_array($_POST['sofia_global_settings'])) {
|
||||
if (!empty($_POST['sofia_global_settings'])) {
|
||||
$action = $_POST['action'];
|
||||
$search = $_POST['search'];
|
||||
$sofia_global_settings = $_POST['sofia_global_settings'];
|
||||
}
|
||||
|
||||
//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) {
|
||||
case 'copy':
|
||||
|
|
@ -80,8 +87,8 @@
|
|||
}
|
||||
|
||||
//get order and order by
|
||||
$order_by = $_GET["order_by"];
|
||||
$order = $_GET["order"];
|
||||
$order_by = $_GET["order_by"] ?? '';
|
||||
$order = $_GET["order"] ?? '';
|
||||
|
||||
//add the search
|
||||
if (isset($_GET["search"])) {
|
||||
|
|
@ -93,17 +100,20 @@
|
|||
$sql .= "from v_sofia_global_settings ";
|
||||
if (isset($search)) {
|
||||
$sql .= "where (";
|
||||
$sql .= " global_setting_name like :search ";
|
||||
$sql .= " or global_setting_value like :search ";
|
||||
$sql .= " or global_setting_description like :search ";
|
||||
$sql .= ") ";
|
||||
$parameters['search'] = '%'.$search.'%';
|
||||
}
|
||||
$database = new database;
|
||||
$num_rows = $database->select($sql, $parameters, 'column');
|
||||
$num_rows = $database->select($sql, $parameters ?? '', '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;
|
||||
$page = is_numeric($_GET['page']) ? $_GET['page'] : 0;
|
||||
$param = !empty($search) ? "&search=".$search : null;
|
||||
$page = !empty($_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;
|
||||
|
|
@ -116,7 +126,7 @@
|
|||
$sql .= "cast(global_setting_enabled as text), ";
|
||||
$sql .= "global_setting_description ";
|
||||
$sql .= "from v_sofia_global_settings ";
|
||||
if (isset($_GET["search"])) {
|
||||
if (isset($search)) {
|
||||
$sql .= "where (";
|
||||
$sql .= " global_setting_name like :search ";
|
||||
$sql .= " or global_setting_value like :search ";
|
||||
|
|
@ -127,7 +137,7 @@
|
|||
$sql .= order_by($order_by, $order, 'global_setting_name', 'asc');
|
||||
$sql .= limit_offset($rows_per_page, $offset);
|
||||
$database = new database;
|
||||
$sofia_global_settings = $database->select($sql, $parameters, 'all');
|
||||
$sofia_global_settings = $database->select($sql, $parameters ?? '', 'all');
|
||||
unset($sql, $parameters);
|
||||
|
||||
//create token
|
||||
|
|
@ -187,19 +197,19 @@
|
|||
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')) {
|
||||
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_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_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";
|
||||
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'> </td>\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;
|
||||
foreach ($sofia_global_settings as $row) {
|
||||
if (permission_exists('sofia_global_setting_edit')) {
|
||||
|
|
@ -232,7 +242,7 @@
|
|||
}
|
||||
echo " </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 button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
|
||||
echo " </td>\n";
|
||||
|
|
|
|||
Loading…
Reference in New Issue