2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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.
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
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 \*=====================================================================*/
22 require_once('./global.php');
23 require_once('./includes/functions_datastore.php');
25 if (!can_perform('canadmingroups'))
30 // ###################################################################
31 // define permissions as groups
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')
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')
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')
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')
71 // ###################################################################
73 if (empty($_REQUEST['do']))
75 $_REQUEST['do'] = 'modify';
78 // ###################################################################
80 if ($_REQUEST['do'] == 'kill')
82 if ($bugsys->in
['usergroupid'] < 7)
84 $admin->error($lang->string('You can\'t delete a default usergroup.'));
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']));
93 $admin->redirect('usergroup.php?do=modify');
96 // ###################################################################
98 if ($_REQUEST['do'] == 'delete')
100 if ($bugsys->in
['usergroupid'] < 7)
102 $admin->error($lang->string('You can\'t delete a default usergroup.'));
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&usergroupid=' . intval($bugsys->in
['usergroupid']));
108 // ###################################################################
110 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
112 $add = (($_REQUEST['do'] == 'add') ? true : false);
113 $edit = (($_REQUEST['do'] == 'edit') ? true : false);
115 $admin->page_start(($add ? $lang->string('New Usergroup') : $lang->string('Edit Usergroup')));
117 $admin->form_start('usergroup.php', ($add ? 'insert' : 'update'));
121 $usergroup = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "usergroup WHERE usergroupid = " . intval($bugsys->in
['usergroupid']));
122 if (!is_array($usergroup))
124 $admin->error($lang->getlex('error_invalid_id'));
127 $admin->form_hidden_field('usergroupid', $usergroup['usergroupid']);
131 $usergroup['permissions'] = 319;
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']));
142 $admin->table_start();
144 $admin->table_head($lang->string('Permission Settings'), 2, 'usergroups');
146 foreach ($permissions AS $group => $settings)
148 $admin->row_span($group, 'thead', 'center');
149 foreach ($settings AS $setting => $name)
151 $admin->row_yesno($name, "perm[$setting]", ($usergroup['permissions'] & $_PERMISSION["$setting"]));
157 // custom field permissions
158 $admin->table_start();
159 $admin->table_head($lang->string('Custom Field Permissions'), 2, 'usergroups');
163 $perms = $db->query("SELECT fieldid
, mask FROM
" . TABLE_PREFIX . "bugfieldpermission WHERE usergroupid
= $usergroup[usergroupid
]");
164 while ($perm = $db->fetch_array($perms))
166 $permissions["$perm[fieldid
]"] = $perm['mask'];
170 $fields = $db->query("SELECT fieldid
, name FROM
" . TABLE_PREFIX . "bugfield ORDER BY fieldid
");
171 while ($field = $db->fetch_array($fields))
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
]]");
183 $admin->table_start();
184 $admin->row_submit();
192 // ###################################################################
194 if ($_POST['do'] == 'insert')
196 foreach ($_POST['perm'] AS $permtitle => $binaryswitch)
198 $permissionvalue += $_PERMISSION["$permtitle"] * $binaryswitch;
202 INSERT INTO " . TABLE_PREFIX
. "usergroup
203 (title, displaytitle, permissions)
205 ('" . $bugsys->in
['title'] . "', '" . $bugsys->in
['displaytitle'] . "',
210 $ugroupid = $db->insert_id();
214 foreach ($_POST['custom'] AS $fieldid => $mask)
216 $values[] = "$ugroupid, " . intval($fieldid) . ", " . intval($mask);
219 if (is_array($values))
222 INSERT INTO " . TABLE_PREFIX
. "bugfieldpermission
223 (usergroupid, fieldid, mask)
225 (" . implode("\n\t\t\t", $values) . "
230 $admin->redirect('usergroup.php?do=modify');
233 // ###################################################################
235 if ($_POST['do'] == 'update')
237 foreach ($_POST['perm'] AS $permtitle => $binaryswitch)
239 $permissionvalue +
= $_PERMISSION["$permtitle"] * $binaryswitch;
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'])
253 $ugroupid = intval($bugsys->in['usergroupid']);
254 foreach ($_POST['custom'] AS $fieldid => $mask)
256 $values[] = "$ugroupid, " . intval($fieldid) . ", " . intval($mask);
259 if (is_array($values))
262 REPLACE INTO
" . TABLE_PREFIX . "bugfieldpermission
263 (usergroupid
, fieldid
, mask
)
265 (" . implode("),\n\t\t\t(", $values) . ")"
270 $admin->redirect('usergroup.php?do=modify');
273 // ###################################################################
275 if ($_REQUEST['do'] == 'modify')
277 $admin->page_start($lang->string('Usergroup Manager'));
279 $admin->form_start('usergroup.php', 'null');
280 $admin->table_start();
281 $admin->table_head($lang->string('Usergroup Manager'), 3, 'usergroups');
283 $groups = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "usergroup ORDER BY usergroupid ASC
");
284 while ($group = $db->fetch_array($groups))
286 $usergroups["$group[usergroupid
]"] = $group;
288 $db->free_result($groups);
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
"
297 while ($group = $db->fetch_array($groups))
299 $usergroups["$group[usergroupid
]"]['total'] = $group['total'];
302 $admin->table_column_head(array($lang->string('Usergroup'), $lang->string('Number of Users'), $lang->string('Action')));
303 foreach ($usergroups AS $group)
305 $admin->row_multi_item(array("<a href
=\"usergroup
.php
?do=edit
&
;usergroupid
=$group[usergroupid
]\">$group[title
]</a
>" => 'l', ((!$group['total']) ? '-' : $group['total']) => 'c', "<a href
=\"usergroup
.php
?do=edit
&
;usergroupid
=$group[usergroupid
]\">[" . $lang->string('Edit') . "]</a
>" . (($group['usergroupid'] > 6) ? "<a href
=\"usergroup
.php
?do=delete
&
;usergroupid
=$group[usergroupid
]\">[" . $lang->string('Delete') . "]</a
>" : '') => 'c'));
308 $admin->row_span('<a href="usergroup
.php
?do=add
">[' . $lang->string('Add New Usergroup') . ']</a>', 'tfoot', 'center', 3);
315 /*=====================================================================*\
316 || ###################################################################
319 || ###################################################################
320 \*=====================================================================*/