working on the user/group administration page.
authorpaulr <me@pjr.cc>
Sat, 5 Nov 2011 15:41:50 +0000 (02:41 +1100)
committerpaulr <me@pjr.cc>
Sat, 5 Nov 2011 15:41:50 +0000 (02:41 +1100)
- group membership
- group creation
- group modifications
- user createion

gwvplib/gwvpdatabase.php
gwvplib/gwvpdebug.php
gwvplib/gwvplib.php
gwvplib/gwvprepoadmin.php
gwvplib/gwvpuseradmin.php

index d9b51cd..a79adb0 100644 (file)
@@ -26,6 +26,7 @@ function gwvp_dbCreateSQLiteStructure($dbloc)
                CREATE TABLE groups (
            "groups_id" INTEGER PRIMARY KEY AUTOINCREMENT,
            "groups_name" TEXT,
+           "groups_description" TEXT,
            "groups_is_admin" INTEGER,
                "groups_owner_id" INTEGER
                )';
@@ -118,6 +119,7 @@ function gwvp_ConnectDB()
        return $DB_CONNECTION;
 }
 
+// TODO: we have to define what "Status" is
 function gwvp_createUser($email, $fullname, $password, $username, $desc, $status)
 {
        $conn = gwvp_ConnectDB();
@@ -125,7 +127,9 @@ function gwvp_createUser($email, $fullname, $password, $username, $desc, $status
        // TODO: change from sha1
        $shapass = sha1($password);
        //error_log("Create user called with $email");
-       $conn->query("insert into users values (null, '$fullname', '$shapass', '$username', '$email', '$desc', '$status')");
+       $sql = "insert into users values (null, '$fullname', '$shapass', '$username', '$email', '$desc', '$status')";
+       error_log("Creating user, $sql");
+       return $conn->query($sql);
        /*
         *          "users_id" INTEGER PRIMARY KEY AUTOINCREMENT,
         "user_full_name" TEXT,
@@ -196,7 +200,7 @@ function gwvp_deleteUser($email)
        $conn->query($sql);
 }
 
-function gwvp_createGroup($group_name, $is_admin, $owner_id)
+function gwvp_createGroup($group_name, $group_desc, $is_admin, $owner_id)
 {
        $conn = gwvp_ConnectDB();
 
@@ -214,7 +218,8 @@ function gwvp_createGroup($group_name, $is_admin, $owner_id)
        } else {
                $is_admin_t = 0;
        }
-       $sql = "insert into groups values( null, '$group_name', '$is_admin_t', '$owner_id')";
+       $sql = "insert into groups values( null, '$group_name', '$group_desc', '$is_admin_t', '$owner_id')";
+       
 
        $conn->query($sql);
 
@@ -350,6 +355,39 @@ function gwvp_getGroupId($groupname)
        return $return;
 }
 
+function gwvp_getGroup($gid)
+{
+       /* 
+        *      $groupsql = '
+               CREATE TABLE groups (
+           "groups_id" INTEGER PRIMARY KEY AUTOINCREMENT,
+           "groups_name" TEXT,
+           "groups_is_admin" INTEGER,
+               "groups_owner_id" INTEGER
+               )';
+
+        */
+       $conn = gwvp_ConnectDB();
+       
+       $sql = "select * from groups where groups_id='$gid'";
+       
+       $res = $conn->query($sql);
+       $return = false;
+       foreach($res as $u_res) {
+               $return["id"] = $u_res["groups_id"];
+               $return["name"] = $u_res["groups_name"];
+               if($u_res["groups_is_admin"] == 1) {
+                       $return["isadmin"] = true;
+               } else {
+                       $return["isadmin"] = false;
+               }
+               $return["ownerid"] = $u_res["groups_owner_id"];
+               $return["description"] = $u_res["groups_description"];
+       }
+       
+       return $return;
+}
+
 function gwvp_getUserId($useremail=null, $username = null)
 {
        $conn = gwvp_ConnectDB();
@@ -369,6 +407,26 @@ function gwvp_getUserId($useremail=null, $username = null)
        return $return;
 }
 
+function gwvp_getUserName($id = null, $email=null)
+{
+       $conn = gwvp_ConnectDB();
+
+       if($email != null) { 
+               $sql = "select user_username from users where user_email='$email'";
+       } else if($id != null) {
+               $sql = "select user_username from users where users_id='$id'";
+       } else return false;
+
+       $res = $conn->query($sql);
+       $return = false;
+       foreach($res as $u_res) {
+               $return = $u_res["user_username"];
+       }
+
+       return $return;
+}
+
+
 function gwvp_getUserEmail($id)
 {
        $conn = gwvp_ConnectDB();
@@ -447,6 +505,7 @@ function gwvp_IsUserAdmin($email=null, $username = null)
 
        $res = $conn->query($sql);
        $rn = 0;
+       $gid = false;
        foreach($res as $u_res) {
                $gid[$rn] = $u_res["groupmember_groupid"];
                $rn++;
index d9f787d..ee44f40 100644 (file)
@@ -94,13 +94,20 @@ function gwvp_DebugCall()
                                        //gwvp_createUser($email, $fullname, $password, $username, $desc, $status)
                                        //gwvp_addGroupMember($email, $groupname)
                                        gwvp_createUser("admin@localhost", "adminer", "password", "admin", "initial admin user", 0);
-                                       gwvp_createGroup("admingroup", 1, gwvp_getUserId("admin@localhost"));
+                                       $adminid = gwvp_getUserId("admin@localhost");
+                                       gwvp_createGroup("admingroup", "admingroup", 1, $adminid);
+                                       error_log("adminid is $adminid");
                                        gwvp_addGroupMember("admin@localhost", "admingroup");
                                        gwvp_createUser("user@localhost", "userer", "password", "user", "initial pleb user", 0);
-                                       gwvp_createGroup("usergroup", 0, gwvp_getUserId("user@localhost"));
+                                       $userid = gwvp_getUserId("user@localhost");
+                                       error_log("userid is $userid");
+                                       gwvp_createGroup("usergroup", "usergroup", 0, $userid);
                                        gwvp_addGroupMember("user@localhost", "usergroup");
                                        gwvp_SendMessage("info", "blank db re-created");
                                        
+                                       gwvp_createGitRepo("repo1");
+                                       gwvp_createGitRepo("repo2");
+                                       gwvp_createGitRepo("repo3");
                                        gwvp_AddRepo("repo1", "this is a test repo1", 1);
                                        gwvp_AddRepo("repo2", "this is a test repo2", 1);
                                        gwvp_AddRepo("repo2", "this is a test repo3", 1);
index 526c9cc..693486c 100644 (file)
@@ -15,7 +15,7 @@ require_once("gwvpgitcontrol.php");
 require_once("gwvppluginloader.php");
 
 // only enable this if you need it:
-// require_once("gwvpdebug.php");
+require_once("gwvpdebug.php");
 
 
 ?>
\ No newline at end of file
index 7a0b10c..9ead6d3 100644 (file)
@@ -82,10 +82,27 @@ function gwvp_CreateRepoPageBody()
        echo "<h2>Create a Repo</h2>";
        echo "<form method=\"post\" enctype=\"multipart/form-data\" action=\"$BASE_URL/admin/repos/docreate\">";
        echo "<table>";
-       echo "<tr><td>Repository Name</td><td><input type=\"text\" name=\"reponame\" value=\"$reponameobv\"></td></tr>";
-       echo "<tr><td>Repository Description</td><td><input type=\"text\" name=\"repodesc\" value=\"$repodescobv\"></td></tr>";
-       echo "<tr><td>Repository Bundle</td><td><input type=\"file\" name=\"bundlefile\"></td><td><i>Create a bundle for pro-creating the git repository (export your git bundle with \"git bundle create /tmp/filename --branches\")</i></td></tr>";
+       echo "<tr><td>Repository Name</td><td bgcolor=\"#eeeeee\"><input type=\"text\" name=\"reponame\" value=\"$reponameobv\"></td></tr>";
+       echo "<tr><td>Repository Description</td><td bgcolor=\"#eeeeee\"><input type=\"text\" name=\"repodesc\" value=\"$repodescobv\"></td></tr>";
+       echo "<tr><td>Repository Bundle</td><td bgcolor=\"#eeeeee\"><input type=\"file\" name=\"bundlefile\"></td><td><i>Create a bundle for pro-creating the git repository (export your git bundle with \"git bundle create /tmp/filename --branches\")</i></td></tr>";
+       
+       echo "<tr><td>Default Permisison Set</td><td bgcolor=\"#eeeeee\">";
+       
+       echo "<table>";
+       echo "<tr><td><input type=\"checkbox\" name=\"permsall\" checked></td><td>Anyone Can Read, Only you can write</td></tr>";
+       echo "<tr><td><input type=\"checkbox\" name=\"permsmeonly\"></td><td>Anyone can see the repository exists, but only you can read or write to it</td></tr>";
+       echo "<tr><td><input type=\"checkbox\" name=\"permsinvisible\"></td><td>Repository only visible to you</td></tr>";
+       echo "</table>";
+       
+       
+       echo "</td><td><i>Permissions can be changed in repository management later</i></td></tr>";
+       
        echo "</table>";
+       
+       
+       
+       
+       
        echo "<input type=\"submit\" name=\"create\" value=\"Create\"><br>";
        echo "</form>";
 }
@@ -103,12 +120,13 @@ function gwvp_RepoAdminPageBody()
        // i must also remember that the home page will also contain a list of repos and that this page is solely for maintance
        // and creation of repos - so i dont need to get over-worked about the info stored on this page outside of those activities
        $rlist = gwvp_GetRepoList();
-       echo "<table border=\"1\"><tr><th>Repo Name</th><th>Repo Description</th><th>Repo Owner</th></tr>";
+       echo "<table border=\"1\"><tr><th>Repo Name</th><th>Repo Description</th><th>Repo Owner</th><th>Control</th></tr>";
        foreach($rlist as $u_res) {
+               $rid = $u_res["id"];
                $rname = $u_res["name"];
                $rdesc = $u_res["description"];
-               $rown = $u_res["owner"];
-               echo "<tr><td>$rname</td><td>$rdesc</td><td>$rown</td></tr>";
+               $rown = gwvp_getUserName($u_res["owner"]);
+               echo "<tr><td>$rname</td><td>$rdesc</td><td>$rown</td><td><a href=\"$BASE_URL/admin/repos/modify/$rid\">Modify</a></td></tr>";
        }
        echo "</table>";
        
index d39aeae..7ccfb9b 100644 (file)
@@ -44,11 +44,59 @@ function gwvp_UserAdminCallMe()
 
 function gwvp_AddUserPage()
 {
+       global $BASE_URL;
+       
+       $email = $_REQUEST["email"];
+       $fullname = $_REQUEST["fullname"];
+       $pass1 = $_REQUEST["pass1"];
+       $pass2 = $_REQUEST["pass2"];
+       $username = $_REQUEST["username"];
+       $desc = $_REQUEST["desc"];
+       
+       // TODO: we need to do alot of checking here - that can come later
+       if(gwvp_createUser($email, $fullname, $pass1, $username, $desc, 0)) {
+               gwvp_SendMessage("info", "user $username, $fullname ($email) created");
+               header("Location: $BASE_URL/admin/users");
+               return;
+       } else {
+               gwvp_SendMessage("error", "error creating user for some unknown reason");
+               header("Location: $BASE_URL/admin/users");
+               return;
+       }
+
+       
+       /*
+               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>";
+               */
        
 }
 
 function gwvp_AddGroupPage()
 {
+       /*
+        *              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\">";
+
+        */
+       global $BASE_URL;
+       
+       $gname = $_REQUEST["groupname"];
+       $isadmin = isset($_REQUEST["admingroup"]);
+       $gdesc = $_REQUEST["groupdesc"];
+       $owner = $_REQUEST["groupowner"];
+       
+       // gwvp_createGroup($group_name, $is_admin, $owner_id)
+       gwvp_createGroup("$gname", $gdesc, $isadmin, $owner);
+       
+       
+       header("Location: $BASE_URL/admin/users");
+       return;
        
 }
 
@@ -88,6 +136,8 @@ function gwvp_ModifyUserPageBody()
 
 function gwvp_ModifyGroupPageBody()
 {
+       global $LOGIN_TYPE, $BASE_URL;
+       
        $gid = -1;
        if(isset($_REQUEST["q"])) {
                $query = $_REQUEST["q"];
@@ -95,7 +145,82 @@ function gwvp_ModifyGroupPageBody()
                $gid = $qspl[3];
        }
        
-       echo "modify group $gid";
+       $users = gwvp_getUsers();
+       
+       $ginfo = gwvp_getGroup($gid);
+       $groupname = $ginfo["name"];
+       $groupdesc = $ginfo["description"];
+       if($ginfo["isadmin"]) $admin = "checked";
+       else $admin = "";
+       
+       echo "<h2>Modify Group - $groupname</h2>";
+       echo "<form method=\"post\" action=\"$BASE_URL/admin/users/groupmodify/$gid\">";
+       echo "<table>";
+       echo "<tr><td>Description</td><td><input type=\"text\" name=\"groupdesc\" value=\"$groupdesc\"></td></tr>";
+       echo "<tr><td>Admin</td><td><input type=\"checkbox\" name=\"is_admin\" $admin></td></tr>";
+       echo "<tr><td><input type=\"submit\" name=\"change\" value=\"Change\"></td></tr>";
+       
+       echo "</table>";
+       echo "</form>";
+       
+       echo "<h3>Group Membership</h3>";
+       echo "<form method=\"post\" action=\"$BASE_URL/admin/users/groupmember/$gid\">";
+       echo "<table border=\"1\"><tr><th>Members</th><th></th><th>All Users</th></tr>";
+       
+       echo "<tr><td>";
+       
+       
+       // members
+       echo "<select name=\"members\" size=\"20\" multiple>";
+       foreach($users as $u_users) {
+               $uid = $u_users["id"];
+               $email = $u_users["email"];
+               $username = $u_users["username"];
+               $fullname = $u_users["fullname"];
+               if(gwvp_IsGroupMember($email, $groupname)) {
+                       echo "<option value=\"$uid\">$username, $fullname ($email)</option>";
+               }
+               
+
+       }
+       
+       echo "</select>";
+       
+       
+       echo "</td><td>";
+       
+       // move buttons
+       echo "<input type=\"submit\" name=\"add\" value=\"<<\"><br>";
+       echo "<input type=\"submit\" name=\"remove\" value=\">>\"><br>";
+
+       
+       
+       echo "</td><td>";
+       
+       
+       // all users
+       echo "<select name=\"members\" size=\"20\" multiple>";
+       foreach($users as $u_users) {
+               $uid = $u_users["id"];
+               $email = $u_users["email"];
+               $username = $u_users["username"];
+               $fullname = $u_users["fullname"];
+               if(!gwvp_IsGroupMember($email, $groupname)) {
+                       echo "<option value=\"$uid\">$username, $fullname ($email)</option>";
+               }
+       }
+       echo "</select>";
+       
+       
+       
+       echo "</td></tr></table>";
+       echo "</form>";
+       
+       
+       
+       
+       
+       return;
 }
 
 function gwvp_UserAdminPageBody()
@@ -157,6 +282,7 @@ function gwvp_UserAdminPageBody()
                echo "<form method=\"post\" action=\"$BASE_URL/admin/users/addgroup\">";
                echo "<table>";
                echo "<tr><td>Group Name</td><td><input type=\"text\" name=\"groupname\"><td></tr>";
+               echo "<tr><td>Group Description</td><td><input type=\"text\" name=\"groupdesc\"><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) {