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
|
<?php
class SubPage
{
private static $show;
public static function doPreprocess()
{
self::$show = Request::any('show', false, 'string');
$action = Request::post('action');
if ($action === 'deleteFilter') {
User::assertPermission("ldapfilters.save");
self::deleteLdapFilter();
} else if ($action === 'saveFilter') {
User::assertPermission("ldapfilters.save");
self::saveLdapFilter();
}
User::assertPermission("ldapfilters.view");
}
public static function doRender()
{
if (self::$show === false) {
// Get all ldapfilters from the sat db.
$ldapfilters = Database::queryAll("SELECT filterid, filtername, filterkey, filtervalue FROM sat.presetlecturefilter
WHERE filtertype ='LDAP' ORDER BY filtername ASC");
$data = array(
'ldapfilters' => $ldapfilters,
'hasEditPermission' => User::hasPermission('ldapfilters.save')
);
Render::addTemplate('ldapfilters', $data);
} else if (self::$show === 'edit') {
$filterid = Request::get('filterid', false, 'int');
if ($filterid === false) {
Render::addTemplate('ldapfilter-add', array(
'filterid' => 0
));
} else {
$ldapfilter = Database::queryFirst("SELECT filterid, filtername, filterkey, filtervalue FROM sat.presetlecturefilter
WHERE filterid = :id AND filtertype = 'LDAP'", array( 'id' => $filterid));
// TODO: Show error if not exists
Render::addTemplate('ldapfilter-add', $ldapfilter);
}
}
}
private static function deleteLdapFilter() {
User::assertPermission('ldapfilters.save');
$filterid = Request::post('filterid', false, 'int');
if ($filterid === false) {
Message::addError('ldap-filter-id-missing');
return;
}
$res = Database::exec("DELETE FROM sat.presetlecturefilter WHERE filterid = :id AND filtertype = 'LDAP'", array('id' => $filterid));
if ($res !== 1) {
Message::addWarning('ldap-invalid-filter-id', $filterid);
} else {
Message::addSuccess('ldap-filter-deleted');
}
}
private static function saveLdapFilter() {
$filterid = Request::post('filterid', '', 'int');
$filtername = Request::post('filtername', false, 'string');
$filterattribute = Request::post('attribute', false, 'string');
$filtervalue = Request::post('value', false, 'string');
if ($filtername === false || $filterattribute === false || $filtervalue === false) {
Message::addError('ldap-filter-save-missing-information');
return;
}
if ($filterid === 0) {
// Insert filter in the db.
$res = Database::exec("INSERT INTO sat.presetlecturefilter (filtertype, filtername, filterkey, filtervalue)
VALUES ('LDAP', :filtername, :attribute, :value)", array(
'filtername' => $filtername,
'attribute' => $filterattribute,
'value' => $filtervalue
));
if ($res !== 1) {
Message::addError('ldap-filter-insert-failed');
} else {
Message::addSuccess('ldap-filter-created');
}
} else {
// Update filter in the db.
$res = Database::exec("UPDATE sat.presetlecturefilter SET
filtername = :filtername, filterkey = :attribute, filtervalue = :value
WHERE filterid = :filterid AND filtertype = 'LDAP'", array(
'filterid' => $filterid,
'filtername' => $filtername,
'attribute' => $filterattribute,
'value' => $filtervalue
));
if ($res !== 1) {
Message::addError('ldap-filter-insert-failed');
} else {
Message::addSuccess('ldap-filter-saved');
}
}
Util::redirect("?do=dozmod§ion=ldapfilters");
}
public static function doAjax()
{
}
}
|