#------------------------------------------------------------
$string[answered] = "Answered";
-$string[choice1] = "First choice";
-$string[choice2] = "Second choice";
+$string[choice] = "Choice \$a";
$string[choicename] = "Choice name";
$string[choicetext] = "Choice text";
$string[notanswered] = "Not answered yet";
<?PHP // $Id$
-function choice_user_summary($course, $user, $mod, $choice) {
- global $CFG;
-}
-
+$CHOICE_MAX_NUMBER = 6;
function choice_user_outline($course, $user, $mod, $choice) {
if ($current = get_record_sql("SELECT * FROM choice_answers
WHERE choice='$choice->id' AND user='$user->id'")) {
- if ($current->answer == "1") {
- $result->info = "'$choice->answer1'";
- } else if ($current->answer == "2") {
- $result->info = "'$choice->answer2'";
- }
+ $result->info = "'".choice_get_answer($choice, $current->answer)."'";
$result->time = $current->timemodified;
return $result;
}
function choice_user_complete($course, $user, $mod, $choice) {
if ($current = get_record_sql("SELECT * FROM choice_answers
WHERE choice='$choice->id' AND user='$user->id'")) {
- if ($current->answer == "1") {
- $result->info = "'$choice->answer1'";
- } else if ($current->answer == "2") {
- $result->info = "'$choice->answer2'";
- }
+ $result->info = "'".choice_get_answer($choice, $current->answer)."'";
$result->time = $current->timemodified;
echo get_string("answered", "choice").": $result->info , last updated ".userdate($result->time);
} else {
return "$choice->answer1";
case 2:
return "$choice->answer2";
+ case 3:
+ return "$choice->answer3";
+ case 4:
+ return "$choice->answer4";
+ case 5:
+ return "$choice->answer5";
+ case 6:
+ return "$choice->answer6";
default:
return get_string("notanswered", "choice");
}
}
+function choice_get_choice($choiceid) {
+// Gets a full choice record
+
+ if ($choice = get_record("choice", "id", $choiceid)) {
+ $choice->answer[1] = $choice->answer1;
+ $choice->answer[2] = $choice->answer2;
+ $choice->answer[3] = $choice->answer3;
+ $choice->answer[4] = $choice->answer4;
+ $choice->answer[5] = $choice->answer5;
+ $choice->answer[6] = $choice->answer6;
+ return $choice;
+ } else {
+ return false;
+ }
+}
+
?>
<td align=right><P><B><? print_string("choicetext","choice") ?>:</B></P></TD>
<td>
<textarea name="text" rows=15 cols=30 wrap="virtual"><? p($form->text) ?></textarea>
+ <? helpbutton("text", get_string("helptext")); ?>
</td>
</tr>
<tr valign=top>
- <td align=right><P><B><? print_string("choice1","choice") ?>:</B></P></TD>
+ <td align=right><P><B><? print_string("choice","choice","1") ?>:</B></P></TD>
<td>
- <input type="text" name="answer1" size=30 value="<?
- if ($form->answer1) {
- p($form->answer1);
- } else {
- print_string("yes");
- } ?>">
+ <input type="text" name="answer1" size=30 value="<? p($form->answer1) ?>">
+ <? helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
</td>
</tr>
<tr valign=top>
- <td align=right><P><B><? print_string("choice2","choice") ?>:</B></P></TD>
+ <td align=right><P><B><? print_string("choice","choice","2") ?>:</B></P></TD>
<td>
- <input type="text" name="answer2" size=30 value="<?
- if ($form->answer2) {
- p($form->answer2);
- } else {
- print_string("no");
- } ?>">
+ <input type="text" name="answer2" size=30 value="<? p($form->answer2) ?>">
+ <? helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
+ </td>
+</tr>
+
+<tr valign=top>
+ <td align=right><P><B><? print_string("choice","choice","3") ?>:</B></P></TD>
+ <td>
+ <input type="text" name="answer3" size=30 value="<? p($form->answer3) ?>">
+ <? helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
+ </td>
+</tr>
+<tr valign=top>
+ <td align=right><P><B><? print_string("choice","choice","4") ?>:</B></P></TD>
+ <td>
+ <input type="text" name="answer4" size=30 value="<? p($form->answer4) ?>">
+ <? helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
+ </td>
+</tr>
+<tr valign=top>
+ <td align=right><P><B><? print_string("choice","choice","5") ?>:</B></P></TD>
+ <td>
+ <input type="text" name="answer5" size=30 value="<? p($form->answer5) ?>">
+ <? helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
+ </td>
+</tr>
+<tr valign=top>
+ <td align=right><P><B><? print_string("choice","choice","6") ?>:</B></P></TD>
+ <td>
+ <input type="text" name="answer6" size=30 value="<? p($form->answer6) ?>">
+ <? helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
</td>
</tr>
error("Only teachers can look at this page");
}
- if (! $choice = get_record("choice", "id", $cm->instance)) {
+ if (!$choice = choice_get_choice($cm->instance)) {
error("Course module is incorrect");
}
foreach ($allanswers as $aa) {
$answers[$aa->user] = $aa;
}
-
} else {
$answers = array () ;
}
$timenow = time();
- for ($i=0; $i<=2; $i++) { // number of choices (presently hardcoded)
- $useranswer[$i] = array();
+ foreach ($choice->answer as $key => $answer) {
+ $useranswer[$key] = array();
}
-
foreach ($users as $user) {
$answer = $answers[$user->id];
$useranswer[(int)$answer->answer][] = $user;
}
+ foreach ($choice->answer as $key => $answer) {
+ if (!$choice->answer[$key]) {
+ unset($useranswer[$key]); // Throw away any data that doesn't apply
+ }
+ }
ksort($useranswer);
$tablewidth = (int) (100.0 / count($useranswer));
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2002082000;
+$module->version = 2002090800;
$module->cron = 0;
function choice_upgrade($oldversion) {
// This function does anything necessary to upgrade
// older versions to match current functionality
+ if ($oldversion < 2002090800) {
+ execute_sql(" ALTER TABLE `choice` CHANGE `answer1` `answer1` VARCHAR( 255 )");
+ execute_sql(" ALTER TABLE `choice` CHANGE `answer2` `answer2` VARCHAR( 255 )");
+ }
return true;
}
<P>
<FORM name="form" method="post" action="view.php">
<TABLE WIDTH=70% CELLPADDING=20 CELLSPACING=20><TR>
+<? foreach (
<TD ALIGN=CENTER NOWRAP WIDTH=50%>
<INPUT type="radio" name=answer value="1" <?=$answer1checked ?> >
<? p($choice->answer1) ?>
require_login($course->id);
- if (! $choice = get_record("choice", "id", $cm->instance)) {
+ if (!$choice = choice_get_choice($cm->instance)) {
error("Course module is incorrect");
}
if ($current = get_record_sql("SELECT * FROM choice_answers
WHERE choice='$choice->id' AND user='$USER->id'")) {
- if ($current->answer == "1") {
- $answer1checked = "CHECKED";
- } else if ($current->answer == "2") {
- $answer2checked = "CHECKED";
- }
+ $answerchecked[$current->answer] = "CHECKED";
}
if (match_referer() && isset($HTTP_POST_VARS)) { // form submitted
print_simple_box( text_to_html($choice->text) , "center");
- require("view.html");
+ echo "<CENTER><P><FORM name=\"form\" method=\"post\" action=\"view.php\">";
+ echo "<TABLE CELLPADDING=20 CELLSPACING=20><TR>";
+
+ foreach ($choice->answer as $key => $answer) {
+ if ($answer) {
+ echo "<TD ALIGN=CENTER>";
+ echo "<INPUT type=radio name=answer value=\"$key\" ".$answerchecked[$key].">";
+ p($answer);
+ echo "</TD>";
+ }
+ }
+
+ echo "</TR></TABLE>";
+ echo "<INPUT type=hidden name=id value=\"$cm->id\">";
+ echo "<INPUT type=submit value=\"".get_string("savemychoice","choice")."\">";
+ echo "</P></FORM></CENTER>";
print_footer($course);