<?php
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/cmsvoteresult.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/cmsvoteresultcont.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Doc/cmsdoc.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Other/cmsvoteresult.php');

class PaDefault extends CustomPage {
	public $sParid=3;
	public $sVoteDescriptions=array();
	public $sResultDescriptions=array();
	
	public $sIntroduct='';
	
	public function PaDefault(){
		$this->ComPage();
	}
	public function OnBInitial(){
		$this->sMetaTitle='在线调查';
		$this->sApp=new cmsvoteresult($this->sConnString);
	}
	public function OnAdd(){
		$tmpDbDescription=array();
		$tmpDbDescription[]=$this->sDbDescriptions[$this->sysTableHead.'cmsvoteresult'];
		$tmpDbDescription[]=$this->sDbDescriptions[$this->sysTableHead.'cmsvoteresultcont'];
		$tmpMainUserid=$this->AnalyerRequest('mainUserid',0,1);
		//-- ------ #Check CCode ------ --
		$tmpSTR='CCode';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt','',1);
		$tmpCCode=$tmpAR0[0];
		if(!array_key_exists('NetsCCode',$_SESSION)){
			$this->sJscript=$this->Message('ERROR','提交失败','验证码错误','');
			return 1;
		}
		if($_SESSION['NetsCCode']=='' || $_SESSION['NetsCCode']!=$tmpCCode){
			$this->sJscript=$this->Message('ERROR','提交失败','验证码错误','');
			return 1;
		}
		//-- ------ #Add ------ --
		//#Get numCode
		$tmpSTR='cvrtNumCode';
		$tmpDbDescription[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescription[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
		$this->sApp->numCode($tmpDbDescription[0]);
		//#Set value
		$tmpSQL=' SELECT
			A.cvtID,A.cvtName
			FROM '.$this->sysTableHead.'cmsvote AS A
			INNER JOIN cmsvotecont AS B ON B.cvctIndexID=A.cvtID
			WHERE 1=1 AND A.cvtRecycle=0 AND A.cvtChecked>1 AND A.cvtParid={Nets.Parid} ';
		$tmpSTR=str_replace('{Nets.Parid}',$this->sParid,$tmpSQL);
		$tmpData0=$this->sApp->Search($tmpSTR);
		$Coun0=0;
		$tmpDbDescription[1]['Columns']['cvrctContent']['Value']='';
		foreach($tmpData0 as $Row0){
			$tmpINT=$Coun0+1;
			$tmpAR0=$this->AnalyerRequest('VoteSheme_'.$tmpINT.'Txt','',1);
			$tmpDbDescription[1]['Columns']['cvrctContent']['Value'].=$tmpINT.'.'.$Row0['cvtName'].$this->sysSPLIT4.$tmpAR0[0].$this->sysSPLIT4.$this->sysSPLIT4;
			$Coun0++;
		}
		
		//-- #填表-联系人 --
		$tmpSTR='cvrctConMan';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescription[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
		$tmpDbDescription[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		//-- #填表-电子邮件 --
		$tmpSTR='cvrctConEmail';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescription[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
		$tmpDbDescription[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		//-- #填表-电话 --
		$tmpSTR='cvrctConTitle';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescription[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
		$tmpDbDescription[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		//-- #填表-地址 --
		$tmpSTR='cvrctConAddress';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescription[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
		$tmpDbDescription[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		//-- #填表-留言内容 --
		$tmpSTR='cvrctConContent';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescription[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
		$tmpDbDescription[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		
		$tmpDbDescription[0]['Columns']['cvrtName']['Value']='问卷调查('.$tmpDbDescription[1]['Columns']['cvrctConMan']['Value'].')_'.$tmpDbDescription[0]['Columns']['cvrtNumCode']['Value'];
		//#Add
		$tmpINT=$this->sApp->Check($tmpDbDescription,array(),array());
		if($tmpINT!=0){
			$this->sJscript=$this->Message('ERROR','',$this->sApp->sysLastError,'');
			return 1;
		}
		$tmpDbDescription[0]['TableDescription']['SearchColumn']='cvrtNumCode,cvrtID';
		$tmpDbDescription[1]['TableDescription']['SearchColumn']='cvrctIndexID';
		$tmpINT=$this->sApp->add($tmpDbDescription);
		if($tmpINT!=0){
			$this->sJscript=$this->Message('ERROR','',$this->sApp->sysLastError,'');
			return 1;
		}
		
		$this->sJscript=$this->Message('SUCCESS','','感谢您参与本次调查。',$this->sysPage);
		return 0;
	}
	public function OnBLoad(){
		$tmpSQL=' SELECT
			A.cvgtID,A.cvgtName,B.cvgctContent
			FROM '.$this->sysTableHead.'cmsvotegroup AS A
			INNER JOIN '.$this->sysTableHead.'cmsvotegroupcont AS B ON B.cvgctIndexID=A.cvgtID
			WHERE 1=1 AND A.cvgtRecycle=0 AND A.cvgtChecked>1 AND A.cvgtID={Nets.Parid} ';
		$tmpSTR=str_replace('{Nets.Parid}',$this->sParid,$tmpSQL);
		$tmpData0=$this->sDb->Search($tmpSTR);
		if(count($tmpData0)==0){
			return 0;
		}
		$this->sMetaTitle=$tmpData0[0]['cvgtName'];
		$this->sIntroduct=$tmpData0[0]['cvgctContent'];
		
		$tmpSQL=' SELECT
			A.cvtID,A.cvtName,
			B.cvctControlType,B.cvctControlLen
			FROM '.$this->sysTableHead.'cmsvote AS A
			INNER JOIN '.$this->sysTableHead.'cmsvotecont AS B ON B.cvctIndexID=A.cvtID
			WHERE 1=1 AND A.cvtRecycle=0 AND A.cvtChecked>1 AND A.cvtParid={Nets.Parid} ';
		$tmpSTR=str_replace('{Nets.Parid}',$this->sParid,$tmpSQL);
		$tmpData0=$this->sApp->Search($tmpSTR);
		$Coun0=0;
		foreach($tmpData0 as $Row0){
			$this->sVoteDescriptions[$Coun0]=$this->sysUiDescriptionModel;
			$this->sVoteDescriptions[$Coun0]['Index']=$Coun0+1;
			$this->sVoteDescriptions[$Coun0]['stcotName']='VoteSheme_'.$this->sVoteDescriptions[$Coun0]['Index'];
			$this->sVoteDescriptions[$Coun0]['stcoctUiName']=$Row0['cvtName'];
			$this->sVoteDescriptions[$Coun0]['stcoctUiType']=$Row0['cvctControlType'];
			$this->sVoteDescriptions[$Coun0]['stcoctUiLen']=$Row0['cvctControlLen'];
			
			$tmpSQL=' SELECT
				A.cvotID,A.cvotName,A.cvotValue
				FROM '.$this->sysTableHead.'cmsvoteoption AS A
				INNER JOIN '.$this->sysTableHead.'cmsvoteoptioncont AS B ON B.cvoctIndexID=A.cvotID
				WHERE 1=1 AND A.cvotRecycle=0 AND A.cvotChecked>1 AND A.cvotParid={Nets.Parid} ';
			$tmpSTR=str_replace('{Nets.Parid}',$Row0['cvtID'],$tmpSQL);
			$tmpData1=$this->sApp->Search($tmpSTR);
			$Coun1=0;
			foreach($tmpData1 as $Row1){
				$this->sVoteDescriptions[$Coun0]['Option'][$Coun1]=array('Text'=>$Row1['cvotName'],'Value'=>$Row1['cvotValue']);
				$Coun1++;
			}
			
			$Coun0++;
		}
		//-- ------ # ------ --
		$Coun0=0;
		$tmpAR0=array(
			array('stcotName'=>'cvrctConMan','stcoctUiName'=>'填表-联系人','stcoctUiType'=>'Text'),
			array('stcotName'=>'cvrctConEmail','stcoctUiName'=>'填表-电子邮件','stcoctUiType'=>'Text'),
			array('stcotName'=>'cvrctConTitle','stcoctUiName'=>'填表-电话','stcoctUiType'=>'Text'),
			array('stcotName'=>'cvrctConAddress','stcoctUiName'=>'填表-地址','stcoctUiType'=>'Text'),
			array('stcotName'=>'cvrctConContent','stcoctUiName'=>'填表-留言内容','stcoctUiType'=>'TextArea'),
			array('stcotName'=>'CCode','stcoctUiName'=>'验证码','stcoctUiType'=>'CCode'),
			);
		foreach($tmpAR0 as $Cell){
			$this->sResultDescriptions[$Coun0]=$this->sysUiDescriptionModel;
			$this->sResultDescriptions[$Coun0]['stcotName']=$Cell['stcotName'];
			$this->sResultDescriptions[$Coun0]['stcoctUiName']=$Cell['stcoctUiName'];
			$this->sResultDescriptions[$Coun0]['stcoctUiType']=$Cell['stcoctUiType'];
			$Coun0++;
		}
		return 0;
	}
	public function DefUiButton($pFlag,$Exception){
		parent::DefUiButton($pFlag,array('List','Normal','ListChildLink','NormalChildLink',));
		if ($pFlag=='Normal') { ?>
<li class="ButBut"><input type="submit" value="提交本调查问卷" class="Control2" onclick="setActionType('Normal','DAdd','','');" /></li>
<?php }
	}
	public function DefUiJscript($pFlag){
?>
function jsDCheck(pPara){
	var tmpControl="";
	var tmpError="";
	var tmpChecker=new netsChecker();
	var tmpActionWithOut=document.getElementById("ActionWithOut");
	var Coun0=0;
	//-- ------ #ActionWithOut ------ --
	if(tmpActionWithOut==undefined){
		return true;
	}
	if(tmpActionWithOut.value=="1"){
		return true;
	}else if(tmpActionWithOut.value=="2"){
		return false;
	}
	//-- ------ #Check ------ --
	//#CCode
	tmpCheckCont=document.getElementById("CCodeTxt");
	tmpCheckCont.value=tmpChecker.Filter(tmpCheckCont.value,0);
	if(!tmpCheckCont.value.length!=5){
		Coun0++;
		tmpError+=Coun0+".请输入5位验证码"+sysSPLIT8;
	}
	//-- ------ #Result ------ --
	if(tmpError!=""){
		tmpSTR="<span class=\"FStrong\">对不起，您提交的内容存在以下错误:</span>"+sysSPLIT8+tmpError;
		showMessage("系统消息 - <?php echo ($this->sysFileConfig['sysTitle']); ?>",tmpSTR,"","0");
		return false;
	}else{
		return true;
	}
}
<?php
	}
}
?>