<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Other/cmslink.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.'cmslink','sttColumnHead'=>'clt'),
			array('sttTableName'=>$this->sysTableHead.'cmslinkcont','sttColumnHead'=>'clct'),);
		$this->sUiName='Platform/cms/other_link';
		
	}
	public function OnBInitial(){
		$this->sMetaTitle='链接';
		$this->sLimitCount=1;
		$this->sApp=new cmslink($this->sConnString);
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.cltID,A.cltName,A.cltParid 
			FROM '.$this->sysTableHead.'cmslink AS A
			WHERE 1=1 AND A.cltRecycle=0 AND A.cltChecked>1 AND A.cltParid={Nets.Parid}
			ORDER BY A.cltOrderBy DESC,A.cltID DESC ';
		$tmpAR0['SQL0']=' SELECT A.cltID,A.cltName,A.cltParid 
			FROM '.$this->sysTableHead.'cmslink AS A
			WHERE 1=1 AND A.cltRecycle=0 AND A.cltChecked>1 AND A.cltID={Nets.Parid}
			ORDER BY A.cltOrderBy DESC,A.cltID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='cltID';
		$tmpAR0['Text']='cltName';
		$tmpAR0['Value']='cltID';
		$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']=85;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/options_LinkTarget';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sType1);
		$this->sType2=$this->sType1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有对象]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sType2,$tmpAR0);
		
		//Target
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=16;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/options_LinkTarget_sys';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sTarget1);
		$this->sTarget2=$this->sTarget1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有对象]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sTarget2,$tmpAR0);
		
		
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'cltID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1,',0);
		//#Spell sql
		$tmpSQL=' SELECT 
			A.cltID,A.cltName,A.cltParid,A.cltURL,A.cltOrderBy
			FROM '.$this->sysTableHead.'cmslink AS A 
			WHERE 1=1 
			AND A.cltID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.cltName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.cltParid='.$this->sSearchData[1].' ';
		}
		if($this->sSearchData[2]!=''){
			$tmpSQL.=' AND A.cltURL LIKE \'%'.$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->sSearchData[1].','.$this->sSearchData[2];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'cltID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'cltName','stcoctUiName'=>'链接标题');
		
		return 0;
	}
	public function OnNormal(){
		$tmpINT=0;
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'cmslink AS A 
			INNER JOIN '.$this->sysTableHead.'cmslinkcont AS B ON B.clctIndexID=A.cltID ';
		$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.cltID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.cltID='.$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']=='cltParid'){
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='cltTableid'){
						$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_Normal as $Row0){
				if($Row0['stcotName']=='cltTableid'){
					$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
				}
				$Coun0++;
			}
		}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='cltParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='cltParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
		
		}else if($pColumn['stcotName']=='cltType' && $pFlag=='Search'){
			$pColumn['Option']=$this->sType2;
		}else if($pColumn['stcotName']=='cltType' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sType1;
		}else if($pColumn['stcotName']=='cltTarget' && $pFlag=='Search'){
			$pColumn['Option']=$this->sTarget2;
		}else if($pColumn['stcotName']=='cltTarget' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sTarget1;
			
		}else if($pColumn['stcotName']=='cltURL' && $pFlag=='List'){
			$pColumn['ControlStyle']='width:240px;';
		}else if($pColumn['stcotName']=='cltOrderBy' && $pFlag=='List'){
			$pColumn['ControlStyle']='width:40px;';
		}
		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'); ?>