<?php

class Pagination{
        
  
/*##################################################
  #   REQUIRED CSS CLASSESS
  ####################################################

  A.paginationlink:LINK{
    color:#003574;
    text-decoration: none;
    font-family: Arial, Verdana, sans-serif;
    line-height: 7pt;
  }

  A.paginationlink:VISITED {
    color:#003574;
    text-decoration: none;
    font-family: Arial, Verdana, sans-serif;
    line-height: 7pt;
  }

  A.paginationlink:ACTIVE {
    color:#003574;
    text-decoration: none;
    font-family: Arial, Verdana, sans-serif;
    line-height: 7pt;
  }

  A.paginationlink:HOVER {
    color:#3B8DD2;
    text-decoration: none;
    font-family: Arial, Verdana, sans-serif;
    line-height: 7pt;
  }

  .paginationoutline {
    border:solid 1px #98AED7;
    background-color:#FFFFFF;
  }

  .paginationheading {
    background-color:#98AED7;
    color: #FFFFFF;
  }


  ##################################################*/

  
var $current_page;
  var 
$num_per_page;
  var 
$link;
  var 
$linkstyle "dynamic";


  function 
getLink($page){

    if(
$this->linkstyle == "permalink"){

      
$link preg_replace("/(\[PAGE\])/"$page$this->link);


    }else{

      
$extention substr($this->link, -44);
      if(
strtolower($extention) == ".php"){
    
$link .= $this->link "?";
      }else{
    
$link .= $this->link "&";
      }

      
$link .= $link "page=" $page;
    }

    return 
$link;

  }

  function 
getCount($countquery){
    
//count must be the first thing returned from the query;
    //$countquery = "SELECT count(ID) FROM journals";
    
$row mysql_fetch_array(mysql_query($countquery));
    return 
$row[0];
  }


  function 
getLimits($count){

    
$page $this->current_page;
    
$increment $this->num_per_page -1;

    
$multiplier $this->current_page 1;
    if(
$multiplier ){ $multiplier 0; }
    
$lower $multiplier $this->num_per_page;

    
//echo "$lower = $multiplier * $this->num_per_page";

    
$limit " LIMIT $lower, $this->num_per_page ";
    
//echo "<p>limit: $limit</p>";

    
return $limit;
  }

  function 
getNavigation($count){

    
$curpage $this->current_page;
    
$numperpage $this->num_per_page;

    
$linkclass "class='paginationlink'";
    
$numpages intval($count/$numperpage);
    
$temp $count/$numperpage;
    if (
$temp $numpages){
      
$numpages++;
    }
    if(
$numpages == 0){
      
$numpages 1;
    }

   
    
/*--- Basic Components ---*/

    
$heading "<td class='paginationheading'>&nbsp;page $curpage of $numpages&nbsp;</td>";
    if(
$curpage <= 1){
      
$firstpage "<td> <span title='Jump to first page'>&lt;&lt; First</span> </td>";
      
$previouspage "<td> <span title='Previous page'>&lt;</span> </td>";
      
$firstpage "";
      
$previouspage "";
    }else{
      
$firstpage "<td>&nbsp;<span title='Jump to first page'><a href='"$this->getLink(1) ."' $linkclass>&lt;&lt; First</a></span>&nbsp;</td>";
      
$temp $curpage 1;
      
$previouspage "<td>&nbsp;<span title='Previous page'><a href='"$this->getLink($temp) ."' $linkclass>&lt;</span></a>&nbsp;</td>";

    }

    if(
$curpage >= $numpages){
      
$lastpage "<td> <span title='Jump to last page'>Last &gt;&gt;</span> </td>";
      
$nextpage "<td> <span title='Next Page'>&gt;</span> </td>";
      
$lastpage "";
      
$nextpage "";
    }else{
      
$lastpage "<td>&nbsp;<span title='Jump to last page'><a href='"$this->getLink($numpages) ."' $linkclass>Last &gt;&gt;</a></span>&nbsp;</td>";
      
$temp $curpage 1;
      
$nextpage "<td>&nbsp;<span title='Next Page'><a href='"$this->getLink($temp) ."' $linkclass>&gt;</a></span>&nbsp;</td>";

    }

    
/*--- Numbers Section ---*/

    
$leftover $numpages $curpage
    
$page "";
    
    if(
$numpages 7){
      for(
$i 1$i <= $numpages$i++){
    if(
$i == $curpage){
      
$pages .= "<td>&nbsp;&nbsp;$i&nbsp;&nbsp;</td>";
    }else{
      
$pages .= "<td><a href='"$this->getLink($i) ."' $linkclass>&nbsp;$i&nbsp;</a></td>";
    }
      }

    }else if(
$curpage 3){
      for(
$i 1$i <= 7$i++){
    if(
$i == $curpage){
      
$pages .= "<td>&nbsp;&nbsp;$i&nbsp;&nbsp;</td>";
    }else{
      
$pages .= "<td><a href='"$this->getLink($i) ."' $linkclass>&nbsp;$i&nbsp;</a></td>";
    }
      }

    }else if(
$leftover 3){
      for(
$i $numpages 7$i <= $numpages$i++){
    if(
$i == $curpage){
      
$pages .= "<td>&nbsp;&nbsp;$i&nbsp;&nbsp;</td>";
    }else{
      
$pages .= "<td><a href='"$this->getLink($i) ."' $linkclass>&nbsp;$i&nbsp;</a></td>";
    }
      }

    }else{

      for(
$i $curpage 3$i <= $curpage 3$i++){
    if(
$i == $curpage){
      
$pages .= "<td>&nbsp;&nbsp;$i&nbsp;&nbsp;</td>";
    }else{
      
$pages .= "<td><a href='"$this->getLink($i) ."' $linkclass>&nbsp;$i&nbsp;</a></td>";
    }
      }

    } 
// end if


    /*--- Put the table together ---*/
    
$table "<table class='paginationoutline' cellpadding='0' cellspacing='0'><tr>".
      
$heading $firstpage $previouspage 
      
$pages $nextpage$lastpage .
      
"</tr></table>";

    return 
$table;
  }



}
?>