page = intval($bugsys->in["$page"]); $this->perpage = intval($bugsys->in["$perpage"]); $this->pagelinks = intval($bugsys->options['pagelinks']); $this->vars = array('p' => $page, 'pp' => $perpage); if ($this->page <= 0) { $this->page = 1; } if ($this->perpage <= 0) { $this->perpage = $bugsys->options['defaultpp']; } if ($this->perpage > $bugsys->options['maxpp']) { $this->perpage = $bugsys->options['maxpp']; } $this->perpage = intval($this->perpage); } /** * Takes the variables and splits up the pages * * @access protected */ function split_pages() { $this->pagecount = ceil($this->total / $this->perpage); if ($this->pagelinks == 0) { $this->pagelinks = $this->pagecount; } } /** * Returns the lower limit of the pages * * @access public * * @param integer Page number * * @return integer Lower result limit */ function fetch_limit($page = null) { if ($page === null) { $page = $this->page; } $limit = $page * $this->perpage; if ($page < 1) { $page = 1; $limit = 0; } else if ($page > $this->pagecount) { $page = $this->pagecount - 1; $limit = $this->total; } if ($limit < 0) { return 0; } else if ($limit > $this->total) { return $this->total; } else { return $limit; } } /** * Constructs the page navigator * * @access public * * @param string Base link path * * @return string Generated HTML page navigator */ function construct_page_nav($baselink) { global $bugsys; // handle base link if (strpos($baselink, '?') === false) { $baselink .= '?'; } else if (!preg_match('#\?$#', $baselink) AND !preg_match('#(&|&)$#', $baselink)) { $baselink .= '&'; } // first page number in page nav $startpage = $this->page - $this->pagelinks; if ($startpage < 1) { $startpage = 1; } // last page number in page nav $endpage = $this->page + $this->pagelinks; if ($endpage > $this->pagecount) { $endpage = $this->pagecount; } // prev page in page nav $prevpage = $this->page - 1; if ($prevpage < 1) { $prevpage = 1; } // next page in page nav $nextpage = $this->page + 1; if ($nextpage > $this->pagecount) { $nextpage = $this->pagecount; } // show the prev page $show['prev'] = true; if ($this->page == $startpage) { $show['prev'] = false; } // show the next page $show['next'] = true; if ($this->page == $endpage) { $show['next'] = false; } // show the first page $show['first'] = false; if ($startpage > 1) { $show['first'] = true; } // show the last page $show['last'] = false; if ($endpage < $this->pagecount) { $show['last'] = true; } // construct the page bits $pagebits = array(); for ($i = $startpage; $i <= $endpage; $i++) { if ($i == $this->page) { $nolink = true; } else { $nolink = false; } eval('$pagebits[] .= "' . $bugsys->template->fetch('pagenav_bit') . '";'); } $pagebits = implode(",\n", $pagebits); eval('$pagenav = "' . $bugsys->template->fetch('pagenav') . '";'); return $pagenav; } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>