Index: moodle/mod/choice/index.php
--- moodle/mod/choice/index.php Base (1.53)
+++ moodle/mod/choice/index.php Locally Modified (Based On 1.53)
@@ -20,6 +20,7 @@
     $strchoices = get_string("modulenameplural", "choice");
     $strsectionname  = get_string('sectionname', 'format_'.$course->format);
     $PAGE->set_title($strchoices);
+    $PAGE->set_heading($course->fullname);
     $PAGE->navbar->add($strchoices);
     echo $OUTPUT->header();
 
Index: moodle/mod/choice/lang/en/choice.php
--- moodle/mod/choice/lang/en/choice.php Base (1.7)
+++ moodle/mod/choice/lang/en/choice.php Locally Modified (Based On 1.7)
@@ -85,3 +85,6 @@
 $string['viewallresponses'] = 'View {$a} responses';
 $string['withselected'] = 'With selected';
 $string['yourselection'] = 'Your selection';
+$string['skipresultgraph'] = 'Skip Result Graph';
+$string['moveselectedusersto'] = 'Move selected users to...';
+$string['numberofuser'] = 'The number of user';
Index: moodle/mod/choice/lib.php
--- moodle/mod/choice/lib.php Base (1.132)
+++ moodle/mod/choice/lib.php Locally Modified (Based On 1.132)
@@ -25,6 +25,10 @@
 global $CHOICE_COLUMN_HEIGHT;
 $CHOICE_COLUMN_HEIGHT = 300;
 
+/** @global int $CHOICE_COLUMN_WIDTH */
+global $CHOICE_COLUMN_WIDTH;
+$CHOICE_COLUMN_WIDTH = 300;
+
 define('CHOICE_PUBLISH_ANONYMOUS', '0');
 define('CHOICE_PUBLISH_NAMES',     '1');
 
@@ -184,126 +188,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', array('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,32 +326,49 @@
 
 /**
  * @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, $cm, $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 = $cm->id;
+    $display->courseid = $course->id;
+
+    //overwrite options value;
+    $display->options = array();
+    $totaluser = 0;
+    foreach ($choice->option as $optionid => $optiontext) {
+        $display->options[$optionid] = new stdClass;
+        $display->options[$optionid]->text = $optiontext;
+        $display->options[$optionid]->maxanswer = $choice->maxanswers[$optionid];
+
+        if (array_key_exists($optionid, $allresponses)) {
+            $display->options[$optionid]->user = $allresponses[$optionid]; //->user;
+            $totaluser += count($allresponses[$optionid]);
     }
+    }
+    unset($display->option);
+    unset($display->maxanswers);
 
+    $display->numberofuser = $totaluser;
+    $context = get_context_instance(CONTEXT_MODULE, $cm->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 (empty($allresponses)) {
         echo $OUTPUT->heading(get_string("nousersyet"));
         return false;
     }
 
+
     $totalresponsecount = 0;
     foreach ($allresponses as $optionid => $userlist) {
         if ($choice->showunanswered || $optionid) {
@@ -559,94 +504,10 @@
                 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];
+    return $display;
             }
-            $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").":";
-                    echo $choice->maxanswers[$optionid];
-                } 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,401 @@
+<?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
+ **/
+define ('DISPLAY_HORIZONTAL_LAYOUT', 0);
+define ('DISPLAY_VERTICAL_LAYOUT', 1);
+
+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;
+        
+        $layoutclass = 'horizontal';
+        if ($vertical) {
+            $layoutclass = 'vertical';
+        }
+
+        $attributes = array('method'=>'POST', 'target'=>$CFG->wwwroot.'/mod/choice/view.php', 'class'=> $layoutclass);
+        
+        $html = html_writer::start_tag('form', $attributes);
+        $html .= html_writer::start_tag('ul', array('class'=>'choices' ));
+        
+        $availableoption = count($options['options']);
+        foreach ($options['options'] as $option) {            
+            $html .= html_writer::start_tag('li', array('class'=>'option'));
+            $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('li');
+        }
+        $html .= html_writer::end_tag('ul');
+        $html .= html_writer::tag('div', '', array('class'=>'clearfloat'));
+        $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('ul');
+        $html .= html_writer::end_tag('form');
+        
+        
+        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;
+        }
+
+        $displaylayout = $choices->display;
+
+        if ($forcepublish) {  //CHOICE_PUBLISH_NAMES            
+            return $this->display_publish_name_vertical($choices);
+        } else { //CHOICE_PUBLISH_ANONYMOUS';
+            if ($displaylayout == DISPLAY_HORIZONTAL_LAYOUT) {
+                return $this->display_publish_anonymous_horizontal($choices);
+            }
+            return $this->display_publish_anonymous_vertical($choices);
+        }                
+    }
+
+    /**
+     * Returns HTML to display choices result
+     * @param object $choices
+     * @param bool $forcepublish
+     * @return string
+     */
+    public function display_publish_name_vertical($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';
+                
+        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('div', format_string(get_string('notanswered', 'choice')), array('class'=>'option'));
+            } else if ($optionid > 0) {
+                $coldata .= html_writer::tag('div', format_string($choices->options[$optionid]->text), array('class'=>'option'));
+            }
+            $numberofuser = 0;
+            if (!empty($options->user) && count($options->user) > 0) {
+                $numberofuser = count($options->user);                
+            } 
+
+            //if($optionid != 0) {
+                $coldata .= html_writer::tag('div', ' ('.$numberofuser. ')', array('class'=>'numberofuser', 'title' => get_string('numberofuser', 'choice')));
+            //}
+            $columns[] = $coldata;
+        }
+        
+        $table->head = $columns;
+
+        $coldata = '';
+        $columns = array();
+        foreach ($choices->options as $optionid => $options) {
+            $coldata = '';
+            if ($choices->showunanswered || $optionid > 0) {
+                if (!empty($options->user)) {
+                    foreach ($options->user as $user) { 
+                        $data = '';
+                        if (empty($user->imagealt)){
+                            $user->imagealt = '';
+                        }
+                        $usernameclass = 'fullname';
+                        if ($optionid <= 0) {
+                            $usernameclass = 'unanswereduser';
+                        }
+                        if ($choices->viewresponsecapability && $choices->deleterepsonsecapability  && $optionid > 0) {                            
+                            $attemptaction = html_writer::checkbox('attemptid[]', $user->id,'');
+                            $data .= html_writer::tag('div', $attemptaction, array('class'=>'attemptaction'));
+                        }
+                        $userimage = $OUTPUT->user_picture($user, array('courseid'=>$choices->courseid));
+                        $data .= html_writer::tag('div', $userimage, array('class'=>'image'));
+
+                        $name = html_writer::tag('a', fullname($user, $choices->fullnamecapability), array('href'=>$CFG->wwwroot . '/user/view.php?id='.$user->id.'&course='.$choices->courseid, 'class'=>'username'));
+                        $data .= html_writer::tag('div', $name, array('class'=>$usernameclass));
+                        $data .= html_writer::tag('div','', array('class'=>'clearfloat'));
+                        $coldata .= html_writer::tag('div', $data, array('class'=>'user'));                        
+                    }                    
+                }                
+            }
+            
+            $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(), 'action'=>'delete_confirmation()'));
+            $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_vertical($choices) {
+        global $CHOICE_COLUMN_HEIGHT, $OUTPUT;
+
+        $html = '';        
+        $table = new html_table();
+        $table->cellpadding = 5;
+        $table->cellspacing = 0;       
+        $table->attributes['class'] = 'results anonymous ';        
+        $table->data = array();        
+        $count = 0;
+        ksort($choices->options);
+        $columns = array();
+        $rows = array();
+
+        foreach ($choices->options as $optionid => $options) {
+
+            $numberofuser = 0;
+            if (!empty($options->user)) {
+               $numberofuser = count($options->user);
+            }
+            $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('style'=>'height:'.$height.'px;width:49px;', 'alt'=>'', 'src'=>$OUTPUT->pix_url('column', 'choice')));
+
+            $cell = new html_table_cell();
+            $cell->text = $displaydiagram;
+            $cell->attributes = array('class'=>'graph vertical');
+            $columns[] = $cell;
+        }
+        $rowgraph = new html_table_row();
+        $rowgraph->cells = $columns;
+        $rows[] = $rowgraph;
+
+        $cell = new html_table_cell();
+        $cell->text = html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipresultgraph'));
+        $cell->colspan = count($columns);        
+
+        $rowskip = new html_table_row();
+        $rowskip->cells[] = $cell;
+        $rowskip->attributes = array('class'=>'skip-block-to');
+        $rows[] = $rowskip;
+        
+        $columns = array();
+        foreach ($choices->options as $optionid => $options) {
+            $columndata = '';
+            $numberofuser = 0;
+            if (!empty($options->user)) {
+               $numberofuser = count($options->user);
+            }
+            
+            
+            if ($choices->showunanswered && $optionid == 0) {
+                $columndata .= html_writer::tag('div', format_string(get_string('notanswered', 'choice')), array('class'=>'option'));
+            } else if ($optionid > 0) {
+                $columndata .= html_writer::tag('div', format_string($choices->options[$optionid]->text), array('class'=>'option'));
+            }
+            $columndata .= html_writer::tag('div', ' ('.$numberofuser.')', array('class'=>'numberofuser', 'title'=> get_string('numberofuser', 'choice')));
+            
+            if($choices->numberofuser > 0) {
+               $percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0;
+            }
+            $columndata .= html_writer::tag('div', format_float($percentageamount,1). '%', array('class'=>'percentage'));
+            
+            $cell = new html_table_cell();
+            $cell->text = $columndata;
+            $cell->attributes = array('class'=>'data');
+            $columns[] = $cell;            
+        }
+        $rowdata = new html_table_row();
+        $rowdata->cells = $columns;
+        $rows[] = $rowdata;
+
+        $table->data = $rows;
+        
+        $header = html_writer::tag('h2',format_string(get_string("responses", "choice")));
+        $html .= html_writer::tag('div', $header, array('class'=>'responseheader'));
+        $html .= html_writer::tag('a', get_string('skipresultgraph', 'choice'), array('href'=>'#skipresultgraph', 'class'=>'skip-block'));
+        $html .= html_writer::table($table);
+        
+        return $html;
+    }
+
+    /**
+     * Returns HTML to display choices result
+     * @param object $choices
+     * @return string
+     */
+    public function display_publish_anonymous_horizontal($choices) {
+        global $CHOICE_COLUMN_WIDTH, $OUTPUT;
+        
+        $table = new html_table();
+        $table->cellpadding = 5;
+        $table->cellspacing = 0;
+        $table->attributes['class'] = 'results anonymous ';
+        $table->data = array();
+
+        $count = 0;
+        ksort($choices->options);
+
+        $rows = array();
+        foreach ($choices->options as $optionid => $options) {         
+            $numberofuser = 0;
+            $graphcell = new html_table_cell();
+            if (!empty($options->user)) {
+               $numberofuser = count($options->user);
+            }
+
+            $width = 0;
+            $percentageamount = 0;
+            $columndata = '';
+            if($choices->numberofuser > 0) {
+               $width = ($CHOICE_COLUMN_WIDTH * ((float)$numberofuser / (float)$choices->numberofuser));
+               $percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0;
+            }
+            $displaydiagram = html_writer::tag('img','', array('style'=>'height:50px; width:'.$width.'px', 'alt'=>'', 'src'=>$OUTPUT->pix_url('row', 'choice')));
+
+            $skiplink = html_writer::tag('a', get_string('skipresultgraph', 'choice'), array('href'=>'#skipresultgraph'. $optionid, 'class'=>'skip-block'));
+            $skiphandler = html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipresultgraph'.$optionid));
+            
+            $graphcell->text = $skiplink . $displaydiagram . $skiphandler;
+            $graphcell->attributes = array('class'=>'graph horizontal');
+
+            $datacell = new html_table_cell();
+            if ($choices->showunanswered && $optionid == 0) {
+                $columndata .= html_writer::tag('div', format_string(get_string('notanswered', 'choice')), array('class'=>'option'));
+            } else if ($optionid > 0) {
+                $columndata .= html_writer::tag('div', format_string($choices->options[$optionid]->text), array('class'=>'option'));
+            }
+            $columndata .= html_writer::tag('div', ' ('.$numberofuser.')', array('title'=> get_string('numberofuser', 'choice'), 'class'=>'numberofuser'));
+
+            if($choices->numberofuser > 0) {
+               $percentageamount = ((float)$numberofuser/(float)$choices->numberofuser)*100.0;
+            }
+            $columndata .= html_writer::tag('div', format_float($percentageamount,1). '%', array('class'=>'percentage'));
+            
+
+            $datacell->text = $columndata;
+            $datacell->attributes = array('class'=>'data');
+
+            $row = new html_table_row();
+            $row->cells = array($datacell, $graphcell);
+            $rows[] = $row;
+        }
+        
+        $table->data = $rows;
+        
+        $html = '';
+        $header = html_writer::tag('h2',format_string(get_string("responses", "choice")));
+        $html .= html_writer::tag('div', $header, array('class'=>'responseheader'));        
+        $html .= html_writer::table($table);
+        
+        return $html;
+    }
+}
+
Index: moodle/mod/choice/report.php
--- moodle/mod/choice/report.php Base (1.80)
+++ moodle/mod/choice/report.php Locally Modified (Based On 1.80)
@@ -215,25 +215,31 @@
         }
         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, has_capability('mod/choice:readresponses', $context));
+    
    //now give links for downloading spreadsheets.
     if (!empty($users) && has_capability('mod/choice:downloadresponses',$context)) {
-        echo "<br />\n";
-        echo "<table class=\"downloadreport\"><tr>\n";
-        echo "<td>";
+        $downloadoptions = array();
         $options = array();
         $options["id"] = "$cm->id";
         $options["download"] = "ods";
-        echo $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadods"));
-        echo "</td><td>";
+        $button =  $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadods"));
+        $downloadoptions[] = html_writer::tag('li', $button, array('class'=>'reportoption'));
+
         $options["download"] = "xls";
-        echo $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadexcel"));
-        echo "</td><td>";
+        $buttons = $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadexcel"));
+        $downloadoptions[] = html_writer::tag('li', $button, array('class'=>'reportoption'));
+
         $options["download"] = "txt";
-        echo $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadtext"));
+        $button = $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadtext"));
+        $downloadoptions[] = html_writer::tag('li', $button, array('class'=>'reportoption'));
 
-        echo "</td></tr></table>";
+        $downloadlist = html_writer::tag('ul', implode('', $downloadoptions));
+        $downloadlist .= html_writer::tag('div', '', array('class'=>'clearfloat'));
+        echo html_writer::tag('div',$downloadlist, array('class'=>'downloadreport'));
     }
     echo $OUTPUT->footer();
 
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)
@@ -6,5 +6,46 @@
 .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 .choiceresponse .picture,
+.path-mod-choice .choiceresponse .fullname{width:10px;white-space: nowrap;}
+
+.path-mod-choice .responseheader {width: 100%; text-align: center; margin-top: 10px;}
+.path-mod-choice .choices .option label {vertical-align: top;}
+.path-mod-choice .choices .option input {vertical-align: middle;}
+
+.path-mod-choice .horizontal,
+.path-mod-choice .vertical {margin-left: 15%;margin-right: 15%;}
+.path-mod-choice .horizontal .choices .option {padding-right:20px;display:inline; white-space: normal;}
+.path-mod-choice .horizontal .choices .button {margin-top: 10px;}
+.path-mod-choice ul.choices li {list-style:none;}
+.path-mod-choice .results { text-align: center;}
+.path-mod-choice .results.anonymous .graph.horizontal {vertical-align: middle;text-align: left;}
+
+.path-mod-choice .results.anonymous .graph.vertical,
+.path-mod-choice .cell {vertical-align: bottom; text-align: center; }
+.path-mod-choice .results .cell,
+.path-mod-choice .results.names .header{width:10%; white-space: normal;}
+.path-mod-choice .results.names .cell{vertical-align: top; text-align: left;}
+.path-mod-choice .results.names .user {padding: 5px;}
+.path-mod-choice .results.names .user .attemptaction,
+.path-mod-choice .results.names .user .image,
+.path-mod-choice .results.names .user .fullname{float:left;}
+
+#page-mod-choice-report .downloadreport ul li {list-style:none;padding: 0 20px; display: inline;float: left; }
+.path-mod-choice .downloadreport {margin-left:25%;}
+
+.path-mod-choice .clearfloat {float:none; clear:both;}
+
+/** Overide for RTL layout **/
+.path-mod-choice.dir-rtl .horizontal .choices {vertical-align: top;text-align: center;}
+.path-mod-choice.dir-rtl .horizontal .choices .option{padding: 20px;display: normal; float: right;}
+.path-mod-choice.dir-rtl .horizontal .choices .option {padding-left: 20px;padding-right:0; display:inline;}
+.path-mod-choice.dir-rtl .results.anonymous .graph.horizontal {text-align: right;}
+.path-mod-choice.dir-rtl .results.anonymous { text-align: center; }
+.path-mod-choice.dir-rtl .results.names .cell{text-align: right;}
+.path-mod-choice.dir-rtl .results.names .user .attemptaction,
+.path-mod-choice.dir-rtl .results.names .user .image,
+.path-mod-choice.dir-rtl .results.names .user .fullname,
+#page-mod-choice-report.dir-rtl .downloadreport ul li{float:right;}
+.path-mod-choice.dir-rtl .downloadreport {margin-left:0;margin-right: 25%;}
+#page-mod-choice-view.dir-rtl .reportlink {text-align: left;}

Index: moodle/mod/choice/view.php
--- moodle/mod/choice/view.php Base (1.138)
+++ moodle/mod/choice/view.php Locally Modified (Based On 1.138)
@@ -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));
         }
     }
@@ -95,7 +94,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
@@ -115,21 +114,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">';
-
-        choice_show_form($choice, $USER, $cm, $allresponses);
-
-        echo '</form>';
-
+        $options = choice_prepare_options($choice, $USER, $cm, $allresponses);
+        $renderer = $PAGE->get_renderer('mod_choice');        
+        echo $renderer->display_options($options, $cm->id, $choice->display);
         $choiceformshown = true;
     } else {
         $choiceformshown = false;
     }
 
-
-
     if (!$choiceformshown) {
-
         $sitecontext = get_context_instance(CONTEXT_SYSTEM);
 
         if (isguestuser()) {
@@ -153,14 +146,22 @@
     }
 
     // print the results at the bottom of the screen
-
+    $readresponsescapability = has_capability('mod/choice:readresponses', $context);
     if ( $choice->showresults == CHOICE_SHOWRESULTS_ALWAYS or
         ($choice->showresults == CHOICE_SHOWRESULTS_AFTER_ANSWER and $current ) or
-        ($choice->showresults == CHOICE_SHOWRESULTS_AFTER_CLOSE and !$choiceopen ) )  {
+        ($choice->showresults == CHOICE_SHOWRESULTS_AFTER_CLOSE and !$choiceopen ) or
+        ($readresponsescapability))  {
 
-        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;
+        }
 
-    } else if (!$choiceformshown) {
+        $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'));
     }
 
Index: moodle/theme/base/style/core.css
--- moodle/theme/base/style/core.css Base (1.47)
+++ moodle/theme/base/style/core.css Locally Modified (Based On 1.47)
@@ -624,6 +627,13 @@
 .userenrolment .col_enrol .enrolment {float:left;padding:3px;margin:3px;}
 .userenrolment .col_enrol .enrolment a {float:right;margin-left:3px;}
 
+/**
+ * Choice
+ */
+.path-mod-choice .results .option,
+.path-mod-choice .results .numberofuser,
+.path-mod-choice .results .percentage {font-weight: bold; font-size: 108%;}
+
 /** Overide for RTL layout **/
 .dir-rtl .headermain {float:right;}
 .dir-rtl .headermenu {float:left;}
