set_focus('tab', 'users', null);
if (!can_perform('canadmingroups'))
{
admin_login();
}
// ###################################################################
// define permissions as groups
$permissions = array(
_('General Permissions') => array(
'canviewbugs' => _('Can View Bugs'),
'canviewhidden' => _('Can View Hidden Bugs and Comments'),
'canviewownhidden' => _('Can View Own Hidden Bugs'),
'cansearch' => _('Can Search Bugs'),
'cansubscribe' => _('Can Subscribe to Bugs'),
'canbeassignedto' => _('Can Be Assigned Bugs')
),
_('Posting/Submitting Permissions') => array(
'canvote' => _('Can Vote on Polls'),
'cansubmitbugs' => _('Can Submit Bugs'),
'canpostcomments' => _('Can Post Comments'),
'cangetattach' => _('Can View Attachments'),
'canputattach' => _('Can Upload/Edit Own Attachments'),
'caneditattach' => _('Can Manage All Attachments')
),
_('Moderation/Managment Permissions') => array(
'caneditown' => _('Can Edit Own Bugs'),
'caneditother' => _('Can Edit Others\' Bugs'),
'caneditownreply' => _('Can Edit Own Comments'),
'caneditotherreply' => _('Can Edit Others\' Comments'),
'canassign' => _('Can Assign Bugs'),
'canchangestatus' => _('Can Change Status'),
'candeletedata' => _('Can Delete Bugs and Comments')
),
_('Administrator Permissions') => array(
'canadminpanel' => _('Can Access Control Panel'),
'canadminbugs' => _('Can Administer Bug Reports'),
'canadminfields' => _('Can Administer Additional Bug Fields'),
'canadminversions' => _('Can Administer Products / Components / Versions'),
'canadminusers' => _('Can Administer Users'),
'canadmingroups' => _('Can Administer Usergroups'),
'canadmintools' => _('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(_('You can\'t delete a default usergroup.'));
}
$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']));
}
// ###################################################################
if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit' OR $_REQUEST['do'] == 'clone')
{
$clone = ($_REQUEST['do'] == 'clone');
$add = ($_REQUEST['do'] == 'add' OR $clone);
$edit = !$add;
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 ? _('New Usergroup') : _('Edit Usergroup')));
$admin->form_start('usergroup.php', ($add ? 'insert' : 'update'));
if ($edit OR $clone)
{
$usergroup = new UsergroupAPI($bugsys);
$usergroup->set('usergroupid', $bugsys->in['usergroupid']);
$usergroup->set_condition();
$usergroup->fetch();
if ($clone)
{
$admin->form_hidden_field('cloneid', $usergroup->objdata['usergroupid']);
}
else
{
$admin->form_hidden_field('usergroupid', $usergroup->objdata['usergroupid']);
}
}
else
{
$usergroup['permissions'] = 319;
}
// Details
$admin->table_start();
$admin->table_head(_('Usergroup Details'));
$admin->row_input(_('Usergroup Title'), 'title', (($add AND $clone) ? '' : $bugsys->sanitize($usergroup->objdata['title'])));
$admin->row_input(_('Display Title
This is the title that others will be able to see when comments are posted.
'), 'displaytitle', (($add AND $clone) ? '' : $bugsys->sanitize($usergroup->objdata['displaytitle'])));
$admin->table_end();
// Permission
$admin->table_start();
$admin->table_head(_('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(_('Custom Field Permissions'));
if ($edit OR $clone)
{
$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(_('No Permission'), 0, $permissions["$field[fieldid]"] == 0);
$admin->list_item(_('Can View Field'), 1, $permissions["$field[fieldid]"] == 1);
$admin->list_item(_('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);
if (is_array($bugsys->in['custom']))
{
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) . "
)"
);
}
// copy product permissions from cloning
if ($bugsys->input_clean('cloneid', TYPE_UINT))
{
$prodperms = $db->query("SELECT * FROM " . TABLE_PREFIX . "permission WHERE usergroupid = " . $bugsys->in['cloneid']);
while ($prod = $db->fetch_array($prodperms))
{
$db->query("INSERT INTO " . TABLE_PREFIX . "permission (usergroupid, productid, mask) VALUES (" . $usergroup->insertid . ", $prod[productid], $prod[mask])");
}
build_permissions();
}
$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);
if (is_array($bugsys->in['custom']))
{
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 ($_POST['do'] == 'doapprove')
{
$bugsys->input_clean('approve', TYPE_UINT);
$idlist = array();
if (is_array($bugsys->in['approve']))
{
foreach ($bugsys->in['approve'] AS $id => $yesno)
{
if ($yesno > 0)
{
$idlist[] = $bugsys->clean($id, TYPE_UINT);
}
}
}
// load the template system...
$bugsys->load('template_fs', 'template', true);
$template->setExtension('tpl');
$template->setTemplateDir('templates/');
$template->setDatabaseCache(TABLE_PREFIX . 'template');
if (sizeof($idlist) > 0)
{
$users = $db->query("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid IN (" . implode(',', $idlist) . ")");
while ($user = $db->fetch_array($users))
{
eval('$email = "' . $template->fetch('email/accountapproved.xml') . '";');
$email = $bugsys->xml->parse($email);
$mail->setSubject($email['email']['subject']['value']);
$mail->setBodyText($email['email']['bodyText']['value']);
$mail->send($user['email'], $user['displayname']);
}
$db->query("UPDATE " . TABLE_PREFIX . "user SET usergroupid = 2 WHERE userid IN (" . implode(',', $idlist) . ")");
}
$admin->redirect('usergroup.php', _('The selected users have been promoted to the "Registered" usergroup.'));
}
// ###################################################################
if ($_REQUEST['do'] == 'approve')
{
NavLinks::usergroupsAdd();
$navigator->set_focus('link', 'usergroups-approve', 'usergroups');
$admin->page_start(_('Moderate Awaiting Users'), 3);
$admin->form_start('usergroup.php', 'doapprove');
$admin->table_start();
$admin->table_head(_('Moderate Un-Approved Users'), 3);
$admin->table_column_head(array(_('Display Name'), _('Usergroup'), _('Approve')));
$users = $db->query("SELECT * FROM " . TABLE_PREFIX . "user WHERE usergroupid IN (3, 4)");
while ($user = $db->fetch_array($users))
{
$admin->row_multi_item(array(
'' . $user['email'] . '' => 'l',
$bugsys->datastore['usergroup']["$user[usergroupid]"]['title'] => 'c',
'' => 'c'
));
}
$admin->row_submit(false, ':save:', ':reset:', 3);
$admin->table_end();
$admin->form_end();
$admin->page_end();
}
// ###################################################################
if ($_REQUEST['do'] == 'modify')
{
NavLinks::usergroupsAdd();
$navigator->set_focus('link', 'users-pages-usergroups', 'users-pages');
$admin->page_start(_('Usergroup Manager'));
$admin->form_start('usergroup.php', 'null');
$admin->table_start();
$admin->table_head(_('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(_('Usergroup'), _('Number of Users'), _('Action')));
foreach ($usergroups AS $group)
{
$admin->row_multi_item(array(
"$group[title]" => 'l',
(!$group['total'] ? '-' : $group['total']) => 'c',
"[" . _('Edit') . "] " .
"[" . _('Clone') . "]" .
($group['usergroupid'] > 6 ? " [" . _('Delete') . "]" : '') => 'c'
));
}
$admin->table_end();
$admin->form_end();
$admin->page_end();
}
/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>