set_focus('tab', 'users', null);
if (!can_perform('canadmingroups'))
{
admin_login();
}
// ###################################################################
// define permissions as groups
$permissions = array(
$lang->string('General Permissions') => array(
'canviewbugs' => $lang->string('Can View Bugs'),
'canviewhidden' => $lang->string('Can View Hidden Bugs and Comments'),
'cansearch' => $lang->string('Can Search Bugs'),
'cansubscribe' => $lang->string('Can Subscribe to Bugs'),
'canbeassignedto' => $lang->string('Can Be Assigned Bugs')
),
$lang->string('Posting/Submitting Permissions') => array(
'canvote' => $lang->string('Can Vote on Polls'),
'cansubmitbugs' => $lang->string('Can Submit Bugs'),
'canpostcomments' => $lang->string('Can Post Comments'),
'cangetattach' => $lang->string('Can View Attachments'),
'canputattach' => $lang->string('Can Upload/Edit Own Attachments'),
'caneditattach' => $lang->string('Can Manage All Attachments')
),
$lang->string('Moderation/Managment Permissions') => array(
'caneditown' => $lang->string('Can Edit Own Bugs'),
'caneditother' => $lang->string('Can Edit Others\' Bugs'),
'caneditownreply' => $lang->string('Can Edit Own Comments'),
'caneditotherreply' => $lang->string('Can Edit Others\' Comments'),
'canassign' => $lang->string('Can Assign Bugs'),
'canchangestatus' => $lang->string('Can Change Status'),
'candeletedata' => $lang->string('Can Delete Bugs and Comments')
),
$lang->string('Administrator Permissions') => array(
'canadminpanel' => $lang->string('Can Access Control Panel'),
'canadminbugs' => $lang->string('Can Administer Bug Reports'),
'canadminfields' => $lang->string('Can Administer Additional Bug Fields'),
'canadminversions' => $lang->string('Can Administer Products / Components / Versions'),
'canadminusers' => $lang->string('Can Administer Users'),
'canadmingroups' => $lang->string('Can Administer Usergroups'),
'canadmintools' => $lang->string('Can Administer Settings / Maintenance Tools')
)
);
// ###################################################################
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'modify';
}
// ###################################################################
if ($_REQUEST['do'] == 'kill')
{
$usergroup = new UsergroupAPI($bugsys);
$usergroup->set('usergroupid', $bugsys->in['usergroupid']);
$usergroup->set_condition();
$usergroup->delete();
$admin->redirect('usergroup.php?do=modify');
}
// ###################################################################
if ($_REQUEST['do'] == 'delete')
{
if ($bugsys->in['usergroupid'] < 7)
{
$admin->error($lang->string('You can\'t delete a default usergroup.'));
}
$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=' . $bugsys->in['usergroupid']);
}
// ###################################################################
if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
{
$add = (($_REQUEST['do'] == 'add') ? true : false);
$edit = (($_REQUEST['do'] == 'edit') ? true : false);
if ($edit)
{
NavLinks::usergroupsEdit($bugsys->in['usergroupid']);
$navigator->set_focus('link', 'users-pages-usergroups', 'users-pages');
}
else
{
NavLinks::usergroupsAdd();
$navigator->set_focus('link', 'usergroups-add', 'usergroups');
}
$admin->page_start(($add ? $lang->string('New Usergroup') : $lang->string('Edit Usergroup')));
$admin->form_start('usergroup.php', ($add ? 'insert' : 'update'));
if ($edit)
{
$usergroup = new UsergroupAPI($bugsys);
$usergroup->set('usergroupid', $bugsys->in['usergroupid']);
$usergroup->set_condition();
$usergroup->fetch();
$admin->form_hidden_field('usergroupid', $usergroup->objdata['usergroupid']);
}
else
{
$usergroup['permissions'] = 319;
}
// Details
$admin->table_start();
$admin->table_head($lang->string('Usergroup Details'));
$admin->row_input($lang->string('Usergroup Title'), 'title', $bugsys->sanitize($usergroup->objdata['title']));
$admin->row_input($lang->string('Display Title
This is the title that others will be able to see when comments are posted.
'), 'displaytitle', $bugsys->sanitize($usergroup->objdata['displaytitle']));
$admin->table_end();
// Permission
$admin->table_start();
$admin->table_head($lang->string('Permission Settings'));
foreach ($permissions AS $group => $settings)
{
$admin->row_span($group, 'thead', 'center');
foreach ($settings AS $setting => $name)
{
$admin->row_yesno($name, "perm[$setting]", ($usergroup->objdata['permissions'] & $bugsys->permissions["$setting"]));
}
}
$admin->table_end();
// custom field permissions
$admin->table_start();
$admin->table_head($lang->string('Custom Field Permissions'));
if ($edit)
{
$perms = $db->query("SELECT fieldid, mask FROM " . TABLE_PREFIX . "bugfieldpermission WHERE usergroupid = " . $usergroup->objdata['usergroupid']);
while ($perm = $db->fetch_array($perms))
{
$permissions["$perm[fieldid]"] = $perm['mask'];
}
}
$fields = $db->query("SELECT fieldid, name FROM " . TABLE_PREFIX . "bugfield ORDER BY fieldid");
while ($field = $db->fetch_array($fields))
{
unset($listitem);
$admin->list_item($lang->string('No Permission'), 0, $permissions["$field[fieldid]"] == 0);
$admin->list_item($lang->string('Can View Field'), 1, $permissions["$field[fieldid]"] == 1);
$admin->list_item($lang->string('Can View, Edit Field'), 2, $permissions["$field[fieldid]"] == 2);
$admin->row_list($field['name'], "custom[$field[fieldid]]");
}
$admin->table_end();
// Submit
$admin->table_start();
$admin->row_submit();
$admin->table_end();
$admin->form_end();
$admin->page_end();
}
// ###################################################################
if ($_POST['do'] == 'insert')
{
$bugsys->input_clean('perm', TYPE_UINT);
foreach ($bugsys->in['perm'] AS $permtitle => $binaryswitch)
{
$permissionvalue += $bugsys->permissions["$permtitle"] * $binaryswitch;
}
$usergroup = new UsergroupAPI($bugsys);
$usergroup->set('title', $bugsys->in['title']);
$usergroup->set('displaytitle', $bugsys->in['displaytitle']);
$usergroup->set('permissions', $permissionvalue);
$usergroup->insert();
$bugsys->input_clean('custom', TYPE_UINT);
foreach ($bugsys->in['custom'] AS $fieldid => $mask)
{
$values[] = $usergroup->insertid . ", " . $bugsys->clean($fieldid, TYPE_UINT) . ", " . $mask;
}
if (is_array($values))
{
$db->query("
INSERT INTO " . TABLE_PREFIX . "bugfieldpermission
(usergroupid, fieldid, mask)
VALUES
(" . implode("\n\t\t\t", $values) . "
)"
);
}
$admin->redirect('usergroup.php?do=modify');
}
// ###################################################################
if ($_POST['do'] == 'update')
{
$bugsys->input_clean_array(array(
'perm' => TYPE_UINT,
'usergroupid' => TYPE_UINT,
'custom' => TYPE_UINT
));
$bugsys->input_clean('perm', TYPE_UINT);
foreach ($bugsys->in['perm'] AS $permtitle => $binaryswitch)
{
$permissionvalue += $bugsys->permissions["$permtitle"] * $binaryswitch;
}
$usergroup = new UsergroupAPI($bugsys);
$usergroup->set('usergroupid', $bugsys->in['usergroupid']);
$usergroup->set_condition();
$usergroup->set('title', $bugsys->in['title']);
$usergroup->set('displaytitle', $bugsys->in['displaytitle']);
$usergroup->set('permissions', $permissionvalue);
$usergroup->update();
$bugsys->input_clean('custom', TYPE_UINT);
foreach ($bugsys->in['custom'] AS $fieldid => $mask)
{
$values[] = $usergroup->values['usergroupid'] . ", " . $bugsys->clean($fieldid, TYPE_UINT) . ", " . $mask;
}
if (is_array($values))
{
$db->query("
REPLACE INTO " . TABLE_PREFIX . "bugfieldpermission
(usergroupid, fieldid, mask)
VALUES
(" . implode("),\n\t\t\t(", $values) . ")"
);
}
$admin->redirect('usergroup.php?do=modify');
}
// ###################################################################
if ($_REQUEST['do'] == 'modify')
{
NavLinks::usergroupsAdd();
$navigator->set_focus('link', 'users-pages-usergroups', 'users-pages');
$admin->page_start($lang->string('Usergroup Manager'));
$admin->form_start('usergroup.php', 'null');
$admin->table_start();
$admin->table_head($lang->string('Usergroup Manager'), 3, 'usergroups');
$groups = $db->query("SELECT * FROM " . TABLE_PREFIX . "usergroup ORDER BY usergroupid ASC");
while ($group = $db->fetch_array($groups))
{
$usergroups["$group[usergroupid]"] = $group;
}
$db->free_result($groups);
$groups = $db->query("
SELECT COUNT(user.userid) AS total, user.usergroupid
FROM " . TABLE_PREFIX . "user AS user
LEFT JOIN " . TABLE_PREFIX . "usergroup AS usergroup USING (usergroupid)
GROUP BY usergroup.usergroupid
ORDER BY usergroup.usergroupid"
);
while ($group = $db->fetch_array($groups))
{
$usergroups["$group[usergroupid]"]['total'] = $group['total'];
}
$admin->table_column_head(array($lang->string('Usergroup'), $lang->string('Number of Users'), $lang->string('Action')));
foreach ($usergroups AS $group)
{
$admin->row_multi_item(array("$group[title]" => 'l', ((!$group['total']) ? '-' : $group['total']) => 'c', "[" . $lang->string('Edit') . "]" . (($group['usergroupid'] > 6) ? "[" . $lang->string('Delete') . "]" : '') => 'c'));
}
$admin->table_end();
$admin->form_end();
$admin->page_end();
}
/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>