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