<?php
class Page
{
	var $pageStr = false; 
	function Page()
	{

	}


	//当前页码，总记录数，每次显示条数
	function htmlPageStr( $url = '', $pageNum = 1, $pageSize = 30, $resultCount='', $endArray = array() )
	{
		$pageCount = ceil($resultCount / $pageSize);
		$numBegin = 1;
		$numEnd   = 0 ;
		
		if( ( $pageNum  <= ($pageCount - 3) ) and  ( $pageCount > 3 ) and  ($pageNum  <= $pageCount ) )
		{
			$numEnd = $pageNum + 3 ;
		}else{
			$numEnd = $pageCount;
		}
		
		if( ( $numBegin  <= ($pageNum -3) ) and (($pageNum -3) > 0 ) )
		{
			$numBegin = $pageNum - 3;
		}else{ 
			$numBegin = $numBegin;
		}
		$endurl = '';
		
		
		foreach((array)$endArray as $key => $val)
		{
			$endurl .= '&'.$key.'='.$val;
		}
		
		$this -> pageStr  = " <div align='right' id='pagediv'>  ";
				
		if($pageNum > 4)
		{
			$this -> pageStr .= '<a href="'.$url.'-1'.$endurl.'.html"  class="page_first" >第一页</a>';
		}
		
		for($numBegin; $numBegin <= $numEnd;  $numBegin++)
		{
			if($numBegin==$pageNum)
			{
				if($pageCount ==1 and $pageNum==1)
				{
					//单页不显示一页
				}else{
					$this -> pageStr .= '<b>'.$numBegin.'</b>&nbsp;';
				}
			}else{
				$this -> pageStr .= '<a href="'.$url.'-'.$numBegin.$endurl.'.html" title="第'.$numBegin.'页" >'.$numBegin.'</a>&nbsp;';
			}
		}
		if($pageNum < ($pageCount -3) )
		{
			$this -> pageStr .= '<a href="'.$url.'-'.$pageCount.$endurl.'"  class="page_end" >最末页</a>';
		}

		$this -> pageStr .=  "&nbsp;&nbsp;</div>";
		//显示隐藏数据
		$this -> pageStr .= '<input type="hidden" name="PGURL" id="PGURL" value="'.$url.'"  />';

		return $this -> pageStr;
		
	}


	//当前页码，总记录数，每次显示条数
	function buildPageStr( $url = '', $pageNum = 1, $pageSize = 30, $resultCount='', $endArray = array() )
	{
		$pageCount = ceil($resultCount / $pageSize);
		$numBegin = 1;
		$numEnd   = 0 ;
		




		if( ( $pageNum  <= ($pageCount - 3) ) and  ( $pageCount > 3 ) and  ($pageNum  <= $pageCount ) )
		{
			$numEnd = $pageNum + 3 ;
		}else{
			$numEnd = $pageCount;
		}
		
		if( ( $numBegin  <= ($pageNum -3) ) and (($pageNum -3) > 0 ) )
		{
			$numBegin = $pageNum - 3;
		}else{ 
			$numBegin = $numBegin;
		}
		$endurl = '';
		
		

		
		$this -> pageStr  = " <div align='right' id='pagediv'>  ";
		
		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{
				//'.$key.'-
				foreach((array)$endArray as $key => $val)
				{
					if($val!='') $endurl .= '-'.$val;  
				}
			
				if($pageNum > 4)
				{
					$this -> pageStr .= '<a href="'.$url.'-1'.$endurl.'.html"  class="page_first" >第一页</a>';
				}
				
				for($numBegin; $numBegin <= $numEnd;  $numBegin++)
				{
					if($numBegin==$pageNum)
					{
						if($pageCount ==1 and $pageNum==1)
						{
							//单页不显示一页
						}else{
							$this -> pageStr .= '<b>'.$numBegin.'</b>&nbsp;';
						}
					}else{
						$this -> pageStr .= '<a href="'.$url.'-'.$numBegin.$endurl.'.html" title="第'.$numBegin.'页" >'.$numBegin.'</a>&nbsp;';
					}
				}
				if($pageNum < ($pageCount -3) )
				{
					$this -> pageStr .= '<a href="'.$url.'-'.$pageCount.$endurl.'.html"  class="page_end" >最末页</a>';
				}
				
		}else{
		
			foreach((array)$endArray as $key => $val)
			{
				$endurl .= '&'.$key.'='.$val;
			}
				
			if($pageNum > 4)
			{
				$this -> pageStr .= '<a href="'.$url.'&pageNum=1'.$endurl.'"  class="page_first" >第一页</a>';
			}
			
			for($numBegin; $numBegin <= $numEnd;  $numBegin++)
			{
				if($numBegin==$pageNum)
				{
					if($pageCount ==1 and $pageNum==1)
					{
						//单页不显示一页
					}else{
						$this -> pageStr .= '<b>'.$numBegin.'</b>&nbsp;';
					}
				}else{
					$this -> pageStr .= '<a href="'.$url.'&pageNum='.$numBegin.$endurl.'" title="第'.$numBegin.'页" >'.$numBegin.'</a>&nbsp;';
				}
			}
			if($pageNum < ($pageCount -3) )
			{
				$this -> pageStr .= '<a href="'.$url.'&pageNum='.$pageCount.$endurl.'"  class="page_end" >最末页</a>';
			}
	
	 
			}
		
		$this -> pageStr .=  "&nbsp;&nbsp;</div>";
		//显示隐藏数据
		$this -> pageStr .= '<input type="hidden" name="PGURL" id="PGURL" value="'.$url.'"  />';
		
		
		return $this -> pageStr;
		
	}
	
	//当前页码，总记录数，每次显示条数
	function adminPageStr( $url = '', $pageNum = 1, $pageSize = 30, $resultCount='',  $endArray = array()  ) // $type = 'js' or 'url'
	{
		//总页数
		//echo $resultCount;
		$pageCount = ceil($resultCount / $pageSize);
		$numBegin = 1;
		$numEnd   = 0 ;
		if($pageNum > $pageCount)
		{
			return false;
		}
		if($pageCount<=1){ return false; }
		
		if( ( $pageNum  <= ($pageCount - 3) ) and  ( $pageCount > 3 ) and  ($pageNum  <= $pageCount ) )
		{
			$numEnd = $pageNum + 3 ;
		}else{
			$numEnd = $pageCount;
		}
		
		if( ( $numBegin  <= ($pageNum -3) ) and (($pageNum -3) > 0 ) )
		{
			$numBegin = $pageNum - 3;
		}else{ 
			$numBegin = $numBegin;
		}
		

		$this -> pageStr  = " <div align='right' id='pagediv'>";
				
		if($pageNum > 4)
		{
			$this -> pageStr .= '<a href="javascript:getToPage(1)"  class="page_first" >第一页</a>';
		}
		
		for($numBegin; $numBegin <= $numEnd;  $numBegin++)
		{
			if($numBegin==$pageNum)
			{
				$this -> pageStr .= '<b>'.$numBegin.'</b>&nbsp;';
			}else{
				$this -> pageStr .= '<a href="javascript:getToPage('.$numBegin.')" title="第'.$numBegin.'页" >'.$numBegin.'</a>&nbsp;';
			}
		}
		if($pageNum < ($pageCount -3) )
		{
			$this -> pageStr .= '<a href="javascript:getToPage('.$pageCount.')"  class="page_end" >最末页</a>';
		}

		$this -> pageStr .=  "&nbsp;&nbsp;</div>";
		
		//显示隐藏数据
		$this -> pageStr .= '<input type="hidden" name="PURL[url]" id="PURL[url]" value="'.$url.'"  />';
		
		foreach((array)$endArray as $key => $val)
		{
			
				$this -> pageStr .= '<input type="hidden" name="PG['.$key.']" id="PG['.$key.']" value="'.$val.'"  />';
		}
		
		return $this -> pageStr;
	}
}

$Page = new Page();
?>