<?php
	include substr(dirname(__FILE__),0,-4).'/include/common.inc.php';
	
	$page=isset($page)?max(intval($page),1):1;
	
	$r=$yp->ypinfobyu($u);

	$id=$ypid=intval($r['id']);

	$areaid=isset($areaid)?intval($areaid):0;
	$typeid=isset($typeid)?intval($typeid):0;

	if($id<=0)  
	{
		show404($yplang['msg-yp-noexists']);
	}

	/*
		优先读取缓存
	*/
	$data=$cache->get(md5(CURURL));

	if(!$data)
	{
		/*
			获取黄页数据
		*/
		$data=$yp->allinfo($id);

		if(!$data) 
		{
			show404($yplang['msg-yp-noexists']);
		}

		if($data['status']==2)
		{
			show404($yplang['msg-yp-closed-admin']);
		}

		if($data['status']==0)
		{
			show404($yplang['msg-yp-closed-owner']);
		}

		unset($data['password']);
		$cache->set(md5(CURURL),$data);
	}
	//print_r($data);
	$YP['domain']=$data['domain'];
	if(!$data['menu'])
	{
		$data['menu']=array(
						'店铺首页'=>'yp/web/index.php?u='.$data['dir'].'&siteid='.SITEID,
						'新闻动态'=>'yp/web/news.php?u='.$data['dir'].'&siteid='.SITEID,
						'产品展示'=>'yp/web/product.php?u='.$data['dir'].'&siteid='.SITEID,
						'优惠促销'=>'yp/web/discount.php?u='.$data['dir'].'&siteid='.SITEID,
						'联系我们'=>'yp/web/contact.php?u='.$data['dir'].'&siteid='.SITEID,
						'在线留言'=>'yp/web/guestbook.php?u='.$data['dir'].'&siteid='.SITEID
					);
	}
	else
	{
		$data['menu']=string2array($data['menu']);
	}
	$menu=array_keys($data['menu']);
	$YP['menu']['index']=$menu[0];
	$YP['menu']['news']=$menu[1];
	$YP['menu']['product']=$menu[2];
	$YP['menu']['discount']=$menu[3];
	$YP['menu']['contact']=$menu[4];
	$YP['menu']['guestbook']=$menu[5];
	
	$YP['url']['index']=$data['menu'][$menu[0]];
	$YP['url']['news']=$data['menu'][$menu[1]];
	$YP['url']['product']=$data['menu'][$menu[2]];
	$YP['url']['discount']=$data['menu'][$menu[3]];
	$YP['url']['contact']=$data['menu'][$menu[4]];
	$YP['url']['guestbook']=$data['menu'][$menu[5]];

	$areaid=$data['areaid'];
	extract($data,EXTR_SKIP);

	/*
		SEO数据
	*/
	$head['title'] = $name.'-'.$meta_title;
	$head['keywords'] =$meta_keywords;
	$head['description'] =$meta_description;

	/*
		会员等级
	*/
	$r=cache_read('membergrade'.$gradeid.'.cache.php',DIRCMS_ROOT.'data/cache_module/');
	$gradename=$r['name'];

	/*
		更新访问次数
	*/
	$yp->set($data['id'],array('visits'=>$visits+1));
	include template('index','yp',$template);
?>