X-Git-Url: http://git.pjr.cc/?a=blobdiff_plain;f=gwvpmini%2Fgwvpmini_db.php;h=64277bcde13a2cf8488ff204010a20096381c8d6;hb=366baaa372e9c911249ce35f045c5eee1b864d84;hp=4e939afaa6717c3fe1c73c8e4bb6f9d7faf16dc4;hpb=5433c422794029259de4512640485aeb650e0c87;p=gwvp-mini.git diff --git a/gwvpmini/gwvpmini_db.php b/gwvpmini/gwvpmini_db.php index 4e939af..64277bc 100644 --- a/gwvpmini/gwvpmini_db.php +++ b/gwvpmini/gwvpmini_db.php @@ -6,7 +6,7 @@ $DB_CONNECTION = false; global $db_url, $db_type; -error_log("in include for database, $db_type, $db_name"); +//error_log("in include for database, $db_type, $db_name"); function gwvpmini_DBExists() @@ -14,15 +14,15 @@ function gwvpmini_DBExists() 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"); + //error_log("checking for $db_name, $db_type"); if($db_type == "sqlite") { if(file_exists($db_name)) { - error_log("Exists"); + //error_log("Exists"); return true; } else { - error_log("no exists"); + //error_log("no exists"); return false; } } @@ -118,30 +118,73 @@ function gwvpmini_ChangeRepoPerm($rid, $uid, $acc) if($cperms_t === false) return false; $permsarray = array(); - if($cperms_t == "") { - $permsarray[$uid] = $acc; + if($uid != "b") { + if($cperms_t == "") { + $permsarray[$uid] = $acc; + } else { + $permsarray = unserialize(base64_decode($cperms_t)); + $permsarray[$uid] = $acc; + if($acc == 0) { + error_log("PERMSUPDATE: REMOVE $uid"); + unset($permsarray[$uid]); + } + } } else { - $permsarray = unserialize(base64_decode($cperms_t)); - $permsarray[$uid] = $acc; + error_log("CHANGEREPOPERMS for b of $acc"); + $permsarray["b"] = $acc; } // check if base is now r or a, we can drop any 1's if($permsarray["b"] == "a" || $permsarray["b"] == "r") { foreach($permsarray as $key => $val) { if($val == 1) { + error_log("CHANGEREPOPERMS removed $key $val for base perm change"); unset($permsarray[$key]); } } } + if(is_array($permsarray)) { + if(!isset($permsarray["b"])) { + // something went wrong, repalce b bit + $permsarray["b"] = "a"; + } + } else { + // something went even wronger + $permsarray["b"] = "a"; + } + + $encperms = base64_encode(serialize($permsarray)); $sql = "update repos set repos_perms='$encperms' where repos_id='$rid'"; + + error_log("PERMSARRAYNOW $sql ".print_r($permsarray,true)); $conn->query($sql); } +function gwvpmini_GetRepoPerms($rid) +{ + $conn = gwvpmini_ConnectDB(); + + $sql = "select repos_perms from repos where repos_id='$rid'"; + + $res = $conn->query($sql); + + $cperms_t = false; + if($res !== false) foreach($res as $row) { + $cperms_t = $row[0]; + } + + if($cperms_t === false) return false; + + $permsarray = unserialize(base64_decode($cperms_t)); + + return $permsarray; +} + //returns 0 for none, 1 for read, 2 for writes function gwvpmini_GetRepoPerm($rid, $uid) { @@ -153,8 +196,6 @@ function gwvpmini_GetRepoPerm($rid, $uid) $res = $conn->query($sql); - error_log("PERMCHECK: FUCK U! $sql"); - $cperms_t = false; if($res !== false) foreach($res as $row) { $cperms_t = $row[0]; @@ -220,6 +261,19 @@ function gwvpmini_DisableUser($uid) $sql = "update users set user_status=1 where user_id='$uid'"; return $conn->query($sql); +} + +function gwvpmini_UpdateRepoDescription($rid, $desc) +{ + $conn = gwvpmini_ConnectDB(); + + // remove any tag elements + $newdesc_r = preg_replace("/[\<\>\;]+/", "", $desc); + $newdesc = preg_replace("/\n/", "
", $newdesc_r); + + $sql = "update repos set repos_description='$newdesc' where repos_id='$rid'"; + + return $conn->query($sql); } function gwvpmini_EnableUser($uid) @@ -261,14 +315,14 @@ function gwvpmini_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"); + //error_log("in connection $db_type, $db_name"); if($DB_CONNECTION != false) return $DB_CONNECTION; if($db_type == "sqlite") { $db_url = $db_name; if(!file_exists($db_name)) { - error_log("$db_name does not exist - problem"); + //error_log("$db_name does not exist - problem"); // TODO: NEED A SETUP AGENT! gwvpmini_dbCreateSQLiteStructure($db_name); gwvpmini_setConfigVal("repodir", "$data_directory/repos"); @@ -276,7 +330,7 @@ function gwvpmini_ConnectDB() } // and here we go with pdo. - error_log("attmpting to open db, $db_type:$db_url"); + //error_log("attmpting to open db, $db_type:$db_url"); try { $DB_CONNECTION = new PDO("$db_type:$db_url"); } catch(PDOException $exep) { @@ -370,7 +424,15 @@ function gwvpmini_dbCreateSQLiteStructure($dbloc) // this looks like null, , , user:|group:|authed|anon // where authed = any authenticated user, anon = everyone (logged in, not logged in, etc) // read|visible|write = can clone from repo|can see repo exists and see description but not clone from it|can push to repo - // TODO: is this sufficient? i have to think about it + // TODO: is this sufficient? i have to think about it + + $activitysql = ' + CREATE TABLE "activity" ( + "activity_type" TEXT, + "activity_date" TEXT, + "activity_desc" TEXT, + "activity_viewby" TEXT + )'; $configsql = ' CREATE TABLE "config" ( @@ -389,7 +451,8 @@ function gwvpmini_dbCreateSQLiteStructure($dbloc) $DB_CONNECTION->query($initialuser_admin); $DB_CONNECTION->query($initialuser_user); $DB_CONNECTION->query($reposql); - $DB_CONNECTION->query($configsql); + $DB_CONNECTION->query($configsql); + $DB_CONNECTION->query($activitysql); } function gwvpmini_getConfigVal($confname) @@ -613,6 +676,7 @@ function gwvpmini_GetUserNameFromEmail($email) return $retval; } + function gwvpmini_GetOwnedRepos($username) { /* @@ -639,6 +703,7 @@ function gwvpmini_GetOwnedRepos($username) $retval[$id]["name"] = $row["repos_name"]; $retval[$id]["desc"] = $row["repos_description"]; $retval[$id]["id"] = $row["repos_id"]; + $retval[$id]["status"] = $row["repos_status"]; error_log(print_r($row, true)); } @@ -646,6 +711,51 @@ function gwvpmini_GetOwnedRepos($username) return $retval; } +function gwvpmini_GetContributedRepos($username) +{ + /* + * CREATE TABLE "repos" ( + "repos_id" INTEGER PRIMARY KEY AUTOINCREMENT, + "repos_name" TEXT, + "repos_description" TEXT, + "repos_owner" INTEGER + )'; + + */ + $conn = gwvpmini_ConnectDB(); + + + $uid = gwvpmini_GetUserId($username); + $sql = "select repos_id,repos_description,repos_perms,repos_owner,repos_status,repos_name from repos"; + $res = $conn->query($sql); + if($username == "") return false; + + $retval = false; + $rids = null; + $i = 0; + foreach($res as $row) { + $perms = unserialize(base64_decode($row["repos_perms"])); + error_log("CONTRIB: $uid for ".$row["repos_id"]." - ".print_r($perms,true)); + if(isset($perms["$uid"])) if($perms["$uid"] > 1) { + $rids[$i]["id"] = $row["repos_id"]; + $rids[$i]["desc"] = $row["repos_description"]; + $rids[$i]["owner"] = $row["repos_owner"]; + $rids[$i]["status"] = $row["repos_status"]; + $rids[$i]["name"] = $row["repos_name"]; + $i++; + } + } + $retval = $rids; + + if($i == 0) { + error_log("CONTRIBREPOS: no repos found?"); + return false; + } + + error_log("CONTRIBREPOS: ".print_r($retval, true)); + return $retval; +} + function gwvpmini_userLevel($id) { $conn = gwvpmini_ConnectDB();