<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Doc/cmsdocdiscuss.php');

class PaDefault extends CustomPage {
	public $ssetParid=1;
	
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnPInitial(){
		$this->checkUser('1,2,3,');
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'cmsdocdiscuss','sttColumnHead'=>'cddt'),
			array('sttTableName'=>$this->sysTableHead.'cmsdocdiscusscont','sttColumnHead'=>'cddct'),);
		$this->sUiName='Platform/cms/doc_docdiscuss';
	}
	public function OnBInitial(){
		$this->sMetaTitle='文档评论';
		$this->sLimitCount=0;
		$this->sApp=new cmsdocdiscuss($this->sConnString);
		//-- ------ #Options ------ --
		//Type
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=138;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/options_discussType';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sType1);
		$this->sType2=$this->sType1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有类型]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sType2,$tmpAR0);
		
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'cddtID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',',0);
		//#Spell sql
		$tmpSQL=' SELECT 
			A.cddtID,A.cddtName,A.cddtParid,B.cdtName 
			FROM '.$this->sysTableHead.'cmsdocdiscuss AS A 
			INNER JOIN '.$this->sysTableHead.'cmsdoc AS B ON B.cdtID=A.cddtParid
			WHERE 1=1 
			AND A.cddtID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.cddtName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!=''){
			$tmpSQL.=' AND B.cdtName LIKE \'%'.$this->sSearchData[1].'%\' ';
		}
		if($tmpAR1[1]==1){
			$tmpSQL.=' ORDER BY '.$tmpAR1[0].' ';
		}else if($tmpAR1[1]==2){
			$tmpSQL.=' ORDER BY '.$tmpAR1[0].' DESC ';
		}
		$this->sListData=$this->sDb->SearchP($tmpSQL,$tmpAR0);
		//#Set page button
		$this->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&'.$tmpSTR2.'='.$this->sSearchData[0].','.$this->sSearchData[1];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'cddtID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'cddtName','stcoctUiName'=>'文档评论标题');
		
		return 0;
	}
	public function OnNormal(){
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'cmsdocdiscuss AS A 
			INNER JOIN '.$this->sysTableHead.'cmsdocdiscusscont AS B ON B.cddctIndexID=A.cddtID ';
		$Coun0=2;
		foreach ($this->sTable as $Row0){
			if (count($this->sTable)>2) {
				$tmpSQL.=' INNER JOIN '.$Row0['sttTableName'].' AS '.$this->sysTableMark[$Coun0].' ON '.$this->sysTableMark[$Coun0].'.'.$Row0['sttColumnHead'].'IndexID=A.cddtID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.cddtID='.$tmpAR0[0].' ';
		$tmpDataCollection0=$this->sDb->Search($tmpSQL);
		if(count($tmpDataCollection0)>0){
			$tmpRow=$tmpDataCollection0[0];
			$this->sMainID=$tmpRow[$this->sTable[0]['sttColumnHead'].'ID'];
			//-- #Get value --
			$Coun0=0;
			while (count($this->sUiDescription_Normal)>$Coun0) {
				if(isset($tmpRow[$this->sUiDescription_Normal[$Coun0]['stcotName']])){
					$this->sUiDescription_Normal[$Coun0]['Value']=$tmpRow[$this->sUiDescription_Normal[$Coun0]['stcotName']];
					//Spical set
					if($this->sUiDescription_Normal[$Coun0]['stcotName']=='cddtParid'){
						
					}
				}
				$Coun0++;
			}
		}else {}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='cddtParid' && $pFlag=='Normal'){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_cms/doc/doc.php';
			$pColumn['Parameter']=$tmpParameters;
			
			$tmpSQL=' SELECT A.cdtName AS tName FROM {Nets.TableHead}cmsdoc AS A
				WHERE 1=1 AND A.cdtID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$this->sCode->Int32($pColumn['Value'],0),$tmpSTR);
			$tmpData0=$this->sDb->Search($tmpSTR);
			if(count($tmpData0)>0){
				$pColumn['ShowValue']=$tmpData0[0]['tName'];
			}
			
		}else if($pColumn['stcotName']=='cddtType' && $pFlag=='Search'){
			$pColumn['Option']=$this->sType2;
		}else if($pColumn['stcotName']=='cddtType' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sType1;
			
		}
		return $pColumn;
	}
}
//-- ------ #Instanct ------ --
$tmpDefault=new PaDefault();
$tmpDefault->OnPage();
$tmpControls=new CustomControls();
$tmpControlPage=new CustomControlPage();
$tmpComHead->sMenuid=$tmpDefault->sMenuid;
$tmpDefault->sysMetaTitle=$tmpDefault->sMetaTitle.' - '.$tmpDefault->sysFileConfig['sysTitle'];
//-- ------ #Template ------ --
require($tmpDefault->sysFileConfig['sysCoreRoot'].$tmpDefault->sysQPlatformTemplatePath.'Component/Group_0.php'); ?>