alter_customer.php (3663B) download
1<!DOCTYPE html>
2<!--Deltron 3030 - The mastermind -->
3<html lang="eng">
4 <head>
5 <title>Add user</title>
6 <!-- Bootstrap CSS -->
7 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
8 <link rel="stylesheet" type="text/css" href="/css/homepage.css">
9 </head>
10<?php
11include "views/navbar.php";
12include "utils/autoloader.php";
13if(!in_array(1, $_SESSION['user_permissions'])){
14 header('Location: /dashboard');
15 exit;
16}
17$db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
18 //if not found set to empty if not GET
19$fname = "";
20$lname = "";
21$email = "";
22$msg = "";
23if($_SERVER["REQUEST_METHOD"] == "GET"){
24 //if the get var isset and user is found in the database load data into forms
25 if(!isset($_GET['email'])){
26 echo"";
27 }else{
28 $get_email = $_GET['email'];
29 $c = $db->get(Customer::class);
30 if($c->where("email", $get_email)){
31 $fname = $c->first_name;
32 $lname = $c->last_name;
33 $email = $c->email;
34 $customer_id = $c->customer_id;
35 }
36 }
37}
38if ($_SERVER["REQUEST_METHOD"] == "POST") {
39 $errors = array(); // initialize an empty array to store errors
40
41 // Check if voornaam is set and not empty
42 if (isset($_POST['voornaam']) && !empty($_POST['voornaam'])) {
43 $fname = $_POST['voornaam'];
44 } else {
45 $errors[] = "Voornaam is required";
46 }
47
48 // Check if achternaam is set and not empty
49 if (isset($_POST['achternaam']) && !empty($_POST['achternaam'])) {
50 $lname = $_POST['achternaam'];
51 } else {
52 $errors[] = "Achternaam is required";
53 }
54 // Check if email is set and not empty
55 if (isset($_POST['email']) && !empty($_POST['email'])) {
56 $email = $_POST['email'];
57 } else {
58 $errors[] = "E-mail is required";
59 }
60 // Check if there are any errors
61 if (count($errors) > 0) {
62 // Print out the errors
63 foreach ($errors as $error) {
64 $msg .= $error . "<br>";
65 }
66 } else {
67 //create a database object with table customer
68 $c = $db->get(Customer::class);
69 //check if customer already exists
70 if(!$c->where("email", $email)){
71 $msg = "this user does not exist: " . $email . " " . $fname . " " . $lname;
72 }else{
73 $c = $db->get(Customer::class);
74 $c->where('email', $email);
75 //set new user data
76 $c->first_name = $fname;
77 $c->last_name = $lname;
78 $c->email = $email;
79 //add user with the add function
80 if($c->save()){
81 $msg = "update to the db this info:<br> email: {$c->email}<br> firstname: {$c->first_name}<br> lastname: {$c->last_name}";
82 };
83 }
84 }
85}
86?>
87 <body>
88 <div class="container">
89 <h1>Alter customer</h1>
90
91 <form action="alter_customer" method="post">
92 <div class="mb-3">
93 <label for="voornaam" class="form-label"><b>Voornaam:</b></label>
94 <input type="text" class="form-control" name="voornaam" id="voornaam" placeholder="Voornaam" value=<?php echo$fname?>>
95 </div>
96 <div class="mb-3">
97 <label for="achternaam" class="form-label"><b>Achternaam:</b></label>
98 <input type="text" class="form-control" name="achternaam" id="achternaam" placeholder="Achternaam" value=<?php echo$lname?>>
99 </div>
100 <div class="mb-3">
101 <label for="email" class="form-label"><b>Email:</b></label>
102 <input type="text" class="form-control" name="email" id="email" placeholder="Email" value=<?php echo$email?>>
103 </div>
104 <button type="submit" class="btn btn-primary" name="submit">Alter customer</button>
105 </form>
106 <?php echo $msg;?>
107 </div>
108 </body>
109</html>