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 // TODO - 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 All Hidden Bugs and Comments'),
43 'canviewownhidden' => _('Can View Own Hidden Bugs'),
44 'cansubscribe' => _('Can Subscribe to Bugs'),
47 _('Posting/Submitting Permissions') => array(
48 'canvote' => _('Can Vote on Polls'),
49 'cansubmitbugs' => _('Can Submit Bugs'),
50 'canpostcomments' => _('Can Post Comments'),
51 'cangetattach' => _('Can View Attachments'),
52 'canputattach' => _('Can Upload/Edit Own Attachments'),
53 'caneditattach' => _('Can Manage All Attachments')
56 _('Moderation/Managment Permissions') => array(
57 'caneditown' => _('Can Edit Own Bugs'),
58 'caneditother' => _('Can Edit Others\' Bugs'),
59 'caneditownreply' => _('Can Edit Own Comments'),
60 'caneditotherreply' => _('Can Edit Others\' Comments'),
61 'canassign' => _('Can Assign Bugs'),
62 'canchangestatus' => _('Can Change Status'),
63 'candeletedata' => _('Can Delete Bugs and Comments')
67 // ###################################################################
69 if (empty($_REQUEST['do']))
71 $_REQUEST['do'] = 'modify';
74 // ###################################################################
76 if ($_REQUEST['do'] == 'kill')
78 $bugsys->input_clean('usergroupid', TYPE_UINT
);
79 $db->query("DELETE FROM " . TABLE_PREFIX
. "permission WHERE usergroupid = " . $bugsys->in
['usergroupid'] . " AND productid = " . $bugsys->input_clean('productid', TYPE_UINT
));
83 $admin->redirect('permission.php?do=modify&usergroupid=' . $bugsys->in
['usergroupid']);
86 // ###################################################################
88 if ($_REQUEST['do'] == 'delete')
90 $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
)));
93 // ###################################################################
95 if ($_REQUEST['do'] == 'edit')
97 $bugsys->input_clean_array(array(
98 'usergroupid' => TYPE_UINT
,
99 'productid' => TYPE_UINT
101 $perm = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "permission WHERE usergroupid = " . $bugsys->in
['usergroupid'] . " AND productid = " . $bugsys->in
['productid']);
102 $usergroup = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "usergroup WHERE usergroupid = " . $bugsys->in
['usergroupid']);
103 $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . $bugsys->in
['productid']);
105 if (!$usergroup OR !$product)
107 $admin->error(L_INVALID_ID
);
110 $admin->page_start(_('Edit Permissions'));
112 $admin->form_start('permission.php', 'update');
113 $admin->form_hidden_field('usergroupid', $usergroup['usergroupid']);
114 $admin->form_hidden_field('productid', $product['productid']);
116 // determine the value to work off of
119 $mask = $perm['mask'];
123 $mask = $usergroup['permissions'];
127 $admin->table_start();
128 $admin->table_head(sprintf(_('Permissions: %1$s - %2$s'), $usergroup['title
'], $product['title
']));
130 foreach ($permissions AS $group => $settings)
132 $admin->row_span($group, 'thead
', 'center
');
133 foreach ($settings AS $setting => $name)
135 $admin->row_yesno($name, "perm[$setting]", ($mask & $bugsys->permissions["$setting"]));
139 $admin->row_submit();
145 // ###################################################################
147 if ($_POST['do'] == 'update
')
149 $bugsys->input_clean_array(array(
151 'usergroupid
' => TYPE_UINT,
152 'productid
' => TYPE_UINT
154 foreach ($bugsys->in['perm
'] AS $permtitle => $binaryswitch)
156 $permissionvalue += $bugsys->permissions["$permtitle"] * $binaryswitch;
160 REPLACE INTO " . TABLE_PREFIX . "permission
161 (usergroupid, productid, mask)
163 (" . $bugsys->in['usergroupid
'] . ",
164 " . $bugsys->in['productid
'] . ",
171 $admin->redirect('permission
.php
?do=modify
&usergroupid
=' . $bugsys->in['usergroupid
']);
174 // ###################################################################
176 if ($_REQUEST['do'] == 'modify
')
178 $admin->page_start(_('Permission Manager
'));
180 $admin->table_start();
181 $admin->table_head(_('Permission Manager
'));
183 $groups = $db->query("SELECT * FROM " . TABLE_PREFIX . "usergroup ORDER BY usergroupid ASC");
184 while ($group = $db->fetch_array($groups))
186 $usergroups["$group[usergroupid]"] = $group;
188 $db->free_result($groups);
190 foreach ($usergroups AS $group)
192 $admin->row_text($group['title
'], ($bugsys->in['usergroupid
'] != $group['usergroupid
'] ? "<a href=\"permission.php?do=modify&usergroupid=$group[usergroupid]\">[" . _('Expand
') . "]</a>" : ''), 'top
', 2, 'alt3
');
194 if ($bugsys->in['usergroupid
'] == $group['usergroupid
'])
196 $permissions_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "permission WHERE usergroupid = $group[usergroupid]");
197 while ($permission = $db->fetch_array($permissions_fetch))
199 $permissions["$permission[productid]"] = $permission['mask
'];
202 $products_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE !parentid OR parentid IS NULL ORDER BY displayorder ASC");
203 while ($product = $db->fetch_array($products_fetch))
205 $groupid = $group['usergroupid
'];
206 $prodid = $product['productid
'];
208 if (!isset($permissions["$product[productid]"]))
210 $statuslink = _('Inherited From Usergroup Settings
: ');
211 $statuslink .= "<a href=\"permission.php?do=edit&usergroupid=$groupid&productid=$prodid\">[" . _('Customize
') . ']</a
>';
215 $statuslink = _('Customized
: ');
216 $statuslink .= "<a href=\"permission.php?do=edit&usergroupid=$groupid&productid=$prodid\">[" . _('Edit
') . ']</a
>';
217 $statuslink .= " <a href=\"permission.php?do=delete&usergroupid=$groupid&productid=$prodid\">[" . _('Revert
') . ']</a
>';
220 $admin->row_text($product['title
'], $statuslink);
230 /*=====================================================================*\
231 || ###################################################################
234 || ###################################################################
235 \*=====================================================================*/