<?php
	!defined('MEMBER_CENTER') && exit('Access Denied!');
	$action=isset($action)?$action:'yp';
	
	include_once substr(dirname(__FILE__),0,-7).'/data/config.inc.php';

	include substr(dirname(__FILE__),0,-7).'/include/yp.class.php';
	$yp=new yp();
	switch($action)
	{
		case 'set':
			$r=$yp->userypinfo($_userid);
			if(isset($do_submit)) 
			{
				include DIRCMS_ROOT.'include/data.input.class.php';
				$datainput = new data_input(2,'member');
				$info=$datainput->filter($info);

				if(!preg_match('/^[a-z0-9_]{1,32}$/i',$info['dir']))
				{
					showmsg('门店目录由1-30位字母、数字、下划线组成! ');
				}
				
				if(!$yp->checkdir($info['dir'])&& (!$r || ($r && $info['dir']!=$r['dir'])))
				{
					showmsg('门店目录已经存在, 请更换!');
				}

				$err=$yp->setyp($info);
				$cache->clear();
				if($err===true)
				{
					showmsg('黄页资料设置成功!');
				}
				else
				{	
					showmsg('请选择行业类别!');
				}
			}
			$info=$yp->userypinfo($_userid);
			require DIRCMS_ROOT.'include/form.class.php';	
			$form=new form('info');
			$forms=$form->get(2,$info,'member');
			
			include member_tlp('yp_set','yp');
			break;
		case 'domain':
			if(isset($do_submit)) 
			{
				$yp->setdomain($name,$url,$domain);
				$cache->clear();
				showmsg('域名菜单设置成功!');
			}

			$ypinfo=$yp->userypinfo($_userid);

			if(!$ypinfo['menu'])
			{
				$menu=array(
						'店铺首页'=>'yp/web/index.php?u='.$ypinfo['dir'].'&siteid='.SITEID,
						'新闻动态'=>'yp/web/news.php?u='.$ypinfo['dir'].'&siteid='.SITEID,
						'产品展示'=>'yp/web/product.php?u='.$ypinfo['dir'].'&siteid='.SITEID,
						'优惠促销'=>'yp/web/discount.php?u='.$ypinfo['dir'].'&siteid='.SITEID,
						'联系我们'=>'yp/web/contact.php?u='.$ypinfo['dir'].'&siteid='.SITEID,
						'在线留言'=>'yp/web/guestbook.php?u='.$ypinfo['dir'].'&siteid='.SITEID
					);
			}
			else
			{
				$menu=string2array($ypinfo['menu']);
			}
			include member_tlp('yp_domain','yp');
			break;
		case 'news':
			$k=isset($k)?trim($k):'';
			$ypinfo=$yp->userypinfo($_userid);

			$result=$yp->newslist($ypinfo['id'],$k,20);
			include member_tlp('yp_news','yp');
			break;
		case 'news_add':
			$ypinfo=$yp->userypinfo($_userid);

			if(isset($do_submit))
			{
				if($_SESSION['checkcode']!=strtolower($inputcheckcode))showmsg('验证码输入不正确!');
				if($yp->news_add($info))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}

			require DIRCMS_ROOT.'include/form.class.php';	
			$form=new form('info');
			include member_tlp('news_add','yp');
			break;
		case 'news_edit':
			$ypinfo=$yp->userypinfo($_userid);

			if(isset($do_submit))
			{
				if($_SESSION['checkcode']!=strtolower($inputcheckcode))showmsg('验证码输入不正确!');
				if($yp->news_edit($info,$id))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			require DIRCMS_ROOT.'include/form.class.php';	
			$form=new form('info');
			$info=$yp->newsinfo($id);
			include member_tlp('news_edit','yp');
			break;
		case 'news_delete':
			$ypinfo=$yp->userypinfo($_userid,'id');
			
			if(!$ypinfo)
			{
				showmsg('您尚未开通企业店铺, 不能进行此操作, 请先开通!',SITE_URL.'member/index.php?mod=yp&file=yp&action=set');
			}

			if(!isset($id) || !$id)showmsg('请选择需要操作的选项!');
			if($yp->news_delete($id))
			{
				showmsg('操作成功!');
			}
			else
			{
				showmsg('操作失败!');
			}
			break;
		case 'discount':
			$k=isset($k)?trim($k):'';
			$ypinfo=$yp->userypinfo($_userid);

			$result=$yp->discountlist($ypinfo['id'],$k,20);
			include member_tlp('yp_discount','yp');
			break;
		case 'discount_add':
			$ypinfo=$yp->userypinfo($_userid);

			if(isset($do_submit))
			{
				if($_SESSION['checkcode']!=strtolower($inputcheckcode))showmsg('验证码输入不正确!');
				if($yp->discount_add($info))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}

			require DIRCMS_ROOT.'include/form.class.php';	
			$form=new form('info');
			include member_tlp('discount_add','yp');
			break;
		case 'discount_edit':
			$ypinfo=$yp->userypinfo($_userid);

			if(isset($do_submit))
			{
				if($_SESSION['checkcode']!=strtolower($inputcheckcode))showmsg('验证码输入不正确!');
				if($yp->discount_edit($info,$id))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			require DIRCMS_ROOT.'include/form.class.php';	
			$form=new form('info');
			$info=$yp->discountinfo($id);
			include member_tlp('discount_edit','yp');
			break;
		case 'discount_delete':
			$ypinfo=$yp->userypinfo($_userid,'id');
			
			if(!$ypinfo)
			{
				showmsg('您尚未开通企业店铺, 不能进行此操作, 请先开通!',SITE_URL.'member/index.php?mod=yp&file=yp&action=set');
			}

			if(!isset($id) || !$id)showmsg('请选择需要操作的选项!');
			if($yp->discount_delete($id))
			{
				showmsg('操作成功!');
			}
			else
			{
				showmsg('操作失败!');
			}
			break;
		case 'product_type':
			$ypinfo=$yp->userypinfo($_userid,'id');
			$ypid=$ypinfo['id'];
			if(isset($do_submit))
			{
				if($yp->setproducttype($name,$parentid,$newname))
				{
					exit('<script language="javascript">alert("操作成功!");history.back();</script>');
				}
				else
				{
					exit('<script language="javascript">alert("操作失败!");history.back();</script>');
				}
			}
			include member_tlp('yp_product_type','yp');
			break;
		case 'product':
			$k=isset($k)?trim($k):'';
			$ypinfo=$yp->userypinfo($_userid,'id');
			$ypid=$ypinfo['id'];
			
			if(!$ypinfo)
			{
				showmsg('您尚未开通企业店铺, 不能进行此操作, 请先开通!',SITE_URL.'member/index.php?mod=yp&file=yp&action=set');
			}

			$result=$yp->productlist($ypinfo['id'],$k,20);
			include member_tlp('yp_product','yp');
			break;
		case 'product_add':
			$ypinfo=$yp->userypinfo($_userid,'id');
			$ypid=$ypinfo['id'];
			
			if(!$ypinfo)
			{
				showmsg('您尚未开通企业店铺, 不能进行此操作, 请先开通!',SITE_URL.'member/index.php?mod=yp&file=yp&action=set');
			}

			if(isset($do_submit))
			{
				if($_SESSION['checkcode']!=strtolower($inputcheckcode))showmsg('验证码输入不正确!');
				if($yp->product_add($info))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			require DIRCMS_ROOT.'include/form.class.php';	
			$form=new form('info');
			include member_tlp('product_add','yp');
			break;
		case 'product_edit':
			$ypinfo=$yp->userypinfo($_userid,'id');
			$ypid=$ypinfo['id'];
			
			if(!$ypinfo)
			{
				showmsg('您尚未开通企业店铺, 不能进行此操作, 请先开通!',SITE_URL.'member/index.php?mod=yp&file=yp&action=set');
			}

			if(isset($do_submit))
			{
				if($_SESSION['checkcode']!=strtolower($inputcheckcode))showmsg('验证码输入不正确!');
				if($yp->product_edit($info,$id))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			require DIRCMS_ROOT.'include/form.class.php';	
			$form=new form('info');
			$info=$yp->productinfo($id);
			include member_tlp('product_edit','yp');
			break;
		case 'product_delete':
			$ypinfo=$yp->userypinfo($_userid,'id');
			
			if(!$ypinfo)
			{
				showmsg('您尚未开通企业店铺, 不能进行此操作, 请先开通!',SITE_URL.'member/index.php?mod=yp&file=yp&action=set');
			}

			if(!isset($id) || !$id)showmsg('请选择需要操作的选项!');
			if($yp->product_delete($id))
			{
				showmsg('操作成功!');
			}
			else
			{
				showmsg('操作失败!');
			}
			break;
		case 'template':

			$info=$yp->userypinfo($_userid);

			$_template=$info['template'];
			$list=glob(TPL_ROOT.TPL_NAME.'/yp/*');
			$files=glob(TPL_ROOT.TPL_NAME.'/yp/*.*');
			$dirs=array_diff($list,$files);
			$r=array();
			foreach($dirs as $v)
			{
				$r[]=basename($v);
			}
			include member_tlp('yp_template','yp');
			break;
		case 'settemplate':
			$ypinfo=$yp->userypinfo($_userid,'id');
			
			if(!$ypinfo)
			{
				showmsg('您尚未开通企业店铺, 不能进行此操作, 请先开通!',SITE_URL.'member/index.php?mod=yp&file=yp&action=set');
			}

			if($_level!=2 || !$_expire)
			{
				showmsg('该会员等级不允许自定义模板 ,请先升级!','index.php?file=user&action=upgrade',2000);
			}
			if($yp->settemplate($template))
			{
				showmsg('黄页模板设置成功!');
			}
			else
			{	
				showmsg('黄页模板设置失败!');
			}
			break;
		case 'comment':
			$k=isset($k)?trim($k):'';
			$ypinfo=$yp->userypinfo($_userid,'id');
			
			if(!$ypinfo)
			{
				showmsg('您尚未开通企业店铺, 不能进行此操作, 请先开通!',SITE_URL.'member/index.php?mod=yp&file=yp&action=set');
			}

			$result=$yp->commentlist($ypinfo['id'],$k,20);
			include member_tlp('comment','yp');
			break;
		case 'comment_pass':
			$ypinfo=$yp->userypinfo($_userid,'id');
			
			if(!$ypinfo)
			{
				showmsg('您尚未开通企业店铺, 不能进行此操作, 请先开通!',SITE_URL.'member/index.php?mod=yp&file=yp&action=set');
			}

			if(!isset($id) || !$id)showmsg($lang['RETURN_NOSELECT']);
			if($yp->comment_pass($id,1))
			{
				showmsg('操作成功!');
			}
			else
			{	
				showmsg('操作失败!');
			}
			break;
		case 'comment_unpass':
			$ypinfo=$yp->userypinfo($_userid,'id');
			
			if(!$ypinfo)
			{
				showmsg('您尚未开通企业店铺, 不能进行此操作, 请先开通!',SITE_URL.'member/index.php?mod=yp&file=yp&action=set');
			}

			if(!isset($id) || !$id)showmsg($lang['RETURN_NOSELECT']);
			if($yp->comment_pass($id,0))
			{
				showmsg('操作成功!');
			}
			else
			{	
				showmsg('操作失败!');
			}
			break;
		case 'comment_delete':
			$ypinfo=$yp->userypinfo($_userid,'id');
			
			if(!$ypinfo)
			{
				showmsg('您尚未开通企业店铺, 不能进行此操作, 请先开通!',SITE_URL.'member/index.php?mod=yp&file=yp&action=set');
			}

			if(!isset($id) || !$id)showmsg($lang['RETURN_NOSELECT']);
			if($yp->comment_delete($id))
			{
				showmsg('操作成功!');
			}
			else
			{	
				showmsg('操作失败!');
			}
			break;
	}
?>