2007-10-30 22:31:13 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-30 22:31:13 +00:00
|
|
|
|
2008-01-28 22:42:05 +00:00
|
|
|
// Bolt exercise API
|
|
|
|
|
2007-11-29 23:26:49 +00:00
|
|
|
$bolt_ex_mode = 0;
|
|
|
|
$bolt_ex_index = 0;
|
|
|
|
$bolt_ex_state = 0;
|
|
|
|
$bolt_ex_score = 0;
|
2007-12-19 16:31:41 +00:00
|
|
|
$bolt_ex_query_string = "";
|
2007-11-29 23:26:49 +00:00
|
|
|
|
2008-02-08 17:20:09 +00:00
|
|
|
function exclusive_choice($choices) {
|
2007-11-29 23:26:49 +00:00
|
|
|
global $bolt_ex_mode; // input
|
|
|
|
global $bolt_ex_index; // input
|
2007-12-18 20:28:08 +00:00
|
|
|
global $bolt_ex_score; // incremental output if SCORE
|
2007-12-19 16:31:41 +00:00
|
|
|
global $bolt_ex_query_string;
|
|
|
|
|
|
|
|
parse_str($bolt_ex_query_string);
|
2007-11-29 16:47:56 +00:00
|
|
|
|
2007-11-29 23:26:49 +00:00
|
|
|
switch ($bolt_ex_mode) {
|
2007-11-29 16:47:56 +00:00
|
|
|
case BOLT_MODE_SHOW:
|
2007-11-29 23:26:49 +00:00
|
|
|
shuffle($choices);
|
|
|
|
$i = 0;
|
2007-12-07 23:23:25 +00:00
|
|
|
start_table();
|
2007-11-29 16:47:56 +00:00
|
|
|
foreach ($choices as $choice) {
|
2007-12-07 23:23:25 +00:00
|
|
|
row2($choice, "<input name=q_$bolt_ex_index type=radio value=$i>");
|
2007-11-29 23:26:49 +00:00
|
|
|
$i++;
|
2007-11-29 16:47:56 +00:00
|
|
|
}
|
2007-12-07 23:23:25 +00:00
|
|
|
end_table();
|
2007-11-29 16:47:56 +00:00
|
|
|
break;
|
|
|
|
case BOLT_MODE_SCORE:
|
2007-11-29 23:26:49 +00:00
|
|
|
$right_ans = $choices[0];
|
|
|
|
shuffle($choices);
|
2007-12-18 20:28:08 +00:00
|
|
|
$key = "q_$bolt_ex_index";
|
2007-12-19 16:31:41 +00:00
|
|
|
if (isset($$key)) {
|
|
|
|
$response = $$key;
|
2007-12-18 20:28:08 +00:00
|
|
|
if ($choices[$response] == $right_ans) {
|
|
|
|
$bolt_ex_score += 1;
|
|
|
|
}
|
2007-11-29 23:26:49 +00:00
|
|
|
}
|
2007-11-29 16:47:56 +00:00
|
|
|
break;
|
|
|
|
case BOLT_MODE_ANSWER:
|
2007-11-29 23:26:49 +00:00
|
|
|
$right_ans = $choices[0];
|
|
|
|
shuffle($choices);
|
2007-12-18 20:28:08 +00:00
|
|
|
$key = "q_$bolt_ex_index";
|
2007-12-19 16:31:41 +00:00
|
|
|
if (isset($$key)) {
|
|
|
|
$response = $$key;
|
2007-12-18 20:28:08 +00:00
|
|
|
} else {
|
|
|
|
$response = -1;
|
|
|
|
}
|
2007-11-29 23:26:49 +00:00
|
|
|
$i = 0;
|
2007-12-07 23:23:25 +00:00
|
|
|
start_table();
|
2007-11-29 23:26:49 +00:00
|
|
|
foreach ($choices as $choice) {
|
2008-02-01 23:11:09 +00:00
|
|
|
$x = "<td><br></td>";
|
|
|
|
if ($response == $i) {
|
|
|
|
if ($choice == $right_ans) {
|
|
|
|
$x = "<td bgcolor=#88ff88>Right</a>";
|
|
|
|
} else {
|
|
|
|
$x = "<td bgcolor=#ff8888>You chose this answer</a>";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($choice == $right_ans) {
|
|
|
|
$x = "<td>Right answer</td>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "<tr><td width=50% class=fieldname>$choice $x </tr>";
|
2007-11-29 23:26:49 +00:00
|
|
|
$i++;
|
|
|
|
}
|
2007-12-07 23:23:25 +00:00
|
|
|
end_table();
|
2007-11-29 16:47:56 +00:00
|
|
|
break;
|
2007-10-30 22:31:13 +00:00
|
|
|
}
|
2007-11-29 23:26:49 +00:00
|
|
|
$bolt_ex_index++;
|
2007-10-30 22:31:13 +00:00
|
|
|
}
|
2007-12-01 22:43:11 +00:00
|
|
|
|
2008-02-08 17:20:09 +00:00
|
|
|
function inclusive_choice($choices) {
|
2007-12-10 22:13:48 +00:00
|
|
|
global $bolt_ex_mode; // input
|
|
|
|
global $bolt_ex_index; // input
|
2007-12-18 20:28:08 +00:00
|
|
|
global $bolt_ex_score; // incremental output if SCORE
|
2007-12-19 16:31:41 +00:00
|
|
|
global $bolt_ex_query_string;
|
|
|
|
|
|
|
|
parse_str($bolt_ex_query_string);
|
2007-12-10 22:13:48 +00:00
|
|
|
|
|
|
|
switch ($bolt_ex_mode) {
|
|
|
|
case BOLT_MODE_SHOW:
|
|
|
|
shuffle($choices);
|
|
|
|
$i = 0;
|
|
|
|
start_table();
|
|
|
|
foreach ($choices as $choice) {
|
|
|
|
$c = $choice[0];
|
2007-12-18 20:28:08 +00:00
|
|
|
row2("<input name=q_".$bolt_ex_index."_$i type=checkbox>", $c);
|
2007-12-10 22:13:48 +00:00
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
end_table();
|
|
|
|
break;
|
|
|
|
case BOLT_MODE_SCORE:
|
|
|
|
$i = 0;
|
|
|
|
$n = count($choices);
|
|
|
|
$score = 0;
|
|
|
|
shuffle($choices);
|
|
|
|
foreach ($choices as $choice) {
|
2007-12-12 04:43:04 +00:00
|
|
|
$key = "q_".$bolt_ex_index."_$i";
|
2007-12-19 16:31:41 +00:00
|
|
|
$response = isset($$key);
|
2007-12-10 22:13:48 +00:00
|
|
|
$r = $choice[1];
|
|
|
|
$correct = ($r && $response) || (!$r && !$response);
|
|
|
|
if ($correct) $score += 1./$n;
|
2007-12-18 20:28:08 +00:00
|
|
|
$i++;
|
2007-12-10 22:13:48 +00:00
|
|
|
}
|
2007-12-18 20:28:08 +00:00
|
|
|
$bolt_ex_score += $score;
|
2007-12-10 22:13:48 +00:00
|
|
|
break;
|
|
|
|
case BOLT_MODE_ANSWER:
|
|
|
|
$i = 0;
|
|
|
|
$n = count($choices);
|
|
|
|
shuffle($choices);
|
|
|
|
start_table();
|
2007-12-18 20:28:08 +00:00
|
|
|
table_header("Choice", "Correct?", "Your answer");
|
2007-12-10 22:13:48 +00:00
|
|
|
foreach ($choices as $choice) {
|
|
|
|
$c = $choice[0];
|
2007-12-12 04:43:04 +00:00
|
|
|
$key = "q_".$bolt_ex_index."_$i";
|
2007-12-19 16:31:41 +00:00
|
|
|
$response = isset($$key);
|
2007-12-10 22:13:48 +00:00
|
|
|
$r = $choice[1];
|
|
|
|
$correct = ($r && $response) || (!$r && !$response);
|
2008-02-01 23:11:09 +00:00
|
|
|
$color = $correct?"#88ff88":"#ff8888";
|
|
|
|
table_row($c, $r?"yes":"no",
|
|
|
|
array($response?"yes":"no", "bgcolor=$color")
|
|
|
|
);
|
2007-12-10 22:13:48 +00:00
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
end_table();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$bolt_ex_index++;
|
|
|
|
}
|
|
|
|
|
2008-02-08 17:20:09 +00:00
|
|
|
function image_rect($img, $rect) {
|
2007-12-01 22:43:11 +00:00
|
|
|
global $bolt_ex_mode; // input
|
|
|
|
global $bolt_ex_index; // input
|
|
|
|
global $bolt_ex_state; // output if SHOW, else input
|
2007-12-18 20:28:08 +00:00
|
|
|
global $bolt_ex_score; // incremental output if SCORE
|
2007-12-01 22:43:11 +00:00
|
|
|
|
2007-12-19 16:31:41 +00:00
|
|
|
parse_str($bolt_ex_query_string);
|
|
|
|
|
2007-12-01 22:43:11 +00:00
|
|
|
switch ($bolt_ex_mode) {
|
|
|
|
case BOLT_MODE_SHOW:
|
|
|
|
echo "<img src=$img";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-30 22:31:13 +00:00
|
|
|
?>
|