4 * Copyright (c) 2003, The Burgiss Group, LLC
5 * This source code is part of eWiki LiveUser Plugin.
7 * eWiki LiveUser Plugin is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
12 * eWiki LiveUser Plugin is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with Wiki LiveUser Plugin; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 require_once(dirname(__FILE__).'/liveuser_aux.php');
24 // ewiki callback for rights administration page
25 $ewiki_plugins['page']['AdminRights'] = 'ewiki_page_liveuser_admin_rights';
28 * admin gui for modifying LiveWeb rights
32 * @param string action
33 * @return string page output response
35 function ewiki_page_liveuser_admin_rights($id, $data, $action)
37 global $liveuserPermAdmin;
41 echo ewiki_make_title($id, $id, 2);
43 // handle posted updates and deletes
44 if (isset($_POST['submit_changerights'])) {
45 foreach ($_POST as $key => $value) {
46 list($prefix, $id) = explode('_',$key,2);
48 if ($prefix == 'chk' && is_numeric($id) && $value == 'on') {
49 if (liveuser_removeEntity('right_id', $id)) {
50 echo '<p>Right '.$id.' was successfully deleted.</p>';
52 echo '<p>Deletion of right '.$id.' failed.</p>';
58 // handle posted new rights
59 if (isset($_POST['rightname_text']) && isset($_POST['submit_addright'])) {
60 $right_id = liveuser_checkEntity('right', $_POST['rightname_text']);
62 if ($right_id === false) {
63 $right_const = 'LU_R_'.strtoupper($_POST['rightname_text']);
64 $right_id = liveuser_addEntity('right', array(LU_AREA_LIVEWEB, $right_const, $_POST['rightname_text']));
66 if ($right_id !== false) {
67 echo '<p>Right '.$_POST['rightname_text'].' was successfully created.</p>';
69 echo '<p>Creation of right '.$_POST['rightname_text'].' failed.</p>';
72 echo '<p>Right '.$_POST['rightname_text'].' already exists.</p>';
75 if (isset($_POST['addgroup']) && $right_id !== false) {
76 $group_id = liveuser_checkEntity('group', $_POST['rightname_text']);
78 if ($group_id === false) {
79 $group_const = 'LU_G_'.strtoupper($_POST['rightname_text']);
80 $group_id = liveuser_addEntity('group', array($group_const, $_POST['rightname_text'], null, true));
82 if ($group_id !== false) {
83 echo '<p>Group '.$_POST['rightname_text'].' was successfully created.</p>';
85 echo '<p>Creation of group '.$_POST['rightname_text'].' failed.</p>';
88 echo '<p>Group '.$_POST['rightname_text'].' already exists.</p>';
91 if ($group_id !== false) {
92 // check if group already has the right
93 if (liveuser_checkGroupRight($group_id, $right_id)) {
94 echo 'Group '.$_POST['rightname_text'].' already has right '.$_POST['rightname_text'].'.</p>';
96 // attempt to assign right to group
97 if ($liveuserPermAdmin->grantGroupRight($group_id, $right_id, 1) === true) {
98 echo '<p>Right '.$_POST['rightname_text'].' has been assigned to group '.$_POST['rightname_text'].'.</p>';
100 echo '<p>Assignment of right '.$_POST['rightname_text'].' to group '.$_POST['rightname_text'].' failed.</p>';
107 // Show current table listing of rights
108 $rights = $liveuserPermAdmin->getRights();
110 if (is_array($rights) && !empty($rights)) {
112 <form method="post" action="">
115 <tr><th>Delete</th><th>Right ID</th><th>Right</th></tr>
118 foreach ($rights as $right) {
121 <td><input name="chk_<?=$right['right_id']?>" type="checkbox" /></td>
122 <td><?=$right['right_id']?></td>
123 <td><?=$right['name']?></td>
130 <input type="reset" value="Reset" />
131 <input name="submit_changerights" type="submit" value="Submit Changes" />
137 <p>No rights were found in the database.</p>
141 // Show Add a new right section
143 <form method="post" action="">
145 <p>When creating a right, you may choose to create a group with the right, which may then be applied to user accounts. If the right already exists, this form will still attempt to link a group to it. If the group already exists and does not have the right, the right will be assigned.</p>
146 <label for="rightname_text">Right Name</label>
147 <input id="rightname_text" name="rightname_text" type="text" /><br />
148 <label for="addgroup">Add/Assign Group</label>
149 <input id="addgroup" name="addgroup" type="checkbox" checked="checked" /><br />
150 <input name="submit_addright" type="submit" value="Add Right" />
154 $o = ob_get_contents();