<?php
require($netsFileConfig['sysCoreRoot'].'Inc/m_Gsnavigation/gsnavigation/gsnavigationactive.php');

class PaDefault extends CustomPage {
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnBInitial(){
		$this->sMetaTitle='团购首页';
		$this->getUser('1,2,3,4,5,');
		$this->sTemplatePath='Gsnavigation/gsnavigationactiveList_Normal.php';
		//-- #Share link --
		$this->sData_LinkShare=array();
		$tmpCacheFlag='nets/options_LinkShare_Groupsale';
		$tmpAR_Cache=$this->sDb->readCache($tmpCacheFlag);
		if(count($tmpAR_Cache)==0){
			$tmpParid=20;
			$tmpSQL=' SELECT A.cltID,A.cltName,A.cltURL,A.cltTarget,B.clctSourceR00
				FROM {Nets.TableHead}cmslink AS A
				INNER JOIN {Nets.TableHead}cmslinkcont AS B ON B.clctIndexID=A.cltID
				WHERE 1=1 AND A.cltRecycle=0 AND A.cltChecked>1 AND A.cltParid={Nets.Parid}
				ORDER BY A.cltOrderBy DESC,A.cltID DESC ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.Parid}',$tmpParid,$tmpSTR);
			$this->sData_LinkShare=$this->sDb->Search($tmpSTR);
			
			if($this->sysFileConfig['CacheDbAble']==1){
				$this->sDb->writeCache($tmpCacheFlag,$this->sData_LinkShare);
			}
		}else {
			$this->sData_LinkShare=$tmpAR_Cache;
		}
		
		//-- ------ #Option ------ --
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.gsnagtID,A.gsnagtName,A.gsnagtParid FROM '.$this->sysTableHead.'gsnavigationactivegroup AS A
			WHERE 1=1 AND A.gsnagtRecycle=0 AND A.gsnagtChecked>1 AND A.gsnagtParid={Nets.Parid}
			ORDER BY A.gsnagtOrderBy DESC,A.gsnagtID DESC ';
		$tmpAR0['InitialString']=2;
		$tmpAR0['Parid']='gsnagtID';
		$tmpAR0['Text']='gsnagtName';
		$tmpAR0['Value']='gsnagtID';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='Gsnavigation/options_Groupsalenavigation_Activegroup';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sParid1);
		$this->sParid2=$this->sParid1;
		$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']=81;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/options_Groupsale_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);
		
		//Alphabet
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=84;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/options_Alphabet';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sAlphabet1);
		$this->sAlphabet2=$this->sAlphabet1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='所有字母';
		$tmpAR0['Value']='';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sAlphabet2,$tmpAR0);
		
		
	}
	public function OnList(){
		//-- ------ ### ------ --
		$tmpApp=new gsnavigationactive($this->sConnString);
		$tmpApp->setAllState();
		//-- ------ ### ------ --
		$tmpAR0=$this->AnalyerRequest('ID',-1,0);
		$this->sMainID=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('DKeyword','',0);
		$this->sKeyword=$tmpAR0[0];
		$this->sSearchAR=$this->AnalyerRequest('DSearch','-1,,ID',0);
		//-- ------ #This group ------ --
		$tmpSQL=' SELECT A.gsnagtID,A.gsnagtName,B.gsnagctTemplateid_List 
			FROM {Nets.TableHead}gsnavigationactivegroup AS A 
			INNER JOIN {Nets.TableHead}gsnavigationactivegroupcont AS B ON B.gsnagctIndexID=A.gsnagtID
			WHERE 1=1 AND A.gsnagtRecycle=0 AND A.gsnagtChecked>1 AND A.gsnagtID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sMainID,$tmpSTR);
		$tmpData_Group=$this->sDb->Search($tmpSTR);
		if(count($tmpData_Group)==0){
			//Error
			$tmpData_Group=array(array(
				'gsnagtID'=>0,
				'gsnagtName'=>'所有团购',
				'gsnagctTemplateid_List'=>0,
				),);
			//return 1;
		}
		$this->sMetaTitle=$tmpData_Group[0]['gsnagtName'];
		//-- ------ #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}',$tmpData_Group[0]['gsnagctTemplateid_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.'gsnavigationactivegroup','gsnagt');
		$this->sNavigation=$this->sDb->getParent($this->sMainID,$this->sysTableHead.'gsnavigationactivegroup','gsnagt');
		//-- ------ #Datas ------ --
		$tmpListSTR0='DList0';
		$tmpListAR0=$this->AnalyerRequest($tmpListSTR0,'1,0,24,0',0);
		$tmpSortSTR0='DSort0';
		$tmpSortAR0=$this->AnalyerRequest($tmpSortSTR0,'cdtID,2',0);
		//-- #Spell SQL --
		$tmpSQL=' SELECT A.gsnatID,A.gsnatName,A.gsnatParid,A.gsnatState,A.gsnatURL,
			B.gsnactPrice_EndTime,B.gsnactPrice_Origin,B.gsnactPrice_Now,B.gsnactPrice_Sale,B.gsnactCount_Order,B.gsnactSourceR00,
			C.gsnutID,C.gsnutName
			FROM {Nets.TableHead}gsnavigationactive AS A
			INNER JOIN {Nets.TableHead}gsnavigationactivecont AS B ON B.gsnactIndexID=A.gsnatID
			INNER JOIN {Nets.TableHead}gsnavigationunit AS C ON C.gsnutID=A.gsnatUnitid
			WHERE 1=1 AND A.gsnatRecycle=0 AND A.gsnatChecked>1 ';

		if ($this->sKeyword!='') {
			$tmpSQL.=' AND A.gsnatName LIKE \'%'.$this->sKeyword.'%\' ';
		}
		if ($this->sMainID!=-1) {
			$tmpSTR_0='';
			foreach ($tmpChildidAR0 as $Cell){
				$tmpSTR_0.=' OR A.gsnatParid='.$Cell.' ';
			}
			$tmpSQL.=' AND (1=2 '.$tmpSTR_0.') ';
		}
		if ($this->sSearchAR[0]!=-1) {
			$tmpSQL.=' AND A.gsnatState='.$this->sSearchAR[0].' ';
		}
		if ($this->sSearchAR[1]!='') {
			$tmpSQL.=' AND A.gsnatAlphabet LIKE \''.$this->sSearchAR[1].'\' ';
		}
		if ($this->sZoneid!=-1) {
			$tmpSQL.=' AND A.gsnatZoneid='.$this->sZoneid.' ';
		}
		
		if ($this->sSearchAR[2]=='ID') {
			$tmpSQL.=' ORDER BY A.gsnatID DESC ';
		}else if ($this->sSearchAR[2]=='Price_Sale') {
			$tmpSQL.=' ORDER BY B.gsnactPrice_Sale ';
		}else if ($this->sSearchAR[2]=='Price_Now') {
			$tmpSQL.=' ORDER BY B.gsnactPrice_Now ';
		}else if ($this->sSearchAR[2]=='Price_EndTime') {
			$tmpSQL.=' ORDER BY B.gsnactPrice_EndTime DESC ';
		}

		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$this->sListData=$this->sDb->SearchP($tmpSTR,$tmpListAR0);
		$this->sRecordCount=$this->sDb->sysPageInfo[3];
		//#Set page button
		$this->sPButton->resetTemlate('../../../Config/m_default/File/pageButton3.htm');
		$this->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&ID='.$this->sMainID.'&DKeyword='.$this->sKeyword.'&DSearch='.$this->sSearchAR[0].$this->sysSPLIT1.$this->sSearchAR[1].$this->sysSPLIT1.$this->sSearchAR[2];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		
	}
	public function getSearch($pValue,$pType){
/*
Parid
Keyword
State
Alphabet
OrderBy

*/
		$tmpAR0=array(
			$this->sMainID,
			$this->sKeyword,
			$this->sSearchAR[0],
			$this->sSearchAR[1],
			$this->sSearchAR[2],
			);
		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;
			*/
		}else if ($pType==101) {
		}
		//#SPELL
		$tmpSTR=$this->sysPage.'?ID='.$tmpAR0[0].
			'&DKeyword='.$tmpAR0[1].
			'&DSearch='.$tmpAR0[2].$this->sysSPLIT1.$tmpAR0[3].$this->sysSPLIT1.$tmpAR0[4];
		return $tmpSTR;
	}
	
	
}

?>