-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart.php
More file actions
841 lines (750 loc) · 34.9 KB
/
Copy pathcart.php
File metadata and controls
841 lines (750 loc) · 34.9 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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
<?php
//―――――――――――――――――――――――――――――――――― ┏ Panggil Fail Function ┓ ―――――――――――――――――――――――――――――――― \\
include("function/autoKeluar.php");
include('function/connection.php');
//―――――――――――――――――――――――――――――――――― ┏ Kod Php ┓ ―――――――――――――――――――――――――――――――― \\
$jumlah_harga = 0; # setkan nila awal kosong
# Memamparkan Bilanggan Senarai Tempahan
if (isset($_SESSION['orders'])) {
$bil = "<span style='color:red';'>[" . count($_SESSION['orders']) . "]</span>";
} else {
$bil = "";
}
# menyemak jika tatasusunan order kosong
if (!isset($_SESSION['orders']) or count($_SESSION['orders']) == 0) {
#jika tiada data tempahan di session pergi ke page menu semula dan memulang toast
$_SESSION['info'] = "Cart Anda Kosong";
header("Location: menu.php");
exit();
} else {
# jika ada data tempahan muat fail html cart
# dapatkan bilangan setiap elemen
$bilangan = array_count_values($_SESSION['orders']);
# Filter elemen yang muncul lebih dari satu kali
$sama = array_filter($bilangan, function ($count) {
return $count >= 1;
});
?>
<!-- Kod HTML & CSS + TAILWIND & JAVASCRIPT -->
<html lang="ms">
<head>
<title>CART</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="apple-touch-icon" sizes="180x180" href="lib/icon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="lib/icon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="lib/icon/favicon-16x16.png">
<link rel="manifest" href="lib/icon/site.webmanifest">
<link rel="stylesheet" href="lib/css/all.css">
<link rel="stylesheet" href="lib/css/sharp-solid.css">
<link rel="stylesheet" href="lib/css/sharp-regular.css">
<link rel="stylesheet" href="lib/css/sharp-light.css">
<link rel="stylesheet" href="lib/css/duotone.css" />
<link rel="stylesheet" href="lib/css/brands.css" />
<link href="lib/css/css2.css" rel="stylesheet" />
<script src="lib/js/tailwind.js"></script>
<link rel="stylesheet" href="lib/css/sweetalert2.min.css">
<script src="lib/js/sweetalert2@11.js"></script>
<style>
@font-face {
font-family: 'BebasNeue';
src: url('lib/fonts/BebasNeue-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'LilitiaOne';
src: url('lib/fonts/LilitaOne-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'LobsterTwo';
src: url('lib/fonts/LobsterTwo-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'Merriweather';
src: url('lib/fonts/Merriweather-Regular.ttf') format('truetype');
font-weight: normal;
font-size: 60px;
font-style: normal;
}
@font-face {
font-family: 'Teko';
src: url('lib/fonts/Teko-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
.fontkafelip,
h2 {
font-family: 'LobsterTwo', sans-serif;
}
.text-table {
font-family: 'LobsterTwo', sans-serif;
font-size: 20px;
}
.nav {
font-family: 'Teko', sans-serif;
font-size: 20px;
position: relative;
}
.button {
font-family: 'BebasNeue', sans-serif;
}
.content {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}
.container {
max-width: 1200px;
/* Menghadkan lebar maksimum jadual */
width: 100%;
}
table {
width: 100%;
border-collapse: collapse;
}
thead th {
text-align: center;
}
.overflow-x-auto {
overflow-x: auto;
/* Untuk responsif jika jadual terlalu besar */
}
.table-auto {
width: 100%;
/* Pastikan jadual memenuhi ruang */
max-width: 900px;
/* Hadkan lebar maksimum jadual */
margin: 0 auto;
/* Pusatkan jadual */
}
.container-wrapper {
display: flex;
flex-direction: column;
min-height: 20vh;
}
#scrollToTopBtn:hover {
background-color: #68B0AB;
color: #fff;
transition: background-color 0.3s ease, color 0.3s ease;
}
@media (max-width: 768px) {
.nav a span,
.goMenu a span {
display: none;
}
}
/* Custom scrollbar styles */
::-webkit-scrollbar {
width: 12px;
}
::-webkit-scrollbar-track {
background: #FAF3DD;
}
::-webkit-scrollbar-thumb {
background-color: #000;
border-radius: 6px;
border: 3px solid #FAF3DD;
}
::-webkit-scrollbar-thumb:hover {
background-color: #333;
}
/* Scroll to top button */
#scrollToTopBtn {
display: none;
position: fixed;
bottom: 60px;
right: 20px;
z-index: 100;
background-color: #4A7C59;
color: white;
border: none;
border-radius: 50%;
padding: 10px 15px;
cursor: pointer;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}
/* Hover effect for header navigation links */
.nav a::after,
.goMenu a::after {
content: '';
display: block;
width: 0;
height: 2px;
background: #4A7C59;
transition: width 0.3s;
}
.nav a:hover::after,
.goMenu a:hover::after {
width: 100%;
}
.add-to-cart:hover,
#scrollToTopBtn:hover {
background-color: #68B0AB;
color: #fff;
transition: background-color 0.3s ease, color 0.3s ease;
}
.quantity-controls {
display: flex;
align-items: center;
gap: 10px;
}
.quantity-btn {
background-color: #4A7C59;
color: white;
border: none;
width: 30px;
height: 30px;
border-radius: 50%;
cursor: pointer;
font-size: 18px;
display: flex;
align-items: center;
justify-content: center;
transition: background-color 0.3s ease;
}
.quantity-btn:hover {
background-color: #68B0AB;
}
.quantity-value {
font-size: 18px;
font-weight: bold;
min-width: 30px;
text-align: center;
}
/* Buang garis statik */
.nav a::after {
display: none;
}
/* Garis bergerak */
.nav .moving-line {
position: absolute;
bottom: -4px;
height: 2px;
background-color: #4A7C59;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
pointer-events: none;
}
</style>
</head>
<body class="bg-[#FAF3DD] text-gray-800">
<!-- Header -->
<div class="w-full bg-[#FAF3DD] fixed top-0 left-0 z-50 border-b border-gray-200">
<div class="container mx-auto flex justify-between items-center py-6 px-4">
<div class="logo text-2xl font-bold flex items-center mr-4 cursor-pointer"
onclick="window.location.href='index.php'">
<i class="fas fa-coffee text-[#4A7C59] mr-2">
</i>
<span class="text-black fontkafelip">Kafe</span>
<span class="text-black fontkafelip">Lip</span>
</div>
<div class="nav flex gap-6 -ml-10 mr-12">
<a class="text-black font-bold <?= basename($_SERVER['PHP_SELF']) == 'menu.php' ? 'active' : '' ?>"
href="menu.php">
<i class="fas fa-utensils text-[#4A7C59] mr-1"></i>
<span>MENU</span>
</a>
<a class="text-black font-bold <?= basename($_SERVER['PHP_SELF']) == 'cart.php' ? 'active' : '' ?>"
href="cart.php">
<i class="fas fa-shopping-cart text-[#4A7C59] mr-1"></i>
<span>CART <?= $bil ?></span>
</a>
<a class="text-black font-bold <?= basename($_SERVER['PHP_SELF']) == 'sejarah-tempah.php' ? 'active' : '' ?>"
href="sejarah-tempah.php">
<i class="fas fa-history text-[#4A7C59] mr-1"></i>
<span>SEJARAH TEMPAHAN</span>
</a>
<div class="moving-line"></div>
</div>
<div class="relative">
<button id="menuButton" class="p-2 hover:bg-gray-100 rounded-full">
<i class="fas fa-bars text-[#4A7C59] text-xl"></i>
</button>
<div id="dropdownMenu"
class="hidden absolute right-0 mt-2 w-48 bg-white rounded-lg shadow-lg py-2 z-50">
<?php if ($_SESSION['tahap'] == "ADMIN"): ?>
<a href="admin/panel.php" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
<i class="fa fa-list-alt mr-2 text-[#4A7C59]"></i>Panel Admin
</a>
<?php endif; ?>
<a href="profil.php" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
<i class="fas fa-user mr-2 text-[#4A7C59]"></i>Profil
</a>
<a href="account.php" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
<i class="fas fa-cog mr-2 text-[#4A7C59]"></i>Akaun
</a>
<hr class="my-1">
<a href="logout.php" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
<i class="fas fa-sign-out-alt mr-2 text-[#4A7C59]"></i>Log Keluar
</a>
</div>
</div>
</div>
</div>
<div class="h-24"></div>
<!-- Body -->
<div class="content">
<div class="container mx-auto text-center py-8 px-4 rounded-lg">
<h2 class="text-4xl font-bold mb-6 relative inline-block text-center w-full text-black">
Senarai Tempahan
<span class="absolute bottom-0 left-1/2 transform -translate-x-1/2 w-1/2 h-1 bg-[#4A7C59]">
</span>
</h2>
<div class="overflow-x-auto">
<table
class="border-2 border-[#4A7C59] table-auto min-w-ful border-separate shadow-lg rounded-lg bg-[#4A7C59]">
<thead>
<tr class="text-white">
<th width="20%" class="bg-[#4A7C59] px-4 py-2">Menu</th>
<th width="10%" class="bg-[#4A7C59] px-4 py-2">Gambar</th>
<th width="15%" class="bg-[#4A7C59] px-4 py-2">Kuantiti</th>
<th width="15%" class="bg-[#4A7C59] px-4 py-2">Harga seunit (RM)</th>
<th width="15%" class="bg-[#4A7C59] px-4 py-2">Harga (RM)</th>
</tr>
</thead>
<tbody>
<?php
foreach ($sama as $key => $bil) {
$sql = "select* from makanan where kod_makanan = '$key'";
$lak = mysqli_query($condb, $sql);
$m = mysqli_fetch_array($lak);
?>
<tr class="bg-[#FAF3DD] hover:bg-white">
<td class="shadow-lg px-4 py-2 font-semibold text-table"><?= $m['nama_makanan'] ?></td>
<td class='px-8 py-4 flex justify-center items-center'>
<div class="relative group">
<div class="w-32 h-32 overflow-hidden">
<img src='menu-images/<?php echo htmlspecialchars($m['gambar']); ?>'
alt='Gambar menu <?php echo htmlspecialchars($m['nama_makanan']); ?>'
class="w-full h-full object-cover rounded-md cursor-pointer transition-opacity group-hover:opacity-50">
</div>
<div
class="absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity">
<i onclick="showImagePopup('menu-images/<?php echo htmlspecialchars($m['gambar']); ?>', '<?php echo htmlspecialchars($m['nama_makanan']); ?>')"
class="fas fa-eye text-3xl text-white bg-black bg-opacity-50 p-3 rounded-full"></i>
</div>
</div>
</td>
<td class="px-4 py-2 h-full">
<div class="flex items-center justify-center h-full min-h-[160px]">
<div class="quantity-controls">
<button class="quantity-btn minus bg-[#CA0000D9] hover:bg-[#d33]"
onclick="updateCartQuantity('<?= $m['kod_makanan'] ?>', 'decrease', <?= $m['harga'] ?>)"><i
class="fas fa-minus"></i></button>
<span id="quantity-<?= $m['kod_makanan'] ?>"
class="quantity-value"><?= $bil ?></span>
<button class="quantity-btn plus"
onclick="updateCartQuantity('<?= $m['kod_makanan'] ?>', 'increase', <?= $m['harga'] ?>)"><i
class="fas fa-plus"></i></button>
</div>
</div>
</td>
<td class="shadow-lg text-center px-4 py-2 font-semibold text-table"><?= $m['harga'] ?>
</td>
<td class="shadow-lg text-center px-4 py-2 font-semibold text-table">
<span id="total-<?= $m['kod_makanan'] ?>">
<?php
$harga = $bil * $m['harga'];
$jumlah_bayaran = $jumlah_bayaran + $harga;
echo number_format($harga, 2);
?>
</span>
</td>
</tr>
<?php } ?>
<tr class="bg-[#FAF3DD] hover:bg-white">
<td class="shadow-lg px-4 py-2 text-right font-semibold text-table" colspan="4">Jumlah
Bayaran (RM)</td>
<td class="shadow-lg text-center px-4 py-2 font-semibold text-table">
<span id="grand-total"><?php echo number_format($jumlah_bayaran, 2) ?></span>
</td>
</tr>
</tbody>
</table>
</div>
<div class="mt-5">
<button class="buang-btn bg-[#CA0000D9] text-white px-4 py-2 rounded button hover:bg-[#d33]">
<i class="fas fa-times-circle mr-2"></i>Reset
</button>
<button class="Sahkan-btn bg-[#4A7C59] text-white px-4 py-2 rounded button hover:bg-[#68B0AB]">
<i class="fas fa-check-circle mr-2"></i>Tempah Sekarang
</button>
</div>
</div>
</div>
<!-- Footer -->
<footer class="w-full bg-[#FAF3DD] text-black py-6 px-10">
<div class="container mx-auto flex flex-col lg:flex-row justify-between items-center">
<div class="mb-4 lg:mb-0">
© 2025 KAFELIP. Semua hak terpelihara.
</div>
<div class="flex gap-6">
<a class="text-[#4A7C59]" href="#">
<i class="fab fa-facebook-f">
</i>
</a>
<a class="text-[#4A7C59]" href="#">
<i class="fab fa-twitter">
</i>
</a>
<a class="text-[#4A7C59]" href="https://www.instagram.com/alipje29/#">
<i class="fab fa-instagram">
</i>
</a>
</div>
</div>
</footer>
<!-- Butang scroll keatas -->
<button id="scrollToTopBtn" onclick="scrollToTop()">
<i class="fas fa-arrow-up"></i>
</button>
<!-- Image Popup Modal -->
<div id="imageModal" class="fixed inset-0 bg-black bg-opacity-75 hidden items-center justify-center z-50">
<div class="relative max-w-2xl mx-auto p-4">
<button onclick="closeImagePopup()"
class="absolute top-0 right-0 -mt-[14.5px] -mr-[14px] text-white text-3xl font-bold hover:text-gray-300">×</button>
<div class="max-h-[70vh] max-w-[600px]">
<img id="popupImage" src="" alt="" class="w-full h-[70%] rounded-md object-contain">
</div>
<p id="imageCaption" class="text-white text-center mt-4 text-lg"></p>
</div>
</div>
<script>
// function butang scroll keatas dan auto ajdust kedudukan footer
function adjustFooter() {
const content = document.querySelector('.content');
const footer = document.querySelector('footer');
const windowHeight = window.innerHeight;
const contentHeight = content.offsetHeight;
const footerHeight = footer.offsetHeight;
// Kira margin top footer supaya sentiasa berada di bawah
const marginTop = windowHeight - (contentHeight + footerHeight);
if (marginTop > 0) {
footer.style.marginTop = marginTop + 'px';
} else {
footer.style.marginTop = '0px';
}
}
// Panggil fungsi setiap kali halaman dimuat
window.onload = adjustFooter;
// Panggil fungsi semasa resize window
window.onresize = adjustFooter;
// Show or hide the scroll to top button
window.onscroll = function() {
var scrollToTopBtn = document.getElementById("scrollToTopBtn");
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
scrollToTopBtn.style.display = "block";
} else {
scrollToTopBtn.style.display = "none";
}
};
// Scroll to top function
function scrollToTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
</script>
<script>
// function toast dan popup
const notifsuccess = new Audio('lib/audio/notif.mp3'); // Path fail audio success
const notiferror = new Audio('lib/audio/error.mp3'); // Path fail audio ralat
const notifinfo = new Audio('lib/audio/info.mp3'); // Path fail audio info
const notifwarning = new Audio('lib/audio/warning.mp3'); // Path fail audio amaran
const Toast = Swal.mixin({
toast: true,
position: "top-end",
showConfirmButton: false,
timer: 3000,
timerProgressBar: true,
didOpen: (toast) => {
toast.onmouseenter = Swal.stopTimer;
toast.onmouseleave = Swal.resumeTimer;
}
});
document.addEventListener('DOMContentLoaded', function() {
<?php if (isset($_SESSION['success'])): ?>
Toast.fire({
icon: "success",
title: "<?= $_SESSION['success'] ?>"
});
notifsuccess.play(); // Main bunyi bila toast muncul
<?php unset($_SESSION['success']); ?>
<?php endif; ?>
<?php if (isset($_SESSION['info'])): ?>
Toast.fire({
icon: "info",
title: "<?= $_SESSION['info'] ?>"
});
notifinfo.play();
<?php unset($_SESSION['info']); ?>
<?php endif; ?>
<?php if (isset($_SESSION['warning'])): ?>
Toast.fire({
icon: "warning",
title: "<?= $_SESSION['warning'] ?>"
});
notifwarning.play();
<?php unset($_SESSION['warning']); ?>
<?php endif; ?>
// Untuk popup error
<?php if (isset($_SESSION['error'])): ?>
Toast.fire({
icon: "error",
title: "<?= $_SESSION['error'] ?>"
});
notiferror.play();
<?php unset($_SESSION['error']); ?>
<?php endif; ?>
})
document.querySelectorAll('.Sahkan-btn').forEach(button => {
button.addEventListener('click', function(e) {
e.preventDefault();
notifinfo.play();
// Kumpul semua data kuantiti terkini
let updatedQuantities = {};
document.querySelectorAll('[id^="quantity-"]').forEach(element => {
const menuId = element.id.replace('quantity-', '');
updatedQuantities[menuId] = parseInt(element.textContent);
});
Swal.fire({
title: 'Anda pasti?',
text: "Selepas tempah Berjaya, anda dapat batalkan tempahan anda selama 60 saat sahaja di sejarah tempahan",
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Ya',
cancelButtonText: 'Batal'
}).then((result) => {
if (result.isConfirmed) {
// Hantar data kuantiti terkini ke server
fetch('function/update-cart.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(updatedQuantities)
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.location.href = 'function/sah-tempah.php';
} else {
notiferror.play();
Toast.fire({
icon: "error",
title: "Ralat semasa mengemas kini cart"
});
}
});
}
});
});
});
document.querySelectorAll('.buang-btn').forEach(button => {
button.addEventListener('click', function(e) {
e.preventDefault();
notifwarning.play();
Swal.fire({
title: 'Anda pasti?',
text: "Mahu Kosongkan Cart Anda",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#d33',
cancelButtonColor: '#3085d6',
confirmButtonText: 'Ya',
cancelButtonText: 'Batal'
}).then((result) => {
if (result.isConfirmed) {
window.location.href = 'function/kosongkan-cart.php';
}
});
});
});
</script>
<script>
//function drawer menu di header
const menuButton = document.getElementById('menuButton');
const dropdownMenu = document.getElementById('dropdownMenu');
menuButton.addEventListener('click', () => {
dropdownMenu.classList.toggle('hidden');
});
// Tutup dropdown bila klik di luar
document.addEventListener('click', (event) => {
if (!menuButton.contains(event.target) && !dropdownMenu.contains(event.target)) {
dropdownMenu.classList.add('hidden');
}
});
</script>
<script>
function showImagePopup(imageSrc, caption) {
const modal = document.getElementById('imageModal');
const popupImage = document.getElementById('popupImage');
const imageCaption = document.getElementById('imageCaption');
popupImage.src = imageSrc;
imageCaption.textContent = caption;
modal.classList.remove('hidden');
modal.classList.add('flex');
// Tutup modal bila klik di luar gambar
modal.onclick = function(e) {
if (e.target === modal) {
closeImagePopup();
}
}
}
function closeImagePopup() {
const modal = document.getElementById('imageModal');
modal.classList.add('hidden');
modal.classList.remove('flex');
}
// Tutup modal dengan kekunci ESC
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeImagePopup();
}
});
</script>
<script>
// function butang + dan - untuk kuantii makanan
function updateCartQuantity(menuId, action, hargaSeunit) {
const quantityElement = document.getElementById(`quantity-${menuId}`);
let quantity = parseInt(quantityElement.textContent);
if (action === 'increase') {
quantity++;
} else if (action === 'decrease' && quantity > 1) {
quantity--;
} else if (action === 'decrease' && quantity === 1) {
notifwarning.play();
// Tanya pengguna jika mahu buang item
Swal.fire({
title: 'Buang item ini?',
text: "Item ini akan dibuang dari cart",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#d33',
cancelButtonColor: '#3085d6',
confirmButtonText: 'Ya',
cancelButtonText: 'Batal'
}).then((result) => {
if (result.isConfirmed) {
removeItem(menuId);
return;
}
});
return;
}
// Kemas kini paparan
quantityElement.textContent = quantity;
updateItemTotal(menuId, quantity, hargaSeunit);
updateGrandTotal();
// Hantar perubahan ke server menggunakan AJAX
fetch('function/update-quantity.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
menuId: menuId,
quantity: quantity
})
})
.then(response => response.json())
.then(data => {
if (!data.success) {
notiferror.play();
Toast.fire({
icon: "error",
title: "Ralat semasa mengemas kini kuantiti"
});
}
});
}
function removeItem(menuId) {
fetch('function/del-item.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
menuId: menuId
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
if (data.isEmpty) {
// Jika cart kosong, pergi ke menu.php
window.location.href = 'menu.php';
} else {
// Jika masih ada item lain, reload halaman cart
window.location.href = 'cart.php';
}
} else {
notiferror.play();
Toast.fire({
icon: "error",
title: "Ralat semasa membuang item"
});
}
});
}
function updateItemTotal(menuId, quantity, hargaSeunit) {
const totalElement = document.getElementById(`total-${menuId}`);
const total = quantity * hargaSeunit;
totalElement.textContent = total.toFixed(2);
}
function updateGrandTotal() {
let grandTotal = 0;
// Dapatkan semua elemen total harga
document.querySelectorAll('[id^="total-"]').forEach(element => {
grandTotal += parseFloat(element.textContent);
});
// Kemas kini jumlah keseluruhan
document.getElementById('grand-total').textContent = grandTotal.toFixed(2);
}
</script>
<script>
//script animation navigation
document.addEventListener('DOMContentLoaded', function() {
const nav = document.querySelector('.nav');
const movingLine = nav.querySelector('.moving-line');
const links = nav.querySelectorAll('a');
// Tetapkan posisi awal garis untuk link aktif
const activeLink = nav.querySelector('a.active');
if (activeLink) {
updateLinePosition(activeLink);
}
// Fungsi untuk kemaskini posisi garis
function updateLinePosition(link) {
const rect = link.getBoundingClientRect();
const navRect = nav.getBoundingClientRect();
movingLine.style.width = `${rect.width}px`;
movingLine.style.left = `${rect.left - navRect.left}px`;
}
// Event listeners untuk hover
links.forEach(link => {
link.addEventListener('mouseenter', () => {
updateLinePosition(link);
});
});
// Kembalikan ke link aktif apabila cursor keluar dari nav
nav.addEventListener('mouseleave', () => {
const activeLink = nav.querySelector('a.active');
if (activeLink) {
updateLinePosition(activeLink);
}
});
// Set posisi awal garis
if (activeLink) {
updateLinePosition(activeLink);
}
});
</script>
</body>
</html>
<?php } ?>