]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19756 Migrated popup_form
authornicolasconnault <nicolasconnault>
Thu, 30 Jul 2009 03:47:12 +0000 (03:47 +0000)
committernicolasconnault <nicolasconnault>
Thu, 30 Jul 2009 03:47:12 +0000 (03:47 +0000)
lib/deprecatedlib.php
lib/javascript-static.js
lib/outputlib.php
lib/simpletest/testoutputlib.php
lib/weblib.php

index 28a28e8be2fd55f708a1807f90f8b0d85fb234f1..5783d6dce9a839ec39a5a4e3a193c55e13a1597f 100644 (file)
@@ -2625,11 +2625,13 @@ function print_single_button($link, $options, $label='OK', $method='get', $notus
     $form->id = $formid;
 
     if ($jsconfirmmessage) {
-        $confirmaction = new component_action('click', 'confirm_dialog', array($jsconfirmmessage));
+        $confirmaction = new component_action('click', 'confirm_dialog', array('message' => $jsconfirmmessage));
         $form->button->add_action($confirmaction);
     }
 
     $output = $OUTPUT->button($form);
+    
+    $icon = new action_icon();
 
     if ($return) {
         return $output;
@@ -2843,8 +2845,8 @@ function helpbutton($page, $title, $module='moodle', $image=true, $linktext=fals
 
     $helpicon = new help_icon();
     $helpicon->page = $page;
-    $helpicon->module = $module;
     $helpicon->text = $title;
+    $helpicon->module = $module;
     $helpicon->linktext = $linktext;
 
     // If image is true, the defaults are handled by the helpicon's prepare method
@@ -3252,16 +3254,16 @@ function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $
  * @param int $currenttime A default timestamp in GMT
  * @param int $step minute spacing
  * @param boolean $return If set to true returns rather than echo's
- * @return string|bool Depending on value of $return 
+ * @return string|bool Depending on value of $return
  */
 function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
     // debugging('print_time_selector() has been deprecated. Please change your code to use $OUTPUT->select_menu($timeselector).');
-    global $OUTPUT;    
+    global $OUTPUT;
     $hourselector = moodle_select_menu::make_time_selector('hours', $hour, $currenttime);
     $minuteselector = moodle_select_menu::make_time_selector('minutes', $minute, $currenttime, $step);
-    
+
     $output = $OUTPUT->select_menu($hourselector) . $OUTPUT->select_menu($minuteselector);
-    
+
     if ($return) {
         return $output;
     } else {
@@ -3284,14 +3286,94 @@ function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=fa
 function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
 
     // debugging('print_date_selector() has been deprecated. Please change your code to use $OUTPUT->select_menu($dateselector).');
-    global $OUTPUT;    
-    
+    global $OUTPUT;
+
     $dayselector = moodle_select_menu::make_time_selector('days', $day, $currenttime);
     $monthselector = moodle_select_menu::make_time_selector('months', $month, $currenttime);
     $yearselector = moodle_select_menu::make_time_selector('years', $year, $currenttime);
-    
+
     $output = $OUTPUT->select_menu($dayselector) . $OUTPUT->select_menu($monthselector) . $OUTPUT->select_menu($yearselector);
+
+    if ($return) {
+        return $output;
+    } else {
+        echo $output;
+    }
+}
+
+/**
+ * Implements a complete little form with a dropdown menu.
+ *
+ * @deprecated since Moodle 2.0
+ *
+ * When JavaScript is on selecting an option from the dropdown automatically
+ * submits the form (while avoiding the usual acessibility problems with this appoach).
+ * With JavaScript off, a 'Go' button is printed.
+ *
+ * @todo Finish documenting this function
+ *
+ * @global object
+ * @global object
+ * @param string $baseurl The target URL up to the point of the variable that changes
+ * @param array $options A list of value-label pairs for the popup list
+ * @param string $formid id for the control. Must be unique on the page. Used in the HTML.
+ * @param string $selected The option that is initially selected
+ * @param string $nothing The label for the "no choice" option
+ * @param string $help The name of a help page if help is required
+ * @param string $helptext The name of the label for the help button
+ * @param boolean $return Indicates whether the function should return the HTML
+ *         as a string or echo it directly to the page being rendered
+ * @param string $targetwindow The name of the target page to open the linked page in.
+ * @param string $selectlabel Text to place in a [label] element - preferred for accessibility.
+ * @param array $optionsextra an array with the same keys as $options. The values are added within the corresponding <option ...> tag.
+ * @param string $submitvalue Optional label for the 'Go' button. Defaults to get_string('go').
+ * @param boolean $disabled If true, the menu will be displayed disabled.
+ * @param boolean $showbutton If true, the button will always be shown even if JavaScript is available
+ * @return string|void If $return=true returns string, else echo's and returns void
+ */
+function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
+    $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
+    global $OUTPUT;
+
+    // debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->select_menu($dateselector).');
+
+    if (!empty($optionsextra)) {
+        debugging('the optionsextra param has been deprecated in popup_form, it will be ignored.', DEBUG_DEVELOPER);
+    }
+
+    if (empty($options)) {
+        return '';
+    }
+    $selectmenu = moodle_select_menu::make_popup_form($baseurl, $options, $formid, $submitvalue, $selected);
+    $selectmenu->disabled = $disabled;
     
+    // Extract the last param of the baseurl for the name of the select
+    if (preg_match('/([a-z_]*)=$/', $baseurl, $matches)) {
+        $selectmenu->name = $matches[1];
+        $selectmenu->form->url->remove_params(array($matches[1]));
+    }
+
+    if ($nothing == 'choose') {
+        $selectmenu->nothinglabel = '';
+    } else {
+        $selectmenu->nothinglabel = $nothing;
+    }
+
+    if ($selectlabel) {
+        $selectmenu->label = new html_label();
+        $selectmenu->label->text = $selectlabel;
+        $selectmenu->label->for = $selectmenu->id;
+    }
+
+    if ($help) {
+        $selectmenu->helpicon = new help_icon();
+        $selectmenu->helpicon->page = $help;
+        $selectmenu->helpicon->text = $helptext;
+        $selectmenu->helpicon->linktext = false;
+    }
+
+    $output = $OUTPUT->select_menu($selectmenu);
+
     if ($return) {
         return $output;
     } else {
index 0f4de7a7202c8322a20c8381e79ee0944d5e4a55..05467ece2e8f18443fd70f6a1e31b3dfd6270353 100644 (file)
@@ -1186,8 +1186,9 @@ function init_help_icons() {
  * @param string url The URL to forward to if YES is clicked. Disabled if fn is given
  * @param function fn A JS function to run if YES is clicked.
  */
-function confirm_dialog(event, message) {
-
+function confirm_dialog(event, args) {
+    var message = args.message;
+    var target = this;
     YAHOO.util.Event.preventDefault(event);
 
     var simpledialog = new YAHOO.widget.SimpleDialog('confirmdialog',
@@ -1209,8 +1210,7 @@ function confirm_dialog(event, message) {
 
     var handle_yes = function() {
         this.hide();
-        var target = event.target;
-
+        
         if (target.tagName.toLowerCase() == 'a') {
             window.location = target.href;
         } else if (target.tagName.toLowerCase() == 'input') {
index 724af1b1d05eb29b9e365d8a0b114bba31cebc6b..227bad67317f41dc71c793d312f6675b2518df83 100644 (file)
@@ -2767,11 +2767,6 @@ class moodle_core_renderer extends moodle_renderer_base {
 
         $this->prepare_event_handlers($selectmenu);
 
-        if ($selectmenu->nothinglabel) {
-            $selectmenu->options = array($selectmenu->nothingvalue => $selectmenu->nothinglabel) +
-                    $selectmenu->options;
-        }
-
         if (empty($selectmenu->id)) {
             $selectmenu->id = 'menu' . str_replace(array('[', ']'), '', $selectmenu->name);
         }
@@ -2806,47 +2801,50 @@ class moodle_core_renderer extends moodle_renderer_base {
             $html .= $this->label($selectmenu->label);
         }
 
+        if (!empty($selectmenu->helpicon) && $selectmenu->helpicon instanceof help_icon) {
+            $html .= $this->help_icon($selectmenu->helpicon);
+        }
+
         $html .= $this->output_start_tag('select', $attributes) . "\n";
 
-        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 => $display) {
-                    $attributes = array('value' => $value);
+        foreach ($selectmenu->options as $option) {
+            // $OUTPUT->select_option detects if $option is an option or an optgroup
+            $html .= $this->select_option($option);
+        }
 
-                    if ((string) $value == (string) $selectmenu->selectedvalue ||
-                            (is_array($selectmenu->selectedvalue) && in_array($value, $selectmenu->selectedvalue))) {
-                        $attributes['selected'] = 'selected';
-                    }
+        $html .= $this->output_end_tag('select') . "\n";
 
-                    $html .= $this->output_start_tag('option', $attributes);
+        if (!empty($selectmenu->form) && $selectmenu->form instanceof html_form) {
+            $html = $this->form($selectmenu->form, $html);
+        }
 
-                    if ($display === '') {
-                        $html .= $value;
-                    } else {
-                        $html .= $display;
-                    }
+        return $html;
+    }
 
-                    $html .= $this->output_end_tag('option');
-                }
-                $html .= $this->output_end_tag('optgroup');
-            }
-        } else {
-            foreach ($selectmenu->options as $value => $display) {
-                $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($display)) . "\n";
+    /**
+     * Output an <option> or <optgroup> element. If an optgroup element is detected,
+     * this will recursively output its options as well.
+     *
+     * @param mixed $option a moodle_select_option or moodle_select_optgroup
+     * @return string the HTML for the <option> or <optgroup>
+     */
+    public function select_option($option) {
+        $option->prepare();
+        $this->prepare_event_handlers($option);
+
+        if ($option instanceof html_select_option) {
+            return $this->output_tag('option', array(
+                    'value' => $option->value,
+                    'class' => $option->get_classes_string(),
+                    'selected' => $option->selected), $option->text);
+        } else if ($option instanceof html_select_optgroup) {
+            $output = $this->output_start_tag('optgroup', array('label' => $option->text, 'class' => $option->get_classes_string()));
+            foreach ($option->options as $selectoption) {
+                $output .= $this->select_option($selectoption);
             }
+            $output .= $this->output_end_tag('optgroup');
+            return $output;
         }
-        $html .= $this->output_end_tag('select') . "\n";
-
-        return $html;
     }
 
     /**
@@ -3385,7 +3383,9 @@ class moodle_html_component {
  */
 class moodle_select_menu extends moodle_html_component {
     /**
-     * @var array the choices to show in the menu. An array $value => $display.
+     * The moodle_select_menu object parses an array of options into component objects
+     * @see nested attribute
+     * @var mixed $options the choices to show in the menu. An array $value => $display, of html_select_option or of html_select_optgroup objects.
      */
     public $options;
     /**
@@ -3437,15 +3437,27 @@ class moodle_select_menu extends moodle_html_component {
      */
     public $multiple = false;
     /**
+     * Another way to use nested menu is to prefix optgroup labels with -- and end the optgroup with --
+     * Leave this setting to false if you are using the latter method.
      * @var boolean $nested if true, uses $options' keys as option headings (optgroup)
      */
     public $nested = false;
+    /**
+     * @var html_form $form An optional html_form component
+     */
+    public $form;
+    /**
+     * @var help_icon $form An optional help_icon component
+     */
+    public $helpicon;
 
     /**
      * @see moodle_html_component::prepare()
      * @return void
      */
     public function prepare() {
+        global $CFG;
+        
         // name may contain [], which would make an invalid id. e.g. numeric question type editing form, assignment quickgrading
         if (empty($this->id)) {
             $this->id = 'menu' . str_replace(array('[', ']'), '', $this->name);
@@ -3462,7 +3474,7 @@ class moodle_select_menu extends moodle_html_component {
             $this->nothinglabel = '';
         }
 
-        if (!($this->label instanceof html_label)) {
+        if (!empty($this->label) && !($this->label instanceof html_label)) {
             $label = new html_label();
             $label->text = $this->label;
             $label->for = $this->name;
@@ -3471,6 +3483,100 @@ class moodle_select_menu extends moodle_html_component {
 
         $this->add_class('select');
 
+        $firstoption = reset($this->options);
+        if (is_object($firstoption)) {
+            parent::prepare();
+            return true;
+        }
+
+        $options = $this->options;
+        $this->options = array();
+
+        if ($this->nested) {
+            foreach ($options as $section => $values) {
+                $optgroup = new html_select_optgroup();
+                $optgroup->text = $section;
+
+                foreach ($values as $value => $display) {
+                    $option = new html_select_option();
+                    $option->value = s($value);
+                    $option->text = $display;
+                    if ($display === '') {
+                        $option->text = $value;
+                    }
+
+                    if ((string) $value == (string) $this->selectedvalue ||
+                            (is_array($this->selectedvalue) && in_array($value, $this->selectedvalue))) {
+                        $option->selected = 'selected';
+                    }
+
+                    $optgroup->options[] = $option;
+                }
+
+                $this->options[] = $optgroup;
+            }
+        } else {
+            $inoptgroup = false;
+            $optgroup = false;
+            foreach ($options as $value => $display) {
+                if ($display == '--') { /// we are ending previous optgroup
+                    $this->options[] = $optgroup;
+                    $inoptgroup = false;
+                    continue;
+                } else if (substr($display,0,2) == '--') { /// we are starting a new optgroup
+                    if (!empty($optgroup->options)) {
+                        $this->options[] = $optgroup;
+                    }
+
+                    $optgroup = new html_select_optgroup();
+                    $optgroup->text = substr($display,2); // stripping the --
+
+                    $inoptgroup = true; /// everything following will be in an optgroup
+                    continue;
+
+                } else {
+                    // Add $nothing option if there are not optgroups
+                    if ($this->nothinglabel && empty($this->options[0]) && !$inoptgroup) {
+                        $nothingoption = new html_select_option();
+                        $nothingoption->value = 0;
+                        if (!empty($this->nothingvalue)) {
+                            $nothingoption->value = $this->nothingvalue;
+                        }
+                        $nothingoption->text = $this->nothinglabel;
+                        $this->options = array($nothingoption) + $this->options;
+                    }
+
+                    $option = new html_select_option();
+                    $option->text = $display;
+
+                    if ($display === '') {
+                        $option->text = $value;
+                    }
+
+                    if ((string) $value == (string) $this->selectedvalue ||
+                            (is_array($this->selectedvalue) && in_array($value, $this->selectedvalue))) {
+                        $option->selected = 'selected';
+                    }
+
+                    $option->value = s($value);
+
+                    if (!empty($optionsextra[$value])) {
+                        $optstr .= ' '.$optionsextra[$value];
+                    }
+
+                    if ($inoptgroup) {
+                        $optgroup->options[] = $option;
+                    } else {
+                        $this->options[] = $option;
+                    }
+                }
+            }
+
+            if ($optgroup) {
+                $this->options[] = $optgroup;
+            }
+        }
+
         parent::prepare();
     }
 
@@ -3562,10 +3668,40 @@ class moodle_select_menu extends moodle_html_component {
 
         return $timerselector;
     }
+
+    /**
+     * This is a shortcut for making a select popup form.
+     * @param string $baseurl The target URL up to the point of the variable that changes
+     * @param array $options A list of value-label pairs for the popup list
+     * @param string $formid id for the control. Must be unique on the page. Used in the HTML.
+     * @param string $submitvalue Optional label for the 'Go' button. Defaults to get_string('go').
+     * @param string $selected The option that is initially selected
+     * @return moodle_select_menu A menu initialised as a popup form.
+     */
+    public function make_popup_form($baseurl, $options, $formid, $submitvalue='', $selected=null) {
+        $selectmenu = self::make($options, 'jump', $selected);
+        $selectmenu->form = new html_form();
+        $selectmenu->form->id = $formid;
+        $selectmenu->form->method = 'get';
+        $selectmenu->form->add_class('popupform');
+        $selectmenu->form->url = new moodle_url($baseurl);
+        $selectmenu->form->button->text = get_string('go');
+
+        if (!empty($submitvalue)) {
+            $selectmenu->form->button->text = $submitvalue;
+        }
+
+        $selectmenu->id = $formid . '_jump';
+        $selectmenu->baseurl = $baseurl;
+
+        $selectmenu->add_action('change', 'submit_form_by_id', array('id' => $formid, 'selectid' => $selectmenu->id));
+
+        return $selectmenu;
+    }
 }
 
 /**
- * This class represents how a block appears on a page.
+ * This class represents a label element
  *
  * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@@ -3581,7 +3717,75 @@ class html_label extends moodle_html_component {
      */
     public $for;
 
+    /**
+     * @see moodle_html_component::prepare()
+     * @return void
+     */
     public function prepare() {
+        if (empty($this->text)) {
+            throw new coding_exception('html_label must have a $text value.');
+        }
+        parent::prepare();
+    }
+}
+
+/**
+ * This class represents a select option element
+ *
+ * @copyright 2009 Nicolas Connault
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since     Moodle 2.0
+ */
+class html_select_option extends moodle_html_component {
+    /**
+     * @var string $value The value of this option (will be sent with form)
+     */
+    public $value;
+    /**
+     * @var string $text The display value of the option
+     */
+    public $text;
+    /**
+     * @var boolean $selected Whether or not this option is selected
+     */
+    public $selected = false;
+
+    /**
+     * @see moodle_html_component::prepare()
+     * @return void
+     */
+    public function prepare() {
+        if (empty($this->text)) {
+            throw new coding_exception('html_select_option requires a $text value.');
+        }
+        parent::prepare();
+    }
+}
+
+/**
+ * This class represents a select optgroup element
+ *
+ * @copyright 2009 Nicolas Connault
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since     Moodle 2.0
+ */
+class html_select_optgroup extends moodle_html_component {
+    /**
+     * @var string $text The display value of the optgroup
+     */
+    public $text;
+    /**
+     * @var array $options An array of html_select_option objects
+     */
+    public $options = array();
+
+    public function prepare() {
+        if (empty($this->text)) {
+            throw new coding_exception('html_select_optgroup requires a $text value.');
+        }
+        if (empty($this->options)) {
+            throw new coding_exception('html_select_optgroup requires at least one html_select_option object');
+        }
         parent::prepare();
     }
 }
@@ -4041,7 +4245,7 @@ class help_icon extends moodle_html_component {
     }
 
     public static function make_scale_menu($courseid, $scale) {
-        $helpbutton = new help_button();
+        $helpbutton = new help_icon();
         $strscales = get_string('scales');
         $helpbutton->image->alt = $scale->name;
         $helpbutton->link->url = new moodle_url('/course/scales.php', array('id' => $courseid, 'list' => true, 'scaleid' => $scale->id));
index d41b0a4f3c1b74b8f86bc82978269f33434e0ad0..a7056002b8a1fc1a961a932e16f3343647f77dc5 100644 (file)
@@ -886,9 +886,7 @@ class moodle_core_renderer_test extends UnitTestCase {
     public function test_select_menu_simple() {
         $selectmenu = moodle_select_menu::make(array(10 => 'ten', 'c2' => 'two'), 'mymenu');
         $html = $this->renderer->select_menu($selectmenu);
-        $this->assert(new ContainsTagWithAttribute('select', 'class', 'menumymenu select'), $html);
-        $this->assert(new ContainsTagWithAttribute('select', 'name', 'mymenu'), $html);
-        $this->assert(new ContainsTagWithAttribute('select', 'id', 'menumymenu'), $html);
+        $this->assert(new ContainsTagWithAttributes('select', array('class' => 'menumymenu select', 'name' => 'mymenu', 'id' => 'menumymenu')), $html);
         $this->assert(new ContainsTagWithContents('option', 'ten'), $html);
         $this->assert(new ContainsTagWithAttribute('option', 'value', '10'), $html);
         $this->assert(new ContainsTagWithContents('option', 'two'), $html);
@@ -1161,4 +1159,32 @@ class moodle_core_renderer_test extends UnitTestCase {
         $htmllist->items[2]->type = 'ordered';
         $html = $this->renderer->htmllist($htmllist);
     }
+
+    public function test_moodle_select_menu() {
+        $options = array('var1' => 'value1', 'var2' => 'value2', 'var3' => 'value3');
+        $selectmenu = moodle_select_menu::make($options, 'mymenu', 'var2');
+        $html = $this->renderer->select_menu($selectmenu);
+        $this->assert(new ContainsTagWithAttributes('select', array('name' => 'mymenu')), $html);
+        $this->assert(new ContainsTagWithAttributes('option', array('value' => 'var1'), array('selected' => 'selected')), $html);
+        $this->assert(new ContainsTagWithAttributes('option', array('value' => 'var2', 'selected' => 'selected')), $html);
+        $this->assert(new ContainsTagWithAttributes('option', array('value' => 'var3'), array('selected' => 'selected')), $html);
+        $this->assert(new ContainsTagWithContents('option', 'value1'), $html);
+        $this->assert(new ContainsTagWithContents('option', 'value2'), $html);
+        $this->assert(new ContainsTagWithContents('option', 'value3'), $html);
+
+        $options = array('group1' => '--group1', 'var1' => 'value1', 'var2' => 'value2', 'group2' => '--', 'group2' => '--group2', 'var3' => 'value3', 'var4' => 'value4');
+        $selectmenu = moodle_select_menu::make($options, 'mymenu', 'var2');
+        $html = $this->renderer->select_menu($selectmenu);
+        $this->assert(new ContainsTagWithAttributes('select', array('name' => 'mymenu')), $html);
+        $this->assert(new ContainsTagWithAttributes('optgroup', array('label' => 'group1')), $html);
+        $this->assert(new ContainsTagWithAttributes('optgroup', array('label' => 'group2')), $html);
+        $this->assert(new ContainsTagWithAttributes('option', array('value' => 'var1'), array('selected' => 'selected')), $html);
+        $this->assert(new ContainsTagWithAttributes('option', array('value' => 'var2', 'selected' => 'selected')), $html);
+        $this->assert(new ContainsTagWithAttributes('option', array('value' => 'var3'), array('selected' => 'selected')), $html);
+        $this->assert(new ContainsTagWithAttributes('option', array('value' => 'var4'), array('selected' => 'selected')), $html);
+        $this->assert(new ContainsTagWithContents('option', 'value1'), $html);
+        $this->assert(new ContainsTagWithContents('option', 'value2'), $html);
+        $this->assert(new ContainsTagWithContents('option', 'value3'), $html);
+        $this->assert(new ContainsTagWithContents('option', 'value4'), $html);
+    }
 }
index 5560cfe6eb7d672210964e86bee9ec18e37750e5..5b0d574855d2378658dc29c8ded700a94e68cbc5 100644 (file)
@@ -797,200 +797,6 @@ function print_textfield ($name, $value, $alt = '',$size=50,$maxlength=0, $retur
 }
 
 
-/**
- * Implements a complete little form with a dropdown menu. 
- *
- * When JavaScript is on selecting an option from the dropdown automatically 
- * submits the form (while avoiding the usual acessibility problems with this appoach). 
- * With JavaScript off, a 'Go' button is printed.
- *
- * @todo Finish documenting this function
- *
- * @global object
- * @global object
- * @param string $baseurl The target URL up to the point of the variable that changes
- * @param array $options A list of value-label pairs for the popup list
- * @param string $formid id for the control. Must be unique on the page. Used in the HTML.
- * @param string $selected The option that is initially selected
- * @param string $nothing The label for the "no choice" option
- * @param string $help The name of a help page if help is required
- * @param string $helptext The name of the label for the help button
- * @param boolean $return Indicates whether the function should return the HTML
- *         as a string or echo it directly to the page being rendered
- * @param string $targetwindow The name of the target page to open the linked page in.
- * @param string $selectlabel Text to place in a [label] element - preferred for accessibility.
- * @param array $optionsextra an array with the same keys as $options. The values are added within the corresponding <option ...> tag.
- * @param string $submitvalue Optional label for the 'Go' button. Defaults to get_string('go').
- * @param boolean $disabled If true, the menu will be displayed disabled.
- * @param boolean $showbutton If true, the button will always be shown even if JavaScript is available
- * @return string|void If $return=true returns string, else echo's and returns void
- */
-function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
-    $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
-    global $CFG, $SESSION, $PAGE;
-    static $go, $choose;   /// Locally cached, in case there's lots on a page
-
-    if (empty($options)) {
-        return '';
-    }
-
-    if (empty($submitvalue)){
-        if (!isset($go)) {
-            $go = get_string('go');
-            $submitvalue=$go;
-        }
-    }
-    if ($nothing == 'choose') {
-        if (!isset($choose)) {
-            $choose = get_string('choose');
-        }
-        $nothing = $choose.'...';
-    }
-    if ($disabled) {
-        $disabled = ' disabled="disabled"';
-    } else {
-        $disabled = '';
-    }
-
-    // changed reference to document.getElementById('id_abc') instead of document.abc
-    // MDL-7861
-    $output = '<form action="'.$CFG->wwwroot.'/course/jumpto.php"'.
-                        ' method="get" '.
-                         $CFG->frametarget.
-                        ' id="'.$formid.'"'.
-                        ' class="popupform">';
-    if ($help) {
-        $button = helpbutton($help, $helptext, 'moodle', true, false, '', true);
-    } else {
-        $button = '';
-    }
-
-    if ($selectlabel) {
-        $selectlabel = '<label for="'.$formid.'_jump">'.$selectlabel.'</label>';
-    }
-
-    if ($showbutton) {
-        // Using the no-JavaScript version
-        $javascript = '';
-    } else if (check_browser_version('MSIE') || (check_browser_version('Opera') && !check_browser_operating_system("Linux"))) {
-        //IE and Opera fire the onchange when ever you move into a dropdown list with the keyboard.
-        //onfocus will call a function inside dropdown.js. It fixes this IE/Opera behavior.
-        //Note: There is a bug on Opera+Linux with the javascript code (first mouse selection is inactive),
-        //so we do not fix the Opera behavior on Linux
-        $PAGE->requires->js('lib/dropdown.js')->asap();
-        $javascript = ' onfocus="initSelect(\''.$formid.'\','.$targetwindow.')"';
-    } else {
-        //Other browser
-        $javascript = ' onchange="'.$targetwindow.
-          '.location=document.getElementById(\''.$formid.
-          '\').jump.options[document.getElementById(\''.
-          $formid.'\').jump.selectedIndex].value;"';
-    }
-
-    $output .= '<div style="white-space:nowrap">'.$selectlabel.$button.'<select id="'.$formid.'_jump" name="jump"'.$javascript.$disabled.'>'."\n";
-
-    if ($nothing != '') {
-        $selectlabeloption = '';
-        if ($selected=='') {
-            $selectlabeloption = ' selected="selected"';
-        }
-        foreach ($options as $value => $label) {  //if one of the options is the empty value, don't make this the default
-            if ($value == '') {
-                $selected = '';
-            }
-        }
-        $output .= "   <option value=\"javascript:void(0)\"$selectlabeloption>$nothing</option>\n";
-    }
-
-    $inoptgroup = false;
-
-    foreach ($options as $value => $label) {
-
-        if ($label == '--') { /// we are ending previous optgroup
-            /// Check to see if we already have a valid open optgroup
-            /// XHTML demands that there be at least 1 option within an optgroup
-            if ($inoptgroup and (count($optgr) > 1) ) {
-                $output .= implode('', $optgr);
-                $output .= '   </optgroup>';
-            }
-            $optgr = array();
-            $inoptgroup = false;
-            continue;
-        } else if (substr($label,0,2) == '--') { /// we are starting a new optgroup
-
-            /// Check to see if we already have a valid open optgroup
-            /// XHTML demands that there be at least 1 option within an optgroup
-            if ($inoptgroup and (count($optgr) > 1) ) {
-                $output .= implode('', $optgr);
-                $output .= '   </optgroup>';
-            }
-
-            unset($optgr);
-            $optgr = array();
-
-            $optgr[]  = '   <optgroup label="'. s(format_string(substr($label,2))) .'">';   // Plain labels
-
-            $inoptgroup = true; /// everything following will be in an optgroup
-            continue;
-
-        } else {
-           if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()]))
-            {
-                $url = $SESSION->sid_process_url( $baseurl . $value );
-            } else
-            {
-                $url=$baseurl . $value;
-            }
-            $optstr = '   <option value="' . $url . '"';
-
-            if ($value == $selected) {
-                $optstr .= ' selected="selected"';
-            }
-
-            if (!empty($optionsextra[$value])) {
-                $optstr .= ' '.$optionsextra[$value];
-            }
-
-            if ($label) {
-                $optstr .= '>'. $label .'</option>' . "\n";
-            } else {
-                $optstr .= '>'. $value .'</option>' . "\n";
-            }
-
-            if ($inoptgroup) {
-                $optgr[] = $optstr;
-            } else {
-                $output .= $optstr;
-            }
-        }
-
-    }
-
-    /// catch the final group if not closed
-    if ($inoptgroup and count($optgr) > 1) {
-        $output .= implode('', $optgr);
-        $output .= '    </optgroup>';
-    }
-
-    $output .= '</select>';
-    $output .= '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
-    if (!$showbutton) {
-        $output .= '<div id="noscript'.$formid.'" style="display: inline;">';
-    }
-    $output .= '<input type="submit" value="'.$submitvalue.'" '.$disabled.' />';
-    if (!$showbutton) {
-        $PAGE->requires->js_function_call('hide_item', Array('noscript'.$formid));
-        $output .= '</div>';
-    }
-    $output .= '</div></form>';
-
-    if ($return) {
-        return $output;
-    } else {
-        echo $output;
-    }
-}
-
 
 /**
  * Validates an email to make sure it makes sense.