<?php

//分页函数
function show_page($page){
    $pageSize = $page['pageSize'];
    $total = $page['total'];
    $url = $page['url'];
    $pageNumber = ceil($total / $pageSize);
    $currentPage = $page['current'] ? $page['current'] : 1;

    $befor = $after = 0;
    $nowview=ceil(($currentPage+1)/10);
    $befor = $nowview==1?($nowview-1)*10+1:($nowview-1)*10;
    if($pageNumber>=$nowview*10){
        $after = $nowview*10;
    }else{
        $after = $pageNumber;
    }

    $html='';
    if($nowview>1) $befor--;
    if ($pageSize <= $total) { 
        for ($i = $befor; $i <= $after; $i++) {
          if ($i == $currentPage) {
                $html .= "<li class=\"active\"><a href=\"javascript:void(0)\">{$i}</a></li>";
           }else {
                $html .= "<li><a href=\"{$url}/{$i}\">$i</a></li>";
           }
        }
        $prev_page_url='javascript:void(0);';
        $next_page_url='javascript:void(0);';
        $prev_disabled=$next_disabled='disabled';
        if ($currentPage>1) {
            $prev_disabled='';
            $prev_page_url=$url.'/'.($currentPage-1);
        }
        if($currentPage<$pageNumber){
            $next_disabled='';
            $next_page_url=$url.'/'.($currentPage+1);
        }
        $html='<li class="'.$prev_disabled.'"><a href="'.$prev_page_url.'">上一页</a></li>'.$html;
        $html.='<li class="'.$next_disabled.'"><a href="'.$next_page_url.'">下一页</a></li>';
    }
    $res['htmls']=$html;
    $res['prepage']=$currentPage - 1;
    $res['nextpage']=$currentPage + 1;
    $res['totalpage']=$pageNumber;
    return  $res;
}