prepare($sql); $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); if(!isset($row['address'])) $row['address'] = "N/A"; if(!isset($row['phone'])) $row['phone'] = "N/A"; $row['membership_status'] = "N/A"; $row['expired_date'] = "N/A"; $sql = "SELECT * FROM member WHERE memberid = :userid"; $stmt = $conn->prepare($sql); $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT); $stmt->execute(); $res = $stmt->fetch(PDO::FETCH_ASSOC); if($stmt->rowCount() > 0) { $row['membership_status'] = $res['membership_status']; $row['expired_date'] = $res['expired_date']; } // CHECK IF MEMBERSHIP IS EXPIRED if ($row['expired_date'] < $current_date && $row['membership_status'] == 'Active') { $update_sql = "UPDATE member SET membership_status = 'Inactive' WHERE memberid = :userid"; $update_stmt = $conn->prepare($update_sql); $update_stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT); $update_stmt->execute(); $row['membership_status'] = 'Inactive'; } else if ($row['expired_date'] > $current_date && $row['membership_status'] == 'Inactive') { $update_sql = "UPDATE member SET membership_status = 'Inactive' WHERE memberid = :userid"; $update_stmt = $conn->prepare($update_sql); $update_stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT); $update_stmt->execute(); $row['membership_status'] = 'Active'; } // LOAN QUERY $sql = "SELECT member.*, loan.* FROM users INNER JOIN member ON member.memberid = users.userid INNER JOIN loan ON loan.memberid = member.memberid WHERE users.userid = :userid;"; $stmt = $conn->prepare($sql); $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT); $stmt->execute(); $loans = $stmt->fetchAll(PDO::FETCH_ASSOC); $loanCount = 0; $currentDate = new DateTime(); $onTime = 0; $soon = 0; $overdue = 0; foreach ($loans as $loan) { if ($loan['status'] == 'Returned') { continue; } $loanCount++; $loanDate = new DateTime($loan['loandate']); $dueDate = clone $loanDate; $dueDate->modify('+14 days'); $daysSinceLoan = $currentDate->diff($loanDate)->days; if ($currentDate > $dueDate) { // Change status to Overdue $updateSql = "UPDATE loan SET status = 'Overdue' WHERE loanid = :loanid"; $updateStmt = $conn->prepare($updateSql); $updateStmt->bindParam(':loanid', $loan['loanid'], PDO::PARAM_INT); $updateStmt->execute(); $overdue++; } elseif ($daysSinceLoan >= 11 && $daysSinceLoan <= 13) { // Change status to Soon $updateSql = "UPDATE loan SET status = 'Soon' WHERE loanid = :loanid"; $updateStmt = $conn->prepare($updateSql); $updateStmt->bindParam(':loanid', $loan['loanid'], PDO::PARAM_INT); $updateStmt->execute(); $soon++; } elseif ($daysSinceLoan < 11) { // Change status to On Time $updateSql = "UPDATE loan SET status = 'On Time' WHERE loanid = :loanid"; $updateStmt = $conn->prepare($updateSql); $updateStmt->bindParam(':loanid', $loan['loanid'], PDO::PARAM_INT); $updateStmt->execute(); $onTime++; } } // BOOK QUERY $sql = "SELECT loan.*, book.* FROM loan INNER JOIN Book_Copies ON loan.bookcopyid = Book_Copies.copyid INNER JOIN Book ON Book_Copies.bookid = book.bookid WHERE loan.memberid = :memberid;"; $stmt = $conn->prepare($sql); $stmt->bindParam(':memberid', $_SESSION['userid'], PDO::PARAM_INT); $stmt->execute(); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); // FINE QUERY $sql = "SELECT fine.*, loan.*, member.*, Book_Copies.*, book.*, fine.status AS fine_status, loan.status AS loan_status FROM fine INNER JOIN loan ON fine.loanid = loan.loanid INNER JOIN member ON loan.memberid = member.memberid INNER JOIN Book_Copies ON loan.BookCopyID = Book_Copies.copyid INNER JOIN book ON Book_Copies.bookid = book.bookid WHERE member.memberid = :memberid;"; $stmt = $conn->prepare($sql); $stmt->bindParam(':memberid', $_SESSION['userid'], PDO::PARAM_INT); $stmt->execute(); $fines = $stmt->fetchAll(PDO::FETCH_ASSOC); $totalFine = 0; foreach ($fines as $fine) { if ($fine['fine_status'] == 'Unpaid') { $totalFine += $fine['fineamount']; } } ?> Profile

Account Overview

Items Borrowed
Items On Hold
Overdue Items
$
Current Fines

Alerts

You have overdue item/s and $ in unpaid fines.

item/s is due in the next 3 days.

View Details
'; echo '

Current Loans

'; echo ''; // Generate table header echo ''; echo ''; // Loop through loans and match with book details foreach ($loans as $loan) { // Skip returned books if ($loan['status'] == 'Returned') { continue; } // Find matching book details $bookTitle = ''; foreach ($results as $book) { if ($book['loanid'] == $loan['loanid']) { $bookTitle = $book['title']; break; } } // Calculate due date $loanDate = new DateTime($loan['loandate']); $dueDate = clone $loanDate; $dueDate->modify('+14 days'); // Get status class $statusClass = ''; switch ($loan['status']) { case 'Overdue': $statusClass = 'status-overdue'; break; case 'Soon': $statusClass = 'status-due-soon'; break; case 'On Time': $statusClass = 'status-ontime'; break; } $formatted_date = DateTime::createFromFormat('Y-m-d', $loan['loandate'])->format('M d, Y'); // Generate the row echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo ''; echo '
Title Borrowed Date Due Date Status Actions
" . htmlspecialchars($bookTitle) . "" . $formatted_date . "" . $dueDate->format('M d, Y') . "" . $loan['status'] . ""; // Handle renewals based on status if ($loan['status'] == 'Overdue') { echo ""; } else { //echo ""; echo ""; } echo "
'; echo '
'; } ?> '; echo '

Fines & Fees

'; echo ''; // Generate table header echo ''; echo ''; $totalUnpaid = 0; $hasUnpaidFines = false; // Loop through fines foreach ($fines as $fine) { $fineDate = new DateTime($fine['finedate']); $formattedFineDate = $fineDate->format('M d, Y'); $fineAmount = number_format($fine['fineamount'], 2); if ($fine['fine_status'] === 'Unpaid') { $totalUnpaid += $fine['fineamount']; $hasUnpaidFines = true; } // Generate the row echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo ''; echo '
Date Description Amount Status
" . $formattedFineDate . "Late Return - " . htmlspecialchars($fine['title']) . "$" . $fineAmount . "" . htmlspecialchars($fine['fine_status']) . "
'; if ($hasUnpaidFines) { $formattedTotal = number_format($totalUnpaid, 2); echo ' Pay Fines Online (Total: $' . $formattedTotal . ') '; } echo ''; } ?>