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.

invite_tree.class.php 8.4KB

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