<?php
class cmslink extends netsDb {
	private $sysErrorClassID='0000';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	
	public function cmslink($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='cltName';
		if(strlen($pTableDescriptAR[0]['Columns'][$tmpSTR]['Value'])<1 && !in_array($tmpSTR,$pExceptionAR2)){
			$this->sysLastError='提交内容错误:1.名称不能为空';
			return $this->sysErrorFuncID.'001';
		}
		return 0;
	}
	
	public function initialObject($pID){
		$this->sysErrorFuncID=$this->sysErrorClassID.'02';
		$tmpCode=new netsCode();
		$tmpHtml=new netsHtml();
		$this->TransStart();
		//-- ------ #Check cookie exist ------ --
		//Get cookie
		$tmpCookieName=$this->sysCookieHead.'Cookie_CmsDoc_'.$pID;
		$tmpAR0=$tmpHtml->AnalyerRequest($tmpCookieName,'',2);
		//-- ------ #Update data ------ --
		//-- #Update Reply --
		$tmpSQL=' UPDATE '.$this->sysTableHead.'cmsdoccont SET cdctReply=(SELECT COUNT(cddtID) FROM cmsdocdiscuss AS A WHERE 1=1 AND A.cddtRecycle=0 AND A.cddtChecked>1 AND A.cddtID={Nets.ID}) WHERE 1=1 AND cdctID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.ID}',$pID,$tmpSQL);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->sysLastError='更新文档数据时出错，请稍后再试。';
			$this->TransRollback();
			return $tmpINT;
		}
		//-- #Update Hit --
		if($tmpAR0[0]==''){
			$tmpSQL=' UPDATE '.$this->sysTableHead.'cmsdoc SET cdtHit=cdtHit+1 WHERE 1=1 AND cdtID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.ID}',$pID,$tmpSQL);
			$tmpINT=$this->Execute($tmpSTR);
			if($tmpINT!=0){
				$this->sysLastError='更新文档数据时出错，请稍后再试。';
				$this->TransRollback();
				return $tmpINT;
			}
			$this->writeCookie($this->sysNormalCookiePath,$tmpCookieName,1);
		}
		
		$this->TransCommit();
		return 0;
	}
	
	public function makeSitemap($pKeyword){
		$tmpID=0;
		//-- ------ # ------ --
		$tmpSQL=' SELECT 
			A.citID,A.citName
			FROM '.$this->sysTableHead.'cmsintroduct AS A 
			WHERE 1=1 AND A.citName LIKE \'{Nets.Name}\' LIMIT 0,1 ';
		$tmpSTR=str_replace('{Nets.Name}',$pKeyword,$tmpSQL);
		$tmpData0=$this->Search($tmpSTR);
		if(count($tmpData0)==0){
			return 1;
		}
		$tmpID=$tmpData0[0]['citID'];
		//-- ------ #Analyse sitemap config ------ --
		$tmpSTR=$this->sysFileConfig['SitemapTemplate'];
		$tmpOpen_Introduct=0;
		$tmpStart_IntroductgroupID=1;
		$tmpLevel_Introductgroup=0;
		$tmpStart_DocgroupID=1;
		$tmpLevel_Docgroup=0;
		$tmpContainDoc_DocgroupID=array();
		$tmpSitemapTemplate=array();
		
		$tmpAR0=explode($this->sysSPLIT7,$this->sysFileConfig['SitemapTemplate']);
		if(count($tmpAR0)!=2){
			return 2;
		}
		$tmpAR1=explode($this->sysSPLIT4,$tmpAR0[0]);
		if(count($tmpAR1)!=7){
			return 2;
		}
		$tmpSitemapTemplate=explode($this->sysSPLIT4,$tmpAR0[1]);
		if(count($tmpSitemapTemplate)!=5){
			return 2;
		}
		$tmpAR0=explode($this->sysSPLIT1,$tmpAR1[0]);
		if(count($tmpAR0)!=2) return 2;
		$tmpOpen_Introduct=$tmpAR0[1];
		
		$tmpAR0=explode($this->sysSPLIT1,$tmpAR1[1]);
		if(count($tmpAR0)!=2) return 2;
		$tmpStart_IntroductgroupID=$tmpAR0[1];
		
		$tmpAR0=explode($this->sysSPLIT1,$tmpAR1[2]);
		if(count($tmpAR0)!=2) return 2;
		$tmpLevel_Introductgroup=$tmpAR0[1];
		
		$tmpAR0=explode($this->sysSPLIT1,$tmpAR1[3]);
		if(count($tmpAR0)!=2) return 2;
		$tmpStart_DocgroupID=$tmpAR0[1];
		
		$tmpAR0=explode($this->sysSPLIT1,$tmpAR1[4]);
		if(count($tmpAR0)!=2) return 2;
		$tmpLevel_Docgroup=$tmpAR0[1];
		
		$tmpAR0=explode($this->sysSPLIT1,$tmpAR1[5]);
		if(count($tmpAR0)<1) return 2;
		$Coun0=0;
		foreach ($tmpAR0 as $Cell){
			if($Coun0>0){
				$tmpContainDoc_DocgroupID[]=$tmpAR0[$Coun0];
			}
			$Coun0++;
		}
		
		$tmpContent=$tmpSitemapTemplate[0];
		if($tmpOpen_Introduct==1){
			$tmpSQL=' SELECT
				A.cigtID,A.cigtName
				FROM '.$this->sysTableHead.'cmsintroductgroup AS A
				WHERE 1=1 AND A.cigtRecycle=0 AND A.cigtChecked>1 AND A.cigtParid={Nets.Parid}
				ORDER BY A.cigtOrderBy DESC,A.cigtID DESC ';
			$tmpSTR=str_replace('{Nets.Parid}',$tmpStart_IntroductgroupID,$tmpSQL);
			$tmpData0=$this->Search($tmpSTR);
			foreach ($tmpData0 as $Row0){
				$tmpSTR=str_replace('<Nets.IntroductgroupName>',$Row0['cigtName'],$tmpSitemapTemplate[1]);
				$tmpContent.=$tmpSTR;
				
				$tmpSQL=' SELECT
					A.citID,A.citName
					FROM '.$this->sysTableHead.'cmsintroduct AS A
					WHERE 1=1 AND A.citRecycle=0 AND A.citChecked>1 AND A.citParid={Nets.Parid}
					ORDER BY A.citOrderBy DESC,A.citID DESC ';
				$tmpSTR=str_replace('{Nets.Parid}',$Row0['cigtID'],$tmpSQL);
				$tmpData0=$this->Search($tmpSTR);
				foreach ($tmpData0 as $Row0){
					$tmpSTR=str_replace('<Nets.IntroductID>',$Row0['citID'],$tmpSitemapTemplate[2]);
					$tmpSTR=str_replace('<Nets.IntroductName>',$Row0['citName'],$tmpSTR);
					$tmpContent.=$tmpSTR;
				}
				$tmpContent.=$this->sysSPLIT8.$this->sysSPLIT8;
			}
		}
		
		$tmpSQL=' SELECT
			A.cdgtID,A.cdgtName
			FROM '.$this->sysTableHead.'cmsdocgroup AS A
			WHERE 1=1 AND A.cdgtRecycle=0 AND A.cdgtChecked>1 AND A.cdgtParid={Nets.Parid}
			ORDER BY A.cdgtOrderBy DESC,A.cdgtID DESC ';
		$tmpSTR=str_replace('{Nets.Parid}',$tmpStart_DocgroupID,$tmpSQL);
		$tmpData0=$this->Search($tmpSTR);
		foreach ($tmpData0 as $Row0){
			$tmpSTR=str_replace('<Nets.docgroupID>',$Row0['cdgtID'],$tmpSitemapTemplate[3]);
			$tmpSTR=str_replace('<Nets.docgroupName>',$Row0['cdgtName'],$tmpSTR);
			$tmpContent.=$tmpSTR;
			
			$tmpSTR=str_replace('{Nets.Parid}',$Row0['cdgtID'],$tmpSQL);
			$tmpData0=$this->Search($tmpSTR);
			foreach ($tmpData0 as $Row0){
				$tmpSTR=str_replace('<Nets.docgroupID>',$Row0['cdgtID'],$tmpSitemapTemplate[4]);
				$tmpSTR=str_replace('<Nets.docgroupName>',$Row0['cdgtName'],$tmpSTR);
				$tmpContent.=$tmpSTR;
			}
			$tmpContent.=$this->sysSPLIT8.$this->sysSPLIT8;
		}
		//-- ------ #Update ------ --
		$tmpSQL=' UPDATE '.$this->sysTableHead.'cmsintroductcont SET cictContent=\'{Nets.Content}\' WHERE 1=1 AND cictIndexID={Nets.ID}; ';
		$tmpSTR=str_replace('{Nets.Content}',$tmpContent,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$tmpID,$tmpSTR);
		$this->Execute($tmpSTR);
		return 0;
	}
}
?>