<?php
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/cmsdocdiscuss.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/cmsdocdiscusscont.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Doc/cmsdoc.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Doc/cmsdocdiscuss.php');

class PaDefault extends CustomPage {
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnBInitial(){
		$this->sMetaTitle='文档评论';
		$this->getUser('1,2,3,4,5,');
	}
	public function OnAdd(){
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'cmsdocdiscuss','sttColumnHead'=>'cddt'),
			array('sttTableName'=>$this->sysTableHead.'cmsdocdiscusscont','sttColumnHead'=>'cddct'),);
		$tmpDbDescriptions=array();
		foreach ($this->sTable as $tableCell){
			$tmpDbDescriptions[]=$this->sDbDescriptions[$tableCell['sttTableName']];
		}
		$tmpApp=new cmsdocdiscuss($this->sConnString);
		//-- ------ #Check login ------ --
		if(!isset($this->sUserInfo[0]['Columns']['uitID']['Value'])){
			$this->sJscript=$this->Message('SUCCESS','','对不起，只有登陆后才能评论。',$this->sysFileConfig['businessLoginAddress']);
			return 1;
		}
		if($this->sUserInfo[0]['Columns']['uitID']['Value']==0){
			$this->sJscript=$this->Message('SUCCESS','','对不起，只有登陆后才能评论。',$this->sysFileConfig['businessLoginAddress']);
			return 1;
		}
		//-- ------ #Submit limit check ------ --
		$tmpINT=$this->submitLimitRead($this->sysPage,-1,-1,-1);
		if($tmpINT!=0){
			$this->sJscript=$this->Message('SUCCESS','','对不起，您登陆次数过多，请'.$this->sysFileConfig['SubmitLimitFreeze'].'秒后再尝试登陆。','');
			return 1;
		}
		//-- ------ #CCode ------ --
		$tmpSTR='CCode';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt','',1);
		$tmpCCode=$tmpAR0[0];
		$tmpSTR=$tmpSTR.'Txt_IFrame';
		if(!array_key_exists($tmpSTR,$_SESSION)){
			$this->submitLimitWrite($this->sysPage,-1,-1,-1);
			$this->sJscript=$this->Message('ERROR','提交失败','验证码错误','');
			return 1;
		}
		if($_SESSION[$tmpSTR]=='' || $_SESSION[$tmpSTR]!=$tmpCCode){
			$this->submitLimitWrite($this->sysPage,-1,-1,-1);
			$this->sJscript=$this->Message('ERROR','提交失败','验证码错误','');
			return 1;
		}
		//-- ------ #Add ------ --
		$tmpApp->TransStart();
		//#Get numCode
		$tmpSTR=$this->sTable[0]['sttColumnHead'].'NumCode';
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N'.$this->sysSPLIT11.date('YmdHis');
		$tmpApp->numCode($tmpDbDescriptions[0]);
		//#Set value
		$tmpAR0=$this->AnalyerRequest('mainID','',1);
		$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'Parid']['Value']=$this->sCode->Int32($tmpAR0[0],0);
		$tmpAR0=$this->AnalyerRequest($this->sTable[1]['sttColumnHead'].'ContentTxt','',1);
		$tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].'Content']['Value']=$tmpAR0[0];
		$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateBy']['Value']=$this->sCode->Int32($this->sUserInfo[0]['Columns']['uitID']['Value'],0);
		
		$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'Name']['Value']=$this->sCode->SubString($tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].'Content']['Value'],0,60);
		$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateTime']['Value']=date($this->sysTimeFormat);
		$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'Checked']['Value']=2;
		//#Add
		$tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].'Content']['Value']=$this->sCode->FilterINPUT($tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].'Content']['Value'],3);
		$tmpINT=$tmpApp->Check($tmpDbDescriptions,array(),array());
		if($tmpINT!=0){
			$tmpApp->TransRollback();
			$this->sJscript=$this->Message('ERROR','',$tmpApp->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=$tmpApp->add($tmpDbDescriptions);
		if($tmpINT!=0){
			$tmpApp->TransRollback();
			$this->sJscript=$this->Message('ERROR','',$tmpApp->sysLastError,'');
			return 1;
		}
		
		$tmpApp->TransCommit();
		$this->submitLimitWrite($this->sysPage,-1,-1,-1);
		$this->sJscript=$this->Message('SUCCESS','','评论成功',$this->sysPage.'?ID='.$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'Parid']['Value']);
		return 0;
	}
	public function OnList(){
		$tmpAR0=$this->AnalyerRequest('ID',1,0);
		$this->sMainID=$tmpAR0[0];
		//-- ------ #Doc ------ --
		$tmpSQL=' SELECT 
			A.cdtID,A.cdtName,A.cdtParid,A.cdtCreateTime
			FROM '.$this->sysTableHead.'cmsdoc AS A
			WHERE 1=1 AND A.cdtRecycle=0 AND A.cdtChecked>1 AND A.cdtID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.ID}',$this->sMainID,$tmpSQL);
		$this->sDetailData=$this->sDb->Search($tmpSTR);
		if(count($this->sDetailData)==0){
			//Error
		}
		$this->sMetaTitle='评论'.$this->sDetailData[0]['cdtName'];
		//-- ------ #Navigation ------ --
		$this->sNavigation=$this->sDb->getParent($this->sDetailData[0]['cdtParid'],$this->sysTableHead.'cmsdocgroup','cdgt');
		//-- ------ #Datas ------ --
		$tmpListSTR0='DList0';
		$tmpListAR0=$this->getQueryString($tmpListSTR0);
		$tmpSortSTR0='DSort0';
		$tmpSortAR0=$this->AnalyerRequest($tmpSortSTR0,'cddtID,2',0);
		//Discuss
		$tmpSQL=' SELECT A.cddtID,A.cddtCreateTime,
			B.cddctContent,
			C.uitID,C.uitName
			FROM '.$this->sysTableHead.'cmsdocdiscuss AS A
			INNER JOIN '.$this->sysTableHead.'cmsdocdiscusscont AS B ON B.cddctIndexID=A.cddtID
			LEFT OUTER JOIN '.$this->sysTableHead.'netsuserinfo AS C ON C.uitID=A.cddtCreateBy
			WHERE 1=1 AND A.cddtRecycle=0 AND A.cddtChecked>1 AND A.cddtParid={Nets.ID}
			ORDER BY A.cddtOrderBy DESC,A.cddtID DESC ';
		$tmpSTR=str_replace('{Nets.ID}',$this->sMainID,$tmpSQL);
		$this->sDiscussData=$this->sDb->SearchP($tmpSTR,$tmpListAR0);
		$this->sRecordCount=$this->sDb->sysPageInfo[3];
		//#Set page button
		$this->sPButton->resetTemlate('../../../Config/m_default/File/pageButton3.htm');
		$this->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&ID='.$this->sMainID;
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		//-- ------ #Discuss form ------ --
		$this->sUiDescription_0=array();
		$tmpSTR=$this->sUiDescriptionPath.'Plus/cms/doc_discuss.php';
		if(file_exists($tmpSTR)){
			require($tmpSTR);
			$this->sUiDescription_0=$sysUiDescriptions['doc_discuss'];
			$sysUiDescriptions=array();
		}
	}
	public function DefUiPanel(&$pColumn,$pFlag){}
}
?>