<?php
class PaDefault extends CustomPage {
	public $ssetParid=2;
	
	public function PaDefault($pSsetParid,$pSpicalAR,$pTitle){
		$this->ssetParid=$pSsetParid;
		$this->sSpicalValue=$pSpicalAR;
		$this->sMetaTitle=$pTitle;
		$this->CustomPage();
	}
	public function OnPInitial(){
		$this->checkUser('1,2,3,');
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'netssysmenu','sttColumnHead'=>'smet'),
			array('sttTableName'=>$this->sysTableHead.'netssysmenucont','sttColumnHead'=>'smect'),);
		$this->sUiName='Platform/nets/system_menuMana';
	}
	public function OnBInitial(){
		$this->sLimitCount=2;
		$this->sApp=new netssysmenu($this->sConnString);
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.smetID,A.smetName,A.smetParid 
			FROM '.$this->sysTableHead.'netssysmenu AS A
			WHERE 1=1 AND A.smetRecycle=0 AND A.smetChecked>1 AND A.smetParid={Nets.Parid}
			ORDER BY A.smetOrderBy DESC,A.smetID DESC ';
		$tmpAR0['SQL0']=' SELECT A.smetID,A.smetName,A.smetParid 
			FROM '.$this->sysTableHead.'netssysmenu AS A
			WHERE 1=1 AND A.smetRecycle=0 AND A.smetChecked>1 AND A.smetID={Nets.Parid}
			ORDER BY A.smetOrderBy DESC,A.smetID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='smetID';
		$tmpAR0['Text']='smetName';
		$tmpAR0['Value']='smetID';
		$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->sParid1,$tmpAR0);
		//Target
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=16;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$this->sTarget1=$this->sTarget2=$this->sControl->bindDropdown($tmpAR0);
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[ALL]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sTarget2,$tmpAR0);
		
		//-- ------ #ActionType ------ --
		if ($this->sActionType=='DMenuState') {
			$this->OnMenuState();
		}
		
		
	}
	public function OnBEvent(){
		if($this->sActionTypeF=='DData_Update'){
			$this->OnData_Update();
		}
	}
	public function OnData_Update(){
		$this->sApp->clearAllCache('Menu/');
		$this->sJscript=$this->Message('SUCCESS','','菜单缓存更新成功',$this->sysPage);
		return 0;
	}
	public function OnMenuState(){
		$tmpAR0=$this->AnalyerRequest('DMenuState',0,0);
		$this->writeCookie($this->sysNormalCookiePath,$this->sysCookieHead.'Systemmenustate',$tmpAR0[0]);
		
		return 0;
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'smetID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1,',0);
		//#Spell sql
		$tmpSQL=' SELECT 
			A.smetID,A.smetName,A.smetParid,A.smetOrderBy,A.smetLink
			FROM '.$this->sysTableHead.'netssysmenu AS A 
			INNER JOIN '.$this->sysTableHead.'netssysmenucont AS B ON B.smectIndexID=A.smetID 
			WHERE 1=1 
			AND A.smetType='.$this->sSpicalValue[0][2].' 
			AND A.smetID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.smetName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.smetParid='.$this->sSearchData[1].' ';
		}
		if($this->sSearchData[2]!=''){
			$tmpSQL.=' AND A.smetLink LIKE \'%'.$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->sSearchData[1].','.$this->sSearchData[2];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'smetID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'smetName','stcoctUiName'=>'菜单名称');
		
		return 0;
	}
	public function OnNormal(){
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'netssysmenu AS A 
			INNER JOIN '.$this->sysTableHead.'netssysmenucont AS B ON B.smectIndexID=A.smetID ';
		$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.smetID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.smetID='.$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']];
				}
				$Coun0++;
			}
		}else {}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		if($pColumn['stcotName']=='Quick'){
			$pColumn['Style']='width:50px;';
		}else if($pColumn['stcotName']=='smetChecked'){
			$pColumn['Option']=$this->sChecked1;
		}else if($pColumn['stcotName']=='smetParid'){
			$pColumn['Option']=$this->sParid1;
		}else if($pColumn['stcotName']=='smetTarget'){
			$pColumn['Option']=$this->sTarget1;
		}else if($pColumn['stcotName']=='smetLink' && $pFlag=='List'){
			$pColumn['ControlStyle']=' width:240px; ';
		}else if($pColumn['stcotName']=='smetOrderBy' && $pFlag=='List'){
			$pColumn['ControlStyle']=' width:40px; ';
		}
		return $pColumn;
	}
	public function DefUiButton($pFlag,$Exception){
		parent::DefUiButton($pFlag,array('List',));
		if($pFlag=='List'){ ?>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpControl.onDelete_Multiple();tmpCommon.setActionType('','DDelete_Multiple','',''); tmpCommon.netsSubmit();">批量删除</a></li>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpControl.onNormal_MultipleByTxt('','','');">批量修改所选（文本）</a></li>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpControl.onModify_Page();tmpCommon.setActionType('','DModify_Page','',''); tmpCommon.netsSubmit();">保存本页修改</a></li>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpCommon.setActionType('','DData_Update','',''); tmpCommon.netsSubmit();">清理菜单缓存</a></li>
<?php
		}
	}
}
?>