iwa-panda1

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

commit 2ef417b7b6a46955294404035e16c56da2bd7d1c
parent beb5e0b50d95130125250bdec568a942629fb89c
Author: MoiBaguette <[email protected]>
Date:   Mon,  3 Apr 2023 15:28:06 +0200

search user

Diffstat:
Abackup | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcrud_user.php | 14+++++++-------
Mdashboard.php | 104+++++--------------------------------------------------------------------------
Aincludes.html | 0
Mlogin.php | 16++++++++--------
Anavbar.php | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asearchuser.php | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 259 insertions(+), 113 deletions(-)

diff --git a/backup b/backup @@ -0,0 +1,91 @@ +<?php +session_start(); + +// Check if user is logged in and has permission level set +if(!isset($_SESSION['email'])) { + // Redirect to login page if permission level is not set + header('Location: login.php'); + exit; +} +// Get the permission level of the user +$permission_levels= $_SESSION['permissions']; + +// Assume $permission_levels is an array containing the user's permission levels + +$links = array(); + +// Define the links for each type of employee +if (in_array(1, $permission_levels)) { + // Admin links + $admin_links = array( + array('url' => '/crud_user.php', 'title' => 'User toevoegen'), + array('url' => 'admin_page_2.php', 'title' => 'Admin Page 2'), + array('url' => 'admin_page_3.php', 'title' => 'Admin Page 3') + ); + $links[] = array('name' => 'Admin', 'links' => $admin_links); +} + +if (in_array(2, $permission_levels)) { + // Administrative employee links + $admin_employee_links = array( + array('url' => 'admin_employee_page_1.php', 'title' => 'Admin Employee Page 1'), + array('url' => 'admin_employee_page_2.php', 'title' => 'Admin Employee Page 2'), + array('url' => 'admin_employee_page_3.php', 'title' => 'Admin Employee Page 3') + ); + $links[] = array('name' => 'Administrative Employee', 'links' => $admin_employee_links); +} + +if (in_array(3, $permission_levels)) { + // Scientific employee links + $scientific_employee_links = array( + array('url' => 'scientific_employee_page_1.php', 'title' => 'Scientific Employee Page 1'), + array('url' => 'scientific_employee_page_2.php', 'title' => 'Scientific Employee Page 2'), + array('url' => 'scientific_employee_page_3.php', 'title' => 'Scientific Employee Page 3') + ); + $links[] = array('name' => 'Scientific Employee', 'links' => $scientific_employee_links); +} + +if (empty($links)) { + // Guest links + $guest_links = array( + array('url' => 'guest_page_1.php', 'title' => 'Guest Page 1') + ); + $links[] = array('name' => 'Guest', 'links' => $guest_links); +} +?> +<!DOCTYPE html> +<html> +<head> + <title>Dashboard</title> + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> +</head> +<body> + <nav class="navbar navbar-expand-lg navbar-light bg-light"> + <a class="navbar-brand" href="#">Dashboard</a> + <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation"> + <span class="navbar-toggler-icon"></span> + </button> + <div class="collapse navbar-collapse" id="navbarNavDropdown"> + <ul class="navbar-nav"> + <?php foreach($links as $employee_links) { ?> + <li class="nav-item dropdown"> + <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"> + <?php echo $employee_links['name']; ?> + </a> + <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink<?php echo $employee_links['name']; ?>"> + <?php foreach ($employee_links['links'] as $link) { ?> + <li><a class="dropdown-item" href="<?php echo $link['url']; ?>"><?php echo $link['title']; ?></a></li> + <?php } ?> + </ul> + </li> + <?php } ?> + </ul> + </div> + </nav> + <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> + <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script> + <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script> +</body> +</html> + + diff --git a/crud_user.php b/crud_user.php @@ -1,15 +1,18 @@ <!DOCTYPE html> <html lang="nl"> <head> - <meta charset="UTF-8"> - <meta http-equiv="X-UA-Compatible" content="IE=edge"> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>User toevoegen</title> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> </head> + <?php + include "navbar.php"; + if(!in_array(1, $_SESSION['permissions'])){ + header('Location: dashboard.php'); + exit; + } + ?> <body> - <div class="container"> <h1>User toevoegen</h1> @@ -46,9 +49,6 @@ <button type="submit" class="btn btn-primary" name="submit">Voeg toe</button> </form> </div> - - <!-- Bootstrap Bundle JS (including Popper) and jQuery --> - <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> <?php $servername = "86.92.67.21"; $username = "friedel"; diff --git a/dashboard.php b/dashboard.php @@ -1,100 +1,8 @@ -<?php -session_start(); - -// Check if user is logged in and has permission level set -if(!isset($_SESSION['email'])) { - // Redirect to login page if permission level is not set - header('Location: login.php'); - exit; -} -// Get the permission level of the user -$permission_levels= $_SESSION['permissions']; - -// Assume $permission_levels is an array containing the user's permission levels - -$links = array(); - -// Define the links for each type of employee -if (in_array(1, $permission_levels)) { - // Admin links - $admin_links = array( - array('url' => 'localhost:8080/crud_user.php', 'title' => 'User toevoegen'), - array('url' => 'admin_page_2.php', 'title' => 'Admin Page 2'), - array('url' => 'admin_page_3.php', 'title' => 'Admin Page 3') - ); - $links[] = array('name' => 'Admin', 'links' => $admin_links); -} - -if (in_array(2, $permission_levels)) { - // Administrative employee links - $admin_employee_links = array( - array('url' => 'admin_employee_page_1.php', 'title' => 'Admin Employee Page 1'), - array('url' => 'admin_employee_page_2.php', 'title' => 'Admin Employee Page 2'), - array('url' => 'admin_employee_page_3.php', 'title' => 'Admin Employee Page 3') - ); - $links[] = array('name' => 'Administrative Employee', 'links' => $admin_employee_links); -} - -if (in_array(3, $permission_levels)) { - // Scientific employee links - $scientific_employee_links = array( - array('url' => 'scientific_employee_page_1.php', 'title' => 'Scientific Employee Page 1'), - array('url' => 'scientific_employee_page_2.php', 'title' => 'Scientific Employee Page 2'), - array('url' => 'scientific_employee_page_3.php', 'title' => 'Scientific Employee Page 3') - ); - $links[] = array('name' => 'Scientific Employee', 'links' => $scientific_employee_links); -} - -if (empty($links)) { - // Guest links - $guest_links = array( - array('url' => 'guest_page_1.php', 'title' => 'Guest Page 1') - ); - $links[] = array('name' => 'Guest', 'links' => $guest_links); -} -?> -<!DOCTYPE html> <html> -<head> - <title>Dashboard</title> - <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> -</head> -<body> - <nav class="navbar navbar-expand-lg navbar-light bg-light"> - <a class="navbar-brand" href="#">Dashboard</a> - <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation"> - <span class="navbar-toggler-icon"></span> - </button> - <div class="collapse navbar-collapse" id="navbarNavDropdown"> - <ul class="navbar-nav"> - <?php foreach($links as $employee) { ?> - <li class="nav-item dropdown"> - <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink<?php echo $employee['id']; ?>" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> - <?php echo $employee['name']; ?> - </a> - <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink<?php echo $employee['id']; ?>"> - <?php foreach ($employee['links'] as $link) { ?> - <li><a class="dropdown-item" href="<?php echo $link['url']; ?>"><?php echo $link['title']; ?></a></li> - <?php } ?> - </ul> - </li> - <?php } ?> - </ul> - </div> - </nav> - - <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> - <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script> - <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script> - <script> - $(document).ready(function() { - var dropdownMenuList = [].slice.call(document.querySelectorAll('.dropdown-menu')); - dropdownMenuList.map(function (dropdownMenu) { - return new bootstrap.Dropdown(dropdownMenu); - }); - }); - </script> -</body> + <head> + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> + </head> + <?php + include "navbar.php"; + ?> </html> - - diff --git a/includes.html b/includes.html diff --git a/login.php b/login.php @@ -54,11 +54,11 @@ } // create, prepare sql statement and execute sql statement - $sql = "select m.email, m.wachtwoord, pm.permissie_id, pm.permissie_naam - from medewerkers m - join medewerkers_permissie mp on mp.email = m.email - join permissie pm on pm.permissie_id = mp.permissie_id - where m.email = ?"; + $sql = "select u.email, u.password, p.permission_id, p.permission_name + from user u + join user_permission up on up.email = u.email + join permission p on p.permission_id = up.permission_id + where u.email = ? "; $stmt= $conn->prepare($sql); $stmt->bind_param("s", $email); $stmt->execute(); @@ -66,15 +66,15 @@ // verification logic and $_SESSION start if(count($row = $result->fetch_assoc()) > 0){ - if($email == $row['email'] && password_verify($pwd, $row['wachtwoord'])) { + if($email == $row['email'] && password_verify($pwd, $row['password'])) { session_start(); $_SESSION['email'] = $row['email']; mysqli_data_seek($result, 0); $permissions = array(); $permissions_names = array(); while($row = mysqli_fetch_assoc($result)){ - array_push($permissions, $row['permissie_id']); - array_push($permissions_names, $row['permissie_naam']); + array_push($permissions, $row['permission_id']); + array_push($permissions_names, $row['permission_name']); } $_SESSION['permissions'] = $permissions; $_SESSION['permissions_names'] = $permissions_names; diff --git a/navbar.php b/navbar.php @@ -0,0 +1,78 @@ +<?php + session_start(); + if(!isset($_SESSION['email'])){ + header('Location: login.php'); + exit; + } + // Get the permission level of the user + $permission_levels= $_SESSION['permissions']; + + // Assume $permission_levels is an array containing the user's permission levels + + $links = array(); + + // Define the links for each type of employee + if (in_array(1, $permission_levels)) { + // Admin links + $admin_links = array( + array('url' => '/crud_user.php', 'title' => 'Add User'), + array('url' => '/searchuser.php', 'title' => 'Search for user'), + array('url' => '/alteruser', 'title' => 'Alter user') + ); + $links[] = array('name' => 'Admin', 'links' => $admin_links); + } + + if (in_array(2, $permission_levels)) { + // Administrative employee links + $admin_employee_links = array( + array('url' => 'admin_employee_page_1.php', 'title' => 'Admin Employee Page 1'), + array('url' => 'admin_employee_page_2.php', 'title' => 'Admin Employee Page 2'), + array('url' => 'admin_employee_page_3.php', 'title' => 'Admin Employee Page 3') + ); + $links[] = array('name' => 'Administrative Employee', 'links' => $admin_employee_links); + } + + if (in_array(3, $permission_levels)) { + // Scientific employee links + $scientific_employee_links = array( + array('url' => 'scientific_employee_page_1.php', 'title' => 'Scientific Employee Page 1'), + array('url' => 'scientific_employee_page_2.php', 'title' => 'Scientific Employee Page 2'), + array('url' => 'scientific_employee_page_3.php', 'title' => 'Scientific Employee Page 3') + ); + $links[] = array('name' => 'Scientific Employee', 'links' => $scientific_employee_links); + } + + if (empty($links)) { + // Guest links + $guest_links = array( + array('url' => 'guest_page_1.php', 'title' => 'Guest Page 1') + ); + $links[] = array('name' => 'Guest', 'links' => $guest_links); + } +?> + +<nav class="navbar navbar-expand-lg navbar-light bg-light"> + <a class="navbar-brand" href="#">Dashboard</a> + <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation"> + <span class="navbar-toggler-icon"></span> + </button> + <div class="collapse navbar-collapse" id="navbarNavDropdown"> + <ul class="navbar-nav"> + <?php foreach($links as $employee_links) { ?> + <li class="nav-item dropdown"> + <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"> + <?php echo $employee_links['name']; ?> + </a> + <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink<?php echo $employee_links['name']; ?>"> + <?php foreach ($employee_links['links'] as $link) { ?> + <li><a class="dropdown-item" href="<?php echo $link['url']; ?>"><?php echo $link['title']; ?></a></li> + <?php } ?> + </ul> + </li> + <?php } ?> + </ul> + </div> +</nav> +<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> +<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script> +<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script> +\ No newline at end of file diff --git a/searchuser.php b/searchuser.php @@ -0,0 +1,68 @@ +<html> + <head> + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> + </head> + <?php + include "navbar.php"; + ?> + <body> + <form class="d-flex" action="searchuser.php" method="post"> + <input class="form-control me-2" type="search" name="search" placeholder="Search" aria-label="Search"> + <button class="btn btn-outline-success" type="submit">Search</button> + </form> + <?php + $servername = "86.92.67.21"; + $username = "friedel"; + $password = "hailiwa"; + $dbname = "wap2"; + // Create connection + $conn = mysqli_connect($servername, $username, $password, $dbname); + // Check connection + if (!$conn) { + die("Connection failed: " . mysqli_connect_error()); + } + + if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['search'])) { + $search = $_POST['search']; + $search = "%" . $search . "%"; + $sql = "SELECT u.email, u.first_name, u.last_name + FROM user u + where u.email LIKE ?"; + $stmt= $conn->prepare($sql); + $stmt->bind_param("s", $search); + $stmt->execute(); + + $result = $stmt->get_result(); + + // verification logic and $_SESSION start + if($result->num_rows > 0){ + echo "<table class=\"table table-striped\"> + <thead> + <tr> + <th>E-mail</th> + <th>First name</th> + <th>Last name</th> + <th>Action</th> + </tr> + </thead> + <tbody>"; + while ($row = mysqli_fetch_assoc($result)) { + $link = "/alteruser.php?email=" . $row['email']; + echo "<tr>"; + echo "<td>" . $row['email'] . "</td>"; + echo "<td>" . $row['first_name'] . "</td>"; + echo "<td>" . $row['last_name'] . "</td>"; + echo "<td><a href='" . $link . "'>Edit</a></td>"; + echo "</tr>"; + } + echo" + </tbody> + </table>"; + }else{ + echo "No users with this email address were found."; + } + } + ?> + </body> +</html> +