2007-10-30 22:31:13 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-30 22:31:13 +00:00
|
|
|
|
|
|
|
require_once("../inc/db_conn.inc");
|
|
|
|
require_once("../inc/util.inc");
|
|
|
|
|
2008-01-28 15:48:09 +00:00
|
|
|
define('BOLT_PHASE_STUDY', 1);
|
2008-01-31 23:43:37 +00:00
|
|
|
// sequential progress through course
|
2008-01-28 15:48:09 +00:00
|
|
|
define('BOLT_PHASE_REVIEW', 2);
|
2008-01-17 18:09:30 +00:00
|
|
|
// review and repeat of an exercise set
|
2008-01-28 15:48:09 +00:00
|
|
|
define('BOLT_PHASE_REFRESH', 3);
|
2008-01-31 23:43:37 +00:00
|
|
|
// timed repeat of exercise set, and possibly review and repeat
|
2008-01-17 18:09:30 +00:00
|
|
|
|
2007-12-07 23:23:25 +00:00
|
|
|
define('BOLT_MODE_LESSON', 1);
|
|
|
|
define('BOLT_MODE_SHOW', 2);
|
|
|
|
define('BOLT_MODE_SCORE', 3);
|
|
|
|
define('BOLT_MODE_ANSWER', 4);
|
2007-12-18 21:48:36 +00:00
|
|
|
define('BOLT_MODE_FINISHED', 5);
|
2007-12-07 23:23:25 +00:00
|
|
|
|
|
|
|
define('BOLT_ACTION_NONE', 0);
|
|
|
|
define('BOLT_ACTION_NEXT', 1);
|
2007-12-12 04:43:04 +00:00
|
|
|
define('BOLT_ACTION_PREV', 2);
|
|
|
|
define('BOLT_ACTION_SUBMIT', 3);
|
|
|
|
define('BOLT_ACTION_QUESTION', 4);
|
2007-12-19 16:31:41 +00:00
|
|
|
define('BOLT_ACTION_COURSE_HOME', 5);
|
2008-01-30 19:29:51 +00:00
|
|
|
define('BOLT_ACTION_REVIEW', 6);
|
|
|
|
define('BOLT_ACTION_REPEAT', 7);
|
2007-12-07 23:23:25 +00:00
|
|
|
|
2008-02-15 15:25:44 +00:00
|
|
|
define('BOLT_COURSE_NOT_STARTED', 1);
|
|
|
|
define('BOLT_COURSE_STARTED', 2);
|
|
|
|
define('BOLT_COURSE_FINISHED', 3);
|
|
|
|
|
2008-02-01 23:11:09 +00:00
|
|
|
// bits in bolt_user.flags
|
|
|
|
define('BOLT_FLAGS_DEBUG', 1); // print debugging info in output pages
|
|
|
|
define('BOLT_FLAGS_SHOW_ALL', 2); // show hidden courses
|
|
|
|
|
2007-10-30 22:31:13 +00:00
|
|
|
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();
|
|
|
|
$name = parse_config($config, '<bolt_db_name>');
|
2008-06-29 20:57:21 +00:00
|
|
|
if (!$name) {
|
|
|
|
$name = parse_config($config, '<db_name>');
|
|
|
|
$user = parse_config($config, '<db_user>');
|
|
|
|
$passwd = parse_config($config, '<db_passwd>');
|
|
|
|
$host = parse_config($config, '<db_host>');
|
|
|
|
} else {
|
|
|
|
$user = parse_config($config, '<bolt_db_user>');
|
|
|
|
$passwd = parse_config($config, '<bolt_db_passwd>');
|
|
|
|
$host = parse_config($config, '<bolt_db_host>');
|
|
|
|
}
|
2007-10-30 22:31:13 +00:00
|
|
|
if ($host == null) {
|
|
|
|
$host = "localhost";
|
|
|
|
}
|
|
|
|
$instance = new DbConn();
|
|
|
|
$retval = $instance->init_conn($user, $passwd, $host, $name);
|
|
|
|
if (!$retval) return null;
|
|
|
|
}
|
|
|
|
return $instance;
|
|
|
|
}
|
2007-12-12 04:43:04 +00:00
|
|
|
static function escape_string($string) {
|
|
|
|
$db = self::get();
|
|
|
|
return $db->base_escape_string($string);
|
|
|
|
}
|
2007-10-30 22:31:13 +00:00
|
|
|
}
|
|
|
|
|
2007-11-29 02:56:10 +00:00
|
|
|
class BoltUser {
|
|
|
|
static $cache;
|
|
|
|
static function lookup_userid($id) {
|
2008-02-13 04:25:52 +00:00
|
|
|
$db = BoltDb::get();
|
2007-11-29 02:56:10 +00:00
|
|
|
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();
|
2008-02-13 19:02:44 +00:00
|
|
|
$ret = $db->insert('bolt_course', $clause);
|
|
|
|
if (!$ret) return $ret;
|
|
|
|
return $db->insert_id();
|
2007-11-29 02:56:10 +00:00
|
|
|
}
|
2007-10-30 22:31:13 +00:00
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->lookup_id($id, 'bolt_course', 'BoltCourse');
|
|
|
|
}
|
2008-02-15 15:25:44 +00:00
|
|
|
static function lookup_name($name) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->lookup('bolt_course', 'BoltCourse', "short_name='$name'");
|
|
|
|
}
|
2007-10-30 22:31:13 +00:00
|
|
|
static function enum() {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->enum('bolt_course', 'BoltCourse');
|
|
|
|
}
|
2008-02-01 23:11:09 +00:00
|
|
|
function update($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->update($this, 'bolt_course', $clause);
|
|
|
|
}
|
2008-08-14 15:46:30 +00:00
|
|
|
function doc_file() {
|
|
|
|
$sn = $this->short_name;
|
|
|
|
return "../inc/$sn.inc";
|
|
|
|
}
|
2007-10-30 22:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoltEnrollment {
|
2008-06-24 22:20:40 +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
|
|
|
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
|
|
|
}
|
2008-08-21 23:24:11 +00:00
|
|
|
static function delete($user_id, $course_id) {
|
2007-12-07 23:23:25 +00:00
|
|
|
$db = BoltDb::get();
|
|
|
|
$db->delete_aux('bolt_enrollment', "user_id=$user_id and course_id=$course_id");
|
|
|
|
}
|
2008-08-21 23:24:11 +00:00
|
|
|
static function delete_aux($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
$db->delete_aux('bolt_enrollment', $clause);
|
|
|
|
}
|
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);
|
|
|
|
}
|
2007-12-07 23:23:25 +00:00
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->enum('bolt_view', 'BoltView', $clause);
|
|
|
|
}
|
2008-08-21 23:24:11 +00:00
|
|
|
static function delete_aux($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
$db->delete_aux('bolt_view', $clause);
|
|
|
|
}
|
2007-12-07 23:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoltResult {
|
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
$ret = $db->insert('bolt_result', $clause);
|
|
|
|
if (!$ret) return null;
|
|
|
|
return $db->insert_id();
|
|
|
|
}
|
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->lookup_id($id, 'bolt_result', 'BoltResult');
|
|
|
|
}
|
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoltDb::get();
|
2008-06-26 23:24:43 +00:00
|
|
|
return $db->enum('bolt_result', 'BoltResult', $clause);
|
2007-12-07 23:23:25 +00:00
|
|
|
}
|
2008-08-21 23:24:11 +00:00
|
|
|
static function delete_aux($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
$db->delete_aux('bolt_result', $clause);
|
|
|
|
}
|
2007-10-30 22:31:13 +00:00
|
|
|
}
|
|
|
|
|
2008-01-17 18:09:30 +00:00
|
|
|
class BoltXsetResult {
|
2008-01-31 23:43:37 +00:00
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->lookup_id($id, 'bolt_xset_result', 'BoltXsetResult');
|
|
|
|
}
|
2008-06-24 22:20:40 +00:00
|
|
|
static function insert($clause) {
|
2008-01-17 18:09:30 +00:00
|
|
|
$db = BoltDb::get();
|
2008-01-30 19:29:51 +00:00
|
|
|
$ret = $db->insert('bolt_xset_result', $clause);
|
|
|
|
if (!$ret) return null;
|
|
|
|
return $db->insert_id();
|
2008-01-17 18:09:30 +00:00
|
|
|
}
|
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->enum('bolt_xset_result', 'BoltXsetResult', $clause);
|
|
|
|
}
|
2008-08-21 23:24:11 +00:00
|
|
|
static function delete_aux($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
$db->delete_aux('bolt_xset_result', $clause);
|
|
|
|
}
|
2008-01-17 18:09:30 +00:00
|
|
|
}
|
|
|
|
|
2008-01-30 19:29:51 +00:00
|
|
|
class BoltRefreshRec {
|
2008-01-31 23:43:37 +00:00
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->lookup_id($id, 'bolt_refresh', 'BoltRefreshRec');
|
|
|
|
}
|
|
|
|
function lookup($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->lookup('bolt_refresh', 'BoltRefreshRec', $clause);
|
|
|
|
}
|
2008-01-30 19:29:51 +00:00
|
|
|
static function replace($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->replace('bolt_refresh', $clause);
|
|
|
|
}
|
2008-06-24 22:20:40 +00:00
|
|
|
static function insert($clause) {
|
2008-02-01 23:11:09 +00:00
|
|
|
$db = BoltDb::get();
|
|
|
|
$ret = $db->insert('bolt_refresh', $clause);
|
|
|
|
if (!$ret) return null;
|
|
|
|
return $db->insert_id();
|
|
|
|
}
|
2008-01-31 23:43:37 +00:00
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->enum('bolt_refresh', 'BoltRefreshRec', $clause);
|
|
|
|
}
|
|
|
|
function update($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
$db->update($this, 'bolt_refresh', $clause);
|
|
|
|
}
|
2008-08-21 23:24:11 +00:00
|
|
|
static function delete_aux($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
$db->delete_aux('bolt_refresh', $clause);
|
|
|
|
}
|
2008-01-30 19:29:51 +00:00
|
|
|
}
|
|
|
|
|
2008-01-31 23:43:37 +00:00
|
|
|
class BoltSelectFinished {
|
2008-06-24 22:20:40 +00:00
|
|
|
static function insert($clause) {
|
2008-01-17 18:09:30 +00:00
|
|
|
$db = BoltDb::get();
|
2008-01-31 23:43:37 +00:00
|
|
|
return $db->insert('bolt_select_finished', $clause);
|
2008-01-17 18:09:30 +00:00
|
|
|
}
|
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoltDb::get();
|
2008-01-31 23:43:37 +00:00
|
|
|
return $db->enum('bolt_select_finished', 'BoltSelectFinished', $clause);
|
2008-01-17 18:09:30 +00:00
|
|
|
}
|
2008-08-21 23:24:11 +00:00
|
|
|
static function delete_aux($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
$db->delete_aux('bolt_select_finished', $clause);
|
|
|
|
}
|
2008-01-17 18:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoltQuestion {
|
2008-06-24 22:20:40 +00:00
|
|
|
static function insert($clause) {
|
2008-01-17 18:09:30 +00:00
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->insert('bolt_question', $clause);
|
|
|
|
}
|
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
return $db->enum('bolt_question', 'BoltQuestion', $clause);
|
|
|
|
}
|
2008-08-21 23:24:11 +00:00
|
|
|
static function delete_aux($clause) {
|
|
|
|
$db = BoltDb::get();
|
|
|
|
$db->delete_aux('bolt_question', $clause);
|
|
|
|
}
|
2008-01-17 18:09:30 +00:00
|
|
|
}
|
|
|
|
|
2008-02-15 15:25:44 +00:00
|
|
|
// TODO: move this somewhere else, and think about whether it's correct
|
|
|
|
//
|
|
|
|
function bolt_course_status($course_id, $user_id) {
|
|
|
|
$e = BoltEnrollment::lookup($user_id, $course_id);
|
|
|
|
if (!$e) return BOLT_COURSE_NOT_STARTED;
|
|
|
|
$view = BoltView::lookup_id($e->last_view_id);
|
|
|
|
if ($view->fraction_done == 1) return BOLT_COURSE_FINISHED;
|
|
|
|
return BOLT_COURSE_STARTED;
|
|
|
|
}
|
|
|
|
|
2007-10-30 22:31:13 +00:00
|
|
|
?>
|