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

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

		$filecategory2=new model_Filecategory();
		$filecategory2->setSubsection('WHERE type LIKE \'m%\' ORDER BY path ASC');
		$results2=$filecategory2->doSelect();

		$ctype=FilecategoryType();		//分类属性

		$i=0;
		foreach($results2 as $rs2) {
			$filecategoryname[$i]["title"] = StrRepeat("─",$rs2->getDepth()-1).$rs2->getTitle();
			$filecategoryname[$i]["id"] = $rs2->getFilecategoryId();
			$i++;
		}

		//分类
		$filecategory2=new model_Filecategory();
		$filecategory2->setSubsection('WHERE parentid=0 AND type LIKE \'m%\'');
		//$filecategoryrs=$filecategory2->doSelect();
		$childcount=$filecategory2->doCount();
		
		$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',MiceRestoreQuote('micefun',$results->getSummary()),$editor);

		$afiles=array();
		$cfiles=array();
		$ifiles=array();
		$a=0;
		$c=0;
		$i=0;
		include_once MICE_DIR.'/includes/filelist.php';
		$table_data=read_dir(MICE_DIR.MICE_TPL.'/index/',"file",true);
		foreach ($table_data as $key => $row){
			if(stripos($row['id'],'article')===0){
				$afiles[$a]['name']=$row['id'];
				$afiles[$a]['filename']='index/'.$row['id'];
				$a++;
			}elseif(stripos($row['id'],'list')===0){
				$cfiles[$c]['name']=$row['id'];
				$cfiles[$c]['filename']='index/'.$row['id'];
				$c++;
			}elseif(stripos($row['id'],'channel')===0){
				$ifiles[$i]['name']=$row['id'];
				$ifiles[$i]['filename']='index/'.$row['id'];
				$i++;
			}
		}

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileAdmin');
		$smarty->assign('results',$results);
		$smarty->assign('usergroups',$usergroups);
		$smarty->assign('editor',$editor);
		$smarty->assign('afiles',$afiles);
		$smarty->assign('cfiles',$cfiles);
		$smarty->assign('ifiles',$ifiles);
		$smarty->assign('filecategoryname',$filecategoryname);
		$smarty->assign('filecategorytype',$ctype);
		$smarty->assign('sql',$conn->lastsql);
		$smarty->assign('childcount',$childcount);
		$smarty->assign('index',MICE_URL.'admin.php/filecategory');
		$smarty->assign('formaction',MICE_URL.'admin.php/filecategory/update');
		$filename = new getTPLFileName(__CLASS__);
		$smarty->display($filename->TPLFileName);
	}
}
?>