From 904cbe5a4f3f9665cf5b36ccd6dedb9ad192226c Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 1 Feb 2008 23:11:09 +0000 Subject: [PATCH] - Add Bolt admin page - added "hidden" flag to courses svn path=/trunk/boinc/; revision=14660 --- bolt_checkin_notes.txt | 18 +++++++ db/bolt_schema.sql | 5 +- html/inc/bolt_db.inc | 14 +++++ html/inc/bolt_ex.inc | 22 ++++++-- html/inc/bolt_xset.inc | 3 -- html/inc/util.inc | 4 +- html/inc/util_ops.inc | 36 ++++++------- html/ops/bolt_ops.php | 114 +++++++++++++++++++++++++++++++++++++++ html/user/bolt.php | 12 ++++- html/user/bolt_sched.php | 47 ++++++++-------- 10 files changed, 217 insertions(+), 58 deletions(-) create mode 100644 html/ops/bolt_ops.php 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 = "
"; + if ($response == $i) { + if ($choice == $right_ans) { + $x = "Right"; + } else { + $x = "You chose this answer"; + } + } else { + if ($choice == $right_ans) { + $x = "Right answer"; + } + } + echo "$choice $x "; $i++; } end_table(); @@ -109,7 +118,10 @@ function bolt_inclusive_choice($choices) { $response = isset($$key); $r = $choice[1]; $correct = ($r && $response) || (!$r && !$response); - table_row($c, $r?"yes":"no", $response?"yes":"no"); + $color = $correct?"#88ff88":"#ff8888"; + table_row($c, $r?"yes":"no", + array($response?"yes":"no", "bgcolor=$color") + ); $i++; } end_table(); diff --git a/html/inc/bolt_xset.inc b/html/inc/bolt_xset.inc index 3280766713..86381ae0b8 100644 --- a/html/inc/bolt_xset.inc +++ b/html/inc/bolt_xset.inc @@ -19,7 +19,6 @@ class BoltExerciseSet extends BoltRandom { global $user; global $refresh; - echo "XSET_CALLBACK: $score"; $nav_info = null; $state_rec = $iter->state[$this->name]; $nshown = $state_rec['nshown']; @@ -27,7 +26,6 @@ class BoltExerciseSet extends BoltRandom { $iter->state[$this->name] = $state_rec; $is_last = ($nshown+1 == $this->ntoshow); if (!$is_last) { - echo "XSET_CALLBACK: not done"; return false; } @@ -41,7 +39,6 @@ class BoltExerciseSet extends BoltRandom { } $avg_score = $total_score/($nshown+1); - echo "XSET_CALLBACK: avg $avg_score"; $repeat = null; $least = 1; foreach ($this->repeats as $r) { diff --git a/html/inc/util.inc b/html/inc/util.inc index 770335b112..93dbe43a7f 100644 --- a/html/inc/util.inc +++ b/html/inc/util.inc @@ -127,7 +127,7 @@ function show_login($user) { // if (!function_exists("page_head")){ function page_head($title, $java_onload=null, $title_plain=null, $prefix="") { - $styleSheet = URL_BASE.STYLESHEET; + $stylesheet = URL_BASE.STYLESHEET; $rssname = PROJECT . " RSS 2.0"; $rsslink = URL_BASE."rss_main.php"; @@ -142,7 +142,7 @@ function page_head($title, $java_onload=null, $title_plain=null, $prefix="") { } else { echo "".strip_tags($title_plain)."\n"; } - echo " + echo " "; diff --git a/html/inc/util_ops.inc b/html/inc/util_ops.inc index 498ca286b9..d069c4ff1e 100644 --- a/html/inc/util_ops.inc +++ b/html/inc/util_ops.inc @@ -1,41 +1,36 @@ "); -define("SM_FONT", ""); - +// TODO: get rid of the following. use style sheets define("TD", ""); define("TD2", ""); define("TD3", ""); - define("TABLE", ""); define("TABLE2", "
"); -define("TITLE_COLOR", " bgcolor=\"#000000\" "); -define("TITLE_FONT", " "); -define("BODY_COLOR", " bgcolor=\"#ffffff\" "); -define("NOLOGIN", "Not logged in. Click here to login.\n"); - function admin_page_head($title) { - //TODO: Add DOCTYPE description here when ready for HTML 4.01 - echo "$title\n"; - echo TABLE . "
" . TITLE_FONT . "".PROJECT.": $title
\n"; + $stylesheet = URL_BASE.STYLESHEET; + + echo "$title + + + +

".PROJECT.": $title

+ "; } function admin_page_tail() { - echo "

"; - echo " Back to Main admin page
\n"; - echo "\n"; + echo "

+ Back to Main admin page
+ + "; } +// TODO: get rid of all the following + function print_checkbox($text,$name,$checked) { echo "" @@ -71,4 +66,5 @@ function show_profile_link_ops($user) { } } +$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit ?> diff --git a/html/ops/bolt_ops.php b/html/ops/bolt_ops.php new file mode 100644 index 0000000000..e67292c3d8 --- /dev/null +++ b/html/ops/bolt_ops.php @@ -0,0 +1,114 @@ + + Name: $course->name
Description: $course->description
Created: ".date_str($course->create_time)." + $course->doc_file + + "; + if ($course->hidden) { + show_button("bolt_ops.php?action=unhide&course_id=$course->id", "Unhide", "Unhide this course"); + } else { + show_button("bolt_ops.php?action=hide&course_id=$course->id", "Hide", "Hide this course"); + } +} + +function show_courses() { + $courses = BoltCourse::enum(); + start_table(); + row1("Existing courses", 3); + table_header("Name/description", "Course document", ""); + foreach ($courses as $course) { + show_course($course); + } + end_table(); +} + +function add_course_form() { + echo " +
+ "; + start_table(); + row1("Add course"); + row2("Name
Visible to users
", ""); + row2("Internal name
Not visible to users; used as a directory name, so no spaces or special chars
", ""); + row2("Description
Visible to users
", ""); + row2("Course document", ""); + row2("", ""); + end_table(); + echo "
"; +} + +function user_settings() { + global $user; + $flags = $user->bolt->flags; + echo "
"; + start_table(); + row1("User settings"); + $x = ($flags&BOLT_FLAGS_SHOW_ALL)?"checked":""; + row2("Show hidden courses?", ""); + $x = ($flags&BOLT_FLAGS_DEBUG)?"checked":""; + row2("Show debugging output?", ""); + row2("", ""); + end_table(); + echo "
"; +} + +function show_all() { + admin_page_head("Bolt course administration"); + show_courses(); + echo "

"; + 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 " -

-

- - - - -
$prevUp
-
- "; + $links[] = ""; + $up_link = "Course home page"; + show_nav($links, $up_link); if (function_exists('bolt_footer')) bolt_footer(); } @@ -101,9 +93,14 @@ function show_nav($links, $up_link) { echo "$link"; } echo " - $up_link +
+ Question or comment? +
+ +
+

- 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':