X-Git-Url: http://git.pjr.cc/?p=gwvp.git;a=blobdiff_plain;f=gwvplib%2Fgwvpdatabase.php;h=5823c0c315b81451032333361f4f26ba14d384b4;hp=b45e360c23098118717dd25a2913c338af915e21;hb=4f4bf1da18181d412cd755143e016ede587cc1d6;hpb=fe6b9fc0c565c690aee78c3b4620f27a65385c31 diff --git a/gwvplib/gwvpdatabase.php b/gwvplib/gwvpdatabase.php index b45e360..5823c0c 100644 --- a/gwvplib/gwvpdatabase.php +++ b/gwvplib/gwvpdatabase.php @@ -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() { @@ -75,6 +80,7 @@ function gwvp_dbCreateSQLiteStructure($dbloc) $DB_CONNECTION->query($usersql); $DB_CONNECTION->query($groupsql); $DB_CONNECTION->query($reposql); + $DB_CONNECTION->query($repoperms); $DB_CONNECTION->query($configsql); $DB_CONNECTION->query($groupmemsql); } @@ -146,15 +152,16 @@ function gwvp_getConfigVal($confname) $conn = gwvp_ConnectDB(); - $sql = "select * from config where config_name='$confname'"; + $sql = "select config_value from config where config_name='$confname'"; $res = $conn->query($sql); $return = null; foreach($res as $val) { - $return = $val; + $return = $val["config_value"]; } + return $return; } function gwvp_eraseConfigVal($confname) @@ -198,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, $repo_base, $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; } @@ -211,9 +223,11 @@ function gwvp_isDBSetup() function gwvp_ConnectDB() { - global $WEB_ROOT_FS, $BASE_URL, $repo_base, $data_directory, $db_type, $db_name, $DB_CONNECTION; + 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") { @@ -391,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) @@ -683,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(); @@ -708,6 +746,46 @@ function gwvp_IsGroupMember($email, $groupname) if($result == 1) return true; } +function gwvp_IsGroupAdmin($groupname = null, $gid = null) +{ + $conn = gwvp_ConnectDB(); + + if($groupname != null) { + $sql = "select groups_is_admin from groups where groups_name='$groupname'"; + } else if($gid != null) { + $sql = "select groups_is_admin from groups where groups_id='$gid'"; + } else return false; + + $res = $conn->query($sql); + + $return = false; + foreach($res as $u_res) { + if($u_res["groups_is_admin"] == "1") $return = true; + } + + 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) { $conn = gwvp_ConnectDB(); @@ -834,6 +912,42 @@ 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(); + + $sql = "select * from repos where repos_id='$rid'"; + + $res = $conn->query($sql); + + $return = false; + foreach($res as $u_res) { + $return["id"] = $u_res["repos_id"]; + $return["name"] = $u_res["repos_name"]; + $return["description"] = $u_res["repos_description"]; + $return["owner"] = $u_res["repos_owner"]; + } + + return $return; +} + function gwvp_GetRepoList() { $conn = gwvp_ConnectDB(); @@ -935,7 +1049,7 @@ function gwvp_getRepoPermissions($repoid) $returns = false; $rn = 0; foreach($res as $perm) { - $returns[$rn]["permid"] = $perm["repoperms_id"]; + $returns[$rn]["id"] = $perm["repoperms_id"]; $returns[$rn]["type"] = $perm["repoperms_type"]; $returns[$rn]["ref"] = $perm["repoperms_ref"]; $rn++; @@ -944,10 +1058,21 @@ function gwvp_getRepoPermissions($repoid) return $returns; } +function gwvp_removeRepoPermission($permid) +{ + $conn = gwvp_ConnectDB(); + + $sql = "delete from repoperms where repoperms_id='$permid'"; + error_log("attempting: \"$sql\""); + + return $conn->query($sql); +} + function gwvp_addRepoPermission($repoid, $permtype, $permref) { $conn = gwvp_ConnectDB(); + error_log("PERMS: $repoid, $permtype, $permref"); $sql = "insert into repoperms values(null, '$repoid', '$permtype', '$permref')"; return $conn->query($sql);