]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19976 Refactored select_menu() into select(), now supporting menu, radio and...
authornicolasconnault <nicolasconnault>
Tue, 4 Aug 2009 02:05:32 +0000 (02:05 +0000)
committernicolasconnault <nicolasconnault>
Tue, 4 Aug 2009 02:05:32 +0000 (02:05 +0000)
19 files changed:
course/category.php
course/report/participation/index.php
course/search.php
files/index.php
grade/edit/tree/index.php
grade/edit/tree/lib.php
lib/deprecatedlib.php
lib/javascript-static.js
lib/outputlib.php
lib/simpletest/testoutputlib.php
lib/weblib.php
mod/choice/lib.php
mod/feedback/analysis_course.php
mod/lesson/report.php
mod/scorm/locallib.php
mod/scorm/report.php
mod/wiki/admin.php
mod/wiki/view.php
user/index.php

index 0f79b1af924338a3d351181b37dc899e930d3b4d..171d6d9a7651c4d4a6d742e406d09a2f651764f5 100644 (file)
             make_categories_list($movetocategories, $notused, 'moodle/category:manage');
             $movetocategories[$category->id] = get_string('moveselectedcoursesto');
             echo '<tr><td colspan="3" align="right">';
-            $selectmenu = new moodle_select_menu();
-            $selectmenu->options = $movetocategories;
-            $selectmenu->name = 'moveto';
-            $selectmenu->selectedvalue = $category->id;
-            $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'movecourses'));
-            echo $OUTPUT->select_menu($selectmenu);
+            $select = new moodle_select();
+            $select->options = $movetocategories;
+            $select->name = 'moveto';
+            $select->selectedvalue = $category->id;
+            $select->add_action('change', 'submit_form_by_id', array('id' => 'movecourses'));
+            echo $OUTPUT->select($select);
             echo '<input type="hidden" name="id" value="'.$category->id.'" />';
             echo '</td></tr>';
         }
index f376a08b411e87e81d43e69fbd443239016ae723..26a2dc6aacd2249439a1600e62808e9a114ab991 100644 (file)
             echo '<input type="button" onclick="checknos()" value="'.get_string('selectnos').'" />'."\n";
         }
         $displaylist['messageselect.php'] = get_string('messageselectadd');
-        $selectmenu = new moodle_select_menu();
-        $selectmenu->options = $displaylist;
-        $selectmenu->name = "formaction";
-        $selectmenu->label = get_string("withselectedusers");
-        $selectmenu->add_action('change', 'conditionalsubmit', array('formid' => 'studentsform'));
-        echo $OUTPUT->select_menu($selectmenu);
+        $select = new moodle_select();
+        $select->options = $displaylist;
+        $select->name = "formaction";
+        $select->label = get_string("withselectedusers");
+        $select->add_action('change', 'conditionalsubmit', array('formid' => 'studentsform'));
+        echo $OUTPUT->select($select);
         helpbutton("participantswithselectedusers", get_string("withselectedusers"));
         echo '<input type="submit" value="' . get_string('ok') . '" />'."\n";
         echo '</div>'."\n";
index 0762d67c9f1fdb78b017c9cba99dd046d80d3917..15d401ed903125a439632071c4f116fd4654bd3d 100644 (file)
             echo "<br />";
             echo "<input type=\"button\" onclick=\"checkall()\" value=\"$strselectall\" />\n";
             echo "<input type=\"button\" onclick=\"checknone()\" value=\"$strdeselectall\" />\n";
-            $selectmenu = new moodle_select_menu();
-            $selectmenu->options = $displaylist;
-            $selectmenu->name = "moveto";
-            $selectmenu->label = get_string("moveselectedcoursesto");
-            $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'movecourses'));
-            echo $OUTPUT->select_menu($selectmenu);
+            $select = new moodle_select();
+            $select->options = $displaylist;
+            $select->name = "moveto";
+            $select->label = get_string("moveselectedcoursesto");
+            $select->add_action('change', 'submit_form_by_id', array('id' => 'movecourses'));
+            echo $OUTPUT->select($select);
             echo "</td>\n</tr>\n";
             echo "</table>\n</form>";
 
index 7e1d733e1ac0146d82fcfadaf117ca8d72f5942e..77b486b0fb1aecaa69f5fdab7b7c9fcf741d721c 100644 (file)
@@ -46,7 +46,7 @@ if ($courseid) {
     if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) {
         print_error('invalidcontext');
     }
-    redirect('index.php?contextid='.$context->id.'&amp;itemid=0&amp;filearea=course_content');
+    redirect(new moodle_url('index.php', array('contextid' => $context->id, 'itemid'=> 0, 'filearea' => 'course_content')));
 }
 
 if (!$context = get_context_instance_by_id($contextid)) {
@@ -82,8 +82,7 @@ $file_info = $browser->get_file_info($context, $filearea, $itemid, $filepath, $f
 if ($file_info and $file_info->is_directory() and $file_info->is_writable() and $newdirname !== '' and data_submitted() and confirm_sesskey()) {
     if ($newdir_info = $file_info->create_directory($newdirname, $USER->id)) {
         $params = $newdir_info->get_params_rawencoded();
-        $params = implode('&amp;', $params);
-        redirect("index.php?$params");
+        redirect(new moodle_url('index.php', $params));
     } else {
         $error = "Could not create new dir"; // TODO: localise
     }
@@ -96,8 +95,7 @@ if ($file_info and $file_info->is_directory() and $file_info->is_writable() and
         try {
             if ($newfile = $file_info->create_file_from_pathname($newfilename, $_FILES['newfile']['tmp_name'], $USER->id)) {
                 $params = $file_info->get_params_rawencoded();
-                $params = implode('&amp;', $params);
-                redirect("index.php?$params");
+                redirect(new moodle_url('index.php', $params));
 
             } else {
                 $error = "Could not create upload file"; // TODO: localise
@@ -129,8 +127,7 @@ if ($file_info and $delete) {
             $error = "Could not delete file!"; // TODO: localise
         }
         $params = $parent_info->get_params_rawencoded();
-        $params = implode('&amp;', $params);
-        redirect("index.php?$params", $error);
+        redirect(new moodle_url('index.php', $params));
     }
 }
 
index 7b71f6f536c83a56b2fa0ab558d748313ab38403..879e42b6ebff67fb5f15f5e24a03a4888c2c92d3 100644 (file)
@@ -309,13 +309,13 @@ if (!$moving && count($categories) > 1) {
     echo '<br /><br />';
     echo '<input type="hidden" name="bulkmove" value="0" id="bulkmoveinput" />';
     echo get_string('moveselectedto', 'grades') . ' ';
-    $selectmenu = new moodle_select_menu();
-    $selectmenu->options = $categories;
-    $selectmenu->name = 'moveafter';
-    $selectmenu->disabled = true;
-    $selectmenu->id = 'menumoveafter';
-    $selectmenu->add_action('change', 'submit_bulk_move');
-    echo $OUTPUT->select_menu($selectmenu);
+    $select = new moodle_select();
+    $select->options = $categories;
+    $select->name = 'moveafter';
+    $select->disabled = true;
+    $select->id = 'menumoveafter';
+    $select->add_action('change', 'submit_bulk_move');
+    echo $OUTPUT->select($select);
     echo '<div id="noscriptgradetreeform" style="display: inline;">
             <input type="submit" value="'.get_string('go').'" />
           </div>';
index c1b71e34ac57bda87e1a260bb42d0ff85a05695f..551b9d7034816bbdac1defc1fb8d541ed12b6965 100755 (executable)
@@ -564,12 +564,12 @@ class grade_edit_tree_column_aggregation extends grade_edit_tree_column_category
             }
         }
 
-        $selectmenu = new moodle_select_menu();
-        $selectmenu->options = $options;
-        $selectmenu->name = 'aggregation_'.$category->id;
-        $selectmenu->selectedvalue = $category->aggregation;
-        $selectmenu->add_action('change', 'update_category_aggregation', array('courseid' => $params['id'], 'category' => $category->id, 'sesskey' => sesskey()));
-        $aggregation = $OUTPUT->select_menu($selectmenu);
+        $select = new moodle_select();
+        $select->options = $options;
+        $select->name = 'aggregation_'.$category->id;
+        $select->selectedvalue = $category->aggregation;
+        $select->add_action('change', 'update_category_aggregation', array('courseid' => $params['id'], 'category' => $category->id, 'sesskey' => sesskey()));
+        $aggregation = $OUTPUT->select($select);
 
         if ($this->forced) {
             $aggregation = $options[$category->aggregation];
index 9735870e4b62a1178516c41958ba9f69ea259100..60c42b09ffa0c9f7ee07cd318b6376087af1cf95 100644 (file)
@@ -2634,7 +2634,7 @@ function print_single_button($link, $options, $label='OK', $method='get', $notus
     }
 
     $output = $OUTPUT->button($form);
-    
+
     $icon = new action_icon();
 
     if ($return) {
@@ -3080,29 +3080,29 @@ function choose_from_menu ($options, $name, $selected='', $nothing='choose', $sc
                            $id='', $listbox=false, $multiple=false, $class='') {
 
     global $OUTPUT;
-    // debugging('choose_from_menu() has been deprecated. Please change your code to use $OUTPUT->select_menu($selectmenu).');
+    // debugging('choose_from_menu() has been deprecated. Please change your code to use $OUTPUT->select($select).');
 
     if ($script) {
         debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
     }
-    $selectmenu = new moodle_select_menu();
-    $selectmenu->options = $options;
-    $selectmenu->name = $name;
-    $selectmenu->selectedvalue = $selected;
-    $selectmenu->nothinglabel = $nothing;
-    $selectmenu->nothingvalue = $nothingvalue;
-    $selectmenu->disabled = $disabled;
-    $selectmenu->tabindex = $tabindex;
-    $selectmenu->id = $id;
-    $selectmenu->listbox = $listbox;
-    $selectmenu->multiple = $multiple;
-    $selectmenu->add_classes($class);
+    $select = new moodle_select();
+    $select->options = $options;
+    $select->name = $name;
+    $select->selectedvalue = $selected;
+    $select->nothinglabel = $nothing;
+    $select->nothingvalue = $nothingvalue;
+    $select->disabled = $disabled;
+    $select->tabindex = $tabindex;
+    $select->id = $id;
+    $select->listbox = $listbox;
+    $select->multiple = $multiple;
+    $select->add_classes($class);
 
     if ($nothing == 'choose') {
-        $selectmenu->nothinglabel = '';
+        $select->nothinglabel = '';
     }
 
-    $output = $OUTPUT->select_menu($selectmenu);
+    $output = $OUTPUT->select($select);
 
     if ($return) {
         return $output;
@@ -3130,17 +3130,17 @@ function choose_from_menu ($options, $name, $selected='', $nothing='choose', $sc
  */
 function choose_from_menu_yesno($name, $selected, $script = '',
         $return = false, $disabled = false, $tabindex = 0) {
-    // debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use $OUTPUT->select_menu($selectmenu).');
+    // debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use $OUTPUT->select($select).');
     global $OUTPUT;
 
     if ($script) {
         debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
     }
 
-    $selectmenu = moodle_select_menu::make_yes_no($name, $selected);
-    $selectmenu->disabled = $disabled;
-    $selectmenu->tabindex = $tabindex;
-    $output = $OUTPUT->select_menu($select_menu);
+    $select = moodle_select::make_yes_no($name, $selected);
+    $select->disabled = $disabled;
+    $select->tabindex = $tabindex;
+    $output = $OUTPUT->select($select);
 
     if ($return) {
         return $output;
@@ -3177,23 +3177,23 @@ function choose_from_menu_yesno($name, $selected, $script = '',
 function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
                                  $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
 
-    // debugging('choose_from_menu_nested() has been deprecated. Please change your code to use $OUTPUT->select_menu($selectmenu).');
+    // debugging('choose_from_menu_nested() has been deprecated. Please change your code to use $OUTPUT->select($select).');
     global $OUTPUT;
 
     if ($script) {
         debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
     }
-    $selectmenu = moodle_select_menu::make($options, $name, $selected);
-    $selectmenu->tabindex = $tabindex;
-    $selectmenu->disabled = $disabled;
-    $selectmenu->nothingvalue = $nothingvalue;
-    $selectmenu->nested = true;
+    $select = moodle_select::make($options, $name, $selected);
+    $select->tabindex = $tabindex;
+    $select->disabled = $disabled;
+    $select->nothingvalue = $nothingvalue;
+    $select->nested = true;
 
     if ($nothing == 'choose') {
-        $selectmenu->nothinglabel = '';
+        $select->nothinglabel = '';
     }
 
-    $output = $OUTPUT->select_menu($selectmenu);
+    $output = $OUTPUT->select($select);
 
     if ($return) {
         return $output;
@@ -3214,7 +3214,7 @@ function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$
  * @return string|bool Depending on value of $return
  */
 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
-    // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_button($scaleselectmenu).');
+    // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_button($scaleselect).');
     global $OUTPUT;
 
     $helpbutton = help_button::make_scale_menu($courseid, $scale);
@@ -3245,7 +3245,7 @@ function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
  * @return string|bool Depending on value of $return
  */
 function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $return=false) {
-    throw new coding_exception('print_timer_selector is completely deprecated. Please use $OUTPUT->select_menu($selectmenu) instead');
+    throw new coding_exception('print_timer_selector is completely deprecated. Please use $OUTPUT->select($select) instead');
 }
 
 /**
@@ -3261,12 +3261,12 @@ function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $
  * @return string|bool Depending on value of $return
  */
 function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
-    // debugging('print_time_selector() has been deprecated. Please change your code to use $OUTPUT->select_menu($timeselector).');
+    // debugging('print_time_selector() has been deprecated. Please change your code to use $OUTPUT->select($timeselector).');
     global $OUTPUT;
-    $hourselector = moodle_select_menu::make_time_selector('hours', $hour, $currenttime);
-    $minuteselector = moodle_select_menu::make_time_selector('minutes', $minute, $currenttime, $step);
+    $hourselector = moodle_select::make_time_selector('hours', $hour, $currenttime);
+    $minuteselector = moodle_select::make_time_selector('minutes', $minute, $currenttime, $step);
 
-    $output = $OUTPUT->select_menu($hourselector) . $OUTPUT->select_menu($minuteselector);
+    $output = $OUTPUT->select($hourselector) . $OUTPUT->select($minuteselector);
 
     if ($return) {
         return $output;
@@ -3289,14 +3289,14 @@ function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=fa
  */
 function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
 
-    // debugging('print_date_selector() has been deprecated. Please change your code to use $OUTPUT->select_menu($dateselector).');
+    // debugging('print_date_selector() has been deprecated. Please change your code to use $OUTPUT->select($dateselector).');
     global $OUTPUT;
 
-    $dayselector = moodle_select_menu::make_time_selector('days', $day, $currenttime);
-    $monthselector = moodle_select_menu::make_time_selector('months', $month, $currenttime);
-    $yearselector = moodle_select_menu::make_time_selector('years', $year, $currenttime);
+    $dayselector = moodle_select::make_time_selector('days', $day, $currenttime);
+    $monthselector = moodle_select::make_time_selector('months', $month, $currenttime);
+    $yearselector = moodle_select::make_time_selector('years', $year, $currenttime);
 
-    $output = $OUTPUT->select_menu($dayselector) . $OUTPUT->select_menu($monthselector) . $OUTPUT->select_menu($yearselector);
+    $output = $OUTPUT->select($dayselector) . $OUTPUT->select($monthselector) . $OUTPUT->select($yearselector);
 
     if ($return) {
         return $output;
@@ -3337,7 +3337,7 @@ function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose'
     $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
     global $OUTPUT;
 
-    // debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->select_menu($dateselector).');
+    // debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->select($dateselector).');
 
     if (!empty($optionsextra)) {
         debugging('the optionsextra param has been deprecated in popup_form, it will be ignored.', DEBUG_DEVELOPER);
@@ -3346,25 +3346,25 @@ function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose'
     if (empty($options)) {
         return '';
     }
-    $selectmenu = moodle_select_menu::make_popup_form($baseurl, $options, $formid, $submitvalue, $selected);
-    $selectmenu->disabled = $disabled;
-    
+    $select = moodle_select::make_popup_form($baseurl, $options, $formid, $submitvalue, $selected);
+    $select->disabled = $disabled;
+
     // Extract the last param of the baseurl for the name of the select
     if (preg_match('/([a-z_]*)=$/', $baseurl, $matches)) {
-        $selectmenu->name = $matches[1];
-        $selectmenu->form->url->remove_params(array($matches[1]));
+        $select->name = $matches[1];
+        $select->form->url->remove_params(array($matches[1]));
     }
 
     if ($nothing == 'choose') {
-        $selectmenu->nothinglabel = '';
+        $select->nothinglabel = '';
     } else {
-        $selectmenu->nothinglabel = $nothing;
+        $select->nothinglabel = $nothing;
     }
 
-    $selectmenu->set_label($selectlabel, $selectmenu->id);
-    $selectmenu->set_help_icon($help, $helptext);
+    $select->set_label($selectlabel, $select->id);
+    $select->set_help_icon($help, $helptext);
 
-    $output = $OUTPUT->select_menu($selectmenu);
+    $output = $OUTPUT->select($select);
 
     if ($return) {
         return $output;
@@ -3387,13 +3387,86 @@ function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose'
  */
 function close_window_button($name='closewindow', $return=false, $reloadopener = false) {
     global $OUTPUT;
-    
+
     // debugging('close_window_button() has been deprecated. Please change your code to use $OUTPUT->close_window_button().');
     $output = $OUTPUT->close_window_button(get_string($name));
-    
+
     if ($return) {
         return $output;
     } else {
         echo $output;
     }
 }
+
+/**
+ * Given an array of values, creates a group of radio buttons to be part of a form
+ *
+ * @deprecated since Moodle 2.0
+ *
+ * @staticvar int $idcounter
+ * @param array  $options  An array of value-label pairs for the radio group (values as keys)
+ * @param string $name     Name of the radiogroup (unique in the form)
+ * @param string $checked  The value that is already checked
+ * @param bool $return Whether this function should return a string or output
+ *                     it (defaults to false)
+ * @return string|void If $return=true returns string, else echo's and returns void
+ */
+function choose_from_radio ($options, $name, $checked='', $return=false) {
+
+    // debugging('choose_from_radio() has been deprecated. Please change your code to use $OUTPUT->select($select).');
+    global $OUTPUT;
+
+    $select = moodle_select::make($options, $name, $checked);
+    $select->rendertype = 'radio';
+
+    $output = $OUTPUT->select($select);
+
+    if ($return) {
+        return $output;
+    } else {
+        echo $output;
+    }
+}
+
+/**
+ * Display an standard html checkbox with an optional label
+ *
+ * @deprecated since Moodle 2.0
+ *
+ * @staticvar int $idcounter
+ * @param string $name    The name of the checkbox
+ * @param string $value   The valus that the checkbox will pass when checked
+ * @param bool $checked The flag to tell the checkbox initial state
+ * @param string $label   The label to be showed near the checkbox
+ * @param string $alt     The info to be inserted in the alt tag
+ * @param string $script If not '', then this is added to the checkbox element
+ *                       as an onchange handler.
+ * @param bool $return Whether this function should return a string or output
+ *                     it (defaults to false)
+ * @return string|void If $return=true returns string, else echo's and returns void
+ */
+function print_checkbox ($name, $value, $checked = true, $label = '', $alt = '', $script='',$return=false) {
+
+    // debugging('print_checkbox() has been deprecated. Please change your code to use $OUTPUT->checkbox($checkbox).');
+    global $OUTPUT;
+    
+    if (!empty($script)) {
+        debugging('The use of the $script param in print_checkbox has not been migrated into $OUTPUT->checkbox. Please use $checkbox->add_action().', DEBUG_DEVELOPER);
+    }
+
+    $checkbox = new html_select_option();
+    $checkbox->value = $value;
+    $checkbox->selected = $checked;
+    $checkbox->text = $label;
+    $checkbox->label->text = $label;
+    $checkbox->alt = $alt;
+
+    $output = $OUTPUT->checkbox($checkbox, $name);
+
+    if (empty($return)) {
+        echo $output;
+    } else {
+        return $output;
+    }
+
+}
index 2dedac9bda8ea6587e025dc08446932ff18c13c0..44221394f75e35d7f33abf87448d526211fb6cee 100644 (file)
@@ -210,15 +210,15 @@ function lockoptionsallsetup(formid) {
  * submits the form designated by args.id. If args.selectid is also
  * given, it only submits the form if the selected <option> is not 
  * the first one (usually the "Choose..." option)
- * Example usage of the moodle_select_menu component with this function:
+ * Example usage of the moodle_select component with this function:
  * <pre>
- * $selectmenu = new moodle_select_menu();
- * $selectmenu->options = array('delete' => get_string('delete'));
- * $selectmenu->name = 'action';
- * $selectmenu->button->label = get_string('withselected', 'quiz');
- * $selectmenu->id = 'menuaction';
- * $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
- * echo $OUTPUT->select_menu($selectmenu);
+ * $select = new moodle_select();
+ * $select->options = array('delete' => get_string('delete'));
+ * $select->name = 'action';
+ * $select->button->label = get_string('withselected', 'quiz');
+ * $select->id = 'menuaction';
+ * $select->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
+ * echo $OUTPUT->select($select);
  * </pre>
  */
 function submit_form_by_id(e, args) {
index d5189fe25de8be2e81b4ef740fd131b3196c9ffd..48004591863fcf31b2fbec1963d025b81aae29bb 100644 (file)
@@ -1318,6 +1318,10 @@ class moodle_renderer_base {
      * @return string HTML fragment
      */
     protected function output_attribute($name, $value) {
+        if (is_array($value)) {
+            debugging("Passed an array for the HTML attribute $name", DEBUG_DEVELOPER);
+        }
+
         $value = trim($value);
         if ($value == HTML_ATTR_EMPTY) {
             return ' ' . $name . '=""';
@@ -2782,7 +2786,7 @@ class moodle_core_renderer extends moodle_renderer_base {
 
         return $output . $this->output_end_tag($tag);
     }
-    
+
     /**
      * Prints a simple button to close a window
      *
@@ -2799,100 +2803,197 @@ class moodle_core_renderer extends moodle_renderer_base {
         return $this->container($this->button($closeform), 'closewindow');
     }
 
-    public function close_window($delay = 0, $reloadopener = false) {
-        // TODO
-    }
-
     /**
-     * Output a <select> menu.
+     * Outputs a <select> menu or a list of radio/checkbox inputs.
      *
      * This method is extremely versatile, and can be used to output yes/no menus,
      * form-enclosed menus with automatic redirects when an option is selected,
      * descriptive labels and help icons. By default it just outputs a select
      * menu.
      *
-     * To add a descriptive label, use moodle_select_menu::set_label($text, $for) or
-     * moodle_select_menu::set_label($label) passing a html_label object
+     * To add a descriptive label, use moodle_select::set_label($text, $for) or
+     * moodle_select::set_label($label) passing a html_label object
+     *
+     * To add a help icon, use moodle_select::set_help($page, $text, $linktext) or
+     * moodle_select::set_help($helpicon) passing a help_icon object
      *
-     * To add a help icon, use moodle_select_menu::set_help($page, $text, $linktext) or
-     * moodle_select_menu::set_help($helpicon) passing a help_icon object
+     * If you moodle_select::$rendertype to "radio", it will render radio buttons
+     * instead of a <select> menu, unless $multiple is true, in which case it
+     * will render checkboxes.
      *
-     * To surround the menu with a form, simply set moodle_select_menu->form as a
-     * valid html_form object.
+     * To surround the menu with a form, simply set moodle_select->form as a
+     * valid html_form object. Note that this function will NOT automatically
+     * add a form for non-JS browsers. If you do not set one up, it assumes
+     * that you are providing your own form in some other way.
      *
-     * You can either call this function with a single moodle_select_menu argument
+     * You can either call this function with a single moodle_select argument
      * or, with a list of parameters, in which case those parameters are sent to
-     * the moodle_select_menu constructor.
+     * the moodle_select constructor.
      *
-     * @param moodle_select_menu $selectmenu a moodle_select_menu that describes
+     * @param moodle_select $select a moodle_select that describes
      *      the select menu you want output.
      * @return string the HTML for the <select>
      */
-    public function select_menu($selectmenu) {
-        $selectmenu = clone($selectmenu);
-        $selectmenu->prepare();
+    public function select($select) {
+        $select = clone($select);
+        $select->prepare();
 
-        $this->prepare_event_handlers($selectmenu);
+        $this->prepare_event_handlers($select);
 
-        if (empty($selectmenu->id)) {
-            $selectmenu->id = 'menu' . str_replace(array('[', ']'), '', $selectmenu->name);
+        if (empty($select->id)) {
+            $select->id = 'menu' . str_replace(array('[', ']'), '', $select->name);
         }
 
         $attributes = array(
-            'name' => $selectmenu->name,
-            'id' => $selectmenu->id,
-            'class' => $selectmenu->get_classes_string()
+            'name' => $select->name,
+            'id' => $select->id,
+            'class' => $select->get_classes_string()
         );
-        if ($selectmenu->disabled) {
+        if ($select->disabled) {
             $attributes['disabled'] = 'disabled';
         }
-        if ($selectmenu->tabindex) {
+        if ($select->tabindex) {
             $attributes['tabindex'] = $tabindex;
         }
 
-        if ($selectmenu->listbox) {
-            if (is_integer($selectmenu->listbox)) {
-                $size = $selectmenu->listbox;
+        if ($select->rendertype == 'menu' && $select->listbox) {
+            if (is_integer($select->listbox)) {
+                $size = $select->listbox;
             } else {
-                $size = min($selectmenu->maxautosize, count($selectmenu->options));
+                $size = min($select->maxautosize, count($select->options));
             }
             $attributes['size'] = $size;
-            if ($selectmenu->multiple) {
+            if ($select->multiple) {
                 $attributes['multiple'] = 'multiple';
             }
         }
 
         $html = '';
 
-        if (!empty($selectmenu->label)) {
-            $html .= $this->label($selectmenu->label);
+        if (!empty($select->label)) {
+            $html .= $this->label($select->label);
         }
 
-        if (!empty($selectmenu->helpicon) && $selectmenu->helpicon instanceof help_icon) {
-            $html .= $this->help_icon($selectmenu->helpicon);
+        if (!empty($select->helpicon) && $select->helpicon instanceof help_icon) {
+            $html .= $this->help_icon($select->helpicon);
         }
 
-        $html .= $this->output_start_tag('select', $attributes) . "\n";
+        if ($select->rendertype == 'menu') {
+            $html .= $this->output_start_tag('select', $attributes) . "\n";
 
-        foreach ($selectmenu->options as $option) {
-            // $OUTPUT->select_option detects if $option is an option or an optgroup
-            $html .= $this->select_option($option);
-        }
+            foreach ($select->options as $option) {
+                // $OUTPUT->select_option detects if $option is an option or an optgroup
+                $html .= $this->select_option($option);
+            }
 
-        $html .= $this->output_end_tag('select') . "\n";
+            $html .= $this->output_end_tag('select') . "\n";
+        } else if ($select->rendertype == 'radio') {
+            $currentradio = 0;
+            foreach ($select->options as $option) {
+                $html .= $this->radio($option, $select->name);
+                $currentradio++;
+            }
+        } else if ($select->rendertype == 'checkbox') {
+            $currentcheckbox = 0;
+            foreach ($select->options as $option) {
+                $html .= $this->checkbox($option, $select->name);
+                $currentcheckbox++;
+            }
+
+        }
 
-        if (!empty($selectmenu->form) && $selectmenu->form instanceof html_form) {
-            $html = $this->form($selectmenu->form, $html);
+        if (!empty($select->form) && $select->form instanceof html_form) {
+            $html = $this->form($select->form, $html);
         }
 
         return $html;
     }
 
+    /**
+     * Outputs a <input type="radio" /> element. Optgroups are ignored, so do not
+     * pass a html_select_optgroup as a param to this function.
+     *
+     * @param html_select_option $option a html_select_option
+     * @return string the HTML for the <input type="radio">
+     */
+    public function radio($option, $name='unnamed') {
+        if ($option instanceof html_select_optgroup) {
+            throw new coding_exception('$OUTPUT->radio($option) does not support a html_select_optgroup object as param.');
+        } else if (!($option instanceof html_select_option)) {
+            throw new coding_exception('$OUTPUT->radio($option) only accepts a html_select_option object as param.');
+        }
+
+        $option->prepare();
+        $option->generate_id();
+        $option->label->for = $option->id;
+        $this->prepare_event_handlers($option);
+
+        $output = $this->output_start_tag('span', array('class' => "radiogroup $select->name rb$currentradio")) . "\n";
+        $output .= $this->label($option->label);
+
+        if ($option->selected == 'selected') {
+            $option->selected = 'checked';
+        }
+
+        $output .= $this->output_empty_tag('input', array(
+                'type' => 'radio',
+                'value' => $option->value,
+                'name' => $name,
+                'alt' => $option->alt,
+                'id' => $option->id,
+                'class' => $option->get_classes_string(),
+                'checked' => $option->selected));
+
+        $output .= $this->output_end_tag('span');
+
+        return $output;
+    }
+
+    /**
+     * Outputs a <input type="checkbox" /> element. Optgroups are ignored, so do not
+     * pass a html_select_optgroup as a param to this function.
+     *
+     * @param html_select_option $option a html_select_option
+     * @return string the HTML for the <input type="checkbox">
+     */
+    public function checkbox($option, $name='unnamed') {
+        if ($option instanceof html_select_optgroup) {
+            throw new coding_exception('$OUTPUT->checkbox($option) does not support a html_select_optgroup object as param.');
+        } else if (!($option instanceof html_select_option)) {
+            throw new coding_exception('$OUTPUT->checkbox($option) only accepts a html_select_option object as param.');
+        }
+
+        $option->prepare();
+        $option->generate_id();
+        $option->label->for = $option->id;
+        $this->prepare_event_handlers($option);
+
+        $output = $this->output_start_tag('span', array('class' => "checkbox $name")) . "\n";
+
+        if ($option->selected == 'selected') {
+            $option->selected = 'checked';
+        }
+
+        $output .= $this->output_empty_tag('input', array(
+                'type' => 'checkbox',
+                'value' => $option->value,
+                'name' => $name,
+                'id' => $option->id,
+                'alt' => $option->alt,
+                'class' => $option->get_classes_string(),
+                'checked' => $option->selected));
+        $output .= $this->label($option->label);
+
+        $output .= $this->output_end_tag('span');
+
+        return $output;
+    }
+
     /**
      * Output an <option> or <optgroup> element. If an optgroup element is detected,
      * this will recursively output its options as well.
      *
-     * @param mixed $option a moodle_select_option or moodle_select_optgroup
+     * @param mixed $option a html_select_option or moodle_select_optgroup
      * @return string the HTML for the <option> or <optgroup>
      */
     public function select_option($option) {
@@ -3278,7 +3379,7 @@ class moodle_core_renderer extends moodle_renderer_base {
 /// COMPONENTS
 
 /**
- * Base class for classes representing HTML elements, like moodle_select_menu.
+ * Base class for classes representing HTML elements, like moodle_select.
  *
  * Handles the id and class attributes.
  *
@@ -3291,6 +3392,10 @@ class moodle_html_component {
      * @var string value to use for the id attribute of this HTML tag.
      */
     public $id = '';
+    /**
+     * @var string $alt value to use for the alt attribute of this HTML tag.
+     */
+    public $alt = '';
     /**
      * @var array class names to add to this HTML element.
      */
@@ -3413,7 +3518,7 @@ class moodle_html_component {
     /**
      * Internal method for generating a unique ID for the purpose of event handlers.
      */
-    protected function generate_id() {
+    public function generate_id() {
         // Generate an id that is not already used.
         do {
             $newid = get_class($this) . '-' . substr(sha1(microtime() * rand(0, 500)), 0, 6);
@@ -3429,12 +3534,43 @@ class moodle_html_component {
     public function get_actions() {
         return $this->actions;
     }
+
+    /**
+     * Adds a descriptive label to the component.
+     *
+     * This can be used in two ways:
+     *
+     * <pre>
+     * $component->set_label($elementid, $elementlabel);
+     * // OR
+     * $label = new html_label();
+     * $label->for = $elementid;
+     * $label->text = $elementlabel;
+     * $component->set_label($label);
+     * </pre>
+     *
+     * Use the second form when you need to add additional HTML attributes
+     * to the label and/or JS actions.
+     *
+     * @param mixed $text Either the text of the label or a html_label object
+     * @param text  $for The value of the "for" attribute (the associated element's id)
+     * @return void
+     */
+    public function set_label($text, $for=null) {
+        if ($text instanceof html_label) {
+            $this->label = $text;
+        } else if (!empty($text)) {
+            $this->label = new html_label();
+            $this->label->for = $for;
+            $this->label->text = $text;
+        }
+    }
 }
 
 
 /**
  * This class hold all the information required to describe a <select> menu that
- * will be printed by {@link moodle_core_renderer::select_menu()}. (Or by an overridden
+ * will be printed by {@link moodle_core_renderer::select()}. (Or by an overridden
  * version of that method in a subclass.)
  *
  * This component can also hold enough metadata to be used as a popup form. It just
@@ -3448,9 +3584,9 @@ class moodle_html_component {
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  * @since     Moodle 2.0
  */
-class moodle_select_menu extends moodle_html_component {
+class moodle_select extends moodle_html_component {
     /**
-     * The moodle_select_menu object parses an array of options into component objects
+     * The moodle_select object parses an array of options into component objects
      * @see nested attribute
      * @var mixed $options the choices to show in the menu. An array $value => $display, of html_select_option or of html_select_optgroup objects.
      */
@@ -3470,9 +3606,10 @@ class moodle_select_menu extends moodle_html_component {
      */
     public $selectedvalue;
     /**
-     * @var string The label for the 'nothing is selected' option.
      * Defaults to get_string('choosedots').
      * Set this to '' if you do not want a 'nothing is selected' option.
+     * This is ignored if the rendertype is 'radio' or 'checkbox'
+     * @var string The label for the 'nothing is selected' option.
      */
     public $nothinglabel = null;
     /**
@@ -3500,7 +3637,8 @@ class moodle_select_menu extends moodle_html_component {
      */
     public $maxautosize = 10;
     /**
-     * @var boolean if true, allow multiple selection. Only used if $listbox is true.
+     * @var boolean if true, allow multiple selection. Only used if $listbox is true, or if
+     *      the select is to be output as checkboxes.
      */
     public $multiple = false;
     /**
@@ -3517,6 +3655,10 @@ class moodle_select_menu extends moodle_html_component {
      * @var help_icon $form An optional help_icon component
      */
     public $helpicon;
+    /**
+     * @var boolean $rendertype How the select element should be rendered: menu or radio (checkbox is just radio + multiple)
+     */
+    public $rendertype = 'menu';
 
     /**
      * @see moodle_html_component::prepare()
@@ -3536,8 +3678,12 @@ class moodle_select_menu extends moodle_html_component {
             $this->nothinglabel = get_string('choosedots');
         }
 
-        // If nested is on, remove the default Choose option
-        if ($this->nested) {
+        if ($this->rendertype == 'radio' && $this->multiple) {
+            $this->rendertype = 'checkbox';
+        }
+
+        // If nested is on, or if radio/checkbox rendertype is set, remove the default Choose option
+        if ($this->nested || $this->rendertype == 'radio' || $this->rendertype == 'checkbox') {
             $this->nothinglabel = '';
         }
 
@@ -3557,9 +3703,12 @@ class moodle_select_menu extends moodle_html_component {
         }
 
         $options = $this->options;
+
         $this->options = array();
 
-        if ($this->nested) {
+        if ($this->nested && $this->rendertype != 'menu') {
+            throw new coding_exception('moodle_select cannot render nested options as radio buttons or checkboxes.');
+        } else if ($this->nested) {
             foreach ($options as $section => $values) {
                 $optgroup = new html_select_optgroup();
                 $optgroup->text = $section;
@@ -3653,10 +3802,10 @@ class moodle_select_menu extends moodle_html_component {
      * @param array $options used to initialise {@link $options}.
      * @param string $name used to initialise {@link $name}.
      * @param string $selected  used to initialise {@link $selected}.
-     * @return moodle_select_menu A moodle_select_menu object with the three common fields initialised.
+     * @return moodle_select A moodle_select object with the three common fields initialised.
      */
     public static function make($options, $name, $selected = '') {
-        $menu = new moodle_select_menu();
+        $menu = new moodle_select();
         $menu->options = $options;
         $menu->name = $name;
         $menu->selectedvalue = $selected;
@@ -3667,7 +3816,7 @@ class moodle_select_menu extends moodle_html_component {
      * This is a shortcut for making a yes/no select menu.
      * @param string $name used to initialise {@link $name}.
      * @param string $selected  used to initialise {@link $selected}.
-     * @return moodle_select_menu A menu initialised with yes/no options.
+     * @return moodle_select A menu initialised with yes/no options.
      */
     public static function make_yes_no($name, $selected) {
         return self::make(array(0 => get_string('no'), 1 => get_string('yes')), $name, $selected);
@@ -3679,7 +3828,7 @@ class moodle_select_menu extends moodle_html_component {
      * @param string $name fieldname
      * @param int $currenttime A default timestamp in GMT
      * @param int $step minute spacing
-     * @return moodle_select_menu A menu initialised with hour options.
+     * @return moodle_select A menu initialised with hour options.
      */
     public static function make_time_selector($type, $name, $currenttime=0, $step=5) {
 
@@ -3723,7 +3872,7 @@ class moodle_select_menu extends moodle_html_component {
                 }
                 break;
             default:
-                throw new coding_exception("Time type $type is not supported by moodle_select_menu::make_time_selector().");
+                throw new coding_exception("Time type $type is not supported by moodle_select::make_time_selector().");
         }
 
         $timerselector = self::make($timeunits, $name, $currentdate[$userdatetype]);
@@ -3743,58 +3892,27 @@ class moodle_select_menu extends moodle_html_component {
      * @param string $formid id for the control. Must be unique on the page. Used in the HTML.
      * @param string $submitvalue Optional label for the 'Go' button. Defaults to get_string('go').
      * @param string $selected The option that is initially selected
-     * @return moodle_select_menu A menu initialised as a popup form.
+     * @return moodle_select A menu initialised as a popup form.
      */
     public function make_popup_form($baseurl, $options, $formid, $submitvalue='', $selected=null) {
-        $selectmenu = self::make($options, 'jump', $selected);
-        $selectmenu->form = new html_form();
-        $selectmenu->form->id = $formid;
-        $selectmenu->form->method = 'get';
-        $selectmenu->form->add_class('popupform');
-        $selectmenu->form->url = new moodle_url($baseurl);
-        $selectmenu->form->button->text = get_string('go');
+        $select = self::make($options, 'jump', $selected);
+        $select->form = new html_form();
+        $select->form->id = $formid;
+        $select->form->method = 'get';
+        $select->form->add_class('popupform');
+        $select->form->url = new moodle_url($baseurl);
+        $select->form->button->text = get_string('go');
 
         if (!empty($submitvalue)) {
-            $selectmenu->form->button->text = $submitvalue;
+            $select->form->button->text = $submitvalue;
         }
 
-        $selectmenu->id = $formid . '_jump';
-        $selectmenu->baseurl = $baseurl;
+        $select->id = $formid . '_jump';
+        $select->baseurl = $baseurl;
 
-        $selectmenu->add_action('change', 'submit_form_by_id', array('id' => $formid, 'selectid' => $selectmenu->id));
+        $select->add_action('change', 'submit_form_by_id', array('id' => $formid, 'selectid' => $select->id));
 
-        return $selectmenu;
-    }
-
-    /**
-     * Adds a descriptive label to the select menu.
-     *
-     * This can be used in two ways:
-     *
-     * <pre>
-     * $selectmenu->set_label($elementid, $elementlabel);
-     * // OR
-     * $label = new html_label();
-     * $label->for = $elementid;
-     * $label->text = $elementlabel;
-     * $selectmenu->set_label($label);
-     * </pre>
-     *
-     * Use the second form when you need to add additional HTML attributes
-     * to the label and/or JS actions.
-     *
-     * @param mixed $text Either the text of the label or a html_label object
-     * @param text  $for The value of the "for" attribute (the associated element's id)
-     * @return void
-     */
-    public function set_label($text, $for=null) {
-        if ($text instanceof html_label) {
-            $this->label = $text;
-        } else if (!empty($text)) {
-            $this->label = new html_label();
-            $this->label->for = $for;
-            $this->label->text = $text;
-        }
+        return $select;
     }
 
     /**
@@ -3803,13 +3921,13 @@ class moodle_select_menu extends moodle_html_component {
      * This can be used in two ways:
      *
      * <pre>
-     * $selectmenu->set_help_icon($page, $text, $linktext);
+     * $select->set_help_icon($page, $text, $linktext);
      * // OR
      * $helpicon = new help_icon();
      * $helpicon->page = $page;
      * $helpicon->text = $text;
      * $helpicon->linktext = $linktext;
-     * $selectmenu->set_help_icon($helpicon);
+     * $select->set_help_icon($helpicon);
      * </pre>
      *
      * Use the second form when you need to add additional HTML attributes
@@ -3881,6 +3999,14 @@ class html_select_option extends moodle_html_component {
      * @var boolean $selected Whether or not this option is selected
      */
     public $selected = false;
+    /**
+     * @var mixed $label The label for that component. String or html_label object
+     */
+    public $label;
+
+    public function __construct() {
+        $this->label = new html_label();
+    }
 
     /**
      * @see moodle_html_component::prepare()
@@ -3890,6 +4016,13 @@ class html_select_option extends moodle_html_component {
         if (empty($this->text)) {
             throw new coding_exception('html_select_option requires a $text value.');
         }
+
+        if (empty($this->label->text)) {
+            $this->set_label($this->text);
+        } else if (!($this->label instanceof html_label)) {
+            $this->set_label($this->label);
+        }
+
         parent::prepare();
     }
 }
index 275bcf58c33d8a1d75087b1cabc491a7aea62ce4..978625a573770e72af920251271e7fd510e768fe 100644 (file)
@@ -883,9 +883,9 @@ class moodle_core_renderer_test extends UnitTestCase {
         $this->renderer = new moodle_core_renderer(new moodle_page);
     }
 
-    public function test_select_menu_simple() {
-        $selectmenu = moodle_select_menu::make(array(10 => 'ten', 'c2' => 'two'), 'mymenu');
-        $html = $this->renderer->select_menu($selectmenu);
+    public function test_select_simple() {
+        $select = moodle_select::make(array(10 => 'ten', 'c2' => 'two'), 'mymenu');
+        $html = $this->renderer->select($select);
         $this->assert(new ContainsTagWithAttributes('select', array('class' => 'menumymenu select', 'name' => 'mymenu', 'id' => 'menumymenu')), $html);
         $this->assert(new ContainsTagWithContents('option', 'ten'), $html);
         $this->assert(new ContainsTagWithAttribute('option', 'value', '10'), $html);
@@ -1160,10 +1160,10 @@ class moodle_core_renderer_test extends UnitTestCase {
         $html = $this->renderer->htmllist($htmllist);
     }
 
-    public function test_moodle_select_menu() {
+    public function test_moodle_select() {
         $options = array('var1' => 'value1', 'var2' => 'value2', 'var3' => 'value3');
-        $selectmenu = moodle_select_menu::make($options, 'mymenu', 'var2');
-        $html = $this->renderer->select_menu($selectmenu);
+        $select = moodle_select::make($options, 'mymenu', 'var2');
+        $html = $this->renderer->select($select);
         $this->assert(new ContainsTagWithAttributes('select', array('name' => 'mymenu')), $html);
         $this->assert(new ContainsTagWithAttributes('option', array('value' => 'var1'), array('selected' => 'selected')), $html);
         $this->assert(new ContainsTagWithAttributes('option', array('value' => 'var2', 'selected' => 'selected')), $html);
@@ -1173,8 +1173,8 @@ class moodle_core_renderer_test extends UnitTestCase {
         $this->assert(new ContainsTagWithContents('option', 'value3'), $html);
 
         $options = array('group1' => '--group1', 'var1' => 'value1', 'var2' => 'value2', 'group2' => '--', 'group2' => '--group2', 'var3' => 'value3', 'var4' => 'value4');
-        $selectmenu = moodle_select_menu::make($options, 'mymenu', 'var2');
-        $html = $this->renderer->select_menu($selectmenu);
+        $select = moodle_select::make($options, 'mymenu', 'var2');
+        $html = $this->renderer->select($select);
         $this->assert(new ContainsTagWithAttributes('select', array('name' => 'mymenu')), $html);
         $this->assert(new ContainsTagWithAttributes('optgroup', array('label' => 'group1')), $html);
         $this->assert(new ContainsTagWithAttributes('optgroup', array('label' => 'group2')), $html);
index cda5465550839573fc0a8461e114d138d9655dac..8f4f23b523647804316f42635eecb3ebdb073770 100644 (file)
@@ -228,19 +228,19 @@ function qualified_me() {
  *
  * It can be used in moodle pages where config.php has been included without any further includes.
  *
- * It is useful for manipulating urls with long lists of params. 
- * One situation where it will be useful is a page which links to itself to perfrom various actions 
+ * It is useful for manipulating urls with long lists of params.
+ * One situation where it will be useful is a page which links to itself to perfrom various actions
  * and / or to process form data. A moodle_url object :
- * can be created for a page to refer to itself with all the proper get params being passed from page call to 
- * page call and methods can be used to output a url including all the params, optionally adding and overriding 
+ * can be created for a page to refer to itself with all the proper get params being passed from page call to
+ * page call and methods can be used to output a url including all the params, optionally adding and overriding
  * params and can also be used to
  *     - output the url without any get params
- *     - and output the params as hidden fields to be output within a form 
+ *     - and output the params as hidden fields to be output within a form
  *
  * One important usage note is that data passed to methods out, out_action, get_query_string and
- * hidden_params_out affect what is returned by the function and do not change the data stored in the object. 
- * This is to help with typical usage of these objects where one object is used to output urls 
- * in many places in a page. 
+ * hidden_params_out affect what is returned by the function and do not change the data stored in the object.
+ * This is to help with typical usage of these objects where one object is used to output urls
+ * in many places in a page.
  *
  * @link http://docs.moodle.org/en/Development:lib/weblib.php_moodle_url See short write up here
  * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@@ -259,13 +259,13 @@ class moodle_url {
     protected $path = '';
     protected $fragment = '';
     /**
-     * @var array 
+     * @var array
      * @access protected
      */
     protected $params = array(); // Associative array of query string params
 
     /**
-     * Pass no arguments to create a url that refers to this page. 
+     * Pass no arguments to create a url that refers to this page.
      * Use empty string to create empty url.
      *
      * @global string
@@ -314,7 +314,7 @@ class moodle_url {
     }
 
     /**
-     * Add an array of params to the params for this page. 
+     * Add an array of params to the params for this page.
      *
      * The added params override existing ones if they have the same name.
      *
@@ -330,8 +330,8 @@ class moodle_url {
     }
 
     /**
-     * Remove all params if no arguments passed. 
-     * Remove selected params if arguments are passed. 
+     * Remove all params if no arguments passed.
+     * Remove selected params if arguments are passed.
      *
      * Can be called as either remove_params('param1', 'param2')
      * or remove_params(array('param1', 'param2')).
@@ -355,7 +355,7 @@ class moodle_url {
     }
 
     /**
-     * Add a param to the params for this page. 
+     * Add a param to the params for this page.
      *
      * The added param overrides existing one if theyhave the same name.
      *
@@ -503,7 +503,7 @@ function prepare_url($url, $stripformparams=false) {
     // Handle relative URLs
     if (substr($output, 0, 4) != 'http' && substr($output, 0, 1) != '/') {
         if (preg_match('/(.*)\/([A-Za-z0-9-_]*\.php)$/', $PAGE->url->out(true), $matches)) {
-            
+
             return $matches[1] . "/$output";
         } else {
             throw new coding_exception('Your page uses bizarre relative URLs which Moodle cannot handle. Please use absolute URLs.');
@@ -621,105 +621,6 @@ function close_window($delay = 0, $reloadopener = false) {
 }
 
 
-/**
- * Given an array of values, creates a group of radio buttons to be part of a form
- *
- * @staticvar int $idcounter
- * @param array  $options  An array of value-label pairs for the radio group (values as keys)
- * @param string $name     Name of the radiogroup (unique in the form)
- * @param string $checked  The value that is already checked
- * @param bool $return Whether this function should return a string or output 
- *                     it (defaults to false)
- * @return string|void If $return=true returns string, else echo's and returns void
- */
-function choose_from_radio ($options, $name, $checked='', $return=false) {
-
-    static $idcounter = 0;
-
-    if (!$name) {
-        $name = 'unnamed';
-    }
-
-    $output = '<span class="radiogroup '.$name."\">\n";
-
-    if (!empty($options)) {
-        $currentradio = 0;
-        foreach ($options as $value => $label) {
-            $htmlid = 'auto-rb'.sprintf('%04d', ++$idcounter);
-            $output .= ' <span class="radioelement '.$name.' rb'.$currentradio."\">";
-            $output .= '<input name="'.$name.'" id="'.$htmlid.'" type="radio" value="'.$value.'"';
-            if ($value == $checked) {
-                $output .= ' checked="checked"';
-            }
-            if ($label === '') {
-                $output .= ' /> <label for="'.$htmlid.'">'.  $value .'</label></span>' .  "\n";
-            } else {
-                $output .= ' /> <label for="'.$htmlid.'">'.  $label .'</label></span>' .  "\n";
-            }
-            $currentradio = ($currentradio + 1) % 2;
-        }
-    }
-
-    $output .= '</span>' .  "\n";
-
-    if ($return) {
-        return $output;
-    } else {
-        echo $output;
-    }
-}
-
-/** 
- * Display an standard html checkbox with an optional label
- *
- * @staticvar int $idcounter
- * @param string $name    The name of the checkbox
- * @param string $value   The valus that the checkbox will pass when checked
- * @param bool $checked The flag to tell the checkbox initial state
- * @param string $label   The label to be showed near the checkbox
- * @param string $alt     The info to be inserted in the alt tag
- * @param string $script If not '', then this is added to the checkbox element 
- *                       as an onchange handler.
- * @param bool $return Whether this function should return a string or output 
- *                     it (defaults to false)
- * @return string|void If $return=true returns string, else echo's and returns void
- */
-function print_checkbox ($name, $value, $checked = true, $label = '', $alt = '', $script='',$return=false) {
-
-    static $idcounter = 0;
-
-    if (!$name) {
-        $name = 'unnamed';
-    }
-
-    if ($alt) {
-        $alt = strip_tags($alt);
-    } else {
-        $alt = 'checkbox';
-    }
-
-    if ($checked) {
-        $strchecked = ' checked="checked"';
-    } else {
-        $strchecked = '';
-    }
-
-    $htmlid = 'auto-cb'.sprintf('%04d', ++$idcounter);
-    $output  = '<span class="checkbox '.$name."\">";
-    $output .= '<input name="'.$name.'" id="'.$htmlid.'" type="checkbox" value="'.$value.'" alt="'.$alt.'"'.$strchecked.' '.((!empty($script)) ? ' onclick="'.$script.'" ' : '').' />';
-    if(!empty($label)) {
-        $output .= ' <label for="'.$htmlid.'">'.$label.'</label>';
-    }
-    $output .= '</span>'."\n";
-
-    if (empty($return)) {
-        echo $output;
-    } else {
-        return $output;
-    }
-
-}
-
 /**
  * Display an standard html text field with an optional label
  *
@@ -728,7 +629,7 @@ function print_checkbox ($name, $value, $checked = true, $label = '', $alt = '',
  * @param string $alt     The info to be inserted in the alt tag
  * @param int $size Sets the size attribute of the field. Defaults to 50
  * @param int $maxlength Sets the maxlength attribute of the field. Not set by default
- * @param bool $return Whether this function should return a string or output 
+ * @param bool $return Whether this function should return a string or output
  *                     it (defaults to false)
  * @return string|void If $return=true returns string, else echo's and returns void
  */
@@ -1028,12 +929,12 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL
         }
     }
     return $text.$cmt;
-                
+
 }
 
 /**
  * Converts the text format from the value to the 'internal'
- * name or vice versa. 
+ * name or vice versa.
  *
  * $key can either be the value or the name and you get the other back.
  *
@@ -1078,7 +979,7 @@ function reset_text_filters_cache() {
     remove_dir($purifdir, true);
 }
 
-/** 
+/**
  * Given a simple string, this function returns the string
  * processed by enabled string filters if $CFG->filterall is enabled
  *
@@ -1160,7 +1061,7 @@ function replace_ampersands_not_followed_by_entity($string) {
 
 /**
  * Given a string, replaces all <a>.*</a> by .* and returns the string.
- * 
+ *
  * @param string $string
  * @return string
  */
@@ -1180,13 +1081,13 @@ function wikify_links($string) {
 
 /**
  * Replaces non-standard HTML entities
- * 
+ *
  * @param string $string
  * @return string
  */
 function fix_non_standard_entities($string) {
     $text = preg_replace('/(&#[0-9]+)(;?)/', '$1;', $string);
-    $text = preg_replace('/(&#x[0-9a-fA-F]+)(;?)/', '$1;', $text); 
+    $text = preg_replace('/(&#x[0-9a-fA-F]+)(;?)/', '$1;', $text);
     return $text;
 }
 
@@ -1304,8 +1205,8 @@ function trusttext_strip($text) {
  */
 function trusttext_pre_edit($object, $field, $context) {
     $trustfield  = $field.'trust';
-    $formatfield = $field.'format'; 
-    
+    $formatfield = $field.'format';
+
     if (!$object->$trustfield or !trusttext_trusted($context)) {
         $object->$field = clean_text($object->$field, $object->$formatfield);
     }
@@ -1322,7 +1223,7 @@ function trusttext_pre_edit($object, $field, $context) {
  * @return bool true if user trusted
  */
 function trusttext_trusted($context) {
-    return (trusttext_active() and has_capability('moodle/site:trustcontent', $context)); 
+    return (trusttext_active() and has_capability('moodle/site:trustcontent', $context));
 }
 
 /**
@@ -1335,7 +1236,7 @@ function trusttext_trusted($context) {
 function trusttext_active() {
     global $CFG;
 
-    return !empty($CFG->enabletrusttext); 
+    return !empty($CFG->enabletrusttext);
 }
 
 /**
@@ -2425,7 +2326,7 @@ function print_heading_with_help($text, $helppage, $module='moodle', $icon='', $
 /**
  * Print (or return) a collapisble region, that has a caption that can
  * be clicked to expand or collapse the region.
- * 
+ *
  * If JavaScript is off, then the region will always be exanded.
  *
  * @param string $contents the contents of the box.
@@ -2630,7 +2531,7 @@ function _print_custom_corners_end($idbase) {
  * @uses SITEID
  * @param object $user A {@link $USER} object representing a user
  * @param object $course A {@link $COURSE} object representing a course
- * @param bool $messageselect 
+ * @param bool $messageselect
  * @param bool $return If set to true then the HTML is returned rather than echo'd
  * @return string|void Depending on the setting of $return
  */
@@ -2821,7 +2722,7 @@ function print_group_picture($group, $courseid, $large=false, $return=false, $li
 
 /**
  * Display a recent activity note
- * 
+ *
  * @uses CONTEXT_SYSTEM
  * @staticvar string $strftimerecent
  * @param object A time object
@@ -3317,8 +3218,8 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid
  *
  * @global object
  * @param int $courseid The course ID
- * @param string $name 
- * @param string $current 
+ * @param string $name
+ * @param string $current
  * @param boolean $includenograde Include those with no grades
  * @param boolean $return If set to true returns rather than echo's
  * @return string|bool Depending on value of $return
@@ -3530,7 +3431,7 @@ function notice ($message, $link='', $course=NULL) {
  * <strong>Good practice:</strong> You should call this method before starting page
  * output by using any of the OUTPUT methods.
  *
- * @param mixed $url either a string URL, or a moodle_url to redirect to
+ * @param moodle_url $url A moodle_url to redirect to. Strings are not to be trusted!
  * @param string $message The message to display to the user
  * @param int $delay The delay before redirecting
  * @return void
@@ -3540,6 +3441,8 @@ function redirect($url, $message='', $delay=-1) {
 
     if ($url instanceof moodle_url) {
         $url = $url->out(false, array(), false);
+    } else {
+        debugging("String URLs are not safe in redirect(), please use a moodle_url object.", DEBUG_DEVELOPER);
     }
 
     if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) {
@@ -3699,7 +3602,7 @@ function rebuildnolinktag($text) {
 
 /**
  * Prints a maintenance message from $CFG->maintenance_message or default if empty
- * @return void 
+ * @return void
  */
 function print_maintenance_message() {
     global $CFG, $SITE, $PAGE;
@@ -3751,9 +3654,9 @@ class tabobject {
      */
     var $linkedwhenselected;
 
-    /** 
+    /**
      * A constructor just because I like constructors
-     * 
+     *
      * @param string $id
      * @param string $link
      * @param string $text
@@ -3883,7 +3786,7 @@ function convert_tree_to_html($tree, $row=0) {
  * @param string $selected The tabrow to select (by id)
  * @param array $inactive An array of tabrow id's to make inactive
  * @param array $activated An array of tabrow id's to make active
- * @return array The nested array 
+ * @return array The nested array
  */
 function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) {
 
@@ -4140,7 +4043,7 @@ class progress_bar {
     }
     /**
       * Create a new progress bar, this function will output html.
-      * 
+      *
       * @return void Echo's output
       */
     function create(){
index 5f1db1d42a35068aa765292eae0373f628700095..b0f9eeefcd159d658d4a232c913b88abfcd3a50c 100644 (file)
@@ -544,13 +544,13 @@ function choice_show_results($choice, $course, $cm, $allresponses, $forcepublish
                 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;';
-                $selectmenu = new moodle_select_menu();
-                $selectmenu->options = array('delete' => get_string('delete'));
-                $selectmenu->name = 'action';
-                $selectmenu->button->label = get_string('withselected', 'quiz');
-                $selectmenu->id = 'menuaction';
-                $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
-                echo $OUTPUT->select_menu($selectmenu);
+                $select = new moodle_select();
+                $select->options = array('delete' => get_string('delete'));
+                $select->name = 'action';
+                $select->button->label = get_string('withselected', 'quiz');
+                $select->id = 'menuaction';
+                $select->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
+                echo $OUTPUT->select($select);
                 echo '<noscript id="noscriptmenuaction" style="display: inline;">';
                 echo '<div>';
                 echo '<input type="submit" value="'.get_string('go').'" /></div></noscript>';
index f0c24d1d1e8a9dabfa8e3f92ea4629036c43d52d..a3e51df2bc446a3f7e7688023556da3a3d05a699 100644 (file)
         if ($courses = $DB->get_records_sql_menu($sql, $params)) {
 
              echo ' ' . get_string('filter_by_course', 'feedback') . ': ';
-             $selectmenu = new moodle_select_menu();
-             $selectmenu->options = $courses;
-             $selectmenu->name = 'coursefilter';
-             $selectmenu->selectedvalue = $coursefilter;
-             $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'analysis-form'));
-             echo $OUTPUT->select_menu($selectmenu);
+             $select = new moodle_select();
+             $select->options = $courses;
+             $select->name = 'coursefilter';
+             $select->selectedvalue = $coursefilter;
+             $select->add_action('change', 'submit_form_by_id', array('id' => 'analysis-form'));
+             echo $OUTPUT->select($select);
         }
         echo '<hr />';
         $itemnr = 0;
index dd6413ddb31f0ce69b36bb19e93a2afca6cf00bd..c9fcd06b1f5dd87c9019fb0724f9498e638d1e7f 100644 (file)
                  '<a href="javascript: checkall();">'.get_string('selectall').'</a> / '.
                  '<a href="javascript: checknone();">'.get_string('deselectall').'</a> ';
              
-            $selectmenu = new moodle_select_menu();
-            $selectmenu->options = array('delete' => get_string('deleteselected'));
-            $selectmenu->name = 'attemptaction';
-            $selectmenu->selectedvalue = 0;
-            $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'theform'));
-            echo $OUTPUT->select_menu($selectmenu); 
+            $select = new moodle_select();
+            $select->options = array('delete' => get_string('deleteselected'));
+            $select->name = 'attemptaction';
+            $select->selectedvalue = 0;
+            $select->add_action('change', 'submit_form_by_id', array('id' => 'theform'));
+            echo $OUTPUT->select($select); 
         
             echo '</td></tr></table></form>';
         }
index 5253f2da90f016befb4004ea833840da0da6454f..e4aacf556b425dcba66ae90136de75e2b7e21dba 100755 (executable)
@@ -740,12 +740,12 @@ function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') {
                 <?php print_string('organizations','scorm') ?>
                 <form id='changeorg' method='post' action='<?php echo $action ?>'>
                     <?php 
-                    $selectmenu = new moodle_select_menu();
-                    $selectmenu->options = $orgs;
-                    $selectmenu->name = 'organization';
-                    $selectmenu->selectedvalue = $organization;
-                    $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'changeorg'));
-                    echo $OUTPUT->select_menu($selectmenu); 
+                    $select = new moodle_select();
+                    $select->options = $orgs;
+                    $select->name = 'organization';
+                    $select->selectedvalue = $organization;
+                    $select->add_action('change', 'submit_form_by_id', array('id' => 'changeorg'));
+                    echo $OUTPUT->select($select); 
                     ?>
                 </form>
             </div>
index a03a715035800e720bcda57f10a2d8e7d4e41d8f..a4d2f8ffb6b97198eee1173fdee3a7cf77f210f3 100755 (executable)
                     echo '<a href="javascript:select_all_in(\'DIV\',null,\'scormtablecontainer\');">'.get_string('selectall', 'quiz').'</a> / ';
                     echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'scormtablecontainer\');">'.get_string('selectnone', 'quiz').'</a> ';
                     echo '&nbsp;&nbsp;';
-                    $selectmenu = new moodle_select_menu();
-                    $selectmenu->options = array('delete' => get_string('delete'));
-                    $selectmenu->name = 'action';
-                    $selectmenu->button->label = get_string('withselected', 'quiz');
-                    $selectmenu->id = 'menuaction';
-                    $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
-                    echo $OUTPUT->select_menu($selectmenu);
+                    $select = new moodle_select();
+                    $select->options = array('delete' => get_string('delete'));
+                    $select->name = 'action';
+                    $select->button->label = get_string('withselected', 'quiz');
+                    $select->id = 'menuaction';
+                    $select->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
+                    echo $OUTPUT->select($select);
                     echo '<noscript id="noscriptmenuaction" style="display: inline;">';
                     echo '<div>';
                     echo '<input type="submit" value="'.get_string('go').'" /></div></noscript>';
index 73cead33b7cad331462ea842d74060eeff337b13..e6e23b1b364f22cb27aa85b43064c74e40b1774c 100644 (file)
         while(list($key,$val)=each($wiki_list)) {
           $wiki_admin_list[$key."&amp;action=$action"]=$val;
         }
-        $selectmenu = new moodle_select_menu();
-        $selectmenu->options = $wiki_admin_list;
-        $selectmenu->name = 'wikiselect';
-        $selectmenu->selectedvalue = $selected;
-        $selectmenu->add_action('change', 'go_to_wiki');
-        echo $OUTPUT->select_menu($selectmenu);
+        $select = new moodle_select();
+        $select->options = $wiki_admin_list;
+        $select->name = 'wikiselect';
+        $select->selectedvalue = $selected;
+        $select->add_action('change', 'go_to_wiki');
+        echo $OUTPUT->select($select);
         echo '</td>';
         echo '</tr></table>';
         echo '</fieldset></form>';
index 785ea9c19635f2e3a3838f92dc2c220190cd0e7e..e37149cf32f6ad3705169c1073e0dce11aa5d939 100644 (file)
 
         echo '<td class="sideblockheading">'
             .get_string('otherwikis', 'wiki').':&nbsp;&nbsp;';
-        $selectmenu = new moodle_select_menu();
-        $selectmenu->options = $wiki_list;
-        $selectmenu->name = 'wikiselect';
-        $selectmenu->selectedvalue = $selected;
-        $selectmenu->add_action('change', 'go_to_wiki');
-        echo $OUTPUT->select_menu($selectmenu);
+        $select = new moodle_select();
+        $select->options = $wiki_list;
+        $select->name = 'wikiselect';
+        $select->selectedvalue = $selected;
+        $select->add_action('change', 'go_to_wiki');
+        echo $OUTPUT->select($select);
         echo '</td>';
         echo '</tr></table>';
         echo '</form>';
index 9d0fd4eb5a3eaacb48bbdce46b6cd46864f24666..cd3c2906530d940509019a177f64c4cafea66723 100644 (file)
         }
 
         helpbutton("participantswithselectedusers", get_string("withselectedusers"));
-        $selectmenu = new moodle_select_menu();
-        $selectmenu->options = $displaylist;
-        $selectmenu->name = "formaction";
-        $selectmenu->label = get_string("withselectedusers");
-        $selectmenu->add_action('change', 'conditionalsubmit', array('formid' => 'participantsform'));
-        echo $OUTPUT->select_menu($selectmenu);
+        $select = new moodle_select();
+        $select->options = $displaylist;
+        $select->name = "formaction";
+        $select->label = get_string("withselectedusers");
+        $select->add_action('change', 'conditionalsubmit', array('formid' => 'participantsform'));
+        echo $OUTPUT->select($select);
         echo '<input type="hidden" name="id" value="'.$course->id.'" />';
         echo '<div id="noscriptparticipantsform" style="display: inline;">';
         echo '<input type="submit" value="'.get_string('ok').'" /></div>';