<?php
class buyAction extends security_normal {
	
	function action(){
		$miceSession = new session();	
		if($miceSession->get('mu__userid')<1)
		{
			$uid=0;
			$name='';
		}
		else
		{
			$uid=$miceSession->get('mu__userid');
			$name=$miceSession->get('mu__loginname');
		}
		$pid=ceil($this->_getParamId(1));
		$article=new model_Article();
		$article->setSubsection('WHERE isvisible=0 AND type=\'article1\' AND article_id='.$pid);
		$ArticleRS=$article->doSelectOne();
		if(!$ArticleRS){
			$jsstring='Dialog.alert(\'对不起,您查看的产品信息不存在或已经被删除\',function(){window.location.href="'.MICE_URL.'";window.event.returnValue = false;},300,100,"提示信息");';
			MessageBox($jsstring);
			exit;
		}

		global $conn;
		if($_POST){
			if($_POST['checkcode']<>$miceSession->get('checkcode')){
				$jsstring='Dialog.alert("验证码错误",function(){history.back(-1);});';
				MessageBox($jsstring);
				exit;
			}

			if($_POST['name']==''){
				$jsstring='Dialog.alert("请填写姓名",function(){history.back(-1);});';
				MessageBox($jsstring);
				exit;
			}

			if($_POST['content']<1){
				$jsstring='Dialog.alert("请填写购买数量",function(){history.back(-1);});';
				MessageBox($jsstring);
				exit;
			}

			$form=new model_Form();
			$form->setName(MiceFilterHtml($_POST['name']));
			$form->setUserId($uid);
			$form->setEmail(MiceFilterHtml($_POST['email']));
			$form->setTitle(MiceFilterHtml($_POST['title']));
			$form->setCreatedat(time());
			$form->setType('product');
			$form->setIp(GetRealIp());
			$form->setContent(MiceFilterHtml($_POST['content']));
			$results=$form->doInsert();

			if($results)
				$exeresult='提交成功';
			else
				$exeresult='提交失败';
			$jsstring='Dialog.alert(\'我们的工作人员会尽快按照您提供的联系方式和您联系\',function(){window.location.href="'.MICE_URL.'";window.event.returnValue = false;},300,100,"'.$exeresult.'");';
			MessageBox($jsstring);
			exit;
		}

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileIndex');
		$smarty->assign("name",$name);
		$smarty->assign("pid",$pid);
		$smarty->assign("title",$ArticleRS->getTitle());
		$smarty->assign("checkcode",MICE_URL.'index.php/checkcode');

		$filename = new getTPLFileName(__CLASS__);
		$tpl=$filename->TPLFileName;
		$smarty->display($tpl);
	}	
}
?>