Please fill in all fields.
"; } } //Copy Submission if ($_POST['submissionType'] == "copy") { $bookID = $_POST['book'] ?? ''; $amount = $_POST['amount'] ?? ''; $copyCondition = $_POST['condition'] ?? ''; if ($bookID && $amount && $copyCondition) { addCopies($pdo, $bookID, $amount, $copyCondition); } else { echo "Please fill in all fields.
"; } } //Borrower Submission if ($_POST['submissionType'] == "borrower") { $firstname = $_POST['firstname'] ?? ''; $lastname = $_POST['lastname'] ?? ''; $role = $_POST['role'] ?? ''; if ($firstname && $lastname && $role) { addBorrower($pdo, $firstname, $lastname, $role); } else { echo "Please fill in all fields.
"; } } if ($_POST['submissionType'] == "loan") { $copyID = $_POST['copyID'] ?? ''; $borrowerID = $_POST['borrowerID'] ?? ''; $borrowedDate = $_POST['borrowedDate'] ?? ''; $dueDate = $_POST['dueDate']; if ($copyID && $borrowerID && $borrowedDate && $dueDate) { addLoan($pdo, $copyID, $borrowerID, $borrowedDate, $dueDate); } else { echo "Please fill in all fields.
"; } } if ($_POST['submissionType'] == "return") { $copyIDLoanID = explode("-", $_POST['copyID-loanID'], 2); $copyID = $copyIDLoanID[0]; $loanID = $copyIDLoanID[1]; $returnedDate = $_POST['returnedDate']; if ($copyID && $loanID) { removeLoan($pdo, $copyID, $loanID, $returnedDate); } else { echo "Please fill in all fields
"; } } if ($_POST['submissionType'] == "selectRequest") { $selectRequest = $_POST['sqlSelectTextarea']; if ($selectRequest) { selectRequest($pdo, $selectRequest); } else { echo "Please fill in all fields
"; } } } if ($_SERVER['REQUEST_METHOD'] == 'GET') { if (!hash_equals($sessionToken, $getToken)) { die("Invalid request: Token mismatch."); } if ($_GET['submissionType'] == "getCopies") { $bookID = $_GET['bookID']; if ($bookID) { $copies = getAvailableCopiesOfBook($pdo, $bookID); echo json_encode($copies); } else { echo json_encode([]); } } if ($_GET['submissionType'] == "getReturnCopies") { $borrowerID = $_GET['borrowerID']; if ($borrowerID) { $copies = getBorrowedCopiesOfBorrower($pdo, $borrowerID); echo json_encode($copies); } else { echo json_encode([]); } } } ?>