Albisrieden/admin/index.php

216 lines
10 KiB
PHP
Raw Normal View History

2025-01-07 04:13:11 +01:00
<?php include('includes/header.php'); ?>
<!-- Button zum Exportieren der Tabelle in eine Excel-Datei -->
<div class="row">
<div class="col-md-3 d-flex align-items-strech">
<div class="card bg-primary-subtle w-100">
<div class="card-body">
<div class="d-sm-flex d-block align-items-center justify-content-between mb-9">
<div class="mb-3 mb-sm-0">
<h5 class="card-title fw-semibold"><?=countEntriesByClass('2ABa'); ?></h5>
<p>Anmeldungen für 2ABa</p>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-3 d-flex align-items-strech">
<div class="card bg-success-subtle w-100">
<div class="card-body">
<div class="d-sm-flex d-block align-items-center justify-content-between mb-9">
<div class="mb-3 mb-sm-0">
<h5 class="card-title fw-semibold"><?=countEntriesByClass('2ABb'); ?></h5>
<p>Anmeldungen für 2ABb</p>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-3 d-flex align-items-strech">
<div class="card bg-warning-subtle w-100">
<div class="card-body">
<div class="d-sm-flex d-block align-items-center justify-content-between mb-9">
<div class="mb-3 mb-sm-0">
<h5 class="card-title fw-semibold"><?=countEntriesByClass('2ABc'); ?></h5>
<p>Anmeldungen für 2ABc</p>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-3 d-flex align-items-strech">
<div class="card bg-danger-subtle w-100">
<div class="card-body">
<div class="d-sm-flex d-block align-items-center justify-content-between mb-9">
<div class="mb-3 mb-sm-0">
<h5 class="card-title fw-semibold"><?=countEntriesByClass('2ABd'); ?></h5>
<p>Anmeldungen für 2ABd</p>
</div>
</div>
</div>
</div>
</div>
</div><div class="row">
<div class="col-3">
<button onclick="exportToExcel()" class="btn btn-success mb-3">Excel-Export</button>
</div>
<div class="col-4">
<input type="text" class="form-control" id="myInput" onkeyup="myFunction()" placeholder="Suche...">
</div>
</div>
<?= alertMessage(); ?>
<div class="table-responsive">
<table class="table table-hover table-striped table-bordered" id="sortTable">
<thead>
<tr>
<th></th>
<th></th>
<th style="cursor: pointer;" onclick="sortTable(0)">Vorname</th>
<th style="cursor: pointer;" onclick="sortTable(1)">Nachname</th>
<th style="cursor: pointer;" onclick="sortTable(2)">Klasse</th>
<th style="cursor: pointer;" onclick="sortTable(3)">Sek</th>
<th style="cursor: pointer;" onclick="sortTable(4)">F-Niveau</th>
<th style="cursor: pointer;" onclick="sortTable(5)">M-Niveau</th>
<th style="cursor: pointer;" onclick="sortTable(6)">Anzahl Lektionen</th>
<!-- Weitere Spalten hinzufügen, falls erforderlich -->
<?php
// Kurse abrufen
$courseQuery = "SELECT * FROM tbl_courses";
$courseResult = mysqli_query($conn, $courseQuery);
// Tabelle mit Kursen erstellen, wenn die Abfrage erfolgreich war
if ($courseResult && mysqli_num_rows($courseResult) > 0) {
while ($row = mysqli_fetch_assoc($courseResult)) {
echo '<th>' . $row['name'] . '</th>';
}
}
?>
</tr>
</thead>
<tbody>
<?php
// Schüler abrufen
$studentsQuery = "SELECT * FROM tbl_registrations";
$studentsResult = mysqli_query($conn, $studentsQuery);
if ($studentsResult && mysqli_num_rows($studentsResult) > 0) {
while ($student = mysqli_fetch_assoc($studentsResult)) {
$rowClass = ($student['sent'] === null) ? 'table-danger' : '';
?>
<tr class="<?= $rowClass ?>">
<td><button type="button" class="btn btn-sm btn-outline-danger" data-bs-toggle="modal" data-bs-target="#confirmDeleteModal-<?= $student['id'];?>"><i class="ti ti-trash"></i></button></td>
<td><button type="button" class="btn btn-sm btn-light" data-bs-toggle="modal" data-bs-target="#signature-<?= $student['id'];?>"><i class="ti ti-signature"></i></button></td>
<td><?= $student['firstname']; ?></td>
<td><?= $student['lastname']; ?></td>
<td><?= $student['class']; ?></td>
<td><?= $student['sek']; ?></td>
<td><?= $student['fniveau']; ?></td>
<td><?= $student['mniveau']; ?></td>
<div class="modal fade" id="confirmDeleteModal-<?=$student['id'] ;?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Eintrag Löschen</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 den Eintrag von<b> <?= $student['firstname'] . ' ' . $student['lastname'];?></b> entfernen möchten?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Abbrechen</button>
<a href="registrations-delete.php?id=<?=$student['id'] ;?>" class="btn btn-danger"><i class="ti ti-trash"></i> Löschen</a>
</div>
</div>
</div>
</div>
<div class="modal fade" id="signature-<?=$student['id'] ;?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Signaturen von <?= $student['firstname'] . ' ' . $student['lastname'];?></h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<h6>Schüler:in:</h6>
<img src="<?= $student['sig_student'] ?>" alt="Unterschrift des Schülers / der Schülerin">
<h6>Elternteil:</h6>
<img src="<?= $student['sig_parent'] ?>" alt="Unterschrift des Elternteils">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Schliessen</button>
</div>
</div>
</div>
</div>
<?php
// Anzahl der Lektionen für diesen Schüler abrufen
$lessonsQuery = "SELECT SUM(c.lessons) AS total_lessons FROM tbl_courses c INNER JOIN tbl_assign_courses ac ON c.id = ac.course_id WHERE ac.user_id = {$student['id']}";
$lessonsResult = mysqli_query($conn, $lessonsQuery);
$totalLessons = 0;
if ($lessonsResult && mysqli_num_rows($lessonsResult) > 0) {
$totalLessonsRow = mysqli_fetch_assoc($lessonsResult);
$totalLessons = $totalLessonsRow['total_lessons'] + 22; // 22 hinzufügen
}
// Anzahl der Lektionen anzeigen
echo '<td>' . $totalLessons . '</td>';
// Kurse anzeigen und prüfen, ob der Schüler den Kurs ausgewählt hat
if ($courseResult && mysqli_num_rows($courseResult) > 0) {
mysqli_data_seek($courseResult, 0); // Zurücksetzen des Cursors
while ($row = mysqli_fetch_assoc($courseResult)) {
echo '<td>';
$courseId = $row['id'];
$isAssignedQuery = "SELECT 1 FROM tbl_assign_courses WHERE user_id = {$student['id']} AND course_id = $courseId";
$isAssignedResult = mysqli_query($conn, $isAssignedQuery);
if ($isAssignedResult && mysqli_num_rows($isAssignedResult) > 0) {
echo 'X';
}
echo '</td>';
}
}
echo '</tr>';
}
} else {
echo '<tr><td colspan="7">Keine Schüler gefunden.</td></tr>';
}
?>
</tbody>
</table>
</div>
<?php include('includes/footer.php'); ?>
<script>
function exportToExcel() {
const table = document.getElementById("sortTable");
const rows = table.getElementsByTagName("tr");
const data = [];
for (let i = 0; i < rows.length; i++) {
const row = [],
cols = rows[i].querySelectorAll("td, th");
// Überspringen der ersten beiden Spalten (Index 0 und 1)
for (let j = 2; j < cols.length; j++) {
row.push(cols[j].textContent);
}
data.push(row);
}
const ws = XLSX.utils.aoa_to_sheet(data);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "Scolify");
// Exportiere die Arbeitsmappe in ein XLSX-Dateiformat
XLSX.writeFile(wb, "scolify-export.xlsx");
}
</script>