-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbooking.php
More file actions
181 lines (161 loc) · 5.98 KB
/
booking.php
File metadata and controls
181 lines (161 loc) · 5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<script type="text/javascript" >
function EventHandler() {
var form=document.getElementById("booking_form");
form.addEventListener('submit',function(e){
e.preventDefault();
if (form.problem.value=="") {
alert("You should describe the problem");
form.problem.classList.add("invalid");
form.problem.classList.remove("valid");
form.problem.focus();
return false;
}else{
form.problem.classList.add("valid");
form.problem.classList.remove("invalid");
}
if (form.date.value=="") {
alert("You should insert a date");
form.date.classList.add("invalid");
form.date.classList.remove("valid");
form.date.focus();
return false;
}else{
form.date.classList.add("valid");
form.date.classList.remove("invalid");
}
if (form.product.value=="") {
alert("You should insert a product");
form.product.classList.add("invalid");
form.product.classList.remove("valid");
form.product.focus();
return false;
}else{
form.product.classList.add("valid");
form.product.classList.remove("invalid");
}
if (form.tech.value=="") {
alert("You should insert a tech");
form.tech.classList.add("invalid");
form.tech.classList.remove("valid");
form.tech.focus();
return false;
}else{
form.tech.classList.add("valid");
form.tech.classList.remove("invalid");
}
form.submit();
});
}
</script>
<!-- Set the character encoding for the HTML document -->
<meta charset="UTF-8">
<!-- Configure the viewport for responsive design -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Indicate the name of the page's author or the organization responsible for its creation -->
<meta name="author" content="TechFixExperts">
<title>Booking form</title>
<link rel="icon" href="images/apple-whole-solid.png" type="img/png">
<link rel="stylesheet" href="booking.css" type="text/css">
<link rel="stylesheet" type="text/css" href="header.css">
<?php
include 'db_connection.php';
?>
</head>
<body onload="EventHandler()"id="booking">
<?php
include 'header.php';
if (isset($_POST["problem"])) {
$user_email = $_SESSION['email'];
$problem = pg_escape_string($db, $_POST["problem"]);
$date = pg_escape_string($db, $_POST["date"]);
$address = "";
if (empty($_POST["address"])) {
$request = "SELECT address,civic_number FROM users WHERE email='$user_email';";
$elem = pg_query($db, $request);
$row = pg_fetch_row($elem);
$address = $row[0] . " " . $row[1];
} else {
$address = pg_escape_string($db, $_POST["address"]);
}
$product = explode(".", $_POST["product"]);
$product_name = pg_escape_string($db, $product[0]);
$model = pg_escape_string($db, $product[1]);
$tech = pg_escape_string($db, $_POST["tech"]);
$email = pg_escape_string($db, $user_email);
$request2 = "SELECT MAX(code) FROM booking;";
$elem2 = pg_query($db, $request2);
$code = 0;
if (!$elem2)
$code = 0;
else {
$row2 = pg_fetch_row($elem2);
$code = $row2[0] + 1;
}
$request3 = "INSERT INTO booking (code, problem_description, booking_date,booking_address, tech_code, user_email, product_name, product_model) VALUES ('$code', '$problem', '$date','$address','$tech', '$email', '$product_name', '$model');";
$elem3 = pg_query($db, $request3);
if (!$elem3) {
echo "<script>alert('Booking error')</script>";
} else {
header("Location: account_page.php");
}
}
?>
<div class="container" id="container">
<div class="form-container">
<form action=<?php echo $_SERVER["PHP_SELF"]; ?> name="booking" method="post" id="booking_form">
<div class="booking-form">
<h1>MAKE YOUR BOOKING</h1>
<div class="Problem">
<input type="text" placeholder="Describe your problem" name="problem" />
</div>
<div class="Date">
<input type="date" placeholder="Choose the date" name="date" min="<?php echo date('Y-m-d'); ?>" />
</div>
<div class="Address">
<input type="text" placeholder="Delivery Address (If it's different from yours)" name="address" maxlength="40" />
</div>
<div class="Product">
<select name="product" >
<option value="" disabled selected hidden>Choose your product</option>
<?php
$request4 = "SELECT name,model FROM product ;";
$elem4 = pg_query($db, $request4);
while ($row4 = pg_fetch_row($elem4)) {
echo "<option value=";
echo $row4[0] . "." . $row4[1];
echo "> ";
echo $row4[0] . " " . $row4[1];
echo "</option>";
}
?>
</select>
</div>
<div class="Tech">
<select name="tech">
<?php
echo "<option value='' disabled selected hidden>Choose your tech</option>";
$request5 = "SELECT code,name,surname FROM tech ;";
$elem5 = pg_query($db, $request5);
while ($row5 = pg_fetch_row($elem5)) {
echo "<option value=";
echo $row5[0];
echo "> ";
echo $row5[1] . " " . $row5[2];
echo "</option>";
}
?>
</select>
</div>
<div class="Commit">
<button id="commit" type="submit" form="booking_form">Commit your booking</button>
</div>
</form>
</div>
</div>
<script type="text/javascript" src="script.js">
</script>
</body>
</html>