<?php

//页数
function get_page($n, $ps = false) {
  global $web;

  $ps = $ps ? $ps : $web['pagesize'];
  $_GET['p'] = abs($_GET['p']);
  if (!$_GET['p'] || $_GET['p'] < 1) {
    return 1;
  } elseif ($n && $_GET['p'] > ceil($n / $ps)) {
    return ceil($n / $ps);
  } else {
    return floor($_GET['p']);
  }
}

//分页
function get_page_foot($totallists, $pagesize, $p, $mpurl_before, $mpurl_after, $pagestep = 10, $target = '_self', $code1 = '', $code2 = '') {
  $text = '';
  $totalpages = 1;
  if ($totallists > $pagesize) {
    $offset = 4; //当前页前面显几页
    $totalpages = @ceil($totallists / $pagesize);
    if ($pagestep > $totalpages) {
      $fr = 1;
      $to = $totalpages;
    } else {
      $fr = $p - $offset;
      $to = $fr + $pagestep - 1;
      if ($fr < 1) {
        $to = $p + 1 - $fr;
        $fr = 1;
        if ($to - $fr < $pagestep) {
          $to = $pagestep;
        }
      } elseif ($to > $totalpages) {
        $fr = $totalpages - $pagestep + 1;
        $to = $totalpages;
      }
    }

  if (!isset($GLOBALS['page_style'])) {
    $text .= '<span id="page_style"><style type="text/css">
<!--
/*页码*/
.page { clear:both; text-align:center; margin-top:10px; }
.page .pagein { display:inline-block !important; display:inline; zoom:1; vertical-align:middle; border:1px #DDDDDD solid; height:22px; line-height:22px; padding:2px; text-align:right; }
.page a, .page strong { display:inline-block !important; display:inline; zoom:1; vertical-align:middle; margin-left:2px; margin-right:2px; }
.page a b, .page strong b { padding-left:6px; padding-right:6px; cursor:pointer; }
.page strong b { color:#FF6600; }
.page a { text-decoration:none; }
.page a:hover { color:#FF6600; background-color:#ECECEC; }
.page .prev, .page .next { }
.page span.totallists { width:auto; line-height:22px; margin-right:2px; display:inline-block !important; display:inline; zoom:1; vertical-align:middle; height:22px; padding:0 6px; background-color:#ECECEC; }
.page kbd { margin-left:2px; width:28px; height:22px; display:inline-block !important; display:inline; zoom:1; vertical-align:middle; line-height:normal; overflow:hidden; }
.page kbd #pagego { padding:0; width:26px; height:20px; border:1px #CCCCCC solid; }
.pnis { color:#FF6600; text-decoration:underline; font-weight:bold; }
-->
</style></span>
';
    $GLOBALS['page_style'] = true;
  }

    $text .= '
<div class="page">'.$code1.'<div class="pagein">';
    $text .= '<span class="totallists" title="总记录数" style="width:auto">'.$totallists.'</span>';
    $text .= ($p - $offset > 1 && $totalpages > $pagestep ? '<a target="'.$target.'" href="'.$mpurl_before.'1'.$mpurl_after.'" class="first"><b>1 …</b></a>' : '').($p > 1 ? '<a target="'.$target.'" href="'.$mpurl_before.($p - 1).$mpurl_after.'" class="prev" title="前一页"><b>&lt;&lt;</b></a>' : '');
    for ($i = $fr; $i <= $to; $i++) {
      $text .= $i == $p ? '<strong><b>'.$i.'</b></strong>' : '<a target="'.$target.'" href="'.$mpurl_before.$i.$mpurl_after.'" title="第'.$i.'页"><b>'.$i.'</b></a>';
    }
    $text .= ($p < $totalpages ? '<a target="'.$target.'" href="'.$mpurl_before.($p + 1).$mpurl_after.'" class="next" title="后一页"><b>&gt;&gt;</b></a>' : '').($to < $totalpages ? '<a target="'.$target.'" href="'.$mpurl_before.$totalpages.$mpurl_after.'" class="last" title="最后页"><b>… '.$totalpages.'</b></a>' : '');
    $text .= ($totalpages > $pagestep ? '<kbd><input type="text" name="pagego" id="pagego" size="3" title="按回车直接跳页" onblur="$(\'pagego\').value=this.value;" onkeydown="if(event.keyCode==13&&!isNaN(this.value)&&this.value>=1&&this.value<='.$totalpages.'){window.location=\''.$mpurl_before.'\'+this.value+\''.$mpurl_after.'\';return false;}" /><!-- button type="button" id="gopage" onclick="if(!isNaN($(\'pagego\').value) && $(\'pagego\').value>=1 && $(\'pagego\').value<='.$totalpages.'){window.location=\''.$mpurl_before.'\'+$(\'pagego\').value+\''.$mpurl_after.'\';return false;}">go</button --></kbd>' : '');
    $text .='</div>'.$code2.'</div>';
  }
  return $text;
}








?>