<?php
/**
 *	Generated by miceCMS
 *	http://www.miceCMS.com/
 */
class plugin_indexAction extends security_login {
	function action(){
		//接收参数并放入Session
		ModuleLimit(__CLASS__);
		$miceSession = new session();
		if($_POST['isopen']!=''){
			$miceSession->set('pi_isopen',$_POST['isopen']);
		}else{
			$miceSession->set('pi_isopen','2');
		}

		if($_POST['phook']){
			$miceSession->set('pi_phook',$_POST['phook']);
		}elseif($miceSession->get('pi_phook')<='0'){
			$miceSession->set('pi_phook','挂载点');
		}

		//查看所有插件文件
		include_once MICE_DIR.'/includes/filelist.php';
		include_once MICE_DIR.'/includes/plugin.php';
		$table_data=read_dir(MICE_DIR.'plugins/',"dir",true);
		$prs=array();
		$prhook=array();
		$prid=array();
		$i=0;
		foreach ($table_data as $key => $row)
		{
			if(file_exists(MICE_DIR.'plugins/'.$row['id'].'/index.php')) {
				$prs[$i]['id']=$row['id'];
				$pinfo=get_plugin_info(MICE_DIR.'plugins/'.$row['id'].'/index.php');
				$prs[$i]['plugin_hook']=$pinfo['plugin_hook'];
				$prs[$i]['plugin_name']=$pinfo['plugin_name'];
				$prs[$i]['author_name']=$pinfo['author_name'];
				$prs[$i]['version']=$pinfo['version'];
				$prs[$i]['plugin_uri']=$pinfo['plugin_uri'];
				$prs[$i]['description']=$pinfo['description'];

				$prhook[$i]=$pinfo['plugin_hook'];
				$prid[$i]=$row['id'];

				$plugin=new model_Plugin();
				$plugin->setSubsection('WHERE hook=\''.$pinfo['plugin_hook'].'\' AND name=\''.$row['id'].'\'');
				$plugins=$plugin->doSelectOne();
				if($plugins){
					$prs[$i]['isopen']=$plugins->getIsopen();
					$prs[$i]['pid']=$plugins->getPluginId();
					$prs[$i]['orderid']=$plugins->getOrderid();
					if($plugins->getIsopen()){
						$prs[$i]['status']='禁用';
					}else{
						$prs[$i]['status']='启用';
					}
				}else{
					$prs[$i]['isopen']=0;
					$prs[$i]['pid']=0;
					$prs[$i]['status']='启用';
				}
				$i++;
			}
		}
		array_multisort($prhook,SORT_ASC,$prid,SORT_ASC,$prs);		//按hook排序

		

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileAdmin');

		$smarty->assign('index',MICE_URL.'admin.php/plugin/index');
		$smarty->assign('edit',MICE_URL.'admin.php/plugin/edit/plugin_id/');
		$smarty->assign('change',MICE_URL.'admin.php/plugin/change/plugin_id/');
		$smarty->assign('delete',MICE_URL.'admin.php/plugin/delete/plugin_id/');

		$smarty->assign('phook',$miceSession->get('pi_phook'));
		$smarty->assign('isopen',$miceSession->get('pi_isopen'));

		$smarty->assign('results',$plugins);
		$smarty->assign('prs',$prs);
		$filename = new getTPLFileName(__CLASS__);
		$smarty->display($filename->TPLFileName);
	}
}
?>