steffen: server/kolab-horde-framework/kolab-horde-framework/UI/UI Language.php, NONE, 1.1 Pager.php, NONE, 1.1 Table.php, NONE, 1.1 Tabs.php, NONE, 1.1 VarRenderer.php, NONE, 1.1 Widget.php, NONE, 1.1

cvs at intevation.de cvs at intevation.de
Fri Oct 14 16:33:16 CEST 2005


Author: steffen

Update of /kolabrepository/server/kolab-horde-framework/kolab-horde-framework/UI/UI
In directory doto:/tmp/cvs-serv28903/kolab-horde-framework/kolab-horde-framework/UI/UI

Added Files:
	Language.php Pager.php Table.php Tabs.php VarRenderer.php 
	Widget.php 
Log Message:
Separated Horde Framework from kolab-resource-handlers

--- NEW FILE: Language.php ---
<?php
/**
 * The Horde_UI_Language:: class provides a widget for changing the
 * currently selected language.
 *
 * $Horde: framework/UI/UI/Language.php,v 1.4 2004/02/04 17:02:26 chuck Exp $
 *
 * Copyright 2003-2004 Jason M. Felice <jfelice at cronosys.com>
 *
 * See the enclosed file LICENSE for license information (LGPL).
 *
 * @version $Revision: 1.1 $
 * @since   Horde_UI 0.0.1
 * @package Horde_UI
 */
class Horde_UI_Language {

    /**
     * Render the language selection.
     *
     * @abstract
     *
     * @param optional bool $form  Return the selection box as an complete
     *                             standalone form.
     *
     * @return string  The HTML selection box.
     */
    function render()
    {
        $html = '';
        if (!$GLOBALS['prefs']->isLocked('language')) {
            Horde::addScriptFile('language.js', 'horde');
            $_SESSION['horde_language'] = NLS::select();
            $html = sprintf('<form name="language" action="%s">',
                            Horde::url($GLOBALS['registry']->getParam('webroot', 'horde') . '/services/language.php', false, -1));
            $html .= '<input type="hidden" name="url" value="' . Horde::selfUrl(false, false, true) . '" />';
            $html .= '<select name="new_lang" onchange="document.language.submit()">';
            foreach ($GLOBALS['nls']['languages'] as $key => $val) {
                $sel = ($key == $_SESSION['horde_language']) ? ' selected="selected"' : '';
                $html .= "<option value=\"$key\"$sel>$val</option>";
            }
            $html .= '</select></form>';
        }
        return $html;
    }

}

--- NEW FILE: Pager.php ---
<?php

require_once dirname(__FILE__) . '/Widget.php';

/**
 * The Horde_UI_Pager:: provides links to individual pages.
 *
 * $Horde: framework/UI/UI/Pager.php,v 1.5 2004/02/25 19:12:35 eraserhd Exp $
 *
 * Copyright 2004 Joel Vandal <jvandal at infoteck.qc.ca>
 *
 * See the enclosed file LICENSE for license information (BSD). If you
 * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
 *
 * @author  Ben Chavet <ben at chavet.net>
 * @author  Joel Vandal <jvandal at infoteck.qc.ca>
 * @author  Chuck Hagenbuch <chuck at horde.org>
 * @version $Revision: 1.1 $
 * @since   Horde_UI 0.0.1
 * @package Horde_UI
 */
class Horde_UI_Pager extends Horde_UI_Widget {

    function Horde_UI_Pager($name, &$vars, $config)
    {
        if (!isset($config['page_limit'])) {
            $config['page_limit'] = 10;
        }
        if (!isset($config['perpage'])) {
            $config['perpage'] = 100;
        }
        parent::Horde_UI_Widget($name, $vars, $config);
    }

    /**
     * Render the pager.
     *
     * @return string  HTML code containing a centered table with the pager
     *      links.
     */
    function render()
    {
        global $prefs, $registry, $conf;

        $num = $this->_config['num'];
        $url = $this->_config['url'];
        $page_limit = $this->_config['page_limit'];
        $perpage = $this->_config['perpage'];

        $current_page = $this->_vars->get($this->_name);

        // Figure out how many pages there will be.
        $pages = ($num / $perpage);
        if (is_integer($pages)) {
            $pages--;
        }
        $pages = (int)$pages;

        // Return nothing if there is only one page.
        if ($pages == 0 || $num == 0) {
            return '';
        }

        $html = '<table cellpadding="2" align="center" border="0" cellspacing="1"><tr>';

        // Create the '<< Prev' link if we are not on the first page.
        $link = Util::addParameter($url, $this->_name, $current_page - 1);
        $link = $this->_addPreserved($link);
        if ($current_page > 0) {
            $html .= '<td>' . Horde::link(Horde::applicationUrl($link),
                                          _("Previous Page"));
            $html .= Horde::img('nav/left.gif', _("Previous Page"),
                                'width="16" height="16" align="middle"',
                                $registry->getParam('graphics', 'horde')) .
                     '</a></td>';
        }

        // Figure out the top & bottom display limits.
        $bottom = $current_page - ($current_page % $page_limit);
        $top = $bottom + $page_limit - 1;

        // Create bottom '[x-y]' link if necessary.
        $link = Util::addParameter($url, $this->_name, $bottom - 1);
        $link = $this->_addPreserved($link);
        if ($bottom > 1) {
            $html .= '<td>' . Horde::link(Horde::applicationUrl($link)) . '[' . ($bottom - $page_limit + 1) . '-' . $bottom . ']</a></td>';
        }

        // Create links to individual pages between limits.
        for ($i = $bottom; $i <= $top && $i <= $pages; $i++) {
            if ($i == $current_page) {
                $html .= '<td><b>(' . ($i + 1) . ')</b></td>';
            } elseif ($i >= 0 && $i <= $pages) {
                $link = Util::addParameter($url, $this->_name, $i);
                $link = $this->_addPreserved($link);
                $html .= '<td>' . Horde::link(Horde::applicationUrl($link)) .
                         ($i + 1) . '</a></td>';
            }
        }

        // Create top '[x-y]' link if necessary.
        if ($top < $pages) {
            $last = $top + $page_limit < $pages ? $top + $page_limit + 1 : $pages + 1;
            $link = Util::addParameter($url, $this->_name, $top + 1);
            $link = $this->_addPreserved($link);
            $html .= '<td>' . Horde::link(Horde::applicationUrl($link)) . '[' .
                     ($top + 2) . '-' . $last . ']</a></td>';
        }

        // Create the 'Next>>' link if we are not on the last page.
        if ($current_page < $pages) {
            $link = Util::addParameter($url, $this->_name, $current_page + 1);
            $link = $this->_addPreserved($link);
            $html .= '<td>' . Horde::link(Horde::applicationUrl($link),
                                          _("Next Page"));
            $html .= Horde::img('nav/right.gif', _("Next Page"),
                                'width="16" height="16" align="middle"',
                                $registry->getParam('graphics', 'horde'))
                     . '</a></td>';
        }

        $html .= '</tr></table>';

        return $html;
    }

}

--- NEW FILE: Table.php ---
<?php

require_once dirname(__FILE__) . '/Widget.php';

/**
 * The Horde_UI_Table:: class displays and allows manipulation of tabular
 * data.
 *
 * $Horde: framework/UI/UI/Table.php,v 1.1 2004/05/02 21:25:56 eraserhd Exp $
 *
 * Copyright 2001 Robert E. Coyle <robertecoyle at hotmail.com>
 *
 * See the enclosed file LICENSE for license information (BSD). If you
 * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
 *
 * @version $Revision: 1.1 $
 * @since   Horde_UI 0.0.1
 * @package Horde_UI
 */
class Horde_UI_Table extends Horde_UI_Widget {

    /**
     * Data loaded from the getTableMetaData API.
     *
     * @access private
     * @var array $_metaData
     */
    var $_metaData = null;

    var $_formVars = array();

    function getMetaData()
    {
        global $registry;
        if (is_null($this->_metaData)) {
            list($app, $name) = explode('/', $this->_config['name']);
            $args = array($name, $this->_config['params']);
            $this->_metaData = $registry->callByPackage($app,
                                                        'getTableMetaData',
                                                        $args);

            // We need to make vars for the columns.
            foreach ($this->_metaData['columns'] as $col) {
                $typename = isset($col['type']) ? $col['type'] : 'text';
                $params = isset($col['params']) ? $col['params'] : array();
                $type = &Horde_Form::getType($typename, $params);

                $var = &new Horde_Form_Variable($col['title'], $col['name'],
                                                $type, false, true, '');
                $this->_formVars[$col['name']] = &$var;
            }
        }
        return $this->_metaData;
    }

    function _getData($start, $end)
    {
        global $registry;
        list($app, $name) = explode('/', $this->_config['name']);
        $args = array($name, $this->_config['params'], $start, $end);
        return $registry->callByPackage($app, 'getTableData', $args);
    }

    function getColumnCount()
    {
        $this->getMetaData();
        return count($this->_metaData['columns']);
    }

    /**
     * Render the tabs.
     */
    function render()
    {
        global $registry;

        $this->getMetaData();

        require_once dirname(__FILE__) . '/VarRenderer.php';
        $varRenderer = &Horde_UI_VarRenderer::singleton('html');

        $html = '<table width="100%" cellspacing="1" cellpadding="0" border="0" class="item"><tr><td align="left" class="header" colspan="' .
                $this->getColumnCount() . '">';

        // Table title.
        if (isset($this->_config['title'])) {
            $title = $this->_config['title'];
        } else {
            $title = _("Table");
        }
        $html .= $title;

        /*
        //
        // Export icon.  We store the parameters in the session so that smart
        // users can't hack it (in Hermes, you could make it show other
        // people's time, for example).
        //
        $id = $this->_config['name'] . ':' . $this->_name;
        $_SESSION['horde']['tables'][$id] = $this->_config;
        $exportlink = Horde::url($registry->getParam('webroot', 'horde') .
                                 '/services/table/export.php');
        $exportlink = Util::addParameter($exportlink, array('id' => $id));

        $html .= '  ' . Horde::link($exportlink, _("Export Data")) .
                 Horde::img('data.gif', _("Export Data"), 'hspace="2"',
                            $registry->getParam('graphics', 'horde')) .
                 '</a>';
        */

        // Column titles.
        $html .= '</td></tr><tr class="item">';
        foreach ($this->_metaData['columns'] as $col) {
            $html .= '<td><b>' . $col['title'] . '</b></td>';
        }
        $html .= '</tr>';

        // Display data.
        $data = $this->_getData(0, $this->_metaData['rows']);
        if (empty($data)) {
            $html .= '<tr><td colspan="' . $this->getColumnCount() . '"><em>' .
                     '    ' .
                     _("(There are no rows to display.)") . '</em></td></tr>';
        } else {
            /* This Variables:: is populated for each table row so that we
             * can use the Horde_UI_VarRenderer:: */
            $vars = &new Variables();
            $form = null;
            foreach ($data as $row) {
                $html .= '<tr class="text" ' .
                         'onmouseover="className=\'text-hi\';" ' .
                         'onmouseout="className=\'text\';">';
                foreach ($row as $key => $value) {
                    $vars->set($key, $value);
                }
                foreach ($this->_metaData['columns'] as $col) {
                    $value = null;
                    if (isset($row[$col['name']])) {
                        $value = $row[$col['name']];
                    }
                    $align = '';
                    if (isset($col['align'])) {
                        $align = ' align="' . htmlspecialchars($col['align']) .
                                 '"';
                    }
                    $html .= "<td$align>";
                    if (!empty($col['nobr'])) {
                        $html .= '<nobr>';
                    }
                    $html .= $varRenderer->render($form, $this->_formVars[$col['name']], $vars);
                    if (!empty($col['nobr'])) {
                        $html .= '</nobr>';
                    }
                    $html .= '</td>';
                }
                $html .= '</tr>';
            }
        }

        $html .= '</table>';
        return $html;
    }

}

--- NEW FILE: Tabs.php ---
<?php

require_once dirname(__FILE__) . '/Widget.php';

/**
 * The Horde_UI_Tabs:: class manages and renders a tab-like interface.
 *
 * $Horde: framework/UI/UI/Tabs.php,v 1.13 2004/03/18 16:47:37 chuck Exp $
 *
 * Copyright 2001 Robert E. Coyle <robertecoyle at hotmail.com>
 *
 * See the enclosed file LICENSE for license information (BSD). If you
 * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
 *
 * @version $Revision: 1.1 $
 * @since   Horde_UI 0.0.1
 * @package Horde_UI
 */
class Horde_UI_Tabs extends Horde_UI_Widget {

    /**
     * The array of tabs.
     * @var array $_tabs
     */
    var $_tabs = array();

    /**
     * Add a tab to the interface.
     *
     * @access public
     *
     * @param string $title    The text which appears on the tab.
     * @param string $link     The target page.
     * @param string $tabname  The value to set the tab variable to.
     */
    function addTab($title, $link, $tabname = null)
    {
        $this->_tabs[] = array('title' => $title, 'link' => $link, 'tabname' => $tabname);
    }

    /**
     * Retreive the title of the tab with the specified name.
     *
     * @access public
     *
     * @param string $tabname  The name of the tab.
     *
     * @return string  The tab's title.
     */
    function getTitleFromAction($tabname)
    {
        foreach ($this->_tabs as $tab) {
            if ($tab['tabname'] == $tabname) {
                return $tab['title'];
            }
        }
        return null;
    }

    /**
     * Render the tabs.
     */
    function render()
    {
        $html = '<table width="100%" cellspacing="0" cellpadding="1" border="0" class="tabset"><tr>';

        $width = round(100.0 / count($this->_tabs));
        $first = true;
        $active = $this->_vars->get($this->_name);

        foreach ($this->_tabs as $tab) {
            $class = 'tab';
            $title = $tab['title'];
            $link = $this->_addPreserved($tab['link']);
            $accesskey = Horde::getAccessKey($title);

            if (!is_null($tab['tabname'])) {
                $link = Util::addParameter($link, $this->_name,
                                           $tab['tabname']);

                if ($active == $tab['tabname']) {
                    $class = 'tab-hi';
                }
            }

            $html .= '<td style="padding-left:10px;"> </td><td width="' .
                $width . '%" align="center" class="' . $class .
                '" onclick="window.location.href=\'' .
                addslashes(Horde::applicationUrl($link)) . '\'"><b>' .
                Horde::link(Horde::applicationUrl($link), $title, $class,
                            null, null, null, $accesskey) .
                Horde::highlightAccessKey($title, $accesskey) .
                '</a></b></td>';
        }

        $html .= '<td style="padding-left:10px;"> </td></tr></table>';
        return $html;
    }

}

--- NEW FILE: VarRenderer.php ---
<?php
/**
 * The Horde_UI_VarRenderer:: class provides base functionality for
 * other Horde UI elements.
 *
 * $Horde: framework/UI/UI/VarRenderer.php,v 1.10 2004/03/20 22:13:14 eraserhd Exp $
 *
 * Copyright 2003-2004 Jason M. Felice <jfelice at cronosys.com>
 *
 * See the enclosed file LICENSE for license information (LGPL).
 *
 * @version $Revision: 1.1 $
 * @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 mixed $driver             This is the renderer subclass we
     *                                  will instantiate.  If an array is
     *                                  passed, the first element is the
     *                                  library path and the second element
     *                                  is the driver name.
     * @param optional array $params    parameters specific to the subclass
     * @return object a Horde_UI_VarRenderer:: subclass instance.
     */
    function &factory($driver, $params = array())
    {
        if (is_array($driver)) {
            $app = $driver[0];
            $driver = $driver[1];
        }

        $driver = basename($driver);

        if (!empty($app)) {
            require_once $GLOBALS['registry']->getParam('fileroot', $app) . '/lib/UI/VarRenderer/' . $driver . '.php';
        } elseif (@file_exists(dirname(__FILE__) . '/VarRenderer/' . $driver . '.php')) {
            require_once dirname(__FILE__) . '/VarRenderer/' . $driver . '.php';
        } else {
            @include_once 'Horde/UI/VarRenderer/' . $driver . '.php';
        }

        $class = 'Horde_UI_VarRenderer_' . $driver;
        if (class_exists($class)) {
            return $ret = &new $class($params);
        } else {
            return PEAR::raiseError('Class definition of ' . $class . ' not found.');
        }
    }

    /**
     * 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 Variables::
     * @param bool $isInput             Whether this is an input field.
     */
    function render(&$form, &$var, &$vars, $isInput = false)
    {
        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);
    }

    /**
     * Finish rendering after all fields are output.
     */
    function renderEnd()
    {
        return "";
    }

}

--- NEW FILE: Widget.php ---
<?php
/**
 * The Horde_UI_Widget:: class provides base functionality for other Horde
 * UI elements.
 *
 * $Horde: framework/UI/UI/Widget.php,v 1.6 2004/02/25 19:12:35 eraserhd Exp $
 *
 * Copyright 2003-2004 Jason M. Felice <jfelice at cronosys.com>
 *
 * See the enclosed file LICENSE for license information (LGPL).
 *
 * @version $Revision: 1.1 $
 * @since   Horde_UI 0.0.1
 * @package Horde_UI
 */
class Horde_UI_Widget {

    /**
     * Any variables that should be preserved in all of the widget's
     * links.
     * @var array $_preserve
     */
    var $_preserve = array();

    /**
     * The name of this widget.  This is used as the basename for variables
     * we access and manipulate.
     * @var string $_name
     */
    var $_name;

    /**
     * A reference to a Variables:: object this widget will use and
     * manipulate.
     * @var object Variables $_vars
     */
    var $_vars;

    /**
     * An array of name => value pairs which configure how this widget
     * behaves.
     */
    var $_config;

    /**
     * Construct a new UI Widget interface.
     *
     * @access public
     *
     * @param string $name                   The name of the variable which
     *                                       will track this UI widget's state.
     * @param object Variables &$vars  A Variables:: object.
     * @param optional array $config         The widget's configuration.
     */
    function Horde_UI_Widget($name, &$vars, $config = array())
    {
        $this->_name = $name;
        $this->_vars = &$vars;
        $this->_config = $config;
    }

    /**
     * Instruct Horde_UI_Widget:: to preserve a variable.
     *
     * @access public
     *
     * @param string $var    The name of the variable to preserve.
     * @param mixed  $value  The value of the variable to preserve.
     */
    function preserve($var, $value)
    {
        $this->_preserve[$var] = $value;
    }

    /**
     * @access private
     */
    function _addPreserved($link)
    {
        foreach ($this->_preserve as $varName => $varValue) {
            $link = Util::addParameter($link, $varName, $varValue);
        }
        return $link;
    }

    /**
     * Render the widget.
     *
     * @abstract
     *
     * @param optional mixed $data  The widget's state data.
     */
    function render() {}

}





More information about the commits mailing list