<?php
class netssysconfiginfo extends netsDb {
	private $sysErrorClassID='0000';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	
	public function netssysconfiginfo($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='scitName';
		if(strlen($pTableDescriptAR[0]['Columns'][$tmpSTR]['Value'])<1 && !in_array($tmpSTR,$pExceptionAR2)){
			$this->sysLastError='提交内容错误:1.名称不能为空';
			return $this->sysErrorFuncID.'001';
		}
		
		return 0;
	}
	
	public function getFileConfig($pConfigParid,&$pUiDescription_Normal,&$pDbDescription){
		$tmpSQL=' SELECT A.scgtID,A.scgtName
			FROM '.$this->sysTableHead.'netssysconfiggroup AS A 
			WHERE 1=1 AND A.scgtChecked>1 AND A.scgtParid='.$pConfigParid.' 
			ORDER BY A.scgtOrderBy DESC,A.scgtID DESC ';
		$tmpDataCollection0=$this->Search($tmpSQL);
		$Coun0=0;
		foreach ($tmpDataCollection0 as $Row0){
			//Config ui
			$tmpAR0=$this->sysUiDescriptionModel;
			$tmpAR0['stcotName']=$Row0['scgtName'];
			$tmpAR0['stcoctUiName']=$Row0['scgtName'];
			$tmpAR0['stcotType']=4;
			$pUiDescription_Normal[]=$tmpAR0;
			//Get child
			$tmpSQL=' SELECT A.scitID,A.scitName,A.scitSign,A.scitUiType,A.scitUiLen,A.scitEnable,
				A.scitDefaultValue,A.scitUserValue,A.scitOptionAR,A.scitIntroduct
				FROM '.$this->sysTableHead.'netssysconfiginfo AS A
				WHERE 1=1 AND A.scitChecked>1 AND A.scitParid='.$Row0['scgtID'].' 
				ORDER BY A.scitOrderBy DESC,A.scitID DESC ';
			$tmpDataCollection1=$this->Search($tmpSQL);
			$Coun1=0;
			foreach ($tmpDataCollection1 as $Row1) {
				//Config ui
				$tmpAR0=$this->sysUiDescriptionModel;
				$tmpAR0['stcotName']=$Row1['scitSign'];
				$tmpAR0['stcoctUiName']=$Row1['scitName'];
				$tmpAR0['stcotType']=1;
				$tmpAR0['stcoctUiLabelid']=$Coun0;
				$tmpAR0['stcoctUiType']=$Row1['scitUiType'];
				$tmpAR0['stcoctUiLen']=$Row1['scitUiLen'];
				$tmpAR0['stcoctUiEnable']=$Row1['scitEnable'];
				$tmpAR0['Value']=$Row1['scitUserValue'];
				$tmpAR0['stcoctUiOptionAR']=$Row1['scitOptionAR'];
				$tmpAR0['stcoctUiIntroduct']=$Row1['scitIntroduct'];
				$pUiDescription_Normal[]=$tmpAR0;
				//Config db
				$tmpAR0=$this->sysDbDescriptionModel['Columns'];
				$tmpAR0['stcotName']=$Row1['scitSign'];
				$tmpAR0['stcoctUiName']=$Row1['scitName'];
				$tmpAR0['stcoctDbType']=$Row1['scitUiType'];
				$tmpAR0['stcoctDbLen']=180;
				$tmpAR0['stcoctDbIsKey']=0;
				$tmpAR0['stcoctUiType']=$Row1['scitUiType'];
				$tmpAR0['stcoctDefaultValue']=$Row1['scitDefaultValue'];
				$tmpAR0['Value']=$Row1['scitUserValue'];
				$pDbDescription['Columns'][$Row1['scitSign']]=$tmpAR0;
				$Coun1++;
			}
			$Coun0++;
		}
		return 0;
	}
	public function getUnitConfig(){}
	public function getDepartmentConfig(){}
	public function getUserConfig(){}
	public function getFileConfigControl($pConfigParid){
		$tmpSQL=' SELECT 
			A.scgtID,A.scgtName
			FROM '.$this->sysTableHead.'netssysconfiggroup AS A 
			WHERE 1=1 AND A.scgtChecked>1 AND A.scgtParid='.$pConfigParid.' 
			ORDER BY A.scgtOrderBy DESC,A.scgtID DESC ';
		$tmpDataCollection0=$this->Search($tmpSQL);
		$tmpSQL=' SELECT 
			A.scitID,A.scitName,A.scitSign,A.scitUiType,A.scitUiLen,A.scitEnable,
			A.scitDefaultValue,A.scitUserValue,A.scitOptionAR,A.scitIntroduct
			FROM '.$this->sysTableHead.'netssysconfiginfo AS A
			WHERE 1=1 AND A.scitChecked>1 AND (1=2 {Nets.Parid})
			ORDER BY A.scitOrderBy DESC,A.scitID DESC ';
		$tmpSTR='';
		foreach ($tmpDataCollection0 as $Row0){
			$tmpSTR.=' OR A.scitParid='.$Row0['scgtID'].' ';
		}
		$tmpSQL=str_replace('{Nets.Parid}',$tmpSTR,$tmpSQL);
		$tmpDataCollection0=$this->Search($tmpSQL);
		
		$Coun0=0;
		$tmpDbDescription=array();
		foreach ($tmpDataCollection0 as $Row0) {
			//Config db
			$tmpAR0=$this->sysDbDescriptionModel['Columns'];
			$tmpAR0['stcotName']=$Row0['scitSign'];
			$tmpAR0['stcoctUiName']=$Row0['scitName'];
			$tmpAR0['stcoctDbType']=$Row0['scitUiType'];
			$tmpAR0['stcoctDbLen']=180;
			$tmpAR0['stcoctDbIsKey']=0;
			$tmpAR0['stcoctUiType']=$Row0['scitUiType'];
			$tmpAR0['stcoctDefaultValue']=$Row0['scitDefaultValue'];
			$tmpAR0['Value']=$Row0['scitUserValue'];
			$tmpDbDescription['Columns'][$Row0['scitSign']]=$tmpAR0;
			$Coun0++;
		}
		return $tmpDbDescription;
	}
	public function setUnitConfig(){}
	public function setDepartmentConfig(){}
	public function setUserConfig(){}
	public function saveToFile($pFilepath,$pFilepathCore){
		//Get all config
		$tmpSQL=' SELECT 
			A.scitID,A.scitName,A.scitSign,A.scitUiType,A.scitUiLen,A.scitEnable,
			A.scitDefaultValue,A.scitUserValue,A.scitOptionAR,A.scitIntroduct
			FROM '.$this->sysTableHead.'netssysconfiginfo AS A
			WHERE 1=1 AND A.scitChecked>1 AND A.scitParid<>0 AND A.scitParid<>1
			ORDER BY A.scitID ';
		$tmpDataCollection0=$this->Search($tmpSQL);
		//Save to file
		if($pFilepath==$pFilepathCore){
			$tmpSTR='<?php $netsFileConfig=array(); ';
		}else {
			$tmpSTR='<?php ';
		}
		foreach ($tmpDataCollection0 as $Row0){
			$tmpSTR.='
//'.$Row0['scitName'].'
$netsFileConfig[\''.$Row0['scitSign'].'\']=\''.$Row0['scitUserValue'].'\'; ';
		}
		$tmpSTR.=' ?>';
		$this->writeFile($pFilepath,$tmpSTR);
		return 0;
	}
	public function saveToFile_Regular($pFilepath){
		//Get all config
		$tmpSQL=' SELECT 
			A.scitID,A.scitName,A.scitSign,A.scitUiType,A.scitUiLen,A.scitEnable,
			A.scitDefaultValue,A.scitUserValue,A.scitOptionAR,A.scitIntroduct
			FROM '.$this->sysTableHead.'netssysconfiginfo AS A
			WHERE 1=1 AND A.scitChecked>1 AND A.scitParid<>0 AND A.scitParid<>1 AND (1=2 {Nets.Sign})
			ORDER BY A.scitID ';
		$tmpSTR_0='';
		$tmpAR0=explode($this->sysSPLIT1,$this->sysFileConfig['RegularSysconfigFlag']);
		foreach ($tmpAR0 as $Row0){
			$tmpSTR_0.=' OR A.scitSign LIKE \''.$Row0.'\'';
		}
		$tmpSTR=str_replace('{Nets.Sign}',$tmpSTR_0,$tmpSQL);
		$tmpDataCollection0=$this->Search($tmpSTR);
		//Save to file
		$tmpSTR='<?php ';
		foreach ($tmpDataCollection0 as $Row0){
			$tmpSTR.='
//'.$Row0['scitName'].'
$netsFileConfig[\''.$Row0['scitSign'].'\']=\''.$Row0['scitUserValue'].'\'; ';
		}
		$tmpSTR.=' ?>';
		$this->writeFile($pFilepath,$tmpSTR);
		return 0;
	}
	
	
}
?>