BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

user_flow.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. #declare(strict_types=1);
  3. if (!check_perms('site_view_flow')) {
  4. error(403);
  5. }
  6. // Timeline generation
  7. if (!isset($_GET['page'])) {
  8. if (!list($Labels, $InFlow, $OutFlow) = $Cache->get_value('users_timeline')) {
  9. $DB->query("
  10. SELECT DATE_FORMAT(JoinDate, \"%b %y\") AS Month, COUNT(UserID)
  11. FROM users_info
  12. GROUP BY Month
  13. ORDER BY JoinDate DESC
  14. LIMIT 1, 11");
  15. $TimelineIn = array_reverse($DB->to_array());
  16. $DB->query("
  17. SELECT DATE_FORMAT(BanDate, \"%b %y\") AS Month, COUNT(UserID)
  18. FROM users_info
  19. WHERE BanDate > 0
  20. GROUP BY Month
  21. ORDER BY BanDate DESC
  22. LIMIT 1, 11");
  23. $TimelineOut = array_reverse($DB->to_array());
  24. $Labels = [];
  25. foreach ($TimelineIn as $Month) {
  26. list($Labels[], $InFlow[]) = $Month;
  27. }
  28. foreach ($TimelineOut as $Month) {
  29. list(, $OutFlow[]) = $Month;
  30. }
  31. $Cache->cache_value('users_timeline', array($Labels, $InFlow, $OutFlow), mktime(0, 0, 0, date('n') + 1, 2));
  32. }
  33. }
  34. // End timeline generation
  35. define('DAYS_PER_PAGE', 100);
  36. list($Page, $Limit) = Format::page_limit(DAYS_PER_PAGE);
  37. # wtf
  38. $RS = $DB->query("
  39. SELECT
  40. SQL_CALC_FOUND_ROWS
  41. j.Date,
  42. DATE_FORMAT(j.Date, '%Y-%m') AS Month,
  43. CASE ISNULL(j.Flow)
  44. WHEN 0 THEN j.Flow
  45. ELSE '0'
  46. END AS Joined,
  47. CASE ISNULL(m.Flow)
  48. WHEN 0 THEN m.Flow
  49. ELSE '0'
  50. END AS Manual,
  51. CASE ISNULL(r.Flow)
  52. WHEN 0 THEN r.Flow
  53. ELSE '0'
  54. END AS Ratio,
  55. CASE ISNULL(i.Flow)
  56. WHEN 0 THEN i.Flow
  57. ELSE '0'
  58. END AS Inactivity
  59. FROM (
  60. SELECT
  61. DATE_FORMAT(JoinDate, '%Y-%m-%d') AS Date,
  62. COUNT(UserID) AS Flow
  63. FROM users_info
  64. WHERE JoinDate IS NOT NULL
  65. GROUP BY Date
  66. ) AS j
  67. LEFT JOIN (
  68. SELECT
  69. DATE_FORMAT(BanDate, '%Y-%m-%d') AS Date,
  70. COUNT(UserID) AS Flow
  71. FROM users_info
  72. WHERE BanDate IS NOT NULL
  73. AND BanReason = '1'
  74. GROUP BY Date
  75. ) AS m ON j.Date = m.Date
  76. LEFT JOIN (
  77. SELECT
  78. DATE_FORMAT(BanDate, '%Y-%m-%d') AS Date,
  79. COUNT(UserID) AS Flow
  80. FROM users_info
  81. WHERE BanDate IS NOT NULL
  82. AND BanReason = '2'
  83. GROUP BY Date
  84. ) AS r ON j.Date = r.Date
  85. LEFT JOIN (
  86. SELECT
  87. DATE_FORMAT(BanDate, '%Y-%m-%d') AS Date,
  88. COUNT(UserID) AS Flow
  89. FROM users_info
  90. WHERE BanDate IS NOT NULL
  91. AND BanReason = '3'
  92. GROUP BY Date
  93. ) AS i ON j.Date = i.Date
  94. ORDER BY j.Date DESC
  95. LIMIT $Limit");
  96. $DB->query('SELECT FOUND_ROWS()');
  97. list($Results) = $DB->next_record();
  98. View::show_header('User Flow', 'chart');
  99. $DB->set_query_id($RS);
  100. ?>
  101. <div class="linkbox">
  102. <?php
  103. $Pages = Format::get_pages($Page, $Results, DAYS_PER_PAGE, 11);
  104. echo $Pages;
  105. ?>
  106. </div>
  107. <div class="box">
  108. <table width="100%">
  109. <tr class="colhead">
  110. <td>Date</td>
  111. <td>+ Joined</td>
  112. <td>− Manual</td>
  113. <td>− Ratio</td>
  114. <td>− Inactivity</td>
  115. <td>− Total</td>
  116. <td>Net Growth</td>
  117. </tr>
  118. <?php
  119. while (list($Date, $Month, $Joined, $Manual, $Ratio, $Inactivity) = $DB->next_record()) {
  120. $TotalOut = $Ratio + $Inactivity + $Manual;
  121. $TotalGrowth = $Joined - $TotalOut; ?>
  122. <tr class="row">
  123. <td>
  124. <?=$Date?>
  125. </td>
  126. <td>
  127. <?=number_format($Joined)?>
  128. </td>
  129. <td>
  130. <?=number_format($Manual)?>
  131. </td>
  132. <td>
  133. <?=number_format((float)$Ratio)?>
  134. </td>
  135. <td>
  136. <?=number_format($Inactivity)?>
  137. </td>
  138. <td>
  139. <?=number_format($TotalOut)?>
  140. </td>
  141. <td>
  142. <?=number_format($TotalGrowth)?>
  143. </td>
  144. </tr>
  145. <?php
  146. } ?>
  147. </table>
  148. </div>
  149. <div class="linkbox">
  150. <?=$Pages?>
  151. </div>
  152. </div>
  153. <?php
  154. View::show_footer();