set_focus('tab', 'users', null);
$navigator->set_focus('link', 'users-pages-permissions', 'users-pages');
if (!can_perform('canadmingroups'))
{
admin_login();
}
// ###################################################################
// define permissions as groups
$permissions = array(
_('General Permissions') => array(
'canviewbugs' => _('Can View Bugs'),
'canviewhidden' => _('Can View All Hidden Bugs and Comments'),
'canviewownhidden' => _('Can View Own Hidden Bugs'),
'cansubscribe' => _('Can Subscribe to 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')
)
);
// ###################################################################
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'modify';
}
// ###################################################################
if ($_REQUEST['do'] == 'kill')
{
$bugsys->input_clean('usergroupid', TYPE_UINT);
$db->query("DELETE FROM " . TABLE_PREFIX . "permission WHERE usergroupid = " . $bugsys->in['usergroupid'] . " AND productid = " . $bugsys->input_clean('productid', TYPE_UINT));
build_permissions();
$admin->redirect('permission.php?do=modify&usergroupid=' . $bugsys->in['usergroupid']);
}
// ###################################################################
if ($_REQUEST['do'] == 'delete')
{
$admin->page_confirm(_('Are you sure you want to revert this permission mask?'), 'permission.php', 'kill', array('usergroupid' => $bugsys->input_clean('usergroupid', TYPE_UINT), 'productid' => $bugsys->input_clean('productid', TYPE_UINT)));
}
// ###################################################################
if ($_REQUEST['do'] == 'edit')
{
$bugsys->input_clean_array(array(
'usergroupid' => TYPE_UINT,
'productid' => TYPE_UINT
));
$perm = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "permission WHERE usergroupid = " . $bugsys->in['usergroupid'] . " AND productid = " . $bugsys->in['productid']);
$usergroup = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "usergroup WHERE usergroupid = " . $bugsys->in['usergroupid']);
$product = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . $bugsys->in['productid']);
if (!$usergroup OR !$product)
{
$admin->error(L_INVALID_ID);
}
$admin->page_start(_('Edit Permissions'));
$admin->form_start('permission.php', 'update');
$admin->form_hidden_field('usergroupid', $usergroup['usergroupid']);
$admin->form_hidden_field('productid', $product['productid']);
// determine the value to work off of
if ($perm)
{
$mask = $perm['mask'];
}
else
{
$mask = $usergroup['permissions'];
}
// Permission
$admin->table_start();
$admin->table_head(sprintf(_('Permissions: %1$s - %2$s'), $usergroup['title'], $product['title']));
foreach ($permissions AS $group => $settings)
{
$admin->row_span($group, 'thead', 'center');
foreach ($settings AS $setting => $name)
{
$admin->row_yesno($name, "perm[$setting]", ($mask & $bugsys->permissions["$setting"]));
}
}
$admin->row_submit();
$admin->table_end();
$admin->form_end();
$admin->page_end();
}
// ###################################################################
if ($_POST['do'] == 'update')
{
$bugsys->input_clean_array(array(
'perm' => TYPE_UINT,
'usergroupid' => TYPE_UINT,
'productid' => TYPE_UINT
));
foreach ($bugsys->in['perm'] AS $permtitle => $binaryswitch)
{
$permissionvalue += $bugsys->permissions["$permtitle"] * $binaryswitch;
}
$db->query("
REPLACE INTO " . TABLE_PREFIX . "permission
(usergroupid, productid, mask)
VALUES
(" . $bugsys->in['usergroupid'] . ",
" . $bugsys->in['productid'] . ",
$permissionvalue
)"
);
build_permissions();
$admin->redirect('permission.php?do=modify&usergroupid=' . $bugsys->in['usergroupid']);
}
// ###################################################################
if ($_REQUEST['do'] == 'modify')
{
$admin->page_start(_('Permission Manager'));
$admin->table_start();
$admin->table_head(_('Permission Manager'));
$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);
foreach ($usergroups AS $group)
{
$admin->row_text($group['title'], ($bugsys->in['usergroupid'] != $group['usergroupid'] ? "[" . _('Expand') . "]" : ''), 'top', 2, 'alt3');
if ($bugsys->in['usergroupid'] == $group['usergroupid'])
{
$permissions_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "permission WHERE usergroupid = $group[usergroupid]");
while ($permission = $db->fetch_array($permissions_fetch))
{
$permissions["$permission[productid]"] = $permission['mask'];
}
$products_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE !parentid ORDER BY displayorder ASC");
while ($product = $db->fetch_array($products_fetch))
{
$groupid = $group['usergroupid'];
$prodid = $product['productid'];
if (!isset($permissions["$product[productid]"]))
{
$statuslink = _('Inherited From Usergroup Settings: ');
$statuslink .= "[" . _('Customize') . ']';
}
else
{
$statuslink = _('Customized: ');
$statuslink .= "[" . _('Edit') . ']';
$statuslink .= " [" . _('Revert') . ']';
}
$admin->row_text($product['title'], $statuslink);
}
}
}
$admin->table_end();
$admin->page_end();
}
/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>