diff options
| author | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:07:19 +0200 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:19:12 +0200 |
| commit | a3da1483a9e689846179159355badfec8073dbec (patch) | |
| tree | 770dcca6bdf5f6f2a11b0e7fcbbeda6919a3fc52 /app/controllers/admin/lockrules.php | |
current code from svn, revision 62608
Diffstat (limited to 'app/controllers/admin/lockrules.php')
| -rw-r--r-- | app/controllers/admin/lockrules.php | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/app/controllers/admin/lockrules.php b/app/controllers/admin/lockrules.php new file mode 100644 index 0000000..56879fe --- /dev/null +++ b/app/controllers/admin/lockrules.php @@ -0,0 +1,189 @@ +<?php +# Lifter010: TODO +/** + * lockrules.php - lock rules admin 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é Noack <noack@data-quest.de> + * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2 + * @category Stud.IP + * @package admin + */ + +class Admin_LockrulesController extends AuthenticatedController +{ + /** + * common tasks for all actions + */ + public function before_filter (&$action, &$args) + { + parent::before_filter($action, $args); + + $GLOBALS['perm']->check(Config::get()->LOCK_RULE_ADMIN_PERM ? Config::get()->LOCK_RULE_ADMIN_PERM : 'admin'); + + PageLayout::setTitle(_('Verwaltung der Sperrebenen')); + Navigation::activateItem('/admin/locations/lock_rules'); + + URLHelper::bindLinkParam('lock_rule_type', $this->lock_rule_type); + + if (!$this->lock_rule_type || !$GLOBALS['perm']->have_perm('root')) { + $this->lock_rule_type = 'sem'; + } + if ($this->lock_rule_type === 'sem') { + if($GLOBALS['perm']->have_perm('root')) { + $this->lock_rule_permissions = ['tutor','dozent','admin','root']; + } else { + $this->lock_rule_permissions = ['tutor','dozent']; + } + } elseif ($this->lock_rule_type === 'inst') { + $this->lock_rule_permissions = ['admin','root']; + } elseif ($this->lock_rule_type === 'user') { + $this->lock_rule_permissions = ['tutor','dozent','admin','root']; + } + $this->sidebar = Sidebar::Get(); + $this->rule_type_names = [ + 'sem' => _('Veranstaltung'), + 'inst' => _('Einrichtung'), + 'user' => _('Person') + ]; + } + + /** + * Display the list of lock rules + */ + public function index_action() + { + $actions = new ActionsWidget(); + $actions->addLink( + _('Neue Sperrebene anlegen'), + $this->url_for('admin/lockrules/new'), + Icon::create('add') + ); + $this->sidebar->addWidget($actions); + if ($GLOBALS['perm']->have_perm('root')) { + $list = new SelectWidget( + _('Bereichsauswahl'), + $this->url_for('admin/lockrules'), + 'lock_rule_type' + ); + $types = [ + 'sem' => _('Veranstaltung'), + 'inst' => _('Einrichtung'), + 'user' => _('Nutzer') + ]; + foreach ($types as $type => $desc) { + $list->addElement( + new SelectElement( + $type, + $desc, + Request::get('lock_rule_type') === $type + ), + 'lock_rule_type-' . $type + ); + } + $this->sidebar->addWidget($list); + } + + if ($this->lock_rule_type === 'sem') { + $this->lock_rules = LockRules::getAdministrableSeminarRules($GLOBALS['user']->id); + } else { + $this->lock_rules = LockRule::findAllByType($this->lock_rule_type); + } + } + + /** + * edit one lock rule + */ + public function edit_action($lock_rule_id) + { + $this->lock_rule = LockRule::find($lock_rule_id); + $this->lock_config = LockRules::getLockRuleConfig($this->lock_rule_type); + + if (Request::submitted('ok')) { + $ok = $this->handle_form_data(); + if ($ok === false) { + PageLayout::postError(_('Die Änderungen der Sperrebene konnten nicht gespeichert werden.'), $this->msg['error']); + } else if ($ok) { + PageLayout::postSuccess(_('Die Änderungen wurden gespeichert.')); + } + } + + $info = new ListWidget(); + $info->setTitle(_('Informationen')); + $info->addElement( + new WidgetElement(sprintf( + _('Diese Sperrebene wird von %s Objekten benutzt.'), + $this->lock_rule->getUsage()) + ) + ); + $this->sidebar->addWidget($info); + $actions = new ActionsWidget(); + $actions->addLink( + _('Diese Ebene löschen'), + $this->url_for('admin/lockrules/delete/' . $this->lock_rule->getid()), + Icon::create('trash') + ); + $actions->addLink( + _('Bearbeiten abbrechen'), + $this->url_for('admin/lockrules'), + Icon::create('decline') + ); + $this->sidebar->addWidget($actions); + + } + + public function new_action() + { + $this->lock_rule = new LockRule(); + $this->lock_config = LockRules::getLockRuleConfig($this->lock_rule_type); + + if (Request::submitted('ok')) { + $this->lock_rule->user_id = $GLOBALS['user']->id; + $this->lock_rule->object_type = $this->lock_rule_type; + if (!$this->handle_form_data()) { + PageLayout::postError(_('Die neue Sperrebene konnte nicht gespeichert werden.'), $this->msg['error']); + } else { + PageLayout::postSuccess(_('Die neue Sperrebene wurde gespeichert')); + $this->redirect($this->url_for('admin/lockrules/edit/' . $this->lock_rule->getid())); + } + } + $actions = new ActionsWidget(); + $actions->addLink( + _('Bearbeiten abbrechen'), + $this->url_for('admin/lockrules'), + Icon::create('decline') + ); + $this->sidebar->addWidget($actions); + } + + public function delete_action($lock_rule_id) + { + $this->lock_rule = LockRule::find($lock_rule_id); + if (!(!$this->lock_rule->isNew() && ($GLOBALS['perm']->have_perm('root') || $this->lock_rule->user_id === $GLOBALS['user']->id))) { + throw new Trails_Exception(403); + } + CSRFProtection::verifyUnsafeRequest(); + if ($this->lock_rule->delete()) { + PageLayout::postSuccess(_('Die Sperrebene wurde gelöscht.')); + } + $this->redirect($this->url_for('admin/lockrules')); + } + + public function handle_form_data() + { + CSRFProtection::verifyUnsafeRequest(); + $this->lock_rule->name = Request::get('lockdata_name'); + $this->lock_rule->description = Request::get('lockdata_description'); + $this->lock_rule->permission = Request::option('lockdata_permission'); + $this->lock_rule->attributes = Request::intArray('lockdata_attributes'); + if (!$this->lock_rule->name) { + $this->msg['error'][] = _('Bitte geben Sie einen Namen für die Sperrebene an!'); + return false; + } + return $this->lock_rule->store(); + } +}
\ No newline at end of file |
