mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 07:25:30 +02:00
MDL-7909 add optional id parameter to choose_from_menu() and print_textarea() + minor quoting improvement in choose_from_menu()
This commit is contained in:
parent
9706fa5684
commit
7850588ab8
@ -43,7 +43,7 @@ class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
|
||||
function toHtml(){
|
||||
if ($this->_options['canUseHtmlEditor'] && !$this->_flagFrozen){
|
||||
ob_start();
|
||||
use_html_editor($this->getName());
|
||||
use_html_editor($this->getName(), '', $this->getAttribute('id'));
|
||||
$script=ob_get_clean();
|
||||
} else {
|
||||
$script='';
|
||||
@ -60,7 +60,8 @@ class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
|
||||
$this->getName(),
|
||||
preg_replace("/(\r\n|\n|\r)/", '
',$this->getValue()),
|
||||
$this->_options['course'],
|
||||
true).$script;
|
||||
true,
|
||||
$this->getAttribute('id')).$script;
|
||||
}
|
||||
} //end func toHtml
|
||||
|
||||
|
@ -666,7 +666,7 @@ function close_window($delay=0) {
|
||||
* @todo Finish documenting this function
|
||||
*/
|
||||
function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
|
||||
$nothingvalue='0', $return=false, $disabled=false, $tabindex=0) {
|
||||
$nothingvalue='0', $return=false, $disabled=false, $tabindex=0, $id='') {
|
||||
|
||||
if ($nothing == 'choose') {
|
||||
$nothing = get_string('choose') .'...';
|
||||
@ -681,10 +681,13 @@ function choose_from_menu ($options, $name, $selected='', $nothing='choose', $sc
|
||||
$attributes .= ' tabindex="'.$tabindex.'"';
|
||||
}
|
||||
|
||||
$id = str_replace('[]', '', $name); // name may end in [], which would make an invalid id. e.g. numeric question type editing form.
|
||||
$output = '<select id="menu'.$id.'" name="'. $name .'" '. $attributes .'>' . "\n";
|
||||
if ($id ==='') {
|
||||
$id = 'menu'.str_replace('[]', '', $name); // name may end in [], which would make an invalid id. e.g. numeric question type editing form.
|
||||
}
|
||||
|
||||
$output = '<select id="'.$id.'" name="'. $name .'" '. $attributes .'>' . "\n";
|
||||
if ($nothing) {
|
||||
$output .= ' <option value="'. $nothingvalue .'"'. "\n";
|
||||
$output .= ' <option value="'. s($nothingvalue) .'"'. "\n";
|
||||
if ($nothingvalue === $selected) {
|
||||
$output .= ' selected="selected"';
|
||||
}
|
||||
@ -692,7 +695,7 @@ function choose_from_menu ($options, $name, $selected='', $nothing='choose', $sc
|
||||
}
|
||||
if (!empty($options)) {
|
||||
foreach ($options as $value => $label) {
|
||||
$output .= ' <option value="'. $value .'"';
|
||||
$output .= ' <option value="'. s($value) .'"';
|
||||
if ((string)$value == (string)$selected) {
|
||||
$output .= ' selected="selected"';
|
||||
}
|
||||
@ -3595,7 +3598,7 @@ function print_recent_activity_note($time, $user, $text, $link, $return=false) {
|
||||
* @param int $courseid ?
|
||||
* @todo Finish documenting this function
|
||||
*/
|
||||
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $courseid=0, $return=false) {
|
||||
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $courseid=0, $return=false, $id='') {
|
||||
/// $width and height are legacy fields and no longer used as pixels like they used to be.
|
||||
/// However, you can set them to zero to override the mincols and minrows values below.
|
||||
|
||||
@ -3606,6 +3609,10 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v
|
||||
$minrows = 10;
|
||||
$str = '';
|
||||
|
||||
if ($id === '') {
|
||||
$id = 'edit-'.$name;
|
||||
}
|
||||
|
||||
if ( empty($CFG->editorsrc) ) { // for backward compatibility.
|
||||
if (empty($courseid)) {
|
||||
if (!empty($course->id)) { // search for it in global context
|
||||
@ -3642,7 +3649,7 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v
|
||||
}
|
||||
}
|
||||
}
|
||||
$str .= '<textarea class="form=textarea" id="id_'. $name .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">';
|
||||
$str .= '<textarea class="form=textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">';
|
||||
if ($usehtmleditor) {
|
||||
$str .= htmlspecialchars($value); // needed for editing of cleaned text!
|
||||
} else {
|
||||
@ -3682,10 +3689,13 @@ function print_richedit_javascript($form, $name, $source='no') {
|
||||
*
|
||||
* @param string $name Form element to replace with HTMl editor by name
|
||||
*/
|
||||
function use_html_editor($name='', $editorhidebuttons='') {
|
||||
function use_html_editor($name='', $editorhidebuttons='', $id='') {
|
||||
$editor = 'editor_'.md5($name); //name might contain illegal characters
|
||||
if ($id === '') {
|
||||
$id = 'edit-'.$name;
|
||||
}
|
||||
echo '<script language="javascript" type="text/javascript" defer="defer">'."\n";
|
||||
echo "$editor = new HTMLArea('id_$name');\n";
|
||||
echo "$editor = new HTMLArea('$id');\n";
|
||||
echo "var config = $editor.config;\n";
|
||||
|
||||
echo print_editor_config($editorhidebuttons);
|
||||
|
@ -110,7 +110,7 @@
|
||||
echo '</center>';
|
||||
|
||||
echo "\n<script type=\"text/javascript\">\n<!--\n"; /// Focus on the textarea
|
||||
echo 'document.getElementById("id_message").focus();'."\n";
|
||||
echo 'document.getElementById("edit-message").focus();'."\n";
|
||||
echo "\n-->\n</script>\n\n";
|
||||
|
||||
echo '</body></html>';
|
||||
|
@ -161,7 +161,7 @@
|
||||
switch ($page->qtype) {
|
||||
case LESSON_MATCHING:
|
||||
if ($n == 0) {
|
||||
echo "<tr><td><b><label for=\"id_answer[$n]\">".get_string('correctresponse', 'lesson').":</label></b>\n";
|
||||
echo "<tr><td><b><label for=\"edit-answer[$n]\">".get_string('correctresponse', 'lesson').":</label></b>\n";
|
||||
if ($flags & LESSON_ANSWER_EDITOR) {
|
||||
echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
|
||||
"<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" checked=\"checked\" />";
|
||||
@ -177,7 +177,7 @@
|
||||
print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer);
|
||||
}
|
||||
} elseif ($n == 1) {
|
||||
echo "<tr><td><b><label for=\"id_answer[$n]\">".get_string('wrongresponse', 'lesson').":</label></b>\n";
|
||||
echo "<tr><td><b><label for=\"edit-answer[$n]\">".get_string('wrongresponse', 'lesson').":</label></b>\n";
|
||||
if ($flags & LESSON_ANSWER_EDITOR) {
|
||||
echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
|
||||
"<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" checked=\"checked\" />";
|
||||
@ -194,7 +194,7 @@
|
||||
}
|
||||
} else {
|
||||
$ncorrected = $n - 1;
|
||||
echo "<tr><td><b><label for=\"id_answer[$n]\">".get_string('answer', 'lesson')." $ncorrected:</label></b>\n";
|
||||
echo "<tr><td><b><label for=\"edit-answer[$n]\">".get_string('answer', 'lesson')." $ncorrected:</label></b>\n";
|
||||
if ($flags & LESSON_ANSWER_EDITOR) {
|
||||
echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
|
||||
"<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" checked=\"checked\" />";
|
||||
@ -210,7 +210,7 @@
|
||||
print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer);
|
||||
}
|
||||
echo "</td></tr>\n";
|
||||
echo "<tr><td><b><label for=\"id_response[$n]\">".get_string('matchesanswer', 'lesson')." $ncorrected:</label></b>\n";
|
||||
echo "<tr><td><b><label for=\"edit-response[$n]\">".get_string('matchesanswer', 'lesson')." $ncorrected:</label></b>\n";
|
||||
if ($flags & LESSON_RESPONSE_EDITOR) {
|
||||
echo " [<label for=\"responseeditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
|
||||
"<input type=\"checkbox\" id=\"responseeditor[$n]\" name=\"responseeditor[$n]\" value=\"1\" checked=\"checked\" />";
|
||||
@ -232,7 +232,7 @@
|
||||
case LESSON_MULTICHOICE:
|
||||
case LESSON_SHORTANSWER:
|
||||
case LESSON_NUMERICAL:
|
||||
echo "<tr><td><b><label for=\"id_answer[$n]\">".get_string('answer', 'lesson')." $nplus1:</label></b>\n";
|
||||
echo "<tr><td><b><label for=\"edit-answer[$n]\">".get_string('answer', 'lesson')." $nplus1:</label></b>\n";
|
||||
if ($flags & LESSON_ANSWER_EDITOR and $page->qtype != LESSON_SHORTANSWER and $page->qtype != LESSON_NUMERICAL) {
|
||||
echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
|
||||
"<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" checked=\"checked\" />";
|
||||
@ -253,7 +253,7 @@
|
||||
}
|
||||
}
|
||||
echo "</td></tr>\n";
|
||||
echo "<tr><td><b><label for=\"id_response[$n]\">".get_string('response', 'lesson')." $nplus1:</label></b>\n";
|
||||
echo "<tr><td><b><label for=\"edit-response[$n]\">".get_string('response', 'lesson')." $nplus1:</label></b>\n";
|
||||
if ($flags & LESSON_RESPONSE_EDITOR) {
|
||||
echo " [<label for=\"responseeditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
|
||||
"<input type=\"checkbox\" id=\"responseeditor[$n]\" name=\"responseeditor[$n]\" value=\"1\" checked=\"checked\" />";
|
||||
@ -271,7 +271,7 @@
|
||||
echo "</td></tr>\n";
|
||||
break;
|
||||
case LESSON_BRANCHTABLE:
|
||||
echo "<tr><td><b><label for=\"id_answer[$n]\">".get_string("description", "lesson")." $nplus1:</label></b>\n";
|
||||
echo "<tr><td><b><label for=\"edit-answer[$n]\">".get_string("description", "lesson")." $nplus1:</label></b>\n";
|
||||
if ($flags & LESSON_ANSWER_EDITOR) {
|
||||
echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
|
||||
"<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" checked=\"checked\" />";
|
||||
|
Loading…
x
Reference in New Issue
Block a user