<?php
/**
 *	Generated by miceCMS
 *	http://www.miceCMS.com/
 */
class menu_editAction extends security_login {
	function action(){
		ModuleLimit(__CLASS__);
		global $conn;
		$menu_id=$this->_getParam('menu_id');
		if($menu_id){
			$category=new model_Menu();
			$category->setSubsection('WHERE menu_id='.$menu_id);
			$results=$category->doSelectOne();
		}else{
			$results=new model_Menu();
		}

		$category2=new model_Menu();
		$category2->setSubsection('WHERE parentid=0 ORDER BY orderid');
		$results2=$category2->doSelect();

		$i=0;
		foreach($results2 as $rs2) {
			$categoryname[$i]["title"] = $rs2->getTitle();
			$categoryname[$i]["id"] = $rs2->getMenuId();
			$i++;
		}

		//菜单图标
		$mfiles=array();
		$m=0;
		include_once MICE_DIR.'/includes/filelist.php';
		$table_data=read_dir(MICE_DIR.MICE_TPL.'/admin/imgs/menu/',"file",true);
		foreach ($table_data as $key => $row){
			if(stripos($row['id'],'icon')===0){
				$mfiles[$m]['name']=$row['id'];
				$mfiles[$m]['filename']='imgs/menu/'.$row['id'];
				$m++;
			}
		}
		
		$editor='';
		//调用插件
		$plugin=new model_Plugin();
		$plugin->setSubsection('WHERE isopen=1 AND hook=\'editor_fast\' 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_fast', $plugins->getName());
				$editor=apply_filters('editor_fast',1);
				remove_filter('editor_fast', $plugins->getName());
			}
		}

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

		$editor=str_replace('MCEname','summary',$editor);
		$editor=str_replace('MCEcontent',str_replace("\r\n","",$results->getSummary()),$editor);

		

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileAdmin');
		$smarty->assign('results',$results);
		$smarty->assign('editor',$editor);
		$smarty->assign('categoryname',$categoryname);
		$smarty->assign('mfiles',$mfiles);
		$smarty->assign('sql',$conn->lastsql);
		$smarty->assign('index',MICE_URL.'admin.php/menu');
		$smarty->assign('formaction',MICE_URL.'admin.php/menu/update');
		$filename = new getTPLFileName(__CLASS__);
		$smarty->display($filename->TPLFileName);
	}
}
?>