* @copyright 2003-2007 Lorenzo Alberton * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version CVS: $Id: HtmlWidgets.php,v 1.7 2009/03/13 16:51:37 quipo Exp $ * @link http://pear.php.net/package/Pager */ /** * Pager_HtmlWidgets * * @category HTML * @package Pager * @author Lorenzo Alberton * @copyright 2003-2007 Lorenzo Alberton * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @link http://pear.php.net/package/Pager */ class Pager_HtmlWidgets { var $pager = null; // {{{ constructor /** * Constructor * * @param object &$pager Pager instance */ function __construct(&$pager) { $this->pager =& $pager; } // }}} // {{{ getPerPageSelectBox() /** * Returns a string with a XHTML SELECT menu, * useful for letting the user choose how many items per page should be * displayed. If parameter useSessions is TRUE, this value is stored in * a session var. The string isn't echoed right now so you can use it * with template engines. * * @param integer $start starting value for the select menu * @param integer $end ending value for the select menu * @param integer $step step between values in the select menu * @param boolean $showAllData If true, perPage is set equal to totalItems. * @param array $extraParams (or string $optionText for BC reasons) * - 'optionText': text to show in each option. * Use '%d' where you want to see the number of pages selected. * - 'attributes': (html attributes) Tag attributes or * HTML attributes (id="foo" pairs), will be inserted in the * pager->_httpMethod) { $selector = '\' + '.'this.options[this.selectedIndex].value + \''; if ($this->pager->_append) { $tmpLinkData = $this->pager->_linkData; if (isset($tmpLinkData[$this->pager->_urlVar])) { $tmpLinkData[$this->pager->_urlVar] = $this->pager->getCurrentPageID(); } $tmpLinkData[$this->pager->_sessionVar] = '1'; $href = '?' . $this->pager->_http_build_query_wrapper($tmpLinkData); $href = htmlentities($this->pager->_url, ENT_COMPAT, 'UTF-8'). preg_replace( '/(&|&|\?)('.$this->pager->_sessionVar.'=)(\d+)/', '\\1\\2'.$selector, htmlentities($href, ENT_COMPAT, 'UTF-8') ); } else { $href = htmlentities($this->pager->_url . str_replace('%d', $selector, $this->pager->_fileName), ENT_COMPAT, 'UTF-8'); } $tmp .= ' onchange="document.location.href=\'' . $href .'\'' . '"'; } elseif ($this->pager->_httpMethod == 'POST') { $tmp .= " onchange='" . $this->pager->_generateFormOnClick($this->pager->_url, $this->pager->_linkData) . "'"; $tmp = preg_replace( '/(input\.name = \"'.$this->pager->_sessionVar.'\"; input\.value =) \"(\d+)\";/', '\\1 this.options[this.selectedIndex].value;', $tmp ); } } $tmp .= '>'; $last = $start; for ($i=$start; $i<=$end; $i+=$step) { $last = $i; $tmp .= ''; } if (substr($tmp, -9, 9) !== '') { //empty select $tmp .= '