-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
302 lines (277 loc) · 12.6 KB
/
Copy pathindex.php
File metadata and controls
302 lines (277 loc) · 12.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
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
<?php
date_default_timezone_set('Asia/Manila');
require_once 'config/session.php';
requireLogin();
require_once 'config/database.php';
$database = new Database();
$db = $database->getConnection();
// Handle parking spot updates
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['spot_id'])) {
$spot_id = $_POST['spot_id'];
$action = $_POST['action'] ?? '';
if ($action === 'occupy') {
$query = "UPDATE parking_spots SET status = 'occupied', user_id = :user_id, entry_time = NOW()
WHERE id = :spot_id AND status = 'available'";
$stmt = $db->prepare($query);
$stmt->bindParam(":user_id", $_SESSION['user_id']);
$stmt->bindParam(":spot_id", $spot_id);
$stmt->execute();
} elseif ($action === 'vacate') {
$query = "UPDATE parking_spots SET status = 'available', user_id = NULL, exit_time = NOW()
WHERE id = :spot_id AND user_id = :user_id";
$stmt = $db->prepare($query);
$stmt->bindParam(":user_id", $_SESSION['user_id']);
$stmt->bindParam(":spot_id", $spot_id);
$stmt->execute();
}
}
// Reset all parking spots to available
$query = "UPDATE parking_spots SET status = 'available', user_id = NULL, entry_time = NULL, exit_time = NULL";
$stmt = $db->prepare($query);
$stmt->execute();
$current_date_php = date('Y-m-d');
$current_time_php = date('H:i:s');
// Get parking spots with their current status and reservations
$query = "SELECT a.*,
CASE
WHEN EXISTS (
SELECT 1 FROM occupied_spots o
WHERE o.spot_id = a.id
AND o.status != 'completed'
AND (
(o.reservation_date = :cur_date AND :cur_time BETWEEN o.start_time AND o.end_time)
OR (o.reservation_date < :cur_date AND o.end_date >= :cur_date AND :cur_time <= o.end_time)
OR (o.reservation_date = :cur_date AND o.start_time > o.end_time AND :cur_time >= o.start_time)
OR (o.reservation_date = :cur_date AND o.start_time > o.end_time AND :cur_time <= o.end_time)
)
) THEN 'occupied'
WHEN EXISTS (
SELECT 1 FROM occupied_spots o
WHERE o.spot_id = a.id
AND o.status = 'reserved'
AND (
o.reservation_date > :cur_date
OR (o.reservation_date = :cur_date AND o.start_time > :cur_time)
OR (o.reservation_date < :cur_date AND o.end_date >= :cur_date)
)
) THEN 'reserved'
ELSE 'available'
END as current_status,
(
SELECT GROUP_CONCAT(
CONCAT(
DATE_FORMAT(o.reservation_date, '%Y-%m-%d'),
'|',
DATE_FORMAT(o.end_date, '%Y-%m-%d'),
'|',
TIME_FORMAT(o.start_time, '%H:%i'),
'|',
TIME_FORMAT(o.end_time, '%H:%i'),
'|',
CASE
WHEN (o.reservation_date = :cur_date AND :cur_time BETWEEN o.start_time AND o.end_time) OR
(o.reservation_date < :cur_date AND o.end_date >= :cur_date AND :cur_time <= o.end_time) OR
(o.reservation_date = :cur_date AND o.start_time > o.end_time AND :cur_time >= o.start_time) OR
(o.reservation_date = :cur_date AND o.start_time > o.end_time AND :cur_time <= o.end_time)
THEN 'ongoing'
ELSE o.status
END
) SEPARATOR '||'
)
FROM occupied_spots o
WHERE o.spot_id = a.id
AND o.status IN ('reserved', 'ongoing')
AND (
o.reservation_date > :cur_date
OR (o.reservation_date = :cur_date AND o.end_time > :cur_time)
OR (o.reservation_date < :cur_date AND o.end_date >= :cur_date)
OR (o.reservation_date = :cur_date AND o.start_time > o.end_time)
)
) as reservations
FROM available_spots a
ORDER BY CAST(SUBSTRING(a.spot_number, 2) AS UNSIGNED)";
$stmt = $db->prepare($query);
$stmt->bindParam(':cur_date', $current_date_php);
$stmt->bindParam(':cur_time', $current_time_php);
$stmt->execute();
$parking_spots = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Debug logging
error_log("Parking spots data: " . print_r($parking_spots, true));
// Calculate available spots count
$total_spots = count($parking_spots);
$available_spots = 0;
foreach ($parking_spots as $spot) {
if ($spot['current_status'] === 'available') {
$available_spots++;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Parking System Management">
<meta name="keywords" content="parking, system, management">
<meta name="author" content="Your Name">
<title>Smart Parking System</title>
<!-- Favicon -->
<link rel="icon" type="image/x-icon" href="favicon.ico">
<!-- CSS -->
<link rel="stylesheet" href="css/stylesIndex.css">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
</head>
<body>
<header>
<nav class="navbar">
<a href="index.php" class="nav-brand">
<img src="images/logo.png" alt="Smart Parking System Logo" class="nav-logo">
<span>Smart Parking System</span>
</a>
<div class="nav-links">
<a href="index.php" class="nav-link active">Home</a>
<a href="reservation.php" class="nav-link">Reserve Parking</a>
<a href="profile.php" class="nav-link">Profile</a>
<a href="logout.php" class="nav-link">Logout</a>
</div>
</nav>
</header>
<div class="dashboard-container">
<div class="dashboard-header">
<h1>Parking Dashboard</h1>
<p class="welcome-message">Welcome to the Smart Parking System</p>
</div>
<div class="parking-layout">
<div class="parking-info">
<div class="info-card">
<h3>Available Spots</h3>
<p class="count"><?php echo $available_spots; ?></p>
</div>
<div class="info-card">
<h3>Total Spots</h3>
<p class="count"><?php echo $total_spots; ?></p>
</div>
<div class="info-card">
<h3>Find Nearest Time</h3>
<div class="button-group">
<button id="findVacantSpots" class="find-time-btn">Find Vacant Spots</button>
<button id="findNearestTime" class="find-time-btn">Find Available Time</button>
</div>
</div>
</div>
<div class="parking-grid">
<div class="parking-row">
<?php
$first_row = array_slice($parking_spots, 0, 7);
foreach ($first_row as $spot): ?>
<div class="parking-spot <?php echo $spot['current_status']; ?>"
data-reservations="<?php echo htmlspecialchars($spot['reservations'] ?? ''); ?>">
<span class="spot-number"><?php echo htmlspecialchars($spot['spot_number']); ?></span>
<span class="spot-status"><?php echo ucfirst($spot['current_status']); ?></span>
</div>
<?php endforeach; ?>
</div>
<div class="road">
<div class="road-markings"></div>
</div>
<div class="parking-row">
<?php
$second_row = array_slice($parking_spots, 7);
foreach ($second_row as $spot): ?>
<div class="parking-spot <?php echo $spot['current_status']; ?>"
data-reservations="<?php echo htmlspecialchars($spot['reservations'] ?? ''); ?>">
<span class="spot-number"><?php echo htmlspecialchars($spot['spot_number']); ?></span>
<span class="spot-status"><?php echo ucfirst($spot['current_status']); ?></span>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
<footer>
<div class="footer-content">
<div class="footer-section">
<h3>About Us</h3>
<p>Smart parking solutions for modern cities. Making parking easier, one spot at a time.</p>
</div>
<div class="footer-section">
<h3>Quick Links</h3>
<p><a href="index.php">Home</a></p>
<p><a href="reservation.php">Reserve Parking</a></p>
<p><a href="profile.php">My Profile</a></p>
</div>
<div class="footer-section">
<h3>Contact</h3>
<p>Email: srjeerh09@gmail.com</p>
<p>Phone: (123) 456-7890</p>
<p>Address: 123 Parking Street, City</p>
</div>
<div class="footer-section">
<h3>Developer</h3>
<p><strong>Developer:</strong> Satwinder Jeerh</p>
<p><strong>Role:</strong> Full Stack Developer</p>
<p><strong>Specialization:</strong> Web Development, UI/UX Designer, Frontend Designer, Backend Developer</p>
<div class="developer-links">
<a href="https://github.com/Satwinder-stack" target="_blank" class="dev-link">
<i class="fab fa-github"></i> GitHub
</a>
<a href="https://www.linkedin.com/in/satwinder-jeerh-120331322/" target="_blank" class="dev-link">
<i class="fab fa-linkedin"></i> LinkedIn
</a>
<a href="" target="_blank" class="dev-link">
<i class="fas fa-globe"></i> Portfolio
</a>
</div>
</div>
<div class="footer-section">
<h3>Other Projects</h3>
<p><a href="https:" target="_blank">E-Commerce Platform</a></p>
<p><a href="https:" target="_blank">Task Management System</a></p>
<p><a href="https:" target="_blank">Weather Dashboard</a></p>
</div>
</div>
<div class="social-links">
<a href="#" class="social-link">📱</a>
<a href="#" class="social-link">💬</a>
<a href="#" class="social-link">📧</a>
</div>
<div class="footer-bottom">
<p>Parking System Management © <?php echo date('Y'); ?> | All rights reserved</p>
<p class="developer-credit">Developed with ❤️ by <a href="https://" target="_blank">Satwinder Jeerh</a></p>
</div>
</footer>
<!-- Sliding Panels -->
<div class="panel-overlay" id="panelOverlay"></div>
<!-- Reservation Details Panel -->
<div id="reservationPanel" class="sliding-panel">
<div class="sliding-panel-header">
<h2>Reservation Details</h2>
<button class="sliding-panel-close">×</button>
</div>
<div class="sliding-panel-content">
<div id="spotNumber" class="spot-header"></div>
<div class="reservations-list" id="reservationsList"></div>
</div>
</div>
<!-- Nearest Time Panel -->
<div id="nearestTimePanel" class="sliding-panel">
<div class="sliding-panel-header">
<h2>Nearest Available Time</h2>
<button class="sliding-panel-close">×</button>
</div>
<div class="sliding-panel-content" id="nearestTimeResult"></div>
</div>
<!-- Vacant Spots Panel -->
<div id="vacantSpotsPanel" class="sliding-panel">
<div class="sliding-panel-header">
<h2>Currently Vacant Spots</h2>
<button class="sliding-panel-close">×</button>
</div>
<div class="sliding-panel-content" id="vacantSpotsResult"></div>
</div>
<!-- Add Font Awesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<script src="js/scriptIndex.js"></script>
</body>
</html>