4 global $DB_CONNECTION;
\r
5 $DB_CONNECTION = false;
\r
8 global $db_url, $db_type;
\r
9 //// error_log("in include for database, $db_type, $db_name");
12 function gwvpmini_DBExists()
14 global $WEB_ROOT_FS, $BASE_URL, $data_directory, $db_type, $db_name;
16 // oh this isnt working. poo.
17 //// error_log("checking for $db_name, $db_type");
19 if($db_type == "sqlite") {
20 if(file_exists($db_name)) {
21 //// error_log("Exists");
25 //// error_log("no exists");
31 function gwvpmini_getUser($username=null, $email=null, $id=null)
\r
33 $conn = gwvpmini_ConnectDB();
\r
35 if($username != null) {
\r
36 $res = $conn->query("select * from users where user_username='$username'");
\r
37 } else if($email != null) {
\r
38 $res = $conn->query("select * from users where user_email='$email'");
\r
39 } else if($id != null) {
\r
40 $res = $conn->query("select * from users where user_id='$id'");
\r
41 } else return false;
\r
44 foreach($res as $u_res) {
\r
45 $returns["id"] = $u_res["user_id"];
\r
46 $returns["fullname"] = $u_res["user_full_name"];
\r
47 $returns["password"] = $u_res["user_password"];
\r
48 $returns["username"] = $u_res["user_username"];
\r
49 $returns["email"] = $u_res["user_email"];
\r
50 $returns["desc"] = $u_res["user_desc"];
\r
51 $returns["status"] = $u_res["user_status"];
\r
58 function gwvpmini_GetActivityLog($nentries = 20, $forid=-1)
61 * "activity_id" INTEGER PRIMARY KEY AUTOINCREMENT,
66 "activity_commitid" TEXT,
67 "activity_commitlog" TEXT,
68 "activity_visibleto" TEXT
71 $conn = gwvpmini_ConnectDB();
\r
74 // we're searching for anonymous ones
75 $sql = "select * from activity where activity_visibleto='a' order by activity_date desc limit $nentries";
77 $sql = "select * from activity where activity_visibleto='a' or activity_visibleto='r' or activity_visibleto like '%:$forid:%' order by activity_date desc limit $nentries";
80 $vls = $conn->query($sql);
84 if($vls !== false) foreach($vls as $vals) {
85 $ret[$nent]["type"] = $vals["activity_type"];
86 $ret[$nent]["date"] = $vals["activity_date"];
87 $ret[$nent]["userid"] = $vals["activity_user"];
88 $ret[$nent]["repoid"] = $vals["activity_repo"];
89 $ret[$nent]["commitid"] = $vals["activity_commitid"];
90 $ret[$nent]["commitlog"] = $vals["activity_commitlog"];
94 if($nent == 0) return false;
98 // TODO: deal with multiple repos from one ownerid
99 function gwvpmini_getRepo($ownerid=null, $name=null, $id=null)
\r
101 $conn = gwvpmini_ConnectDB();
105 CREATE TABLE "repos" (
106 "repos_id" INTEGER PRIMARY KEY AUTOINCREMENT,
108 "repos_description" TEXT,
109 "repos_owner" INTEGER,
110 "repos_readperms" TEXT,
116 if($ownerid != null) {
\r
117 $res = $conn->query("select * from repos where repos_owner='$ownerid'");
\r
118 } else if($name != null) {
\r
119 $res = $conn->query("select * from repos where repos_name='$name'");
\r
120 } else if($id != null) {
\r
121 $res = $conn->query("select * from repos where repos_id='$id'");
\r
122 } else return false;
\r
125 if(!$res) return false;
\r
126 foreach($res as $u_res) {
\r
127 $returns["id"] = $u_res["repos_id"];
\r
128 $returns["name"] = $u_res["repos_name"];
\r
129 $returns["desc"] = $u_res["repos_description"];
\r
130 $returns["ownerid"] = $u_res["repos_owner"];
131 $returns["status"] = $u_res["repos_status"];
\r
139 // $uid = user id (a for "anyone", r for "registered")
140 // $acc = 0 or 1, 0 = no access, 1 = read access, 2 = write
141 // first part of ths is the "base" repo permissions
142 // this is spec'd as b:t where t = a (anyone can read), r (only registered can read) or x (explicit read perms)
143 function gwvpmini_ChangeRepoPerm($rid, $uid, $acc)
145 $conn = gwvpmini_ConnectDB();
147 $sql = "select repos_perms from repos where repos_id='$rid'";
149 $res = $conn->query($sql);
151 // error_log("CHANGEREPOPERMS: call with $rid, $uid, $acc");
154 foreach($res as $row) {
158 if($cperms_t === false) return false;
160 $permsarray = array();
162 if($cperms_t == "") {
163 $permsarray[$uid] = $acc;
165 $permsarray = unserialize(base64_decode($cperms_t));
166 $permsarray[$uid] = $acc;
168 // error_log("PERMSUPDATE: REMOVE $uid");
169 unset($permsarray[$uid]);
173 // error_log("CHANGEREPOPERMS for b of $acc");
174 $permsarray["b"] = $acc;
177 // check if base is now r or a, we can drop any 1's
178 if($permsarray["b"] == "a" || $permsarray["b"] == "r") {
179 foreach($permsarray as $key => $val) {
181 // error_log("CHANGEREPOPERMS removed $key $val for base perm change");
182 unset($permsarray[$key]);
187 if(is_array($permsarray)) {
188 if(!isset($permsarray["b"])) {
189 // something went wrong, repalce b bit
190 $permsarray["b"] = "a";
193 // something went even wronger
194 $permsarray["b"] = "a";
198 $encperms = base64_encode(serialize($permsarray));
200 $sql = "update repos set repos_perms='$encperms' where repos_id='$rid'";
\r
202 // error_log("PERMSARRAYNOW $sql ".print_r($permsarray,true));
\r
208 function gwvpmini_GetRepoPerms($rid)
210 $conn = gwvpmini_ConnectDB();
\r
212 $sql = "select repos_perms from repos where repos_id='$rid'";
\r
214 $res = $conn->query($sql);
\r
217 if($res !== false) foreach($res as $row) {
\r
218 $cperms_t = $row[0];
\r
221 if($cperms_t === false) return false;
\r
223 $permsarray = unserialize(base64_decode($cperms_t));
228 //returns 0 for none, 1 for read, 2 for writes
229 function gwvpmini_GetRepoPerm($rid, $uid)
231 $conn = gwvpmini_ConnectDB();
\r
233 $dets = gwvpmini_getRepo(null, null, $rid);
235 $sql = "select repos_perms from repos where repos_id='$rid'";
\r
237 $res = $conn->query($sql);
240 if($res !== false) foreach($res as $row) {
\r
241 $cperms_t = $row[0];
\r
244 if($cperms_t === false) return 0;
246 // error_log("PERMSCHECK $rid, $uid:".print_r($dets, true));
\r
248 if($dets === false) return 0;
250 if($dets["ownerid"] == $uid) return 2;
\r
252 $permsarray = unserialize(base64_decode($cperms_t));
254 error_log("PERMSARRAY: with call for $rid and user $uid ".print_r($permsarray,true));
260 if(isset($permsarray[$uid])) {
261 $perm = $permsarray[$uid];
262 } else if($permsarray["b"] == "a" ||$permsarray["b"] == "r") {
266 if($permsarray["b"] == "a") $perm = 1;
273 function gwvpmini_RemoveRepoDB($id)
275 $conn = gwvpmini_ConnectDB();
\r
277 if($id < 0) return;
\r
279 $sql = "delete from repos where repos_id='$id'";
\r
281 return $conn->query($sql);
\r
285 function gwvpmini_RemoveUser($uid)
287 $conn = gwvpmini_ConnectDB();
\r
291 $sql = "delete from users where user_id='$uid'";
293 return $conn->query($sql);
296 function gwvpmini_UpdateUserEmail($uid, $email)
298 $conn = gwvpmini_ConnectDB();
\r
300 if($uid < 0) return;
\r
302 $sql = "update users set user_email='$email' where user_id='$uid'";
\r
304 return $conn->query($sql);
307 function gwvpmini_UpdateUserDesc($uid, $desc)
\r
309 $conn = gwvpmini_ConnectDB();
\r
311 if($uid < 0) return;
\r
313 $sql = "update users set user_desc='$desc' where user_id='$uid'";
\r
315 return $conn->query($sql);
\r
318 function gwvpmini_SetUserStatusAdmin($uid, $adminstat)
320 $conn = gwvpmini_ConnectDB();
\r
322 if($uid < 0) return;
\r
324 $sql = "update users set user_level='$adminstat' where user_id='$uid'";
\r
326 return $conn->query($sql);
329 function gwvpmini_UpdateUserPassword($uid, $pass)
331 $conn = gwvpmini_ConnectDB();
335 $sql = "update users set user_password='".sha1($pass)."' where user_id='$uid'";
337 return $conn->query($sql);
340 function gwvpmini_DisableUser($uid)
\r
342 $conn = gwvpmini_ConnectDB();
\r
344 if($uid < 0) return;
\r
346 $sql = "update users set user_status=1 where user_id='$uid'";
\r
348 return $conn->query($sql);
\r
351 function gwvpmini_UpdateRepoDescription($rid, $desc)
353 $conn = gwvpmini_ConnectDB();
\r
355 // remove any tag elements
356 $newdesc_r = preg_replace("/[\<\>\;]+/", "", $desc);
357 $newdesc = preg_replace("/\n/", "<br>", $newdesc_r);
359 $sql = "update repos set repos_description='$newdesc' where repos_id='$rid'";
361 return $conn->query($sql);
364 function gwvpmini_EnableUser($uid)
\r
366 $conn = gwvpmini_ConnectDB();
\r
368 if($uid < 0) return;
\r
370 $sql = "update users set user_status=0 where user_id='$uid'";
\r
372 return $conn->query($sql);
\r
375 function gwvpmini_SetRepoCloning($rid)
\r
377 $conn = gwvpmini_ConnectDB();
\r
379 if($rid < 0) return;
\r
381 $sql = "update repos set repos_status=2 where repos_id='$rid'";
\r
383 return $conn->query($sql);
\r
386 function gwvpmini_DisableRepo($rid)
388 $conn = gwvpmini_ConnectDB();
\r
390 if($rid < 0) return;
\r
392 $sql = "update repos set repos_status=1 where repos_id='$rid'";
\r
394 return $conn->query($sql);
397 function gwvpmini_EnableRepo($rid)
\r
399 $conn = gwvpmini_ConnectDB();
\r
403 $sql = "update repos set repos_status=0 where repos_id='$rid'";
405 return $conn->query($sql);
\r
409 function gwvpmini_ConnectDB()
\r
411 global $WEB_ROOT_FS, $BASE_URL, $data_directory, $db_type, $db_name, $DB_CONNECTION;
\r
413 // first check if $DB_CONNECTION IS live
\r
414 //// error_log("in connection $db_type, $db_name");
417 if($DB_CONNECTION != false) return $DB_CONNECTION;
\r
419 if($db_type == "sqlite") {
\r
420 $db_url = $db_name;
\r
421 if(!file_exists($db_name)) {
\r
422 //// error_log("$db_name does not exist - problem");
423 // TODO: NEED A SETUP AGENT!
424 gwvpmini_dbCreateSQLiteStructure($db_name);
425 gwvpmini_setConfigVal("repodir", "$data_directory/repos");
\r
429 // and here we go with pdo.
\r
430 // error_log("attmpting to open db, $db_type:$db_url");
\r
432 $DB_CONNECTION = new PDO("$db_type:$db_url");
\r
433 } catch(PDOException $exep) {
\r
434 // error_log("execpt on db open");
\r
438 return $DB_CONNECTION;
\r
441 function gwvpmini_UpdateStatusFromConfirm($confirmhash)
443 $conn = gwvpmini_ConnectDB();
\r
445 $sql = "select count(*) from users where user_status='2:$confirmhash'";
447 $res = $conn->query($sql);
449 if(!$res) return false;
451 foreach($res as $row) {
456 $sql = "update users set user_status='0' where user_status='2:$confirmhash'";
457 return $conn->query($sql);
462 function gwvpmini_AddUser($username, $password, $fullname, $email, $desc, $level, $status)
467 $conn = gwvpmini_ConnectDB();
\r
469 $sql = "insert into 'users' values ( null, '$fullname', '".sha1($password)."', '$username', '$email', '$desc', '$level', '$status')";
\r
471 $res = $conn->query($sql);
474 $sql = "select user_id from users where user_username='$username'";
\r
475 $res = $conn->query($sql);
\r
476 if(!$res) return -1;
\r
479 foreach($res as $row) {
486 function gwvpmini_AddActivityLog($type, $userid, $repoid, $commitid, $commitlog, $visibleto="a")
489 * CREATE TABLE "activity" (
490 "activity_id" INTEGER PRIMARY KEY AUTOINCREMENT,
491 "activity_type" TEXT,
492 "activity_date" TEXT,
493 "activity_user" TEXT,
494 "activity_repo" TEXT,
495 "activity_commitid" TEXT,
496 "activity_commitlog" TEXT,
497 "activity_visibleto" TEXT
502 $conn = gwvpmini_ConnectDB();
504 // TODO: implement visibility
505 //$visibleto = "a";
\r
507 $sql = "insert into 'activity' values ( null, '$type', '".time()."', '$userid', '$repoid', '$commitid', '$commitlog', '$visibleto')";
509 // error_log("SQL IS $sql");
\r
511 $res = $conn->query($sql);
\r
516 function gwvpmini_dbCreateSQLiteStructure($dbloc)
\r
519 CREATE TABLE "users" (
\r
520 "user_id" INTEGER PRIMARY KEY AUTOINCREMENT,
\r
521 "user_full_name" TEXT,
\r
522 "user_password" TEXT,
\r
523 "user_username" TEXT,
\r
528 UNIQUE(user_username)
\r
531 $initialuser_admin = '
532 insert into "users" values ( null, "Administrator", "'.sha1("password").'", "admin", "admin@localhost", "the admin", "1", "0");
\r
535 $initialuser_user = '
\r
536 insert into "users" values ( null, "User", "'.sha1("password").'", "user", "user@localhost", "the user", "0", "0");
\r
540 CREATE TABLE "repos" (
\r
541 "repos_id" INTEGER PRIMARY KEY AUTOINCREMENT,
\r
543 "repos_description" TEXT,
\r
544 "repos_owner" INTEGER,
552 CREATE TABLE "messages" (
553 "msgs_id" INTEGER PRIMARY KEY AUTOINCREMENT,
560 // this looks like null, <repoid>, <read|visible|write>, user:<uid>|group:<gid>|authed|anon
\r
561 // where authed = any authenticated user, anon = everyone (logged in, not logged in, etc)
\r
562 // read|visible|write = can clone from repo|can see repo exists and see description but not clone from it|can push to repo
\r
563 // TODO: is this sufficient? i have to think about it
566 // type for now will only be "git"
568 // desc is a desction of the activity
569 // link is of the form "repo,reponame,repoid:user,username,useremail,userid" so it
570 // can be attached simply
571 // viewby is a simple list of uid's that should be able to see it... "r" for all registered
574 CREATE TABLE "activity" (
575 "activity_id" INTEGER PRIMARY KEY AUTOINCREMENT,
576 "activity_type" TEXT,
577 "activity_date" TEXT,
578 "activity_user" TEXT,
579 "activity_repo" TEXT,
580 "activity_commitid" TEXT,
581 "activity_commitlog" TEXT,
582 "activity_visibleto" TEXT
586 CREATE TABLE "config" (
\r
587 "config_name" TEXT,
\r
588 "config_value" TEXT
\r
592 $DB_CONNECTION = new PDO("sqlite:$dbloc");
\r
593 } catch(PDOException $exep) {
\r
594 // error_log("execpt on db open");
\r
598 $DB_CONNECTION->query($usersql);
\r
599 $DB_CONNECTION->query($initialuser_admin);
600 $DB_CONNECTION->query($initialuser_user);
601 $DB_CONNECTION->query($reposql);
\r
602 $DB_CONNECTION->query($configsql);
603 $DB_CONNECTION->query($activitysql);
604 $DB_CONNECTION->query($msgsql);
\r
607 function gwvpmini_getConfigVal($confname)
\r
611 CREATE TABLE "config" (
\r
612 "config_name" TEXT,
\r
613 "config_value" TEXT
\r
618 $conn = gwvpmini_ConnectDB();
\r
620 $sql = "select config_value from config where config_name='$confname'";
\r
622 $res = $conn->query($sql);
\r
625 foreach($res as $val) {
\r
626 $return = $val["config_value"];
\r
632 function gwvpmini_eraseConfigVal($confname)
\r
636 CREATE TABLE "config" (
\r
637 "config_name" TEXT,
\r
638 "config_value" TEXT
\r
643 $conn = gwvpmini_ConnectDB();
\r
645 $sql = "delete from config where config_name='$confname'";
\r
647 return $conn->query($sql);
\r
650 function gwvpmini_GetRepoId($reponame)
655 CREATE TABLE "repos" (
656 "repos_id" INTEGER PRIMARY KEY AUTOINCREMENT,
658 "repos_description" TEXT,
659 "repos_owner" INTEGER
664 $conn = gwvpmini_ConnectDB();
666 $sql = "select repos_id from repos where repos_name='$reponame'";
668 $res = $conn->query($sql);
672 foreach($res as $row) {
673 $retval = (int)$row[0];
679 function gwvpmini_GetRepoDescFromName($reponame)
\r
684 CREATE TABLE "repos" (
\r
685 "repos_id" INTEGER PRIMARY KEY AUTOINCREMENT,
\r
687 "repos_description" TEXT,
\r
688 "repos_owner" INTEGER
\r
693 $conn = gwvpmini_ConnectDB();
\r
695 $sql = "select repos_description from repos where repos_name='$reponame'";
696 // error_log("desc for name sql: $sql");
\r
698 $res = $conn->query($sql);
\r
701 if(!$res) return -1;
\r
702 foreach($res as $row) {
\r
709 function gwvpmini_SendMessageByDb($type, $data, $forid)
711 $conn = gwvpmini_ConnectDB();
713 $sql = "insert into messages values (null, '$type', '$data', '$forid')";
715 return $conn->query($sql);
718 function gwvpmini_GetMessagesForId($uid)
722 CREATE TABLE "messages" (
723 "msgs_id" INTEGER PRIMARY KEY AUTOINCREMENT,
730 $conn = gwvpmini_ConnectDB();
\r
732 $sql = "select * from messages where msgs_to_id='$uid'";
\r
733 // error_log("desc for name sql: $sql");
\r
735 $res = $conn->query($sql);
737 error_log("request message for uid, $uid with sql $sql");
\r
740 if(!$res) return 0;
\r
741 foreach($res as $row) {
742 $retval[$i]["id"] = $row["msgs_id"];
743 $retval[$i]["type"] = $row["msgs_type"];
744 $retval[$i]["data"] = $row["msgs_data"];
753 function gwvpmini_DeleteMessagesById($mid)
755 $conn = gwvpmini_ConnectDB();
\r
757 $sql = "delete from messages where msgs_id='$mid'";
759 return $conn->query($sql);
762 function gwvpmini_GetRepoOwnerDetailsFromName($reponame)
\r
767 CREATE TABLE "repos" (
\r
768 "repos_id" INTEGER PRIMARY KEY AUTOINCREMENT,
\r
770 "repos_description" TEXT,
\r
771 "repos_owner" INTEGER
\r
774 "user_id" INTEGER PRIMARY KEY AUTOINCREMENT,
775 "user_full_name" TEXT,
776 "user_password" TEXT,
777 "user_username" TEXT,
782 UNIQUE(user_username)
\r
786 $conn = gwvpmini_ConnectDB();
\r
788 $sql = "select users.* from repos,users where repos_name='$reponame' and repos_owner=user_id";
\r
790 $res = $conn->query($sql);
\r
793 if(!$res) return -1;
\r
794 foreach($res as $row) {
796 // error_log("STUFF2: ".print_r($row,true));
\r
797 $retval["id"] = $row["user_id"];
798 $retval["fullname"] = $row["user_full_name"];
799 $retval["username"] = $row["user_username"];
800 $retval["email"] = $row["user_email"];
801 $retval["desc"] = $row["user_desc"];
802 $retval["level"] = $row["user_level"];
803 $retval["status"] = $row["user_status"];
\r
809 function gwvpmini_setConfigVal($confname, $confval)
\r
813 CREATE TABLE "config" (
\r
814 "config_name" TEXT,
\r
815 "config_value" TEXT
\r
819 gwvpmini_eraseConfigVal($confname);
\r
821 $conn = gwvpmini_ConnectDB();
823 $sql = "delete from config where config_name='$confname'";
824 $conn->query($sql);
\r
826 $sql = "insert into config values('$confname', '$confval')";
\r
828 return $conn->query($sql);
\r
831 function gwvpmini_AddRepo($name, $desc, $ownerid, $defperms, $clonefrom)
834 // error_log("addrepo in db for $name, $desc, $ownerid");
835 $conn = gwvpmini_ConnectDB();
\r
837 $perms["b"] = $defperms;
839 $encperms = base64_encode(serialize($perms));
841 if($clonefrom === false) $clonefrom = "";
843 $sql = "insert into repos values (null, '$name', '$desc', '$ownerid', '$encperms', 0, '$clonefrom')";
\r
845 $conn->query($sql);
\r
848 function gwvpmini_GetUserId($username)
850 $conn = gwvpmini_ConnectDB();
\r
852 $sql = "select user_id from users where user_username='$username'";
854 // error_log("userid sql $sql");
\r
856 $res = $conn->query($sql);
859 foreach($res as $row) {
866 function gwvpmini_GetUserNameFromEmail($email)
\r
868 $conn = gwvpmini_ConnectDB();
\r
870 $sql = "select user_username from users where user_email='$email'";
\r
872 // error_log("username sql $sql");
\r
874 $res = $conn->query($sql);
\r
877 foreach($res as $row) {
\r
884 function gwvpmini_GetOwnedRepos($username)
\r
887 * CREATE TABLE "repos" (
888 "repos_id" INTEGER PRIMARY KEY AUTOINCREMENT,
890 "repos_description" TEXT,
891 "repos_owner" INTEGER
895 $conn = gwvpmini_ConnectDB();
898 $uid = gwvpmini_GetUserId($username);
899 $sql = "select * from repos where repos_owner='$uid'";
900 // error_log("owned repos sql $sql for username $username");
901 $res = $conn->query($sql);
902 if($username == "") return false;
\r
905 foreach($res as $row) {
906 $id = $row["repos_id"];
907 $retval[$id]["name"] = $row["repos_name"];
908 $retval[$id]["desc"] = $row["repos_description"];
909 $retval[$id]["id"] = $row["repos_id"];
910 $retval[$id]["status"] = $row["repos_status"];
911 // error_log(print_r($row, true));
914 error_log(print_r($retval, true));
\r
918 function gwvpmini_GetContributedRepos($username)
\r
921 * CREATE TABLE "repos" (
\r
922 "repos_id" INTEGER PRIMARY KEY AUTOINCREMENT,
\r
924 "repos_description" TEXT,
\r
925 "repos_owner" INTEGER
\r
929 $conn = gwvpmini_ConnectDB();
\r
932 $uid = gwvpmini_GetUserId($username);
\r
933 $sql = "select repos_id,repos_description,repos_perms,repos_owner,repos_status,repos_name from repos";
\r
934 $res = $conn->query($sql);
\r
935 if($username == "") return false;
\r
940 foreach($res as $row) {
941 $perms = unserialize(base64_decode($row["repos_perms"]));
942 // error_log("CONTRIB: $uid for ".$row["repos_id"]." - ".print_r($perms,true));
943 if(isset($perms["$uid"])) if($perms["$uid"] > 1) {
944 $rids[$i]["id"] = $row["repos_id"];
945 $rids[$i]["desc"] = $row["repos_description"];
946 $rids[$i]["owner"] = $row["repos_owner"];
947 $rids[$i]["status"] = $row["repos_status"];
948 $rids[$i]["name"] = $row["repos_name"];
955 // error_log("CONTRIBREPOS: no repos found?");
959 // error_log("CONTRIBREPOS: ".print_r($retval, true));
\r
963 function gwvpmini_userLevel($id)
965 $conn = gwvpmini_ConnectDB();
967 $sql = "select user_level from users where user_id='$id'";
969 $res = $conn->query($sql);
973 foreach($res as $row) {
980 function gwvpmini_GetUsers($startat = 0, $num = 10)
982 $conn = gwvpmini_ConnectDB();
985 * CREATE TABLE "users" (
986 "user_id" INTEGER PRIMARY KEY AUTOINCREMENT,
987 "user_full_name" TEXT,
988 "user_password" TEXT,
989 "user_username" TEXT,
997 $sql = "select * from users where user_id>='$startat' order by user_id asc limit $num";
999 $res = $conn->query($sql);
1002 foreach($res as $row) {
1003 $id = $row["user_id"];
1004 $retval[$id]["fullname"] = $row["user_full_name"];
1005 $retval[$id]["username"] = $row["user_username"];
1006 $retval[$id]["email"] = $row["user_email"];
1007 $retval[$id]["desc"] = $row["user_desc"];
1008 $retval[$id]["level"] = $row["user_level"];
1009 $retval[$id]["status"] = $row["user_status"];
1010 $retval[$id]["id"] = $row["user_id"];
1016 function gwvpmini_findPeopleLike($search)
\r
1018 $conn = gwvpmini_ConnectDB();
1020 $sql = "select * from users where user_username like '%$search%' or user_full_name like '%$search%'";
\r
1022 $res = $conn->query($sql);
1025 // error_log("SERACHUSER: $sql returned false");
1028 // error_log("SERACHUSER: $sql returned true");
1032 foreach($res as $row) {
\r
1033 $id = $row["user_id"];
\r
1034 $retval[$id]["fullname"] = $row["user_full_name"];
\r
1035 $retval[$id]["username"] = $row["user_username"];
\r
1036 $retval[$id]["email"] = $row["user_email"];
\r
1037 $retval[$id]["desc"] = $row["user_desc"];
\r
1038 $retval[$id]["level"] = $row["user_level"];
\r
1039 $retval[$id]["status"] = $row["user_status"];
\r
1040 $retval[$id]["id"] = $row["user_id"];
\r
1043 // error_log("SEARCHUSER: array is ".print_r($retval, true));
\r
1047 function gwvpmini_GetRepos($startat=0, $num=200)
\r
1049 $conn = gwvpmini_ConnectDB();
\r
1052 * CREATE TABLE "repos" (
1053 "repos_id" INTEGER PRIMARY KEY AUTOINCREMENT,
1055 "repos_description" TEXT,
1056 "repos_owner" INTEGER
1061 $sql = "select * from repos where repos_id > '$startat' order by repos_id asc limit $num";
\r
1063 $res = $conn->query($sql);
\r
1066 foreach($res as $row) {
\r
1067 $id = $row["repos_id"];
\r
1068 $retval[$id]["name"] = $row["repos_name"];
\r
1069 $retval[$id]["desc"] = $row["repos_description"];
\r
1070 $retval[$id]["owner"] = $row["repos_owner"];
\r
1071 $retval[$id]["id"] = $row["repos_id"];
1072 $retval[$id]["status"] = $row["repos_status"];
1080 function gwvpmini_findReposLike($search)
\r
1082 $conn = gwvpmini_ConnectDB();
1085 * CREATE TABLE "repos" (
1086 "repos_id" INTEGER PRIMARY KEY AUTOINCREMENT,
1088 "repos_description" TEXT,
1089 "repos_owner" INTEGER
1094 $sql = "select * from repos where repos_name like '%$search%' or repos_description like '%$search%'";
1096 $res = $conn->query($sql);
1098 if(!$res) return false;
1101 foreach($res as $row) {
1102 $id = $row["repos_id"];
1103 $retval[$id]["name"] = $row["repos_name"];
1104 $retval[$id]["desc"] = $row["repos_description"];
1105 $retval[$id]["owner"] = $row["repos_owner"];
1106 $retval[$id]["id"] = $row["repos_id"];
1107 $retval[$id]["status"] = $row["repos_status"];
1114 function gwvpmini_GetNRepos()
1116 $conn = gwvpmini_ConnectDB();
1118 $sql = "select count(*) from repos";
1120 $res = $conn->query($sql);
1123 foreach($res as $row) {
1131 function gwvpmini_GetNUsers()
\r
1133 $conn = gwvpmini_ConnectDB();
\r
1135 $sql = "select count(*) from users";
\r
1137 $res = $conn->query($sql);
\r
1140 foreach($res as $row) {
\r
1141 $retval = $row[0];
\r