<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Func/netsSimpleXml.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/shopsale.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/shopsalecont.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Shop/Sale/shopsale.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.'shopsale','sttColumnHead'=>'shst'),
			array('sttTableName'=>$this->sysTableHead.'shopsalecont','sttColumnHead'=>'shsct'),);
		$this->sFunctionid=0;
		$this->sUiName='Platform/shop/sale_sale';
	}
	public function OnBInitial(){
		$this->sMetaTitle='商品';
		$this->sLimitCount=0;
		$this->sApp=new shopsale($this->sConnString);
		//Parid
		$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->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,'shstID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1,,,',0);
		//#Spell sql
		$tmpSQL=' SELECT 
			A.shstID,A.shstName,A.shstParid,A.shstTag,A.shstPrice,A.shstCode
			FROM '.$this->sysTableHead.'shopsale AS A 
			INNER JOIN '.$this->sysTableHead.'shopsalecont AS B ON B.shsctIndexID=A.shstID
			WHERE 1=1 
			AND A.shstID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.shstName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.shstParid='.$this->sSearchData[1].' ';
		}
		if($this->sSearchData[2]!=''){
			$tmpSQL.=' AND A.shstPrice='.$this->sSearchData[2].' ';
		}
		if($this->sSearchData[3]!=''){
			$tmpSQL.=' AND A.shstCode='.$this->sSearchData[3].' ';
		}
		if($this->sSearchData[4]!=''){
			$tmpSQL.=' AND A.shstTag LIKE \'%'.$this->sSearchData[4].'%\' ';
		}
		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'=>'shstID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'shstName','stcoctUiName'=>'商品名');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'shstID,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.shstID,A.shstName
			FROM '.$this->sysTableHead.'shopsale AS A 
			WHERE 1=1 
			AND A.shstID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.shstName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.shstParid='.$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'=>'shstID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'shstName','stcoctUiName'=>'名称');
		
		return 0;
	}
	public function OnNormal(){
		$tmpINT=0;
		$tmpCode=new netsCode();
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'shopsale AS A 
			INNER JOIN '.$this->sysTableHead.'shopsalecont AS B ON B.shsctIndexID=A.shstID ';
		$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.shstID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.shstID='.$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']=='shstTableid'){
						$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_Normal as $Row0){
				if($Row0['stcotName']=='shstTableid'){
					$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
				}
				$Coun0++;
			}
		}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		$tmpSimpleXml=new netsSimpleXml();
		if($pColumn['stcotName']=='shstParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='shstParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
			
		}else if(($pColumn['stcotName']=='shstZoneid' || $pColumn['stcotName']=='shstShoppingid') && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_nets/system/zone.php';
			$pColumn['Parameter']=$tmpParameters;
			
			//shstZoneid
			$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']=='shstUnitid' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/shopunit.php';
			$pColumn['Parameter']=$tmpParameters;
			//shstUnitid
			$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']=='shstBrandid' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/brand.php';
			$pColumn['Parameter']=$tmpParameters;
			//shstBrandid
			$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']=='shstRealshopid' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/realshop.php';
			$pColumn['Parameter']=$tmpParameters;
			//shstRealshopid
			$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']=='shstClassid' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/shopsaleclass.php';
			$pColumn['Parameter']=$tmpParameters;
			//shstUnitid
			$tmpSQL=' SELECT A.shscltID,A.shscltName AS tName
				FROM {Nets.TableHead}shopsaleclass AS A
				WHERE 1=1 AND A.shscltRecycle=0 AND A.shscltChecked>1 AND A.shscltID={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']=='shsctInventorys' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_nets/system/zone.php';
			$tmpParameters['Columns']=array(
				array('ID','编号','Label',100,),
				array('Name','名称','Text',370,),
				array('Count','数量','Text',40,),
				);
			$pColumn['Parameter']=$tmpParameters;
		}else if($pColumn['stcotName']=='shsctRelateds' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/sale.php';
			$pColumn['Parameter']=$tmpParameters;
		}else if($pColumn['stcotName']=='shsctPesents' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/sale.php';
			$pColumn['Parameter']=$tmpParameters;
		}else if($pColumn['stcotName']=='shsctRelated' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/sale.php';
			$pColumn['Parameter']=$tmpParameters;
		}else if($pColumn['stcotName']=='shsctFavourables' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/sale.php';
			$pColumn['Parameter']=$tmpParameters;
		}else if($pColumn['stcotName']=='shsctAccessories' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/sale.php';
			$pColumn['Parameter']=$tmpParameters;
		}else if($pColumn['stcotName']=='shsctAccessoriesP' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/sale.php';
			$tmpParameters['Columns']=array(
				array('ID','编号','Label',100,),
				array('Name','名称','Text',370,),
				array('Count','价格','Text',40,),
				);
			$pColumn['Parameter']=$tmpParameters;
			
		}else if($pColumn['stcotName']=='shsctZones' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_nets/system/zone.php';
			$pColumn['Parameter']=$tmpParameters;
		}else if($pColumn['stcotName']=='shsctShoppings' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_nets/system/zone.php';
			$pColumn['Parameter']=$tmpParameters;
			
			$tmpSimpleXml->loadXml_UiParameter($this->readFile($this->sysFileConfig['sysCoreRoot'].$this->sysFileConfig['sysUiParameterPath'].'Mana/nets/Zone_Parid.php'));
			$pColumn['Parameter']=$tmpSimpleXml->sXmlElement->Parameters[3]->Value;
			
		}else if($pColumn['stcotName']=='shsctBrands' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/brand.php';
			$pColumn['Parameter']=$tmpParameters;
		}else if($pColumn['stcotName']=='shsctRealshops' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/realshop.php';
			$pColumn['Parameter']=$tmpParameters;
		}else if($pColumn['stcotName']=='shsctUnits' && ($pFlag=='Normal' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/shopunit.php';
			$pColumn['Parameter']=$tmpParameters;
			
		}
		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'); ?>