Update domain_setting_edit with improved syntax

This commit is contained in:
FusionPBX 2023-05-13 12:13:38 -06:00 committed by GitHub
parent 0a37d8c8d5
commit e7ed4fe568
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 255 additions and 242 deletions

View File

@ -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) 2008-2021
Portions created by the Initial Developer are Copyright (C) 2008-2023
the Initial Developer. All Rights Reserved.
Contributor(s):
@ -47,17 +47,17 @@
//retrieve allowed setting categories
if (!permission_exists('domain_setting_category_edit')) {
if (is_array($_SESSION['settings']) && sizeof($_SESSION['settings']) > 0) {
if (!empty($_SESSION['settings'])) {
foreach ($_SESSION['groups'] as $index => $group) {
$group_name = $group['group_name'];
if (is_array($_SESSION['settings'][$group_name]) && sizeof($_SESSION['settings'][$group_name]) > 0) {
if (!empty($_SESSION['settings'][$group_name])) {
foreach ($_SESSION['settings'][$group_name] as $category) {
$categories[] = strtolower($category);
}
}
}
}
if (is_array($categories) && sizeof($categories) > 0) {
if (!empty($categories)) {
$allowed_categories = array_unique($categories);
sort($allowed_categories, SORT_NATURAL);
}
@ -65,7 +65,7 @@
}
//action add or update
if (is_uuid($_REQUEST["id"])) {
if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$action = "update";
$domain_setting_uuid = $_REQUEST["id"];
}
@ -74,12 +74,12 @@
}
//set the domain_uuid
if (is_uuid($_GET["domain_uuid"])) {
if (!empty($_GET["domain_uuid"]) && is_uuid($_GET["domain_uuid"])) {
$domain_uuid = $_GET["domain_uuid"];
}
//get http post variables and set them to php variables
if (count($_POST) > 0) {
if (!empty($_POST)) {
$domain_setting_category = strtolower($_POST["domain_setting_category"]);
$domain_setting_subcategory = strtolower($_POST["domain_setting_subcategory"]);
$domain_setting_name = strtolower($_POST["domain_setting_name"]);
@ -89,10 +89,11 @@
$domain_setting_description = $_POST["domain_setting_description"];
}
if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
//process the data
if (!empty($_POST) && empty($_POST["persistformvar"])) {
$msg = '';
if ($action == "update") {
//get the domain setting uuid
if ($action == "update" && !empty($_POST["domain_setting_uuid"])) {
$domain_setting_uuid = $_POST["domain_setting_uuid"];
}
@ -105,7 +106,8 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
}
//check for all required/authorized data
if (empty($domain_setting_category) || (is_array($allowed_categories) && sizeof($allowed_categories) > 0 && !in_array(strtolower($domain_setting_category), $allowed_categories))) { $msg .= $text['message-required'].$text['label-category']."<br>\n"; }
$msg = '';
if (empty($domain_setting_category) || (!empty($allowed_categories) && !in_array(strtolower($domain_setting_category), $allowed_categories))) { $msg .= $text['message-required'].$text['label-category']."<br>\n"; }
if (empty($domain_setting_subcategory)) { $msg .= $text['message-required'].$text['label-subcategory']."<br>\n"; }
if (empty($domain_setting_name)) { $msg .= $text['message-required'].$text['label-type']."<br>\n"; }
//if (empty($domain_setting_value)) { $msg .= $text['message-required'].$text['label-value']."<br>\n"; }
@ -126,9 +128,9 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
}
//add or update the database
if ($_POST["persistformvar"] != "true") {
if (empty($_POST["persistformvar"])) {
// fix null
$domain_setting_order = $domain_setting_order != '' ? $domain_setting_order : 'null';
$domain_setting_order = !empty($domain_setting_order) ? $domain_setting_order : 'null';
//update switch timezone variables
if ($domain_setting_category == "domain" && $domain_setting_subcategory == "time_zone" && $domain_setting_name == "name" ) {
@ -174,7 +176,8 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
$array['dialplan_details'][0]['dialplan_detail_order'] = '20';
$p->add('dialplan_detail_add', 'temp');
}
if (is_array($array) && sizeof($array) != 0) {
view_array($array);
if (!empty($array)) {
$database = new database;
$database->app_name = 'domain_settings';
$database->app_uuid = 'b31e723a-bf70-670c-a49b-470d2a232f71';
@ -242,7 +245,7 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
unset($sql, $parameters);
$time_zone_found = false;
if (is_array($result) && sizeof($result) != 0) {
if (!empty($result)) {
foreach ($result as &$row) {
//get the dialplan_uuid
$dialplan_uuid = $row["dialplan_uuid"];
@ -255,7 +258,7 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
$parameters['domain_uuid'] = $_SESSION["domain_uuid"];
$database = new database;
$sub_result = $database->select($sql, $parameters, 'all');
if (is_array($sub_result) && sizeof($sub_result) != 0) {
if (!empty($sub_result)) {
foreach ($sub_result as $field) {
$dialplan_detail_uuid = $field["dialplan_detail_uuid"];
$dialplan_detail_tag = $field["dialplan_detail_tag"]; //action //condition
@ -299,7 +302,7 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
}
//execute
if (is_array($array) && sizeof($array) != 0) {
if (!empty($array)) {
$database = new database;
$database->app_name = 'domain_settings';
$database->app_uuid = 'b31e723a-bf70-670c-a49b-470d2a232f71';
@ -323,10 +326,10 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
header("Location: ".PROJECT_PATH."/core/domain_settings/domain_settings.php?id=".$domain_uuid);
exit;
}
}
}
//pre-populate the form
if (count($_GET)>0 && $_POST["persistformvar"] != "true" && is_uuid($_GET["id"])) {
if (empty($_POST["persistformvar"]) && !empty($_GET["id"]) && is_uuid($_GET["id"])) {
$domain_setting_uuid = $_GET["id"];
$sql = "select domain_setting_uuid, domain_setting_category, domain_setting_subcategory, domain_setting_name, domain_setting_value, domain_setting_order, cast(domain_setting_enabled as text), domain_setting_description ";
$sql .= "from v_domain_settings ";
@ -336,7 +339,7 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
$parameters['domain_setting_uuid'] = $domain_setting_uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row) && sizeof($row) != 0) {
if (!empty($row)) {
$domain_setting_category = $row["domain_setting_category"];
$domain_setting_subcategory = $row["domain_setting_subcategory"];
$domain_setting_name = $row["domain_setting_name"];
@ -349,7 +352,13 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
}
//set the defaults
if (empty($domain_setting_enabled)) { $domain_setting_enabled = 'true'; }
$domain_setting_category = $domain_setting_category ?? '';
$domain_setting_subcategory = $domain_setting_subcategory ?? '';
$domain_setting_name = $domain_setting_name ?? '';
$domain_setting_value = $domain_setting_value ?? '';
$domain_setting_order = $domain_setting_order ?? '';
$domain_setting_enabled = $domain_setting_enabled ?? 'true';
$domain_setting_description = $domain_setting_description ?? '';
//create token
$object = new token;
@ -400,14 +409,14 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
echo "<td width='70%' class='vtable' align='left'>\n";
if (permission_exists('domain_setting_category_edit')) {
if ($action == 'add') {
$domain_setting_category = $_GET['domain_setting_category'];
$domain_setting_category = $_GET['domain_setting_category'] ?? '';
}
echo " <input type='text' class='formfld' name='domain_setting_category' id='domain_setting_category' maxlength='255' value=\"".escape($domain_setting_category)."\">\n";
}
else {
echo " <select class='formfld' name='domain_setting_category' id='domain_setting_category' onchange=\"$('#domain_setting_subcategory').trigger('focus');\">\n";
echo " <option value=''></option>\n";
if (is_array($allowed_categories) && sizeof($allowed_categories) > 0) {
if (!empty($allowed_categories)) {
foreach ($allowed_categories as $category) {
$selected = ($domain_setting_category == $category) ? 'selected' : null;
echo " <option value='".escape($category)."' ".$selected.">".ucwords(str_replace('_',' ',escape($category)))."</option>\n";
@ -439,9 +448,11 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
$setting_types = ['Array','Boolean','Code','Dir','Name','Numeric','Text','UUID'];
echo " <select class='formfld' id='domain_setting_name' name='domain_setting_name' required='required'>\n";
echo " <option value=''></option>\n";
if (!empty($setting_types)) {
foreach ($setting_types as $setting_type) {
echo " <option value='".strtolower($setting_type)."' ".($domain_setting_name == strtolower($setting_type) ? "selected='selected'" : null).">".$setting_type."</option>\n";
}
}
echo " </select>\n";
unset($setting_types, $setting_type);
echo "<br />\n";
@ -454,9 +465,9 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
echo " ".$text['label-value']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
$category = $row['domain_setting_category'];
$category = $row['domain_setting_category'] ?? '';
$subcategory = $row['domain_setting_subcategory'] ?? '';
$name = $row['domain_setting_name'];
$name = $row['domain_setting_name'] ?? '';
if ($category == "domain" && $subcategory == "menu" && $name == "uuid" ) {
echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value' style=''>\n";
echo " <option value=''></option>\n";
@ -464,7 +475,7 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
$sql .= "order by menu_language, menu_name asc ";
$database = new database;
$sub_result = $database->select($sql, null, 'all');
if (is_array($sub_result) && sizeof($sub_result) != 0) {
if (!empty($sub_result)) {
foreach ($sub_result as $sub_row) {
$selected = strtolower($row['domain_setting_value']) == strtolower($sub_row["menu_uuid"]) ? "selected='selected'" : null;
echo " <option value='".strtolower(escape($sub_row["menu_uuid"]))."' ".$selected.">".escape($sub_row["menu_language"])." - ".escape($sub_row["menu_name"])."</option>\n";
@ -568,6 +579,7 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
echo " <option value=''></option>\n";
echo " <optgroup label='".$text['label-web_fonts']."'>\n";
$option_found = false;
if (!empty($fonts)) {
foreach ($fonts as $n => $font) {
if ($row['domain_setting_value'] == $font) {
$selected = 'selected';
@ -578,9 +590,10 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
}
echo " <option value='".escape($font)."' ".$selected.">".escape($font)."</option>\n";
}
}
echo " </optgroup>\n";
echo " <option value='' disabled='disabled'></option>\n";
echo " <option value='' ".(($row['domain_setting_value'] != '' && $option_found == false) ? 'selected' : null).">".$text['label-other']."...</option>\n";
echo " <option value='' ".((!empty($row['domain_setting_value']) && $option_found == false) ? 'selected' : null).">".$text['label-other']."...</option>\n";
echo " </select>";
echo " <input type='text' class='formfld' ".(($row['domain_setting_value'] == '' || $option_found) ? "style='display: none;'" : null)." id='txt_domain_setting_value' name='domain_setting_value' value=\"".escape($row['domain_setting_value'])."\">\n";
}
@ -742,26 +755,26 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
elseif ($category == "destinations" && $subcategory == "select_mode" && $name == "text" ) {
echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
echo " <option value='default'>".$text['label-default']."</option>\n";
echo " <option value='dynamic' ".(($row['domain_setting_value'] == "dynamic") ? "selected='selected'" : null).">".$text['label-dynamic']."</option>\n";
echo " <option value='dynamic' ".((!empty($row['domain_setting_value']) && $row['domain_setting_value'] == "dynamic") ? "selected='selected'" : null).">".$text['label-dynamic']."</option>\n";
echo " </select>\n";
}
elseif (is_json($row['domain_setting_value'])) {
elseif (!empty($row['domain_setting_value']) && is_json($row['domain_setting_value'])) {
echo " <textarea class='formfld' style='width: 100%; height: 80px; font-family: courier, monospace; overflow: auto;' id='domain_setting_value' name='domain_setting_value' wrap='off'>".$row['domain_setting_value']."</textarea>\n";
}
elseif ($name == "boolean") {
echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
if ($category == "provision" && is_numeric($row['domain_setting_value'])) {
echo " <option value='0'>".$text['label-false']."</option>\n";
echo " <option value='1' ".(($row['domain_setting_value'] == 1) ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
echo " <option value='1' ".((!empty($row['domain_setting_value']) && $row['domain_setting_value'] == 1) ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
}
else {
echo " <option value='false'>".$text['label-false']."</option>\n";
echo " <option value='true' ".((strtolower($row['domain_setting_value']) == "true") ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
echo " <option value='true' ".((!empty($row['domain_setting_value']) && strtolower($row['domain_setting_value']) == "true") ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
}
echo " </select>\n";
}
else {
echo " <input class='formfld' type='text' id='domain_setting_value' name='domain_setting_value' value=\"".escape($row['domain_setting_value'])."\">\n";
echo " <input class='formfld' type='text' id='domain_setting_value' name='domain_setting_value' value=\"".escape($row['domain_setting_value'] ?? '') ."\">\n";
}
echo "<br />\n";
echo $text['description-value']."\n";