234 lines
11 KiB
PHP
234 lines
11 KiB
PHP
|
<?php include('includes/header.php'); ?>
|
||
|
<div>
|
||
|
<div class="card card-body p-4">
|
||
|
<div class="row">
|
||
|
<div class="col">
|
||
|
<h3 class="fw-semibold mb-4">Kursanmeldungen</h3>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
<?= alertMessage(); ?>
|
||
|
<div class="btn-group col-4 mb-2" role="group">
|
||
|
<button id="btnGroupDrop1" type="button" class="btn btn-success dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||
|
Auswertungen
|
||
|
</button>
|
||
|
<ul class="dropdown-menu" aria-labelledby="btnGroupDrop1">
|
||
|
<!-- <li><button onclick="exportTableToExcel('sortTable', 'Scolify - Kursanmeldungen nach Klasse')" class="btn btn-success mb-1"><i class="ti ti-table me-2"></i>Export (nach Klasse), Alle Status</button></li>
|
||
|
<li><button onclick="exportTableToExcelOnlyRegistered('sortTable', 'Scolify - Kursanmeldungen nach Klasse')" class="btn btn-success mb-1"><i class="ti ti-table me-2"></i>Export (nach Klasse), Nur angemeldete</button></li>
|
||
|
--> <li> <button onclick="exportTableToExcelGesamt('sortTable', 'Scolify - Kursanmeldungen Gesamt')" class="btn btn-success mb-1"><i class="ti ti-table me-2"></i>Export (Gesamt), Alle Status</button></li>
|
||
|
<li><button onclick="exportTableToExcelGesamtOnlyRegistered('sortTable', 'Scolify - Kursanmeldungen Gesamt')" class="btn btn-success mb-1"><i class="ti ti-table me-2"></i>Export (Gesamt), Nur angemeldete</button></li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
<input type="text" class="form-control mb-3" id="myInput" onkeyup="myFunction()" placeholder="Volltextsuche...">
|
||
|
|
||
|
<div class="row mb-3">
|
||
|
<div class="col-auto">
|
||
|
<span class="badge bg-secondary">Dienstag Vormittag</span>
|
||
|
</div>
|
||
|
<div class="col-auto">
|
||
|
<span class="badge bg-info">Dienstag Nachmittag</span>
|
||
|
</div>
|
||
|
<div class="col-auto">
|
||
|
<span class="badge bg-warning">Donnerstag Vormittag</span>
|
||
|
</div>
|
||
|
<div class="col-auto">
|
||
|
<span class="badge bg-danger">Donnerstag Nachmittag</span>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<div class="table-responsive">
|
||
|
<table class="table table-hover table-striped table-bordered" id="sortTable">
|
||
|
<thead>
|
||
|
<tr>
|
||
|
<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>
|
||
|
|
||
|
<?php
|
||
|
$days = ['di-vo', 'di-na', 'do-vo', 'do-na'];
|
||
|
$courses = [];
|
||
|
$colIndex = 3; // Beginnt bei 3, da die ersten drei Spalten bereits definiert sind
|
||
|
|
||
|
foreach ($days as $day) {
|
||
|
// Kursfarben je nach Tageszeit
|
||
|
$colorClass = '';
|
||
|
if ($day == 'di-vo') {
|
||
|
$colorClass = 'bg-secondary text-white';
|
||
|
} elseif ($day == 'di-na') {
|
||
|
$colorClass = 'bg-info text-white';
|
||
|
} elseif ($day == 'do-vo') {
|
||
|
$colorClass = 'bg-warning text-white';
|
||
|
} elseif ($day == 'do-na') {
|
||
|
$colorClass = 'bg-danger text-white';
|
||
|
}
|
||
|
|
||
|
$courses[$day] = getCoursesByDay($day);
|
||
|
foreach ($courses[$day] as $course) {
|
||
|
// Zähle die Anzahl der Schüler mit Status "Ausgewählt" für diesen Kurs
|
||
|
$courseID = $course['id'];
|
||
|
$countSelectedQuery = "SELECT COUNT(*) as selected_count FROM tbl_assign_students_courses WHERE course_id = $courseID AND status = 'Ausgewählt'";
|
||
|
$countSelectedResult = mysqli_query($conn, $countSelectedQuery);
|
||
|
$selectedCount = 0;
|
||
|
|
||
|
if ($countSelectedResult && mysqli_num_rows($countSelectedResult) > 0) {
|
||
|
$countSelectedData = mysqli_fetch_assoc($countSelectedResult);
|
||
|
$selectedCount = $countSelectedData['selected_count'];
|
||
|
}
|
||
|
|
||
|
// Zähle die Anzahl der Schüler mit Status "Angemeldet" für diesen Kurs
|
||
|
$countRegisteredQuery = "SELECT COUNT(*) as registered_count FROM tbl_assign_students_courses WHERE course_id = $courseID AND status = 'Angemeldet'";
|
||
|
$countRegisteredResult = mysqli_query($conn, $countRegisteredQuery);
|
||
|
$registeredCount = 0;
|
||
|
|
||
|
if ($countRegisteredResult && mysqli_num_rows($countRegisteredResult) > 0) {
|
||
|
$countRegisteredData = mysqli_fetch_assoc($countRegisteredResult);
|
||
|
$registeredCount = $countRegisteredData['registered_count'];
|
||
|
}
|
||
|
$maxStudents = $course['maxstudents'];
|
||
|
// Ausgabe des Kursnamens mit beiden Badges für "Ausgewählt" und "Angemeldet"
|
||
|
echo '<th style="cursor: pointer; white-space: nowrap;" class="' . $colorClass . '" onclick="sortTable(' . $colIndex . ')">'
|
||
|
. $course['name']
|
||
|
. '<br><span class="btn btn-sm bg-dark text-white">' . $maxStudents . '</span>'
|
||
|
. '<span class="btn btn-sm bg-light text-info">' . $selectedCount . '</span>'
|
||
|
. ' <span class="btn btn-sm bg-light text-success">' . $registeredCount . '</span></th>';
|
||
|
|
||
|
$colIndex++; // Erhöhe den Index für jede neue Spalte
|
||
|
}
|
||
|
|
||
|
}
|
||
|
?>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
|
||
|
<tbody>
|
||
|
<?php
|
||
|
// Schüler abrufen
|
||
|
$studentsQuery = "SELECT * FROM tbl_students";
|
||
|
$studentsResult = mysqli_query($conn, $studentsQuery);
|
||
|
|
||
|
if ($studentsResult && mysqli_num_rows($studentsResult) > 0) {
|
||
|
while ($student = mysqli_fetch_assoc($studentsResult)) {
|
||
|
$classOptions = getAllClasses('active');
|
||
|
$classID = $student['class'];
|
||
|
$className = isset($classOptions[$classID]) ? $classOptions[$classID] : 'Nicht verfügbar';
|
||
|
?>
|
||
|
<tr>
|
||
|
<td><?= $student['firstname']; ?></td>
|
||
|
<td><?= $student['lastname']; ?></td>
|
||
|
<td><?= $className; ?></td>
|
||
|
<?php
|
||
|
foreach ($days as $day) {
|
||
|
foreach ($courses[$day] as $course) {
|
||
|
// Anmeldung für den Kurs prüfen
|
||
|
$courseID = $course['id'];
|
||
|
$studentID = $student['id'];
|
||
|
$enrollmentQuery = "SELECT status FROM tbl_assign_students_courses WHERE course_id = $courseID AND student_id = $studentID";
|
||
|
$enrollmentResult = mysqli_query($conn, $enrollmentQuery);
|
||
|
$status = '';
|
||
|
|
||
|
if ($enrollmentResult && mysqli_num_rows($enrollmentResult) > 0) {
|
||
|
$enrollment = mysqli_fetch_assoc($enrollmentResult);
|
||
|
$status = $enrollment['status'];
|
||
|
|
||
|
// Bestimme die Klasse basierend auf dem Status
|
||
|
$btnClass = 'btn-secondary'; // Default-Klasse falls kein Status gefunden wird
|
||
|
if ($status == 'Angemeldet') {
|
||
|
$btnClass = 'btn-success';
|
||
|
} elseif ($status == 'Ausgewählt') {
|
||
|
$btnClass = 'btn-info';
|
||
|
}
|
||
|
|
||
|
echo '<td> <button type="button" class="btn btn-sm ' . $btnClass . '">' . $status . '</button> </td>';
|
||
|
} else {
|
||
|
echo '<td></td>';
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
?>
|
||
|
</tr>
|
||
|
<?php
|
||
|
}
|
||
|
} else {
|
||
|
echo '<tr><td colspan="7">Keine Schüler gefunden.</td></tr>';
|
||
|
}
|
||
|
?>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
<?php include('includes/footer.php'); ?>
|
||
|
|
||
|
<script>
|
||
|
function exportTableToExcelGesamt(tableID, filename = ''){
|
||
|
var downloadLink;
|
||
|
var dataType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';
|
||
|
var tableSelect = document.getElementById(tableID);
|
||
|
var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
|
||
|
|
||
|
filename = filename?filename+'.xlsx':'excel_data.xlsx';
|
||
|
|
||
|
downloadLink = document.createElement("a");
|
||
|
|
||
|
document.body.appendChild(downloadLink);
|
||
|
|
||
|
var workbook = XLSX.utils.table_to_book(tableSelect, {sheet: "Sheet1"});
|
||
|
var excelBuffer = XLSX.write(workbook, {bookType: 'xlsx', type: 'array'});
|
||
|
var data = new Blob([excelBuffer], {type: dataType});
|
||
|
|
||
|
var url = URL.createObjectURL(data);
|
||
|
downloadLink.href = url;
|
||
|
downloadLink.download = filename;
|
||
|
|
||
|
downloadLink.click();
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
|
||
|
<script>
|
||
|
function exportTableToExcelGesamtOnlyRegistered(tableID, filename = '') {
|
||
|
var downloadLink;
|
||
|
var dataType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';
|
||
|
var tableSelect = document.getElementById(tableID);
|
||
|
var rows = tableSelect.rows;
|
||
|
var filteredTable = document.createElement('table');
|
||
|
var filteredTableBody = document.createElement('tbody');
|
||
|
|
||
|
// Clone the header row
|
||
|
var headerRow = rows[0].cloneNode(true);
|
||
|
filteredTable.appendChild(headerRow);
|
||
|
|
||
|
// Iterate through the rows and append only those with the status "Angemeldet"
|
||
|
for (var i = 1; i < rows.length; i++) {
|
||
|
var cells = rows[i].cells;
|
||
|
for (var j = 0; j < cells.length; j++) {
|
||
|
if (cells[j].innerText.trim() === "Angemeldet") {
|
||
|
var rowClone = rows[i].cloneNode(true);
|
||
|
filteredTableBody.appendChild(rowClone);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
filteredTable.appendChild(filteredTableBody);
|
||
|
|
||
|
filename = filename ? filename + '.xlsx' : 'excel_data_only_registered.xlsx';
|
||
|
|
||
|
downloadLink = document.createElement("a");
|
||
|
document.body.appendChild(downloadLink);
|
||
|
|
||
|
var workbook = XLSX.utils.table_to_book(filteredTable, { sheet: "Sheet1" });
|
||
|
var excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
|
||
|
var data = new Blob([excelBuffer], { type: dataType });
|
||
|
|
||
|
var url = URL.createObjectURL(data);
|
||
|
downloadLink.href = url;
|
||
|
downloadLink.download = filename;
|
||
|
|
||
|
downloadLink.click();
|
||
|
}
|
||
|
</script>
|