From be20ad2af278b3ff8f32fad0cb54637c0e585635 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 29 Nov 2007 23:26:49 +0000 Subject: [PATCH] - web: updating forum prefs would undo banishment, reset #posts, and clear moderator flags. Fixed. svn path=/trunk/boinc/; revision=14324 --- checkin_notes | 10 ++ html/inc/bolt.inc | 18 ++- html/inc/bolt_ex.inc | 61 ++++++++- html/inc/db_conn.inc | 4 +- html/user/bolt_sched.php | 138 ++++++++++++++------ html/user/edit_forum_preferences_action.php | 2 +- 6 files changed, 176 insertions(+), 57 deletions(-) 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 " +
+ + id> + + "; + require($item->filename); + echo "

+ "; + } else { + require_once($item->filename); + echo "

id&action=next&view_id=$view_id>Next"; + } + + echo "

Fraction done: $frac_done"; +} + +switch ($action) { +case 'start': + if (info_incomplete($user)) { + request_info($user, $course); + exit(); + } + start_course($user, $course, $course_doc); + break; +case 'update_info': + update_info(); + start_course($user, $course, $course_doc); +case 'next': // "next" button in lesson or exercise answer page + $view = finalize_view($user, $view_id); $e = BoltEnrollment::lookup($user->id, $course_id); + $x = get_next_item($e, $course_doc); + if (!$x->item) { + page_head("Done with course"); + echo "All done!"; + page_tail(); + exit(); + } + show_item($x->item, $x->frac_done, $user, $course, $e); + break; +case 'answer': // submit answer in exercise + $e = BoltEnrollment::lookup($user->id, $course_id); + $view = finalize_view($user, $view_id); + $x = get_current_item($e, $course_doc); + $item = $x->item; + if (!$item->is_exercise()) { + error_page("expected an exercise"); + } + if ($view->item_name != $item->name) { + error_page("unexpected name"); + } + $bolt_ex_mode = BOLT_MODE_SCORE; + $bolt_ex_index = 0; + $bolt_ex_score = 0; + require($item->filename); + echo "score: $bolt_ex_score"; + break; } -if (!$item) { - page_head("Done with course"); - echo "All done!"; - page_tail(); - exit(); -} - -$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)"); - -require_once($item->filename); - -echo "

Next"; - -echo "

Fraction done: $frac_done"; ?> diff --git a/html/user/edit_forum_preferences_action.php b/html/user/edit_forum_preferences_action.php index e27a165436..56c0d17f69 100644 --- a/html/user/edit_forum_preferences_action.php +++ b/html/user/edit_forum_preferences_action.php @@ -36,7 +36,7 @@ if (post_str("action", true)=="reset"){ $special_user = $user->prefs->special_user; $user->prefs->delete(); BoincForumPrefs::lookup($user); - $user->prefs->update("posts=$posts, banished_until=$banished_until, special_user=$special_user"); + $user->prefs->update("posts=$posts, banished_until=$banished_until, special_user='$special_user'"); Header("Location: edit_forum_preferences_form.php"); exit; }