From ff8d654f005603f1335d68dae9c3a7024687654f Mon Sep 17 00:00:00 2001 From: danmarsden Date: Mon, 16 Oct 2006 00:01:13 +0000 Subject: [PATCH] Fix for MDL-6550 - patch from Graeme Byrne thanks! :-) + remove a bit of unneeded space! :-) --- mod/choice/lib.php | 78 +++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/mod/choice/lib.php b/mod/choice/lib.php index c27604bd75..9f15f43062 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -65,9 +65,9 @@ function choice_add_instance($choice) { $choice->timeclose = 0; } - //insert answers + //insert answers if ($choice->id = insert_record("choice", $choice)) { - foreach ($choice as $name => $value) { + foreach ($choice as $name => $value) { if (strstr($name, "newoption")) { /// New option $value = trim($value); if (isset($value) && $value <> '') { @@ -78,7 +78,7 @@ function choice_add_instance($choice) { $option->maxanswers = $choice->{'newlimit'.substr($name, 9)}; } $option->timemodified = time(); - insert_record("choice_options", $option); + insert_record("choice_options", $option); } } } @@ -105,10 +105,10 @@ function choice_update_instance($choice) { $choice->timeopen = 0; $choice->timeclose = 0; } - + //update answers - - foreach ($choice as $name => $value) { + + foreach ($choice as $name => $value) { $value = trim($value); if (strstr($name, "oldoption")) { // Old option @@ -134,13 +134,13 @@ function choice_update_instance($choice) { $option->maxanswers = $choice->{'newlimit'.substr($name, 9)}; } $option->timemodified = time(); - insert_record("choice_options", $option); + insert_record("choice_options", $option); } - } + } } return update_record('choice', $choice); - + } function choice_show_form($choice, $user, $cm) { @@ -157,7 +157,7 @@ function choice_show_form($choice, $user, $cm) { $countans = 0; $context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!empty($countanswers)) { - foreach ($countanswers as $ca) { //only return enrolled users. + foreach ($countanswers as $ca) { //only return enrolled users. if (has_capability('mod/choice:choose', $context)) { $countans = $countans+1; } @@ -176,12 +176,12 @@ function choice_show_form($choice, $user, $cm) { $cdisplay[$aid]->countanswers = $countans; if ($current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $user->id, 'optionid', $optionid)) { - $cdisplay[$aid]->checked = ' checked="checked" '; + $cdisplay[$aid]->checked = ' checked="checked" '; } else { - $cdisplay[$aid]->checked = ''; + $cdisplay[$aid]->checked = ''; } if ($choice->limitanswers && ($countans >= $maxans) && (empty($cdisplay[$aid]->checked)) ) { - $cdisplay[$aid]->disabled = ' disabled="disabled" '; + $cdisplay[$aid]->disabled = ' disabled="disabled" '; } else { $cdisplay[$aid]->disabled = ''; } @@ -195,13 +195,13 @@ function choice_show_form($choice, $user, $cm) { foreach ($cdisplay as $cd) { echo ""; - echo "optionid."\" alt=\"".strip_tags(format_text($cd->text))."\"". $cd->checked.$cd->disabled." />"; + echo "optionid."\" alt=\"".strip_tags(format_text($cd->text))."\"". $cd->checked.$cd->disabled." />"; if (!empty($cd->disabled)) { - echo format_text($cd->text."
".get_string('full', 'choice').""); + echo format_text($cd->text."
".get_string('full', 'choice').""); } else { echo format_text($cd->text); } - echo ""; + echo ""; } echo ""; echo ""; @@ -210,15 +210,15 @@ function choice_show_form($choice, $user, $cm) { case CHOICE_DISPLAY_VERTICAL: $displayoptions->para = false; echo ""; - foreach ($cdisplay as $cd) { + foreach ($cdisplay as $cd) { echo "
"; - echo "optionid."\" alt=\"".strip_tags(format_text($cd->text))."\"". $cd->checked.$cd->disabled." />"; + echo "optionid."\" alt=\"".strip_tags(format_text($cd->text))."\"". $cd->checked.$cd->disabled." />"; echo format_text($cd->text. ' ', FORMAT_MOODLE, $displayoptions); //display text for option. - + if ($choice->limitanswers && ($choice->showresults==CHOICE_SHOWRESULTS_ALWAYS) ){ //if limit is enabled, and show results always has been selected, display info beside each choice. echo ""; - + if (!empty($cd->disabled)) { echo get_string('full', 'choice'); } elseif(!empty($cd->checked)) { @@ -262,15 +262,15 @@ function choice_user_submit_response($formanswer, $choice, $userid, $courseid, $ if (has_capability('mod/choice:choose', $context)) { $countans = $countans+1; } - } - - $countanswers = count($countans); + } + + $countanswers = $countans; } else { $countanswers = 0; } $maxans = $choice->maxanswers[$formanswer]; - - if (!($choice->limitanswers && ($countanswers >= $maxans) )) { + + if (!($choice->limitanswers && ($countanswers >= $maxans) )) { if ($current) { $newanswer = $current; @@ -317,14 +317,14 @@ function choice_show_reportlink($choice, $courseid, $cmid) { } function choice_show_results($choice, $course, $cm, $forcepublish='') { - + global $CFG, $COLUMN_HEIGHT, $USER; $context = get_context_instance(CONTEXT_MODULE, $cm->id); - print_heading(get_string("responses", "choice")); + print_heading(get_string("responses", "choice")); if (empty($forcepublish)) { //alow the publish setting to be overridden $forcepublish = $choice->publish; - } - + } + /// 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, $_SERVER['PHP_SELF']."?id=$cm->id"); @@ -382,7 +382,7 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') { echo ''; echo ''; } - + echo ""; echo ""; $count = 0; @@ -441,13 +441,13 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') { continue; } echo "
"; - $countanswers = get_records("choice_answers", "optionid", $optionid); + $countanswers = get_records("choice_answers", "optionid", $optionid); $countans = 0; if (!empty($countanswers)) { - foreach ($countanswers as $ca) { //only return enrolled users. - if (has_capability('mod/choice:choose', get_context_instance(CONTEXT_MODULE, $cm->id))) { + foreach ($countanswers as $ca) { //only return enrolled users. + if (has_capability('mod/choice:choose', get_context_instance(CONTEXT_MODULE, $cm->id))) { $countans = $countans+1; - } + } } } if ($choice->limitanswers && !$optionid==0) { @@ -485,7 +485,7 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') { case CHOICE_PUBLISH_ANONYMOUS: - + $tablewidth = (int) (100.0 / count($useranswer)); echo ""; @@ -636,18 +636,18 @@ function choice_get_option_text($choice, $id) { return $result->text; } else { return get_string("notanswered", "choice"); - } + } } function choice_get_choice($choiceid) { -// Gets a full choice record +// Gets a full choice record if ($choice = get_record("choice", "id", $choiceid)) { if ($options = get_records("choice_options", "choiceid", $choiceid, "id")) { - foreach ($options as $option) { + foreach ($options as $option) { $choice->option[$option->id] = $option->text; $choice->maxanswers[$option->id] = $option->maxanswers; - } + } return $choice; } } -- 2.39.5