<?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,');
		$this->sApp=new cmsdoc($this->sConnString);
		$this->sTemplatePath='Cms/docDetail_Normal.php';
		//-- ------ #ActionType ------ --
		if($this->sActionType=='DEvaluation'){
			$this->OnEvaluation();
		}
	}
	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);
		//-- ------ #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']=$this->sysFileConfig['CheckCmsDocDiscuss'];
		if ($tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateBy']['Value']==0) {
			$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateBy']['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 OnEvaluation(){
		$tmpAR0=$this->AnalyerRequest('ID',0,0);
		$tmpID=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('DEvaluation',-1,0);
		$tmpEvaluation=$tmpAR0[0];
		
		$tmpINT=$this->sApp->onEvaluation($tmpID,$tmpEvaluation,$this->sysFileConfig['CmsDocEvaluationSetting']);
		if($tmpINT!=0){
			$this->sJscript=$this->Message('ERROR','',$this->sApp->sysLastError,'');
			return 1;
		}
		
		$this->sJscript=$this->Message('SUCCESS','','打分成功，谢谢您的打分。','');
		return 0;
	}
	public function OnList(){
		$tmpAR0=$this->AnalyerRequest('ID',1,0);
		$this->sMainID=$tmpAR0[0];
		//-- ------ #Initial ------ --
		$tmpINT=$this->sApp->initialObject($this->sMainID);
		//-- ------ #Datas ------ --
		$tmpSQL=' SELECT A.cdtID,A.cdtName,A.cdtParid,A.cdtCreateTime,
			B.cdctTemplateid_Detail,B.cdctCount_Views,B.cdctEvaluation,B.cdctContent,B.cdctSmallContent,B.cdctFrom,B.cdctAuthor,B.cdctCount_Reply,B.cdctPageAble,B.cdctTemplateid_Detail,
			C.cdgtID,D.cdgctTemplateid_Detail
			FROM '.$this->sysTableHead.'cmsdoc AS A 
			INNER JOIN '.$this->sysTableHead.'cmsdoccont AS B ON B.cdctIndexID=A.cdtID
			INNER JOIN '.$this->sysTableHead.'cmsdocgroup AS C ON C.cdgtID=A.cdtParid
			INNER JOIN '.$this->sysTableHead.'cmsdocgroupcont AS D ON D.cdgctIndexID=C.cdgtID
			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
			//#Other
			$tmpSQL=' SELECT A.cdtID,A.cdtName,A.cdtCreateTime
				FROM '.$this->sysTableHead.'cmsdoc AS A 
				WHERE 1=1 AND A.cdtRecycle=0 AND A.cdtChecked>1
				ORDER BY A.cdtOrderBy DESC,A.cdtID DESC LIMIT 0,8 ';
			$tmpSTR=$tmpSQL;
			$this->sOtherData=$this->sDb->Search($tmpSTR);
			return 1;
		}
		$this->sMainID=$this->sDetailData[0]['cdtID'];
		$this->sMetaTitle=$this->sDetailData[0]['cdtName'];
		
		if($this->sDetailData[0]['cdctPageAble']==1){
			$tmpCListSTR0='DCList0';
			$tmpCListAR0=$this->AnalyerRequest($tmpCListSTR0,'1,0',0);
			$this->sCPButton=new netsConPButton();
			$this->sCPButton->sPage=$this->sysPage;
			$this->sCPButton->sExtendParameter='&ID='.$this->sMainID;
			$this->sCPButton->setPage($tmpCListAR0,$this->sDetailData[0]['cdctContent']);
			$this->sDetailData[0]['cdctContent']=$this->sCPButton->getContent();
		}else {
			$this->sDetailData[0]['cdctContent']=str_replace($this->sysSPLIT12,'',$this->sDetailData[0]['cdctContent']);
		}
		//-- ------ #Template ------ --
		//#List
		$tmpSQL=' SELECT A.stemtID,A.stemtName,B.stemctPath 
			FROM '.$this->sysTableHead.'netssystemplate AS A
			INNER JOIN '.$this->sysTableHead.'netssystemplatecont AS B ON B.stemctIndexID=A.stemtID
			WHERE 1=1 AND A.stemtRecycle=0 AND A.stemtChecked>1 AND A.stemtID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['cdgctTemplateid_Detail'],$tmpSQL);
		$tmpData0=$this->sDb->Search($tmpSTR);
		if(count($tmpData0)!=0){
			$this->sTemplatePath=$tmpData0[0]['stemctPath'];
		}
		//#Detail
		$tmpSQL=' SELECT A.stemtID,A.stemtName,B.stemctPath 
			FROM '.$this->sysTableHead.'netssystemplate AS A
			INNER JOIN '.$this->sysTableHead.'netssystemplatecont AS B ON B.stemctIndexID=A.stemtID
			WHERE 1=1 AND A.stemtRecycle=0 AND A.stemtChecked>1 AND A.stemtID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['cdctTemplateid_Detail'],$tmpSQL);
		$tmpData0=$this->sDb->Search($tmpSTR);
		if(count($tmpData0)!=0){
			$this->sTemplatePath=$tmpData0[0]['stemctPath'];
		}
		//-- ------ #Evaluation ------ --
		$tmpAR0=explode($this->sysSPLIT4,$this->sysFileConfig['CmsDocEvaluationSetting']);
		$tmpAR1=explode($this->sysSPLIT1,$this->sDetailData[0]['cdctEvaluation']);
		if(count($tmpAR0)!=count($tmpAR1)){
			$tmpAR1=array();
			foreach($tmpAR0 as $Row0){
				$tmpAR1[]='0';
			}
		}
		$Coun0=0;
		foreach ($tmpAR1 as $Cell){
			if($Coun0==0){
				$this->sDetailData[0]['cdctEvaluation']=$Cell;
			}else {
				$this->sDetailData[0]['cdctEvaluation'].=$this->sysSPLIT1.$Cell;
			}
			$Coun0++;
		}
		//-- ------ #Navigation ------ --
		$this->sNavigation=$this->sDb->getParent($this->sDetailData[0]['cdtParid'],$this->sysTableHead.'cmsdocgroup','cdgt');
		//-- ------ #Other ------ --
		//Next
		$tmpSQL=' SELECT A.cdtID,A.cdtName,A.cdtCreateTime
			FROM '.$this->sysTableHead.'cmsdoc AS A 
			WHERE 1=1 AND A.cdtRecycle=0 AND A.cdtChecked>1 AND cdtID>{Nets.ID} AND A.cdtParid={Nets.Parid}
			ORDER BY A.cdtOrderBy DESC,A.cdtID DESC LIMIT 0,1 ';
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['cdtID'],$tmpSQL);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sDetailData[0]['cdtParid'],$tmpSTR);
		$this->sNextData=$this->sDb->Search($tmpSTR);
		//Previous
		$tmpSQL=' SELECT A.cdtID,A.cdtName,A.cdtCreateTime
			FROM '.$this->sysTableHead.'cmsdoc AS A 
			WHERE 1=1 AND A.cdtRecycle=0 AND A.cdtChecked>1 AND cdtID<{Nets.ID} AND A.cdtParid={Nets.Parid}
			ORDER BY A.cdtOrderBy DESC,A.cdtID DESC LIMIT 0,1 ';
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['cdtID'],$tmpSQL);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sDetailData[0]['cdtParid'],$tmpSTR);
		$this->sPreviousData=$this->sDb->Search($tmpSTR);
		//Other
		$tmpSQL=' SELECT A.cdtID,A.cdtName,A.cdtCreateTime
			FROM '.$this->sysTableHead.'cmsdoc AS A 
			WHERE 1=1 AND A.cdtRecycle=0 AND A.cdtChecked>1 AND A.cdtParid={Nets.Parid}
			ORDER BY A.cdtOrderBy DESC,A.cdtID DESC LIMIT 0,8 ';
		$tmpSTR=str_replace('{Nets.Parid}',$this->sDetailData[0]['cdtParid'],$tmpSQL);
		$this->sOtherData=$this->sDb->Search($tmpSTR);
		//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 LIMIT 0,9 ';
		$tmpSTR=str_replace('{Nets.ID}',$this->sMainID,$tmpSQL);
		$this->sDiscussData=$this->sDb->Search($tmpSTR);
		//-- ------ #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){}
}
?>