43 lines
1.6 KiB
PHP
43 lines
1.6 KiB
PHP
<?php
|
|
include('includes/header.php');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
$student_id = $studentInfos['data']['id'];
|
|
$courses = [
|
|
'di_vo' => validate($_POST['di_vo']),
|
|
'di_na' => validate($_POST['di_na']),
|
|
'do_vo' => validate($_POST['do_vo']),
|
|
'do_na' => validate($_POST['do_na'])
|
|
];
|
|
|
|
// Löschen aller vorhandenen Kursanmeldungen für diesen Schüler
|
|
$deleteQuery = "DELETE FROM tbl_assign_students_courses WHERE student_id = '$student_id'";
|
|
mysqli_query($conn, $deleteQuery);
|
|
|
|
// Einfügen der neuen Kursanmeldungen, nur wenn genügend Platz vorhanden ist
|
|
foreach ($courses as $course_id) {
|
|
if (!empty($course_id)) {
|
|
// Überprüfen, ob der Kurs noch Platz hat
|
|
$checkQuery = "SELECT COUNT(ascs.course_id) as current_students, c.maxstudents
|
|
FROM tbl_courses c
|
|
LEFT JOIN tbl_assign_students_courses ascs ON c.id = ascs.course_id
|
|
WHERE c.id = '$course_id'
|
|
GROUP BY c.id";
|
|
$result = mysqli_query($conn, $checkQuery);
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
if ($row && $row['current_students'] < $row['maxstudents']) {
|
|
// Wenn der Kurs Platz hat, speichern
|
|
$insertQuery = "INSERT INTO tbl_assign_students_courses (student_id, course_id, status)
|
|
VALUES ('$student_id', '$course_id', 'Ausgewählt')";
|
|
mysqli_query($conn, $insertQuery);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Weiterleitung nach register.php
|
|
header("Location: register.php");
|
|
exit();
|
|
}
|
|
?>
|