<?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';
		//-- #Share link --
		$this->sData_LinkShare=array();
		$tmpCacheFlag='nets/options_LinkShare_Groupsale';
		$tmpAR_Cache=$this->sDb->readCache($tmpCacheFlag);
		if(count($tmpAR_Cache)==0){
			$tmpParid=20;
			$tmpSQL=' SELECT A.cltID,A.cltName,A.cltURL,A.cltTarget,B.clctSourceR00
				FROM {Nets.TableHead}cmslink AS A
				INNER JOIN {Nets.TableHead}cmslinkcont AS B ON B.clctIndexID=A.cltID
				WHERE 1=1 AND A.cltRecycle=0 AND A.cltChecked>1 AND A.cltParid={Nets.Parid}
				ORDER BY A.cltOrderBy DESC,A.cltID DESC ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.Parid}',$tmpParid,$tmpSTR);
			$this->sData_LinkShare=$this->sDb->Search($tmpSTR);
			
			if($this->sysFileConfig['CacheDbAble']==1){
				$this->sDb->writeCache($tmpCacheFlag,$this->sData_LinkShare);
			}
		}else {
			$this->sData_LinkShare=$tmpAR_Cache;
		}
		
		//-- ------ #ActionType ------ --
		if($this->sActionType=='DEvaluation'){
			$this->OnEvaluation();
			$this->OnList();
		}
		
	}
	public function OnAdd(){
		$tmpApp=new cmsdocdiscuss($this->sConnString);
		$tmpTable=array(
			array('sttTableName'=>$this->sysTableHead.'cmsdocdiscuss','sttColumnHead'=>'cddt'),
			array('sttTableName'=>$this->sysTableHead.'cmsdocdiscusscont','sttColumnHead'=>'cddct'),);
		
		$tmpDbDescriptions=array();
		foreach ($tmpTable 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];
		//-- ------ #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=$tmpTable[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'][$tmpTable[0]['sttColumnHead'].'Parid']['Value']=$this->sCode->Int32($tmpAR0[0],0);
		$tmpAR0=$this->AnalyerRequest($tmpTable[1]['sttColumnHead'].'ContentTxt','',1);
		$tmpDbDescriptions[1]['Columns'][$tmpTable[1]['sttColumnHead'].'Content']['Value']=$tmpAR0[0];
		$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateBy']['Value']=$this->sCode->Int32($this->sUserInfo[0]['Columns']['uitID']['Value'],0);
		
		//-- #Set conventional --
		if(isset($tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateBy']['Value'])){
			$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateBy']['Value']=$tmpMainUserid[0];
		}
		if(isset($tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateTime'])){
			$tmpDbDescriptions[0]['Columns'][$tmpTable[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'][$tmpTable[1]['sttColumnHead'].$Row0[0]])){
					$tmpFlag=1;
				}
			}
			if ($this->sUserInfo[0]['Columns']['uitID']['Value']==0 && $tmpFlag==1) {
				$tmpDbDescriptions[1]['Columns'][$tmpTable[1]['sttColumnHead'].$Row0[0]]['Value']=$Row0[4];
			}else if ($tmpFlag==1) {
				$tmpDbDescriptions[1]['Columns'][$tmpTable[1]['sttColumnHead'].$Row0[0]]['Value']=$this->sUserInfo[$Row0[2]]['Columns'][$Row0[3]]['Value'];
			}
		}
		//Spical value array
		foreach ($this->sSpicalValue as $Cell){
			if(isset($tmpDbDescription[$Cell[0]]['Columns'][$Cell[1]]['Value'])){
				$tmpDbDescription[$Cell[0]]['Columns'][$Cell[1]]['Value']=$Cell[2];
			}
		}
		//-- #Set spical --
		$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'Name']['Value']=$this->sCode->SubString($tmpDbDescriptions[1]['Columns'][$tmpTable[1]['sttColumnHead'].'Content']['Value'],0,60);
		$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateTime']['Value']=date($this->sysTimeFormat);
		$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'Checked']['Value']=$this->sysFileConfig['CheckCmsDocDiscuss'];
		if ($tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateBy']['Value']==0) {
			$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateBy']['Value']=2;
		}
		//#Add
		$tmpDbDescriptions[1]['Columns'][$tmpTable[1]['sttColumnHead'].'Content']['Value']=$this->sCode->FilterINPUT($tmpDbDescriptions[1]['Columns'][$tmpTable[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']=$tmpTable[$Coun0]['sttColumnHead'].'NumCode,'.$tmpTable[$Coun0]['sttColumnHead'].'ID';
			}else {
				$tmpDbDescriptions[$Coun0]['TableDescription']['SearchColumn']=$tmpTable[$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='.$this->sMainID);
		/*
		$this->sJscript=$this->Message_Frame('A,0',
			$this->sysFileConfig['sysCoreRoot'].$this->sysFileConfig['PathManaFrameMessage'],
			$this->sCode->URL_MakeParameter('添加成功',0),
			$this->sCode->URL_MakeParameter($this->sApp->sysLastError,0),
			$this->sCode->URL_MakeParameter($this->sysFileConfig['sysCoreRoot'].'Mana/m_cms/doc/doc.php',0));
		*/
		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.cdctSources,B.cdctSmallContent,
			B.cdctFrom,B.cdctAuthor,B.cdctCount_Discuss,B.cdctPageAble,B.cdctTemplateid_Detail
			FROM {Nets.TableHead}cmsdoc AS A 
			INNER JOIN {Nets.TableHead}cmsdoccont AS B ON B.cdctIndexID=A.cdtID
			WHERE 1=1 AND A.cdtRecycle=0 AND A.cdtChecked>1 AND A.cdtID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sMainID,$tmpSTR);
		$this->sDetailData=$this->sDb->Search($tmpSTR);
		if(count($this->sDetailData)==0){
			//#Error
			//#Other
			$tmpSQL=' SELECT A.cdtID,A.cdtName,A.cdtParid,A.cdtCreateTime
				FROM {Nets.TableHead}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=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$this->sOtherData=$this->sDb->Search($tmpSTR);
			return 1;
		}
		$this->sMainID=$this->sDetailData[0]['cdtID'];
		$this->sMetaTitle=$this->sDetailData[0]['cdtName'];
		$this->sParid=$this->sDetailData[0]['cdtParid'];
		
		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']);
		}
		//-- ------ #Group ------ --
		$tmpSQL=' SELECT A.cdgtID,A.cdgtName,B.cdgctTemplateid_Detail
			FROM {Nets.TableHead}cmsdocgroup AS A
			INNER JOIN {Nets.TableHead}cmsdocgroupcont AS B ON B.cdgctIndexID=A.cdgtID
			WHERE 1=1 AND A.cdgtRecycle=0 AND A.cdgtChecked>1 AND A.cdgtID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sParid,$tmpSTR);
		$this->sData_Group=$this->sDb->Search($tmpSTR);
		if(count($this->sData_Group)==0){
			//#Non group
			//#Other
			$this->sData_Group[0]=array(
				'cdgctTemplateid_Detail'=>0
				);
		}
		//-- ------ #Template ------ --
		//#List
		$tmpSQL=' SELECT A.stemtID,A.stemtName,B.stemctPath 
			FROM {Nets.TableHead}netssystemplate AS A
			INNER JOIN {Nets.TableHead}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.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sData_Group[0]['cdgctTemplateid_Detail'],$tmpSTR);
		$tmpData0=$this->sDb->Search($tmpSTR);
		if(count($tmpData0)!=0){
			$this->sTemplatePath=$tmpData0[0]['stemctPath'];
		}
		//#Detail
		$tmpSQL=' SELECT A.stemtID,A.stemtName,B.stemctPath 
			FROM {Nets.TableHead}netssystemplate AS A
			INNER JOIN {Nets.TableHead}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.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['cdctTemplateid_Detail'],$tmpSTR);
		$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,B.cdctSourceR00
			FROM {Nets.TableHead}cmsdoc AS A 
			INNER JOIN {Nets.TableHead}cmsdoccont AS B ON B.cdctIndexID=A.cdtID
			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.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['cdtID'],$tmpSTR);
		$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,B.cdctSourceR00
			FROM {Nets.TableHead}cmsdoc AS A 
			INNER JOIN {Nets.TableHead}cmsdoccont AS B ON B.cdctIndexID=A.cdtID
			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.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['cdtID'],$tmpSTR);
		$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,B.cdctSourceR00
			FROM {Nets.TableHead}cmsdoc AS A 
			INNER JOIN {Nets.TableHead}cmsdoccont AS B ON B.cdctIndexID=A.cdtID
			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,4 ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sDetailData[0]['cdtParid'],$tmpSTR);
		$this->sOtherData=$this->sDb->Search($tmpSTR);
		//-- ------ #Discuss ------ --
		$tmpListSTR0='DList0';
		$tmpListAR0=$this->getQueryString($tmpListSTR0);
		$tmpSortSTR0='DSort0';
		$tmpSortAR0=$this->AnalyerRequest($tmpSortSTR0,'cddtID,2',0);
		//Data
		$tmpSQL=' SELECT A.cddtID,A.cddtCreateTime,B.cddctPublisher_Name,B.cddctContent
			FROM {Nets.TableHead}cmsdocdiscuss AS A
			INNER JOIN {Nets.TableHead}cmsdocdiscusscont AS B ON B.cddctIndexID=A.cddtID
			WHERE 1=1 AND A.cddtRecycle=0 AND A.cddtChecked>1 AND A.cddtParid={Nets.ID}
			ORDER BY A.cddtOrderBy DESC,A.cddtID ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sMainID,$tmpSTR);
		$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){
		if($pColumn['stcotName']=='cddctContent' && $pFlag=='Normal'){
			$pColumn['ControlStyle']='width:500px;height:40px;';
			$pColumn['Parameter_JS_Onfocus']="tmpMCommon.OnDiscussInput(this.name,0);CCodeTxt_ShowCACode(0);";
		}
	}
	
}


?>