<?php
class pollAction extends security_normal {
	
	function action(){
		$pollcategory=new model_Pollcategory();
		$pollcategory->setSubsection('WHERE isvisible=0 AND pollcategory_id='.$_POST['pollid']);
		$PollCategoryRS=$pollcategory->doSelectOne();
		if(!$PollCategoryRS){
			$jsstring='Dialog.alert(\'对不起,您查看的投票不存在或已经被删除\',function(){window.location.href="'.MICE_URL.'";window.event.returnValue = false;},300,100,"提示信息");';
			MessageBox($jsstring);
			exit;
		}
		if($_COOKIE["pollip"]){
			$jsstring='Dialog.alert(\'对不起,您已经投过票了\',function(){window.location.href="'.MICE_URL.'";window.event.returnValue = false;},300,100,"提示信息");';
			MessageBox($jsstring);
			exit;
		}
		if($PollCategoryRS->getChecks()>0 and $PollCategoryRS->getChecks()<sizeof($_POST['poll'])){
			$jsstring='Dialog.alert(\'您最多可以同时选中'.$PollCategoryRS->getChecks().'项\',function(){window.location.href="'.MICE_URL.'index.php/Pollresults/'.$_POST['pollid'].'";window.event.returnValue = false;},300,100,"提示信息");';
			MessageBox($jsstring);
			exit;
		}
		setcookie("pollip",GetRealIp(),time()+$PollCategoryRS->getTimes());

		global $conn;
		if(sizeof($_POST['poll'])){
			if(is_array($_POST['poll'])){
				foreach($_POST['poll'] as $pid){
					$poll=new model_Poll();
					$poll->setSubsection('WHERE poll_id='.$pid);
					$results=$poll->doSelectOne();
					$poll->setNum($results->getNum()+1);
					$poll->doUpdate();
				}
			}else{
				$poll=new model_Poll();
				$poll->setSubsection('WHERE poll_id='.$_POST['poll']);
				$results=$poll->doSelectOne();
				$poll->setNum($results->getNum()+1);
				$poll->doUpdate();
			}
			$pollcategory->setNum($PollCategoryRS->getNum()+sizeof($_POST['poll']));//总票数
			$pollcategory->doUpdate();
			$jsstring='Dialog.alert(\'投票成功\',function(){window.location.href="'.MICE_URL.'index.php/Pollresults/'.$_POST['pollid'].'";window.event.returnValue = false;},300,100,"提示信息");';
			MessageBox($jsstring);
			exit;
		}else{
			$jsstring='Dialog.alert(\'投票失败\',function(){window.location.href="'.MICE_URL.'index.php/Pollresults/'.$_POST['pollid'].'";window.event.returnValue = false;},300,100,"提示信息");';
			MessageBox($jsstring);
			exit;
		}
	}	
}
?>