<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	2011/6/5 Lay
*/

	//载入全局配置和函数包
	require '../../include/global.php';

	//module
	require 'function.php';

	$keys = $_GET["keys"];
	
	$hash = unserialize( authcrypt( $keys, VI_START, 'decode' ) );
	
	//exit(authcrypt( $keys, VI_START, 'decode' ));
	
	$do = getgpc('do');
	
	if( !$do ) $do = "Y";

?>
<!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(VI_BASE."style/share.css","utf-8",$_G['product']['version']);
?>
</head>

<body>

	<div id="wrapper">
    
    	<div id="header">
        	<h2>分享统计</h2>
        </div>
        
        <div id="main">
        	
            <?php
			
			if( !is_array($hash) ){
				
				echo '<p>无效链接！</p>';
				
			}elseif( time() - $hash['expire'] > $_G['setting']['global']['expire'] ){
			
				echo '<p>已过期链接！</p>';
			
			}else{
            ?>
                
                <p>
                    <strong><?php echo urldecode($hash['name']);?></strong>
                    （有效查看时间：<strong><?php echo date("Y-m-d H:i:s",$hash['expire']+$_G['setting']['global']['expire']);?></strong>）
                </p>
                
                <p>
                <?php
                
                echo '
                    <a'.($do!='Y'?' href="?do=Y&keys='.rawurlencode($keys):'').'">年份统计</a>
                    <a'.($do!='M'?' href="?do=M&keys='.rawurlencode($keys):'').'">月份统计</a>
                    <a'.($do!='D'?' href="?do=D&keys='.rawurlencode($keys):'').'">天统计</a>
                    <a'.($do!='H'?' href="?do=H&keys='.rawurlencode($keys):'').'">时段统计</a>
                ';
                ?>
                </p>
            
                <script language="JavaScript" src="../../source/fusionchart/JSClass/FusionCharts.js"></script>
                
                <?php
                include(VI_ROOT."source/fusionchart/Includes/FusionCharts.php");
                include(VI_ROOT."source/fusionchart/Includes/FC_Colors.php");
                ?>
            
                <?php
                
                //统计类型
                $type = $hash["type"];
                
                //统计标识
                $appkey = $hash["appkey"];
            
                //连接数据库
				System :: connect();                

                //广告名称
                if( $appkey && $do && $type ){
                
                    $sql="SELECT date,".$type." from `mod:analytic` WHERE appkey='".$appkey."' and category='".$do."'";
                    
                    if( in_array($type,array("views","clicks")) ){
                        $sql .=" and $type>0";
                    }
                    
                    //echo $sql;
                    
                    System :: $db -> query($sql);
                    $array = System :: $db -> fetchAll();
                }                
                
                //关闭数据库
				System :: connect();
                
                /*********************/
               
                //$array=Array ( 0 => Array ( 'key' => '', 'value' => 1 ) );
                
                $active = array( "Y"=>" 年", "M"=>" 月", "D"=>" 天", "H"=>" 时" );
                
                if( in_array($type,array("views","clicks")) ){
                    
                    $strXML = "<graph caption='".$name.$active[$do]." 统计' numberPrefix='' formatNumberScale='0' decimalPrecision='0' >";		
                    
                    foreach ($array as $arSubData){
                        $strXML .= "<set name='" . $arSubData["date"] .$active[$do]. "' value='" . $arSubData[$type]*$hash['multiple'] . "' colo='" .getFCColor() . "' />";
                    }
                    
                    $strXML .= "</graph>";
                    
                }else{
                    
                    $strXML = "<graph xaxisname='类别' yaxisname='Export' hovercapbg='DEDEBE' hovercapborder='889E6D' rotateNames='0' yAxisMaxValue='100' numdivlines='9' divLineColor='CCCCCC' divLineAlpha='80' decimalPrecision='0' showAlternateHGridColor='1' AlternateHGridAlpha='30' AlternateHGridColor='CCCCCC' caption='".$name.$active[$do]." 统计' subcaption='展示与点击效果报表'>";
                    
                        $strXML .= "<categories font='Arial' fontSize='11' fontColor='000000'>";
                        foreach ($array as $arSubData){
                            $strXML .= "<category name='" . $arSubData["date"] . "' />";
                        }				
                        $strXML .= "</categories>";				
                        
                        $strXML .= "<dataset seriesname='展示' color='" .getFCColor() . "'>";				
                        foreach ($array as $arSubData){
                            $strXML .= "<set value='" . $arSubData["views"]*$hash['multiple'] . "' />";
                        }				
                        $strXML .= "</dataset>";
                        
                        $strXML .= "<dataset seriesname='点击' color='" .getFCColor() . "'>";				
                        foreach ($array as $arSubData){
                            $strXML .= "<set value='" . $arSubData["clicks"]*$hash['multiple'] . "' />";
                        }				
                        $strXML .= "</dataset>";
        
                    $strXML .= "</graph>";
                    
                }
                
                switch($do){
                    
                    case "Y":
                        
                        if( in_array($type,array("views","clicks")) ){
                            //swf / xml / data / id / width / height
                            echo renderChart(VI_BASE."source/fusionchart/Charts/FCF_Column2D.swf", "", $strXML, "productSales", 700, 320);
                        }else{
                            echo renderChart(VI_BASE."source/fusionchart/Charts/FCF_MSColumn2D.swf", "", $strXML, "productSales", 700, 320);					
                        }
                    
                    break;
                    
                    case "M":
                        
                        if( in_array($type,array("views","clicks")) ){
                            //swf / xml / data / id / width / height
                            echo renderChart(VI_BASE."source/fusionchart/Charts/FCF_Column2D.swf", "", $strXML, "productSales", 700, 320);
                        }else{
                            echo renderChart(VI_BASE."source/fusionchart/Charts/FCF_MSColumn2D.swf", "", $strXML, "productSales", 700, 320);					
                        }
                    
                    break;
                    
                    case "D":
                        
                        if( in_array($type,array("views","clicks")) ){
                            //swf / xml / data / id / width / height
                            echo renderChart(VI_BASE."source/fusionchart/Charts/FCF_Column2D.swf", "", $strXML, "productSales", 700, 320);
                        }else{
                            echo renderChart(VI_BASE."source/fusionchart/Charts/FCF_MSColumn2D.swf", "", $strXML, "productSales", 700, 320);					
                        }
                    
                    break;
                    
                    case "H":
                        
                        if( in_array($type,array("views","clicks")) ){
                            //swf / xml / data / id / width / height
                            echo renderChart(VI_BASE."source/fusionchart/Charts/FCF_Line.swf", "", $strXML, "productSales", 700, 320);
                        }else{
                            echo renderChart(VI_BASE."source/fusionchart/Charts/FCF_MSLine.swf", "", $strXML, "productSales", 700, 320);					
                        }
                    break;			
                
                }
					
			}
			?>

        </div>
         
        <div id="adsense">        
        	<?php echo $_G['adsense']["share"];?>        
        </div>
       
    	<div id="footer">
                <?php echo $_G['project']['powered'];?>
                <?php echo $_G['product']['appname'];?>
                <?php echo $_G['product']['version'];?>
        </div>
    
    
    </div>

</body>
</html>