group membership can now be modified
authorpaulr <me@pjr.cc>
Sat, 5 Nov 2011 17:03:40 +0000 (04:03 +1100)
committerpaulr <me@pjr.cc>
Sat, 5 Nov 2011 17:03:40 +0000 (04:03 +1100)
gwvplib/gwvpdatabase.php
gwvplib/gwvpdebug.php
gwvplib/gwvpuseradmin.php

index a79adb0..065b406 100644 (file)
@@ -79,6 +79,14 @@ function gwvp_dbCreateSQLiteStructure($dbloc)
        $DB_CONNECTION->query($groupmemsql);
 }
 
+function gwvp_forceDisconnect()
+{
+       
+       global $DB_CONNECTION;
+       
+       $DB_CONNECTION = false;
+}
+
 function gwvp_isDBSetup()
 {
        // for sqlite, we just check if the db exists, for everyone else, we check for a conneciton and go yay or nay
@@ -442,6 +450,44 @@ function gwvp_getUserEmail($id)
        return $return;
 }
 
+function gwvp_deleteGroupMemberByID($uid, $gid)
+{
+       $conn = gwvp_ConnectDB();
+
+       /*
+        *              CREATE TABLE "group_membership" (
+        "groupmember_id" INTEGER PRIMARY KEY AUTOINCREMENT,
+        "groupmember_groupid" INTEGER,
+        "groupmember_userid" INTEGER
+
+        */
+       $sql = "delete from group_membership where groupmember_groupid='$gid' and  groupmember_userid='$uid'";
+
+       $conn->query($sql);
+
+       return true;
+}
+
+
+function gwvp_addGroupMemberByID($uid, $gid)
+{
+       $conn = gwvp_ConnectDB();
+
+       /*
+        *              CREATE TABLE "group_membership" (
+        "groupmember_id" INTEGER PRIMARY KEY AUTOINCREMENT,
+        "groupmember_groupid" INTEGER,
+        "groupmember_userid" INTEGER
+
+        */
+       $sql = "insert into group_membership values (null, '$gid', '$uid')";
+
+       $conn->query($sql);
+
+       return true;
+}
+
+
 function gwvp_addGroupMember($email, $groupname)
 {
        $conn = gwvp_ConnectDB();
@@ -456,7 +502,7 @@ function gwvp_addGroupMember($email, $groupname)
         "groupmember_userid" INTEGER
 
         */
-       if($uid!=false&&$gid!=false) $sql = "insert into group_membership values (null, '$gid', '$uid')";
+       if($uid!=false&&$gid!=false) gwvp_addGroupMemberByID($uid, $gid);
        else return false;
 
        $conn->query($sql);
index ee44f40..a957a93 100644 (file)
@@ -88,7 +88,8 @@ function gwvp_DebugCall()
                                        break;
                                case "recreatedb":
                                        global $db_name;
-                                       unlink("$db_name");
+                                       gwvp_forceDisconnect();
+                                       rename("$db_name", "$db_name.tmp");
                                        gwvp_dbCreateSQLiteStructure("$db_name");
                                        //gwvp_createGroup($group_name, $is_admin, $owner_id)
                                        //gwvp_createUser($email, $fullname, $password, $username, $desc, $status)
index 7ccfb9b..171778f 100644 (file)
@@ -19,6 +19,9 @@ function gwvp_UserAdminCallMe()
                                                case "adduser":
                                                        return "gwvp_AddUserPage";
                                                        break;
+                                               case "groupmember":
+                                                       return "gwvp_groupMemberChange";
+                                                       break;
                                                case "addgroup":
                                                        return "gwvp_AddGroupPage";
                                                        break;
@@ -93,6 +96,8 @@ function gwvp_AddGroupPage()
        
        // gwvp_createGroup($group_name, $is_admin, $owner_id)
        gwvp_createGroup("$gname", $gdesc, $isadmin, $owner);
+       // we also need to add the owner to the group
+       gwvp_addGroupMember(gwvp_getUserName($owner), $gname);
        
        
        header("Location: $BASE_URL/admin/users");
@@ -134,6 +139,51 @@ function gwvp_ModifyUserPageBody()
        echo "modify user $uid";
 }
 
+function gwvp_groupMemberChange()
+{
+       global $LOGIN_TYPE, $BASE_URL;
+       
+       $gid = -1;
+       
+       if(isset($_REQUEST["q"])) {
+               $query = $_REQUEST["q"];
+               $qspl = explode("/", $query);
+               $gid = $qspl[3];
+       }
+       error_log("into groupmemberchange with $gid");
+       if($gid!= -1) {
+               
+       }
+       
+       if(isset($_REQUEST["add"])) {
+               error_log("$gid add set to ".$_REQUEST["add"]);
+               // this is an add op
+               if(isset($_REQUEST["membersout"])) {
+                       foreach($_REQUEST["membersout"] as $uid) {
+                               error_log("would add $uid from $gid");
+                               gwvp_addGroupMemberByID($uid, $gid);
+                               
+                       }
+               }
+       }
+       if(isset($_REQUEST["remove"])) {
+               error_log("$gid remove set to ".$_REQUEST["remove"]);
+               // this is a remove op
+               if(isset($_REQUEST["membersin"])) {
+                       foreach($_REQUEST["membersin"] as $uid) {
+                               error_log("would remote $uid from $gid");
+                               gwvp_deleteGroupMemberByID($uid, $gid);
+                       }
+               }
+       }
+       
+       error_log("redirect to $BASE_URL/admin/users/modifygroup/$gid");
+       header("Location: $BASE_URL/admin/users/modifygroup/$gid");
+       //gwvp_goMainPage("gwvp_ModifyGroupPageBody");
+       
+       return;
+}
+
 function gwvp_ModifyGroupPageBody()
 {
        global $LOGIN_TYPE, $BASE_URL;
@@ -171,7 +221,7 @@ function gwvp_ModifyGroupPageBody()
        
        
        // members
-       echo "<select name=\"members\" size=\"20\" multiple>";
+       echo "<select name=\"membersin[]\" size=\"20\" multiple=\"true\">";
        foreach($users as $u_users) {
                $uid = $u_users["id"];
                $email = $u_users["email"];
@@ -199,7 +249,7 @@ function gwvp_ModifyGroupPageBody()
        
        
        // all users
-       echo "<select name=\"members\" size=\"20\" multiple>";
+       echo "<select name=\"membersout[]\" size=\"20\" multiple=\"true\">";
        foreach($users as $u_users) {
                $uid = $u_users["id"];
                $email = $u_users["email"];