192 lines
No EOL
6.8 KiB
PHP
192 lines
No EOL
6.8 KiB
PHP
<script>
|
|
document.getElementById('bookForm').addEventListener('submit', function (e) {
|
|
e.preventDefault(); // prevent normal form submission
|
|
|
|
const formData = new FormData(this);
|
|
|
|
fetch('submission.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
document.getElementById('result').innerHTML = data; // show success/error
|
|
this.reset(); // reset form after success
|
|
})
|
|
.catch(error => {
|
|
document.getElementById('result').innerHTML = 'Error: ' + error;
|
|
});
|
|
});
|
|
|
|
document.getElementById('copyForm').addEventListener('submit', function (e) {
|
|
e.preventDefault(); // prevent normal form submission
|
|
|
|
const formData = new FormData(this);
|
|
|
|
fetch('submission.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
document.getElementById('result').innerHTML = data; // show success/error
|
|
this.reset(); // optional: reset form after success
|
|
})
|
|
.catch(error => {
|
|
document.getElementById('result').innerHTML = 'Error: ' + error;
|
|
});
|
|
});
|
|
|
|
document.getElementById('borrowerForm').addEventListener('submit', function (e) {
|
|
e.preventDefault(); // prevent normal form submission
|
|
|
|
const formData = new FormData(this);
|
|
|
|
fetch('submission.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
document.getElementById('result').innerHTML = data; // show success/error
|
|
this.reset(); // optional: reset form after success
|
|
})
|
|
.catch(error => {
|
|
document.getElementById('result').innerHTML = 'Error: ' + error;
|
|
});
|
|
});
|
|
|
|
document.getElementById('loanForm').addEventListener('submit', function (e) {
|
|
e.preventDefault(); // prevent normal form submission
|
|
|
|
const formData = new FormData(this);
|
|
|
|
fetch('submission.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
document.getElementById('result').innerHTML = data; // show success/error
|
|
this.reset(); // optional: reset form after success
|
|
})
|
|
.catch(error => {
|
|
document.getElementById('result').innerHTML = 'Error: ' + error;
|
|
});
|
|
|
|
location.reload();
|
|
});
|
|
|
|
document.getElementById('checkInForm').addEventListener('submit', function (e) {
|
|
e.preventDefault(); // prevent normal form submission
|
|
|
|
const formData = new FormData(this);
|
|
|
|
fetch('submission.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
document.getElementById('result').innerHTML = data; // show success/error
|
|
this.reset(); // optional: reset form after success
|
|
})
|
|
.catch(error => {
|
|
document.getElementById('result').innerHTML = 'Error: ' + error;
|
|
});
|
|
|
|
location.reload();
|
|
});
|
|
|
|
document.getElementById('sqlSelectInputForm').addEventListener('submit', function (e) {
|
|
e.preventDefault(); // prevent normal form submission
|
|
|
|
const formData = new FormData(this);
|
|
|
|
fetch('submission.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
const container = document.getElementById('result');
|
|
|
|
container.innerHTML = data; // show success/error
|
|
this.reset(); // optional: reset form after success
|
|
|
|
// scroll after the new content is in place
|
|
if (container) {
|
|
container.scrollIntoView({ behavior: 'smooth' });
|
|
}
|
|
})
|
|
.catch(error => {
|
|
document.getElementById('result').innerHTML = 'Error: ' + error;
|
|
});
|
|
});
|
|
|
|
document.querySelector("#bookSelect").addEventListener("change", function () {
|
|
const csrf_token = "<?= $_SESSION['csrf_token'] ?>";
|
|
const bookID = this.value;
|
|
const copySelect = document.querySelector("#copySelect");
|
|
|
|
// reset exemplar list
|
|
copySelect.innerHTML = '<option value="">Lade Exemplare...</option>';
|
|
|
|
if (bookID) {
|
|
fetch("submission.php?submissionType=" + encodeURI("getCopies") + "&bookID=" + encodeURIComponent(bookID) + "&csrf_token=" + encodeURIComponent(csrf_token))
|
|
.then(response => response.json())
|
|
.then(copies => {
|
|
copySelect.innerHTML = "";
|
|
if (copies.length === 0) {
|
|
copySelect.innerHTML = '<option value="">Keine Exemplare verfügbar</option>';
|
|
} else {
|
|
copies.forEach(copy => {
|
|
const opt = document.createElement("option");
|
|
opt.value = copy.copyID;
|
|
opt.textContent = "Exemplar #" + copy.copyID + " (" + copy.bookCondition + ")";
|
|
copySelect.appendChild(opt);
|
|
});
|
|
}
|
|
})
|
|
.catch(err => {
|
|
copySelect.innerHTML = '<option value="">Fehler beim Laden</option>';
|
|
console.error(err);
|
|
});
|
|
} else {
|
|
copySelect.innerHTML = '<option value="">Bitte zuerst ein Buch wählen</option>';
|
|
}
|
|
});
|
|
|
|
document.querySelector("#borrowerSelect").addEventListener("change", function () {
|
|
const csrf_token = "<?= $_SESSION['csrf_token'] ?>";
|
|
const borrowerID = this.value;
|
|
const copySelect = document.querySelector("#copyReturnSelect");
|
|
|
|
// reset copy list
|
|
copySelect.innerHTML = '<option value="">Lade Exemplare...</option>';
|
|
|
|
if (borrowerID) {
|
|
fetch("submission.php?submissionType=" + encodeURI("getReturnCopies") + "&borrowerID=" + encodeURIComponent(borrowerID) + "&csrf_token=" + encodeURIComponent(csrf_token))
|
|
.then(response => response.json())
|
|
.then(copies => {
|
|
copySelect.innerHTML = "";
|
|
if (copies.length === 0) {
|
|
copySelect.innerHTML = '<option value="">Keine Exemplare ausgeliehen</option>';
|
|
} else {
|
|
copies.forEach(copy => {
|
|
const opt = document.createElement("option");
|
|
opt.value = copy.copyID + "-" + copy.loanID;
|
|
opt.textContent = copy.bookTitle + " von " + copy.bookAuthor + " Exemplar #" + copy.copyID + " (" + copy.bookCondition + ")";
|
|
copySelect.appendChild(opt);
|
|
});
|
|
}
|
|
})
|
|
.catch(err => {
|
|
copySelect.innerHTML = '<option value="">Fehler beim Laden</option>';
|
|
console.error(err);
|
|
});
|
|
} else {
|
|
copySelect.innerHTML = '<option value="">Bitte zuerst einen Ausleiher wählen</option>';
|
|
}
|
|
});
|
|
</script> |