-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtables.php
More file actions
192 lines (166 loc) · 8 KB
/
Copy pathtables.php
File metadata and controls
192 lines (166 loc) · 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
<?php
require_once('includes/header.php');
require_once('config/db.php');
$is_logged_in = isset($_SESSION['logged_in']) && $_SESSION['logged_in'];
$limit = 9;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$total_limit = $limit * $page;
$stmt_tables = $conn->prepare("SELECT * FROM tables ORDER BY created_at DESC LIMIT ?");
$stmt_tables->bind_param("i", $total_limit);
$stmt_tables->execute();
$tables_result = $stmt_tables->get_result();
$tables_count_result = $conn->query("SELECT COUNT(*) as total FROM tables");
$total_tables = mysqli_fetch_assoc($tables_count_result)['total'];
$tables = [];
while($row = mysqli_fetch_assoc($tables_result)) {
$tables[] = $row;
}
?>
<main class="tables-container">
<header class="tables-hero">
<div class="tables-hero-overlay"></div>
<div class="tables-hero-content">
<h1>Dining Experiences</h1>
<p>Reserve your perfect dining spot in our elegant and luxurious restaurant spaces.</p>
</div>
</header>
<section class="tables-grid">
<?php foreach($tables as $table):
$price_today = $table['price_today'] ? $table['price_today'] : $table['price_main'];
$image_url = !empty($table['image_path']) ? $table['image_path'] : 'https://via.placeholder.com/400x300?text=Table';
?>
<article class="tables-card">
<div class="tables-card-image-wrapper">
<img src="<?php echo htmlspecialchars($image_url); ?>" alt="<?php echo htmlspecialchars($table['location']); ?> - Table <?php echo htmlspecialchars($table['table_no']); ?>" class="tables-image">
<div class="tables-card-overlay"></div>
<span class="tables-status-badge <?php echo $table['booking_status']; ?>"><?php echo ucfirst($table['booking_status']); ?></span>
</div>
<div class="tables-content">
<div class="tables-header">
<h2 class="tables-title"><?php echo htmlspecialchars($table['location']); ?> - Table <?php echo htmlspecialchars($table['table_no']); ?></h2>
<span class="tables-location-badge"><?php echo ucfirst($table['location']); ?></span>
</div>
<p class="tables-description"><?php echo htmlspecialchars($table['short_description']); ?></p>
<div class="tables-info">
<div class="tables-info-item">
<i class="fas fa-chair"></i>
<span><?php echo $table['total_chairs']; ?> Seat<?php echo $table['total_chairs'] > 1 ? 's' : ''; ?></span>
</div>
<div class="tables-info-item">
<i class="fas fa-map-pin"></i>
<span><?php echo ucfirst($table['location']); ?></span>
</div>
</div>
<div class="tables-features">
<span class="tables-feature"><i class="fas fa-star"></i> Premium Service</span>
<span class="tables-feature"><i class="fas fa-wine-glass-alt"></i> Full Bar</span>
<span class="tables-feature"><i class="fas fa-utensils"></i> Fine Dining</span>
</div>
<div class="tables-pricing">
<div class="tables-price-item">
<span class="tables-price-label">Regular Price</span>
<span class="tables-price-original">RS <?php echo number_format($table['price_main'], 2); ?></span>
</div>
<div class="tables-price-item">
<span class="tables-price-label">Today's Price</span>
<span class="tables-price-current">RS <?php echo number_format($price_today, 2); ?></span>
</div>
</div>
<div class="tables-savings">
You Save: RS <?php echo number_format($table['price_main'] - $price_today, 2); ?>
</div>
<footer class="tables-card-footer">
<button onclick="addTableToCart(<?php echo htmlspecialchars(json_encode($table)); ?>)" class="tables-reserve-btn">
<i class="fas fa-shopping-cart"></i> Add to Cart
</button>
<button onclick="reserveTable(<?php echo htmlspecialchars(json_encode($table)); ?>)" class="tables-explore-btn">
<i class="fas fa-calendar-check"></i> Reserve Now
</button>
</footer>
</div>
</article>
<?php endforeach; ?>
</section>
<div class="tables-pagination">
<?php if($total_tables > $page * $limit): ?>
<a href="?page=<?php echo $page + 1; ?>" class="tables-see-more-btn">See More Tables</a>
<?php endif; ?>
<?php if($page > 1): ?>
<a href="?page=<?php echo $page - 1; ?>" class="tables-see-less-btn">See Less</a>
<?php endif; ?>
</div>
</main>
<script>
const isLoggedIn = <?php echo $is_logged_in ? 'true' : 'false'; ?>;
function addTableToCart(table) {
// Check table availability
if (table.booking_status !== 'available') {
alert('⚠️ This table is not available for cart.\n\nCurrent Status: ' + table.booking_status.toUpperCase());
return;
}
const cartManager = {
loadCart: function() {
const stored = localStorage.getItem('hotelCart');
return stored ? JSON.parse(stored) : { foods: [], rooms: [], tables: [] };
},
saveCart: function(cart) {
localStorage.setItem('hotelCart', JSON.stringify(cart));
}
};
const cart = cartManager.loadCart();
const reservationDate = new Date().toISOString().split('T')[0];
const tableData = {
...table,
date: reservationDate,
quantity: 1
};
const existing = cart.tables.find(t => t.id === table.id && t.date === reservationDate);
if (existing) {
existing.quantity += 1;
} else {
cart.tables.push(tableData);
}
cartManager.saveCart(cart);
alert(`✓ Table ${table.table_no} added to cart!`);
window.location.href = 'cart.php';
window.location.href = 'cart.php';
}
function reserveTable(table) {
if (!isLoggedIn) {
alert('Please login to continue with your reservation');
window.location.href = 'login.php';
return;
}
// Check table availability
if (table.booking_status !== 'available') {
alert('⚠️ This table is not available for booking.\n\nCurrent Status: ' + table.booking_status.toUpperCase());
return;
}
const price = table.price_today || table.price_main;
const message = `Are you sure you want to reserve ${table.location} - Table ${table.table_no} (${table.total_chairs} seats) for RS ${parseFloat(price).toFixed(2)}?`;
if (confirm(message)) {
const formData = new FormData();
formData.append('item_type', 'table');
formData.append('item_id', table.id);
formData.append('item_data', JSON.stringify(table));
formData.append('price', price);
fetch('api/create-booking.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.location.href = 'payment.php?booking_id=' + data.booking_id;
} else {
alert('❌ ' + (data.message || 'Failed to create reservation'));
}
})
.catch(error => {
console.error('Error:', error);
alert('❌ An error occurred. Please try again.');
});
}
}
</script>
<?php require_once('includes/footer.php'); ?>