added a modify line to groups for admin users
[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                 $userid = $u_users["id"];
140                 $email = $u_users["email"];
141                 $fullname = $u_users["fullname"];
142                 $username = $u_users["username"];
143                 $desc = $u_users["desc"];
144                 $status = $u_users["status"];
145                 if(gwvp_IsUserAdmin($email) == 1) {
146                         $globaladmin = "Yes";
147                 } else {
148                         $globaladmin = "No";
149                 }
150                 
151                 
152                 // TODO: sort out group prints here
153                 $ingroups = gwvp_getGroupsForUser($email);
154                 
155                 $ownedgroups = gwvp_getGroupsOwnedByUser($email);
156                 $ugroups = "";
157                 if($ownedgroups == false) $ogroups = "-";
158                 else {
159                         foreach($ownedgroups as $gr_u) {
160                                 $ugroups .= "<font color=\"#3333ff\">$gr_u</font><br>";
161                         }
162                 }
163                 trim($ugroups);
164                 
165                 
166                 foreach($ingroups as $grname) {
167                         $isownedgroup = false;
168                         foreach($ownedgroups as $gr_u) {
169                                 if($grname == $gr_u) $isownedgroup = true;
170                         }
171                         if(!$isownedgroup) $ugroups .= "$grname<br>";
172                 }
173                 trim($ugroups);
174                 
175                 switch($LOGIN_TYPE) {
176                         case "anon":
177                                 echo "<tr><td>$username</td><td>$ugroups</td><td>$desc</td></tr>";
178                                 break;
179                         case "admin":
180                                 echo "<tr><td>$email</td><td>$username</td><td>$fullname</td><td>$ugroups</td><td>$desc</td>";
181                                 echo "<td>$globaladmin</td><td>$status</td><td><a href=\"$BASE_URL/users/modify?id=$userid\">Modify</a></td></tr>";
182                                 break;
183                         case "user":
184                                 echo "<tr><td>$username</td><td>$ugroups</td><td>$desc</td></tr>";
185                                 break;
186                 }
187                 
188                 
189         }
190         echo "</table>";
191         
192         echo "</td><td valign=\"top\">";
193         
194         // group part of table
195         
196         echo "<table border=\"1\">";
197         
198         switch($LOGIN_TYPE) {
199                 case "anon":
200                         echo "<tr><th>Group Name</th><th>Owner</th></tr>";
201                         break;
202                 case "admin":
203                         echo "<tr><th>Group Name</th><th>Owner</th><th>Admin Group?</th><th>Modify</th></tr>";
204                         break;
205                 case "user":
206                         echo "<tr><th>Group Name</th><th>Owner</th><th>Admin Group?</th></tr>";
207                         break;
208         }
209         
210         foreach($groups as $u_groups) {
211                 /*
212                  *              $returns[$rn]["id"] = $u_res["groups_id"];
213                 $returns[$rn]["name"] = $u_res["groups_name"];
214                 if($u_res["groups_is_admin"]=="1") $return[$rn]["admin"] = true;
215                 else $return[$rn]["admin"] = false;
216                 $returns[$rn]["admin"] = $u_res["groups_is_admin"];
217                 $returns[$rn]["ownerid"] = $u_res["groups_owner_id"];
218
219                  */
220                 $gname = $u_groups["name"];
221                 $gid = $u_groups["id"];
222                 $owner = gwvp_getUserEmail($u_groups["ownerid"]);
223                 if($u_groups["admin"]) $gadmin = "Yes";
224                 else $gadmin  = "No";
225
226                 switch($LOGIN_TYPE) {
227                         case "anon":
228                                 echo "<tr><td>$gname</td><td>$owner</td></tr>";
229                                 break;
230                         case "admin":
231                                 echo "<tr><td>$gname</td><td>$owner</td><td>$gadmin</td><td><a href=\"$BASE_URL/users/modifygroup?groupid=$gid\">Modify</a></td></tr>";
232                                 break;
233                         case "user":
234                                 echo "<tr><td>$gname</td><td>$owner</td><td>$gadmin</td></tr>";
235                                 break;
236                 }
237                 
238                 
239         }
240         echo "</table>";
241         echo "</td></tr></table>";
242 }
243
244
245 ?>