public function MakePagination($query, $rpp_def = NULL, $location = "DB") { $return_set = array(); $this->{$location}->query($query); // This query should select all needed fields from database if ((int) $this->_S->Get('rpp') != 0) { if (isset($_POST['rpp'])) { if ((int) $_POST['rpp'] == 0) { $this->_S->Set('rpp', 50); } else { $this->_S->Set('rpp', (int) $_POST['rpp']); } } $rpp = (int) $this->_S->Get('rpp'); } else { $this->_S->Set('rpp', 50); $rpp = (int) $this->_S->Get('rpp'); } // http://pear.php.net/package/Net_URL2 $op = new Net_URL2($_SERVER["REQUEST_URI"]); $op->unsetQueryVariable('cpage'); $op->setQueryVariable('cpage', ''); $str = (string) $op; if (strpos($str, "search=1")) { $str = str_replace("search=1", "search=0", $str); } $OptionForm = new TForm(); $OptionForm->Action = $str . $this->CurrentPage; $OptionForm->Name = "paginationform"; $OptionForm->class_name = "pagination_form"; $TSelect = new TForm_TSelect('rpp'); $TSelect->class_name = 'select2'; $TSelect->style = 'width: 60px;'; $OptionForm->Add("SlRPP", $TSelect); $OptionForm->SlRPP->Label = "Rezultate pe pagina: "; $OptionForm->SlRPP->label_class = 'inline'; $OptionForm->SlRPP->AddOption('10', '10'); $OptionForm->SlRPP->AddOption('20', '20'); $OptionForm->SlRPP->AddOption('30', '30'); $OptionForm->SlRPP->AddOption('50', '50'); $OptionForm->SlRPP->AddOption('100', '100'); $OptionForm->SlRPP->Value = $rpp; $OptionForm->SlRPP->Paragraph = false; $OptionForm->SlRPP->onChange = 'this.form.submit();'; $total_pages = ceil($this->{$location}->numRows() / $rpp); if (!$this->CurrentPage || $this->CurrentPage <= 0 || $this->CurrentPage > $total_pages) { $this->CurrentPage = 1; } $return_set[1] = " LIMIT " . ($this->CurrentPage - 1) * $rpp . ", " . $rpp; $TSelect = new TForm_TSelect('pag'); $TSelect->class_name = 'select2'; $TSelect->style = 'width: 60px;'; $OptionForm->Add('SlPag', $TSelect); for ($i = 1; $i <= $total_pages; $i++) { $OptionForm->SlPag->AddOption($str . $i, $i); } $OptionForm->SlPag->Label = "Afiseaza pagina: "; $OptionForm->SlPag->label_class = 'inline'; $OptionForm->SlPag->Paragraph = false; $OptionForm->SlPag->Value = $str . $this->CurrentPage; $OptionForm->SlPag->onChange = 'pagination_check_link(this.options[this.selectedIndex].value);'; $return_set[2] = "<div class=\"result_pages\">" . $OptionForm->Html() . ""; $ppages = ''; $j = 0; $nextpage = $pervpage = ''; if ($this->CurrentPage != 1) { $pervpage = '<li><a href="' . $str . '1"> <i class="icon-double-angle-left"></i></a></li><li><a href="' . $str . ($this->CurrentPage - 1) . '"> <i class="icon-angle-left"></i></a></li>'; } else { $pervpage = '<li class="disabled"><a href="' . $str . '1"> <i class="icon-double-angle-left"></i></a></li><li class="disabled"><a href="' . $str . ($this->CurrentPage - 1) . '"> <i class="icon-angle-left"></i></a></li>'; } if ($this->CurrentPage != $total_pages) { $nextpage = '<li><a href="' . $str . ($this->CurrentPage + 1) . '"><i class="icon-angle-right"></i> </a></li><li><a href="' . $str . $total_pages . '"><i class="icon-double-angle-right"></i> </a></li>'; } else { $nextpage = '<li class="disabled"><a href="' . $str . ($this->CurrentPage + 1) . '"><i class="icon-angle-right"></i> </a></li><li class="disabled"><a href="' . $str . $total_pages . '"><i class="icon-double-angle-right"></i> </a></li>'; } for ($i = 0; $i <= $j + 10; $i++) { if ($this->CurrentPage - 5 + $i > 0 && $this->CurrentPage - 5 + $i <= $total_pages) { if ($this->CurrentPage == $this->CurrentPage - 5 + $i) { $ppages .= '<li class="active"><a>' . ($this->CurrentPage - 5 + $i) . '</a></li>'; } else { $ppages .= '<li><a href="' . $str . ($this->CurrentPage - 5 + $i) . '">' . ($this->CurrentPage - 5 + $i) . '</a></li>'; } } else { if ($this->CurrentPage - 5 + $i <= $total_pages) { $j++; } } } $return_set[2] .= '<ul class="pagination">'; if ($total_pages > 1) { $return_set[2] .= $pervpage . $ppages . $nextpage; } else { $return_set[2] .= '<li class="active"><a>' . $this->CurrentPage . '</a></li>'; } $return_set[2] .= '</ul>'; $return_set[2] .= '</div>'; return $return_set; }
protected function MakePagination($query, $rpp_def = NULL, $location = "DB") { $return_set = array(); $this->{$location}->query($query); // This query should select all needed fields from database if ((int) $this->_S->Get('rpp') != 0) { if (isset($_POST['rpp'])) { if ((int) $_POST['rpp'] == 0) { $this->_S->Set('rpp', 50); } else { $this->_S->Set('rpp', (int) $_POST['rpp']); } } $rpp = (int) $this->_S->Get('rpp'); } else { $this->_S->Set('rpp', 50); $rpp = (int) $this->_S->Get('rpp'); } if (strpos($_SERVER['REQUEST_URI'], "?") === true) { $url = explode("?", $_SERVER['REQUEST_URI']); if (strpos($url[1], "&cpage=")) { $url = explode("&cpage=", $url[1]); $str = "?" . $url[0] . "&cpage="; } else { $str = "?" . $url[1] . "&cpage="; } } else { if ($this->idUser) { $str = "?idUser="******"&cpage="; } elseif ($this->UserType) { $str = "?type=" . $this->UserType . "&cpage="; } else { $str = "?cpage="; } } if (strpos($str, "search=1")) { $str = str_replace("search=1", "search=0", $str); } $OptionForm = new TForm(); $OptionForm->Action = $str . $this->CurrentPage; $OptionForm->Name = "paginationform"; $OptionForm->class_name = "pagination_form"; $TSelect = new TForm_TSelect('rpp'); $TSelect->class_name = 'select2 col-md-1 no-float'; $OptionForm->Add("SlRPP", $TSelect); $OptionForm->SlRPP->Label = "Rezultate pe pagina: "; $OptionForm->SlRPP->label_class = 'inline'; $OptionForm->SlRPP->AddOption('10', '10'); $OptionForm->SlRPP->AddOption('20', '20'); $OptionForm->SlRPP->AddOption('30', '30'); $OptionForm->SlRPP->AddOption('50', '50'); $OptionForm->SlRPP->AddOption('100', '100'); $OptionForm->SlRPP->Value = $rpp; $OptionForm->SlRPP->Paragraph = false; $OptionForm->SlRPP->onChange = 'this.form.submit();'; $total_pages = ceil($this->{$location}->numRows() / $rpp); if (!$this->CurrentPage || $this->CurrentPage <= 0 || $this->CurrentPage > $total_pages) { $this->CurrentPage = 1; } $return_set[1] = " LIMIT " . ($this->CurrentPage - 1) * $rpp . ", " . $rpp; $TSelect = new TForm_TSelect('pag'); $TSelect->class_name = 'select2 col-md-1 no-float'; $OptionForm->Add('SlPag', $TSelect); for ($i = 1; $i <= $total_pages; $i++) { $OptionForm->SlPag->AddOption($str . $i, $i); } $OptionForm->SlPag->Label = "Afiseaza pagina: "; $OptionForm->SlPag->label_class = 'inline'; $OptionForm->SlPag->Paragraph = false; $OptionForm->SlPag->Value = $str . $this->CurrentPage; $OptionForm->SlPag->onChange = 'pagination_check_link(this.options[this.selectedIndex].value);'; $return_set[2] = "<div class=\"result_pages\">" . $OptionForm->Html() . ""; $ppages = ''; $j = 0; $nextpage = $pervpage = ''; if ($this->CurrentPage != 1) { $pervpage = '<li><a href="' . $str . '1"> <i class="icon-fast-backward"></i> ' . _T('first') . '</a></li><li><a href="' . $str . ($this->CurrentPage - 1) . '"> <i class="icon-step-backward"></i> ' . _T('previous') . '</a></li>'; } else { $pervpage = '<li class="disabled"><a href="' . $str . '1"> <i class="icon-fast-backward"></i> ' . _T('first') . '</a></li><li class="disabled"><a href="' . $str . ($this->CurrentPage - 1) . '"> <i class="icon-step-backward"></i> ' . _T('previous') . '</a></li>'; } if ($this->CurrentPage != $total_pages) { $nextpage = '<li><a href="' . $str . ($this->CurrentPage + 1) . '">' . _T('next') . ' <i class="icon-step-forward"></i> </a></li><li><a href="' . $str . $total_pages . '">' . _T('last') . ' <i class="icon-fast-forward"></i> </a></li>'; } else { $nextpage = '<li class="disabled"><a href="' . $str . ($this->CurrentPage + 1) . '">' . _T('next') . ' <i class="icon-step-forward"></i> </a></li><li class="disabled"><a href="' . $str . $total_pages . '">' . _T('last') . ' <i class="icon-fast-forward"></i> </a></li>'; } for ($i = 0; $i <= $j + 10; $i++) { if ($this->CurrentPage - 5 + $i > 0 && $this->CurrentPage - 5 + $i <= $total_pages) { if ($this->CurrentPage == $this->CurrentPage - 5 + $i) { $ppages .= '<li class="active"><a>' . ($this->CurrentPage - 5 + $i) . '</a></li>'; } else { $ppages .= '<li><a href="' . $str . ($this->CurrentPage - 5 + $i) . '">' . ($this->CurrentPage - 5 + $i) . '</a></li>'; } } else { if ($this->CurrentPage - 5 + $i <= $total_pages) { $j++; } } } $return_set[2] .= '<ul class="pagination">'; if ($total_pages > 1) { $return_set[2] .= $pervpage . $ppages . $nextpage; } else { $return_set[2] .= '<li class="active"><a>' . $this->CurrentPage . '</a></li>'; } $return_set[2] .= '</ul>'; $return_set[2] .= '</div>'; return $return_set; }