2007-10-26 21:14:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once("../inc/db_conn.inc");
|
2008-07-01 22:16:49 +00:00
|
|
|
require_once("../inc/util_basic.inc");
|
2007-10-26 21:14:35 +00:00
|
|
|
|
|
|
|
class BoincDb extends DbConn {
|
2007-10-29 04:02:41 +00:00
|
|
|
static $instance;
|
2007-10-26 21:14:35 +00:00
|
|
|
|
2007-10-29 16:38:25 +00:00
|
|
|
static function get($readonly = false) {
|
2007-10-26 21:14:35 +00:00
|
|
|
if (!isset($instance)) {
|
2008-07-08 21:07:33 +00:00
|
|
|
if (web_stopped()) {
|
|
|
|
show_page("Project down for maintenence",
|
|
|
|
"Please check back in a few hours."
|
|
|
|
);
|
|
|
|
exit;
|
|
|
|
}
|
2007-10-29 16:38:25 +00:00
|
|
|
$config = get_config();
|
|
|
|
$user = parse_config($config, '<db_user>');
|
|
|
|
$passwd = parse_config($config, '<db_passwd>');
|
|
|
|
$host = parse_config($config, '<db_host>');
|
|
|
|
$replica_host = parse_config($config, '<replica_db_host>');
|
|
|
|
$name = parse_config($config, '<db_name>');
|
|
|
|
if ($host == null) {
|
|
|
|
$host = "localhost";
|
|
|
|
}
|
2007-10-26 21:14:35 +00:00
|
|
|
$instance = new DbConn();
|
2007-10-29 16:38:25 +00:00
|
|
|
if ($readonly && $replica_host) {
|
|
|
|
$retval = $instance->init_conn($user, $passwd, $replica_host, $name);
|
|
|
|
if ($retval) return $instance;
|
|
|
|
}
|
|
|
|
$retval = $instance->init_conn($user, $passwd, $host, $name);
|
2007-10-26 21:14:35 +00:00
|
|
|
if (!$retval) return null;
|
|
|
|
}
|
|
|
|
return $instance;
|
|
|
|
}
|
2007-10-27 20:38:12 +00:00
|
|
|
static function escape_string($string) {
|
|
|
|
$db = self::get();
|
|
|
|
return $db->base_escape_string($string);
|
|
|
|
}
|
2007-11-12 22:28:17 +00:00
|
|
|
static function error() {
|
|
|
|
$db = self::get();
|
|
|
|
return $db->base_error();
|
|
|
|
}
|
2007-10-26 21:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoincUser {
|
2007-11-10 00:32:42 +00:00
|
|
|
static $cache;
|
2007-10-29 16:38:25 +00:00
|
|
|
static function lookup($clause) {
|
2007-10-26 21:14:35 +00:00
|
|
|
$db = BoincDb::get();
|
2007-10-29 16:38:25 +00:00
|
|
|
return $db->lookup('user', 'BoincUser', $clause);
|
2007-10-26 21:14:35 +00:00
|
|
|
}
|
|
|
|
|
2007-11-10 00:32:42 +00:00
|
|
|
static function lookup_id_nocache($id) {
|
2007-10-26 21:14:35 +00:00
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup_id($id, 'user', 'BoincUser');
|
|
|
|
}
|
2007-11-10 00:32:42 +00:00
|
|
|
static function lookup_id($id) {
|
|
|
|
if (!isset(self::$cache[$id])) {
|
|
|
|
self::$cache[$id] = self::lookup_id_nocache($id);
|
|
|
|
}
|
|
|
|
return self::$cache[$id];
|
|
|
|
}
|
2007-10-26 21:14:35 +00:00
|
|
|
static function count($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->count('user', $clause);
|
|
|
|
}
|
|
|
|
function update($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->update($this, 'user', $clause);
|
|
|
|
}
|
2007-11-05 23:55:33 +00:00
|
|
|
static function enum($where_clause, $order_clause=null) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('user', 'BoincUser', $where_clause, $order_clause);
|
|
|
|
}
|
|
|
|
static function enum_fields($fields, $where_clause, $order_clause=null) {
|
2007-10-26 21:14:35 +00:00
|
|
|
$db = BoincDb::get();
|
2007-11-05 23:55:33 +00:00
|
|
|
return $db->enum_fields(
|
|
|
|
'user', 'BoincUser', $fields, $where_clause, $order_clause
|
|
|
|
);
|
2007-10-26 21:14:35 +00:00
|
|
|
}
|
2007-10-28 15:03:14 +00:00
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoincDb::get();
|
2008-06-24 22:20:40 +00:00
|
|
|
$ret = $db->insert('user', $clause);
|
|
|
|
if (!$ret) return 0;
|
|
|
|
return $db->insert_id();
|
2007-10-28 15:03:14 +00:00
|
|
|
}
|
2007-12-07 23:23:25 +00:00
|
|
|
function delete() {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->delete($this, 'user');
|
|
|
|
}
|
2007-10-26 21:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoincTeam {
|
2007-11-05 23:55:33 +00:00
|
|
|
static $cache;
|
2007-11-01 17:54:44 +00:00
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoincDb::get();
|
2008-06-24 22:20:40 +00:00
|
|
|
$ret = $db->insert('team', $clause);
|
|
|
|
if (!$ret) return 0;
|
|
|
|
return $db->insert_id();
|
2007-11-01 17:54:44 +00:00
|
|
|
}
|
2007-11-15 22:51:05 +00:00
|
|
|
static function lookup_id_nocache($id) {
|
2007-10-26 21:14:35 +00:00
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup_id($id, 'team', 'BoincTeam');
|
|
|
|
}
|
2007-11-15 22:51:05 +00:00
|
|
|
static function lookup_id($id) {
|
|
|
|
if (!isset(self::$cache[$id])) {
|
|
|
|
self::$cache[$id] = self::lookup_id_nocache($id);
|
2007-11-05 23:55:33 +00:00
|
|
|
}
|
2007-11-15 22:51:05 +00:00
|
|
|
return self::$cache[$id];
|
2007-11-05 23:55:33 +00:00
|
|
|
}
|
2007-10-26 21:14:35 +00:00
|
|
|
function update($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->update($this, 'team', $clause);
|
|
|
|
}
|
2007-10-29 16:38:25 +00:00
|
|
|
static function enum($clause, $clause2=null) {
|
2007-10-26 21:14:35 +00:00
|
|
|
$db = BoincDb::get();
|
2007-10-29 16:38:25 +00:00
|
|
|
return $db->enum('team', 'BoincTeam', $clause, $clause2);
|
2007-10-26 21:14:35 +00:00
|
|
|
}
|
2007-11-01 17:54:44 +00:00
|
|
|
static function lookup($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup('team', 'BoincTeam', $clause);
|
|
|
|
}
|
2007-11-07 17:23:29 +00:00
|
|
|
function delete() {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->delete($this, 'team');
|
|
|
|
}
|
2007-10-26 21:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoincTeamDelta {
|
2007-10-29 16:38:25 +00:00
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->insert('team_delta', $clause);
|
|
|
|
}
|
2007-10-26 21:14:35 +00:00
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('team_delta', 'BoincTeamDelta', $clause);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-27 20:38:12 +00:00
|
|
|
class BoincHost {
|
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup_id($id, 'host', 'BoincHost');
|
|
|
|
}
|
2007-10-28 15:03:14 +00:00
|
|
|
function update($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->update($this, 'host', $clause);
|
|
|
|
}
|
2007-10-27 20:38:12 +00:00
|
|
|
function delete() {
|
2007-11-06 23:21:55 +00:00
|
|
|
$db = BoincDb::get();
|
2007-10-27 20:38:12 +00:00
|
|
|
return $db->delete($this, 'host');
|
|
|
|
}
|
2007-10-28 15:03:14 +00:00
|
|
|
static function enum($clause, $clause2=null) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('host', 'BoincHost', $clause, $clause2);
|
|
|
|
}
|
2007-10-27 20:38:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoincResult {
|
|
|
|
static function count($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->count('result', $clause);
|
|
|
|
}
|
2007-10-28 15:03:14 +00:00
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('result', 'BoincResult', $clause);
|
|
|
|
}
|
2007-10-29 04:02:41 +00:00
|
|
|
static function update_aux($clause) {
|
2007-10-28 15:03:14 +00:00
|
|
|
$db = BoincDb::get();
|
2007-10-29 04:02:41 +00:00
|
|
|
return $db->update_aux('result', $clause);
|
2007-10-28 15:03:14 +00:00
|
|
|
}
|
2007-11-12 22:39:56 +00:00
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup_id($id, 'result', 'BoincResult');
|
|
|
|
}
|
2007-10-28 15:03:14 +00:00
|
|
|
}
|
|
|
|
|
2007-11-12 22:28:17 +00:00
|
|
|
class BoincWorkunit {
|
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup_id($id, 'workunit', 'BoincWorkunit');
|
|
|
|
}
|
2008-03-04 23:50:38 +00:00
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
$ret = $db->insert('workunit', $clause);
|
|
|
|
if (!$ret) return $ret;
|
|
|
|
return $db->insert_id();
|
|
|
|
}
|
2008-07-03 18:41:13 +00:00
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('workunit', 'BoincWorkunit', $clause);
|
|
|
|
}
|
|
|
|
function update($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->update($this, 'workunit', $clause);
|
|
|
|
}
|
2007-11-12 22:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoincApp {
|
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup_id($id, 'app', 'BoincApp');
|
|
|
|
}
|
2008-03-04 23:50:38 +00:00
|
|
|
static function lookup($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup('app', 'BoincApp', $clause);
|
|
|
|
}
|
2007-11-12 22:28:17 +00:00
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('app', 'BoincApp', $clause);
|
|
|
|
}
|
2008-03-04 23:50:38 +00:00
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoincDb::get();
|
2008-03-05 20:16:10 +00:00
|
|
|
$ret = $db->insert('app', $clause);
|
|
|
|
if (!$ret) return $ret;
|
|
|
|
return $db->insert_id();
|
2008-03-04 23:50:38 +00:00
|
|
|
}
|
2007-11-12 22:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoincAppVersion {
|
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('app_version', 'BoincAppVersion', $clause);
|
|
|
|
}
|
2008-03-05 20:16:10 +00:00
|
|
|
static function lookup($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup('app_version', 'BoincAppVersion', $clause);
|
|
|
|
}
|
2007-11-12 22:28:17 +00:00
|
|
|
}
|
|
|
|
|
2007-10-29 04:02:41 +00:00
|
|
|
class BoincProfile {
|
2007-12-23 23:09:10 +00:00
|
|
|
static function lookup_fields($fields, $clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup_fields('profile', 'BoincProfile', $fields, $clause);
|
|
|
|
}
|
2007-10-29 04:02:41 +00:00
|
|
|
static function lookup($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup('profile', 'BoincProfile', $clause);
|
|
|
|
}
|
|
|
|
static function update_aux($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->update_aux('profile', $clause);
|
|
|
|
}
|
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->insert('profile', $clause);
|
|
|
|
}
|
2007-10-29 16:38:25 +00:00
|
|
|
static function enum($clause, $clause2=null) {
|
2007-10-29 04:02:41 +00:00
|
|
|
$db = BoincDb::get();
|
2007-10-29 16:38:25 +00:00
|
|
|
return $db->enum('profile', 'BoincProfile', $clause, $clause2);
|
2007-10-29 04:02:41 +00:00
|
|
|
}
|
2007-11-20 19:23:26 +00:00
|
|
|
function delete_aux($clause) {
|
2007-11-12 22:28:17 +00:00
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->delete_aux('profile', $clause);
|
|
|
|
}
|
2007-10-29 04:02:41 +00:00
|
|
|
}
|
|
|
|
|
2007-11-07 17:23:29 +00:00
|
|
|
class BoincTeamAdmin {
|
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->insert('team_admin', $clause);
|
|
|
|
}
|
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('team_admin', 'BoincTeamAdmin', $clause);
|
|
|
|
}
|
|
|
|
static function delete($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->delete_aux('team_admin', $clause);
|
|
|
|
}
|
|
|
|
static function lookup($teamid, $userid) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup('team_admin', 'BoincTeamAdmin', "teamid=$teamid and userid=$userid");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-12 16:00:37 +00:00
|
|
|
class BoincPrivateMessage {
|
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup_id($id, 'private_messages', 'BoincPrivateMessage');
|
|
|
|
}
|
|
|
|
function update($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->update($this, 'private_messages', $clause);
|
|
|
|
}
|
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('private_messages', 'BoincPrivateMessage', $clause);
|
|
|
|
}
|
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoincDb::get();
|
2007-12-30 22:02:16 +00:00
|
|
|
$ret = $db->insert('private_messages', $clause);
|
|
|
|
if (!$ret) return $ret;
|
|
|
|
return $db->insert_id();
|
2007-11-12 16:00:37 +00:00
|
|
|
}
|
|
|
|
static function count($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->count('private_messages', $clause);
|
|
|
|
}
|
|
|
|
function delete() {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->delete($this, 'private_messages');
|
|
|
|
}
|
2007-11-12 22:28:17 +00:00
|
|
|
function delete_aux($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->delete_aux('private_messages', $clause);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BoincPlatform {
|
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('platform', 'BoincPlatform', $clause);
|
|
|
|
}
|
2008-07-03 18:41:13 +00:00
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup_id($id, 'platform', 'BoincPlatform');
|
|
|
|
}
|
2007-11-12 16:00:37 +00:00
|
|
|
}
|
|
|
|
|
2007-10-26 21:14:35 +00:00
|
|
|
?>
|