<?php
	include substr(dirname(__FILE__),0,-4).'/include/common.inc.php';
	if(isset($do_submit))
	{
		if(!isset($_SESSION['checkcode']) || strtolower($chkcode)!=$_SESSION['checkcode'])showmsg('验证码输入不正确!');
		if($authkey!=md5(AUTH_KEY.$ypid.$ypname))showmsg('参数错误!');
		$info=array();
		$info['areaid']=$_areaid;
		$info['ypid']=intval($ypid);
		$info['ypname']=trim($ypname);
		$info['guestid']=$_userid?$_userid:0;
		$info['guestname']=$_username?$_username:'游客';
		$info['guestface']=$_facephoto?$_facephoto:'images/nophoto.gif';
		$info['service']=intval($service);
		$info['condition']=intval($condition);
		$info['price']=intval($price);
		$info['score']=intval($score);
		$info['addtime']=TIME;
		$info['ip']=IP;
		$info['status']=$_userid || !COMMENTPASS?1:0;
		$info['content']=bbcode(strip_tags(sub_string($content,200,'...')));

		if($yp->comment_add($info))
		{
			showmsg('留言成功!');
		}
		else
		{
			showmsg('留言失败!');
		}
	}

	$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);
	}
	$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'] = $YP['menu']['guestbook'].'-'.$name;
	$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('guestbook','yp',$template);
?>