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_add') || permission_exists('dashboard_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //set the defaults $domain_uuid = ''; $dashboard_uuid = ''; $dashboard_name = ''; $dashboard_description = ''; //action add or update if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { $action = "update"; $dashboard_uuid = $_REQUEST["id"]; $id = $_REQUEST["id"]; } else { $action = "add"; $domain_uuid = $_SESSION['domain_uuid']; } //get http post variables and set them to php variables if (!empty($_POST)) { $domain_uuid = permission_exists('dashboard_domain') ? $_POST["domain_uuid"] : $_SESSION['domain_uuid']; $dashboard_name = $_POST["dashboard_name"] ?? ''; $dashboard_enabled = $_POST["dashboard_enabled"]; $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 $domain_uuid = preg_replace($uuid_pattern, '', $domain_uuid); $dashboard_name = trim($dashboard_name); $dashboard_enabled = preg_replace($text_pattern, '', $dashboard_enabled); $dashboard_description = preg_replace($text_pattern, '', $dashboard_description); } //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; } //check for all required data $msg = ''; //if (empty($dashboard_name)) { $msg .= $text['message-required']." ".$text['label-dashboard_name']."
\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 "
\n"; echo $msg."
\n"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/footer.php"; return; } //add the dashboard_uuid if (!is_uuid($_POST["dashboard_uuid"])) { $dashboard_uuid = uuid(); } //prepare the array $array['dashboards'][0]['domain_uuid'] = $domain_uuid; $array['dashboards'][0]['dashboard_uuid'] = $dashboard_uuid; $array['dashboards'][0]['dashboard_name'] = $dashboard_name; $array['dashboards'][0]['dashboard_enabled'] = $dashboard_enabled; $array['dashboards'][0]['dashboard_description'] = $dashboard_description; //save the data $result = $database->save($array); //redirect the user if (isset($action)) { if ($action == "add") { $_SESSION["message"] = $text['message-add']; } if ($action == "update") { $_SESSION["message"] = $text['message-update']; } //header('Location: dashboard.php'); header('Location: dashboard_edit.php?id='.urlencode($dashboard_uuid)); return; } } //pre-populate the form if (empty($_POST["persistformvar"])) { $sql = "select "; $sql .= " domain_uuid, "; $sql .= " dashboard_uuid, "; $sql .= " dashboard_name, "; $sql .= " dashboard_enabled, "; $sql .= " dashboard_description "; $sql .= "from v_dashboards "; $sql .= "where dashboard_uuid = :dashboard_uuid "; $parameters['dashboard_uuid'] = $dashboard_uuid; $row = $database->select($sql, $parameters ?? null, 'row'); if (is_array($row) && @sizeof($row) != 0) { $domain_uuid = $row["domain_uuid"]; $dashboard_name = $row["dashboard_name"]; $dashboard_enabled = $row["dashboard_enabled"]; $dashboard_description = $row["dashboard_description"]; } unset($sql, $parameters, $row); } //set the defaults $dashboard_enabled = $dashboard_enabled ?? true; //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //show the header $document['title'] = $text['title-dashboard']; require_once "resources/header.php"; //show the content echo "
\n"; echo "\n"; echo "
\n"; echo "
".$text['title-dashboard']."
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'dashboard.php']); echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$settings->get('theme', 'button_icon_save'),'id'=>'btn_save','collapse'=>'hide-xs']); echo "
\n"; echo "
\n"; echo "
\n"; //echo $text['title_description-dashboard']."\n"; //echo "

\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists('dashboard_domain')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo $text['label-dashboard_name'] ?? ''; echo "\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-dashboard_name']."\n"; echo "
\n"; echo " ".$text['label-domain']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-domain_name']."\n"; echo "
\n"; echo " ".$text['label-dashboard_enabled']."\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-dashboard_enabled']."\n"; echo "
\n"; echo " ".$text['label-dashboard_description']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-dashboard_description']."\n"; echo "
\n"; echo "
\n"; echo "

\n"; echo "\n"; echo "
\n"; if ($action == "update") { require_once "core/dashboard/dashboard_widget_list.php"; } //include the footer require_once "resources/footer.php"; ?>