iwa-panda1

Manage Weather Data by International Weather Agency (Version 1)
Log | Files | Refs

navbar.php (3759B)


      1 <?php
      2     session_start();
      3     if(!isset($_SESSION['email'])){
      4         header('Location: /');
      5         exit;
      6     }
      7     // Get the permission level of the user
      8     $permission_levels= $_SESSION['user_permissions'];
      9 
     10     // Assume $permission_levels is an array containing the user's permission levels
     11 
     12     $links = array();
     13 
     14     // Define the links for each type of employee
     15     // Define the links for each type of employee
     16     if (in_array(1, $permission_levels)) {
     17         // Admin links
     18         $admin_links = array(
     19         array('url' => '/add_user', 'title' => 'Add User'),
     20         array('url' => '/search_user', 'title' => 'Search for user'),
     21         );
     22         $links[] = array('name' => 'Admin', 'links' => $admin_links);
     23     }
     24 
     25     if (in_array(2, $permission_levels)) {
     26         // Administrative employee links
     27         $admin_employee_links = array(
     28         array('url' => '/add_customer', 'title' => 'Add customer'),
     29         array('url' => '/search_customer', 'title' => 'Search customer'),
     30         array('url' => '/add_contract', 'title' => 'Add contract'),
     31         array('url' => '/search_contract', 'title' => 'Search contract'),
     32         );
     33         $links[] = array('name' => 'Administrative Employee', 'links' => $admin_employee_links);
     34     }
     35 
     36     if (in_array(3, $permission_levels)) {
     37         // Scientific employee links
     38         $scientific_employee_links = array(
     39         array('url' => 'search_data', 'title' => 'Search data'),
     40         array('url' => 'scientific_employee_page_2', 'title' => 'Scientific Employee Page 2'),
     41         array('url' => 'scientific_employee_page_3', 'title' => 'Scientific Employee Page 3')
     42         );
     43         $links[] = array('name' => 'Scientific Employee', 'links' => $scientific_employee_links);
     44     }
     45         
     46     if($_SERVER["REQUEST_METHOD"] == "POST"){
     47         if(isset($_POST['logout'])){
     48             session_unset();
     49             session_destroy();
     50             header('Location: login');
     51             exit;
     52         }
     53     }
     54 ?>
     55 
     56 <nav class="navbar navbar-expand-lg navbar-light bg-light">
     57     <a class="navbar-brand" href="/dashboard">Dashboard</a>
     58     <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
     59         <span class="navbar-toggler-icon"></span>
     60     </button>
     61     <div class="collapse navbar-collapse" id="navbarNavDropdown">
     62         <ul class="navbar-nav">
     63             <?php foreach($links as $employee_links) { ?>
     64                 <li class="nav-item dropdown">
     65                     <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink<?php echo $employee_links['name']; ?>" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
     66                         <?php echo $employee_links['name']; ?>
     67                     </a>
     68                     <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink<?php echo $employee_links['name']; ?>">
     69                         <?php foreach ($employee_links['links'] as $link) { ?>
     70                             <li><a class="dropdown-item" href="<?php echo $link['url']; ?>"><?php echo $link['title']; ?></a></li>
     71                         <?php } ?>
     72                     </ul>
     73                 </li>
     74             <?php } ?>
     75         </ul>
     76         <form method="post" action="/logout">
     77             <button type="submit" id='logout' class="btn btn-primary">Log out</button>
     78         </form>
     79     </div>
     80 </nav>
     81 
     82 <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
     83 <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
     84 <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>