<?php
class cmsadv extends netsDb {
	private $sysErrorClassID='0000';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;

	public function cmsadv($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='catName';
		if(strlen($pTableDescriptAR[0]['Columns'][$tmpSTR]['Value'])<1 && !in_array($tmpSTR,$pExceptionAR2)){
			$this->sysLastError='提交内容错误:1.名称不能为空';
			return $this->sysErrorFuncID.'001';
		}
		
		return 0;
	}
	
	public function saveToFile(){
		//Get data
		$tmpSQL=' SELECT A.catID,A.catName,A.catSign,A.catType,A.catTimeType,A.catEndTime,
			B.cactLink,B.cactWidth,B.cactHeight,B.cactStyle,B.cactEndLink,B.cactContent,B.cactEndContent,B.cactIntroduct
			FROM '.$this->sysTableHead.'cmsadv AS A
			INNER JOIN '.$this->sysTableHead.'cmsadvcont AS B ON B.cactID=A.catID
			WHERE 1=1 AND A.catRecycle=0 AND A.catChecked>1 ';
		$tmpDataCollection0=$this->Search($tmpSQL);
		//Save to file
		$tmpSTR='<?php $sysCmsadvData=array(); ';
		foreach ($tmpDataCollection0 as $Row0){
			$tmpSource=$Row0['cactContent'];
			$tmpLink=$Row0['cactLink'];
			if($Row0['catTimeType']==0 && $Row0['catEndTime']<date($this->sysTimeFormat)){
				$tmpSource=$Row0['cactEndContent'];
				$tmpLink=$Row0['cactEndLink'];
			}
			$tmpContent='';
			if($Row0['catType']==0){
				//Img
				$tmpContent='\'<a href="'.$tmpLink.'" target="_blank"><img alt="'.$Row0['cactIntroduct'].'" title="'.$Row0['cactIntroduct'].' - '.$Row0['catSign'].'" src="'.$tmpSource.'" ';
				if($Row0['cactWidth']!=0 && $Row0['cactHeight']!=0){
					$tmpContent.='style="width:'.$Row0['cactWidth'].'px; height:'.$Row0['cactHeight'].'px;"';
				}
				$tmpContent.=' /></a>\'';
			}else if($Row0['catType']==1){
				//Txt
				$tmpContent='\'<a href="'.$tmpLink.'" target="_blank" title="'.$Row0['cactIntroduct'].' - '.$Row0['catSign'].'" style="'.$Row0['cactStyle'].'">'.$tmpSource.'</a>\'';
			}else if($Row0['catType']==2){
				//Flash
				$tmpContent='\'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" ';
				if($Row0['cactWidth']!=0 && $Row0['cactHeight']!=0){
					$tmpContent.='width="'.$Row0['cactWidth'].'" height="'.$Row0['cactHeight'].'"';
				}
				$tmpContent.=' ><param name="movie" value="'.$tmpSource.'"><param name="quality" value="high"><embed src="'.$tmpSource.'" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" ';
				if($Row0['cactWidth']!=0 && $Row0['cactHeight']!=0){
					$tmpContent.='width="'.$Row0['cactWidth'].'" height="'.$Row0['cactHeight'].'"';
				}
				$tmpContent.='></embed></object>\'';
			}else if($Row0['catType']==3){
				//Array
				$tmpContent='array(\''.$Row0['catName'].'\',\''.$tmpLink.'\',\''.$tmpSource.'\',\''.$Row0['cactIntroduct'].' - '.$Row0['catSign'].'\',)';
			}
			
			$tmpSTR.='
//'.$Row0['catName'].'
$sysCmsadvData[\''.$Row0['catSign'].'\']='.$tmpContent.'; ';
		}
		$tmpSTR.=' ?>';
		$tmpPATH=$this->sysFileConfig['PathRoot'].$this->sysFileConfig['PathAdvCache'].'Cache_0.php';
		$this->writeFile($tmpPATH,$tmpSTR);
		return 0;
	}
}
?>