149 lines
5.9 KiB
PHP
149 lines
5.9 KiB
PHP
|
<?php include "includes/header.php"; ?>
|
||
|
<div>
|
||
|
<div class="card card-body p-4">
|
||
|
<?= alertMessage() ?>
|
||
|
<?php
|
||
|
$paramResult = checkParamId('id');
|
||
|
if(!is_numeric($paramResult)){
|
||
|
echo '<div class="alert alert-danger" role="alert">'.$paramResult.'</div>';
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
$formcontent = getById('tbl_formcontents',checkParamId('id'));
|
||
|
if($formcontent['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="formscontents-edit.php?id=<?= $formcontent["data"]["id"] ?>" class="btn btn-light float-end"> <i class="ti ti-arrow-left"></i> Zurück zum Formularabschnitt</a>
|
||
|
</div>
|
||
|
</div>
|
||
|
<form action="code.php" method="POST">
|
||
|
<input type="hidden" name="formcontent_id" value="<?= $formcontent["data"]['id'] ;?>" required>
|
||
|
<div class="row">
|
||
|
<div class="col-6">
|
||
|
<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">Anz. Lektionen</label>
|
||
|
<input type="number" name="lessons" class="form-control">
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<?php
|
||
|
$classesform = getClassesPerFormContent($formcontent["data"]["id"]);
|
||
|
echo "<h5 class='fw-semibold mb-4 mt-3'>Klassenzuweisung</h5>";
|
||
|
echo "<div class='row'>";
|
||
|
$assignedClasses = getAssignedItems('tbl_assign_formcontents_classes', $formcontent['data']['id'], 'class_id', 'formcontent_id');
|
||
|
|
||
|
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 Formularabschnitt sind keine Klassen zugewiesen.</h6>";
|
||
|
}
|
||
|
?>
|
||
|
<div class="col-12">
|
||
|
<button type="submit" name="createformcourse" class="btn btn-info mx-3 float-end"><i class="ti ti-check me-1"></i>Änderungen speichern</button>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</form>
|
||
|
|
||
|
<?php
|
||
|
} else {
|
||
|
echo '<div class="alert alert-danger" role="alert">' .
|
||
|
$formcontent["message"] .
|
||
|
"</div>";
|
||
|
}
|
||
|
?>
|
||
|
|
||
|
|
||
|
<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"; ?>
|