<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Other/cmstopics.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.'cmstopics','sttColumnHead'=>'ctot'),
			array('sttTableName'=>$this->sysTableHead.'cmstopicscont','sttColumnHead'=>'ctoct'),);
		$this->sUiName='Platform/cms/cmstopics';

	}
	public function OnBInitial(){
		$this->sMetaTitle='专题';
		$this->sLimitCount=0;
		$this->sApp=new cmstopics($this->sConnString);
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.ctogtID,A.ctogtName,A.ctogtParid FROM '.$this->sysTableHead.'cmstopicsgroup AS A
			WHERE 1=1 AND A.ctogtRecycle=0 AND A.ctogtChecked>1 AND A.ctogtParid={Nets.Parid}
			ORDER BY A.ctogtOrderBy DESC,A.ctogtID DESC ';
		$tmpAR0['SQL0']=' SELECT A.ctogtID,A.ctogtName,A.ctogtParid FROM '.$this->sysTableHead.'cmstopicsgroup AS A
			WHERE 1=1 AND A.ctogtRecycle=0 AND A.ctogtChecked>1 AND A.ctogtID={Nets.Parid}
			ORDER BY A.ctogtOrderBy DESC,A.ctogtID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='ctogtID';
		$tmpAR0['Text']='ctogtName';
		$tmpAR0['Value']='ctogtID';
		$tmpAR0['Type']=0;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='cms/doc_Group';
		$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);
		
		
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'ctotID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.ctotID,A.ctotName,A.ctotParid
			FROM '.$this->sysTableHead.'cmstopics AS A 
			WHERE 1=1 
			AND A.ctotID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.ctotName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.ctotParid='.$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->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&'.$tmpSTR2.'='.$this->sSearchData[0].$this->sysSPLIT1.$this->sSearchData[1];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'ctotID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'ctotName','stcoctUiName'=>'专题名称');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'ctotID,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.ctotID,A.ctotName,A.ctotParid
			FROM '.$this->sysTableHead.'cmstopics AS A 
			WHERE 1=1 
			AND A.ctotID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.ctotName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.ctotParid='.$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'=>'ctotID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'ctotName','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.ctotID,A.ctotName,A.ctotParid 
				FROM '.$this->sysTableHead.'cmstopics AS A
				WHERE 1=1 AND A.ctotRecycle=0 AND A.ctotChecked>1 AND 
				A.ctotParid=(SELECT ctotParid FROM cmstopics WHERE 1=1 AND ctotRecycle=0 AND ctotChecked>1 AND ctotID={Nets.ID})
				ORDER BY A.ctotOrderBy DESC,A.ctotID DESC ';
		}else if($this->sExternal_ChildChooseSData[0]==1 || $this->sExternal_ChildChooseSData[0]==3){
			//-- Child grade --
			$tmpSQL=' SELECT A.ctotID,A.ctotName,A.ctotParid 
				FROM '.$this->sysTableHead.'cmstopics AS A
				WHERE 1=1 AND A.ctotRecycle=0 AND A.ctotChecked>1 AND A.ctotParid={Nets.ID}
				ORDER BY A.ctotOrderBy DESC,A.ctotID 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.'cmstopics AS A 
			INNER JOIN '.$this->sysTableHead.'cmstopicscont AS B ON B.ctoctIndexID=A.ctotID ';
		$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.ctotID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.ctotID='.$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']=='ctotParid'){
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='ctotModelid_Detail'){
						$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_Normal as $Row0){
				if($Row0['stcotName']=='ctotTableid'){
					$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
				}
				$Coun0++;
			}
		}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='ctotParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='ctotParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
			
		}else if(($pColumn['stcotName']=='ctoctZones' || $pColumn['stcotName']=='ctoctShoppings') && ($pFlag=='Normal' || $pFlag=='List' || $pFlag=='Search')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_nets/system/zone.php';
			$pColumn['Parameter']=$tmpParameters;
			
			//ctoctZones
			$tmpSQL=' SELECT A.sztID,A.sztName AS tName
				FROM {Nets.TableHead}netssyszone AS A
				WHERE 1=1 AND A.sztRecycle=0 AND A.sztChecked>1 AND A.sztID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$this->sCode->Int32($pColumn['Value'],0),$tmpSTR);
			$tmpData0=$this->sDb->Search($tmpSTR);
			if(count($tmpData0)>0){
				$pColumn['ShowValue']=$tmpData0[0]['tName'];
			}
		}else if($pColumn['stcotName']=='ctoctBrands' && ($pFlag=='Normal' || $pFlag=='List' || $pFlag=='Search')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/brand.php';
			$pColumn['Parameter']=$tmpParameters;
			//rertUnitid
			$tmpSQL=' SELECT A.shbtID,A.shbtName AS tName
				FROM {Nets.TableHead}shopbrand AS A
				WHERE 1=1 AND A.shbtRecycle=0 AND A.shbtChecked>1 AND A.shbtID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$this->sCode->Int32($pColumn['Value'],0),$tmpSTR);
			$tmpData0=$this->sDb->Search($tmpSTR);
			if(count($tmpData0)>0){
				$pColumn['ShowValue']=$tmpData0[0]['tName'];
			}
		}else if($pColumn['stcotName']=='ctoctRealshops' && ($pFlag=='Normal' || $pFlag=='List' || $pFlag=='Search')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/realshop.php';
			$pColumn['Parameter']=$tmpParameters;
			//rertUnitid
			$tmpSQL=' SELECT A.shrstID,A.shrstName AS tName
				FROM {Nets.TableHead}shoprealshop AS A
				WHERE 1=1 AND A.shrstRecycle=0 AND A.shrstChecked>1 AND A.shrstID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$this->sCode->Int32($pColumn['Value'],0),$tmpSTR);
			$tmpData0=$this->sDb->Search($tmpSTR);
			if(count($tmpData0)>0){
				$pColumn['ShowValue']=$tmpData0[0]['tName'];
			}
		}else if($pColumn['stcotName']=='ctoctUnits' && ($pFlag=='Normal' || $pFlag=='List' || $pFlag=='Search')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/shopunit.php';
			$pColumn['Parameter']=$tmpParameters;
			//rertUnitid
			$tmpSQL=' SELECT A.shutID,A.shutName AS tName
				FROM {Nets.TableHead}shopunit AS A
				WHERE 1=1 AND A.shutRecycle=0 AND A.shutChecked>1 AND A.shutID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$this->sCode->Int32($pColumn['Value'],0),$tmpSTR);
			$tmpData0=$this->sDb->Search($tmpSTR);
			if(count($tmpData0)>0){
				$pColumn['ShowValue']=$tmpData0[0]['tName'];
			}
		}else if($pColumn['stcotName']=='ctoctCmsdocs' && ($pFlag=='Normal' || $pFlag=='List' || $pFlag=='Search')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_cms/doc/doc.php';
			$pColumn['Parameter']=$tmpParameters;
			//rertUnitid
			$tmpSQL=' SELECT A.cdtID,A.cdtName AS tName
				FROM {Nets.TableHead}cmsdoc AS A
				WHERE 1=1 AND A.cdtRecycle=0 AND A.cdtChecked>1 AND A.cdtID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$this->sCode->Int32($pColumn['Value'],0),$tmpSTR);
			$tmpData0=$this->sDb->Search($tmpSTR);
			if(count($tmpData0)>0){
				$pColumn['ShowValue']=$tmpData0[0]['tName'];
			}
		}else if($pColumn['stcotName']=='ctoctShopsales' && ($pFlag=='Normal' || $pFlag=='List' || $pFlag=='Search')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/sale.php';
			$pColumn['Parameter']=$tmpParameters;
			//rertUnitid
			$tmpSQL=' SELECT A.shstID,A.shstName AS tName
				FROM {Nets.TableHead}shopsale AS A
				WHERE 1=1 AND A.shstRecycle=0 AND A.shstChecked>1 AND A.shstID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$this->sCode->Int32($pColumn['Value'],0),$tmpSTR);
			$tmpData0=$this->sDb->Search($tmpSTR);
			if(count($tmpData0)>0){
				$pColumn['ShowValue']=$tmpData0[0]['tName'];
			}
		}else if($pColumn['stcotName']=='ctoctReqsupplys' && ($pFlag=='Normal' || $pFlag=='List' || $pFlag=='Search')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_require/supply/reqsupply.php';
			$pColumn['Parameter']=$tmpParameters;
			//rertUnitid
			$tmpSQL=' SELECT A.restID,A.restName AS tName
				FROM {Nets.TableHead}reqsupply AS A
				WHERE 1=1 AND A.restRecycle=0 AND A.restChecked>1 AND A.restID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$this->sCode->Int32($pColumn['Value'],0),$tmpSTR);
			$tmpData0=$this->sDb->Search($tmpSTR);
			if(count($tmpData0)>0){
				$pColumn['ShowValue']=$tmpData0[0]['tName'];
			}
			
			
			
			
		}
		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'); ?>