]>
src.bluestatic.org Git - bugdar.git/blob - includes/class_pagination.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 \*=====================================================================*/
23 * Class that is responsible for paginating data. Takes passed
24 * parameters and creates pagination links.
41 * Number of page links
47 * Total number of results
53 * Total number of pages
65 * Constructor: sanitize incoming variables
67 * @param string Name of page number variable
68 * @param string Name of per-page variable
70 function Pagination($page, $perpage)
74 $this->page
= intval($bugsys->in
["$page"]);
75 $this->perpage = intval($bugsys->in["$perpage"]);
76 $this->pagelinks
= intval($bugsys->options
['pagelinks']);
78 $this->vars
= array('p' => $page, 'pp' => $perpage);
85 if ($this->perpage
<= 0)
87 $this->perpage
= $bugsys->options
['defaultpp'];
89 if ($this->perpage
> $bugsys->options
['maxpp'])
91 $this->perpage
= $bugsys->options
['maxpp'];
94 $this->perpage
= intval($this->perpage
);
98 * Takes the variables and splits up the pages
102 function split_pages()
104 $this->pagecount
= ceil($this->total
/ $this->perpage
);
108 * Returns the lower limit of the pages
112 * @param integer Page number
114 * @return integer Lower result limit
116 function fetch_limit($page = null)
123 $limit = $page * $this->perpage
;
130 else if ($page > $this->pagecount
)
132 $page = $this->pagecount
- 1;
133 $limit = $this->total
;
140 else if ($limit > $this->total
)
151 * Constructs the page navigator
155 * @param string Base link path
157 * @return string Generated HTML page navigator
159 function construct_page_nav($baselink)
164 if (strpos($baselink, '?') === false)
168 else if (!preg_match('#\?$#', $baselink) AND !preg_match('#(&|&)$#', $baselink))
170 $baselink .= '&';
173 // first page number in page nav
174 $startpage = $this->page
- $this->pagelinks
;
180 // last page number in page nav
181 $endpage = $this->page +
$this->pagelinks
;
182 if ($endpage > $this->pagecount
)
184 $endpage = $this->pagecount
;
187 // prev page in page nav
188 $prevpage = $this->page
- 1;
194 // next page in page nav
195 $nextpage = $this->page +
1;
196 if ($nextpage > $this->pagecount
)
198 $nextpage = $this->pagecount
;
201 // show the prev page
202 $show['prev'] = true;
203 if ($this->page
== $startpage)
205 $show['prev'] = false;
208 // show the next page
209 $show['next'] = true;
210 if ($this->page
== $endpage)
212 $show['next'] = false;
215 // show the first page
216 $show['first'] = false;
219 $show['first'] = true;
222 // show the last page
223 $show['last'] = false;
224 if ($endpage < $this->pagecount
)
226 $show['last'] = true;
229 // construct the page bits
230 for ($i = $startpage; $i <= $endpage; $i++
)
232 if ($i == $this->page
)
240 eval('$pagebits[] .= "' . $bugsys->template
->fetch('pagenav_bit') . '";');
243 $pagebits = implode(",\n", $pagebits);
245 eval('$pagenav = "' . $bugsys->template
->fetch('pagenav') . '";');
251 /*=====================================================================*\
252 || ###################################################################
255 || ###################################################################
256 \*=====================================================================*/