<?php

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

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

<!--body start-->

	<?php
    
    //loader
    loader_setting("naver.stats");
    
    echo loader_script(array(VI_BASE."js/mo.effect.js"),"utf-8",$Project["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 $Project;
		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;
		
        $result3=mysql_query($sql,$mysql);
		
		$Project["queries"]++;
        
        if(mysql_errno()){
            echo "
                <tr class='line'>
                <td colspan='8'><span class='text-key'>".loader_image("icon/warning.png")." 数据表 ".$table." 不存在</span></td>						
                </tr>";
        }else{
        
            $row3=mysql_fetch_assoc($result3);
            $user_count=$row3["row_count"];
            
            $Project["queries"]++;
            
            //栏目信息量
            $sql="select count(*) as row_count from $table where 1=1 $extra";	  	    		
            $result=mysql_query($sql,$mysql);
            $row=mysql_fetch_assoc($result);
            $channel_count=$row["row_count"];
            
            $Project["queries"]++;
            
            //个人信息百分比
            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($Project["module"].$appid.'/icon.png') ){
				$icon = '<img src="'.$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

    //mysql open
    reader_mysql();
    
    foreach($Project["stat"] as $table => $module){		
		
		//私有
		$private = ($table == "{TableManPre}admins"?"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
	
	//读取配置			   
	//require("cache/system/files.modules.php");	
    
    //var_dump( $VICACHE["sys.module"] );			
	 
	foreach($VICACHE["sys.module"] as $key=>$val){
		
		if ( $val["config"] ) {
            
            //配置地址
            $self = VI_ROOT.$val["config"];
			
			if( file_exists( $self ) && require( $self ) ){
            
                //搜索配置
                $sch = $Modules[$appid]["search"];
            
                if( is_array($sch) ){
            
				    SA($mysql,$appid,$Modules[$appid]["name"],$sch["table"],$sch["private"],$sch["where"]);
                
                }
			}
		}
	}
    
    //mysql close
    reader_mysql(true);
        
    ?>
    
    </table>
    
    <script type="text/javascript">var P = new Mo.Process();<?php echo $JS;?>P.Show();</script>
<!--body end-->

<?php html_close();?>