<?php
require($netsFileConfig['sysCoreRoot'].'Inc/m_Oa/Oa/oacontact.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.'oacontact','sttColumnHead'=>'ocot'),
			array('sttTableName'=>$this->sysTableHead.'oacontactcont','sttColumnHead'=>'ococt'),);
		$this->sUiName='mana0_nets_self_contact';
		
	}
	public function OnBInitial(){
		$this->sMetaTitle='联系人';
		$this->sLimitCount=0;
		$this->sApp=new oacontact($this->sConnString);
		
		//-- ------ #ActionType ------ --
		if ($this->sActionType=='DAdd_Get') {
			$this->OnAdd_Get();
		}else if ($this->sActionType=='DCancel_Get') {
			$this->OnCancel_Get();
			
		}
		
	}
	public function OnAdd_Get(){
		//-- ------ #Get ------ --
		$tmpAR0=$this->AnalyerRequest('DAdd_Get','',0);
		$tmpIDS=explode($this->sysSPLIT2,$tmpAR0[0]);
		//-- ------ #Content ------ --
		$tmpDbDescriptions=array();
		foreach ($this->sTable as $tableCell){
			$tmpDbDescriptions[]=$this->sDbDescriptions[$tableCell['sttTableName']];
		}
		$tmpDbDescriptions[0]['Columns']['ocotCreateBy']['Value']=$this->sUserInfo[0]['Columns']['uitID']['Value'];
		$tmpINT=$this->sApp->AddContacts($tmpDbDescriptions,$tmpIDS);
		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 OnCancel_Get(){
		//-- ------ #Get ------ --
		$tmpAR0=$this->AnalyerRequest('DCancel_Get','',0);
		$tmpIDS=explode($this->sysSPLIT2,$tmpAR0[0]);
		//-- ------ #Content ------ --
		$tmpDbDescriptions=array();
		foreach ($this->sTable as $tableCell){
			$tmpDbDescriptions[]=$this->sDbDescriptions[$tableCell['sttTableName']];
		}
		$tmpDbDescriptions[0]['Columns']['ocotCreateBy']['Value']=$this->sUserInfo[0]['Columns']['uitID']['Value'];
		$tmpINT=$this->sApp->CancelContacts($tmpDbDescriptions,$tmpIDS);
		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,'ocotID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.ocotID,A.ocotName,A.ocotParid
			FROM '.$this->sysTableHead.'oacontact AS A 
			WHERE 1=1 
			AND A.ocotID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.ocotName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.ocotParid='.$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'=>'ocotID','stcoctUiName'=>'缂栧彿');
		$this->sSortButton[1]=array('stcotName'=>'ocotName','stcoctUiName'=>'联系人鍚嶇О');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'ocotID,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.ocotID,A.ocotName,A.ocotParid
			FROM '.$this->sysTableHead.'oacontact AS A 
			WHERE 1=1 
			AND A.ocotID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.ocotName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.ocotParid='.$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'=>'ocotID','stcoctUiName'=>'缂栧彿');
		$this->sSortButton[1]=array('stcotName'=>'ocotName','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.ocotID,A.ocotName,A.ocotParid 
				FROM '.$this->sysTableHead.'oacontact AS A
				WHERE 1=1 AND A.ocotRecycle=0 AND A.ocotChecked>1 AND 
				A.ocotParid=(SELECT ocotParid FROM oacontact WHERE 1=1 AND ocotRecycle=0 AND ocotChecked>1 AND ocotID={Nets.ID})
				ORDER BY A.ocotOrderBy DESC,A.ocotID DESC ';
		}else if($this->sExternal_ChildChooseSData[0]==1 || $this->sExternal_ChildChooseSData[0]==3){
			//-- Child grade --
			$tmpSQL=' SELECT A.ocotID,A.ocotName,A.ocotParid 
				FROM '.$this->sysTableHead.'oacontact AS A
				WHERE 1=1 AND A.ocotRecycle=0 AND A.ocotChecked>1 AND A.ocotParid={Nets.ID}
				ORDER BY A.ocotOrderBy DESC,A.ocotID 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.'oacontact AS A 
			INNER JOIN '.$this->sysTableHead.'oacontactcont AS B ON B.ococtIndexID=A.ocotID ';
		if(count($this->sTable)>2){
			$tmpSQL.=' LEFT OUTER JOIN '.$this->sTable[2]['sttTableName'].' AS C ON C.'.$this->sTable[2]['sttColumnHead'].'IndexID=A.ocotID ';
		}
		$tmpSQL.=' WHERE 1=1 AND A.ocotID='.$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']=='ocotParid'){
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='ocotModelid_Detail'){
						$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_Normal as $Row0){
				if($Row0['stcotName']=='ocotTableid'){
					$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
				}
				$Coun0++;
			}
		}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);

		return $pColumn;
	}
}

?>