<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Func/netsSimpleXml.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Other/cmsadv.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.'cmsadv','sttColumnHead'=>'cat'),
			array('sttTableName'=>$this->sysTableHead.'cmsadvcont','sttColumnHead'=>'cact'),);
		$this->sUiName='Platform/cms/other_adv';
	}
	public function OnBInitial(){
		$this->sMetaTitle='广告';
		$this->sLimitCount=0;
		$this->sApp=new cmsadv($this->sConnString);
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.cagtID,A.cagtName,A.cagtParid 
			FROM '.$this->sysTableHead.'cmsadvgroup AS A
			WHERE 1=1 AND A.cagtRecycle=0 AND A.cagtChecked>1 AND A.cagtParid={Nets.Parid}
			ORDER BY A.cagtOrderBy DESC,A.cagtID DESC ';
		$tmpAR0['SQL0']=' SELECT A.cagtID,A.cagtName,A.cagtParid 
			FROM '.$this->sysTableHead.'cmsadvgroup AS A
			WHERE 1=1 AND A.cagtRecycle=0 AND A.cagtChecked>1 AND A.cagtID={Nets.Parid}
			ORDER BY A.cagtOrderBy DESC,A.cagtID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='cagtID';
		$tmpAR0['Text']='cagtName';
		$tmpAR0['Value']='cagtID';
		$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);
		//Type
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=36;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$this->sType1=$this->sType2=$this->sControl->bindDropdown($tmpAR0);
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有类型]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sType2,$tmpAR0);
		//TimeType
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=37;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$this->sTimeType1=$this->sTimeType2=$this->sControl->bindDropdown($tmpAR0);
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有时间类型]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sTimeType2,$tmpAR0);
	}
	public function OnBEvent(){
		if($this->sActionTypeF=='DData_Save'){
			$this->OnData_Save();
		}
	}
	public function OnData_Save(){
		$this->sApp->saveToFile();
		$this->sJscript=$this->Message('SUCCESS','','广告缓存数据生成成功',$this->sysPage);
		return 0;
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'catID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1,,-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.catID,A.catName,A.catParid,A.catSign,A.catType
			FROM '.$this->sysTableHead.'cmsadv AS A 
			WHERE 1=1 
			AND A.catID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.catName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.catParid='.$this->sSearchData[1].' ';
		}
		if($this->sSearchData[2]!=''){
			$tmpSQL.=' AND A.catSign LIKE \'%'.$this->sSearchData[2].'%\' ';
		}
		if($this->sSearchData[3]!='-1'){
			$tmpSQL.=' AND A.catType='.$this->sSearchData[3].' ';
		}
		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->sSearchData[1].','.$this->sSearchData[2].','.$this->sSearchData[3];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'catID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'catName','stcoctUiName'=>'广告名称');
		return 0;
	}
	public function OnNormal(){
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'cmsadv AS A 
			INNER JOIN '.$this->sysTableHead.'cmsadvcont AS B ON B.cactIndexID=A.catID ';
		$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.catID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.catID='.$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']];
				}
				$Coun0++;
			}
		}else {}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		$tmpSimpleXml=new netsSimpleXml();
		
		if($pColumn['stcotName']=='catParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='catParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
		}else if($pColumn['stcotName']=='catType' && $pFlag=='Search'){
			$pColumn['Option']=$this->sType2;
		}else if($pColumn['stcotName']=='catType' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sType1;
		}else if($pColumn['stcotName']=='catTimeType' && $pFlag=='Normal'){
			$pColumn['Option']=$this->sTimeType1;
		}else if($pColumn['stcotName']=='cactZoneChoose' && $pFlag=='Normal'){
			$tmpSimpleXml->loadXml_UiParameter($this->readFile($this->sysFileConfig['sysCoreRoot'].$this->sysFileConfig['sysUiParameterPath'].'Mana/nets/Zone_Parid.php'));
			$pColumn['Parameter']=$tmpSimpleXml->sXmlElement->Parameters[0]->Value;
		}
		return $pColumn;
	}
	public function DefUiButton($pFlag,$Exception){
		parent::DefUiButton($pFlag,array('List',));
		if($pFlag=='List'){ ?>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpControl.onDelete_Multiple();tmpCommon.setActionType('','DDelete_Multiple','',''); tmpCommon.netsSubmit();">批量删除</a></li>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpControl.onModify_Page();tmpCommon.setActionType('','DModify_Page','',''); tmpCommon.netsSubmit();">保存本页修改</a></li>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpCommon.setActionType('','DData_Save','',''); tmpCommon.netsSubmit();">生成广告缓存</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 ------ --
require($tmpDefault->sysFileConfig['sysCoreRoot'].$tmpDefault->sysQPlatformTemplatePath.'Component/Group_0.php'); ?>