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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
<?php
/**
* autu_insert.php - controller class for the auto insert seminars
*
* 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 2.1
*/
class Admin_AutoinsertController extends AuthenticatedController
{
/**
* Common tasks for all actions.
*/
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
// user must have root permission
$GLOBALS['perm']->check('root');
Navigation::activateItem('/admin/user/auto_insert');
PageLayout::setTitle(_('Automatisiertes Eintragen verwalten'));
PageLayout::setHelpKeyword('Admins.AutomatisiertesEintragen');
}
/**
* Maintenance view for the auto insert parameters
*
*/
public function index_action()
{
// search seminars
if (Request::submitted('suchen')) {
if (Request::get('sem_search')) {
$this->sem_search = Request::get('sem_search');
$this->sem_select = Request::option('sem_select');
$search = new SeminarSearch();
$this->seminar_search = $search->getResults
(Request::get('sem_search'),
['search_sem_sem' => Request::option('sem_select')]
);
if (count($this->seminar_search) == 0) {
PageLayout::postInfo(_('Es wurden keine Veranstaltungen gefunden.'));
}
} else {
PageLayout::postError(_('Bitte geben Sie einen Suchparameter ein.'));
}
}
$seminare = AutoInsert::getAllSeminars();
$this->auto_sems = $seminare;
$domains = [];
$domains[] = [
'id' => 'keine',
'name' => _('Ohne Domäne'),
];
foreach (UserDomain::getUserDomains() as $domain) {
$domains[] = $domain;
}
$this->userdomains = $domains;
$links = new ActionsWidget();
$links->addLink(
_('Benutzergruppen manuell eintragen'),
$this->manualURL(),
Icon::create('visibility-visible')
);
Sidebar::Get()->addWidget($links);
}
/**
* Create a new seminar for auto insert
*/
public function new_action()
{
if (Request::submitted('anlegen')) {
$sem_id = Request::option('sem_id');
$domains = Request::getArray('rechte');
if (empty($domains)) {
PageLayout::postError(_('Mindestens ein Status sollte selektiert werden!'));
} else {
foreach ($domains as $id => $rechte) {
if ($id === 'keine')
$id = '';
if (!AutoInsert::checkSeminar($sem_id, $id)) {
AutoInsert::saveSeminar($sem_id, $rechte, $id);
PageLayout::postSuccess(_('Die Zuordnung wurde erfolgreich gespeichert!'));
} else {
PageLayout::postError(_('Das Seminar wird bereits zu diesem Zweck verwendet!'));
}
}
}
}
$this->redirect('admin/autoinsert');
}
/**
* Edit a rule
*
* @param string $seminar_id
*/
public function edit_action($seminar_id)
{
$domain = Request::get('domain_id');
$status = Request::get('status');
$remove = Request::get('remove');
if ($domain === 'keine')
$domain = '';
AutoInsert::updateSeminar($seminar_id, $domain, $status, $remove);
PageLayout::postSuccess(_('Die Statusgruppenanpassung wurde erfolgreich übernommen!'));
$this->redirect('admin/autoinsert');
}
/**
* Removes a seminar from the auto-insert list, with modal dialog
*
* @param string $seminar_id
*/
public function delete_action($seminar_id)
{
if (Request::int('delete') === 1) {
if (AutoInsert::deleteSeminar($seminar_id)) {
PageLayout::postSuccess(_('Die Zuordnung der Veranstaltung wurde gelöscht!'));
}
} elseif (!Request::get('back')) {
$this->flash['delete'] = $seminar_id;
}
$this->redirect('admin/autoinsert');
}
/**
* Maintenance view for the manual insert parameters
*
*/
public function manual_action()
{
PageLayout::setTitle(_('Manuelles Eintragen von Nutzergruppen in Veranstaltungen'));
if (Request::submitted('submit')) {
$filters = array_filter(Request::getArray('filter'));
if (!Request::get('sem_id') || Request::get('sem_id') == 'false') {
PageLayout::postError(_('Ungültiger Aufruf'));
} elseif (!count($filters)) {
PageLayout::postError(_('Keine Filterkriterien gewählt'));
} else {
$seminar = Seminar::GetInstance(Request::option('sem_id'));
$group = select_group($seminar->getSemesterStartTime());
$userlookup = new UserLookup();
foreach ($filters as $type => $values) {
$userlookup->setFilter($type, $values);
}
$user_ids = $userlookup->execute();
$real_users = 0;
foreach ($user_ids as $user_id) {
if (!AutoInsert::checkAutoInsertUser(Request::option('sem_id'), $user_id)) {
$seminar->addMember($user_id);
$real_users += AutoInsert::saveAutoInsertUser(Request::option('sem_id'), $user_id);
}
}
//messagebox
$text = sprintf(
_('Es wurden %u von %u möglichen Personen in die Veranstaltung %s eingetragen.'),
$real_users,
count($user_ids),
sprintf(
'<a href="%s">%s</a>',
URLHelper::getLink('dispatch.php/course/details/', ['cid' => $seminar->getId()]),
htmlReady($seminar->getName()
)
)
);
$details = [_('Etwaige Abweichungen der Personenzahlen enstehen durch bereits vorhandene bzw. wieder ausgetragene Personen.')];
if ($real_users > 0) {
PageLayout::postSuccess($text, $details);
} else {
PageLayout::postInfo($text, $details);
}
$this->redirect('admin/autoinsert/manual');
}
}
$this->sem_id = Request::option('sem_id');
$this->sem_search = Request::get('sem_search');
$this->sem_select = Request::option('sem_select');
$this->filtertype = Request::getArray('filtertype');
$this->filter = Request::getArray('filter');
if (count(Request::getArray('remove_filter'))) {
$this->filtertype = array_diff($this->filtertype, array_keys(Request::getArray('remove_filter')));
} elseif (Request::submitted('add_filter')) {
array_push($this->filtertype, Request::get('add_filtertype'));
}
if (Request::get('sem_search') and Request::get('sem_select')) {
if (Request::get('sem_search')) {
$search = new SeminarSearch('number-name');
$this->seminar_search = $search->getResults(Request::get('sem_search'), ['search_sem_sem' => $this->sem_select]);
if (count($this->seminar_search) == 0) {
PageLayout::postInfo(_('Es wurden keine Veranstaltungen gefunden.'));
}
} else {
PageLayout::postError(_('Im Suchfeld wurde nichts eingetragen!'));
}
}
$this->values = [];
foreach ($this->filtertype as $type) {
$this->values[$type] = UserLookup::getValuesForType($type);
}
$this->available_filtertypes = [
'fach' => _('Studienfach'),
'abschluss' => _('Studienabschluss'),
'fachsemester' => _('Studienfachsemester'),
'institut' => _('Einrichtung'),
'status' => _('Statusgruppe'),
'domain' => _('Domäne')
];
$links = new ActionsWidget();
$links->addLink(_('Übersicht'), $this->indexURL(), Icon::create('edit'));
Sidebar::Get()->addWidget($links);
}
/**
* Count how many user a insert
*/
public function manual_count_action()
{
$filters = array_filter(Request::getArray('filter'));
if (empty($filters)) {
$data = ['error' => _('Keine Filterkriterien gewählt')];
} else {
$userlookup = new UserLookup();
foreach ($filters as $type => $values) {
$userlookup->setFilter($type, $values);
}
$data = ['users' => count($userlookup->execute())];
}
$this->set_content_type('application/json;charset=utf-8');
return $this->render_text(json_encode($data));
}
}
|