<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Shop/Sale/shopbrand.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.'shopbrand','sttColumnHead'=>'shbt'),
			array('sttTableName'=>$this->sysTableHead.'shopbrandcont','sttColumnHead'=>'shbct'),);
		$this->sUiName='Platform/shop/sale_brand';
	}
	public function OnBInitial(){
		$this->sMetaTitle='品牌';
		$this->sLimitCount=0;
		$this->sApp=new shopbrand($this->sConnString);
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.shbgtID,A.shbgtName,A.shbgtParid 
			FROM '.$this->sysTableHead.'shopbrandgroup AS A
			WHERE 1=1 AND A.shbgtRecycle=0 AND A.shbgtChecked>1 AND A.shbgtParid={Nets.Parid}
			ORDER BY A.shbgtOrderBy DESC,A.shbgtID DESC ';
		$tmpAR0['SQL0']=' SELECT A.shbgtID,A.shbgtName,A.shbgtParid 
			FROM '.$this->sysTableHead.'shopbrandgroup AS A
			WHERE 1=1 AND A.shbgtRecycle=0 AND A.shbgtChecked>1 AND A.shbgtID={Nets.Parid}
			ORDER BY A.shbgtOrderBy DESC,A.shbgtID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='shbgtID';
		$tmpAR0['Text']='shbgtName';
		$tmpAR0['Value']='shbgtID';
		$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);
		//Salegroupid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.shsgtID,A.shsgtName,A.shsgtParid 
			FROM '.$this->sysTableHead.'shopsalegroup AS A
			WHERE 1=1 AND A.shsgtRecycle=0 AND A.shsgtChecked>1 AND A.shsgtParid={Nets.Parid}
			ORDER BY A.shsgtOrderBy DESC,A.shsgtID DESC ';
		$tmpAR0['SQL0']=' SELECT A.shsgtID,A.shsgtName,A.shsgtParid 
			FROM '.$this->sysTableHead.'shopsalegroup AS A
			WHERE 1=1 AND A.shsgtRecycle=0 AND A.shsgtChecked>1 AND A.shsgtID={Nets.Parid}
			ORDER BY A.shsgtOrderBy DESC,A.shsgtID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='shsgtID';
		$tmpAR0['Text']='shsgtName';
		$tmpAR0['Value']='shsgtID';
		$tmpAR0['Type']=0;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='shop/salegroup_all';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sSalegroupid1);
		$this->sSalegroupid2=$this->sSalegroupid1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有分类]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sSalegroupid2,$tmpAR0);

		
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'shbtID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1,-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.shbtID,A.shbtName,A.shbtParid,A.shbtSalegroupid,A.shbtTag
			FROM '.$this->sysTableHead.'shopbrand AS A 
			WHERE 1=1 
			AND A.shbtID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.shbtName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.shbtParid='.$this->sSearchData[1].' ';
		}
		if($this->sSearchData[2]!='-1'){
			$tmpSQL.=' AND A.shbtSalegroupid='.$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->sysSPLIT1.
			$this->sSearchData[1].$this->sysSPLIT1.
			$this->sSearchData[2];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'shbtID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'shbtName','stcoctUiName'=>'品牌名称');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'shbtID,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.shbtID,A.shbtName
			FROM '.$this->sysTableHead.'shopbrand AS A 
			WHERE 1=1 
			AND A.shbtID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.shbtName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.shbtParid='.$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->sysSPLIT1.$this->sExternal_SearchData[1];
		$this->sysPages[0]=$this->sysPage.'?'.$this->sExtendParameter;
		
		$this->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&'.$tmpSTR2.'='.$this->sSearchData[0].$this->sysSPLIT1.$this->sSearchData[1].$this->sExtendParameter;
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'shbtID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'shbtName','stcoctUiName'=>'名称');
		
		return 0;
	}
	public function OnNormal(){
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'shopbrand AS A 
			INNER JOIN '.$this->sysTableHead.'shopbrandcont AS B ON B.shbctIndexID=A.shbtID ';
		$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.shbtID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.shbtID='.$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']=='shbtParid'){
						$tmpSQL=' SELECT A.dptName FROM '.$this->sysTableHead.'downproduct AS A WHERE 1=1 AND A.dptID='.$tmpRow['shbtParid'].' ';
						$tmpDataCollection1=$this->sDb->Search($tmpSQL);
						if(count($tmpDataCollection1)>0){
							$this->sUiDescription_Normal[$Coun0]['ShowValue']=$tmpDataCollection1[0]['dptName'];
						}
					}
				}
				$Coun0++;
			}
		}else {}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='shbtParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='shbtParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
		}else if($pColumn['stcotName']=='shbtSalegroupid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sSalegroupid2;
		}else if($pColumn['stcotName']=='shbtSalegroupid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sSalegroupid1;
			
		}
		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'); ?>