<?php
/*
 +----------------------------------------------------------------------
 | TEMMOKUMVC [ NO BEST, ONLY BETTER ]
 +----------------------------------------------------------------------
 | Copyright (c) 2018~2019 https://www.temmoku.cn All rights reserved.
 +----------------------------------------------------------------------
 | Author: 张宗强 Email:webmaster@temmoku.cn QQ:158726877 516669373 TEL:17895221001 微信:temmokumvc
 +---------------------------------------------------------------------- 
*/
namespace temmoku\lib;
use \temmoku\db;
class pages {
	//上下页带中间参数
	public function pages($TABLE='',$WHERER='',$URL='',$ROWS='10',$page='1',$ALLNUM='0',$connector='_'){
		!isset($page) && $page=1;
		if($TABLE && $ALLNUM=='0'){
			if($WHERER){
				extract(db::select('COUNT(*) AS NUM')->from("{$TABLE}") ->where($WHERER) ->row());
			}else{
				extract(db::select('COUNT(*) AS NUM')->from("{$TABLE}")->row());
			}
			$ALLNUM=$NUM;
		}
		$All_Page=@ceil($ALLNUM/$ROWS);
		
		$street="<a href='{$URL}page{$connector}1'>首页</a>";
		if($page>1){
			$up_page=$page-1;
			$street.="<a href='{$URL}page{$connector}{$up_page}'>上一页</a>";
		}else{
			$street.="<a href='#'>上一页</a>";
		}
		$center_page='';
		if($All_Page/5>1){
			$center_pageu=$page-2;
			$center_paged=$page+2;
			if($center_pageu<1){
				$center_pageu=1;
				$center_paged=5;
			}
			if($center_paged>$All_Page){
				$center_pageu=$All_Page-4;
				$center_paged=$All_Page;
			}
			for($i=$center_pageu;$i<=$center_paged;$i++){
				if($i==$page){
					$center_page.="<a href='{$URL}page{$connector}$i' class=\"background-color-red\">$i</a>";
				}else{
					$center_page.="<a href='{$URL}page{$connector}$i'>$i</a>";
				}
			}
		}else{
			for($i=1;$i<=$All_Page;$i++){
				if($page==$i){
					$center_page.="<a href='#' class=\"background-color-red\">$i</a>";
				}else{
					$center_page.="<a href='{$URL}page{$connector}$i'>$i</a>";
				}
			}
		}
		$street.=$center_page;
		if($page >=$All_Page){
			$street.="";
		}else{
			$down_page=$page+1;
			$street.="<a href='{$URL}page{$connector}{$down_page}'>下一页</a>";
			$street.="<a href='{$URL}page{$connector}{$All_Page}'>末页</a>";
		}
		if($All_Page>1){
			return $street;
		}
	}
}
?>