course)) { error("Course is misconfigured"); } require_course_login($course); if (!$choice = choice_get_choice($cm->instance)) { error("Course module is incorrect"); } for ($i=1; $i <= $CHOICE_MAX_NUMBER; $i++) { $answerchecked[$i] = ''; } if (isset($USER->id) and $current = get_record("choice_answers", "choice", $choice->id, "userid", $USER->id)) { $answerchecked[$current->answer] = 'CHECKED'; } else { $current = false; } if ($form = data_submitted()) { $timenow = time(); if (empty($form->answer)) { redirect("view.php?id=$cm->id", get_string('mustchooseone', 'choice')); } else { 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", "choose again", "view.php?id=$cm->id", $choice->id, $cm->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", "choose", "view.php?id=$cm->id", $choice->id, $cm->id); } } redirect("view.php?id=$cm->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, $cm->id); print_header_simple("$choice->name", "", "id\">$strchoices -> $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", "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( format_text($choice->text) , "center"); // print the form if ($choice->timeopen > time() ) { print_simple_box(get_string("notopenyet", "choice", userdate($choice->timeopen)), "center"); print_footer(); exit; } if ( (!$current or $choice->allowupdate) and ($choice->timeclose >= time() or $choice->timeclose == 0) ) { // They haven't made their choice yet or updates allowed and choice is open echo "
"; echo ""; foreach ($choice->answer as $key => $answer) { if ($answer) { echo ""; } } echo "
"; echo ""; p($answer); echo "
"; echo "
"; echo "id\" />"; if (isstudent($course->id) or isteacher($course->id, 0, false)) { echo ""; } else { print_string('havetologin', 'choice'); } echo "
"; echo "
"; } // print the results if ( $choice->release == CHOICE_RELEASE_ALWAYS or ( $choice->release == CHOICE_RELEASE_AFTER_ANSWER and $current ) or ( $choice->release == CHOICE_RELEASE_AFTER_CLOSE and $choice->timeclose <= time() ) ) { print_heading(get_string("responses", "choice")); if ($currentgroup) { $users = get_group_users($currentgroup, "u.firstname ASC"); } else { $users = get_course_users($course->id, "u.firstname ASC"); } if (!$users) { print_heading(get_string("nousersyet")); print_footer($course); exit; } 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 { $useranswer[0][] = $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: $isteacher = isteacher($course->id); $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 if ($choice->showunanswered) { echo "body\" width=\"$tablewidth%\">"; } else { continue; } echo choice_get_answer($choice, $key); echo "
cellcontent\">"; } else if ($choice->showunanswered) { echo "body\">"; } else { continue; } echo ""; foreach ($answer as $user) { echo ""; } echo "
"; print_user_picture($user->id, $course->id, $user->picture); echo ""; echo "

".fullname($user, $isteacher)."

"; 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) { if (!$key and !$choice->showunanswered) { continue; } $column[$key] = count($answer); if ($column[$key] > $maxcolumn) { $maxcolumn = $column[$key]; } } echo ""; foreach ($useranswer as $key => $answer) { if (!$key and !$choice->showunanswered) { continue; } $height = 0; if ($maxcolumn) { $height = $COLUMN_HEIGHT * ((float)$column[$key] / (float)$maxcolumn); } echo ""; } echo ""; echo ""; foreach ($useranswer as $key => $answer) { if (!$key and !$choice->showunanswered) { continue; } echo ""; } echo "
"; } else if ($choice->showunanswered) { echo "body\" width=\"$tablewidth%\">"; } else { continue; } echo choice_get_answer($choice, $key); echo "
"; echo "\"\""; echo "
".$column[$key]."
"; break; } } print_footer($course); ?>