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

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