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']; } } ?>
Welcome back,
********
Visa ending in 2027
Expires 12/27
Status:
Valid until:
Title | Borrowed Date | Due Date | Status | Actions |
---|---|---|---|---|
" . htmlspecialchars($bookTitle) . " | "; echo "" . $formatted_date . " | "; echo "" . $dueDate->format('M d, Y') . " | "; echo "" . $loan['status'] . " | "; echo ""; // Handle renewals based on status if ($loan['status'] == 'Overdue') { echo ""; } else { //echo ""; echo ""; } echo " | "; echo "
Date | Description | Amount | Status |
---|---|---|---|
" . $formattedFineDate . " | "; echo "Late Return - " . htmlspecialchars($fine['title']) . " | "; echo "$" . $fineAmount . " | "; echo "" . htmlspecialchars($fine['fine_status']) . " | "; echo "