<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Doc/cmsdocgroup.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.'cmsdocgroup','sttColumnHead'=>'cdgt'),
			array('sttTableName'=>$this->sysTableHead.'cmsdocgroupcont','sttColumnHead'=>'cdgct'),);
		$this->sUiName='Platform/cms/doc_docgroup';
	}
	public function OnBInitial(){
		$this->sMetaTitle='文档分类';
		$this->sLimitCount=1;
		$this->sDb->sysDbCacheClear=array('cms/doc_doc_Group');
		$this->sApp=new cmsdocgroup($this->sConnString);
		$this->sChildlist_Parid=1;
		$this->sChildlist_ParColumnName='Parid';
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.cdgtID,A.cdgtName,A.cdgtParid 
			FROM '.$this->sysTableHead.'cmsdocgroup AS A
			WHERE 1=1 AND A.cdgtRecycle=0 AND A.cdgtChecked>1 AND A.cdgtParid={Nets.Parid}
			ORDER BY A.cdgtOrderBy DESC,A.cdgtID DESC ';
		$tmpAR0['SQL0']=' SELECT A.cdgtID,A.cdgtName,A.cdgtParid 
			FROM '.$this->sysTableHead.'cmsdocgroup AS A
			WHERE 1=1 AND A.cdgtRecycle=0 AND A.cdgtChecked>1 AND A.cdgtID={Nets.Parid}
			ORDER BY A.cdgtOrderBy DESC,A.cdgtID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='cdgtID';
		$tmpAR0['Text']='cdgtName';
		$tmpAR0['Value']='cdgtID';
		$tmpAR0['Type']=0;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='cms/doc_doc_Group';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sParid1);
		$this->sParid2=$this->sParid1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有的分类]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sParid2,$tmpAR0);
		//Templateid_Detail
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.stemtID,A.stemtName FROM '.$this->sysTableHead.'netssystemplate AS A 
			WHERE 1=1 AND A.stemtRecycle=0 AND A.stemtChecked>1 AND A.stemtFunctionid={Nets.Parid}
			ORDER BY A.stemtOrderBy DESC,A.stemtID DESC ';
		$tmpAR0['InitialString']=3;
		$tmpAR0['Parid']='stemtID';
		$tmpAR0['Text']='stemtName';
		$tmpAR0['Value']='stemtID';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$this->sTemplateid_Detail1=$this->sTemplateid_Detail2=$this->sControl->bindDropdown($tmpAR0);
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有的模板]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sTemplateid_Detail2,$tmpAR0);
		
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'cdgtID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1',0);
		//#Spell sql
		$tmpSQL=' SELECT 
			A.cdgtID,A.cdgtName,A.cdgtParid,A.cdgtNameStyle,A.cdgtOrderBy 
			FROM '.$this->sysTableHead.'cmsdocgroup AS A 
			WHERE 1=1 
			AND A.cdgtID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.cdgtName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.cdgtParid='.$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'=>'cdgtID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'cdgtName','stcoctUiName'=>'文档分类名');
		
		return 0;
	}
	public function OnExternal_Folder(){
		//-- ------ #Search data ------ --
		$tmpSTR0='External_Folder';
		$this->sSortSearch=$this->AnalyerRequest($tmpSTR0,'-1|',0);
		$this->sSortSearch=explode($this->sysSPLIT3,$this->sSortSearch[0]);
		$this->sSortPage=$this->sysFileConfig['sysCoreRoot'].$this->sysFileConfig['sysManaRoot'].'m_cms/doc/doc.php?Search0=,{Nets.ID}';
		//#Spell sql
		$tmpSQL=' SELECT A.cdgtID,A.cdgtName,A.cdgtParid,A.cdgtNameStyle 
			FROM '.$this->sysTableHead.'cmsdocgroup AS A 
			WHERE 1=1 AND A.cdgtRecycle=0 AND A.cdgtChecked>1 ';
		if($this->sSortSearch[0]!='-1'){
			$tmpSQL.=' AND A.cdgtParid='.$this->sSortSearch[0].' ';
		}
		$tmpSQL.=' ORDER BY A.cdgtOrderBy DESC,A.cdgtID DESC ';
		$this->sSortData=$this->sDb->Search($tmpSQL);
	}
	public function OnNormal(){
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'cmsdocgroup AS A
			INNER JOIN '.$this->sysTableHead.'cmsdocgroupcont AS B ON B.cdgctIndexID=A.cdgtID ';
		$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.cdgtID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.cdgtID='.$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']];
				}
				$Coun0++;
			}
		}else {}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='cdgtParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='cdgtParid' && ($pFlag=='Normal' || $pFlag=='List' || $pFlag=='Childlist_Normal')){
			$pColumn['Option']=$this->sParid1;
		}else if($pColumn['stcotName']=='cdgctTemplateid_Detail' && $pFlag=='Search'){
			$pColumn['Option']=$this->sTemplateid_Detail2;
		}else if($pColumn['stcotName']=='cdgctTemplateid_Detail' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sTemplateid_Detail2;
			
		}
		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'); ?>