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='';
$this->getName(),
preg_replace("/(\r\n|\n|\r)/", '
',$this->getValue()),
$this->_options['course'],
- true).$script;
+ true,
+ $this->getAttribute('id')).$script;
}
} //end func toHtml
* @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') .'...';
$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"';
}
}
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"';
}
* @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.
$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
}
}
}
- $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 {
*
* @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);
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>';
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\" />";
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\" />";
}
} 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\" />";
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\" />";
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\" />";
}
}
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\" />";
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\" />";