. require_once("../inc/bolt_db.inc"); require_once("../inc/util_ops.inc"); function show_course($course) { $x = "$course->name
Description: $course->description
Created: ".date_str($course->create_time)." "; $y = "id>Map
id>Experiments
"; row2_init($x, $y); if ($course->hidden) { show_button("bolt_admin.php?action=unhide&course_id=$course->id", "Unhide", "Unhide this course"); } else { show_button("bolt_admin.php?action=hide&course_id=$course->id", "Hide", "Hide this course"); } show_button("bolt_admin.php?action=clear_confirm&course_id=$course->id", "Clear data", "Clear student data for this course"); echo ""; } function show_courses() { $courses = BoltCourse::enum(); start_table(); table_header("Course", "Tools"); foreach ($courses as $course) { show_course($course); } end_table(); } function add_course_form() { echo "
"; start_table(); row1("Add course"); row2("Course 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("", ""); 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

User settings "; admin_page_tail(); } function clear_confirm() { global $course_id; admin_page_head("Bolt course administration"); echo "This will clear all student data for this course. This is irrevocable. Are you sure you want to do this?

Yes "; admin_page_tail(); } function clear() { global $course_id; admin_page_head("Deleting course data"); BoltEnrollment::delete_aux("course_id = $course_id"); BoltView::delete_aux("course_id = $course_id"); BoltResult::delete_aux("course_id = $course_id"); BoltXsetResult::delete_aux("course_id = $course_id"); BoltSelectFinished::delete_aux("course_id = $course_id"); BoltRefreshRec::delete_aux("course_id = $course_id"); BoltQuestion::delete_aux("course_id = $course_id"); echo " Course data deleted. "; admin_page_tail(); } $user = get_logged_in_user(); $db = BoltDb::get(); if (!$db) error_page("Can't connect to database server"); if (!$db->table_exists('bolt_course')) { page_head("Create Bolt database"); $db_name = $db->db_name; echo " The database tables for Bolt don't seem to exist. To create them, go to ~/boinc/db and type

mysql $db_name < bolt_schema.sql
Then reload this page. "; page_tail(); exit(); } BoltUser::lookup($user); $course_id = get_int('course_id', true); if ($course_id) $course = BoltCourse::lookup_id($course_id); $action = get_str('action', true); switch ($action) { case 'add_course_form': admin_page_head("Add course"); add_course_form(); admin_page_tail(); break; case 'add_course': $short_name = BoltDb::escape_string(get_str('short_name')); $name = BoltDb::escape_string(get_str('course_name')); $description = BoltDb::escape_string(get_str('description')); $now = time(); BoltCourse::insert("(create_time, short_name, name, description) values ($now, '$short_name', '$name', '$description')"); Header('Location: bolt_admin.php'); break; case 'update_user_form': admin_page_head("Bolt user settings"); user_settings(); admin_page_tail(); break; case '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_admin.php'); break; case 'hide': if (!$course) error_page("no such course"); $course->update("hidden=1"); Header('Location: bolt_admin.php'); break; case 'unhide': if (!$course) error_page("no such course"); $course->update("hidden=0"); Header('Location: bolt_admin.php'); break; case 'clear_confirm': clear_confirm(); break; case 'clear': clear(); break; case '': show_all(); break; default: error_page("unknown action $action"); } ?>