]> src.bluestatic.org Git - bugdar.git/blob - admin/usergroup.php
r496: Removing #submitrow from report.css to global.css
[bugdar.git] / admin / usergroup.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 require_once('./global.php');
14 require_once('./includes/functions_datastore.php');
15
16 if (!can_perform('canadmingroups'))
17 {
18 admin_login();
19 }
20
21 // ###################################################################
22 // define permissions as groups
23
24 $permissions = array(
25 $lang->string('General Permissions') => array(
26 'canviewbugs' => $lang->string('Can View Bugs'),
27 'canviewhidden' => $lang->string('Can View Hidden Bugs and Comments'),
28 'cansearch' => $lang->string('Can Search Bugs'),
29 'cansubscribe' => $lang->string('Can Subscribe to Bugs'),
30 'canbeassignedto' => $lang->string('Can Be Assigned Bugs')
31 ),
32
33 $lang->string('Posting/Submitting Permissions') => array(
34 'canvote' => $lang->string('Can Vote on Polls'),
35 'cansubmitbugs' => $lang->string('Can Submit Bugs'),
36 'canpostcomments' => $lang->string('Can Post Comments'),
37 'cangetattach' => $lang->string('Can View Attachments'),
38 'canputattach' => $lang->string('Can Upload/Edit Own Attachments'),
39 'caneditattach' => $lang->string('Can Manage All Attachments')
40 ),
41
42 $lang->string('Moderation/Managment Permissions') => array(
43 'caneditown' => $lang->string('Can Edit Own Bugs'),
44 'caneditothers' => $lang->string('Can Edit Others\' Bugs'),
45 'caneditinfo' => $lang->string('Can Edit Bug Information'),
46 'canassign' => $lang->string('Can Assign Bugs'),
47 'canchangestatus' => $lang->string('Can Change Status')
48 ),
49
50 $lang->string('Administrator Permissions') => array(
51 'canadminpanel' => $lang->string('Can Access Control Panel'),
52 'canadminbugs' => $lang->string('Can Administer Bug Reports'),
53 'canadminfields' => $lang->string('Can Administer Additional Bug Fields'),
54 'canadminversions' => $lang->string('Can Administer Products / Components / Versions'),
55 'canadminusers' => $lang->string('Can Administer Users'),
56 'canadmingroups' => $lang->string('Can Administer Usergroups'),
57 'canadmintools' => $lang->string('Can Administer Settings / Maintenance Tools')
58 )
59 );
60
61 // ###################################################################
62
63 if (empty($_REQUEST['do']))
64 {
65 $_REQUEST['do'] = 'modify';
66 }
67
68 // ###################################################################
69
70 if ($_REQUEST['do'] == 'kill')
71 {
72 if ($bugsys->in['usergroupid'] < 7)
73 {
74 $admin->error($lang->string('You can\'t delete a default usergroup.'));
75 }
76
77 $db->query("DELETE FROM " . TABLE_PREFIX . "usergroup WHERE usergroupid = " . intval($bugsys->in['usergroupid']));
78 $db->query("UPDATE " . TABLE_PREFIX . "user SET usergroupid = 2 WHERE usergroupid = " . intval($bugsys->in['usergroupid']));
79
80 build_usergroups();
81 build_assignedto();
82
83 $admin->redirect('usergroup.php?do=modify');
84 }
85
86 // ###################################################################
87
88 if ($_REQUEST['do'] == 'delete')
89 {
90 if ($bugsys->in['usergroupid'] < 7)
91 {
92 $admin->error($lang->string('You can\'t delete a default usergroup.'));
93 }
94
95 $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']));
96 }
97
98 // ###################################################################
99
100 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
101 {
102 $add = (($_REQUEST['do'] == 'add') ? true : false);
103 $edit = (($_REQUEST['do'] == 'edit') ? true : false);
104
105 $admin->page_start(($add ? $lang->string('New Usergroup') : $lang->string('Edit Usergroup')));
106
107 $admin->form_start('usergroup.php', ($add ? 'insert' : 'update'));
108
109 if ($edit)
110 {
111 $usergroup = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "usergroup WHERE usergroupid = " . intval($bugsys->in['usergroupid']));
112 if (!is_array($usergroup))
113 {
114 $admin->error($lang->getlex('error_invalid_id'));
115 }
116
117 $admin->form_hidden_field('usergroupid', $usergroup['usergroupid']);
118 }
119 else
120 {
121 $usergroup['permissions'] = 319;
122 }
123
124 // Details
125 $admin->table_start();
126 $admin->table_head($lang->string('Usergroup Details'));
127 $admin->row_input($lang->string('Usergroup Title'), 'title', $bugsys->sanitize($usergroup['title']));
128 $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']));
129 $admin->row_input($lang->string('Opening Tag Markup<div><dfn>Place all open HTML tags here that will be wrapped around the username.</dfn></div>'), 'opentag', $bugsys->sanitize($usergroup['opentag']));
130 $admin->row_input($lang->string('Closing Tag Markup<div><dfn>Place all closed HTML tags that will close any open HTML tags entered above.</dfn></div>'), 'closetag', $bugsys->sanitize($usergroup['closetag']));
131 $admin->table_end();
132
133 // Permission
134 $admin->table_start();
135
136 $admin->table_head($lang->string('Permission Settings'));
137
138 foreach ($permissions AS $group => $settings)
139 {
140 $admin->row_span($group, 'thead', 'center');
141 foreach ($settings AS $setting => $name)
142 {
143 $admin->row_yesno($name, "perm[$setting]", ($usergroup['permissions'] & $_PERMISSION["$setting"]));
144 }
145 }
146
147 $admin->table_end();
148
149 // custom field permissions
150 $admin->table_start();
151 $admin->table_head($lang->string('Custom Field Permissions'));
152
153 if ($edit)
154 {
155 $perms = $db->query("SELECT fieldid, mask FROM " . TABLE_PREFIX . "bugfieldpermission WHERE usergroupid = $usergroup[usergroupid]");
156 while ($perm = $db->fetch_array($perms))
157 {
158 $permissions["$perm[fieldid]"] = $perm['mask'];
159 }
160 }
161
162 $fields = $db->query("SELECT fieldid, name FROM " . TABLE_PREFIX . "bugfield ORDER BY fieldid");
163 while ($field = $db->fetch_array($fields))
164 {
165 unset($listitem);
166 $admin->list_item($lang->string('No Permission'), 0, $permissions["$field[fieldid]"] == 0);
167 $admin->list_item($lang->string('Can View Field'), 1, $permissions["$field[fieldid]"] == 1);
168 $admin->list_item($lang->string('Can View, Edit Field'), 2, $permissions["$field[fieldid]"] == 2);
169 $admin->row_list($field['name'], "custom[$field[fieldid]]");
170 }
171
172 $admin->table_end();
173
174 // Submit
175 $admin->table_start();
176 $admin->row_submit();
177 $admin->table_end();
178
179 $admin->form_end();
180
181 $admin->page_end();
182 }
183
184 // ###################################################################
185
186 if ($_POST['do'] == 'insert')
187 {
188 foreach ($_POST['perm'] AS $permtitle => $binaryswitch)
189 {
190 $permissionvalue += $_PERMISSION["$permtitle"] * $binaryswitch;
191 }
192
193 $db->query("
194 INSERT INTO " . TABLE_PREFIX . "usergroup
195 (title, displaytitle, opentag, closetag, permissions)
196 VALUES
197 ('" . $bugsys->in['title'] . "', '" . $bugsys->in['displaytitle'] . "',
198 '" . $bugsys->in['opentag'] . "', '" . $bugsys->in['closetag'] . "',
199 $permissionvalue
200 )"
201 );
202
203 $ugroupid = $db->insert_id();
204
205 build_usergroups();
206
207 foreach ($_POST['custom'] AS $fieldid => $mask)
208 {
209 $values[] = "$ugroupid, " . intval($fieldid) . ", " . intval($mask);
210 }
211
212 $db->query("
213 INSERT INTO " . TABLE_PREFIX . "bugfieldpermission
214 (usergroupid, fieldid, mask)
215 VALUES
216 (" . implode("\n\t\t\t", $values) . "
217 )"
218 );
219
220 $admin->redirect('usergroup.php?do=modify');
221 }
222
223 // ###################################################################
224
225 if ($_POST['do'] == 'update')
226 {
227 foreach ($_POST['perm'] AS $permtitle => $binaryswitch)
228 {
229 $permissionvalue += $_PERMISSION["$permtitle"] * $binaryswitch;
230 }
231
232 $db->query("
233 UPDATE " . TABLE_PREFIX . "usergroup
234 SET title = '" . $bugsys->in['title'] . "',
235 displaytitle = '" . $bugsys->in['displaytitle'] . "',
236 opentag = '" . $bugsys->unsanitize($bugsys->in['opentag']) . "',
237 closetag = '" . $bugsys->unsanitize($bugsys->in['closetag']) . "',
238 permissions = $permissionvalue
239 WHERE usergroupid = " . intval($bugsys->in['usergroupid'])
240 );
241
242 build_usergroups();
243 build_assignedto();
244
245 $ugroupid = intval($bugsys->in['usergroupid']);
246 foreach ($_POST['custom'] AS $fieldid => $mask)
247 {
248 $values[] = "$ugroupid, " . intval($fieldid) . ", " . intval($mask);
249 }
250
251 $db->query("
252 REPLACE INTO " . TABLE_PREFIX . "bugfieldpermission
253 (usergroupid, fieldid, mask)
254 VALUES
255 (" . implode("),\n\t\t\t(", $values) . ")"
256 );
257
258
259 $admin->redirect('usergroup.php?do=modify');
260 }
261
262 // ###################################################################
263
264 if ($_REQUEST['do'] == 'modify')
265 {
266 $admin->page_start($lang->string('Usergroup Manager'));
267
268 $admin->form_start('usergroup.php', 'null');
269 $admin->table_start();
270 $admin->table_head($lang->string('Usergroup Manager'), 3);
271
272 $groups = $db->query("SELECT * FROM " . TABLE_PREFIX . "usergroup ORDER BY usergroupid ASC");
273 while ($group = $db->fetch_array($groups))
274 {
275 $usergroups["$group[usergroupid]"] = $group;
276 }
277 $db->free_result($groups);
278
279 $groups = $db->query("
280 SELECT COUNT(user.userid) AS total, user.usergroupid
281 FROM " . TABLE_PREFIX . "user AS user
282 LEFT JOIN " . TABLE_PREFIX . "usergroup AS usergroup USING (usergroupid)
283 GROUP BY usergroup.usergroupid
284 ORDER BY usergroup.usergroupid"
285 );
286 while ($group = $db->fetch_array($groups))
287 {
288 $usergroups["$group[usergroupid]"]['total'] = $group['total'];
289 }
290
291 $admin->table_column_head(array($lang->string('Usergroup'), $lang->string('Number of Users'), $lang->string('Action')));
292 foreach ($usergroups AS $group)
293 {
294 $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'));
295 }
296
297 $admin->row_span('<a href="usergroup.php?do=add">[' . $lang->string('Add New Usergroup') . ']</a>', 'tfoot', 'center', 3);
298 $admin->table_end();
299 $admin->form_end();
300
301 $admin->page_end();
302 }
303
304 /*=====================================================================*\
305 || ###################################################################
306 || # $HeadURL$
307 || # $Id$
308 || ###################################################################
309 \*=====================================================================*/
310 ?>