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

class PaDefault extends CustomPage {
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnBInitial(){
		$this->sMetaTitle='问卷';
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'cmsvoteoption','sttColumnHead'=>'cvot'),
			array('sttTableName'=>$this->sysTableHead.'cmsvoteoptioncont','sttColumnHead'=>'cvoct'),);
		$this->getUser('1,2,3,4,5,');
		$this->sApp=new cmsvote($this->sConnString);
		$this->sTemplatePath='Cms/voteSurvey_Normal.php';
		
		//-- ------ #ActionType ------ --
		if ($this->sActionType=='DViewResult') {
			$this->OnViewResult();
		}
		
		
	}
	public function OnList(){
		$tmpAR0=$this->AnalyerRequest('ID',0,0);
		$this->sMainID=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('Result','0,',0);
		$this->sVotepageindex=$tmpAR0[0];
		$this->sVoteresult=$tmpAR0[1];
		
		$tmpAR0=$this->AnalyerRequest('mainID',0,1);
		if ($tmpAR0[0]!=0) {
			$this->sMainID=$tmpAR0[0];
		}
		$tmpAR0=$this->AnalyerRequest('votePageindexTxt',0,1);
		if ($tmpAR0[0]!=0) {
			$this->sVotepageindex=$tmpAR0[0];
		}
		$tmpAR0=$this->AnalyerRequest('voteResultTxt','',1);
		if ($tmpAR0[0]!='') {
			$this->sVoteresult=$tmpAR0[0];
		}
		
		$this->sData_Group=array();
		$this->sData_List=array();
		//-- ------ ### ------ --
		if ($this->sMainID==0) {
			//#Error
			//#Other
			$tmpSQL=' SELECT A.cvgtID,A.cvgtName,A.cvgtParid,A.cvgtCreateTime
				FROM {Nets.TableHead}cmsvotegroup AS A 
				WHERE 1=1 AND A.cvgtRecycle=0 AND A.cvgtChecked>1
				ORDER BY A.cvgtOrderBy DESC,A.cvgtID DESC LIMIT 0,8 ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$this->sOtherData=$this->sDb->Search($tmpSTR);
			return 1;
		}
		//-- ------ ### ------ --
		//-- #GROUP --
		$tmpSQL=' SELECT A.cvgtID,A.cvgtName,
			B.cvgctContent
			FROM {Nets.TableHead}cmsvotegroup AS A
			INNER JOIN {Nets.TableHead}cmsvotegroupcont AS B ON B.cvgctIndexID=A.cvgtID
			WHERE 1=1 AND A.cvgtRecycle=0 AND A.cvgtChecked>1 AND A.cvgtID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sMainID,$tmpSTR);
		$this->sData_Group=$this->sDb->Search($tmpSTR);
		if (count($this->sData_Group)==0) {
			//#Error
			//#Other
			$tmpSQL=' SELECT A.cvgtID,A.cvgtName,A.cvgtParid,A.cvgtCreateTime
				FROM {Nets.TableHead}cmsvotegroup AS A 
				WHERE 1=1 AND A.cvgtRecycle=0 AND A.cvgtChecked>1
				ORDER BY A.cvgtOrderBy DESC,A.cvgtID DESC LIMIT 0,8 ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$this->sOtherData=$this->sDb->Search($tmpSTR);
			return 1;
		}
		$this->sMetaTitle=$this->sData_Group[0]['cvgtName'];
		//-- #Vote --
		$tmpSQL=' SELECT A.cvtID,A.cvtName,A.cvtNameStyle,
			B.cvctSet_Result,B.cvctTime_End,B.cvctControl_Type,B.cvctControl_Len,B.cvctControl_Default,
			B.cvctControl_Need,B.cvctControl_Input,B.cvctContent
			
			FROM {Nets.TableHead}cmsvote AS A
			INNER JOIN {Nets.TableHead}cmsvotecont AS B ON B.cvctIndexID=A.cvtID
			WHERE 1=1 AND A.cvtRecycle=0 AND A.cvtChecked>1 AND 
			A.cvtParid={Nets.Parid} AND B.cvctSet_Page={Nets.Page}
			ORDER BY A.cvtOrderBy DESC,A.cvtID DESC ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sMainID,$tmpSTR);
		$tmpSTR=str_replace('{Nets.Page}',$this->sVotepageindex,$tmpSTR);
		$tmpData0=$this->sDb->Search($tmpSTR);
		if (count($tmpData0)==0 && $this->sVoteresult!='') {
			//#Record
			$tmpDbDescriptions=array(
				$this->sysDbDescriptions[$this->sysTableHead.'cmsvoteresult'],
				$this->sysDbDescriptions[$this->sysTableHead.'cmsvoteresultcont'],
				);
			$tmpDbDescriptions[0]['Columns']['cvrtParid']['Value']=$this->sMainID;
			$tmpDbDescriptions[0]['Columns']['cvrtChecked']['Value']=2;
			$tmpDbDescriptions[0]['Columns']['cvrtCreateBy']['Value']=$this->sUserInfo[0]['Columns']['uitID']['Value'];
			$tmpDbDescriptions[1]['Columns']['cvrctConContent']['Value']=$this->sVoteresult;
			$tmpNumCode='';
			$tmpINT=$this->sApp->recordResult($tmpDbDescriptions,$tmpNumCode);
			if($tmpINT!=0){
				$this->sJscript=$this->Message('ERROR','',$this->sApp->sysLastError,'');
				return 1;
			}
			
			$this->sJscript=$this->Message('SUCCESS','','您的问卷结果已正确提交',$this->sysPage.'?ActionType=DViewResult&DViewResult='.$tmpNumCode);
			return 0;
		}else if (count($tmpData0)==0) {
			//#Error
			return 1;
		}
		$this->sData_List=array();
		foreach ($tmpData0 as $Row0){
			$tmpFlag=0;
			$tmpAR1=explode($this->sysSPLIT4,$Row0['cvctSet_Result']);
			foreach ($tmpAR1 as $Row1) {
				if (stripos($this->sVoteresult,$Row1)!=false) {
					$this->sData_List[]=$Row0;
					$tmpFlag=1;
				}
			}
			if ($Row0['cvctSet_Result']=='' && $tmpFlag==0) {
				$this->sData_List[]=$Row0;
			}
			
		}
		
		
		return 0;
	}
	public function OnViewResult(){
		$tmpAR0=$this->AnalyerRequest('DViewResult','',0);
		
		$this->sData_Group=array();
		$this->sData_List=array();
		//-- ------ ### ------ --
		//-- #Result --
		$tmpSQL=' SELECT A.cvrtID,A.cvrtParid,B.cvrctConContent
			FROM {Nets.TableHead}cmsvoteresult AS A
			INNER JOIN {Nets.TableHead}cmsvoteresultcont AS B ON B.cvrctIndexID=A.cvrtID
			WHERE 1=1 AND A.cvrtRecycle=0 AND A.cvrtChecked>1 AND A.cvrtNumCode LIKE \'{Nets.NumCode}\' ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.NumCode}',$tmpAR0[0],$tmpSTR);
		$tmpData_Result=$this->sDb->Search($tmpSTR);
		if (count($tmpData_Result)!=1) {
			//#Error
			//#Other
			$tmpSQL=' SELECT A.cvgtID,A.cvgtName,A.cvgtParid,A.cvgtCreateTime
				FROM {Nets.TableHead}cmsvotegroup AS A 
				WHERE 1=1 AND A.cvgtRecycle=0 AND A.cvgtChecked>1
				ORDER BY A.cvgtOrderBy DESC,A.cvgtID DESC LIMIT 0,8 ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$this->sOtherData=$this->sDb->Search($tmpSTR);
			return 1;
		}
		//-- #GROUP --
		$tmpSQL=' SELECT A.cvgtID,A.cvgtName,
			B.cvgctContent
			FROM {Nets.TableHead}cmsvotegroup AS A
			INNER JOIN {Nets.TableHead}cmsvotegroupcont AS B ON B.cvgctIndexID=A.cvgtID
			WHERE 1=1 AND A.cvgtRecycle=0 AND A.cvgtChecked>1 AND A.cvgtID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$tmpData_Result[0]['cvrtParid'],$tmpSTR);
		$this->sData_Group=$this->sDb->Search($tmpSTR);
		if (count($this->sData_Group)==0) {
			//#Error
			//#Other
			$tmpSQL=' SELECT A.cvgtID,A.cvgtName,A.cvgtParid,A.cvgtCreateTime
				FROM {Nets.TableHead}cmsvotegroup AS A 
				WHERE 1=1 AND A.cvgtRecycle=0 AND A.cvgtChecked>1
				ORDER BY A.cvgtOrderBy DESC,A.cvgtID DESC LIMIT 0,8 ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$this->sOtherData=$this->sDb->Search($tmpSTR);
			return 1;
		}
		$this->sMetaTitle=$this->sData_Group[0]['cvgtName'];
		//-- #RESULT --
		$this->sData_Result=array();
		$tmpAR0=explode($this->sysSPLIT6,$tmpData_Result[0]['cvrctConContent']);
		$Coun0=0;
		foreach ($tmpAR0 as $Row0){
			$tmpAR1=explode($this->sysSPLIT5,$Row0);
			if (count($tmpAR1)==2) {
				$tmpSQL=' SELECT A.cvtID,A.cvtName,
					B.cvctControl_Type,B.cvctContent
					FROM {Nets.TableHead}cmsvote AS A
					INNER JOIN {Nets.TableHead}cmsvotecont AS B ON B.cvctIndexID=A.cvtID
					WHERE 1=1 AND A.cvtRecycle=0 AND A.cvtChecked>1 AND A.cvtID={Nets.ID} ';
				$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
				$tmpSTR=str_replace('{Nets.ID}',$tmpAR1[1],$tmpSTR);
				$tmpData0=$this->sDb->Search($tmpSTR);
				if (count($tmpData0)==1) {
					$this->sData_Result[$Coun0]['cvtName']=$tmpData0[0]['cvtName'];
					$this->sData_Result[$Coun0]['cvctControl_Type']=$tmpData0[0]['cvctControl_Type'];
					$this->sData_Result[$Coun0]['cvctContent']=$tmpData0[0]['cvctContent'];
					$this->sData_Result[$Coun0]['cvctOptions']='';
					if ($this->sData_Result[$Coun0]['cvctControl_Type']=='TextArea') {
						$this->sData_Result[$Coun0]['cvctOptions']=$tmpAR1[0];
					}else if ($this->sData_Result[$Coun0]['cvctControl_Type']=='Label') {
						$this->sData_Result[$Coun0]['cvctOptions']=$tmpAR1[0];
					}else if ($this->sData_Result[$Coun0]['cvctControl_Type']=='Text') {
						$this->sData_Result[$Coun0]['cvctOptions']=$tmpAR1[0];
					}else if ($this->sData_Result[$Coun0]['cvctControl_Type']=='CheckboxAR' ||
						$this->sData_Result[$Coun0]['cvctControl_Type']=='RadioAR') {
						$tmpAR2=explode($this->sysSPLIT2,$tmpAR1[0]);
						$Coun2=1;
						foreach ($tmpAR2 as $Row2){
							if ($Row2==''){
							}else {
								$this->sData_Result[$Coun0]['cvctOptions'].=$Coun2.'.'.$Row2.$this->sysSPLIT8;
								$Coun2++;
							}
						}
						
						
					}
					
					
					
					$Coun0++;
				}
			}
		}
		
		
		return 0;
	}
	
	public function getOption($pID,&$pData){
		
		$tmpSQL=' SELECT A.cvotID,A.cvotName,A.cvotValue
			FROM {Nets.TableHead}cmsvoteoption AS A
			INNER JOIN {Nets.TableHead}cmsvoteoptioncont AS B ON B.cvoctIndexID=A.cvotID
			WHERE 1=1 AND A.cvotRecycle=0 AND A.cvotChecked>1 AND A.cvotParid={Nets.Parid}
			ORDER BY A.cvotOrderBy DESC,A.cvotID DESC ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.Parid}',$pID,$tmpSTR);
		$tmpData0=$this->sDb->Search($tmpSTR);
		
		$tmpOptions=array();
		foreach ($tmpData0 as $Row0){
			$tmpAR0=$this->sControl->sDpReturnTemplate;
			$tmpAR0['Text']=$Row0['cvotName'];
			$tmpAR0['Value']=$Row0['cvotValue'];
			$tmpAR0['Style']='';
			$tmpAR0['Title']='';
			$tmpAR0['AddOne']='';
			$tmpOptions[]=$tmpAR0;
		}
		
		$pData=$tmpOptions;
		return 0;
	}
	
	
}
?>