diff --git a/admin/report/capability/index.php b/admin/report/capability/index.php index 41220d2ca22..42d88afa2e5 100644 --- a/admin/report/capability/index.php +++ b/admin/report/capability/index.php @@ -70,24 +70,15 @@ if (count($cleanedroleids) == count($allroles)) { // Print the settings form. echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter centerpara'); -echo '
'; +echo '
'; echo $OUTPUT->heading(get_string('reportsettings', 'report_capability')); echo '

', get_string('intro', 'report_capability') , '

'; echo '

'; -$select = html_select::make($capabilitychoices, 'capability', $capability); -$select->nothingvalue = ''; -$select->listbox = true; -$select->tabindex = 0; -echo $OUTPUT->select($select); +echo html_writer::input_select($capabilitychoices, 'capability', $capability, array(''=>'choose'), array('size'=>10)); echo '

'; -$select = html_select::make($rolechoices, 'roles[]', $selectedroleids, false); -$select->nothingvalue = ''; -$select->listbox = true; -$select->multiple = true; -$select->tabindex = 0; -echo $OUTPUT->select($select); +echo html_writer::input_select($rolechoices, 'roles[]', $selectedroleids, false, array('size'=>10, 'multiple'=>'multiple')); echo '

'; -echo ''; +echo '
'; echo $OUTPUT->box_end(); // If we have a capability, generate the report. diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 53aa48b858d..8593eabb62d 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -428,6 +428,65 @@ class html_writer { $attributes['href'] = $url; return self::tag('a', $attributes, $text); } + + /** + * Generates a simple select form field + * @param array $options associative array value=>label + * @param string $name name of select element + * @param string|array $selected value or arary of values depending on multiple attribute + * @param array|bool $nothing, add nothing selected option, or false of not added + * @param array $attributes - html select element attributes + * @return string HRML fragment + */ + public static function input_select(array $options, $name, $selected = '', $nothing = array(''=>'choose'), array $attributes = null) { + $attributes = (array)$attributes; + if (is_array($nothing)) { + foreach ($nothing as $k=>$v) { + if ($v === 'choose') { + $nothing[$k] = get_string('choosedots'); + } + } + $options = $nothing + $options; // keep keys, do not override + } + + // we may accept more values if multiple attribute specified + $selected = (array)$selected; + foreach ($selected as $k=>$v) { + $selected[$k] = (string)$v; + } + + if (!isset($attributes['id'])) { + $id = 'menu'.$name; + // name may contaion [], which would make an invalid id. e.g. numeric question type editing form, assignment quickgrading + $id = str_replace('[', '', $id); + $id = str_replace(']', '', $id); + $attributes['id'] = $id; + } + + if (!isset($attributes['class'])) { + $class = 'menu'.$name; + // name may contaion [], which would make an invalid class. e.g. numeric question type editing form, assignment quickgrading + $class = str_replace('[', '', $class); + $class = str_replace(']', '', $class); + $attributes['class'] = $class; + } + $attributes['class'] = 'select ' . $attributes['class']; /// Add 'select' selector always + + $attributes['name'] = $name; + + $output = ''; + foreach ($options as $value=>$label) { + $ias = array(); + $value = (string)$value; //TODO: add support for opt groups as nested arrays + if (in_array($value, $selected, true)) { + $ias['selected'] = 'selected'; + } + $ias['value'] = $value; + $output .= self::tag('option', $ias, $label); + } + + return self::tag('select', $attributes, $output); + } } diff --git a/mod/glossary/formats.php b/mod/glossary/formats.php index 538deb5f589..5f101609c55 100644 --- a/mod/glossary/formats.php +++ b/mod/glossary/formats.php @@ -84,7 +84,7 @@ echo ''; //Sort it asort($formats); - echo $OUTPUT->select(html_select::make($formats,'popupformatname',$displayformat->popupformatname)); + echo html_writer::input_select($formats, 'popupformatname', $displayformat->popupformatname, false); ?>
diff --git a/tag/manage.php b/tag/manage.php index 526926c6b11..678d067750e 100644 --- a/tag/manage.php +++ b/tag/manage.php @@ -235,7 +235,7 @@ if ($tagrecords = $DB->get_records_sql($query, $params, $table->get_page_start() $timemodified = format_time(time() - $tag->timemodified); $checkbox = ''; $text = ''; - $tagtype = $OUTPUT->select(html_select::make($existing_tagtypes, 'tagtypes['.$tag->id.']', $tag->tagtype, false)); + $tagtype = html_writer::input_select($existing_tagtypes, 'tagtypes['.$tag->id.']', $tag->tagtype, false); //if the tag if flagged, highlight it if ($tag->flag > 0) { diff --git a/user/addnote.php b/user/addnote.php index d8510d50132..22bed79c0ee 100644 --- a/user/addnote.php +++ b/user/addnote.php @@ -31,17 +31,7 @@ $users = optional_param('userid', array(), PARAM_INT); // array of user id $contents = optional_param('contents', array(), PARAM_RAW); // array of user notes $states = optional_param('states', array(), PARAM_ALPHA); // array of notes states -$url = new moodle_url('/user/addnote.php', array('id'=>$id)); -if ($users !== 0) { - $url->param('userid', $users); -} -if ($contents !== 0) { - $url->param('contents', $contents); -} -if ($states !== 0) { - $url->param('states', $states); -} -$PAGE->set_url($url); +$PAGE->set_url('/user/addnote.php', array('id'=>$id)); if (! $course = $DB->get_record('course', array('id'=>$id))) { print_error('invalidcourseid'); @@ -119,7 +109,7 @@ foreach ($users as $k => $v) { if(!$user = $DB->get_record('user', array('id'=>$v))) { continue; } - $checkbox = $OUTPUT->select(html_select::make($state_names, 'states[' . $k . ']', empty($states[$k]) ? NOTES_STATE_PUBLIC : $states[$k], false)); + $checkbox = html_writer::input_select($state_names, 'states[' . $k . ']', empty($states[$k]) ? NOTES_STATE_PUBLIC : $states[$k], false); $table->data[] = array( ''. fullname($user, true), '', diff --git a/user/extendenrol.php b/user/extendenrol.php index 408f6da3aea..2cb66aa5b1a 100644 --- a/user/extendenrol.php +++ b/user/extendenrol.php @@ -171,8 +171,8 @@ foreach ($_POST as $k => $v) { unset($userbasemenu[2]); } - $checkbox = $OUTPUT->select(html_select::make($periodmenu, "extendperiod[{$m[1]}]", "0", $nochange)); - $checkbox2 = $OUTPUT->select(html_select::make($userbasemenu, "extendbase[{$m[1]}]", "2", false)); + $checkbox = html_writer::input_select($periodmenu, "extendperiod[{$m[1]}]", "0", array('0'=>$nochange)); + $checkbox2 = html_writer::input_select($userbasemenu, "extendbase[{$m[1]}]", "2", false); $table->data[] = array( fullname($user, true), $timestart, diff --git a/user/groupaddnote.php b/user/groupaddnote.php index d89f7360c91..5881f988c01 100644 --- a/user/groupaddnote.php +++ b/user/groupaddnote.php @@ -121,7 +121,7 @@ echo '