<?php
class cmsvote extends netsDb {
	private $sysErrorClassID='0000';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	
	public function cmsvote($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='cvtName';
		if(strlen($pTableDescriptAR[0]['Columns'][$tmpSTR]['Value'])<1 && !in_array($tmpSTR,$pExceptionAR2)){
			$this->sysLastError='提交内容错误:1.名称不能为空';
			return $this->sysErrorFuncID.'001';
		}
		
		return 0;
	}
	
	public function OnVote($pID,$pOptionid){
		$this->sysErrorFuncID=$this->sysErrorClassID.'02';
		$tmpCode=new netsCode();
		$tmpHtml=new netsHtml();
		$this->TransStart();
		//-- ------ #Check cookie exist ------ --
		//Get cookie
		$tmpCookieName=$this->sysCookieHead.'Cookie_Cmsvote_'.$pID;
		$tmpAR0=$tmpHtml->AnalyerRequest($tmpCookieName,'',2);
		if ($tmpAR0[0]!='') {
			$this->TransRollback();
			$this->sysLastError='您已投过票了，谢谢关注。';
			return $this->sysErrorFuncID.'001';
		}
		//-- ------ #Update data ------ --
		$tmpSQL=' UPDATE {Nets.TableHead}cmsvoteoption AS A
			SET A.cvotCount=A.cvotCount+1
			WHERE 1=1 AND A.cvotID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pOptionid,$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='更新用户习惯设置是出错，请与客服人员联系。';
			return $tmpINT;
		}
		//-- ------ #Write cookie ------ --
		$this->writeCookie($this->sysNormalCookiePath,$tmpCookieName,1);
		
		$this->TransCommit();
		return 0;
	}
	public function recordResult($pDbDescriptions,&$pNumCode){
		$this->sysErrorFuncID=$this->sysErrorClassID.'02';
		$tmpCode=new netsCode();
		$tmpHtml=new netsHtml();
		$this->TransStart();
		//-- ------ #Add ------ --
		//#Get numCode
		$tmpSTR='cvrtNumCode';
		$pDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$pDbDescriptions[0]['Columns'][$tmpSTR]['Value']=$this->sysFileConfig['NumCodeHead_SubscribeOrder'].$this->sysSPLIT11.date('YmdHis');
		$this->numCode($pDbDescriptions[0]);
		
		//-- #Setting --
		$pDbDescriptions[0]['Columns']['cvrtName']['Value']=$pDbDescriptions[0]['Columns']['cvrtNumCode']['Value'];
		$pDbDescriptions[0]['Columns']['cvrtCreateTime']['Value']=date($this->sysTimeFormat);
		
		//-- #Add --
		$pDbDescriptions[0]['TableDescription']['SearchColumn']='cvrtNumCode,cvrtID';
		$pDbDescriptions[1]['TableDescription']['SearchColumn']='cvrctIndexID';
		$tmpINT=$this->add($pDbDescriptions);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='记录调查结果时错误，请客服人员联系。';
			return $tmpINT;
		}
		
		
		$pNumCode=$pDbDescriptions[0]['Columns']['cvrtNumCode']['Value'];
		$this->TransCommit();
		return 0;
	}
	
	
}
?>