PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyfaq/admin/stat.main.php

https://github.com/cyrke/phpMyFAQ
PHP | 209 lines | 171 code | 13 blank | 25 comment | 43 complexity | 69abbc029ae652c7725f1b1dc3affa61 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * The main statistics page
  4. *
  5. * PHP Version 5.3
  6. *
  7. * This Source Code Form is subject to the terms of the Mozilla Public License,
  8. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  9. * obtain one at http://mozilla.org/MPL/2.0/.
  10. *
  11. * @category phpMyFAQ
  12. * @package Administration
  13. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  14. * @author Matteo Scaramuccia <matteo@scaramuccia.com>
  15. * @copyright 2003-2012 phpMyFAQ Team
  16. * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
  17. * @link http://www.phpmyfaq.de
  18. * @since 2003-02-24
  19. */
  20. if (!defined('IS_VALID_PHPMYFAQ')) {
  21. header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']));
  22. exit();
  23. }
  24. printf('<header><h2>%s</h2></header>', $PMF_LANG['ad_stat_sess']);
  25. if ($permission['viewlog']) {
  26. $session = new PMF_Session($faqConfig);
  27. $date = new PMF_Date($faqConfig);
  28. $statdelete = PMF_Filter::filterInput(INPUT_POST, 'statdelete', FILTER_SANITIZE_STRING);
  29. $month = PMF_Filter::filterInput(INPUT_POST, 'month', FILTER_SANITIZE_STRING);
  30. if (!is_null($statdelete) && !is_null($month)) {
  31. // Search for related tracking data files and
  32. // delete them including the sid records in the faqsessions table
  33. $dir = opendir(PMF_ROOT_DIR."/data");
  34. $first = 9999999999999999999999999;
  35. $last = 0;
  36. while($trackingFile = readdir($dir)) {
  37. // The filename format is: trackingDDMMYYYY
  38. // e.g.: tracking02042006
  39. if (($trackingFile != '.') && ($trackingFile != '..') && (10 == strpos($trackingFile, $month))) {
  40. $candidateFirst = PMF_Date::getTrackingFileDate($trackingFile);
  41. $candidateLast = PMF_Date::getTrackingFileDate($trackingFile, true);
  42. if (($candidateLast > 0) && ($candidateLast > $last)) {
  43. $last = $candidateLast;
  44. }
  45. if (($candidateFirst > 0) && ($candidateFirst < $first)) {
  46. $first = $candidateFirst;
  47. }
  48. unlink(PMF_ROOT_DIR.'/data/'.$trackingFile);
  49. }
  50. }
  51. closedir($dir);
  52. $session->deleteSessions($first, $last);
  53. printf('<p class="success">%s</p>', $PMF_LANG['ad_adminlog_delete_success']);
  54. }
  55. ?>
  56. <form action="?action=sessionbrowse" method="post" style="display: inline;">
  57. <table class="table table-striped">
  58. <tr>
  59. <td><?php print $PMF_LANG["ad_stat_days"]; ?>:</td>
  60. <td>
  61. <?php
  62. $danz = 0;
  63. $first = 9999999999999999999999999;
  64. $last = 0;
  65. $dir = opendir(PMF_ROOT_DIR."/data");
  66. while ($dat = readdir($dir)) {
  67. if ($dat != "." && $dat != "..") {
  68. $danz++;
  69. }
  70. if (PMF_Date::getTrackingFileDate($dat) > $last) {
  71. $last = PMF_Date::getTrackingFileDate($dat);
  72. }
  73. if (PMF_Date::getTrackingFileDate($dat) < $first && PMF_Date::getTrackingFileDate($dat) > 0) {
  74. $first = PMF_Date::getTrackingFileDate($dat);
  75. }
  76. }
  77. closedir($dir);
  78. print $danz;
  79. ?>
  80. </td>
  81. </tr>
  82. <tr>
  83. <td><?php print $PMF_LANG["ad_stat_vis"]; ?>:</td>
  84. <td><?php print $vanz = $session->getNumberOfSessions(); ?></td>
  85. </tr>
  86. <tr>
  87. <td><?php print $PMF_LANG["ad_stat_vpd"]; ?>:</td>
  88. <td><?php print (($danz != 0) ? round(($vanz / $danz),2) : 0); ?></td>
  89. </tr>
  90. <tr>
  91. <td><?php print $PMF_LANG["ad_stat_fien"]; ?>:</td>
  92. <td>
  93. <?php
  94. if (is_file(PMF_ROOT_DIR."/data/tracking".date("dmY", $first))) {
  95. $fp = @fopen(PMF_ROOT_DIR."/data/tracking".date("dmY", $first), "r");
  96. list($dummy, $dummy, $dummy, $dummy, $dummy, $dummy, $dummy, $qstamp) = fgetcsv($fp, 1024, ";");
  97. fclose($fp);
  98. print $date->format(date('Y-m-d H:i', $qstamp));
  99. } else {
  100. print $PMF_LANG["ad_sess_noentry"];
  101. }
  102. ?>
  103. </td>
  104. </tr>
  105. <tr>
  106. <td><?php print $PMF_LANG["ad_stat_laen"]; ?>:</td>
  107. <td>
  108. <?php
  109. if (is_file(PMF_ROOT_DIR."/data/tracking".date("dmY", $last))) {
  110. $fp = fopen(PMF_ROOT_DIR."/data/tracking".date("dmY", $last), "r");
  111. while (list($dummy, $dummy, $dummy, $dummy, $dummy, $dummy, $dummy, $tstamp) = fgetcsv($fp, 1024, ";")) {
  112. $stamp = $tstamp;
  113. }
  114. fclose($fp);
  115. if (empty($stamp)) {
  116. $stamp = $_SERVER['REQUEST_TIME'];
  117. }
  118. print $date->format(date('Y-m-d H:i', $stamp)).'<br />';
  119. } else {
  120. print $PMF_LANG["ad_sess_noentry"].'<br />';
  121. }
  122. $dir = opendir(PMF_ROOT_DIR."/data");
  123. $trackingDates = array();
  124. while (false !== ($dat = readdir($dir))) {
  125. if ($dat != "." && $dat != ".." && strlen($dat) == 16 && !is_dir($dat)) {
  126. $trackingDates[] = PMF_Date::getTrackingFileDate($dat);
  127. }
  128. }
  129. closedir($dir);
  130. sort($trackingDates);
  131. ?>
  132. </td>
  133. </tr>
  134. <tr>
  135. <td><?php print $PMF_LANG["ad_stat_browse"]; ?>:</td>
  136. <td><select name="day" size="1">
  137. <?php
  138. foreach ($trackingDates as $trackingDate) {
  139. printf('<option value="%d"', $trackingDate);
  140. if (date("Y-m-d", $trackingDate) == strftime('%Y-%m-%d', $_SERVER['REQUEST_TIME'])) {
  141. print ' selected="selected"';
  142. }
  143. print '>';
  144. print $date->format(date('Y-m-d H:i', $trackingDate));
  145. print "</option>\n";
  146. }
  147. ?>
  148. </select>
  149. <button class="btn btn-primary" type="submit" name="statbrowse">
  150. <?php print $PMF_LANG["ad_stat_ok"]; ?>
  151. </button>
  152. </td>
  153. </tr>
  154. </table>
  155. </form>
  156. <form action="?action=viewsessions" method="post" class="form-horizontal">
  157. <fieldset>
  158. <legend><?php print $PMF_LANG['ad_stat_management']; ?></legend>
  159. <div class="control-group">
  160. <label class="control-label" for="month"><?php print $PMF_LANG['ad_stat_choose']; ?>:</label>
  161. <div class="controls">
  162. <select name="month" id="month" size="1">
  163. <?php
  164. $oldValue = mktime(0, 0, 0, 1, 1, 1970);
  165. $isFirstDate = true;
  166. foreach ($trackingDates as $trackingDate) {
  167. if (date("Y-m", $oldValue) != date("Y-m", $trackingDate)) {
  168. // The filename format is: trackingDDMMYYYY
  169. // e.g.: tracking02042006
  170. printf('<option value="%s"', date('mY', $trackingDate));
  171. // Select the oldest month
  172. if ($isFirstDate) {
  173. print ' selected="selected"';
  174. $isFirstDate = false;
  175. }
  176. print '>';
  177. print date('Y-m', $trackingDate);
  178. print "</option>\n";
  179. $oldValue = $trackingDate;
  180. }
  181. }
  182. ?>
  183. </select>
  184. </div>
  185. </div>
  186. <div class="form-actions">
  187. <button class="btn btn-primary" type="submit" name="statdelete">
  188. <?php print $PMF_LANG['ad_stat_delete']; ?>
  189. </button>
  190. </div>
  191. </fieldset>
  192. </form>
  193. <?php
  194. } else {
  195. print $PMF_LANG["err_NotAuth"];
  196. }