fixing up the "is setup" check in the installer
[gwvp.git] / gwvplib / gwvpdatabase.php
index 82533cb..5823c0c 100644 (file)
@@ -3,6 +3,11 @@
 global $DB_CONNECTION;
 $DB_CONNECTION = false;
 
+
+global $db_url, $db_type;
+error_log("in include for database, $db_type, $db_name");
+
+
 // i need to figure out how i do data encapsulation here. We'll support mysql and sqlite3 off the bat if we can - sqlite3 comes first tho
 function gwvp_dbCreateMysqlStructure()
 {
@@ -200,10 +205,15 @@ function gwvp_setConfigVal($confname, $confval)
 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
-       global $WEB_ROOT_FS, $BASE_URL, $data_directory, $db_type, $db_url;
-
+       global $WEB_ROOT_FS, $BASE_URL, $data_directory, $db_type, $db_name;
+       
+       // oh this isnt working. poo.
+       error_log("checking for $db_name, $db_type");
+       
        if($db_type == "sqlite") {
-               if(file_exists($db_url)) return true;
+               if(file_exists($db_name)) {
+                       return true;
+               }
                else return false;
        }
 
@@ -216,6 +226,8 @@ function gwvp_ConnectDB()
        global $WEB_ROOT_FS, $BASE_URL, $data_directory, $db_type, $db_name, $DB_CONNECTION;
 
        // first check if $DB_CONNECTION IS live
+       error_log("in connection $db_type, $db_name");
+       
        if($DB_CONNECTION != false) return $DB_CONNECTION;
 
        if($db_type == "sqlite") {
@@ -393,7 +405,15 @@ function gwvp_createGroup($group_name, $group_desc, $is_admin, $owner_id)
        
 
        $conn->query($sql);
-
+       
+       // add the owner to the group
+       $gid = gwvp_getGroupId($group_name);
+       
+       
+       error_log("calling addgroupmember with $owner_id, $gid");
+       gwvp_addGroupMemberById($owner_id, $gid);
+       
+       return true;
 }
 
 function gwvp_deleteGroup($groupname)
@@ -685,6 +705,22 @@ function gwvp_addGroupMember($email, $groupname)
        return true;
 }
 
+function gwvp_IsGroupMemberById($uid, $gid)
+{
+       $conn = gwvp_ConnectDB();
+       
+       $sql = "select count(*) from group_membership where groupmember_userid='$uid' and groupmember_groupid='$gid'";
+
+       $res = $conn->query($sql);
+       $result = 0;
+       foreach($res as $u_res) {
+               $result = $u_res[0];
+       }
+
+       if($result == 0) return false;
+       if($result == 1) return true;
+}
+
 function gwvp_IsGroupMember($email, $groupname)
 {
        $conn = gwvp_ConnectDB();
@@ -730,6 +766,25 @@ function gwvp_IsGroupAdmin($groupname = null, $gid = null)
        return $return;
 }
 
+function gwvp_IsRepoOwner($userid, $repoid)
+{
+       $conn = gwvp_ConnectDB();
+       
+       $sql = "select repos_owner from repos where repos_id='$repoid'";
+       
+       $res = $conn->query($sql);
+       
+       $return = false;
+       foreach($res as $u_res) {
+               $return["owner"] = $u_res["repos_owner"];
+       }
+
+       if($return == false) return false;
+       if($return["owner"] == $userid) return true;
+       else return false;
+       
+       
+}
 
 function gwvp_IsUserAdmin($email=null, $username = null, $userid = null)
 {
@@ -857,6 +912,23 @@ function gwvp_ModifyGroup($groupid, $groupname = null, $group_is_admin = null, $
        return true;
 }
 
+function gwvp_GetRepoId($reponame)
+{
+       $conn = gwvp_ConnectDB();
+       
+       $sql = "select repos_id from repos where repos_name='$reponame'";
+       
+       $res = $conn->query($sql);
+       
+       $return = false;
+       foreach($res as $u_res) {
+               $return = $u_res["repos_id"];
+       }
+       
+       return $return;
+       
+}
+
 function gwvp_GetRepo($rid)
 {
        $conn = gwvp_ConnectDB();