[dev] [patch] Implement Horde_UI_VarRenderer:: (rev 2)

Jason M. Felice jfelice at cronosys.com
Tue Dec 2 08:26:22 PST 2003


This patch implements the Horde_UI_VarRenderer:: class.  It moves variable
rendering out of Horde_Form_Renderer:: into this class so that it can be used
from other code.

This revision also patches lib/Form/Renderer/rows.php, which I had missed in
the first revision.
      
-------------- next part --------------
epm diff framework/UI/package.xml
--- framework/UI/package.xml	2003-12-02 10:56:25.000000000 -0500
+++ framework/UI/package.xml	2003-12-02 10:58:20.000000000 -0500
@@ -35,12 +35,18 @@
       <dir role="php" baseinstalldir="/Horde" name="UI">
         <file name="Language.php" />
         <file name="Tabs.php" />
+        <file name="VarRenderer.php" />
+        <dir role="php" name="VarRenderer">
+          <file name="html.php" />
+        </dir>
         <file name="Widget.php" />
       </dir>
     </filelist>
 
     <provides type="class" name="Horde_UI_Language" />
     <provides type="class" name="Horde_UI_Tabs" />
+    <provides type="class" name="Horde_UI_VarRenderer" />
+    <provides type="class" name="Horde_UI_VarRenderer_html" />
     <provides type="class" name="Horde_UI_Widget" />
 
   </release>
epm diff lib/Form/Renderer.php
--- lib/Form/Renderer.php	2003-12-02 10:56:25.000000000 -0500
+++ lib/Form/Renderer.php	2003-12-02 11:04:18.000000000 -0500
@@ -22,6 +22,7 @@
     var $_onLoadJS = array();
     var $_showHeader = true;
     var $_cols = 2;
+    var $_varRenderer = null;
 
     /**
      * Width of the attributes column, in percent.
@@ -38,6 +39,9 @@
     function Horde_Form_Renderer($params = array())
     {
         $this->_requiredMarker = Horde::img('required.gif', '*', '', $GLOBALS['registry']->getParam('graphics', 'horde'));
+
+        require_once 'Horde/UI/VarRenderer.php';
+        $this->_varRenderer = Horde_UI_VarRenderer::factory('html');
     }
 
     function showHeader($bool)
@@ -201,18 +205,14 @@
                     break;
 
                 default:
-                    $format = (!$active || $var->isReadonly()) ? 'Display' : 'Input';
+                    $isInput = ($active && !$var->isReadonly());
+                    $format = $isInput ? 'Input' : 'Display';
                     $begin = "_renderVar${format}Begin";
                     $end = "_renderVar${format}End";
-                    $method = "_renderVar${format}_$type";
 
                     $this->$begin($form, $var, $vars);
 
-                    if (@method_exists($this, $method) == false) {
-                        $method = "_renderVar${format}Default";
-                    }
-
-                    $this->$method($form, $var, $vars);
+                    $this->_varRenderer->render($form, $var, $vars, $isInput);
                     $this->$end($form, $var, $vars);
 
                     if ($var->hasAction()) { ?><script language="JavaScript" type="text/javascript">
@@ -262,13 +262,7 @@
     function _renderEnd()
     {
 ?></table><?php
-        if (count($this->_onLoadJS)): ?>
-<script language="JavaScript" type="text/javascript">
-<!--
-<?php echo implode("\n", $this->_onLoadJS); ?>
-// -->
-</script>
-<?php endif;
+        $this->_varRenderer->renderEnd();
     }
 
     function _renderHeader($header, $error = '')
@@ -342,579 +336,6 @@
 <?php
     }
 
-    function _renderVarInputDefault(&$form, &$var, &$vars)
-    {
-?><strong>Warning:</strong> Unknown variable type <?php echo $var->getTypeName() ?><?php
-    }
-
-    function _renderVarInput_number(&$form, &$var, &$vars, $index = null)
-    {
-?><input type="text" size="5" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
-<?php
-    }
-
-    function _renderVarInput_int(&$form, &$var, &$vars, $index = null)
-    {
-?><input type="text" size="5" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
-<?php
-    }
-
-    function _renderVarInput_intlist(&$form, &$var, &$vars, $index = null)
-    {
-?><input type="text" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
-<?php
-    }
-
-    function _renderVarInput_text(&$form, &$var, &$vars, $index = null)
-    {
-        $maxlength = $var->type->getMaxLength();
-        if (!empty($maxlength)) {
-            $maxlength = ' maxlength="' . $maxlength . '"';
-        }
-?><input <?php echo $this->_genID($var->getVarName(), $index) ?>type="text" <?php echo $var->isDisabled() ? 'disabled="disabled" ' : '' ?>size="<?php echo $var->type->getSize() ?>"<?php echo $maxlength ?> name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" <?php if ($var->hasAction()) $this->_genActionScript($form, $var->_action, $var->getVarName(), $index) ?> />
-<?php
-    }
-
-    function _renderVarInput_stringlist(&$form, &$var, &$vars, $index = null)
-    {
-?><input type="text" size="60" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
-<?php
-    }
-
-    function _renderVarInput_file(&$form, &$var, &$vars, $index = null)
-    {
-?><input type="file" size="30" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
-<?php
-    }
-
-    /**
-     * @todo Show image dimensions in the width/height boxes.
-     */
-    function _renderVarInput_image(&$form, &$var, &$vars, $index = null)
-    {
-        $varname = $var->getVarName();
-        $var_array = $var->getValue($vars, $index);
-
-        Horde::addScriptFile('image.js', 'horde');
-        $graphics_dir = $GLOBALS['registry']->getParam('graphics', 'horde');
-        $img_dir = $graphics_dir . '/image';
-
-        if (isset($var_array['img'])) {
-            /* Hidden tag to store the preview image filename. */
-            printf('<input type="hidden" name="%s" value="%s" %s />',
-                   $varname . '[img]',
-                   htmlspecialchars($var_array['img'], ENT_QUOTES, NLS::getCharset()),
-                   $this->_genID($varname . '[img]'));
-        }
-
-        $upload = $vars->getVar($varname);
-        $upload['img'] = @unserialize($upload['img']);
-
-        /* Output the input tag. */
-        if (empty($upload['img'])) {
-            $js = "var p = document.getElementById('" . $varname . "[preview]'); o = '\\\\'; a = '/'; tmp = '' + document.getElementById('" . $varname . "[new]').value; if (tmp) { while (tmp.indexOf(o) > -1) { pos = tmp.indexOf(o); tmp = '' + (tmp.substring(0, pos) + a + tmp.substring((pos + o.length), tmp.length));}; p.src = 'file:///' + tmp; };";
-            $browser = &Browser::singleton();
-            if ($browser->isBrowser('msie')) {
-                printf('<input type="file" size="30" name="%s" id="%s" onchange="%s" />',
-                       $varname . '[new]',
-                       $varname . '[new]',
-                       $js);
-            } else {
-                printf('<input type="file" size="30" name="%s" id="%s" onclick="window.setTimeout(\'this.blur();\', 5);" onblur="%s" />',
-                       $varname . '[new]',
-                       $varname . '[new]',
-                       $js);
-            }
-        } else {
-                printf('<input type="file" size="30" name="%s" />',
-                       $varname . '[new]');
-        }
-
-        /* Output the button to upload/reset the image. */
-        echo '&nbsp;';
-        printf('<input class="button" name="%s" type="submit" value="%s" /> ',
-               '_do_' . $varname,
-               _("Upload"));
-
-        if (empty($upload['img'])) {
-            echo Horde::img('tree/blank.gif', _("Preview"), 'width="50" height="40" align="top" id="' . $varname . '[preview]"', $graphics_dir);
-        }
-
-        if (!empty($upload['img'])) {
-            /* Add all the buttons to control the image editing. */
-            echo '<br />';
-            $img = Horde::url($GLOBALS['registry']->getParam('webroot', 'horde') . '/services/images/view.php');
-            if (isset($upload['img']['vfs_id'])) {
-                /* Calling an image from VFS. */
-                $img = Util::addParameter($img, array('f' => $upload['img']['vfs_id'],
-                                                       's' => 'vfs',
-                                                       'p' => $upload['img']['vfs_path']));
-            } else {
-                /* Calling an image from a tmp directory (uploads). */
-                $img = Util::addParameter($img, 'f', $upload['img']['file']);
-            }
-
-            /* Rotate 270. */
-            echo Horde::link('#', '', '', '', 'showImage(\'' . Util::addParameter($img, array('a' => 'rotate', 'v' => '270')) . '\', \'_p_' . $varname . '\', true);') . Horde::img('rotate-270.png', _("Rotate Left"), 'align="middle"', $img_dir) . '</a>';
-
-            /* Rotate 180. */
-            echo Horde::link('#', '', '', '', 'showImage(\'' . Util::addParameter($img, array('a' => 'rotate', 'v' => '180')) . '\', \'_p_' . $varname . '\', true);') . Horde::img('rotate-180.png', _("Rotate 180"), 'align="middle"', $img_dir) . '</a>';
-
-            /* Rotate 90. */
-            echo Horde::link('#', '', '', '', 'showImage(\'' . Util::addParameter($img, array('a' => 'rotate', 'v' => '90')) . '\', \'_p_' . $varname . '\', true);') . Horde::img('rotate-90.png', _("Rotate Right"), 'align="middle"', $img_dir) . '</a>';
-
-            /* Flip image. */
-            echo Horde::link('#', '', '', '', 'showImage(\'' . Util::addParameter($img, 'a', 'flip') . '\', \'_p_' . $varname . '\', true);') . Horde::img('flip.png', _("Flip"), 'align="middle"', $img_dir) . '</a>';
-
-            /* Mirror image. */
-            echo Horde::link('#', '', '', '', 'showImage(\'' . Util::addParameter($img, 'a', 'mirror') . '\', \'_p_' . $varname . '\', true);') . Horde::img('mirror.png', _("Mirror"), 'align="middle"', $img_dir) . '</a>';
-
-            /* Apply grayscale. */
-            echo Horde::link('#', '', '', '', 'showImage(\'' . Util::addParameter($img, 'a', 'grayscale') . '\', \'_p_' . $varname . '\', true);') . Horde::img('grayscale.gif', _("Grayscale"), 'align="middle"', $img_dir) . '</a>';
-
-            /* Resize width. */
-            printf('%s<input type="text" size="4" onChange="src=getResizeSrc(\'%s\', \'%s\');showImage(src, \'_p_%s\', true);" %s />',
-                   _("w:"),
-                   Util::addParameter($img, 'a', 'resize'),
-                   $varname,
-                   $varname,
-                   $this->_genID('_w_' . $varname, $index));
-
-            /* Resize height. */
-            printf('%s<input type="text" size="4" onChange="src=getResizeSrc(\'%s\', \'%s\');showImage(src, \'_p_%s\', true);" %s />',
-                   _("h:"),
-                   Util::addParameter($img, 'a', 'resize'),
-                   $varname,
-                   $varname,
-                   $this->_genID('_h_' . $varname, $index));
-
-            /* Apply fixed ratio resize. */
-            echo Horde::link('#', '', '', '', 'src=getResizeSrc(\'' . Util::addParameter($img, 'a', 'resize') . '\', \'' . $varname . '\', \'1\');showImage(src, \'_p_' . $varname . '\', true);') . Horde::img('ratio.png', _("Fix ratio"), 'align="middle"', $img_dir) . '</a>';
-
-            /* Keep also original. */
-            printf('<input type="checkbox" name="%s"%s />%s<br />' . "\n",
-                   $varname . '[keep_orig]',
-                   !empty($upload['keep_orig']) ? ' checked="checked"' : '',
-                   _("Keep original?"));
-
-            /* The preview image element. */
-            echo '<img src="' . $img . '" ' . $this->_genID('_p_' . $varname, $index) . ">\n";
-        }
-    }
-
-    function _renderVarInput_longtext(&$form, &$var, &$vars, $index = null)
-    {
-        global $browser;
-
-        $id = $this->_genID($var->getVarName(), $index, false);
-
-        printf('<textarea id="%s" name="%s" cols="%s" rows="%s">%s</textarea>',
-               $id,
-               $var->getVarName(),
-               $var->type->getCols(),
-               $var->type->getRows(),
-               $var->getValue($vars, $index));
-
-        if ($var->type->hasHelper('rte') && $browser->hasFeature('rte')) {
-            require_once HORDE_BASE . '/lib/Editor.php';
-            $editor = &Horde_Editor::singleton('htmlarea');
-            $editor->runEditor($id);
-        }
-
-        if ($var->type->hasHelper() && $browser->hasFeature('javascript')) {
-            echo '<br /><table border="0" cellpadding="1" cellspacing="0"><tr><td>';
-            Horde::addScriptFile('open_html_helper.js', 'horde');
-            $imgId = $this->_genID($var->getVarName(), $index, false) . 'goto';
-            if ($var->type->hasHelper('emoticons')) {
-                echo Horde::link('', _("Emoticons"), '', '', 'openHtmlHelper(\'emoticons\', \'' . $var->getVarName() . '\'); return false;') . Horde::img('smile.gif', _("Emoticons"), 'id="' . $imgId . '" align="middle"', $GLOBALS['registry']->getParam('graphics', 'horde') . '/emoticons') . '</a>';
-            }
-            echo '</td></tr><tr><td><div ' . $this->_genID('htmlhelper_' . $var->getVarName(), $index) . ' class="control"></div></td></tr></table>' . "\n";
-        }
-    }
-
-    function _renderVarInput_countedtext(&$form, &$var, &$vars, $index = null)
-    {
-?><textarea name="<?php echo $var->getVarName() ?>" cols="<?php echo $var->type->getCols() ?>" rows="<?php echo $var->type->getRows() ?>"><?php echo $var->getValue($vars, $index) ?></textarea>
-<?php
-    }
-
-    function _renderVarInput_address(&$form, &$var, &$vars, $index = null)
-    {
-?><textarea <?php echo $this->_genID($var->getVarName(), $index) ?> name="<?php echo $var->getVarName() ?>" cols="<?php echo $var->type->getCols() ?>" rows="<?php echo $var->type->getRows() ?>"><?php echo $var->getValue($vars, $index) ?></textarea>
-<?php
-    }
-
-    function _renderVarInput_date(&$form, &$var, &$vars, $index = null)
-    {
-?><input type="text" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
-<?php
-    }
-
-    function _renderVarInput_time(&$form, &$var, &$vars, $index = null)
-    {
-?><input type="text" size="5" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
-<?php
-    }
-
-    function _renderVarInput_hourminutesecond(&$form, &$var, &$vars, $index = null)
-    {
-        $hours = array('' => _("HH"));
-        for ($i = 0; $i <= 23; $i++) {
-            $hours[sprintf('%02d', $i)] = $i;
-        }
-        $minutes = array('' => _("MM"));
-        for ($i = 0; $i <= 59; $i++) {
-            $minutes[sprintf('%02d', $i)] = $i;
-        }
-        $seconds = array('' => _("SS"));
-        for ($i = 0; $i <= 59; $i++) {
-            $seconds[sprintf('%02d', $i)] = $i;
-        }
-        $time = $var->type->getTimeParts($var->getValue($vars, $index));
-?>
-<select name="<?php echo $var->getVarName() ?>[hour]" id="<?php echo $var->getVarName() ?>[hour]"><?php echo $this->_selectOptions($hours, $time['hour']) ?></select>
-<select name="<?php echo $var->getVarName() ?>[minute]" id="<?php echo $var->getVarName() ?>[minute]"><?php echo $this->_selectOptions($minutes, $time['minute']) ?></select>
-<select name="<?php echo $var->getVarName() ?>[second]" id="<?php echo $var->getVarName() ?>[second]"><?php echo $this->_selectOptions($seconds, $time['second']) ?></select>
-<?php
-    }
-
-    function _renderVarInput_monthyear(&$form, &$var, &$vars, $index = null)
-    {
-        $months = array('' => _("MM"),
-                        1 => _("January"),
-                        2 => _("February"),
-                        3 => _("March"),
-                        4 => _("April"),
-                        5 => _("May"),
-                        6 => _("June"),
-                        7 => _("July"),
-                        8 => _("August"),
-                        9 => _("September"),
-                        10 => _("October"),
-                        11 => _("November"),
-                        12 => _("December"));
-        $years = array('' => _("YYYY"));
-        if ($var->type->_start_year > $var->type->_end_year) {
-            for ($i = $var->type->_start_year; $i >= $var->type->_end_year; $i--) {
-                $years[$i] = $i;
-            }
-        } else {
-            for ($i = $var->type->_start_year; $i <= $var->type->_end_year; $i++) {
-                $years[$i] = $i;
-            }
-        }
-?><select name="<?php echo $var->type->getMonthVar($var) ?>"><?php echo $this->_selectOptions($months, $vars->getVar($var->type->getMonthVar($var))) ?></select>
-<select name="<?php echo $var->type->getYearVar($var) ?>"><?php echo $this->_selectOptions($years, $vars->getVar($var->type->getYearVar($var))) ?></select>
-<?php
-    }
-
-    function _renderVarInput_monthdayyear(&$form, &$var, &$vars, $index = null)
-    {
-        $months = array(''   => _("MM"),
-                        '1'  => _("January"),
-                        '2'  => _("February"),
-                        '3'  => _("March"),
-                        '4'  => _("April"),
-                        '5'  => _("May"),
-                        '6'  => _("June"),
-                        '7'  => _("July"),
-                        '8'  => _("August"),
-                        '9'  => _("September"),
-                        '10' => _("October"),
-                        '11' => _("November"),
-                        '12' => _("December"));
-        $days = array('' => _("DD"));
-        for ($i = 1; $i <= 31; $i++) {
-            $days[$i] = $i;
-        }
-        $years = array('' => _("YYYY"));
-        if ($var->type->_start_year > $var->type->_end_year) {
-            for ($i = $var->type->_start_year; $i >= $var->type->_end_year; $i--) {
-                $years[$i] = $i;
-            }
-        } else {
-            for ($i = $var->type->_start_year; $i <= $var->type->_end_year; $i++) {
-                $years[$i] = $i;
-            }
-        }
-        $date = $var->type->getDateParts($var->getValue($vars, $index));
-?>
-<select name="<?php echo $var->getVarName() ?>[month]" id="<?php echo $var->getVarName() ?>[month]"><?php echo $this->_selectOptions($months, $date['month']) ?></select>
-<select name="<?php echo $var->getVarName() ?>[day]" id="<?php echo $var->getVarName() ?>[day]"><?php echo $this->_selectOptions($days, $date['day']) ?></select>
-<select name="<?php echo $var->getVarName() ?>[year]" id="<?php echo $var->getVarName() ?>[year]"><?php echo $this->_selectOptions($years, $date['year']) ?></select>
-<?php
-        if ($var->type->_picker && $GLOBALS['browser']->hasFeature('javascript')) {
-            Horde::addScriptFile('open_calendar.js', 'horde');
-            $imgId = $this->_genID($var->getVarName(), $index, false) . 'goto';
-            echo '<div id="goto" class="control" style="position:absolute;visibility:hidden;padding:1px"></div>';
-            echo Horde::link('', _("Select a date"), '', '', 'openCalendar(\'' . $imgId . '\', \'' . $var->getVarName() . '\'); return false;') . Horde::img('calendar.gif', _("Calendar"), 'id="' . $imgId . '" align="middle"', $GLOBALS['registry']->getParam('graphics', 'horde')) . "</a>\n";
-        }
-    }
-
-    function _renderVarInput_colorpicker(&$form, &$var, &$vars, $index = null)
-    {
-        global $registry, $browser;
-?><table border="0" cellpadding="0" cellspacing="0"><tr><td><input type="text" size="10" maxlength="7" name="<?php echo $var->getVarName() ?>" id="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" /></td><?php
-        if ($browser->hasFeature('javascript')) {
-            Horde::addScriptFile('open_colorpicker.js', 'horde');
-            echo '<td width="20" id="colordemo_' . $var->getVarName() . '" style="background-color:' . $var->getValue($vars, $index) . '"> </td>';
-            echo '<td>' . Horde::link('#', _("Color Picker"), 'widget', '', 'openColorPicker(\'' . $var->getVarName() . '\'); return false;') . Horde::img('colorpicker.gif', _("Color Picker"), 'height="16"', $registry->getParam('graphics', 'horde')) . '</a></td>';
-            echo '<td><div id="colorpicker_' . $var->getVarName() . '" class="control"></div></td>';
-        }
-?></tr></table>
-<?php
-    }
-
-    function _renderVarInput_sorter(&$form, &$var, &$vars, $index = null)
-    {
-        global $registry;
-
-        $varname = $var->getVarName();
-        $instance = $var->type->_instance;
-
-        Horde::addScriptFile('sorter.js', 'horde');
-
-        echo '<input type="hidden" name="' . $varname . '[array]" value="" ' . $this->_genID($varname . '[array]') . ' />';
-        echo '<table border="0" cellpadding="0" cellspacing="0"><tr><td>';
-        echo '<select multiple="multiple" size="' . $var->type->getSize() . '" name="' . $varname . '[list]" onchange="' . $instance . '.deselectHeader();" ' . $this->_genID($varname . '[list]') . '>';
-        echo $var->type->getOptions();
-        echo '</select></td><td>';
-        echo Horde::link('#', _("Move up"), '', '', $instance . '.moveColumnUp(); return false;') . Horde::img('nav/up.gif', _("Move up"), '', $registry->getParam('graphics', 'horde')) . '</a><br />';
-        echo Horde::link('#', _("Move up"), '', '', $instance . '.moveColumnDown(); return false;') . Horde::img('nav/down.gif', _("Move down"), '', $registry->getParam('graphics', 'horde')) . '</a></td></tr></table>';
-        echo '<script language="JavaScript" type="text/javascript">' . "\n";
-        printf('%1$s = new Horde_Form_Sorter(\'%1$s\', \'%2$s\', \'%3$s\');' . "\n",
-               $instance, $varname, $var->type->getHeader());
-
-        printf("%s.setHidden();\n</script>\n",
-               $instance);
-    }
-
-    function _renderVarInput_invalid(&$form, &$var, &$vars, $index = null)
-    {
-        return $this->_renderVarDisplay_invalid($form, $var, $vars);
-    }
-
-    function _renderVarInput_enum(&$form, &$var, &$vars, $index = null)
-    {
-        $values = $var->getValues();
-        $prompt = $var->type->getPrompt();
-        $selected = $var->getValue($vars, $index);
-?><select <?php echo $this->_genID($var->getVarName(), $index) ?> name="<?php echo $var->getVarName() ?>"<?php if ($var->hasAction()) $this->_genActionScript($form, $var->_action, $var->getVarName(), $index) ?>>
-  <?php if (!empty($prompt)) { echo '<option value="">' . htmlspecialchars($prompt, ENT_QUOTES, NLS::getCharset()) . '</option>'; } echo $this->_selectOptions($values, $selected) ?>
-  </select>
-<?php
-    }
-
-    function _renderVarInput_multienum(&$form, &$var, &$vars, $index = null)
-    {
-        $values = $var->getValues();
-        $selected = $vars->getVarWasset($var->getVarName(), $wasset);
-        if (!$wasset) {
-            $selected = $var->getDefault();
-        }
-?><select multiple="multiple" size="<?php echo $var->type->size ?>" name="<?php echo $var->getVarName() ?>[]">
-  <?php echo $this->_multiSelectOptions($values, $selected) ?>
-  </select>
-<?php
-        echo "<br />\n" . _("To select multiple items, hold down the Control (PC) or Command (Mac) key while clicking.") . "\n";
-    }
-
-    function _renderVarInput_radio(&$form, &$var, &$vars, $index = null)
-    {
-        $values = $var->getValues();
-        $value  = $var->getValue($vars, $index);
-        echo $this->_radioButtons($var->getVarName(), $values, $value);
-    }
-
-    function _renderVarInput_set(&$form, &$var, &$vars, $index = null)
-    {
-        $values = $var->getValues();
-        $value  = $var->getValue($vars, $index);
-        echo $this->_checkBoxes($var->getVarName(), $values, $value);
-    }
-
-    function _renderVarInput_link(&$form, &$var, &$vars, $index = null)
-    {
-        return _renderVarDisplay_link($form, $var, $vars);
-    }
-
-    function _renderVarInput_email(&$form, &$var, &$vars, $index = null)
-    {
-?><input type="text" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
-<?php
-    }
-
-    function _renderVarInput_blockselect(&$form, &$var, &$vars, $index = null)
-    {
-        $varname = $var->getVarName();
-        $var_array = $var->type->getBlockArray($var->getValue($vars, $index));
-        $blocks = $var->type->getBlocks();
-        $block_select = $var->type->getBlockSelect();
-
-        if (isset($var_array['old'])) {
-            /* Hidden tag to store previous block values. */
-            printf('<input type="hidden" name="%s" value="%s" %s />',
-                   $varname . '[old]',
-                   htmlspecialchars($var_array['old'], ENT_QUOTES, NLS::getCharset()),
-                   $this->_genID($varname . '[old]'));
-        }
-
-        /* Output the block name selection box. */
-        printf('<select %s name="%s" %s><option value="">%s</option>%s</select><br />',
-               $this->_genID($varname . '[name]', $index),
-               $varname . '[name]',
-               ($var->hasAction() ? $this->_genActionScript($form, $var->_action, $varname . '[block]', $index) : ''),
-               _("-- select --"),
-               $this->_selectOptions($block_select, $var_array['name']));
-
-        /* If name has been selected, output the block params input. */
-        if (!empty($var_array['name'])) {
-            list($this_app, $this_type) = explode(':', $var_array['name']);
-            $this_block = $blocks[$this_app][$this_type];
-            /* Go through the params of this block and set up any required
-             * extra input. */
-            foreach ($this_block['params'] as $param_id => $param) {
-                $value = (isset($var_array['params'][$param_id]) ? $var_array['params'][$param_id] : '');
-                $value = $var->type->setValue($value, $param);
-                /* Figure out what type of extra input is required. */
-                switch ($param['type']) {
-                case 'enum':
-                    /* Simple selection box. */
-                    printf('%s: <select %s name="%s" %s><option value="">%s</option>%s</select><br />',
-                           $param['name'],
-                           $this->_genID($varname . '[params][' . $param_id . ']', $index),
-                           $varname . '[params][' . $param_id . ']',
-                           ($var->hasAction() ? $this->_genActionScript($form, $var->_action, $varname . '[params]' . $param_id . ']', $index) : ''),
-                           _("-- select --"),
-                           $this->_selectOptions($param['values'], $value));
-                    break;
-
-                case 'mlenum':
-                    /* Multiple level selection box. */
-                    $first_level = array_flip(array_keys($param['values']));
-                    foreach ($first_level as $key => $val) {
-                        $first_level[$key] = $key;
-                    }
-                    printf('%s: <select %s name="%s" %s><option value="">%s</option>%s</select>',
-                           $param['name'],
-                           $this->_genID($varname . '[params][' . $param_id . '][1]', $index),
-                           $varname . '[params][' . $param_id . '][1]',
-                           ($var->hasAction() ? $this->_genActionScript($form, $var->_action, $varname . '[params]' . $param_id . '][1]', $index) : ''),
-                           _("-- select --"),
-                           $this->_selectOptions($first_level, $value[1]));
-                    if (!empty($value[1])) {
-                        if (!isset($value[2])) {
-                            $value[2] = '';
-                        }
-                        $second_level = $param['values'][$value[1]];
-                        printf('<select %s name="%s" %s><option value="">%s</option>%s</select><br />',
-                               $this->_genID($varname . '[params][' . $param_id . '][2]', $index),
-                               $varname . '[params][' . $param_id . '][2]',
-                               ($var->hasAction() ? $this->_genActionScript($form, $var->_action, $varname . '[params]' . $param_id . '][2]', $index) : ''),
-                               _("-- select --"),
-                               $this->_selectOptions($second_level, $value[2]));
-                    }
-                    break;
-
-                default:
-                    /* Default to a text input box. */
-                    printf('%s: <input %s type="text" size="%s" name="%s" %s value="%s" /><br />',
-                           $param['name'],
-                           $this->_genID($var->getVarName(), $index),
-                           '20',
-                           $varname . '[params][' . $param_id . ']',
-                           ($var->hasAction() ? $this->_genActionScript($form, $var->_action, $varname . '[params]' . $param_id . ']', $index) : ''),
-                           $value);
-                }
-            }
-        }
-    }
-
-    function _renderVarInput_matrix(&$form, &$var, &$vars, $index = null)
-    {
-        $varname   = $var->getVarName();
-        $var_array = $var->getValue($vars, $index);
-        $cols      = $var->type->getCols();
-        $rows      = $var->type->getRows();
-        $matrix    = $var->type->getMatrix();
-        $new_input = $var->type->getNewInput();
-
-        echo '<table border="0" cellpadding="0" cellspacing="0"><tr>';
-
-        echo '<td align="right" width="20%"></td>';
-        foreach ($cols as $col_title) {
-            printf('<td align="center" width="1%%">%s</td>', $col_title);
-        }
-        echo '<td align="right" width="60%"></td></tr>';
-
-        /* Offer a new row of data to be added to the matrix? */
-        if ($new_input) {
-            echo '<tr><td>';
-            if (is_array($new_input)) {
-                printf('<select %s name="%s[n][r]"><option value="">%s</option>%s</select><br />',
-                       $this->_genID($varname . '[n][r]', $index),
-                       $varname,
-                       _("-- select --"),
-                       $this->_selectOptions($new_input, $var_array['n']['r']));
-            } elseif ($new_input == true) {
-                printf('<input %s type="text" name="%s[n][r]" value="%s" />',
-                       $this->_genID($varname . '[n][r]', $index),
-                       $varname,
-                       $var_array['n']['r']);
-            }
-            echo ' </td>';
-            foreach ($cols as $col_id => $col_title) {
-                printf('<td align="center"><input type="checkbox" name="%s[n][v][%s]" /></td>', $varname, $col_id);
-            }
-            echo '<td> </td></tr>';
-        }
-
-        /* Loop through the rows and create checkboxes for each column. */
-        foreach ($rows as $row_id => $row_title) {
-            printf('<tr><td>%s</td>', $row_title);
-            foreach ($cols as $col_id => $col_title) {
-                printf('<td align="center"><input type="checkbox" name="%s[r][%s][%s]"%s /></td>', $varname, $row_id, $col_id, (!empty($matrix[$row_id][$col_id]) ? ' checked="checked"' : ''));
-            }
-            echo '<td> </td></tr>';
-        }
-
-        echo '</table>';
-    }
-
-    function _renderVarInput_password(&$form, &$var, &$vars, $index = null)
-    {
-?><input type="password" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
-<?php
-    }
-
-    function _renderVarInput_emailconfirm(&$form, &$var, &$vars, $index = null)
-    {
-        $email = $var->getValue($vars, $index);
-?><input type="text" name="<?php echo $var->getVarName() ?>[original]" value="<?php $email['original'] ?>" /><br />
-  <input type="text" name="<?php echo $var->getVarName() ?>[confirm]" value="<?php $email['confirm'] ?>" />
-<?php
-    }
-
-    function _renderVarInput_passwordconfirm(&$form, &$var, &$vars, $index = null)
-    {
-        $password = $var->getValue($vars, $index);
-?><input type="password" name="<?php echo $var->getVarName() ?>[original]" value="<?php echo $password['original'] ?>" /><br />
-  <input type="password" name="<?php echo $var->getVarName() ?>[confirm]" value="<?php echo $password['confirm'] ?>" />
-<?php
-    }
-
-    function _renderVarInput_boolean(&$form, &$var, &$vars, $index = null)
-    {
-?><input type="checkbox" name="<?php echo $var->getVarName() ?>"<?php echo $var->getValue($vars, $index) ? ' checked="checked"' : ''; if ($var->hasAction()) $this->_genActionScript($form, $var->_action, $var->getVarName(), $index) ?> />
-<?php
-    }
-
-    function _renderVarInput_creditcard(&$form, &$var, &$vars, $index = null)
-    {
-?><input type="text" name="<?php echo $var->getVarName() ?>"<?php echo $var->getValue($vars, $index); if ($var->hasAction()) $this->_genActionScript($form, $var->_action, $var->getVarName(), $index) ?> />
-<?php
-    }
-
     // Implementation specifics -- display variables.
     function _renderVarDisplayBegin(&$form, &$var, &$vars)
     {
@@ -930,271 +351,6 @@
 <?php
     }
 
-    function _renderVarDisplayDefault(&$form, &$var, &$vars, $index = null)
-    {
-        echo nl2br(htmlspecialchars($var->getValue($vars, $index), ENT_QUOTES, NLS::getCharset()));
-    }
-
-    function _renderVarDisplay_html(&$form, &$var, &$vars, $index = null)
-    {
-        echo $var->getValue($vars, $index);
-    }
-
-    function _renderVarDisplay_password(&$form, &$var, &$vars, $index = null)
-    {
-        echo htmlspecialchars('********', ENT_QUOTES, NLS::getCharset());
-    }
-
-    function _renderVarDisplay_passwordconfirm(&$form, &$var, &$vars, $index = null)
-    {
-        echo htmlspecialchars('********', ENT_QUOTES, NLS::getCharset());
-    }
-
-    function _renderVarDisplay_boolean(&$form, &$var, &$vars, $index = null)
-    {
-        echo $var->getValue($vars, $index) == 'on' ? _("On") : _("Off");
-    }
-
-    function _renderVarDisplay_enum(&$form, &$var, &$vars, $index = null)
-    {
-        $values = $var->getValues();
-        if (count($values) == 0) {
-            echo _("No values");
-        } elseif (isset($values[$var->getValue($vars, $index)]) && $var->getValue($vars, $index) != '') {
-            echo htmlspecialchars($values[$var->getValue($vars, $index)], ENT_QUOTES, NLS::getCharset());
-        }
-    }
-
-    function _renderVarDisplay_radio(&$form, &$var, &$vars, $index = null)
-    {
-        $values = $var->getValues();
-        if (count($values) == 0) {
-            echo _("No values");
-        } elseif (isset($values[$var->getValue($vars, $index)])) {
-            echo htmlspecialchars($values[$var->getValue($vars, $index)], ENT_QUOTES, NLS::getCharset());
-        }
-    }
-
-    function _renderVarDisplay_multienum(&$form, &$var, &$vars, $index = null)
-    {
-        $values = $var->getValues();
-        $on = $var->getValue($vars, $index);
-        if (!count($values) || !count($on)) {
-            echo _("No values");
-        } else {
-            $display = array();
-            foreach ($values as $value => $name) {
-                if (in_array($value, $on)) {
-                    $display[] = $name;
-                }
-            }
-            echo htmlspecialchars(implode(', ', $display), ENT_QUOTES, NLS::getCharset());
-        }
-    }
-
-    function _renderVarDisplay_set(&$form, &$var, &$vars, $index = null)
-    {
-        $values = $var->getValues();
-        $on = $var->getValue($vars, $index);
-        if (!count($values) || !count($on)) {
-            echo _("No values");
-        } else {
-            $display = array();
-            foreach ($values as $value => $name) {
-                if (in_array($value, $on)) {
-                    $display[] = $name;
-                }
-            }
-            echo htmlspecialchars(implode(', ', $display), ENT_QUOTES, NLS::getCharset());
-        }
-    }
-
-    function _renderVarDisplay_image(&$form, &$var, &$vars, $index = null)
-    {
-        $img_params = $var->getValue($vars, $index);
-        $img_url = Horde::url($GLOBALS['registry']->getParam('webroot', 'horde') . '/services/images/view.php');
-        $img_url = Util::addParameter($img_url, $img_params);
-        echo Horde::img($img_url, $img_params['f'], '', '');
-    }
-
-    function _renderVarDisplay_address(&$form, &$var, &$vars, $index = null)
-    {
-        $address = $var->getValue($vars, $index);
-
-        if (preg_match('/(.*)\n(.*)\s*,\s*(\w+)\.?\s+(\d+|[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d)/', $address, $addressParts)) {
-            /* American/Canadian address style. */
-            $mapurl = 'http://www.mapquest.com/maps/map.adp?size=big&zoom=7';
-            if (!empty($addressParts[1])) {
-                $mapurl .= '&address=' . urlencode($addressParts[1]);
-            }
-            if (!empty($addressParts[2])) {
-                $mapurl .= '&city=' . urlencode($addressParts[2]);
-            }
-            if (!empty($addressParts[3])) {
-                $mapurl .= '&state=' . urlencode($addressParts[3]);
-            }
-            if (!empty($addressParts[4])) {
-                $mapurl .= '&zipcode=' . urlencode($addressParts[4]);
-                if (preg_match('|[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d|', $addressParts[4])) {
-                    $mapurl .= '&country=CA';
-                }
-            }
-        } elseif (preg_match('/(.*)\nD-(\d{5})\s+(.*)/i', $address, $addressParts)) {
-            /* German address style. */
-            $mapurl = 'http://www.map24.de/map24/index.php3?maptype=RELOAD&country0=de&gcf=1';
-            if (!empty($addressParts[1])) {
-                $mapurl .= '&street0=' . urlencode($addressParts[1]);
-            }
-            if (!empty($addressParts[2])) {
-                $mapurl .= '&zip0=' . urlencode($addressParts[2]);
-            }
-            if (!empty($addressParts[3])) {
-                $mapurl .= '&city0=' . urlencode($addressParts[3]);
-            }
-        }
-        echo nl2br(htmlspecialchars($var->getValue($vars, $index), ENT_QUOTES, NLS::getCharset()));
-        if (!empty($mapurl)) {
-            global $registry;
-            echo Horde::link($mapurl, _("View map"), null, '_blank') . Horde::img('map.gif', _("View map"), 'align="middle"', $registry->getParam('graphics', 'horde')) . '</a>';
-        }
-    }
-
-    function _renderVarDisplay_date(&$form, &$var, &$vars, $index = null)
-    {
-        echo $var->type->getFormattedTimeFull($var->getValue($vars, $index));
-    }
-
-    function _renderVarDisplay_monthyear(&$form, &$var, &$vars, $index = null)
-    {
-        echo $vars->getVar($var->getVarName() . '[month]') . ', ' . $vars->getVar($var->getVarName() . '[year]');
-    }
-
-    function _renderVarDisplay_monthdayyear(&$form, &$var, &$vars, $index = null)
-    {
-        $date = $var->getValue($vars, $index);
-        if ((is_array($date) && !empty($date['year']) && !empty($date['month']) && !empty($date['day'])) || (!is_array($date) && !empty($date))) {
-            echo $var->type->formatDate($date);
-        }
-    }
-
-    function _renderVarDisplay_invalid(&$form, &$var, &$vars, $index = null)
-    {
-        echo '<span class="form-error">' . htmlspecialchars($var->type->message, ENT_QUOTES, NLS::getCharset()) . '</span>';
-    }
-
-    function _renderVarDisplay_link(&$form, &$var, &$vars, $index = null)
-    {
-        if (isset($var->type->values[0]) && is_array($var->type->values[0])) {
-            $count = count($var->type->values);
-            for ($i = 0; $i < $count; $i++) {
-                if (empty($var->type->values[$i]['url']) || empty($var->type->values[$i]['text'])) {
-                    continue;
-                }
-                if ($i > 0) {
-                    echo ' | ';
-                }
-                echo Horde::link($var->type->values[$i]['url'], $var->type->values[$i]['text'], 'widget') . $var->type->values[$i]['text'] . '</a>';
-            }
-        } else {
-            if (empty($var->type->values['url']) || empty($var->type->values['text'])) {
-                return;
-            }
-            echo Horde::link($var->type->values['url'], $var->type->values['text'], 'widget') . $var->type->values['text'] . '</a>';
-        }
-    }
-
-    function _selectOptions(&$values, $selectedValue = false)
-    {
-        $result = '';
-        $sel = false;
-        foreach ($values as $value => $display) {
-            if (!is_null($selectedValue) && !$sel && $value == $selectedValue) {
-                $selected = ' selected="selected"';
-                $sel = true;
-            } else {
-                $selected = '';
-            }
-            $result .= ' <option value="' . htmlspecialchars($value, ENT_QUOTES, NLS::getCharset()) . '"' . $selected . '>' . htmlspecialchars($display) . "</option>\n";
-        }
-
-        return $result;
-    }
-
-    function _multiSelectOptions(&$values, $selectedValues)
-    {
-        $result = '';
-        $sel = false;
-        foreach ($values as $value => $display) {
-            if (@in_array($value, $selectedValues)) {
-                $selected = ' selected="selected"';
-            } else {
-                $selected = '';
-            }
-            $result .= " <option value=\"" . htmlspecialchars($value, ENT_QUOTES, NLS::getCharset()) . "\"$selected>" . htmlspecialchars($display) . "</option>\n";
-        }
-
-        return $result;
-    }
-
-    function _checkBoxes($name, $values, $checkedValues)
-    {
-        $result = '';
-        if (!is_array($checkedValues)) {
-            $checkedValues = array();
-        }
-        $i = 0;
-        foreach ($values as $value => $display) {
-            $checked = (in_array($value, $checkedValues)) ? ' checked="checked"' : '';
-            $result .= "<input id=\"${name}${i}\" type=\"checkbox\" name=\"${name}[]\" value=\"$value\"$checked /><label for=\"${name}${i}\">&nbsp;$display</label><br />";
-            $i++;
-        }
-
-        return $result;
-    }
-
-    function _radioButtons($name, $values, $checkedValue = null)
-    {
-        $result = '';
-        $i = 0;
-        foreach ($values as $value => $display) {
-            $checked = (!is_null($checkedValue) && $value == $checkedValue) ? ' checked="checked"' : '';
-            $result .= "<input id=\"${name}${i}\" type=\"radio\" name=\"$name\" value=\"$value\"$checked /><label for=\"${name}${i}\">&nbsp;$display</label><br />";
-            $i++;
-        }
-
-        return $result;
-    }
-
-    function _genID($name, $index = null, $fulltag = true)
-    {
-        $name = str_replace('[]', '', $name);
-        if (!is_null($index)) {
-            $name .= $index;
-        }
-        return $fulltag ? 'id="' . htmlspecialchars($name, ENT_QUOTES, NLS::getCharset()) . '"' : $name;
-    }
-
-    function _genActionScript(&$form, $action, $varname, $index = null)
-    {
-        $triggers = $action->getTrigger();
-        if (!is_array($triggers)) {
-            $triggers = array($triggers);
-        }
-        $js = $action->getActionScript($form, $this, $varname, $index);
-        foreach ($triggers as $trigger) {
-            if ($trigger == 'onload') {
-                $this->_addOnLoadJavascript($js);
-            } else {
-                echo ' ' . $trigger . '="' . $js . '"';
-            }
-        }
-    }
-
-    function _addOnLoadJavascript($script)
-    {
-        $this->_onLoadJS[] = $script;
-    }
-
     function getRowClass($increment = true)
     {
         static $i = 1;
epm diff framework/UI/UI/VarRenderer.php
--- framework/UI/UI/VarRenderer.php	1969-12-31 19:00:00.000000000 -0500
+++ framework/UI/UI/VarRenderer.php	2003-12-02 10:56:25.000000000 -0500
@@ -0,0 +1,103 @@
+<?php
+/**
+ * The Horde_UI_VarRenderer:: class provides base functionality for other Horde
+ * UI elements.
+ *
+ * $Horde: $
+ *
+ * Copyright 2003 Jason M. Felice <jfelice at cronosys.com>
+ *
+ * See the enclosed file LICENSE for license information (LGPL).
+ *
+ * @version $Revision: 1.6 $
+ * @since   Horde_UI 0.0.1
+ * @package Horde_UI
+ */
+class Horde_UI_VarRenderer {
+
+    /**
+     * Parameters which change this renderer's behavior.
+     * @var array $_params
+     */
+    var $_params;
+
+    /**
+     * Construct a new renderer.
+     *
+     * @access public
+     *
+     * @param array $params    The name of the variable which will track this
+     *                         UI widget's state.
+     */
+    function Horde_UI_VarRenderer($params = array())
+    {
+        $this->_params = $params;
+    }
+
+    /**
+     * Construct a new Horde_UI_VarRenderer:: instance.
+     * 
+     * @param string $driver            This is the renderer subclass we
+     *                                  will instantiate.
+     * @param optional array $params    parameters specific to the subclass
+     * @return object a Horde_UI_VarRenderer:: subclass instance.
+     */
+    function &factory($driver, $params = array())
+    {
+        $class = 'Horde_UI_VarRenderer_' . $driver;
+        require_once 'Horde/UI/VarRenderer/' . $driver . '.php';
+        return new $class($params);
+    }
+
+    /**
+     * Return a Horde_UI_VarRenderer:: instance, constructing one with
+     * the specified parameters if necessary.
+     * 
+     * @param string $driver            This is the renderer subclass we
+     *                                  will instantiate.
+     * @param optional array $params    parameters specific to the subclass
+     * @return object a Horde_UI_VarRenderer:: subclass instance.
+     */
+    function &singleton($driver, $params = array())
+    {
+        static $cache;
+
+        if (is_null($driver)) {
+            $class = 'Horde_UI_VarRenderer';
+        }
+        $key = serialize(array ($driver, $params));
+        if (!isset($cache[$key])) {
+            $cache[$key] = &Horde_UI_VarRenderer::factory($driver, $params);
+        }
+        return $cache[$key];
+    }
+
+    /**
+     * Render a variable.
+     *
+     * @param object &$form             Reference to a Horde_Form:: instance,
+     *                                  or null if none is available.
+     * @param object &$var              Reference to a Horde_Form_Var::
+     * @param object &$vars             A Horde_Form_Vars:: 
+     * @param bool $isInput             Whether this is an input field.
+     */
+    function render(&$form, &$var, &$vars, $isInput = false, $index = null)
+    {
+        if ($isInput) {
+            $state = 'Input';
+        } else {
+            $state = 'Display';
+        }
+        $method = "_renderVar${state}_" . $var->type->getTypeName();
+        if (!@method_exists($this, $method)) {
+            $method = "_renderVar${state}Default";
+        }
+        return $this->$method($form, $var, $vars, $index);
+    }
+
+    /**
+     * Finish rendering after all fields are output.
+     */
+    function renderEnd() {}
+
+}
epm diff framework/UI/UI/VarRenderer/html.php
--- framework/UI/UI/VarRenderer/html.php	1969-12-31 19:00:00.000000000 -0500
+++ framework/UI/UI/VarRenderer/html.php	2003-12-02 11:20:09.000000000 -0500
@@ -0,0 +1,872 @@
+<?php
+/**
+ * The Horde_UI_VarRenderer_html:: class renders variables to HTML.
+ *
+ * $Horde: $
+ *
+ * Copyright 2003 Jason M. Felice <jfelice at cronosys.com>
+ *
+ * See the enclosed file LICENSE for license information (LGPL).
+ *
+ * @version $Revision: 1.6 $
+ * @since   Horde_UI 0.0.1
+ * @package Horde_UI
+ */
+class Horde_UI_VarRenderer_html extends Horde_UI_VarRenderer {
+
+    var $_onLoadJS = array();
+
+    function _renderVarInputDefault(&$form, &$var, &$vars)
+    {
+?><strong>Warning:</strong> Unknown variable type <?php echo $var->getTypeName() ?><?php
+    }
+
+    function _renderVarInput_number(&$form, &$var, &$vars, $index = null)
+    {
+?><input type="text" size="5" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
+<?php
+    }
+
+    function _renderVarInput_int(&$form, &$var, &$vars, $index = null)
+    {
+?><input type="text" size="5" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
+<?php
+    }
+
+    function _renderVarInput_intlist(&$form, &$var, &$vars, $index = null)
+    {
+?><input type="text" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
+<?php
+    }
+
+    function _renderVarInput_text(&$form, &$var, &$vars, $index = null)
+    {
+        $maxlength = $var->type->getMaxLength();
+        if (!empty($maxlength)) {
+            $maxlength = ' maxlength="' . $maxlength . '"';
+        }
+?><input <?php echo $this->_genID($var->getVarName(), $index) ?>type="text" <?php echo $var->isDisabled() ? 'disabled="disabled" ' : '' ?>size="<?php echo $var->type->getSize() ?>"<?php echo $maxlength ?> name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" <?php if ($var->hasAction()) $this->_genActionScript($form, $var->_action, $var->getVarName(), $index) ?> />
+<?php
+    }
+
+    function _renderVarInput_stringlist(&$form, &$var, &$vars, $index = null)
+    {
+?><input type="text" size="60" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
+<?php
+    }
+
+    function _renderVarInput_file(&$form, &$var, &$vars, $index = null)
+    {
+?><input type="file" size="30" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
+<?php
+    }
+
+    /**
+     * @todo Show image dimensions in the width/height boxes.
+     */
+    function _renderVarInput_image(&$form, &$var, &$vars, $index = null)
+    {
+        $varname = $var->getVarName();
+        $var_array = $var->getValue($vars, $index);
+
+        Horde::addScriptFile('image.js', 'horde');
+        $graphics_dir = $GLOBALS['registry']->getParam('graphics', 'horde');
+        $img_dir = $graphics_dir . '/image';
+
+        if (isset($var_array['img'])) {
+            /* Hidden tag to store the preview image filename. */
+            printf('<input type="hidden" name="%s" value="%s" %s />',
+                   $varname . '[img]',
+                   htmlspecialchars($var_array['img'], ENT_QUOTES, NLS::getCharset()),
+                   $this->_genID($varname . '[img]'));
+        }
+
+        $upload = $vars->getVar($varname);
+        $upload['img'] = @unserialize($upload['img']);
+
+        /* Output the input tag. */
+        if (empty($upload['img'])) {
+            $js = "var p = document.getElementById('" . $varname . "[preview]'); o = '\\\\'; a = '/'; tmp = '' + document.getElementById('" . $varname . "[new]').value; if (tmp) { while (tmp.indexOf(o) > -1) { pos = tmp.indexOf(o); tmp = '' + (tmp.substring(0, pos) + a + tmp.substring((pos + o.length), tmp.length));}; p.src = 'file:///' + tmp; };";
+            $browser = &Browser::singleton();
+            if ($browser->isBrowser('msie')) {
+                printf('<input type="file" size="30" name="%s" id="%s" onchange="%s" />',
+                       $varname . '[new]',
+                       $varname . '[new]',
+                       $js);
+            } else {
+                printf('<input type="file" size="30" name="%s" id="%s" onclick="window.setTimeout(\'this.blur();\', 5);" onblur="%s" />',
+                       $varname . '[new]',
+                       $varname . '[new]',
+                       $js);
+            }
+        } else {
+                printf('<input type="file" size="30" name="%s" />',
+                       $varname . '[new]');
+        }
+
+        /* Output the button to upload/reset the image. */
+        echo '&nbsp;';
+        printf('<input class="button" name="%s" type="submit" value="%s" /> ',
+               '_do_' . $varname,
+               _("Upload"));
+
+        if (empty($upload['img'])) {
+            echo Horde::img('tree/blank.gif', _("Preview"), 'width="50" height="40" align="top" id="' . $varname . '[preview]"', $graphics_dir);
+        }
+
+        if (!empty($upload['img'])) {
+            /* Add all the buttons to control the image editing. */
+            echo '<br />';
+            $img = Horde::url($GLOBALS['registry']->getParam('webroot', 'horde') . '/services/images/view.php');
+            if (isset($upload['img']['vfs_id'])) {
+                /* Calling an image from VFS. */
+                $img = Util::addParameter($img, array('f' => $upload['img']['vfs_id'],
+                                                       's' => 'vfs',
+                                                       'p' => $upload['img']['vfs_path']));
+            } else {
+                /* Calling an image from a tmp directory (uploads). */
+                $img = Util::addParameter($img, 'f', $upload['img']['file']);
+            }
+
+            /* Rotate 270. */
+            echo Horde::link('#', '', '', '', 'showImage(\'' . Util::addParameter($img, array('a' => 'rotate', 'v' => '270')) . '\', \'_p_' . $varname . '\', true);') . Horde::img('rotate-270.png', _("Rotate Left"), 'align="middle"', $img_dir) . '</a>';
+
+            /* Rotate 180. */
+            echo Horde::link('#', '', '', '', 'showImage(\'' . Util::addParameter($img, array('a' => 'rotate', 'v' => '180')) . '\', \'_p_' . $varname . '\', true);') . Horde::img('rotate-180.png', _("Rotate 180"), 'align="middle"', $img_dir) . '</a>';
+
+            /* Rotate 90. */
+            echo Horde::link('#', '', '', '', 'showImage(\'' . Util::addParameter($img, array('a' => 'rotate', 'v' => '90')) . '\', \'_p_' . $varname . '\', true);') . Horde::img('rotate-90.png', _("Rotate Right"), 'align="middle"', $img_dir) . '</a>';
+
+            /* Flip image. */
+            echo Horde::link('#', '', '', '', 'showImage(\'' . Util::addParameter($img, 'a', 'flip') . '\', \'_p_' . $varname . '\', true);') . Horde::img('flip.png', _("Flip"), 'align="middle"', $img_dir) . '</a>';
+
+            /* Mirror image. */
+            echo Horde::link('#', '', '', '', 'showImage(\'' . Util::addParameter($img, 'a', 'mirror') . '\', \'_p_' . $varname . '\', true);') . Horde::img('mirror.png', _("Mirror"), 'align="middle"', $img_dir) . '</a>';
+
+            /* Apply grayscale. */
+            echo Horde::link('#', '', '', '', 'showImage(\'' . Util::addParameter($img, 'a', 'grayscale') . '\', \'_p_' . $varname . '\', true);') . Horde::img('grayscale.gif', _("Grayscale"), 'align="middle"', $img_dir) . '</a>';
+
+            /* Resize width. */
+            printf('%s<input type="text" size="4" onChange="src=getResizeSrc(\'%s\', \'%s\');showImage(src, \'_p_%s\', true);" %s />',
+                   _("w:"),
+                   Util::addParameter($img, 'a', 'resize'),
+                   $varname,
+                   $varname,
+                   $this->_genID('_w_' . $varname, $index));
+
+            /* Resize height. */
+            printf('%s<input type="text" size="4" onChange="src=getResizeSrc(\'%s\', \'%s\');showImage(src, \'_p_%s\', true);" %s />',
+                   _("h:"),
+                   Util::addParameter($img, 'a', 'resize'),
+                   $varname,
+                   $varname,
+                   $this->_genID('_h_' . $varname, $index));
+
+            /* Apply fixed ratio resize. */
+            echo Horde::link('#', '', '', '', 'src=getResizeSrc(\'' . Util::addParameter($img, 'a', 'resize') . '\', \'' . $varname . '\', \'1\');showImage(src, \'_p_' . $varname . '\', true);') . Horde::img('ratio.png', _("Fix ratio"), 'align="middle"', $img_dir) . '</a>';
+
+            /* Keep also original. */
+            printf('<input type="checkbox" name="%s"%s />%s<br />' . "\n",
+                   $varname . '[keep_orig]',
+                   !empty($upload['keep_orig']) ? ' checked="checked"' : '',
+                   _("Keep original?"));
+
+            /* The preview image element. */
+            echo '<img src="' . $img . '" ' . $this->_genID('_p_' . $varname, $index) . ">\n";
+        }
+    }
+
+    function _renderVarInput_longtext(&$form, &$var, &$vars, $index = null)
+    {
+        global $browser;
+
+        $id = $this->_genID($var->getVarName(), $index, false);
+
+        printf('<textarea id="%s" name="%s" cols="%s" rows="%s">%s</textarea>',
+               $id,
+               $var->getVarName(),
+               $var->type->getCols(),
+               $var->type->getRows(),
+               $var->getValue($vars, $index));
+
+        if ($var->type->hasHelper('rte') && $browser->hasFeature('rte')) {
+            require_once HORDE_BASE . '/lib/Editor.php';
+            $editor = &Horde_Editor::singleton('htmlarea');
+            $editor->runEditor($id);
+        }
+
+        if ($var->type->hasHelper() && $browser->hasFeature('javascript')) {
+            echo '<br /><table border="0" cellpadding="1" cellspacing="0"><tr><td>';
+            Horde::addScriptFile('open_html_helper.js', 'horde');
+            $imgId = $this->_genID($var->getVarName(), $index, false) . 'goto';
+            if ($var->type->hasHelper('emoticons')) {
+                echo Horde::link('', _("Emoticons"), '', '', 'openHtmlHelper(\'emoticons\', \'' . $var->getVarName() . '\'); return false;') . Horde::img('smile.gif', _("Emoticons"), 'id="' . $imgId . '" align="middle"', $GLOBALS['registry']->getParam('graphics', 'horde') . '/emoticons') . '</a>';
+            }
+            echo '</td></tr><tr><td><div ' . $this->_genID('htmlhelper_' . $var->getVarName(), $index) . ' class="control"></div></td></tr></table>' . "\n";
+        }
+    }
+
+    function _renderVarInput_countedtext(&$form, &$var, &$vars, $index = null)
+    {
+?><textarea name="<?php echo $var->getVarName() ?>" cols="<?php echo $var->type->getCols() ?>" rows="<?php echo $var->type->getRows() ?>"><?php echo $var->getValue($vars, $index) ?></textarea>
+<?php
+    }
+
+    function _renderVarInput_address(&$form, &$var, &$vars, $index = null)
+    {
+?><textarea <?php echo $this->_genID($var->getVarName(), $index) ?> name="<?php echo $var->getVarName() ?>" cols="<?php echo $var->type->getCols() ?>" rows="<?php echo $var->type->getRows() ?>"><?php echo $var->getValue($vars, $index) ?></textarea>
+<?php
+    }
+
+    function _renderVarInput_date(&$form, &$var, &$vars, $index = null)
+    {
+?><input type="text" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
+<?php
+    }
+
+    function _renderVarInput_time(&$form, &$var, &$vars, $index = null)
+    {
+?><input type="text" size="5" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
+<?php
+    }
+
+    function _renderVarInput_hourminutesecond(&$form, &$var, &$vars, $index = null)
+    {
+        $hours = array('' => _("HH"));
+        for ($i = 0; $i <= 23; $i++) {
+            $hours[sprintf('%02d', $i)] = $i;
+        }
+        $minutes = array('' => _("MM"));
+        for ($i = 0; $i <= 59; $i++) {
+            $minutes[sprintf('%02d', $i)] = $i;
+        }
+        $seconds = array('' => _("SS"));
+        for ($i = 0; $i <= 59; $i++) {
+            $seconds[sprintf('%02d', $i)] = $i;
+        }
+        $time = $var->type->getTimeParts($var->getValue($vars, $index));
+?>
+<select name="<?php echo $var->getVarName() ?>[hour]" id="<?php echo $var->getVarName() ?>[hour]"><?php echo $this->_selectOptions($hours, $time['hour']) ?></select>
+<select name="<?php echo $var->getVarName() ?>[minute]" id="<?php echo $var->getVarName() ?>[minute]"><?php echo $this->_selectOptions($minutes, $time['minute']) ?></select>
+<select name="<?php echo $var->getVarName() ?>[second]" id="<?php echo $var->getVarName() ?>[second]"><?php echo $this->_selectOptions($seconds, $time['second']) ?></select>
+<?php
+    }
+
+    function _renderVarInput_monthyear(&$form, &$var, &$vars, $index = null)
+    {
+        $months = array('' => _("MM"),
+                        1 => _("January"),
+                        2 => _("February"),
+                        3 => _("March"),
+                        4 => _("April"),
+                        5 => _("May"),
+                        6 => _("June"),
+                        7 => _("July"),
+                        8 => _("August"),
+                        9 => _("September"),
+                        10 => _("October"),
+                        11 => _("November"),
+                        12 => _("December"));
+        $years = array('' => _("YYYY"));
+        if ($var->type->_start_year > $var->type->_end_year) {
+            for ($i = $var->type->_start_year; $i >= $var->type->_end_year; $i--) {
+                $years[$i] = $i;
+            }
+        } else {
+            for ($i = $var->type->_start_year; $i <= $var->type->_end_year; $i++) {
+                $years[$i] = $i;
+            }
+        }
+?><select name="<?php echo $var->type->getMonthVar($var) ?>"><?php echo $this->_selectOptions($months, $vars->getVar($var->type->getMonthVar($var))) ?></select>
+<select name="<?php echo $var->type->getYearVar($var) ?>"><?php echo $this->_selectOptions($years, $vars->getVar($var->type->getYearVar($var))) ?></select>
+<?php
+    }
+
+    function _renderVarInput_monthdayyear(&$form, &$var, &$vars, $index = null)
+    {
+        $months = array(''   => _("MM"),
+                        '1'  => _("January"),
+                        '2'  => _("February"),
+                        '3'  => _("March"),
+                        '4'  => _("April"),
+                        '5'  => _("May"),
+                        '6'  => _("June"),
+                        '7'  => _("July"),
+                        '8'  => _("August"),
+                        '9'  => _("September"),
+                        '10' => _("October"),
+                        '11' => _("November"),
+                        '12' => _("December"));
+        $days = array('' => _("DD"));
+        for ($i = 1; $i <= 31; $i++) {
+            $days[$i] = $i;
+        }
+        $years = array('' => _("YYYY"));
+        if ($var->type->_start_year > $var->type->_end_year) {
+            for ($i = $var->type->_start_year; $i >= $var->type->_end_year; $i--) {
+                $years[$i] = $i;
+            }
+        } else {
+            for ($i = $var->type->_start_year; $i <= $var->type->_end_year; $i++) {
+                $years[$i] = $i;
+            }
+        }
+        $date = $var->type->getDateParts($var->getValue($vars, $index));
+?>
+<select name="<?php echo $var->getVarName() ?>[month]" id="<?php echo $var->getVarName() ?>[month]"><?php echo $this->_selectOptions($months, $date['month']) ?></select>
+<select name="<?php echo $var->getVarName() ?>[day]" id="<?php echo $var->getVarName() ?>[day]"><?php echo $this->_selectOptions($days, $date['day']) ?></select>
+<select name="<?php echo $var->getVarName() ?>[year]" id="<?php echo $var->getVarName() ?>[year]"><?php echo $this->_selectOptions($years, $date['year']) ?></select>
+<?php
+        if ($var->type->_picker && $GLOBALS['browser']->hasFeature('javascript')) {
+            Horde::addScriptFile('open_calendar.js', 'horde');
+            $imgId = $this->_genID($var->getVarName(), $index, false) . 'goto';
+            echo '<div id="goto" class="control" style="position:absolute;visibility:hidden;padding:1px"></div>';
+            echo Horde::link('', _("Select a date"), '', '', 'openCalendar(\'' . $imgId . '\', \'' . $var->getVarName() . '\'); return false;') . Horde::img('calendar.gif', _("Calendar"), 'id="' . $imgId . '" align="middle"', $GLOBALS['registry']->getParam('graphics', 'horde')) . "</a>\n";
+        }
+    }
+
+    function _renderVarInput_colorpicker(&$form, &$var, &$vars, $index = null)
+    {
+        global $registry, $browser;
+?><table border="0" cellpadding="0" cellspacing="0"><tr><td><input type="text" size="10" maxlength="7" name="<?php echo $var->getVarName() ?>" id="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" /></td><?php
+        if ($browser->hasFeature('javascript')) {
+            Horde::addScriptFile('open_colorpicker.js', 'horde');
+            echo '<td width="20" id="colordemo_' . $var->getVarName() . '" style="background-color:' . $var->getValue($vars, $index) . '"> </td>';
+            echo '<td>' . Horde::link('#', _("Color Picker"), 'widget', '', 'openColorPicker(\'' . $var->getVarName() . '\'); return false;') . Horde::img('colorpicker.gif', _("Color Picker"), 'height="16"', $registry->getParam('graphics', 'horde')) . '</a></td>';
+            echo '<td><div id="colorpicker_' . $var->getVarName() . '" class="control"></div></td>';
+        }
+?></tr></table>
+<?php
+    }
+
+    function _renderVarInput_sorter(&$form, &$var, &$vars, $index = null)
+    {
+        global $registry;
+
+        $varname = $var->getVarName();
+        $instance = $var->type->_instance;
+
+        Horde::addScriptFile('sorter.js', 'horde');
+
+        echo '<input type="hidden" name="' . $varname . '[array]" value="" ' . $this->_genID($varname . '[array]') . ' />';
+        echo '<table border="0" cellpadding="0" cellspacing="0"><tr><td>';
+        echo '<select multiple="multiple" size="' . $var->type->getSize() . '" name="' . $varname . '[list]" onchange="' . $instance . '.deselectHeader();" ' . $this->_genID($varname . '[list]') . '>';
+        echo $var->type->getOptions();
+        echo '</select></td><td>';
+        echo Horde::link('#', _("Move up"), '', '', $instance . '.moveColumnUp(); return false;') . Horde::img('nav/up.gif', _("Move up"), '', $registry->getParam('graphics', 'horde')) . '</a><br />';
+        echo Horde::link('#', _("Move up"), '', '', $instance . '.moveColumnDown(); return false;') . Horde::img('nav/down.gif', _("Move down"), '', $registry->getParam('graphics', 'horde')) . '</a></td></tr></table>';
+        echo '<script language="JavaScript" type="text/javascript">' . "\n";
+        printf('%1$s = new Horde_Form_Sorter(\'%1$s\', \'%2$s\', \'%3$s\');' . "\n",
+               $instance, $varname, $var->type->getHeader());
+
+        printf("%s.setHidden();\n</script>\n",
+               $instance);
+    }
+
+    function _renderVarInput_invalid(&$form, &$var, &$vars, $index = null)
+    {
+        return $this->_renderVarDisplay_invalid($form, $var, $vars);
+    }
+
+    function _renderVarInput_enum(&$form, &$var, &$vars, $index = null)
+    {
+        $values = $var->getValues();
+        $prompt = $var->type->getPrompt();
+        $selected = $var->getValue($vars, $index);
+?><select <?php echo $this->_genID($var->getVarName(), $index) ?> name="<?php echo $var->getVarName() ?>"<?php if ($var->hasAction()) $this->_genActionScript($form, $var->_action, $var->getVarName(), $index) ?>>
+  <?php if (!empty($prompt)) { echo '<option value="">' . htmlspecialchars($prompt, ENT_QUOTES, NLS::getCharset()) . '</option>'; } echo $this->_selectOptions($values, $selected) ?>
+  </select>
+<?php
+    }
+
+    function _renderVarInput_multienum(&$form, &$var, &$vars, $index = null)
+    {
+        $values = $var->getValues();
+        $selected = $vars->getVarWasset($var->getVarName(), $wasset);
+        if (!$wasset) {
+            $selected = $var->getDefault();
+        }
+?><select multiple="multiple" size="<?php echo $var->type->size ?>" name="<?php echo $var->getVarName() ?>[]">
+  <?php echo $this->_multiSelectOptions($values, $selected) ?>
+  </select>
+<?php
+        echo "<br />\n" . _("To select multiple items, hold down the Control (PC) or Command (Mac) key while clicking.") . "\n";
+    }
+
+    function _renderVarInput_radio(&$form, &$var, &$vars, $index = null)
+    {
+        $values = $var->getValues();
+        $value  = $var->getValue($vars, $index);
+        echo $this->_radioButtons($var->getVarName(), $values, $value);
+    }
+
+    function _renderVarInput_set(&$form, &$var, &$vars, $index = null)
+    {
+        $values = $var->getValues();
+        $value  = $var->getValue($vars, $index);
+        echo $this->_checkBoxes($var->getVarName(), $values, $value);
+    }
+
+    function _renderVarInput_link(&$form, &$var, &$vars, $index = null)
+    {
+        return _renderVarDisplay_link($form, $var, $vars);
+    }
+
+    function _renderVarInput_email(&$form, &$var, &$vars, $index = null)
+    {
+?><input type="text" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
+<?php
+    }
+
+    function _renderVarInput_blockselect(&$form, &$var, &$vars, $index = null)
+    {
+        $varname = $var->getVarName();
+        $var_array = $var->type->getBlockArray($var->getValue($vars, $index));
+        $blocks = $var->type->getBlocks();
+        $block_select = $var->type->getBlockSelect();
+
+        if (isset($var_array['old'])) {
+            /* Hidden tag to store previous block values. */
+            printf('<input type="hidden" name="%s" value="%s" %s />',
+                   $varname . '[old]',
+                   htmlspecialchars($var_array['old'], ENT_QUOTES, NLS::getCharset()),
+                   $this->_genID($varname . '[old]'));
+        }
+
+        /* Output the block name selection box. */
+        printf('<select %s name="%s" %s><option value="">%s</option>%s</select><br />',
+               $this->_genID($varname . '[name]', $index),
+               $varname . '[name]',
+               ($var->hasAction() ? $this->_genActionScript($form, $var->_action, $varname . '[block]', $index) : ''),
+               _("-- select --"),
+               $this->_selectOptions($block_select, $var_array['name']));
+
+        /* If name has been selected, output the block params input. */
+        if (!empty($var_array['name'])) {
+            list($this_app, $this_type) = explode(':', $var_array['name']);
+            $this_block = $blocks[$this_app][$this_type];
+            /* Go through the params of this block and set up any required
+             * extra input. */
+            foreach ($this_block['params'] as $param_id => $param) {
+                $value = (isset($var_array['params'][$param_id]) ? $var_array['params'][$param_id] : '');
+                $value = $var->type->setValue($value, $param);
+                /* Figure out what type of extra input is required. */
+                switch ($param['type']) {
+                case 'enum':
+                    /* Simple selection box. */
+                    printf('%s: <select %s name="%s" %s><option value="">%s</option>%s</select><br />',
+                           $param['name'],
+                           $this->_genID($varname . '[params][' . $param_id . ']', $index),
+                           $varname . '[params][' . $param_id . ']',
+                           ($var->hasAction() ? $this->_genActionScript($form, $var->_action, $varname . '[params]' . $param_id . ']', $index) : ''),
+                           _("-- select --"),
+                           $this->_selectOptions($param['values'], $value));
+                    break;
+
+                case 'mlenum':
+                    /* Multiple level selection box. */
+                    $first_level = array_flip(array_keys($param['values']));
+                    foreach ($first_level as $key => $val) {
+                        $first_level[$key] = $key;
+                    }
+                    printf('%s: <select %s name="%s" %s><option value="">%s</option>%s</select>',
+                           $param['name'],
+                           $this->_genID($varname . '[params][' . $param_id . '][1]', $index),
+                           $varname . '[params][' . $param_id . '][1]',
+                           ($var->hasAction() ? $this->_genActionScript($form, $var->_action, $varname . '[params]' . $param_id . '][1]', $index) : ''),
+                           _("-- select --"),
+                           $this->_selectOptions($first_level, $value[1]));
+                    if (!empty($value[1])) {
+                        if (!isset($value[2])) {
+                            $value[2] = '';
+                        }
+                        $second_level = $param['values'][$value[1]];
+                        printf('<select %s name="%s" %s><option value="">%s</option>%s</select><br />',
+                               $this->_genID($varname . '[params][' . $param_id . '][2]', $index),
+                               $varname . '[params][' . $param_id . '][2]',
+                               ($var->hasAction() ? $this->_genActionScript($form, $var->_action, $varname . '[params]' . $param_id . '][2]', $index) : ''),
+                               _("-- select --"),
+                               $this->_selectOptions($second_level, $value[2]));
+                    }
+                    break;
+
+                default:
+                    /* Default to a text input box. */
+                    printf('%s: <input %s type="text" size="%s" name="%s" %s value="%s" /><br />',
+                           $param['name'],
+                           $this->_genID($var->getVarName(), $index),
+                           '20',
+                           $varname . '[params][' . $param_id . ']',
+                           ($var->hasAction() ? $this->_genActionScript($form, $var->_action, $varname . '[params]' . $param_id . ']', $index) : ''),
+                           $value);
+                }
+            }
+        }
+    }
+
+    function _renderVarInput_matrix(&$form, &$var, &$vars, $index = null)
+    {
+        $varname   = $var->getVarName();
+        $var_array = $var->getValue($vars, $index);
+        $cols      = $var->type->getCols();
+        $rows      = $var->type->getRows();
+        $matrix    = $var->type->getMatrix();
+        $new_input = $var->type->getNewInput();
+
+        echo '<table border="0" cellpadding="0" cellspacing="0"><tr>';
+
+        echo '<td align="right" width="20%"></td>';
+        foreach ($cols as $col_title) {
+            printf('<td align="center" width="1%%">%s</td>', $col_title);
+        }
+        echo '<td align="right" width="60%"></td></tr>';
+
+        /* Offer a new row of data to be added to the matrix? */
+        if ($new_input) {
+            echo '<tr><td>';
+            if (is_array($new_input)) {
+                printf('<select %s name="%s[n][r]"><option value="">%s</option>%s</select><br />',
+                       $this->_genID($varname . '[n][r]', $index),
+                       $varname,
+                       _("-- select --"),
+                       $this->_selectOptions($new_input, $var_array['n']['r']));
+            } elseif ($new_input == true) {
+                printf('<input %s type="text" name="%s[n][r]" value="%s" />',
+                       $this->_genID($varname . '[n][r]', $index),
+                       $varname,
+                       $var_array['n']['r']);
+            }
+            echo ' </td>';
+            foreach ($cols as $col_id => $col_title) {
+                printf('<td align="center"><input type="checkbox" name="%s[n][v][%s]" /></td>', $varname, $col_id);
+            }
+            echo '<td> </td></tr>';
+        }
+
+        /* Loop through the rows and create checkboxes for each column. */
+        foreach ($rows as $row_id => $row_title) {
+            printf('<tr><td>%s</td>', $row_title);
+            foreach ($cols as $col_id => $col_title) {
+                printf('<td align="center"><input type="checkbox" name="%s[r][%s][%s]"%s /></td>', $varname, $row_id, $col_id, (!empty($matrix[$row_id][$col_id]) ? ' checked="checked"' : ''));
+            }
+            echo '<td> </td></tr>';
+        }
+
+        echo '</table>';
+    }
+
+    function _renderVarInput_password(&$form, &$var, &$vars, $index = null)
+    {
+?><input type="password" name="<?php echo $var->getVarName() ?>" value="<?php echo $var->getValue($vars, $index) ?>" />
+<?php
+    }
+
+    function _renderVarInput_emailconfirm(&$form, &$var, &$vars, $index = null)
+    {
+        $email = $var->getValue($vars, $index);
+?><input type="text" name="<?php echo $var->getVarName() ?>[original]" value="<?php $email['original'] ?>" /><br />
+  <input type="text" name="<?php echo $var->getVarName() ?>[confirm]" value="<?php $email['confirm'] ?>" />
+<?php
+    }
+
+    function _renderVarInput_passwordconfirm(&$form, &$var, &$vars, $index = null)
+    {
+        $password = $var->getValue($vars, $index);
+?><input type="password" name="<?php echo $var->getVarName() ?>[original]" value="<?php echo $password['original'] ?>" /><br />
+  <input type="password" name="<?php echo $var->getVarName() ?>[confirm]" value="<?php echo $password['confirm'] ?>" />
+<?php
+    }
+
+    function _renderVarInput_boolean(&$form, &$var, &$vars, $index = null)
+    {
+        $varName = $var->getVarName();
+        if (!is_null($index)) {
+            $varName = str_replace('[]', '[' . $index . ']', $varName);
+        }
+?><input type="checkbox" name="<?php echo $varName ?>"<?php echo $var->getValue($vars, $index) ? ' checked="checked"' : ''; if ($var->hasAction()) $this->_genActionScript($form, $var->_action, $var->getVarName(), $index) ?> />
+<?php
+    }
+
+    function _renderVarInput_creditcard(&$form, &$var, &$vars, $index = null)
+    {
+?><input type="text" name="<?php echo $var->getVarName() ?>"<?php echo $var->getValue($vars, $index); if ($var->hasAction()) $this->_genActionScript($form, $var->_action, $var->getVarName(), $index) ?> />
+<?php
+    }
+
+    function _renderVarDisplayDefault(&$form, &$var, &$vars, $index = null)
+    {
+        echo nl2br(htmlspecialchars($var->getValue($vars, $index), ENT_QUOTES, NLS::getCharset()));
+    }
+
+    function _renderVarDisplay_html(&$form, &$var, &$vars, $index = null)
+    {
+        echo $var->getValue($vars, $index);
+    }
+
+    function _renderVarDisplay_password(&$form, &$var, &$vars, $index = null)
+    {
+        echo htmlspecialchars('********', ENT_QUOTES, NLS::getCharset());
+    }
+
+    function _renderVarDisplay_passwordconfirm(&$form, &$var, &$vars, $index = null)
+    {
+        echo htmlspecialchars('********', ENT_QUOTES, NLS::getCharset());
+    }
+
+    function _renderVarDisplay_boolean(&$form, &$var, &$vars, $index = null)
+    {
+        echo $var->getValue($vars, $index) == 'on' ? _("On") : _("Off");
+    }
+
+    function _renderVarDisplay_enum(&$form, &$var, &$vars, $index = null)
+    {
+        $values = $var->getValues();
+        if (count($values) == 0) {
+            echo _("No values");
+        } elseif (isset($values[$var->getValue($vars, $index)]) && $var->getValue($vars, $index) != '') {
+            echo htmlspecialchars($values[$var->getValue($vars, $index)], ENT_QUOTES, NLS::getCharset());
+        }
+    }
+
+    function _renderVarDisplay_radio(&$form, &$var, &$vars, $index = null)
+    {
+        $values = $var->getValues();
+        if (count($values) == 0) {
+            echo _("No values");
+        } elseif (isset($values[$var->getValue($vars, $index)])) {
+            echo htmlspecialchars($values[$var->getValue($vars, $index)], ENT_QUOTES, NLS::getCharset());
+        }
+    }
+
+    function _renderVarDisplay_multienum(&$form, &$var, &$vars, $index = null)
+    {
+        $values = $var->getValues();
+        $on = $var->getValue($vars, $index);
+        if (!count($values) || !count($on)) {
+            echo _("No values");
+        } else {
+            $display = array();
+            foreach ($values as $value => $name) {
+                if (in_array($value, $on)) {
+                    $display[] = $name;
+                }
+            }
+            echo htmlspecialchars(implode(', ', $display), ENT_QUOTES, NLS::getCharset());
+        }
+    }
+
+    function _renderVarDisplay_set(&$form, &$var, &$vars, $index = null)
+    {
+        $values = $var->getValues();
+        $on = $var->getValue($vars, $index);
+        if (!count($values) || !count($on)) {
+            echo _("No values");
+        } else {
+            $display = array();
+            foreach ($values as $value => $name) {
+                if (in_array($value, $on)) {
+                    $display[] = $name;
+                }
+            }
+            echo htmlspecialchars(implode(', ', $display), ENT_QUOTES, NLS::getCharset());
+        }
+    }
+
+    function _renderVarDisplay_image(&$form, &$var, &$vars, $index = null)
+    {
+        $img_params = $var->getValue($vars, $index);
+        $img_url = Horde::url($GLOBALS['registry']->getParam('webroot', 'horde') . '/services/images/view.php');
+        $img_url = Util::addParameter($img_url, $img_params);
+        echo Horde::img($img_url, $img_params['f'], '', '');
+    }
+
+    function _renderVarDisplay_address(&$form, &$var, &$vars, $index = null)
+    {
+        $address = $var->getValue($vars, $index);
+
+        if (preg_match('/(.*)\n(.*)\s*,\s*(\w+)\.?\s+(\d+|[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d)/', $address, $addressParts)) {
+            /* American/Canadian address style. */
+            $mapurl = 'http://www.mapquest.com/maps/map.adp?size=big&zoom=7';
+            if (!empty($addressParts[1])) {
+                $mapurl .= '&address=' . urlencode($addressParts[1]);
+            }
+            if (!empty($addressParts[2])) {
+                $mapurl .= '&city=' . urlencode($addressParts[2]);
+            }
+            if (!empty($addressParts[3])) {
+                $mapurl .= '&state=' . urlencode($addressParts[3]);
+            }
+            if (!empty($addressParts[4])) {
+                $mapurl .= '&zipcode=' . urlencode($addressParts[4]);
+                if (preg_match('|[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d|', $addressParts[4])) {
+                    $mapurl .= '&country=CA';
+                }
+            }
+        } elseif (preg_match('/(.*)\nD-(\d{5})\s+(.*)/i', $address, $addressParts)) {
+            /* German address style. */
+            $mapurl = 'http://www.map24.de/map24/index.php3?maptype=RELOAD&country0=de&gcf=1';
+            if (!empty($addressParts[1])) {
+                $mapurl .= '&street0=' . urlencode($addressParts[1]);
+            }
+            if (!empty($addressParts[2])) {
+                $mapurl .= '&zip0=' . urlencode($addressParts[2]);
+            }
+            if (!empty($addressParts[3])) {
+                $mapurl .= '&city0=' . urlencode($addressParts[3]);
+            }
+        }
+        echo nl2br(htmlspecialchars($var->getValue($vars, $index), ENT_QUOTES, NLS::getCharset()));
+        if (!empty($mapurl)) {
+            global $registry;
+            echo Horde::link($mapurl, _("View map"), null, '_blank') . Horde::img('map.gif', _("View map"), 'align="middle"', $registry->getParam('graphics', 'horde')) . '</a>';
+        }
+    }
+
+    function _renderVarDisplay_date(&$form, &$var, &$vars, $index = null)
+    {
+        echo $var->type->getFormattedTimeFull($var->getValue($vars, $index));
+    }
+
+    function _renderVarDisplay_monthyear(&$form, &$var, &$vars, $index = null)
+    {
+        echo $vars->getVar($var->getVarName() . '[month]') . ', ' . $vars->getVar($var->getVarName() . '[year]');
+    }
+
+    function _renderVarDisplay_monthdayyear(&$form, &$var, &$vars, $index = null)
+    {
+        $date = $var->getValue($vars, $index);
+        if ((is_array($date) && !empty($date['year']) && !empty($date['month']) && !empty($date['day'])) || (!is_array($date) && !empty($date))) {
+            echo $var->type->formatDate($date);
+        }
+    }
+
+    function _renderVarDisplay_invalid(&$form, &$var, &$vars, $index = null)
+    {
+        echo '<span class="form-error">' . htmlspecialchars($var->type->message, ENT_QUOTES, NLS::getCharset()) . '</span>';
+    }
+
+    function _renderVarDisplay_link(&$form, &$var, &$vars, $index = null)
+    {
+        if (isset($var->type->values[0]) && is_array($var->type->values[0])) {
+            $count = count($var->type->values);
+            for ($i = 0; $i < $count; $i++) {
+                if (empty($var->type->values[$i]['url']) || empty($var->type->values[$i]['text'])) {
+                    continue;
+                }
+                if ($i > 0) {
+                    echo ' | ';
+                }
+                echo Horde::link($var->type->values[$i]['url'], $var->type->values[$i]['text'], 'widget') . $var->type->values[$i]['text'] . '</a>';
+            }
+        } else {
+            if (empty($var->type->values['url']) || empty($var->type->values['text'])) {
+                return;
+            }
+            echo Horde::link($var->type->values['url'], $var->type->values['text'], 'widget') . $var->type->values['text'] . '</a>';
+        }
+    }
+
+    function _selectOptions(&$values, $selectedValue = false)
+    {
+        $result = '';
+        $sel = false;
+        foreach ($values as $value => $display) {
+            if (!is_null($selectedValue) && !$sel && $value == $selectedValue) {
+                $selected = ' selected="selected"';
+                $sel = true;
+            } else {
+                $selected = '';
+            }
+            $result .= ' <option value="' . htmlspecialchars($value, ENT_QUOTES, NLS::getCharset()) . '"' . $selected . '>' . htmlspecialchars($display) . "</option>\n";
+        }
+
+        return $result;
+    }
+
+    function _multiSelectOptions(&$values, $selectedValues)
+    {
+        $result = '';
+        $sel = false;
+        foreach ($values as $value => $display) {
+            if (@in_array($value, $selectedValues)) {
+                $selected = ' selected="selected"';
+            } else {
+                $selected = '';
+            }
+            $result .= " <option value=\"" . htmlspecialchars($value, ENT_QUOTES, NLS::getCharset()) . "\"$selected>" . htmlspecialchars($display) . "</option>\n";
+        }
+
+        return $result;
+    }
+
+    function _checkBoxes($name, $values, $checkedValues)
+    {
+        $result = '';
+        if (!is_array($checkedValues)) {
+            $checkedValues = array();
+        }
+        $i = 0;
+        foreach ($values as $value => $display) {
+            $checked = (in_array($value, $checkedValues)) ? ' checked="checked"' : '';
+            $result .= "<input id=\"${name}${i}\" type=\"checkbox\" name=\"${name}[]\" value=\"$value\"$checked /><label for=\"${name}${i}\">&nbsp;$display</label><br />";
+            $i++;
+        }
+
+        return $result;
+    }
+
+    function _radioButtons($name, $values, $checkedValue = null)
+    {
+        $result = '';
+        $i = 0;
+        foreach ($values as $value => $display) {
+            $checked = (!is_null($checkedValue) && $value == $checkedValue) ? ' checked="checked"' : '';
+            $result .= "<input id=\"${name}${i}\" type=\"radio\" name=\"$name\" value=\"$value\"$checked /><label for=\"${name}${i}\">&nbsp;$display</label><br />";
+            $i++;
+        }
+
+        return $result;
+    }
+
+    function _genID($name, $index = null, $fulltag = true)
+    {
+        $name = str_replace('[]', '', $name);
+        if (!is_null($index)) {
+            $name .= $index;
+        }
+        return $fulltag ? 'id="' . htmlspecialchars($name, ENT_QUOTES, NLS::getCharset()) . '"' : $name;
+    }
+
+    function _genActionScript(&$form, $action, $varname, $index = null)
+    {
+        $triggers = $action->getTrigger();
+        if (!is_array($triggers)) {
+            $triggers = array($triggers);
+        }
+        $js = $action->getActionScript($form, $this, $varname, $index);
+        foreach ($triggers as $trigger) {
+            if ($trigger == 'onload') {
+                $this->_addOnLoadJavascript($js);
+            } else {
+                echo ' ' . $trigger . '="' . $js . '"';
+            }
+        }
+    }
+
+    function _addOnLoadJavascript($script)
+    {
+        $this->_onLoadJS[] = $script;
+    }
+
+    function renderEnd()
+    {
+        if (count($this->_onLoadJS)): ?>
+<script language="JavaScript" type="text/javascript">
+<!--
+<?php echo implode("\n", $this->_onLoadJS); ?>
+// -->
+</script>
+<?php endif;
+        $this->_onLoadJS = array();
+    }
+}
epm diff lib/Form/Renderer/rows.php
--- lib/Form/Renderer/rows.php	2003-12-02 11:00:22.000000000 -0500
+++ lib/Form/Renderer/rows.php	2003-12-02 11:11:59.000000000 -0500
@@ -49,16 +49,13 @@
                     break;
 
                 default:
-                    $format = (!$active || $var->isReadonly()) ? 'Display' : 'Input';
-                    $method = "_renderVar${format}_$type";
+                    $isInput = ($active && !$var->isReadonly());
+                    $format = $isInput ? 'Input' : 'Display';
 
                     $this->_beginCell();
 
-                    if (@method_exists($this, $method) == false) {
-                        $method = "_renderVar${format}Default";
-                    }
-
-                    $this->$method($form, $var, $vars, $i);
+                    $this->_varRenderer->render($form, $var, $vars, $isInput,
+                                                $i);
                     $this->_endCell();
                 }
             }
@@ -97,11 +94,6 @@
         }
     }
 
-    function _renderVarInput_boolean(&$form, &$var, &$vars, $index = null)
-    {
-?><input type="checkbox" name="<?php echo str_replace('[]', '[' . $index . ']', $var->getVarName()) ?>"<?php echo $var->getValue($vars, $index) ? ' checked="checked"' : '' ?> /><?php
-    }
-
     function _renderColumnHeaders($variables, $form)
     {
 ?><tr>


More information about the dev mailing list