CREATE TABLE groups (
"groups_id" INTEGER PRIMARY KEY AUTOINCREMENT,
"groups_name" TEXT,
+ "groups_description" TEXT,
"groups_is_admin" INTEGER,
"groups_owner_id" INTEGER
)';
return $DB_CONNECTION;
}
+// TODO: we have to define what "Status" is
function gwvp_createUser($email, $fullname, $password, $username, $desc, $status)
{
$conn = gwvp_ConnectDB();
// 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,
$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();
} 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);
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();
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();
$res = $conn->query($sql);
$rn = 0;
+ $gid = false;
foreach($res as $u_res) {
$gid[$rn] = $u_res["groupmember_groupid"];
$rn++;
//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);
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
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>";
}
// 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>";
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;
}
function gwvp_ModifyGroupPageBody()
{
+ global $LOGIN_TYPE, $BASE_URL;
+
$gid = -1;
if(isset($_REQUEST["q"])) {
$query = $_REQUEST["q"];
$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()
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) {