2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
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
64 * Number of page links
71 * Total number of results
78 * Total number of pages
85 * Name of page variable
92 * Name of per-page variable
99 * Maximum number of per-page results
103 var $maxperpage = 100;
106 * Default number of per-page results
110 var $defaultperpage = 20;
112 // ###################################################################
116 function __construct(&$registry)
118 $this->registry
=& $registry;
121 // ###################################################################
123 * (PHP 4) Constructor
125 function Pagination(&$registry)
127 $this->__construct($registry);
130 // ###################################################################
136 * @param integer Total number
138 function setTotal($total)
140 $this->total
= $total;
143 // ###################################################################
149 * @param integer Number of page links
151 function setPageLinks($pagelinks)
153 $this->pagelinks
= $pagelinks;
156 // ###################################################################
162 * @param string Page variable
164 function setPageVar($pagevar)
166 $this->pagevar
= $pagevar;
169 // ###################################################################
175 * @param string Per-page variable
177 function setPerPageVar($perpagevar)
179 $this->perpagevar
= $perpagevar;
182 // ###################################################################
188 * @param integer Maximum number per page
190 function setMaxPerPage($maxperpage)
192 $this->maxperpage
= $maxperpage;
195 // ###################################################################
197 * Sets defaultperpage
201 * @param integer Total number
203 function setDefaultPerPage($defaultperpage)
205 $this->defaultperpage
= $defaultperpage;
208 // ###################################################################
210 * Takes the variables and splits up the pages
214 function split_pages()
216 $this->page
= $this->registry
->input_clean($this->pagevar
, TYPE_INT
);
217 $this->perpage
= $this->registry
->input_clean($this->perpagevar
, TYPE_INT
);
218 $this->pagelinks
= $this->registry
->input_clean($this->pagelinks
, TYPE_INT
);
220 if ($this->page
<= 0)
225 if ($this->perpage
<= 0)
227 $this->perpage
= $this->defaultperpage
;
229 if ($this->perpage
> $this->maxperpage
['maxpp'])
231 $this->perpage
= $this->maxperpage
['maxpp'];
234 $this->perpage
= $this->registry
->clean($this->perpage
, TYPE_INT
);
236 $this->pagecount
= ceil($this->total
/ $this->perpage
);
239 // ###################################################################
241 * Returns the lower limit of the pages
245 * @param integer Page number
247 * @return integer Lower result limit
249 function fetch_limit($page = null
)
256 $limit = $page * $this->perpage
;
263 else if ($page > $this->pagecount
)
265 $page = $this->pagecount
- 1;
266 $limit = $this->total
;
273 else if ($limit > $this->total
)
283 // ###################################################################
285 * Constructs the page navigator
289 * @param string Base link path
291 * @return string Generated HTML page navigator
293 function construct_page_nav($baselink)
298 if (strpos($baselink, '?') === false
)
302 else if (!preg_match('#\?$#', $baselink) AND !preg_match('#(&|&)$#', $baselink))
304 $baselink .= '&';
307 // first page number in page nav
308 $startpage = $this->page
- $this->pagelinks
;
314 // last page number in page nav
315 $endpage = $this->page +
$this->pagelinks
;
316 if ($endpage > $this->pagecount
)
318 $endpage = $this->pagecount
;
321 // prev page in page nav
322 $prevpage = $this->page
- 1;
328 // next page in page nav
329 $nextpage = $this->page +
1;
330 if ($nextpage > $this->pagecount
)
332 $nextpage = $this->pagecount
;
335 // show the prev page
336 $show['prev'] = true
;
337 if ($this->page
== $startpage)
339 $show['prev'] = false
;
342 // show the next page
343 $show['next'] = true
;
344 if ($this->page
== $endpage)
346 $show['next'] = false
;
349 // show the first page
350 $show['first'] = false
;
353 $show['first'] = true
;
356 // show the last page
357 $show['last'] = false
;
358 if ($endpage < $this->pagecount
)
360 $show['last'] = true
;
363 // construct the page bits
364 for ($i = $startpage; $i <= $endpage; $i++
)
366 if ($i == $this->page
)
375 eval('$pagebits[] .= "' . $this->registry
->modules
['template']->fetch('pagenav_bit') . '";');
378 $pagebits = implode(",\n", $pagebits);
380 eval('$pagenav = "' . $this->registry
->modules
['template']->fetch('pagenav') . '";');
386 /*=====================================================================*\
387 || ###################################################################
390 || ###################################################################
391 \*=====================================================================*/