User page code for user/group admin
[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         $groups = gwvp_getGroups();
30         $users = gwvp_getUsers();
31         
32         echo "<h2>User/Group Administration</h2>";
33         echo "On this page you can manage users, groups, group membership and update your profile<br>";
34         echo "<table>";
35         
36         // Header part of table
37         echo "<tr><td valign=\"top\"><h3>My Profile</h3></td><td><h3>My Groups</h3></td></tr>";
38         
39         echo "<tr>";
40         // user profile bit
41         echo "<td valign=\"top\">";
42         echo "User profile bits go here";
43         echo "</td>";
44         
45         // now the group bit for the user
46         echo "<td valign=\"top\">";
47         echo "User owned groups, and groups their a member of go here";
48         echo "</td>";
49         echo "</tr>";
50         
51         
52         echo "<tr><td valign=\"top\"><h3>Users</h3></td><td><h3>Groups</h3></td></tr>";
53         
54         // create user bit
55         echo "<tr><td valign=\"top\">";
56         
57         echo "Create User<br>";
58         echo "<form method=\"post\">";
59         echo "<table>";
60         echo "<tr><td>EMail</td><td><input type=\"text\" name=\"email\"></td>";
61         echo "<td>Full Name</td><td><input type=\"text\" name=\"fullname\"></td></tr>";
62         echo "<tr><td>Password</td><td><input type=\"text\" name=\"pass1\"></td>";
63         echo "<td>Password Confirm</td><td><input type=\"text\" name=\"pass2\"></td></tr>";
64         echo "<tr><td>Nickname</td><td><input type=\"text\" name=\"nick\"></td>";
65         echo "<td>Description</td><td><input type=\"text\" name=\"desc\"></td></tr>";
66         echo "<tr><td><input type=\"submit\" name=\"Create\" value=\"Create\" class=\"buttons\"></td></tr>";
67         echo "</table>";
68         echo "</form>";
69         
70         echo "</td><td valign=\"top\">";
71         
72         // Create group
73         echo "<form method=\"post\">";
74         echo "<table>";
75         echo "<tr><td>Group Name</td><td><input type=\"text\" name=\"groupname\"><td></tr>";
76         echo "<tr><td>Admin Group?</td><td><input type=\"checkbox\" name=\"admingroup\" class=\"mycheckbox\"></td></tr>";
77         echo "<tr><td>Owner</td><td><div><select class=\"myselect\" name=\"groupowner\">";
78         foreach($users as $u_users) {
79                 $uid = $u_users["id"];
80                 $email = $u_users["email"];
81                 $nickname = $u_users["nickname"];
82                 $fullname = $u_users["fullname"];
83                 echo "<option value=\"$uid\">$nickname, $fullname ($email)</option>";
84         }
85         echo "</select></div></td></tr>";
86         echo "<tr><td><input type=\"submit\" name=\"Create\" value=\"Create\" class=\"buttons\"></td></tr>";
87         echo "</table>";
88         echo "</form>";
89         
90         
91         echo "</td></tr>";
92         
93         // user list
94         echo "<tr><td>";
95         echo "<table border=\"1\">";
96         echo "<tr><th>EMail</th><th>Nick Name</th><th>Full Name</th><th>In Groups</th><th>Owns Groups</th><th>Description</th><th>Is Global Admin?</th><th>Status</th></tr>";
97         /*
98          *              $returns[$rn]["id"] = $u_res["users_id"];
99                 $returns[$rn]["fullname"] = $u_res["user_full_name"];
100                 $returns[$rn]["password"] = $u_res["user_password"];
101                 $returns[$rn]["nickname"] = $u_res["user_nickname"];
102                 $returns[$rn]["email"] = $u_res["user_email"];
103                 $returns[$rn]["desc"] = $u_res["user_desc"];
104                 $returns[$rn]["status"] = $u_res["user_status"];
105
106          */
107         foreach($users as $u_users) {
108                 $email = $u_users["email"];
109                 $fullname = $u_users["fullname"];
110                 $nickname = $u_users["nickname"];
111                 $desc = $u_users["desc"];
112                 $status = $u_users["status"];
113                 if(gwvp_IsUserAdmin($email) == 1) {
114                         $globaladmin = "Yes";
115                 } else {
116                         $globaladmin = "No";
117                 }
118                 
119                 $ingroups = gwvp_getGroupsForUser($email);
120                 $ugroups = "";
121                 foreach($ingroups as $grname) {
122                         $ugroups .= "$grname ";
123                 }
124                 trim($ugroups);
125                 
126                 $ownedgroups = gwvp_getGroupsOwnedByUser($email);
127                 $ogroups = "";
128                 if($ownedgroups == false) $ogroups = "-";
129                 else {
130                         foreach($ownedgroups as $gr_u) {
131                                 $ogroups .= "$gr_u ";
132                         }
133                 }
134                 
135                 echo "<tr><td>$email</td><td>$nickname</td><td>$fullname</td><td>$ugroups</td><td>$ogroups</td><td>$desc</td><td>$globaladmin</td><td>$status</td></tr>";
136         }
137         echo "</table>";
138         
139         echo "</td><td valign=\"top\">";
140         
141         // group part of table
142         
143         echo "<table border=\"1\">";
144         echo "<tr><th>Group Name</th><th>Owner</th><th>Global Admin Group?</th></tr>";
145         foreach($groups as $u_groups) {
146                 /*
147                  *              $returns[$rn]["id"] = $u_res["groups_id"];
148                 $returns[$rn]["name"] = $u_res["groups_name"];
149                 if($u_res["groups_is_admin"]=="1") $return[$rn]["admin"] = true;
150                 else $return[$rn]["admin"] = false;
151                 $returns[$rn]["admin"] = $u_res["groups_is_admin"];
152                 $returns[$rn]["ownerid"] = $u_res["groups_owner_id"];
153
154                  */
155                 $gname = $u_groups["name"];
156                 $owner = gwvp_getUserEmail($u_groups["ownerid"]);
157                 if($u_groups["admin"]) $gadmin = "Yes";
158                 else $gadmin  = "No";
159                 echo "<tr><td>$gname</td><td>$owner</td><td>$gadmin</td></tr>";
160         }
161         echo "</table>";
162         echo "</td></tr></table>";
163 }
164
165
166 ?>