added an auth component to allow permission checking and rejection for
[gwvp.git] / gwvplib / gwvpuseradmin.php
1 <?php
2
3 // setup the call me function for useradmin - matches on url of admin/users
4 $CALL_ME_FUNCTIONS["useradmin"] = "gwvp_UserAdminCallMe";
5
6 $MENU_ITEMS["10users"]["text"] = "Users/Groups";
7 $MENU_ITEMS["10users"]["link"] = "$BASE_URL/admin/users";
8
9
10 function gwvp_UserAdminCallMe()
11 {
12         if(isset($_REQUEST["q"])) {
13                 $query = $_REQUEST["q"];
14                 $qspl = explode("/", $query);
15                 if(isset($qspl[0]) && isset($qspl[1])) {
16                         if($qspl[0] == "admin" && $qspl[1] == "users") {
17                                 if(isset($qspl[2])) {
18                                         switch($qspl[2]) {
19                                                 case "adduser":
20                                                         return "gwvp_AddUserPage";
21                                                         break;
22                                                 case "addgroup":
23                                                         return "gwvp_AddGroupPage";
24                                                         break;
25                                                 case "modify":
26                                                         return "gwvp_ModifyUserPage";
27                                                         break;
28                                                 case "modifygroup":
29                                                         return "gwvp_ModifyGroupPage";
30                                                         break;
31                                                 default:
32                                                         return "gwvp_UserAdminPage";
33                                         }                                       
34                                 } else {
35                                         return "gwvp_UserAdminPage";
36                                 }
37                         }
38                 } 
39                 else return false;
40         }
41         
42         return false;
43 }
44
45 function gwvp_AddUserPage()
46 {
47         
48 }
49
50 function gwvp_AddGroupPage()
51 {
52         
53 }
54
55 function gwvp_UserAdminPage()
56 {
57         gwvp_goMainPage("gwvp_UserAdminPageBody");
58 }
59
60 function gwvp_ModifyUserPage()
61 {
62         if(!gwvp_CheckAuthLevel("admin")) {
63                 gwvp_AuthNoPerms();
64                 return;
65         }
66         
67         gwvp_goMainPage("gwvp_ModifyUserPageBody");
68 }
69
70 function gwvp_ModifyGroupPage()
71 {
72         gwvp_goMainPage("gwvp_ModifyGroupPageBody");
73 }
74
75 function gwvp_ModifyUserPageBody()
76 {
77         error_log("modify user body - coming in");
78         if(!gwvp_CheckAuthLevel("admin")) {
79                 gwvp_AuthNoPermsBody();
80                 return;
81         }
82         
83         
84         $uid = -1;
85         if(isset($_REQUEST["q"])) {
86                 $query = $_REQUEST["q"];
87                 $qspl = explode("/", $query);
88                 $uid = $qspl[3];
89         }
90         
91         echo "modify user $uid";
92 }
93
94 function gwvp_ModifyGroupPageBody()
95 {
96         $gid = -1;
97         if(isset($_REQUEST["q"])) {
98                 $query = $_REQUEST["q"];
99                 $qspl = explode("/", $query);
100                 $gid = $qspl[3];
101         }
102         
103         echo "modify group $gid";
104 }
105
106 function gwvp_UserAdminPageBody()
107 {
108         global $LOGIN_TYPE, $BASE_URL;
109         
110         $groups = gwvp_getGroups();
111         $users = gwvp_getUsers();
112         
113         echo "<h2>Users and Groups</h2>";
114         echo "On this page you can manage users, groups, group membership and update your profile<br>";
115         echo "<table>";
116         
117         echo "<tr><td colspan=\"2\"><hr></td></tr>";
118         
119         
120         // Header part of table
121         // user self-management bit
122         if($LOGIN_TYPE != "anon") {
123                 echo "<tr><td valign=\"top\"><h3>My Profile</h3></td><td><h3>My Groups</h3></td></tr>";
124                 
125                 echo "<tr>";
126                 // user profile bit
127                 echo "<td valign=\"top\">";
128                 echo "User profile bits go here";
129                 echo "</td>";
130                 
131                 // now the group bit for the user
132                 echo "<td valign=\"top\">";
133                 echo "User owned groups, and groups their a member of go here";
134                 echo "</td>";
135                 echo "</tr>";
136                 
137                 echo "<tr><td colspan=\"2\"><hr></td></tr>";
138         }
139         
140         // admin only bit
141         if($LOGIN_TYPE == "admin") {
142                 echo "<tr><td valign=\"top\"><h3>Create User</h3></td><td><h3>Create Group</h3></td></tr>";
143                 
144                 // create user bit
145                 echo "<tr><td valign=\"top\">";
146                 
147                 echo "<form method=\"post\" action=\"$BASE_URL/admin/users/adduser\">";
148                 echo "<table>";
149                 echo "<tr><td>EMail</td><td><input type=\"text\" name=\"email\"></td>";
150                 echo "<td>Full Name</td><td><input type=\"text\" name=\"fullname\"></td></tr>";
151                 echo "<tr><td>Password</td><td><input type=\"text\" name=\"pass1\"></td>";
152                 echo "<td>Password Confirm</td><td><input type=\"text\" name=\"pass2\"></td></tr>";
153                 echo "<tr><td>Username</td><td><input type=\"text\" name=\"username\"></td>";
154                 echo "<td>Description</td><td><input type=\"text\" name=\"desc\"></td></tr>";
155                 echo "<tr><td><input type=\"submit\" name=\"Create\" value=\"Create\" class=\"buttons\"></td></tr>";
156                 echo "</table>";
157                 echo "</form>";
158                 
159                 echo "</td><td valign=\"top\">";
160                 
161                 // Create group
162                 echo "<form method=\"post\" action=\"$BASE_URL/admin/users/addgroup\">";
163                 echo "<table>";
164                 echo "<tr><td>Group Name</td><td><input type=\"text\" name=\"groupname\"><td></tr>";
165                 echo "<tr><td>Admin Group?</td><td><input type=\"checkbox\" name=\"admingroup\" class=\"mycheckbox\"></td></tr>";
166                 echo "<tr><td>Owner</td><td><div><select class=\"myselect\" name=\"groupowner\">";
167                 foreach($users as $u_users) {
168                         $uid = $u_users["id"];
169                         $email = $u_users["email"];
170                         $username = $u_users["username"];
171                         $fullname = $u_users["fullname"];
172                         echo "<option value=\"$uid\">$username, $fullname ($email)</option>";
173                 }
174                 echo "</select></div></td></tr>";
175                 
176                 
177                 
178                 echo "<tr><td><input type=\"submit\" name=\"Create\" value=\"Create\" class=\"buttons\"></td></tr>";
179                 echo "</table>";
180                 echo "</form>";
181                 
182                 
183                 echo "</td></tr>";
184                 echo "<tr><td colspan=\"2\"><hr></td></tr>";
185         }
186         
187         
188         
189         // TODO: whats seen here will depend GREATLY on setting in config - need to fix this later
190         // user list
191         echo "<tr><td valign=\"top\"><h3>Users</h3></td><td><h3>Groups</h3></td></tr>";
192         
193         echo "<tr><td>";
194         echo "<table border=\"1\">";
195         switch($LOGIN_TYPE) {
196                 case "anon":
197                         echo "<tr><th>Username</th><th>Groups</th><th>Description</th></tr>";
198                         break;
199                 case "admin":
200                         echo "<tr><th>EMail</th><th>Username</th><th>Full Name</th><th>Groups</th><th>Description</th><th>Admin?</th><th>Status</th><th>Modify</th></tr>";
201                         break;
202                 case "user":
203                         echo "<tr><th>Username</th><th>Groups</th><th>Description</th></tr>";
204                         break;
205         }
206                 
207         /*
208          *              $returns[$rn]["id"] = $u_res["users_id"];
209                 $returns[$rn]["fullname"] = $u_res["user_full_name"];
210                 $returns[$rn]["password"] = $u_res["user_password"];
211                 $returns[$rn]["username"] = $u_res["user_username"];
212                 $returns[$rn]["email"] = $u_res["user_email"];
213                 $returns[$rn]["desc"] = $u_res["user_desc"];
214                 $returns[$rn]["status"] = $u_res["user_status"];
215
216          */
217         foreach($users as $u_users) {
218                 $userid = $u_users["id"];
219                 $email = $u_users["email"];
220                 $fullname = $u_users["fullname"];
221                 $username = $u_users["username"];
222                 $desc = $u_users["desc"];
223                 $status = $u_users["status"];
224                 if(gwvp_IsUserAdmin($email) == 1) {
225                         $globaladmin = "Yes";
226                 } else {
227                         $globaladmin = "No";
228                 }
229                 
230                 
231                 // TODO: sort out group prints here
232                 $ingroups = gwvp_getGroupsForUser($email);
233                 
234                 $ownedgroups = gwvp_getGroupsOwnedByUser($email);
235                 $ugroups = "";
236                 if($ownedgroups == false) $ogroups = "-";
237                 else {
238                         foreach($ownedgroups as $gr_u) {
239                                 $ugroups .= "<font color=\"#3333ff\">$gr_u</font><br>";
240                         }
241                 }
242                 trim($ugroups);
243                 
244                 
245                 foreach($ingroups as $grname) {
246                         $isownedgroup = false;
247                         foreach($ownedgroups as $gr_u) {
248                                 if($grname == $gr_u) $isownedgroup = true;
249                         }
250                         if(!$isownedgroup) $ugroups .= "$grname<br>";
251                 }
252                 trim($ugroups);
253                 
254                 switch($LOGIN_TYPE) {
255                         case "anon":
256                                 echo "<tr><td>$username</td><td>$ugroups</td><td>$desc</td></tr>";
257                                 break;
258                         case "admin":
259                                 echo "<tr><td>$email</td><td>$username</td><td>$fullname</td><td>$ugroups</td><td>$desc</td>";
260                                 echo "<td>$globaladmin</td><td>$status</td><td><a href=\"$BASE_URL/admin/users/modify/$userid\">Modify</a></td></tr>";
261                                 break;
262                         case "user":
263                                 echo "<tr><td>$username</td><td>$ugroups</td><td>$desc</td></tr>";
264                                 break;
265                 }
266                 
267                 
268         }
269         echo "</table>";
270         
271         echo "</td><td valign=\"top\">";
272         
273         // group part of table
274         
275         echo "<table border=\"1\">";
276         
277         switch($LOGIN_TYPE) {
278                 case "anon":
279                         echo "<tr><th>Group Name</th><th>Owner</th></tr>";
280                         break;
281                 case "admin":
282                         echo "<tr><th>Group Name</th><th>Owner</th><th>Admin Group?</th><th>Modify</th></tr>";
283                         break;
284                 case "user":
285                         echo "<tr><th>Group Name</th><th>Owner</th><th>Admin Group?</th></tr>";
286                         break;
287         }
288         
289         foreach($groups as $u_groups) {
290                 /*
291                  *              $returns[$rn]["id"] = $u_res["groups_id"];
292                 $returns[$rn]["name"] = $u_res["groups_name"];
293                 if($u_res["groups_is_admin"]=="1") $return[$rn]["admin"] = true;
294                 else $return[$rn]["admin"] = false;
295                 $returns[$rn]["admin"] = $u_res["groups_is_admin"];
296                 $returns[$rn]["ownerid"] = $u_res["groups_owner_id"];
297
298                  */
299                 $gname = $u_groups["name"];
300                 $gid = $u_groups["id"];
301                 $owner = gwvp_getUserEmail($u_groups["ownerid"]);
302                 if($u_groups["admin"]) $gadmin = "Yes";
303                 else $gadmin  = "No";
304
305                 switch($LOGIN_TYPE) {
306                         case "anon":
307                                 echo "<tr><td>$gname</td><td>$owner</td></tr>";
308                                 break;
309                         case "admin":
310                                 echo "<tr><td>$gname</td><td>$owner</td><td>$gadmin</td><td><a href=\"$BASE_URL/admin/users/modifygroup/$gid\">Modify</a></td></tr>";
311                                 break;
312                         case "user":
313                                 echo "<tr><td>$gname</td><td>$owner</td><td>$gadmin</td></tr>";
314                                 break;
315                 }
316                 
317                 
318         }
319         echo "</table>";
320         echo "</td></tr></table>";
321 }
322
323
324 ?>