/
statistics.php
91 lines (77 loc) · 2.34 KB
/
statistics.php
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
<?php
require_once('lib/settings.php');
require_once('lib/db.php');
require_once('lib/users.php');
require_once('lib/session.php');
require_once('lib/login.php');
require_once('lib/voc.php');
if(!connect_mysql()) {
exit();
}
include('lib/loginfilter.php');
include('lib/navbar.php');
$isAdmin = isUserInRole('admin');
if(!isset($_SESSION['statsorder']))
$_SESSION['statsorder'] = $_SESSION['userinfo']->statsorder;
$orderby = $_SESSION['statsorder'];
if(isset($_REQUEST['o'])) {
$allowed = array('total' => true, 'ratio' => true, 'username' => true, 'correct' => true, 'wrong' => true);
if(isset($allowed[$_REQUEST['o']]))
$orderby = $_REQUEST['o'];
else {
header('location: /statistics');
exit();
}
if($_SESSION['statsorder'] != $orderby) {
$_SESSION['statsorder'] = $orderby;
if(setStatisticsOrder($_SESSION['userid'], $orderby))
setInfo('Sortierreihenfolge wurde gespeichert!');
else
setError('Fehler beim speichern der Sortierreihenfolge!');
header("location: {$SETTINGS['url']}/statistics");
exit();
}
}
$stats = getStatistics($orderby);
if($stats === false) {
setError('Fehler beim laden der Statistik!');
}
$tablebody = '';
foreach($stats as $user) {
$username = htmlspecialchars($user->username, 0, 'UTF-8');
$lastname = htmlspecialchars($user->lastname, 0, 'UTF-8');
$group = getRoleName($user->group);
$userid = $user->id;
$ratio = intval($user->ratio);
$name = $username;
$extra = '';
if($isAdmin) {
$name = "<a href=\"{$SETTINGS['path']}/user/$userid\">$name</a>";
$extra = "<td>$group</td>";
}
$tablebody .= "<tr><td>$name ($lastname)</td><td>{$user->total}</td><td>{$user->correct}</td><td>{$user->wrong}</td><td>$ratio %</td>$extra</tr>\n";
}
$xhdr = $isAdmin ? "<th>Gruppe</th>" : '';
$table = <<< EOT
<table class="list">
<thead>
<tr>
<th>Benuztername (<a href="{$SETTINGS['path']}/statistics/username">↑</a>)</th>
<th>Gesamt (<a href="{$SETTINGS['path']}/statistics/total">↑</a>)</th>
<th>Davon richtig (<a href="{$SETTINGS['path']}/statistics/correct">↑</a>)</th>
<th>Davon falsch (<a href="{$SETTINGS['path']}/statistics/wrong">↑</a>)</th>
<th>Quote (<a href="{$SETTINGS['path']}/statistics/ratio">↑</a>)</th>
$xhdr </tr>
</thead>
<tbody>
$tablebody
</tbody>
</table>
EOT;
$TITLE = 'Statistik';
$CONTENT = <<< EOT
<h2>Statistik</h2>
$table
EOT;
include('lib/template.php');
exit();