From b5c65e004d72da6b9248c077a1d9dd7d6b3cd729 Mon Sep 17 00:00:00 2001 From: AlexC <40072887+alexdcrane@users.noreply.github.com> Date: Tue, 23 Nov 2021 18:34:00 -0700 Subject: [PATCH] Add dashboard edit with widget drag and drop (#6150) --- core/dashboard/index.php | 131 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 5 deletions(-) diff --git a/core/dashboard/index.php b/core/dashboard/index.php index a50bc247dc..ee6a05743e 100644 --- a/core/dashboard/index.php +++ b/core/dashboard/index.php @@ -85,6 +85,40 @@ $dashboard = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); +//get http post variables and set them to php variables + if (count($_POST) > 0 && permission_exists('dashboard_edit')) { + //set the variables from the http values + if (isset($_POST["widget_order"])) { + $widgets = explode(",", $_POST["widget_order"]); + $dashboard_order = '0'; + $x = 0; + foreach($widgets as $widget) { + foreach($dashboard as $row) { + $dashboard_name = strtolower($row['dashboard_name']); + $dashboard_name = str_replace(" ", "_", $dashboard_name); + if ($widget == $dashboard_name) { + $dashboard_order = $dashboard_order + 10; + $array['dashboard'][$x]['dashboard_name'] = $row['dashboard_name']; + $array['dashboard'][$x]['dashboard_uuid'] = $row['dashboard_uuid']; + $array['dashboard'][$x]['dashboard_order'] = $dashboard_order; + $x++; + } + } + } + + //save the data + $database = new database; + $database->app_name = 'dashboard'; + $database->app_uuid = '55533bef-4f04-434a-92af-999c1e9927f7'; + $database->save($array); + + //redirect the browser + message::add($text['message-update']); + header("Location: /core/dashboard/index.php"); + return; + } + } + //add multi-lingual support $language = new text; $text = $language->get(); @@ -93,6 +127,9 @@ $document['title'] = $text['title-dashboard']; require_once "resources/header.php"; +//include sortablejs + echo ""; + //include chart.js echo ""; @@ -133,6 +170,7 @@ \n"; echo "
\n"; echo "
".$text['title-dashboard']."
\n"; echo "
\n"; @@ -140,15 +178,24 @@ echo " ".$text['label-welcome']." ".$_SESSION["username"]."   "; } if (permission_exists('dashboard_edit')) { + if ($_GET['edit'] == 'true') { + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','name'=>'btn_back','link'=>'index.php']); + echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','name'=>'btn_save']); + } + else { + echo button::create(['type'=>'button','label'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'id'=>'btn_edit','name'=>'btn_edit','link'=>'index.php?edit=true']); + } echo button::create(['type'=>'button','label'=>$text['button-settings'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','name'=>'btn_add','link'=>'dashboard.php']); } echo "
\n"; echo "
".$text['description-dashboard']."
\n"; echo "
\n"; + echo "\n"; + echo "\n"; //display login message if (if_group("superadmin") && isset($_SESSION['login']['message']['text']) && $_SESSION['login']['message']['text'] != '') { - echo "
".$text['login-message_attention']."  ".$_SESSION['login']['message']['text']."  (".$text['login-message_dismiss'].")
"; + echo "
".$text['login-message_attention']."  ".$_SESSION['login']['message']['text']."  (".$text['login-message_dismiss'].")
\n"; } ?> @@ -208,12 +255,12 @@ \n"; + echo "
\n"; $x = 0; foreach($dashboard as $row) { - //if ($x > 3) { $class = 'col-num'; } - //echo "
"; - echo "
"; + $dashboard_name = strtolower($row['dashboard_name']); + $dashboard_name = str_replace(" ", "_", $dashboard_name); + echo "
\n"; include($row['dashboard_path']); echo "
\n"; $x++; @@ -223,4 +270,78 @@ //show the footer require_once "resources/footer.php"; +//begin edit + if ($_GET['edit'] == 'true') { + +?> + + + + +