search_customer.php (3425B) download
1<!DOCTYPE html>
2<html lang="eng">
3 <head>
4 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
5 <link rel="stylesheet" type="text/css" href="/css/homepage.css">
6 <?php
7 include "views/navbar.php";
8 include "utils/autoloader.php";
9 if(!in_array(1, $_SESSION['user_permissions'])){
10 header('Location: /dashboard');
11 exit;
12 }
13 $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
14 ?>
15 </head>
16<body>
17 <form class="d-flex" action="search_customer" method="post">
18 <input class="form-control me-2" type="search" name="search_email" placeholder="Email" aria-label="Search">
19 <input class="form-control me-2" type="search" name="search_first_name" placeholder="First name" aria-label="Search">
20 <input class="form-control me-2" type="search" name="search_last_name" placeholder="Last name" aria-label="Search">
21 <button class="btn btn-outline-success" type="submit">Search</button>
22</form>
23 <?php
24 $query = [];
25 if(isset($_POST['search_email'])) {
26 $query["email"] = "%{$_POST['search_email']}%";
27 }
28 if(isset($_POST['search_last_name'])) {
29 $query["first_name"] = "%{$_POST['search_first_name']}%";
30 }
31 if(isset($_POST['search_first_name'])) {
32 $query["last_name"] = "%{$_POST['search_last_name']}%";
33 }
34 if(isset($_POST['delete'])){
35 $c = $db->get(Customer::class);
36 $c->where("email", $_POST['delete']);
37 $c->delete();
38 }
39 if($query == []){
40 $query['email'] = "%";
41 }
42 display_results($db, $query);
43 function display_results($db, $query){
44 //create a User orm class and load all the records where user like query
45 $results = $db->all_where(Customer::class, $query);
46
47 // display results
48 if($results != null){
49 echo "<table class=\"table table-striped\">
50 <thead>
51 <tr>
52 <th>Id</th>
53 <th>E-mail</th>
54 <th>First name</th>
55 <th>Last name</th>
56 <th>Alter customer data</th>
57 <th>Add conctract</th>
58 <th>Delete</th>
59 </tr>
60 </thead>
61 <tbody>";
62 foreach($results as $data) {
63 $link_alter = "/alter_customer?email=" . $data->email;
64 $link_add_contract = "/add_contract?email=" . $data->email;
65 echo "<tr>";
66 echo "<td>" . $data->customer_id . "</td>";
67 echo "<td>" . $data->email . "</td>";
68 echo "<td>" . $data->first_name . "</td>";
69 echo "<td>" . $data->last_name . "</td>";
70 echo "<td><a href='" . $link_alter . "'>Alter</a></td>";
71 echo "<td><a href='" . $link_add_contract . "'>Add Contract</a></td>";
72 echo "
73 <td>
74 <form method=\"post\" action=\"search_customer\">
75 <button type=\"submit\" name='delete' value=" . $data->email ." ' class=\"btn btn-primary\">delete</button>
76 </form>
77 </td>";
78 echo "</tr>";
79 }
80 echo"
81 </tbody>
82 </table>";
83 }else{
84 echo "No customers were found.";
85 }
86 }
87 ?>
88 </body>
89</html>
90