Portions created by the Initial Developer are Copyright (C) 2021-2025
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_widget_add') || permission_exists('dashboard_widget_edit')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//set the defaults
$widget_uuid = '';
$widget_name = '';
$widget_path = 'dashboard/icon';
$widget_icon = '';
$widget_icon_color = '';
$widget_url = '';
$widget_target = 'self';
$widget_width = '';
$widget_height = '';
$widget_content = '';
$widget_content_text_align = '';
$widget_content_details = '';
$widget_groups = [];
$widget_label_enabled = '';
$widget_label_text_color = '';
$widget_label_text_color_hover = '';
$widget_label_background_color = '';
$widget_label_background_color_hover = '';
$widget_number_text_color = '';
$widget_number_background_color = '';
$widget_column_span = '';
$widget_row_span = '';
$widget_details_state = '';
$widget_parent_uuid = '';
$widget_order = '';
$widget_enabled = '';
$widget_description = '';
//action add or update
if (!empty($_REQUEST["widget_uuid"]) && is_uuid($_REQUEST["widget_uuid"])) {
$action = "update";
$dashboard_uuid = $_REQUEST["id"];
$widget_uuid = $_REQUEST["widget_uuid"];
}
else {
$action = "add";
$dashboard_uuid = $_REQUEST["id"];
}
//get http post variables and set them to php variables
if (!empty($_POST)) {
$widget_name = $_POST["widget_name"] ?? '';
$widget_path = $_POST["widget_path"] ?? '';
$widget_icon = $_POST["widget_icon"] ?? '';
$widget_icon_color = $_POST["widget_icon_color"] ?? '';
$widget_url = $_POST["widget_url"] ?? '';
$widget_target = $_POST["widget_target"] ?? 'self';
$widget_width = $_POST["widget_width"] ?? '';
$widget_height = $_POST["widget_height"] ?? '';
$widget_content = $_POST["widget_content"] ?? '';
$widget_content_text_align = $_POST["widget_content_text_align"] ?? '';
$widget_content_details = $_POST["widget_content_details"] ?? '';
$widget_groups = $_POST["dashboard_widget_groups"] ?? '';
$widget_chart_type = $_POST["widget_chart_type"] ?? '';
$widget_label_enabled = $_POST["widget_label_enabled"];
$widget_label_text_color = $_POST["widget_label_text_color"] ?? '';
$widget_label_text_color_hover = $_POST["widget_label_text_color_hover"] ?? '';
$widget_label_background_color = $_POST["widget_label_background_color"] ?? '';
$widget_label_background_color_hover = $_POST["widget_label_background_color_hover"] ?? '';
$widget_number_text_color = $_POST["widget_number_text_color"] ?? '';
$widget_number_text_color_hover = $_POST["widget_number_text_color_hover"] ?? '';
$widget_number_background_color = $_POST["widget_number_background_color"] ?? '';
$widget_background_color = $_POST["widget_background_color"] ?? '';
$widget_background_color_hover = $_POST["widget_background_color_hover"] ?? '';
$widget_detail_background_color = $_POST["widget_detail_background_color"] ?? '';
$widget_background_gradient_style = $_POST["widget_background_gradient_style"] ?? 'mirror';
$widget_background_gradient_angle = $_POST["widget_background_gradient_angle"] ?? '90';
$widget_column_span = $_POST["widget_column_span"] ?? '';
$widget_row_span = $_POST["widget_row_span"] ?? '';
$widget_details_state = $_POST["widget_details_state"] ?? '';
$widget_parent_uuid = $_POST["dashboard_widget_parent_uuid"] ?? '';
$widget_order = $_POST["widget_order"] ?? '';
$widget_enabled = $_POST["widget_enabled"];
$widget_description = $_POST["widget_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
$widget_name = trim($widget_name);
$widget_path = preg_replace($text_pattern, '', strtolower($widget_path));
$widget_icon = preg_replace($text_pattern, '', $widget_icon);
$widget_icon_color = preg_replace($text_pattern, '', $widget_icon_color);
$widget_url = trim(preg_replace($text_pattern, '', $widget_url));
$widget_target = trim(preg_replace($text_pattern, '', $widget_target));
$widget_width = trim(preg_replace($text_pattern, '', $widget_width));
$widget_height = trim(preg_replace($text_pattern, '', $widget_height));
$widget_content = trim($widget_content);
$widget_content_text_align = trim(preg_replace($text_pattern, '', $widget_content_text_align));
$widget_content_details = trim(preg_replace($text_pattern, '', $widget_content_details));
$widget_chart_type = preg_replace($text_pattern, '', $widget_chart_type);
$widget_label_enabled = preg_replace($text_pattern, '', $widget_label_enabled);
$widget_label_text_color = preg_replace($text_pattern, '', $widget_label_text_color);
$widget_label_text_color_hover = preg_replace($text_pattern, '', $widget_label_text_color_hover);
$widget_label_background_color = preg_replace($text_pattern, '', $widget_label_background_color);
$widget_label_background_color_hover = preg_replace($text_pattern, '', $widget_label_background_color_hover);
$widget_number_text_color = preg_replace($text_pattern, '', $widget_number_text_color);
$widget_number_text_color_hover = preg_replace($text_pattern, '', $widget_number_text_color_hover);
$widget_number_background_color = preg_replace($text_pattern, '', $widget_number_background_color);
$widget_background_color = preg_replace($text_pattern, '', $widget_background_color);
$widget_background_color_hover = preg_replace($text_pattern, '', $widget_background_color_hover);
$widget_detail_background_color = preg_replace($text_pattern, '', $widget_detail_background_color);
$widget_background_gradient_style = preg_replace($text_pattern, '', $widget_background_gradient_style);
$widget_background_gradient_angle = preg_replace($text_pattern, '', $widget_background_gradient_angle);
$widget_column_span = preg_replace($number_pattern, '', $widget_column_span);
$widget_row_span = preg_replace($number_pattern, '', $widget_row_span);
$widget_details_state = preg_replace($text_pattern, '', $widget_details_state);
$widget_parent_uuid = preg_replace($uuid_pattern, '', $widget_parent_uuid);
$widget_order = preg_replace($number_pattern, '', $widget_order);
$widget_enabled = preg_replace($text_pattern, '', $widget_enabled);
$widget_description = preg_replace($text_pattern, '', $widget_description);
}
//delete the group from the sub table
if (!empty($_POST["action"]) && $_POST["action"] === "delete" && permission_exists("dashboard_widget_group_delete") && is_uuid($_POST["dashboard_widget_group_uuid"]) && is_uuid($_POST["dashboard_widget_uuid"])) {
//get the uuid
$widget_group_uuid = $_POST['dashboard_widget_group_uuid'];
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: dashboard_edit.php?id='.urlencode($dashboard_uuid));
exit;
}
//delete the group from the widget
$array['dashboard_widget_groups'][0]['dashboard_widget_group_uuid'] = $widget_group_uuid;
$database->delete($array);
unset($array);
//redirect the user
message::add($text['message-delete']);
header("Location: dashboard_widget_edit.php?id=".urlencode($dashboard_uuid)."&widget_uuid=".urlencode($widget_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_edit.php?id='.urlencode($dashboard_uuid));
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_widget_add')) {
$database->copy($array);
}
break;
case 'delete':
if (permission_exists('dashboard_widget_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='.urlencode($dashboard_uuid));
exit;
}
}
//check for all required data
$msg = '';
//if (empty($widget_name)) { $msg .= $text['message-required']." ".$text['label-widget_name']."
\n"; }
//if (empty($widget_path)) { $msg .= $text['message-required']." ".$text['label-widget_path']."
\n"; }
//if (empty($widget_groups)) { $msg .= $text['message-required']." ".$text['label-widget_groups']."
\n"; }
//if (empty($widget_order)) { $msg .= $text['message-required']." ".$text['label-widget_order']."
\n"; }
//if (empty($widget_enabled)) { $msg .= $text['message-required']." ".$text['label-widget_enabled']."
\n"; }
//if (empty($widget_description)) { $msg .= $text['message-required']." ".$text['label-widget_description']."
\n"; }
if (!empty($msg) && empty($_POST["persistformvar"])) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "
| \n";
echo $msg." \n"; echo " |
| \n"; echo $text['label-widget_name'] ?? ''; echo "\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_name']."\n"; echo " | \n";
echo "||
| \n"; echo " ".$text['label-widget_path']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_path']."\n"; echo " | \n";
echo "||
| ".$text['label-icon']." | \n"; echo "\n";
if (file_exists($_SERVER["PROJECT_ROOT"].'/resources/fontawesome/fa_icons.php')) {
include $_SERVER["PROJECT_ROOT"].'/resources/fontawesome/fa_icons.php';
}
if (!empty($font_awesome_icons) && is_array($font_awesome_icons)) {
echo "
| \n";
echo " ||
| \n"; echo $text['label-widget_icon_color']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_icon_color']."\n"; echo " | \n";
echo "||
| \n"; echo " ".$text['label-link']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_url'] ?? ''; echo "\n"; echo " | \n";
echo "||
| \n"; echo $text['label-target']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_target']."\n"; echo " | \n";
echo "||
| \n"; echo " ".$text['label-width']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_width'] ?? ''; echo "\n"; echo " | \n";
echo "||
| \n"; echo " ".$text['label-height']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_height'] ?? ''; echo "\n"; echo " | \n";
echo "||
| \n"; echo " ".$text['label-content']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_content']."\n"; echo " | \n";
echo "||
| \n"; echo " ".$text['label-widget_content_text_align']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_content_text_align']."\n"; echo " | \n";
echo "||
| \n"; echo " ".$text['label-details']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_content_details']."\n"; echo " | \n";
echo "||
| \n"; echo " ".$text['label-widget_groups']."\n"; echo " | \n"; echo "\n";
if (is_array($widget_groups) && sizeof($widget_groups) != 0) {
echo "
\n"; } echo "\n"; echo button::create(['type'=>'submit','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add')]); } echo " \n"; echo $text['description-widget_groups']."\n"; echo " | \n";
echo "||
| \n"; echo $text['label-widget_chart_type']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n";
echo " \n";
echo " \n";
echo " \n";
echo " \n";
echo " \n";
echo $text['description-widget_chart_type']."\n";
echo " | \n";
echo "||
| \n"; echo $text['label-widget_label_enabled'] ?? ''; echo "\n"; echo " | \n"; echo "\n";
if ($input_toggle_style_switch) {
echo " \n";
}
echo " \n";
if ($input_toggle_style_switch) {
echo " \n";
echo " \n";
}
echo " \n"; echo $text['description-widget_label_enabled']."\n"; echo " | \n";
echo "||
| \n"; echo $text['label-widget_label_text_color']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_label_text_color']."\n"; echo " | \n";
echo "||
| \n"; echo $text['label-widget_label_text_color_hover']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_label_text_color_hover']."\n"; echo " | \n";
echo "||
| \n"; echo $text['label-widget_label_background_color']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_label_background_color']."\n"; echo " | \n";
echo "||
| \n"; echo $text['label-widget_label_background_color_hover']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_label_background_color_hover']."\n"; echo " | \n";
echo "||
| \n"; echo $text['label-widget_number_text_color']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_number_text_color']."\n"; echo " | \n";
echo "||
| \n"; echo $text['label-widget_number_text_color_hover']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_number_text_color_hover']."\n"; echo " | \n";
echo "||
| \n"; echo $text['label-widget_number_background_color']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_number_background_color']."\n"; echo " | \n";
echo "||
| \n"; echo $text['label-widget_background_color']."\n"; echo " | \n"; echo "\n";
if (!empty($widget_background_color) && is_array($widget_background_color)) {
foreach ($widget_background_color as $c => $background_color) {
echo " \n";
if ($c < sizeof($widget_background_color) - 1) { echo " \n"; } } //swap button if (!empty($widget_background_color) && is_array($widget_background_color) && sizeof($widget_background_color) > 1) { echo " \n"; echo button::create(['type'=>'button','title'=>$text['button-swap'],'icon'=>'fa-solid fa-arrow-right-arrow-left fa-rotate-90','style'=>"z-index: 0; position: absolute; display: inline-block; margin: -14px 0 0 7px;",'onclick'=>"document.getElementById('widget_background_color_temp').value = document.getElementById('widget_background_color_0').value; document.getElementById('widget_background_color_0').value = document.getElementById('widget_background_color_1').value; document.getElementById('widget_background_color_1').value = document.getElementById('widget_background_color_temp').value; this.blur();"])." \n"; } else { echo " \n"; } } if (empty($widget_background_color) || (is_array($widget_background_color) && count($widget_background_color) < 2)) { echo " \n"; if (empty($widget_background_color)) { echo " \n"; } } if (!empty($widget_background_color) && !is_array($widget_background_color)) { echo " \n"; echo " \n"; } echo $text['description-widget_background_color']."\n"; echo " | \n";
echo "||
| \n"; echo $text['label-widget_background_color_hover']."\n"; echo " | \n"; echo "\n";
if (!empty($widget_background_color_hover) && is_array($widget_background_color_hover)) {
foreach ($widget_background_color_hover as $c => $background_color) {
echo " \n";
if ($c < sizeof($widget_background_color_hover) - 1) { echo " \n"; } } //swap button if (!empty($widget_background_color_hover) && is_array($widget_background_color_hover) && sizeof($widget_background_color_hover) > 1) { echo " \n"; echo button::create(['type'=>'button','title'=>$text['button-swap'],'icon'=>'fa-solid fa-arrow-right-arrow-left fa-rotate-90','style'=>"z-index: 0; position: absolute; display: inline-block; margin: -14px 0 0 7px;",'onclick'=>"document.getElementById('widget_background_color_hover_temp').value = document.getElementById('widget_background_color_hover_0').value; document.getElementById('widget_background_color_hover_0').value = document.getElementById('widget_background_color_hover_1').value; document.getElementById('widget_background_color_hover_1').value = document.getElementById('widget_background_color_hover_temp').value; this.blur();"])." \n"; } else { echo " \n"; } } if (empty($widget_background_color_hover) || (is_array($widget_background_color_hover) && count($widget_background_color_hover) < 2)) { echo " \n"; if (empty($widget_background_color_hover)) { echo " \n"; } } if (!empty($widget_background_color_hover) && !is_array($widget_background_color_hover)) { echo " \n"; echo " \n"; } echo $text['description-widget_background_color_hover']."\n"; echo " | \n";
echo "||
| \n"; echo $text['label-widget_detail_background_color']."\n"; echo " | \n"; echo "\n";
if (!empty($widget_detail_background_color) && is_array($widget_detail_background_color)) {
foreach ($widget_detail_background_color as $c => $detail_background_color) {
echo " \n";
if ($c < sizeof($widget_detail_background_color) - 1) { echo " \n"; } } //swap button if (!empty($widget_detail_background_color) && is_array($widget_detail_background_color) && sizeof($widget_detail_background_color) > 1) { echo " \n"; echo button::create(['type'=>'button','title'=>$text['button-swap'],'icon'=>'fa-solid fa-arrow-right-arrow-left fa-rotate-90','style'=>"z-index: 0; position: absolute; display: inline-block; margin: -14px 0 0 7px;",'onclick'=>"document.getElementById('widget_detail_background_color_temp').value = document.getElementById('widget_detail_background_color_0').value; document.getElementById('widget_detail_background_color_0').value = document.getElementById('widget_detail_background_color_1').value; document.getElementById('widget_detail_background_color_1').value = document.getElementById('widget_detail_background_color_temp').value; this.blur();"])." \n"; } else { echo " \n"; } } if (empty($widget_detail_background_color) || (is_array($widget_detail_background_color) && count($widget_detail_background_color) < 2)) { echo " \n"; if (empty($widget_detail_background_color)) { echo " \n"; } } if (!empty($widget_detail_background_color) && !is_array($widget_detail_background_color)) { echo " \n"; echo " \n"; } echo $text['description-widget_detail_background_color']."\n"; echo " | \n";
echo "||
| \n"; echo $text['label-widget_background_gradient_style']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_background_gradient_style']."\n"; echo " | \n";
echo "||
| \n"; echo $text['label-widget_background_gradient_angle']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n";
echo " ―\n";
echo " \n";
echo $text['description-widget_background_gradient_angle']."\n";
echo " | \n";
echo "||
| \n"; echo " ".$text['label-widget_column_span']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_column_span']."\n"; echo " | \n";
echo "||
| \n"; echo " ".$text['label-widget_row_span']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_row_span']."\n"; echo " | \n";
echo "||
| \n"; echo " ".$text['label-widget_details_state']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_details_state']."\n"; echo " | \n";
echo "||
| ".$text['label-dashboard_widget_parent_uuid']." | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-dashboard_widget_parent_uuid']."\n"; echo " | \n";
echo " ||
| \n"; echo " ".$text['label-widget_order']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_order']."\n"; echo " | \n";
echo "||
| \n"; echo " ".$text['label-widget_enabled']."\n"; echo " | \n"; echo "\n";
if ($input_toggle_style_switch) {
echo " \n";
}
echo " \n";
if ($input_toggle_style_switch) {
echo " \n";
echo " \n";
}
echo " \n"; echo $text['description-widget_enabled']."\n"; echo " | \n";
echo "||
| \n"; echo " ".$text['label-widget_description']."\n"; echo " | \n"; echo "\n";
echo " \n";
echo " \n"; echo $text['description-widget_description']."\n"; echo " | \n";
echo "