<?php
class netssystable extends netsDb {
	private $sysErrorClassID='0000';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	
	public function netssystable($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='sttName';
		if(strlen($pTableDescriptAR[0]['Columns'][$tmpSTR]['Value'])<1 && !in_array($tmpSTR,$pExceptionAR2)){
			$this->sysLastError='提交内容错误:1.名称不能为空';
			return $this->sysErrorFuncID.'001';
		}
		
		return 0;
	}
	
	public function getTableFromFunction($pFunctionid,$pTableid){
		$tmpSQL=' SELECT
A.sttTableName,A.sttColumnHead,B.stctUiName
FROM '.$this->sysTableHead.'netssystable AS A INNER JOIN '.$this->sysTableHead.'netssystablecont AS B ON B.stctIndexID=A.sttID
WHERE 1=1 AND A.sttRecycle=0 AND A.sttChecked>1 AND 
((A.sttFunctionid='.$pFunctionid.' AND (A.sttType=1 OR A.sttType=2)) OR
(A.sttID='.$pTableid.' AND A.sttType=3))
ORDER BY A.sttType,A.sttOrderBy DESC,A.sttID DESC ';
		return $this->Search($tmpSQL);
	}
	public function getTableoption($pFunctionid){
		$tmpSQL=' SELECT
A.sttID,A.sttName
FROM '.$this->sysTableHead.'netssystable AS A
WHERE 1=1 AND A.sttRecycle=0 AND A.sttChecked>1 AND
A.sttFunctionid='.$pFunctionid.' AND A.sttType=3
ORDER BY A.sttType,A.sttOrderBy DESC,A.sttID DESC ';
		$tmpData0=$this->Search($tmpSQL);
		//Define option
		$tmpAR0=array();
		$tmpAR0[]=array('ID'=>0,
			'Name'=>'[未选择模型]',
			'Index'=>0,
			'Parid'=>0,
			'Text'=>'[未选择模型]',
			'Value'=>-1,
			'Style'=>'color:#AAAAAA;background-color:#FAFAFA;',
			'Title'=>'[未选择模型]',
			'AddOne'=>'');
		//Set other option
		$Coun0=0;
		foreach ($tmpData0 as $Row0){
			$tmpAR0[]=array('ID'=>$Row0['sttID'],
				'Name'=>$Row0['sttName'],
				'Index'=>$Coun0+1,
				'Parid'=>0,
				'Text'=>$Row0['sttName'],
				'Value'=>$Row0['sttID'],
				'Style'=>'',
				'Title'=>$Row0['sttName'],
				'AddOne'=>'');
			$Coun0++;
		}
		return $tmpAR0;
	}
	public function getAllColumn($pTables){
		$tmpSTR='';
		//-- #From db --
		$tmpSQL=' SELECT
A.stcotID,A.stcotName,B.stcoctUiName,
A.stcotType,A.stcotOrderBy,B.stcoctUiType,
B.stcoctUiRecognise,B.stcoctUiLabelid,B.stcoctDefaultValue,B.stcoctUiOptionAR,
B.stcoctUiIntroduct,B.stcoctUiLen,B.stcoctUiEnable,
B.stcoctDbIsKey,B.stcoctModifyAble,
C.sttFunctionid,C.sttType,C.sttTableName,C.sttColumnHead
FROM (('.$this->sysTableHead.'netssystablecolumn AS A
INNER JOIN '.$this->sysTableHead.'netssystablecolumncont AS B ON B.stcoctIndexID=A.stcotID)
INNER JOIN '.$this->sysTableHead.'netssystable AS C ON C.sttID=A.stcotParid)
WHERE 1=1 AND ({Nets.TableName}1=2)
ORDER BY A.stcotOrderBy DESC,A.stcotID DESC ';
		foreach ($pTables as $Cell){
			$tmpSTR.=' C.sttTableName LIKE \''.$Cell['sttTableName'].'\' OR ';
		}
		$tmpSQL=str_replace('{Nets.TableName}',$tmpSTR,$tmpSQL);
		return $this->Search($tmpSQL);
	}
	public function filterColumnByFlag($pColumns,$pFlag){
		$tmpAR0=array();
		
		foreach ($pColumns as $Column){
			if($Column['stcoctUiRecognise']==$pFlag){
				array_push($tmpAR0,$Column);
			}
		}
		
		return $tmpAR0;
	}
	public function filterColumnByType($pColumns,$pTypes){
		$tmpAR0=array();
		$tmpTypeAR=explode($this->sysSPLIT1,$pTypes);
		
		$Coun0=0;
		foreach ($pColumns as $Column){
			if(in_array($Column['stcotType'],$tmpTypeAR)){
				if(!isset($Column['Value'])){
					$Column['Value']=$Column['stcoctDefaultValue'];
				}
				$tmpAR1=array('Index','ShowValue','NameExtend','LineStyle','Option','ControlStyle','Parameter',);
				foreach ($tmpAR1 as $Cell){
					if(!isset($Column[$Cell])){
						$Column[$Cell]='';
					}
				}
				array_push($tmpAR0,$Column);
			}
		}

		return $tmpAR0;
	}
	public function filterColumnByLabelid($pColumns,$pTypes,$pLabelid){
		$tmpAR0=array();
		$tmpTypeAR=explode($this->sysSPLIT1,$pTypes);
		$tmpLabelidAR=explode($this->sysSPLIT1,$pLabelid);
		
		foreach ($pColumns as $Column){
			if(in_array($Column['stcotType'],$tmpTypeAR) &&
				in_array($Column['stcoctUiLabelid'],$tmpLabelidAR)){
				if(!isset($Column['Value'])){
					$Column['Value']=$Column['stcoctDefaultValue'];
				}
				$tmpAR1=array('Index','ShowValue','NameExtend','Option','ControlStyle','Parameter',);
				foreach ($tmpAR1 as $Cell){
					if(!isset($Column[$Cell])){
						$Column[$Cell]='';
					}
				}
				array_push($tmpAR0,$Column);
			}
		}

		return $tmpAR0;
	}
}
?>