<?php
class PaDefault extends CustomPage {
	public $ssetParid=1;
	
	public function PaDefault(){
		$this->ComPage();
	}
	public function OnPInitial(){
		$this->checkUser('1,2,3,4,5,');
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'cmsdoc','sttColumnHead'=>'cdt'),
			array('sttTableName'=>$this->sysTableHead.'cmsdoccont','sttColumnHead'=>'cdct'),);
		$this->sUiName='Mana/cms/doc_doc_u';
	}
	public function OnBInitial(){
		$this->sMetaTitle='文档';
		$this->sLimitCount=0;
		$this->sSortParameter='chooseFolder;cdtParid;External_Folder;'.$this->sysFileConfig['sysCoreRoot'].'Mana/m_cms/doc/docGroup.php;2|';
		$this->sApp=new cmsdoc($this->sConnString);
		$this->sSpicalValue=array();
		$this->sSpicalValue=array(0,$this->sTable[0]['sttColumnHead'].'CreateBy',$this->sUserInfo[0]['Columns']['uitID']['Value']);
		$this->sSpicalValue=array(0,$this->sTable[0]['sttColumnHead'].'IsUPublic',1);
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' 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 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']='';
		$this->sParid1=$this->sParid2=$this->sControl->bindDropdown($tmpAR0);
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有的分类]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sParid2,$tmpAR0);
		/*
		//UserParid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT 
			A.cdugtID,A.cdugtName,A.cdugtParid 
			FROM '.$this->sysTableHead.'cmsdocusergroup AS A
			WHERE 1=1 AND A.cdugtRecycle=0 AND A.cdugtChecked>1 AND A.cdugtParid={Nets.Parid}
			AND ((A.cdugtCreateBy='.$this->sUserInfo[0]['Columns']['uitID']['Value'].' AND cdugtPublicType=0) OR (A.cdugtCreateBy='.$this->sUserInfo[0]['Columns']['uitUnitid']['Value'].' AND cdugtPublicType=1))
			ORDER BY A.cdugtOrderBy DESC,A.cdugtID DESC ';
		$tmpAR0['InitialString']=0;
		$tmpAR0['Parid']='cdugtID';
		$tmpAR0['Text']='cdugtName';
		$tmpAR0['Value']='cdugtID';
		$tmpAR0['Type']=0;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$this->sUserParid1=$this->sUserParid2=$this->sControl->bindDropdown($tmpAR0);
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有分类]';
		$tmpAR0['Value']=-1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sUserParid2,$tmpAR0);
		*/
		
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'cdtID,1',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1,-1',0);
		//#Spell sql
		$tmpSQL=' SELECT 
			A.cdtID,A.cdtName,A.cdtParid,C.cdgtName
			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)
			WHERE 1=1 
			AND A.cdtCreateBy='.$this->sUserInfo[0]['Columns']['uitID']['Value'].'
			AND A.cdtID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.cdtName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.cdtParid='.$this->sSearchData[1].' ';
		}
		if($this->sSearchData[2]!='-1'){
			$tmpSQL.=' AND A.cdtUserParid='.$this->sSearchData[2].' ';
		}
		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->sSearchData[2];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'cdtID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'cdtName','stcoctUiName'=>'文档名称');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'cdtID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1',0);
		$tmpSTR3='External_Search';
		$this->sExternal_SearchData=$this->AnalyerRequest($tmpSTR3,',0',0);
		//#Spell sql
		$tmpSQL=' SELECT 
			A.cdtID,A.cdtName
			FROM '.$this->sysTableHead.'cmsdoc AS A 
			WHERE 1=1 
			AND A.cdtCreateBy='.$this->sUserInfo[0]['Columns']['uitID']['Value'].'
			AND A.cdtID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.cdtName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.cdtParid='.$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->sExtendParameter='&ActionType='.$tmpSTR3.'&'.$tmpSTR3.'='.$this->sExternal_SearchData[0].','.$this->sExternal_SearchData[1];
		
		$this->sPAjaxButton->sPage=$this->sysPage;
		$this->sPAjaxButton->sFlag='External_Search';
		$this->sPAjaxButton->sPanel='chooseBox';
		$this->sPAjaxButton->sExtendParameter='&'.$tmpSTR2.'='.$this->sSearchData[0].','.$this->sSearchData[1].$this->sExtendParameter;
		$this->sPAjaxButton->setPage($this->sDb->sysPageInfo);
		$this->sPAjaxButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'cdtID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'cdtName','stcoctUiName'=>'文档标题');
		
		return 0;
	}
	public function OnNormal(){
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT 
			* 
			FROM '.$this->sysTableHead.'cmsdoc AS A 
			INNER JOIN '.$this->sysTableHead.'cmsdoccont AS B ON B.cdctIndexID=A.cdtID
			WHERE 1=1 AND A.cdtID='.$tmpAR0[0].'
			AND A.cdtCreateBy='.$this->sUserInfo[0]['Columns']['uitID']['Value'].' ';
		$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){
		if($pColumn['stcotName']=='Quick'){
			$pColumn['Style']='width:50px;';
		}else if($pColumn['stcotName']=='cdtTableid'){
			$pColumn['Option']=$this->sTableAR;
			$pColumn['Parameter']=$this->sysPage.'?ActionType=Normal&Normal='.$this->sMainID.',';
		}else if($pColumn['stcotName']=='cdtChecked' && $pFlag=='Search'){
			$pColumn['Option']=$this->sChecked2;
		}else if($pColumn['stcotName']=='cdtChecked' && $pFlag=='Normal'){
			$pColumn['Option']=$this->sChecked1;
		}else if($pColumn['stcotName']=='cdtParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='cdtParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
		}else if($pColumn['stcotName']=='cdtUserParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sUserParid2;
		}else if($pColumn['stcotName']=='cdtUserParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sUserParid1;
		}
		return $pColumn;
	}
}
?>