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
|
<?php
# Lifter010: TODO
/**
* specification.php - controller class for the specification
*
* 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 2 of
* the License, or (at your option) any later version.
*
* @author Nico Müller <nico.mueller@uni-oldenburg.de>
* @author Michael Riehemann <michael.riehemann@uni-oldenburg.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @package admin
* @since Stud.IP version 2.1
*/
class Admin_SpecificationController extends AuthenticatedController
{
/**
* Common tasks for all actions.
*/
public function before_filter(&$action, &$args)
{
global $perm;
parent::before_filter($action, $args);
# user must have special permission
if (!$perm->have_perm(Config::get()->AUX_RULE_ADMIN_PERM ?: 'admin')) {
throw new AccessDeniedException();
}
//setting title and navigation
Navigation::activateItem('/admin/config/specification');
PageLayout::setTitle(_('Verwaltung von Zusatzangaben'));
}
/**
* Maintenance view for the specification parameters
*/
public function index_action()
{
$this->allrules = AuxLockRules::getAllLockRules();
}
/**
* Edit or create a rule
*
* @param md5 $edit_id
*/
public function edit_action($id = null)
{
//get data
$user_field = 'user';
$semdata_field = 'usersemdata';
$this->semFields = AuxLockRules::getSemFields();
$this->entries_user = DataField::getDataFields($user_field);
$this->entries_semdata = DataField::getDataFields($semdata_field);
$this->rule = is_null($id) ? false : AuxLockRules::getLockRuleByID($id);
if ($GLOBALS['perm']->have_perm('root') && count($this->entries_semdata) == 0) {
PageLayout::postWarning(sprintf(
_('Sie müssen zuerst im Bereich %sDatenfelder%s in der Kategorie '
. '<em>Datenfelder für Personenzusatzangaben in Veranstaltungen</em> '
. 'einen neuen Eintrag erstellen.'),
'<a href="' . URLHelper::getLink('dispatch.php/admin/datafields') . '">',
'</a>'
));
}
}
/**
* Store or edit Rule
* @param string $id
*/
public function store_action($id = '')
{
CSRFProtection::verifyRequest();
$errors = [];
if (!Request::get('rulename')) {
$errors[] = _('Bitte geben Sie der Regel mindestens einen Namen!');
}
if (!AuxLockRules::checkLockRule(Request::getArray('fields'))) {
$errors[] = _('Bitte wählen Sie mindestens ein Feld aus der Kategorie "Zusatzinformationen" aus!');
}
if (empty($errors)) {
if (!$id) {
//new
AuxLockRules::createLockRule(Request::get('rulename'), Request::get('description'), Request::getArray('fields'), Request::getArray('order'));
} else {
//edit
AuxLockRules::updateLockRule($id, Request::get('rulename'), Request::get('description'), Request::getArray('fields'), Request::getArray('order'));
}
PageLayout::postSuccess(sprintf(
_('Die Regel "%s" wurde erfolgreich gespeichert!'),
htmlReady(Request::get('rulename'))
));
} else {
PageLayout::postError(_('Ihre Eingaben sind ungültig.'), $errors);
}
$this->redirect('admin/specification');
}
/**
* Delete a rule, using a modal dialog
*
* @param md5 $rule_id
*/
public function delete_action($rule_id)
{
CSRFProtection::verifyUnsafeRequest();
if (AuxLockRules::deleteLockRule($rule_id)) {
PageLayout::postSuccess(_('Die Regel wurde erfolgreich gelöscht!'));
} else {
PageLayout::postError(_('Es können nur nicht verwendete Regeln gelöscht werden!'));
}
$this->redirect('admin/specification');
}
}
|