81dee53dc4d9050bcd1a150a021a2462e0bea5e6
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
14 * Class that is responsible for paginating data. Takes passed
15 * parameters and creates pagination links.
32 * Number of page links
38 * Total number of results
44 * Total number of pages
56 * Constructor: sanitize incoming variables
58 * @param string Name of page number variable
59 * @param string Name of per-page variable
61 function Pagination($page, $perpage)
65 $this->page
= intval($bugsys->in
["$page"]);
66 $this->perpage
= intval($bugsys->in
["$perpage"]);
67 $this->pagelinks
= intval($bugsys->options
['pagelinks']);
69 $this->vars
= array('p' => $page, 'pp' => $perpage);
76 if ($this->perpage
<= 0)
78 $this->perpage
= $bugsys->options
['defaultpp'];
80 if ($this->perpage
> $bugsys->options
['maxpp'])
82 $this->perpage
= $bugsys->options
['maxpp'];
87 * Takes the variables and splits up the pages
91 function split_pages()
93 $this->pagecount
= ceil($this->total
/ $this->perpage
);
97 * Returns the lower limit of the pages
101 * @param integer Page number
103 * @return integer Lower result limit
105 function fetch_limit($page = null
)
116 else if ($page > $this->pagecount
)
118 $page = $this->pagecount
- 1;
121 $limit = $page * $this->perpage
;
127 else if ($limit > $this->total
)
138 * Constructs the page navigator
142 * @param string Base link path
144 * @return string Generated HTML page navigator
146 function construct_page_nav($baselink)
151 if (strpos($baselink, '?') === false
)
155 else if (!preg_match('#\?$#', $baselink) AND !preg_match('#(&|&)$#', $baselink))
157 $baselink .= '&';
160 // first page number in page nav
161 $startpage = $this->page
- $this->pagelinks
;
167 // last page number in page nav
168 $endpage = $this->page +
$this->pagelinks
;
169 if ($endpage > $this->pagecount
)
171 $endpage = $this->pagecount
;
174 // prev page in page nav
175 $prevpage = $this->page
- 1;
181 // next page in page nav
182 $nextpage = $this->page +
1;
183 if ($nextpage > $this->pagecount
)
185 $nextpage = $this->pagecount
;
188 // show the prev page
189 $show['prev'] = true
;
190 if ($this->page
== $startpage)
192 $show['prev'] = false
;
195 // show the next page
196 $show['next'] = true
;
197 if ($this->page
== $endpage)
199 $show['next'] = false
;
202 // show the first page
203 $show['first'] = false
;
206 $show['first'] = true
;
209 // show the last page
210 $show['last'] = false
;
211 if ($endpage < $this->pagecount
)
213 $show['last'] = true
;
216 // construct the page bits
217 for ($i = $startpage; $i <= $endpage; $i++
)
219 if ($i == $this->page
)
227 eval('$pagebits[] .= "' . $bugsys->template
->fetch('pagenav_bit') . '";');
230 $pagebits = implode(",\n", $pagebits);
232 eval('$pagenav = "' . $bugsys->template
->fetch('pagenav') . '";');
238 /*=====================================================================*\
239 || ###################################################################
242 || ###################################################################
243 \*=====================================================================*/