This repository has been archived by the owner on Nov 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nav1.php
81 lines (77 loc) · 2.81 KB
/
Nav1.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
<?php
require_once "SQLFunctions.php";
if(empty($_SESSION['userID'])) {
$navHeading = 'Login now';
$navItems = [
'Home' => 'dashboard.php',
'Help' => 'help.php'
];
} else {
/*copy the session $userID to a local variable*/
$userID = $_SESSION['userID'];
$role = $_SESSION['role'];
$navHeading = $_SESSION['firstname'] . ' ' . $_SESSION['lastname'];
$navItems = [
'Home' => 'dashboard.php',
'Help' => 'help.php',
'Deficiencies' => empty($_SESSION['bdPermit'])
? 'defs.php'
: [
'Project Deficiencies' => 'defs.php',
'BART Deficiencies' => 'defs.php?view=BART'
],
'Safety Certs' => 'ViewSC.php'
];
if ($_SESSION['inspector']) {
$navItems['Daily Report'] = 'idr.php';
}
}
?>
<nav class="navbar navbar-expand-md navbar-dark navbar-vta-blue">
<span class="navbar-brand navbar-heading">
<a
href="<?php echo empty($userID) ? 'login.php' : 'userAccount.php'; ?>"
class='navbar-link navbar-brand-link'><?php echo $navHeading; ?></a>
</span>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar">
<ul class="navbar-nav mr-auto">
<?php
// conditionally render nav items
foreach ($navItems as $text => $element) {
$classList = 'nav-link';
$disableLink = ' disabled';
if (is_string($element)) {
if (strpos($_SERVER['PHP_SELF'], $element) !== false) $classList .= $disableLink;
echo "
<li class='nav-item'>
<a href='$element' class='$classList'>$text</a>
</li>";
} elseif (is_array($element)) {
$navLink = "
<li class='nav-item dropdown'>
<a class='nav-link dropdown-toggle' href='#' id='defsDropdown' role='button' data-toggle='dropdown' aria-expanded='false'>
Deficiencies
</a>
<div class='dropdown-menu' aria-labelledby='defsDropdown'>%s</div></li>";
$subNavList = '';
$itemClasslist = 'dropdown-item';
foreach ($element as $text => $href) {
if (strpos($_SERVER['PHP_SELF'], $href) !== false) $itemClasslist .= $disableLink;
$subNavList .= "<a href='{$href}' class='{$itemClasslist}'>{$text}</a>";
}
printf($navLink, $subNavList);
}
}
if($navHeading !== 'Login now') {
echo "
<li class='nav-item'>
<a class='nav-link' href='logout.php'>Logout</a>
</li>";
}
?>
</ul>
</div>
</nav>