Lachenzelg/admin/classes-edit.php
2025-01-07 03:02:25 +01:00

229 lines
8.2 KiB
PHP

<?php include('includes/header.php'); ?>
<div class="row">
<div class="card card-body p-4 col-md-8">
<?= alertMessage(); ?>
<div class="d-block d-sm-none">
<div>
<div class="row mb-4">
<div class="col-3">
<a href="classes.php" class="btn btn-light float-start"> <i class="ti ti-arrow-left"></i></a>
</div>
<div class="col-9 my-auto">
<h5 class="fw-semibold mb-0">Klasse bearbeiten</h5>
</div>
</div>
</div>
<form action="code.php" method="POST">
<?php
$paramResult = checkParamId('id');
if(!is_numeric($paramResult)){
echo '<div class="alert alert-danger" role="alert">'.$paramResult.'</div>';
return false;
}
$class = getById('tbl_classes',checkParamId('id'));
if(($class['status'] == 200) && $class['data']['status'] == 'archived')
{
echo '<div class="alert alert-warning" role="alert">Diese Klasse ist archiviert und kann nicht bearbeitet werden. Bitte reaktivieren Sie die Klasse, um sie zu bearbeiten.</div>';
}
elseif(($class['status'] == 200) && ($class['data']['status'] != 'archived'))
{
?>
<input type="hidden" name="id" value="<?= $class['data']['id'] ;?>" required>
<div class="row">
<div class="col-6 col-md-6">
<div class="mb-1">
<label class="col-form-label-sm">Sek</label>
<select name="sek" required class="form-select">
<option value="">--- Auswählen ---</option>
<?php createEnumSelect('tbl_classes', 'sek',$class['data']['sek']); ?>
</select>
</div>
</div>
<div class="col-6 col-md-6">
<div class="mb-1">
<label class="col-form-label-sm">Typ</label>
<select name="type" required class="form-select">
<option value="">--- Auswählen ---</option>
<?php createEnumSelect('tbl_classes', 'type',$class['data']['type']); ?>
</select>
</div>
</div>
<div class="col-6 col-md-6">
<div class="mb-4">
<label class="col-form-label-sm">Name</label>
<input type="text" name="name" value="<?= $class['data']['name'] ;?>" required class="form-control">
</div>
</div>
<div class="text-center">
<div class="col-12">
<button type="submit" name="updateclass" class="btn btn-info mx-1"><i class="ti ti-check"></i> Änderungen speichern</button>
<a type="button" class="btn btn-warning mx-1" data-bs-toggle="modal" data-bs-target="#archiveClass<?= $class['data']['id']; ?>"><i class="ti ti-archive"></i></a>
</div>
</div>
<?php
}
else
{
echo '<div class="alert alert-danger" role="alert">'.$class['message'].'</div>';
}
?>
</form>
</div>
</div>
<div class="d-none d-sm-block">
<div class="row">
<div class="col-6">
<h3 class="fw-semibold mb-4">Klasse bearbeiten</h3>
</div>
<div class="col-6">
<a href="classes.php" class="btn btn-light float-end"> <i class="ti ti-arrow-left"></i> Zurück zur Übersicht</a>
</div>
</div>
<form action="code.php" method="POST">
<?php
$paramResult = checkParamId('id');
if(!is_numeric($paramResult)){
echo '<div class="alert alert-danger" role="alert">'.$paramResult.'</div>';
return false;
}
$class = getById('tbl_classes',checkParamId('id'));
if(($class['status'] == 200) && $class['data']['status'] == 'archived')
{
echo '<div class="alert alert-warning" role="alert">Diese Klasse ist archiviert und kann nicht bearbeitet werden. Bitte reaktivieren Sie die Klasse, um sie zu bearbeiten.</div>';
}
elseif(($class['status'] == 200) && ($class['data']['status'] != 'archived'))
{
?>
<input type="hidden" name="id" value="<?= $class['data']['id'] ;?>" required>
<div class="row">
<div class="col-4 col-md-4">
<div class="mb-3">
<label class="form-label">Sek</label>
<select name="sek" required class="form-select">
<option value="">--- Auswählen ---</option>
<?php createEnumSelect('tbl_classes', 'sek',$class['data']['sek']); ?>
</select>
</div>
</div>
<div class="col-4 col-md-4">
<div class="mb-3">
<label class="form-label">Typ</label>
<select name="type" required class="form-select">
<option value="">--- Auswählen ---</option>
<?php createEnumSelect('tbl_classes', 'type',$class['data']['type']); ?>
</select>
</div>
</div>
<div class="col-4 col-md-4">
<div class="mb-3">
<label class="form-label">Name</label>
<input type="text" name="name" value="<?= $class['data']['name'] ;?>" required class="form-control">
</div>
</div>
<div>
<div class="col-md-12 mt-4">
<button type="submit" name="updateclass" class="btn btn-info float-end mx-1"><i class="ti ti-check"></i> Änderungen speichern</button>
<a type="button" class="btn btn-warning float-end mx-1" data-bs-toggle="modal" data-bs-target="#archiveClass"><i class="ti ti-archive"></i> Archivieren</a>
</div>
</div>
</div>
<?php
}
else
{
echo '<div class="alert alert-danger" role="alert">'.$class['message'].'</div>';
}
?>
</form>
</div>
</div>
<div class="col-md-4">
<div class="card card-body p-4">
<h6 class="fw-semibold mb-4">Schüler:innen</h6>
<div class="table-responsive">
<table class="table table-hover">
<tbody>
<?php
$students = getAll('id,firstname,lastname', 'tbl_students', "WHERE class={$class['data']['id']} AND status !='archived'");
if(mysqli_num_rows($students) > 0)
{
foreach($students as $studentEntry)
{
?>
<tr>
<td><?= $studentEntry['firstname'] . ' ' . $studentEntry['lastname']; ?></td>
<td>
<a href="students-edit.php?id=<?= $studentEntry['id']; ?>" class="btn btn-light btn-sm float-end mx-1"> <i class="ti ti-arrow-right"></i></a>
</td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="7"> Keine Schüler:innen zugewiesen</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php
$classInfo = getById('tbl_classes', $class['data']['id']);
if ($classInfo['status'] == 200) {
$studentCount = mysqli_num_rows($students);
$className = $classInfo['data']['sek'] . ' ' . $classInfo['data']['type'] . ' - ' . $classInfo['data']['name'];
if ($studentCount == 0) {
$ModalText = "";
} elseif ($studentCount == 1) {
$ModalText = "Sie beinhaltet <b>{$studentCount} Schüler:in,</b> der/die ebenfalls archiviert wird:";
} else {
$ModalText = "Sie beinhaltet <b>{$studentCount} Schüler:innen,</b> die ebenfalls archiviert werden:";
}
}
?>
<!-- Modal -->
<div class="modal fade" id="archiveClass" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="staticBackdropLabel">Klasse archivieren</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Sind Sie sicher, dass Sie die Klasse <b><?= $className; ?></b> archivieren möchten?</p>
<p><?= $ModalText ?></p>
<ul>
<?php foreach ($students as $student) : ?>
<li>- <?= $student['firstname'] . ' ' . $student['lastname']; ?></li>
<?php endforeach; ?>
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Schliessen</button>
<a href="classes-archive.php?id=<?= $class['data']['id']; ?>" class="btn btn-warning"><i class="ti ti-archive"></i> Archivieren</a>
</div>
</div>
</div>
</div>
<!-- Modal Ende -->
<?php include('includes/footer.php'); ?>