374 lines
16 KiB
PHP
374 lines
16 KiB
PHP
|
<?php include "includes/header.php"; ?>
|
||
|
<div>
|
||
|
<div class="card card-body p-4">
|
||
|
<?= alertMessage() ?>
|
||
|
<?php
|
||
|
$paramResult = checkParamId("form_id");
|
||
|
if (!is_numeric($paramResult)) {
|
||
|
echo '<div class="alert alert-danger" role="alert">' .
|
||
|
$paramResult .
|
||
|
"</div>";
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
$form = getById("tbl_forms", checkParamId("form_id"));
|
||
|
?>
|
||
|
<?php
|
||
|
if ($form["status"] == 200) { ?>
|
||
|
<div class="row">
|
||
|
<div class="col-6">
|
||
|
<h3 class="fw-semibold mb-4">Formularabschnitt erstellen</h3>
|
||
|
</div>
|
||
|
<div class="col-6">
|
||
|
<a href="forms-edit.php?id=<?= $form["data"]["id"] ?>" class="btn btn-light float-end"> <i class="ti ti-arrow-left"></i> Zurück zum Formular</a>
|
||
|
</div>
|
||
|
</div>
|
||
|
<form action="code.php" method="POST">
|
||
|
<input type="hidden" name="form_id" value="<?= $form["data"]['id'] ;?>" required>
|
||
|
<div class="row">
|
||
|
<div class="col-5">
|
||
|
<div class="mb-3">
|
||
|
<label class="form-label">Name</label>
|
||
|
<input type="text" name="name" required class="form-control">
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="col-auto">
|
||
|
<div class="mb-3">
|
||
|
<label class="form-label">Min. Auswahl</label>
|
||
|
<input type="number" name="min" class="form-control">
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="col-auto">
|
||
|
<div class="mb-3">
|
||
|
<label class="form-label">Max. Auswahl</label>
|
||
|
<input type="number" name="min" class="form-control">
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<?php
|
||
|
$classesform = getClassesPerForm($form["data"]["id"]);
|
||
|
echo "<h5 class='fw-semibold mb-4 mt-3'>Klassenzuweisung</h5>";
|
||
|
echo "<div class='row'>";
|
||
|
if (!empty($classesform)) {
|
||
|
|
||
|
|
||
|
$groupedClasses = array();
|
||
|
|
||
|
foreach ($classesform 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>Diesem Formular sind keine Klassen zugewiesen.</h6>";
|
||
|
}
|
||
|
?>
|
||
|
<div class="col-12">
|
||
|
<button type="submit" name="createformcontent" 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">' .
|
||
|
$form["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"; ?>
|