Oppaitime'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 4.4KB

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