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

		

		$category_id='0';
		$miceSession = new session();
		$user_id=$miceSession->get('userid');
		$title=MiceFilterHtml($_POST['title']);
		$upfile=MiceFilterQuote($_POST['upfile']);
		$img=MiceFilterQuote($_POST['img']);
		$url=MiceFilterQuote($_POST['url']);
		$browses=MiceFilterQuote($_POST['browses']);
		$ip=GetRealIp();

		if($title==""){
			$jsstring='Dialog.alert("文章标题不能为空",function(){history.back(-1);});';
			MessageBox($jsstring);
			exit;
		}
		if(strlen($img)<1){
			$img=MiceFilterQuote(GetImgUrl(MiceStripslashes($_POST['content'])));
		}

		if($upfile==""){
			$jsstring='Dialog.alert("图片不能为空",function(){history.back(-1);});';
			MessageBox($jsstring);
			exit;
		}

		if($results)
		{
			$ins='内容已存在';
			$aid=$results->getArticleId();
			$article->setCategoryId($category_id);
			$article->setTitle($title);
			$article->setUpfile($upfile);
			$article->setImg($img);
			$article->setUrl($url);
			$article->setBrowses($browses);
			$article->setIsvisible(1);			

			$article->setUserId($user_id);
			$article->setCreatedat(time());
			$article->setIp($ip);
			$article->setType('flash');
			$results=$article->doUpdate();
			if($results)
				$exeresult='更新成功';
			else
				$exeresult='更新失败';
		}else{

			$ins='内容已不存在';
			$article=new model_Article();
			$article->setCategoryId($category_id);
			$article->setTitle($title);
			$article->setUpfile($upfile);			
			$article->setImg($img);
			$article->setUrl($url);
			$article->setBrowses($browses);
			$article->setIsvisible(1);

			$article->setUserId($user_id);
			$article->setCreatedat(time());
			$article->setIp($ip);
			$article->setType('flash');
			$results=$article->doInsert();
			if($results){
				$exeresult='插入成功';
				$aid=$conn->Insert_ID();
				UpPostnums('micefun',$user_id);		//文章数+1
			}else
				$exeresult='插入失败';
		}

		if($_POST['goon']==1){
			$jsstring='Dialog.alert(\''.$exeresult.'\',function(){window.location.href="'.MICE_URL.'admin.php/flash/edit";window.event.returnValue = false;},300,100,"继续添加Flash图片");';
			MessageBox($jsstring);
		}else{
			$jsstring='Dialog.alert(\''.$exeresult.'\',function(){window.location.href="'.MICE_URL.'admin.php/flash";window.event.returnValue = false;},300,100,"跳转到Flash图片列表");';
			MessageBox($jsstring);
		}

		exit;
	}
}
?>