-
Notifications
You must be signed in to change notification settings - Fork 517
/
Copy pathmenu_view.php
147 lines (133 loc) · 6.04 KB
/
menu_view.php
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/*
All Emoncms code is released under the GNU General Public License v3.
See COPYRIGHT.txt and LICENSE.txt.
---------------------------------------------------------------------
Emoncms - open source energy visualisation
Part of the OpenEnergyMonitor project: http://openenergymonitor.org
*/
global $path, $session, $menu;
if (!isset($session['profile'])) $session['profile'] = 0;
// Example how to add a fixed menu item:
//$menu['dropdownconfig'][] = array('name'=>'Documentation', 'icon'=>'icon-book', 'path'=>"docs", 'session'=>"write", 'order' => 60,'divider' => true);
usort($menu['left'], "menu_sort");
usort($menu['dropdown'], "menu_sort");
usort($menu['dropdownconfig'], "menu_sort");
usort($menu['right'], "menu_sort");
function drawItem($item)
{
global $path,$session;
$out="";
if (isset($item['session'])) {
if ((isset($session[$item['session']]) && ($session[$item['session']]==1)) || $item['session'] == 'all') {
$i = 0;
$subactive = false;
if (isset($item['dropdown']) && count($item['dropdown']) > 0) {
usort($item['dropdown'], "menu_sort");
$outdrop="";
foreach ($item['dropdown'] as $dropdownitem) {
if (!isset($dropdownitem['session']) || (isset($dropdownitem['session']) && $session[$dropdownitem['session']]==1)) {
$i++;
if (is_active($dropdownitem)) { $subactive = true; }
if (isset($dropdownitem['divider']) && $dropdownitem['divider']) { $outdrop .= '<li class="divider"></li>'; }
// TODO: Remove dependency of index position on APPs module
$outdrop .= '<li class="'. (is_active($dropdownitem) ? ' active' : '') . '"><a href="' . $path . (isset($dropdownitem['path']) ? $dropdownitem['path']:$dropdownitem['1']) . '">' . (isset($dropdownitem['name']) ? drawNameIcon($dropdownitem,true) : $dropdownitem['0']) . '</a></li>';
}
}
}
$show = true; if (isset($item['hideinactive']) && $item['hideinactive']) $show = false;
if (is_active($item)) $show = true;
if ($i > 0) {
$out .= '<li class="dropdown' . ($subactive ? " active" : "") . (isset($item['class']) ? " ".$item['class'] : "") . '">';
$out .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown">' . drawNameIcon($item,false) . '<b class="caret"></b></a>';
$out .= '<ul class="dropdown-menu scrollable-menu">';
$out .= $outdrop;
$out .= '</ul></li>';
}
else if (isset($item['path']) && isset($item['name'])) {
if ($show) $out .= "<li class='" . (is_active($item) ? "active" : "") . (isset($item['class']) ? " ".$item['class'] : "") ."'><a href=\"".$path.$item['path']."\">" . drawNameIcon($item,false) . "</a></li>";
}
}
} else {
$out .= "<li class='" . (is_active($item) ? "active" : "") . (isset($item['class']) ? " ".$item['class'] : "") . "'><a href=\"".$path.$item['path']."\">" . drawNameIcon($item,false) . "</a></li>";
}
return $out;
}
function drawNameIcon($item, $alwaysshowname=false) {
$out = "";
$name = false;
$desc = false;
$icon = false;
$published = false;
$divid = "";
if (isset($item['name'])) $name = $item['name'];
if (isset($item['desc'])) $desc = $item['desc'];
if (isset($item['icon'])) $icon = $item['icon'];
if (isset($item['published'])) $published = $item['published'];
if (isset($item['id'])) $divid = "id='".$item['id']."'";
$title = ($desc ? $desc : $name);
if($name && $published) $name = "<b>".$name."</b>";
$out = "<div $divid style='display: inline'>";
if ($icon) $out .= "<i class='".$icon."'" . ($title ? " title='".$title."'" : "") . "></i>";
if ($name) {
if ($alwaysshowname || !$icon) {
$out .= " " . $name;
} else {
$out .= " <span class='menu-text'>" . $name . "</span>";
}
} else {
$out .= 'unknown';
}
if ($desc) $out .= "<span class='menu-description'><small>".$desc."</small></span>";
$out .= "</div>";
return $out;
}
function is_active($item) {
global $route;
if (isset($item['path']) && ($item['path'] == $route->controller."/".$route->action || $item['path'] == $route->controller."/".$route->action."/".$route->subaction || $item['path'] == $route->controller."/".$route->action."&id=".get('id')))
return true;
return false;
}
// Menu sort by order
function menu_sort($a,$b) {
return $a['order']>$b['order'];
}
?>
<ul class="nav">
<?php
foreach ($menu['dashboard'] as $item) {
$item['class'] = 'menu-dashboard';
echo drawItem($item);
}
foreach ($menu['left'] as $item) {
$item['class'] = 'menu-left';
echo drawItem($item);
}
?>
</ul>
<ul class="nav pull-right">
<?php
if (count($menu['dropdown']) && $session['read']) {
$extra = array();
$extra['name'] = 'Extra';
$extra['icon'] = 'icon-plus icon-white';
$extra['class'] = 'menu-extra';
$extra['session'] = 'read';
$extra['dropdown'] = $menu['dropdown'];
echo drawItem($extra);
}
if (count($menu['dropdownconfig'])) {
$setup = array();
$setup['name'] = 'Setup';
$setup['icon'] = 'icon-wrench icon-white';
$setup['class'] = 'menu-setup';
$setup['session'] = 'read';
$setup['dropdown'] = $menu['dropdownconfig'];
echo drawItem($setup);
}
foreach ($menu['right'] as $item) {
$item['class'] = 'menu-right';
echo drawItem($item);
}
?>
</ul>