<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Nets/System/netssystemplate.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.'netssystemplate','sttColumnHead'=>'stemt'),
			array('sttTableName'=>$this->sysTableHead.'netssystemplatecont','sttColumnHead'=>'stemct'),);
		$this->sUiName='Platform/nets/system_template';
	}
	public function OnBInitial(){
		$this->sMetaTitle='模板';
		$this->sLimitCount=0;
		$this->sApp=new netssystemplate($this->sConnString);
		//Shemeid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.sstID,A.sstName,A.sstParid FROM '.$this->sysTableHead.'netssyssheme AS A
			WHERE 1=1 AND A.sstRecycle=0 AND A.sstChecked>1 AND A.sstParid={Nets.Parid}
			ORDER BY A.sstOrderBy DESC,A.sstID DESC ';
		$tmpAR0['InitialString']=1;
		$tmpAR0['Parid']='sstID';
		$tmpAR0['Text']='sstName';
		$tmpAR0['Value']='sstID';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$this->sShemeid1=$this->sShemeid2=$this->sControl->bindDropdown($tmpAR0);
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有主题]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sShemeid2,$tmpAR0);
		//Functionid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.sftID,A.sftName FROM '.$this->sysTableHead.'netssysfunction AS A
			WHERE 1=1 AND A.sftRecycle=0 AND A.sftChecked>1
			ORDER BY A.sftOrderBy DESC,A.sftID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='sftID';
		$tmpAR0['Text']='sftName';
		$tmpAR0['Value']='sftID';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$this->sFunctionid1=$this->sFunctionid2=$this->sControl->bindDropdown($tmpAR0);
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有模块]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sFunctionid2,$tmpAR0);
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'stemtID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1,-1,',0);
		//#Spell sql
		$tmpSQL=' SELECT 
			A.stemtID,A.stemtName,A.stemtShemeid,A.stemtFunctionid,B.stemctPath
			FROM '.$this->sysTableHead.'netssystemplate AS A INNER JOIN '.$this->sysTableHead.'netssystemplatecont AS B ON B.stemctIndexID=A.stemtID
			WHERE 1=1 
			AND A.stemtID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.stemtName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.stemtShemeid='.$this->sSearchData[1].' ';
		}
		if($this->sSearchData[2]!='-1'){
			$tmpSQL.=' AND A.stemtFunctionid='.$this->sSearchData[2].' ';
		}
		if($this->sSearchData[3]!=''){
			$tmpSQL.=' AND B.stemctPath LIKE \'%'.$this->sSearchData[3].'%\' ';
		}
		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->sSearchData[3];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'stemtID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'stemtName','stcoctUiName'=>'模板名称');
		
		return 0;
	}
	public function OnNormal(){
		$tmpINT=0;
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'netssystemplate AS A 
			INNER JOIN '.$this->sysTableHead.'netssystemplatecont AS B ON B.stemctIndexID=A.stemtID ';
		$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.stemtID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.stemtID='.$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']=='stemtParid'){
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='stemtTableid'){
						$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_Normal as $Row0){
				if($Row0['stcotName']=='stemtTableid'){
					$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
				}
				$Coun0++;
			}
		}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='stemtShemeid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sShemeid2;
		}else if($pColumn['stcotName']=='stemtParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sShemeid1;
		}else if($pColumn['stcotName']=='stemtFunctionid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sFunctionid2;
		}else if($pColumn['stcotName']=='stemtFunctionid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sFunctionid1;
		}
		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'); ?>