2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
32 * On many pages, it is necessary to limit the amount of records to display.
33 * Using this class, you can set the maximum and minimum values to display,
34 * and then the input variables for page number and perpage. This will
35 * then create a page navigator and manage the SQL LIMIT statements.
38 * pagenav_bit - The individual page numbers in the page navigator
39 * pagenav - The entirity of the page navigtaor
42 * @copyright Copyright ©2002 - [#]year[#], Blue Static
62 * Number of page links
68 * Total number of results
74 * Total number of pages
80 * Name of page variable
86 * Name of per-page variable
92 * Maximum number of per-page results
95 private $maxperpage = 100;
98 * Default number of per-page results
101 private $defaultperpage = 20;
107 private $fields = array(
108 'total' => array(REQ_YES
, null
, false
),
109 'pagelinks' => array(REQ_YES
, null
, false
),
110 'pagevar' => array(REQ_YES
, null
, false
),
111 'perpagevar' => array(REQ_YES
, null
, false
),
112 'maxperpage' => array(REQ_YES
, null
, true
),
113 'defaultperpage' => array(REQ_YES
, null
, true
)
116 // ###################################################################
120 function __construct(&$registry)
122 $this->registry
=& $registry;
125 // ###################################################################
127 * (PHP 4) Constructor
129 function Pagination(&$registry)
131 $this->__construct($registry);
134 // ###################################################################
140 * @param string Field name
141 * @param mixed Value of the field
143 function set($name, $value)
145 $this->registry
->do_set($name, $value, 'pagination');
148 // ###################################################################
154 * @param string Field name
156 * @return mixed Value of the field
158 function get($fieldname)
160 return $this->registry
->do_get($fieldname, 'pagination');
164 * Takes the variables and splits up the pages
168 function split_pages()
170 $this->page
= $this->registry
->input_clean($this->pagevar
, TYPE_INT
);
171 $this->perpage
= $this->registry
->input_clean($this->perpagevar
, TYPE_INT
);
172 $this->pagelinks
= $this->registry
->input_clean($this->pagelinkx
, TYPE_INT
);
174 if ($this->page
<= 0)
179 if ($this->perpage
<= 0)
181 $this->perpage
= $this->defaultperpage
;
183 if ($this->perpage
> $this->maxperpage
['maxpp'])
185 $this->perpage
= $this->maxperpage
['maxpp'];
188 $this->perpage
= $this->registry
->clean($this->perpage
, TYPE_INT
);
190 $this->pagecount
= ceil($this->total
/ $this->perpage
);
194 * Returns the lower limit of the pages
198 * @param integer Page number
200 * @return integer Lower result limit
202 function fetch_limit($page = null
)
209 $limit = $page * $this->perpage
;
216 else if ($page > $this->pagecount
)
218 $page = $this->pagecount
- 1;
219 $limit = $this->total
;
226 else if ($limit > $this->total
)
237 * Constructs the page navigator
241 * @param string Base link path
243 * @return string Generated HTML page navigator
245 function construct_page_nav($baselink)
250 if (strpos($baselink, '?') === false
)
254 else if (!preg_match('#\?$#', $baselink) AND !preg_match('#(&|&)$#', $baselink))
256 $baselink .= '&';
259 // first page number in page nav
260 $startpage = $this->page
- $this->pagelinks
;
266 // last page number in page nav
267 $endpage = $this->page +
$this->pagelinks
;
268 if ($endpage > $this->pagecount
)
270 $endpage = $this->pagecount
;
273 // prev page in page nav
274 $prevpage = $this->page
- 1;
280 // next page in page nav
281 $nextpage = $this->page +
1;
282 if ($nextpage > $this->pagecount
)
284 $nextpage = $this->pagecount
;
287 // show the prev page
288 $show['prev'] = true
;
289 if ($this->page
== $startpage)
291 $show['prev'] = false
;
294 // show the next page
295 $show['next'] = true
;
296 if ($this->page
== $endpage)
298 $show['next'] = false
;
301 // show the first page
302 $show['first'] = false
;
305 $show['first'] = true
;
308 // show the last page
309 $show['last'] = false
;
310 if ($endpage < $this->pagecount
)
312 $show['last'] = true
;
315 // construct the page bits
316 for ($i = $startpage; $i <= $endpage; $i++
)
318 if ($i == $this->page
)
327 eval('$pagebits[] .= "' . $this->registry
->modules
['template']->fetch('pagenav_bit') . '";');
330 $pagebits = implode(",\n", $pagebits);
332 eval('$pagenav = "' . $this->registry
->modules
['template']->fetch('pagenav') . '";');
338 /*=====================================================================*\
339 || ###################################################################
342 || ###################################################################
343 \*=====================================================================*/