2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
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/api_usergroup.php');
25 require_once('./includes/class_api_error.php');
26 APIError(array(new API_Error_Handler($admin), 'admin_error'));
28 NavLinks
::usersPages();
29 $navigator->set_focus('tab', 'users', null);
31 if (!can_perform('canadmingroups'))
36 // ###################################################################
37 // define permissions as groups
40 _('General Permissions') => array(
41 'canviewbugs' => _('Can View Bugs'),
42 'canviewhidden' => _('Can View Hidden Bugs and Comments'),
43 'canviewownhidden' => _('Can View Own Hidden Bugs'),
44 'cansearch' => _('Can Search Bugs'),
45 'cansubscribe' => _('Can Subscribe to Bugs'),
46 'canbeassignedto' => _('Can Be Assigned Bugs')
49 _('Posting/Submitting Permissions') => array(
50 'canvote' => _('Can Vote on Polls'),
51 'cansubmitbugs' => _('Can Submit Bugs'),
52 'canpostcomments' => _('Can Post Comments'),
53 'cangetattach' => _('Can View Attachments'),
54 'canputattach' => _('Can Upload/Edit Own Attachments'),
55 'caneditattach' => _('Can Manage All Attachments')
58 _('Moderation/Managment Permissions') => array(
59 'caneditown' => _('Can Edit Own Bugs'),
60 'caneditother' => _('Can Edit Others\' Bugs'),
61 'caneditownreply' => _('Can Edit Own Comments'),
62 'caneditotherreply' => _('Can Edit Others\' Comments'),
63 'canassign' => _('Can Assign Bugs'),
64 'canchangestatus' => _('Can Change Status'),
65 'candeletedata' => _('Can Delete Bugs and Comments')
68 _('Administrator Permissions') => array(
69 'canadminpanel' => _('Can Access Control Panel'),
70 'canadminbugs' => _('Can Administer Bug Reports'),
71 'canadminfields' => _('Can Administer Additional Bug Fields'),
72 'canadminversions' => _('Can Administer Products / Components / Versions'),
73 'canadminusers' => _('Can Administer Users'),
74 'canadmingroups' => _('Can Administer Usergroups'),
75 'canadmintools' => _('Can Administer Settings / Maintenance Tools')
79 // ###################################################################
81 if (empty($_REQUEST['do']))
83 $_REQUEST['do'] = 'modify';
86 // ###################################################################
88 if ($_REQUEST['do'] == 'kill')
90 $usergroup = new UsergroupAPI($bugsys);
91 $usergroup->set('usergroupid', $bugsys->in
['usergroupid']);
92 $usergroup->set_condition();
95 $admin->redirect('usergroup.php?do=modify');
98 // ###################################################################
100 if ($_REQUEST['do'] == 'delete')
102 if ($bugsys->in
['usergroupid'] < 7)
104 $admin->error(_('You can\'t delete a default usergroup.'));
107 $admin->page_confirm(_('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', 'kill', array('usergroupid' => $bugsys->in
['usergroupid']));
110 // ###################################################################
112 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
114 $add = (($_REQUEST['do'] == 'add') ? true : false);
115 $edit = (($_REQUEST['do'] == 'edit') ? true : false);
119 NavLinks
::usergroupsEdit($bugsys->in
['usergroupid']);
120 $navigator->set_focus('link', 'users-pages-usergroups', 'users-pages');
124 NavLinks
::usergroupsAdd();
125 $navigator->set_focus('link', 'usergroups-add', 'usergroups');
128 $admin->page_start(($add ? _('New Usergroup') : _('Edit Usergroup')));
130 $admin->form_start('usergroup.php', ($add ? 'insert' : 'update'));
134 $usergroup = new UsergroupAPI($bugsys);
135 $usergroup->set('usergroupid', $bugsys->in
['usergroupid']);
136 $usergroup->set_condition();
139 $admin->form_hidden_field('usergroupid', $usergroup->objdata
['usergroupid']);
143 $usergroup['permissions'] = 319;
147 $admin->table_start();
148 $admin->table_head(_('Usergroup Details'));
149 $admin->row_input(_('Usergroup Title'), 'title', $bugsys->sanitize($usergroup->objdata
['title']));
150 $admin->row_input(_('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->objdata
['displaytitle']));
154 $admin->table_start();
156 $admin->table_head(_('Permission Settings'));
158 foreach ($permissions AS $group => $settings)
160 $admin->row_span($group, 'thead', 'center');
161 foreach ($settings AS $setting => $name)
163 $admin->row_yesno($name, "perm[$setting]", ($usergroup->objdata
['permissions'] & $bugsys->permissions
["$setting"]));
169 // custom field permissions
170 $admin->table_start();
171 $admin->table_head(_('Custom Field Permissions'));
175 $perms = $db->query("SELECT fieldid
, mask FROM
" . TABLE_PREFIX . "bugfieldpermission WHERE usergroupid
= " . $usergroup->objdata['usergroupid']);
176 while ($perm = $db->fetch_array($perms))
178 $permissions["$perm[fieldid
]"] = $perm['mask'];
182 $fields = $db->query("SELECT fieldid
, name FROM
" . TABLE_PREFIX . "bugfield ORDER BY fieldid
");
183 while ($field = $db->fetch_array($fields))
186 $admin->list_item(_('No Permission'), 0, $permissions["$field[fieldid
]"] == 0);
187 $admin->list_item(_('Can View Field'), 1, $permissions["$field[fieldid
]"] == 1);
188 $admin->list_item(_('Can View, Edit Field'), 2, $permissions["$field[fieldid
]"] == 2);
189 $admin->row_list($field['name'], "custom
[$field[fieldid
]]");
195 $admin->table_start();
196 $admin->row_submit();
204 // ###################################################################
206 if ($_POST['do'] == 'insert')
208 $bugsys->input_clean('perm', TYPE_UINT);
209 foreach ($bugsys->in['perm'] AS $permtitle => $binaryswitch)
211 $permissionvalue += $bugsys->permissions["$permtitle"] * $binaryswitch;
214 $usergroup = new UsergroupAPI($bugsys);
215 $usergroup->set('title', $bugsys->in
['title']);
216 $usergroup->set('displaytitle', $bugsys->in
['displaytitle']);
217 $usergroup->set('permissions', $permissionvalue);
218 $usergroup->insert();
220 $bugsys->input_clean('custom', TYPE_UINT
);
221 if (is_array($bugsys->in
['custom']))
223 foreach ($bugsys->in
['custom'] AS $fieldid => $mask)
225 $values[] = $usergroup->insertid
. ", " . $bugsys->clean($fieldid, TYPE_UINT
) . ", " . $mask;
229 if (is_array($values))
232 INSERT INTO " . TABLE_PREFIX
. "bugfieldpermission
233 (usergroupid, fieldid, mask)
235 (" . implode("\n\t\t\t", $values) . "
240 $admin->redirect('usergroup.php?do=modify');
243 // ###################################################################
245 if ($_POST['do'] == 'update')
247 $bugsys->input_clean_array(array(
249 'usergroupid' => TYPE_UINT
,
250 'custom' => TYPE_UINT
252 $bugsys->input_clean('perm', TYPE_UINT
);
253 foreach ($bugsys->in
['perm'] AS $permtitle => $binaryswitch)
255 $permissionvalue +
= $bugsys->permissions
["$permtitle"] * $binaryswitch;
258 $usergroup = new UsergroupAPI($bugsys);
259 $usergroup->set('usergroupid', $bugsys->in['usergroupid']);
260 $usergroup->set_condition();
261 $usergroup->set('title', $bugsys->in['title']);
262 $usergroup->set('displaytitle', $bugsys->in['displaytitle']);
263 $usergroup->set('permissions', $permissionvalue);
264 $usergroup->update();
266 $bugsys->input_clean('custom', TYPE_UINT);
267 if (is_array($bugsys->in['custom']))
269 foreach ($bugsys->in['custom'] AS $fieldid => $mask)
271 $values[] = $usergroup->values['usergroupid'] . ", " . $bugsys->clean($fieldid, TYPE_UINT) . ", " . $mask;
275 if (is_array($values))
278 REPLACE INTO
" . TABLE_PREFIX . "bugfieldpermission
279 (usergroupid
, fieldid
, mask
)
281 (" . implode("),\n\t\t\t(", $values) . ")"
286 $admin->redirect('usergroup.php?do=modify');
289 // ###################################################################
291 if ($_POST['do'] == 'doapprove')
293 $bugsys->input_clean('approve', TYPE_UINT);
296 if (is_array($bugsys->in['approve']))
298 foreach ($bugsys->in['approve'] AS $id => $yesno)
302 $idlist[] = $bugsys->clean($id, TYPE_UINT);
307 if (sizeof($idlist) > 0)
309 $users = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "user WHERE userid
IN (" . implode(',', $idlist) . ")");
311 $mail->set('subject', sprintf(_('Account Approved at %1$s'), $bugsys->options['trackertitle']));
312 while ($user = $db->fetch_array($users))
315 $mail->to_add($user['displayname'], $user['email']);
316 $mail->set('bodytext', sprintf(_('Hi %1$s,
318 Your account was awaiting moderation at %2$s. Today, an administrator approved your registration and you are now able to use the bug tracker fully.
320 If you have any questions, please don\'t hesitate to contact the webmaster.'),
321 $user['displayname'],
322 $bugsys->options['trackertitle']
328 $db->query("UPDATE
" . TABLE_PREFIX . "user SET usergroupid
= 2 WHERE userid
IN (" . implode(',', $idlist) . ")");
331 $admin->redirect('usergroup.php', _('The selected users have been promoted to the "Registered
" usergroup.'));
334 // ###################################################################
336 if ($_REQUEST['do'] == 'approve')
338 NavLinks::usergroupsAdd();
339 $navigator->set_focus('link', 'usergroups-approve', 'usergroups');
341 $admin->page_start(_('Moderate Awaiting Users'), 3);
343 $admin->form_start('usergroup.php', 'doapprove');
344 $admin->table_start();
345 $admin->table_head(_('Moderate Un-Approved Users'), 3);
347 $admin->table_column_head(array(_('Display Name'), _('Usergroup'), _('Approve')));
349 $users = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "user WHERE usergroupid
IN (3, 4)");
350 while ($user = $db->fetch_array($users))
352 $admin->row_multi_item(array(
353 '<a href="user
.php
?do=edit
&
;userid
=' . $user['userid
'] . '">' . $user['email'] . '</a>' => 'l',
354 $bugsys->datastore['usergroup']["$user[usergroupid
]"]['title'] => 'c',
355 '<input name="approve
[' . $user['userid
'] . ']" type="checkbox
" value="1" />' => 'c'
359 $admin->row_submit(false, ':save:', ':reset:', 3);
366 // ###################################################################
368 if ($_REQUEST['do'] == 'modify')
370 NavLinks::usergroupsAdd();
371 $navigator->set_focus('link', 'users-pages-usergroups', 'users-pages');
373 $admin->page_start(_('Usergroup Manager'));
375 $admin->form_start('usergroup.php', 'null');
376 $admin->table_start();
377 $admin->table_head(_('Usergroup Manager'), 3, 'usergroups');
379 $groups = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "usergroup ORDER BY usergroupid ASC
");
380 while ($group = $db->fetch_array($groups))
382 $usergroups["$group[usergroupid
]"] = $group;
384 $db->free_result($groups);
386 $groups = $db->query("
387 SELECT
COUNT(user
.userid
) AS total
, user
.usergroupid
388 FROM
" . TABLE_PREFIX . "user
AS user
389 LEFT JOIN
" . TABLE_PREFIX . "usergroup
AS usergroup
USING (usergroupid
)
390 GROUP BY usergroup
.usergroupid
391 ORDER BY usergroup
.usergroupid
"
393 while ($group = $db->fetch_array($groups))
395 $usergroups["$group[usergroupid
]"]['total'] = $group['total'];
398 $admin->table_column_head(array(_('Usergroup'), _('Number of Users'), _('Action')));
399 foreach ($usergroups AS $group)
401 $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
]\">[" . _('Edit') . "]</a
>" . (($group['usergroupid'] > 6) ? "<a href
=\"usergroup
.php
?do=delete
&
;usergroupid
=$group[usergroupid
]\">[" . _('Delete') . "]</a
>" : '') => 'c'));
410 /*=====================================================================*\
411 || ###################################################################
414 || ###################################################################
415 \*=====================================================================*/