1 | <?php
|
---|
2 | session_start();
|
---|
3 |
|
---|
4 | require './connect.php';
|
---|
5 |
|
---|
6 | if(!isset($_SESSION['userid'])) {
|
---|
7 | header("Location: ./Sign&Log.php");
|
---|
8 | }
|
---|
9 |
|
---|
10 | $current_date = date('Y-m-d');
|
---|
11 |
|
---|
12 | // GET USER DETAILS
|
---|
13 | $sql = "SELECT * FROM users WHERE userid = :userid";
|
---|
14 | $stmt = $conn->prepare($sql);
|
---|
15 | $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
16 | $stmt->execute();
|
---|
17 | $row = $stmt->fetch(PDO::FETCH_ASSOC);
|
---|
18 |
|
---|
19 | if(!isset($row['address'])) $row['address'] = "N/A";
|
---|
20 | if(!isset($row['phone'])) $row['phone'] = "N/A";
|
---|
21 |
|
---|
22 | $row['membership_status'] = "N/A";
|
---|
23 | $row['expired_date'] = "N/A";
|
---|
24 |
|
---|
25 | $sql = "SELECT * FROM member WHERE memberid = :userid";
|
---|
26 | $stmt = $conn->prepare($sql);
|
---|
27 | $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
28 | $stmt->execute();
|
---|
29 |
|
---|
30 | $res = $stmt->fetch(PDO::FETCH_ASSOC);
|
---|
31 |
|
---|
32 | if($stmt->rowCount() > 0) {
|
---|
33 | $row['membership_status'] = $res['membership_status'];
|
---|
34 | $row['expired_date'] = $res['expired_date'];
|
---|
35 | }
|
---|
36 |
|
---|
37 | // CHECK IF MEMBERSHIP IS EXPIRED
|
---|
38 | if ($row['expired_date'] < $current_date && $row['membership_status'] == 'Active') {
|
---|
39 | $update_sql = "UPDATE member SET membership_status = 'Inactive' WHERE memberid = :userid";
|
---|
40 | $update_stmt = $conn->prepare($update_sql);
|
---|
41 | $update_stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
42 | $update_stmt->execute();
|
---|
43 |
|
---|
44 | $row['membership_status'] = 'Inactive';
|
---|
45 | }
|
---|
46 | else if ($row['expired_date'] > $current_date && $row['membership_status'] == 'Inactive') {
|
---|
47 | $update_sql = "UPDATE member SET membership_status = 'Inactive' WHERE memberid = :userid";
|
---|
48 | $update_stmt = $conn->prepare($update_sql);
|
---|
49 | $update_stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
50 | $update_stmt->execute();
|
---|
51 |
|
---|
52 | $row['membership_status'] = 'Active';
|
---|
53 | }
|
---|
54 |
|
---|
55 | // LOAN QUERY
|
---|
56 | $sql = "SELECT member.*, loan.* FROM users INNER JOIN member ON member.memberid = users.userid
|
---|
57 | INNER JOIN loan ON loan.memberid = member.memberid
|
---|
58 | WHERE users.userid = :userid;";
|
---|
59 | $stmt = $conn->prepare($sql);
|
---|
60 | $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
61 | $stmt->execute();
|
---|
62 | $loans = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
---|
63 |
|
---|
64 | $loanCount = 0;
|
---|
65 |
|
---|
66 | $currentDate = new DateTime();
|
---|
67 |
|
---|
68 | $onTime = 0;
|
---|
69 | $soon = 0;
|
---|
70 | $overdue = 0;
|
---|
71 |
|
---|
72 | foreach ($loans as $loan) {
|
---|
73 |
|
---|
74 | if ($loan['status'] == 'Returned') {
|
---|
75 | continue;
|
---|
76 | }
|
---|
77 |
|
---|
78 | $loanCount++;
|
---|
79 |
|
---|
80 | $loanDate = new DateTime($loan['loandate']);
|
---|
81 | $dueDate = clone $loanDate;
|
---|
82 | $dueDate->modify('+14 days');
|
---|
83 |
|
---|
84 | $daysSinceLoan = $currentDate->diff($loanDate)->days;
|
---|
85 |
|
---|
86 |
|
---|
87 | if ($currentDate > $dueDate) {
|
---|
88 | // Change status to Overdue
|
---|
89 | $updateSql = "UPDATE loan SET status = 'Overdue' WHERE loanid = :loanid";
|
---|
90 | $updateStmt = $conn->prepare($updateSql);
|
---|
91 | $updateStmt->bindParam(':loanid', $loan['loanid'], PDO::PARAM_INT);
|
---|
92 | $updateStmt->execute();
|
---|
93 | $overdue++;
|
---|
94 | } elseif ($daysSinceLoan >= 11 && $daysSinceLoan <= 13) {
|
---|
95 | // Change status to Soon
|
---|
96 | $updateSql = "UPDATE loan SET status = 'Soon' WHERE loanid = :loanid";
|
---|
97 | $updateStmt = $conn->prepare($updateSql);
|
---|
98 | $updateStmt->bindParam(':loanid', $loan['loanid'], PDO::PARAM_INT);
|
---|
99 | $updateStmt->execute();
|
---|
100 | $soon++;
|
---|
101 | } elseif ($daysSinceLoan < 11) {
|
---|
102 | // Change status to On Time
|
---|
103 | $updateSql = "UPDATE loan SET status = 'On Time' WHERE loanid = :loanid";
|
---|
104 | $updateStmt = $conn->prepare($updateSql);
|
---|
105 | $updateStmt->bindParam(':loanid', $loan['loanid'], PDO::PARAM_INT);
|
---|
106 | $updateStmt->execute();
|
---|
107 | $onTime++;
|
---|
108 | }
|
---|
109 |
|
---|
110 | }
|
---|
111 |
|
---|
112 | // BOOK QUERY
|
---|
113 | $sql = "SELECT loan.*, book.*
|
---|
114 | FROM loan
|
---|
115 | INNER JOIN Book_Copies ON loan.bookcopyid = Book_Copies.copyid
|
---|
116 | INNER JOIN Book ON Book_Copies.bookid = book.bookid
|
---|
117 | WHERE loan.memberid = :memberid;";
|
---|
118 |
|
---|
119 | $stmt = $conn->prepare($sql);
|
---|
120 | $stmt->bindParam(':memberid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
121 | $stmt->execute();
|
---|
122 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
---|
123 |
|
---|
124 |
|
---|
125 |
|
---|
126 | // FINE QUERY
|
---|
127 |
|
---|
128 | $sql = "SELECT
|
---|
129 | fine.*,
|
---|
130 | loan.*,
|
---|
131 | member.*,
|
---|
132 | Book_Copies.*,
|
---|
133 | book.*,
|
---|
134 | fine.status AS fine_status,
|
---|
135 | loan.status AS loan_status
|
---|
136 | FROM fine
|
---|
137 | INNER JOIN loan ON fine.loanid = loan.loanid
|
---|
138 | INNER JOIN member ON loan.memberid = member.memberid
|
---|
139 | INNER JOIN Book_Copies ON loan.BookCopyID = Book_Copies.copyid
|
---|
140 | INNER JOIN book ON Book_Copies.bookid = book.bookid
|
---|
141 | WHERE member.memberid = :memberid;";
|
---|
142 | $stmt = $conn->prepare($sql);
|
---|
143 | $stmt->bindParam(':memberid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
144 | $stmt->execute();
|
---|
145 | $fines = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
---|
146 |
|
---|
147 | $totalFine = 0;
|
---|
148 | foreach ($fines as $fine) {
|
---|
149 | if ($fine['fine_status'] == 'Unpaid') {
|
---|
150 | $totalFine += $fine['fineamount'];
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | ?>
|
---|
155 |
|
---|
156 | <!DOCTYPE html>
|
---|
157 | <html>
|
---|
158 | <head>
|
---|
159 | <title>Profile</title>
|
---|
160 | <link rel="stylesheet" href="CSS/Profile.css">
|
---|
161 | </head>
|
---|
162 | <body>
|
---|
163 | <?php include 'Components/Header.html';?>
|
---|
164 |
|
---|
165 | <div class="container">
|
---|
166 | <div class="page-header">
|
---|
167 | <h1 class="page-title">My Account</h1>
|
---|
168 | <p class="welcome-text">Welcome back, <?php echo $row['firstname']." ".$row['lastname'] ?></p>
|
---|
169 | </div>
|
---|
170 |
|
---|
171 | <div class="account-grid">
|
---|
172 | <div class="account-card">
|
---|
173 | <div class="card-header">
|
---|
174 | <svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
---|
175 | <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
|
---|
176 | <circle cx="12" cy="7" r="4"></circle>
|
---|
177 | </svg>
|
---|
178 | <h2 class="card-title">Account Details</h2>
|
---|
179 | </div>
|
---|
180 | <div class="card-content">
|
---|
181 | <p><?php echo $row['firstname']." ".$row['lastname'] ?><br><?php echo $row['email'] ?><br>********</p>
|
---|
182 | <a href="./EditProfile.php" class="action-link">Edit Profile</a>
|
---|
183 | </div>
|
---|
184 | </div>
|
---|
185 |
|
---|
186 | <div class="account-card">
|
---|
187 | <div class="card-header">
|
---|
188 | <svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
---|
189 | <rect x="1" y="4" width="22" height="16" rx="2" ry="2"></rect>
|
---|
190 | <line x1="1" y1="10" x2="23" y2="10"></line>
|
---|
191 | </svg>
|
---|
192 | <h2 class="card-title">Payment Methods</h2>
|
---|
193 | </div>
|
---|
194 | <div class="card-content">
|
---|
195 | <p>Visa ending in 2027<br>Expires 12/27</p>
|
---|
196 | <a href="#" class="action-link">Manage Payment Methods</a>
|
---|
197 | </div>
|
---|
198 | </div>
|
---|
199 |
|
---|
200 | <div class="account-card">
|
---|
201 | <div class="card-header">
|
---|
202 | <svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
---|
203 | <path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"></path>
|
---|
204 | <circle cx="12" cy="10" r="3"></circle>
|
---|
205 | </svg>
|
---|
206 | <h2 class="card-title">Addresses</h2>
|
---|
207 | </div>
|
---|
208 | <div class="card-content">
|
---|
209 | <p><?php echo $row['address'] ?></p>
|
---|
210 | <p><?php echo $row['phone'] ?></p>
|
---|
211 | <a href="./EditProfile.php" class="action-link">Manage Addresses</a>
|
---|
212 | </div>
|
---|
213 | </div>
|
---|
214 |
|
---|
215 | <div class="account-card">
|
---|
216 | <div class="card-header">
|
---|
217 | <svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
---|
218 | <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
|
---|
219 | <circle cx="12" cy="7" r="4"></circle>
|
---|
220 | </svg>
|
---|
221 | <h2 class="card-title">Membership</h2>
|
---|
222 | </div>
|
---|
223 | <div class="card-content">
|
---|
224 | <p>Status: <?php echo $row['membership_status']; ?><br>Valid until: <?php echo $row['expired_date']; ?></p>
|
---|
225 | <a href="<?php echo $row['membership_status'] != 'Suspended' ? './Renew.php' : '#'; ?>" class="action-link <?php echo $row['membership_status'] == 'Suspended' ? 'disabled' : ''; ?>"
|
---|
226 | <?php echo $row['membership_status'] == 'Suspended' ? 'onclick="return false;"' : ''; ?>>
|
---|
227 | Renew
|
---|
228 | </a>
|
---|
229 | </div>
|
---|
230 | </div>
|
---|
231 |
|
---|
232 | <div class="account-card">
|
---|
233 | <div class="card-header">
|
---|
234 | <svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
---|
235 | <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
|
---|
236 | <circle cx="12" cy="7" r="4"></circle>
|
---|
237 | </svg>
|
---|
238 | <h2 class="card-title">Actions</h2>
|
---|
239 | </div>
|
---|
240 | <div class="card-content">
|
---|
241 | <a href="./Logout.php" class="action-link">Logout</a>
|
---|
242 | </div>
|
---|
243 | </div>
|
---|
244 |
|
---|
245 | </div>
|
---|
246 |
|
---|
247 | <div class="account-summary">
|
---|
248 | <div class="summary-card">
|
---|
249 | <div class="card-header">
|
---|
250 | <svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
---|
251 | <path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"></path>
|
---|
252 | <path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"></path>
|
---|
253 | </svg>
|
---|
254 | <h2 class="card-title">Account Overview</h2>
|
---|
255 | </div>
|
---|
256 | <div class="stat-grid">
|
---|
257 | <div class="stat-item">
|
---|
258 | <div class="stat-value"><?php echo $loanCount ?></div>
|
---|
259 | <div class="stat-label">Items Borrowed</div>
|
---|
260 | </div>
|
---|
261 | <div class="stat-item">
|
---|
262 | <div class="stat-value"><?php echo $onTime + $soon ?></div>
|
---|
263 | <div class="stat-label">Items On Hold</div>
|
---|
264 | </div>
|
---|
265 | <div class="stat-item">
|
---|
266 | <div class="stat-value"><?php echo $overdue ?></div>
|
---|
267 | <div class="stat-label">Overdue Items</div>
|
---|
268 | </div>
|
---|
269 | <div class="stat-item">
|
---|
270 | <div class="stat-value">$<?php echo number_format($totalFine, 2)?></div>
|
---|
271 | <div class="stat-label">Current Fines</div>
|
---|
272 | </div>
|
---|
273 | </div>
|
---|
274 | </div>
|
---|
275 |
|
---|
276 | <div class="summary-card alert">
|
---|
277 | <div class="card-header">
|
---|
278 | <svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
---|
279 | <circle cx="12" cy="12" r="10"></circle>
|
---|
280 | <line x1="12" y1="8" x2="12" y2="12"></line>
|
---|
281 | <line x1="12" y1="16" x2="12.01" y2="16"></line>
|
---|
282 | </svg>
|
---|
283 | <h2 class="card-title">Alerts</h2>
|
---|
284 | </div>
|
---|
285 | <div class="card-content">
|
---|
286 | <p>You have <?php echo $overdue ?> overdue item/s and $<?php echo number_format($totalFine, 2)?> in unpaid fines.</p>
|
---|
287 | <p style="margin-top: 8px"><?php echo $soon ?> item/s is due in the next 3 days.</p>
|
---|
288 | <a href="#" class="action-link">View Details</a>
|
---|
289 | </div>
|
---|
290 | </div>
|
---|
291 | </div>
|
---|
292 |
|
---|
293 | <?php
|
---|
294 | function generateLoanCards($loans, $results) {
|
---|
295 | // Start the section card container
|
---|
296 | echo '<div class="section-card">';
|
---|
297 | echo '<h2 class="section-title">Current Loans</h2>';
|
---|
298 | echo '<table class="loan-table">';
|
---|
299 |
|
---|
300 | // Generate table header
|
---|
301 | echo '<thead>
|
---|
302 | <tr>
|
---|
303 | <th>Title</th>
|
---|
304 | <th>Borrowed Date</th>
|
---|
305 | <th>Due Date</th>
|
---|
306 | <th>Status</th>
|
---|
307 | <th>Actions</th>
|
---|
308 | </tr>
|
---|
309 | </thead>';
|
---|
310 |
|
---|
311 | echo '<tbody>';
|
---|
312 |
|
---|
313 | // Loop through loans and match with book details
|
---|
314 | foreach ($loans as $loan) {
|
---|
315 | // Skip returned books
|
---|
316 | if ($loan['status'] == 'Returned') {
|
---|
317 | continue;
|
---|
318 | }
|
---|
319 |
|
---|
320 | // Find matching book details
|
---|
321 | $bookTitle = '';
|
---|
322 | foreach ($results as $book) {
|
---|
323 | if ($book['loanid'] == $loan['loanid']) {
|
---|
324 | $bookTitle = $book['title'];
|
---|
325 | break;
|
---|
326 | }
|
---|
327 | }
|
---|
328 |
|
---|
329 | // Calculate due date
|
---|
330 | $loanDate = new DateTime($loan['loandate']);
|
---|
331 | $dueDate = clone $loanDate;
|
---|
332 | $dueDate->modify('+14 days');
|
---|
333 |
|
---|
334 | // Get status class
|
---|
335 | $statusClass = '';
|
---|
336 | switch ($loan['status']) {
|
---|
337 | case 'Overdue':
|
---|
338 | $statusClass = 'status-overdue';
|
---|
339 | break;
|
---|
340 | case 'Soon':
|
---|
341 | $statusClass = 'status-due-soon';
|
---|
342 | break;
|
---|
343 | case 'On Time':
|
---|
344 | $statusClass = 'status-ontime';
|
---|
345 | break;
|
---|
346 | }
|
---|
347 |
|
---|
348 | $formatted_date = DateTime::createFromFormat('Y-m-d', $loan['loandate'])->format('M d, Y');
|
---|
349 | // Generate the row
|
---|
350 | echo "<tr>";
|
---|
351 | echo "<td>" . htmlspecialchars($bookTitle) . "</td>";
|
---|
352 | echo "<td>" . $formatted_date . "</td>";
|
---|
353 | echo "<td>" . $dueDate->format('M d, Y') . "</td>";
|
---|
354 | echo "<td><span class='status-badge {$statusClass}'>" . $loan['status'] . "</span></td>";
|
---|
355 | echo "<td>";
|
---|
356 |
|
---|
357 | // Handle renewals based on status
|
---|
358 | if ($loan['status'] == 'Overdue') {
|
---|
359 | echo "<button class='renewal-btn' onclick='returnWithFine(" . $loan['loanid'] . ")'>Return & Pay Fine</button>";
|
---|
360 | } else {
|
---|
361 | //echo "<button class='renewal-btn'>Return Book</button>";
|
---|
362 | echo "<button class='renewal-btn' onclick='returnBook(" . $loan['loanid'] . ")'>Return Book</button>";
|
---|
363 | }
|
---|
364 |
|
---|
365 | echo "</td>";
|
---|
366 | echo "</tr>";
|
---|
367 | }
|
---|
368 |
|
---|
369 | echo '</tbody>';
|
---|
370 | echo '</table>';
|
---|
371 | echo '</div>';
|
---|
372 | }
|
---|
373 |
|
---|
374 | ?>
|
---|
375 |
|
---|
376 | <?php generateLoanCards($loans, $results); ?>
|
---|
377 |
|
---|
378 |
|
---|
379 | <?php
|
---|
380 | function generateFineCards($fines) {
|
---|
381 | // Start the section card container
|
---|
382 | echo '<div class="section-card">';
|
---|
383 | echo '<h2 class="section-title">Fines & Fees</h2>';
|
---|
384 | echo '<table class="loan-table">';
|
---|
385 |
|
---|
386 | // Generate table header
|
---|
387 | echo '<thead>
|
---|
388 | <tr>
|
---|
389 | <th>Date</th>
|
---|
390 | <th>Description</th>
|
---|
391 | <th>Amount</th>
|
---|
392 | <th>Status</th>
|
---|
393 | </tr>
|
---|
394 | </thead>';
|
---|
395 |
|
---|
396 | echo '<tbody>';
|
---|
397 |
|
---|
398 |
|
---|
399 | $totalUnpaid = 0;
|
---|
400 | $hasUnpaidFines = false;
|
---|
401 | // Loop through fines
|
---|
402 | foreach ($fines as $fine) {
|
---|
403 | $fineDate = new DateTime($fine['finedate']);
|
---|
404 | $formattedFineDate = $fineDate->format('M d, Y');
|
---|
405 |
|
---|
406 | $fineAmount = number_format($fine['fineamount'], 2);
|
---|
407 |
|
---|
408 | if ($fine['fine_status'] === 'Unpaid') {
|
---|
409 | $totalUnpaid += $fine['fineamount'];
|
---|
410 | $hasUnpaidFines = true;
|
---|
411 | }
|
---|
412 | // Generate the row
|
---|
413 | echo "<tr>";
|
---|
414 | echo "<td>" . $formattedFineDate . "</td>";
|
---|
415 | echo "<td>Late Return - " . htmlspecialchars($fine['title']) . "</td>";
|
---|
416 | echo "<td class='fine-amount'>$" . $fineAmount . "</td>";
|
---|
417 | echo "<td>" . htmlspecialchars($fine['fine_status']) . "</td>";
|
---|
418 | echo "</tr>";
|
---|
419 | }
|
---|
420 |
|
---|
421 | echo '</tbody>';
|
---|
422 | echo '</table>';
|
---|
423 |
|
---|
424 | if ($hasUnpaidFines) {
|
---|
425 | $formattedTotal = number_format($totalUnpaid, 2);
|
---|
426 | echo '<a href="#" class="action-link-pay" data-total="' . $totalUnpaid . '" onclick="payFines(); return false;">
|
---|
427 | Pay Fines Online (Total: $' . $formattedTotal . ')
|
---|
428 | </a>';
|
---|
429 | }
|
---|
430 |
|
---|
431 | echo '</div>';
|
---|
432 | }
|
---|
433 | ?>
|
---|
434 |
|
---|
435 | <?php generateFineCards($fines); ?>
|
---|
436 |
|
---|
437 |
|
---|
438 | <script src="Scripts/Profile.js"></script>
|
---|
439 |
|
---|
440 | <?php include 'Components/Footer.html';?>
|
---|
441 | </body>
|
---|
442 | </html> |
---|