search_user.php (2186B) download
1<?php
2include "utils/autoloader.php";
3
4session_start();
5
6$db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "lollipop");
7if (!isset($_SESSION['permissions']) || !in_array(0, $_SESSION['permissions'])) {
8 header('Location: /dashboard');
9 exit;
10}
11
12if (isset($_GET['delete'])) {
13 $u = $db->get(Model\User::class);
14 $u->load($_GET['delete']);
15 $u->delete();
16}
17
18$query = '';
19if (isset($_GET['query'])) {
20 $query = $_GET['query'];
21 $results = $db->where(Model\User::class, ['email' => "%$query%"], true);
22} else {
23 $results = $db->all(Model\User::class);
24}
25
26?>
27
28<!DOCTYPE html>
29<html lang="en">
30
31<head>
32 <meta charset="UTF-8">
33 <title>User Search</title>
34 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
35</head>
36
37<body>
38 <?= include "navbar.php"; ?>
39 <form class="d-flex" action="/user/search" method="get">
40 <input class="form-control me-2" type="search" name="query" placeholder="Email" aria-label="Search">
41 <button class="btn btn-outline-success" type="submit">Search</button>
42 </form>
43 <?php
44 if (!empty($results)) {
45 ?>
46 <table class='table table-striped'>
47 <thead>
48 <tr>
49 <th>Email</th>
50 <th>First Name</th>
51 <th>Last Name</th>
52 <th>Alter</th>
53 <th>Delete</th>
54 </tr>
55 </thead>
56 <tbody>
57 <?php
58 foreach ($results as $data) { ?>
59 <tr>
60 <td>
61 <?= $data->email ?>
62 </td>
63 <td>
64 <?= $data->fname ?>
65 </td>
66 <td>
67 <?= $data->lname ?>
68 </td>
69 <td><a href='/user/<?= $data->email ?>/update'>Edit</a></td>
70 <td>
71 <form method='get' action='/user/search'>
72 <input type='hidden' name='query' value='<?= $query ?>'>
73 <button type='submit' name='delete' value='<?= $data->email ?>' class='btn btn-primary'>Delete</button>
74 </form>
75 </td>
76 </tr>
77 <?php
78 }
79 echo "</tbody></table>";
80 } else {
81 echo "No users with this email address were found.";
82 }
83 ?>
84</body>
85
86</html>