/** construct a generic form with a dialog
 *
 * this constructs an HTML form with a simple dialog where
 *
 *  - every label and every widget has its own line
 *    (enforced by a BR-tag)
 *  - label/widget-combinations are separated with a P-tag
 *  - buttons are stringed together on a single line (ie no trailing BR)
 *
 * This should be sufficient for many dialogs.
 * If the layout needs to be more complex a custom dialog can
 * always be constructed using functions {@link dialog_get_label()}
 * and {@link dialog_get_widget()}.
 *
 * @param string $href the target of the HTML form
 * @param array &$dialogdef the array which describes the complete dialog
 * @param string $method method to submit data to the server, either 'post' or 'get'
 * @param string|array $attributes holds the attributes to add to the form tag
 * @return array constructed HTML-form with dialog, one line per array element
 * @uses html_form()
 */
function dialog_quickform($href, &$dialogdef, $method = 'post', $attributes = '')
{
    $buttons_seen = FALSE;
    $a = array(0 => html_form($href, $method, $attributes));
    // result starts with opening a form tag
    foreach ($dialogdef as $item) {
        if (!isset($item['name'])) {
            // skip spurious item (possibly empty array)
            continue;
        }
        $label = dialog_get_label($item);
        if (!empty($label)) {
            $a[] = '<p>';
            $a[] = $label . '<br>';
        }
        $widget = dialog_get_widget($item);
        if (is_array($widget)) {
            // add every radio button on a separate line
            $postfix = $item['type'] == F_RADIO ? '<br>' : '';
            foreach ($widget as $widget_line) {
                $a[] = $widget_line . $postfix;
            }
        } else {
            // quick and dirty:
            // add a <p> before the first button in a dialog
            // add a <br> after every 1-line item except buttons
            // result: fields line up nicely and buttons are on a single row
            $postfix = '';
            if ($item['type'] == F_SUBMIT) {
                if (!$buttons_seen) {
                    $buttons_seen = TRUE;
                    $a[] = '<p>';
                }
            } elseif (!(isset($item['hidden']) && $item['hidden'])) {
                $postfix = '<br>';
            }
            $a[] = $widget . $postfix;
        }
    }
    $a[] = '<p>';
    $a[] = html_form_close();
    return $a;
}
/** present the user with a dialog to modify the workshop that is connected to node $node_id
 *
 * this prepares a dialog for the user filled with existing data (if any), possibly allowing
 * the user to modify the content. If the flag $viewonly is TRUE, this routine should only
 * display the content rather than let the user edit it. If the flag $edit_again is TRUE,
 * the routine should use the data available in the $_POST array, otherwise it should read
 * the data from the database (or wherever the data comes from). The parameter $href is the
 * place where the form should be POST'ed.
 *
 * The dialog should be added to the $output object. Useful routines are:
 * <code>
 * $output->add_content($content): add $content to the content area
 * $output->add_message($message): add $message to the message area (feedback to the user)
 * $output->add_popup_bottom($message): make $message popup in the browser after loading the page (uses JS)
 * $output->add_popup_top($message): make $message popup in the browser before loading the page (uses JS)
 * </code>
 * 
 * @param object &$output collects the html output (if any)
 * @param int $area_id the area in which $node_id resides
 * @param int $node_id the node to which this module is connected
 * @param array $module the module record straight from the database
 * @param bool $viewonly if TRUE, editing is not allowed (but simply showing the content is allowed)
 * @param bool $edit_again if TRUE start with data from $_POST, else use data from database
 * @param string $href the action property of the HTML-form, the place where data will be POST'ed
 * @return bool TRUE on success + output stored via $output, FALSE otherwise
 */
function crew_show_edit(&$output, $area_id, $node_id, $module, $viewonly, $edit_again, $href)
{
    global $USER;
    $module_id = intval($module['module_id']);
    $dialogdef = crew_get_dialogdef($output, $viewonly, $module_id, $area_id, $node_id, $USER->user_id);
    if ($edit_again) {
        // retrieve and (again) validate the POSTed values
        dialog_validate($dialogdef);
        // no need to show messages; we did that alread in crew_save() below
    }
    $output->add_content('<h2>' . t('crew_content_header', 'm_crew') . '</h2>');
    $output->add_content(t('crew_content_explanation', 'm_crew'));
    // Manually construct the form because of embedded HTML-table
    $in_table = FALSE;
    $postponed = array();
    $oddeven = 'even';
    $output->add_content(html_form($href));
    foreach ($dialogdef as $name => $item) {
        // this always works because the last item is not an acl field
        if ($in_table && substr($name, 0, 3) != 'acl') {
            $output->add_content(html_table_close());
            $in_table = FALSE;
        }
        if (!$in_table && substr($name, 0, 3) == 'acl') {
            $output->add_content(html_table(array('class' => 'acl_form')));
            $in_table = TRUE;
        }
        if (substr($name, 0, 3) == 'acl') {
            $oddeven = $oddeven == 'even' ? 'odd' : 'even';
            $attributes = array('class' => $oddeven);
            $output->add_content('  ' . html_table_row($attributes));
            $output->add_content('    ' . html_table_cell($attributes, dialog_get_label($item)));
            $widget = dialog_get_widget($item);
            if (is_array($widget)) {
                $output->add_content('    ' . html_table_cell($attributes));
                // add every radio button on a separate line
                $postfix = $item['type'] == F_RADIO ? '<br>' : '';
                foreach ($widget as $widget_line) {
                    $output->add_content('      ' . $widget_line . $postfix);
                }
                $output->add_content('    ' . html_table_cell_close());
            } else {
                $output->add_content('    ' . html_table_cell($attributes, $widget));
            }
            $output->add_content('  ' . html_table_row_close());
        } else {
            if ($item['type'] == F_SUBMIT) {
                $postponed[$name] = $item;
            } else {
                $output->add_content('<p>');
                $output->add_content(dialog_get_label($item) . '<br>');
                $widget = dialog_get_widget($item);
                if (is_array($widget)) {
                    // add every radio button on a separate line
                    $postfix = $item['type'] == F_RADIO ? '<br>' : '';
                    foreach ($widget as $widget_line) {
                        $output->add_content($widget_line . $postfix);
                    }
                } else {
                    $output->add_content($widget);
                }
            }
        }
    }
    foreach ($postponed as $item) {
        $output->add_content(dialog_get_widget($item));
    }
    $output->add_content('<p>');
    $output->add_content(html_form_close());
    return TRUE;
}
/** display the contact form
 *
 * this displays the contact form. Every destination gets a
 * separate DIV just below the listbox, with the additional
 * information for that destination. If JavaScript is NOT
 * enabled, all DIVs are displayed, otherwise only the
 * currently selected destination is displayed and the
 * others are not. IOW: this form is still usable even
 * without JS enabled AND it is screenreader-friendly.
 *
 * If there is only a single destination, the listbox is
 * not defined in the dialogdef and hence not rendered at all:
 * there is no point in showing a list of options
 * if there is nothing to choose from. This means that the
 * necessary javascript is NOT added and also no DIVs are
 * shown. So: a clean, uncluttered form in case of a single
 * destination.
 *
 * @param object &$theme collects the (html) output
 * @param array mailpage configuration data in a (nested) array
 * @param array $dialogdef array that defines the input fields
 * @return void output writted to $theme
 */
function mailpage_show_form(&$theme, $config, $dialogdef)
{
    //
    // 1 -- maybe output a header and an introduction
    //
    $header = trim($config['header']);
    if (!empty($header)) {
        $theme->add_content(html_tag('h2', '', $header));
    }
    $introduction = trim($config['introduction']);
    if (!empty($introduction)) {
        $theme->add_content($introduction);
    }
    $href = was_node_url($theme->node_record);
    //
    // 2 -- Render the dialog (maybe including the additional DIVs)
    //
    $postponed = array();
    $theme->add_content(html_form($href));
    foreach ($dialogdef as $name => $item) {
        if ($item['type'] == F_SUBMIT || isset($item['hidden']) && $item['hidden']) {
            $postponed[$name] = $item;
        } else {
            $theme->add_content('<p>');
            $theme->add_content(dialog_get_label($item) . '<br>');
            $widget = dialog_get_widget($item);
            if (is_array($widget)) {
                // add every radio button on a separate line
                $postfix = $item['type'] == F_RADIO ? '<br>' : '';
                foreach ($widget as $widget_line) {
                    $theme->add_content($widget_line . $postfix);
                }
            } else {
                $theme->add_content($widget);
            }
        }
        if ($name == 'destination') {
            foreach ($item['options'] as $index => $option) {
                $theme->add_content(sprintf('<div class="%s" id="%s%d">%s: %s</div>', 'mailpage_destination_option', 'mailpage_destination_', $index, htmlspecialchars($option['option']), htmlspecialchars($option['title'])));
            }
            // This suppresses the DIVs that correspond to currently
            // not selected options in the listbox
            $js = "<script><!--\n" . "var sel=document.getElementById('mailpage_destination');\n" . "sel.onchange=function() {\n" . "  var div;\n" . "  for(var i=0; i<this.length; ++i) {\n" . "    div=document.getElementById('mailpage_destination_'+this.options[i].value);\n" . "    div.style.display=(this.options[i].selected)?'block':'none';\n" . "  }\n" . "}\n" . "sel.onchange();\n" . "--></script>\n";
            $theme->add_content($js);
        }
    }
    $theme->add_content('<p>');
    foreach ($postponed as $item) {
        $theme->add_content(dialog_get_widget($item));
    }
    $theme->add_content(html_form_close());
}
 /** show a thumbnail of a single (image) file perhaps including clickable links for selection in FCK Editor
  *
  * This constructs a single clickable image with either a selection of the file (for FCK Editor, in
  * file/image browser mode) or a link to the file preview. If a file is not an image or otherwise no
  * suitable thumbnail is found, a large question mark is displayed (unknown.gif). Otherwise the existing
  * thumbnail is shown, maintaining the original aspect ratio. Either way the image is scaled to the currently
  * specified thumbail dimension so the image fits the corresponding DIV-tag.
  *
  * The strategy for finding a thumbnail is as follows:
  * - is the file to show an image at all? If not, show unknown.gif
  * - if the file zz_thumb_{filename.ext} exists, use that, otherwise
  * - if not AND the original file is smaller than a thumbnailm use the original file, otherwise
  * - use 'unknown.gif' after all.
  *
  * If the flag $delete_file is set, we also generate a checkbox and a delete icon. This means that
  * even in file/image browser mode files can be deleted by the user. In fact the file/image browser
  * is basically the same old filemanager.
  *
  * @param string $directory the current working directory (necessary to construct (full) paths)
  * @param array $entry information about the file to show, see {@link get_entries()} for the format
  * @param bool $delete_file if TRUE, user is allowed to delete the file (used for generating delete icon)
  * @param int $index a counter used to generate a unique field name for the checkbox
  * @param string $m optional margin for better code readability
  * @return output generated via $this->output
  * @uses $WAS_SCRIPT_NAME
  * @uses $CFG
  */
 function show_file_as_thumbnail($directory, $entry, $delete_file, $index, $m = '')
 {
     global $WAS_SCRIPT_NAME, $CFG;
     // 1A -- prepare the clickable thumbnail (or 'unknown') image
     $filename = $entry['name'];
     $params = array('{FILENAME}' => $entry['vname'], '{SIZE}' => $this->human_readable_size($entry['size']), '{DATIM}' => strftime('%Y-%m-%d %T', $entry['mtime']));
     $image_path = sprintf('%s%s/%s', $CFG->datadir, $directory, $filename);
     if (($image_info = @getimagesize($image_path)) === FALSE) {
         // not an image, show 'unknown'
         $thumb_url = $CFG->progwww_short . '/graphics/unknown.gif';
         $thumb_width = $CFG->thumbnail_dimension;
         $thumb_height = $CFG->thumbnail_dimension;
         $properties = t('filemanager_title_thumb_file', 'admin', $params);
     } else {
         $image_width = $image_info[0];
         $image_height = $image_info[1];
         $image_dimension = max($image_width, $image_height);
         $thumb_path = sprintf('%s%s/%s%s', $CFG->datadir, $directory, THUMBNAIL_PREFIX, $filename);
         if (file_exists($thumb_path)) {
             $thumb_url = $this->file_url(sprintf('%s/%s%s', $directory, THUMBNAIL_PREFIX, $filename));
             $thumb_width = intval($image_width * $CFG->thumbnail_dimension / $image_dimension);
             $thumb_height = intval($image_height * $CFG->thumbnail_dimension / $image_dimension);
         } elseif ($image_dimension <= $CFG->thumbnail_dimension) {
             $thumb_url = $this->file_url(sprintf('%s/%s', $directory, $filename));
             $thumb_width = $image_width;
             $thumb_height = $image_height;
         } else {
             $thumb_url = $CFG->progwww_short . '/graphics/unknown.gif';
             $thumb_width = $CFG->thumbnail_dimension;
             $thumb_height = $CFG->thumbnail_dimension;
         }
         $params['{WIDTH}'] = strval($image_width);
         $params['{HEIGHT}'] = strval($image_height);
         $properties = t('filemanager_title_thumb_image', 'admin', $params);
     }
     $title = $properties;
     $img_attr = array('width' => $thumb_width, 'height' => $thumb_height, 'title' => $title);
     $anchor = html_img($thumb_url, $img_attr);
     // 1B -- choose between a file select (for FCK Editor) or file preview (generic file manager)
     if ($this->job == JOB_FILEBROWSER || $this->job == JOB_IMAGEBROWSER || $this->job == JOB_FLASHBROWSER) {
         // Note: we depend on Javascript here, but since FCK Editor is also a Javascript application...
         // In other words: we would not be here in the first place if Javascript wasn't enabled.
         // (The file preview option does not depend on Javascript, see task_preview_file().)
         $url = $this->file_url($entry['path']);
         $title = t('filemanager_select', 'admin', array('{FILENAME}' => htmlspecialchars($entry['name'])));
         $a_attr = sprintf('title="%s" onclick="select_url(\'%s\'); return false;"', $title, $url);
         $html_a_tag = html_a("#", NULL, $a_attr, $anchor);
     } else {
         $a_params = sprintf('job=%s&task=%s&%s=%s', $this->job, TASK_PREVIEW_FILE, PARAM_PATH, rawurlencode($entry['path']));
         $url = $WAS_SCRIPT_NAME . '?' . htmlspecialchars($a_params);
         $a_attr = sprintf('title="%s" target="_blank" onclick="popup(\'%s\'); return false;"', $title, $url);
         $html_a_tag = html_a($WAS_SCRIPT_NAME, $a_params, $a_attr, $anchor);
     }
     // 2 -- prepare checkbox and delete icon (if file deletion is allowed)
     if ($delete_file && $entry['is_file']) {
         $checkbox_def = array('type' => F_CHECKBOX, 'name' => sprintf('%s%d', PARAM_FILENAME, $index), 'options' => array($entry['name'] => ' '), 'title' => t('filemanager_select_file_entry_title', 'admin'), 'value' => '');
         $widget = dialog_get_widget($checkbox_def);
         $title = t('filemanager_delete_file', 'admin', array('{FILENAME}' => htmlspecialchars($entry['vname'])));
         $a_params = array('job' => $this->job, 'task' => TASK_REMOVE_FILE, PARAM_PATH => $entry['path']);
         $a_attr = array('title' => $title);
         $alt = t('icon_delete_file_alt', 'admin');
         $text = t('icon_delete_file_text', 'admin');
         $anchor = $this->output->skin->get_icon('delete', $title, $alt, $text);
         $icon = html_a($WAS_SCRIPT_NAME, $a_params, $a_attr, $anchor);
     } else {
         $icon = '';
         $widget = '';
     }
     // 3 -- place all prepared items in a separate DIV
     $this->output->add_content($m . '<div class="thumbnail_container">');
     $this->output->add_content($m . '  <div class="thumbnail_image">');
     $this->output->add_content($m . '    ' . $html_a_tag);
     $this->output->add_content($m . '  </div>');
     $this->output->add_content($m . '  <div class="thumbnail_delete">');
     $this->output->add_content($widget);
     $this->output->add_content($m . '    ' . $icon);
     $this->output->add_content($m . '  </div>');
     $this->output->add_content($m . '  <div class="thumbnail_description">');
     $this->output->add_content($m . '    ' . html_tag('span', array('title' => $properties), htmlspecialchars($entry['vname'])));
     $this->output->add_content($m . '  </div>');
     $this->output->add_content($m . '</div>');
 }
 /** construct a form with a dialog in a table with 2 or 3 columns
  *
  * this constructs a 2- or 3-column table and fills it with data from
  * the dialogdef.
  *
  * The first column holds the labels for the widgets.
  * The second column holds the corresponding widget, e.g. a list box with roles.
  * The optional third column (depends on the flag $show_related) shows
  * related information. This is used to list group/capacities and roles
  * from related groups (ie. groups of which the user is a member).
  *
  * The table has headers for the columns: 'Realm','Role' and optional 'Related'.
  * Rows in the table can have alternating colours via the odd/even class.
  * This is done via the stylesheet.
  *
  * @param string $href the target of the HTML form
  * @param array &$dialogdef the array which describes the complete dialog
  * @return array constructed HTML-form with dialog, one line per array element
  * @todo bailing out on non-array is a crude way of error handling: this needs to be fixed
  */
 function dialog_tableform($href, &$dialogdef, $show_related = FALSE)
 {
     if (!is_array($dialogdef)) {
         logger('dialog_tableform(): weird: there is no valid dialogdef?');
         return array(t('error_retrieving_data', 'admin'));
     }
     // result starts with opening a form tag and a 2- or 3-column table
     $attributes = array('class' => 'header');
     $a = array(html_form($href), html_table(array('class' => 'acl_form')), '  ' . html_table_row($attributes), '    ' . html_table_head($attributes, t('acl_column_header_realm', 'admin')), '    ' . html_table_head($attributes, t('acl_column_header_role', 'admin')));
     if ($show_related) {
         $a[] = '    ' . html_table_head($attributes, t('acl_column_header_related', 'admin'));
     }
     $a[] = '  ' . html_table_row_close();
     $oddeven = 'even';
     $postponed = array();
     foreach ($dialogdef as $item) {
         if (!isset($item['name'])) {
             // skip spurious item (possibly empty array)
             continue;
         }
         if ($item['type'] == F_SUBMIT || isset($item['hidden']) && $item['hidden']) {
             // always postpone the buttons and hidden fields to the end
             $postponed[] = $item;
             continue;
         }
         $oddeven = $oddeven == 'even' ? 'odd' : 'even';
         $attributes = array('class' => $oddeven);
         $a[] = '  ' . html_table_row($attributes);
         //
         // column 1 - realm
         //
         if ($this->area_view_enabled) {
             if (isset($item['area_id'])) {
                 // site level or area level
                 $icon = $this->get_icon_area($item['area_id'], $item['area_is_open'], $item['area_offset']);
             } else {
                 // node level, show a blank icon to line things up
                 $icon = $this->output->skin->get_icon('blank');
             }
         } else {
             $icon = '';
         }
         $a[] = '    ' . html_table_cell($attributes, ltrim($icon . ' ' . dialog_get_label($item)));
         //
         // column 2 - role
         //
         $widget = dialog_get_widget($item);
         if (is_array($widget)) {
             $a[] = '    ' . html_table_cell($attributes);
             // add every radio button on a separate line
             $postfix = $item['type'] == F_RADIO ? '<br>' : '';
             foreach ($widget as $widget_line) {
                 $a[] = '      ' . $widget_line . $postfix;
             }
             $a[] = '    ' . html_table_cell_close();
         } else {
             $a[] = '    ' . html_table_cell($attributes, $widget);
         }
         //
         // column 3 (optional) - related items in a single comma delimited string
         //
         if ($show_related) {
             $related = isset($item['related']) && !empty($item['related']) ? $item['related'] : '';
             $cell_content = is_array($related) ? implode(',<br>', $related) : $related;
             $a[] = '    ' . html_table_cell($attributes, $cell_content);
         }
         $a[] = '  ' . html_table_row_close();
     }
     $a[] = html_table_close();
     // now handle the postponed fields such as the Save and Cancel buttons and the hidden fields
     if (sizeof($postponed) > 0) {
         foreach ($postponed as $item) {
             $a[] = dialog_get_widget($item);
         }
     }
     $a[] = html_form_close();
     return $a;
 }
 /** construct a simple jumplist to navigate to other areas
  *
  * this constructs a listbox with areas to which the current user has access.
  * The user can pick an area from the list and press the [Go] button to navigate
  * to that area. Only the active areas are displayed. Private areas are only displayed
  * when the user actually has access to those areas.
  *
  * This routine always shows the Submit-button even when JavaScript is turned 'off'. If it is 'on',
  * a tiny snippet auto-submits the form whenever the user selects another area; no need
  * press any button anymore. However, pressing the Go button is necessary when Javascript is 'off'.
  * Rationale: the user will find out soon enough that pressing the button is superfluous, and
  * as a benefit we keep the same look and feel no matter the state of Javascript.
  *
  * We rely on the constructor to provide us with an array of area_id=>area_title pairs
  * in the $this->jumps array.
  *
  * The special preview-mode is implemented by adding the necessary hash in the preview parameter
  * via a hidden field. This will ultimately lead to ourselves, with the preview code so we can
  * never leave for another area in preview mode.
  *
  * @param string $m add readabiliy to output
  * @return string properly indented ready-to-use HTML or an empty string on error
  * @uses dialog_get_widget()
  */
 function get_jumpmenu($m = '')
 {
     // 1 -- KISS form with a whiff of javascript (but don't  get rid of the Go-button)
     $title = t('jumpmenu_area_title', $this->domain);
     $attributes = array('name' => 'area', 'title' => $title, 'onchange' => 'this.form.submit();');
     $jumpmenu = $m . html_form(was_node_url(), 'get') . "\n" . $m . '  ' . t('jumpmenu_area', $this->domain) . "\n";
     // 2 -- maybe add the hidden field that keeps us in preview-mode
     if ($this->preview_mode) {
         $hash = md5($_SESSION['preview_salt'] . $_SESSION['preview_node']);
         $jumpmenu .= $m . '  ' . html_tag('input', array('type' => 'hidden', 'name' => 'preview', 'value' => $hash)) . "\n";
     }
     // 3 -- add a select box with available areas
     $jumpmenu .= $m . "  " . html_tag('select', $attributes) . "\n";
     foreach ($this->jumps as $k => $v) {
         $attributes = array('title' => $title, 'value' => $k);
         if ($k == $this->area_id) {
             $attributes['selected'] = NULL;
         }
         $jumpmenu .= $m . '    ' . html_tag('option', $attributes, $v) . "\n";
     }
     $jumpmenu .= $m . "  </select>\n";
     // 4 -- add button and close all open tags.
     $jumpmenu .= $m . "  " . dialog_get_widget(dialog_buttondef(BUTTON_GO)) . "\n" . $m . html_form_close() . "\n";
     return $jumpmenu;
 }
 /** render a translation dialog based on a dialog definition
  *
  * This routine looks a bit like the generic {@link dialog_quickform()}.
  * The differences are:
  *  - we show a comment (if any) in a box before label and input
  *  - the labels don't have hotkeys based on tildes at all (except the submit buttons)
  *  - comments and labels are wrapped in separate div's especially for the occasion
  *
  * We do take any errors into account: fields with errors are displayed using the
  * additional error class (which shows a label completely in red to indicate the error).
  *
  * @param string $href the target of the HTML form
  * @param array &$dialogdef the array which describes the complete dialog
  * @param string $method method to submit data to the server, either 'post' or 'get'
  * @param string|array $attributes holds the attributes to add to the form tag
  * @return array constructed HTML-form with dialog, one line per array element
  * @uses html_form()
  */
 function render_translation_dialog($href, &$dialogdef, $method = 'post', $attributes = '')
 {
     $buttons_seen = FALSE;
     $a = array(0 => html_form($href, $method, $attributes));
     // result starts with opening a form tag
     foreach ($dialogdef as $item) {
         if (!isset($item['name'])) {
             // skip spurious item (possibly empty array)
             continue;
         }
         if (isset($item['comment']) && !empty($item['comment'])) {
             $a[] = '<div class="translatetool_comment">';
             $a[] = $item['comment'];
             $a[] = '</div>';
         }
         if (isset($item['label']) && !empty($item['label'])) {
             $errorclass = isset($item['errors']) && $item['errors'] > 0 ? ' error' : '';
             $a[] = sprintf('<div class="translatetool_label%s">', $errorclass);
             $a[] = $item['label'];
             $a[] = '</div>';
         }
         $widget = dialog_get_widget($item);
         if (is_array($widget)) {
             // add every radio button on a separate line
             $postfix = $item['type'] == F_RADIO ? '<br>' : '';
             foreach ($widget as $widget_line) {
                 $a[] = $widget_line . $postfix;
             }
         } else {
             // quick and dirty:
             // add a <p> before the first button in a dialog
             // add a <p> after every regular input item except buttons and hidden fields
             // result: fields line up nicely and buttons are on a single row
             $postfix = '';
             if ($item['type'] == F_SUBMIT) {
                 if (!$buttons_seen) {
                     $buttons_seen = TRUE;
                     $a[] = '<p>';
                 }
             } elseif (!(isset($item['hidden']) && $item['hidden'])) {
                 $postfix = '<p>';
             }
             $a[] = $widget . $postfix;
         }
     }
     $a[] = '<p>';
     $a[] = html_form_close();
     return $a;
 }