<?php
class articleAction extends security_normal {
	
	function action(){	
		$CategoryFN=$this->_getParamId(1);
		$ArticleFN=$this->_getParamId(2);
		$htmlfn=MICE_DIR.'article/'.$CategoryFN.'/'.$ArticleFN;
		if(MICE_HTML){
				if(file_exists($htmlfn)){
				include_once $htmlfn;
				exit;
			}
		}
		$ArticleId=preg_replace("/(\w+)_(\d+)".MICE_HTML_EXT."/i","\${2}",$ArticleFN);
		
		if($ArticleId<1)	$ArticleId=1;
		
		if($CategoryFN!='' and is_numeric($ArticleId)){
			global $conn;
			//查找分类
			$category=new model_Category();
			if(is_numeric($CategoryFN)){
				$category->setSubsection('WHERE type LIKE \'article%\' AND isvisible=0 AND (filename=\''.$CategoryFN.'\' OR category_id='.$CategoryFN.')');
			}else{
				$category->setSubsection('WHERE type LIKE \'article%\' AND isvisible=0 AND filename=\''.$CategoryFN.'\'');
			}
			$CategoryRS=$category->doSelectOne();
			$CategoryId=$CategoryRS->getCategoryId();

			if($CategoryRS){
				if($CategoryRS->getSubtpl()){								//模板
					$tpl=$CategoryRS->getSubtpl();
				}else{
					$filename = new getTPLFileName(__CLASS__);
					$tpl=$filename->TPLFileName;
				}
				//查找文章
				$article=new model_Article();
				$article->setSubsection('WHERE isvisible=0 AND category_id LIKE \'%,'.$CategoryId.',%\' AND article_id='.$ArticleId);
				$ArticleRS=$article->doSelectOne();
				if(!$ArticleRS){
					$jsstring='Dialog.alert(\'对不起,您查看的文章不存在或已经被删除\',function(){window.location.href="'.MICE_URL.'";window.event.returnValue = false;},300,100,"提示信息");';
					MessageBox($jsstring);
					exit;
				}
			}else{
				$jsstring='Dialog.alert(\'对不起,您查看的文章不存在或已经被删除\',function(){window.location.href="'.MICE_URL.'";window.event.returnValue = false;},300,100,"提示信息");';
				MessageBox($jsstring);
				exit;
			}
		}else{
			$jsstring='Dialog.alert(\'参数错误\',function(){window.location.href="'.MICE_URL.'";window.event.returnValue = false;},300,100,"提示信息");';
			MessageBox($jsstring);
			exit;
		}
		if($ArticleRS->getUsergroupId()<0){
			$gid=$CategoryRS->getUsergroupId();
		}else{
			$gid=$ArticleRS->getUsergroupId();
		}
		$miceSession = new session();
		if($gid>0)
		{			
			if($miceSession->get('mu__grouplevel')<$gid){
				$jsstring='Dialog.alert(\'只有会员才能查看,您尚未登录或注册\',function(){window.location.href="'.MICE_URL.'";window.event.returnValue = false;},300,100,"提示信息");';
				MessageBox($jsstring);
				exit;
			}
		}

		//作者
		$user=new model_User();
		$user->setSubsection('where user_id='.$ArticleRS->getUserId());
		$userrs=$user->doSelectOne();
		$wname=$userrs->getLoginname();

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileIndex');
		$smarty->assign('CategoryRS',$CategoryRS);
		$smarty->assign('ArticleRS',$ArticleRS);
		$smarty->assign('CategoryId',$CategoryId);
		$smarty->assign('ArticleId',$ArticleId);
		$smarty->assign('wname',$wname);
		
		if(MICE_HTML){
			//将内容写入至静态文件
			$content = $smarty->fetch($tpl);
			$fp = fopen($htmlfn, 'w'); 
			fwrite($fp, $content); 
			fclose($fp);
		}

		$smarty->display($tpl);
	}
}
?>