Lachenzelg/admin/courses-create.php
2025-01-07 03:02:25 +01:00

637 lines
30 KiB
PHP

<?php include "includes/header.php"; ?>
<div>
<div class="card card-body p-4">
<?= alertMessage() ?>
<?php
$paramResult = checkParamId("cat_id");
if (!is_numeric($paramResult)) {
echo '<div class="alert alert-danger" role="alert">' .
$paramResult .
"</div>";
return false;
}
$category = getById("tbl_categories", checkParamId("cat_id"));
?>
<?php
if ($category["status"] == 200) { ?>
<div class="row">
<div class="col-6">
<h3 class="fw-semibold mb-4">Kurs erstellen</h3>
</div>
<div class="col-6">
<a href="categories-edit.php?id=<?= $category["data"][
"id"
] ?>" class="btn btn-light float-end"> <i class="ti ti-arrow-left"></i> Zurück zur Kategorie</a>
</div>
</div>
<form action="code.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="category_id" value="<?= $category["data"]['id'] ;?>" required>
<div class="row">
<div class="col-auto">
<div class="mb-3">
<label class="form-label">Name</label>
<input type="text" name="name" required class="form-control">
</div>
</div>
<?php
if ($category["data"]["registration"] == "custom") { ?>
<div class="col-auto">
<div class="mb-3">
<div class="form-group">
<label class="form-label">Benötigt der Kurs eine Anmeldung?</label>
<a tabindex="0" class="badge rounded-pill text-bg-info ms-2" role="button" data-bs-toggle="popover" data-bs-trigger="focus" data-bs-html="true" data-bs-content="Wenn <b>Ja</b> ausgewählt wird, wird bei diesem Kurs eine Anmeldung verlangt.</br> Wenn <b>Nein</b> ausgewählt wird, müssen sich Schüler:innen für diesen Kurs nicht anmelden.">?</i></a>
</div>
<div class="btn-group" role="group">
<input type="radio" class="btn-check" name="regbtnradio" id="registrationyes" value="registrationyes" autocomplete="off">
<label class="btn btn-outline-info" for="registrationyes">Ja</label>
<input type="radio" class="btn-check" name="regbtnradio" id="registrationno" value="registrationno" autocomplete="off">
<label class="btn btn-outline-info" for="registrationno">Nein</label>
</div>
</div>
</div>
<?php }
if (
($category["data"]["registration"] == "custom" && $category["data"]["confirmation"] == "custom") || ($category["data"]["registration"] == "yes" && $category["data"]["confirmation"] == "custom")
) { ?>
<div class="col-auto" id="showconfirmation">
<div class="mb-3">
<div class="form-group">
<label class="form-label">Muss die Anmeldung bestätigt werden?</label>
<a tabindex="0" class="badge rounded-pill text-bg-info ms-2" role="button" data-bs-toggle="popover" data-bs-trigger="focus" data-bs-html="true" data-bs-content="Wenn <b>Ja</b> ausgewählt wird, haben Sie bei der Kurszuweisung die Möglichkeit, die Anmeldung anzunehmen oder abzulehnen.</br> Wenn <b>Nein</b> ausgewählt wird, ist die Anmeldung des/der Schüler:in ohne Ihre Interaktion definitiv.">?</a>
</div>
<div class="btn-group" role="group">
<input type="radio" class="btn-check" name="confbtnradio" id="confirmationyes" value="confirmationyes" autocomplete="off">
<label class="btn btn-outline-info" for="confirmationyes">Ja</label>
<input type="radio" class="btn-check" name="confbtnradio" id="confirmationno" value="confirmationno" autocomplete="off">
<label class="btn btn-outline-info" for="confirmationno">Nein</label>
</div>
</div>
</div>
<?php }
if (
($category["data"]["registration"] == "no" && $category["data"]["showuntil_set"] == "custom") || ($category["data"]["registration"] == "custom")
) { ?>
<div class="col-auto" id="showuntil">
<div class="mb-3">
<div class="form-group">
<label class="form-label">Kurs anzeigen bis</label>
</div>
<div class="btn-group" role="group">
<input type="date" name="showuntil" class="form-control">
</div>
</div>
</div>
<?php }
if (
(($category["data"]["registration"] == "yes" && $category["data"]["deadline_set"] == "custom") || ($category["data"]["registration"] == "custom"))
) { ?>
<div class="col-auto" id="showdeadline">
<div class="mb-3">
<div class="form-group">
<label class="form-label">Anmeldefrist </label>
</div>
<div class="btn-group" role="group">
<input type="date" name="deadline" class="form-control">
</div>
</div>
</div>
<?php }
?>
</div>
<div class="row">
<div class="col-3">
<div class="mb-3">
<label class="form-label">Slogan</label><i> (optional)</i>
<input type="text" name="slogan" class="form-control">
</div>
</div>
<div class="col-3">
<label for="courseImage" class="form-label">Kursbild hochladen</label>
<input class="form-control" type="file" id="courseImage" name="courseImage" accept="image/*">
</div>
</div>
<div class="row">
<div class="col">
<div class="mb-3">
<label class="form-label">Kursbeschreibung</label>
<textarea id="summernote" name="description" required class="form-control"></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-auto">
<div class="mb-3">
<label class="form-label">Kursraum / Ort</label>
<input type="text" name="place" required class="form-control">
</div>
</div>
<?php
if (
($category["data"]["registration"] == "custom" && $category["data"]["type"] == "year")
|| ($category["data"]["registration"] == "yes" && $category["data"]["confirmation"] == "yes" && $category["data"]["type"] == "year")
|| ($category["data"]["registration"] == "yes" && $category["data"]["confirmation"] == "custom" && $category["data"]["type"] == "year")
|| ($category["data"]["registration"] == "yes" && $category["data"]["confirmation"] == "no")
|| ($category["data"]["registration"] == "no")
) { ?>
<div class="col-auto">
<div class="mb-3">
<label class="form-label">Kursleiter:in</label>
<select name="teacheryear" required class="form-select">
<option value="">--- Auswählen ---</option>
<?php
$teacherOptions = getTeachers();
if ($teacherOptions) {
foreach ($teacherOptions as $teacher) {
$id = $teacher['id'];
$name = $teacher['name'];
echo '<option value="' . $id . '">' . $name . '</option>';
}
}
?>
</select>
</div>
</div>
<?php }
if (
($category["data"]["registration"] == "custom" && $category["data"]["type"] == "semester")
|| ($category["data"]["registration"] == "yes" && $category["data"]["confirmation"] == "yes" && $category["data"]["type"] == "semester")
|| ($category["data"]["registration"] == "yes" && $category["data"]["confirmation"] == "custom" && $category["data"]["type"] == "semester")
) { ?>
<div class="col-auto">
<div class="mb-3">
<label class="form-label">Kursleiter:in 1. Semester</label>
<select name="teacher1sem" required class="form-select">
<option value="">--- Auswählen ---</option>
<?php
$teacherOptions = getTeachers();
if ($teacherOptions) {
foreach ($teacherOptions as $teacher) {
$id = $teacher['id'];
$name = $teacher['name'];
echo '<option value="' . $id . '">' . $name . '</option>';
}
}
?>
</select>
</div>
</div>
<div class="col-auto">
<div class="mb-3">
<label class="form-label">Kursleiter:in 2. Semester</label>
<select name="teacher2sem" required class="form-select">
<option value="">--- Auswählen ---</option>
<?php
$teacherOptions = getTeachers();
if ($teacherOptions) {
foreach ($teacherOptions as $teacher) {
$id = $teacher['id'];
$name = $teacher['name'];
echo '<option value="' . $id . '">' . $name . '</option>';
}
}
?>
</select>
</div>
</div>
<?php }
if (
($category["data"]["registration"] == "custom" && $category["data"]["type"] == "year")
|| ($category["data"]["registration"] == "yes" && $category["data"]["confirmation"] == "yes" && $category["data"]["type"] == "year")
|| ($category["data"]["registration"] == "yes" && $category["data"]["confirmation"] == "custom" && $category["data"]["type"] == "year")
|| ($category["data"]["registration"] == "yes" && $category["data"]["confirmation"] == "no")
) {
?>
<div class="col-auto" id="minyear">
<div class="mb-3">
<label class="form-label">Min. Schüler:innen</label>
<input type="text" name="minstudentyear" onkeydown="if(!(event.key >= '0' && event.key <= '9') && event.key !== 'Backspace' && event.key !== 'Tab'){return false;}" class="form-control">
</div>
</div>
<div class="col-auto" id="maxyear">
<div class="mb-3">
<label class="form-label">Max. Schüler:innen</label>
<input type="text" name="maxstudentyear" onkeydown="if(!(event.key >= '0' && event.key <= '9') && event.key !== 'Backspace' && event.key !== 'Tab'){return false;}" class="form-control">
</div>
</div>
<?php }
if (
($category["data"]["registration"] == "custom" && $category["data"]["type"] == "semester")
|| ($category["data"]["registration"] == "yes" && $category["data"]["confirmation"] == "yes" && $category["data"]["type"] == "semester")
|| ($category["data"]["registration"] == "yes" && $category["data"]["confirmation"] == "custom" && $category["data"]["type"] == "semester")
) {
?>
</div>
<div class="row">
<div class="col-auto" id="min1sem">
<div class="mb-3">
<label class="form-label">Min. Schüler:innen 1. Sem</label>
<input type="text" name="minstudent1sem" onkeydown="if(!(event.key >= '0' && event.key <= '9') && event.key !== 'Backspace' && event.key !== 'Tab'){return false;}" class="form-control">
</div>
</div>
<div class="col-auto" id="max1sem">
<div class="mb-3">
<label class="form-label">Max. Schüler:innen 1. Sem</label>
<input type="text" name="maxstudent1sem" onkeydown="if(!(event.key >= '0' && event.key <= '9') && event.key !== 'Backspace' && event.key !== 'Tab'){return false;}" class="form-control">
</div>
</div>
<div class="col-auto" id="min2sem">
<div class="mb-3">
<label class="form-label">Min. Schüler:innen 2. Sem</label>
<input type="text" name="minstudent2sem" onkeydown="if(!(event.key >= '0' && event.key <= '9') && event.key !== 'Backspace' && event.key !== 'Tab'){return false;}" class="form-control">
</div>
</div>
<div class="col-auto" id="max2sem">
<div class="mb-3">
<label class="form-label">Max. Schüler:innen 2. Sem</label>
<input type="text" name="maxstudent2sem" onkeydown="if(!(event.key >= '0' && event.key <= '9') && event.key !== 'Backspace' && event.key !== 'Tab'){return false;}" class="form-control">
</div>
</div>
</div>
<?php }
if (
($category["data"]["registration"] == "yes") || ($category["data"]["registration"] == "custom")
) {
?>
<div class="row">
<div class="col-auto" id="maxbehavior">
<div class="mb-3">
<div class="form-group">
<label class="form-label">Wenn Höchstanzahl der Anmeldungen erreicht ist</label>
</div>
<div class="btn-group" role="group">
<input type="radio" class="btn-check" name="maxbtnradio" id="hidecourse" value="hidecourse" autocomplete="off">
<label class="btn btn-outline-info" for="hidecourse">Kurs ausblenden</label>
<input type="radio" class="btn-check" name="maxbtnradio" id="showcourse" value="showcourse" autocomplete="off">
<label class="btn btn-outline-info" for="showcourse">Weitere Anmeldungen zulassen</label>
</div>
</div>
</div>
<?php }
?>
</div>
<div class="row mt-3 mb-4">
<h5 class='fw-semibold mb-4 mt-3'>Kursdaten</h5>
<div id="time-input-container">
<div class="row mb-3 align-items-center time-input">
<div class="col-md-3">
<select name="days[]" class="form-select">
<option value="Montag">Montag</option>
<option value="Dienstag">Dienstag</option>
<option value="Mittwoch">Mittwoch</option>
<option value="Donnerstag">Donnerstag</option>
<option value="Freitag">Freitag</option>
<option value="Samstag">Samstag</option>
<option value="Sonntag">Sonntag</option>
</select>
</div>
<div class="col-md-4">
<input type="time" name="start_times[]" class="form-control">
</div>
<div class="col-md-4">
<input type="time" name="end_times[]" class="form-control">
</div>
<div class="col-md-1">
<button type="button" class="btn btn-sm btn-success" onclick="addTimeInput(this)">+</button>
<button type="button" class="btn btn-sm btn-danger" onclick="removeTimeInput(this)">-</button>
</div>
</div>
</div>
<div class="mb-3">
<button type="button" class="btn btn-outline-info" onclick="addDayInput()">Weiteren Tag hinzufügen</button>
</div>
</div>
<?php
$classesCategory = getClassesPerCategory($category["data"]["id"]);
echo "<h5 class='fw-semibold mb-4 mt-3'>Klassenzuweisung</h5>";
echo "<div class='row'>";
if (!empty($classesCategory)) {
$groupedClasses = array();
foreach ($classesCategory as $class) {
$level = $class['sek'];
$groupedClasses[$level][] = $class;
}
foreach ($groupedClasses as $level => $levelClasses) {
echo "<div class='col'>";
echo "<div class='card' style='border-radius:10px;'>";
echo "<div class='card-header fw-semibold bg-info-subtle'>";
echo "$level";
echo "</div>";
// Checkbox für "Alle Auswählen"
$idSafeLevel = str_replace(['.', ' '], '_', $level);
$idSafeLevel = preg_replace('/[^A-Za-z0-9_]/', '', $idSafeLevel);
echo "<div class='form-check ms-3 mt-2 mb-3'>";
echo "<input class='form-check-input' type='checkbox' id='select-all_$idSafeLevel' data-toggle='select-all' data-level='$level'>";
echo "<label class='form-check-label' for='select-all_$idSafeLevel' style='user-select: none; -webkit-user-select: none; -ms-user-select: none;' for=''>Alle auswählen</label>";
echo "</div>";
foreach ($levelClasses as $class) {
$classId = $class['id'];
$className = htmlspecialchars($class['classDisplayName']);
echo "<div class='form-check ms-3 mt-2 mb-3'>";
echo "<input class='form-check-input' type='checkbox' name='selected_classes[]' id='class_$classId' data-class-id='$level' value='$classId'>";
echo "<label class='form-check-label' style='user-select: none; -webkit-user-select: none; -ms-user-select: none;' for='class_$classId'>$className</label>";
echo "</div>";
}
echo "</div>";
echo "</div>";
}
echo "</div>";
} else {
echo "<h6>Dieser Kategorie sind keine Klassen zugewiesen.</h6>";
}
?>
<div class="col-12">
<button type="submit" name="createcourse" class="btn btn-info mx-3 float-end"><i class="ti ti-plus me-1"></i>Erstellen</button>
</div>
</div>
</div>
<div>
</div>
</form>
</div>
<?php
} else {
echo '<div class="alert alert-danger" role="alert">' .
$category["message"] .
"</div>";
}
?>
<script>
// Funktion zum Hinzufügen einer neuen Zeitzeile
function addTimeInput(button) {
const container = button.closest('.time-input');
const newTimeInput = document.createElement('div');
newTimeInput.className = 'row mb-3 align-items-center time-input';
newTimeInput.innerHTML = `
<div class="col-md-3">
<select name="days[]" class="form-select">
<option value="${container.querySelector('select').value}">${container.querySelector('select').value}</option>
</select>
</div>
<div class="col-md-4">
<input type="time" name="start_times[]" class="form-control">
</div>
<div class="col-md-4">
<input type="time" name="end_times[]" class="form-control">
</div>
<div class="col-md-1">
<button type="button" class="btn btn-success btn-sm" onclick="addTimeInput(this)">+</button>
<button type="button" class="btn btn-danger btn-sm" onclick="removeTimeInput(this)">-</button>
</div>
`;
container.parentNode.insertBefore(newTimeInput, container.nextSibling);
updateDaySelects(); // Aktualisiert die Anzeige der Wochentage
}
// Funktion zum Entfernen einer Zeitzeile
function removeTimeInput(button) {
const container = button.closest('.time-input');
container.remove();
updateDaySelects(); // Aktualisiert die Anzeige der Wochentage
}
// Funktion zum Aktualisieren der Anzeige der Wochentage
function updateDaySelects() {
const daySelects = document.querySelectorAll('.time-input select[name="days[]"]');
let currentDay = '';
daySelects.forEach(select => {
const value = select.value;
if (value !== currentDay) {
currentDay = value;
select.style.display = ''; // Zeigt den Wochentag an, wenn er der erste in der Gruppe ist
} else {
select.style.display = 'none'; // Versteckt den Wochentag, wenn er nicht der erste in der Gruppe ist
}
});
}
// Funktion zum Hinzufügen eines neuen Wochentages
function addDayInput() {
const container = document.getElementById('time-input-container');
const days = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'];
const existingDays = Array.from(document.querySelectorAll('select[name="days[]"]')).map(select => select.value);
const remainingDays = days.filter(day => !existingDays.includes(day));
const newTimeInput = document.createElement('div');
newTimeInput.className = 'row mb-3 align-items-center time-input';
newTimeInput.innerHTML = `
<div class="col-md-3">
<select name="days[]" class="form-select">
${remainingDays.map(day => `<option value="${day}">${day}</option>`).join('')}
</select>
</div>
<div class="col-md-4">
<input type="time" name="start_times[]" class="form-control">
</div>
<div class="col-md-4">
<input type="time" name="end_times[]" class="form-control">
</div>
<div class="col-md-1">
<button type="button" class="btn btn-success btn-sm" onclick="addTimeInput(this)">+</button>
<button type="button" class="btn btn-danger btn-sm" onclick="removeTimeInput(this)">-</button>
</div>
`;
container.appendChild(newTimeInput);
updateDaySelects(); // Aktualisiert die Anzeige der Wochentage
}
</script>
<script>
// Funktion zum Überwachen von Änderungen in den Textfeldern
function checkMinMaxCourses() {
// Wert von min_courses und max_courses holen
var minStudentsYearField = document.getElementsByName("minstudentyear");
var maxStudentsYearField = document.getElementsByName("maxstudentyear");
var minStudents1SemField = document.getElementsByName("minstudent1sem");
var maxStudents1SemField = document.getElementsByName("maxstudent1sem");
var minStudents2SemField = document.getElementsByName("minstudent2sem");
var maxStudents2SemField = document.getElementsByName("maxstudent2sem");
// Überprüfen und Anpassen der Werte
if (minStudentsYearField.length > 0 && maxStudentsYearField.length > 0) {
var minStudentsYearValue = parseInt(minStudentsYearField[0].value);
var maxStudentsYearValue = parseInt(maxStudentsYearField[0].value);
if (!isNaN(minStudentsYearValue) && !isNaN(maxStudentsYearValue)) {
if (minStudentsYearValue > maxStudentsYearValue) {
// Wenn min_courses größer ist als max_courses, setze max_courses auf den Wert von min_courses
maxStudentsYearField[0].value = minStudentsYearValue;
} else if (maxStudentsYearValue < minStudentsYearValue) {
// Wenn max_courses kleiner ist als min_courses, setze min_courses auf den Wert von max_courses
minStudentsYearField[0].value = maxStudentsYearValue;
}
}
}
if (minStudents1SemField.length > 0 && maxStudents1SemField.length > 0) {
var minStudents1SemValue = parseInt(minStudents1SemField[0].value);
var maxStudents1SemValue = parseInt(maxStudents1SemField[0].value);
if (!isNaN(minStudents1SemValue) && !isNaN(maxStudents1SemValue)) {
if (minStudents1SemValue > maxStudents1SemValue) {
// Wenn min_courses größer ist als max_courses, setze max_courses auf den Wert von min_courses
maxStudents1SemField[0].value = minStudents1SemValue;
} else if (maxStudents1SemValue < minStudents1SemValue) {
// Wenn max_courses kleiner ist als min_courses, setze min_courses auf den Wert von max_courses
minStudents1SemField[0].value = maxStudents1SemValue;
}
}
}
if (minStudents2SemField.length > 0 && maxStudents2SemField.length > 0) {
var minStudents2SemValue = parseInt(minStudents2SemField[0].value);
var maxStudents2SemValue = parseInt(maxStudents2SemField[0].value);
if (!isNaN(minStudents2SemValue) && !isNaN(maxStudents2SemValue)) {
if (minStudents2SemValue > maxStudents2SemValue) {
// Wenn min_courses größer ist als max_courses, setze max_courses auf den Wert von min_courses
maxStudents2SemField[0].value = minStudents2SemValue;
} else if (maxStudents2SemValue < minStudents2SemValue) {
// Wenn max_courses kleiner ist als min_courses, setze min_courses auf den Wert von max_courses
minStudents2SemField[0].value = maxStudents2SemValue;
}
}
}
// Analog für die anderen Felder
};
// Event-Listener hinzufügen
document.addEventListener("DOMContentLoaded", function() {
if (document.getElementsByName("minstudentyear").length > 0) {
document.getElementsByName("minstudentyear")[0].addEventListener("input", checkMinMaxCourses);
}
if (document.getElementsByName("maxstudentyear").length > 0) {
document.getElementsByName("maxstudentyear")[0].addEventListener("input", checkMinMaxCourses);
}
if (document.getElementsByName("minstudent1sem").length > 0) {
document.getElementsByName("minstudent1sem")[0].addEventListener("input", checkMinMaxCourses);
}
if (document.getElementsByName("maxstudent1sem").length > 0) {
document.getElementsByName("maxstudent1sem")[0].addEventListener("input", checkMinMaxCourses);
}
if (document.getElementsByName("minstudent2sem").length > 0) {
document.getElementsByName("minstudent2sem")[0].addEventListener("input", checkMinMaxCourses);
}
if (document.getElementsByName("maxstudent2sem").length > 0) {
document.getElementsByName("maxstudent2sem")[0].addEventListener("input", checkMinMaxCourses);
}
});
</script>
<script>
// Funktion zum Aktualisieren des Anzeigezustands
function updateDisplay() {
if ($("#registrationno").is(":checked")) {
$("#showuntil").show();
$("#showconfirmation").hide();
$("#showdeadline").hide();
$("#maxbehavior").hide();
$("#minyear").hide();
$("#maxyear").hide();
$("#min1sem").hide();
$("#min2sem").hide();
$("#max1sem").hide();
$("#max2sem").hide();
} else {
$("#showconfirmation").show();
$("#showdeadline").show();
$("#showuntil").hide();
$("#maxbehavior").show();
$("#minyear").show();
$("#maxyear").show();
$("#min1sem").show();
$("#min2sem").show();
$("#max1sem").show();
$("#max2sem").show();
}
if ($("#registrationyes").is(":checked")) {
$("#showuntil").hide();
} else {
$("#showuntil").show();
}
}
$(document).ready(function(){
// Setze den Anfangszustand beim Laden der Seite
updateDisplay();
// Überwache Änderungen am Radiobutton
$('input[name="regbtnradio"]').change(function(){
updateDisplay();
});
$('input[name="confbtnradio"]').change(function(){
updateDisplay();
});
});
</script>
<script>
$(document).ready(function() {
// Überwache Änderungen an den Klassen-Checkboxen
$('input[name="selected_classes[]"]').change(function() {
updateSelectAllCheckbox($(this).data('class-id'));
});
// Überwache Änderungen an den "Alle auswählen"-Checkboxen
$('input[type="checkbox"][data-toggle="select-all"]').change(function() {
var level = $(this).data('level');
var isChecked = $(this).prop('checked');
$('input[name="selected_classes[]"][data-class-id="' + level + '"]').prop('checked', isChecked);
});
// Initialisiere den Status der "Alle auswählen"-Checkboxen beim Laden der Seite
$('input[data-toggle="select-all"]').each(function() {
updateSelectAllCheckbox($(this).data('level'));
});
});
// Funktion zum Aktualisieren des Status der "Alle auswählen"-Checkboxen
function updateSelectAllCheckbox(level) {
var classCheckboxes = $('input[name="selected_classes[]"][data-class-id="' + level + '"]');
var selectAllCheckbox = $('input[data-toggle="select-all"][data-level="' + level + '"]');
var allChecked = true;
var anyChecked = false;
classCheckboxes.each(function() {
if (!$(this).prop('checked')) {
allChecked = false;
} else {
anyChecked = true;
}
});
selectAllCheckbox.prop('checked', allChecked);
selectAllCheckbox.prop('indeterminate', anyChecked && !allChecked);
}
</script>
<?php include "includes/footer.php"; ?>