-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnav.php
249 lines (179 loc) · 6.84 KB
/
nav.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
/*
Copyright 2018 The Zhou Laboratory, Earlham Institute, Norwich, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
?>
<?php
if (!isset($_SESSION['project_selection'])) {
$projects = $sql->query("SELECT * FROM " . $sqldatabase . ".projectgroup WHERE active=1;");
if ($result = $projects->fetch_assoc()) {
$_SESSION['project_selection'] = $result['groupid'];
} //$result = $projects->fetch_assoc()
else {
$_SESSION['project_selection'] = '';
}
} //!isset($_SESSION['project_selection'])
$nodeselection = "none";
$class = "navButtonGrey";
if (!isset($_SESSION['view'])) {
$_SESSION['view'] = 'list';
} //!isset($_SESSION['view'])
if (isset($_GET['view'])) {
if ($_GET['view'] == 'grid') {
$_SESSION['view'] = 'grid';
} //$_GET['view'] == 'grid'
else {
$_SESSION['view'] = 'list';
}
} //isset($_GET['view'])
if ($authorised == true) {
?>
<div id="navbar">
<?php
if ($admin) {
if (isset($_GET['selection'])) {
$_SESSION['project_selection'] = $sql->real_escape_string($_GET['selection']);
} //isset($_GET['selection'])
elseif (isset($_GET['page']) && $_GET['page'] == 'admin') {
$class = "navButton";
} //isset($_GET['page']) && $_GET['page'] == 'admin'
?>
<div style="float: right">
<?php
include('loginstate.php');
?>
<a href="index.php?page=admin" class="<?php
echo $class;
?>">Admin</a>
</div>
<?php
$projects = $sql->query("SELECT * FROM " . $sqldatabase . ".projectgroup WHERE active=1");
while ($project = $projects->fetch_assoc()) {
if ($_SESSION['project_selection'] == $project['groupid']) {
$class = "navButton";
} //$_SESSION['project_selection'] == $project['groupid']
else {
$class = "navButtonGrey";
}
?>
<a href="index.php?selection=<?php
echo $project['groupid'];
?>" class="<?php
echo $class;
?>"><?php
echo $project['name'];
?></a>
<?php
} //$project = $projects->fetch_assoc()
?>
<div class="dropdown">
<button onclick="historicaldatabutton()" class="dropbtn">Historical Data</button>
<div id="historicaldata" class="dropdown-content">
<?php
$projects = $sql->query("SELECT * FROM " . $sqldatabase . ".projectgroup WHERE active=0");
while ($project = $projects->fetch_assoc()) {
?>
<a href="index.php?selection=<?php
echo $project['groupid'];
?>"><?php
echo $project['name'];
?></a>
<?php
} //$project = $projects->fetch_assoc()
?>
</div>
</div>
<?php
} //$admin
} //$authorised == true
else {
?>
<div style="float: right">
<?php
include('loginstate.php');
?>
</div>
<?php
if (isset($_GET['selection'])) {
$_SESSION['project_selection'] = $sql->real_escape_string($_GET['selection']);
$permissiontest = $sql->query("SELECT COUNT(email) as total FROM " . $sqldatabase . ".permissions WHERE email='" . $_SESSION['email'] . "' AND projectid='" . $_SESSION['project_selection'] . "';");
$permissioncount = $permissiontest->fetch_assoc();
if ($permissioncount['total'] == 0) {
$projectselection = "none";
} //$permissioncount['total'] == 0
} //isset($_GET['selection'])
if (isset($_SESSION['email'])) {
$permissions = $sql->query("SELECT * FROM " . $sqldatabase . ".permissions WHERE email='" . $_SESSION['email'] . "';");
while ($project = $permissions->fetch_assoc()) {
if ($_SESSION['project_selection'] == "none") {
$_SESSION['project_selection'] = $project['projectid'];
} //$_SESSION['project_selection'] == "none"
if ($_SESSION['project_selection'] == $project['projectid']) {
$class = "navButton";
} //$_SESSION['project_selection'] == $project['projectid']
else {
$class = "navButtonGrey";
}
} //$project = $permissions->fetch_assoc()
$details = $sql->query("SELECT * FROM " . $sqldatabase . ".projects WHERE projectid='" . $project['projectid'] . "';");
$res = $details->fetch_assoc();
?>
<a href="index.php?selection=<?php
echo $res['projectid'];
?>" class="<?php
echo $class;
?>"><?php
echo $res['description'];
?></a>
<?php
} //isset($_SESSION['email'])
}
?>
</div>
<?php
if (isset($_GET['node'])) {
$nodeproject = $sql->query("SELECT projectid from " . $sqldatabase . ".pistatus WHERE macaddress = '" . $sql->real_escape_string($_GET['node']) . "';");
if ($projectid = $nodeproject->fetch_assoc()) {
if ($admin) {
$nodeselection = $sql->real_escape_string($_GET['node']);
} //$admin
else {
$usercount = $sql->query("SELECT COUNT(projectid) AS total FROM " . $sqldatabase . ".permissions WHERE projectid='" . $projectid['projectid'] . "' AND email='" . $_SESSION['email'] . "';");
$countres = $usercount->fetch_assoc();
if ($countres['total'] > 0) {
$nodeselection = $sql->real_escape_string($_GET['node']);
} //$countres['total'] > 0
}
} //$projectid = $nodeproject->fetch_assoc()
} //isset($_GET['node'])
?>
<script>
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function historicaldatabutton() {
document.getElementById("historicaldata").classList.toggle("show");
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
</script>