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.

invite_tree.class.php 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. /**************************************************************************/
  3. /*-- Invite tree class -----------------------------------------------------
  4. ***************************************************************************/
  5. class INVITE_TREE
  6. {
  7. public $UserID = 0;
  8. public $Visible = true;
  9. // Set things up
  10. public function INVITE_TREE($UserID, $Options = [])
  11. {
  12. $this->UserID = $UserID;
  13. if ($Options['visible'] === false) {
  14. $this->Visible = false;
  15. }
  16. }
  17. public function make_tree()
  18. {
  19. $QueryID = G::$DB->get_query_id();
  20. $UserID = $this->UserID; ?>
  21. <div class="invitetree pad">
  22. <?php
  23. G::$DB->query("
  24. SELECT TreePosition, TreeID, TreeLevel
  25. FROM invite_tree
  26. WHERE UserID = $UserID");
  27. list($TreePosition, $TreeID, $TreeLevel) = G::$DB->next_record(MYSQLI_NUM, false);
  28. if (!$TreeID) {
  29. return;
  30. }
  31. G::$DB->query("
  32. SELECT TreePosition
  33. FROM invite_tree
  34. WHERE TreeID = $TreeID
  35. AND TreeLevel = $TreeLevel
  36. AND TreePosition > $TreePosition
  37. ORDER BY TreePosition ASC
  38. LIMIT 1");
  39. if (G::$DB->has_results()) {
  40. list($MaxPosition) = G::$DB->next_record(MYSQLI_NUM, false);
  41. } else {
  42. $MaxPosition = false;
  43. }
  44. $TreeQuery = G::$DB->query("
  45. SELECT
  46. it.UserID,
  47. Enabled,
  48. PermissionID,
  49. Donor,
  50. Uploaded,
  51. Downloaded,
  52. Paranoia,
  53. TreePosition,
  54. TreeLevel
  55. FROM invite_tree AS it
  56. JOIN users_main AS um ON um.ID = it.UserID
  57. JOIN users_info AS ui ON ui.UserID = it.UserID
  58. WHERE TreeID = $TreeID
  59. AND TreePosition > $TreePosition".
  60. ($MaxPosition ? " AND TreePosition < $MaxPosition" : '')."
  61. AND TreeLevel > $TreeLevel
  62. ORDER BY TreePosition");
  63. $PreviousTreeLevel = $TreeLevel;
  64. // Stats for the summary
  65. $MaxTreeLevel = $TreeLevel; // The deepest level (this changes)
  66. $OriginalTreeLevel = $TreeLevel; // The level of the user we're viewing
  67. $BaseTreeLevel = $TreeLevel + 1; // The level of users invited by our user
  68. $Count = 0;
  69. $Branches = 0;
  70. $DisabledCount = 0;
  71. $DonorCount = 0;
  72. $ParanoidCount = 0;
  73. $TotalUpload = 0;
  74. $TotalDownload = 0;
  75. $TopLevelUpload = 0;
  76. $TopLevelDownload = 0;
  77. $ClassSummary = [];
  78. global $Classes;
  79. foreach ($Classes as $ClassID => $Val) {
  80. $ClassSummary[$ClassID] = 0;
  81. }
  82. // We store this in an output buffer, so we can show the summary at the top without having to loop through twice
  83. ob_start();
  84. while (list($ID, $Enabled, $Class, $Donor, $Uploaded, $Downloaded, $Paranoia, $TreePosition, $TreeLevel) = G::$DB->next_record(MYSQLI_NUM, false)) {
  85. // Do stats
  86. $Count++;
  87. if ($TreeLevel > $MaxTreeLevel) {
  88. $MaxTreeLevel = $TreeLevel;
  89. }
  90. if ($TreeLevel == $BaseTreeLevel) {
  91. $Branches++;
  92. $TopLevelUpload += $Uploaded;
  93. $TopLevelDownload += $Downloaded;
  94. }
  95. $ClassSummary[$Class]++;
  96. if ($Enabled == 2) {
  97. $DisabledCount++;
  98. }
  99. if ($Donor) {
  100. $DonorCount++;
  101. }
  102. // Manage tree depth
  103. if ($TreeLevel > $PreviousTreeLevel) {
  104. for ($i = 0; $i < $TreeLevel - $PreviousTreeLevel; $i++) {
  105. echo "\n\n<ul class=\"invitetree\">\n\t<li>\n";
  106. }
  107. } elseif ($TreeLevel < $PreviousTreeLevel) {
  108. for ($i = 0; $i < $PreviousTreeLevel - $TreeLevel; $i++) {
  109. echo "\t</li>\n</ul>\n";
  110. }
  111. echo "\t</li>\n\t<li>\n";
  112. } else {
  113. echo "\t</li>\n\t<li>\n";
  114. }
  115. $UserClass = $Classes[$Class]['Level']; ?>
  116. <strong><?=Users::format_username($ID, true, true, ($Enabled != 2 ? false : true), true)?></strong>
  117. <?php
  118. if (check_paranoia(array('uploaded', 'downloaded'), $Paranoia, $UserClass)) {
  119. $TotalUpload += $Uploaded;
  120. $TotalDownload += $Downloaded; ?>
  121. &nbsp;Uploaded: <strong><?=Format::get_size($Uploaded)?></strong>
  122. &nbsp;Downloaded: <strong><?=Format::get_size($Downloaded)?></strong>
  123. &nbsp;Ratio: <strong><?=Format::get_ratio_html($Uploaded, $Downloaded)?></strong>
  124. <?php
  125. } else {
  126. $ParanoidCount++; ?>
  127. &nbsp;Hidden
  128. <?php
  129. } ?>
  130. <?php
  131. $PreviousTreeLevel = $TreeLevel;
  132. G::$DB->set_query_id($TreeQuery);
  133. }
  134. $Tree = ob_get_clean();
  135. for ($i = 0; $i < $PreviousTreeLevel - $OriginalTreeLevel; $i++) {
  136. $Tree .= "\t</li>\n</ul>\n";
  137. }
  138. if ($Count) {
  139. ?>
  140. <p style="font-weight: bold;">
  141. This tree has <?=number_format($Count)?> entries, <?=number_format($Branches)?> branches, and a depth of <?=number_format($MaxTreeLevel - $OriginalTreeLevel)?>.
  142. It has
  143. <?php
  144. $ClassStrings = [];
  145. foreach ($ClassSummary as $ClassID => $ClassCount) {
  146. if ($ClassCount == 0) {
  147. continue;
  148. }
  149. $LastClass = Users::make_class_string($ClassID);
  150. if ($ClassCount > 1) {
  151. if ($LastClass == 'Torrent Celebrity') {
  152. $LastClass = 'Torrent Celebrities';
  153. } else {
  154. // Prevent duplicate letterss
  155. if (substr($LastClass, -1) != 's') {
  156. $LastClass.='s';
  157. }
  158. }
  159. }
  160. $LastClass = "$ClassCount $LastClass (" . number_format(($ClassCount / $Count) * 100) . '%)';
  161. $ClassStrings[] = $LastClass;
  162. }
  163. if (count($ClassStrings) > 1) {
  164. array_pop($ClassStrings);
  165. echo implode(', ', $ClassStrings);
  166. echo ' and '.$LastClass;
  167. } else {
  168. echo $LastClass;
  169. }
  170. echo '. ';
  171. echo $DisabledCount;
  172. echo ($DisabledCount == 1) ? ' user is' : ' users are';
  173. echo ' disabled (';
  174. if ($DisabledCount == 0) {
  175. echo '0%)';
  176. } else {
  177. echo number_format(($DisabledCount / $Count) * 100) . '%)';
  178. }
  179. echo ', and ';
  180. echo $DonorCount;
  181. echo ($DonorCount == 1) ? ' user has' : ' users have';
  182. echo ' donated (';
  183. if ($DonorCount == 0) {
  184. echo '0%)';
  185. } else {
  186. echo number_format(($DonorCount / $Count) * 100) . '%)';
  187. }
  188. echo '. </p>';
  189. echo '<p style="font-weight: bold;">';
  190. echo 'The total amount uploaded by the entire tree was '.Format::get_size($TotalUpload);
  191. echo '; the total amount downloaded was '.Format::get_size($TotalDownload);
  192. echo '; and the total ratio is '.Format::get_ratio_html($TotalUpload, $TotalDownload).'. ';
  193. echo '</p>';
  194. echo '<p style="font-weight: bold;">';
  195. echo 'The total amount uploaded by direct invitees (the top level) was '.Format::get_size($TopLevelUpload);
  196. echo '; the total amount downloaded was '.Format::get_size($TopLevelDownload);
  197. echo '; and the total ratio is '.Format::get_ratio_html($TopLevelUpload, $TopLevelDownload).'. ';
  198. echo "These numbers include the stats of paranoid users and will be factored into the invitation giving script.\n\t\t</p>\n";
  199. if ($ParanoidCount) {
  200. echo '<p style="font-weight: bold;">';
  201. echo $ParanoidCount;
  202. echo ($ParanoidCount == 1) ? ' user (' : ' users (';
  203. echo number_format(($ParanoidCount / $Count) * 100);
  204. echo '%) ';
  205. echo ($ParanoidCount == 1) ? ' is' : ' are';
  206. echo ' too paranoid to have their stats shown here, and ';
  207. echo ($ParanoidCount == 1) ? ' was' : ' were';
  208. echo ' not factored into the stats for the total tree.';
  209. echo '</p>';
  210. }
  211. } ?>
  212. <br />
  213. <?= $Tree?>
  214. </div>
  215. <?php
  216. G::$DB->set_query_id($QueryID);
  217. }
  218. }
  219. ?>