X-Git-Url: http://git.pjr.cc/?a=blobdiff_plain;f=gwvpmini%2Fgwvpmini_db.php;h=d3d1057acec4872ddd23c937e7f5b76ae018dfb3;hb=746924e785c55b28d1d7a36d3f3dfab79559bc7e;hp=b74a334fa0d35bd1a0a78f3816720181398bde71;hpb=1b92a34cf5410903805474d427466ca4063f8b6c;p=gwvp-mini.git
diff --git a/gwvpmini/gwvpmini_db.php b/gwvpmini/gwvpmini_db.php
index b74a334..d3d1057 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;
}
}
@@ -55,6 +55,46 @@ function gwvpmini_getUser($username=null, $email=null, $id=null)
}
+function gwvpmini_GetActivityLog($nentries = 20, $forid=-1)
+{
+ /*
+ * "activity_id" INTEGER PRIMARY KEY AUTOINCREMENT,
+ "activity_type" TEXT,
+ "activity_date" TEXT,
+ "activity_user" TEXT,
+ "activity_repo" TEXT,
+ "activity_commitid" TEXT,
+ "activity_commitlog" TEXT,
+ "activity_visibleto" TEXT
+
+ */
+ $conn = gwvpmini_ConnectDB();
+
+ if($forid == -1) {
+ // we're searching for anonymous ones
+ $sql = "select * from activity where activity_visibleto='a' order by activity_date desc limit $nentries";
+ } else {
+ $sql = "select * from activity where activity_visibleto='a' or activity_visibleto='r' or activity_visibleto like '%:$forid:%' order by activity_date desc limit $nentries";
+ }
+
+ $vls = $conn->query($sql);
+
+ $nent = 0;
+ $ret = array();
+ if($vls !== false) foreach($vls as $vals) {
+ $ret[$nent]["type"] = $vals["activity_type"];
+ $ret[$nent]["date"] = $vals["activity_date"];
+ $ret[$nent]["userid"] = $vals["activity_user"];
+ $ret[$nent]["repoid"] = $vals["activity_repo"];
+ $ret[$nent]["commitid"] = $vals["activity_commitid"];
+ $ret[$nent]["commitlog"] = $vals["activity_commitlog"];
+ $nent++;
+ }
+
+ if($nent == 0) return false;
+ else return $ret;
+}
+
function gwvpmini_getRepo($ownerid=null, $name=null, $id=null)
{
@@ -108,7 +148,7 @@ function gwvpmini_ChangeRepoPerm($rid, $uid, $acc)
$res = $conn->query($sql);
- error_log("CHANGEREPOPERMS: call with $rid, $uid, $acc");
+ // error_log("CHANGEREPOPERMS: call with $rid, $uid, $acc");
$cperms_t = "";
foreach($res as $row) {
@@ -125,12 +165,12 @@ function gwvpmini_ChangeRepoPerm($rid, $uid, $acc)
$permsarray = unserialize(base64_decode($cperms_t));
$permsarray[$uid] = $acc;
if($acc == 0) {
- error_log("PERMSUPDATE: REMOVE $uid");
+ // error_log("PERMSUPDATE: REMOVE $uid");
unset($permsarray[$uid]);
}
}
} else {
- error_log("CHANGEREPOPERMS for b of $acc");
+ // error_log("CHANGEREPOPERMS for b of $acc");
$permsarray["b"] = $acc;
}
@@ -138,7 +178,7 @@ function gwvpmini_ChangeRepoPerm($rid, $uid, $acc)
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");
+ // error_log("CHANGEREPOPERMS removed $key $val for base perm change");
unset($permsarray[$key]);
}
}
@@ -159,7 +199,7 @@ function gwvpmini_ChangeRepoPerm($rid, $uid, $acc)
$sql = "update repos set repos_perms='$encperms' where repos_id='$rid'";
- error_log("PERMSARRAYNOW $sql ".print_r($permsarray,true));
+ // error_log("PERMSARRAYNOW $sql ".print_r($permsarray,true));
$conn->query($sql);
@@ -203,7 +243,7 @@ function gwvpmini_GetRepoPerm($rid, $uid)
if($cperms_t === false) return 0;
- error_log("PERMSCHECK $rid, $uid:".print_r($dets, true));
+ // error_log("PERMSCHECK $rid, $uid:".print_r($dets, true));
if($dets === false) return 0;
@@ -211,7 +251,7 @@ function gwvpmini_GetRepoPerm($rid, $uid)
$permsarray = unserialize(base64_decode($cperms_t));
- error_log("PERMSARRAY: ".print_r($permsarray,true));
+ // error_log("PERMSARRAY: ".print_r($permsarray,true));
$perm = 0;
@@ -252,6 +292,50 @@ function gwvpmini_RemoveUser($uid)
return $conn->query($sql);
}
+function gwvpmini_UpdateUserEmail($uid, $email)
+{
+ $conn = gwvpmini_ConnectDB();
+
+ if($uid < 0) return;
+
+ $sql = "update users set user_email='$email' where user_id='$uid'";
+
+ return $conn->query($sql);
+}
+
+function gwvpmini_UpdateUserDesc($uid, $desc)
+{
+ $conn = gwvpmini_ConnectDB();
+
+ if($uid < 0) return;
+
+ $sql = "update users set user_desc='$desc' where user_id='$uid'";
+
+ return $conn->query($sql);
+}
+
+function gwvpmini_SetUserStatusAdmin($uid, $adminstat)
+{
+ $conn = gwvpmini_ConnectDB();
+
+ if($uid < 0) return;
+
+ $sql = "update users set user_level='$adminstat' where user_id='$uid'";
+
+ return $conn->query($sql);
+}
+
+function gwvpmini_UpdateUserPassword($uid, $pass)
+{
+ $conn = gwvpmini_ConnectDB();
+
+ if($uid < 0) return;
+
+ $sql = "update users set user_password='".sha1($pass)."' where user_id='$uid'";
+
+ return $conn->query($sql);
+}
+
function gwvpmini_DisableUser($uid)
{
$conn = gwvpmini_ConnectDB();
@@ -261,6 +345,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)
@@ -302,14 +399,15 @@ 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");
+ $db_url = false;
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");
@@ -317,11 +415,11 @@ 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) {
- error_log("execpt on db open");
+ // error_log("execpt on db open");
return false;
}
@@ -373,6 +471,35 @@ function gwvpmini_AddUser($username, $password, $fullname, $email, $desc, $level
return $retval;
}
+function gwvpmini_AddActivityLog($type, $userid, $repoid, $commitid, $commitlog, $visibleto="a")
+{
+ /*
+ * CREATE TABLE "activity" (
+ "activity_id" INTEGER PRIMARY KEY AUTOINCREMENT,
+ "activity_type" TEXT,
+ "activity_date" TEXT,
+ "activity_user" TEXT,
+ "activity_repo" TEXT,
+ "activity_commitid" TEXT,
+ "activity_commitlog" TEXT,
+ "activity_visibleto" TEXT
+ )';
+
+ */
+
+ $conn = gwvpmini_ConnectDB();
+
+ // TODO: implement visibility
+ //$visibleto = "a";
+
+ $sql = "insert into 'activity' values ( null, '$type', '".time()."', '$userid', '$repoid', '$commitid', '$commitlog', '$visibleto')";
+
+ // error_log("SQL IS $sql");
+
+ $res = $conn->query($sql);
+ if(!$res) return -1;
+ return true;
+}
function gwvpmini_dbCreateSQLiteStructure($dbloc)
{
@@ -405,13 +532,34 @@ function gwvpmini_dbCreateSQLiteStructure($dbloc)
"repos_owner" INTEGER,
"repos_perms" TEXT,
"repos_status" TEXT,
+ "repos_origin" TEXT,
UNIQUE(repos_name)
)';
// 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
+
+
+ // type for now will only be "git"
+ // date is obvious
+ // desc is a desction of the activity
+ // link is of the form "repo,reponame,repoid:user,username,useremail,userid" so it
+ // can be attached simply
+ // viewby is a simple list of uid's that should be able to see it... "r" for all registered
+ // "a" for everyone
+ $activitysql = '
+ CREATE TABLE "activity" (
+ "activity_id" INTEGER PRIMARY KEY AUTOINCREMENT,
+ "activity_type" TEXT,
+ "activity_date" TEXT,
+ "activity_user" TEXT,
+ "activity_repo" TEXT,
+ "activity_commitid" TEXT,
+ "activity_commitlog" TEXT,
+ "activity_visibleto" TEXT
+ )';
$configsql = '
CREATE TABLE "config" (
@@ -422,7 +570,7 @@ function gwvpmini_dbCreateSQLiteStructure($dbloc)
try {
$DB_CONNECTION = new PDO("sqlite:$dbloc");
} catch(PDOException $exep) {
- error_log("execpt on db open");
+ // error_log("execpt on db open");
return false;
}
@@ -430,7 +578,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)
@@ -522,7 +671,7 @@ function gwvpmini_GetRepoDescFromName($reponame)
$conn = gwvpmini_ConnectDB();
$sql = "select repos_description from repos where repos_name='$reponame'";
- error_log("desc for name sql: $sql");
+ // error_log("desc for name sql: $sql");
$res = $conn->query($sql);
@@ -569,7 +718,7 @@ function gwvpmini_GetRepoOwnerDetailsFromName($reponame)
if(!$res) return -1;
foreach($res as $row) {
$retval = array();
- error_log("STUFF2: ".print_r($row,true));
+ // error_log("STUFF2: ".print_r($row,true));
$retval["id"] = $row["user_id"];
$retval["fullname"] = $row["user_full_name"];
$retval["username"] = $row["user_username"];
@@ -604,17 +753,19 @@ function gwvpmini_setConfigVal($confname, $confval)
return $conn->query($sql);
}
-function gwvpmini_AddRepo($name, $desc, $ownerid)
+function gwvpmini_AddRepo($name, $desc, $ownerid, $clonefrom)
{
- error_log("addrepo in db for $name, $desc, $ownerid");
+ // error_log("addrepo in db for $name, $desc, $ownerid");
$conn = gwvpmini_ConnectDB();
$perms["b"] = "a";
$encperms = base64_encode(serialize($perms));
+
+ if($clonefrom === false) $clonefrom = "";
- $sql = "insert into repos values (null, '$name', '$desc', '$ownerid', '$encperms', 0)";
+ $sql = "insert into repos values (null, '$name', '$desc', '$ownerid', '$encperms', 0, '$clonefrom')";
$conn->query($sql);
}
@@ -625,7 +776,7 @@ function gwvpmini_GetUserId($username)
$sql = "select user_id from users where user_username='$username'";
- error_log("userid sql $sql");
+ // error_log("userid sql $sql");
$res = $conn->query($sql);
@@ -643,7 +794,7 @@ function gwvpmini_GetUserNameFromEmail($email)
$sql = "select user_username from users where user_email='$email'";
- error_log("username sql $sql");
+ // error_log("username sql $sql");
$res = $conn->query($sql);
@@ -654,6 +805,7 @@ function gwvpmini_GetUserNameFromEmail($email)
return $retval;
}
+
function gwvpmini_GetOwnedRepos($username)
{
/*
@@ -670,7 +822,7 @@ function gwvpmini_GetOwnedRepos($username)
$uid = gwvpmini_GetUserId($username);
$sql = "select * from repos where repos_owner='$uid'";
- error_log("owned repos sql $sql for username $username");
+ // error_log("owned repos sql $sql for username $username");
$res = $conn->query($sql);
if($username == "") return false;
@@ -680,10 +832,56 @@ function gwvpmini_GetOwnedRepos($username)
$retval[$id]["name"] = $row["repos_name"];
$retval[$id]["desc"] = $row["repos_description"];
$retval[$id]["id"] = $row["repos_id"];
- error_log(print_r($row, true));
+ $retval[$id]["status"] = $row["repos_status"];
+ // error_log(print_r($row, true));
+ }
+
+ // error_log(print_r($retval, true));
+ 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;
- error_log(print_r($retval, true));
+ if($i == 0) {
+ // error_log("CONTRIBREPOS: no repos found?");
+ return false;
+ }
+
+ // error_log("CONTRIBREPOS: ".print_r($retval, true));
return $retval;
}
@@ -749,10 +947,10 @@ function gwvpmini_findPeopleLike($search)
$res = $conn->query($sql);
if(!$res) {
- error_log("SERACHUSER: $sql returned false");
+ // error_log("SERACHUSER: $sql returned false");
return false;
} else {
- error_log("SERACHUSER: $sql returned true");
+ // error_log("SERACHUSER: $sql returned true");
}
$retval = false;
@@ -767,7 +965,7 @@ function gwvpmini_findPeopleLike($search)
$retval[$id]["id"] = $row["user_id"];
}
- error_log("SEARCHUSER: array is ".print_r($retval, true));
+ // error_log("SEARCHUSER: array is ".print_r($retval, true));
return $retval;
}