Path : /var/www/html/main/ap/statistic/
File Upload :
Current File : /var/www/html/main/ap/statistic/index.php

<?php
error_reporting(E_ALL);
ini_set("display_errors", 0);

if($_GET['nu']==""){
  include('../../head.php');

  $xsites = "$ap_site$ap_folder"."ap/statistic/";
  ?>
  <div class="body-main-row-body container theme-showcase" role="main">
    <div class="breadcrumbx">
      <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12">
          <ul class="breadcrumb" itemscope="" itemtype="http://schema.org/BreadcrumbList">
            <li itemprop="itemListElement" itemscope="" itemtype="http://schema.org/ListItem">
              <a href="<?php echo $_SERVER['SERVER_SCRIPT'] ?>?lang=<?php echo $_GET['lang'] ?>" itemprop="item">
                <span itemprop="name"><?php echo $ap_home; ?></span>
              </a>
              <meta itemprop="position" content="1">
            </li>
            <li itemprop="itemListElement" itemscope="" itemtype="http://schema.org/ListItem">
              <a href="<?php echo $xsites; ?>" itemprop="item">
                <span itemprop="name">สถิติ</span>
              </a>
              <meta itemprop="position" content="2">
            </li>
          </ul>
        </div>
      </div>

      <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12">
          <?php if(!empty($_COOKIE['lat'])){ ?><div id="map" style="width: 100%;height: 500px"></div><?php } ?>
          <p></p>
          <script>
          $(document).ready(function(){
            setInterval(function(){
              initMap();
            },300000);
          });

          var customLabel = {
            You: {
              label: 'A'
            }
          };

          var map;
          var directionsService;
          var directionsDisplay;

          function computeTotalDistance(result) {
            var total = 0;
            var myroute = result.routes[0];
            for (var i = 0; i < myroute.legs.length; i++) {
              total += myroute.legs[i].distance.value;
            }
            total = total / 1000;
            document.getElementById('total').innerHTML = total + ' km';
          }

          function initMap() {
            map = new google.maps.Map(document.getElementById('map'), {
              center: new google.maps.LatLng(<?php echo $_COOKIE['lat']?>,<?php echo $_COOKIE['lng']?>),
              mapTypeId: google.maps.MapTypeId.HYBRID,
              zoom: 8,
            });

            var trafficLayer = new google.maps.TrafficLayer();
            trafficLayer.setMap(map);

            directionsService = new google.maps.DirectionsService;
            directionsDisplay = new google.maps.DirectionsRenderer({
              draggable: true,
              suppressMarkers : true,
              map: map
            });
            directionsDisplay.addListener('directions_changed', function() {
              computeTotalDistance(directionsDisplay.getDirections());
            });

            var geocoder = new google.maps.Geocoder;
            var infoWindow = new google.maps.InfoWindow;

            downloadUrl('<?php echo $ap_site.$ap_folder;?>ap/statistic/markers.php?date=<?php echo $_GET['date']; ?>', function(data)
            {
              var xml = data.responseXML;
              var markers = xml.documentElement.getElementsByTagName('marker');
              Array.prototype.forEach.call(markers, function(markerElem) {
                var name = markerElem.getAttribute('name');
                var address = markerElem.getAttribute('address');
                var type = markerElem.getAttribute('type');
                var point = new google.maps.LatLng(
                    parseFloat(markerElem.getAttribute('lat')),
                    parseFloat(markerElem.getAttribute('lng'))
                );

                var infowincontent = document.createElement('div');
                var strong = document.createElement('strong');
                strong.textContent = name
                infowincontent.appendChild(strong);
                infowincontent.appendChild(document.createElement('br'));

                var text = document.createElement('text');
                text.textContent = address
                infowincontent.appendChild(text);
                var icon = customLabel[type] || {};
                var marker = new google.maps.Marker({
                  map: map,
                  position: point,
                  label: icon.label
                });
                marker.addListener('click', function() {
                  infoWindow.setContent(infowincontent);
                  infoWindow.open(map, marker);
                });
              });
            });
          }

          function downloadUrl(url, callback) {
            var request = window.ActiveXObject ?
                new ActiveXObject('Microsoft.XMLHTTP') :
                new XMLHttpRequest;

            request.onreadystatechange = function() {
              if (request.readyState == 4) {
                request.onreadystatechange = doNothing;
                callback(request, request.status);
              }
            };

            request.open('GET', url, true);
            request.send(null);
          }

          function doNothing() {}
          </script>
          <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCFfrtIXXeUtabOdKthKxVy6R5pl7IXRQ0&libraries=places&callback=initMap"></script>
        </div>
      </div>

      <?php
      $sql = "select * from ap_counters where lang='$_GET[lang]'";
      $query = mysqli_query($conn,$sql);
      $num_rows = mysqli_num_rows($query);
      $rows2 = mysqli_fetch_array(mysqli_query($conn,"select count(id) as total from ap_counters where lang='$_GET[lang]' and xyear='".date('Y')."'"));
      $num_rows2 = $rows2['total'];
      $rows2_1 = mysqli_fetch_array(mysqli_query($conn,"select count(id) as total from ap_counters where lang='$_GET[lang]' and  xyear='".date('Y',strtotime("-1 year"))."'"));
      $num_rows2_1 = $rows2_1['total'];
      $rows3 = mysqli_fetch_array(mysqli_query($conn,"select count(id) as total from ap_counters where lang='$_GET[lang]' and  xmonth='".date('Ym')."'"));
      $num_rows3 = $rows3['total'];
      $rows3_1 = mysqli_fetch_array(mysqli_query($conn,"select count(id) as total from ap_counters where lang='$_GET[lang]' and  xmonth='".date('Ym',strtotime("-1 month"))."'"));
      $num_rows3_1 = $rows3_1['total'];
      $rows4 = mysqli_fetch_array(mysqli_query($conn,"select count(id) as total from ap_counters where lang='$_GET[lang]' and  xday='".date('Ymd')."'"));
      $num_rows4 = $rows4['total'];
      $rows4_1 = mysqli_fetch_array(mysqli_query($conn,"select count(id) as total from ap_counters where lang='$_GET[lang]' and  xday='".date('Ymd',strtotime("-1 day"))."'"));
      $num_rows4_1 = $rows4_1['total'];

      $sql .= " group by xyear order by xyear asc";
      $query = mysqli_query($conn,$sql);
      while($rows = mysqli_fetch_array($query)){
        $rows2x = mysqli_fetch_array(mysqli_query($conn,"select count(id) as total from ap_counters where lang='$_GET[lang]' and xyear='$rows[xyear]'"));
        $num_rows2x = $rows2x['total'];
        $y .= $rows['xyear'].",";
        $yn .= number_format((($num_rows2x*100)/$num_rows),2).",";
      }
      $y = substr($y,0,-1);
      $yn = substr($yn,0,-1);
      ?>
      <script src="<?php echo "$ap_site$ap_folder"; ?>js/jquery.min.js"></script>
      <script src="<?php echo "$ap_site$ap_folder"; ?>bower_components/chart.js/Chart.js"></script>
    
      <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-12">
          <ul class="list-group">
            <li class="list-group-item active">
              <span class="badge"><?php echo number_format($num_rows+$visit_counters);?></span>
              <font color="#fff">สถิติผู้เข้าชมเว็บไซต์</font>
            </li>
            <li class="list-group-item">
              <span class="badge"><?php echo number_format($num_rows2);?></span>
              ปีนี้
            </li>
            <li class="list-group-item">
              <span class="badge"><?php echo number_format($num_rows2_1+$visit_counters);?></span>
              ปีที่แล้ว
            </li>
            <li class="list-group-item">
              <span class="badge"><?php echo number_format($num_rows3);?></span>
              เดือนนี้
            </li>
            <li class="list-group-item">
              <span class="badge"><?php echo number_format($num_rows3_1);?></span>
              เดือนที่แล้ว
            </li>
            <li class="list-group-item">
              <span class="badge"><?php echo number_format($num_rows4);?></span>
              วันนี้
            </li>
            <li class="list-group-item">
              <span class="badge"><?php echo number_format($num_rows4_1);?></span>
              เมื่อวานนี้
            </li>
            <li style="display: none" class="list-group-item">
              <span class="badge" id="usersOnline">0</span>
              ขณะนี้
            </li>
            <a href="#" class="list-group-item disabled">
            <center><?php echo $date_counters;?></center>
            </a>
          </ul>
        </div>
        <div class="col-lg-6 col-md-6 col-sm-12">
          <div style="width:100%">
            <canvas id="canvas" height="200"></canvas>
          </div>
        </div>
      </div>
      <p></p>
      
      <script>
      var barChartData = {
        labels : [<?php echo $y; ?>],
        datasets : [
          <?php /* ?>{
            fillColor : "rgba(220,220,220,0.5)",
            strokeColor : "rgba(220,220,220,0.8)",
            highlightFill: "rgba(220,220,220,0.75)",
            highlightStroke: "rgba(220,220,220,1)",
            data : [<?php echo $yn; ?>]
          },<?php */ ?>
          {
            fillColor : "rgba(151,187,205,0.5)",
            strokeColor : "rgba(151,187,205,0.8)",
            highlightFill : "rgba(151,187,205,0.75)",
            highlightStroke : "rgba(151,187,205,1)",
            data : [<?php echo $yn; ?>]
          }
        ]
      }
      window.onload = function(){
        var ctx = document.getElementById("canvas").getContext("2d");
        window.myBar = new Chart(ctx).Bar(barChartData, {
          responsive : true
        });
      }
      </script>
    </div>
  </div>
  <?php
  include('../../footText.php');
  include('../../foot.php');
}

if($_GET['nu']=="statistic"){
  include('../../ap.php');
  $headers = array("Content-Type: application/json", "Method: GET", "Token: ");
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, "$ap_site$ap_folder"."api.php?nu=statistic&q2=$_POST[q2]");
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $data = curl_exec($ch);
  curl_close($ch);
  $json = json_decode($data, true);
  $json_total = count($json);
  ?>
  <?php /* ?>ผู้เข้าชมทั้งหมด <span class="badge"><a href="<?php echo $ap_site.$ap_folder?>ap/statistic/" target="_blank"><font color="#ffffff"><?php echo number_format($json['0']['total']+$_POST['q']); ?></font></a></span><?php */ ?>
  
  <?php /* ?><p class="counter-count"><?php echo $json['0']['total']+$_POST['q']; ?></p>
  <style type="text/css">
  .counter{
    background-color: #eaecf0;
    text-align: center;
  }
  .employees,.customer,.design,.order{
    margin-top: 70px;
    margin-bottom: 70px;
  }
  .counter-count{
    font-size: 18px;
    background-color: #00b3e7;
    border-radius: 50%;
    position: relative;
    color: #ffffff;
    text-align: center;
    line-height: 92px;
    width: 92px;
    height: 92px;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    -ms-border-radius: 50%;
    -o-border-radius: 50%;
    display: inline-block;
  }
  .employee-p,.customer-p,.order-p,.design-p{
    font-size: 24px;
    color: #000000;
    line-height: 34px;
  }
  </style>
  <script type="text/javascript">
  $('.counter-count').each(function () {
    $(this).prop('Counter',0).animate({
      Counter: $(this).text()
    }, {
      duration: 5000,
      easing: 'swing',
      step: function (now) {
          $(this).text(Math.ceil(now));
      }
    });
  });
  </script><?php */ ?>

  ผู้เข้าชมทั้งหมด <a href="<?php echo $ap_site.$ap_folder?>ap/statistic/" target="_blank"><span class="badge timer count-number" data-to="<?php echo ($json['0']['total']+$_POST['q']); ?>" data-speed="1500"></span></a><p></p>
  <?php /* ?><link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css">
  <div class="container">
    <div class="row">
      <br/>
      <div class="col text-center">
        <h2>Bootstrap 4 counter</h2>
        <p>counter to count up to a target number</p>
      </div>
    </div>
    <div class="row text-center">
      <div class="col">
        <div class="counter">
          <i class="fa fa-code fa-2x"></i>
          <h2 class="timer count-title count-number" data-to="100" data-speed="1500"></h2>
          <p class="count-text ">Our Customer</p>
        </div>
      </div>
      <div class="col">
        <div class="counter">
          <i class="fa fa-coffee fa-2x"></i>
          <h2 class="timer count-title count-number" data-to="1700" data-speed="1500"></h2>
          <p class="count-text ">Happy Clients</p>
        </div>
      </div>
      <div class="col">
        <div class="counter">
          <i class="fa fa-lightbulb-o fa-2x"></i>
          <h2 class="timer count-title count-number" data-to="11900" data-speed="1500"></h2>
          <p class="count-text ">Project Complete</p>
        </div>
      </div>
      <div class="col">
        <div class="counter">
          <i class="fa fa-bug fa-2x"></i>
          <h2 class="timer count-title count-number" data-to="157" data-speed="1500"></h2>
          <p class="count-text ">Coffee With Clients</p>
        </div>
      </div>
    </div>
  </div><?php */ ?>
  <style type="text/css">
  .counter {
      background-color:#f5f5f5;
      padding: 20px 0;
      border-radius: 5px;
  }
  .count-title {
      font-size: 40px;
      font-weight: normal;
      margin-top: 10px;
      margin-bottom: 0;
      /*text-align: center;*/
  }
  .count-text {
      font-size: 13px;
      font-weight: normal;
      margin-top: 10px;
      margin-bottom: 0;
      text-align: center;
  }
  .fa-2x {
      margin: 0 auto;
      float: none;
      display: table;
      color: #4ad1e5;
  }
  </style>
  <script type="text/javascript">
  (function ($) {
    $.fn.countTo = function (options) {
      options = options || {};
      
      return $(this).each(function () {
        // set options for current element
        var settings = $.extend({}, $.fn.countTo.defaults, {
          from: $(this).data('from'),
          to: $(this).data('to'),
          speed: $(this).data('speed'),
          refreshInterval: $(this).data('refresh-interval'),
          decimals: $(this).data('decimals')
        }, options);
        
        // how many times to update the value, and how much to increment the value on each update
        var loops = Math.ceil(settings.speed / settings.refreshInterval),
        increment = (settings.to - settings.from) / loops;
        
        // references & variables that will change with each update
        var self = this,
          $self = $(this),
          loopCount = 0,
          value = settings.from,
          data = $self.data('countTo') || {};
        
        $self.data('countTo', data);
        
        // if an existing interval can be found, clear it first
        if (data.interval) {
          clearInterval(data.interval);
        }
        data.interval = setInterval(updateTimer, settings.refreshInterval);
        
        // initialize the element with the starting value
        render(value);
        
        function updateTimer() {
          value += increment;
          loopCount++;
          
          render(value);
          
          if (typeof(settings.onUpdate) == 'function') {
            settings.onUpdate.call(self, value);
          }
          
          if (loopCount >= loops) {
            // remove the interval
            $self.removeData('countTo');
            clearInterval(data.interval);
            value = settings.to;
            
            if (typeof(settings.onComplete) == 'function') {
              settings.onComplete.call(self, value);
            }
          }
        }
        
        function render(value) {
          var formattedValue = settings.formatter.call(self, value, settings);
          $self.html(formattedValue);
        }
      });
    };
    
    $.fn.countTo.defaults = {
      from: 0,               // the number the element should start at
      to: 0,                 // the number the element should end at
      speed: 1000,           // how long it should take to count between the target numbers
      refreshInterval: 100,  // how often the element should be updated
      decimals: 0,           // the number of decimal places to show
      formatter: formatter,  // handler for formatting the value before rendering
      onUpdate: null,        // callback method for every time the element is updated
      onComplete: null       // callback method for when the element finishes updating
    };
    
    function formatter(value, settings) {
      return value.toFixed(settings.decimals);
    }
  }(jQuery));

  jQuery(function ($) {
    // custom formatting example
    $('.count-number').data('countToOptions', {
    formatter: function (value, options) {
      return value.toFixed(options.decimals).replace(/\B(?=(?:\d{3})+(?!\d))/g, ',');
    }
    });
    
    // start all the timers
    $('.timer').each(count);  
    
    function count(options) {
    var $this = $(this);
    options = $.extend({}, options || {}, $this.data('countToOptions') || {});
    $this.countTo(options);
    }
  });
  </script>

<?php
}

if($_GET['nu']=="statistic2"){
  include('../../ap.php');
  $headers = array("Content-Type: application/json", "Method: GET", "Token: ");
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, "$ap_site$ap_folder"."api.php?nu=statistic&q2=$_POST[q2]");
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $data = curl_exec($ch);
  curl_close($ch);
  $json = json_decode($data, true);
  $json_total = count($json);
  ?>
  <div class="">
    <div class="text-center">
      <div class="counter">
        <h2 class="timer count-title count-number" data-to="<?php echo ($json['0']['total']+$_POST['q']); ?>" data-speed="1500"></h2>
        <p class="count-text ">Visitors</p>
      </div>
    </div>
  </div>
  <dir class="pt-3"></dir>
  <?php /* ?><link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css">
  <div class="container">
    <div class="row">
      <br/>
      <div class="col text-center">
        <h2>Bootstrap 4 counter</h2>
        <p>counter to count up to a target number</p>
      </div>
    </div>
    <div class="row text-center">
      <div class="col">
        <div class="counter">
          <i class="fa fa-code fa-2x"></i>
          <h2 class="timer count-title count-number" data-to="100" data-speed="1500"></h2>
          <p class="count-text ">Our Customer</p>
        </div>
      </div>
      <div class="col">
        <div class="counter">
          <i class="fa fa-coffee fa-2x"></i>
          <h2 class="timer count-title count-number" data-to="1700" data-speed="1500"></h2>
          <p class="count-text ">Happy Clients</p>
        </div>
      </div>
      <div class="col">
        <div class="counter">
          <i class="fa fa-lightbulb-o fa-2x"></i>
          <h2 class="timer count-title count-number" data-to="11900" data-speed="1500"></h2>
          <p class="count-text ">Project Complete</p>
        </div>
      </div>
      <div class="col">
        <div class="counter">
          <i class="fa fa-bug fa-2x"></i>
          <h2 class="timer count-title count-number" data-to="157" data-speed="1500"></h2>
          <p class="count-text ">Coffee With Clients</p>
        </div>
      </div>
    </div>
  </div><?php */ ?>
  <style type="text/css">
  .counter {
      background-color:#f5f5f5;
      padding: 20px 0;
      border-radius: 5px;
  }
  .count-title {
      font-size: 40px;
      font-weight: normal;
      margin-top: 10px;
      margin-bottom: 0;
      /*text-align: center;*/
  }
  .count-text {
      font-size: 13px;
      font-weight: normal;
      margin-top: 10px;
      margin-bottom: 0;
      text-align: center;
  }
  .fa-2x {
      margin: 0 auto;
      float: none;
      display: table;
      color: #4ad1e5;
  }
  </style>
  <script type="text/javascript">
  (function ($) {
    $.fn.countTo = function (options) {
      options = options || {};
      
      return $(this).each(function () {
        // set options for current element
        var settings = $.extend({}, $.fn.countTo.defaults, {
          from: $(this).data('from'),
          to: $(this).data('to'),
          speed: $(this).data('speed'),
          refreshInterval: $(this).data('refresh-interval'),
          decimals: $(this).data('decimals')
        }, options);
        
        // how many times to update the value, and how much to increment the value on each update
        var loops = Math.ceil(settings.speed / settings.refreshInterval),
        increment = (settings.to - settings.from) / loops;
        
        // references & variables that will change with each update
        var self = this,
          $self = $(this),
          loopCount = 0,
          value = settings.from,
          data = $self.data('countTo') || {};
        
        $self.data('countTo', data);
        
        // if an existing interval can be found, clear it first
        if (data.interval) {
          clearInterval(data.interval);
        }
        data.interval = setInterval(updateTimer, settings.refreshInterval);
        
        // initialize the element with the starting value
        render(value);
        
        function updateTimer() {
          value += increment;
          loopCount++;
          
          render(value);
          
          if (typeof(settings.onUpdate) == 'function') {
            settings.onUpdate.call(self, value);
          }
          
          if (loopCount >= loops) {
            // remove the interval
            $self.removeData('countTo');
            clearInterval(data.interval);
            value = settings.to;
            
            if (typeof(settings.onComplete) == 'function') {
              settings.onComplete.call(self, value);
            }
          }
        }
        
        function render(value) {
          var formattedValue = settings.formatter.call(self, value, settings);
          $self.html(formattedValue);
        }
      });
    };
    
    $.fn.countTo.defaults = {
      from: 0,               // the number the element should start at
      to: 0,                 // the number the element should end at
      speed: 1000,           // how long it should take to count between the target numbers
      refreshInterval: 100,  // how often the element should be updated
      decimals: 0,           // the number of decimal places to show
      formatter: formatter,  // handler for formatting the value before rendering
      onUpdate: null,        // callback method for every time the element is updated
      onComplete: null       // callback method for when the element finishes updating
    };
    
    function formatter(value, settings) {
      return value.toFixed(settings.decimals);
    }
  }(jQuery));

  jQuery(function ($) {
    // custom formatting example
    $('.count-number').data('countToOptions', {
    formatter: function (value, options) {
      return value.toFixed(options.decimals).replace(/\B(?=(?:\d{3})+(?!\d))/g, ',');
    }
    });
    
    // start all the timers
    $('.timer').each(count);  
    
    function count(options) {
    var $this = $(this);
    options = $.extend({}, options || {}, $this.data('countToOptions') || {});
    $this.countTo(options);
    }
  });
  </script>
<?php
}
?>