<?php
require($netsFileConfig['sysCoreRoot'].'Inc/m_Oa/Oa/oafavorite.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.'oafavorite','sttColumnHead'=>'oft'),
			array('sttTableName'=>$this->sysTableHead.'oafavoritecont','sttColumnHead'=>'ofct'),);
		$this->sUiName='User/oa/my_favorite';
	}
	public function OnBInitial(){
		$this->sMetaTitle='收藏';
		$this->sLimitCount=0;
		$this->sApp=new oafavorite($this->sConnString);
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.ofgtID,A.ofgtName,A.ofgtParid FROM '.$this->sysTableHead.'oafavoritegroup AS A
			WHERE 1=1 AND A.ofgtChecked>1 AND A.ofgtParid={Nets.Parid}
			ORDER BY A.ofgtOrderBy DESC,A.ofgtID DESC ';
		$tmpAR0['SQL0']=' SELECT A.ofgtID,A.ofgtName,A.ofgtParid FROM '.$this->sysTableHead.'oafavoritegroup AS A
			WHERE 1=1 AND A.ofgtChecked>1 AND A.ofgtID={Nets.Parid}
			ORDER BY A.ofgtOrderBy DESC,A.ofgtID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='ofgtID';
		$tmpAR0['Text']='ofgtName';
		$tmpAR0['Value']='ofgtID';
		$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);
		
		//-- ------ #ActionType ------ --
		if ($this->sActionType=='DAdd_Get') {
			$this->OnAdd_Get();

		}
		
	}
	public function OnAdd_Get(){
		//-- ------ #Get ------ --
		$tmpAR0=$this->AnalyerRequest('DAdd_Get',',,-1,-1',0);
		//-- ------ #Content ------ --
		$tmpDbDescriptions=array();
		foreach ($this->sTable as $tableCell){
			$tmpDbDescriptions[]=$this->sDbDescriptions[$tableCell['sttTableName']];
		}
		$tmpDbDescriptions[0]['Columns']['oftName']['Value']=$tmpAR0[0];
		$tmpDbDescriptions[0]['Columns']['oftURL']['Value']=$this->sCode->URL_DecodeParameter($tmpAR0[1],1);
		$tmpDbDescriptions[0]['Columns']['oftFavid']['Value']=$tmpAR0[2];
		$tmpDbDescriptions[0]['Columns']['oftFavType']['Value']=$tmpAR0[3];
		$tmpDbDescriptions[0]['Columns']['oftCreateBy']['Value']=$this->sUserInfo[0]['Columns']['uitID']['Value'];
		$tmpINT=$this->sApp->addFavorite($tmpDbDescriptions);
		if ($tmpINT!=0) {
			$this->sApp->TransRollback();
			$this->sMessage=$this->sApp->sysLastError.$this->sysSPLIT1.$tmpAR0[0];
			return 1;
		}
		
		$this->sMessage='关注成功'.$this->sysSPLIT1.$tmpAR0[0];
		return 0;
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'oftID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.oftID,A.oftName,A.oftParid
			FROM '.$this->sysTableHead.'oafavorite AS A 
			WHERE 1=1 
			AND A.oftID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.oftName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.oftParid='.$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->sysSPLIT1.$this->sSearchData[1];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'oftID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'oftName','stcoctUiName'=>'收藏名称');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'oftID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',,-1',0);
		$this->sExternal_SearchData=$this->AnalyerRequest($this->sActionType,',-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.oftID,A.oftName,A.oftParid
			FROM '.$this->sysTableHead.'oafavorite AS A 
			WHERE 1=1 
			AND A.oftID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.oftName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.oftParid='.$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='.$this->sActionType.'&'.$this->sActionType.'='.$this->sExternal_SearchData[0].','.$this->sExternal_SearchData[1];
		$this->sysPages[0]=$this->sysPage.'?'.$this->sExtendParameter;
		
		$this->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&'.$tmpSTR2.'='.$this->sSearchData[0].$this->sExtendParameter;
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'oftID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'oftName','stcoctUiName'=>'收藏名称');
		
		return 0;
	}
	public function OnExternal_ChildChoose(){
		//-- ------ #Search data ------ --
		$tmpSTR0='External_ChildChoose';
		$this->sExternal_ChildChooseSData=$this->AnalyerRequest($tmpSTR0,'0,,0,0',0);
		//#Spell sql
		$tmpSQL='';
		if($this->sExternal_ChildChooseSData[0]==0 || $this->sExternal_ChildChooseSData[0]==2){
			//-- Same grade --
			$tmpSQL=' SELECT A.oftID,A.oftName,A.oftParid 
				FROM '.$this->sysTableHead.'oafavorite AS A
				WHERE 1=1 AND A.oftRecycle=0 AND A.oftChecked>1 AND 
				A.oftParid=(SELECT oftParid FROM oafavorite WHERE 1=1 AND oftRecycle=0 AND oftChecked>1 AND oftID={Nets.ID})
				ORDER BY A.oftOrderBy DESC,A.oftID DESC ';
		}else if($this->sExternal_ChildChooseSData[0]==1 || $this->sExternal_ChildChooseSData[0]==3){
			//-- Child grade --
			$tmpSQL=' SELECT A.oftID,A.oftName,A.oftParid 
				FROM '.$this->sysTableHead.'oafavorite AS A
				WHERE 1=1 AND A.oftRecycle=0 AND A.oftChecked>1 AND A.oftParid={Nets.ID}
				ORDER BY A.oftOrderBy DESC,A.oftID DESC ';
		}
		$tmpSTR=str_replace('{Nets.ID}',$this->sExternal_ChildChooseSData[2],$tmpSQL);
		$this->sExternal_ChildChooseData=$this->sDb->Search($tmpSTR);
		
		return 0;
	}
	public function OnNormal(){
		$tmpINT=0;
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'oafavorite AS A 
			INNER JOIN '.$this->sysTableHead.'oafavoritecont AS B ON B.ofctIndexID=A.oftID ';
		if(count($this->sTable)>2){
			$tmpSQL.=' LEFT OUTER JOIN '.$this->sTable[2]['sttTableName'].' AS C ON C.'.$this->sTable[2]['sttColumnHead'].'IndexID=A.oftID ';
		}
		$tmpSQL.=' WHERE 1=1 AND A.oftID='.$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']=='oftParid'){
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='oftModelid_Detail'){
						$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_Normal as $Row0){
				if($Row0['stcotName']=='oftTableid'){
					$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
				}
				$Coun0++;
			}
		}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='oftParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='oftParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
		}else if($pColumn['stcotName']=='ofctIsUsually' && $pFlag=='Search'){
			$pColumn['Option']=$this->sBoolean2;
		}else if($pColumn['stcotName']=='ofctIsUsually' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sBoolean1;
			
		}
		return $pColumn;
	}
}

?>