aboutsummaryrefslogtreecommitdiff
path: root/show-user.php
blob: 5d9a1f4c1c24003cd1e4e52ac9b323203fecf40a (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
include "setup.php";
if (session_status() === PHP_SESSION_NONE) {
    my_session_start();
}
$login=false;
if (isset($_SESSION["login"])) {
    $login = $_SESSION["login"];
}

if ($login !== "admin" and $login !== "user") {
    header("Location: index.php");
    exit;
}
?>
<!DOCTYPE html>
<html>
<body>
<table>
<tr>
<?php
if ($login === "admin") {
?>
<td>
    <a href="admin-addusers.php">Add students</a>
</td>
<td>
    <a href="admin-show.php">Show students</a>
</td>
<td>
    <a href="logout.php">Logout</a>
</td>
<?php
} elseif ($login === "user") {
?>
<td>
    <a href="logout.php">Logout</a>
</td>
<?php
}
?>
</tr>
</table>

<?php

// return matrikelnummer or FALSE
function retrieve_get_data () {
    if (empty($_GET["matrikelnummer"])) {
        return FALSE;
    } else {
        $mat = $_GET["matrikelnummer"];
    }
    // Exactly 9 digits
    if (!preg_match("/^[0-9]{7}$/",$mat)) {
        return FALSE;
    }
    return $mat;
}

if ($login === "admin") {
    $matrikelnummer = retrieve_get_data();
} elseif ($login === "user") {
    $matrikelnummer = $_SESSION["mymatrikelnummer"];
} else {
    $matrikelnummer = FALSE;
}

if ($matrikelnummer and 
    !empty($students[$matrikelnummer])) {
    $vorname = $students[$matrikelnummer]["vorname"];
    $nachname = $students[$matrikelnummer]["nachname"];
    echo "<h1>$nachname, $vorname ($matrikelnummer)</h1>";
    echo "<h3>Status</h3>";
    echo "<table>";
    echo "<tr>";
    echo "<th>Fach</th>";
    echo "<th>Labor</th>";
    echo "<th>Klausur</th>";
    echo "</tr>";
    foreach ($students[$matrikelnummer]["noten"] as $fach => $notenliste) {
        $fachname = $pfp[$fach]["name"];
        if (!empty($notenliste["klausur"])) {
            $klausurnote = $notenliste["klausur"];
        } else {
            $klausurnote = "-";
        }
        if (!empty($notenliste["labor"])) {
            $labornote = $notenliste["labor"];
        } else {
            $labornote = "-";
        }
        echo "<tr>";
        echo "<td>$fachname</td>";
        echo "<td>$labornote</td>";
        echo "<td>$klausurnote</td>";
        echo "</tr>";     
    }
    echo "</table>";

    echo "<h3>Gruppen</h3>";
    echo "<table>";
    echo "<tr>";
    echo "<th>Semester</th>";
    echo "<th>Fach</th>";
    echo "<th>Gruppenname</th>";
    echo "<th>Teilnehmer</th>";
    echo "</tr>";
    foreach ($groups as $semestername => $fachliste) {
        foreach ($fachliste as $fachname => $gruppenliste) {
            foreach ($gruppenliste as $gname => $teilnehmerliste) {
                if (in_array($matrikelnummer, $teilnehmerliste)) {
                    $tnnamensliste = "";
                    foreach ($teilnehmerliste as $tnmat) {
                        if (empty($tnnamensliste)) {
                            $tnnamensliste = $students[$tnmat]["nachname"];
                        } else {
                            $tnnamensliste = $tnnamensliste.", ".$students[$tnmat]["nachname"];
                        }
                    }
                    echo "<tr>";
                    echo "<td>$semestername</td>";
                    echo "<td>$fachname</td>";
                    echo "<td>$gname</td>";
                    echo "<td>$tnnamensliste</td>";
                    echo "</tr>";
                }
            }
        }
    }
    echo "</table>";
    
    echo "<h3>Geschichte</h3>";
    echo "<table>";
    echo "<tr>";
    echo "<th>Ereignisliste</th>";
    echo "</tr>";
    foreach ($students[$matrikelnummer]["history"] as $ereignis) {
        echo "<tr>";
        echo "<td>$ereignis</td>";
        echo "</tr>";
    }
    echo "</table>";
} else {
    echo "<h1>Error</h1>";
}
?>

</body>
</html>