-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservices_form.php
More file actions
449 lines (306 loc) · 15.4 KB
/
Copy pathservices_form.php
File metadata and controls
449 lines (306 loc) · 15.4 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
<?php
require 'dbconnect.php'; // Ensure this file correctly initializes $conn
session_start(); // Start the session
// Check if the user is logged in
if (!isset($_SESSION['user_id'])) {
// If the user is not logged in, redirect to the login page
header("Location: login.php");
exit(); // Stop further execution
}
$response = ['success' => false, 'message' => ''];
// Validate view_id
if (isset($_GET['view_id'])) {
$view_id = intval($_GET['view_id']);
$view_query = "SELECT * FROM services WHERE service_id = ?";
if ($stmt = $conn->prepare($view_query)) {
$stmt->bind_param('i', $view_id);
$stmt->execute();
$view_result = $stmt->get_result();
$view_data = $view_result->fetch_assoc();
$stmt->close();
} else {
$response['message'] = 'Failed to prepare SQL statement for fetching room details.';
echo json_encode($response);
exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Service Form</title>
<!-- important file -->
<?php
include 'important.php'
?>
<link rel="stylesheet" href="css_main/main.css?v=<?php echo time(); ?>">
<link rel="stylesheet" href="css_main/services_form.css?v=<?php echo time(); ?>">
<link rel="shortcut icon" href="system_images/whitelogo.png" type="image/png">
</head>
<body>
<?php
include 'navigation.php';
?>
<main>
<!-- Loading Indicator -->
<div id="loading-indicator" style="display: none;">
<div class="modal-overlay"></div>
<div class="lds-facebook">
<div></div>
<div></div>
<div></div>
</div>
</div>
<form method="post" action="process_request.php" enctype="multipart/form-data" class="form-container">
<h1 class="hidden"><i class="fa-solid fa-bell-concierge"></i> Service Form</h1>
<!-- select service -->
<div class="services-box-wrapper">
<div class="services-box-container hidden">
<?php
// Query to select services
$sql = "SELECT service_id, service_status, service_name, service_description, service_photo FROM services WHERE service_status = 'active'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Output data of each row
while ($row = $result->fetch_assoc()) {
?>
<label class="service-box">
<input type="radio" name="service_name" value="<?php echo $row['service_name']; ?>" required>
<img src="admin/services/<?php echo $row['service_photo']; ?>"
alt="<?php echo $row['service_name']; ?>">
<h2><?php echo $row['service_name']; ?></h2>
<p><?php echo $row['service_description']; ?></p>
<br>
<b class="click-message" style="font-size: 1.4rem; font-style:italic; color:red; font-family: 'Anton', Arial, sans-serif; "><i class="fa-solid fa-hand-pointer"></i> Click to select</b>
</label>
<?php
}
} else {
echo "No services found.";
}
?>
</div>
</div>
<!-- end of select service -->
<h2 class="hidden">Customer's Information</h2>
<div class="customer-input-container hidden">
<input type="text" name="name" placeholder="Enter your name" required>
<input type="number" name="contact-number" placeholder="Enter your contact number" required>
<select name="gender" id="" required>
<option value="" selected disabled>Select Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="unknown">Prefer not to say</option>
</select>
<input type="email" name="email" placeholder="Enter your email (optional)">
<input type="text" name="address" placeholder="Enter your address" required>
</div>
<h2 class="hidden"> Fitting or Measurement Time and Date</h2>
<div class="customer-input-container hidden">
<input type="date" name="date" placeholder="Enter date" title="Select the date"
required min="<?= date('Y-m-d'); ?>">
<input type="time" name="time" placeholder="Enter time" title="Select the time "
required>
<p style="margin-top: 10px; font-size:1.2rem; text-align:right;">
"Note: Reservation time is tentative and subject to change by admin. Please verify upon confirmation."
</p>
</div>
<h2 class="hidden">Upload Photo/s <em style="font-size:1.4rem; color:gray;">(if applicable)</em></h2>
<div class="upload-container hidden">
<!-- Custom styled file input -->
<label for="photo_uploaded" class="custom-file-upload">
<i class="fa fa-cloud-upload"></i> Choose Files
</label>
<input type="file" name="photo_uploaded[]" id="photo_uploaded" multiple accept="image/*"
onchange="previewImages()">
<!-- Container for image previews -->
<div id="preview-container" class="preview-container"></div>
<!-- Clear Selection button (Initially hidden) -->
<button type="button" id="clear-selection" style="display: none;" onclick="clearSelection(event)">Clear
Selection</button>
</div>
<p class="instruction hidden"><b>Instruction:</b> To select multiple images at once, simply hold
down
the Ctrl key on your keyboard while clicking on the desired images. This allows you to
choose multiple images simultaneously.</p>
<h2 class="hidden">Message</h2>
<div class="customer-input-container hidden">
<textarea name="message" id=""></textarea>
</div>
<div class="terms-and-conditions-container hidden">
<input type="checkbox" id="termsCheckbox" name="terms" required>
<label for="termsCheckbox">
I agree to the
<a href="terms_and_condition.php" target="_blank" style="color:blue">Terms and Conditions</a>.
</label>
<style>
.terms-and-conditions-container {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
gap: 10px;
background-color: var(--first-bgcolor);
}
.terms-and-conditions-container label {
font-size: 1.5rem;
text-transform: uppercase;
color: var(--text-color);
}
</style>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const form = document.querySelector('form.form-container');
const termsCheckbox = document.getElementById('termsCheckbox');
form.addEventListener('submit', function(event) {
// Check if the terms checkbox is checked
if (!termsCheckbox.checked) {
event.preventDefault(); // Prevent form submission
Swal.fire({
icon: 'warning',
title: 'Terms and Conditions',
text: 'You must agree to the Terms and Conditions before submitting.',
confirmButtonText: 'Okay',
});
}
});
});
</script>
<p class="instruction hidden" id="last-instruction"><b>Tip:</b> To better assist you, please use the textbox above to
provide the details of your request. This will help us understand your needs more clearly
and ensure we address your specifications accurately.</p>
<div class="product-buttons-container hidden">
<a id="return" href="index.php?#services">
RETURN</a>
<div id="order-container">
<script>
document.addEventListener('DOMContentLoaded', function() {
// Make an AJAX request to check the login status
fetch('check_login_status.php')
.then(response => response.json())
.then(data => {
const orderContainer = document.getElementById('order-container');
if (data.loggedIn) {
// If logged in, display the "Order Now" button
orderContainer.innerHTML = '<button id="order-now" type="submit" name="request"><i class="fa-solid fa-bell-concierge"></i> SUBMIT</button>';
} else {
// If not logged in, display the "Log in to order" text
orderContainer.innerHTML = '<span style="color: gray; cursor: not-allowed;"><i class="fa-solid fa-bell-concierge"></i> Log in to book</span>';
}
})
.catch(error => console.error('Error checking login status:', error));
});
</script>
<!-- The button or text will be dynamically inserted here -->
</div>
</div>
</form>
</main>
</body>
</html>
<script>
document.addEventListener('DOMContentLoaded', function() {
const form = document.querySelector('form.form-container');
const loadingIndicator = document.getElementById('loading-indicator');
form.addEventListener('submit', function(event) {
event.preventDefault(); // Prevent default form submission
const formData = new FormData(form);
// Show loading indicator
loadingIndicator.style.display = 'flex'; // Display the spinner
// Create a promise that resolves after 2 seconds
const minLoadingTime = new Promise(resolve => setTimeout(resolve, 2000));
// Perform the fetch request
const request = fetch('process_request.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.status === 'success') {
toastr.success(data.message); // Show success message
return new Promise(resolve => setTimeout(() => {
window.location.href = 'index.php#services'; // Redirect to index.php
}, 2000)); // Wait for 2 seconds before redirection
} else {
toastr.error(data.message); // Show error message
return Promise.resolve(); // Resolve immediately
}
})
.catch(error => {
console.error('Error:', error);
toastr.error('An unexpected error occurred. Please try again.');
return Promise.resolve(); // Resolve immediately
});
// Use Promise.race to wait for the longer of the two promises
Promise.race([minLoadingTime, request]).finally(() => {
loadingIndicator.style.display = 'none'; // Hide loading indicator
});
});
});
</script>
<!-- radio script -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const serviceBoxes = document.querySelectorAll('.service-box');
serviceBoxes.forEach(function(box) {
box.addEventListener('click', function() {
// Remove the 'selected' class from all service boxes
serviceBoxes.forEach(function(b) {
b.classList.remove('selected');
});
// Add the 'selected' class to the clicked service box
this.classList.add('selected');
// Select the radio input inside the clicked service box
const radioInput = this.querySelector('input[type="radio"]');
radioInput.checked = true;
});
});
});
</script>
<!-- button script -->
<!-- JavaScript for image preview and clearing selection -->
<script>
function previewImages() {
const previewContainer = document.getElementById('preview-container');
const clearButton = document.getElementById('clear-selection');
previewContainer.innerHTML = ''; // Clear any existing previews
const files = document.getElementById('photo_uploaded').files;
if (files.length > 0) {
// Show the "Clear Selection" button when files are selected
clearButton.style.display = 'inline-block';
for (let i = 0; i < files.length; i++) {
const file = files[i];
// Ensure the file is an image and check its size
if (file.type.startsWith('image/') && file.size <= 5 * 1024 * 1024) { // Limit size to 5MB
const reader = new FileReader();
reader.onload = function(e) {
const imgWrapper = document.createElement('div');
imgWrapper.className = 'img-wrapper';
const img = document.createElement('img');
img.src = e.target.result;
img.alt = file.name;
imgWrapper.appendChild(img);
previewContainer.appendChild(imgWrapper);
};
reader.readAsDataURL(file);
} else {
alert('One of the files is not an image or exceeds the 5MB size limit.');
}
}
} else {
// Hide the "Clear Selection" button if no files are selected
clearButton.style.display = 'none';
}
}
function clearSelection(event) {
event.preventDefault(); // Prevent the page from refreshing
const fileInput = document.getElementById('photo_uploaded');
fileInput.value = ''; // Clear the file input
document.getElementById('preview-container').innerHTML = ''; // Clear the preview container
// Hide the "Clear Selection" button
document.getElementById('clear-selection').style.display = 'none';
}
</script>