implemented authentication levels of anon,user,admin and setup the
[gwvp.git] / gwvplib / gwvpuseradmin.php
index e282fd0..5fe0442 100644 (file)
@@ -26,74 +26,105 @@ function gwvp_UserAdminPage()
 
 function gwvp_UserAdminPageBody()
 {
+       global $LOGIN_TYPE;
+       
        $groups = gwvp_getGroups();
        $users = gwvp_getUsers();
        
-       echo "<h2>User/Group Administration</h2>";
+       echo "<h2>Users and Groups</h2>";
        echo "On this page you can manage users, groups, group membership and update your profile<br>";
        echo "<table>";
        
-       // Header part of table
-       echo "<tr><td valign=\"top\"><h3>My Profile</h3></td><td><h3>My Groups</h3></td></tr>";
-       
-       echo "<tr>";
-       // user profile bit
-       echo "<td valign=\"top\">";
-       echo "User profile bits go here";
-       echo "</td>";
-       
-       // now the group bit for the user
-       echo "<td valign=\"top\">";
-       echo "User owned groups, and groups their a member of go here";
-       echo "</td>";
-       echo "</tr>";
+       echo "<tr><td colspan=\"2\"><hr></td></tr>";
        
        
-       echo "<tr><td valign=\"top\"><h3>Users</h3></td><td><h3>Groups</h3></td></tr>";
-       
-       // create user bit
-       echo "<tr><td valign=\"top\">";
-       
-       echo "Create User<br>";
-       echo "<form method=\"post\">";
-       echo "<table>";
-       echo "<tr><td>EMail</td><td><input type=\"text\" name=\"email\"></td>";
-       echo "<td>Full Name</td><td><input type=\"text\" name=\"fullname\"></td></tr>";
-       echo "<tr><td>Password</td><td><input type=\"text\" name=\"pass1\"></td>";
-       echo "<td>Password Confirm</td><td><input type=\"text\" name=\"pass2\"></td></tr>";
-       echo "<tr><td>Username</td><td><input type=\"text\" name=\"username\"></td>";
-       echo "<td>Description</td><td><input type=\"text\" name=\"desc\"></td></tr>";
-       echo "<tr><td><input type=\"submit\" name=\"Create\" value=\"Create\" class=\"buttons\"></td></tr>";
-       echo "</table>";
-       echo "</form>";
-       
-       echo "</td><td valign=\"top\">";
+       // Header part of table
+       // user self-management bit
+       if($LOGIN_TYPE != "anon") {
+               echo "<tr><td valign=\"top\"><h3>My Profile</h3></td><td><h3>My Groups</h3></td></tr>";
+               
+               echo "<tr>";
+               // user profile bit
+               echo "<td valign=\"top\">";
+               echo "User profile bits go here";
+               echo "</td>";
+               
+               // now the group bit for the user
+               echo "<td valign=\"top\">";
+               echo "User owned groups, and groups their a member of go here";
+               echo "</td>";
+               echo "</tr>";
+               
+               echo "<tr><td colspan=\"2\"><hr></td></tr>";
+       }
        
-       // Create group
-       echo "<form method=\"post\">";
-       echo "<table>";
-       echo "<tr><td>Group Name</td><td><input type=\"text\" name=\"groupname\"><td></tr>";
-       echo "<tr><td>Admin Group?</td><td><input type=\"checkbox\" name=\"admingroup\" class=\"mycheckbox\"></td></tr>";
-       echo "<tr><td>Owner</td><td><div><select class=\"myselect\" name=\"groupowner\">";
-       foreach($users as $u_users) {
-               $uid = $u_users["id"];
-               $email = $u_users["email"];
-               $username = $u_users["username"];
-               $fullname = $u_users["fullname"];
-               echo "<option value=\"$uid\">$username, $fullname ($email)</option>";
+       // admin only bit
+       if($LOGIN_TYPE == "admin") {
+               echo "<tr><td valign=\"top\"><h3>Create User</h3></td><td><h3>Create Group</h3></td></tr>";
+               
+               // create user bit
+               echo "<tr><td valign=\"top\">";
+               
+               echo "<form method=\"post\">";
+               echo "<table>";
+               echo "<tr><td>EMail</td><td><input type=\"text\" name=\"email\"></td>";
+               echo "<td>Full Name</td><td><input type=\"text\" name=\"fullname\"></td></tr>";
+               echo "<tr><td>Password</td><td><input type=\"text\" name=\"pass1\"></td>";
+               echo "<td>Password Confirm</td><td><input type=\"text\" name=\"pass2\"></td></tr>";
+               echo "<tr><td>Username</td><td><input type=\"text\" name=\"username\"></td>";
+               echo "<td>Description</td><td><input type=\"text\" name=\"desc\"></td></tr>";
+               echo "<tr><td><input type=\"submit\" name=\"Create\" value=\"Create\" class=\"buttons\"></td></tr>";
+               echo "</table>";
+               echo "</form>";
+               
+               echo "</td><td valign=\"top\">";
+               
+               // Create group
+               echo "<form method=\"post\">";
+               echo "<table>";
+               echo "<tr><td>Group Name</td><td><input type=\"text\" name=\"groupname\"><td></tr>";
+               echo "<tr><td>Admin Group?</td><td><input type=\"checkbox\" name=\"admingroup\" class=\"mycheckbox\"></td></tr>";
+               echo "<tr><td>Owner</td><td><div><select class=\"myselect\" name=\"groupowner\">";
+               foreach($users as $u_users) {
+                       $uid = $u_users["id"];
+                       $email = $u_users["email"];
+                       $username = $u_users["username"];
+                       $fullname = $u_users["fullname"];
+                       echo "<option value=\"$uid\">$username, $fullname ($email)</option>";
+               }
+               echo "</select></div></td></tr>";
+               
+               
+               
+               echo "<tr><td><input type=\"submit\" name=\"Create\" value=\"Create\" class=\"buttons\"></td></tr>";
+               echo "</table>";
+               echo "</form>";
+               
+               
+               echo "</td></tr>";
+               echo "<tr><td colspan=\"2\"><hr></td></tr>";
        }
-       echo "</select></div></td></tr>";
-       echo "<tr><td><input type=\"submit\" name=\"Create\" value=\"Create\" class=\"buttons\"></td></tr>";
-       echo "</table>";
-       echo "</form>";
        
        
-       echo "</td></tr>";
        
+       // TODO: whats seen here will depend GREATLY on setting in config - need to fix this later
        // user list
+       echo "<tr><td valign=\"top\"><h3>Users</h3></td><td><h3>Groups</h3></td></tr>";
+       
        echo "<tr><td>";
        echo "<table border=\"1\">";
-       echo "<tr><th>EMail</th><th>Username</th><th>Full Name</th><th>In Groups</th><th>Owns Groups</th><th>Description</th><th>Admin?</th><th>Status</th></tr>";
+       switch($LOGIN_TYPE) {
+               case "anon":
+                       echo "<tr><th>Username</th><th>Groups</th><th>Description</th></tr>";
+                       break;
+               case "admin":
+                       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>";
+                       break;
+               case "user":
+                       echo "<tr><th>Username</th><th>Groups</th><th>Description</th></tr>";
+                       break;
+       }
+               
        /*
         *              $returns[$rn]["id"] = $u_res["users_id"];
                $returns[$rn]["fullname"] = $u_res["user_full_name"];
@@ -116,23 +147,43 @@ function gwvp_UserAdminPageBody()
                        $globaladmin = "No";
                }
                
+               
+               // TODO: sort out group prints here
                $ingroups = gwvp_getGroupsForUser($email);
-               $ugroups = "";
-               foreach($ingroups as $grname) {
-                       $ugroups .= "$grname<br>";
-               }
-               trim($ugroups);
                
                $ownedgroups = gwvp_getGroupsOwnedByUser($email);
-               $ogroups = "";
+               $ugroups = "";
                if($ownedgroups == false) $ogroups = "-";
                else {
                        foreach($ownedgroups as $gr_u) {
-                               $ogroups .= "$gr_u ";
+                               $ugroups .= "<font color=\"#3333ff\">$gr_u</font><br>";
+                       }
+               }
+               trim($ugroups);
+               
+               
+               foreach($ingroups as $grname) {
+                       $isownedgroup = false;
+                       foreach($ownedgroups as $gr_u) {
+                               if($grname == $gr_u) $isownedgroup = true;
                        }
+                       if(!$isownedgroup) $ugroups .= "$grname<br>";
                }
+               trim($ugroups);
+               
+               switch($LOGIN_TYPE) {
+                       case "anon":
+                               echo "<tr><td>$username</td><td>$ugroups</td><td>$desc</td></tr>";
+                               break;
+                       case "admin":
+                               echo "<tr><td>$email</td><td>$username</td><td>$fullname</td><td>$ugroups</td><td>$desc</td><td>$globaladmin</td><td>$status</td></tr>";
+                               break;
+                       case "user":
+                               echo "<tr><td>$username</td><td>$ugroups</td><td>$desc</td></tr>";
+                               break;
+               }
+               
                
-               echo "<tr><td>$email</td><td>$username</td><td>$fullname</td><td>$ugroups</td><td>$ogroups</td><td>$desc</td><td>$globaladmin</td><td>$status</td></tr>";
        }
        echo "</table>";
        
@@ -141,7 +192,19 @@ function gwvp_UserAdminPageBody()
        // group part of table
        
        echo "<table border=\"1\">";
-       echo "<tr><th>Group Name</th><th>Owner</th><th>Global Admin Group?</th></tr>";
+       
+       switch($LOGIN_TYPE) {
+               case "anon":
+                       echo "<tr><th>Group Name</th><th>Owner</th></tr>";
+                       break;
+               case "admin":
+                       echo "<tr><th>Group Name</th><th>Owner</th><th>Admin Group?</th></tr>";
+                       break;
+               case "user":
+                       echo "<tr><th>Group Name</th><th>Owner</th><th>Admin Group?</th></tr>";
+                       break;
+       }
+       
        foreach($groups as $u_groups) {
                /*
                 *              $returns[$rn]["id"] = $u_res["groups_id"];
@@ -156,7 +219,20 @@ function gwvp_UserAdminPageBody()
                $owner = gwvp_getUserEmail($u_groups["ownerid"]);
                if($u_groups["admin"]) $gadmin = "Yes";
                else $gadmin  = "No";
-               echo "<tr><td>$gname</td><td>$owner</td><td>$gadmin</td></tr>";
+
+               switch($LOGIN_TYPE) {
+                       case "anon":
+                               echo "<tr><td>$gname</td><td>$owner</td></tr>";
+                               break;
+                       case "admin":
+                               echo "<tr><td>$gname</td><td>$owner</td><td>$gadmin</td></tr>";
+                               break;
+                       case "user":
+                               echo "<tr><td>$gname</td><td>$owner</td><td>$gadmin</td></tr>";
+                               break;
+               }
+               
+               
        }
        echo "</table>";
        echo "</td></tr></table>";