From 74399e0d5226d43656c618451b4e6fc06702e5ab Mon Sep 17 00:00:00 2001 From: paulr Date: Sun, 6 Nov 2011 02:41:50 +1100 Subject: [PATCH] working on the user/group administration page. - group membership - group creation - group modifications - user createion --- gwvplib/gwvpdatabase.php | 65 ++++++++++++++++++++++- gwvplib/gwvpdebug.php | 11 +++- gwvplib/gwvplib.php | 2 +- gwvplib/gwvprepoadmin.php | 30 ++++++++-- gwvplib/gwvpuseradmin.php | 128 ++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 223 insertions(+), 13 deletions(-) diff --git a/gwvplib/gwvpdatabase.php b/gwvplib/gwvpdatabase.php index d9b51cd..a79adb0 100644 --- a/gwvplib/gwvpdatabase.php +++ b/gwvplib/gwvpdatabase.php @@ -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++; diff --git a/gwvplib/gwvpdebug.php b/gwvplib/gwvpdebug.php index d9f787d..ee44f40 100644 --- a/gwvplib/gwvpdebug.php +++ b/gwvplib/gwvpdebug.php @@ -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); diff --git a/gwvplib/gwvplib.php b/gwvplib/gwvplib.php index 526c9cc..693486c 100644 --- a/gwvplib/gwvplib.php +++ b/gwvplib/gwvplib.php @@ -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 diff --git a/gwvplib/gwvprepoadmin.php b/gwvplib/gwvprepoadmin.php index 7a0b10c..9ead6d3 100644 --- a/gwvplib/gwvprepoadmin.php +++ b/gwvplib/gwvprepoadmin.php @@ -82,10 +82,27 @@ function gwvp_CreateRepoPageBody() echo "

Create a Repo

"; echo "
"; echo ""; - echo ""; - echo ""; - echo ""; + echo ""; + echo ""; + echo ""; + + echo ""; + echo "
Repository Name
Repository Description
Repository BundleCreate a bundle for pro-creating the git repository (export your git bundle with \"git bundle create /tmp/filename --branches\")
Repository Name
Repository Description
Repository BundleCreate a bundle for pro-creating the git repository (export your git bundle with \"git bundle create /tmp/filename --branches\")
Default Permisison Set"; + + echo ""; + echo ""; + echo ""; + echo ""; + echo "
Anyone Can Read, Only you can write
Anyone can see the repository exists, but only you can read or write to it
Repository only visible to you
"; + + + echo "
Permissions can be changed in repository management later
"; + + + + + echo "
"; echo "
"; } @@ -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 ""; + echo "
Repo NameRepo DescriptionRepo Owner
"; foreach($rlist as $u_res) { + $rid = $u_res["id"]; $rname = $u_res["name"]; $rdesc = $u_res["description"]; - $rown = $u_res["owner"]; - echo ""; + $rown = gwvp_getUserName($u_res["owner"]); + echo ""; } echo "
Repo NameRepo DescriptionRepo OwnerControl
$rname$rdesc$rown
$rname$rdesc$rownModify
"; diff --git a/gwvplib/gwvpuseradmin.php b/gwvplib/gwvpuseradmin.php index d39aeae..7ccfb9b 100644 --- a/gwvplib/gwvpuseradmin.php +++ b/gwvplib/gwvpuseradmin.php @@ -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 "EMail"; + echo "Full Name"; + echo "Password"; + echo "Password Confirm"; + echo "Username"; + echo "Description"; + */ } function gwvp_AddGroupPage() { + /* + * echo "Group Name"; + echo "Admin Group?"; + echo "Owner
"; + echo "Admin"; + echo ""; + + echo ""; + echo ""; + + echo "

Group Membership

"; + echo "
"; + echo ""; + + echo "
MembersAll Users
"; + + + // members + echo ""; + + + echo ""; + + // move buttons + echo "
"; + echo ">\">
"; + + + + echo "
"; + + + // all users + echo ""; + + + + echo "
"; + echo "
"; + + + + + + return; } function gwvp_UserAdminPageBody() @@ -157,6 +282,7 @@ function gwvp_UserAdminPageBody() echo "
"; echo ""; echo ""; + echo ""; echo ""; echo "
Group Name
Group Description
Admin Group?
Owner