2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright ©2002-2007 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 2 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 require_once('./global.php');
23 require_once('./includes/api_usergroup.php');
25 APIError(array(new API_Error_Handler($admin), 'admin_error'));
27 NavLinks
::usersPages();
28 $navigator->set_focus('tab', 'users', null
);
30 if (!can_perform('canadmingroups'))
35 // ###################################################################
36 // define permissions as groups
39 T('General Permissions') => array(
40 'canviewbugs' => T('Can View Bugs'),
41 'canviewhidden' => T('Can View Hidden Bugs and Comments'),
42 'canviewownhidden' => T('Can View Own Hidden Bugs'),
43 'cansearch' => T('Can Search Bugs'),
44 'cansubscribe' => T('Can Subscribe to Bugs'),
45 'canbeassignedto' => T('Can Be Assigned Bugs')
48 T('Posting/Submitting Permissions') => array(
49 'canvote' => T('Can Vote on Polls'),
50 'cansubmitbugs' => T('Can Submit Bugs'),
51 'canpostcomments' => T('Can Post Comments'),
52 'cangetattach' => T('Can View Attachments'),
53 'canputattach' => T('Can Upload/Edit Own Attachments'),
54 'caneditattach' => T('Can Manage All Attachments')
57 T('Moderation/Managment Permissions') => array(
58 'caneditown' => T('Can Edit Own Bugs'),
59 'caneditother' => T('Can Edit Others\' Bugs'),
60 'caneditownreply' => T('Can Edit Own Comments'),
61 'caneditotherreply' => T('Can Edit Others\' Comments'),
62 'canassign' => T('Can Assign Bugs'),
63 'canchangestatus' => T('Can Change Status'),
64 'candeletedata' => T('Can Delete Bugs and Comments')
67 T('Administrator Permissions') => array(
68 'canadminpanel' => T('Can Access Control Panel'),
69 'canadminbugs' => T('Can Administer Bug Reports'),
70 'canadminfields' => T('Can Administer Additional Bug Fields'),
71 'canadminversions' => T('Can Administer Products / Components / Versions'),
72 'canadminusers' => T('Can Administer Users'),
73 'canadmingroups' => T('Can Administer Usergroups'),
74 'canadmintools' => T('Can Administer Settings / Maintenance Tools')
78 // ###################################################################
80 if (empty($_REQUEST['do']))
82 $_REQUEST['do'] = 'modify';
85 // ###################################################################
87 if ($_REQUEST['do'] == 'kill')
89 $usergroup = new UsergroupAPI();
90 $usergroup->set('usergroupid', $input->in
['usergroupid']);
91 $usergroup->set_condition();
94 $admin->redirect('usergroup.php?do=modify');
97 // ###################################################################
99 if ($_REQUEST['do'] == 'delete')
101 if ($input->in
['usergroupid'] < 7)
103 $admin->error(T('You can\'t delete a default usergroup.'));
106 $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' => $input->in
['usergroupid']));
109 // ###################################################################
111 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit' OR $_REQUEST['do'] == 'clone')
113 $clone = ($_REQUEST['do'] == 'clone');
114 $add = ($_REQUEST['do'] == 'add' OR $clone);
119 NavLinks
::usergroupsEdit($input->in
['usergroupid']);
120 $navigator->set_focus('link', 'users-pages-usergroups', 'users-pages');
124 NavLinks
::usergroupsAdd();
125 $navigator->set_focus('link', 'usergroups-add', 'usergroups');
128 $admin->page_start(($add ?
T('New Usergroup') : T('Edit Usergroup')));
130 $admin->form_start('usergroup.php', ($add ?
'insert' : 'update'));
134 $usergroup = new UsergroupAPI();
135 $usergroup->set('usergroupid', $input->in
['usergroupid']);
136 $usergroup->set_condition();
141 $admin->form_hidden_field('cloneid', $usergroup->record
['usergroupid']);
145 $admin->form_hidden_field('usergroupid', $usergroup->record
['usergroupid']);
150 $usergroup['permissions'] = 319;
154 $admin->table_start();
155 $admin->table_head(T('Usergroup Details'));
156 $admin->row_input(T('Usergroup Title'), 'title', (($add AND $clone) ?
'' : $bugsys->sanitize($usergroup->record
['title'])));
157 $admin->row_input(T('Display Title<div><dfn>This is the title that others will be able to see when comments are posted.</dfn></div>'), 'displaytitle', (($add AND $clone) ?
'' : $bugsys->sanitize($usergroup->record
['displaytitle'])));
161 $admin->table_start();
163 $admin->table_head(T('Permission Settings'));
165 foreach ($permissions AS $group => $settings)
167 $admin->row_span($group, 'thead', 'center');
168 foreach ($settings AS $setting => $name)
170 $admin->row_yesno($name, "perm[$setting]", ($usergroup->record
['permissions'] & bugdar
::$permissions["$setting"]));
176 // custom field permissions
177 $admin->table_start();
178 $admin->table_head(T('Custom Field Permissions'));
182 $perms = $db->query("SELECT fieldid, mask FROM " . TABLE_PREFIX
. "bugfieldpermission WHERE usergroupid = " . $usergroup->record
['usergroupid']);
183 foreach ($perms as $perm)
185 $permissions["$perm[fieldid]"] = $perm['mask'];
189 $fields = $db->query("SELECT fieldid, name FROM " . TABLE_PREFIX
. "bugfield ORDER BY fieldid");
190 foreach ($fields as $field)
193 $admin->list_item(T('No Permission'), 0, $permissions["$field[fieldid]"] == 0);
194 $admin->list_item(T('Can View Field'), 1, $permissions["$field[fieldid]"] == 1);
195 $admin->list_item(T('Can View, Edit Field'), 2, $permissions["$field[fieldid]"] == 2);
196 $admin->row_list($field['name'], "custom[$field[fieldid]]");
202 $admin->table_start();
203 $admin->row_submit();
211 // ###################################################################
213 if ($_POST['do'] == 'insert')
215 $input->inputClean('perm', TYPE_UINT
);
216 foreach ($input->in
['perm'] AS $permtitle => $binaryswitch)
218 $permissionvalue +
= bugdar
::$permissions["$permtitle"] * $binaryswitch;
221 $usergroup = new UsergroupAPI();
222 $usergroup->set('title', $input->in
['title']);
223 $usergroup->set('displaytitle', $input->in
['displaytitle']);
224 $usergroup->set('permissions', $permissionvalue);
225 $usergroup->insert();
227 $input->inputClean('custom', TYPE_UINT
);
228 if (is_array($input->in
['custom']))
230 foreach ($input->in
['custom'] AS $fieldid => $mask)
232 $values[] = $usergroup->insertid
. ", " . $bugsys->clean($fieldid, TYPE_UINT
) . ", " . $mask;
236 if (is_array($values))
239 INSERT INTO " . TABLE_PREFIX
. "bugfieldpermission
240 (usergroupid, fieldid, mask)
242 (" . implode("),\n\t\t\t(", $values) . "
247 // copy product permissions from cloning
248 if ($input->inputClean('cloneid', TYPE_UINT
))
250 $prodperms = $db->query("SELECT * FROM " . TABLE_PREFIX
. "permission WHERE usergroupid = " . $input->in
['cloneid']);
251 foreach ($prodperms as $prod)
253 $db->query("INSERT INTO " . TABLE_PREFIX
. "permission (usergroupid, productid, mask) VALUES (" . $usergroup->insertid
. ", $prod[productid], $prod[mask])");
258 $admin->redirect('usergroup.php?do=modify');
261 // ###################################################################
263 if ($_POST['do'] == 'update')
265 $input->inputClean_array(array(
267 'usergroupid' => TYPE_UINT
,
268 'custom' => TYPE_UINT
270 $input->inputClean('perm', TYPE_UINT
);
271 foreach ($input->in
['perm'] AS $permtitle => $binaryswitch)
273 $permissionvalue +
= bugdar
::$permissions["$permtitle"] * $binaryswitch;
276 $usergroup = new UsergroupAPI();
277 $usergroup->set('usergroupid', $input->in
['usergroupid']);
278 $usergroup->set_condition();
279 $usergroup->set('title', $input->in
['title']);
280 $usergroup->set('displaytitle', $input->in
['displaytitle']);
281 $usergroup->set('permissions', $permissionvalue);
282 $usergroup->update();
284 $input->inputClean('custom', TYPE_UINT
);
285 if (is_array($input->in
['custom']))
287 foreach ($input->in
['custom'] AS $fieldid => $mask)
289 $values[] = $usergroup->values
['usergroupid'] . ", " . $bugsys->clean($fieldid, TYPE_UINT
) . ", " . $mask;
293 if (is_array($values))
296 REPLACE INTO " . TABLE_PREFIX
. "bugfieldpermission
297 (usergroupid, fieldid, mask)
299 (" . implode("),\n\t\t\t(", $values) . ")"
304 $admin->redirect('usergroup.php?do=modify');
307 // ###################################################################
309 if ($_POST['do'] == 'doapprove')
311 $input->inputClean('approve', TYPE_UINT
);
314 if (is_array($input->in
['approve']))
316 foreach ($input->in
['approve'] AS $id => $yesno)
320 $idlist[] = $bugsys->clean($id, TYPE_UINT
);
325 // load the template system...
326 $bugsys->load('template_fs', 'template', true
);
327 $template->setExtension('tpl');
328 $template->setTemplateDir('templates/');
329 $template->setDatabaseCache(TABLE_PREFIX
. 'template');
331 if (sizeof($idlist) > 0)
333 $users = $db->query("SELECT * FROM " . TABLE_PREFIX
. "user WHERE userid IN (" . implode(',', $idlist) . ")");
334 foreach ($users as $user)
336 $tpl = $template->fetch(FetchEmailPath('accountapproved.xml', bugdar
::$datastore['language'][bugdar
::$options['defaultlanguage']]['langcode']));
337 eval('$email = "' . $tpl . '";');
338 $email = $bugsys->xml
->parse($email);
339 $mail->setSubject($email['email']['subject']['value']);
340 $mail->setBodyText($email['email']['bodyText']['value']);
341 $mail->send($user['email'], $user['displayname']);
344 $db->query("UPDATE " . TABLE_PREFIX
. "user SET usergroupid = 2 WHERE userid IN (" . implode(',', $idlist) . ")");
347 $admin->redirect('usergroup.php', T('The selected users have been promoted to the "Registered" usergroup.'));
350 // ###################################################################
352 if ($_REQUEST['do'] == 'approve')
354 NavLinks
::usergroupsAdd();
355 $navigator->set_focus('link', 'usergroups-approve', 'usergroups');
357 $admin->page_start(T('Moderate Awaiting Users'), 3);
359 $admin->form_start('usergroup.php', 'doapprove');
360 $admin->table_start();
361 $admin->table_head(T('Moderate Un-Approved Users'), 3);
363 $admin->table_column_head(array(T('Display Name'), T('Usergroup'), T('Approve')));
365 $users = $db->query("SELECT * FROM " . TABLE_PREFIX
. "user WHERE usergroupid IN (3, 4)");
366 foreach ($users as $user)
368 $admin->row_multi_item(array(
369 '<a href="user.php?do=edit&userid=' . $user['userid'] . '">' . $user['email'] . '</a>' => 'l',
370 bugdar
::$datastore['usergroup']["$user[usergroupid]"]['title'] => 'c',
371 '<input name="approve[' . $user['userid'] . ']" type="checkbox" value="1" />' => 'c'
375 $admin->row_submit(false
, ':save:', ':reset:', 3);
382 // ###################################################################
384 if ($_REQUEST['do'] == 'modify')
386 NavLinks
::usergroupsAdd();
387 $navigator->set_focus('link', 'users-pages-usergroups', 'users-pages');
389 $admin->page_start(T('Usergroup Manager'));
391 $admin->form_start('usergroup.php', 'null');
392 $admin->table_start();
393 $admin->table_head(T('Usergroup Manager'), 3, 'usergroups');
395 $groups = $db->query("SELECT * FROM " . TABLE_PREFIX
. "usergroup ORDER BY usergroupid ASC");
396 foreach ($groups as $group)
398 $usergroups["$group[usergroupid]"] = $group;
400 $db->free_result($groups);
402 $groups = $db->query("
403 SELECT COUNT(user.userid) AS total, user.usergroupid
404 FROM " . TABLE_PREFIX
. "user AS user
405 LEFT JOIN " . TABLE_PREFIX
. "usergroup AS usergroup USING (usergroupid)
406 GROUP BY usergroup.usergroupid
407 ORDER BY usergroup.usergroupid"
409 foreach ($groups as $group)
411 $usergroups["$group[usergroupid]"]['total'] = $group['total'];
414 $admin->table_column_head(array(T('Usergroup'), T('Number of Users'), T('Action')));
415 foreach ($usergroups AS $group)
417 $admin->row_multi_item(array(
418 "<a href=\"usergroup.php?do=edit&usergroupid=$group[usergroupid]\">$group[title]</a>" => 'l',
419 (!$group['total'] ?
'-' : $group['total']) => 'c',
421 "<a href=\"usergroup.php?do=edit&usergroupid=$group[usergroupid]\">[" . T('Edit') . "]</a> " .
422 "<a href=\"usergroup.php?do=clone&usergroupid=$group[usergroupid]\">[" . T('Clone') . "]</a>" .
423 ($group['usergroupid'] > 6 ?
" <a href=\"usergroup.php?do=delete&usergroupid=$group[usergroupid]\">[" . T('Delete') . "]</a>" : '') => 'c'
433 /*=====================================================================*\
434 || ###################################################################
437 || ###################################################################
438 \*=====================================================================*/