<?php
class oafavorite extends netsDb {
	private $sysErrorClassID='0000';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	
	public function oafavorite($pConnection){
		$this->netsDb($pConnection);
	}
	public function Check(&$pTableDescriptAR,$pExceptionAR1,$pExceptionAR2){
		$this->sysErrorFuncID=$this->sysErrorClassID.'02';

		if(count($pExceptionAR1)==0){
			$pExceptionAR1=array();
		}
		parent::Check($pTableDescriptAR,$pExceptionAR1,$pExceptionAR2);
		//
		$tmpSTR='oftName';
		if(strlen($pTableDescriptAR[0]['Columns'][$tmpSTR]['Value'])<1 && !in_array($tmpSTR,$pExceptionAR2)){
			$this->sysLastError='提交内容错误:1.名称不能为空';
			return $this->sysErrorFuncID.'001';
		}
		//$tmpSTR='oftUrl';
		//$pTableDescriptAR[0]['Columns'][$tmpSTR]['Value']=urlencode($pTableDescriptAR[0]['Columns'][$tmpSTR]['Value']);
		
		return 0;
	}
	
	public function addFavorite($pDescriptions){
		$this->sysErrorFuncID=$this->sysErrorClassID.'02';
		$this->TransStart();
		//-- ------ #Check MyUserid ------ --
		$tmpSQL=' SELECT A.uitID,A.uitName,A.uitNickname,A.uitEmail
			
			FROM {Nets.TableHead}netsuserinfo AS A
			WHERE 1=1 AND A.uitRecycle=0 AND A.uitChecked>1 AND A.uitID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['oftCreateBy']['Value'],$tmpSTR);
		$tmpData_My=$this->Search($tmpSTR);
		if (count($tmpData_My)==0) {
			$this->sysLastError='新增收藏失败:登陆后才能收藏';
			$this->TransRollback();
			return $this->sysErrorFuncID.'001';
		}
		//-- ------ #Update exist favorite ------ --
		//-- #GET --
		$tmpSQL=' SELECT A.oftID,A.oftName,A.oftParid,A.oftType,A.oftURL,A.oftFavid,A.oftFavType
			FROM {Nets.TableHead}oafavorite AS A
			WHERE 1=1 AND
			A.oftCreateBy={Nets.CreateBy} AND A.oftURL LIKE \'{Nets.URL}\' ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.CreateBy}',$pDescriptions[0]['Columns']['oftCreateBy']['Value'],$tmpSTR);
		$tmpSTR=str_replace('{Nets.URL}',$pDescriptions[0]['Columns']['oftURL']['Value'],$tmpSTR);
		$tmpData_Favorite=$this->Search($tmpSTR);
		if (count($tmpData_Favorite)>0) {
			$this->sysLastError='新增收藏失败:您已收藏过此地址';
			$this->TransRollback();
			return $this->sysErrorFuncID.'001';
		}
		//-- ------ #Add ------ --
		//#Get numCode
		$tmpSTR='oftNumCode';
		$pDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$pDescriptions[0]['Columns'][$tmpSTR]['Value']=$this->sysFileConfig['NumCodeHead_Normal'].date('YmdHis');
		$tmpINT=$this->numCode($pDescriptions[0]);
		//#Set value
		$pDescriptions[0]['Columns']['oftParid']['Value']=0;
		$pDescriptions[0]['Columns']['oftCreateTime']['Value']=date($this->sysTimeFormat);
		//#Add
		$tmpINT=$this->Check($pDescriptions,array(),array());
		if($tmpINT!=0){
			$this->TransRollback();
			return $tmpINT;
		}
		$pDescriptions[0]['TableDescription']['SearchColumn']='oftNumCode,oftID';
		$pDescriptions[1]['TableDescription']['SearchColumn']='ofctIndexID';
		$tmpINT=$this->add($pDescriptions);
		if($tmpINT!=0){
			$this->sysLastError='新增收藏失败:新增收藏失败，请与客户人员联系。';
			$this->TransRollback();
			return $this->sysErrorFuncID.'001';
		}
		
		$this->TransCommit();
		return 0;
	}
}
?>