<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Ask/cmsask.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.'cmsask','sttColumnHead'=>'cast'),
			array('sttTableName'=>$this->sysTableHead.'cmsaskcont','sttColumnHead'=>'casct'),);
		$this->sUiName='Platform/cms/cmsask';
	}
	public function OnBInitial(){
		$this->sMetaTitle='问题';
		$this->sLimitCount=0;
		$this->sApp=new cmsask($this->sConnString);
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.casgtID,A.casgtName,A.casgtParid FROM '.$this->sysTableHead.'cmsaskgroup AS A
			WHERE 1=1 AND A.casgtRecycle=0 AND A.casgtChecked>1 AND A.casgtParid={Nets.Parid}
			ORDER BY A.casgtOrderBy DESC,A.casgtID DESC ';
		$tmpAR0['SQL0']=' SELECT A.casgtID,A.casgtName,A.casgtParid FROM '.$this->sysTableHead.'cmsaskgroup AS A
			WHERE 1=1 AND A.casgtRecycle=0 AND A.casgtChecked>1 AND A.casgtID={Nets.Parid}
			ORDER BY A.casgtOrderBy DESC,A.casgtID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='casgtID';
		$tmpAR0['Text']='casgtName';
		$tmpAR0['Value']='casgtID';
		$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);
		//State
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=19;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/options_Cmsask_State';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sState1);
		$this->sState2=$this->sState1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有状态]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sState2,$tmpAR0);
		
		
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'castID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1,-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.castID,A.castName,A.castParid,A.castState
			FROM '.$this->sysTableHead.'cmsask AS A 
			WHERE 1=1 
			AND A.castID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.castName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.castParid='.$this->sSearchData[1].' ';
		}
		if($this->sSearchData[2]!='-1'){
			$tmpSQL.=' AND A.castState='.$this->sSearchData[2].' ';
		}
		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->sysSPLIT1.$this->sSearchData[2];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'castID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'castName','stcoctUiName'=>'问题名称');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'castID,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.castID,A.castName,A.castParid
			FROM '.$this->sysTableHead.'cmsask AS A 
			WHERE 1=1 
			AND A.castID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.castName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.castParid='.$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'=>'castID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'castName','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.castID,A.castName,A.castParid 
				FROM '.$this->sysTableHead.'cmsask AS A
				WHERE 1=1 AND A.castRecycle=0 AND A.castChecked>1 AND 
				A.castParid=(SELECT castParid FROM cmsask WHERE 1=1 AND castRecycle=0 AND castChecked>1 AND castID={Nets.ID})
				ORDER BY A.castOrderBy DESC,A.castID DESC ';
		}else if($this->sExternal_ChildChooseSData[0]==1 || $this->sExternal_ChildChooseSData[0]==3){
			//-- Child grade --
			$tmpSQL=' SELECT A.castID,A.castName,A.castParid 
				FROM '.$this->sysTableHead.'cmsask AS A
				WHERE 1=1 AND A.castRecycle=0 AND A.castChecked>1 AND A.castParid={Nets.ID}
				ORDER BY A.castOrderBy DESC,A.castID 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);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'cmsask AS A 
			INNER JOIN '.$this->sysTableHead.'cmsaskcont AS B ON B.casctIndexID=A.castID ';
		$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.castID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.castID='.$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']=='castParid'){
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='castModelid_Detail'){
						$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
						
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='castCreateBy' ||
						$this->sUiDescription_Normal[$Coun0]['stcotName']=='castTo'){
						//cdtCreateBy
						$tmpSQL=' SELECT A.uitID,A.uitName FROM '.$this->sysTableHead.'netsuserinfo AS A
							WHERE 1=1 AND A.uitRecycle=0 AND A.uitChecked>1 AND A.uitID={Nets.ID} ';
						$tmpSTR=str_replace('{Nets.ID}',$tmpRow[$this->sUiDescription_Normal[$Coun0]['stcotName']],$tmpSQL);
						$tmpData0=$this->sDb->Search($tmpSTR);
						if(count($tmpData0)>0){
							$this->sUiDescription_Normal[$Coun0]['ShowValue']=$tmpData0[0]['uitName'];
						}
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='casctChannelid'){
						//cdctChannelid
						$tmpSQL=' SELECT A.cctID,A.cctName FROM '.$this->sysTableHead.'cmschannel AS A
							WHERE 1=1 AND A.cctRecycle=0 AND A.cctChecked>1 AND (1=2 {Nets.IDS}) ';
						$tmpAR0=explode($this->sysSPLIT1,$tmpRow[$this->sUiDescription_Normal[$Coun0]['stcotName']]);
						$tmpSTR='';
						foreach ($tmpAR0 as $Cell0){
							$tmpSTR.=' OR A.cctID='.$this->sCode->Int32($Cell0,0);
						}
						$tmpSTR=str_replace('{Nets.IDS}',$tmpSTR,$tmpSQL);
						$tmpData0=$this->sDb->Search($tmpSTR);
						$tmpAR0=array();
						foreach ($tmpData0 as $Row0){
							$tmpAR1=$this->sControl->sDpReturnTemplate;
							$tmpAR1['Text']=$Row0['cctName'];
							$tmpAR1['Value']=$Row0['cctID'];
							$tmpAR0[]=$tmpAR1;
						}
						$this->sUiDescription_Normal[$Coun0]['Option']=$tmpAR0;
						
						
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_Normal as $Row0){
				if($Row0['stcotName']=='castTableid'){
					$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
				}
				$Coun0++;
			}
		}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='castParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='castParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
		}else if($pColumn['stcotName']=='castState' && $pFlag=='Search'){
			$pColumn['Option']=$this->sState2;
		}else if($pColumn['stcotName']=='castState' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sState1;
		}else if($pColumn['stcotName']=='casctOpen' && $pFlag=='Search'){
			$pColumn['Option']=$this->sBoolean2;
		}else if($pColumn['stcotName']=='casctOpen' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sBoolean1;
			
		}else if($pColumn['stcotName']=='castCreateBy'){
			$pColumn['Parameter']='chooseSearch;castCreateByTxt;External_Search;'.$this->sysFileConfig['sysCoreRoot'].'Mana/m_nets/user/userUserinfo.php';
		}else if($pColumn['stcotName']=='castTo'){
			$pColumn['Parameter']='chooseSearch;castToTxt;External_Search;'.$this->sysFileConfig['sysCoreRoot'].'Mana/m_nets/user/userUserinfo.php';
		}else if($pColumn['stcotName']=='castCreateTime'){
			$pColumn['Parameter']='chooseDay;castCreateTimeTxt;External_Day;'.$this->sysFileConfig['sysCoreRoot'].'Component/Nets/netsJscript/chooseDay.php?ID=A';
		}else if($pColumn['stcotName']=='castEndtime'){
			$pColumn['Parameter']='chooseDay;castEndtimeTxt;External_Day;'.$this->sysFileConfig['sysCoreRoot'].'Component/Nets/netsJscript/chooseDay.php?ID=A';
		}else if($pColumn['stcotName']=='cdctChannelid'){
			$pColumn['Parameter']='chooseSearch;cdctChannelidTxt;External_Search;'.$this->sysFileConfig['sysCoreRoot'].'Mana/m_cms/other/channel.php';
		}else if($pColumn['stcotName']=='cdctZoneChoose' && $pFlag=='Normal'){
			$tmpSimpleXml->loadXml_UiParameter($this->readFile($this->sysFileConfig['sysCoreRoot'].$this->sysFileConfig['sysUiParameterPath'].'Mana/nets/Zone_Parid.php'));
			$tmpSTR=str_replace($this->sysSPLIT10,'',$tmpSimpleXml->sXmlElement->Parameters[2]->Value);
			$pColumn['Parameter']=$tmpSTR;
			
		}
		return $pColumn;
	}
}
//-- ------ #Instanct ------ --
$tmpDefault=new PaDefault();
$tmpDefault->OnPage();
$tmpControls=new CustomControls();
$tmpControlPage=new CustomControlPage();
$tmpComHead->sMenuid=$tmpDefault->sMenuid;
$tmpDefault->sysMetaTitle=$tmpDefault->sMetaTitle.' - '.$tmpDefault->sysFileConfig['sysTitle'];
//-- ------ #Template ------ --
require($tmpDefault->sysFileConfig['sysCoreRoot'].$tmpDefault->sysQPlatformTemplatePath.'Component/Group_0.php'); ?>