# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/mod/choice/lang/en/choice.php
--- moodle/mod/choice/lang/en/choice.php Base (1.5)
+++ moodle/mod/choice/lang/en/choice.php Locally Modified (Based On 1.5)
@@ -83,3 +83,15 @@
 $string['timerestrict'] = 'Restrict answering to this time period';
 $string['viewallresponses'] = 'View {$a} responses';
 $string['yourselection'] = 'Your selection';
+$string['percentageoftotaluser'] = '{$a}% of total';
+$string['numberofanswers'] = '{$a} answers';
+$string['resultsummary'] = 'Result Summary';
+$string['skipresultgraph'] = 'Skip Result Graph';
+$string['moveselectedusersto'] = 'Move selected users to...';
+$string['deleteusertcheck'] = 'Are you absolutely sure you want to completely delete these users?';
+$string['percentageoftotaluser'] = '{$a}% of total';
+$string['numberofanswers'] = '{$a} answers';
+$string['resultsummary'] = 'Result Summary';
+$string['skipresultgraph'] = 'Skip Result Graph';
+$string['moveselectedusersto'] = 'Move selected users to...';
+$string['deleteusertcheck'] = 'Are you absolutely sure you want to completely delete these users?';
Index: moodle/mod/choice/lib.php
--- moodle/mod/choice/lib.php Base (1.127)
+++ moodle/mod/choice/lib.php Locally Modified (Based On 1.127)
@@ -184,126 +184,50 @@
  * @global object
  * @param object $choice
  * @param object $user
- * @param object $cm
+ * @param object $coursemodule
  * @param array $allresponses
- * @return void output is echo'd
+ * @return array
  */
-function choice_show_form($choice, $user, $cm, $allresponses) {
+function choice_prepare_options($choice, $user, $coursemodule, $allresponses) {
     global $DB;
-//$cdisplay is an array of the display info for a choice $cdisplay[$optionid]->text  - text name of option.
-//                                                                            ->maxanswers -maxanswers for this option
-//                                                                            ->full - whether this option is full or not. 0=not full, 1=full
-    $cdisplay = array();
 
-    $aid = 0;
-    $choicefull = false;
-    $cdisplay = array();
+    $cdisplay = array('options'=>array());
 
-    if ($choice->limitanswers) { //set choicefull to true by default if limitanswers.
-        $choicefull = true;
-    }
+    $cdisplay['limitanswers'] = true;
+    $context = get_context_instance(CONTEXT_MODULE, $coursemodule->id);
 
-    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
     foreach ($choice->option as $optionid => $text) {
         if (isset($text)) { //make sure there are no dud entries in the db with blank text values.
-            $cdisplay[$aid]->optionid = $optionid;
-            $cdisplay[$aid]->text = $text;
-            $cdisplay[$aid]->maxanswers = $choice->maxanswers[$optionid];
+            $option = new stdClass;
+            $option->attributes = new stdClass;
+            $option->attributes->value = $optionid;
+            $option->text = $text;
+            $option->maxanswers = $choice->maxanswers[$optionid];
+            $option->displaylayout = $choice->display;
+
             if (isset($allresponses[$optionid])) {
-                $cdisplay[$aid]->countanswers = count($allresponses[$optionid]);
+                $option->countanswers = count($allresponses[$optionid]);
             } else {
-                $cdisplay[$aid]->countanswers = 0;
+                $option->countanswers = 0;
             }
-            if ($current = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $user->id, 'optionid' => $optionid))) {
-                $cdisplay[$aid]->checked = ' checked="checked" ';
-            } else {
-                $cdisplay[$aid]->checked = '';
+            if ($DB->record_exists('choice_answers', array('choiceid' => $choice->id, 'userid' => $user->id, 'optionid' => $optionid))) {
+                $option->attributes->checked = true;
             }
-            if ( $choice->limitanswers &&
-                ($cdisplay[$aid]->countanswers >= $cdisplay[$aid]->maxanswers) &&
-                (empty($cdisplay[$aid]->checked)) ) {
-                $cdisplay[$aid]->disabled = ' disabled="disabled" ';
-            } else {
-                $cdisplay[$aid]->disabled = '';
-                if ($choice->limitanswers && ($cdisplay[$aid]->countanswers < $cdisplay[$aid]->maxanswers)) {
-                    $choicefull = false; //set $choicefull to false - as the above condition hasn't been set.
+            if ( $choice->limitanswers && ($option->countanswers >= $option->maxanswers) && empty($option->attributes->checked)) {
+                $option->attributes->disabled = true;
                 }
+            $cdisplay['options'][] = $option;
             }
-            $aid++;
         }
-    }
 
-    switch ($choice->display) {
-        case CHOICE_DISPLAY_HORIZONTAL:
-            echo "<table cellpadding=\"20\" cellspacing=\"20\" class=\"boxaligncenter\"><tr>";
+    $cdisplay['hascapability'] = is_enrolled($context, NULL, 'mod/choice:choose'); //only enrolled users are allowed to make a choice
 
-            foreach ($cdisplay as $cd) {
-                echo "<td align=\"center\" valign=\"top\">";
-                echo "<input type=\"radio\" name=\"answer\" value=\"".$cd->optionid."\" alt=\"".strip_tags(format_text($cd->text))."\"". $cd->checked.$cd->disabled." />";
-                if (!empty($cd->disabled)) {
-                    echo format_text($cd->text."<br /><strong>".get_string('full', 'choice')."</strong>");
-                } else {
-                    echo format_text($cd->text);
+    if ($choice->allowupdate && $DB->record_exists('choice_answers', array('choiceid'=> $choice->id, 'userid'=> $user->id))) {
+        $cdisplay['allowupdate'] = true;
                 }
-                echo "</td>";
-            }
-            echo "</tr>";
-            echo "</table>";
-            break;
 
-        case CHOICE_DISPLAY_VERTICAL:
-            $displayoptions->para = false;
-            echo "<table cellpadding=\"10\" cellspacing=\"10\" class=\"boxaligncenter\">";
-            foreach ($cdisplay as $cd) {
-                echo "<tr><td align=\"left\">";
-                echo "<input type=\"radio\" name=\"answer\" value=\"".$cd->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 "</td><td>";
-
-                    if (!empty($cd->disabled)) {
-                        echo get_string('full', 'choice');
-                    } elseif(!empty($cd->checked)) {
-                                //currently do nothing - maybe some text could be added here to signfy that the choice has been 'selected'
-                    } elseif ($cd->maxanswers-$cd->countanswers==1) {
-                        echo ($cd->maxanswers - $cd->countanswers);
-                        echo " ".get_string('spaceleft', 'choice');
-                    } else {
-                        echo ($cd->maxanswers - $cd->countanswers);
-                        echo " ".get_string('spacesleft', 'choice');
+    return $cdisplay;
                     }
-                    echo "</td>";
-                } else if ($choice->limitanswers && ($cd->countanswers >= $cd->maxanswers)) {  //if limitanswers and answers exceeded, display "full" beside the choice.
-                    echo " <strong>".get_string('full', 'choice')."</strong>";
-                }
-                echo "</td>";
-                echo "</tr>";
-            }
-        echo "</table>";
-        break;
-    }
-    //show save choice button
-    echo '<div class="button">';
-    echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />";
-    echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />";
-    if (is_enrolled($context, NULL, 'mod/choice:choose')) { //only enrolled users are allowed to make a choice
-        if ($choicefull) {
-            print_string('choicefull', 'choice');
-            echo "</br>";
-        } else {
-            echo "<input type=\"submit\" value=\"".get_string("savemychoice","choice")."\" />";
-        }
-        if ($choice->allowupdate && $aaa = $DB->get_record('choice_answers', 'choiceid', $choice->id, 'userid', $user->id)) {
-            echo "<br /><a href='view.php?id=".$cm->id."&amp;action=delchoice&amp;sesskey=".sesskey()."'>".get_string("removemychoice","choice")."</a>";
-        }
-    } else {
-        print_string('havetologin', 'choice');
-    }
-    echo "</div>";
-}
 
 /**
  * @global object
@@ -398,257 +322,52 @@
 
 /**
  * @global object
- * @global int
- * @global string
- * @global object
- * @uses CONTEXT_MODULE
- * @uses CHOICE_PUBLISH_NAMES
- * @uses CHOICE_PUBLISH_ANONYMOUS
  * @param object $choice
  * @param object $course
- * @param object $cm
+ * @param object $coursemodule
  * @param array $allresponses
- * @param int $forcepublish
- * @return void Output is echo'd
+
+ *  * @param bool $allresponses
+ * @return object
  */
-function choice_show_results($choice, $course, $cm, $allresponses, $forcepublish='') {
+function prepare_choice_show_results($choice, $course, $coursemodule, $allresponses, $forcepublish=false) {
     global $CFG, $CHOICE_COLUMN_HEIGHT, $FULLSCRIPT, $PAGE, $OUTPUT, $DB;
 
-    echo $OUTPUT->heading(get_string("responses", "choice"));
-    if (empty($forcepublish)) { //alow the publish setting to be overridden
-        $forcepublish = $choice->publish;
-    }
+    $display = clone($choice);
+    $display->coursemoduleid = $coursemodule->id;
+    $display->courseid = $course->id;
 
-    if (empty($allresponses)) {
-        echo $OUTPUT->heading(get_string("nousersyet"));
-        return false;
-    }
-
-    $totalresponsecount = 0;
-    foreach ($allresponses as $optionid => $userlist) {
-        if ($choice->showunanswered || $optionid) {
-            $totalresponsecount += count($userlist);
-        }
-    }
-
-    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
-    $hascapfullnames = has_capability('moodle/site:viewfullnames', $context);
-
-    $viewresponses = has_capability('mod/choice:readresponses', $context);
-    switch ($forcepublish) {
-        case CHOICE_PUBLISH_NAMES:
-            echo '<div id="tablecontainer">';
-            if ($viewresponses) {
-                echo '<form id="attemptsform" method="post" action="'.$FULLSCRIPT.'" onsubmit="var menu = document.getElementById(\'menuaction\'); return (menu.options[menu.selectedIndex].value == \'delete\' ? \''.addslashes_js(get_string('deleteattemptcheck','quiz')).'\' : true);">';
-                echo '<div>';
-                echo '<input type="hidden" name="id" value="'.$cm->id.'" />';
-                echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
-                echo '<input type="hidden" name="mode" value="overview" />';
-            }
-
-            echo "<table cellpadding=\"5\" cellspacing=\"10\" class=\"results names\">";
-            echo "<tr>";
-
-            $columncount = array(); // number of votes in each column
-            if ($choice->showunanswered) {
-                $columncount[0] = 0;
-                echo "<th class=\"col0 header\" scope=\"col\">";
-                print_string('notanswered', 'choice');
-                echo "</th>";
-            }
-            $count = 1;
+    //overwrite options value;
+    $display->options = array();
+    $totaluser = 0;
             foreach ($choice->option as $optionid => $optiontext) {
-                $columncount[$optionid] = 0; // init counters
-                echo "<th class=\"col$count header\" scope=\"col\">";
-                echo format_string($optiontext);
-                echo "</th>";
-                $count++;
-            }
-            echo "</tr><tr>";
+        $display->options[$optionid] = new stdClass;
+        $display->options[$optionid]->text = $optiontext;
+        $display->options[$optionid]->maxanswer = $choice->maxanswers[$optionid];
 
-            if ($choice->showunanswered) {
-                echo "<td class=\"col$count data\" >";
-                // added empty row so that when the next iteration is empty,
-                // we do not get <table></table> erro from w3c validator
-                // MDL-7861
-                echo "<table class=\"choiceresponse\"><tr><td></td></tr>";
-                if (!empty($allresponses[0])) {
-                    foreach ($allresponses[0] as $user) {
-                        echo "<tr>";
-                        echo "<td class=\"picture\">";
-                        echo $OUTPUT->user_picture($user, array('courseid'=>$course->id));
-                        echo "</td><td class=\"fullname\">";
-                        echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">";
-                        echo fullname($user, $hascapfullnames);
-                        echo "</a>";
-                        echo "</td></tr>";
+        if (array_key_exists($optionid, $allresponses)) {
+            $display->options[$optionid]->user = $allresponses[$optionid]; //->user;
+            $totaluser += count($allresponses[$optionid]);
                     }
                 }
-                echo "</table></td>";
-            }
-            $count = 1;
-            foreach ($choice->option as $optionid => $optiontext) {
-                    echo '<td class="col'.$count.' data" >';
+    unset($display->option);
+    unset($display->maxanswers);
 
-                    // added empty row so that when the next iteration is empty,
-                    // we do not get <table></table> erro from w3c validator
-                    // MDL-7861
-                    echo '<table class="choiceresponse"><tr><td></td></tr>';
-                    if (isset($allresponses[$optionid])) {
-                        foreach ($allresponses[$optionid] as $user) {
-                            $columncount[$optionid] += 1;
-                            echo '<tr><td class="attemptcell">';
-                            if ($viewresponses and has_capability('mod/choice:deleteresponses',$context)) {
-                                echo '<input type="checkbox" name="attemptid[]" value="'. $user->id. '" />';
-                            }
-                            echo '</td><td class="picture">';
-                            echo $OUTPUT->user_picture($user, array('courseid'=>$course->id));
-                            echo '</td><td class="fullname">';
-                            echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">";
-                            echo fullname($user, $hascapfullnames);
-                            echo '</a>';
-                            echo '</td></tr>';
-                       }
-                    }
-                    $count++;
-                    echo '</table></td>';
-            }
-            echo "</tr><tr>";
-            $count = 1;
+    $display->numberofuser = $totaluser;
+    $context = get_context_instance(CONTEXT_MODULE, $coursemodule->id);
+    $display->viewresponsecapability = has_capability('mod/choice:readresponses', $context);
+    $display->deleterepsonsecapability = has_capability('mod/choice:deleteresponses',$context);
+    $display->fullnamecapability = has_capability('moodle/site:viewfullnames', $context);
 
-            if ($choice->showunanswered) {
-                echo "<td></td>";
+    if (empty($allresponses)) {
+        echo $OUTPUT->heading(get_string("nousersyet"));
+        return false;
             }
             
-            foreach ($choice->option as $optionid => $optiontext) {
-                echo "<td align=\"center\" class=\"col$count count\">";
-                if ($choice->limitanswers) {
-                    echo get_string("taken", "choice").":";
-                    echo $columncount[$optionid];
-                    echo "<br/>";
-                    echo get_string("limit", "choice").":";
-                    $choice_option = $DB->get_record("choice_options", array("id" => $optionid));
-                    echo $choice_option->maxanswers;
-                } else {
-                    if (isset($columncount[$optionid])) {
-                        echo $columncount[$optionid];
-                    }
-                }
-                echo "</td>";
-                $count++;
-            }
-            echo "</tr>";
 
-            /// Print "Select all" etc.
-            if ($viewresponses and has_capability('mod/choice:deleteresponses',$context)) {
-                echo '<tr><td></td><td>';
-                echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectall', 'quiz').'</a> / ';
-                echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectnone', 'quiz').'</a> ';
-                echo '&nbsp;&nbsp;';
-                echo html_writer::tag('label', get_string('withselected', 'quiz'), array('for'=>'menuaction')); 
-                echo html_writer::select(array('delete' => get_string('delete')), 'action', '', array(''=>get_string('moveselectedcoursesto')), array('id'=>'menuaction'));
-                $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('attemptsform', 'menuaction', ''));
-                echo '<noscript id="noscriptmenuaction" style="display:inline">';
-                echo '<div>';
-                echo '<input type="submit" value="'.get_string('go').'" /></div></noscript>';
-                echo '</td><td></td></tr>';
+    return $display;
             }
 
-            echo "</table></div>";
-            if ($viewresponses) {
-                echo "</form></div>";
-            }
-            break;
-
-
-        case CHOICE_PUBLISH_ANONYMOUS:
-
-            echo "<table cellpadding=\"5\" cellspacing=\"0\" class=\"results anonymous\">";
-            echo "<tr>";
-            $maxcolumn = 0;
-            if ($choice->showunanswered) {
-                echo "<th  class=\"col0 header\" scope=\"col\">";
-                print_string('notanswered', 'choice');
-                echo "</th>";
-                $column[0] = 0;
-                foreach ($allresponses[0] as $user) {
-                    $column[0]++;
-                }
-                $maxcolumn = $column[0];
-            }
-            $count = 1;
-
-            foreach ($choice->option as $optionid => $optiontext) {
-                echo "<th class=\"col$count header\" scope=\"col\">";
-                echo format_string($optiontext);
-                echo "</th>";
-
-                $column[$optionid] = 0;
-                if (isset($allresponses[$optionid])) {
-                    $column[$optionid] = count($allresponses[$optionid]);
-                    if ($column[$optionid] > $maxcolumn) {
-                        $maxcolumn = $column[$optionid];
-                    }
-                } else {
-                    $column[$optionid] = 0;
-                }
-            }
-            echo "</tr><tr>";
-
-            $height = 0;
-
-            if ($choice->showunanswered) {
-                if ($maxcolumn) {
-                    $height = $CHOICE_COLUMN_HEIGHT * ((float)$column[0] / (float)$maxcolumn);
-                }
-                echo "<td style=\"vertical-align:bottom\" align=\"center\" class=\"col0 data\">";
-                echo "<img src=\"column.png\" height=\"$height\" width=\"49\" alt=\"\" />";
-                echo "</td>";
-            }
-            $count = 1;
-            foreach ($choice->option as $optionid => $optiontext) {
-                if ($maxcolumn) {
-                    $height = $CHOICE_COLUMN_HEIGHT * ((float)$column[$optionid] / (float)$maxcolumn);
-                }
-                echo "<td style=\"vertical-align:bottom\" align=\"center\" class=\"col$count data\">";
-                echo "<img src=\"column.png\" height=\"$height\" width=\"49\" alt=\"\" />";
-                echo "</td>";
-                $count++;
-            }
-            echo "</tr><tr>";
-
-
-            if ($choice->showunanswered) {
-                echo '<td align="center" class="col0 count">';
-                if (!$choice->limitanswers) {
-                    echo $column[0];
-                    echo '<br />('.format_float(((float)$column[0]/(float)$totalresponsecount)*100.0,1).'%)';
-                }
-                echo '</td>';
-            }
-            $count = 1;
-            foreach ($choice->option as $optionid => $optiontext) {
-                echo "<td align=\"center\" class=\"col$count count\">";
-                if ($choice->limitanswers) {
-                    echo get_string("taken", "choice").":";
-                    echo $column[$optionid].'<br />';
-                    echo get_string("limit", "choice").":";
-                    $choice_option = $DB->get_record("choice_options", array("id" => $optionid));
-                    echo $choice_option->maxanswers;
-                } else {
-                    echo $column[$optionid];
-                    echo '<br />('.format_float(((float)$column[$optionid]/(float)$totalresponsecount)*100.0,1).'%)';
-                }
-                echo "</td>";
-                $count++;
-            }
-            echo "</tr></table>";
-
-            break;
-    }
-}
-
 /**
  * @global object
  * @param array $attemptids
Index: moodle/mod/choice/renderer.php
--- moodle/mod/choice/renderer.php No Base Revision
+++ moodle/mod/choice/renderer.php Locally New
@@ -0,0 +1,322 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Moodle renderer used to display special elements of the lesson module
+ *
+ * @package   Choice
+ * @copyright 2010 Rossiani Wijaya
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ **/
+
+class mod_choice_renderer extends plugin_renderer_base {
+
+    /**
+     * Returns HTML to display choices of option
+     * @param object $options
+     * @param int  $coursemoduleid
+     * @param bool $vertical
+     * @return string
+     */
+    public function display_options($options, $coursemoduleid, $vertical = false) {
+        global $CFG;
+
+        $attributes = array('method'=>'POST', 'target'=>$CFG->wwwroot.'/mod/choice/view.php', 'class'=>'displaychoices');
+        $layoutclass = 'horizontal';
+        if ($vertical) {
+            $layoutclass = 'vertical';
+        }
+        
+        $html = html_writer::start_tag('div', array('class'=>$layoutclass ));
+        $html .= html_writer::start_tag('form', $attributes);
+
+        $html .= html_writer::start_tag('div', array('class'=>'choices'));
+        $availableoption = count($options['options']);
+        foreach ($options['options'] as $option) {
+            $attributes = array('class'=>'choice_option');
+            $html .= html_writer::start_tag('div', $attributes);
+            $option->attributes->name = 'answer';
+            $option->attributes->type = 'radio';
+            
+            $labeltext = $option->text;
+            if (!empty($option->attributes->disabled)) { 
+                $labeltext .= ' ' . get_string('full', 'choice');
+                $availableoption--;
+            }            
+
+            $html .= html_writer::empty_tag('input', (array)$option->attributes);
+            $html .= html_writer::tag('label', $labeltext, array('for'=>$option->attributes->name));
+            $html .= html_writer::end_tag('div');            
+        }
+        
+        $html .= html_writer::end_tag('div');
+        
+        $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
+        $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=>$coursemoduleid));
+
+        if (!empty($options['hascapability']) && ($options['hascapability'])) {            
+            if ($availableoption < 1) {
+               $html .= html_writer::tag('label', get_string('choicefull', 'choice'));
+            } else {
+                $html .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('savemychoice','choice'), 'class'=>'button'));
+            }
+
+            if (!empty($options['allowupdate']) && ($options['allowupdate'])) {
+                $url = new moodle_url('view.php', array('id'=>$coursemoduleid, 'action'=>'delchoice', 'sesskey'=>sesskey()));
+                $html .= html_writer::link($url, get_string('removemychoice','choice'));
+            }
+        } else {
+            $html .= html_writer::tag('label', get_string('havetologin', 'choice'));
+        }
+        
+        $html .= html_writer::end_tag('form');
+        $html .= html_writer::end_tag('div');
+        
+        return $html;
+    }
+
+    /**
+     * Returns HTML to display choices result
+     * @param object $choices
+     * @param bool $forcepublish
+     * @return string
+     */
+    public function display_result($choices, $forcepublish = false) {
+        global $CFG, $OUTPUT;
+                
+        if (empty($forcepublish)) { //alow the publish setting to be overridden
+            $forcepublish = $choices->publish;
+        }
+        if ($forcepublish) {  //CHOICE_PUBLISH_NAMES
+            return $this->display_publish_name($choices);
+
+        } else { //CHOICE_PUBLISH_ANONYMOUS
+            return $this->display_publish_anonymous($choices);
+        }                
+    }
+
+    /**
+     * Returns HTML to display choices result
+     * @param object $choices
+     * @param bool $forcepublish
+     * @return string
+     */
+    public function display_publish_name($choices) {
+        global $CFG, $OUTPUT, $PAGE;
+
+        $html ='';
+        $html .= html_writer::tag('h2',format_string(get_string("responses", "choice")), array('class'=>'main'));
+        
+        $attributes = array('method'=>'POST');
+        $attributes['action'] = $CFG->wwwroot.'/mod/choice/view.php';
+        $attributes['id'] = 'attemptsform';
+        //$attributes['onsubmit'] = 'var menu = document.getElementById(\'menuaction\'); return (menu.options[menu.selectedIndex].value == \'delete\' ? \''.addslashes_js(get_string('deleteattemptcheck','quiz')).'\' : true);';
+                
+        if ($choices->viewresponsecapability) {
+            $html .= html_writer::start_tag('form', $attributes);
+            $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=> $choices->coursemoduleid));
+            $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey()));
+            $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode', 'value'=>'overview'));                
+        }
+
+        $table = new html_table();
+        $table->cellpadding = 0;
+        $table->cellspacing = 0;
+        $table->attributes['class'] = 'results names ';
+        $table->tablealign = 'center';
+        $table->data = array();
+
+        $count = 0;
+        ksort($choices->options);
+
+        $columns = array();
+        foreach ($choices->options as $optionid => $options) {
+            $coldata = '';            
+            if ($choices->showunanswered && $optionid == 0) {
+                $coldata .= html_writer::tag('h3', format_string(get_string('notanswered', 'choice')));
+            } else if ($optionid > 0) {
+                $coldata .= html_writer::tag('h3', format_string($choices->options[$optionid]->text));
+            }         
+            
+            if ($choices->showunanswered || $optionid > 0) {
+                $numberofuser = 0;
+                if (!empty($options->user) && count($options->user) > 0) {
+                    $numberofuser = count($options->user);
+                }
+
+                if($optionid != 0) {
+                    $coldata .= html_writer::tag('div', get_string("taken", "choice").": ".$numberofuser, array('class'=>'userinfo'));
+                    if ($choices->limitanswers) {
+                        $coldata .= html_writer::tag('div', get_string("limit", "choice").": ".$options->maxanswer, array('class'=>'userinfo'));
+                    }
+                } else {
+                    $coldata .= html_writer::tag('div', '&nbsp', array('class'=>'userinfo'));
+                    $coldata .= html_writer::tag('div', '&nbsp', array('class'=>'userinfo'));
+                }
+
+                if (!empty($options->user)) {
+                    foreach ($options->user as $user) { 
+                        $dataholder = '';
+                        if (empty($user->imagealt)){
+                            $user->imagealt = '';
+                        }
+
+                        if ($choices->viewresponsecapability && $choices->deleterepsonsecapability  && $optionid > 0) {
+                            $dataholder .= html_writer::checkbox('attemptid[]', $user->id,'');
+                        }
+                        $dataholder .= $OUTPUT->user_picture($user, array('courseid'=>$choices->courseid));
+                        $dataholder .= html_writer::tag('a', fullname($user, $choices->fullnamecapability), array('href'=>$CFG->wwwroot . '/user/view.php?id='.$user->id.'&course='.$choices->courseid));
+                        $coldata .= html_writer::tag('div', $dataholder, array('class'=>'userinfo'));
+                    }                    
+                }                                     
+            }
+            
+            $columns[] = $coldata;
+            $count++;
+        }
+
+        $table->data[] = $columns;
+        $html .= html_writer::table($table);
+        
+        $actiondata = '';
+        if ($choices->viewresponsecapability && $choices->deleterepsonsecapability) {            
+            $selecturl = new moodle_url('#');
+
+            $selectallactions = new component_action('click',"select_all_in", array('div',null,'tablecontainer'));
+            $selectall = new action_link($selecturl, get_string('selectall', 'quiz'), $selectallactions);
+            $actiondata .= $OUTPUT->render($selectall) . ' / ';
+
+            $deselectallactions = new component_action('click',"deselect_all_in", array('div',null,'tablecontainer'));
+            $deselectall = new action_link($selecturl, get_string('selectnone', 'quiz'), $deselectallactions);
+            $actiondata .= $OUTPUT->render($deselectall);
+
+            $actiondata .= html_writer::tag('label', ' ' . get_string('withselected', 'quiz') . ' ', array('for'=>'menuaction'));
+            
+            $actionurl = new moodle_url($CFG->wwwroot.'/mod/choice/view.php', array('sesskey'=>sesskey()));
+            $select = new single_select($actionurl, 'action', array('delete'=>get_string('delete')), null, array(''=>get_string('moveselectedusersto', 'choice')), 'attemptsform');
+            $actiondata .= $OUTPUT->render($select);
+        }
+        $html .= html_writer::tag('div', $actiondata, array('class'=>'responseaction'));
+        
+        if ($choices->viewresponsecapability) {
+            $html .= html_writer::end_tag('form');
+        }
+        
+        return $html;        
+    }
+
+    /**
+     * Returns HTML to display choices result
+     * @param object $choices
+     * @return string
+     */
+    public function display_publish_anonymous($choices) {
+        global $CHOICE_COLUMN_HEIGHT;
+
+        $html = '';        
+        $table = new html_table();
+        $table->cellpadding = 5;
+        $table->cellspacing = 0;       
+        $table->attributes['class'] = 'skip-block results anonymous ';        
+        $table->data = array();        
+        $count = 0;
+        ksort($choices->options);
+
+        $columns = array();
+        $rawdata = array();
+        foreach ($choices->options as $optionid => $options) {
+            $columndata = '';
+            $rawdata[$optionid] = new stdClass;
+            if ($choices->showunanswered && $optionid == 0) {
+                $columndata .= html_writer::tag('h3', format_string(get_string('notanswered', 'choice')), array('class'=>'topalignment'));
+                $rawdata[$optionid]->text = get_string('notanswered', 'choice');
+            } else if ($optionid > 0) {
+                $columndata .= html_writer::tag('h3', format_string($choices->options[$optionid]->text), array('class'=>'topalignment'));
+                $rawdata[$optionid]->text = $choices->options[$optionid]->text;
+            }
+
+            if ($choices->showunanswered || $optionid > 0) { 
+               $numberofuser = 0;
+               if (!empty($options->user)) {
+                   $numberofuser = count($options->user);
+               }
+               $rawdata[$optionid]->numberofuserhastaken = $numberofuser;
+
+               $height = 0;
+               $percentageamount = 0;
+               if($choices->numberofuser > 0) {
+                   $height = ($CHOICE_COLUMN_HEIGHT * ((float)$numberofuser / (float)$choices->numberofuser));
+                   $percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0;
+               }
+               
+               $displaydiagram = html_writer::tag('img','', array('height'=>$height, 'width'=>'49', 'alt'=>'', 'src'=>'column.png', 'class'=>'dataimg'));
+
+               $columndata .= html_writer::tag('div', format_float($percentageamount,1). '%');
+               $columndata .= $displaydiagram;
+
+               if ($choices->limitanswers) {
+                   $maxanswer = '&nbsp;';
+                   $takenanswer = '&nbsp;';
+                   $answerclass ='skip';
+                   if ($optionid > 0) {
+                       $maxanswer =  format_string(get_string('limit', 'choice') . ': ' . $choices->options[$optionid]->maxanswer);
+                       $answerclass = '';
+                       if (!empty($choices->options[$optionid]->maxanswer)) {
+                            $takenanswer = format_string(get_string('taken', 'choice') . ': ' . $numberofuser);
+                       }                       
+                   }
+                   $columndata .= html_writer::tag('div', $takenanswer, array('class'=>$answerclass));
+                   $columndata .= html_writer::tag('div', $maxanswer, array('class'=>$answerclass)); 
+                } else {                    
+                    $columndata .= html_writer::tag('div', format_string($numberofuser), null);                                        
+                }
+                $rawdata[$optionid]->percentage = format_float($percentageamount,1);
+            }
+
+            $columns[] = $columndata;
+            $table->colclasses[] = 'data';
+        }
+        $table->data[] = $columns;
+        
+        $rawstring = '';
+        
+        if(!empty($rawdata)) {
+            foreach ($rawdata as $id => $content) {
+                if (($choices->showunanswered || $optionid > 0) ) {
+                    $datastr = '';
+                    $datastr .= format_string($content->text) . ': ';
+                    $datastr .= get_string('numberofanswers', 'choice', $content->numberofuserhastaken ) . ', ';
+                    $datastr .= get_string('percentageoftotaluser', 'choice', $content->percentage);
+                    $rawstring .= html_writer::tag('div', $datastr, array('class'=>'choiceresult'));
+                }
+            }
+        }
+
+        if (!empty($rawstring)) {
+            $html .= html_writer::tag('h3', get_string('resultsummary', 'choice'), array('class'=> 'main'));
+            $html .= html_writer::tag('div', $rawstring, array('id'=>'resultsummary', 'class'=> 'box generalbox'));
+        }
+        
+        $html .= html_writer::tag('a', get_string('skipresultgraph', 'choice'), array('href'=>'#skipresultgraph', 'class'=>'skip-block'));
+        $html .= html_writer::tag('h2',format_string(get_string("responses", "choice")), array('class'=>'skip-block main '));
+        $html .= html_writer::table($table);
+        $html .= html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipresultgraph'));
+
+        return $html;
+    }    
+}
+
Index: moodle/mod/choice/report.php
--- moodle/mod/choice/report.php Base (1.79)
+++ moodle/mod/choice/report.php Locally Modified (Based On 1.79)
@@ -214,8 +214,11 @@
         }
         exit;
     }
-    choice_show_results($choice, $course, $cm, $users, $format); //show table with students responses.
 
+    $results = prepare_choice_show_results($choice, $course, $cm, $users);
+    $renderer = $PAGE->get_renderer('mod_choice');
+    echo $renderer->display_result($results);
+    
    //now give links for downloading spreadsheets.
     if (!empty($users) && has_capability('mod/choice:downloadresponses',$context)) {
         echo "<br />\n";
Index: moodle/mod/choice/styles.css
--- moodle/mod/choice/styles.css Base (1.1)
+++ moodle/mod/choice/styles.css Locally Modified (Based On 1.1)
@@ -2,9 +2,26 @@
 .path-mod-choice .results .data {vertical-align:top;white-space: nowrap;}
 .path-mod-choice .button {text-align:center;}
 .path-mod-choice .attemptcell {width:5px;white-space: nowrap;}
-.path-mod-choice .anonymous,
-.path-mod-choice .names {margin-left:auto;margin-right:auto;}
+.path-mod-choice .anonymous,.path-mod-choice .names {margin-left:auto;margin-right:auto;}
 .path-mod-choice .downloadreport {border-width:0;margin-left:auto;margin-right:auto;}
 .path-mod-choice .choiceresponse {width:100%;}
 .path-mod-choice .choiceresponse .picture {width:10px;white-space: nowrap;}
 .path-mod-choice .choiceresponse .fullname {width:100%;white-space: nowrap;}
+.path-mod-choice .horizontal .displaychoices {text-align: center;margin: 10px auto;    }
+.path-mod-choice .horizontal .displaychoices .choices {margin: 10px auto;     }
+.path-mod-choice .horizontal .displaychoices .choices .choice_option{padding: 20px 20px;text-align: center;    display: inline;}
+.path-mod-choice .horizontal .displaychoices .choices .choice_option label {vertical-align: top;}
+.path-mod-choice .horizontal .displaychoices .button {text-align: center;}
+.path-mod-choice .vertical .displaychoices {width: 70%;margin: 0 auto;text-align: center;}
+.path-mod-choice .vertical .displaychoices .choice_option {padding: 10px 50px;}
+.path-mod-choice .vertical .displaychoices .choice_option label {display: inline;vertical-align: top;}
+.path-mod-choice .results.anonymous .data {vertical-align: bottom;text-align: center;margin: 20px 300px;}
+.path-mod-choice .results.names td {vertical-align: top;}
+.path-mod-choice .results.names .userinfo {padding: 5px 20px 5px 0;text-align: left;}
+.path-mod-choice .results.names .userinfo input,
+.path-mod-choice .results.names .userinfo a ,
+.path-mod-choice .results.names .userinfo img{vertical-align: middle;}
+.path-mod-choice #resultsummary {width: 70%;margin: 20px auto;}
+.path-mod-choice #resultsummary .resultsummaryheader{text-align: center;margin: auto;}
+.path-mod-choice .responseaction {width: 50%;margin: 0 auto;text-align: center;}
+.path-mod-choice #yourselection.generalbox {width:70%;margin-left:auto;margin-right:auto;padding-bottom:15px;}
Index: moodle/mod/choice/view.php
--- moodle/mod/choice/view.php Base (1.134)
+++ moodle/mod/choice/view.php Locally Modified (Based On 1.134)
@@ -37,7 +37,6 @@
 
     if ($action == 'delchoice' and confirm_sesskey() and is_enrolled($context, NULL, 'mod/choice:choose') and $choice->allowupdate) {
         if ($answer = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id))) {
-            //print_object($answer);
             $DB->delete_records('choice_answers', array('id' => $answer->id));
         }
     }
@@ -92,7 +91,7 @@
     //if user has already made a selection, and they are not allowed to update it, show their selected answer.
     if (isloggedin() && ($current = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id))) &&
         empty($choice->allowupdate) ) {
-        echo $OUTPUT->box(get_string("yourselection", "choice", userdate($choice->timeopen)).": ".format_string(choice_get_option_text($choice, $current->optionid)));
+        echo $OUTPUT->box(get_string("yourselection", "choice", userdate($choice->timeopen)).": ".format_string(choice_get_option_text($choice, $current->optionid)), 'generalbox', 'yourselection');
     }
 
 /// Print the form
@@ -112,19 +111,15 @@
     if ( (!$current or $choice->allowupdate) and $choiceopen and is_enrolled($context, NULL, 'mod/choice:choose')) {
     // They haven't made their choice yet or updates allowed and choice is open
 
-        echo '<form id="form" method="post" action="view.php">';
+        $options = choice_prepare_options($choice, $USER, $cm, $allresponses);
+        $renderer = $PAGE->get_renderer('mod_choice');
 
-        choice_show_form($choice, $USER, $cm, $allresponses);
-
-        echo '</form>';
-
+        echo $renderer->display_options($options, $cm->id, $choice->display);
         $choiceformshown = true;
     } else {
         $choiceformshown = false;
     }
 
-
-
     if (!$choiceformshown) {
 
         $sitecontext = get_context_instance(CONTEXT_SYSTEM);
@@ -137,8 +132,10 @@
         } else if (!is_enrolled($context)) {
             // Only people enrolled can make a choice
             $SESSION->wantsurl = $FULLME;
+            $SESSION->enrolcancel = '';
+            if (!empty($_SERVER['HTTP_REFERER'])) {
             $SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
-
+            }
             echo $OUTPUT->box_start('generalbox', 'notice');
             echo '<p align="center">'. get_string('noguestchoose', 'choice') .'</p>';
             echo $OUTPUT->container_start('continuebutton');
@@ -155,8 +152,15 @@
         ($choice->showresults == CHOICE_SHOWRESULTS_AFTER_ANSWER and $current ) or
         ($choice->showresults == CHOICE_SHOWRESULTS_AFTER_CLOSE and !$choiceopen ) )  {
 
-        choice_show_results($choice, $course, $cm, $allresponses); //show table with students responses.
+        if (!empty($choice->showunanswered)) {
+            $choice->option[0] = get_string('notanswered', 'choice');
+            $choice->maxanswers[0] = 0;
+        }
 
+        $results = prepare_choice_show_results($choice, $course, $cm, $allresponses);
+        $renderer = $PAGE->get_renderer('mod_choice');
+        echo $renderer->display_result($results);
+
     } else if (!$choiceformshown) {
         echo $OUTPUT->box(get_string('noresultsviewable', 'choice'));
     }
