<?php
/**
 *	Generated by miceCMS
 *	http://www.miceCMS.com/
 */
class poll_updateAction extends security_login {
	function action(){
		ModuleLimit(__CLASS__);
		global $conn;
		$pollcategory_id=$_POST['pollcategory_id'];
		if($pollcategory_id){
			$pollcategory=new model_Pollcategory();
			$pollcategory->setSubsection('WHERE pollcategory_id='.$pollcategory_id);
			$results=$pollcategory->doSelectOne();
		}

		$miceSession = new session();

		$title=MiceFilterHtml($_POST['title']);
		$content=MiceFilterQuote($_POST['content']);
		$userusergroup_id=$_POST['usergroup_id'];
		$checks=$_POST['checks'];
		$times=$_POST['times'];
		$startdate=Time2Num($_POST['startdate']);
		$stopdate=Time2Num($_POST['stopdate']);
		$isvisible=$_POST['isvisible'];
		$isopen=$_POST['isopen'];
		$user_id=$miceSession->get('userid');
		$ip=GetRealIp();
		$pointnum=$_POST['pointnum'];

		if($title==""){
			$jsstring='Dialog.alert("投票名称不能为空",function(){history.back(-1);});';
			MessageBox($jsstring);
			exit;
		}

		if($results)
		{
			$ins='内容已存在';
			$pid=$results->getPollcategoryId();
			$pollcategory->setTitle($title);
			$pollcategory->setContent($content);
			$pollcategory->setUsergroupId($userusergroup_id);
			$pollcategory->setChecks($checks);
			$pollcategory->setTimes($times);
			$pollcategory->setStartdate($startdate);
			$pollcategory->setStopdate($stopdate);
			$pollcategory->setIsvisible($isvisible);
			$pollcategory->setIsopen($isopen);
			$pollcategory->setUserId($user_id);
			$pollcategory->setIp($ip);
			$pollcategory->setPointnum($pointnum);
			$results=$pollcategory->doUpdate();
			if($results)
			{
				$exeresult='更新成功';
			}else{
				$exeresult='更新失败';
			}

		}else{
			$ins='内容已不存在';
			$pollcategory=new model_Pollcategory();
			$pollcategory->setTitle($title);
			$pollcategory->setContent($content);
			$pollcategory->setUsergroupId($userusergroup_id);
			$pollcategory->setChecks($checks);
			$pollcategory->setTimes($times);
			$pollcategory->setStartdate($startdate);
			$pollcategory->setStopdate($stopdate);
			$pollcategory->setIsvisible($isvisible);
			$pollcategory->setIsopen($isopen);
			$pollcategory->setUserId($user_id);
			$pollcategory->setIp($ip);
			$pollcategory->setPointnum($pointnum);
			$results=$pollcategory->doInsert();
			if($results)
			{
				$exeresult='插入成功';	
				$pid=$conn->Insert_ID();
			}else{
				$exeresult='插入失败';
			}
		}

		

		if($_POST['goon']==1){
			$jsstring='Dialog.alert(\''.$exeresult.'\',function(){window.location.href="'.MICE_URL.'admin.php/poll/edit";window.event.returnValue = false;},300,100,"继续添加投票");';
			MessageBox($jsstring);
		}else{
			$jsstring='Dialog.alert(\''.$exeresult.'\',function(){window.location.href="'.MICE_URL.'admin.php/poll";window.event.returnValue = false;},300,100,"返回投票列表");';
			MessageBox($jsstring);
		}
		exit;
	}
}
?>