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 // #*# look at an API for permission.php
24 require_once('./global.php');
25 require_once('./includes/functions_datastore.php');
27 NavLinks
::usersPages();
28 $navigator->set_focus('tab', 'users', null
);
29 $navigator->set_focus('link', 'users-pages-permissions', 'users-pages');
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 'cansubscribe' => _('Can Subscribe to Bugs'),
46 _('Posting/Submitting Permissions') => array(
47 'canvote' => _('Can Vote on Polls'),
48 'cansubmitbugs' => _('Can Submit Bugs'),
49 'canpostcomments' => _('Can Post Comments'),
50 'cangetattach' => _('Can View Attachments'),
51 'canputattach' => _('Can Upload/Edit Own Attachments'),
52 'caneditattach' => _('Can Manage All Attachments')
55 _('Moderation/Managment Permissions') => array(
56 'caneditown' => _('Can Edit Own Bugs'),
57 'caneditother' => _('Can Edit Others\' Bugs'),
58 'caneditownreply' => _('Can Edit Own Comments'),
59 'caneditotherreply' => _('Can Edit Others\' Comments'),
60 'canassign' => _('Can Assign Bugs'),
61 'canchangestatus' => _('Can Change Status'),
62 'candeletedata' => _('Can Delete Bugs and Comments')
66 // ###################################################################
68 if (empty($_REQUEST['do']))
70 $_REQUEST['do'] = 'modify';
73 // ###################################################################
75 if ($_REQUEST['do'] == 'kill')
77 $bugsys->input_clean('usergroupid', TYPE_UINT
);
78 $db->query("DELETE FROM " . TABLE_PREFIX
. "permission WHERE usergroupid = " . $bugsys->in
['usergroupid'] . " AND productid = " . $bugsys->input_clean('productid', TYPE_UINT
));
82 $admin->redirect('permission.php?do=modify&usergroupid=' . $bugsys->in
['usergroupid']);
85 // ###################################################################
87 if ($_REQUEST['do'] == 'delete')
89 $admin->page_confirm(_('Are you sure you want to revert this permission mask?'), 'permission.php?do=kill&usergroupid=' . $bugsys->input_clean('usergroupid', TYPE_UINT
) . '&productid=' . $bugsys->input_clean('productid', TYPE_UINT
));
92 // ###################################################################
94 if ($_REQUEST['do'] == 'edit')
96 $bugsys->input_clean_array(array(
97 'usergroupid' => TYPE_UINT
,
98 'productid' => TYPE_UINT
100 $perm = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "permission WHERE usergroupid = " . $bugsys->in
['usergroupid'] . " AND productid = " . $bugsys->in
['productid']);
101 $usergroup = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "usergroup WHERE usergroupid = " . $bugsys->in
['usergroupid']);
102 $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . $bugsys->in
['productid']);
104 if (!$usergroup OR !$product)
106 $admin->error($lang->getlex('error_invalid_id'));
109 $admin->page_start(_('Edit Permissions'));
111 $admin->form_start('permission.php', 'update');
112 $admin->form_hidden_field('usergroupid', $usergroup['usergroupid']);
113 $admin->form_hidden_field('productid', $product['productid']);
115 // determine the value to work off of
118 $mask = $perm['mask'];
122 $mask = $usergroup['permissions'];
126 $admin->table_start();
127 $admin->table_head(sprintf(_('Permissions: %1$s - %2$s'), $usergroup['title'], $product['title']));
129 foreach ($permissions AS $group => $settings)
131 $admin->row_span($group, 'thead', 'center');
132 foreach ($settings AS $setting => $name)
134 $admin->row_yesno($name, "perm[$setting]", ($mask & $bugsys->permissions
["$setting"]));
138 $admin->row_submit();
144 // ###################################################################
146 if ($_POST['do'] == 'update')
148 $bugsys->input_clean_array(array(
150 'usergroupid' => TYPE_UINT
,
151 'productid' => TYPE_UINT
153 foreach ($bugsys->in
['perm'] AS $permtitle => $binaryswitch)
155 $permissionvalue +
= $bugsys->permissions
["$permtitle"] * $binaryswitch;
159 REPLACE INTO " . TABLE_PREFIX
. "permission
160 (usergroupid, productid, mask)
162 (" . $bugsys->in
['usergroupid'] . ",
163 " . $bugsys->in
['productid'] . ",
170 $admin->redirect('permission.php?do=modify&usergroupid=' . $bugsys->in
['usergroupid']);
173 // ###################################################################
175 if ($_REQUEST['do'] == 'modify')
177 $admin->page_start(_('Permission Manager'));
179 $admin->table_start();
180 $admin->table_head(_('Permission Manager'));
182 $groups = $db->query("SELECT * FROM " . TABLE_PREFIX
. "usergroup ORDER BY usergroupid ASC");
183 while ($group = $db->fetch_array($groups))
185 $usergroups["$group[usergroupid]"] = $group;
187 $db->free_result($groups);
189 foreach ($usergroups AS $group)
191 $admin->row_text($group['title'], ($bugsys->in
['usergroupid'] != $group['usergroupid'] ?
"<a href=\"permission.php?do=modify&usergroupid=$group[usergroupid]\">[" . _('Expand') . "]</a>" : ''), 'top', 2, 'alt3');
193 if ($bugsys->in
['usergroupid'] == $group['usergroupid'])
195 $permissions_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX
. "permission WHERE usergroupid = $group[usergroupid]");
196 while ($permission = $db->fetch_array($permissions_fetch))
198 $permissions["$permission[productid]"] = $permission['mask'];
201 $products_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX
. "product WHERE !componentmother ORDER BY displayorder ASC");
202 while ($product = $db->fetch_array($products_fetch))
204 $groupid = $group['usergroupid'];
205 $prodid = $product['productid'];
207 if (!isset($permissions["$product[productid]"]))
209 $statuslink = _('Inherited From Usergroup Settings: ');
210 $statuslink .= "<a href=\"permission.php?do=edit&usergroupid=$groupid&productid=$prodid\">[" . _('Customize') . ']</a>';
214 $statuslink = _('Customized: ');
215 $statuslink .= "<a href=\"permission.php?do=edit&usergroupid=$groupid&productid=$prodid\">[" . _('Edit') . ']</a>';
216 $statuslink .= " <a href=\"permission.php?do=delete&usergroupid=$groupid&productid=$prodid\">[" . _('Revert') . ']</a>';
219 $admin->row_text($product['title'], $statuslink);
229 /*=====================================================================*\
230 || ###################################################################
233 || ###################################################################
234 \*=====================================================================*/