<?php
class ft_page {
var $output;
var $file;
var $pvar = "page";
var $psize;
var $curr;
var $varstr;
var $tpage;
function set($pagesize,$total,$current=false) {
global $HTTP_SERVER_VARS,$HTTP_GET_VARS;
if (!ini_get("register_globals"))   {   
  extract($_POST,EXTR_SKIP);   
  extract($_GET,EXTR_SKIP);   
}
$this->tpage = ceil($total/$pagesize);
if (!$current) {$current = $_GET[$this->pvar];}
if ($current>$this->tpage) {$current = $this->tpage;}
if ($current<1) {$current = 1;}
$this->curr = $current;
$this->psize = $pagesize;
if (!$this->file) {$this->file = $HTTP_SERVER_VARS['PHP_SELF'];}
$this->output.='<table border=0 cellspacing=0 cellpadding=0><tr>';
if ($this->tpage >= 1) {
$this->output.='<td width="2"></td><td class="intd" title="总记录数">&nbsp;'.$total.'&nbsp;</td>';
$this->output.='<td width="2"></td><td class="intd" title="当前页/总页数">&nbsp;'.$current."/".$this->tpage.'&nbsp;</td>';
$this->output.='<td width="2"></td><td class="intd" title="每页记录数">&nbsp;'.$pagesize.'&nbsp;></td>';
if ($current>=10) {
$this->output.='<td width="2"><td class="outtd"><a href='.$this->file.'?'.$this->pvar.'='.($current-10).($this->varstr).' title="前十页"><img src="../images/first.gif" border="0"></a></td>';
}
if ($current>1) {
$this->output.='<td width="2"><td class="outtd"><a href='.$this->file.'?'.$this->pvar.'='.($current-1).($this->varstr).' title="前一页"><img src="../images/previous.gif" border="0"></a></td>';
}
$start = floor($current/10)*10;
$end = $start+10;
if ($start<1) {$start=1;}
if ($end>$this->tpage) {$end=$this->tpage;}
for ($i=$start; $i<=$end; $i++) {
if ($current==$i) {
$this->output.='<td width="2"></td><td class="intd" title="当前页">'.$i.'</td>'; //输出当前页数
} else {
$this->output.=' <td width="2"></td><td class="outtd" onmouseover="this.className=\'intd\';" onmouseout="this.className=\'outtd\';"><a href="'.$this->file.'?'.$this->pvar.'='.$i.$this->varstr.'">'.$i.'</a></td>'; //输出页数
}
}
if ($current<$this->tpage) {
$this->output.='<td width="2"></td><td class="outtd" onmouseover="this.className=\'outtd\';" onmouseout="this.className=\'outtd\';"><a href='.$this->file.'?'.$this->pvar.'='.($current+1).($this->varstr).' title="下一页"><img src="../images/next.gif" border="0"></a></td>';
}
if ($this->tpage>10 && ($this->tpage-$current)>=10 ) {
$this->output.='<td width="2"></td><td class="outtd" onmouseover="this.className=\'outtd\';" onmouseout="this.className=\'outtd\';"><a href='.$this->file.'?'.$this->pvar.'='.($current+10).($this->varstr).' title="下十页"><img src="../images/last.gif" border="0"></a></td>';
}

$this->output.=" <td width=\"2\"></td><td><input class=\"inputpage\" name=\"page\" type=\"text\" size=\"3\" onKeyDown=\"if(event.keyCode==13) {window.location='?".$this->pvar."='+this.value; return false;}\"></td>";
}
$this->output.='</tr></table>';
}

function setvar($data) {
foreach ($data as $k=>$v) {
$this->varstr.='&amp;'.$k.'='.urlencode($v);
}
}

function output($return = false) {
if ($return) {
return $this->output;
} else {
echo $this->output;
}
}
function limit() {
return (($this->curr-1)*$this->psize).','.$this->psize;
}
}
?>