aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/LockRules.php
blob: b27bfdf853cc14f17c46ef57f2d5cc6007565366 (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
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
<?php
/**
 * LockRules.php
 *
 *
 * 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      Mark Sievers <msievers@uos.de>
 * @author      André Noack <noack@data-quest.de>
 * @copyright   2011 Stud.IP Core-Group
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
*/

/**
* LockRules.php
*
* This class contains only static methods dealing with lock rules
*
*/

class LockRules {

    private static $lockmap = [];
    private static $lockrules = [];

    /**
     * get lockrule object for given id
     * from static object pool
     *
     * @param string $lock_id id of lockrule
     * @return LockRule
     */
    public static function get($lock_id)
    {
        if(!array_key_exists($lock_id, self::$lockrules)) {
            self::$lockrules[$lock_id] = LockRule::find($lock_id);
        }
        return self::$lockrules[$lock_id];
    }

    /**
     * returns a list of lockrules that can be administrated
     * with the given user id
     *
     * @param string $user_id id of user
     * @return array of LockRule objects
     */
    public static function getAdministrableSeminarRules($user_id)
    {
        return array_filter(LockRule::findAllByType('sem'), function ($rule) use ($user_id) {
            return $GLOBALS['perm']->get_perm($user_id) === 'root'
                || (
                    $rule->user_id === $user_id
                    && !in_array($rule->permission, ['root', 'admin'])
                );
        });
    }

    /**
     * returns a list of lockrules that can be applied to a course
     * with the given user id
     *
     * @param string $user_id id of user
     * @return array of LockRule objects
     */
    public static function getAvailableSeminarRules($user_id)
    {
        return array_filter(LockRule::findAllByType('sem'), function ($rule) use ($user_id) {
            return $GLOBALS['perm']->get_perm($user_id) === 'root'
                || !in_array($rule->permission, ['root', 'admin']);
        });
    }

    /**
     * returns the lock rule object for the given id, else null
     *
     * @param string $object_id id of course, institute or user
     * @param bool $renew if true, reloads the rule from database
     * @param string|null $object_type : The type of object you want to check: "user", "sem" or "inst"
     * @return LockRule
     */
    public static function getObjectRule($object_id, $renew = false, $object_type = null)
    {
        if (!array_key_exists($object_id, self::$lockmap) || $renew) {
            self::$lockmap[$object_id] = null;
            if ($object_type === null) {
                $object_type = get_object_type($object_id, words('sem inst user'));
            }
            if ($object_type) {
                $methodmap = ['sem'  => 'Seminar',
                                   'inst' => 'Institute',
                                   'fak'  => 'Institute',
                                   'user' => 'User'];
                $lr = call_user_func(['LockRule', 'FindBy' . $methodmap[$object_type]], $object_id);
                if ($lr) {
                    self::$lockmap[$object_id] = $lr->getId();
                    self::$lockrules[$lr->getId()] = $lr;
                }
            }
        }
        return self::$lockrules[self::$lockmap[$object_id]] ?? null;
    }

    /**
     * checks if an attribute of an entity is locked for the current user
     * see self::getLockRuleConfig() for the list of attributes
     *
     * @param string $object_id id of course, institute or user
     * @param string $attribute the name of an lockable attribute
     * @param string|null $object_type : The type of object you want to check: "user", "sem" or "inst"
     * @return boolean true if attribute is locked for the current user
     */
    public static function Check($object_id, $attribute, $object_type = null)
    {
        $lr = self::getObjectRule($object_id, false, $object_type);
        if ($lr) {
            return $lr['attributes'][mb_strtolower($attribute)] == 1 && self::CheckLockRulePermission($object_id);
        } else {
            return false;
        }
    }

    /**
     * checks if given entity is locked for the current user
     *
     * @param string $object_id id of course, institute or user
     * @return boolean true if given entity is locked fpr the current user
     */
    public static function CheckLockRulePermission($object_id)
    {
        $perms = ['autor','tutor','dozent','admin','root','god'];
        $lr = self::getObjectRule($object_id);

        if ($lr) {
            $pk = array_search($lr->permission, $perms);
            $check_perm = $perms[$pk + 1];
            if ($lr->object_type == 'sem') {
                return ($lr->permission == 'root' || !$GLOBALS['perm']->have_studip_perm($check_perm, $object_id));
    }
            if ($lr->object_type == 'inst') {
                return ($lr->permission == 'root' || !$GLOBALS['perm']->have_perm('root'));
            }
            if ($lr->object_type == 'user') {
                return ($lr->permission == 'root' || !$GLOBALS['perm']->have_perm($check_perm));
            }
        }
        return false;
    }

    /**
     * returns an array containing all lockable attributes for
     * given entity type
     *
     * @param string $type entity type, one of [sem,inst,user]
     * @return array
     */
    public static function getLockRuleConfig($type)
    {
        $groups['basic'] = _("Grunddaten");
        $groups['personnel'] = _("Personen und Einordnung");
        $groups['misc'] = _("Weitere Daten");
        $groups['room_time'] = _("Zeiten/Räume");
        $groups['access'] = _("Zugangsberechtigungen");
        $groups['actions'] = _("spezielle Aktionen");

        $attributes['sem']['veranstaltungsnummer'] = ['name' => _("Veranstaltungsnummer"), 'group' => 'basic'];
        $attributes['sem']['seminar_inst'] = ['name' => _("beteiligte Einrichtungen"), 'group' => 'basic'];
        $attributes['sem']['name'] = ['name' => _("Name"), 'group' => 'basic'];
        $attributes['sem']['untertitel'] = ['name' => _("Untertitel"), 'group' => 'basic'];
        $attributes['sem']['status'] = ['name' => _("Status"), 'group' => 'basic'];
        $attributes['sem']['beschreibung'] = ['name' => _("Beschreibung"), 'group' => 'basic'];
        $attributes['sem']['ort'] = ['name' => _("Ort"), 'group' => 'basic'];
        $attributes['sem']['art'] = ['name' => _("Veranstaltungstyp"), 'group' => 'basic'];
        $attributes['sem']['ects'] = ['name' => _("ECTS-Punkte"), 'group' => 'basic'];
        $attributes['sem']['admission_turnout'] = ['name' => _("Teilnehmendenzahl"), 'group' => 'basic'];
        $attributes['sem']['dozent'] = ['name' => _("Lehrende"), 'group' => 'personnel'];
        $attributes['sem']['tutor'] = ['name' => _("Tutor/-innen"), 'group' => 'personnel'];
        $attributes['sem']['institut_id'] = ['name' => _("Heimateinrichtung"), 'group' => 'personnel'];
        $attributes['sem']['sem_tree'] = ['name' => _("Studienbereiche"), 'group' => 'personnel'];
        $attributes['sem']['mvv_lvgruppe'] = ['name' => _("Modulzuordnung"), 'group' => 'personnel'];
        $attributes['sem']['participants'] = ['name' => _("Personen hinzufügen/löschen"), 'group' => 'personnel'];
        $attributes['sem']['groups'] = ['name' => _("Gruppen hinzufügen/löschen"), 'group' => 'personnel'];
        $attributes['sem']['sonstiges'] = ['name' => _("Sonstiges"), 'group' => 'misc'];
        $attributes['sem']['teilnehmer'] = ['name' => _("Beschreibung des Teilnehmendenkreises"), 'group' => 'misc'];
        $attributes['sem']['voraussetzungen'] = ['name' => _("Teilnahmevoraussetzungen"), 'group' => 'misc'];
        $attributes['sem']['lernorga'] = ['name' => _("Lernorganisation"), 'group' => 'misc'];
        $attributes['sem']['leistungsnachweis'] = ['name' => _("Leistungsnachweis"), 'group' => 'misc'];
        $attributes['sem']['room_time'] = ['name' => _("Zeiten/Räume"), 'group' => 'room_time'];
        $attributes['sem']['cancelled_dates'] = ['name' => _("Termine ausfallen lassen"), 'group' => 'room_time'];
        $attributes['sem']['edit_dates_in_schedule'] = ['name' => _("Erweiterte Termindaten im Ablaufplan ändern"), 'group' => 'room_time'];
        $attributes['sem']['admission_endtime'] = ['name' => _("Zeit/Datum der Platzverteilung/Kontingentierung"), 'group' => 'access'];
        $attributes['sem']['admission_disable_waitlist'] = ['name' => _("Aktivieren/Deaktivieren der Warteliste"), 'group' => 'access'];
        $attributes['sem']['admission_binding'] = ['name' => _("Verbindlichkeit der Anmeldung"), 'group' => 'access'];
        $attributes['sem']['admission_type'] = ['name' => _("Typ des Anmeldeverfahrens"), 'group' => 'access'];
        $attributes['sem']['admission_prelim'] = ['name' => _("zugelassenene Studiengänge"), 'group' => 'access'];
        $attributes['sem']['admission_prelim_txt'] = ['name' => _("Vorläufigkeit der Anmeldungen"), 'group' => 'access'];
        $attributes['sem']['admission_disable_waitlist'] = ['name' => _("Hinweistext bei Anmeldungen"), 'group' => 'access'];
        $attributes['sem']['admission_starttime'] = ['name' => _("Startzeitpunkt der Anmeldemöglichkeit"), 'group' => 'access'];
        $attributes['sem']['admission_endtime_sem'] = ['name' => _("Endzeitpunkt der Anmeldemöglichkeit"), 'group' => 'access'];
        $attributes['sem']['lesezugriff'] = ['name' => _("Lesezugriff"), 'group' => 'access'];
        $attributes['sem']['schreibzugriff'] = ['name' => _("Schreibzugriff"), 'group' => 'access'];
        $attributes['sem']['passwort'] = ['name' => _("Passwort"), 'group' => 'access'];
        $attributes['sem']['user_domain'] = ['name' => _("Nutzerdomänen zuordnen"), 'group' => 'access'];
        $attributes['sem']['seminar_copy'] = ['name' => _("Veranstaltung kopieren"), 'group' => 'actions'];
        $attributes['sem']['seminar_archive'] = ['name' => _("Veranstaltung archivieren"), 'group' => 'actions'];
        $attributes['sem']['seminar_visibility'] = ['name' => _("Veranstaltung sichtbar/unsichtbar schalten"), 'group' => 'actions'];

        $attributes['inst']['name'] = ['name' => _("Name"), 'group' => 'basic'];
        $attributes['inst']['fakultaets_id'] = ['name' => _("Fakultät"), 'group' => 'basic'];
        $attributes['inst']['type'] = ['name' => _("Bezeichnung"), 'group' => 'basic'];
        $attributes['inst']['strasse'] = ['name' => _("Straße"), 'group' => 'basic'];
        $attributes['inst']['plz'] = ['name' => _("Ort"), 'group' => 'basic'];
        $attributes['inst']['telefon'] = ['name' => _("Telefonnummer"), 'group' => 'basic'];
        $attributes['inst']['fax'] = ['name' => _("Faxnummer"), 'group' => 'basic'];
        $attributes['inst']['email'] = ['name' => _("E-Mail-Adresse"), 'group' => 'basic'];
        $attributes['inst']['url'] = ['name' => _("Homepage"), 'group' => 'basic'];
        $attributes['inst']['participants'] = ['name' => _("Mitarbeiter hinzufügen/löschen"), 'group' => 'personnel'];
        $attributes['inst']['groups'] = ['name' => _("Gruppen hinzufügen/löschen"), 'group' => 'personnel'];

        $attributes['user']['name'] = ['name' => _("Vor- und Nachname"), 'group' => 'basic'];
        $attributes['user']['username'] = ['name' => _("Nutzername"), 'group' => 'basic'];
        $attributes['user']['password'] = ['name' => _("Passwort"), 'group' => 'basic'];
        $attributes['user']['email'] = ['name' => _("E-Mail"), 'group' => 'basic'];
        $attributes['user']['title'] = ['name' => _("Titel"), 'group' => 'basic'];
        $attributes['user']['gender'] = ['name' => _("Geschlecht"), 'group' => 'basic'];
        $attributes['user']['privatnr'] = ['name' => _("Telefon (privat)"), 'group' => 'basic'];
        $attributes['user']['privatcell'] = ['name' => _("Mobiltelefon"), 'group' => 'basic'];
        $attributes['user']['privadr'] = ['name' => _("Adresse (privat)"), 'group' => 'basic'];
        $attributes['user']['hobby'] = ['name' => _("Hobbys"), 'group' => 'basic'];
        $attributes['user']['lebenslauf'] = ['name' => _("Lebenslauf"), 'group' => 'basic'];
        $attributes['user']['home'] = ['name' => _("Homepage"), 'group' => 'basic'];
        $attributes['user']['publi'] = ['name' => _("Schwerpunkte"), 'group' => 'misc'];
        $attributes['user']['schwerp'] = ['name' => _("Publikationen"), 'group' => 'misc'];
        $attributes['user']['institute_data'] = ['name' => _("Einrichtungsdaten"), 'group' => 'misc'];

        foreach(DataField::getDataFields($type) as $df) {
            $attributes[$type][$df->datafield_id] = ['name' => $df->name, 'group' => 'misc'];
        }

        return ['groups' => $groups,'attributes' => $attributes[$type]];
    }

}