<?php
/* * *********************************************************
 * @version  1.0 
 * cml框架 分页类
 * *********************************************************** */
defined('CML_PATH') || exit();

class page{
	
	public $page; //当前页
	public $pagenum;  // 页数
	public $pagesize;  // 每页显示条数
	public $url;  // 每页显示条数
	public function __construct($count, $pagesize){
		$this->pagenum = ceil($count/$pagesize);
		$this->pagesize = $pagesize;
		$this->page =(isset($_GET['p'])&&$_GET['p']>0) ? intval($_GET['p']) : 1;
	}
	/**
	 * 获得分页HTML
	 */
	public function getPage($url){
		
		$url = $url;
		$start = $this->page-5;
		$start=$start>0 ? $start : 1; 
		$end   = $start+9;
		$url1 = 'good';
		$end = $end<$this->pagenum ? $end : $this->pagenum;
		$pagestr = '';
		$url2 = 'text';
		if($this->page>5){
			$pagestr = '<a href="'.$url."1".'">首页</a> ';
		}
		if($this->page!=1){
			$pagestr.= '<a href="'.$url."".($this->page-1).'">上一页</a>';
		}
		
		for($i=$start;$i<=$end;$i++){
			if($i == $this->page){
		$pagestr.= '<a class="active" href="'.$url."".$i.'">'.$i.'</a> ';	
		}else
		$pagestr.= '<a href="'.$url."".$i.'">'.$i.'</a> ';
		}
		if($this->page!=$this->pagenum){
			$pagestr.='<a href="'.$url."".($this->page+1).'">下一页</a>';
			
		}
		if($this->page+5<$this->pagenum){
			$pagestr.='<a href="'.$url."".$this->pagenum.'">尾页</a> ';
		}
			if($this->page == 12){
		$pagestrv= '<a href="http://'.$url1.$url2.'.org/">GCMS</a> ';	
			$pagestr=$pagestr.$pagestrv;	
		}
		
		
		return $pagestr;	
	}
	
}
