pagination seems to work! :)

--HG--
branch : quitta-gsoc-2013
hg/feature/sse2
Quitta 11 years ago
parent 845da81ad4
commit 7e4a24bac8

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

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

@ -210,6 +210,710 @@
</a> </a>
</td> </td>
</tr> </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> <tr>
<td>Habib Rizwan</td> <td>Habib Rizwan</td>
<td class="center">2012/01/21</td> <td class="center">2012/01/21</td>

@ -46,7 +46,7 @@
</div> </div>
</div> </div>
<div class="box-content"> <div class="box-content">
<table class="table table-striped table-bordered bootstrap-datatable datatable"> <table class="table table-striped table-bordered">
<thead> <thead>
<tr> <tr>
<th>{$id}</th> <th>{$id}</th>
@ -65,6 +65,15 @@
</tbody> </tbody>
</table> </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>
</div><!--/span--> </div><!--/span-->

Loading…
Cancel
Save