changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / auth-liveuser / liveuser_rights_gui.php
1 <?php
2
3 /**
4  * Copyright (c) 2003, The Burgiss Group, LLC
5  * This source code is part of eWiki LiveUser Plugin.
6  *
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.
11  *
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
15  * for more details.
16  *
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
20  */
21
22 require_once(dirname(__FILE__).'/liveuser_aux.php');
23
24 // ewiki callback for rights administration page
25 $ewiki_plugins['page']['AdminRights'] = 'ewiki_page_liveuser_admin_rights';
26
27 /**
28  * admin gui for modifying LiveWeb rights
29  *
30  * @param string id
31  * @param mixed data
32  * @param string action
33  * @return string page output response
34  */
35 function ewiki_page_liveuser_admin_rights($id, $data, $action)
36 {
37     global $liveuserPermAdmin;
38
39     ob_start();
40     
41     echo ewiki_make_title($id, $id, 2);
42            
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);
47             
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>';      
51                 } else {
52                     echo '<p>Deletion of right '.$id.' failed.</p>';
53                 }
54             }   
55         }
56     }
57     
58     // handle posted new rights
59     if (isset($_POST['rightname_text']) && isset($_POST['submit_addright'])) {
60         $right_id = liveuser_checkEntity('right', $_POST['rightname_text']);
61         
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']));
65             
66             if ($right_id !== false) {
67                 echo '<p>Right '.$_POST['rightname_text'].' was successfully created.</p>';
68             } else {
69                 echo '<p>Creation of right '.$_POST['rightname_text'].' failed.</p>';
70             }
71         } else {
72             echo '<p>Right '.$_POST['rightname_text'].' already exists.</p>';
73         }
74             
75         if (isset($_POST['addgroup']) && $right_id !== false) { 
76             $group_id = liveuser_checkEntity('group', $_POST['rightname_text']);
77             
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));
81                 
82                 if ($group_id !== false) {
83                     echo '<p>Group '.$_POST['rightname_text'].' was successfully created.</p>';
84                 } else {
85                     echo '<p>Creation of group '.$_POST['rightname_text'].' failed.</p>';
86                 }
87             } else {
88                 echo '<p>Group '.$_POST['rightname_text'].' already exists.</p>';
89             }
90             
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>';
95                 } else {
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>';
99                     } else {
100                         echo '<p>Assignment of right '.$_POST['rightname_text'].' to group '.$_POST['rightname_text'].' failed.</p>';
101                     }
102                 }
103             }
104         }
105     }
106     
107     // Show current table listing of rights
108     $rights = $liveuserPermAdmin->getRights();
109     
110     if (is_array($rights) && !empty($rights)) {
111         ?>
112             <form method="post" action="">
113             <h3>Edit Rights</h3>
114             <table border="1">
115             <tr><th>Delete</th><th>Right ID</th><th>Right</th></tr>
116         <?php
117         
118         foreach ($rights as $right) {
119             ?>
120                 <tr>
121                     <td><input name="chk_<?=$right['right_id']?>" type="checkbox" /></td>
122                     <td><?=$right['right_id']?></td>
123                     <td><?=$right['name']?></td>
124                 </tr>
125             <?php
126         }
127         
128         ?>
129             </table>
130             <input type="reset" value="Reset" />
131             <input name="submit_changerights" type="submit" value="Submit Changes" />
132             </form>
133         <?php
134     } else {
135         ?>
136             <h3>Edit Rights</h3>
137             <p>No rights were found in the database.</p>
138         <?php
139     }
140     
141     // Show Add a new right section
142     ?>
143         <form method="post" action="">
144         <h3>Add a Right</h3>
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" />
151         </form>
152     <?php
153
154     $o = ob_get_contents();
155     ob_end_clean();
156     return $o;
157 }
158 ?>