<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Nets/User/netsusergrade.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.'netsusergrade','sttColumnHead'=>'ugrat'),
			array('sttTableName'=>$this->sysTableHead.'netsusergradecont','sttColumnHead'=>'ugract'),);
		$this->sUiName='Platform/nets/user_usergrade';
	}
	public function OnBInitial(){
		$this->sMetaTitle='用户等级';
		$this->sLimitCount=1;
		$this->sApp=new netsusergrade($this->sConnString);
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT 
			A.ugratID,A.ugratName,A.ugratParid 
			FROM '.$this->sysTableHead.'netsusergrade AS A
			WHERE 1=1 AND A.ugratRecycle=0 AND A.ugratChecked>1 AND A.ugratParid={Nets.Parid}
			ORDER BY A.ugratOrderBy DESC,A.ugratID DESC ';
		$tmpAR0['SQL0']=' SELECT 
			A.ugratID,A.ugratName,A.ugratParid 
			FROM '.$this->sysTableHead.'netsusergrade AS A
			WHERE 1=1 AND A.ugratRecycle=0 AND A.ugratChecked>1 AND A.ugratID={Nets.Parid}
			ORDER BY A.ugratOrderBy DESC,A.ugratID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='ugratID';
		$tmpAR0['Text']='ugratName';
		$tmpAR0['Value']='ugratID';
		$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);
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'ugratID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1,-1',0);
		//#Spell sql
		$tmpSQL=' SELECT 
			A.ugratID,A.ugratName,A.ugratParid,A.ugratType
			FROM '.$this->sysTableHead.'netsusergrade AS A 
			WHERE 1=1 
			AND A.ugratID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.ugratName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.ugratParid='.$this->sSearchData[1].' ';
		}
		if($this->sSearchData[2]!='-1'){
			$tmpSQL.=' AND A.ugratType='.$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'=>'ugratID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'ugratName','stcoctUiName'=>'用户等级名称');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'ugratID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',,-1',0);
		$tmpSTR3='External_Search';
		$this->sExternal_SearchData=$this->AnalyerRequest($tmpSTR3,',0',0);
		//#Spell sql
		$tmpSQL=' SELECT A.ugratID,A.ugratName,A.ugratParid
			FROM '.$this->sysTableHead.'netsusergrade AS A 
			WHERE 1=1 
			AND A.ugratID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.ugratName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.ugratParid='.$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='.$tmpSTR3.'&'.$tmpSTR3.'='.$this->sExternal_SearchData[0].','.$this->sExternal_SearchData[1];
		
		$this->sPAjaxButton->sPage=$this->sysPage;
		$this->sPAjaxButton->sFlag='External_Search';
		$this->sPAjaxButton->sPanel='chooseContent';
		$this->sPAjaxButton->sExtendParameter='&'.$tmpSTR2.'='.$this->sSearchData[0].$this->sExtendParameter;
		$this->sPAjaxButton->setPage($this->sDb->sysPageInfo);
		$this->sPAjaxButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'ugratID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'ugratName','stcoctUiName'=>'用户等级名称');
		
		return 0;
	}
	public function OnNormal(){
		$tmpINT=0;
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'netsusergrade AS A 
			INNER JOIN '.$this->sysTableHead.'netsusergradecont AS B ON B.ugractIndexID=A.ugratID ';
		$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.ugratID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.ugratID='.$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']=='ugratParid'){
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='ugratTableid'){
						$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_Normal as $Row0){
				if($Row0['stcotName']=='ugratTableid'){
					$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
				}
				$Coun0++;
			}
		}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='ugratParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='ugratParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
		}
		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'); ?>