<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php 
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/check.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
	date_default_timezone_set('Asia/Shanghai');
	
	$now_month_start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
	$now_month_end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
	
	$last_month_start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y")));
	$last_month_end = date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y")));
	
	//反馈信息统计 start
	$f_now_month_sql = "select * from ls_pro_feedback where date between '".$now_month_start."' and '".$now_month_end."' and enable=1;";
	$f_now_month_query = $opendb->query($f_now_month_sql);
	$f_now_month = mysql_num_rows($f_now_month_query);  //本月
	
	$f_last_month_sql = "select * from ls_pro_feedback where date between '".$last_month_start."' and '".$last_month_end."' and enable=1;";
	$f_last_month_query = $opendb->query($f_last_month_sql);
	$f_last_month = mysql_num_rows($f_last_month_query);  //上月
	
	$feedback_sql = "select * from ls_pro_feedback where enable=1;";
	$feedback_query = $opendb->query($feedback_sql);
	$feedback_num = mysql_num_rows($feedback_query);  //总量
	
	//反馈信息统计 end
	
	//新闻更新统计 start
	$news_now_month_sql = "select * from ls_news where newsDate between '".$now_month_start."' and '".$now_month_end."' and enable=1;";
	$news_now_month_query = $opendb->query($news_now_month_sql);
	$news_now_month = mysql_num_rows($news_now_month_query);  //本月
	
	$news_last_month_sql = "select * from ls_news where newsDate between '".$last_month_start."' and '".$last_month_end."' and enable=1;";
	$news_last_month_query = $opendb->query($news_last_month_sql);
	$news_last_month = mysql_num_rows($news_last_month_query);  //上月
	
	$news_sql = "select * from ls_news where enable=1;";
	$news_query = $opendb->query($news_sql);
	$news_num = mysql_num_rows($feedback_query);  //总量
	
	//新闻更新统计 end
	
	//产品更新统计 start
	$products_now_month_sql = "select * from ls_products where date between '".$now_month_start."' and '".$now_month_end."' and productID NOT LIKE  'NULL' and enable=1;";
	$products_now_month_query = $opendb->query($products_now_month_sql);
	$products_now_month = mysql_num_rows($products_now_month_query);  //本月
	
	$products_last_month_sql = "select * from ls_products where date between '".$last_month_start."' and '".$last_month_end."' and productID NOT LIKE  'NULL' and enable=1;";
	$products_last_month_query = $opendb->query($products_last_month_sql);
	$products_last_month = mysql_num_rows($products_last_month_query);  //上月
	
	$products_sql = "select * from ls_products where productID NOT LIKE  'NULL' and enable=1;";
	$products_query = $opendb->query($products_sql);
	$products_num = mysql_num_rows($products_query);  //总量
	
	//产品更新统计 end
	
	//下载资源统计 start
	
	$download_times_sql = "select * from ls_download where enable=1;";
	$download_times_query = $opendb->query($download_times_sql);
	$download_times = 0;
	while($download_times_value = mysql_fetch_array($download_times_query)){
		$download_times += $download_times_value['downloadtimes'];
	}
	$download_t = $download_times;  //下载次数
	
	$download_sql = "select * from ls_download where enable=1;";
	$download_query = $opendb->query($download_sql);
	$download_num = mysql_num_rows($download_query);  //总量
	
	//下载资源统计 end
	
	function diffBetweenTwoDays($day1, $day2) {   
		$second1 = strtotime($day1);   
		$second2 = strtotime($day2);        
		if ($second1 < $second2) {     
			$tmp = $second2;     
			$second2 = $second1;     
			$second1 = $tmp;   
		}   
		return ($second1 - $second2) / 86400; 
	}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/admin.css" rel="stylesheet" type="text/css">
<title>蓝信科技网站管理</title>
<link rel="stylesheet" href="css/daterangepicker.css" />

<script src="js/jquery-1.4.2.min.js"></script>
<script src="js/moment.min.js"></script>
<script src="js/jquery.daterangepicker.js"></script>
<script src="js/echarts.js" language="JavaScript"></script>
<!--[if IE]>
<style>
.feedback { padding-left:36%; }
.col_left { padding-left:30%; }
.title_win { height:35px; }
.statistical_h { height:26px;}
.feedback_h { height:59px;}
.feedback_c a { display:block; }
</style>
<![endif]-->
<!--[if !IE]><!-->
<style>
.feedback { padding-left:36%; }
.col_left { padding-left:30%; }
.title_win { height:35px; }
.statistical_h { height:32px;}
.feedback_h { height:65px;}
.feedback_c a { display:block; }
</style>
<!--<![endif]--> 
</head>
<body>
<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#6396d6">
  <tr>
    <td height="20" background="images/admin_bg.gif"><div align="center"><font color="#ffffff" style="font-size:14px;"><strong>蓝信科技网站管理</strong></font></div></td>
  </tr>
  <tr>
    <td height="580" valign="top" bgcolor="#dee7ff"><br>
       <table width="96%" cellpadding="1" cellspacing="1" border="0" align="center">
          <tr>
            <td width="25%">
            	<table width="96%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
                    <tr class="title_win" bgcolor="#B9DAFF">
                      <td align="center" >反馈统计</td>
                    </tr>
                    <tbody id='ZH_59' >
                      <tr bgcolor='#f4f4f4'	>
                        <td>
                        	<table width="100%" border="0" cellpadding="1" cellspacing="1">
                              <tr>
                                <td align="center" style="padding:10px 0px;"><img src="images/feedback_ico.jpg" /></td>
                              </tr>
                              <tr>
                                <td class="feedback">本月：<?=$f_now_month?></td>
                              </tr>
                              <tr>
                                <td class="feedback">上月：<?=$f_last_month?></td>
                              </tr>
                              <tr>
                                <td class="feedback">总量：<?=$feedback_num?></td>
                              </tr>
                            </table>
                        </td>
                      </tr>
                    </tbody>
                  </table>
            </td>
            <td  width="25%">
            	<table width="96%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
                    <tr class="title_win"  bgcolor="#B9DAFF">
                      <td align="center" >新闻统计</td>
                    </tr>
                    <tbody id='ZH_59' >
                      <tr bgcolor='#f4f4f4'	>
                        <td>
                        	<table width="100%" border="0" cellpadding="1" cellspacing="1">
                              <tr>
                                <td align="center" style="padding:10px 0px;"><img src="images/news_ico.jpg" /></td>
                              </tr>
                              <tr>
                                <td class="col_left">本月更量：<?=$news_now_month?></td>
                              </tr>
                              <tr>
                                <td class="col_left">上月更量：<?=$news_last_month?></td>
                              </tr>
                              <tr>
                                <td class="col_left">总更新量：<?=$news_num?></td>
                              </tr>
                            </table>
                        </td>
                      </tr>
                    </tbody>
                  </table>
            </td>
            <td width="25%">
            	<table width="96%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
                    <tr class="title_win"  bgcolor="#B9DAFF">
                      <td align="center" >产品统计</td>
                    </tr>
                    <tbody id='ZH_59' >
                      <tr bgcolor='#f4f4f4'	>
                        <td>
                        	<table width="100%" border="0" cellpadding="1" cellspacing="1">
                              <tr>
                                <td align="center" style="padding:10px 0px;"><img src="images/products_ico.jpg" /></td>
                              </tr>
                              <tr>
                                <td class="col_left">本月更量：<?=$products_now_month?></td>
                              </tr>
                              <tr>
                                <td class="col_left">上月更量：<?=$products_last_month?></td>
                              </tr>
                              <tr>
                                <td class="col_left">总更新量：<?=$products_num?></td>
                              </tr>
                            </table>
                        </td>
                      </tr>
                    </tbody>
                  </table>
            </td>
            <td width="25%">
            	<table width="96%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
                    <tr class="title_win"  bgcolor="#B9DAFF">
                      <td align="center" >下载统计</td>
                    </tr>
                    <tbody id='ZH_59' >
                      <tr bgcolor='#f4f4f4'	>
                        <td>
                        	<table width="100%" border="0" cellpadding="1" cellspacing="1">
                              <tr>
                                <td align="center" style="padding:10px 0px;"><img src="images/download_ico.jpg" /></td>
                              </tr>
                              <tr>
                                <td class="col_left">&nbsp;</td>
                              </tr>
                              <tr>
                                <td class="col_left">下载次数：<?=$download_t?></td>
                              </tr>
                              <tr>
                                <td class="col_left">资源总数：<?=$download_num?></td>
                              </tr>
                            </table>
                        </td>
                      </tr>
                    </tbody>
                  </table>
            </td>
          </tr>
          <tr>
            <td colspan="4">&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2" valign="top">
            	<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
                    <tr class="title_win"  bgcolor="#B9DAFF">
                      <td align="center" width="10%">编号</td>
                      <td align="center" width="40%">年月</td>
                      <td align="center" width="50%">访问量</td>
                    </tr>
                    <?php
					for($i = 0; $i<8; $i++){
						$m_start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-$i,1,date("Y")));
						$m_end = date("Y-m-d H:i:s",mktime(23,59,59,date("m")-$i+1 ,0,date("Y")));
						
						$m_sql = "select * from ls_statistics where date between '".$m_start."' and '".$m_end."' and enable=1;";
						$m_query = $opendb->query($m_sql);
						$month = mysql_num_rows($m_query);  //每月访问量
					?>
                      <tr class="statistical_h" bgcolor='#f4f4f4'	onMouseOver=this.style.backgroundColor='#CCFFCC' onMouseOut=this.style.backgroundColor='#f4f4f4' >
                        <td align="center"><?=$i+1?></td>
                        <td align="center"><?=date("Y年m月",mktime(0, 0 , 0,date("m")-$i,1,date("Y")))?></td>
                        <td align="center"><?=$month?></td>
                      </tr>
                    <?php
					}
                    ?>
                    <tr bgcolor="#B9DAFF"> 
						<td height="25" colspan="3" align="center"></td>
					  </tr>
                  </table>
            </td>
            <td colspan="2" valign="top">
            	<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
                    <tr class="title_win"  bgcolor="#B9DAFF">
                      <td align="center" width="10%">编号</td>
                      <td align="center" width="90%">反馈信息</td>
                    </tr>
                     <?php
						$feedback_sql = "select * from ls_pro_feedback where enable=1 order by date desc limit 0, 3;";
						$feedback_query = $opendb->query($feedback_sql);
						while($feedback_value = mysql_fetch_array($feedback_query)){
					?>
                      <tr class="feedback_h" bgcolor='#f4f4f4'	onMouseOver=this.style.backgroundColor='#CCFFCC' onMouseOut=this.style.backgroundColor='#f4f4f4' >
                        <td align="center"><?=$feedback_value['ID']?></td>
                        <td class='feedback_c'>
                        <a href="ls_feedback.php#f_<?=$feedback_value['ID']?>" >
                            <div style="color:#777"><?=date('Y/m/d', strtotime($feedback_value['date']))?> by <?php echo $feedback_value['name']!=''?$feedback_value['name']:$feedback_value['company']?></div>
                            <?=mb_substr($feedback_value['requirement'],0,160, 'utf-8')?>..
                        </a>
						</td>
                      </tr>
                    <?php
					}
					?>
                    <tr bgcolor="#B9DAFF"> 
						<td height="25" colspan="3" align="center"></td>
					  </tr>
                  </table>
            </td>
          </tr>
          <tr>
            <td colspan="4">&nbsp;</td>
          </tr>
          <?php
		  		$startD = $_GET['startD1'];
				$endD = $_GET['endD1'];
				
				$i = 0;
				if($startD != '' && $endD != ''){
					$m_start = $startD;
					$m_end = $endD;
				}else{
					$m_start = date("Y-m-d",mktime(0, 0 , 0,date("m")-$i,1,date("Y")));
					$m_end = date("Y-m-d",time());
				}

				$d = round(diffBetweenTwoDays($m_start, $m_end));
				$c = round(diffBetweenTwoDays($m_end, date("Y-m-d",time())));
				
				$xAxis = "";
				$series = "";
				for($i = $d; $i>=0; $i--){
					
					$d_start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-$i-$c,date("Y")));
					$d_end = date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,date("d")-$i-$c,date("Y")));
					
					$d_sql = "select * from ls_statistics where date between '".$d_start."' and '".$d_end."' and enable=1;";
					$d_query = $opendb->query($d_sql);
					$day_n = mysql_num_rows($d_query);  //每日访问量
					
					$d_start = date("m-d",mktime(0, 0 , 0,date("m"),date("d")-$i-$c,date("Y")));
					
					if($i>0){
						$xAxis .= "\"".$d_start."\", ";
						$series .= $day_n.", ";
					}else{
						$xAxis .= "\"".$d_start."\"";
						$series .= $day_n;
					}
				}



		  		$startD2 = $_GET['startD2'];
				$endD2 = $_GET['endD2'];
				
				$i2 = 0;
				if($startD2 != '' && $endD2 != ''){
					$m_start2 = $startD2;
					$m_end2 = $endD2;
				}else{
					$m_start2 = date("Y-m-d",mktime(0, 0 , 0,date("m")-$i2,1,date("Y")));
					$m_end2 = date("Y-m-d",time());
				}

				$d2 = round(diffBetweenTwoDays($m_start2, $m_end2));
				$c2 = round(diffBetweenTwoDays($m_end2, date("Y-m-d",time())));
				
				$xAxis2 = "";
				$series2 = "";
				for($i2 = $d2; $i2>=0; $i2--){
					
					$d_start2 = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-$i2-$c2,date("Y")));
					$d_end2 = date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,date("d")-$i2-$c2,date("Y")));
					
					$d_sql2 = "select * from ls_pro_feedback where date between '".$d_start2."' and '".$d_end2."' and enable=1;";
					$d_query2 = $opendb->query($d_sql2);
					$day_n2 = mysql_num_rows($d_query2);  //每日反馈量
					
					$d_sql3 = "select * from ls_news where newsDate between '".$d_start2."' and '".$d_end2."' and enable=1;";
					$d_query3 = $opendb->query($d_sql3);
					$day_n3 = mysql_num_rows($d_query3);  //每日增加新闻量
					
					$d_sql4 = "select * from ls_products where date between '".$d_start2."' and '".$d_end2."' and enable=1;";
					$d_query4 = $opendb->query($d_sql4);
					$day_n4 = mysql_num_rows($d_query4);  //每日增加产品量
					
					$d_start2 = date("m-d",mktime(0, 0 , 0,date("m"),date("d")-$i2-$c2,date("Y")));
					
					if($i2>0){
						$xAxis2 .= "\"".$d_start2."\", ";
						$series2 .= $day_n2.", ";
						$series3 .= $day_n3.", ";
						$series4 .= $day_n4.", ";
					}else{
						$xAxis2 .= "\"".$d_start2."\"";
						$series2 .= $day_n2;
						$series3 .= $day_n3;
						$series4 .= $day_n4;
					}
				}
			?>
<script>
$(function()
{
	$('#date-range').dateRangePicker(
	{
		shortcuts : 
		{
			'prev-days': [3,5,7],
			'prev': ['week','month','year'],
			'next-days':null,
			'next':null
		},
		
		endDate: '<?=date("Y-m-d",time())?>',
		lookBehind: true,
		numid: 1,
		dataA1: '<?=$m_start?>',
		dataB1: '<?=$m_end?>',
		dataA2: '<?=$m_start2?>',
		dataB2: '<?=$m_end2?>'
	});
});
</script>
          <tr>
            <td colspan="4">
            	<table width="99%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
                    <tr class="title_win"  bgcolor="#B9DAFF">
                      <td style="padding-left:15px; font-size:14px;"><strong>访问量指标</strong></td>
                    </tr>
                     
                      <tr class="feedback_h" bgcolor='#f4f4f4'>
                        <td>
                        <div style="position:relative;">
                        	<input type="button" id="date-range" size="30" name="date-range" value="<?=$m_start?> 至 <?=$m_end?>" onclick="createDom()" style="position:absolute; top:6px; left:10px; z-index:10; font-size: 12px;
    padding: 4px 15px;
    line-height: 20px;
	color: #333;
    background-color: #fff;
	display: inline-block;
    font-weight: 400;
    text-align: center;
        white-space: nowrap;
    vertical-align: middle;
    -ms-touch-action: manipulation;
    touch-action: manipulation;
    cursor: pointer;
    border: 1px solid #999;
    border-radius: 4px;
	font-weight:bold;">
                        	<div id="main" style="width: 1100px;height:300px;"></div>
                        </div>
<script type="text/javascript">
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById('main'));
	
	// 指定图表的配置项和数据
	var option = {
		title: {
		},
		tooltip : {
			trigger: 'axis'
		},
		legend: {
			top: '5%',
			right: '6%',
			data:['访问量']
		},
		grid: {
			left: '3%',
			right: '4%',
			bottom: '3%',
			containLabel: true,
			backgroundColor: '#ccc'
		},
		toolbox: {
			feature: {
				saveAsImage: {}
			}
		},
		xAxis: {
			type : 'category',
			boundaryGap : false,
			data: [<?=$xAxis?>]
		},
		yAxis: {
			type : 'value'
		},
		series: [{
			name: '访问量',
			type: 'line',
			stack: '访问总量',
			label: {
				normal: {
					show: true,
					position: 'top'
				}
			},
			data: [<?=$series?>],
			smooth: true
		}],
		color: ['#c23531', '#314656', '#61a0a8', '#dd8668', '#91c7ae', '#6e7074', '#61a0a8', '#bda29a', '#44525d', '#c4ccd3']
	};
	
	myChart.showLoading();

    myChart.hideLoading();
    myChart.setOption(option);

</script>
                        </td>
                      </tr>
                    <tr bgcolor="#B9DAFF"> 
						<td height="25" colspan="3" align="center"></td>
					  </tr>
                  </table>
            </td>
          </tr>
          <tr>
            <td colspan="4">&nbsp;</td>
          </tr>
<script>
$(function()
{
	$('#date-range2').dateRangePicker(
	{
		shortcuts : 
		{
			'prev-days': [3,5,7],
			'prev': ['week','month','year'],
			'next-days':null,
			'next':null
		},
		
		endDate: '<?=date("Y-m-d",time())?>',
		lookBehind: true,
		numid: 2,
		dataA1: '<?=$m_start?>',
		dataB1: '<?=$m_end?>',
		dataA2: '<?=$m_start2?>',
		dataB2: '<?=$m_end2?>'
	});
});
</script>
          <tr>
            <td colspan="4">
            	<table width="99%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
                    <tr class="title_win"  bgcolor="#B9DAFF">
                      <td style="padding-left:15px; font-size:14px;"><strong>各项指标</strong></td>
                    </tr>
                     
                      <tr class="feedback_h" bgcolor='#f4f4f4'>
                        <td>
                        <div style="position:relative;">
                        	<input id="date-range2" type="button" size="30" name="date-range2" value="<?=$m_start2?> 至 <?=$m_end2?>"  style="position:absolute; top:6px; left:10px; z-index:10; font-size: 12px;
    padding: 4px 15px;
    line-height: 20px;
	color: #333;
    background-color: #fff;
	display: inline-block;
    font-weight: 400;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    -ms-touch-action: manipulation;
    touch-action: manipulation;
    cursor: pointer;
    border: 1px solid #999;
    border-radius: 4px;
	font-weight:bold;">
                        	<div id="main2" style="width: 1100px;height:300px;"></div>
                        </div>
<script type="text/javascript">
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById('main2'));
	
	// 指定图表的配置项和数据
	var option = {
		title: {
		},
		tooltip : {
			trigger: 'axis'
		},
		legend: {
			top: '5%',
			right: '6%',
			data:['反馈量', '新闻增量', '产品增量']
		},
		grid: {
			left: '3%',
			right: '4%',
			bottom: '3%',
			containLabel: true,
			backgroundColor: '#ccc'
		},
		toolbox: {
			feature: {
				saveAsImage: {}
			}
		},
		xAxis: {
			type : 'category',
			boundaryGap : false,
			data: [<?=$xAxis2?>]
		},
		yAxis: {
			type : 'value'
		},
		series: [{
			name: '反馈量',
			type: 'line',
			stack: '反馈总量',
			label: {
				normal: {
					show: true,
					position: 'top'
				}
			},
			data: [<?=$series2?>],
			smooth: true
		},{
                name: '新闻增量',
                type: 'line',
				stack: '新闻总量',
				label: {
					normal: {
						show: true,
						position: 'top'
					}
				},
                data: [<?=$series3?>],
				smooth: true
            },{
                name: '产品增量',
                type: 'line',
				stack: '产品总量',
				label: {
					normal: {
						show: true,
						position: 'top'
					}
				},
                data: [<?=$series4?>],
				smooth: true
            }],
		color: ['#ff0000', '#00a50c', '#0000ff', '#61a0a8', '#61a0a8', '#c4ccd3', '#6e7074',  '#dd8668', '#91c7ae', '#44525d']
	};
	
	myChart.showLoading();

    myChart.hideLoading();
    myChart.setOption(option);

</script>
                        </td>
                      </tr>
                    <tr bgcolor="#B9DAFF"> 
						<td height="25" colspan="3" align="center"></td>
					  </tr>
                  </table>
            </td>
          </tr>
        </table>
     </td>
  </tr>
</table>
</body>
</html>
