course)) { error("Course is misconfigured"); } require_course_login($course, false, $cm); if (!$choice = choice_get_choice($cm->instance)) { error("Course module is incorrect"); } if ($choice->option) { foreach ($choice->option as $optionid => $text) { $answerchecked[$optionid] = ''; } } if (isset($USER->id) && $current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $USER->id)) { $answerchecked[$current->optionid] = 'checked="checked"'; } else { $current = false; } /// Submit any new data if there is any if ($form = data_submitted()) { $timenow = time(); if (empty($form->answer)) { redirect("view.php?id=$cm->id", get_string('mustchooseone', 'choice')); } else { $countanswers = get_records("choice_answers", "optionid", $form->answer); if ($countanswers) { $countanswers = count($countanswers); } else { $countanswers = 0; } $maxans = $choice->maxanswers[$form->answer]; if (!($choice->limitanswers && ($countanswers >= $maxans) )) { if ($current) { $newanswer = $current; $newanswer->optionid = $form->answer; $newanswer->timemodified = $timenow; if (! update_record("choice_answers", $newanswer)) { error("Could not update your choice because of a database error"); } add_to_log($course->id, "choice", "choose again", "view.php?id=$cm->id", $choice->id, $cm->id); } else { $newanswer = NULL; $newanswer->choiceid = $choice->id; $newanswer->userid = $USER->id; $newanswer->optionid = $form->answer; $newanswer->timemodified = $timenow; if (! insert_record("choice_answers", $newanswer)) { error("Could not save your choice"); } add_to_log($course->id, "choice", "choose", "view.php?id=$cm->id", $choice->id, $cm->id); } } else { error("this choice is full!"); } } redirect("view.php?id=$cm->id"); exit; } /// Display the choice and possibly results $strchoice = get_string("modulename", "choice"); $strchoices = get_string("modulenameplural", "choice"); add_to_log($course->id, "choice", "view", "view.php?id=$cm->id", $choice->id, $cm->id); print_header_simple(format_string($choice->name), "", "id\">$strchoices -> ".format_string($choice->name), "", "", true, update_module_button($cm->id, $course->id, $strchoice), navmenu($course, $cm)); /// Check to see if groups are being used in this choice if ($groupmode = groupmode($course, $cm)) { // Groups are being used $currentgroup = setup_and_print_groups($course, $groupmode, "view.php?id=$cm->id"); } else { $currentgroup = false; } if (isteacher($course->id)) { if ( $allanswers = get_records("choice_answers", "choiceid", $choice->id)) { $responsecount = 0; foreach ($allanswers as $aa) { if (isstudent($course->id, $aa->userid) or isteacher($course->id, $aa->userid)) { //check to make sure user is enrolled in course. $responsecount++; } } } else { $responsecount = 0; } echo '
"; } else if ($choice->showunanswered) { echo " | "; } else { continue; } echo format_string(choice_get_option_text($choice, $optionid)); echo " | "; $count++; } echo "||
---|---|---|---|
"; } else if ($choice->showunanswered) { echo " | ";
} else {
continue;
}
echo "
| ";
}
echo "||
";
$countanswers = count_records("choice_answers", "optionid", $optionid);
if ($choice->limitanswers && !$optionid==0) {
echo get_string("taken", "choice").":";
echo $countanswers;
echo " "; echo get_string("limit", "choice").":"; $choice_option = get_record("choice_options", "id", $optionid); echo $choice_option->maxanswers; } echo " | ";
$count++;
}
echo "
"; } else if ($choice->showunanswered) { echo " | "; } else { continue; } echo format_string(choice_get_option_text($choice, $optionid)); echo " | "; $count++; } echo "
---|---|
";
echo "![]() | ";
$count++;
}
echo "|
";
if ($choice->limitanswers && !$optionid==0) {
echo get_string("taken", "choice").":";
echo $column[$optionid];
echo " "; echo get_string("limit", "choice").":"; $choice_option = get_record("choice_options", "id", $optionid); echo $choice_option->maxanswers; } else { echo $column[$optionid]; } echo " | ";
$count++;
}
echo "