<?php

class PaDefault extends CustomPage {
	public $ssetParid=2;
	
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnBInitial(){
		$this->sMetaTitle='问答列表';
		$this->getUser('1,2,3,4,5,');
		$this->sTemplatePath='Cms/askList_Normal.php';
		
		//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']='';
		$tmpSTR=$this->sControl->sHeadString;
		$this->sControl->sHeadString='';
		$this->sParid1=$this->sParid2=$this->sControl->bindDropdown($tmpAR0);
		$this->sControl->sHeadString=$tmpSTR;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有分类]';
		$tmpAR0['Value']=2;
		$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);
		//#State for search
		$this->sData_State=array(
			array('Text'=>'全部问题','Value'=>-1,),
			array('Text'=>'待解决','Value'=>0,),
			array('Text'=>'已解决','Value'=>1,),
			array('Text'=>'最佳答案','Value'=>2,),
			array('Text'=>'一周精华','Value'=>3,),
			);
	
	}
	public function OnList(){
		$tmpAR0=$this->AnalyerRequest('ID',2,0);
		$this->sMainID=$tmpAR0[0];
		//-- ------ #Initial ------ --
		
		//-- ------ #This ------ --
		$tmpSQL=' SELECT A.casgtID,A.casgtName,
			B.casgctSourceR00,B.casgctTemplateid_List,B.casgctContent
			FROM {Nets.TableHead}cmsaskgroup AS A 
			INNER JOIN {Nets.TableHead}cmsaskgroupcont AS B ON B.casgctIndexID=A.casgtID
			WHERE 1=1 AND A.casgtRecycle=0 AND A.casgtChecked>1 AND A.casgtID={Nets.ID}
			ORDER BY A.casgtOrderBy DESC,A.casgtID DESC ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sMainID,$tmpSTR);
		$this->sDetailData=$this->sDb->Search($tmpSTR);
		if(count($this->sDetailData)!=1){
			//Error
			//#Other
			$tmpSQL=' SELECT A.casgtID,A.casgtName
				FROM {Nets.TableHead}cmsaskgroup AS A 
				WHERE 1=1 AND A.casgtRecycle=0 AND A.casgtChecked>1
				ORDER BY A.casgtOrderBy DESC,A.casgtID DESC LIMIT 0,8 ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$this->sOtherData=$this->sDb->Search($tmpSTR);
			return 1;
		}
		$this->sMainID=$this->sDetailData[0]['casgtID'];
		$this->sMetaTitle=$this->sDetailData[0]['casgtName'];
		//-- ------ #Template ------ --
		$tmpSQL=' SELECT A.stemtID,A.stemtName,B.stemctPath 
			FROM {Nets.TableHead}netssystemplate AS A
			INNER JOIN {Nets.TableHead}netssystemplatecont AS B ON B.stemctIndexID=A.stemtID
			WHERE 1=1 AND A.stemtRecycle=0 AND A.stemtChecked>1 AND A.stemtID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['casgctTemplateid_List'],$tmpSTR);
		$tmpData0=$this->sDb->Search($tmpSTR);
		if(count($tmpData0)!=0){
			$this->sTemplatePath=$tmpData0[0]['stemctPath'];
		}
		//-- ------ #Navigation ------ --
		$tmpChildidAR0=$this->sDb->getChild($this->sMainID,$this->sysTableHead.'cmsaskgroup','casgt');
		$this->sNavigation=$this->sDb->getParent($this->sMainID,$this->sysTableHead.'cmsaskgroup','casgt');
		//-- ------ #Ask ------ --
		$tmpListSTR0='DList0';
		$tmpListAR0=$this->AnalyerRequest($tmpListSTR0,'1,0,60,0',0);
		$tmpSortSTR0='DSort0';
		$this->sSortAR0=$this->AnalyerRequest($tmpSortSTR0,'castID,2',0);
		$tmpSearchSTR0='DSearch';
		$this->sSearchAR=$this->AnalyerRequest($tmpSearchSTR0,',-1,-1,-1',0);
		//-- #Spell SQL --
		$tmpSQL=' SELECT A.castID,A.castName,A.castParid,A.castCode,A.castState,
			B.casctPublisher_Name,B.casctCount_Views,B.casctCount_Discuss
			FROM {Nets.TableHead}cmsask AS A 
			INNER JOIN {Nets.TableHead}cmsaskcont AS B ON B.casctIndexID=A.castID
			WHERE 1=1 AND A.castRecycle=0 AND A.castChecked>1 AND (1=2 {Nets.Parids}) ';
		if ($this->sSearchAR[0]!='') {
			$tmpSQL.=' AND B.castName LIKE \'%'.$this->sSearchAR[0].'%\' ';
		}
		if ($this->sSearchAR[1]==1) {
			$tmpSQL.=' AND B.castState='.$this->sSearchAR[1].' ';
		}else if ($this->sSearchAR[1]==2) {
			$tmpSQL.=' AND B.castState='.$this->sSearchAR[1].' ';
		}
		if($this->sSortAR0[1]==1){
			$tmpSQL.=' ORDER BY A.castOrderBy DESC,'.$this->sSortAR0[0].' ';
		}else if($this->sSortAR0[1]==2){
			$tmpSQL.=' ORDER BY A.castOrderBy DESC,'.$this->sSortAR0[0].' DESC ';
		}
		$tmpSTR_0='';
		foreach ($tmpChildidAR0 as $Cell){
			$tmpSTR_0.=' OR A.castParid='.$Cell.' ';
		}
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.Parids}',$tmpSTR_0,$tmpSTR);
		$this->sListData=$this->sDb->SearchP($tmpSTR,$tmpListAR0);
		//#Set page button
		$this->sPButton->resetTemlate('../../../Config/m_default/File/pageButton3.htm');
		$this->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&ID='.$this->sMainID.'&DSearch='.$this->sSearchAR[0].$this->sysSPLIT1.
			$this->sSearchAR[1].$this->sysSPLIT1.
			$this->sSearchAR[2].$this->sysSPLIT1.
			$this->sSearchAR[3];
		$this->sPButton->setPage($this->sDb->sysPageInfo);

	}
	public function getSearch($pValue,$pType){
/*
MainID

Keyword
State
Code
ExtendIndex

*/
		$tmpAR0=array(
			$this->sMainID,
			$this->sSearchAR[0],
			$this->sSearchAR[1],
			$this->sSearchAR[2],
			$this->sSearchAR[3],);
		if($pType==0) $tmpAR0[0]=$pValue;
		if($pType==1) $tmpAR0[1]=$pValue;
		if($pType==2) $tmpAR0[2]=$pValue;
		if($pType==3) $tmpAR0[3]=$pValue;
		if($pType==4) $tmpAR0[4]=$pValue;
		
		//#SPICAL
		if ($pType==100) {
			/*
			$tmpAR0[8]=0;
			$tmpAR0[9]=0;
			$tmpAR0[10]=0;
			$tmpAR0[11]=0;
			$tmpAR0[12]=0;
			*/
		}else if ($pType==101) {
		}
		//#SPELL
		$tmpSTR=$this->sysPage.'?ID='.$tmpAR0[0].
			'&DSearch='.$tmpAR0[1].$this->sysSPLIT1.$tmpAR0[2].$this->sysSPLIT1.$tmpAR0[3].$this->sysSPLIT1.$tmpAR0[4];
		return $tmpSTR;
	}
	
}

?>