<?php
	$tgl2=date("Y-m-d");
	$tgl_bawah2 = strtotime("-1 week +1 day",strtotime($tgl2));
	$hasil_tgl_bawah2 = date('Y-m-d', $tgl_bawah2);
	$tablestat = new PoTable('traffic');
    for ($i=3; $i <= 3; $i++){
      $tgl_pengujung = strtotime("+$i day",strtotime($hasil_tgl_bawah2));
      $hasil_tgl_pengujung = date('Y-m-d', $tgl_pengujung);
	  $currentStat3 = $tablestat->findStat(tanggal, $hasil_tgl_pengujung, ip);
    }
    for ($i=4; $i <= 4; $i++){
      $tgl_pengujung = strtotime("+$i day",strtotime($hasil_tgl_bawah2));
      $hasil_tgl_pengujung = date('Y-m-d', $tgl_pengujung);
	  $currentStat4 = $tablestat->findStat(tanggal, $hasil_tgl_pengujung, ip);
    }
    for ($i=5; $i <= 5; $i++){
      $tgl_pengujung = strtotime("+$i day",strtotime($hasil_tgl_bawah2));
      $hasil_tgl_pengujung = date('Y-m-d', $tgl_pengujung);
	  $currentStat5 = $tablestat->findStat(tanggal, $hasil_tgl_pengujung, ip);
    }
    for ($i=6; $i <= 6; $i++){
      $tgl_pengujung = strtotime("+$i day",strtotime($hasil_tgl_bawah2));
      $hasil_tgl_pengujung = date('Y-m-d', $tgl_pengujung);
	  $currentStat6 = $tablestat->findStat(tanggal, $hasil_tgl_pengujung, ip);
    }
?>

<?php
	$tgl3=date("Y-m-d");
	$tgl_bawah3 = strtotime("-1 week +1 day",strtotime($tgl3));
	$hasil_tgl_bawah3 = date('Y-m-d', $tgl_bawah3);
	$tablestatd = new PoTable('traffic');
    for ($i3=3; $i3 <= 3; $i3++){
      $tgl_hits = strtotime("+$i3 day",strtotime($hasil_tgl_bawah3));
      $hasil_tgl_hits = date('Y-m-d', $tgl_hits);
	  $sql_hits = $tablestatd->findStatd(hits, hitstoday, tanggal, $hasil_tgl_hits, tanggal);
	  if ($sql_hits==''){
		$sql_hits3='0';
	  }else{
		$sql_hits3=$sql_hits;
	  }
    }
    for ($i3=4; $i3 <= 4; $i3++){
      $tgl_hits = strtotime("+$i3 day",strtotime($hasil_tgl_bawah3));
      $hasil_tgl_hits = date('Y-m-d', $tgl_hits);
	  $sql_hits = $tablestatd->findStatd(hits, hitstoday, tanggal, $hasil_tgl_hits, tanggal);
	  if ($sql_hits==''){
		$sql_hits4='0';
	  }else{
		$sql_hits4=$sql_hits;
	  }
    }
    for ($i3=5; $i3 <= 5; $i3++){
      $tgl_hits = strtotime("+$i3 day",strtotime($hasil_tgl_bawah3));
      $hasil_tgl_hits = date('Y-m-d', $tgl_hits);
	  $sql_hits = $tablestatd->findStatd(hits, hitstoday, tanggal, $hasil_tgl_hits, tanggal);
	  if ($sql_hits==''){
		$sql_hits5='0';
	  }else{
		$sql_hits5=$sql_hits;
	  }
    }
    for ($i3=6; $i3 <= 6; $i3++){
      $tgl_hits = strtotime("+$i3 day",strtotime($hasil_tgl_bawah3));
      $hasil_tgl_hits = date('Y-m-d', $tgl_hits);
	  $sql_hits = $tablestatd->findStatd(hits, hitstoday, tanggal, $hasil_tgl_hits, tanggal);
	  if ($sql_hits==''){
		$sql_hits6='0';
	  }else{
		$sql_hits6=$sql_hits;
	  }
    }
?>

<script type="text/javascript">
$(document).ready(function () {
    var visitors = [[1, <?php echo $currentStat3; ?>], [2, <?php echo $currentStat4; ?>], [3, <?php echo $currentStat5; ?>], [4, <?php echo $currentStat6; ?>]];
    var hits = [[1, <?php echo $sql_hits3; ?>], [2, <?php echo $sql_hits4; ?>], [3, <?php echo $sql_hits5; ?>], [4, <?php echo $sql_hits6; ?>]];

    var plot = $.plot($(".chart"),
           [ { data: visitors, label: "visitors"}, { data: hits, label: "hits" } ], {
               series: {
                   lines: { show: true },
                   points: { show: true }
               },
               grid: { hoverable: true, clickable: true },
               yaxis: { min: 0, max: 500 },
			   xaxis: { min: 1, max: 4 }
             });

    function showTooltip(x, y, contents) {
        $('<div id="tooltip" class="tooltip">' + contents + '</div>').css( {
            position: 'absolute',
            display: 'none',
            top: y + 5,
            left: x + 5,
			'z-index': '9999',
			'color': '#fff',
			'font-size': '11px',
            opacity: 0.8
        }).appendTo("body").fadeIn(200);
    }

    var previousPoint = null;
    $(".chart").bind("plothover", function (event, pos, item) {
        $("#x").text(pos.x.toFixed(2));
        $("#y").text(pos.y.toFixed(2));

        if ($(".chart").length > 0) {
            if (item) {
                if (previousPoint != item.dataIndex) {
                    previousPoint = item.dataIndex;
                    
                    $("#tooltip").remove();
                    var x = item.datapoint[0].toFixed(2),
                        y = item.datapoint[1].toFixed(2);
                    
                    showTooltip(item.pageX, item.pageY,
                                item.series.label + " of " + x + " = " + y);
                }
            }
            else {
                $("#tooltip").remove();
                previousPoint = null;            
            }
        }
    });

    $(".chart").bind("plotclick", function (event, pos, item) {
        if (item) {
            $("#clickdata").text("You clicked point " + item.dataIndex + " in " + item.series.label + ".");
            plot.highlight(item.series, item.datapoint);
        }
    });
});
</script>