pagination seems to work! :)

This commit is contained in:
Quitta 2013-08-05 05:27:19 +02:00
parent d1795c32f8
commit e5d5cfe0cc
4 changed files with 739 additions and 30 deletions

View file

@ -5,6 +5,7 @@ class Pagination{
private $element_array;
private $last;
private $current;
private $amountOfRows;
function __construct($query,$db,$nrDisplayed,$resultClass) {
if (!(isset($_GET['pagenum']))){
@ -16,7 +17,7 @@ class Pagination{
//Here we count the number of results
$db = new DBLayer($db);
$rows = $db->executeWithoutParams($query)->rowCount();
$this->amountOfRows = $rows;
//the array hat will contain all users
if($rows > 0){
@ -55,39 +56,41 @@ class Pagination{
return $this->last;
}
public function getCurrent(){
return $this->current;
}
public function getElements(){
return $this->element_array;
}
public function getAmountOfRows(){
return $this->amountOfRows;
}
public function getLinks($nrOfLinks){
$pageLinks = Array();
$pageLinks[] = 1;
//if amount of showable links is greater than the amount of pages: show all!
if ($this->last <= $nrOfLinks){
for($var = 2; $var <= $this->last; $var++){
for($var = 1; $var <= $this->last; $var++){
$pageLinks[] = $var;
}
}else{
$offset = ($nrOfLinks-3)/2 ;
print "<font color='purple'>offset:" . $offset . "</font>";
$offset = ($nrOfLinks-1)/2 ;
$startpoint = $this->current - $offset;
$endpoint = $this->current + $offset;
print "<font color='blue'>startpointX:" . $startpoint . "</font>";
if($startpoint < 2){
$startpoint = 2;
$endpoint = $startpoint + $nrOfLinks - 3;
}else if($endpoint > $this->last-1){
$endpoint = $this->last-1;
$startpoint = $endpoint - ($nrOfLinks -3);
if($startpoint < 1){
$startpoint = 1;
$endpoint = $startpoint + $nrOfLinks - 1;
}else if($endpoint > $this->last){
$endpoint = $this->last;
$startpoint = $endpoint - ($nrOfLinks -1);
}
print "<font color='blue'>startpoint:" . $startpoint . "</font>";
print "<font color='orange'>endpoint:" . $endpoint . "</font>";
for($var = $startpoint; $var <= $endpoint; $var++){
$pageLinks[] = $var;
}
$pageLinks[] = $this->last;
}
return $pageLinks;
}

View file

@ -4,19 +4,12 @@
function libuserlist(){
if(Ticket_User::isAdmin($_SESSION['ticket_user'])){
$pagination = new Pagination("SELECT * FROM ams_querycache","lib",1,"Querycache");
print "<font color='red'>1 elements / page </font><br/>";
print "<font color='green'>7 links max</font>";
print "<br/><br/>";
print "last page=";
print_r($pagination->getLast());
print "<br/>----------------------------------------------<br/>";
print "elements:";
print_r($pagination->getElements());
print "<br/>----------------------------------------------<br/>";
print "links:";
print_r($pagination->getLinks(7));
exit;
$pagination = new Pagination("SELECT * FROM ams_querycache","lib",2,"Querycache");
$pageResult['liblist'] = Gui_Elements::make_table($pagination->getElements() , Array("getSID","getType"), Array("id","type"));
$pageResult['links'] = $pagination->getLinks(5);
$pageResult['lastPage'] = $pagination->getLast();
$pageResult['currentPage'] = $pagination->getCurrent();
//check if shard is online
try{

View file

@ -210,6 +210,710 @@
</a>
</td>
</tr>
<tr>
<td>David R</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Chris Jack</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Jack Chris</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Muhammad Usman</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Sheikh Heera</td>
<td class="center">2012/02/01</td>
<td class="center">Staff</td>
<td class="center">
<span class="label label-important">Banned</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Helen Garner</td>
<td class="center">2012/02/01</td>
<td class="center">Staff</td>
<td class="center">
<span class="label label-important">Banned</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Saruar Ahmed</td>
<td class="center">2012/03/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-warning">Pending</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Ahemd Saruar</td>
<td class="center">2012/03/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-warning">Pending</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>David R</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Chris Jack</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Jack Chris</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Muhammad Usman</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Sheikh Heera</td>
<td class="center">2012/02/01</td>
<td class="center">Staff</td>
<td class="center">
<span class="label label-important">Banned</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Helen Garner</td>
<td class="center">2012/02/01</td>
<td class="center">Staff</td>
<td class="center">
<span class="label label-important">Banned</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Saruar Ahmed</td>
<td class="center">2012/03/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-warning">Pending</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Ahemd Saruar</td>
<td class="center">2012/03/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-warning">Pending</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>David R</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Chris Jack</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Jack Chris</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Muhammad Usman</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Sheikh Heera</td>
<td class="center">2012/02/01</td>
<td class="center">Staff</td>
<td class="center">
<span class="label label-important">Banned</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Helen Garner</td>
<td class="center">2012/02/01</td>
<td class="center">Staff</td>
<td class="center">
<span class="label label-important">Banned</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Saruar Ahmed</td>
<td class="center">2012/03/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-warning">Pending</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Ahemd Saruar</td>
<td class="center">2012/03/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-warning">Pending</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>David R</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Chris Jack</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Jack Chris</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Muhammad Usman</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-success">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Sheikh Heera</td>
<td class="center">2012/02/01</td>
<td class="center">Staff</td>
<td class="center">
<span class="label label-important">Banned</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Helen Garner</td>
<td class="center">2012/02/01</td>
<td class="center">Staff</td>
<td class="center">
<span class="label label-important">Banned</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Saruar Ahmed</td>
<td class="center">2012/03/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-warning">Pending</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Ahemd Saruar</td>
<td class="center">2012/03/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label label-warning">Pending</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="icon-zoom-in icon-white"></i>
View
</a>
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<tr>
<td>Habib Rizwan</td>
<td class="center">2012/01/21</td>

View file

@ -46,7 +46,7 @@
</div>
</div>
<div class="box-content">
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>{$id}</th>
@ -65,6 +65,15 @@
</tbody>
</table>
<div style="width: 300px; margin:0px auto;">
<ul class="pagination">
<li><a href="index.php?page=sync&pagenum=1">&laquo;</a></li>
{foreach from=$links item=link}
<li {if $link == $currentPage}class="active"{/if}><a href="index.php?page=sync&pagenum={$link}">{$link}</a></li>
{/foreach}
<li><a href="index.php?page=sync&pagenum={$lastPage}">&raquo;</a></li>
</ul>
</div>
</div>
</div><!--/span-->