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
|
|
|
|
2008-01-01 18:07:13 +00:00
|
|
|
// Bolt scheduler.
|
|
|
|
// GET args:
|
|
|
|
// course_id: course ID
|
|
|
|
// action: see commands below
|
2007-10-30 22:31:13 +00:00
|
|
|
|
|
|
|
require_once("../inc/bolt.inc");
|
2008-01-28 22:42:05 +00:00
|
|
|
require_once("../inc/bolt_sched.inc");
|
2007-10-30 22:31:13 +00:00
|
|
|
require_once("../inc/bolt_db.inc");
|
2007-11-29 23:26:49 +00:00
|
|
|
require_once("../inc/bolt_ex.inc");
|
2007-12-07 23:23:25 +00:00
|
|
|
require_once("../inc/bolt_util.inc");
|
2007-10-30 22:31:13 +00:00
|
|
|
require_once("../inc/util.inc");
|
|
|
|
|
2008-10-20 18:28:58 +00:00
|
|
|
function debug_show_state($state, $tag) {
|
|
|
|
global $user;
|
|
|
|
global $refresh;
|
|
|
|
if ($user->bolt->flags&BOLT_FLAGS_DEBUG) {
|
|
|
|
echo "$tag state: <pre>"; print_r($state); echo "</pre>\n";
|
|
|
|
if ($refresh) {
|
|
|
|
echo "<p>Refresh ID: $refresh->id<p>";
|
|
|
|
}
|
|
|
|
echo "<hr>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function debug_show_item($item) {
|
|
|
|
global $user;
|
|
|
|
if ($user->bolt->flags&BOLT_FLAGS_DEBUG) {
|
|
|
|
echo "Item:<pre>"; print_r($item); echo "</pre>\n";
|
|
|
|
echo "<hr>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-29 23:26:49 +00:00
|
|
|
function update_info() {
|
2007-12-18 20:28:08 +00:00
|
|
|
global $user;
|
2007-11-29 02:56:10 +00:00
|
|
|
$sex = get_int('sex');
|
|
|
|
$birth_year = get_int('birth_year');
|
|
|
|
$user->bolt->update("sex=$sex, birth_year=$birth_year");
|
|
|
|
}
|
|
|
|
|
2008-10-20 18:28:58 +00:00
|
|
|
// The user clicked something on a page.
|
|
|
|
// Look up the view record (the ID is in the URL) and update it
|
|
|
|
// with the action and the time.
|
|
|
|
// Return the record.
|
2008-01-01 18:07:13 +00:00
|
|
|
//
|
2008-01-30 19:29:51 +00:00
|
|
|
function finalize_view($view_id, $action) {
|
|
|
|
global $user;
|
2007-11-29 23:26:49 +00:00
|
|
|
if (!$view_id) return null;
|
2007-10-30 22:31:13 +00:00
|
|
|
$view = BoltView::lookup_id($view_id);
|
2007-12-18 20:28:08 +00:00
|
|
|
if (!$view) {
|
|
|
|
error_page("no view");
|
|
|
|
}
|
|
|
|
if ($view->user_id != $user->id) {
|
|
|
|
error_page("wrong user");
|
|
|
|
}
|
|
|
|
if (!$view->end_time) {
|
2007-10-30 22:31:13 +00:00
|
|
|
$now = time();
|
2007-12-07 23:23:25 +00:00
|
|
|
$view->update("end_time=$now, action=$action");
|
2007-10-30 22:31:13 +00:00
|
|
|
}
|
2007-12-18 20:28:08 +00:00
|
|
|
return $view;
|
2007-10-30 22:31:13 +00:00
|
|
|
}
|
|
|
|
|
2007-12-07 23:23:25 +00:00
|
|
|
function default_mode($item) {
|
|
|
|
return $item->is_exercise()?BOLT_MODE_SHOW:BOLT_MODE_LESSON;
|
|
|
|
}
|
2007-10-30 22:31:13 +00:00
|
|
|
|
2008-01-01 18:07:13 +00:00
|
|
|
// A page is being shown to the user; make a record of it
|
|
|
|
//
|
2008-01-30 19:29:51 +00:00
|
|
|
function create_view($iter, $mode, $prev_view_id) {
|
|
|
|
global $user;
|
|
|
|
global $course;
|
|
|
|
|
2007-11-29 02:56:10 +00:00
|
|
|
$now = time();
|
2007-12-12 04:43:04 +00:00
|
|
|
$item = $iter->item;
|
2007-12-18 21:48:36 +00:00
|
|
|
if (!$item) {
|
|
|
|
$item = null;
|
|
|
|
$item->name = '--end--';
|
|
|
|
}
|
2007-12-04 22:16:37 +00:00
|
|
|
$state = $iter->encode_state();
|
2008-10-20 18:28:58 +00:00
|
|
|
debug_show_state($iter->state, "Ending");
|
2007-12-18 20:28:08 +00:00
|
|
|
return BoltView::insert("(user_id, course_id, item_name, start_time, mode, state, fraction_done, prev_view_id) values ($user->id, $course->id, '$item->name', $now, $mode, '$state', $iter->frac_done, $prev_view_id)");
|
2007-10-30 22:31:13 +00:00
|
|
|
}
|
|
|
|
|
2008-08-15 22:07:24 +00:00
|
|
|
function page_header($title=null) {
|
|
|
|
echo "<html><head>
|
|
|
|
";
|
|
|
|
if ($title) {
|
|
|
|
echo "
|
|
|
|
<title>$title</title>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
echo "
|
2008-02-07 01:09:30 +00:00
|
|
|
<link rel=stylesheet type=text/css href=white.css>
|
|
|
|
</head><body>
|
|
|
|
";
|
|
|
|
if (function_exists('bolt_header')) bolt_header($title);
|
|
|
|
}
|
|
|
|
|
|
|
|
function page_footer() {
|
|
|
|
if (function_exists('bolt_footer')) bolt_footer();
|
|
|
|
echo "</body></html>";
|
|
|
|
}
|
|
|
|
|
2008-01-01 18:07:13 +00:00
|
|
|
// show a page saying the course has been completed
|
|
|
|
//
|
2008-01-30 19:29:51 +00:00
|
|
|
function show_finished_page($view_id, $prev_view_id) {
|
|
|
|
global $course;
|
2008-01-31 23:43:37 +00:00
|
|
|
global $url_args;
|
2008-01-30 19:29:51 +00:00
|
|
|
|
2008-02-07 01:09:30 +00:00
|
|
|
page_header("Course completed");
|
2008-02-13 19:02:44 +00:00
|
|
|
if ($course->bossa_app_id) {
|
|
|
|
require_once("../inc/bossa_db.inc");
|
|
|
|
$app = BossaApp::lookup_id($course->bossa_app_id);
|
|
|
|
echo "
|
|
|
|
Congratulations - you have completed the training for $course->name.
|
|
|
|
<p>
|
|
|
|
You may now
|
2008-02-15 15:25:44 +00:00
|
|
|
<a href=bossa_get_job.php?bossa_app_id=$course->bossa_app_id>do work</a>.
|
2008-02-13 19:02:44 +00:00
|
|
|
";
|
|
|
|
} else {
|
|
|
|
echo "Congratulations - you have completed this course.";
|
|
|
|
$links[] = "<a href=bolt_sched.php?$url_args&action=prev&view_id=$view_id><img src=img/prev.gif></a>";
|
|
|
|
$up_link = "<a href=bolt_sched.php?$url_args&action=course_home&view_id=$view_id>Course home page</a>";
|
|
|
|
show_nav($links, $up_link, $view_id);
|
|
|
|
}
|
2008-02-07 01:09:30 +00:00
|
|
|
page_footer();
|
2007-12-18 21:48:36 +00:00
|
|
|
}
|
|
|
|
|
2008-01-31 23:43:37 +00:00
|
|
|
function show_refresh_finished() {
|
2008-02-07 01:09:30 +00:00
|
|
|
page_header("Refresh completed");
|
2008-08-14 21:05:02 +00:00
|
|
|
echo "<a href=bolt.php>Return to courses</a>";
|
2008-02-07 01:09:30 +00:00
|
|
|
page_footer();
|
2008-01-31 23:43:37 +00:00
|
|
|
}
|
|
|
|
|
2008-02-07 01:09:30 +00:00
|
|
|
function show_nav($links, $up_link, $view_id) {
|
2008-01-30 19:29:51 +00:00
|
|
|
global $course;
|
2008-02-07 01:09:30 +00:00
|
|
|
|
2008-01-30 19:29:51 +00:00
|
|
|
echo "<p><center>
|
|
|
|
<table width=60%><tr>
|
|
|
|
";
|
|
|
|
foreach ($links as $link) {
|
|
|
|
echo "<td align=center>$link</td>";
|
|
|
|
}
|
|
|
|
echo "</tr></table> </center>
|
2008-02-01 23:11:09 +00:00
|
|
|
<hr>
|
|
|
|
<br>
|
2008-02-07 01:09:30 +00:00
|
|
|
<form action=bolt_sched.php>
|
|
|
|
<input type=hidden name=course_id value=$course->id>
|
|
|
|
<input type=hidden name=action value=question>
|
|
|
|
<input type=hidden name=view_id value=$view_id>
|
|
|
|
<textarea name=question cols=60>Enter question or comment here</textarea>
|
2008-02-01 23:11:09 +00:00
|
|
|
<br>
|
2008-02-05 21:26:43 +00:00
|
|
|
<input type=submit value=Submit>
|
2008-02-07 01:09:30 +00:00
|
|
|
</form>
|
2008-01-30 19:29:51 +00:00
|
|
|
<p>
|
2008-02-01 23:11:09 +00:00
|
|
|
$up_link
|
2008-01-30 19:29:51 +00:00
|
|
|
";
|
|
|
|
}
|
|
|
|
|
2008-01-01 18:07:13 +00:00
|
|
|
// show an item (lesson, exercise, answer page)
|
|
|
|
//
|
2008-01-30 19:29:51 +00:00
|
|
|
function show_item($iter, $view_id, $prev_view_id, $mode, $repeat=null) {
|
|
|
|
global $user;
|
|
|
|
global $course;
|
2007-12-07 23:23:25 +00:00
|
|
|
global $bolt_ex_mode;
|
|
|
|
global $bolt_ex_index;
|
2007-12-18 20:28:08 +00:00
|
|
|
global $bolt_ex_score;
|
2008-01-01 18:07:13 +00:00
|
|
|
global $bolt_query_string;
|
2008-01-31 23:43:37 +00:00
|
|
|
global $refresh;
|
|
|
|
global $url_args;
|
2007-12-07 23:23:25 +00:00
|
|
|
|
2007-12-12 04:43:04 +00:00
|
|
|
$item = $iter->item;
|
2008-08-15 22:07:24 +00:00
|
|
|
page_header();
|
2008-01-01 18:07:13 +00:00
|
|
|
$bolt_query_string = $item->query_string;
|
2007-12-18 20:28:08 +00:00
|
|
|
|
2008-01-30 19:29:51 +00:00
|
|
|
$links = array();
|
|
|
|
if ($prev_view_id) {
|
2008-02-01 23:11:09 +00:00
|
|
|
$links[] = "<a href=bolt_sched.php?$url_args&action=prev&view_id=$view_id><img src=img/prev.gif></a>";
|
2008-01-30 19:29:51 +00:00
|
|
|
}
|
|
|
|
|
2008-02-01 23:11:09 +00:00
|
|
|
$next = "<a href=bolt_sched.php?$url_args&action=next&view_id=$view_id><img src=img/next.gif></a>";
|
2008-01-30 19:29:51 +00:00
|
|
|
|
2007-12-18 21:48:36 +00:00
|
|
|
if ($item->is_exercise()) {
|
2007-12-07 23:23:25 +00:00
|
|
|
$bolt_ex_mode = $mode;
|
2007-11-29 23:26:49 +00:00
|
|
|
$bolt_ex_index = 0;
|
2007-12-07 23:23:25 +00:00
|
|
|
switch ($mode) {
|
|
|
|
case BOLT_MODE_SHOW:
|
|
|
|
echo "
|
|
|
|
<form action=bolt_sched.php>
|
|
|
|
<input type=hidden name=view_id value=$view_id>
|
|
|
|
<input type=hidden name=course_id value=$course->id>
|
|
|
|
<input type=hidden name=action value=answer>
|
|
|
|
";
|
2008-01-31 23:43:37 +00:00
|
|
|
if ($refresh) {
|
|
|
|
echo "
|
|
|
|
<input type=hidden name=refresh_id value=$refresh->id>
|
|
|
|
";
|
|
|
|
}
|
2007-12-07 23:23:25 +00:00
|
|
|
srand($view_id);
|
|
|
|
require($item->filename);
|
2007-12-18 20:28:08 +00:00
|
|
|
if (function_exists('bolt_divide')) bolt_divide();
|
2008-02-01 23:11:09 +00:00
|
|
|
$next = "<input type=image src=img/next.gif value=OK></form>";
|
2007-12-07 23:23:25 +00:00
|
|
|
break;
|
|
|
|
case BOLT_MODE_ANSWER:
|
|
|
|
require($item->filename);
|
2007-12-18 20:28:08 +00:00
|
|
|
if (function_exists('bolt_divide')) bolt_divide();
|
|
|
|
$score_pct = number_format($bolt_ex_score*100);
|
2008-02-07 23:21:31 +00:00
|
|
|
echo "Score: $score_pct%";
|
2007-12-07 23:23:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-12-18 21:48:36 +00:00
|
|
|
} else {
|
2007-11-29 23:26:49 +00:00
|
|
|
require_once($item->filename);
|
2007-12-18 20:28:08 +00:00
|
|
|
if (function_exists('bolt_divide')) bolt_divide();
|
2007-11-29 23:26:49 +00:00
|
|
|
}
|
2007-10-30 22:31:13 +00:00
|
|
|
|
2008-01-30 19:29:51 +00:00
|
|
|
if ($repeat) {
|
2008-02-07 23:21:31 +00:00
|
|
|
$avg = number_format($repeat->avg_score*100, 0);
|
|
|
|
echo "<p>Score on this exercise set: $avg%";
|
2008-01-30 19:29:51 +00:00
|
|
|
if ($repeat->flags & REVIEW) {
|
2008-02-07 01:09:30 +00:00
|
|
|
//echo "<pre>";
|
|
|
|
//print_r($repeat);
|
|
|
|
//echo "</pre>";
|
2008-01-30 19:29:51 +00:00
|
|
|
$name = urlencode($repeat->unit->name);
|
2008-02-07 01:09:30 +00:00
|
|
|
$r = "<a href=bolt_sched.php?$url_args&action=review&view_id=$view_id&unit_name=$name>Review, then repeat exercises</a>";
|
2008-01-30 19:29:51 +00:00
|
|
|
$links[] = $r;
|
|
|
|
}
|
|
|
|
if ($repeat->flags & REPEAT) {
|
2008-02-07 01:09:30 +00:00
|
|
|
$r = "<a href=bolt_sched.php?$url_args&action=repeat&view_id=$view_id>Repeat exercises</a>";
|
2008-01-30 19:29:51 +00:00
|
|
|
$links[] = $r;
|
|
|
|
}
|
|
|
|
if ($repeat->flags & NEXT) {
|
|
|
|
$links[] = $next;
|
|
|
|
}
|
2007-12-18 20:28:08 +00:00
|
|
|
} else {
|
2008-01-30 19:29:51 +00:00
|
|
|
$links[] = $next;
|
2007-12-18 20:28:08 +00:00
|
|
|
}
|
|
|
|
|
2008-02-01 23:11:09 +00:00
|
|
|
$up_link = "<a href=bolt_sched.php?$url_args&action=course_home&view_id=$view_id>Course home page</a>";
|
2008-02-07 01:09:30 +00:00
|
|
|
show_nav($links, $up_link, $view_id);
|
2008-01-30 19:29:51 +00:00
|
|
|
|
2008-02-07 01:09:30 +00:00
|
|
|
page_footer();
|
2007-12-18 20:28:08 +00:00
|
|
|
|
2008-01-31 23:43:37 +00:00
|
|
|
if ($refresh) {
|
|
|
|
$refresh->update("last_view_id=$view_id");
|
|
|
|
} else {
|
|
|
|
$e = new BoltEnrollment();
|
|
|
|
$e->user_id = $user->id;
|
|
|
|
$e->course_id = $course->id;
|
|
|
|
$e->update("last_view_id=$view_id");
|
|
|
|
}
|
2007-12-07 23:23:25 +00:00
|
|
|
}
|
|
|
|
|
2007-12-18 23:37:26 +00:00
|
|
|
// 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;
|
2008-01-01 18:07:13 +00:00
|
|
|
global $bolt_query_string;
|
2007-12-18 23:37:26 +00:00
|
|
|
|
|
|
|
$bolt_ex_mode = BOLT_MODE_ANSWER;
|
|
|
|
$bolt_ex_index = 0;
|
|
|
|
|
|
|
|
$item = $iter->item;
|
2008-08-15 22:07:24 +00:00
|
|
|
page_header();
|
2008-01-01 18:07:13 +00:00
|
|
|
$bolt_query_string = $item->query_string;
|
2007-12-18 23:37:26 +00:00
|
|
|
require_once($item->filename);
|
|
|
|
if (function_exists('bolt_divide')) bolt_divide();
|
|
|
|
$score_pct = number_format($score*100);
|
|
|
|
echo "Score: $score_pct%";
|
2008-02-07 01:09:30 +00:00
|
|
|
page_footer();
|
2007-12-18 23:37:26 +00:00
|
|
|
}
|
|
|
|
|
2008-01-31 23:43:37 +00:00
|
|
|
function start_course() {
|
2008-01-30 19:29:51 +00:00
|
|
|
global $user;
|
|
|
|
global $course;
|
2008-01-31 23:43:37 +00:00
|
|
|
global $course_doc;
|
2008-01-30 19:29:51 +00:00
|
|
|
|
2007-12-07 23:23:25 +00:00
|
|
|
BoltEnrollment::delete($user->id, $course->id);
|
|
|
|
$iter = new BoltIter($course_doc);
|
|
|
|
$iter->at();
|
|
|
|
|
|
|
|
$now = time();
|
|
|
|
$mode = default_mode($iter->item);
|
2008-01-30 19:29:51 +00:00
|
|
|
$view_id = create_view($iter, $mode, 0);
|
2007-12-12 04:43:04 +00:00
|
|
|
BoltEnrollment::insert("(create_time, user_id, course_id, last_view_id) values ($now, $user->id, $course->id, $view_id)");
|
2008-01-30 19:29:51 +00:00
|
|
|
show_item($iter, $view_id, 0, $mode);
|
2007-11-29 23:26:49 +00:00
|
|
|
}
|
|
|
|
|
2008-10-20 21:19:13 +00:00
|
|
|
function start_refresh() {
|
2008-01-31 23:43:37 +00:00
|
|
|
global $course_doc;
|
|
|
|
global $refresh;
|
|
|
|
|
|
|
|
$xset_result = BoltXsetResult::lookup_id($refresh->xset_result_id);
|
2008-08-21 23:24:11 +00:00
|
|
|
if (!$xset_result) error_page("Exercise set result not found");
|
2008-01-31 23:43:37 +00:00
|
|
|
$view = BoltView::lookup_id($xset_result->view_id);
|
|
|
|
if (!$view) error_page("view not found");
|
|
|
|
$iter = new BoltIter($course_doc);
|
|
|
|
$iter->decode_state($view->state);
|
|
|
|
$iter->at();
|
|
|
|
$xset = $iter->xset;
|
|
|
|
if (!$xset || $xset->name != $xset_result->name) {
|
|
|
|
error_page("missing exercise set");
|
|
|
|
}
|
2008-10-20 21:19:13 +00:00
|
|
|
$xset->restart($iter);
|
2008-01-31 23:43:37 +00:00
|
|
|
$iter->at();
|
|
|
|
$mode = default_mode($iter->item);
|
|
|
|
$view_id = create_view($iter, $mode, 0);
|
|
|
|
show_item($iter, $view_id, 0, $mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = get_logged_in_user();
|
|
|
|
BoltUser::lookup($user);
|
|
|
|
$course_id = get_int('course_id');
|
|
|
|
$refresh_id = get_int('refresh_id', true);
|
|
|
|
$refresh = null;
|
|
|
|
$url_args = "course_id=$course_id";
|
|
|
|
if ($refresh_id) {
|
|
|
|
$refresh = BoltRefreshRec::lookup_id($refresh_id);
|
|
|
|
if (!$refresh) error_page("No such refresh");
|
|
|
|
if ($refresh->user_id != $user->id) error_page("Wrong user");
|
|
|
|
if ($refresh->course_id != $course_id) error_page("Wrong course");
|
|
|
|
$url_args .= "&refresh_id=$refresh_id";
|
|
|
|
}
|
|
|
|
$course = BoltCourse::lookup_id($course_id);
|
|
|
|
if (!$course) {
|
|
|
|
error_page("no such course");
|
|
|
|
}
|
|
|
|
$view_id = get_int('view_id', true);
|
|
|
|
$action = get_str('action', true);
|
2008-08-14 15:46:30 +00:00
|
|
|
$course_doc = require_once($course->doc_file());
|
2008-01-31 23:43:37 +00:00
|
|
|
|
2007-11-29 23:26:49 +00:00
|
|
|
switch ($action) {
|
|
|
|
case 'start':
|
|
|
|
if (info_incomplete($user)) {
|
|
|
|
request_info($user, $course);
|
|
|
|
exit();
|
|
|
|
}
|
2008-01-31 23:43:37 +00:00
|
|
|
if ($refresh) {
|
2008-10-20 21:19:13 +00:00
|
|
|
start_refresh();
|
2008-01-31 23:43:37 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$e = BoltEnrollment::lookup($user->id, $course_id);
|
2007-12-04 22:16:37 +00:00
|
|
|
if ($e) {
|
2008-02-07 23:21:31 +00:00
|
|
|
page_header("Confirm restart");
|
2007-12-04 22:16:37 +00:00
|
|
|
echo "You are already enrolled in $course->name.
|
2008-02-07 23:21:31 +00:00
|
|
|
<p>
|
|
|
|
Are you sure you want to start over from the beginning?
|
|
|
|
<p>
|
2007-12-04 22:16:37 +00:00
|
|
|
";
|
|
|
|
show_button(
|
2008-01-31 23:43:37 +00:00
|
|
|
"bolt_sched.php?action=start_confirm&$url_args",
|
2007-12-04 22:16:37 +00:00
|
|
|
"Yes",
|
|
|
|
"Start this course from the beginning"
|
|
|
|
);
|
2008-02-07 23:21:31 +00:00
|
|
|
show_button(
|
|
|
|
"bolt_sched.php?action=resume&$url_args",
|
|
|
|
"Resume",
|
|
|
|
"Resume course from current position"
|
|
|
|
);
|
|
|
|
page_footer();
|
2007-12-04 22:16:37 +00:00
|
|
|
exit();
|
|
|
|
}
|
2008-01-31 23:43:37 +00:00
|
|
|
// fall through
|
2007-12-04 22:16:37 +00:00
|
|
|
case 'start_confirm':
|
2008-01-31 23:43:37 +00:00
|
|
|
start_course();
|
2007-11-29 23:26:49 +00:00
|
|
|
break;
|
|
|
|
case 'update_info':
|
|
|
|
update_info();
|
2008-01-31 23:43:37 +00:00
|
|
|
start_course();
|
2008-02-01 23:11:09 +00:00
|
|
|
break;
|
2007-12-12 04:43:04 +00:00
|
|
|
case 'prev':
|
2008-01-30 19:29:51 +00:00
|
|
|
$view = finalize_view($view_id, BOLT_ACTION_PREV);
|
2008-10-23 20:35:39 +00:00
|
|
|
debug_show_state(unserialize($view->state), "Initial");
|
2007-12-18 20:28:08 +00:00
|
|
|
if ($view->prev_view_id) {
|
|
|
|
$view = BoltView::lookup_id($view->prev_view_id);
|
|
|
|
$iter = new BoltIter($course_doc);
|
|
|
|
$iter->decode_state($view->state);
|
|
|
|
$iter->at();
|
2008-02-10 05:17:57 +00:00
|
|
|
$mode = $view->mode;
|
|
|
|
if ($mode == BOLT_MODE_ANSWER) {
|
|
|
|
$v2 = BoltView::lookup_id($view->prev_view_id);
|
|
|
|
$result = BoltResult::lookup_id($v2->result_id);
|
2008-08-14 15:46:30 +00:00
|
|
|
srand($v2->id);
|
|
|
|
$bolt_ex_score = $result->score;
|
2008-02-10 05:17:57 +00:00
|
|
|
$bolt_ex_query_string = $result->response;
|
|
|
|
}
|
2008-01-30 19:29:51 +00:00
|
|
|
$view_id = create_view($iter, $mode, $view->prev_view_id);
|
|
|
|
show_item($iter, $view_id, $view->prev_view_id, $mode);
|
2007-12-18 20:28:08 +00:00
|
|
|
} else {
|
|
|
|
error_page("At start of course");
|
|
|
|
}
|
2007-12-12 04:43:04 +00:00
|
|
|
break;
|
2007-11-29 23:26:49 +00:00
|
|
|
case 'next': // "next" button in lesson or exercise answer page
|
2008-01-30 19:29:51 +00:00
|
|
|
$view = finalize_view($view_id, BOLT_ACTION_NEXT);
|
2008-10-23 20:35:39 +00:00
|
|
|
debug_show_state(unserialize($view->state), "Initial");
|
2007-12-12 04:43:04 +00:00
|
|
|
|
|
|
|
$iter = new BoltIter($course_doc);
|
|
|
|
$iter->decode_state($view->state);
|
|
|
|
$iter->next();
|
|
|
|
|
2008-10-20 21:19:13 +00:00
|
|
|
if ($refresh) {
|
|
|
|
$iter->at();
|
|
|
|
if (!$iter->xset) {
|
|
|
|
// if we're doing a refresh and are no longer in an xset,
|
|
|
|
// we must have finished the refresh
|
|
|
|
//
|
|
|
|
show_refresh_finished();
|
|
|
|
$refresh->update('count=count+1');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-18 20:28:08 +00:00
|
|
|
if ($iter->item) {
|
|
|
|
$state = $iter->encode_state();
|
|
|
|
$mode = default_mode($iter->item);
|
2008-01-30 19:29:51 +00:00
|
|
|
$view_id = create_view($iter, $mode, $view->id);
|
|
|
|
show_item($iter, $view_id, $view->id, $mode);
|
2007-12-18 20:28:08 +00:00
|
|
|
} else {
|
2008-10-20 21:19:13 +00:00
|
|
|
// course finished
|
|
|
|
$iter->frac_done = 1;
|
|
|
|
$fin_view_id = create_view($iter, BOLT_MODE_FINISHED, $view_id);
|
|
|
|
$e = new BoltEnrollment();
|
|
|
|
$e->user_id = $user->id;
|
|
|
|
$e->course_id = $course->id;
|
|
|
|
$e->update("last_view_id=$fin_view_id");
|
|
|
|
show_finished_page($fin_view_id, $view->id);
|
2007-11-29 23:26:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'answer': // submit answer in exercise
|
2008-01-30 19:29:51 +00:00
|
|
|
$view = finalize_view($view_id, BOLT_ACTION_SUBMIT);
|
2008-10-23 20:35:39 +00:00
|
|
|
debug_show_state(unserialize($view->state), "Initial");
|
2007-12-12 04:43:04 +00:00
|
|
|
$iter = new BoltIter($course_doc);
|
|
|
|
$iter->decode_state($view->state);
|
|
|
|
$iter->at();
|
|
|
|
|
2008-10-20 18:28:58 +00:00
|
|
|
debug_show_item($iter->item);
|
2007-12-04 22:16:37 +00:00
|
|
|
$item = $iter->item;
|
2007-11-29 23:26:49 +00:00
|
|
|
if (!$item->is_exercise()) {
|
2008-01-01 18:07:13 +00:00
|
|
|
print_r($item);
|
2007-11-29 23:26:49 +00:00
|
|
|
error_page("expected an exercise");
|
|
|
|
}
|
|
|
|
if ($view->item_name != $item->name) {
|
|
|
|
error_page("unexpected name");
|
|
|
|
}
|
2008-01-01 18:07:13 +00:00
|
|
|
|
|
|
|
// compute the score
|
|
|
|
|
2007-12-19 16:31:41 +00:00
|
|
|
$bolt_ex_query_string = $_SERVER['QUERY_STRING'];
|
2007-11-29 23:26:49 +00:00
|
|
|
$bolt_ex_mode = BOLT_MODE_SCORE;
|
|
|
|
$bolt_ex_index = 0;
|
|
|
|
$bolt_ex_score = 0;
|
2008-01-01 18:07:13 +00:00
|
|
|
$bolt_query_string = $item->query_string;
|
2007-12-07 23:23:25 +00:00
|
|
|
srand($view_id);
|
2008-10-23 20:35:39 +00:00
|
|
|
ob_start(); // buffer output to avoid showing exercise text
|
2007-11-29 23:26:49 +00:00
|
|
|
require($item->filename);
|
2007-11-30 00:38:38 +00:00
|
|
|
ob_end_clean();
|
2007-12-07 23:23:25 +00:00
|
|
|
|
2007-12-18 20:28:08 +00:00
|
|
|
$bolt_ex_score /= $bolt_ex_index;
|
|
|
|
|
2008-10-23 20:35:39 +00:00
|
|
|
if ($item->callback) {
|
|
|
|
$user->bolt->attrs = unserialize($user->bolt->attrs);
|
|
|
|
call_user_func(
|
|
|
|
$item->callback, $user, $bolt_ex_score, $bolt_ex_query_string
|
|
|
|
);
|
|
|
|
$user->bolt->attrs = serialize($user->bolt->attrs);
|
|
|
|
$attrs = $user->bolt->attrs;
|
|
|
|
$user->bolt->update("attrs='$attrs'");
|
|
|
|
}
|
|
|
|
|
2008-01-01 18:07:13 +00:00
|
|
|
// make a record of the result
|
|
|
|
|
2007-12-18 23:37:26 +00:00
|
|
|
$qs = BoltDb::escape_string($_SERVER['QUERY_STRING']);
|
2008-08-14 15:46:30 +00:00
|
|
|
$now = time();
|
2007-12-07 23:23:25 +00:00
|
|
|
$result_id = BoltResult::insert(
|
2008-08-14 15:46:30 +00:00
|
|
|
"(create_time, user_id, course_id, view_id, item_name, score, response)
|
|
|
|
values ($now, $user->id, $course->id, $view->id, '$view->item_name', $bolt_ex_score, '$qs')"
|
2007-12-07 23:23:25 +00:00
|
|
|
);
|
|
|
|
$view->update("result_id=$result_id");
|
2008-01-01 18:07:13 +00:00
|
|
|
|
2008-01-28 22:42:05 +00:00
|
|
|
// If this is part of an exercise set, call its callback function
|
|
|
|
//
|
2008-02-07 01:09:30 +00:00
|
|
|
$repeat = null;
|
2008-08-14 21:05:02 +00:00
|
|
|
$xset = $iter->xset;
|
|
|
|
if ($xset) {
|
2008-10-23 20:35:39 +00:00
|
|
|
$is_last = $xset->xset_record_score(
|
|
|
|
$iter, $bolt_ex_score, $view->id, $avg_score, $repeat
|
|
|
|
);
|
2008-02-07 01:09:30 +00:00
|
|
|
if ($repeat) $repeat->avg_score = $avg_score;
|
2008-01-31 23:43:37 +00:00
|
|
|
if ($is_last) {
|
|
|
|
// if the exercise set if finished, make or update DB records
|
|
|
|
//
|
2008-10-23 20:35:39 +00:00
|
|
|
if ($xset->callback) {
|
|
|
|
$user->bolt->attrs = unserialize($user->bolt->attrs);
|
|
|
|
call_user_func($xset->callback, $user, $avg_score);
|
|
|
|
$user->bolt->attrs = serialize($user->bolt->attrs);
|
|
|
|
$attrs = $user->bolt->attrs;
|
|
|
|
$user->bolt->update("attrs='$attrs'");
|
|
|
|
}
|
2008-01-31 23:43:37 +00:00
|
|
|
$now = time();
|
|
|
|
$id = BoltXsetResult::insert("(create_time, user_id, course_id, name, score, view_id) values ($now, $user->id, $course->id, '$xset->name', $avg_score, $view_id)");
|
2008-10-20 18:28:58 +00:00
|
|
|
$refresh_intervals = $xset->refresh;
|
|
|
|
if ($refresh_intervals) {
|
2008-08-14 21:05:02 +00:00
|
|
|
$refresh_rec = BoltRefreshRec::lookup(
|
|
|
|
"user_id=$user->id and course_id=$course->id and name='$xset->name'"
|
2008-01-31 23:43:37 +00:00
|
|
|
);
|
2008-08-14 21:05:02 +00:00
|
|
|
if ($refresh_rec) {
|
|
|
|
$count = $refresh_rec->count;
|
2008-10-20 18:28:58 +00:00
|
|
|
$n = count($refresh_intervals->intervals);
|
2008-08-14 21:05:02 +00:00
|
|
|
if ($count >= $n) {
|
|
|
|
$count = $n - 1;
|
|
|
|
}
|
2008-10-20 18:28:58 +00:00
|
|
|
$due_time = time() + $refresh_intervals->intervals[$count]*86400;
|
2008-08-14 21:05:02 +00:00
|
|
|
$refresh_rec->update("create_time=$now, xset_result_id=$id, due_time=$due_time");
|
|
|
|
} else {
|
2008-10-20 18:28:58 +00:00
|
|
|
$due_time = time() + $refresh_intervals->intervals[0]*86400;
|
2008-08-14 21:05:02 +00:00
|
|
|
BoltRefreshRec::insert(
|
|
|
|
"(user_id, course_id, name, create_time, xset_result_id, due_time, count) values ($user->id, $course->id, '$xset->name', $now, $id, $due_time, 0)"
|
|
|
|
);
|
|
|
|
}
|
2008-01-31 23:43:37 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-28 22:42:05 +00:00
|
|
|
}
|
|
|
|
|
2008-01-01 18:07:13 +00:00
|
|
|
// show the answer page
|
|
|
|
|
2007-12-07 23:23:25 +00:00
|
|
|
srand($view_id);
|
2008-01-30 19:29:51 +00:00
|
|
|
$view_id = create_view($iter, BOLT_MODE_ANSWER, $view->id);
|
|
|
|
show_item($iter, $view_id, $view->id, BOLT_MODE_ANSWER, $repeat);
|
2007-12-07 23:23:25 +00:00
|
|
|
break;
|
2007-12-18 23:37:26 +00:00
|
|
|
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);
|
2007-12-19 16:31:41 +00:00
|
|
|
$bolt_ex_query_string = $result->response;
|
2007-12-18 23:37:26 +00:00
|
|
|
show_answer_page($iter, $result->score);
|
|
|
|
break;
|
2007-12-19 16:31:41 +00:00
|
|
|
case 'course_home':
|
2008-01-30 19:29:51 +00:00
|
|
|
$view = finalize_view($view_id, BOLT_ACTION_COURSE_HOME);
|
2007-12-19 16:31:41 +00:00
|
|
|
Header("Location: bolt.php");
|
|
|
|
break;
|
2008-01-30 19:29:51 +00:00
|
|
|
case 'review':
|
2008-10-20 21:19:13 +00:00
|
|
|
// user chose to do review then repeat an exercise set
|
|
|
|
//
|
2008-01-30 19:29:51 +00:00
|
|
|
$view = finalize_view($view_id, BOLT_ACTION_REVIEW);
|
2008-10-23 20:35:39 +00:00
|
|
|
debug_show_state(unserialize($view->state), "Initial");
|
2008-01-30 19:29:51 +00:00
|
|
|
$iter = new BoltIter($course_doc);
|
|
|
|
$iter->decode_state($view->state);
|
|
|
|
$iter->at();
|
|
|
|
if (!$iter->xset) {
|
|
|
|
echo "NO XSET"; exit;
|
|
|
|
}
|
|
|
|
$xset = $iter->xset;
|
|
|
|
$unit_name = get_str('unit_name');
|
|
|
|
$found = $xset->start_review($iter, $unit_name);
|
|
|
|
if (!$found) {
|
|
|
|
echo "REVIEW UNIT MISSING"; exit;
|
|
|
|
}
|
|
|
|
$iter->at();
|
|
|
|
$mode = default_mode($iter->item);
|
|
|
|
$view_id = create_view($iter, $mode, $view->id);
|
|
|
|
show_item($iter, $view_id, $view->id, $mode);
|
|
|
|
break;
|
|
|
|
case 'repeat':
|
2008-10-20 21:19:13 +00:00
|
|
|
// user chose to repeat an exercise set
|
|
|
|
//
|
2008-01-30 19:29:51 +00:00
|
|
|
$view = finalize_view($view_id, BOLT_ACTION_REPEAT);
|
2008-10-23 20:35:39 +00:00
|
|
|
debug_show_state(unserialize($view->state), "Initial");
|
2008-01-30 19:29:51 +00:00
|
|
|
$iter = new BoltIter($course_doc);
|
|
|
|
$iter->decode_state($view->state);
|
|
|
|
$iter->at();
|
|
|
|
if (!$iter->xset) {
|
|
|
|
echo "NO XSET"; exit;
|
|
|
|
}
|
|
|
|
$xset = $iter->xset;
|
2008-10-20 21:19:13 +00:00
|
|
|
$xset->restart($iter);
|
2008-01-30 19:29:51 +00:00
|
|
|
$iter->at();
|
|
|
|
$mode = default_mode($iter->item);
|
|
|
|
$view_id = create_view($iter, $mode, $view->id);
|
|
|
|
show_item($iter, $view_id, $view->id, $mode);
|
|
|
|
break;
|
2008-01-31 23:43:37 +00:00
|
|
|
case 'resume':
|
2008-10-20 21:19:13 +00:00
|
|
|
// user chose to resume a course or refresh
|
|
|
|
//
|
2008-01-31 23:43:37 +00:00
|
|
|
if ($refresh) {
|
|
|
|
if ($refresh->last_view_id) {
|
|
|
|
$view = BoltView::lookup_id($refresh->last_view_id);
|
|
|
|
} else {
|
2008-10-20 21:19:13 +00:00
|
|
|
start_refresh();
|
2008-01-31 23:43:37 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$view = null;
|
|
|
|
$e = BoltEnrollment::lookup($user->id, $course_id);
|
|
|
|
if ($e) {
|
|
|
|
$view = BoltView::lookup_id($e->last_view_id);
|
|
|
|
}
|
|
|
|
if (!$view) {
|
|
|
|
start_course();
|
|
|
|
break;
|
|
|
|
}
|
2007-12-18 20:28:08 +00:00
|
|
|
}
|
2007-12-18 21:48:36 +00:00
|
|
|
if ($view->mode == BOLT_MODE_FINISHED) {
|
2008-01-30 19:29:51 +00:00
|
|
|
show_finished_page($view->id, $view->prev_view_id);
|
2007-12-18 21:48:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-12-12 04:43:04 +00:00
|
|
|
$iter = new BoltIter($course_doc);
|
|
|
|
$iter->decode_state($view->state);
|
|
|
|
$iter->at();
|
2007-12-19 16:31:41 +00:00
|
|
|
$mode = $view->mode;
|
|
|
|
if ($view->item_name == $iter->item->name && ($mode == BOLT_MODE_ANSWER)) {
|
|
|
|
// if we're returning to an answer page,
|
|
|
|
// we need to look up the user's responses and the score.
|
|
|
|
//
|
|
|
|
$view_orig = BoltView::lookup_id($view->prev_view_id);
|
|
|
|
$result = BoltResult::lookup_id($view_orig->result_id);
|
|
|
|
srand($view_orig->id);
|
|
|
|
$bolt_ex_query_string = $result->response;
|
|
|
|
$bolt_ex_score = $result->score;
|
|
|
|
$bolt_ex_index = 0;
|
2008-01-30 19:29:51 +00:00
|
|
|
$view_id = create_view($iter, $mode, $view_orig->id);
|
|
|
|
show_item($iter, $view_id, $view_orig->id, $mode);
|
2007-12-19 16:31:41 +00:00
|
|
|
} else {
|
2008-01-30 19:29:51 +00:00
|
|
|
$view_id = create_view($iter, $mode, $view->id);
|
|
|
|
show_item($iter, $view_id, $view->id, $mode);
|
2007-12-19 16:31:41 +00:00
|
|
|
}
|
2007-11-29 23:26:49 +00:00
|
|
|
break;
|
2008-02-07 01:09:30 +00:00
|
|
|
case 'question':
|
|
|
|
$view = finalize_view($view_id, BOLT_ACTION_QUESTION);
|
2008-10-23 20:35:39 +00:00
|
|
|
debug_show_state(unserialize($view->state), "Initial");
|
2008-02-07 01:09:30 +00:00
|
|
|
$now = time();
|
|
|
|
$question = BoltDb::escape_string(get_str('question'));
|
|
|
|
BoltQuestion::insert("(create_time, user_id, course_id, name, question, state) values ($now, $user->id, $course->id, '$view->item_name', '$question', 0)");
|
|
|
|
page_header("Question recorded");
|
|
|
|
echo "
|
|
|
|
Thanks; we have recorded your question.
|
|
|
|
Questions help us improve this course.
|
|
|
|
We aren't able to individually respond to all questions.
|
|
|
|
Responses are delivered as private messages.
|
|
|
|
<p>
|
|
|
|
<a href=bolt_sched.php?$url_args&action=resume>Resume course</a>
|
|
|
|
";
|
|
|
|
page_footer();
|
|
|
|
break;
|
2008-01-31 23:43:37 +00:00
|
|
|
default:
|
|
|
|
error_page("unknown action: $action");
|
2007-11-29 23:26:49 +00:00
|
|
|
}
|
2007-11-29 02:56:10 +00:00
|
|
|
|
2007-10-30 22:31:13 +00:00
|
|
|
?>
|