<?php
class netssysmenu extends netsDb {
	private $sysErrorClassID='0000';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	
	public function netssysmenu($pConnection){
		$this->netsDb($pConnection);
	}
	public function Check(&$pTableDescriptAR,$pExceptionAR1,$pExceptionAR2){
		$this->sysErrorFuncID=$this->sysErrorClassID.'02';

		if(count($pExceptionAR1)==0){
			$pExceptionAR1=array();
		}
		parent::Check($pTableDescriptAR,$pExceptionAR1,$pExceptionAR2);
		//
		$tmpSTR='smetName';
		if(strlen($pTableDescriptAR[0]['Columns'][$tmpSTR]['Value'])<1 && !in_array($tmpSTR,$pExceptionAR2)){
			$this->sysLastError='提交内容错误:1.名称不能为空';
			return $this->sysErrorFuncID.'001';
		}
		
		return 0;
	}
	
	public function getChildMenu($pParid,$pType,$pFlag,$pOrderBy,$pUserTypeid,$pExtendFlags){
		$tmpMenuData0=array();
		//-- ------ ### ------ --
		if ($this->sysFileConfig['DbMenu_'.$pFlag]==0){
			//-- #File --
			require($this->sysFileConfig['PathRoot'].$this->sysFileConfig['MenuConfigPath'].'Config_'.$pFlag.'.php');
			$tmpMenuData0=array();
			$Coun0=0;
			foreach ($tmpMenuConfig as $Row0){
				if ($Row0['smetParid']==$pParid && strpos($Row0['smetPower_UserType'],$pUserTypeid.$this->sysSPLIT1)===false) {
					$tmpMenuData0[$Coun0]=$Row0;
					$Coun0++;
				}
			}
			
		}else {
			//-- #Db and cache --
			$tmpCacheFlag='Menu/Menu_'.$pUserTypeid.'_'.$pParid;
			$tmpAR_Cache=array();
			if($this->sysFileConfig['CacheDbAble']==1){
				$tmpAR_Cache=$this->readCache($tmpCacheFlag);
			}
			if(count($tmpAR_Cache)==0){
				$tmpSQL=' SELECT A.smetID,A.smetName,A.smetNameStyle,A.smetNumCode,A.smetParid,
					A.smetType,A.smetLink,A.smetTarget,A.smetIntroduct,
					B.smectSourceR00
					FROM {Nets.TableHead}netssysmenu AS A
					LEFT OUTER JOIN {Nets.TableHead}netssysmenucont AS B ON B.smectIndexID=A.smetID
					WHERE 1=1 AND A.smetRecycle=0 AND A.smetChecked>1 AND
					A.smetParid={Nets.Parid} AND A.smetType={Nets.Type} AND A.smetPower_UserType NOT LIKE \'{Nets.UType},%\' AND A.smetPower_UserType NOT LIKE \'%,{Nets.UType},%\' {Nets.PowerSTR}
					ORDER BY A.smetOrderBy DESC,A.smetID{Nets.OrderBy} DESC ';
				$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
				$tmpSTR=str_replace('{Nets.Parid}',$pParid,$tmpSTR);
				$tmpSTR=str_replace('{Nets.Type}',$pType,$tmpSTR);
				$tmpSTR=str_replace('{Nets.OrderBy}',$pOrderBy,$tmpSTR);
				$tmpSTR_0='';
				$tmpAR0=explode($this->sysSPLIT1,$pExtendFlags);
				foreach ($tmpAR0 as $Row0){
					if ($Row0!='') {
						$tmpSTR_0.=' AND A.smetPower_Flag != \''.$Row0.'\' ';
					}
				}
				$tmpSTR=str_replace('{Nets.PowerSTR}',$tmpSTR_0,$tmpSTR);
	
				$tmpMenuData0=$this->Search($tmpSTR);
				if($this->sysFileConfig['CacheDbAble']==1){
					$this->writeCache($tmpCacheFlag,$tmpMenuData0);
				}
			}else {
				$tmpMenuData0=$tmpAR_Cache;
			}
		}
		
		return $tmpMenuData0;
	}
	public function getParMenu($pID,$pUserTypeid,$pFlag){
		$tmpMenuData0=array();
		//-- ------ ### ------ --
		if ($this->sysFileConfig['DbMenu_'.$pFlag]==0){
			//-- #File --
			require($this->sysFileConfig['PathRoot'].$this->sysFileConfig['MenuConfigPath'].'Config_'.$pFlag.'.php');
			foreach ($tmpMenuConfig as $Row0){
				if ($Row0['smetID']==$pID) {
					$tmpMenuData0=array();
					$tmpMenuData0[0]=$Row0;
				}
			}
			
		}else {
			//-- #Db and cache --
			if($this->sysFileConfig['CacheDbAble']==1){
				/*
				$tmpCacheFlag='Menu/Menu_'.$pUserTypeid.'_'.$pID;
				$tmpData0=$this->readCache($tmpCacheFlag);
				if (count($tmpData0)>0) {
					$tmpCacheFlag='Menu/Menu_'.$pUserTypeid.'_'.$tmpData0[0]['smetParid'];
					$tmpData1=$this->readCache($tmpCacheFlag);
					foreach ($tmpData1 as $Row1){
						if ($Row1['smetID']==$tmpData0[0]['smetParid']) {
							$tmpMenuData0=array();
							$tmpMenuData0[0]=$Row0;
						}
					}
				}
				*/
			}
			if(count($tmpMenuData0)==0){
				$tmpSQL=' SELECT A.smetID,A.smetName,A.smetNameStyle,A.smetNumCode,A.smetParid,
					A.smetType,A.smetLink,A.smetTarget,A.smetIntroduct,
					B.smectSourceR00
					FROM '.$this->sysTableHead.'netssysmenu AS A
					LEFT OUTER JOIN '.$this->sysTableHead.'netssysmenucont AS B ON B.smectIndexID=A.smetID
					WHERE 1=1 AND A.smetRecycle=0 AND A.smetChecked>1 AND A.smetID={Nets.ID}
					ORDER BY A.smetOrderBy DESC,A.smetID DESC LIMIT 0,1 ';
				$tmpSQL=str_replace('{Nets.ID}',$pID,$tmpSQL);
				$tmpMenuData0=$this->Search($tmpSQL);
			}
		}
		
		return $tmpMenuData0;
	}
	public function getMenuid($pID,$pLink,$pFlag){
		$tmpMenuData0=array();
		$tmpFlag=0;
		//-- ------ ### ------ --
		if ($this->sysFileConfig['DbMenu_'.$pFlag]==0){
			//-- #File --
			require($this->sysFileConfig['PathRoot'].$this->sysFileConfig['MenuConfigPath'].'Config_'.$pFlag.'.php');
			$tmpAR0=array_reverse($tmpMenuConfig);
			$Coun0=0;
			$tmpFlag=0;
			while (count($tmpAR0)>$Coun0){
				if ($tmpAR0[$Coun0]['smetLink']==$pLink && $tmpFlag==0) {
					$tmpMenuData0=array();
					$tmpMenuData0[0]=$tmpAR0[$Coun0];
					$tmpFlag=1;
				}
				$Coun0++;
			}
			
		}else {
			//-- #Db and cache --
			$tmpSQL=' SELECT A.smetID,A.smetName,A.smetLink,A.smetIntroduct
				FROM '.$this->sysTableHead.'netssysmenu AS A 
				WHERE 1=1 AND A.smetRecycle=0 AND A.smetChecked>1 AND A.smetLink LIKE \'{Nets.LINK}\'
				ORDER BY A.smetID DESC LIMIT 0,1 ';
			$tmpSTR=str_replace('{Nets.LINK}',$pLink,$tmpSQL);
			$tmpMenuData0=$this->Search($tmpSTR);
		}
		
		return $tmpMenuData0;
	}
	
}
?>