/**
* This was used by old code to print the blocks in a region.
- *
+ *
* We don't ever want old code to print blocks, so this is now a no-op.
* The function only exists to avoid fatal errors in old code.
*
// Parse the $options string
$popupparams = array();
- if (!empty($options)) {
+ if (!empty($options)) {
$optionsarray = explode(',', $options);
foreach ($optionsarray as $option) {
if (strstr($option, '=')) {
if ($return) {
return $output;
} else {
- echo $output;
+ echo $output;
}
}
// Parse the $options string
$popupparams = array();
- if (!empty($options)) {
+ if (!empty($options)) {
$optionsarray = explode(',', $options);
foreach ($optionsarray as $option) {
if (strstr($option, '=')) {
if ($return) {
return $output;
} else {
- echo $output;
+ echo $output;
}
}
$formcancel->url = new moodle_url($linkno, $optionsno);
$formcancel->button->label = get_string('no');
$formcancel->method = $methodno;
-
+
echo $OUTPUT->confirm($message, $formcontinue, $formcancel);
}
function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
$nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
$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).');
+
+ 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->multiple = $multiple;
$selectmenu->add_classes($class);
- if (!empty($script)) {
- $onchange = new component_action('change', $script);
- $selectmenu->add_action($onchange);
+ if ($nothing == 'choose') {
+ $selectmenu->nothinglabel = '';
+ }
+
+ $output = $OUTPUT->select_menu($selectmenu);
+
+ if ($return) {
+ return $output;
+ } else {
+ echo $output;
}
+}
+
+/**
+ * Choose value 0 or 1 from a menu with options 'No' and 'Yes'.
+ * Other options like choose_from_menu.
+ *
+ * @deprecated since Moodle 2.0
+ *
+ * Calls {@link choose_from_menu()} with preset arguments
+ * @see choose_from_menu()
+ *
+ * @param string $name the name of this form control, as in <select name="..." ...
+ * @param string $selected the option to select initially, default none.
+ * @param string $script if not '', then this is added to the <select> element as an onchange handler.
+ * @param boolean $return Whether this function should return a string or output it (defaults to false)
+ * @param boolean $disabled (defaults to false)
+ * @param int $tabindex
+ * @return string|void If $return=true returns string, else echo's and returns void
+ */
+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).');
+ 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);
+
+ if ($return) {
+ return $output;
+ } else {
+ echo $output;
+ }
+}
+
+/**
+ * Just like choose_from_menu, but takes a nested array (2 levels) and makes a dropdown menu
+ * including option headings with the first level.
+ *
+ * @deprecated since Moodle 2.0
+ *
+ * This function is very similar to {@link choose_from_menu_yesno()}
+ * and {@link choose_from_menu()}
+ *
+ * @todo Add datatype handling to make sure $options is an array
+ *
+ * @param array $options An array of objects to choose from
+ * @param string $name The XHTML field name
+ * @param string $selected The value to select by default
+ * @param string $nothing The label for the 'nothing is selected' option.
+ * Defaults to get_string('choose').
+ * @param string $script If not '', then this is added to the <select> element
+ * as an onchange handler.
+ * @param string $nothingvalue The value for the first `nothing` option if $nothing is set
+ * @param bool $return Whether this function should return a string or output
+ * it (defaults to false)
+ * @param bool $disabled Is the field disabled by default
+ * @param int|string $tabindex Override the tabindex attribute [numeric]
+ * @return string|void If $return=true returns string, else echo's and returns void
+ */
+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).');
+ 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;
if ($nothing == 'choose') {
$selectmenu->nothinglabel = '';
}
-
+
$output = $OUTPUT->select_menu($selectmenu);
-
+
if ($return) {
return $output;
} else {
echo $output;
}
}
+
}
$html .= $this->output_start_tag('select', $attributes) . "\n";
- foreach ($selectmenu->options as $value => $label) {
- $attributes = array('value' => $value);
- if ((string) $value == (string) $selectmenu->selectedvalue ||
- (is_array($selectmenu->selectedvalue) && in_array($value, $selectmenu->selectedvalue))) {
- $attributes['selected'] = 'selected';
+
+ if ($selectmenu->nested) {
+ foreach ($selectmenu->options as $section => $values) {
+ $html .= $this->output_start_tag('optgroup', array('label' => $section));
+ if (!is_array($values)) {
+ var_dump($values);
+ }
+ foreach ($values as $value => $label) {
+ $attributes = array('value' => $value);
+
+ if ((string) $value == (string) $selectmenu->selectedvalue ||
+ (is_array($selectmenu->selectedvalue) && in_array($value, $selectmenu->selectedvalue))) {
+ $attributes['selected'] = 'selected';
+ }
+
+ $html .= $this->output_start_tag('option', $attributes);
+
+ if ($label === '') {
+ $html .= $value;
+ } else {
+ $html .= $label;
+ }
+
+ $html .= $this->output_end_tag('option');
+ }
+ $html .= $this->output_end_tag('optgroup');
+ }
+ } else {
+ foreach ($selectmenu->options as $value => $label) {
+ $attributes = array('value' => $value);
+ if ((string) $value == (string) $selectmenu->selectedvalue ||
+ (is_array($selectmenu->selectedvalue) && in_array($value, $selectmenu->selectedvalue))) {
+ $attributes['selected'] = 'selected';
+ }
+ $html .= ' ' . $this->output_tag('option', $attributes, s($label)) . "\n";
}
- $html .= ' ' . $this->output_tag('option', $attributes, s($label)) . "\n";
}
$html .= $this->output_end_tag('select') . "\n";
}
/**
- * Print a continue button that goes to a particular URL.
+ * Prints a single paging bar to provide access to other pages (usually in a search)
*
* @param string|moodle_url $link The url the button goes to.
* @return string the HTML to output.
* @var boolean if true, allow multiple selection. Only used if $listbox is true.
*/
public $multiple = false;
+ /**
+ * @var boolean $nested if true, uses $options' keys as option headings (optgroup)
+ */
+ public $nested = false;
/**
* @see moodle_html_component::prepare()
if (is_null($this->nothinglabel)) {
$this->nothinglabel = get_string('choosedots');
}
+
+ // If nested is on, remove the default Choose option
+ if ($this->nested) {
+ $this->nothinglabel = '';
+ }
+
$this->add_class('select');
+
parent::prepare();
}
exit;
}
-/**
- * Choose value 0 or 1 from a menu with options 'No' and 'Yes'.
- * Other options like choose_from_menu.
- *
- * Calls {@link choose_from_menu()} with preset arguments
- * @see choose_from_menu()
- *
- * @param string $name the name of this form control, as in <select name="..." ...
- * @param string $selected the option to select initially, default none.
- * @param string $script if not '', then this is added to the <select> element as an onchange handler.
- * @param boolean $return Whether this function should return a string or output it (defaults to false)
- * @param boolean $disabled (defaults to false)
- * @param int $tabindex
- * @return string|void If $return=true returns string, else echo's and returns void
- */
-function choose_from_menu_yesno($name, $selected, $script = '',
- $return = false, $disabled = false, $tabindex = 0) {
- return choose_from_menu(array(get_string('no'), get_string('yes')), $name,
- $selected, '', $script, '0', $return, $disabled, $tabindex);
-}
-
-/**
- * Just like choose_from_menu, but takes a nested array (2 levels) and makes a dropdown menu
- * including option headings with the first level.
- *
- * This function is very similar to {@link choose_from_menu_yesno()}
- * and {@link choose_from_menu()}
- *
- * @todo Add datatype handling to make sure $options is an array
- *
- * @param array $options An array of objects to choose from
- * @param string $name The XHTML field name
- * @param string $selected The value to select by default
- * @param string $nothing The label for the 'nothing is selected' option.
- * Defaults to get_string('choose').
- * @param string $script If not '', then this is added to the <select> element
- * as an onchange handler.
- * @param string $nothingvalue The value for the first `nothing` option if $nothing is set
- * @param bool $return Whether this function should return a string or output
- * it (defaults to false)
- * @param bool $disabled Is the field disabled by default
- * @param int|string $tabindex Override the tabindex attribute [numeric]
- * @return string|void If $return=true returns string, else echo's and returns void
- */
-function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
- $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
-
- if ($nothing == 'choose') {
- $nothing = get_string('choose') .'...';
- }
-
- $attributes = ($script) ? 'onchange="'. $script .'"' : '';
- if ($disabled) {
- $attributes .= ' disabled="disabled"';
- }
-
- if ($tabindex) {
- $attributes .= ' tabindex="'.$tabindex.'"';
- }
-
- $output = '<select id="menu'.$name.'" name="'. $name .'" '. $attributes .'>' . "\n";
- if ($nothing) {
- $output .= ' <option value="'. $nothingvalue .'"'. "\n";
- if ($nothingvalue === $selected) {
- $output .= ' selected="selected"';
- }
- $output .= '>'. $nothing .'</option>' . "\n";
- }
- if (!empty($options)) {
- foreach ($options as $section => $values) {
-
- $output .= ' <optgroup label="'. s(format_string($section)) .'">'."\n";
- foreach ($values as $value => $label) {
- $output .= ' <option value="'. format_string($value) .'"';
- if ((string)$value == (string)$selected) {
- $output .= ' selected="selected"';
- }
- if ($label === '') {
- $output .= '>'. $value .'</option>' . "\n";
- } else {
- $output .= '>'. $label .'</option>' . "\n";
- }
- }
- $output .= ' </optgroup>'."\n";
- }
- }
- $output .= '</select>' . "\n";
-
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
-}
-
/**
* Given an array of values, creates a group of radio buttons to be part of a form