]> src.bluestatic.org Git - bugdar.git/blob - admin/usergroup.php
r836: Implementing user API in userctrl.php
[bugdar.git] / admin / usergroup.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 require_once('./global.php');
23 require_once('./includes/functions_datastore.php');
24
25 if (!can_perform('canadmingroups'))
26 {
27 admin_login();
28 }
29
30 // ###################################################################
31 // define permissions as groups
32
33 $permissions = array(
34 $lang->string('General Permissions') => array(
35 'canviewbugs' => $lang->string('Can View Bugs'),
36 'canviewhidden' => $lang->string('Can View Hidden Bugs and Comments'),
37 'cansearch' => $lang->string('Can Search Bugs'),
38 'cansubscribe' => $lang->string('Can Subscribe to Bugs'),
39 'canbeassignedto' => $lang->string('Can Be Assigned Bugs')
40 ),
41
42 $lang->string('Posting/Submitting Permissions') => array(
43 'canvote' => $lang->string('Can Vote on Polls'),
44 'cansubmitbugs' => $lang->string('Can Submit Bugs'),
45 'canpostcomments' => $lang->string('Can Post Comments'),
46 'cangetattach' => $lang->string('Can View Attachments'),
47 'canputattach' => $lang->string('Can Upload/Edit Own Attachments'),
48 'caneditattach' => $lang->string('Can Manage All Attachments')
49 ),
50
51 $lang->string('Moderation/Managment Permissions') => array(
52 'caneditown' => $lang->string('Can Edit Own Bugs'),
53 'caneditother' => $lang->string('Can Edit Others\' Bugs'),
54 'caneditownreply' => $lang->string('Can Edit Own Comments'),
55 'caneditotherreply' => $lang->string('Can Edit Others\' Comments'),
56 'canassign' => $lang->string('Can Assign Bugs'),
57 'canchangestatus' => $lang->string('Can Change Status')
58 ),
59
60 $lang->string('Administrator Permissions') => array(
61 'canadminpanel' => $lang->string('Can Access Control Panel'),
62 'canadminbugs' => $lang->string('Can Administer Bug Reports'),
63 'canadminfields' => $lang->string('Can Administer Additional Bug Fields'),
64 'canadminversions' => $lang->string('Can Administer Products / Components / Versions'),
65 'canadminusers' => $lang->string('Can Administer Users'),
66 'canadmingroups' => $lang->string('Can Administer Usergroups'),
67 'canadmintools' => $lang->string('Can Administer Settings / Maintenance Tools')
68 )
69 );
70
71 // ###################################################################
72
73 if (empty($_REQUEST['do']))
74 {
75 $_REQUEST['do'] = 'modify';
76 }
77
78 // ###################################################################
79
80 if ($_REQUEST['do'] == 'kill')
81 {
82 if ($bugsys->in['usergroupid'] < 7)
83 {
84 $admin->error($lang->string('You can\'t delete a default usergroup.'));
85 }
86
87 $db->query("DELETE FROM " . TABLE_PREFIX . "usergroup WHERE usergroupid = " . intval($bugsys->in['usergroupid']));
88 $db->query("UPDATE " . TABLE_PREFIX . "user SET usergroupid = 2 WHERE usergroupid = " . intval($bugsys->in['usergroupid']));
89
90 build_usergroups();
91 build_assignedto();
92
93 $admin->redirect('usergroup.php?do=modify');
94 }
95
96 // ###################################################################
97
98 if ($_REQUEST['do'] == 'delete')
99 {
100 if ($bugsys->in['usergroupid'] < 7)
101 {
102 $admin->error($lang->string('You can\'t delete a default usergroup.'));
103 }
104
105 $admin->page_confirm($lang->string('Are you sure you want to delete this usergroup? All users in this group will be set back to the default registered usergroup (id: 2).'), 'usergroup.php?do=kill&amp;usergroupid=' . intval($bugsys->in['usergroupid']));
106 }
107
108 // ###################################################################
109
110 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
111 {
112 $add = (($_REQUEST['do'] == 'add') ? true : false);
113 $edit = (($_REQUEST['do'] == 'edit') ? true : false);
114
115 $admin->page_start(($add ? $lang->string('New Usergroup') : $lang->string('Edit Usergroup')));
116
117 $admin->form_start('usergroup.php', ($add ? 'insert' : 'update'));
118
119 if ($edit)
120 {
121 $usergroup = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "usergroup WHERE usergroupid = " . intval($bugsys->in['usergroupid']));
122 if (!is_array($usergroup))
123 {
124 $admin->error($lang->getlex('error_invalid_id'));
125 }
126
127 $admin->form_hidden_field('usergroupid', $usergroup['usergroupid']);
128 }
129 else
130 {
131 $usergroup['permissions'] = 319;
132 }
133
134 // Details
135 $admin->table_start();
136 $admin->table_head($lang->string('Usergroup Details'), 2, 'usergroups');
137 $admin->row_input($lang->string('Usergroup Title'), 'title', $bugsys->sanitize($usergroup['title']));
138 $admin->row_input($lang->string('Display Title<div><dfn>This is the title that others will be able to see when comments are posted.</dfn></div>'), 'displaytitle', $bugsys->sanitize($usergroup['displaytitle']));
139 $admin->table_end();
140
141 // Permission
142 $admin->table_start();
143
144 $admin->table_head($lang->string('Permission Settings'), 2, 'usergroups');
145
146 foreach ($permissions AS $group => $settings)
147 {
148 $admin->row_span($group, 'thead', 'center');
149 foreach ($settings AS $setting => $name)
150 {
151 $admin->row_yesno($name, "perm[$setting]", ($usergroup['permissions'] & $_PERMISSION["$setting"]));
152 }
153 }
154
155 $admin->table_end();
156
157 // custom field permissions
158 $admin->table_start();
159 $admin->table_head($lang->string('Custom Field Permissions'), 2, 'usergroups');
160
161 if ($edit)
162 {
163 $perms = $db->query("SELECT fieldid, mask FROM " . TABLE_PREFIX . "bugfieldpermission WHERE usergroupid = $usergroup[usergroupid]");
164 while ($perm = $db->fetch_array($perms))
165 {
166 $permissions["$perm[fieldid]"] = $perm['mask'];
167 }
168 }
169
170 $fields = $db->query("SELECT fieldid, name FROM " . TABLE_PREFIX . "bugfield ORDER BY fieldid");
171 while ($field = $db->fetch_array($fields))
172 {
173 unset($listitem);
174 $admin->list_item($lang->string('No Permission'), 0, $permissions["$field[fieldid]"] == 0);
175 $admin->list_item($lang->string('Can View Field'), 1, $permissions["$field[fieldid]"] == 1);
176 $admin->list_item($lang->string('Can View, Edit Field'), 2, $permissions["$field[fieldid]"] == 2);
177 $admin->row_list($field['name'], "custom[$field[fieldid]]");
178 }
179
180 $admin->table_end();
181
182 // Submit
183 $admin->table_start();
184 $admin->row_submit();
185 $admin->table_end();
186
187 $admin->form_end();
188
189 $admin->page_end();
190 }
191
192 // ###################################################################
193
194 if ($_POST['do'] == 'insert')
195 {
196 foreach ($_POST['perm'] AS $permtitle => $binaryswitch)
197 {
198 $permissionvalue += $_PERMISSION["$permtitle"] * $binaryswitch;
199 }
200
201 $db->query("
202 INSERT INTO " . TABLE_PREFIX . "usergroup
203 (title, displaytitle, permissions)
204 VALUES
205 ('" . $bugsys->in['title'] . "', '" . $bugsys->in['displaytitle'] . "',
206 $permissionvalue
207 )"
208 );
209
210 $ugroupid = $db->insert_id();
211
212 build_usergroups();
213
214 foreach ($_POST['custom'] AS $fieldid => $mask)
215 {
216 $values[] = "$ugroupid, " . intval($fieldid) . ", " . intval($mask);
217 }
218
219 if (is_array($values))
220 {
221 $db->query("
222 INSERT INTO " . TABLE_PREFIX . "bugfieldpermission
223 (usergroupid, fieldid, mask)
224 VALUES
225 (" . implode("\n\t\t\t", $values) . "
226 )"
227 );
228 }
229
230 $admin->redirect('usergroup.php?do=modify');
231 }
232
233 // ###################################################################
234
235 if ($_POST['do'] == 'update')
236 {
237 foreach ($_POST['perm'] AS $permtitle => $binaryswitch)
238 {
239 $permissionvalue += $_PERMISSION["$permtitle"] * $binaryswitch;
240 }
241
242 $db->query("
243 UPDATE " . TABLE_PREFIX . "usergroup
244 SET title = '" . $bugsys->in['title'] . "',
245 displaytitle = '" . $bugsys->in['displaytitle'] . "',
246 permissions = $permissionvalue
247 WHERE usergroupid = " . intval($bugsys->in['usergroupid'])
248 );
249
250 build_usergroups();
251 build_assignedto();
252
253 $ugroupid = intval($bugsys->in['usergroupid']);
254 foreach ($_POST['custom'] AS $fieldid => $mask)
255 {
256 $values[] = "$ugroupid, " . intval($fieldid) . ", " . intval($mask);
257 }
258
259 if (is_array($values))
260 {
261 $db->query("
262 REPLACE INTO " . TABLE_PREFIX . "bugfieldpermission
263 (usergroupid, fieldid, mask)
264 VALUES
265 (" . implode("),\n\t\t\t(", $values) . ")"
266 );
267 }
268
269
270 $admin->redirect('usergroup.php?do=modify');
271 }
272
273 // ###################################################################
274
275 if ($_REQUEST['do'] == 'modify')
276 {
277 $admin->page_start($lang->string('Usergroup Manager'));
278
279 $admin->form_start('usergroup.php', 'null');
280 $admin->table_start();
281 $admin->table_head($lang->string('Usergroup Manager'), 3, 'usergroups');
282
283 $groups = $db->query("SELECT * FROM " . TABLE_PREFIX . "usergroup ORDER BY usergroupid ASC");
284 while ($group = $db->fetch_array($groups))
285 {
286 $usergroups["$group[usergroupid]"] = $group;
287 }
288 $db->free_result($groups);
289
290 $groups = $db->query("
291 SELECT COUNT(user.userid) AS total, user.usergroupid
292 FROM " . TABLE_PREFIX . "user AS user
293 LEFT JOIN " . TABLE_PREFIX . "usergroup AS usergroup USING (usergroupid)
294 GROUP BY usergroup.usergroupid
295 ORDER BY usergroup.usergroupid"
296 );
297 while ($group = $db->fetch_array($groups))
298 {
299 $usergroups["$group[usergroupid]"]['total'] = $group['total'];
300 }
301
302 $admin->table_column_head(array($lang->string('Usergroup'), $lang->string('Number of Users'), $lang->string('Action')));
303 foreach ($usergroups AS $group)
304 {
305 $admin->row_multi_item(array("<a href=\"usergroup.php?do=edit&amp;usergroupid=$group[usergroupid]\">$group[title]</a>" => 'l', ((!$group['total']) ? '-' : $group['total']) => 'c', "<a href=\"usergroup.php?do=edit&amp;usergroupid=$group[usergroupid]\">[" . $lang->string('Edit') . "]</a>" . (($group['usergroupid'] > 6) ? "<a href=\"usergroup.php?do=delete&amp;usergroupid=$group[usergroupid]\">[" . $lang->string('Delete') . "]</a>" : '') => 'c'));
306 }
307
308 $admin->row_span('<a href="usergroup.php?do=add">[' . $lang->string('Add New Usergroup') . ']</a>', 'tfoot', 'center', 3);
309 $admin->table_end();
310 $admin->form_end();
311
312 $admin->page_end();
313 }
314
315 /*=====================================================================*\
316 || ###################################################################
317 || # $HeadURL$
318 || # $Id$
319 || ###################################################################
320 \*=====================================================================*/
321 ?>