1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17: class extends Horde_Core_Ui_Widget
18: {
19: 20: 21: 22: 23:
24: public function __construct($name, $vars, $config)
25: {
26: $config = array_merge(array(
27: 'page_limit' => 10,
28: 'perpage' => 100
29: ), $config);
30:
31: parent::__construct($name, $vars, $config);
32:
33:
34: if (!($this->_config['url'] instanceof Horde_Url)) {
35: $this->_config['url'] = new Horde_Url($this->_config['url']);
36: }
37: }
38:
39: 40: 41: 42: 43: 44:
45: public function render($data = null)
46: {
47: global $prefs, $registry, $conf;
48:
49: $num = $this->_config['num'];
50: $url = $this->_config['url'];
51:
52: $page_limit = $this->_config['page_limit'];
53: $perpage = $this->_config['perpage'];
54:
55: $current_page = $this->_vars->get($this->_name);
56:
57:
58: $pages = ($num / $perpage);
59: if (is_integer($pages)) {
60: $pages--;
61: }
62: $pages = (int)$pages;
63:
64:
65: if ($pages == 0 || $num == 0) {
66: return '';
67: }
68:
69: $html = '<div class="pager">';
70:
71: if ($current_page > 0) {
72:
73: $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $current_page - 1)));
74:
75: $prev_text = isset($this->_config['previousHTML'])
76: ? $this->_config['previousHTML']
77: : htmlspecialchars(Horde_Core_Translation::t("<Previous"));
78:
79: $html .= Horde::link($link, '', 'prev') . $prev_text . '</a>';
80: }
81:
82:
83: $bottom = max(0, $current_page - ($page_limit / 2) + 1);
84: $top = $bottom + $page_limit - 1;
85: if ($top - 1 > $pages) {
86: $bottom -= ($top - 1) - $pages;
87: $top = $pages + 1;
88: }
89:
90:
91: if ($bottom > 0) {
92: $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $bottom - 1)));
93: $html .= ' ' . Horde::link($link, '', 'prevRange') . '[' . ($bottom == 1 ? $bottom : '1-' . $bottom) . ']</a>';
94: }
95:
96:
97: for ($i = $bottom; $i <= $top && $i <= $pages; ++$i) {
98: if ($i == $current_page) {
99: $html .= ' <strong>(' . ($i + 1) . ')</strong>';
100: } elseif ($i >= 0 && $i <= $pages) {
101: $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $i)));
102: $html .= ' ' . Horde::link($link) . ($i + 1) . '</a>';
103: }
104: }
105:
106:
107: if ($top < $pages) {
108: $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $top + 1)));
109:
110: $html .= ' ' . Horde::link($link, '', 'nextRange') . '[' .
111: ($top + 2 == $pages + 1 ? $pages + 1 : ($top + 2) . '-' . ($pages + 1)) . ']</a>';
112: }
113:
114:
115: if ($current_page < $pages) {
116: $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $current_page + 1)));
117:
118: $next_text = isset($this->_config['nextHTML'])
119: ? $this->_config['nextHTML']
120: : htmlspecialchars(Horde_Core_Translation::t("Next>"));
121:
122: $html .= ' ' . Horde::link($link, '', 'next') . $next_text . '</a>';
123: }
124:
125: return $html . '</div>';
126: }
127:
128: }
129: