index.php 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. session_start();
  3. $http_host = $_SERVER["HTTP_HOST"];
  4. $doc_root = $_SERVER["DOCUMENT_ROOT"] . "/";
  5. include $doc_root . "functions.php";
  6. $proto = get_protocol();
  7. $lang = "en";
  8. $con = start_db();
  9. $server = $proto . $http_host;
  10. $pserver = $proto . substr($http_host, 0, strpos($http_host, ':')); // public server
  11. if (!check_session($con)){
  12. http_response_code(401);
  13. header("Location: /authentication.php");
  14. }
  15. else{
  16. ?>
  17. <html>
  18. <head>
  19. <meta content='text/html; charset=windows-1252' http-equiv='content-type'/>
  20. <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1'>
  21. <link rel='shortcut icon' href='<?=$pserver?>/img/logo/x2/favicon.ico'/>
  22. <title><?=$title?>Stats - I&ntilde;igo Valentin - Administration Panel</title>
  23. <style>
  24. <?php
  25. include $doc_root . "css/ui.css";
  26. include $doc_root . "css/stats.css";
  27. ?>
  28. </style>
  29. <!-- CSS for mobile version -->
  30. <style media='(max-width : 990px)'>
  31. <?php
  32. include $doc_root . "css/m/ui.css";
  33. include $doc_root . "css/m/stats.css";
  34. ?>
  35. </style>
  36. <!-- Script files -->
  37. <script type='text/javascript'>
  38. <?php
  39. include $doc_root . "script/ui.js";
  40. include $doc_root . "script/stats.js";
  41. ?>
  42. </script>
  43. </head>
  44. <body>
  45. <div id='content'>
  46. <div class='section' id='post_edit'>
  47. <h3 class='section_title'>Visits</h3>
  48. <div class='entry'>
  49. <div id='visitCanvas'></div>
  50. <script>
  51. (function () {
  52. function createCanvas() {
  53. var parent = document.getElementById("visitCanvas");
  54. var canvas = document.createElement("canvas");
  55. parent.appendChild(canvas);
  56. return canvas.getContext("2d");
  57. }
  58. var context = createCanvas();
  59. var graph = new BarGraph(context);
  60. graph.width = 450;
  61. graph.height = 150;;
  62. <?php
  63. $q_month = mysqli_query($con, "SELECT month(dtime) AS month, count(id) AS total FROM stat_visit GROUP BY year(dtime), month(dtime) ORDER BY dtime DESC LIMIT 12;");
  64. $name_string = "";
  65. $valu_string = "";
  66. $month = date('m');
  67. // Show at least the last twelve months, even if there is no data that old.
  68. for ($i = 0; $i < 12 - mysqli_num_rows($q_month); $i ++){
  69. $month_number = intval($month) - (12 - $i) + 1;
  70. if ($month_number <= 0){
  71. $month_number = $month_number + 12;
  72. }
  73. $name_string = $name_string . "\"" . ucfirst(substr(text($con, "MONTH_" . str_pad($month_number, 2, "0", STR_PAD_LEFT), $lang), 0, 3)) . "\", "; //"\"" . text($con, "MONTH_" . $r_month["month"], $lang) . "\", ";
  74. $valu_string = $valu_string . "0, ";
  75. }
  76. // Loop data
  77. while ($r_month = mysqli_fetch_array($q_month)){
  78. $name_string = $name_string . "\"" . ucfirst(substr(text($con, "MONTH_" . $r_month["month"], $lang), 0, 3)) . "\", ";
  79. $valu_string = $valu_string . $r_month["total"] . ", ";
  80. }
  81. $name_string = substr(trim($name_string), 0, -1);
  82. $valu_string = substr(trim($valu_string), 0, -1);
  83. ?>
  84. graph.setLabels([<?=$name_string?>]);
  85. graph.setValues([<?=$valu_string?>]);
  86. graph.draw();
  87. }());
  88. </script>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. <?php
  94. }
  95. ?>