aboutsummaryrefslogtreecommitdiff
path: root/admin-update.php
blob: 5634f6d8fddff93fba47ad4d7374c4813c9179cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/*
    praktrack - tracking the parts of a portfolio review
    Copyright (C) 2026  Friedrich Beckmann <friedrich.beckmann@tha.de>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
*/

// Check the entries in the form and compare them with the
// data in the database. If there are updates, then change
// the data in the database and append the json file with
// the changes.
if (empty($_POST["note"])) {
    return;
}
$notenneu = $_POST["note"];

foreach ($notenneu as $matrikelnummer => $pruefungen) {
    foreach ($pruefungen as $fach => $semesterliste) {
        $notenupdate[$fach] = [];
        if (!array_key_exists($fach,$students[$matrikelnummer]["noten"])) {
            var_dump($students[$matrikelnummer]);
            echo "<p>ERROR: Fach $fach bei $matrikelnummer existiert nicht</p>";
            break;
        }
        foreach ($semesterliste as $semestername => $teilpruefungen) {
            // "amt" is a checkbox input where the name exists only when checked
            // So the $teilpruefung loop will only iterate if it is checked.
            if (!empty($students[$matrikelnummer]["noten"][$fach]["amt"])
                and empty($teilpruefungen["amt"])) {
                $notenupdate[$fach]["amt"]="";
            }
            foreach ($teilpruefungen as $teilpruefung => $note) {
                if (!empty($note)
                    and (in_array($note,$notendelete)
                    or empty($students[$matrikelnummer]["noten"][$fach][$teilpruefung])
                    or $students[$matrikelnummer]["noten"][$fach][$teilpruefung] !== $note)) {
                    if ($teilpruefung === "klausur" and in_array($note,$notenklausur)
                        or $teilpruefung === "labor" and in_array($note,$notenlabor)
                        or $teilpruefung === "amt" and in_array($note,$notenamt)
                        or in_array($note,$notendelete)) {
                        $note = in_array($note,$notendelete) ? "" : $note;
                        $notenupdate[$fach][$teilpruefung]=$note;
                    } else {
                        var_dump($students[$matrikelnummer]);
                        echo "<p>ERROR: Note $note ungueltig fuer $matrikelnummer,$fach,$teilpruefung </p>";
                    }
                }
            }
        }
        foreach ($notenupdate[$fach] as $teilpruefung => $neuenote) {
            $students[$matrikelnummer]["noten"][$fach][$teilpruefung] = $neuenote;
            db_student_update_note($matrikelnummer,$fach,$teilpruefung,$neuenote);
        }
    }
}

?>