index.php 14 KB

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