]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-7909 add optional id parameter to choose_from_menu() and print_textarea() + minor...
authorskodak <skodak>
Tue, 12 Dec 2006 22:06:37 +0000 (22:06 +0000)
committerskodak <skodak>
Tue, 12 Dec 2006 22:06:37 +0000 (22:06 +0000)
lib/form/htmleditor.php
lib/weblib.php
message/send.php
mod/lesson/action/editpage.php

index 442dbc619fcfb86c9674e0353966f17ae97667fc..5d5e2f7f4c5383ab692f1312bcf4a34bdf34e1b5 100644 (file)
@@ -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)/", '&#010;',$this->getValue()),
                                     $this->_options['course'],
-                                    true).$script;
+                                    true,
+                                    $this->getAttribute('id')).$script;
         }
     } //end func toHtml
 
index 89573236a41ca4384bba81b50b5c4b5edd9d0be3..64b9e8c954e573e7af3820002120eb9c435a0f12 100644 (file)
@@ -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);
index 24e262837798b4d6f5772315bb617a011078ee69..152555bed8aaf015d8de3df9b17c1c951a37b022 100644 (file)
     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>';
index fdd8f33998434575abf38db5962e6b23683c0ee6..ae2e7870d8ed6e95c3827064de4be632780b1d05 100644 (file)
             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\" />";