-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathorder.php
More file actions
479 lines (391 loc) · 16.8 KB
/
Copy pathorder.php
File metadata and controls
479 lines (391 loc) · 16.8 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include('nav.php');
include('db.php');
$username = $_SESSION['username'];
$email = $_SESSION['email'];
$phone = $_SESSION['phone'];
$errors = []; // Initialize errors array
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header("Location: login.php");
}
// Handle form submission
if (isset($_POST['submit'])) {
$selectedItem = $_POST['item'];
$Number = $_POST['Number'];
$totalPrice = $_POST['hidden-total-price'];
$name = $_POST['fullname'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$pickupdate = $_POST['pickup-date'];
$pickuptime = $_POST['pickup-time'];
$PetName = $_POST['PetName'];
$Species = $_POST['Species'];
// Function to validate time
function validateTime($time)
{
return strtotime($time) >= strtotime('11:00') && strtotime($time) <= strtotime('16:00');
}
function validateAlphabetic($input, $max_length)
{
return preg_match('/^[a-zA-Z]+$/', $input) && strlen($input) <= $max_length;
}
// Function to validate alphanumeric input with a maximum length
// Validate required fields
$requiredFields = ['item', 'Number', 'hidden-total-price', 'fullname', 'address', 'phone', 'pickup-date', 'pickup-time', 'PetName', 'Species'];
foreach ($requiredFields as $field) {
if (empty($_POST[$field])) {
$errors[] = "The {$field} field is required.";
}
}
// Validate selected item
$validItems = ['2000', '1500', '1200', '1000', '3500', '3200', '3000', '2700', '2500', '2200'];
if (!in_array($selectedItem, $validItems)) {
$errors[] = "Invalid selected item.";
}
// Validate number of pets
if (!is_numeric($Number) || $Number < 1 || $Number > 2 || !preg_match('/^[1-2]$/', $Number)) {
$errors[] = "Invalid number. You can only choose 1 or 2 pets.";
}
if (!validateAlphabetic($PetName, 50)) {
$errors[] = "Pet Name should contain only alphabetic characters and have a maximum length of 50 characters.";
}
// Validate species name
if (!validateAlphabetic($Species, 50)) {
$errors[] = "Species Name should contain only alphabetic characters and have a maximum length of 50 characters.";
}
// Validate appointment date
$currentDate = date('Y-m-d');
$pickupDateObj = DateTime::createFromFormat('Y-m-d', $pickupdate);
if (!$pickupDateObj || $pickupDateObj < new DateTime($currentDate) || $pickupDateObj > (new DateTime($currentDate))->modify('+3 days')) {
$errors[] = "Please choose a date between tomorrow and the next 3 days.";
}
// Validate appointment time
if (!validateTime($pickuptime)) {
$errors[] = "Appointment time must be between 11 AM and 4 PM.";
}
// If no errors, proceed with inserting data
if (empty($errors)) {
$item = mysqli_real_escape_string($conn, $selectedItem);
$quantity = 1; // Assuming quantity is always 1
$Number = mysqli_real_escape_string($conn, $Number);
$totalPrice = mysqli_real_escape_string($conn, $totalPrice);
// Map item to its corresponding service
$services = [
'2000' => 'Wellness Exam',
'1500' => 'Dental Care',
'1200' => 'Dietary Consultation',
'1000' => 'Vaccinations',
'3500' => 'Wellness Exam and Dental Care',
'3200' => 'Wellness Exam and Dietary Consultation',
'3000' => 'Wellness Exam and Vaccinations',
'2700' => 'Dental Care and Dietary Consultation',
'2500' => 'Dental Care and Vaccinations',
'2200' => 'Dietary Consultation and Vaccinations',
];
$laa = isset($services[$item]) ? $services[$item] : 'Unknown Service';
$Status = "Pending";
$insertQuery = "INSERT INTO appointments(Name, Address, Phone, SelectedItem, Number, TotalPrice, PickupDate, PickupTime, PetName, Species, Status) VALUES('$name','$address','$phone','$laa','$Number','$totalPrice','$pickupdate','$pickuptime','$PetName','$Species','$Status')";
$result = mysqli_query($conn, $insertQuery);
if ($result) {
echo "<script>alert('Appointment placed successfully.');</script>";
// Order placed successfully, redirect to myorder.php
echo "<script>window.location.href='myorder.php';</script>";
exit(); // Ensure that no further code is executed after the redirect
} else {
echo "<script>alert('Error: " . mysqli_error($conn) . "');</script>";
}
} else {
// Display individual prompt box for the first error
echo "<script>alert('" . $errors[0] . "');</script>";
}
}
?>
<!-- Remaining HTML code... -->
<!DOCTYPE html>
<html>
<head>
<title>Order- pet treatment services</title>
<!-- <link rel="stylesheet" href="order-style.css"> -->
<style>
h1
{
margin-top: 7%;
font-size: 5vh;
}
h1.x1
{
margin-top: 5%;
margin-bottom: 5%;
font-size: 3em;
background-color: #3C0000;
color:white;
margin-bottom: -3%;
font-style: arial, calibri;
width: 30%;
text-align: center;
margin-left: 33%;
border-radius: 5px;
box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 10px;
padding: 16px;
white-space: nowrap;
}
.container
{
display: flex;
justify-content: space-around;
align-items: center;
margin-top: 5%;
margin: 3%;
padding: 3%;
}
.left-side
{
/* margin-top: 1% ; */
width: 30%;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
margin-left: -80%;
margin-top: -22%;
}
.right-side
{
width: 40%;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-color: #f1dca7;
margin-left: 30%;
}
.table-container
{
margin-top: 6%;
background-color: red;
}
table
{
margin-top: -3%;
font-size: 1.3em;
font-family: Arial, Helvetica, sans-serif;
/* border: 2px solid #000; */
border-collapse: collapse;
width: 100%;
}
thead
{
text-align: center;
font-family: arial, calibri, sans-serif;
}
th
{
background-color: #f2f2f2;
font-weight: lighter;
font-size: 1.5em;
padding: 10px;
}
tbody tr td
{
text-align: center;
font-family: arial, calibri, sans-serif;
font-style: light;
/* padding: 5px; */
line-height: 5vh;
background-color: #ffe5ec;
}
h2
{
text-align: center;
font-size: 3em;
font-weight: lighter;
}
.left-side h2
{
text-align: center;
/* font-size: 3em; */
font-weight: lighter;
margin-bottom: -7%;
background-color: #ffe5ec;
padding: 10px;;
font-family: Arial, Helvetica, calibri;
}
.right-side h2
{
text-align: center;
font-size: 2em;
font-weight: lighter;
font-family: 'arial', 'calibri', 'sans-serif'; /*schedule and pickup delivery form *
/* margin-bottom: -7%;
margin-top:2% ; */
margin: 5%;
}
label
{
display: block;
margin-top: 2%;
}
input[type="number"],
select
{
margin-bottom: 5%;
padding: 5px;
height: 40px;
width: 100%;
/* text field width size change */
align-items: center;
}
input[type="text"]
{
margin-bottom: 5%;
padding: 5px;
height: 40px;
width: 100%;
/* text field width size change */
align-items: center;
}
input[type="submit"]
{
margin-bottom: 30px;
padding: 5px;
height: 40px;
width: 100%;
/* text field width size change */
align-items: center;
background-color: #b8c0ff;
}
label
{
font-size: 1.3em;
color: black;
margin-bottom: 15px;
text-align: center;
}
</style>
</head>
<body>
<h1 class="x1">Pet Treatment Service</h1>
<div class="container">
<img style="z-index:-111; width:50%; margin-left: 25%; " src="pana.png"/>
<div class="left-side">
<h2>Price List</h2>
<div class="table-container">
<table>
<thead>
<tr>
<th>Service</th>
<th>Price per pet</th>
</tr>
</thead>
<tbody>
<?php
// Include your database connection
$serviceQuery = "SELECT * FROM services";
$serviceResult = mysqli_query($conn, $serviceQuery);
while ($row = mysqli_fetch_assoc($serviceResult)) {
echo "<tr>";
echo "<td>{$row['service_name']}</td>";
echo "<td>Rs {$row['service_price']}</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
</div>
<div class="right-side">
<h2>Book you Appointment</h2>
<div class="forms-container">
<form class="pick" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" novalidate>
<input type="hidden" name="hidden-total-price" id="hidden-total-price" value="">
<?php
$userQuery = "SELECT * FROM users WHERE username='$username'";
$userResult = mysqli_query($conn, $userQuery);
if ($userResult && mysqli_num_rows($userResult) > 0) {
$userData = mysqli_fetch_assoc($userResult);
$fullName = $userData['fullname'];
$userPhone = $userData['phone'];
$userAddress = $userData['address'];
$userEmail = $userData['email'];
}
// echo $fullName.$userPhone.$userAddress.$userEmail;
?>
<input type="hidden" name="fullname" value="<?php echo $fullName; ?>">
<input type="hidden" name="phone" value="<?php echo $userPhone; ?>">
<input type="hidden" name="address" value="<?php echo $userAddress; ?>">
<input type="hidden" name="email" value="<?php echo $userEmail; ?>">
<label for="item">Service:</label>
<select name="item" id="item" onchange="updatePriceAndTotal()">
<option value="">Select a service...</option>
<?php
$serviceData = array(); // Store service data for JavaScript
$serviceQuery = "SELECT * FROM services";
$serviceResult = mysqli_query($conn, $serviceQuery);
while ($row = mysqli_fetch_assoc($serviceResult)) {
$serviceData[] = $row;
echo "<option value='{$row['service_price']}'>{$row['service_name']}</option>";
}
?>
</select>
<input type="hidden" name="selected-item-price" id="selected-item-price" value="">
<input type="hidden" name="selected-total-price" id="selected-total-price" value="">
<label for="price">Price:</label>
<span style=" margin-bottom:15px; font-size:12px; text-align:center; font-weight:bold;" id="price-display" name="prices"></span>
<label for="Number">No of Pets:</label>
<input type="number" name="Number" id="Number" min="1" max="10" placeholder="Number of Pets" required>
<label for="PetName">Name of the pet:<span id="PetName-error" style="color: red;"></span></label>
<input type="text" name="PetName" id="PetName" placeholder="Pet Name" required>
<label for="Species">Species of the pet:<span id="PetName-error" style="color: red;"></label>
<input type="text" name="Species" id="Species" placeholder="Dog / Bird /Hamster .." required>
<label style=" margin-bottom:15px;"for="total-price">Total Price:</label>
<span style=" margin-bottom:15px; font-size:12px; text-align:center; font-weight:bold;" id="total-price-display"></span>
<script>
// JavaScript code here
const services = <?php echo json_encode($serviceData); ?>;
function populateServiceOptions()
{
const itemSelect = document.getElementById("item");
itemSelect.innerHTML = "<option value=''>Select a service...</option>";
services.forEach(service => {
const option = document.createElement("option");
option.value = service.service_price;
option.text = service.service_name;
itemSelect.appendChild(option);
});
}
function updatePriceAndTotal()
{
const selectedItem = document.getElementById("item");
const priceDisplay = document.getElementById("price-display");
const Number = parseFloat(document.getElementById("Number").value);
const totalPriceDisplay = document.getElementById("total-price-display");
const selectedService = services.find(service => service.service_price === selectedItem.value);
// PRICE CALCULATE GARNA KO LAGI MATRAI HO
if (selectedService) {
const pricePerUnit = parseFloat(selectedService.service_price);
const totalPrice = pricePerUnit * Number;
priceDisplay.innerText = `Rs ${pricePerUnit.toFixed(2)}`;
totalPriceDisplay.innerText = `Rs ${totalPrice.toFixed(2)}`;
document.getElementById("hidden-total-price").value = totalPrice.toFixed(2);
// Update the hidden fields with price per kg and total price
document.getElementById("selected-item-price").value = pricePerUnit.toFixed(2);
document.getElementById("selected-total-price").value = totalPrice.toFixed(2);
}
}
document.addEventListener("DOMContentLoaded", populateServiceOptions);
document.getElementById("item").addEventListener("change", updatePriceAndTotal);
document.getElementById("Number").addEventListener("input", updatePriceAndTotal);
</script>
<label for="pickup-date">Appointment Date:</label>
<input style="width:100%; height:45px; margin-bottom:15px;" type="date" name="pickup-date" id="pickup-date" required>
<label for="pickup-time">Appointment Time:</label>
<input style="width:100%; height:45px; margin-bottom:15px;" type="time" name="pickup-time" id="pickup-time" required>
<input type="submit" value="Confirm Schedule" name="submit">
</form>
</div>
</div>
</div>
</div>
</body>
</html>