-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
160 lines (149 loc) · 6.52 KB
/
index.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
<?php
/* Setup everything, import configuration and connect to database
*/
include_once('include/functions.php');
include_once('config/config.php');
session_name(SESSIONID);
session_start();
setLanguage(isset($_SESSION['lang']) ? $_SESSION['lang'] : LANG);
$_SESSION['role'] = isset($_SESSION['role']) ? $_SESSION['role'] : 0;
# Add access log to database
addLogData();
$currentPage = '';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Health application</title>
<!-- Import CCS styles -->
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/styles.css">
<link rel="stylesheet" href="assets/css/<?php echo isset($_SESSION['theme']) ? $_SESSION['theme'] : THEME; ?>">
<!-- Import JS frameworks -->
<script src="assets/js/jquery-3.6.0.min.js"></script>
<script src="assets/js/jquery.mCustomScrollbar.concat.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/chart.min.js"></script>
<!-- Enable collapse sidebar -->
<script type="text/javascript">
$(document).ready(function () {
$("#sidebar").mCustomScrollbar({
theme: "minimal"
});
$('#sidebarCollapse').on('click', function () {
$('#sidebar, #content').toggleClass('active');
$('.collapse.in').toggleClass('in');
$('a[aria-expanded=true]').attr('aria-expanded', 'false');
});
});
</script>
</head>
<body>
<?php
/* Array to build the side bar menu. Support section title, menu items and sub menus
* Main page is fetch from pages/<pagename>.php. Session: 0 = guests and 1+ defined in database roles
* array('title' => 'Menu text', 'page' => '<pagename>', 'role' => [0,1,2,3...])
*
* Insert a section title in the menu. Note the '_head' tag in page.
* array('title' => 'Text', 'page' => '_head'),
*
* Build a collapsible menu.
* array('title' => 'Sub menu title', 'page' => 'submenu ID', 'role' => [0,1,2,3...], 'submenu' => array(
* array('title' => 'Sub menu text', 'page' => '<pagename>'), 'role' => [0,1,2,3...] ... )
*/
$menuStructure = array(
array('title' => _('Dashboard'), 'icon' => 'bi-grid-1x2', 'page' => 'home', 'role' => [1,2]),
array('title' => _('New measurement'), 'icon' => 'bi-stopwatch', 'page' => 'addmeasurements', 'role' => [2]),
array('title' => _('Register'), 'icon' => 'bi-person-plus-fill', 'page' => 'register', 'role' => [0]),
array('title' => _('Login'), 'icon' => 'bi-box-arrow-in-right', 'page' => 'login', 'role' => [0]),
array('title' => _('Logout'), 'icon' => 'bi-box-arrow-in-right', 'page' => 'logout', 'role' => [1,2]),
array('title' => _('About'), 'icon' => 'bi-info-circle-fill', 'page' => 'about', 'role' => [0,1,2]),
array('title' => _('Account'), 'page' => '_head', 'role' => [1,2]),
array('title' => _('My goals'), 'icon' => 'bi-trophy', 'page' => 'usergoals', 'role' => [2]),
array('title' => _('Account settings'), 'icon' => 'bi-gear', 'page' => 'usersettings', 'role' => [1,2]),
array('title' => _('Admin'), 'page' => '_head', 'role' => [1]),
array('title' => _('User admin'), 'icon' => 'bi-gear', 'page' => 'useradmin', 'role' => [1], 'submenu' =>
array(
array('title' => _('Edit users'), 'icon' => 'bi-people', 'page' => 'edituser', 'role' => [1]),
array('title' => _('Add user'), 'icon' => '', 'page' => 'adduser', 'role' => [1])
),
),
array('title' => _('View logs'), 'icon' => 'bi-gear', 'page', 'page' => 'logdata', 'role' => [1]),
array('title' => _('Settings'), 'icon' => 'bi-gear', 'page', 'page' => 'settings', 'role' => [1]),
);
?>
<div class="wrapper">
<!-- Build sidebar from $menuStructure array -->
<nav id="sidebar">
<div class="sidebar-header">
<div class="face-image" style="background-image: url('<?php echo ($_SESSION['role'] == 0) ? "media/logo_icon.png" : "media/faces/default_male.png" ?>')"></div>
<?php
echo '<p class="face-text">';
echo ($_SESSION['role'] == 0) ? '' : _("Logged in as") . ' ' . $_SESSION['firstname'];
echo '</p>';
?>
</div>
<ul class="list-unstyled"> <?php
$page = verifyData(isset($_GET['page'])?$_GET['page']:'login',"page", false);
foreach ($menuStructure as $item) {
if (in_array($_SESSION['role'], $item['role'])) {
if (!isset($item['submenu'])) {
if ($item['page'] == '_head') {
echo '<p>'.$item['title'].'</p>';
} else {
echo '<li class="'.($item['page']==$page?'active':'').'"><a class="'.(isset($item['icon'])?$item['icon']:'').'" href="?page='.$item['page'].'"> '.$item['title'].'</a></li>';
if ($item['page']==$page) {
$currentPage = $item['title'];
$permit = in_array($_SESSION['role'], $item['role']);
}
}
} else {
$sublist = '';
$active = false;
foreach ($item['submenu'] as $subitem) {
if ($subitem['page']==$page) {
$active=true; $currentPage = $subitem['title'];
$permit = in_array($_SESSION['role'], $item['role']);
}
$sublist .= '<li class="'.($subitem['page']==$page?'active':NULL).'"><a class="'.(isset($item['icon'])?$item['icon']:'').'"href="?page='.$subitem['page'].'"> '.$subitem['title'].'</a></li>';
}
echo '<li>';
echo '<a class="dropdown-toggle '.(isset($item['icon'])?$item['icon']:'').'"href="#'.$item['page'].'Submenu" data-bs-toggle="collapse" aria-expanded="'.($active?'true':'false').'"> '.$item['title'].'</a>';
echo '<ul class="collapse '.($active?'show':'').' list-unstyled" id="'.$item['page'].'Submenu">';
echo $sublist;
echo '</ul></li>';
}
}
}
?>
</ul>
</nav>
<!-- Navbar content -->
<div id="content">
<nav class="navbar navbar-expand-lg">
<div class="container-fluid stickybar">
<button type="button" id="sidebarCollapse" class="btn">
<i class="bi bi-menu-button-fill"></i>
<span></span>
</button>
<?php echo $currentPage ?>
</div>
</nav>
<!-- Import main page content -->
<?php
if ($page) {
if (!isset($permit)) {
echo '<div class="alert alert-danger"><strong>'._('Access denied').'</strong><br>'._('You don\'t have the right to access this page.')."</div>";
} else {
include('pages/'.$page.'.php');
}
} else {
echo '<div class="alert alert-danger"><strong>'._('Error 404').'</strong><br><br>'._('Requested page not found.')."</div>";
}
?>
</div>
</div>
</body>
</html>