-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmenu.php
More file actions
344 lines (316 loc) · 17.1 KB
/
Copy pathmenu.php
File metadata and controls
344 lines (316 loc) · 17.1 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
<?php
require_once('includes/header.php');
require_once('config/db.php');
$limit = 5;
$veg_current_page = isset($_GET['veg_page']) ? $_GET['veg_page'] : 1;
$nonveg_current_page = isset($_GET['nonveg_page']) ? $_GET['nonveg_page'] : 1;
$special_current_page = isset($_GET['special_page']) ? $_GET['special_page'] : 1;
$veg_limit = $limit * $veg_current_page;
$nonveg_limit = $limit * $nonveg_current_page;
$special_limit = $limit * $special_current_page;
$stmt_veg = $conn->prepare("SELECT * FROM food_items WHERE category = 'veg' LIMIT ?");
$stmt_veg->bind_param("i", $veg_limit);
$stmt_veg->execute();
$veg_result = $stmt_veg->get_result();
$stmt_nonveg = $conn->prepare("SELECT * FROM food_items WHERE category = 'non-veg' LIMIT ?");
$stmt_nonveg->bind_param("i", $nonveg_limit);
$stmt_nonveg->execute();
$nonveg_result = $stmt_nonveg->get_result();
$stmt_special = $conn->prepare("SELECT * FROM food_items WHERE category = 'special' LIMIT ?");
$stmt_special->bind_param("i", $special_limit);
$stmt_special->execute();
$special_result = $stmt_special->get_result();
$veg_count_result = $conn->query("SELECT COUNT(*) as total FROM food_items WHERE category = 'veg'");
$nonveg_count_result = $conn->query("SELECT COUNT(*) as total FROM food_items WHERE category = 'non-veg'");
$special_count_result = $conn->query("SELECT COUNT(*) as total FROM food_items WHERE category = 'special'");
$veg_total = $veg_count_result->fetch_assoc()['total'];
$nonveg_total = $nonveg_count_result->fetch_assoc()['total'];
$special_total = $special_count_result->fetch_assoc()['total'];
?>
<div class="menu-container">
<header class="menu-header">
<h1>Hotel Annapurna</h1>
<p>Discover our curated selection of delightful dishes</p>
</header>
<!-- Veg Items Section -->
<div class="menu-section">
<h2 class="menu-section-title">Vegetarian Delights</h2>
<table class="menu-table">
<thead>
<tr>
<th>#</th>
<th>Select</th>
<th>Image</th>
<th>Food Name</th>
<th>Price</th>
<th>Special Price</th>
</tr>
</thead>
<tbody>
<?php
$counter = 1;
while($row = mysqli_fetch_assoc($veg_result)):
$discount_price = $row['discount_price'] ? $row['discount_price'] : $row['price'];
?>
<tr>
<td><?php echo $counter++; ?></td>
<td><input type="checkbox" class="menu-checkbox" data-id="<?php echo $row['id']; ?>" data-name="<?php echo htmlspecialchars($row['food_name']); ?>" data-price="<?php echo $row['price']; ?>" data-discount="<?php echo $discount_price; ?>" data-image="<?php echo htmlspecialchars($row['image_path']); ?>"></td>
<td><img src="<?php echo !empty($row['image_path']) ? htmlspecialchars($row['image_path']) : 'https://via.placeholder.com/100x100?text=No+Image'; ?>" alt="<?php echo htmlspecialchars($row['food_name']); ?>"></td>
<td class="menu-item-name"><?php echo htmlspecialchars($row['food_name']); ?></td>
<td class="price-column">RS <?php echo number_format($row['price'], 2); ?></td>
<td class="discount-column">RS <?php echo number_format($discount_price, 2); ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<div class="see-more-container">
<?php if($veg_total > $veg_current_page * $limit): ?>
<a href="?veg_page=<?php echo $veg_current_page + 1; ?>&nonveg_page=<?php echo $nonveg_current_page; ?>&special_page=<?php echo $special_current_page; ?>" class="see-more-btn">See More Vegetarian Items</a>
<?php endif; ?>
<?php if($veg_current_page > 1): ?>
<a href="?veg_page=<?php echo $veg_current_page - 1; ?>&nonveg_page=<?php echo $nonveg_current_page; ?>&special_page=<?php echo $special_current_page; ?>" class="see-less-btn">See Less</a>
<?php endif; ?>
</div>
</div>
<!-- Non-Veg Items Section -->
<div class="menu-section">
<h2 class="menu-section-title">Non-Vegetarian Specialties</h2>
<table class="menu-table">
<thead>
<tr>
<th>#</th>
<th>Select</th>
<th>Image</th>
<th>Food Name</th>
<th>Price</th>
<th>Special Price</th>
</tr>
</thead>
<tbody>
<?php
$counter = 1;
while($row = mysqli_fetch_assoc($nonveg_result)):
$discount_price = $row['discount_price'] ? $row['discount_price'] : $row['price'];
?>
<tr>
<td><?php echo $counter++; ?></td>
<td><input type="checkbox" class="menu-checkbox" data-id="<?php echo $row['id']; ?>" data-name="<?php echo htmlspecialchars($row['food_name']); ?>" data-price="<?php echo $row['price']; ?>" data-discount="<?php echo $discount_price; ?>" data-image="<?php echo htmlspecialchars($row['image_path']); ?>"></td>
<td><img src="<?php echo !empty($row['image_path']) ? htmlspecialchars($row['image_path']) : 'https://via.placeholder.com/100x100?text=No+Image'; ?>" alt="<?php echo htmlspecialchars($row['food_name']); ?>"></td>
<td class="menu-item-name"><?php echo htmlspecialchars($row['food_name']); ?></td>
<td class="price-column">RS <?php echo number_format($row['price'], 2); ?></td>
<td class="discount-column">RS <?php echo number_format($discount_price, 2); ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<div class="see-more-container">
<?php if($nonveg_total > $nonveg_current_page * $limit): ?>
<a href="?veg_page=<?php echo $veg_current_page; ?>&nonveg_page=<?php echo $nonveg_current_page + 1; ?>&special_page=<?php echo $special_current_page; ?>" class="see-more-btn">See More Non-Vegetarian Items</a>
<?php endif; ?>
<?php if($nonveg_current_page > 1): ?>
<a href="?veg_page=<?php echo $veg_current_page; ?>&nonveg_page=<?php echo $nonveg_current_page - 1; ?>&special_page=<?php echo $special_current_page; ?>" class="see-less-btn">See Less</a>
<?php endif; ?>
</div>
</div>
<!-- Special Items Section -->
<div class="menu-section todays-special">
<h2 class="menu-section-title">Chef's Special</h2>
<table class="menu-table">
<thead>
<tr>
<th>#</th>
<th>Select</th>
<th>Image</th>
<th>Food Name</th>
<th>Price</th>
<th>Special Price</th>
<th>Available On</th>
</tr>
</thead>
<tbody>
<?php
$counter = 1;
while($row = mysqli_fetch_assoc($special_result)):
$discount_price = $row['discount_price'] ? $row['discount_price'] : $row['price'];
?>
<tr>
<td><?php echo $counter++; ?></td>
<td><input type="checkbox" class="menu-checkbox" data-id="<?php echo $row['id']; ?>" data-name="<?php echo htmlspecialchars($row['food_name']); ?>" data-price="<?php echo $row['price']; ?>" data-discount="<?php echo $discount_price; ?>" data-image="<?php echo htmlspecialchars($row['image_path']); ?>"></td>
<td><img src="<?php echo !empty($row['image_path']) ? htmlspecialchars($row['image_path']) : 'https://via.placeholder.com/100x100?text=No+Image'; ?>" alt="<?php echo htmlspecialchars($row['food_name']); ?>"></td>
<td class="menu-item-name"><?php echo htmlspecialchars($row['food_name']); ?></td>
<td class="price-column">RS <?php echo number_format($row['price'], 2); ?></td>
<td class="discount-column">RS <?php echo number_format($discount_price, 2); ?></td>
<td>
<?php
$days = !empty($row['available_days']) ? $row['available_days'] : 'All Days';
$allDays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
$availableDays = array_map('trim', explode(',', $days));
if (strtolower($days) === 'all days' || strtolower($days) === 'everyday') {
echo '<div style="display: flex; gap: 3px; flex-wrap: wrap;">';
foreach ($allDays as $day) {
echo '<span style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 4px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">' . $day . '</span>';
}
echo '</div>';
} else {
echo '<div style="display: flex; gap: 3px; flex-wrap: wrap;">';
foreach ($allDays as $day) {
$isAvailable = false;
foreach ($availableDays as $availDay) {
if (stripos($availDay, substr($day, 0, 3)) !== false || stripos($day, $availDay) !== false) {
$isAvailable = true;
break;
}
}
if ($isAvailable) {
echo '<span style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 4px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">' . $day . '</span>';
} else {
echo '<span style="background: #e0e0e0; color: #999; padding: 4px 8px; border-radius: 12px; font-size: 11px; font-weight: 600;">' . $day . '</span>';
}
}
echo '</div>';
}
?>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<div class="see-more-container">
<?php if($special_total > $special_current_page * $limit): ?>
<a href="?veg_page=<?php echo $veg_current_page; ?>&nonveg_page=<?php echo $nonveg_current_page; ?>&special_page=<?php echo $special_current_page + 1; ?>" class="see-more-btn">See More Special Items</a>
<?php endif; ?>
<?php if($special_current_page > 1): ?>
<a href="?veg_page=<?php echo $veg_current_page; ?>&nonveg_page=<?php echo $nonveg_current_page; ?>&special_page=<?php echo $special_current_page - 1; ?>" class="see-less-btn">See Less</a>
<?php endif; ?>
</div>
</div>
<div class="selected-items-container">
<div class="selected-items-header">
<h2>Selected Items</h2>
</div>
<table class="menu-table" id="menu-selected-table">
<thead>
<tr>
<th>Image</th>
<th>Item</th>
<th>Price</th>
<th>Special Price</th>
<th>You Save</th>
</tr>
</thead>
<tbody>
<!-- Selected items will appear here -->
</tbody>
<tfoot>
<tr class="menu-total-row">
<td colspan="2" style="text-align: right; font-weight: bold;">Total</td>
<td id="menu-total-price" style="font-weight: bold;">RS 0.00</td>
<td id="menu-total-discount" style="font-weight: bold;">RS 0.00</td>
<td id="menu-total-savings" style="font-weight: bold;">RS 0.00</td>
</tr>
</tfoot>
</table>
<div class="menu-buttons">
<button class="menu-button menu-button-cart" id="menu-add-cart">Add to Cart</button>
<button class="menu-button menu-button-buy" id="menu-buy-now">Buy Now</button>
</div>
</div>
</div>
<script>
const menuCheckboxes = document.querySelectorAll('.menu-checkbox');
const menuSelectedTable = document.querySelector('#menu-selected-table tbody');
const menuTotalPrice = document.getElementById('menu-total-price');
const menuTotalDiscount = document.getElementById('menu-total-discount');
const menuTotalSavings = document.getElementById('menu-total-savings');
let menuSelectedItems = [];
function updateMenuTotals() {
const totals = menuSelectedItems.reduce((acc, item) => ({
price: acc.price + (parseFloat(item.price) || 0),
discount: acc.discount + (parseFloat(item.discount_price) || parseFloat(item.price) || 0)
}), { price: 0, discount: 0 });
const savings = totals.price - totals.discount;
menuTotalPrice.textContent = `RS ${totals.price.toFixed(2)}`;
menuTotalDiscount.textContent = `RS ${totals.discount.toFixed(2)}`;
menuTotalSavings.textContent = `RS ${savings.toFixed(2)}`;
}
function updateMenuSelectedTable() {
menuSelectedTable.innerHTML = '';
menuSelectedItems.forEach(item => {
const price = parseFloat(item.price) || 0;
const discount = parseFloat(item.discount_price) || price;
const savings = (price - discount).toFixed(2);
const imageUrl = item.image_url || item.image || 'images/menu/demoFood.jpg';
const row = document.createElement('tr');
row.innerHTML = `
<td><img src="${imageUrl}" alt="${item.food_name}" style="width: 50px; height: 50px; object-fit: cover; border-radius: 4px;"></td>
<td class="menu-item-name">${item.food_name || 'Unknown Item'}</td>
<td class="price-column">RS ${price.toFixed(2)}</td>
<td class="discount-column">RS ${discount.toFixed(2)}</td>
<td class="menu-price">RS ${savings}</td>
`;
menuSelectedTable.appendChild(row);
});
updateMenuTotals();
}
menuCheckboxes.forEach(checkbox => {
checkbox.addEventListener('change', (e) => {
const checkbox = e.target;
const itemData = {
id: parseInt(checkbox.dataset.id),
food_name: checkbox.dataset.name,
price: parseFloat(checkbox.dataset.price),
discount_price: parseFloat(checkbox.dataset.discount),
image_url: checkbox.dataset.image || checkbox.closest('tr').querySelector('img')?.src || 'https://via.placeholder.com/100x100?text=No+Image'
};
if (checkbox.checked) {
menuSelectedItems.push(itemData);
} else {
menuSelectedItems = menuSelectedItems.filter(item => item.id !== itemData.id);
}
updateMenuSelectedTable();
});
});
document.getElementById('menu-add-cart').addEventListener('click', () => {
if (menuSelectedItems.length === 0) {
alert('Please select items to add to cart!');
return;
}
const cart = JSON.parse(localStorage.getItem('hotelCart') || '{"food":[],"rooms":[],"tables":[]}');
menuSelectedItems.forEach(item => {
const existing = cart.food.find(f => f.id === item.id);
if (existing) {
existing.quantity = (existing.quantity || 1) + 1;
} else {
cart.food.push({
id: item.id,
name: item.food_name,
price: item.price,
image: item.image_url || 'images/menu/demoFood.jpg',
quantity: 1,
type: 'food'
});
}
});
localStorage.setItem('hotelCart', JSON.stringify(cart));
alert(`✓ ${menuSelectedItems.length} item(s) added to cart!`);
window.location.href = 'cart.php';
});
document.getElementById('menu-buy-now').addEventListener('click', () => {
if (menuSelectedItems.length === 0) {
alert('Please select items to purchase!');
return;
}
const cart = JSON.parse(localStorage.getItem('hotelCart') || '{"foods":[],"rooms":[],"tables":[]}');
menuSelectedItems.forEach(item => {
const existing = cart.foods.find(f => f.id === item.id);
if (existing) {
existing.quantity = (existing.quantity || 1) + 1;
} else {
cart.foods.push({ ...item, quantity: 1, type: 'food' });
}
});
localStorage.setItem('hotelCart', JSON.stringify(cart));
window.location.href = 'cart.php';
});
</script>
<?php require_once('includes/footer.php') ?>