Lachenzelg/admin/categories-registrations.php
2025-01-07 03:02:25 +01:00

721 lines
33 KiB
PHP

<?php include('includes/header.php'); ?>
<div>
<div class="card card-body p-4">
<?= alertMessage(); ?>
<div class="row">
<div class="col-8">
<h3 class="fw-semibold mb-4">Kursanmeldungen</h3>
</div>
<?php
$paramResult = checkParamId('id');
if(!is_numeric($paramResult)){
echo '<div class="alert alert-danger" role="alert">'.$paramResult.'</div>';
return false;
} ?>
<div class="col-4">
<a href="categories-edit.php?id=<?=checkParamId('id') ;?>" class="btn btn-light float-end"> <i class="ti ti-arrow-left"></i> Zurück zur Übersicht</a>
</div>
</div>
<?php
$category = getById('tbl_categories',checkParamId('id'));
if($category['status'] == 200)
{
$students = getActiveStudentsByCategory($category['data']['id']);
$courses = getCoursesByCategory($category['data']['id']);
?>
<div class="row mb-3">
<div class="col-auto">
<h5 class="mb-3"><?= $category['data']['name'];?></h5>
</div>
<div class="col-3">
<input type="text" class="form-control" id="myInput" onkeyup="myFunction()" placeholder="Volltextsuche...">
</div>
<?php
if(($category['data']['registration'] == 'yes') && ($category['data']['confirmation'] == 'no')){?>
<div class="col-auto ">
<button onclick="exportTableToExcel('sortTable', 'Scolify - Kursanmeldungen nach Klasse <?= $category['data']['name']; ?>')" class="btn btn-success"><i class="ti ti-table me-2"></i>Export (nach Klasse), Alle Status</button>
</div>
<div class="col-auto ">
<button onclick="exportTableToExcelOnlyRegistered('sortTable', 'Scolify - Kursanmeldungen nach Klasse <?= $category['data']['name']; ?>')" class="btn btn-success"><i class="ti ti-table me-2"></i>Export (nach Klasse), Nur angemeldete</button>
</div>
<div class="col-auto text-end">
<button onclick="exportTableToExcelGesamt('sortTable', 'Scolify - Kursanmeldungen Gesamt<?= $category['data']['name']; ?>')" class="btn btn-success"><i class="ti ti-table me-2"></i>Export (Gesamt), Alle Status</button>
</div>
<div class="col-auto text-end">
<button onclick="exportTableToExcelGesamtOnlyRegistered('sortTable', 'Scolify - Kursanmeldungen Gesamt<?= $category['data']['name']; ?>')" class="btn btn-success"><i class="ti ti-table me-2"></i>Export (Gesamt), Nur angemeldete</button>
</div>
<?php }
if(($category['data']['registration'] == 'yes') && ($category['data']['confirmation'] == 'yes')){?>
<div class="col-auto ">
<button onclick="exportTableToExcelConfirmation('sortTable', 'Scolify - Kursanmeldungen nach Klasse <?= $category['data']['name']; ?>')" class="btn btn-success"><i class="ti ti-table me-2"></i>Export (nach Klasse), Alle Status</button>
</div>
<div class="col-auto ">
<button onclick="exportTableToExcelConfirmationOnlyRegistered('sortTable', 'Scolify - Kursanmeldungen nach Klasse <?= $category['data']['name']; ?>')" class="btn btn-success"><i class="ti ti-table me-2"></i>Export (nach Klasse), Nur angemeldete</button>
</div>
<div class="col-auto text-end">
<button onclick="exportTableToExcelGesamtConfirmation('sortTable', 'Scolify - Kursanmeldungen Gesamt<?= $category['data']['name']; ?>')" class="btn btn-success"><i class="ti ti-table me-2"></i>Export (Gesamt), Alle Status</button>
</div>
<div class="col-auto text-end">
<button onclick="exportTableToExcelGesamtConfirmationOnlyRegistered('sortTable', 'Scolify - Kursanmeldungen Gesamt<?= $category['data']['name']; ?>')" class="btn btn-success"><i class="ti ti-table me-2"></i>Export (Gesamt), Nur angemeldete</button>
</div>
<?php }
?>
</div>
</div>
<?php
if($category['data']['registration'] == 'no'){
echo '<h6>Für diese Kategorie werden keine Anmeldungen benötigt.</h6>';
}
else {
?>
<div class="table-responsive" id="studentTable">
<table class="table table-striped table-hover table-bordered" id="sortTable">
<thead>
<tr>
<!-- Überschrift für die Schüler -->
<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)">Anz.</th>
<!-- Überschriften für die Kurse -->
<?php
// Hole alle Kurse für diese Kategorie
$courses = getCoursesByCategory($category['data']['id']);
$students = getActiveStudentsByCategory($category['data']['id']);
function countApprovedAndEnrolledStudents($students, $courses) {
$approvedStudents = [];
$enrolledStudents = [];
foreach ($courses as $course) {
$approvedStudents[$course['id']] = [
'1_semester' => 0,
'2_semester' => 0
];
$enrolledStudents[$course['id']] = 0;
}
foreach ($students as $student) {
foreach ($courses as $course) {
$data = getStudentCourseData($student['id'], $course['id']);
if ($data !== null) {
if ($data['status'] === 'Genehmigt') {
if (($data['semester'] ?? '') === '1. Semester') {
$approvedStudents[$course['id']]['1_semester']++;
} elseif (($data['semester'] ?? '') === '2. Semester') {
$approvedStudents[$course['id']]['2_semester']++;
}
}
if ($data['status'] === 'Angemeldet') {
$enrolledStudents[$course['id']]++;
}
}
}
}
return ['approved' => $approvedStudents, 'enrolled' => $enrolledStudents];
}
$counts = countApprovedAndEnrolledStudents($students, $courses);
foreach ($courses as $course) {
echo '<th style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: auto;">' . $course['name'] ;//' <button class="ms-2 btn btn-sm btn-outline-primary sort-btn" data-course-id="' . $course['id'] . '">Prio <i class="ti ti-arrow-down"></i></button>';
if(($category['data']['registration'] == 'yes'
&& $category['data']['confirmation'] == 'yes'
&& $category['data']['type'] == 'semester')
|| ($category['data']['registration'] == 'yes'
&& $category['data']['confirmation'] == 'custom'
&& $category['data']['type'] == 'semester')
|| ($category['data']['registration'] == 'custom'
&& $category['data']['type'] == 'semester')){
echo '</br><small>Von Schülern ausgewählt: ' . $counts['enrolled'][$course['id']] . '</br>
1. Sem. Soll: (' . $course['minstudents_1sem'] . ' - ' . $course['maxstudents_1sem'] . ') </br>
1. Sem. Ist: ' . $counts['approved'][$course['id']]['1_semester'] . ' </br>
2. Sem. Soll: (' . $course['minstudents_2sem'] . ' - ' . $course['maxstudents_2sem'] . ') </br>
2. Sem. Ist: ' . $counts['approved'][$course['id']]['2_semester'] . '</small> </th>';
}
}
?>
</tr>
</thead>
<tbody>
<!-- Zeilen für jeden Schüler -->
<?php
// Hole alle aktiven Schüler für diese Kategorie
$students = getActiveStudentsByCategory($category['data']['id']);
foreach ($students as $student) {
echo '<tr>';
// Name des Schülers in der ersten Spalte
echo '<td>' . $student['firstname'] . '</td>';
echo '<td>' . $student['lastname'] . '</td>';
$class = getById('tbl_classes',$student['class']);
echo '<td>' . $class['data']['sek'] . ' ' . $class['data']['type'] . ' - ' . $class['data']['name'] .'</td>';
$allAssignedCourses = getAllAssignedCoursesByCategory($student['id'], $category['data']['id']);
$numAssignedCourses = count($allAssignedCourses);
echo '<td>' . $numAssignedCourses . '</td>';
// Spalten für die Kurse mit Zuweisungen
foreach ($courses as $course) {
// Abfrage, um den Status des Schülers für diesen Kurs zu erhalten
$studentID = $student['id'];
$courseID = $course['id'];
$data = getStudentCourseData($studentID, $courseID);
if(($category['data']['registration'] == 'custom') && ($course['registration'] == 'no')) {
echo '<td> <button type="button" class="btn btn-sm btn-outline-danger">Keine Anmeldung erforderlich</button> </td>';
}
else{
?>
<td>
<?php
if(($category['data']['registration'] == 'yes'
&& $category['data']['confirmation'] == 'yes')
|| ($category['data']['registration'] == 'yes'
&& $category['data']['confirmation'] == 'custom'
&& $course['confirmation'] == 'yes')
|| ($category['data']['confirmation'] == 'custom'
&& $course['registration'] == 'yes'
&& $course['confirmation'] == 'yes')){
?>
<div class="btn-group mb-1" role="group">
<input type="radio" class="btn-check" name="statusbtnradio_<?= $studentID;?>_<?= $courseID;?>" id="statusyes_<?= $studentID;?>_<?= $courseID;?>" value="Angemeldet" autocomplete="off" <?= ($data['status'] ?? '') == 'Angemeldet' ? 'checked':'' ;?>>
<label class="btn btn-sm btn-outline-dark" for="statusyes_<?= $studentID;?>_<?= $courseID;?>">?</label>
<input type="radio" class="btn-check" name="statusbtnradio_<?= $studentID;?>_<?= $courseID;?>" id="statusno_<?= $studentID;?>_<?= $courseID;?>" value="Abgelehnt" autocomplete="off" <?= ($data['status'] ?? '') == 'Abgelehnt' ? 'checked':'' ;?>>
<label class="btn btn-sm btn-outline-danger" for="statusno_<?= $studentID;?>_<?= $courseID;?>">X</label>
<input type="radio" class="btn-check" name="statusbtnradio_<?= $studentID;?>_<?= $courseID;?>" id="statuscustom_<?= $studentID;?>_<?= $courseID;?>" value="Genehmigt" autocomplete="off" <?= ($data['status'] ?? '') == 'Genehmigt' ? 'checked':'' ;?>>
<label class="btn btn-sm btn-outline-success" for="statuscustom_<?= $studentID;?>_<?= $courseID;?>"><i class="ti ti-check"></i></label>
</div>
<?php
if(($category['data']['registration'] == 'yes'
&& $category['data']['confirmation'] == 'yes'
&& $category['data']['type'] == 'semester')
|| ($category['data']['registration'] == 'yes'
&& $category['data']['confirmation'] == 'custom'
&& $category['data']['type'] == 'semester')
|| ($category['data']['registration'] == 'custom'
&& $category['data']['type'] == 'semester')){
?>
<div class="btn-group mb-1" role="group" id="semesterGroup_<?= $studentID;?>_<?= $courseID;?>">
<input type="radio" class="btn-check" name="sembtnradio_<?= $studentID;?>_<?= $courseID;?>" id="sem1_<?= $studentID;?>_<?= $courseID;?>" value="1" autocomplete="off" <?= ($data['semester'] ?? '') == '1. Semester' ? 'checked':'' ;?>>
<label class="btn btn-sm btn-outline-info" for="sem1_<?= $studentID;?>_<?= $courseID;?>">Sem. 1</label>
<input type="radio" class="btn-check" name="sembtnradio_<?= $studentID;?>_<?= $courseID;?>" id="sem2_<?= $studentID;?>_<?= $courseID;?>" value="2" autocomplete="off" <?= ($data['semester'] ?? '') == '2. Semester' ? 'checked':'' ;?>>
<label class="btn btn-sm btn-outline-info" for="sem2_<?= $studentID;?>_<?= $courseID;?>">2</label>
</div>
<?php
}
?>
<?php
if(($category['data']['registration'] == 'yes'
&& $category['data']['confirmation'] == 'yes'
&& $category['data']['set_priority'] == 'yes')
|| ($category['data']['registration'] == 'yes'
&& $category['data']['confirmation'] == 'custom'
&& $category['data']['set_priority'] == 'yes')
|| ($category['data']['registration'] == 'custom'
&& $category['data']['set_priority'] == 'yes')){
?>
<div class="btn-group mb-1" role="group">
<input type="radio" class="btn-check" name="priobtnradio_<?= $studentID;?>_<?= $courseID;?>" id="prio1_<?= $studentID;?>_<?= $courseID;?>" value="1" autocomplete="off" <?= ($data['priority'] ?? '') == '1' ? 'checked':'' ;?>>
<label class="btn btn-sm btn-outline-secondary" for="prio1_<?= $studentID;?>_<?= $courseID;?>">Prio. 1</label>
<input type="radio" class="btn-check" name="priobtnradio_<?= $studentID;?>_<?= $courseID;?>" id="prio2_<?= $studentID;?>_<?= $courseID;?>" value="2" autocomplete="off" <?= ($data['priority'] ?? '') == '2' ? 'checked':'' ;?>>
<label class="btn btn-sm btn-outline-primary" for="prio2_<?= $studentID;?>_<?= $courseID;?>">2</label>
<input type="radio" class="btn-check" name="priobtnradio_<?= $studentID;?>_<?= $courseID;?>" id="prio3_<?= $studentID;?>_<?= $courseID;?>" value="3" autocomplete="off" <?= ($data['priority'] ?? '') == '3' ? 'checked':'' ;?>>
<label class="btn btn-sm btn-outline-warning" for="prio3_<?= $studentID;?>_<?= $courseID;?>">3</label>
</div>
<?php
}
}else{
$studentID = $student['id'];
$courseID = $course['id'];
$data = getStudentCourseData($studentID, $courseID);
if ($data !== null) {?>
<button type="button" class="btn btn-sm btn-info"><?=$data['status']; ?></button>
<?php }
}
?>
</td>
<?php
}
}
echo '</tr>';
}
?>
</tbody>
</table>
</div>
<?php
}
?>
</div>
<?php
}
else
{
echo '<div class="alert alert-danger" role="alert">'.$category['message'].'</div>';
}
?>
</form>
</div>
</div>
<?php include('includes/footer.php'); ?>
<script>
$(document).ready(function() {
// Funktion zum Initialisieren des Status
function initializeStatus() {
$('input[name^="statusbtnradio_"]').each(function() {
var radioName = $(this).attr('name');
var studentID = radioName.split('_')[1];
var courseID = radioName.split('_')[2];
var selectedStatus = $('input[name="' + radioName + '"]:checked').val();
// Zeige das Semesterfeld nur, wenn "Genehmigt" ausgewählt wurde
if (selectedStatus !== 'Genehmigt') {
$('#semesterGroup_' + studentID + '_' + courseID).hide();
}
});
}
// Initialisieren des Status beim Laden der Seite
initializeStatus();
// Funktion zum Hinzufügen der Eventlistener für Radiobutton-Änderungen
function addRadioChangeListeners() {
// Eventlistener für Status-Radiobutton-Änderungen
$('input[name^="statusbtnradio_"]').change(function() {
sendData($(this));
});
// Eventlistener für Semester-Radiobutton-Änderungen
$('input[name^="sembtnradio_"]').change(function() {
sendData($(this));
});
// Eventlistener für Prioritäts-Radiobutton-Änderungen
$('input[name^="priobtnradio_"]').change(function() {
sendData($(this));
});
}
// Eventlistener für Sortierknöpfe
$('.sort-btn').click(function() {
var courseId = $(this).data('course-id');
sortStudentsByPriority(courseId);
// Nach dem Sortieren der Schüler Eventlistener für Radiobutton-Änderungen erneut hinzufügen
addRadioChangeListeners();
});
// Funktion zum Sortieren der Schüler pro Kurs nach ihren Prioritäten
function sortStudentsByPriority(courseId) {
var students = $('#studentTable tbody tr');
var sortedStudents = students.toArray().sort(function(a, b) {
var priorityA = parseInt($(a).find('[data-course-id="' + courseId + '"]').data('priority'));
var priorityB = parseInt($(b).find('[data-course-id="' + courseId + '"]').data('priority'));
// Sortiere aufsteigend nach Priorität, wobei Schüler ohne Priorität zuerst kommen
if (isNaN(priorityA)) return -1;
if (isNaN(priorityB)) return 1;
return priorityA - priorityB;
});
$('#studentTable tbody').empty().append(sortedStudents);
}
// Funktion zum Senden von Daten an den Server
function sendData(element) {
var radioName = element.attr('name');
var studentID = radioName.split('_')[1];
var courseID = radioName.split('_')[2];
var selectedStatus = $('input[name="statusbtnradio_' + studentID + '_' + courseID + '"]:checked').val();
var selectedSemester = $('input[name="sembtnradio_' + studentID + '_' + courseID + '"]:checked').val();
var selectedPrio = $('input[name="priobtnradio_' + studentID + '_' + courseID + '"]:checked').val();
// Zeige das Semesterfeld nur, wenn "Genehmigt" ausgewählt wurde
if (selectedStatus === 'Genehmigt') {
$('#semesterGroup_' + studentID + '_' + courseID).show();
} else {
$('#semesterGroup_' + studentID + '_' + courseID).hide();
}
// AJAX-Anfrage senden
$.ajax({
url: 'code.php',
method: 'POST',
data: {
studentID: studentID,
courseID: courseID,
status: selectedStatus,
semester: selectedSemester,
prio: selectedPrio
},
success: function(response) {
// Erfolgreiche Antwort verarbeiten
console.log(response);
},
error: function(xhr, status, error) {
// Fehlerbehandlung
console.error(error);
}
});
}
// Initialisieren der Eventlistener für Radiobutton-Änderungen
addRadioChangeListeners();
});
</script>
<script>
function exportTableToExcel(tableID, filename = '') {
// Hole die Tabelle
var table = document.getElementById(tableID);
var wb = XLSX.utils.book_new();
// Trenne die Daten nach Klassen
var classSections = {};
for (var i = 1; i < table.rows.length; i++) {
var className = table.rows[i].cells[2].innerText;
if (!classSections[className]) {
classSections[className] = [];
}
var row = [];
for (var j = 0; j < table.rows[i].cells.length; j++) {
row.push(table.rows[i].cells[j].innerText);
}
classSections[className].push(row);
}
// Erstelle ein Arbeitsblatt für jede Klasse
for (var className in classSections) {
var shortenedClassName = className.substring(0, 30); // Kürze den Klassennamen auf 30 Zeichen
var data = [Array.from(table.rows[0].cells).map(cell => cell.innerText)]; // Header-Zeile
data = data.concat(classSections[className]);
var ws = XLSX.utils.aoa_to_sheet(data);
XLSX.utils.book_append_sheet(wb, ws, shortenedClassName);
}
// Generiere die Excel-Datei
filename = filename ? filename + '.xlsx' : 'excel_data.xlsx';
XLSX.writeFile(wb, filename);
}
</script>
<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>
<script>
function exportTableToExcelGesamtConfirmation(tableID, filename = '') {
var table = document.getElementById(tableID);
var wb = XLSX.utils.book_new();
var ws_data = [];
// Get headers
var headers = Array.from(table.rows[0].cells).map(cell => cell.innerText);
ws_data.push(headers);
// Get rows
for (var i = 1; i < table.rows.length; i++) {
var row = [];
for (var j = 0; j < table.rows[i].cells.length; j++) {
if (j >= 4) { // Assuming the status cells start from the 5th column
// For the status cells with radio buttons
var radios = table.rows[i].cells[j].getElementsByTagName('input');
var selectedValue = '';
for (var k = 0; k < radios.length; k++) {
if (radios[k].checked) {
selectedValue = radios[k].value;
break;
}
}
row.push(selectedValue);
} else {
row.push(table.rows[i].cells[j].innerText);
}
}
ws_data.push(row);
}
// Create worksheet
var ws = XLSX.utils.aoa_to_sheet(ws_data);
XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
// Generate Excel file
filename = filename ? filename + '.xlsx' : 'excel_data_confirmation.xlsx';
XLSX.writeFile(wb, filename);
}
</script>
<script>
function exportTableToExcelGesamtConfirmationOnlyRegistered(tableID, filename = '') {
var table = document.getElementById(tableID);
var wb = XLSX.utils.book_new();
var ws_data = [];
// Get headers
var headers = Array.from(table.rows[0].cells).map(cell => cell.innerText);
ws_data.push(headers);
// Iterate through each student
for (var i = 1; i < table.rows.length; i++) {
var studentInfo = [];
var studentCourses = [];
// Get student information
for (var j = 0; j < 4; j++) {
studentInfo.push(table.rows[i].cells[j].innerText);
}
// Check each course for the student
var hasApprovedCourse = false;
for (var j = 4; j < table.rows[i].cells.length; j++) {
var radios = table.rows[i].cells[j].getElementsByTagName('input');
var selectedValue = '';
for (var k = 0; k < radios.length; k++) {
if (radios[k].checked) {
selectedValue = radios[k].value;
if (selectedValue === 'Genehmigt') {
hasApprovedCourse = true;
}
break;
}
}
if (selectedValue === 'Genehmigt') {
studentCourses.push(selectedValue);
} else {
studentCourses.push('');
}
}
// Add student row if at least one course is approved
if (hasApprovedCourse) {
ws_data.push(studentInfo.concat(studentCourses));
}
}
// Create worksheet
var ws = XLSX.utils.aoa_to_sheet(ws_data);
XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
// Generate Excel file
filename = filename ? filename + '.xlsx' : 'excel_data_confirmation_only_registered.xlsx';
XLSX.writeFile(wb, filename);
}
</script>
<script>
function exportTableToExcelConfirmation(tableID, filename = '') {
var table = document.getElementById(tableID);
var wb = XLSX.utils.book_new();
// Group data by class
var dataByClass = {};
for (var i = 1; i < table.rows.length; i++) {
var className = table.rows[i].cells[2].innerText; // Assuming class name is in the third column
if (!dataByClass[className]) {
dataByClass[className] = [];
}
var rowData = [];
for (var j = 0; j < table.rows[i].cells.length; j++) {
if (j >= 4) { // Assuming the status cells start from the 5th column
var radios = table.rows[i].cells[j].getElementsByTagName('input');
var selectedValue = '';
for (var k = 0; k < radios.length; k++) {
if (radios[k].checked) {
selectedValue = radios[k].value;
break;
}
}
rowData.push(selectedValue);
} else {
rowData.push(table.rows[i].cells[j].innerText);
}
}
dataByClass[className].push(rowData);
}
// Create workbook for each class
for (var className in dataByClass) {
var classData = dataByClass[className];
var ws_data = [];
// Get headers
var headers = Array.from(table.rows[0].cells).map(cell => cell.innerText);
ws_data.push(headers);
// Add rows for this class
for (var i = 0; i < classData.length; i++) {
ws_data.push(classData[i]);
}
// Create worksheet
var ws = XLSX.utils.aoa_to_sheet(ws_data);
// Trim class name to maximum 30 characters
var trimmedClassName = className.substring(0, 30);
// Add worksheet to workbook
XLSX.utils.book_append_sheet(wb, ws, trimmedClassName);
}
// Generate Excel file
filename = filename ? filename + '.xlsx' : 'excel_data_confirmation_only_registered.xlsx';
XLSX.writeFile(wb, filename);
}
</script>
<script>
function exportTableToExcelConfirmationOnlyRegistered(tableID, filename = '') {
var table = document.getElementById(tableID);
var wb = XLSX.utils.book_new();
// Group data by class
var dataByClass = {};
for (var i = 1; i < table.rows.length; i++) {
var className = table.rows[i].cells[2].innerText; // Assuming class name is in the third column
if (!dataByClass[className]) {
dataByClass[className] = [];
}
var rowData = [];
var hasApprovedCourse = false;
var studentInfo = [];
for (var j = 0; j < 4; j++) {
studentInfo.push(table.rows[i].cells[j].innerText); // Store student info (first 4 columns)
}
rowData = studentInfo; // Add student info to rowData
for (var j = 4; j < table.rows[i].cells.length; j++) {
var radios = table.rows[i].cells[j].getElementsByTagName('input');
var selectedValue = '';
var courseName = table.rows[0].cells[j].innerText; // Get course name from header
for (var k = 0; k < radios.length; k++) {
if (radios[k].checked && radios[k].value === 'Genehmigt') {
hasApprovedCourse = true;
selectedValue = 'Genehmigt'
break;
}
}
rowData.push(selectedValue);
}
if (hasApprovedCourse) {
dataByClass[className].push(rowData);
}
}
// Create workbook for each class
for (var className in dataByClass) {
var classData = dataByClass[className];
var ws_data = [];
// Add headers
var headers = ['Vorname', 'Nachname', 'Klasse', 'Anzahl ausgewählter Kurse']; // Header for student info
for (var i = 4; i < table.rows[0].cells.length; i++) {
headers.push(table.rows[0].cells[i].innerText); // Add course names from 5th column
}
ws_data.push(headers);
// Add rows for this class
for (var i = 0; i < classData.length; i++) {
ws_data.push(classData[i]);
}
// Create worksheet
var ws = XLSX.utils.aoa_to_sheet(ws_data);
// Trim class name to maximum 30 characters
var trimmedClassName = className.substring(0, 30);
// Add worksheet to workbook
XLSX.utils.book_append_sheet(wb, ws, trimmedClassName);
}
// Generate Excel file
filename = filename ? filename + '.xlsx' : 'excel_data_confirmation_only_registered.xlsx';
XLSX.writeFile(wb, filename);
}
</script>