aboutsummaryrefslogtreecommitdiff
path: root/app/views/resources/_common/_permission_table.php
blob: 614ce577b5ed2a24d7993901c9b0fb79cb6895b7 (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
<?php
/**
 * Template variables:
 * - table_id: The ID of the table. This is required for the JS code which adds
 *   new users to the table to work.
 * - table caption: An optional table caption.
 * - permissions: An array of ResourcePermission objects.
 * - single_user: The User object in case the table is used in single
 *   user mode where the permissions of one specific user are displayed.
 * - custom_columns: An associative multi-dimensional array to display
 *   additional columns.
 *       Structure:
 *       The first layer has the column names as indexes.
 *       The second layer contains an associative array with the cells
 *       for the column. That array has the permission object IDs
 *       (see permissions above) as indexes.
 * - custom_actions: A multi-dimensional array for additional actions in the
 *   actions column. The array has the following structure:
 *       The first layer contains associative arrays where each array represents
 *       one action.
 *       The second layer consists of associative arrays with the following
 *       structure:
 *       [
 *           'icon' => The Icon object for the action.
 *           'title' => The descriptive title for the action.
 *           'link_classes' => Classes which shall be added to the link element
 *                             of the action.
 *           'url' => An optional URL that shall be attached to the action's
 *                         link element via the href attribute.
 *           'js_action' => An optional JavaScript action that shall be attached
 *                          to the link element using the onclick attribute.
 *       ]
 * - show_delete_action: If the delete action shall be shown (true) or not (false).
 *   Defaults to true, if not set.
 */

//Make sure the delete action is shown when the $show_delete_action
//template variable isn't set:
if (!isset($show_delete_action)) {
    $show_delete_action = true;
}
?>
<table class="default sortable-table resource-permissions-table"
       data-sortlist="[[1, 0]]"
       <?= $table_id ? 'id="' . htmlReady($table_id) . '"' : '' ?>>
    <? if (!empty($table_caption)): ?>
        <caption><?= htmlReady($table_caption) ?></caption>
    <? endif ?>
    <colgroup>
        <col class="checkbox">
        <col>
        <col>
        <? if (!empty($custom_columns)): ?>
            <? foreach ($custom_columns as $column_name): ?>
                <col>
            <? endforeach ?>
        <? endif ?>
    </colgroup>
    <thead>
        <tr>
            <th>
                <input type="checkbox"
                       data-proxyfor="input[name='selected_permissions[]']"
                       data-activates="table.resource-permissions-table button.bulk-action">
            </th>
            <th data-sort="text"><?= _('Name') ?></th>
            <th data-sort="htmldata"><?= _('Rechtestufe') ?></th>
            <? if (!empty($custom_columns)): ?>
                <? foreach (array_keys($custom_columns) as $column_name): ?>
                    <th><?= htmlReady($column_name) ?></th>
                <? endforeach ?>
            <? endif ?>
        </tr>
    </thead>
    <? if ($show_delete_action): ?>
    <tfoot>
        <tr>
            <td colspan="3">
                <?
                $button_attrs = [
                    'class'                    => 'bulk-action',
                    'data-activates-condition' => 'table.resource-permissions-table :checkbox:checked'
                ];
                ?>

                    <?= \Studip\Button::create(_('Löschen'), 'bulk_delete', $button_attrs) ?>
            </td>
        </tr>
    </tfoot>
    <? endif ?>
    <tbody>
        <? if (count($permissions)): ?>
            <? foreach ($permissions as $permission): ?>
                <?
                $permission_sort_key = 10;
                switch ($permission->perms) {
                    case 'autor':
                    {
                        $permission_sort_key = 20;
                        break;
                    }
                    case 'tutor':
                    {
                        $permission_sort_key = 30;
                        break;
                    }
                    case 'admin':
                    {
                        $permission_sort_key = 40;
                        break;
                    }
                }
                ?>
                <tr data-user_id="<?= htmlReady($permission->user_id) ?>">
                    <td>
                        <input type="checkbox" name="selected_permissions[]"
                               value="<?= htmlReady($permission->user_id) ?>">
                    </td>
                    <td>
                        <? if ($permission->user instanceof User): ?>
                            <?= htmlReady($permission->user->getFullName('full_rev_username')) ?>
                            (<?= htmlReady($permission->user->perms) ?>)
                        <? else: ?>
                            <?= _('unbekannt') ?>
                        <? endif ?>
                        <input type="hidden" name="permissions[user_id][]"
                               value="<?= htmlReady($permission->user_id) ?>">
                    </td>
                    <td data-sort-value="<?= htmlReady($permission_sort_key) ?>">
                        <select name="permissions[level][]">
                            <option value="user"
                                    <?=
                                    $permission->perms == 'user'
                                        ? 'selected="selected"'
                                        : '' ?>>
                                user
                            </option>
                            <option value="autor"
                                    <?=
                                    $permission->perms == 'autor'
                                        ? 'selected="selected"'
                                        : '' ?>>
                                autor
                            </option>
                            <option value="tutor"
                                    <?=
                                    $permission->perms == 'tutor'
                                        ? 'selected="selected"'
                                        : '' ?>>
                                tutor
                            </option>
                            <option value="admin"
                                    <?=
                                    $permission->perms == 'admin'
                                        ? 'selected="selected"'
                                        : '' ?>>
                                admin
                            </option>
                        </select>
                    </td>
                    <? if (!empty($custom_columns)): ?>
                        <? foreach ($custom_columns as $column_content): ?>
                            <td>
                                <?= htmlReady($column_content[$permission->id]) ?>
                            </td>
                        <? endforeach ?>
                    <? endif ?>
                </tr>
            <? endforeach ?>
        <? endif ?>
        <tr id="resource-empty-permission-list-message"
            <?= count($permissions) ? 'class="invisible"' : '' ?>>
            <td colspan="3" style="text-align: center">
                <? if ($single_user instanceof User): ?>
                    <?= $custom_empty_list_message ?: sprintf(
                        _('Es sind keine besonderen Rechte für %s vorhanden.'),
                        htmlReady($single_user->getFullName()
                        )) ?>
                <? else: ?>
                    <?= $custom_empty_list_message ?: _('Es sind keine besonderen Rechte vorhanden.') ?>
                <? endif ?>
            </td>
        </tr>
        <tr class="invisible resource-permission-list-template">
            <td>
                <input type="checkbox" name="selected_permissions[]"
                       disabled="disabled">
            </td>
            <td>
                <input type="hidden" name="permissions[user_id][]">
            </td>
            <td>
                <select name="permissions[level][]">
                    <option value="user">
                        user
                    </option>
                    <option value="autor" selected="selected">
                        autor
                    </option>
                    <option value="tutor">
                        tutor
                    </option>
                    <option value="admin">
                        admin
                    </option>
                </select>
            </td>
            <? if (!empty($custom_columns)): ?>
                <? foreach (array_keys($custom_columns) as $column_name): ?>
                    <td><?= htmlReady($custom_columns[$column_name]) ?></td>
                <? endforeach ?>
            <? endif ?>
        </tr>
    </tbody>
</table>