*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
use LibreNMS\Config;
/*
* Code for Gridster.sort_by_row_and_col_asc(serialization) call is from http://gridster.net/demos/grid-from-serialize.html
*/
$no_refresh = true;
$default_dash = get_user_pref('dashboard', 0);
require_once 'includes/html/modal/alert_notes.inc.php';
require_once 'includes/html/modal/alert_ack.inc.php';
// get all dashboards this user can access and put them into two lists user_dashboards and shared_dashboards
$dashboards = get_dashboards();
list($user_dashboards, $shared_dashboards) = array_reduce($dashboards, function ($ret, $dash) {
if ($dash['user_id'] == Auth::id()) {
$ret[0][] = $dash;
} else {
$ret[1][] = $dash;
}
return $ret;
}, array());
// if the default dashboard doesn't exist, set it to the global default or to 0
if (!isset($dashboards[$default_dash])) {
$global_default = (int)Config::get('webui.default_dashboard_id');
$default_dash = isset($dashboards[$global_default]) ? $global_default : 0;
}
// if there are no possible dashboards, add one
if ($default_dash == 0 && empty($user_dashboards)) {
$new_dash = array(
'dashboard_name'=>'Default',
'user_id'=>Auth::id(),
);
$dashboard_id = dbInsert($new_dash, 'dashboards');
$new_dash['dashboard_id'] = $dashboard_id;
$new_dash['username'] = Auth::user()->username;
$vars['dashboard'] = $new_dash;
if (dbFetchCell('select 1 from users_widgets where user_id = ? && dashboard_id = ?', array(Auth::id(),0)) == 1) {
dbUpdate(array('dashboard_id'=>$dashboard_id), 'users_widgets', 'user_id = ? && dashboard_id = ?', array(Auth::id(), 0));
}
} else {
// load a dashboard
$orig = $vars['dashboard'];
if (!empty($orig) && isset($dashboards[$orig])) {
// specific dashboard
$vars['dashboard'] = $dashboards[$orig];
} else {
// load a default dashboard
$vars['dashboard'] = $default_dash == 0 ? current($user_dashboards) : $dashboards[$default_dash];
// $dashboard was requested, but doesn't exist
if (!empty($orig)) {
Toastr::error('Dashboard #' . $orig .
'
does not exist! Loaded ' . htmlentities($vars['dashboard']['dashboard_name']) .
'
instead.', 'Requested Dashboard Not Found!');
}
}
}
$data = dbFetchRows(
'SELECT `user_widget_id`,`users_widgets`.`widget_id`,`title`,`widget`,`col`,`row`,`size_x`,`size_y`,`refresh` FROM `users_widgets`
LEFT JOIN `widgets` ON `widgets`.`widget_id`=`users_widgets`.`widget_id` WHERE `dashboard_id`=?',
array($vars['dashboard']['dashboard_id'])
);
if (empty($data)) {
$data[] = array('user_widget_id'=>'0','widget_id'=>1,'title'=>'Add a widget','widget'=>'placeholder','col'=>1,'row'=>1,'size_x'=>6,'size_y'=>2,'refresh'=>60);
}
$data = serialize(json_encode($data));
$dash_config = unserialize(stripslashes($data));
if (empty($vars['bare']) || $vars['bare'] == "no") {
?>