<?php
	!defined('DIRCMS_MANAGE') && exit('Access Denied!');
	if(!$module->roleid_check('yp',$_roleid))showmsg_nourl($lang['RETURN_NOPRI']);

	$action=empty($action)?'manage':trim($action);
	require substr(dirname(__FILE__),0,-6).'/include/yp.class.php';
	$yp=new yp();

	include_once DIRCMS_ROOT.'include/form.class.php';
	include_once DIRCMS_ROOT.'yp/data/config.inc.php';

	switch($action)
	{
		/*
			黄页配置
		*/
		case 'config':
			if(isset($do_submit)) 
			{
				if($yp->setting($info))
				{
					showmsg($lang['RETURN_SUCEESS']);
				}
				else
				{
					showmsg($lang['RETURN_ERROR']);
				}
			}
			include admin_tlp('config','yp');
			break;
		/*
			门店操作
		*/
		case 'manage':
			$k=isset($k)?trim($k):'';
			$typeid=isset($typeid)?intval($typeid):0;
			$result=$yp->yplist($k,$typeid,15);
			include admin_tlp('yp_manage','yp');	
			break;
		case 'add':
			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']))
				{
					showmsg('门店目录已经存在, 请更换!');
				}

				if($yp->add($info))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}

			$form = new form('info');
			$forms=$form->get(2,array(),'member');
			include admin_tlp('yp_add','yp');	
			break;
		case 'edit':
			if(isset($do_submit))
			{
				include DIRCMS_ROOT.'include/data.input.class.php';
				$datainput = new data_input(2,'member');
				$info=$datainput->filter($info);
				
				if($yp->edit($info,$id,$userid))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			$ypinfo=$yp->allinfo($id,false);
			$form = new form('info');
			$forms=$form->get(2,$ypinfo,'member');
			include admin_tlp('yp_edit','yp');	
			break;
		case 'close':
			if(!isset($id) || !$id)showmsg('请选择需要'.($status==1?'开通':'关闭').'的门店!');
			if($yp->close($id,$status))
			{
				$cache->clear();
				showmsg('门店成功'.($status==1?'开通':'关闭').'!');
			}
			else
			{
				showmsg('门店'.($status==1?'开通':'关闭').'失败!');
			}
			break;
		case 'businesslicense':
			if(!isset($id) || !$id)showmsg('请选择需要'.($status==1?'开通认证':'关闭认证').'的门店!');
			if($yp->set($id,array('businesslicense'=>intval($status))))
			{
				$cache->clear();
				showmsg('通过营业执照认证'.($status==1?'开通':'关闭').'成功!');
			}
			else
			{
				showmsg('通过营业执照认证'.($status==1?'开通':'关闭').'失败!');
			}
			break;
		case 'identitycard':
			if(!isset($id) || !$id)showmsg('请选择需要'.($status==1?'开通认证':'关闭认证').'的门店!');
			if($yp->set($id,array('identitycard'=>intval($status))))
			{
				$cache->clear();
				showmsg('通过身份证认证'.($status==1?'开通':'关闭').'成功!');
			}
			else
			{
				showmsg('通过身份证认证'.($status==1?'开通':'关闭').'失败!');
			}
			break;
		case 'top':
			if(!isset($id) || !$id)showmsg('请选择需要'.($istop?'推荐':'取消推荐').'的门店!');
			if($yp->settop($id,$istop))
			{
				$cache->clear();
				showmsg('门店成功'.($istop?'推荐':'取消推荐').'!');
			}
			else
			{
				showmsg('门店'.($istop?'推荐':'取消推荐').'失败!');
			}
			break;
		/*
			企业新闻
		*/
		case 'news':
			if(isset($do_submit))
			{
				if(!isset($id) || !$id)showmsg('请选择需要操作的选项!');
				if($yp->news_delete($id))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			$ypid=isset($ypid)?intval($ypid):'';
			$k=isset($k)?trim($k):'';
			$result=$yp->newslist($ypid,$k,15);
			include admin_tlp('yp_news','yp');	
			break;
		case 'news_add':
			if(isset($do_submit))
			{
				if($yp->news_add($info))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			$ypid=isset($ypid)?intval($ypid):'';
			if(!$ypid)
			{
				showmsg('操作失败!');
			}
			$ypinfo=$yp->ypinfo($ypid);
			$form = new form('info');
			include admin_tlp('yp_news_add','yp');	
			break;
		case 'news_edit':
			if(isset($do_submit))
			{
				if($yp->news_edit($info,$id))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			$id=isset($id)?intval($id):'';
			if(!$id)
			{
				showmsg('操作失败!');
			}
			$form = new form('info');
			$newsinfo=$yp->newsinfo($id);
			include admin_tlp('yp_news_edit','yp');	
			break;
		/*
			优惠信息
		*/
		case 'discount':
			if(isset($do_submit))
			{
				if(!isset($id) || !$id)showmsg('请选择需要操作的选项!');
				if($yp->discount_delete($id))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			$ypid=isset($ypid)?intval($ypid):'';
			$k=isset($k)?trim($k):'';
			$result=$yp->discountlist($ypid,$k,15);
			include admin_tlp('yp_discount','yp');	
			break;
		case 'discount_add':
			if(isset($do_submit))
			{
				if($yp->discount_add($info))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			$ypid=isset($ypid)?intval($ypid):'';
			if(!$ypid)
			{
				showmsg('操作失败!');
			}
			$ypinfo=$yp->ypinfo($ypid);
			$form = new form('info');
			include admin_tlp('yp_discount_add','yp');	
			break;
		case 'discount_edit':
			if(isset($do_submit))
			{
				if($yp->discount_edit($info,$id))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			$id=isset($id)?intval($id):'';
			if(!$id)
			{
				showmsg('操作失败!');
			}
			$form = new form('info');
			$discountinfo=$yp->discountinfo($id);
			include admin_tlp('yp_discount_edit','yp');
			break;

		/*
			企业产品
		*/
		case 'product':
			if(isset($do_submit))
			{
				if(!isset($id) || !$id)showmsg('请选择需要操作的选项!');
				if($yp->product_delete($id))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			$ypid=isset($ypid)?intval($ypid):'';
			$k=isset($k)?trim($k):'';
			$result=$yp->productlist($ypid,$k,15);
			include admin_tlp('yp_product','yp');	
			break;
		case 'product_add':
			if(isset($do_submit))
			{
				if($yp->product_add($info))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			$ypid=isset($ypid)?intval($ypid):'';
			if(!$ypid)
			{
				showmsg('操作失败!');
			}
			$ypinfo=$yp->ypinfo($ypid);
			$form = new form('info');
			include admin_tlp('yp_product_add','yp');	
			break;
		case 'product_edit':
			if(isset($do_submit))
			{
				if($yp->product_edit($info,$id))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			$id=isset($id)?intval($id):'';
			if(!$id)
			{
				showmsg('操作失败!');
			}
			$form = new form('info');
			$productinfo=$yp->productinfo($id);
			include admin_tlp('yp_product_edit','yp');
			break;
		/*
			点评管理
		*/
		case 'comment':
			if(isset($do_submit))
			{
				if(!isset($id) || !$id)showmsg('请选择需要操作的选项!');
				if($yp->comment_delete($id))
				{
					showmsg('操作成功!');
				}
				else
				{
					showmsg('操作失败!');
				}
			}
			$ypid=isset($ypid)?intval($ypid):'';
			$k=isset($k)?trim($k):'';
			$result=$yp->commentlist($ypid,$k,15);
			include admin_tlp('yp_comment','yp');	
			break;
	}
?>