<?php
	include dirname(__FILE__).'/include/common.inc.php';
	if($module->module_disabled('yp'))
	{
		show404('该模块已被管理员禁用!');
	}

	include DIRCMS_ROOT.'include/admin/stepselect.class.php';
	$stepselect= new stepselect();

	session_start();
	
	$id=isset($id) && intval($id)>0?intval($id):0;
	if(!$id) 
	{
		show404('黄页列表ID='.$id.'不存在!',SITE_URL);
	}
	
	$stepselectinfo=$stepselect->enuminfobyid($id);
	$parentid=$stepselectinfo['parentid'];

	/*
		优先读取缓存
	*/
	$data=$cache->get(md5('Myyptype_'.$id));

	if(!$data)
	{
		/*
			获取黄页数据
		*/
		$data=$yp->getyp(intval($id),'typeid');
		$cache->set(md5('Myyptype_'.$id),$data);
	}

	/*
		SEO数据
	*/

	$head['title'] = get_selectmenu('yp',$id).'-'.YP_META_TITLE;
	$head['keywords'] =YP_META_KEYWORDS;
	$head['description'] =YP_META_DESCRIPTION;
	
	/*
		分页
	*/
	$totalnum=count($data);
	$pagesize=isset($pagesize)?max(1,intval($pagesize)):20;
	$pagenum=ceil($totalnum/$pagesize);
	$page=isset($page)?min($pagenum,max(1,intval($page))):1;

	$data=array_slice($data,($page-1)*$pagesize,$pagesize);
	
	$pagearray=range(1,$pagenum);
	$pagearray=array_slice($pagearray,($page/10 < 1?0:floor($page/10)*10) ,10);

	$dir_page=array();

	$querystring=array();

	if($_GET)
	{
		if(isset($_GET['page']))unset($_GET['page']);
		foreach($_GET as $key => $val)
		{
			$querystring[]=$key.'='.$val;
		}
	}
	if($page!=1)
	{
		$querystring['page']='page='.max($page-1,1);
		$dir_page[]='<a href="yp/list.php?'.implode('&',$querystring).'">上一页</a>';
	}

	foreach($pagearray as $_page)
	{
		if($page==$_page)
		{
			$dir_page[]=$_page;
		}
		else
		{
			$querystring['page']='page='.$_page;
			$dir_page[]='<a href="yp/list.php?'.implode('&',$querystring).'">['.$_page.']</a>';
		}
	}

	if($page!=$pagenum)
	{
		$querystring['page']='page='.min($page+1,$pagenum);
		$dir_page[]='<a href="yp/list.php?'.implode('&',$querystring).'">下一页</a>';
	}

	$dir_page=$data?implode(' ',$dir_page):'';
	include template('list','yp');
?>