course)) { error("Course is misconfigured"); } require_login($course->id); if (!$choice = choice_get_choice($cm->instance)) { error("Course module is incorrect"); } for ($i=1; $i <= $CHOICE_MAX_NUMBER; $i++) { $answerchecked[$i] = ""; } if ($current = get_record("choice_answers", "choice", $choice->id, "userid", $USER->id)) { $answerchecked[$current->answer] = "CHECKED"; } if ($form = data_submitted()) { $timenow = time(); if ($current) { $newanswer = $current; $newanswer->answer = $form->answer; $newanswer->timemodified = $timenow; if (! update_record("choice_answers", $newanswer)) { error("Could not update your choice"); } add_to_log($course->id, "choice", "update", "view.php?id=$cm->id", "$choice->id"); } else { $newanswer->choice = $choice->id; $newanswer->userid = $USER->id; $newanswer->answer = $form->answer; $newanswer->timemodified = $timenow; if (! insert_record("choice_answers", $newanswer)) { error("Could not save your choice"); } add_to_log($course->id, "choice", "add", "view.php?id=$cm->id", "$choice->id"); } redirect("$CFG->wwwroot/course/view.php?id=$course->id"); exit; } $strchoice = get_string("modulename", "choice"); $strchoices = get_string("modulenameplural", "choice"); add_to_log($course->id, "choice", "view", "view.php?id=$cm->id", "$choice->id"); if ($course->category) { $navigation = "id\">$course->shortname ->"; } else { $navigation = ""; } print_header("$course->shortname: $choice->name", "$course->fullname", "$navigation id>$strchoices -> $choice->name", "", "", true, update_module_button($cm->id, $course->id, $strchoice), navmenu($course, $cm)); if (isteacher($course->id)) { if ( $allanswers = get_records("choice_answers", "choice", $choice->id)) { $responsecount = count($allanswers); } else { $responsecount = 0; } echo "

id\">".get_string("viewallresponses", "choice", $responsecount)."

"; } else if (!$cm->visible) { notice(get_string("activityiscurrentlyhidden")); } print_simple_box( text_to_html($choice->text) , "center"); if (!$current or !$choice->publish) { // They haven't made their choice yet echo "

"; echo ""; foreach ($choice->answer as $key => $answer) { if ($answer) { echo ""; } } echo "
"; echo ""; p($answer); echo "
"; echo "id\">"; if (!isguest()) { echo ""; } echo "

"; } else { // Print results. print_heading(get_string("responses", "choice")); if (! $users = get_course_users($course->id, "u.firstname ASC")) { error("No users found (very strange)"); } if ( $allanswers = get_records("choice_answers", "choice", $choice->id)) { foreach ($allanswers as $aa) { $answers[$aa->userid] = $aa; } } else { $answers = array () ; } $timenow = time(); foreach ($choice->answer as $key => $answer) { $useranswer[$key] = array(); } foreach ($users as $user) { if (!empty($user->id) and !empty($answers[$user->id])) { $answer = $answers[$user->id]; $useranswer[(int)$answer->answer][] = $user; } else { $answer = ""; $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); switch ($choice->publish) { case CHOICE_PUBLISH_NAMES: $tablewidth = (int) (100.0 / count($useranswer)); echo ""; echo ""; foreach ($useranswer as $key => $answer) { if ($key) { echo ""; } echo ""; foreach ($useranswer as $key => $answer) { if ($key) { echo ""; } echo "
"; } else { echo "body\" WIDTH=\"$tablewidth%\">"; } echo choice_get_answer($choice, $key); echo "
cellcontent\">"; } else { echo "body\">"; } echo ""; foreach ($answer as $user) { echo ""; } echo "
"; print_user_picture($user->id, $course->id, $user->picture); echo ""; echo "

$user->firstname $user->lastname

"; echo "
"; echo "
"; break; case CHOICE_PUBLISH_ANONYMOUS: $tablewidth = (int) (100.0 / count($useranswer)); echo ""; echo ""; foreach ($useranswer as $key => $answer) { if ($key) { echo ""; } echo ""; $maxcolumn = 0; foreach ($useranswer as $key => $answer) { $column[$key] = count($answer); if ($column[$key] > $maxcolumn) { $maxcolumn = $column[$key]; } } echo ""; foreach ($useranswer as $key => $answer) { $height = $COLUMN_HEIGHT * ((float)$column[$key] / (float)$maxcolumn); echo ""; } echo ""; echo ""; foreach ($useranswer as $key => $answer) { echo ""; } echo "
"; } else { echo "body\" WIDTH=\"$tablewidth%\">"; } echo choice_get_answer($choice, $key); echo "
"; echo "
".$column[$key]."
"; break; } } print_footer($course); ?>