<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot_Real'].'Cache/DbDescription/cmsvote.php');
require($netsFileConfig['sysCoreRoot_Real'].'Cache/DbDescription/cmsvotecont.php');
require($netsFileConfig['sysCoreRoot_Real'].'Cache/DbDescription/cmsvoteoption.php');
require($netsFileConfig['sysCoreRoot_Real'].'Cache/DbDescription/cmsvoteoptioncont.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Other/cmsvotegroup.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Other/cmsvote.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Other/cmsvoteoption.php');

class PaDefault extends CustomPage {
	public $ssetParid=1;
	
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnPInitial(){
		$this->checkUser('1,2,3,');
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'cmsvotegroup','sttColumnHead'=>'cvgt'),
			array('sttTableName'=>$this->sysTableHead.'cmsvotegroupcont','sttColumnHead'=>'cvgct'),);
		$this->sUiName='Platform/cms/cmsvotegroup';
	}
	public function OnBInitial(){
		$this->sMetaTitle='投票分类';
		$this->sLimitCount=1;
		$this->sApp=new cmsvotegroup($this->sConnString);
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.cvgtID,A.cvgtName,A.cvgtParid FROM '.$this->sysTableHead.'cmsvotegroup AS A
			WHERE 1=1 AND A.cvgtRecycle=0 AND A.cvgtChecked>1 AND A.cvgtParid={Nets.Parid}
			ORDER BY A.cvgtOrderBy DESC,A.cvgtID DESC ';
		$tmpAR0['SQL0']=' SELECT A.cvgtID,A.cvgtName,A.cvgtParid FROM '.$this->sysTableHead.'cmsvotegroup AS A
			WHERE 1=1 AND A.cvgtRecycle=0 AND A.cvgtChecked>1 AND A.cvgtID={Nets.Parid}
			ORDER BY A.cvgtOrderBy DESC,A.cvgtID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='cvgtID';
		$tmpAR0['Text']='cvgtName';
		$tmpAR0['Value']='cvgtID';
		$tmpAR0['Type']=0;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$this->sParid1=$this->sParid2=$this->sControl->bindDropdown($tmpAR0);
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有分类]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sParid2,$tmpAR0);
		
		//ControlType
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=91;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/options_Vote_ControlType';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sControlType1);
		$this->sControlType2=$this->sControlType1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有控件类型]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sControlType2,$tmpAR0);
		
		//-- ------ #ActionType ------ --
		if ($this->sActionType=='DReport_Options') {
			$this->OnReport_Options();
		}
		if ($this->sActionTypeF=='DReport_Save') {
			$this->OnReport_Save();
		}
		
		
	}
	public function OnReport_Save(){
		//-- ------ #Vote ------ --
		$tmpDbDescriptions=array(
			$this->sDbDescriptions[$this->sysTableHead.'cmsvote'],
			$this->sDbDescriptions[$this->sysTableHead.'cmsvotecont'],
			);
		$this->sApp->TransStart();
		
		$tmpSTR='cvtID';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[0]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		$tmpID=$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value'];
		$tmpSTR='cvtParid';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[0]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		$tmpParid=$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value'];
		
		$tmpApp=new cmsvote($this->sConnString);
		if ($tmpDbDescriptions[0]['Columns']['cvtID']['Value']==0) {
			//-- #ADD --
			//#Get numCode
			$tmpSTR='cvtNumCode';
			$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
			$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
			$this->sDb->numCode($tmpDbDescriptions[0]);
			//#Set value
			$tmpSTR='cvtName';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[0]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctControl_Type';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvtOrderBy';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[0]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctSet_Page';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctSet_Result';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctTime_End';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctControl_Len';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctControl_Default';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctControl_Need';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctControl_Input';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvtID';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[0]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvtParid';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[0]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvtChecked';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[0]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			
			$tmpDbDescriptions[0]['Columns']['cvtCreateBy']['Value']=$this->sUserInfo[0]['Columns']['uitID']['Value'];
			$tmpDbDescriptions[0]['Columns']['cvtCreateTime']['Value']=date($this->sysTimeFormat);
			
			
			//#Add
			$tmpINT=$tmpApp->Check($tmpDbDescriptions,array(),array());
			if($tmpINT!=0){
				$this->sDb->TransRollback();
				$this->sJscript=$this->Message('ERROR','',$this->sDb->sysLastError,'');
				return 1;
			}
			$tmpDbDescriptions[0]['TableDescription']['SearchColumn']='cvtNumCode,cvtID';
			$tmpDbDescriptions[1]['TableDescription']['SearchColumn']='cvctIndexID';
			$tmpINT=$this->sDb->add($tmpDbDescriptions);
			if($tmpINT!=0){
				$this->sDb->TransRollback();
				$this->sJscript=$this->Message('ERROR','',$this->sDb->sysLastError,'');
				return 1;
			}
			
		}else {
			//-- #MODIFY --
			$tmpDbDescriptions[0]['Columns']['cvtID']['Value']=$tmpID;
			$tmpDbDescriptions[1]['Columns']['cvctIndexID']['Value']=$tmpID;
			$this->sDb->getOne($tmpDbDescriptions);
			//#Set value
			$tmpSTR='cvtName';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[0]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctControl_Type';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvtOrderBy';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[0]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctSet_Page';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctSet_Result';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctTime_End';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctControl_Len';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctControl_Default';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctControl_Need';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvctControl_Input';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[1]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[1]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvtID';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[0]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvtParid';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[0]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
			$tmpSTR='cvtChecked';
			$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',$tmpDbDescriptions[0]['Columns'][$tmpSTR]['stcoctDefaultValue'],1);
			$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];

			//#Modify
			$tmpINT=$tmpApp->Check($tmpDbDescriptions,array(),array());
			if($tmpINT!=0){
				$this->sDb->TransRollback();
				$this->sJscript=$this->Message('ERROR','',$this->sDb->sysLastError,'');
				return 1;
			}
			$tmpINT=$this->sDb->modify($tmpDbDescriptions);
			if($tmpINT!=0){
				$this->sDb->TransRollback();
				$this->sJscript=$this->Message('ERROR','',$this->sDb->sysLastError,'');
				return 1;
			}
			
		}
		//-- #GET --
		$tmpSQL=' SELECT A.cvtID
			FROM {Nets.TableHead}cmsvote AS A
			WHERE 1=1 AND A.cvtNumCode LIKE \'{Nets.NumCode}\' ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.NumCode}',$tmpDbDescriptions[0]['Columns']['cvtNumCode']['Value'],$tmpSTR);
		$tmpData_Vote=$this->sDb->Search($tmpSTR);
		if (count($tmpData_Vote)==0) {
			return 1;
		}
		
		//-- ------ #VoteOption ------ --
		$tmpApp=new cmsvoteoption($this->sConnString);
		$tmpAR0=$this->AnalyerRequest('reportPanel_OptionsValueTxt','',1);
		$tmpAR_Rows=explode($this->sysSPLIT3,$tmpAR0[0]);
		if ($tmpDbDescriptions[1]['Columns']['cvctControl_Type']['Value']=='CheckboxAR' || $tmpDbDescriptions[1]['Columns']['cvctControl_Type']['Value']=='RadioAR') {
		}else {
			$tmpAR_Rows=array();
		}
		
		foreach ($tmpAR_Rows as $Row_Rows){
			$tmpAR_Option=explode($this->sysSPLIT2,$Row_Rows);
			if (count($tmpAR_Option)!=2) {
				$tmpAR_Option=array(0,'');
			}
			if ($tmpAR_Option[1]!='') {
				$tmpDbDescriptions=array(
					$this->sDbDescriptions[$this->sysTableHead.'cmsvoteoption'],
					$this->sDbDescriptions[$this->sysTableHead.'cmsvoteoptioncont'],
					);
				if ($tmpAR_Option[0]==0) {
					//-- #ADD --
					//#Get numCode
					$tmpSTR='cvotNumCode';
					$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
					$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
					$this->sDb->numCode($tmpDbDescriptions[0]);
					//#Set value
					$tmpDbDescriptions[0]['Columns']['cvotName']['Value']=$tmpAR_Option[1];
					$tmpDbDescriptions[0]['Columns']['cvotParid']['Value']=$tmpID;
					
					$tmpDbDescriptions[0]['Columns']['cvotChecked']['Value']=2;
					$tmpDbDescriptions[0]['Columns']['cvotCreateBy']['Value']=$this->sUserInfo[0]['Columns']['uitID']['Value'];
					$tmpDbDescriptions[0]['Columns']['cvotCreateTime']['Value']=date($this->sysTimeFormat);
					
					//#Add
					$tmpINT=$tmpApp->Check($tmpDbDescriptions,array(),array());
					if($tmpINT!=0){
						$this->sDb->TransRollback();
						$this->sJscript=$this->Message('ERROR','',$this->sDb->sysLastError,'');
						return 1;
					}
					$tmpDbDescriptions[0]['TableDescription']['SearchColumn']='cvotNumCode,cvotID';
					$tmpDbDescriptions[1]['TableDescription']['SearchColumn']='cvoctIndexID';
					$tmpINT=$this->sDb->add($tmpDbDescriptions);
					if($tmpINT!=0){
						$this->sDb->TransRollback();
						$this->sJscript=$this->Message('ERROR','',$this->sDb->sysLastError,'');
						return 1;
					}
					
					
				}else {
					//-- #MODIFY --
					//#Get one
					$tmpDbDescriptions[0]['Columns']['cvotID']['Value']=$tmpAR_Option[0];
					$tmpDbDescriptions[1]['Columns']['cvotIndexID']['Value']=$tmpAR_Option[0];
					$this->sDb->getOne($tmpDbDescriptions);
					//#Set value
					$tmpDbDescriptions[0]['Columns']['cvotName']['Value']=$tmpAR_Option[1];
					$tmpDbDescriptions[0]['Columns']['cvotParid']['Value']=$tmpID;
					
					
					//#Add
					$tmpINT=$tmpApp->Check($tmpDbDescriptions,array(),array());
					if($tmpINT!=0){
						$this->sDb->TransRollback();
						$this->sJscript=$this->Message('ERROR','',$this->sDb->sysLastError,'');
						return 1;
					}
					$tmpINT=$this->sDb->modify($tmpDbDescriptions);
					if($tmpINT!=0){
						$this->sDb->TransRollback();
						$this->sJscript=$this->Message('ERROR','',$this->sDb->sysLastError,'');
						return 1;
					}
					
					
				}
			}
		}
		
		
		$this->sDb->TransCommit();
		$this->sJscript=$this->Message('SUCCESS','','保存成功',$this->sysPage.'?ActionType=Report&Report='.$tmpParid.',0');
		return 0;
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'cvgtID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.cvgtID,A.cvgtName,A.cvgtParid
			FROM '.$this->sysTableHead.'cmsvotegroup AS A 
			WHERE 1=1 
			AND A.cvgtID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.cvgtName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.cvgtParid='.$this->sSearchData[1].' ';
		}
		if($tmpAR1[1]==1){
			$tmpSQL.=' ORDER BY '.$tmpAR1[0].' ';
		}else if($tmpAR1[1]==2){
			$tmpSQL.=' ORDER BY '.$tmpAR1[0].' DESC ';
		}
		$this->sListData=$this->sDb->SearchP($tmpSQL,$tmpAR0);
		//#Set page button
		$this->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&'.$tmpSTR2.'='.$this->sSearchData[0].$this->sysSPLIT1.$this->sSearchData[1];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'cvgtID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'cvgtName','stcoctUiName'=>'投票分类名称');
		
		return 0;
	}
	public function OnReport(){
		//-- ------ ### ------ --
		$tmpAR0=$this->AnalyerRequest('Report','0,0',0);
		$this->sMainID=$tmpAR0[0];
		$this->sData_Group=array();
		$this->sData_Panel=array();
		//-- ------ #This ------ --
		$tmpSQL=' SELECT A.cvgtID,A.cvgtName,A.cvgtParid,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)!=1) {
			return 1;
		}
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'cvtID,2',0);
		//#Spell sql
		$tmpSQL=' SELECT A.cvtID,A.cvtName,A.cvtParid
			FROM '.$this->sysTableHead.'cmsvote AS A 
			WHERE 1=1 
			AND A.cvtID>'.$this->sLimitCount;
		if($this->sMainID!=0){
			$tmpSQL.=' AND A.cvtParid='.$this->sMainID.' ';
		}
		if($tmpAR1[1]==1){
			$tmpSQL.=' ORDER BY '.$tmpAR1[0].' ';
		}else if($tmpAR1[1]==2){
			$tmpSQL.=' ORDER BY '.$tmpAR1[0].' DESC ';
		}
		$this->sListData=$this->sDb->SearchP($tmpSQL,$tmpAR0);
		//#Set page button
		$this->sPAjaxButton=new netsPAjaxButton();
		$this->sPAjaxButton->sPage=$this->sysPage;
		$this->sPAjaxButton->resetTemlate('../../../Config/m_default/File/pageAjaxButton1.htm');
		$this->sPAjaxButton->sFlag='reportList';
		$this->sPAjaxButton->sPanel='reportList';
		$this->sPAjaxButton->sExtendParameter='&ActionType=Report&Report='.$this->sMainID.$this->sysSPLIT1.'0';
		$this->sPAjaxButton->setPage($this->sDb->sysPageInfo);
		$this->sPAjaxButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'cvtID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'cvtName','stcoctUiName'=>'投票分类名称');
		
		
		return 0;
	}
	public function OnReport_Options(){
		//-- ------ ### ------ --
		$tmpAR0=$this->AnalyerRequest('DReport_Options','0,0',0);
		$this->sData_Group=array();
		$tmpTable=array(
			array('sttTableName'=>$this->sysTableHead.'cmsvote','sttColumnHead'=>'cvt'),
			array('sttTableName'=>$this->sysTableHead.'cmsvotecont','sttColumnHead'=>'cvct'),);
		//-- ------ #This ------ --
		$tmpSQL=' SELECT A.cvgtID,A.cvgtName,A.cvgtParid,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}',$tmpAR0[0],$tmpSTR);
		$tmpData0=$this->sDb->Search($tmpSTR);
		if (count($tmpData0)!=1) {
			return 1;
		}
		$this->sParid=$tmpData0[0]['cvgtID'];
		//-- ------ #Form ------ --
		$this->sUiDescription_0=array();
		$tmpSTR=$this->sUiDescriptionPath.'Mana/cms/cmsvotegroup_options.php';
		if(file_exists($tmpSTR)){
			require($tmpSTR);
			$this->sUiDescription_0=$sysUiDescriptions['cmsvotegroup_options'];
			$sysUiDescriptions=array();
		}
		//-- ------ #This ------ --
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'cmsvote AS A 
			INNER JOIN '.$this->sysTableHead.'cmsvotecont AS B ON B.cvctIndexID=A.cvtID ';
		$Coun0=2;
		foreach ($tmpTable as $Row0){
			if (count($this->sTable)>2) {
				$tmpSQL.=' INNER JOIN '.$Row0['sttTableName'].' AS '.$this->sysTableMark[$Coun0].' ON '.$this->sysTableMark[$Coun0].'.'.$Row0['sttColumnHead'].'IndexID=A.cvgtID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.cvtID='.$tmpAR0[1].' ';
		$tmpData0=$this->sDb->Search($tmpSQL);
		if(count($tmpData0)>0){
			$tmpRow=$tmpData0[0];
			$this->sMainID=$tmpRow[$tmpTable[0]['sttColumnHead'].'ID'];
			//-- #Get value --
			$Coun0=0;
			while (count($this->sUiDescription_0)>$Coun0) {
				if(isset($tmpRow[$this->sUiDescription_0[$Coun0]['stcotName']])){
					$this->sUiDescription_0[$Coun0]['Value']=$tmpRow[$this->sUiDescription_0[$Coun0]['stcotName']];
					//-- ------ #Spical set ------ --
					if($this->sUiDescription_0[$Coun0]['stcotName']=='cvtParid'){
					}else if($this->sUiDescription_0[$Coun0]['stcotName']=='cvtModelid_Detail'){
						$this->sUiDescription_0[$Coun0]['Value']=$this->sMainTableid;
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_0 as $Row0){
				if($Row0['stcotName']=='cvtTableid'){
					$this->sUiDescription_0[$Coun0]['Value']=$this->sMainTableid;
				}else if($Row0['stcotName']=='cvtParid'){
					$this->sUiDescription_0[$Coun0]['Value']=$this->sParid;
				}
				$Coun0++;
			}
		}
		
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'cvgtID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',,-1',0);
		$this->sExternal_SearchData=$this->AnalyerRequest($this->sActionType,',-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.cvgtID,A.cvgtName,A.cvgtParid
			FROM '.$this->sysTableHead.'cmsvotegroup AS A 
			WHERE 1=1 
			AND A.cvgtID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.cvgtName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.cvgtParid='.$this->sSearchData[1].' ';
		}
		if($tmpAR1[1]==1){
			$tmpSQL.=' ORDER BY '.$tmpAR1[0].' ';
		}else if($tmpAR1[1]==2){
			$tmpSQL.=' ORDER BY '.$tmpAR1[0].' DESC ';
		}
		$this->sListData=$this->sDb->SearchP($tmpSQL,$tmpAR0);
		//#Set page button
		$this->sExtendParameter='&ActionType='.$this->sActionType.'&'.$this->sActionType.'='.$this->sExternal_SearchData[0].','.$this->sExternal_SearchData[1];
		$this->sysPages[0]=$this->sysPage.'?'.$this->sExtendParameter;
		
		$this->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&'.$tmpSTR2.'='.$this->sSearchData[0].$this->sExtendParameter;
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'cvgtID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'cvgtName','stcoctUiName'=>'投票分类名称');
		
		return 0;
	}
	public function OnExternal_ChildChoose(){
		//-- ------ #Search data ------ --
		$tmpSTR0='External_ChildChoose';
		$this->sExternal_ChildChooseSData=$this->AnalyerRequest($tmpSTR0,'0,,0,0',0);
		//#Spell sql
		$tmpSQL='';
		if($this->sExternal_ChildChooseSData[0]==0 || $this->sExternal_ChildChooseSData[0]==2){
			//-- Same grade --
			$tmpSQL=' SELECT A.cvgtID,A.cvgtName,A.cvgtParid 
				FROM '.$this->sysTableHead.'cmsvotegroup AS A
				WHERE 1=1 AND A.cvgtRecycle=0 AND A.cvgtChecked>1 AND 
				A.cvgtParid=(SELECT cvgtParid FROM cmsvotegroup WHERE 1=1 AND cvgtRecycle=0 AND cvgtChecked>1 AND cvgtID={Nets.ID})
				ORDER BY A.cvgtOrderBy DESC,A.cvgtID DESC ';
		}else if($this->sExternal_ChildChooseSData[0]==1 || $this->sExternal_ChildChooseSData[0]==3){
			//-- Child grade --
			$tmpSQL=' SELECT A.cvgtID,A.cvgtName,A.cvgtParid 
				FROM '.$this->sysTableHead.'cmsvotegroup AS A
				WHERE 1=1 AND A.cvgtRecycle=0 AND A.cvgtChecked>1 AND A.cvgtParid={Nets.ID}
				ORDER BY A.cvgtOrderBy DESC,A.cvgtID DESC ';
		}
		$tmpSTR=str_replace('{Nets.ID}',$this->sExternal_ChildChooseSData[2],$tmpSQL);
		$this->sExternal_ChildChooseData=$this->sDb->Search($tmpSTR);
		
		return 0;
	}
	public function OnNormal(){
		$tmpINT=0;
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		$this->sOptionControlType='Text';
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'cmsvotegroup AS A 
			INNER JOIN '.$this->sysTableHead.'cmsvotegroupcont AS B ON B.cvgctIndexID=A.cvgtID ';
		$Coun0=2;
		foreach ($this->sTable as $Row0){
			if (count($this->sTable)>2) {
				$tmpSQL.=' INNER JOIN '.$Row0['sttTableName'].' AS '.$this->sysTableMark[$Coun0].' ON '.$this->sysTableMark[$Coun0].'.'.$Row0['sttColumnHead'].'IndexID=A.cvgtID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.cvgtID='.$tmpAR0[0].' ';
		$tmpDataCollection0=$this->sDb->Search($tmpSQL);
		if(count($tmpDataCollection0)>0){
			$tmpRow=$tmpDataCollection0[0];
			$this->sMainID=$tmpRow[$this->sTable[0]['sttColumnHead'].'ID'];
			//-- #Get value --
			$Coun0=0;
			while (count($this->sUiDescription_Normal)>$Coun0) {
				if(isset($tmpRow[$this->sUiDescription_Normal[$Coun0]['stcotName']])){
					$this->sUiDescription_Normal[$Coun0]['Value']=$tmpRow[$this->sUiDescription_Normal[$Coun0]['stcotName']];
					//-- ------ #Spical set ------ --
					if($this->sUiDescription_Normal[$Coun0]['stcotName']=='cvgtParid'){
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='cvgtModelid_Detail'){
						$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_Normal as $Row0){
				if($Row0['stcotName']=='cvgtTableid'){
					$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
				}
				$Coun0++;
			}
		}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='cvgtParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='cvgtParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
			
		}else if($pColumn['stcotName']=='cvctControl_Type' && $pFlag=='Report_Options'){
			$pColumn['Option']=$this->sControlType1;
			$this->sOptionControlType=$pColumn['Value'];
			if (strlen($this->sOptionControlType)<3) {
				$this->sOptionControlType='Text';
			}
			$pColumn['Parameter_JS_Onclick']='tmpCms.OnVote_ControlSelected();';
			
		}else if($pColumn['stcotName']=='cvctControl_Need' && $pFlag=='Report_Options'){
			$pColumn['Option']=$this->sBoolean1;
		}else if($pColumn['stcotName']=='cvctControl_Input' && $pFlag=='Report_Options'){
			$pColumn['Option']=$this->sBoolean1;
		}
		return $pColumn;
	}
	public function DefUiButton($pFlag,$Exception){
		parent::DefUiButton($pFlag,array('NormalChildLink'));
		if ($pFlag=='NormalChildLink' && !in_array($pFlag,$Exception)) { ?>
<li id="ListTabChild_0" class="TabChildNormal"><a href="<?php echo ($this->sysPage); ?>?ActionType=Report&Report=<?php echo ($this->sMainID); ?>,0" class="Link1 FGreen1">编辑本调查或试题</a></li>
<li id="ListTabChild_0" class="TabChildNormal"><a href="<?php echo ($this->sysPage); ?>" class="Link1 FGreen1">更多<?php echo ($this->sMetaTitle); ?></a></li>


<?php }
	}
}
//-- ------ #Instanct ------ --
$tmpDefault=new PaDefault();
$tmpDefault->OnPage();
$tmpControls=new CustomControls();
$tmpControlPage=new CustomControlPage();
$tmpComHead->sMenuid=$tmpDefault->sMenuid;
$tmpDefault->sysMetaTitle=$tmpDefault->sMetaTitle.' - '.$tmpDefault->sysFileConfig['sysTitle'];
//-- ------ #Template ------ --
if ($tmpDefault->sActionType=='Report' || $tmpDefault->sActionType=='DReport_Options') {
	require($tmpDefault->sysFileConfig['sysCoreRoot_Real'].$tmpDefault->sysManaTemplatePath.'Component/Head_0.php');
	require($tmpDefault->sysFileConfig['sysCoreRoot_Real'].$tmpDefault->sysManaTemplatePath.'Cms/cmsvotegroup_reportOptions.php');
	require($tmpDefault->sysFileConfig['sysCoreRoot_Real'].$tmpDefault->sysManaTemplatePath.'Component/End_0.php');
}else {
	require($tmpDefault->sysFileConfig['sysCoreRoot'].$tmpDefault->sysQPlatformTemplatePath.'Component/Group_0.php');
} ?>