forked from gymdb/speechday
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util.php
110 lines (91 loc) · 3.07 KB
/
Util.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
require_once('dao/EventDAO.php');
function escape($string) {
return nl2br(htmlentities($string));
}
class SessionContext {
private static $isCreated = false;
public static function create() {
if (!self::$isCreated) {
self::$isCreated = session_start();
}
return self::$isCreated;
}
}
function redirect($page = null) {
if ($page == null) {
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : $_SERVER['REQUEST_URI'];
}
header("Location: $page");
}
function action($action, $params = null) {
$res = 'controller.php?action=' . rawurlencode($action);
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : $_SERVER['REQUEST_URI'];
$res .= '&page=' . rawurlencode($page);
if (is_array($params)) {
foreach ($params as $name => $value) {
$res .= '&' . rawurlencode($name) . '=' . rawurlencode($value);
}
}
echo $res;
}
function createPasswordHash($password) {
return password_hash($password, PASSWORD_DEFAULT);
}
function getDateOptions($attendance, $dateFrom = true) {
$activeEvent = EventDAO::getActiveEvent();
$time = $activeEvent->getDateFrom();
$endTime = $activeEvent->getDateTo();
$options = '';
while ($time <= $endTime) {
$halfHour = 60 * 60 / 2;
$selected = '';
if ($dateFrom && $time == $attendance['from']) {
$selected = ' selected';
} else if (!$dateFrom && $time == $attendance['to']) {
$selected = ' selected';
}
$options .= sprintf('<option value="%s"%s>%s</option>', $time, $selected, date('H:i', $time));
$time += $halfHour;
}
return $options;
}
function getTeacherOptions() {
$teachers = UserDAO::getUsersForRole('teacher');
$options = '<option value="-1">Bitte wähle einen Lehrer aus ...</option>';
foreach ($teachers as $teacher) {
$options .= sprintf('<option value="%s" %s>%s</option>', $teacher->getId(), ($teacher->isAbsent()==1?'disabled':''),$teacher->getLastName() . ' ' . $teacher->getFirstName().' '.$teacher->getTitle().($teacher->isAbsent()==1?' - abwesend':''));
}
return $options;
}
function toDate($timestamp, $format) {
return date($format, $timestamp);
}
function getActionString($actionId) {
switch ($actionId) {
case 1:
return 'eingeloggt';
case 2:
return 'ausgeloggt';
case 3:
return 'Termin gebucht';
case 4:
return 'Termin gelöscht';
case 5:
return 'Anwesenheit geändert';
default:
return 'Unbekannte Aktion';
}
}
function getActiveSpeechdayText() {
$activeEvent = EventDAO::getActiveEvent();
if ($activeEvent != null) {
return "Elternsprechtag am " . toDate($activeEvent->getDateFrom(), 'd.m.Y');
} else {
return "Es gibt momentan keinen aktiven Elternsrpechtag!";
}
}
function optionalBreak() {
return '<span class="no-print"><br></span><span class="only-print"> - </span>';
//return '<span class="only-print"> - </span>';
}