bolt->update("sex=$sex, birth_year=$birth_year"); } $course_doc = require_once($course->doc_file); 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; } function start_course($user, $course, $course_doc) { $iter = new BoltIter($course_doc); $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')"); $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 "