2007-10-30 22:31:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once("../inc/db_conn.inc");
|
|
|
|
require_once("../inc/util.inc");
|
|
|
|
|
|
|
|
class BoltDb extends DbConn {
|
2007-11-29 02:56:10 +00:00
|
|
|
static $instance;
|
2007-10-30 22:31:13 +00:00
|
|
|
|
|
|
|
static function get() {
|
2007-11-29 02:56:10 +00:00
|
|
|
if (web_stopped()) {
|
|
|
|
if ($generating_xml) {
|
|
|
|
xml_error(-183);
|
|
|
|
} else {
|
|
|
|
page_head("Page not available");
|
|
|
|
echo "This page requires database access.
|
|
|
|
Our database server is temporarily shut down for maintenance.
|
|
|
|
Please try again later.
|
|
|
|
";
|
|
|
|
page_tail();
|
|
|
|
}
|
|
|
|
exit();
|
|
|
|
}
|
2007-10-30 22:31:13 +00:00
|
|
|
if (!isset($instance)) {
|
|
|
|
$config = get_config();
|
|
|
|
$user = parse_config($config, '<bolt_db_user>');
|
|
|
|
$passwd = parse_config($config, '<bolt_db_passwd>');
|
|
|
|
$host = parse_config($config, '<bolt_db_host>');
|
|
|
|
$name = parse_config($config, '<bolt_db_name>');
|
|
|
|
if ($host == null) {
|
|
|
|
$host = "localhost";
|
|
|
|
}
|
|
|
|
$instance = new DbConn();
|
|
|
|
$retval = $instance->init_conn($user, $passwd, $host, $name);
|
|
|
|
if (!$retval) return null;
|
|
|
|
}
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-29 02:56:10 +00:00
|
|
|
class BoltUser {
|
|
|
|
static $cache;
|
|
|
|
static function lookup_userid($id) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup('bolt_user', 'BoltUser', "user_id=$id");
|
|
|
|
}
|
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->insert('bolt_user', $clause);
|
|
|
|
}
|
|
|
|
static function lookup(&$user) {
|
|
|
|
if (!$user) return;
|
|
|
|
if (isset($user->bolt)) return;
|
|
|
|
if (isset(self::$cache[$user->id])) {
|
|
|
|
$bolt = self::$cache[$user->id];
|
|
|
|
} else {
|
|
|
|
$bolt = self::lookup_userid($user->id);
|
|
|
|
if (!$bolt) {
|
|
|
|
self::insert("(user_id) values ($user->id)");
|
|
|
|
$bolt = self::lookup_userid($user->id);
|
|
|
|
}
|
|
|
|
self::$cache[$user->id] = $bolt;
|
|
|
|
}
|
|
|
|
$user->bolt = $bolt;
|
|
|
|
}
|
|
|
|
function update($clause) {
|
2007-10-30 22:31:13 +00:00
|
|
|
$db = BoltDb::get();
|
2007-11-29 02:56:10 +00:00
|
|
|
$clause = "$clause where user_id=$this->user_id";
|
|
|
|
return $db->update_aux('bolt_user', $clause);
|
2007-10-30 22:31:13 +00:00
|
|
|
}
|
2007-11-29 02:56:10 +00:00
|
|
|
}
|
2007-10-30 22:31:13 +00:00
|
|
|
|
2007-11-29 02:56:10 +00:00
|
|
|
class BoltCourse {
|
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->insert('bolt_course', $clause);
|
|
|
|
}
|
2007-10-30 22:31:13 +00:00
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->lookup_id($id, 'bolt_course', 'BoltCourse');
|
|
|
|
}
|
|
|
|
static function enum() {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->enum('bolt_course', 'BoltCourse');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BoltEnrollment {
|
2007-11-29 02:56:10 +00:00
|
|
|
function insert($clause) {
|
2007-10-30 22:31:13 +00:00
|
|
|
$db = BoltDb::get();
|
2007-11-29 02:56:10 +00:00
|
|
|
return $db->insert('bolt_enrollment', $clause);
|
2007-10-30 22:31:13 +00:00
|
|
|
}
|
2007-11-29 02:56:10 +00:00
|
|
|
function lookup($user_id, $course_id) {
|
2007-10-30 22:31:13 +00:00
|
|
|
$db = BoltDb::get();
|
2007-11-29 02:56:10 +00:00
|
|
|
return $db->lookup('bolt_enrollment', 'BoltEnrollment', "user_id=$user_id and course_id=$course_id");
|
2007-10-30 22:31:13 +00:00
|
|
|
}
|
2007-11-29 02:56:10 +00:00
|
|
|
function update($clause) {
|
2007-10-30 22:31:13 +00:00
|
|
|
$db = BoltDb::get();
|
2007-11-29 02:56:10 +00:00
|
|
|
$db->update_aux('bolt_enrollment', "$clause where user_id=$this->user_id and course_id=$this->course_id");
|
2007-10-30 22:31:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BoltView {
|
2007-11-29 02:56:10 +00:00
|
|
|
static function insert($clause) {
|
2007-10-30 22:31:13 +00:00
|
|
|
$db = BoltDb::get();
|
2007-11-29 02:56:10 +00:00
|
|
|
$ret = $db->insert('bolt_view', $clause);
|
|
|
|
if (!$ret) return null;
|
|
|
|
return $db->insert_id();
|
2007-10-30 22:31:13 +00:00
|
|
|
}
|
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->lookup_id($id, 'bolt_view', 'BoltView');
|
|
|
|
}
|
|
|
|
function update($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
$db->update($this, 'bolt_view', $clause);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|