forked from heyabhiraj/CANMANsys
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.php
More file actions
158 lines (134 loc) · 5.6 KB
/
Copy pathmenu.php
File metadata and controls
158 lines (134 loc) · 5.6 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
<?php
$pageName = "Menu";
session_start();
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header("Location: login.php");
exit;
}
include('./admin/function.php');
$items = getDayMenu();
// Add item to cart
if (isset($_POST['add_to_cart']) && isset($_POST['item_id']) && isset($_POST['quantity'])) {
$itemId = $_POST['item_id'];
$quantity = $_POST['quantity'];
// Check if cart session variable exists, if not, initialize it
if (!isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
}
$itemExists = false;
// If item exists, update the quantity
foreach ($_SESSION['cart'] as &$cartItem) {
if ($cartItem['id'] == $itemId) {
$cartItem['quantity'] += $quantity;
$itemExists = true;
break;
}
}
// If item doesn't exist, add it to the cart
if (!$itemExists) {
$_SESSION['cart'][] = array('id' => $itemId, 'quantity' => $quantity);
}
// Redirect back to menu page
header('Location: cart.php');
exit;
}
// Get filter option from query string
$filter = isset($_GET['filter']) ? $_GET['filter'] : 'today';
// Filter items based on the selected option
switch ($filter) {
case 'veg':
$items = vegMenuItem();
$dayitems = getDayMenu();
break;
case 'nonveg':
$items = nvegMenuItem();
$dayitems = getDayMenu();
break;
case 'all':
$items = getAllMenu();
$dayitems = getDayMenu();
break;
case 'today':
default:
$items = getDayMenu();
$dayitems = getDayMenu();
break;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home - <?php echo $_SESSION['fname']; ?> </title>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<div class="h-20 p-5">
<div class="flex p-5 mb-1 items-center justify-around bg-white ">
<!-- Left side Logo -->
<h1 class="text-2xl sm:text-4xl text-yellow-600 drop-shadow-lg"> <a href="">CANMANsys </a></h1>
<!-- Right side buttons -->
<div class="flex items-center">
<button class="bg-black text-white rounded-full px-4 py-2" onclick='window.location.href="logout.php"'>LogOut</button>
</div>
</div>
<div class="bg-orange-100 rounded-lg h-900 w-auto p-2 drop-shadow-lg">
<?php
include('./navbar.php');
?>
<div class="mb-4">
<form action="menu.php" method="get">
<select name="filter" id="filter" class=" px-2 py-2 rounded-md text-sm font-medium bg-white border border-gray-300 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
<option class="cursor-pointer" value="today" <?php if ($filter === 'today') echo 'selected'; ?>>Today</option>
<option class="cursor-pointer" value="veg" <?php if ($filter === 'veg') echo 'selected'; ?>>Veg</option>
<option class="cursor-pointer" value="nonveg" <?php if ($filter === 'nonveg') echo 'selected'; ?>>Non-Veg</option>
<option class="cursor-pointer" value="all" <?php if ($filter === 'all') echo 'selected'; ?>>All</option>
</select>
<!-- <button class="p-1 bg-black text-white rounded-md" type="submit">Filter</button> -->
</form>
</div>
<div class="flex flex-wrap justify-center">
<?php
if(!empty($items)){
foreach ($items as $item) : ?>
<div class="w-full md:w-1/4 p-5">
<div class="sm:flex bg-white border border-gray-200 rounded-lg shadow flex-col relative">
<div class="absolute h-10 pl-2 pr-2 pt-2 -left-4 -t op-3 odd:bg-red-500 even:bg-violet-500 -skew-y-3 text-white"><?=$item['category_name']?></div>
<!-- <img class="self-center p-5 rounded-lg object-cover h-40 w-40" src="<?=($img = $item['item_image'])?"img/$img":"img.svg"?>" alt="image" /> -->
<div class="px-5 pb-5">
<img class="self-center p-5 rounded-lg object-cover h-40 w-40" src="<?=($img = $item['item_image'])?"img/$img":"img.svg"?>" alt="image" />
<form action="menu.php" method="post">
<input type="hidden" name="item_id" value="<?= $item[0]; ?>">
<h5 class="text-xl font-semibold tracking-tight text-gray-900"><?= $item[1]; ?></h5>
<p class="text-sm font-medium text-gray-900"> <?= $item[2]; ?></p>
<input type="hidden" id="quantity" name="quantity" value="1" min="1">
<div class="flex w-full items-center justify-between px-3 py-1 rounded-lg"> <span class="text-xl font-bold text-green-700">₹ <?php echo $item[3]; ?></span>
<?php
if(in_array($item,$dayitems))
echo '<button name="add_to_cart" class="text-white bg-black hover:bg-gray-600 rounded-lg text-sm px-5 py-2.5 text-center">Add + </button>';
else
echo '<button disabled class="text-white bg-gray-700 rounded-lg text-sm px-5 py-2.5 text-center"> Unavailable </button>';
?>
</div>
</form>
</div>
</div>
</div><?php endforeach; ?>
<?php } else echo "No Available Items";?>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('#filter').change(function(){
const filter = $(this).val();
window.location.href = "menu.php?filter=" + filter;
});
});
</script>
</body>
</html>