pagenumber = 1; $this->pagesize = 20; $this->totalrecords = 0; $this->showfirst = true; $this->showlast = true; $this->paginationcss = "pagination-small"; $this->paginationstyle = 0; // 1: advance, 0: normal, 2: pager $this->defaultUrl = "#"; // in case of ajax pagination $this->paginationUrl = "#"; // # incase of ajax pagination e.g index.php?p=[p] --> $this->prevCss = "previous"; $this->nextCss = "next"; } function process() { $paginationlst = ""; $firstbound =0; $lastbound =0; $tooltip = ""; if($this->totalrecords > $this->pagesize) { $totalpages = ceil($this->totalrecords / $this->pagesize); if ($this->pagenumber > 1) { if ($this->showfirst && $this->paginationstyle != 2) { $firstbound = 1; $lastbound = $firstbound + $this->pagesize - 1; $tooltip = "showing " . $firstbound . " - " . $lastbound . " records of " . $this->totalrecords . " records"; // First Link if($this->defaultUrl == "") $this->defaultUrl = "#"; $paginationlst .= "
  • defaultUrl . "\" class=\"pagination-css\" data-toggle=\"tooltip\" title=\"" . $tooltip . "\">
  • \n"; } $firstbound = (($totalpages - 1) * $this->pagesize); $lastbound = $firstbound + $this->pagesize - 1; if ($lastbound > $this->totalrecords) { $lastbound = $this->totalrecords; } $tooltip = "showing " . $firstbound . " - " . $lastbound . " records of " . $this->totalrecords . " records"; // Previous Link Enabled if($this->paginationUrl == "") $this->paginationUrl = "#"; $pid = ($this->pagenumber - 1); if($pid < 1) $pid = 1; $prevPageCss = ""; $prevIcon = ""; if($this->paginationstyle == 2) { if($this->prevCss != "") $prevPageCss = " class=\"" . $this->prevCss . "\""; $prevIcon = "← Previous"; } $paginationlst .= "prepareUrl($pid) . "\" data-toggle=\"tooltip\" class=\"pagination-css\" title=\"" . $tooltip . "\">" . $prevIcon . "\n"; // Normal Links if($this->paginationstyle != 2) $paginationlst .= $this->generate_pagination_links($totalpages, $this->totalrecords, $this->pagenumber, $this->pagesize); if($this->pagenumber < $totalpages) { $paginationlst .= $this->generate_previous_last_links($totalpages, $this->totalrecords, $this->pagenumber, $this->pagesize, $this->showlast); } } else { // Normal Links if($this->paginationstyle != 2) $paginationlst .= $this->generate_pagination_links($totalpages, $this->totalrecords, $this->pagenumber, $this->pagesize); // Next Last Links $paginationlst .= $this->generate_previous_last_links($totalpages, $this->totalrecords, $this->pagenumber, $this->pagesize, $this->showlast); } } $paginationCss = "pagination " . $this->paginationcss; if($this->paginationstyle == 2) $paginationCss = "pager"; return "\n"; } function generate_pagination_links($totalpages, $totalrecords, $pagenumber, $pagesize) { $script = ""; $firstbound = 0; $lastbound = 0; $tooltip = ""; $lst = new pagination(); if($this->paginationstyle == 1) $arr = $lst->advance_pagination_links($totalpages, $pagenumber); else $arr = $lst->simple_pagination_links($totalpages, 15, $pagenumber); if(count($arr) > 0) { foreach ($arr as $item){ $firstbound = (($item - 1) * $pagesize) + 1; $lastbound = $firstbound + $pagesize - 1; if ($lastbound > $totalrecords) $lastbound = $totalrecords; $tooltip = "showing " . $firstbound . " - " . $lastbound . " records of " . $totalrecords . " records"; $css = ""; if ($item == $pagenumber) $css = " class=\"active\""; $script .= "prepareUrl($item) . "\" class=\"pagination-css\" data-toggle=\"tooltip\" title=\"" . $tooltip . "\">" . $item . "\n"; } } return $script; } function generate_previous_last_links($totalpages, $totalrecords, $pagenumber, $pagesize, $showlast) { $script = ""; $firstbound = (($pagenumber) * $pagesize) + 1; $lastbound = $firstbound + $pagesize - 1; if ($lastbound > $totalrecords) $lastbound = $totalrecords; $tooltip = "showing " . $firstbound . " - " . $lastbound . " records of " . $totalrecords . " records"; // Next Link $pid = ($pagenumber + 1); if($pid > $totalpages) $pid = $totalpages; $nextPageCss = ""; $nextPageIcon = ""; if($this->paginationstyle == 2) { if($this->nextCss != "") $nextPageCss = " class=\"" . $this->nextCss . "\""; $nextPageIcon = "Next →"; } $script .= "prepareUrl($pid) . "\" class=\"pagination-css\" data-toggle=\"tooltip\" title=\"" . $tooltip . "\">" . $nextPageIcon . "\n"; if ($showlast && $this->paginationstyle != 2) { // Last Link $firstbound = (($totalpages - 1) * $pagesize) + 1; $lastbound = $firstbound + $pagesize - 1; if ($lastbound > $totalpages) $lastbound = $totalpages; $tooltip = "showing " . $firstbound . " - " . $lastbound . " records of " . $totalrecords . " records"; $script .= "
  • prepareUrl($totalpages) . "\" class=\"pagination-css\" data-toggle=\"tooltip\" title=\"" . $tooltip . "\">
  • \n"; } return $script; } function prepareUrl($pid) { if($this->paginationUrl == "") $this->paginationUrl = "#"; if($pid > 1) return preg_replace("/\[p\]/", $pid, $this->paginationUrl); else return preg_replace("/\[p\]/", $pid, $this->defaultUrl); } } ?>