diff --git a/db/bolt_schema.sql b/db/bolt_schema.sql index 18a14af39e..f1da76375c 100644 --- a/db/bolt_schema.sql +++ b/db/bolt_schema.sql @@ -24,9 +24,11 @@ create table bolt_enrollment ( mastery double not null ); --- represents a view of an item; +-- Represents a view of an item; -- created when we show the item, -- and finalized when the user clicks on something to leave the page +-- A special view is used to represent the end of a course; +-- its mode is BOLT_MODE_FINISHED. -- create table bolt_view ( id integer not null auto_increment, @@ -37,7 +39,7 @@ create table bolt_view ( state text not null, -- course state mode integer not null, - -- distnguishes exercise show/answer + -- distinguishes exercise show/answer action integer not null, -- what the user clicked start_time integer not null, diff --git a/html/inc/bolt_ex.inc b/html/inc/bolt_ex.inc index 8aedaeec22..4e196e755d 100644 --- a/html/inc/bolt_ex.inc +++ b/html/inc/bolt_ex.inc @@ -9,7 +9,6 @@ function bolt_exclusive_choice($choices) { global $bolt_ex_mode; // input global $bolt_ex_index; // input global $bolt_ex_score; // incremental output if SCORE - global $bolt_ex_response; // output if SCORE switch ($bolt_ex_mode) { case BOLT_MODE_SHOW: @@ -31,9 +30,6 @@ function bolt_exclusive_choice($choices) { if ($choices[$response] == $right_ans) { $bolt_ex_score += 1; } - $bolt_ex_response = "$bolt_ex_index: $choices[$response]"; - } else { - $bolt_ex_response = ""; } break; case BOLT_MODE_ANSWER: @@ -64,7 +60,6 @@ function bolt_inclusive_choice($choices) { global $bolt_ex_mode; // input global $bolt_ex_index; // input global $bolt_ex_score; // incremental output if SCORE - global $bolt_ex_response; // output if SCORE switch ($bolt_ex_mode) { case BOLT_MODE_SHOW: @@ -91,7 +86,6 @@ function bolt_inclusive_choice($choices) { if ($correct) $score += 1./$n; $i++; } - $bolt_ex_response = "$bolt_ex_index: $choices[$response]"; $bolt_ex_score += $score; break; case BOLT_MODE_ANSWER: diff --git a/html/user/bolt_course.php b/html/user/bolt_course.php index f397c0c284..fc35b444a0 100644 --- a/html/user/bolt_course.php +++ b/html/user/bolt_course.php @@ -35,15 +35,16 @@ function show_view($view) { if ($view->result_id) { $result = BoltResult::lookup_id($view->result_id); - $x = "Score: $result->score -
Answer: $result->response"; + $qs = str_replace("action=answer", "action=answer_page", $result->response); + $x = "
Score: $result->score +
Answer page"; } echo " - ".time_str($view->start_time)." - $dur - $view->item_name - ".mode_name($view->mode)." $x - ".action_name($view->action)." + ".time_str($view->start_time)." + $dur + $view->item_name + ".mode_name($view->mode)." $x + ".action_name($view->action)." "; } @@ -57,7 +58,7 @@ page_head("Your history in $course->name"); $views = BoltView::enum("user_id=$user->id and course_id=$course_id order by id desc"); start_table(); -table_header("Time", "Duration", "Name", "Type", "Action"); +table_header("Time", "Duration", "Item", "Type", "Action"); foreach ($views as $view) { show_view($view); } diff --git a/html/user/bolt_sched.php b/html/user/bolt_sched.php index 423702220d..a5c40cb869 100644 --- a/html/user/bolt_sched.php +++ b/html/user/bolt_sched.php @@ -148,6 +148,25 @@ function show_item($iter, $user, $course, $view_id, $prev_view_id, $mode) { $e->update("last_view_id=$view_id"); } +// Show the student the results of an old exercise; no navigation items +// +function show_answer_page($iter, $score) { + global $bolt_ex_mode; + global $bolt_ex_index; + + $bolt_ex_mode = BOLT_MODE_ANSWER; + $bolt_ex_index = 0; + + $item = $iter->item; + page_head(null); + if (function_exists('bolt_header')) bolt_header($item->title); + require_once($item->filename); + if (function_exists('bolt_divide')) bolt_divide(); + $score_pct = number_format($score*100); + echo "Score: $score_pct%"; + if (function_exists('bolt_footer')) bolt_footer(); +} + function start_course($user, $course, $course_doc) { BoltEnrollment::delete($user->id, $course->id); $iter = new BoltIter($course_doc); @@ -237,24 +256,35 @@ case 'answer': // submit answer in exercise $bolt_ex_mode = BOLT_MODE_SCORE; $bolt_ex_index = 0; $bolt_ex_score = 0; - $bolt_ex_response = ""; srand($view_id); ob_start(); // turn on output buffering require($item->filename); ob_end_clean(); - $bolt_ex_response = BoltDb::escape_string($bolt_ex_response); $bolt_ex_score /= $bolt_ex_index; + $qs = BoltDb::escape_string($_SERVER['QUERY_STRING']); $result_id = BoltResult::insert( "(view_id, score, response) - values ($view->id, $bolt_ex_score, '$bolt_ex_response')" + values ($view->id, $bolt_ex_score, '$qs')" ); $view->update("result_id=$result_id"); srand($view_id); $view_id = create_view($user, $course, $iter, BOLT_MODE_ANSWER, $view->id); show_item($iter, $user, $course, $view_id, $view->id, BOLT_MODE_ANSWER); break; +case 'answer_page': + $view = BoltView::lookup_id($view_id); + $iter = new BoltIter($course_doc); + $iter->decode_state($view->state); + $iter->at(); + if ($iter->item->name != $view->item_name) { + error_page("Exercise no longer exists in course"); + } + $result = BoltResult::lookup_id($view->result_id); + srand($view_id); + show_answer_page($iter, $result->score); + break; default: $view = $e?BoltView::lookup_id($e->last_view_id):null; if (!$view) {