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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
<?php
/**
* start.php - start page controller
*
*
* 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 André Klaßen <klassen@elan-ev.de>
* @author Nadine Werner <nadine.werner@uni-osnabrueck.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @since 3.1
*/
class StartController extends AuthenticatedController
{
/**
* Callback function being called before an action is executed.
*/
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
Navigation::activateItem('/start');
PageLayout::setTabNavigation(NULL); // disable display of tabs
PageLayout::setHelpKeyword('Basis.Startseite'); // set keyword for new help
PageLayout::setTitle(_('Startseite'));
}
/**
* Entry point of the controller that displays the start page of Stud.IP
*
* @param string $action
* @param string $widgetId
*
* @return void
*/
public function index_action($action = false, $widgetId = null)
{
$plugin_manager = PluginManager::getInstance();
$widgets = WidgetUser::getWidgets($GLOBALS['user']->id);
$this->columns = [[], []];
foreach ($widgets as $col => $list) {
foreach ($list as $plugin_id) {
$plugin = $plugin_manager->getPluginById($plugin_id);
if ($plugin) {
$this->columns[$col][] = $plugin;
}
}
}
$this->widget_layout = $this->get_template_factory()->open('start/_widget.php');
$sidebar = Sidebar::get();
$nav = $sidebar->addWidget(new NavigationWidget());
$nav->setTitle(_('Sprungmarken'));
$nav->setId('navigation-layer-3');
foreach (array_merge(...$this->columns) as $widget) {
$nav->addLink(
$widget->getPluginName(),
$this->url_for("start#widget-" . $widget->getPluginId())
);
}
// Show action to add widget only if not all widgets have already been added.
$actions = $sidebar->addWidget(new ActionsWidget());
if ($this->getAvailableWidgets($GLOBALS['user']->id)) {
$actions->addLink(
_('Widgets hinzufügen'),
$this->url_for('start/add'),
Icon::create('add')
)->asDialog();
}
$actions->addLink(
_('Standard wiederherstellen'),
$this->url_for('start/reset'),
Icon::create('accept')
);
// Root may set initial positions
if ($GLOBALS['perm']->have_perm('root')) {
$settings = $sidebar->addWidget(new ActionsWidget());
$settings->setTitle(_('Einstellungen'));
$settings->addElement(new WidgetElement(_('Standard-Startseite bearbeiten:')));
foreach ($GLOBALS['perm']->permissions as $permission => $useless) {
$settings->addLink(
ucfirst($permission),
$this->url_for("start/edit_defaults/{$permission}"),
Icon::create('link-intern')
)->asDialog();
}
}
if ($GLOBALS['perm']->get_perm() == 'user') {
PageLayout::postInfo(_('Sie haben noch nicht auf Ihre Bestätigungsmail geantwortet.'), [
_('Bitte holen Sie dies nach, um Stud.IP Funktionen wie das Belegen von Veranstaltungen nutzen zu können.'),
sprintf(_('Bei Problemen wenden Sie sich an: %s'), '<a href="mailto:'.$GLOBALS['UNI_CONTACT'].'">'.$GLOBALS['UNI_CONTACT'].'</a>')
]);
$details = Studip\LinkButton::create(
_('Bestätigungsmail erneut verschicken'),
$this->url_for('start/resend_validation_mail')
);
if (!StudipAuthAbstract::CheckField('auth_user_md5.Email', $GLOBALS['user']->auth_plugin) && !LockRules::check($GLOBALS['user']->id, 'email')) {
$details .= ' ';
$details .= Studip\LinkButton::create(
_('E-Mail-Adresse ändern'),
$this->url_for('start/edit_mail_address'),
[
'data-dialog' => 'size=auto',
'title' => _('E-Mail-Adresse')
]
);
}
PageLayout::postInfo(
sprintf(_('Haben Sie die Bestätigungsmail an Ihre Adresse "%s" nicht erhalten?'), htmlReady($GLOBALS['user']->Email)),
[$details]
);
}
}
/**
* Fetches all widgets that are not already in use.
*
* @param string $user_id the user to check
*
* @return array available widgets
*/
private function getAvailableWidgets($user_id)
{
$all_widgets = PluginEngine::getPlugins(PortalPlugin::class);
$user_widgets = WidgetUser::getWidgets($user_id);
$used_widgets = array_merge(...$user_widgets);
$available = [];
foreach ($all_widgets as $widget) {
if (!in_array($widget->getPluginId(), $used_widgets)) {
$available[] = $widget;
}
}
return $available;
}
/**
* This action adds one or more new widgets to the start page
*
* @return void
*/
public function add_action()
{
PageLayout::setTitle(_('Widgets hinzufügen'));
if (Request::isPost()) {
$ticket = Request::get('studip_ticket');
$widgets = Request::intArray('widget_id');
$position = Request::int('position');
$post_url = '';
if (check_ticket($ticket)) {
foreach ($widgets as $widget) {
WidgetUser::addWidget($GLOBALS['user']->id, $widget);
if (!$post_url) {
$post_url = '#widget-' . $widget;
}
}
}
$this->redirect('start' . $post_url);
}
$this->widgets = $this->getAvailableWidgets($GLOBALS['user']->id);
}
/**
* Edit the default startpage configuration for users by permissions
*
* @param string $permission
*
* @throws InvalidArgumentException
*/
public function edit_defaults_action($permission)
{
if (!in_array($permission, array_keys($GLOBALS['perm']->permissions))) {
throw new InvalidArgumentException('There is no such permission!');
}
PageLayout::setTitle(sprintf(_('Standard-Startseite für "%s" bearbeiten'), ucfirst($permission)));
$this->widgets = PluginEngine::getPlugins(PortalPlugin::class);
$this->initial_widgets = WidgetDefault::getWidgets($permission);
$this->permission = $permission;
}
/**
* Store the edited default startpage configuration for users by permissions
*
* @param string $permission
*
* @throws InvalidArgumentException
*/
public function update_defaults_action($permission)
{
$GLOBALS['perm']->check('root');
if (!in_array($permission, array_keys($GLOBALS['perm']->permissions))) {
throw new InvalidArgumentException('There is no such permission!');
}
$widgets = [Request::getArray('left'), Request::getArray('right')];
WidgetDefault::deleteBySQL('perm = ?', [$permission]);
foreach ($widgets as $col => $list) {
foreach ($list as $plugin_id => $position) {
WidgetDefault::create([
'pluginid' => $plugin_id,
'col' => $col,
'position' => $position,
'perm' => $permission
]);
}
}
$this->render_nothing();
}
/**
* This actions removes a new widget from the start page
*
* @param string $widgetId
* @param string $approveDelete
* @param string $studipticket
*/
public function delete_action($id)
{
$plugin_manager = PluginManager::getInstance();
$plugin_info = $plugin_manager->getPluginById($id);
$name = $plugin_info->getPluginName();
if (Request::isPost()) {
if (Request::submitted('yes')) {
if (WidgetUser::removeWidget($GLOBALS['user']->id, $id)) {
$message = sprintf(
_('Widget "%s" wurde entfernt.'),
htmlReady($name)
);
PageLayout::postSuccess($message);
} else {
$message = sprintf(
_('Widget "%s" konnte nicht entfernt werden.'),
htmlReady($name)
);
PageLayout::postError($message);
}
}
} else {
PageLayout::postQuestion(
sprintf(
_('Sind Sie sicher, dass Sie das Widget "%s" von der Startseite entfernen möchten?'),
htmlReady($name)
),
$this->url_for("start/delete/{$id}")
);
}
$this->redirect('start');
}
/**
* Resets widget to initial default state.
*/
public function reset_action()
{
WidgetUser::deleteBySQL('range_id = ?', [$GLOBALS['user']->id]);
$message = _('Die Widgets wurden auf die Standardkonfiguration zurückgesetzt.');
PageLayout::postSuccess($message);
$this->redirect('start');
}
/**
* Action to store the widget placements
*/
public function storeNewOrder_action(): void
{
if (!Request::isPost()) {
throw new MethodNotAllowedException();
}
$lanes = Request::getArray('lanes');
WidgetUser::setInitialWidgets($GLOBALS['user']->id);
foreach ($lanes as $column => $list) {
foreach ($list as $position => $plugin_id) {
$widget = WidgetUser::findOneBySQL('pluginid = ? AND range_id = ?', [$plugin_id, $GLOBALS['user']->id]);
$widget->position = $position;
$widget->col = $column;
$widget->store();
}
}
$this->render_nothing();
}
/**
* Resend the validation mail for the current user
*
* @return void
*/
public function resend_validation_mail_action()
{
if ($GLOBALS['perm']->get_perm() === 'user') {
Seminar_Register_Auth::sendValidationMail($GLOBALS['user']);
PageLayout::postSuccess(
_('Die Bestätigungsmail wurde erneut verschickt.')
);
}
$this->redirect('start');
}
/**
* Show form to change the mail-address for the validation mail
*
* @return void
*/
public function edit_mail_address_action()
{
// only allow editing of mail-address here if user has not yet validated
if ($GLOBALS['perm']->get_perm() !== 'user') {
$this->redirect('start');
return;
}
$this->restricted = StudipAuthAbstract::CheckField('auth_user_md5.Email', $GLOBALS['user']->auth_plugin)
&& LockRules::check($GLOBALS['user']->id, 'email');
$this->email = $GLOBALS['user']->Email;
}
/**
* Change the mail-address and resend validation mail
*
* @return void
*/
public function change_mail_address_action()
{
$email1 = Request::get('email1');
$email2 = Request::get('email2');
if ($GLOBALS['perm']->get_perm() == 'user') {
if($email1 != $email2) {
PageLayout::postError(_('Die Wiederholung der E-Mail-Adresse stimmt nicht mit Ihrer Eingabe überein.'));
$this->redirect('start/edit_mail_address');
return;
}
$user = new User($GLOBALS['user']->id);
$user->Email = $email1;
$user->store();
$GLOBALS['user']->Email = $user->Email;
Seminar_Register_Auth::sendValidationMail($user);
PageLayout::postMessage(MessageBox::success(
_('Ihre Mailadresse wurde geändert und die Bestätigungsmail erneut verschickt.')
));
}
$this->relocate('start');
}
}
|