123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- <?php
- class Pager_HtmlWidgets
- {
- var $pager = null;
-
-
- function Pager_HtmlWidgets(&$pager)
- {
- $this->pager =& $pager;
- }
-
-
-
- function getPerPageSelectBox($start=5, $end=30, $step=5, $showAllData=false, $extraParams=array())
- {
-
- $optionText = '%d';
- $attributes = '';
- $checkMaxLimit = false;
- if (is_string($extraParams)) {
-
- $optionText = $extraParams;
- } else {
- if (array_key_exists('optionText', $extraParams)) {
- $optionText = $extraParams['optionText'];
- }
- if (array_key_exists('attributes', $extraParams)) {
- $attributes = $extraParams['attributes'];
- }
- if (array_key_exists('checkMaxLimit', $extraParams)) {
- $checkMaxLimit = $extraParams['checkMaxLimit'];
- }
- }
- if (!strstr($optionText, '%d')) {
- return $this->pager->raiseError(
- $this->pager->errorMessage(ERROR_PAGER_INVALID_PLACEHOLDER),
- ERROR_PAGER_INVALID_PLACEHOLDER
- );
- }
- $start = (int)$start;
- $end = (int)$end;
- $step = (int)$step;
- if (!empty($_SESSION[$this->pager->_sessionVar])) {
- $selected = (int)$_SESSION[$this->pager->_sessionVar];
- } else {
- $selected = $this->pager->_perPage;
- }
- if ($checkMaxLimit && $this->pager->_totalItems >= 0 && $this->pager->_totalItems < $end) {
- $end = $this->pager->_totalItems;
- }
- $tmp = '<select name="'.$this->pager->_sessionVar.'"';
- if (!empty($attributes)) {
- $tmp .= ' '.$attributes;
- }
- if (!empty($extraParams['autoSubmit'])) {
- if ('GET' == $this->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 .= '<option value="'.$i.'"';
- if ($i == $selected) {
- $tmp .= ' selected="selected"';
- }
- $tmp .= '>'.sprintf($optionText, $i).'</option>';
- }
- if ($showAllData && $last != $this->pager->_totalItems) {
- $tmp .= '<option value="'.$this->pager->_totalItems.'"';
- if ($this->pager->_totalItems == $selected) {
- $tmp .= ' selected="selected"';
- }
- $tmp .= '>';
- if (empty($this->pager->_showAllText)) {
- $tmp .= str_replace('%d', $this->pager->_totalItems, $optionText);
- } else {
- $tmp .= $this->pager->_showAllText;
- }
- $tmp .= '</option>';
- }
- if (substr($tmp, -9, 9) !== '</option>') {
-
- $tmp .= '<option />';
- }
- $tmp .= '</select>';
- return $tmp;
- }
-
-
-
- function getPageSelectBox($params = array(), $extraAttributes = '')
- {
- $optionText = '%d';
- if (array_key_exists('optionText', $params)) {
- $optionText = $params['optionText'];
- }
- if (!strstr($optionText, '%d')) {
- return $this->pager->raiseError(
- $this->pager->errorMessage(ERROR_PAGER_INVALID_PLACEHOLDER),
- ERROR_PAGER_INVALID_PLACEHOLDER
- );
- }
- $tmp = '<select name="'.$this->pager->_urlVar.'"';
- if (!empty($extraAttributes)) {
- $tmp .= ' '.$extraAttributes;
- }
- if (!empty($params['autoSubmit'])) {
- if ($this->pager->_httpMethod == 'GET') {
- $selector = '\' + '.'this.options[this.selectedIndex].value + \'';
- if ($this->pager->_append) {
- $href = '?' . $this->pager->_http_build_query_wrapper($this->pager->_linkData);
-
-
-
-
-
- $href = api_htmlentities($this->pager->_url). preg_replace(
- '/(&|&|\?)('.$this->pager->_urlVar.'=)(\d+)/',
- '\\1\\2'.$selector,
- api_htmlentities($href)
- );
-
- } else {
-
-
- $href = api_htmlentities($this->pager->_url . str_replace('%d', $selector, $this->pager->_fileName));
-
- }
- $tmp .= ' onchange="javascript: 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->_urlVar.'\"; input\.value =) \"(\d+)\";/',
- '\\1 this.options[this.selectedIndex].value;',
- $tmp
- );
- }
- }
- $tmp .= '>';
- $start = 1;
- $end = $this->pager->numPages();
- $selected = $this->pager->getCurrentPageID();
- for ($i=$start; $i<=$end; $i++) {
- $tmp .= '<option value="'.$i.'"';
- if ($i == $selected) {
- $tmp .= ' selected="selected"';
- }
- $tmp .= '>'.sprintf($optionText, $i).'</option>';
- }
- $tmp .= '</select>';
- return $tmp;
- }
-
- }
- ?>
|