<?php
require($netsFileConfig['sysCoreRoot_Real'].'Cache/DbDescription/netssyschildsiterecord.php');
require($netsFileConfig['sysCoreRoot_Real'].'Cache/DbDescription/netssyschildsiterecordcont.php');
require($netsFileConfig['sysCoreRoot_Real'].'Inc/m_Nets/system/netssyschildsiterecord.php');
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Func/netsSimpleXml.php');

class PaDefault extends CustomPage {
	public $ssetParid=1;
	
	public function PaDefault(){
		$this->ComPage();
	}
	public function OnBInitial(){
		$this->sMetaTitle='子站点记录';
		$this->getUser('1,2,3,4,5,');
		$this->sLimitCount=0;
		
		$this->sApp=new netssyschildsiterecord($this->sConnString);
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'netssyschildsiterecord','sttColumnHead'=>'scsrt'),
			array('sttTableName'=>$this->sysTableHead.'netssyschildsiterecordcont','sttColumnHead'=>'scsrct'),);
		
		//-- ------ #ActionType ------ --
		if($this->sActionType=='DChildsiteAdd'){
			$this->OnChildsiteAdd();
			
		}
		
	}
	public function OnChildsiteAdd(){
		//Type,URL
		$this->sSearchAR0=$this->AnalyerRequest('DChildsiteAdd','0,',0);
		//-- ------ #Search data ------ --
		$tmpDbDescriptions=array();
		foreach ($this->sTable as $tableCell){
			$tmpDbDescriptions[]=$this->sDbDescriptions[$tableCell['sttTableName']];
		}
		$tmpMainid=$this->AnalyerRequest('mainID',0,1);
		$this->sMainID=$tmpMainid[0];
		$tmpMainUserid=$this->AnalyerRequest('mainUserid',0,1);
		$this->sMainUserid=$tmpMainid[0];
		$tmpMainTableid=$this->AnalyerRequest('mainTableid',0,1);
		$this->sMainTableid=$tmpMainid[0];
		//-- ------ #Add ------ --
		$this->sApp->TransStart();
		//#Get numCode
		$tmpSTR=$this->sTable[0]['sttColumnHead'].'NumCode';
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
		$this->sApp->numCode($tmpDbDescriptions[0]);
		//#Set value
		$tmpDbDescription0=$tmpDbDescriptions;
		$Coun0=0;
		foreach ($tmpDbDescription0 as $tableCell){
			foreach ($tableCell['Columns'] as $Column){
				if($Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'ID' &&
					$Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'NumCode' &&
					$Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'CreateBy' &&
					$Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'CreateTime' &&
					$Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'IndexID'){
					$tmpAR0=$this->AnalyerRequest($Column['stcotName'].'Txt',$Column['stcoctDefaultValue'],1);
					$tmpDbDescriptions[$Coun0]['Columns'][$Column['stcotName']]['Value']=$tmpAR0[0];
				}
			}
			$Coun0++;
		}
		//-- #Set conventional --
		if(isset($tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateBy']['Value'])){
			$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateBy']['Value']=$tmpMainUserid[0];
		}
		if(isset($tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateTime'])){
			$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateTime']['Value']=date($this->sysTimeFormat);
		}
		//DB name,Condition,User index,User column name
		$tmpFlag=0;
		foreach ($this->AnonymousUserData as $Row0){
			if (count($tmpDbDescriptions)>1) {
				if(isset($tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]])){
					if ($tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]]['Value']==$Row0[1]) {
						$tmpFlag=1;
					}
				}
			}
			if ($this->sUserInfo[0]['Columns']['uitID']['Value']==0 && $tmpFlag==1) {
				$tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]]['Value']=$Row0[4];
			}else if ($tmpFlag==1 && isset($tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]])) {
				$tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]]['Value']=$this->sUserInfo[$Row0[2]]['Columns'][$Row0[3]]['Value'];
			}
		}
		//Spical value array
		foreach ($this->sSpicalValue as $Cell){
			if(isset($tmpDbDescriptions[$Cell[0]]['Columns'][$Cell[1]]['Value'])){
				$tmpDbDescriptions[$Cell[0]]['Columns'][$Cell[1]]['Value']=$Cell[2];
			}
		}
		//-- #Set spical --
		$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'Name']['Value']=$this->sSearchAR0[1];
		$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'URL']['Value']=$this->sSearchAR0[1];
		
		
		//#Add
		$tmpINT=$this->sApp->Check($tmpDbDescriptions,array(),array());
		if($tmpINT!=0){
			$this->sApp->TransRollback();
			$this->Message=$this->sApp->sysLastError;
			return 1;
		}
		$Coun0=0;
		while (count($tmpDbDescriptions)>$Coun0){
			if($Coun0==0){
				$tmpDbDescriptions[$Coun0]['TableDescription']['SearchColumn']=$this->sTable[$Coun0]['sttColumnHead'].'NumCode,'.$this->sTable[$Coun0]['sttColumnHead'].'ID';
			}else {
				$tmpDbDescriptions[$Coun0]['TableDescription']['SearchColumn']=$this->sTable[$Coun0]['sttColumnHead'].'IndexID';
			}
			$Coun0++;
		}
		$tmpINT=$this->sApp->add($tmpDbDescriptions);
		if($tmpINT!=0){
			$this->sApp->TransRollback();
			$this->Message=$this->sApp->sysLastError;
			return 1;
		}
		
		foreach ($this->sDb->sysDbCacheClear as $Cell){
			$this->clearCache($Cell);
		}
		foreach ($this->sysPageCacheClear as $Cell){
			$this->clearCache($Cell);
		}
		$this->sApp->TransCommit();
		
		$this->sMessage='数据保存成功';
		return 0;
	}
	public function OnList(){
		
		return 0;
	}

}
?>