Portions created by the Initial Developer are Copyright (C) 2021
the Initial Developer. All Rights Reserved.
*/
//includes
require_once "root.php";
require_once "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();
//action add or update
if (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 (is_array($_POST)) {
$dashboard_name = $_POST["dashboard_name"];
$dashboard_path = $_POST["dashboard_path"];
$dashboard_groups = $_POST["dashboard_groups"];
$dashboard_column_span = $_POST["dashboard_column_span"];
$dashboard_order = $_POST["dashboard_order"];
$dashboard_enabled = $_POST["dashboard_enabled"];
$dashboard_description = $_POST["dashboard_description"];
}
//delete the group from the sub table
if ($_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 = new database;
$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 && strlen($_POST["persistformvar"]) == 0) {
//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 ($_POST['action'] != '' && strlen($_POST['action']) > 0) {
//prepare the array(s)
//send the array to the database class
switch ($_POST['action']) {
case 'copy':
if (permission_exists('dashboard_add')) {
$obj = new database;
$obj->copy($array);
}
break;
case 'delete':
if (permission_exists('dashboard_delete')) {
$obj = new database;
$obj->delete($array);
}
break;
case 'toggle':
if (permission_exists('dashboard_update')) {
$obj = new database;
$obj->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 (strlen($dashboard_name) == 0) { $msg .= $text['message-required']." ".$text['label-dashboard_name']."
\n"; }
//if (strlen($dashboard_path) == 0) { $msg .= $text['message-required']." ".$text['label-dashboard_path']."
\n"; }
//if (strlen($dashboard_groups) == 0) { $msg .= $text['message-required']." ".$text['label-dashboard_groups']."
\n"; }
//if (strlen($dashboard_order) == 0) { $msg .= $text['message-required']." ".$text['label-dashboard_order']."
\n"; }
//if (strlen($dashboard_enabled) == 0) { $msg .= $text['message-required']." ".$text['label-dashboard_enabled']."
\n"; }
//if (strlen($dashboard_description) == 0) { $msg .= $text['message-required']." ".$text['label-dashboard_description']."
\n"; }
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "
\n";
echo $msg." "; echo " |