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

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

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

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

	if(!$data)
	{
		/*
			获取文章内容
		*/
		$info=$yp->discountinfo($id);
		if(!$info)
		{
			showmsg($yplang['msg-articlebyid-noexists']);
		}

		/*
			获取黄页数据
		*/
		$ypinfo=$yp->allinfo($info['ypid']);
		if(!$ypinfo) 
		{
			show404($yplang['msg-yp-noexists']);
		}
		$YP=array();

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

		if($ypinfo['status']==0)
		{
			show404($yplang['msg-yp-closed-owner']);
		}
		unset($ypinfo['password'],$ypinfo['areaid'],$ypinfo['id']);
		
		/*
			合并数组
		*/
		$data=array_merge($info,$ypinfo);

		$cache->set(md5(CURURL),$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]];

	extract($data,EXTR_SKIP);

	/*
		SEO数据
	*/

	$head['title'] = $title.'-'.$name;
	$head['keywords'] =$keywords;
	$head['description'] =$description;

	$yp->setdiscount($id,array('clicks'=>$clicks+1));

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