Portions created by the Initial Developer are Copyright (C) 2021-2024
the Initial Developer. All Rights Reserved.
*/
//includes files
require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('dashboard_add') || permission_exists('dashboard_edit')) {
//access granted
}
else {
echo "access denied";
exit;
}
//initialize the database
$database = new database;
//add multi-lingual support
$language = new text;
$text = $language->get();
//set the defaults
$dashboard_name = '';
$dashboard_path = 'dashboard/icon';
//$dashboard_path = '';
$dashboard_icon = '';
$dashboard_url = '';
$dashboard_target = 'self';
$dashboard_width = '';
$dashboard_height = '';
$dashboard_content = '';
$dashboard_content_text_align = '';
$dashboard_content_details = '';
$dashboard_label_enabled = 'true';
$dashboard_label_text_color = '';
$dashboard_label_background_color = '';
$dashboard_number_text_color = '';
$dashboard_groups = [];
$dashboard_column_span = '';
$dashboard_row_span = '';
$dashboard_details_state = '';
$dashboard_parent_uuid = '';
$dashboard_order = '';
$dashboard_enabled = 'true';
$dashboard_description = '';
$dashboard_uuid = '';
//action add or update
if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$action = "update";
$dashboard_uuid = $_REQUEST["id"];
$id = $_REQUEST["id"];
}
else {
$action = "add";
}
//get http post variables and set them to php variables
if (!empty($_POST)) {
$dashboard_name = $_POST["dashboard_name"] ?? '';
$dashboard_path = $_POST["dashboard_path"] ?? '';
$dashboard_icon = $_POST["dashboard_icon"] ?? '';
$dashboard_url = $_POST["dashboard_url"] ?? '';
$dashboard_target = $_POST["dashboard_target"] ?? 'self';
$dashboard_width = $_POST["dashboard_width"] ?? '';
$dashboard_height = $_POST["dashboard_height"] ?? '';
$dashboard_content = $_POST["dashboard_content"] ?? '';
$dashboard_content_text_align = $_POST["dashboard_content_text_align"] ?? '';
$dashboard_content_details = $_POST["dashboard_content_details"] ?? '';
$dashboard_groups = $_POST["dashboard_groups"] ?? '';
$dashboard_chart_type = $_POST["dashboard_chart_type"] ?? '';
$dashboard_label_enabled = $_POST["dashboard_label_enabled"] ?? 'false';
$dashboard_label_text_color = $_POST["dashboard_label_text_color"] ?? '';
$dashboard_label_text_color_hover = $_POST["dashboard_label_text_color_hover"] ?? '';
$dashboard_label_background_color = $_POST["dashboard_label_background_color"] ?? '';
$dashboard_label_background_color_hover = $_POST["dashboard_label_background_color_hover"] ?? '';
$dashboard_number_text_color = $_POST["dashboard_number_text_color"] ?? '';
$dashboard_number_text_color_hover = $_POST["dashboard_number_text_color_hover"] ?? '';
$dashboard_background_color = $_POST["dashboard_background_color"] ?? '';
$dashboard_background_color_hover = $_POST["dashboard_background_color_hover"] ?? '';
$dashboard_detail_background_color = $_POST["dashboard_detail_background_color"] ?? '';
$dashboard_background_gradient_style = $_POST["dashboard_background_gradient_style"] ?? 'mirror';
$dashboard_background_gradient_angle = $_POST["dashboard_background_gradient_angle"] ?? '90';
$dashboard_column_span = $_POST["dashboard_column_span"] ?? '';
$dashboard_row_span = $_POST["dashboard_row_span"] ?? '';
$dashboard_details_state = $_POST["dashboard_details_state"] ?? '';
$dashboard_parent_uuid = $_POST["dashboard_parent_uuid"] ?? '';
$dashboard_order = $_POST["dashboard_order"] ?? '';
$dashboard_enabled = $_POST["dashboard_enabled"] ?? 'false';
$dashboard_description = $_POST["dashboard_description"] ?? '';
//define the regex patterns
$uuid_pattern = '/[^-A-Fa-f0-9]/';
$number_pattern = '/[^-A-Za-z0-9()*#]/';
$text_pattern = '/[^a-zA-Z0-9 _\-\/.\?:\=#\n]/';
//sanitize the data
$dashboard_name = trim(preg_replace('/[^a-zA-Z0-9 _\-\/.#]/', '', $dashboard_name));
$dashboard_path = preg_replace($text_pattern, '', strtolower($dashboard_path));
$dashboard_icon = preg_replace($text_pattern, '', $dashboard_icon);
$dashboard_url = trim(preg_replace($text_pattern, '', $dashboard_url));
$dashboard_target = trim(preg_replace($text_pattern, '', $dashboard_target));
$dashboard_width = trim(preg_replace($text_pattern, '', $dashboard_width));
$dashboard_height = trim(preg_replace($text_pattern, '', $dashboard_height));
$dashboard_content = trim(preg_replace($text_pattern, '', $dashboard_content));
$dashboard_content_text_align = trim(preg_replace($text_pattern, '', $dashboard_content_text_align));
$dashboard_content_details = trim(preg_replace($text_pattern, '', $dashboard_content_details));
$dashboard_chart_type = preg_replace($text_pattern, '', $dashboard_chart_type);
$dashboard_label_enabled = preg_replace($text_pattern, '', $dashboard_label_enabled);
$dashboard_label_text_color = preg_replace($text_pattern, '', $dashboard_label_text_color);
$dashboard_label_text_color_hover = preg_replace($text_pattern, '', $dashboard_label_text_color_hover);
$dashboard_label_background_color = preg_replace($text_pattern, '', $dashboard_label_background_color);
$dashboard_label_background_color_hover = preg_replace($text_pattern, '', $dashboard_label_background_color_hover);
$dashboard_number_text_color = preg_replace($text_pattern, '', $dashboard_number_text_color);
$dashboard_number_text_color_hover = preg_replace($text_pattern, '', $dashboard_number_text_color_hover);
$dashboard_background_color = preg_replace($text_pattern, '', $dashboard_background_color);
$dashboard_background_color_hover = preg_replace($text_pattern, '', $dashboard_background_color_hover);
$dashboard_detail_background_color = preg_replace($text_pattern, '', $dashboard_detail_background_color);
$dashboard_background_gradient_style = preg_replace($text_pattern, '', $dashboard_background_gradient_style);
$dashboard_background_gradient_angle = preg_replace($text_pattern, '', $dashboard_background_gradient_angle);
$dashboard_column_span = preg_replace($number_pattern, '', $dashboard_column_span);
$dashboard_row_span = preg_replace($number_pattern, '', $dashboard_row_span);
$dashboard_details_state = preg_replace($text_pattern, '', $dashboard_details_state);
$dashboard_parent_uuid = preg_replace($uuid_pattern, '', $dashboard_parent_uuid);
$dashboard_order = preg_replace($number_pattern, '', $dashboard_order);
$dashboard_enabled = preg_replace($text_pattern, '', $dashboard_enabled);
$dashboard_description = preg_replace($text_pattern, '', $dashboard_description);
}
//delete the group from the sub table
if (isset($_REQUEST["a"]) && $_REQUEST["a"] == "delete" && permission_exists("dashboard_group_delete") && is_uuid($_GET["dashboard_group_uuid"]) && is_uuid($_GET["dashboard_uuid"])) {
//get the uuid
$dashboard_group_uuid = $_GET["dashboard_group_uuid"];
$dashboard_uuid = $_GET["dashboard_uuid"];
//delete the group from the users
$array['dashboard_groups'][0]['dashboard_group_uuid'] = $dashboard_group_uuid;
$database->app_name = 'dashboard';
$database->app_uuid = '55533bef-4f04-434a-92af-999c1e9927f7';
$database->delete($array);
unset($array);
//redirect the user
message::add($text['message-delete']);
header("Location: dashboard_edit.php?id=".urlencode($dashboard_uuid));
return;
}
//process the user data and save it to the database
if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: dashboard.php');
exit;
}
//process the http post data by submitted action
if (!empty($_POST['action'])) {
//prepare the array(s)
//send the array to the database class
switch ($_POST['action']) {
case 'copy':
if (permission_exists('dashboard_add')) {
$database->copy($array);
}
break;
case 'delete':
if (permission_exists('dashboard_delete')) {
$database->delete($array);
}
break;
case 'toggle':
if (permission_exists('dashboard_update')) {
$database->toggle($array);
}
break;
}
//redirect the user
if (in_array($_POST['action'], array('copy', 'delete', 'toggle'))) {
header('Location: dashboard_edit.php?id='.$id);
exit;
}
}
//check for all required data
$msg = '';
//if (empty($dashboard_name)) { $msg .= $text['message-required']." ".$text['label-dashboard_name']."
\n"; }
//if (empty($dashboard_path)) { $msg .= $text['message-required']." ".$text['label-dashboard_path']."
\n"; }
//if (empty($dashboard_groups)) { $msg .= $text['message-required']." ".$text['label-dashboard_groups']."
\n"; }
//if (empty($dashboard_order)) { $msg .= $text['message-required']." ".$text['label-dashboard_order']."
\n"; }
//if (empty($dashboard_enabled)) { $msg .= $text['message-required']." ".$text['label-dashboard_enabled']."
\n"; }
//if (empty($dashboard_description)) { $msg .= $text['message-required']." ".$text['label-dashboard_description']."
\n"; }
if (!empty($msg) && empty($_POST["persistformvar"])) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "
\n";
echo $msg." "; echo " |