<?php

/*

		系统模块列表

*/

//载入全局配置和函数包
require_once dirname(__FILE__).'/../include/global.php';

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $_G['product']['charset'];?>" />
<title>添加插件 - Powered By VeryIDE</title>

<?php

echo loader_style(array(VI_BASE."style/dialog.css"),$_G['product']['charset'],$_G['product']['version']);

echo loader_script(array(VI_BASE."js/mo.js",VI_BASE."js/serv.dialog.js"),"utf-8",$_G['product']['version']);

?>

<script>

Mo.reader(function(){

	//高亮选中主题
	Mo("#module button").bind( 'click', function( index , e ){
			
		switch( this.className ){
				
			//新添加
			case "":
	
				this.innerHTML = '取消';
				this.className = 'added';
				
				//保存设置
				parent.Serv.Addons.added( Mo(this).attr("appid") );
					
			break;                        
			
			 //删除插件
			case "added":
	
				this.innerHTML = '添加';
				this.className = '';                                 
				
				//保存设置
				parent.Serv.Addons.remove( Mo(this).attr("appid") );
	
			break;
		
		}

	});
	
	//主框架载入事件
	Serv.Manager.Loaded();

});

</script>

</head>

<body>

    <div id="wrapper">

        <?php
    
        //未登录
        if( !$_SESSION['Manager']['id'] ){    
            exit('<div id="state" class="failure">未登录，请先登录！</div>');
        }
    
        ?>
        
        <ul id="naver">
            <li class="menu"><a href="http://www.veryide.com/projects/bee/module.htm" target="_blank">开发手册</a></li>
            <li><a href="module.php" ext-hash="true">快捷方式</a></li>
            <li><a href="widget.php" ext-hash="true">小工具</a></li>
            <li><a href="quick.php" ext-hash="true">排序</a></li>
        </ul>
    
        <ul id="module">
        
        <?php
		if( count( $_CACHE['system']['module'] ) == 0 ){
		?>
        
        	<p>
                <button class="submit" type="button" onclick="parent.Serv.Apps.open('system','模块管理','calculator','system.module.php');parent.Serv.store.module.Remove();">模块搜索</button>
            </p>
            
        <?php
		}
		?>
    
        <?php
        
        //连接数据库
        System :: connect();
        
        //插件列表
        
        $sql="SELECT appid from `sys:quick` WHERE aid = '".$_SESSION['Manager']['id']."'";
        
        $res = System :: $db -> getAll( $sql );
        
        foreach( $res as $key => $val ){                
                $addon[] = $val["appid"];
        }        
        
        ///////////////////////////////////////////////////
        
        $i = 1;
    
        //遍历模块
        foreach( $_CACHE['system']['module'] as $appid => $config ){
        
            //配置文件
            $self = VI_ROOT.$config['config'];
    
            //加载配置
            if ( $config["state"] && $config['config'] && file_exists( $self ) && require($self) ) {
            
                $app = $_G['module'][$appid];
                
                //只显示“应用模块”
                if( $app['model'] != "module") continue;
                
                echo '<li'.( $i % 2 == 0 ? ' class="zebra"' : '' ).'>';
                
                echo '
                    <div class="icon">
                        <img src="'.VI_BASE.'module/'.$appid.'/icon.png" />
                    </div>';
                    
                echo '<div class="name">
                        <strong>'.$app["name"].'</strong> '.( $app["version"] ? '<span>'.$app["version"].'</span>' : '' ).'
                        <br />
                        '.$app["describe"].'
                    </div>';
                    
                echo '<div class="site">
                        '.$app["author"].'
                        <br />
                        <a href="'.$_G['project']['home'].'guide.php?appid='.$appid.'" target="_blank">使用手册</a>
                    </div>';
                    
                echo '<div class="plus">';
                
					if( is_array( $addon ) && in_array( $appid , $addon ) ){                        
						echo '<button appid="'.$appid.'" type="button" class="added">取消</button>';                        
					}else{                        
						echo '<button appid="'.$appid.'"type="button">添加</button>';                        
					}
                        
                echo '</div>';
                    
                echo '</li>';
                
                $i++;
    
            }
        }
    
        //关闭数据库
        System :: connect();
    
        ?>
    
        </ul>
        
    </div>
    
</body>
</html>