5fe0442208c99558c5cf16f7deb57b99380f9818
[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                 if($query == "admin/users") return "gwvp_UserAdminPage";
15                 else return false;
16         }
17         
18         return false;
19 }
20
21 function gwvp_UserAdminPage()
22 {
23         gwvp_goMainPage("gwvp_UserAdminPageBody");
24 }
25
26
27 function gwvp_UserAdminPageBody()
28 {
29         global $LOGIN_TYPE;
30         
31         $groups = gwvp_getGroups();
32         $users = gwvp_getUsers();
33         
34         echo "<h2>Users and Groups</h2>";
35         echo "On this page you can manage users, groups, group membership and update your profile<br>";
36         echo "<table>";
37         
38         echo "<tr><td colspan=\"2\"><hr></td></tr>";
39         
40         
41         // Header part of table
42         // user self-management bit
43         if($LOGIN_TYPE != "anon") {
44                 echo "<tr><td valign=\"top\"><h3>My Profile</h3></td><td><h3>My Groups</h3></td></tr>";
45                 
46                 echo "<tr>";
47                 // user profile bit
48                 echo "<td valign=\"top\">";
49                 echo "User profile bits go here";
50                 echo "</td>";
51                 
52                 // now the group bit for the user
53                 echo "<td valign=\"top\">";
54                 echo "User owned groups, and groups their a member of go here";
55                 echo "</td>";
56                 echo "</tr>";
57                 
58                 echo "<tr><td colspan=\"2\"><hr></td></tr>";
59         }
60         
61         // admin only bit
62         if($LOGIN_TYPE == "admin") {
63                 echo "<tr><td valign=\"top\"><h3>Create User</h3></td><td><h3>Create Group</h3></td></tr>";
64                 
65                 // create user bit
66                 echo "<tr><td valign=\"top\">";
67                 
68                 echo "<form method=\"post\">";
69                 echo "<table>";
70                 echo "<tr><td>EMail</td><td><input type=\"text\" name=\"email\"></td>";
71                 echo "<td>Full Name</td><td><input type=\"text\" name=\"fullname\"></td></tr>";
72                 echo "<tr><td>Password</td><td><input type=\"text\" name=\"pass1\"></td>";
73                 echo "<td>Password Confirm</td><td><input type=\"text\" name=\"pass2\"></td></tr>";
74                 echo "<tr><td>Username</td><td><input type=\"text\" name=\"username\"></td>";
75                 echo "<td>Description</td><td><input type=\"text\" name=\"desc\"></td></tr>";
76                 echo "<tr><td><input type=\"submit\" name=\"Create\" value=\"Create\" class=\"buttons\"></td></tr>";
77                 echo "</table>";
78                 echo "</form>";
79                 
80                 echo "</td><td valign=\"top\">";
81                 
82                 // Create group
83                 echo "<form method=\"post\">";
84                 echo "<table>";
85                 echo "<tr><td>Group Name</td><td><input type=\"text\" name=\"groupname\"><td></tr>";
86                 echo "<tr><td>Admin Group?</td><td><input type=\"checkbox\" name=\"admingroup\" class=\"mycheckbox\"></td></tr>";
87                 echo "<tr><td>Owner</td><td><div><select class=\"myselect\" name=\"groupowner\">";
88                 foreach($users as $u_users) {
89                         $uid = $u_users["id"];
90                         $email = $u_users["email"];
91                         $username = $u_users["username"];
92                         $fullname = $u_users["fullname"];
93                         echo "<option value=\"$uid\">$username, $fullname ($email)</option>";
94                 }
95                 echo "</select></div></td></tr>";
96                 
97                 
98                 
99                 echo "<tr><td><input type=\"submit\" name=\"Create\" value=\"Create\" class=\"buttons\"></td></tr>";
100                 echo "</table>";
101                 echo "</form>";
102                 
103                 
104                 echo "</td></tr>";
105                 echo "<tr><td colspan=\"2\"><hr></td></tr>";
106         }
107         
108         
109         
110         // TODO: whats seen here will depend GREATLY on setting in config - need to fix this later
111         // user list
112         echo "<tr><td valign=\"top\"><h3>Users</h3></td><td><h3>Groups</h3></td></tr>";
113         
114         echo "<tr><td>";
115         echo "<table border=\"1\">";
116         switch($LOGIN_TYPE) {
117                 case "anon":
118                         echo "<tr><th>Username</th><th>Groups</th><th>Description</th></tr>";
119                         break;
120                 case "admin":
121                         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>";
122                         break;
123                 case "user":
124                         echo "<tr><th>Username</th><th>Groups</th><th>Description</th></tr>";
125                         break;
126         }
127                 
128         /*
129          *              $returns[$rn]["id"] = $u_res["users_id"];
130                 $returns[$rn]["fullname"] = $u_res["user_full_name"];
131                 $returns[$rn]["password"] = $u_res["user_password"];
132                 $returns[$rn]["username"] = $u_res["user_username"];
133                 $returns[$rn]["email"] = $u_res["user_email"];
134                 $returns[$rn]["desc"] = $u_res["user_desc"];
135                 $returns[$rn]["status"] = $u_res["user_status"];
136
137          */
138         foreach($users as $u_users) {
139                 $email = $u_users["email"];
140                 $fullname = $u_users["fullname"];
141                 $username = $u_users["username"];
142                 $desc = $u_users["desc"];
143                 $status = $u_users["status"];
144                 if(gwvp_IsUserAdmin($email) == 1) {
145                         $globaladmin = "Yes";
146                 } else {
147                         $globaladmin = "No";
148                 }
149                 
150                 
151                 // TODO: sort out group prints here
152                 $ingroups = gwvp_getGroupsForUser($email);
153                 
154                 $ownedgroups = gwvp_getGroupsOwnedByUser($email);
155                 $ugroups = "";
156                 if($ownedgroups == false) $ogroups = "-";
157                 else {
158                         foreach($ownedgroups as $gr_u) {
159                                 $ugroups .= "<font color=\"#3333ff\">$gr_u</font><br>";
160                         }
161                 }
162                 trim($ugroups);
163                 
164                 
165                 foreach($ingroups as $grname) {
166                         $isownedgroup = false;
167                         foreach($ownedgroups as $gr_u) {
168                                 if($grname == $gr_u) $isownedgroup = true;
169                         }
170                         if(!$isownedgroup) $ugroups .= "$grname<br>";
171                 }
172                 trim($ugroups);
173                 
174                 switch($LOGIN_TYPE) {
175                         case "anon":
176                                 echo "<tr><td>$username</td><td>$ugroups</td><td>$desc</td></tr>";
177                                 break;
178                         case "admin":
179                                 echo "<tr><td>$email</td><td>$username</td><td>$fullname</td><td>$ugroups</td><td>$desc</td><td>$globaladmin</td><td>$status</td></tr>";
180                                 break;
181                         case "user":
182                                 echo "<tr><td>$username</td><td>$ugroups</td><td>$desc</td></tr>";
183                                 break;
184                 }
185                 
186                 
187         }
188         echo "</table>";
189         
190         echo "</td><td valign=\"top\">";
191         
192         // group part of table
193         
194         echo "<table border=\"1\">";
195         
196         switch($LOGIN_TYPE) {
197                 case "anon":
198                         echo "<tr><th>Group Name</th><th>Owner</th></tr>";
199                         break;
200                 case "admin":
201                         echo "<tr><th>Group Name</th><th>Owner</th><th>Admin Group?</th></tr>";
202                         break;
203                 case "user":
204                         echo "<tr><th>Group Name</th><th>Owner</th><th>Admin Group?</th></tr>";
205                         break;
206         }
207         
208         foreach($groups as $u_groups) {
209                 /*
210                  *              $returns[$rn]["id"] = $u_res["groups_id"];
211                 $returns[$rn]["name"] = $u_res["groups_name"];
212                 if($u_res["groups_is_admin"]=="1") $return[$rn]["admin"] = true;
213                 else $return[$rn]["admin"] = false;
214                 $returns[$rn]["admin"] = $u_res["groups_is_admin"];
215                 $returns[$rn]["ownerid"] = $u_res["groups_owner_id"];
216
217                  */
218                 $gname = $u_groups["name"];
219                 $owner = gwvp_getUserEmail($u_groups["ownerid"]);
220                 if($u_groups["admin"]) $gadmin = "Yes";
221                 else $gadmin  = "No";
222
223                 switch($LOGIN_TYPE) {
224                         case "anon":
225                                 echo "<tr><td>$gname</td><td>$owner</td></tr>";
226                                 break;
227                         case "admin":
228                                 echo "<tr><td>$gname</td><td>$owner</td><td>$gadmin</td></tr>";
229                                 break;
230                         case "user":
231                                 echo "<tr><td>$gname</td><td>$owner</td><td>$gadmin</td></tr>";
232                                 break;
233                 }
234                 
235                 
236         }
237         echo "</table>";
238         echo "</td></tr></table>";
239 }
240
241
242 ?>