+ /**
+ * Build a drop-down box from a textual list.
+ *
+ * @param $name Mixed: Name and id for the drop-down
+ * @param $class Mixed: CSS classes for the drop-down
+ * @param $other Mixed: Text for the "Other reasons" option
+ * @param $list Mixed: Correctly formatted text to be used to generate the options
+ * @param $selected Mixed: Option which should be pre-selected
+ * @param $tabindex Mixed: Value of the tabindex attribute
+ * @return string
+ */
+ public static function listDropDown( $name= '', $list = '', $other = '', $selected = '', $class = '', $tabindex = Null ) {
+ $options = '';
+ $optgroup = false;
+
+ $options = self::option( $other, 'other', $selected === 'other' );
+
+ foreach ( explode( "\n", $list ) as $option) {
+ $value = trim( $option );
+ if ( $value == '' ) {
+ continue;
+ } elseif ( substr( $value, 0, 1) == '*' && substr( $value, 1, 1) != '*' ) {
+ // A new group is starting ...
+ $value = trim( substr( $value, 1 ) );
+ if( $optgroup ) $options .= self::closeElement('optgroup');
+ $options .= self::openElement( 'optgroup', array( 'label' => $value ) );
+ $optgroup = true;
+ } elseif ( substr( $value, 0, 2) == '**' ) {
+ // groupmember
+ $value = trim( substr( $value, 2 ) );
+ $options .= self::option( $value, $value, $selected === $value );
+ } else {
+ // groupless reason list
+ if( $optgroup ) $options .= self::closeElement('optgroup');
+ $options .= self::option( $value, $value, $selected === $value );
+ $optgroup = false;
+ }
+ }
+ if( $optgroup ) $options .= self::closeElement('optgroup');
+
+ $attribs = array();
+ if( $name ) {
+ $attribs['id'] = $name;
+ $attribs['name'] = $name;
+ }
+ if( $class ) {
+ $attribs['class'] = $class;
+ }
+ if( $tabindex ) {
+ $attribs['tabindex'] = $tabindex;
+ }
+ return Xml::openElement( 'select', $attribs )
+ . "\n"
+ . $options
+ . "\n"
+ . Xml::closeElement( 'select' );
+ }
+
+ /**
+ * Shortcut for creating fieldsets.
+ *
+ * @param $legend Legend of the fieldset. If evaluates to false, legend is not added.
+ * @param $content Pre-escaped content for the fieldset. If false, only open fieldset is returned.
+ * @param $attribs Any attributes to fieldset-element.
+ */
+ public static function fieldset( $legend = false, $content = false, $attribs = array() ) {
+ $s = Xml::openElement( 'fieldset', $attribs ) . "\n";
+ if ( $legend ) {
+ $s .= Xml::element( 'legend', null, $legend ) . "\n";
+ }
+ if ( $content !== false ) {
+ $s .= $content . "\n";
+ $s .= Xml::closeElement( 'fieldset' ) . "\n";
+ }
+
+ return $s;
+ }
+
+ /**
+ * Shortcut for creating textareas.
+ *
+ * @param $name The 'name' for the textarea
+ * @param $content Content for the textarea
+ * @param $cols The number of columns for the textarea
+ * @param $rows The number of rows for the textarea
+ * @param $attribs Any other attributes for the textarea
+ */
+ public static function textarea( $name, $content, $cols = 40, $rows = 5, $attribs = array() ) {
+ return self::element( 'textarea',
+ array( 'name' => $name,
+ 'id' => $name,
+ 'cols' => $cols,
+ 'rows' => $rows
+ ) + $attribs,
+ $content, false );
+ }
+