<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	$Id: veryide_welcome.php,v2 19:47 2008-2-18 Lay $
*/

require '../../include/loader.php';
html_start("统计信息 - VeryIDE");
?>

<!--body start-->

	<?php
    
    //loader
    require('include/naver.stats.php');
    
    echo loader_script(array(VI_BASE."js/mo.effect.js"),"utf-8",$_G['product']['version']);
	
    ?>
    
    <table width="100%" border="0" cellpadding="1" cellspacing="1" class="table">
    <tr class="title">
    	<td></td>
        <td>AppID</td>
        <td>所在表</td>
        <td>模块名称</td>
        <td>表数据总量</td>
        <td>个人占有量</td>
        <td>个人占有率</td>
        <td></td>
    </tr>
    <tr class="item">
        <td colspan="7"><?php echo loader_image("icon/gear.png");?> 系统数据（表前辍：<em><?php echo VI_DBMANPRE;?></em>）</td>
    </tr>
    
    <?php
	/*
		$mysql		MySQL 链接
		$appid		模块ID
		$module		名称
		$table		表名
		$private	私有统计
		$extra		扩展
	*/
	function SA($mysql,$appid,$module,$table,$private,$extra=""){
		global $_G;
		global $JS;
		
		$tmp = $table;
		
        $table = format_table($table);
		
		//echo $module;
    
        //个人信息量
        $sql="SELECT count(*) as row_count from ".$table." WHERE 1=1 ";
		
		if( $private ){
			$sql .= " and ".$private;
		}
		
		$sql .= $extra;
        
        if(mysql_errno()){
            echo "
                <tr class='line'>
                <td colspan='8'><span class='text-key'>".loader_image("icon/warning.png")." 数据表 ".$table." 不存在</span></td>						
                </tr>";
        }else{
        
            $user_count = System :: $db -> getValue( $sql );
            
            
            
            //栏目信息量
            $sql="SELECT count(*) as row_count from $table WHERE 1=1 $extra";	  	    		
            $channel_count = System :: $db -> getValue( $sql );
            
            
            
            //个人信息百分比
            if($channel_count>0){
                $percent_count=number_format(($user_count/$channel_count)*100,2);
            }else{
                $percent_count=0;
            }
			
			$ID = rand_string(5);
			
			$JS .= 'var G = new P.Group("'.$ID.'");';
			
			//个人
			$JS .= 'G.Option("'.$ID.'",'.$user_count.');';
			
			//差余
			$JS .= 'G.Option(null,'.($channel_count-$user_count).');';
			
			        
			if( file_exists($_G['project']['module'].$appid.'/icon.png') ){
				$icon = '<img src="'.$_G['project']['module'].$appid.'/icon.png" />';
			}else{
				$icon = '';
			}
            
            echo "
                <tr class='line'>
                <td width='30'>".$icon."</td>
				<td>".str_replace(array("{TableManPre}","{TableModPre}"),array("",""),$appid)."</td>
                <td>".$table."</td>
                <td>".$module."</td>
                <td class='".($channel_count?'text-yes':'')."'>$channel_count</td>
                <td class='".($user_count?'text-yes':'')."'>$user_count</td>						
                <td class='".($percent_count==100?'text-key':'')."' id='percent-".$ID."'>".$percent_count."%</td>
                <td width='100'>
					<div class='ratio'><span id='option-".$ID."' style='background-color:".rand_color().";'></span></div>
				</td>
                </tr>
				";
            $i++;
			
        }
		
	}
	
	?>
    
    <?php

    //连接数据库
        System :: connect();
    
    foreach($_G['project']['stat'] as $table => $module){		
		
		//私有
		$private = ($table == "{TableManPre}admin"?"id":"aid") ." = ". $_SESSION['Manager']['id'];
		
        SA($mysql,$table,$module,$table,$private);
    }
	
	?>
    <tr class="item">
        <td colspan="8"><?php echo loader_image("icon/box.png");?> 模块数据（表前辍：<em><?php echo VI_DBMODPRE;?></em>）</td>
    </tr>
    
    <?php
	
	//读取配置			   
	foreach($_CACHE['system']['module'] as $key=>$val){
		
		if ( $val["config"] ) {
            
            //配置地址
            $self = VI_ROOT.$val["config"];
			
			if( file_exists( $self ) && require( $self ) ){
            
                //搜索配置
                $sch = $_G['module'][$key]['search'];
            
                if( is_array($sch) ){
            
				    SA($mysql,$appid,$_G['module'][$key]['name'],$sch["table"],$sch["private"],$sch["where"]);
                
                }
			}
		}
	}
    
	//关闭数据库
	System :: connect();
        
    ?>
    
    </table>
    
    <script type="text/javascript">var P = new Mo.Process();<?php echo $JS;?>P.Show();</script>
<!--body end-->

<?php html_close();?>