- web: updating forum prefs would undo banishment,

reset #posts, and clear moderator flags.  Fixed.


svn path=/trunk/boinc/; revision=14324
This commit is contained in:
David Anderson 2007-11-29 23:26:49 +00:00
parent 74c2782624
commit be20ad2af2
6 changed files with 176 additions and 57 deletions

View File

@ -11832,3 +11832,13 @@ David 29 Nov 2007
app_start.C
lib/
app_ipc.h
David 29 Nov 2007
- web: updating forum prefs would undo banishment,
reset #posts, and clear moderator flags. Fixed.
html/
inc/
db_conn.inc
user/
edit_forum_preferences_action.php

View File

@ -62,22 +62,26 @@ class BoltIter {
// get current item
//
function at(&$frac_done) {
function at() {
$new_stack = array();
$this->top->walk($this->stack, $new_stack, false, $item, $frac_done);
$this->stack = $new_stack;
return $item;
$x->item = $item;
$x->frac_done = $frac_done;
return $x;
}
// move to the next item (and return it)
// return true if we're off the end
//
function next(&$frac_done) {
function next() {
$item = null;
$new_stack = array();
$this->top->walk($this->stack, $new_stack, true, $item, $frac_done);
$this->stack = $new_stack;
return $item;
$x->item = $item;
$x->frac_done = $frac-done;
return $x;
}
}
@ -182,9 +186,15 @@ class BoltItem extends BoltUnit {
}
class BoltLesson extends BoltItem {
function is_exercise() {
return false;
}
}
class BoltExercise extends BoltItem {
function is_exercise() {
return true;
}
}
function enum_course($course) {

View File

@ -1,21 +1,68 @@
<?php
function bolt_exclusive_choice($choices) {
global $bolt_mode;
global $bolt_index;
define('BOLT_MODE_SHOW', 0);
define('BOLT_MODE_SCORE', 1);
define('BOLT_MODE_ANSWER', 2);
switch ($bolt_mode) {
$bolt_ex_mode = 0;
$bolt_ex_index = 0;
$bolt_ex_state = 0;
$bolt_ex_score = 0;
function bolt_new_seed() {
return (float)microtime() * 1000000;
}
function bolt_exclusive_choice($choices) {
global $bolt_ex_mode; // input
global $bolt_ex_index; // input
global $bolt_ex_state; // output if SHOW, else input
global $bolt_ex_score; // output if SCORE
echo "BLAH";
switch ($bolt_ex_mode) {
case BOLT_MODE_SHOW:
// Shuffle the answers;
// record the RNG seed so that we can do the same shuffle later
//
$seed = bolt_new_seed();
srand($seed);
shuffle($choices);
$i = 0;
foreach ($choices as $choice) {
echo "<br><input name=q_$bolt_index type=radio> $choice";
echo "<br><input name=q_$bolt_ex_index type=radio value=$i> $choice\n";
$i++;
}
$bolt_ex_state = $seed;
break;
case BOLT_MODE_SCORE:
$resp = $_GET["q_$bolt_index"];
$seed = $bolt_ex_state;
srand($seed);
$right_ans = $choices[0];
shuffle($choices);
$response = $_GET["q_$bolt_ex_index"];
if ($choices[$response] == $right_ans) {
$bolt_ex_score = 1;
} else {
$bolt_ex_score = 0;
}
echo "FOO";
break;
case BOLT_MODE_ANSWER:
$seed = $bolt_ex_state;
srand($seed);
$right_ans = $choices[0];
shuffle($choices);
$response = $_GET["q_$bolt_ex_index"];
$i = 0;
foreach ($choices as $choice) {
echo "<br>$choice";
if ($response == $i) echo "You chose this";
if ($choice == $right_ans) echo "Right answer";
$i++;
}
break;
}
$bolt_ex_index++;
}
?>

View File

@ -22,10 +22,10 @@ class DbConn {
function do_query($query) {
$q = str_replace('DBNAME', $this->db_name, $query);
//echo "query: $q<br>";
//echo "query: $q<br>\n";
$ret = mysql_query($q, $this->db_conn);
if (!$ret) {
echo "Database Error<br>";
echo "Database Error<br>\n";
//echo ": ", mysql_error(), "\n<pre>";
//var_dump(debug_backtrace());
//echo "</pre>query: $q\n";

View File

@ -11,6 +11,7 @@
require_once("../inc/bolt.inc");
require_once("../inc/bolt_db.inc");
require_once("../inc/bolt_ex.inc");
require_once("../inc/util.inc");
$user = get_logged_in_user();
@ -24,69 +25,120 @@ if (!$course) {
error_page("no such course");
}
if ($action == 'update_info') {
function 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();
}
$course_doc = require_once($course->doc_file);
if ($view_id) {
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;
}
$frac_done = 0;
$e = BoltEnrollment::lookup($user->id, $course_id);
if ($e) {
function start_course($user, $course, $course_doc) {
$iter = new BoltIter($course_doc);
$iter->stack = json_decode($e->state);
if ($action == 'next') {
$item = $iter->next($frac_done);
$state = json_encode($iter->stack);
$e->update("state='$state'");
} else if ($action == 'start') {
$iter->stack = null;
$item = $iter->at($frac_done);
$state = json_encode($iter->stack);
$e->update("state='$state'");
} else {
$item = $iter->at();
}
} else {
$iter = new BoltIter($course_doc);
$item = $iter->at();
$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')");
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 "
<form action=bolt_sched.php>
<input type=hidden name=view_id value=$view_id>
<input type=hidden name=course_id value=$course->id>
<input type=hidden name=action value=answer>
";
require($item->filename);
echo "<p><input type=submit value=OK>
";
} else {
require_once($item->filename);
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";
}
switch ($action) {
case 'start':
if (info_incomplete($user)) {
request_info($user, $course);
exit();
}
start_course($user, $course, $course_doc);
break;
case 'update_info':
update_info();
start_course($user, $course, $course_doc);
case 'next': // "next" button in lesson or exercise answer page
$view = finalize_view($user, $view_id);
$e = BoltEnrollment::lookup($user->id, $course_id);
$x = get_next_item($e, $course_doc);
if (!$x->item) {
page_head("Done with course");
echo "All done!";
page_tail();
exit();
}
show_item($x->item, $x->frac_done, $user, $course, $e);
break;
case 'answer': // submit answer in exercise
$e = BoltEnrollment::lookup($user->id, $course_id);
$view = finalize_view($user, $view_id);
$x = get_current_item($e, $course_doc);
$item = $x->item;
if (!$item->is_exercise()) {
error_page("expected an exercise");
}
if ($view->item_name != $item->name) {
error_page("unexpected name");
}
$bolt_ex_mode = BOLT_MODE_SCORE;
$bolt_ex_index = 0;
$bolt_ex_score = 0;
require($item->filename);
echo "score: $bolt_ex_score";
break;
}
if (!$item) {
page_head("Done with course");
echo "All done!";
page_tail();
exit();
}
$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)");
require_once($item->filename);
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";
?>

View File

@ -36,7 +36,7 @@ if (post_str("action", true)=="reset"){
$special_user = $user->prefs->special_user;
$user->prefs->delete();
BoincForumPrefs::lookup($user);
$user->prefs->update("posts=$posts, banished_until=$banished_until, special_user=$special_user");
$user->prefs->update("posts=$posts, banished_until=$banished_until, special_user='$special_user'");
Header("Location: edit_forum_preferences_form.php");
exit;
}