]> git.mjollnir.org Git - moodle.git/commitdiff
question bank: MDL-17302 refactor question bank display code into a class.
authortjhunt <tjhunt>
Mon, 19 Jan 2009 08:50:48 +0000 (08:50 +0000)
committertjhunt <tjhunt>
Mon, 19 Jan 2009 08:50:48 +0000 (08:50 +0000)
Step 2. Remove as many as possbile of the differences between the two classes. This is mostly whitespace and irrelevant code formatting issues, but there are also a few changes to the generated output, taking the best of both views.

mod/quiz/editlib.php
question/editlib.php

index 4bdd5289964293448d12224496c9a48a5507ffe4..c708dbd33c04647dcc71b46a3a53af4d809dc7d1 100644 (file)
@@ -1030,7 +1030,6 @@ class quiz_question_bank_view extends question_bank_view {
 
     /**
      * Shows the question bank editing interface.
-     * A changed copy of the function at question/editlib.php; to be refactored.
      *
      * The function also processes a number of actions:
      *
@@ -1043,7 +1042,7 @@ class quiz_question_bank_view extends question_bank_view {
      */
     function display($tabname, $contexts, $pageurl, $cm, $page, $perpage, $sortorder,
             $sortorderdecoded, $cat, $recurse, $showhidden, $showquestiontext){
-        global $COURSE,$DB;
+        global $COURSE, $DB;
 
         if (optional_param('deleteselected', false, PARAM_BOOL)){ // teacher still has to confirm
             // make a list of all the questions that are selected
@@ -1057,12 +1056,11 @@ class quiz_question_bank_view extends question_bank_view {
                     $key = $matches[1];
                     $questionlist .= $key.',';
                     question_require_capability_on($key, 'edit');
-                    if ($DB->record_exists('quiz_question_instances', array('question'=>$key))) {
+                    if ($DB->record_exists('quiz_question_instances', array('question' => $key))) {
                         $questionnames .= '* ';
                         $inuse = true;
                     }
-                    $questionnames .= $DB->get_field('question', 'name', array('id'=>$key)).
-                            '<br />';
+                    $questionnames .= $DB->get_field('question', 'name', array('id' => $key)) . '<br />';
                 }
             }
             if (!$questionlist) { // no questions were selected
@@ -1075,81 +1073,68 @@ class quiz_question_bank_view extends question_bank_view {
                 $questionnames .= '<br />'.get_string('questionsinuse', 'quiz');
             }
             notice_yesno(get_string("deletequestionscheck", "quiz", $questionnames),
-                        $pageurl->out_action(array('deleteselected'=>$questionlist,
-                                'confirm'=>md5($questionlist))),
+                        $pageurl->out_action(array('deleteselected'=>$questionlist, 'confirm'=>md5($questionlist))),
                         $pageurl->out_action());
-        }else{
-            //actual question bank
-            // starts with category selection form
-            list($categoryid, $contextid)=  explode(',', $cat);
-
-            if (!$categoryid) {
-                print_box_start('generalbox questionbank');
-                $this->display_category_form($contexts->having_one_edit_tab_cap($tabname), $pageurl, $cat, $recurse, $showhidden, $showquestiontext);
-                echo "<p style=\"text-align:center;\"><b>";
-                print_string("selectcategoryabove", "quiz");
-                echo "</b></p>";
-                print_box_end();
-                return;
-            }
 
-            if (!$category = $DB->get_record('question_categories',
-                    array('id' => $categoryid, 'contextid' => $contextid))) {
-                        print_box_start('generalbox questionbank');
-                notify('Category not found!');
-                print_box_end();
-                return;
-            }
-            $formatoptions = new stdClass;
-            $formatoptions->noclean = true;
-            $strcategory = get_string('category', 'quiz');
-            echo '<div class="categoryinfo"><div class="categorynamefieldcontainer">'.
-                    $strcategory;
-            echo ': <span class="categorynamefield">';
-            echo shorten_text(strip_tags(format_text($category->name, FORMAT_MOODLE,
-                    $formatoptions, $COURSE->id)),60);
-            echo '</span></div><div class="categoryinfofieldcontainer"><span class="categoryinfofield">';
-            echo shorten_text(strip_tags(format_text($category->info, FORMAT_MOODLE,
-                    $formatoptions, $COURSE->id)),200);
-            echo '</span></div></div>';
+            return;
+        }
 
+        // Category selection form
+        list($categoryid, $contextid) = explode(',', $cat);
+        if (!$categoryid) {
             print_box_start('generalbox questionbank');
-
-            $this->display_category_form($contexts->having_one_edit_tab_cap($tabname),
-                    $pageurl, $cat, $recurse, $showhidden, $showquestiontext);
-            // continues with list of questions
-
-            $this->display_question_list($contexts->having_one_edit_tab_cap($tabname),
-                    $pageurl,
-                    $cat,
-                    isset($cm) ? $cm : null,
-                    $recurse,
-                    $page,
-                    $perpage,
-                    $showhidden,
-                    $sortorder,
-                    $sortorderdecoded,
-                    $showquestiontext,
-                    $contexts->having_cap('moodle/question:add'));
-
-            echo '<hr/><form method="get" action="edit.php" id="displayoptions">';
-            echo "<fieldset class='invisiblefieldset'>";
-            echo $pageurl->hidden_params_out(array('recurse', 'showhidden',
-                    'showquestiontext'));
-            $this->display_category_form_checkbox('recurse', $recurse);
-            $this->display_category_form_checkbox('showhidden', $showhidden);
-            echo '<noscript><div class="centerpara"><input type="submit" value="'.
-                    get_string('go') .'" />';
-            echo '</div></noscript></fieldset></form>';
-
+            $this->display_category_form($contexts->having_one_edit_tab_cap($tabname), $pageurl, $cat, $recurse, $showhidden, $showquestiontext);
+            echo "<p style=\"text-align:center;\"><b>";
+            print_string("selectcategoryabove", "quiz");
+            echo "</b></p>";
             print_box_end();
+            return;
         }
 
+        if (!$category = $DB->get_record('question_categories',
+                array('id' => $categoryid, 'contextid' => $contextid))) {
+                    print_box_start('generalbox questionbank');
+            notify('Category not found!');
+            return;
+        }
+        $formatoptions = new stdClass;
+        $formatoptions->noclean = true;
+        $strcategory = get_string('category', 'quiz');
+        echo '<div class="categoryinfo"><div class="categorynamefieldcontainer">'.
+                $strcategory;
+        echo ': <span class="categorynamefield">';
+        echo shorten_text(strip_tags(format_text($category->name, FORMAT_MOODLE,
+                $formatoptions, $COURSE->id)),60);
+        echo '</span></div><div class="categoryinfofieldcontainer"><span class="categoryinfofield">';
+        echo shorten_text(strip_tags(format_text($category->info, FORMAT_MOODLE,
+                $formatoptions, $COURSE->id)),200);
+        echo '</span></div></div>';
+
+        print_box_start('generalbox questionbank');
+
+        $this->display_category_form($contexts->having_one_edit_tab_cap($tabname),
+                $pageurl, $cat, $recurse, $showhidden, $showquestiontext);
+
+        // continues with list of questions
+        $this->display_question_list($contexts->having_one_edit_tab_cap($tabname), $pageurl, $cat, isset($cm) ? $cm : null,
+                $recurse, $page, $perpage, $showhidden, $sortorder, $sortorderdecoded, $showquestiontext,
+                $contexts->having_cap('moodle/question:add'));
+
+        echo '<hr/><form method="get" action="edit.php" id="displayoptions">';
+        echo "<fieldset class='invisiblefieldset'>";
+        echo $pageurl->hidden_params_out(array('recurse', 'showhidden',
+                'showquestiontext'));
+        $this->display_category_form_checkbox('recurse', $recurse);
+        $this->display_category_form_checkbox('showhidden', $showhidden);
+        echo '<noscript><div class="centerpara"><input type="submit" value="'.
+                get_string('go') .'" />';
+        echo '</div></noscript></fieldset></form>';
+
+        print_box_end();
     }
+
     /**
      * prints a form to choose categories
-     * A changed copy of the function at question/editlib.php; to be refactored.
-     *
      */
     function display_category_form($contexts, $pageurl, $current, $recurse=1,
             $showhidden=false, $showquestiontext=false) {
@@ -1163,14 +1148,13 @@ class quiz_question_bank_view extends question_bank_view {
         $strshow = get_string('show', 'quiz');
         $streditcats = get_string('editcategories', 'quiz');
 
-        popup_form ('edit.php?'.$pageurl->get_query_string().'&amp;category=',
+        popup_form('edit.php?'.$pageurl->get_query_string().'&amp;category=',
                 $catmenu, 'catmenu', $current, '', '', '', false, 'self',
                 $strselectcategory.":");
     }
 
     /**
     * Prints the table of questions in a category with interactions
-    * A changed copy of the function at question/editlib.php; to be refactored.
     *
     * @param object $course   The course object
     * @param int $categoryid  The id of the question category to be displayed
@@ -1186,8 +1170,12 @@ class quiz_question_bank_view extends question_bank_view {
             $sortorder='typename', $sortorderdecoded='qtype, name ASC',
             $showquestiontext = false, $addcontexts = array()) {
         global $USER, $CFG, $THEME, $COURSE, $DB;
+
         list($categoryid, $contextid)=  explode(',', $categoryandcontext);
 
+        $cmoptions = new stdClass;
+        $cmoptions->hasattempts = $this->quizhasattempts;
+
         $qtypemenu = question_type_menu();
 
         $strcategory = get_string("category", "quiz");
@@ -1237,11 +1225,8 @@ class quiz_question_bank_view extends question_bank_view {
         } else {
             $quizid = 0;
         }
-        //create the url of the new question page to forward to. return url is given
-        //as a parameter and automatically urlencoded.
-
-
 
+        // Create the url of the new question page to forward to.
         $returnurl = $pageurl->out();
         $questionurl = new moodle_url("$CFG->wwwroot/question/question.php",
                                     array('returnurl' => $returnurl));
@@ -1258,38 +1243,34 @@ class quiz_question_bank_view extends question_bank_view {
             $questionmoveurl->param('courseid', $COURSE->id);
         }
 
-
-        $categorylist = ($recurse) ? question_categorylist($category->id) : $category->id;
-
-        // hide-feature
-        $showhidden = $showhidden ? '' : " AND hidden = '0'";
         echo '<div class="createnewquestion">';
         if ($canadd) {
-            popup_form ($questionurl->out(false, array('category' => $category->id)).
-                    '&amp;qtype=', $qtypemenu, "addquestion_$page", "", "choose", "",
+            popup_form($questionurl->out(false, array('category' => $category->id)).
+                    '&amp;qtype=', $qtypemenu, "addquestion", "", "choose", "",
                     "", false, "self", "<strong>$strcreatenewquestion</strong>");
             helpbutton("questiontypes", $strcreatenewquestion, "quiz");
-        }
-        else {
+        } else {
             print_string('nopermissionadd', 'question');
         }
         echo '</div>';
 
+        $categorylist = ($recurse) ? question_categorylist($category->id) : $category->id;
+        $categorylist_array =  explode(',', $categorylist);
 
-            $categorylist_array =  explode(',', $categorylist);
+        $showhidden = $showhidden ? '' : " AND hidden = '0'";
 
         list($usql, $params) = $DB->get_in_or_equal($categorylist_array);
         if (!$totalnumber = $DB->count_records_select('question',
                 "category $usql AND parent = '0' $showhidden", $params)) {
             echo '<div class="categoryquestionscontainer noquestionsincategory">';
-            print_string("noquestions", "quiz");
-            echo "</div>";
+            print_string('noquestions', 'quiz');
+            echo '</div>';
             return;
         }
 
         if (!$questions = $DB->get_records_select('question',
-                    "category $usql AND parent = '0' $showhidden", $params, $sortorderdecoded,
-                    '*', $page*$perpage, $perpage)) {
+                "category $usql AND parent = '0' $showhidden", $params, $sortorderdecoded,
+                '*', $page*$perpage, $perpage)) {
 
             // There are no questions on the requested page.
             $page = 0;
@@ -1298,17 +1279,16 @@ class quiz_question_bank_view extends question_bank_view {
                     '*', 0, $perpage)) {
                 // There are no questions at all
                 echo '<div class="categoryquestionscontainer noquestionsincategory">';
-                print_string("noquestions", "quiz");
-                echo "</div>";
+                print_string('noquestions', 'quiz');
+                echo '</div>';
                 return;
             }
         }
 
-
-
         echo '<div class="categorysortopotionscontainer">';
         $this->display_question_sort_options($pageurl, $sortorder);
         echo '</div>';
+
         echo '<div class="categorypagingbarcontainer">';
         print_paging_bar($totalnumber, $page, $perpage, $pageurl, 'qpage');
         echo '</div>';
@@ -1343,13 +1323,9 @@ class quiz_question_bank_view extends question_bank_view {
 
             echo "<tr>\n<td style=\"white-space:nowrap;\" $nameclass>\n";
 
-            $canuseq = question_has_capability_on($question, 'use',
-                    $question->category);
+            $canuseq = question_has_capability_on($question, 'use', $question->category);
             if (function_exists('module_specific_actions')) {
-                $cmoptions = new stdClass;
-                $cmoptions->hasattempts = $this->quizhasattempts;
-                echo module_specific_actions($pageurl, $question->id, $cm->id,
-                $canuseq, $cmoptions);
+                echo module_specific_actions($pageurl, $question->id, $cm->id, $canuseq, $cmoptions);
             }
 
             if ($caneditall || $canmoveall || $canuseall){
@@ -1358,38 +1334,33 @@ class quiz_question_bank_view extends question_bank_view {
             echo "</td>\n";
 
             echo "<td $nameclass><div>";
-            $questionstring=quiz_question_tostring($question,false,true,true);
+            $questionstring = quiz_question_tostring($question,false,true,true);
             echo "<label for=\"checkq$question->id\">";
             print_question_icon($question);
             echo " $questionstring</label>";
+            echo "</div></td>\n";
 
+            echo "<td>\n";
 
-
-            echo "</div></td>\n";
-            echo "<td>";
-            // edit, hide, delete question, using question capabilities, not quiz capabilieies
+            // edit, hide, delete question, using question capabilities, not quiz capabilities
             if (question_has_capability_on($question, 'edit', $question->category) ||
-                    question_has_capability_on($question, 'move',
-                    $question->category)) {
-                echo "<a title=\"$stredit\" href=\"".$questionurl->out(false,
-                        array('id'=>$question->id))."\"> <img
-                        src=\"$CFG->pixpath/t/edit.gif\" alt=\"$stredit\" /></a>";
-            } elseif (question_has_capability_on($question, 'view',
-                    $question->category)){
-
-                echo "<a title=\"$strview\" href=\"".$questionurl->out(false,
-                        array('id'=>$question->id))."\"><img
-                        src=\"$CFG->pixpath/i/info.gif\" alt=\"$strview\" /></a>";
+                    question_has_capability_on($question, 'move', $question->category)) {
+                echo "<a title=\"$stredit\" href=\"".$questionurl->out(false, array('id'=>$question->id))."\">
+                        <img src=\"$CFG->pixpath/t/edit.gif\" alt=\"$stredit\" /></a>";
+            } elseif (question_has_capability_on($question, 'view', $question->category)) {
+                echo "<a title=\"$strview\" href=\"".$questionurl->out(false, array('id'=>$question->id))."\">
+                        <img src=\"$CFG->pixpath/i/info.gif\" alt=\"$strview\" /></a>";
             }
+
             // preview
             if ($canuseq) {
                 $quizorcourseid = $quizid?('&amp;quizid=' . $quizid):('&amp;courseid=' .$COURSE->id);
                 link_to_popup_window('/question/preview.php?id=' . $question->id .
                         $quizorcourseid, 'questionpreview',
-                        "<img src=\"$CFG->pixpath/t/preview.gif\" class=\"iconsmall\" alt=\"$strpreview\" />",
+                        " <img src=\"$CFG->pixpath/t/preview.gif\" class=\"iconsmall\" alt=\"$strpreview\" />",
                         0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS);
             }
-            echo "</td>";
+            echo "</td>\n";
 
             echo "</tr>\n";
             if($showquestiontext){
@@ -1397,20 +1368,15 @@ class quiz_question_bank_view extends question_bank_view {
                 $formatoptions = new stdClass;
                 $formatoptions->noclean = true;
                 $formatoptions->para = false;
-                echo format_text($question->questiontext,
-                        $question->questiontextformat,
+                echo format_text($question->questiontext, $question->questiontextformat,
                         $formatoptions, $COURSE->id);
                 echo "</td></tr>\n";
             }
         }
         echo "</table></div>\n";
 
-
-
-
         echo '<div class="categorypagingbarcontainer pagingbottom">';
-        $paging = print_paging_bar($totalnumber, $page, $perpage,
-                $pageurl, 'qpage', false, true);
+        $paging = print_paging_bar($totalnumber, $page, $perpage, $pageurl, 'qpage', false, true);
         if ($totalnumber > DEFAULT_QUESTIONS_PER_PAGE) {
             if ($perpage == DEFAULT_QUESTIONS_PER_PAGE) {
                 $showall = '<a href="edit.php?'.$pageurl->get_query_string(array('qperpage'=>1000)).'">'.get_string('showall', 'moodle', $totalnumber).'</a>';
@@ -1426,6 +1392,7 @@ class quiz_question_bank_view extends question_bank_view {
         }
         echo $paging;
         echo '</div>';
+
         echo '<div class="categoryselectallcontainer">';
         if ($caneditall || $canmoveall || $canuseall){
             echo '<a href="javascript:select_all_in(\'TABLE\',null,\'categoryquestions\');">'.$strselectall.'</a> /'.
@@ -1433,22 +1400,22 @@ class quiz_question_bank_view extends question_bank_view {
             echo '<br />';
         }
         echo "</div>\n";
+
         echo '<div class="modulespecificbuttonscontainer">';
         if ($caneditall || $canmoveall || $canuseall){
             echo '<strong>&nbsp;'.get_string('withselected', 'quiz').':</strong><br />';
+
             if (function_exists('module_specific_buttons')) {
                 echo module_specific_buttons($cm->id,$cmoptions);
             }
+
             // print delete and move selected question
             if ($caneditall) {
-                echo '<input type="submit" name="deleteselected" value="'.
-                        $strdelete."\" />\n";
+                echo '<input type="submit" name="deleteselected" value="' . $strdelete . "\" />\n";
             }
+
             if (function_exists('module_specific_controls') && $canuseall) {
-                $cmoptions = new stdClass;
-                $cmoptions->hasattempts = $this->quizhasattempts;
-                $modulespecific=module_specific_controls($totalnumber, $recurse, $category,
-                        $cm->id,$cmoptions);
+                $modulespecific = module_specific_controls($totalnumber, $recurse, $category, $cm->id,$cmoptions);
                 if(!empty($modulespecific)){
                     echo "<hr />$modulespecific";
                 }
index 96ff9698da39a838cf5aef3d255bd13f130257bd..c21b1eabbb33253f260161c54f93adc3a498cebc 100644 (file)
@@ -160,8 +160,6 @@ class question_bank_view {
      * Other actions:
      * category      Chooses the category
      * displayoptions Sets display options
-     *
-     * @param moodle_url $pageurl object representing this pages url.
      */
     function display($tabname, $contexts, $pageurl, $cm, $page, $perpage, $sortorder,
             $sortorderdecoded, $cat, $recurse, $showhidden, $showquestiontext){
@@ -183,7 +181,7 @@ class question_bank_view {
                         $questionnames .= '* ';
                         $inuse = true;
                     }
-                    $questionnames .= $DB->get_field('question', 'name', array('id' => $key)).'<br />';
+                    $questionnames .= $DB->get_field('question', 'name', array('id' => $key)) . '<br />';
                 }
             }
             if (!$questionlist) { // no questions were selected
@@ -199,17 +197,15 @@ class question_bank_view {
                         $pageurl->out_action(array('deleteselected'=>$questionlist, 'confirm'=>md5($questionlist))),
                         $pageurl->out_action());
 
-            echo '</td></tr>';
-            echo '</table>';
-            print_footer($COURSE);
-            exit;
+            return;
         }
 
-
-        // starts with category selection form
+        // Category selection form
         print_box_start('generalbox questionbank');
         print_heading(get_string('questionbank', 'question'), '', 2);
-        $this->display_category_form($contexts->having_one_edit_tab_cap($tabname), $pageurl, $cat, $recurse, $showhidden, $showquestiontext);
+
+        $this->display_category_form($contexts->having_one_edit_tab_cap($tabname),
+                $pageurl, $cat, $recurse, $showhidden, $showquestiontext);
 
         // continues with list of questions
         $this->display_question_list($contexts->having_one_edit_tab_cap($tabname), $pageurl, $cat, isset($cm) ? $cm : null,
@@ -222,10 +218,10 @@ class question_bank_view {
     /**
      * prints a form to choose categories
      */
-    function display_category_form($contexts, $pageurl, $current, $recurse=1, $showhidden=false, $showquestiontext=false) {
+    function display_category_form($contexts, $pageurl, $current, $recurse=1,
+            $showhidden=false, $showquestiontext=false) {
         global $CFG;
 
-
     /// Get all the existing categories now
         $catmenu = question_category_options($contexts, false, 0, true);
 
@@ -233,7 +229,9 @@ class question_bank_view {
         $strshow = get_string('show', 'quiz');
         $streditcats = get_string('editcategories', 'quiz');
 
-        popup_form('edit.php?'.$pageurl->get_query_string().'&amp;category=', $catmenu, 'catmenu', $current, '', '', '', false, 'self', "<strong>$strcategory</strong>");
+        popup_form('edit.php?'.$pageurl->get_query_string().'&amp;category=',
+                $catmenu, 'catmenu', $current, '', '', '', false, 'self',
+                "<strong>$strcategory</strong>");
 
         echo '<form method="get" action="edit.php" id="displayoptions">';
         echo "<fieldset class='invisiblefieldset'>";
@@ -272,8 +270,9 @@ class question_bank_view {
     * @param boolean $showhidden   True if also hidden questions should be displayed
     * @param boolean $showquestiontext whether the text of each question should be shown in the list
     */
-    function display_question_list($contexts, $pageurl, $categoryandcontext, $cm = null,
-            $recurse=1, $page=0, $perpage=100, $showhidden=false, $sortorder='typename', $sortorderdecoded='qtype, name ASC',
+    function display_question_list($contexts, $pageurl, $categoryandcontext,
+            $cm = null, $recurse=1, $page=0, $perpage=100, $showhidden=false,
+            $sortorder='typename', $sortorderdecoded='qtype, name ASC',
             $showquestiontext = false, $addcontexts = array()) {
         global $USER, $CFG, $THEME, $COURSE, $DB;
 
@@ -286,12 +285,12 @@ class question_bank_view {
         $straddquestions = get_string("addquestions", "quiz");
         $strimportquestions = get_string("importquestions", "quiz");
         $strexportquestions = get_string("exportquestions", "quiz");
-        $strnoquestions = get_string("noquestionsincategory", "quiz");
+        $strnoquestions = get_string("noquestions", "quiz");
         $strselect = get_string("select", "quiz");
         $strselectall = get_string("selectall", "quiz");
         $strselectnone = get_string("selectnone", "quiz");
         $strcreatenewquestion = get_string("createnewquestion", "quiz");
-        $strquestionname = get_string("questionname", "quiz");
+        $strquestion = get_string("question", "quiz");
         $strdelete = get_string("delete");
         $stredit = get_string("edit");
         $strmove = get_string('moveqtoanothercontext', 'question');
@@ -310,10 +309,12 @@ class question_bank_view {
             return;
         }
 
-        if (!$category = $DB->get_record('question_categories', array('id' => $categoryid, 'contextid' => $contextid))) {
+        if (!$category = $DB->get_record('question_categories',
+                array('id' => $categoryid, 'contextid' => $contextid))) {
             notify('Category not found!');
             return;
         }
+
         $catcontext = get_context_instance_by_id($contextid);
         $canadd = has_capability('moodle/question:add', $catcontext);
         //check for capabilities on all questions in category, will also apply to sub cats.
@@ -326,6 +327,8 @@ class question_bank_view {
         } else {
             $quizid = 0;
         }
+
+        // Create the url of the new question page to forward to.
         $returnurl = $pageurl->out();
         $questionurl = new moodle_url("$CFG->wwwroot/question/question.php",
                                     array('returnurl' => $returnurl));
@@ -341,66 +344,73 @@ class question_bank_view {
         } else {
             $questionmoveurl->param('courseid', $COURSE->id);
         }
+
         echo '<div class="boxaligncenter">';
         $formatoptions = new stdClass;
         $formatoptions->noclean = true;
         echo format_text($category->info, FORMAT_MOODLE, $formatoptions, $COURSE->id);
+        echo "</div>\n";
 
-        echo '<table><tr>';
-
+        echo '<div class="createnewquestion">';
         if ($canadd) {
-            echo '<td valign="top" align="right">';
-            popup_form ($questionurl->out(false, array('category' => $category->id)).'&amp;qtype=', $qtypemenu, "addquestion", "", "choose", "", "", false, "self", "<strong>$strcreatenewquestion</strong>");
-            echo '</td><td valign="top" align="right">';
+            popup_form($questionurl->out(false, array('category' => $category->id)).
+                    '&amp;qtype=', $qtypemenu, "addquestion", "", "choose", "",
+                    "", false, "self", "<strong>$strcreatenewquestion</strong>");
             helpbutton("questiontypes", $strcreatenewquestion, "quiz");
-            echo '</td>';
-        }
-        else {
-            echo '<td>';
+        } else {
             print_string('nopermissionadd', 'question');
-            echo '</td>';
         }
-
-        echo '</tr></table>';
         echo '</div>';
 
         $categorylist = ($recurse) ? question_categorylist($category->id) : $category->id;
+        $categorylist_array =  explode(',', $categorylist);
 
-        // hide-feature
         $showhidden = $showhidden ? '' : " AND hidden = '0'";
-        $categorylist_array =  explode(',', $categorylist);
+
         list($usql, $params) = $DB->get_in_or_equal($categorylist_array);
-        if (!$totalnumber = $DB->count_records_select('question', "category $usql AND parent = '0' $showhidden", $params)) {
-            echo "<p style=\"text-align:center;\">";
-            echo $strnoquestions;
-            echo "</p>";
+        if (!$totalnumber = $DB->count_records_select('question',
+                "category $usql AND parent = '0' $showhidden", $params)) {
+            echo '<div class="categoryquestionscontainer noquestionsincategory">';
+            print_string('noquestions', 'quiz');
+            echo '</div>';
             return;
         }
 
-        if (!$questions = $DB->get_records_select('question', "category $usql AND parent = '0' $showhidden", $params, $sortorderdecoded, '*', $page*$perpage, $perpage)) {
+        if (!$questions = $DB->get_records_select('question',
+                "category $usql AND parent = '0' $showhidden", $params, $sortorderdecoded,
+                '*', $page*$perpage, $perpage)) {
+
             // There are no questions on the requested page.
             $page = 0;
-            if (!$questions = $DB->get_records_select('question', "category $usql AND parent = '0' $showhidden", $params, $sortorderdecoded, '*', 0, $perpage)) {
+            if (!$questions = $DB->get_records_select('question',
+                    "category $usql AND parent = '0' $showhidden", $params, $sortorderdecoded,
+                    '*', 0, $perpage)) {
                 // There are no questions at all
-                echo "<p style=\"text-align:center;\">";
-                echo $strnoquestions;
-                echo "</p>";
+                echo '<div class="categoryquestionscontainer noquestionsincategory">';
+                print_string('noquestions', 'quiz');
+                echo '</div>';
                 return;
             }
         }
 
-        print_paging_bar($totalnumber, $page, $perpage, $pageurl, 'qpage');
+        echo '<div class="categorysortopotionscontainer">';
         $this->display_question_sort_options($pageurl, $sortorder);
+        echo '</div>';
+
+        echo '<div class="categorypagingbarcontainer">';
+        print_paging_bar($totalnumber, $page, $perpage, $pageurl, 'qpage');
+        echo '</div>';
 
         echo '<form method="post" action="edit.php">';
         echo '<fieldset class="invisiblefieldset" style="display: block;">';
         echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
         echo $pageurl->hidden_params_out();
-        echo '<table id="categoryquestions" style="width: 100%"><tr>';
+        echo '<div class="categoryquestionscontainer">';
+        echo '<table id="categoryquestions" style="width: 100%"><colgroup><col id="qaction"></col><col id="qname"></col><col id="qextraactions"></col></colgroup><tr>';
         echo "<th style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">$straction</th>";
 
-        echo "<th style=\"white-space:nowrap; text-align: left;\" class=\"header\" scope=\"col\">$strquestionname</th>
-        <th style=\"white-space:nowrap; text-align: right;\" class=\"header\" scope=\"col\">$strtype</th>";
+        echo "<th style=\"white-space:nowrap; text-align: left;\" class=\"header\" scope=\"col\">$strquestion</th>";
+        echo "<th style=\"white-space:nowrap; text-align: left;\" class=\"header\" scope=\"col\"></th>";
         echo "</tr>\n";
         foreach ($questions as $question) {
             $nameclass = '';
@@ -426,46 +436,54 @@ class question_bank_view {
                 echo module_specific_actions($pageurl, $question->id, $cm->id, $canuseq);
             }
 
+            if ($caneditall || $canmoveall || $canuseall){
+                echo "<input title=\"$strselect\" type=\"checkbox\" name=\"q$question->id\" id=\"checkq$question->id\" value=\"1\" />";
+            }
+            echo "</td>\n";
+
+            echo "<td $nameclass><div>";
+            print_question_icon($question);
+            echo format_string($question->name);
+            echo "</div></td>\n";
+
+            echo "<td>\n";
+
+            // edit, hide, delete question, using question capabilities, not quiz capabilities
+            if (question_has_capability_on($question, 'edit', $question->category) ||
+                    question_has_capability_on($question, 'move', $question->category)) {
+                echo "<a title=\"$stredit\" href=\"".$questionurl->out(false, array('id'=>$question->id))."\">
+                        <img src=\"$CFG->pixpath/t/edit.gif\" alt=\"$stredit\" /></a>";
+            } elseif (question_has_capability_on($question, 'view', $question->category)) {
+                echo "<a title=\"$strview\" href=\"".$questionurl->out(false, array('id'=>$question->id))."\">
+                        <img src=\"$CFG->pixpath/i/info.gif\" alt=\"$strview\" /></a>";
+            }
+
             // preview
             if ($canuseq) {
                 $quizorcourseid = $quizid?('&amp;quizid=' . $quizid):('&amp;courseid=' .$COURSE->id);
-                link_to_popup_window('/question/preview.php?id=' . $question->id . $quizorcourseid, 'questionpreview',
-                        "<img src=\"$CFG->pixpath/t/preview.gif\" class=\"iconsmall\" alt=\"$strpreview\" />",
+                link_to_popup_window('/question/preview.php?id=' . $question->id .
+                        $quizorcourseid, 'questionpreview',
+                        " <img src=\"$CFG->pixpath/t/preview.gif\" class=\"iconsmall\" alt=\"$strpreview\" />",
                         0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS);
             }
-            // edit, hide, delete question, using question capabilities, not quiz capabilieies
-            if (question_has_capability_on($question, 'edit', $question->category) || question_has_capability_on($question, 'move', $question->category)) {
-                echo "<a title=\"$stredit\" href=\"".$questionurl->out(false, array('id'=>$question->id))."\"><img
-                        src=\"$CFG->pixpath/t/edit.gif\" alt=\"$stredit\" /></a>&nbsp;";
-            } elseif (question_has_capability_on($question, 'view', $question->category)){
-                echo "<a title=\"$strview\" href=\"".$questionurl->out(false, array('id'=>$question->id))."\"><img
-                        src=\"$CFG->pixpath/i/info.gif\" alt=\"$strview\" /></a>&nbsp;";
-            }
 
             if (question_has_capability_on($question, 'move', $question->category) && question_has_capability_on($question, 'view', $question->category)) {
-                echo "<a title=\"$strmove\" href=\"".$questionurl->out(false, array('id'=>$question->id, 'movecontext'=>1))."\"><img
-                        src=\"$CFG->pixpath/t/move.gif\" alt=\"$strmove\" /></a>&nbsp;";
+                echo "<a title=\"$strmove\" href=\"".$questionurl->out(false, array('id'=>$question->id, 'movecontext'=>1))."\">
+                        <img src=\"$CFG->pixpath/t/move.gif\" alt=\"$strmove\" /></a>";
             }
 
             if (question_has_capability_on($question, 'edit', $question->category)) {
                 // hide-feature
                 if($question->hidden) {
-                    echo "<a title=\"$strrestore\" href=\"edit.php?".$pageurl->get_query_string()."&amp;unhide=$question->id&amp;sesskey=".sesskey()."\"><img
-                            src=\"$CFG->pixpath/t/restore.gif\" alt=\"$strrestore\" /></a>";
+                    echo "<a title=\"$strrestore\" href=\"edit.php?".$pageurl->get_query_string()."&amp;unhide=$question->id&amp;sesskey=".sesskey()."\">
+                            <img src=\"$CFG->pixpath/t/restore.gif\" alt=\"$strrestore\" /></a>";
                 } else {
-                    echo "<a title=\"$strdelete\" href=\"edit.php?".$pageurl->get_query_string()."&amp;deleteselected=$question->id&amp;q$question->id=1\"><img
-                            src=\"$CFG->pixpath/t/delete.gif\" alt=\"$strdelete\" /></a>";
+                    echo "<a title=\"$strdelete\" href=\"edit.php?".$pageurl->get_query_string()."&amp;deleteselected=$question->id&amp;q$question->id=1\">
+                            <img src=\"$CFG->pixpath/t/delete.gif\" alt=\"$strdelete\" /></a>";
                 }
             }
-            if ($caneditall || $canmoveall || $canuseall){
-                echo "&nbsp;<input title=\"$strselect\" type=\"checkbox\" name=\"q$question->id\" value=\"1\" />";
-            }
             echo "</td>\n";
 
-            echo "<td $nameclass>" . format_string($question->name) . "</td>\n";
-            echo "<td $nameclass style='text-align: right'>\n";
-            print_question_icon($question);
-            echo "</td>\n";
             echo "</tr>\n";
             if($showquestiontext){
                 echo '<tr><td colspan="3" ' . $textclass . '>';
@@ -477,8 +495,9 @@ class question_bank_view {
                 echo "</td></tr>\n";
             }
         }
-        echo "</table>\n";
+        echo "</table></div>\n";
 
+        echo '<div class="categorypagingbarcontainer pagingbottom">';
         $paging = print_paging_bar($totalnumber, $page, $perpage, $pageurl, 'qpage', false, true);
         if ($totalnumber > DEFAULT_QUESTIONS_PER_PAGE) {
             if ($perpage == DEFAULT_QUESTIONS_PER_PAGE) {
@@ -494,29 +513,43 @@ class question_bank_view {
             }
         }
         echo $paging;
+        echo '</div>';
 
+        echo '<div class="categoryselectallcontainer">';
         if ($caneditall || $canmoveall || $canuseall){
             echo '<a href="javascript:select_all_in(\'TABLE\',null,\'categoryquestions\');">'.$strselectall.'</a> /'.
              ' <a href="javascript:deselect_all_in(\'TABLE\',null,\'categoryquestions\');">'.$strselectnone.'</a>';
             echo '<br />';
+        }
+        echo "</div>\n";
+
+        echo '<div class="modulespecificbuttonscontainer">';
+        if ($caneditall || $canmoveall || $canuseall){
             echo '<strong>&nbsp;'.get_string('withselected', 'quiz').':</strong><br />';
 
             if (function_exists('module_specific_buttons')) {
                 echo module_specific_buttons($cm->id);
             }
+
             // print delete and move selected question
             if ($caneditall) {
-                echo '<input type="submit" name="deleteselected" value="'.$strdelete."\" />\n";
+                echo '<input type="submit" name="deleteselected" value="' . $strdelete . "\" />\n";
             }
+
             if ($canmoveall && count($addcontexts)) {
                 echo '<input type="submit" name="move" value="'.get_string('moveto', 'quiz')."\" />\n";
                 question_category_select_menu($addcontexts, false, 0, "$category->id,$category->contextid");
             }
 
             if (function_exists('module_specific_controls') && $canuseall) {
-                echo module_specific_controls($totalnumber, $recurse, $category, $cm->id);
+                $modulespecific = module_specific_controls($totalnumber, $recurse, $category, $cm->id);
+                if(!empty($modulespecific)){
+                    echo "<hr />$modulespecific";
+                }
             }
         }
+        echo "</div>\n";
+
         echo '</fieldset>';
         echo "</form>\n";
     }