forked from emoncms/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard_controller.php
More file actions
87 lines (74 loc) · 4.02 KB
/
dashboard_controller.php
File metadata and controls
87 lines (74 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/*
All Emoncms code is released under the GNU Affero General Public License.
See COPYRIGHT.txt and LICENSE.txt.
---------------------------------------------------------------------
Emoncms - open source energy visualisation
Part of the OpenEnergyMonitor project:
http://openenergymonitor.org
*/
defined('EMONCMS_EXEC') or die('Restricted access');
function dashboard_controller()
{
global $mysqli, $session, $route, $path;
require "Modules/dashboard/dashboard_model.php";
$dashboard = new Dashboard($mysqli);
// id, userid, content, height, name, alias, description, main, public, published, showdescription
$js_css_version = 5;
$result = false; $submenu = '';
if ($route->format == 'html')
{
if ($route->action == "list" && $session['write'])
{
load_language_files("Modules/dashboard/locale", "dashboard_messages");
$result = view("Modules/dashboard/Views/dashboard_list.php", array(
'js_css_version' => $js_css_version,
'path' => $path,
'gridjs' => view('Lib/gridjs/grid.html')
));
}
else if ($route->action == "view")
{
$dashid =(int) get('id');
if ($dashid) {
$dash = $dashboard->get($dashid);
} else if ($session['read']) {
if ($route->subaction) $dash = $dashboard->get_from_alias($session['userid'],$route->subaction);
else $dash = $dashboard->get_main($session['userid']);
} else if (!$session['read']) {
if ($route->subaction) $dash = $dashboard->get_from_public_alias($route->subaction);
}
if (isset($dash)){
if ($dash['public'] || ($session['read'] && $session['userid']>0 && $dash['userid']==$session['userid'] && !isset($session['profile']) )) {
if (!$session['userid']) { $session['userid'] = $dash['userid']; } // Required for passing userid to feed api
$result = view("Modules/dashboard/Views/dashboard_view.php",array('dashboard'=>$dash, 'js_css_version'=>$js_css_version));
} else if ($session['read'] && !isset($session['profile'])) {
$result = view("Modules/dashboard/Views/dashboard_list.php", array('js_css_version'=>$js_css_version));
}
}
}
else if ($route->action == "edit" && $session['write'])
{
if ($route->subaction) $dash = $dashboard->get_from_alias($session['userid'],$route->subaction);
elseif (isset($_GET['id'])) $dash = $dashboard->get(get('id'));
$result = view("Modules/dashboard/Views/dashboard_edit_view.php",array('dashboard'=>$dash, 'js_css_version'=>$js_css_version));
$result .= view("Modules/dashboard/Views/dashboard_config.php", array('dashboard'=>$dash, 'js_css_version'=>$js_css_version));
$submenu = view("Modules/dashboard/Views/dashboard_menu.php", array('id'=>$dash['id'],'type'=>"edit", 'js_css_version'=>$js_css_version));
}
}
else if ($route->format == 'json')
{
if ($session['read']) {
if ($route->action=='list') $result = $dashboard->get_list($session['userid'], false, false);
}
if ($session['write']) {
if ($route->action=='set') $result = $dashboard->set($session['userid'],prop('id'),prop('fields'));
else if ($route->action=='getcontent') $result = $dashboard->get_content($session['userid'],get('id'));
else if ($route->action=='setcontent') $result = $dashboard->set_content($session['userid'],post('id'),post('content'),post('height'));
else if ($route->action=='create') $result = $dashboard->create($session['userid']);
else if ($route->action=='delete') $result = $dashboard->delete(get('id'));
else if ($route->action=='clone') $result = $dashboard->dashclone($session['userid'], get('id'));
}
}
return array('content'=>$result, 'submenu'=>$submenu);
}