diff --git a/bolt_checkin_notes.txt b/bolt_checkin_notes.txt index dc4b196f48..0159e87892 100644 --- a/bolt_checkin_notes.txt +++ b/bolt_checkin_notes.txt @@ -81,3 +81,21 @@ David Jan 31 2008 bolt_sched.php bolt.phph bolt_compare.php + +David Feb 1 2008 + - Add Bolt admin page + - added "hidden" flag to courses + + db/ + bolt_schema.sql + html/ + inc/ + bolt_db.inc + bolt_ex.inc + util.inc + util_ops.inc + ops/ + bolt_ops.php + user/ + bolt.php + bolt_sched.php diff --git a/db/bolt_schema.sql b/db/bolt_schema.sql index 81a28a4e11..d6f40df6bd 100644 --- a/db/bolt_schema.sql +++ b/db/bolt_schema.sql @@ -2,9 +2,9 @@ create table bolt_user ( user_id integer not null, birth_year integer not null, sex tinyint not null, - debug tinyint not null, - -- if nonzero, print debug info everywhere + flags integer not null, attrs text not null, + -- project-defined. Use JSON. primary key (user_id) ); @@ -15,6 +15,7 @@ create table bolt_course ( name varchar(255) not null, description text not null, doc_file varchar(255) not null, + hidden tinyint not null, primary key (id) ); diff --git a/html/inc/bolt_db.inc b/html/inc/bolt_db.inc index 00700d32d6..12f682f805 100644 --- a/html/inc/bolt_db.inc +++ b/html/inc/bolt_db.inc @@ -25,6 +25,10 @@ define('BOLT_ACTION_COURSE_HOME', 5); define('BOLT_ACTION_REVIEW', 6); define('BOLT_ACTION_REPEAT', 7); +// bits in bolt_user.flags +define('BOLT_FLAGS_DEBUG', 1); // print debugging info in output pages +define('BOLT_FLAGS_SHOW_ALL', 2); // show hidden courses + class BoltDb extends DbConn { static $instance; @@ -108,6 +112,10 @@ class BoltCourse { $db = BoltDb::get(); return $db->enum('bolt_course', 'BoltCourse'); } + function update($clause) { + $db = BoltDb::get(); + return $db->update($this, 'bolt_course', $clause); + } } class BoltEnrollment { @@ -197,6 +205,12 @@ class BoltRefreshRec { $db = BoltDb::get(); return $db->replace('bolt_refresh', $clause); } + function insert($clause) { + $db = BoltDb::get(); + $ret = $db->insert('bolt_refresh', $clause); + if (!$ret) return null; + return $db->insert_id(); + } static function enum($clause) { $db = BoltDb::get(); return $db->enum('bolt_refresh', 'BoltRefreshRec', $clause); diff --git a/html/inc/bolt_ex.inc b/html/inc/bolt_ex.inc index bb8212fd9b..367e565e9a 100644 --- a/html/inc/bolt_ex.inc +++ b/html/inc/bolt_ex.inc @@ -50,10 +50,19 @@ function bolt_exclusive_choice($choices) { $i = 0; start_table(); foreach ($choices as $choice) { - $x = ""; - if ($response == $i) $x .= "(You chose this) "; - if ($choice == $right_ans) $x .= "(Right answer)"; - row2($choice, $x); + $x = "
" . TITLE_FONT . "".PROJECT.": $title |
"; + add_course_form(); + echo "
";
+ user_settings();
+ admin_page_tail();
+}
+
+$user = get_logged_in_user();
+BoltUser::lookup($user);
+
+$submit = get_str('submit', true);
+if ($submit == 'Create course') {
+ $short_name = get_str('short_name');
+ $name = get_str('course_name');
+ $description = get_str('description');
+ $doc_file = get_str('doc_file');
+ $now = time();
+ BoltCourse::insert("(create_time, short_name, name, description, doc_file) values ($now, '$short_name', '$name', '$description', '$doc_file')");
+ Header('Location: bolt_ops.php');
+ exit();
+} else if ($submit == 'Update user') {
+ $flags = 0;
+ if (get_str('show_all', true)) $flags |= BOLT_FLAGS_SHOW_ALL;
+ if (get_str('debug', true)) $flags |= BOLT_FLAGS_DEBUG;
+ $user->bolt->update("flags=$flags");
+ $user->bolt->flags = $flags;
+ Header('Location: bolt_ops.php');
+ exit();
+} else {
+ $action = get_str('action', true);
+ if ($action) {
+ $course_id = get_int('course_id');
+ $course = BoltCourse::lookup_id($course_id);
+ if (!$course) error_page("no such course");
+ switch ($action) {
+ case 'hide':
+ $course->update("hidden=1");
+ break;
+ case 'unhide':
+ $course->update("hidden=0");
+ break;
+ default:
+ error_page("unknown action $action");
+ }
+ Header('Location: bolt_ops.php');
+ exit();
+ }
+}
+
+show_all();
+
+?>
diff --git a/html/user/bolt.php b/html/user/bolt.php
index 05c2e7e9a7..79f5f6c1fe 100644
--- a/html/user/bolt.php
+++ b/html/user/bolt.php
@@ -6,6 +6,7 @@ require_once("../inc/util.inc");
page_head("Courses");
$user = get_logged_in_user(true);
+BoltUser::lookup($user);
$courses = BoltCourse::enum();
start_table();
@@ -13,6 +14,9 @@ table_header(
"Course", "Status"
);
foreach ($courses as $course) {
+ if ($course->hidden && !($user->bolt->flags&BOLT_FLAG_SHOW_ALL)) {
+ continue;
+ }
$e = $user?BoltEnrollment::lookup($user->id, $course->id):null;
if ($e) {
$start = date_str($e->create_time);
@@ -22,9 +26,13 @@ foreach ($courses as $course) {
$status = "Started $start
Last visit: $ago ago
$pct% done
-
id&action=resume>Resume
+ ";
+ if ($view->fraction_done < 1) {
+ $status .= "
id&action=resume>Resume
+ ";
+ }
+ $status .= "
id&action=start>Restart
id>History
-
id&action=start>Restart
";
} else {
$status = "
diff --git a/html/user/bolt_sched.php b/html/user/bolt_sched.php
index d11e88310d..2310838ef8 100644
--- a/html/user/bolt_sched.php
+++ b/html/user/bolt_sched.php
@@ -56,7 +56,7 @@ function create_view($iter, $mode, $prev_view_id) {
$item->name = '--end--';
}
$state = $iter->encode_state();
- if ($user->bolt->debug) {
+ if ($user->bolt->flags&BOLT_FLAGS_DEBUG) {
echo "
Ending state: "; print_r($iter->state); echo "\n"; } 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)"); @@ -71,17 +71,9 @@ function show_finished_page($view_id, $prev_view_id) { page_head(null); if (function_exists('bolt_header')) bolt_header("Course completed"); echo "Congratulations - you have completed this course."; - $prev = "<< Prev"; - echo " -
-
$prev | -Up | -- |
- question link
+ $up_link
";
}
@@ -126,10 +123,10 @@ function show_item($iter, $view_id, $prev_view_id, $mode, $repeat=null) {
$links = array();
if ($prev_view_id) {
- $links[] = "<< Prev";
+ $links[] = "";
}
- $next = "Next >>";
+ $next = "
";
if ($item->is_exercise()) {
$bolt_ex_mode = $mode;
@@ -150,13 +147,13 @@ function show_item($iter, $view_id, $prev_view_id, $mode, $repeat=null) {
srand($view_id);
require($item->filename);
if (function_exists('bolt_divide')) bolt_divide();
- $next = "";
+ $next = "";
break;
case BOLT_MODE_ANSWER:
require($item->filename);
if (function_exists('bolt_divide')) bolt_divide();
$score_pct = number_format($bolt_ex_score*100);
- echo "Score: $score_pct%";
+ echo "Your score: $score_pct%";
break;
}
} else {
@@ -184,7 +181,7 @@ function show_item($iter, $view_id, $prev_view_id, $mode, $repeat=null) {
$links[] = $next;
}
- $up_link = "Up";
+ $up_link = "Course home page";
show_nav($links, $up_link);
if (function_exists('bolt_footer')) bolt_footer();
@@ -310,6 +307,7 @@ case 'start_confirm':
case 'update_info':
update_info();
start_course();
+ break;
case 'prev':
$view = finalize_view($view_id, BOLT_ACTION_PREV);
if ($view->prev_view_id) {
@@ -329,13 +327,13 @@ case 'next': // "next" button in lesson or exercise answer page
$iter = new BoltIter($course_doc);
$iter->decode_state($view->state);
- if ($user->bolt->debug) {
+ if ($user->bolt->flags&BOLT_FLAGS_DEBUG) {
echo "
Initial state: "; print_r($iter->state); echo "\n"; } $iter->next(); - if ($user->bolt->debug) { + if ($user->bolt->flags&BOLT_FLAGS_DEBUG) { echo "
Item: "; print_r($iter->item); echo "\n"; } if ($iter->item) { @@ -361,12 +359,12 @@ case 'answer': // submit answer in exercise $view = finalize_view($view_id, BOLT_ACTION_SUBMIT); $iter = new BoltIter($course_doc); $iter->decode_state($view->state); - if ($user->bolt->debug) { + if ($user->bolt->flags&BOLT_FLAGS_DEBUG) { echo "
Initial state:"; print_r($iter->state); echo "\n"; } $iter->at(); - if ($user->bolt->debug) { + if ($user->bolt->flags&BOLT_FLAGS_DEBUG) { echo "
Item: "; print_r($iter->item); echo "\n"; } $item = $iter->item; @@ -419,7 +417,7 @@ case 'answer': // submit answer in exercise $refresh->update("create_time=$now, xset_result_id=$id, due_time=$due_time"); } else { BoltRefreshRec::insert( - "user_id=$user->id, course_id=$course->id, name='$this->name', create_time=$now, xset_result_id=$id, due_time=$due_time" + "(user_id, course_id, name, create_time, xset_result_id, due_time) values ($user->id, $course->id, '$xset->name', $now, $id, $due_time)" ); } } @@ -429,6 +427,7 @@ case 'answer': // submit answer in exercise srand($view_id); $view_id = create_view($iter, BOLT_MODE_ANSWER, $view->id); + $repeat = null; show_item($iter, $view_id, $view->id, BOLT_MODE_ANSWER, $repeat); break; case 'answer_page':