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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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, $Max) = $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, 12");
  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, 12");
  22. $TimelineOut = array_reverse($DB->to_array());
  23. foreach ($TimelineIn as $Month) {
  24. list($Label, $Amount) = $Month;
  25. if ($Amount > $Max) {
  26. $Max = $Amount;
  27. }
  28. }
  29. foreach ($TimelineOut as $Month) {
  30. list($Label, $Amount) = $Month;
  31. if ($Amount > $Max) {
  32. $Max = $Amount;
  33. }
  34. }
  35. foreach ($TimelineIn as $Month) {
  36. list($Label, $Amount) = $Month;
  37. $Labels[] = $Label;
  38. $InFlow[] = number_format(($Amount / $Max) * 100, 4);
  39. }
  40. foreach ($TimelineOut as $Month) {
  41. list($Label, $Amount) = $Month;
  42. $OutFlow[] = number_format(($Amount / $Max) * 100, 4);
  43. }
  44. $Cache->cache_value('users_timeline', array($Labels, $InFlow, $OutFlow, $Max), mktime(0, 0, 0, date('n') + 1, 2));
  45. }
  46. }
  47. //End timeline generation
  48. define('DAYS_PER_PAGE', 100);
  49. list($Page, $Limit) = Format::page_limit(DAYS_PER_PAGE);
  50. $RS = $DB->query("
  51. SELECT
  52. SQL_CALC_FOUND_ROWS
  53. j.Date,
  54. DATE_FORMAT(j.Date, '%Y-%m') AS Month,
  55. CASE ISNULL(j.Flow)
  56. WHEN 0 THEN j.Flow
  57. ELSE '0'
  58. END AS Joined,
  59. CASE ISNULL(m.Flow)
  60. WHEN 0 THEN m.Flow
  61. ELSE '0'
  62. END AS Manual,
  63. CASE ISNULL(r.Flow)
  64. WHEN 0 THEN r.Flow
  65. ELSE '0'
  66. END AS Ratio,
  67. CASE ISNULL(i.Flow)
  68. WHEN 0 THEN i.Flow
  69. ELSE '0'
  70. END AS Inactivity
  71. FROM (
  72. SELECT
  73. DATE_FORMAT(JoinDate, '%Y-%m-%d') AS Date,
  74. COUNT(UserID) AS Flow
  75. FROM users_info
  76. WHERE JoinDate IS NOT NULL
  77. GROUP BY Date
  78. ) AS j
  79. LEFT JOIN (
  80. SELECT
  81. DATE_FORMAT(BanDate, '%Y-%m-%d') AS Date,
  82. COUNT(UserID) AS Flow
  83. FROM users_info
  84. WHERE BanDate IS NOT NULL
  85. AND BanReason = '1'
  86. GROUP BY Date
  87. ) AS m ON j.Date = m.Date
  88. LEFT JOIN (
  89. SELECT
  90. DATE_FORMAT(BanDate, '%Y-%m-%d') AS Date,
  91. COUNT(UserID) AS Flow
  92. FROM users_info
  93. WHERE BanDate IS NOT NULL
  94. AND BanReason = '2'
  95. GROUP BY Date
  96. ) AS r ON j.Date = r.Date
  97. LEFT JOIN (
  98. SELECT
  99. DATE_FORMAT(BanDate, '%Y-%m-%d') AS Date,
  100. COUNT(UserID) AS Flow
  101. FROM users_info
  102. WHERE BanDate IS NOT NULL
  103. AND BanReason = '3'
  104. GROUP BY Date
  105. ) AS i ON j.Date = i.Date
  106. ORDER BY j.Date DESC
  107. LIMIT $Limit");
  108. $DB->query('SELECT FOUND_ROWS()');
  109. list($Results) = $DB->next_record();
  110. View::show_header('User Flow');
  111. $DB->set_query_id($RS);
  112. ?>
  113. <div class="thin">
  114. <? if (!isset($_GET['page'])) { ?>
  115. <div class="box pad">
  116. <img src="https://chart.googleapis.com/chart?cht=lc&amp;chs=820x160&amp;chco=000D99,99000D&amp;chg=0,-1,1,1&amp;chxt=y,x&amp;chxs=0,h&amp;chxl=1:|<?=implode('|', $Labels)?>&amp;chxr=0,0,<?=$Max?>&amp;chd=t:<?=implode(',', $InFlow)?>|<?=implode(',', $OutFlow)?>&amp;chls=2,4,0&amp;chdl=New+Registrations|Disabled+Users&amp;chf=bg,s,FFFFFF00" alt="User Flow vs. Time" />
  117. </div>
  118. <? } ?>
  119. <div class="linkbox">
  120. <?
  121. $Pages = Format::get_pages($Page, $Results, DAYS_PER_PAGE, 11);
  122. echo $Pages;
  123. ?>
  124. </div>
  125. <div class="box">
  126. <table width="100%">
  127. <tr class="colhead">
  128. <td>Date</td>
  129. <td>(+) Joined</td>
  130. <td>(-) Manual</td>
  131. <td>(-) Ratio</td>
  132. <td>(-) Inactivity</td>
  133. <td>(-) Total</td>
  134. <td>Net Growth</td>
  135. </tr>
  136. <?
  137. while (list($Date, $Month, $Joined, $Manual, $Ratio, $Inactivity) = $DB->next_record()) {
  138. $TotalOut = $Ratio + $Inactivity + $Manual;
  139. $TotalGrowth = $Joined - $TotalOut;
  140. ?>
  141. <tr class="row">
  142. <td><?=$Date?></td>
  143. <td><?=number_format($Joined)?></td>
  144. <td><?=number_format($Manual)?></td>
  145. <td><?=number_format((float)$Ratio)?></td>
  146. <td><?=number_format($Inactivity)?></td>
  147. <td><?=number_format($TotalOut)?></td>
  148. <td><?=number_format($TotalGrowth)?></td>
  149. </tr>
  150. <? } ?>
  151. </table>
  152. </div>
  153. <div class="linkbox">
  154. <?=$Pages?>
  155. </div>
  156. </div>
  157. <? View::show_footer(); ?>