2007-10-30 22:31:13 +00:00
|
|
|
<?php
|
|
|
|
|
2007-11-29 02:56:10 +00:00
|
|
|
// Bolt scheduler. GET args:
|
2007-10-30 22:31:13 +00:00
|
|
|
// course_id: course ID
|
|
|
|
// action:
|
2007-11-29 02:56:10 +00:00
|
|
|
// 'start' or none: show current (or first) item,
|
|
|
|
// and prompt for user info if any missing
|
2007-10-30 22:31:13 +00:00
|
|
|
// 'next': go to next lesson
|
|
|
|
// answers:
|
|
|
|
// JSON represenation of exercise answers
|
|
|
|
|
|
|
|
require_once("../inc/bolt.inc");
|
|
|
|
require_once("../inc/bolt_db.inc");
|
|
|
|
require_once("../inc/util.inc");
|
|
|
|
|
|
|
|
$user = get_logged_in_user();
|
2007-11-29 02:56:10 +00:00
|
|
|
BoltUser::lookup($user);
|
2007-10-30 22:31:13 +00:00
|
|
|
$course_id = get_int('course_id');
|
|
|
|
$view_id = get_int('view_id', true);
|
|
|
|
$action = get_str('action', true);
|
|
|
|
|
|
|
|
$course = BoltCourse::lookup_id($course_id);
|
|
|
|
if (!$course) {
|
|
|
|
error_page("no such course");
|
|
|
|
}
|
|
|
|
|
2007-11-29 02:56:10 +00:00
|
|
|
if ($action == '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();
|
|
|
|
}
|
|
|
|
|
2007-10-30 22:31:13 +00:00
|
|
|
$course_doc = require_once($course->doc_file);
|
|
|
|
|
|
|
|
if ($view_id) {
|
|
|
|
$view = BoltView::lookup_id($view_id);
|
|
|
|
if ($view && $view->user_id == $user->id && !$view->end_time) {
|
|
|
|
$now = time();
|
|
|
|
$view->update("end_time=$now");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-29 02:56:10 +00:00
|
|
|
$frac_done = 0;
|
2007-10-30 22:31:13 +00:00
|
|
|
$e = BoltEnrollment::lookup($user->id, $course_id);
|
|
|
|
if ($e) {
|
|
|
|
$iter = new BoltIter($course_doc);
|
|
|
|
$iter->stack = json_decode($e->state);
|
|
|
|
if ($action == 'next') {
|
2007-11-29 02:56:10 +00:00
|
|
|
$item = $iter->next($frac_done);
|
2007-10-30 22:31:13 +00:00
|
|
|
$state = json_encode($iter->stack);
|
2007-11-29 02:56:10 +00:00
|
|
|
$e->update("state='$state'");
|
2007-10-30 22:31:13 +00:00
|
|
|
} else if ($action == 'start') {
|
|
|
|
$iter->stack = null;
|
2007-11-29 02:56:10 +00:00
|
|
|
$item = $iter->at($frac_done);
|
2007-10-30 22:31:13 +00:00
|
|
|
$state = json_encode($iter->stack);
|
2007-11-29 02:56:10 +00:00
|
|
|
$e->update("state='$state'");
|
2007-10-30 22:31:13 +00:00
|
|
|
} else {
|
|
|
|
$item = $iter->at();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$iter = new BoltIter($course_doc);
|
|
|
|
$item = $iter->at();
|
|
|
|
|
2007-11-29 02:56:10 +00:00
|
|
|
$now = time();
|
|
|
|
$state = json_encode($iter->stack);
|
|
|
|
BoltEnrollment::insert("(create_time, user_id, course_id, state) values ($now, $user->id, $course_id, '$state')");
|
|
|
|
$e = BoltEnrollment::lookup($user->id, $course_id);
|
2007-10-30 22:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$item) {
|
|
|
|
page_head("Done with course");
|
|
|
|
echo "All done!";
|
|
|
|
page_tail();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2007-11-29 02:56:10 +00:00
|
|
|
$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)");
|
2007-10-30 22:31:13 +00:00
|
|
|
|
|
|
|
require_once($item->filename);
|
|
|
|
|
2007-11-29 02:56:10 +00:00
|
|
|
echo "<p><a href=bolt_sched.php?course_id=$course_id&action=next&view_id=$view_id>Next</a>";
|
|
|
|
|
|
|
|
echo "<p>Fraction done: $frac_done";
|
2007-10-30 22:31:13 +00:00
|
|
|
?>
|