<?php
/**
 *	Generated by miceCMS
 *	http://www.miceCMS.com/
 */
class article_editArticleAction extends security_login {
	function action(){
		ModuleLimit(__CLASS__);
		$miceSession = new session();
		global $conn;
		$article_id=$this->_getParam('article_id');
		$category_id=$this->_getParam('category_id');
		if($article_id){
			$article=new model_Article();
			$article->setSubsection('WHERE article_id='.$article_id);
			$results=$article->doSelectOne();
		}else{
			$results=new model_Article();
		}

		$usergroup=new model_Usergroup();
		$usergroup->setSubsection('ORDER BY level');
		$usergroups=$usergroup->doSelect();

		$category=new model_Category();
		$category->setSubsection('WHERE type LIKE \'article%\' AND isvisible=0 ORDER BY path');
		$results2=$category->doSelect();

		$i=0;
		$categorynames='';
		foreach($results2 as $rs2) {
			$level=count(explode(",",$rs2->getPath()))-2;
			if($categorynames){
				$categorynames.='~';
				$categoryid1.='~';
				$categoryid2.=',';
			}
			$categorynames.= StrRepeat("─",$level-1).$rs2->getTitle();
			$categoryid1.= $rs2->getPath().'|';
			if(strstr($results->getCategoryId(),$rs2->getPath().'|'))
			{
				$categoryid2.= $rs2->getPath().'|';
			}
			//新增文档时,如果session中有某个分类的id,则自动选中该分类
			if($rs2->getCategoryId()==$miceSession->get('ai_categoryid') AND strlen($results->getCategoryId())==0)
			{
				$categoryid2.= $rs2->getPath().'|';
			}
			if($rs2->getType()!='article0')
			{
				$categoryid3.='disabled';
			}
			$categoryid3.='~';
			$i++;
		}

		//分类
		$category=new model_Category();
		$category->setSubsection('WHERE parentid=0 AND type LIKE \'article%\'');
		//$categoryrs=$category->doSelect();
		$childcount=$category->doCount();
		
		
		$editor='';
		$summary='';
		//调用插件
		$plugin=new model_Plugin();
		$plugin->setSubsection('WHERE isopen=1 AND hook=\'editor\' ORDER BY orderid ASC,plugin_id DESC');
		$plugins=$plugin->doSelectOne();
		include_once MICE_DIR.'includes/plugin.php';
		if($plugins){
			if(file_exists(MICE_DIR.'plugins/'.$plugins->getName().'/index.php')){
				include_once MICE_DIR.'plugins/'.$plugins->getName().'/index.php';
				add_filter('editor', $plugins->getName());
				$editor=apply_filters('editor',1);
				remove_filter('editor', $plugins->getName());
			}
		}

		//调用插件2
		$plugin=new model_Plugin();
		$plugin->setSubsection('WHERE isopen=1 AND hook=\'editor2\' ORDER BY orderid ASC,plugin_id DESC');
		$plugins=$plugin->doSelectOne();
		include_once MICE_DIR.'includes/plugin.php';
		if($plugins){
			if(file_exists(MICE_DIR.'plugins/'.$plugins->getName().'/index.php')){
				include_once MICE_DIR.'plugins/'.$plugins->getName().'/index.php';
				add_filter('editor2', $plugins->getName());
				$summary=apply_filters('editor2',1);
				remove_filter('editor2', $plugins->getName());
			}
		}

		if($editor==''){
			$editor='<textarea id="MCEname" name="MCEname" rows="15" cols="80" style="width: 100%">MCEcontent</textarea>';
			$summary='<textarea id="MCEname" name="MCEname" rows="15" cols="80" style="width: 100%">MCEcontent</textarea>';
		}

		$editor=str_replace('MCEname','content',$editor);
		$editor=str_replace('MCEcontent',MiceRestoreQuote('micefun',$results->getContent()),$editor);

		$summarstr=$results->getSummary();
		
		$summary=str_replace('MCEname','summary',$summary);
		$summary=str_replace('MCEcontent',MiceRestoreQuote('micefun',$summarstr),$summary);

		$ctype=CategoryType();

		if($article_id>0){
			$maimg_id=$article_id;
		}else{
			$maimg_id=0-date('His');
		}

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileAdmin');
		$smarty->assign('category_id',$category_id);
		$smarty->assign('maimg_id',$maimg_id);
		$smarty->assign('results',$results);
		$smarty->assign('usergroups',$usergroups);
		$smarty->assign('categorytype',$ctype);
		$smarty->assign('categorynames',$categorynames);
		$smarty->assign('categoryid1',$categoryid1);
		$smarty->assign('categoryid2',$categoryid2);
		$smarty->assign('categoryid3',$categoryid3);
		$smarty->assign('editor',$editor);
		$smarty->assign('summary',$summary);
		$smarty->assign('sql',$conn->lastsql);
		$smarty->assign('childcount',$childcount);
		$smarty->assign('index',MICE_URL.'admin.php/article');
		$smarty->assign('formaction',MICE_URL.'admin.php/article/updateArticle');
		$filename = new getTPLFileName(__CLASS__);
		$smarty->display($filename->TPLFileName);
	}
}
?>