aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/admin/additional.php
blob: eb98db8dc7d0eaf658174261e6aaa83389ed1700 (plain)
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
<?php
/**
 * additonal.php - controller class for the additonal data
 *
 * Admin of a Seminar can chose his required aux data and decide if it is
 * forced from the user
 *
 * 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      Florian Bieringer <florian.bieringer@uni-passau.de>
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 * @package     admin
 * @since       3.0
 */
class Admin_AdditionalController extends AuthenticatedController
{
    public function before_filter(&$action, &$args)
    {
        parent::before_filter($action, $args);

        // Load the course
        $this->course = Course::findCurrent();

        // Check permissions to be on this site
        if (!$GLOBALS['perm']->have_studip_perm("tutor", $this->course->id)) {
            throw new AccessDeniedException(_("Sie haben keine Berechtigung diese " .
                    "Veranstaltung zu verändern."));
        }
    }

    /**
     * Index displays and updates
     */
    public function index_action()
    {
        /*
         * Updaterequest
         */
        if (Request::submitted('save')) {
            if ($rule = Request::get('aux_data')) {
                $this->course->aux_lock_rule = $rule;
                $this->course->aux_lock_rule_forced = Request::get('forced') ? : 0;
            } else {
                // If no rule is set we cant force it
                $this->course->aux_lock_rule = null;
                $this->course->aux_lock_rule_forced = 0;
            }
            // purge data
            if (Request::submitted('delete')) {
                DatafieldEntryModel::deleteBySQL('sec_rage_id = ?', [$this->course->id]);
            }

            if ($this->course->store()) {
                if (!is_null($this->course->aux_lock_rule)) {
                    PageLayout::postSuccess(_('Zusatzangaben wurden erfolgreich zugeordnet'));
                } else {
                    PageLayout::postSuccess(_('Zuweisung der Zusatzangaben wurden aufgehoben'));
                }
            }
        }

        // Fetch data
        $this->count = DatafieldEntryModel::countBySql('sec_range_id = ?', [$this->course->id]);
        $this->list = AuxLockRule::findBySQL('1=1');
    }
}