diff --git a/checkin_notes b/checkin_notes
index 83f9c8848f..07c137fb46 100644
--- a/checkin_notes
+++ b/checkin_notes
@@ -11832,3 +11832,13 @@ David 29 Nov 2007
app_start.C
lib/
app_ipc.h
+
+David 29 Nov 2007
+ - web: updating forum prefs would undo banishment,
+ reset #posts, and clear moderator flags. Fixed.
+
+ html/
+ inc/
+ db_conn.inc
+ user/
+ edit_forum_preferences_action.php
diff --git a/html/inc/bolt.inc b/html/inc/bolt.inc
index bc89c0a80b..589369ab39 100644
--- a/html/inc/bolt.inc
+++ b/html/inc/bolt.inc
@@ -62,22 +62,26 @@ class BoltIter {
// get current item
//
- function at(&$frac_done) {
+ function at() {
$new_stack = array();
$this->top->walk($this->stack, $new_stack, false, $item, $frac_done);
$this->stack = $new_stack;
- return $item;
+ $x->item = $item;
+ $x->frac_done = $frac_done;
+ return $x;
}
// move to the next item (and return it)
// return true if we're off the end
//
- function next(&$frac_done) {
+ function next() {
$item = null;
$new_stack = array();
$this->top->walk($this->stack, $new_stack, true, $item, $frac_done);
$this->stack = $new_stack;
- return $item;
+ $x->item = $item;
+ $x->frac_done = $frac-done;
+ return $x;
}
}
@@ -182,9 +186,15 @@ class BoltItem extends BoltUnit {
}
class BoltLesson extends BoltItem {
+ function is_exercise() {
+ return false;
+ }
}
class BoltExercise extends BoltItem {
+ function is_exercise() {
+ return true;
+ }
}
function enum_course($course) {
diff --git a/html/inc/bolt_ex.inc b/html/inc/bolt_ex.inc
index 071c9745cb..6de38f220d 100644
--- a/html/inc/bolt_ex.inc
+++ b/html/inc/bolt_ex.inc
@@ -1,21 +1,68 @@
$choice";
+ echo "
$choice\n";
+ $i++;
}
+ $bolt_ex_state = $seed;
break;
case BOLT_MODE_SCORE:
- $resp = $_GET["q_$bolt_index"];
-
+ $seed = $bolt_ex_state;
+ srand($seed);
+ $right_ans = $choices[0];
+ shuffle($choices);
+ $response = $_GET["q_$bolt_ex_index"];
+ if ($choices[$response] == $right_ans) {
+ $bolt_ex_score = 1;
+ } else {
+ $bolt_ex_score = 0;
+ }
+ echo "FOO";
break;
case BOLT_MODE_ANSWER:
+ $seed = $bolt_ex_state;
+ srand($seed);
+ $right_ans = $choices[0];
+ shuffle($choices);
+ $response = $_GET["q_$bolt_ex_index"];
+ $i = 0;
+ foreach ($choices as $choice) {
+ echo "
$choice";
+ if ($response == $i) echo "You chose this";
+ if ($choice == $right_ans) echo "Right answer";
+ $i++;
+ }
break;
}
+ $bolt_ex_index++;
}
?>
diff --git a/html/inc/db_conn.inc b/html/inc/db_conn.inc
index 58bbc14444..1f824e7b88 100644
--- a/html/inc/db_conn.inc
+++ b/html/inc/db_conn.inc
@@ -22,10 +22,10 @@ class DbConn {
function do_query($query) {
$q = str_replace('DBNAME', $this->db_name, $query);
- //echo "query: $q
";
+ //echo "query: $q
\n";
$ret = mysql_query($q, $this->db_conn);
if (!$ret) {
- echo "Database Error
";
+ echo "Database Error
\n";
//echo ": ", mysql_error(), "\n
"; //var_dump(debug_backtrace()); //echo "query: $q\n"; diff --git a/html/user/bolt_sched.php b/html/user/bolt_sched.php index a9c5dea748..8b3e1468ee 100644 --- a/html/user/bolt_sched.php +++ b/html/user/bolt_sched.php @@ -11,6 +11,7 @@ require_once("../inc/bolt.inc"); require_once("../inc/bolt_db.inc"); +require_once("../inc/bolt_ex.inc"); require_once("../inc/util.inc"); $user = get_logged_in_user(); @@ -24,69 +25,120 @@ if (!$course) { error_page("no such course"); } -if ($action == 'update_info') { +function update_info() { $sex = get_int('sex'); $birth_year = get_int('birth_year'); $user->bolt->update("sex=$sex, birth_year=$birth_year"); - $action = ""; } -if ($action == 'start' && info_incomplete($user)) { - request_info($user, $course); - exit(); -} $course_doc = require_once($course->doc_file); -if ($view_id) { +function finalize_view($user, $view_id) { + if (!$view_id) return null; $view = BoltView::lookup_id($view_id); if ($view && $view->user_id == $user->id && !$view->end_time) { $now = time(); $view->update("end_time=$now"); } + return $view; } -$frac_done = 0; -$e = BoltEnrollment::lookup($user->id, $course_id); -if ($e) { +function start_course($user, $course, $course_doc) { $iter = new BoltIter($course_doc); - $iter->stack = json_decode($e->state); - if ($action == 'next') { - $item = $iter->next($frac_done); - $state = json_encode($iter->stack); - $e->update("state='$state'"); - } else if ($action == 'start') { - $iter->stack = null; - $item = $iter->at($frac_done); - $state = json_encode($iter->stack); - $e->update("state='$state'"); - } else { - $item = $iter->at(); - } -} else { - $iter = new BoltIter($course_doc); - $item = $iter->at(); + $x = $iter->at(); $now = time(); $state = json_encode($iter->stack); - BoltEnrollment::insert("(create_time, user_id, course_id, state) values ($now, $user->id, $course_id, '$state')"); + BoltEnrollment::insert("(create_time, user_id, course_id, state) values ($now, $user->id, $course->id, '$state')"); + $e = BoltEnrollment::lookup($user->id, $course->id); + $e->update("state='$state'"); + show_item($x->item, 0, $user, $course, $e); +} + +function get_current_item($e, $course_doc) { + $frac_done = 0; + $iter = new BoltIter($course_doc); + $iter->stack = json_decode($e->state); + return $iter->at(); +} + +function get_next_item($e, $course_doc) { + $frac_done = 0; + $iter = new BoltIter($course_doc); + $iter->stack = json_decode($e->state); + $ret = $iter->next(); + $state = json_encode($iter->stack); + $e->update("state='$state'"); + return $ret; +} + + +function show_item($item, $frac_done, $user, $course, $e) { + $now = time(); + $e->update("last_view=$now, fraction_done=$frac_done"); + $view_id = BoltView::insert("(user_id, course_id, item_name, start_time) values ($user->id, $course->id, '$item->name', $now)"); + + if ($item->is_exercise()) { + $bolt_ex_mode = BOLT_MODE_SHOW; + $bolt_ex_index = 0; + echo " +