index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. <?php
  46. include $doc_root . "header.php";
  47. ?>
  48. <div id='content'>
  49. <div class='section' id='post_edit'>
  50. <h3 class='section_title'>Visits</h3>
  51. <div class='entry'>
  52. <div id='visitCanvas'></div>
  53. <script>
  54. (function () {
  55. function createVisitCanvas() {
  56. var parent = document.getElementById("visitCanvas");
  57. var canvas = document.createElement("canvas");
  58. parent.appendChild(canvas);
  59. return canvas.getContext("2d");
  60. }
  61. var context = createVisitCanvas();
  62. var graph = new BarGraph(context);
  63. <?php
  64. $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;");
  65. $name_string = "";
  66. $valu_string = "";
  67. $month = date('m');
  68. // Show at least the last twelve months, even if there is no data that old.
  69. for ($i = 0; $i < 12 - mysqli_num_rows($q_month); $i ++){
  70. $month_number = intval($month) - (12 - $i) + 1;
  71. if ($month_number <= 0){
  72. $month_number = $month_number + 12;
  73. }
  74. $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) . "\", ";
  75. $valu_string = $valu_string . "0, ";
  76. }
  77. // Loop data
  78. while ($r_month = mysqli_fetch_array($q_month)){
  79. $name_string = $name_string . "\"" . ucfirst(substr(text($con, "MONTH_" . $r_month["month"], $lang), 0, 3)) . "\", ";
  80. $valu_string = $valu_string . $r_month["total"] . ", ";
  81. }
  82. $name_string = substr(trim($name_string), 0, -1);
  83. $valu_string = substr(trim($valu_string), 0, -1);
  84. ?>
  85. graph.width = parseInt(window.getComputedStyle(document.getElementById("visitCanvas")).width);
  86. graph.height = 180;
  87. graph.setLabels([<?=$name_string?>]);
  88. graph.setValues([<?=$valu_string?>]);
  89. graph.draw();
  90. }());
  91. </script>
  92. </div> <!-- .entry -->
  93. </div> <!-- .section -->
  94. <div class='section' id='post_edit'>
  95. <h3 class='section_title'>Most popular pages</h3>
  96. <div class='entry'>
  97. <div id='pagesCanvas'></div>
  98. <script>
  99. (function () {
  100. function createPagesCanvas() {
  101. var parent = document.getElementById("pagesCanvas");
  102. var canvas = document.createElement("canvas");
  103. parent.appendChild(canvas);
  104. return canvas.getContext("2d");
  105. }
  106. var context = createPagesCanvas();
  107. var graph = new HBarGraph(context);
  108. <?php
  109. $q_visit = mysqli_query($con, "SELECT count(id) AS total, section, entry FROM stat_view GROUP BY section, entry LIMIT 10;");
  110. $name_string = "";
  111. $valu_string = "";
  112. while ($r_visit = mysqli_fetch_array($q_visit)){
  113. $s = $r_visit["section"];
  114. $e = $r_visit["entry"];
  115. switch ($s){
  116. case "index":
  117. $name_string = $name_string . "\"Homepage\", ";
  118. break;
  119. case "profile":
  120. $name_string = $name_string . "\"Profile page\", ";
  121. break;
  122. case "help":
  123. $name_string = $name_string . "\"Help page\", ";
  124. break;
  125. case "project":
  126. if (strlen(e) == 0){
  127. $name_string = $name_string . "\"Projects page\", ";
  128. }
  129. else{
  130. $t = text($con, mysqli_fetch_array(mysqli_query($con, "SELECT title, permalink FROM project WHERE id = $e;"))["title"], $lang);
  131. $name_string = $name_string . "\"Project: " . $t . "\", ";
  132. }
  133. break;
  134. case "blog":
  135. if (strlen(e) == 0){
  136. $name_string = $name_string . "\"Blog\", ";
  137. }
  138. else{
  139. $t = text($con, mysqli_fetch_array(mysqli_query($con, "SELECT title, permalink FROM project WHERE id = $e;"))["title"], $lang);
  140. $name_string = $name_string . "\"Post: " . $t . "\", ";
  141. }
  142. break;
  143. default:
  144. $name_string = $name_string . "\"" . $s . " - " . $e . "\", ";
  145. }
  146. $valu_string = $valu_string . $r_visit["total"] . ", ";
  147. }
  148. $name_string = substr(trim($name_string), 0, -1);
  149. $valu_string = substr(trim($valu_string), 0, -1);
  150. ?>
  151. setTimeout(function(){
  152. graph.width = parseInt(window.getComputedStyle(document.getElementById("pagesCanvas")).width);
  153. graph.height = <?=(40 + (30 * mysqli_num_rows($q_visit)))?>;
  154. graph.setLabels([<?=$name_string?>]);
  155. graph.setValues([<?=$valu_string?>]);
  156. graph.draw();
  157. }, 0);
  158. }());
  159. </script>
  160. </div> <!-- .entry -->
  161. </div> <!-- .section -->
  162. <div class='section'>
  163. <h3 class='section_title'>Visitors profile</h3>
  164. <div class='entry'>
  165. <div class='pie_chart' id='osCanvas'><h4>Top OS</h4></div>
  166. <div class='pie_chart' id='browserCanvas'><h4>Top browsers</h4></div>
  167. <div class='pie_chart' id='osBrowserCanvas'><h4>Top OS/browser</h4></div>
  168. <script>
  169. (function () {
  170. function createOsCanvas() {
  171. var parent = document.getElementById("osCanvas");
  172. var canvas = document.createElement("canvas");
  173. parent.appendChild(canvas);
  174. return canvas.getContext("2d");
  175. }
  176. var context = createOsCanvas();
  177. var graph = new PieGraph(context);
  178. <?php
  179. $q_os = mysqli_query($con, "SELECT count(id) AS total, os FROM stat_visit GROUP BY os ORDER BY total DESC LIMIT 9;");
  180. $name_string = "";
  181. $valu_string = "";
  182. while ($r_os = mysqli_fetch_array($q_os)){
  183. $name_string = $name_string . "\"" . $r_os["os"] . "\", ";
  184. $valu_string = $valu_string . $r_os["total"] . ", ";
  185. }
  186. $name_string = substr(trim($name_string), 0, -1);
  187. $valu_string = substr(trim($valu_string), 0, -1);
  188. ?>
  189. var cHeight = 30 * (<?=mysqli_num_rows($q_os)?> + 3);
  190. if (cHeight < 200){
  191. cHeight = 200;
  192. }
  193. graph.width = 400;
  194. graph.height = cHeight;
  195. graph.setLabels([<?=$name_string?>]);
  196. graph.setValues([<?=$valu_string?>]);
  197. graph.draw();
  198. }());
  199. (function () {
  200. function createBrowserCanvas() {
  201. var parent = document.getElementById("browserCanvas");
  202. var canvas = document.createElement("canvas");
  203. parent.appendChild(canvas);
  204. return canvas.getContext("2d");
  205. }
  206. var context = createBrowserCanvas();
  207. var graph = new PieGraph(context);
  208. <?php
  209. $q_browser = mysqli_query($con, "SELECT count(id) AS total, browser FROM stat_visit GROUP BY browser ORDER BY total DESC LIMIT 9;");
  210. $name_string = "";
  211. $valu_string = "";
  212. while ($r_browser = mysqli_fetch_array($q_browser)){
  213. $name_string = $name_string . "\"" . $r_browser["browser"] . "\", ";
  214. $valu_string = $valu_string . $r_browser["total"] . ", ";
  215. }
  216. $name_string = substr(trim($name_string), 0, -1);
  217. $valu_string = substr(trim($valu_string), 0, -1);
  218. ?>
  219. var cHeight = 30 * (<?=mysqli_num_rows($q_browser)?> + 3);
  220. if (cHeight < 200){
  221. cHeight = 200;
  222. }
  223. graph.width = 400;
  224. graph.height = cHeight;
  225. graph.setLabels([<?=$name_string?>]);
  226. graph.setValues([<?=$valu_string?>]);
  227. graph.draw();
  228. }());
  229. (function () {
  230. function createOsBrowserCanvas() {
  231. var parent = document.getElementById("osBrowserCanvas");
  232. var canvas = document.createElement("canvas");
  233. parent.appendChild(canvas);
  234. return canvas.getContext("2d");
  235. }
  236. var context = createOsBrowserCanvas();
  237. var graph = new PieGraph(context);
  238. <?php
  239. $q_osbrowser = mysqli_query($con, "SELECT count(id) AS total, os, browser FROM stat_visit GROUP BY os, browser ORDER BY total DESC LIMIT 9;");
  240. $name_string = "";
  241. $valu_string = "";
  242. while ($r_osbrowser = mysqli_fetch_array($q_osbrowser)){
  243. $name_string = $name_string . "\"" . $r_osbrowser["os"] . "/" . $r_osbrowser["browser"] . "\", ";
  244. $valu_string = $valu_string . $r_osbrowser["total"] . ", ";
  245. }
  246. $name_string = substr(trim($name_string), 0, -1);
  247. $valu_string = substr(trim($valu_string), 0, -1);
  248. ?>
  249. var cHeight = 30 * (<?=mysqli_num_rows($q_osbrowser)?> + 3);
  250. if (cHeight < 200){
  251. cHeight = 200;
  252. }
  253. graph.width = 400;
  254. graph.height = cHeight;
  255. graph.setLabels([<?=$name_string?>]);
  256. graph.setValues([<?=$valu_string?>]);
  257. graph.draw();
  258. }());
  259. </script>
  260. </div> <!-- .entry -->
  261. </div> <!-- .section -->
  262. </div>
  263. </div>
  264. <?php
  265. }
  266. ?>