set_focus('tab', 'users', null);
if (!can_perform('canadmingroups'))
{
admin_login();
}
// ###################################################################
// define permissions as groups
$permissions = array(
T('General Permissions') => array(
'canviewbugs' => T('Can View Bugs'),
'canviewhidden' => T('Can View Hidden Bugs and Comments'),
'canviewownhidden' => T('Can View Own Hidden Bugs'),
'cansearch' => T('Can Search Bugs'),
'cansubscribe' => T('Can Subscribe to Bugs'),
'canbeassignedto' => T('Can Be Assigned Bugs')
),
T('Posting/Submitting Permissions') => array(
'canvote' => T('Can Vote on Polls'),
'cansubmitbugs' => T('Can Submit Bugs'),
'canpostcomments' => T('Can Post Comments'),
'cangetattach' => T('Can View Attachments'),
'canputattach' => T('Can Upload/Edit Own Attachments'),
'caneditattach' => T('Can Manage All Attachments')
),
T('Moderation/Managment Permissions') => array(
'caneditown' => T('Can Edit Own Bugs'),
'caneditother' => T('Can Edit Others\' Bugs'),
'caneditownreply' => T('Can Edit Own Comments'),
'caneditotherreply' => T('Can Edit Others\' Comments'),
'canassign' => T('Can Assign Bugs'),
'canchangestatus' => T('Can Change Status'),
'candeletedata' => T('Can Delete Bugs and Comments')
),
T('Administrator Permissions') => array(
'canadminpanel' => T('Can Access Control Panel'),
'canadminbugs' => T('Can Administer Bug Reports'),
'canadminfields' => T('Can Administer Additional Bug Fields'),
'canadminversions' => T('Can Administer Products / Components / Versions'),
'canadminusers' => T('Can Administer Users'),
'canadmingroups' => T('Can Administer Usergroups'),
'canadmintools' => T('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(T('You can\'t delete a default usergroup.'));
}
$admin->page_confirm(T('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 ? T('New Usergroup') : T('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(T('Usergroup Details'));
$admin->row_input(T('Usergroup Title'), 'title', (($add AND $clone) ? '' : $bugsys->sanitize($usergroup->objdata['title'])));
$admin->row_input(T('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(T('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(T('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(T('No Permission'), 0, $permissions["$field[fieldid]"] == 0);
$admin->list_item(T('Can View Field'), 1, $permissions["$field[fieldid]"] == 1);
$admin->list_item(T('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))
{
$tpl = $template->fetch(FetchEmailPath('accountapproved.xml', $bugsys->datastore['language'][$bugsys->options['defaultlanguage']]['langcode']));
eval('$email = "' . $tpl . '";');
$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', T('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(T('Moderate Awaiting Users'), 3);
$admin->form_start('usergroup.php', 'doapprove');
$admin->table_start();
$admin->table_head(T('Moderate Un-Approved Users'), 3);
$admin->table_column_head(array(T('Display Name'), T('Usergroup'), T('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(T('Usergroup Manager'));
$admin->form_start('usergroup.php', 'null');
$admin->table_start();
$admin->table_head(T('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(T('Usergroup'), T('Number of Users'), T('Action')));
foreach ($usergroups AS $group)
{
$admin->row_multi_item(array(
"$group[title]" => 'l',
(!$group['total'] ? '-' : $group['total']) => 'c',
"[" . T('Edit') . "] " .
"[" . T('Clone') . "]" .
($group['usergroupid'] > 6 ? " [" . T('Delete') . "]" : '') => 'c'
));
}
$admin->table_end();
$admin->form_end();
$admin->page_end();
}
/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>