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.

promotion.php 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. #declare(strict_types=1);
  3. # todo: I like the idea of store-based promotions expanded to other factors,
  4. # e.g., under an HnR threshold or minimum account age
  5. $UserID = $LoggedUser['ID'];
  6. $GiB = 1024*1024*1024;
  7. $Classes = array(
  8. MEMBER => array(
  9. 'Name' => 'Modest Mounds', // name
  10. 'Price' => 1000, // cost in points
  11. 'MinUpload' => 10, // minimum upload in GiB
  12. 'MinDownload' => 1, // minimum download in GiB
  13. 'MinUploads' => 0, // minimum upload count
  14. 'NonSmall' => 0, // must have at least this many non-doujin torrents or doujins with more than 50 pages
  15. 'MinRatio' => 0.7, // minimum ratio
  16. 'TorUnique' => false // do the uploads have to be unique groups?
  17. ),
  18. POWER => array(
  19. 'Name' => 'Well Endowed',
  20. 'Price' => 10000,
  21. 'MinUpload' => 100,
  22. 'MinDownload' => 25,
  23. 'MinUploads' => 10,
  24. 'NonSmall' => 2,
  25. 'MinRatio' => 1.1,
  26. 'TorUnique' => false
  27. ),
  28. ELITE => array(
  29. 'Name' => 'Bombshell',
  30. 'Price' => 30000,
  31. 'MinUpload' => 500,
  32. 'MinDownload' => 100,
  33. 'MinUploads' => 50,
  34. 'NonSmall' => 12,
  35. 'MinRatio' => 1.2,
  36. 'TorUnique' => false
  37. ),
  38. TORRENT_MASTER => array(
  39. 'Name' => 'Top Heavy',
  40. 'Price' => 60000,
  41. 'MinUpload' => 1024,
  42. 'MinDownload' => 250,
  43. 'MinUploads' => 250,
  44. 'NonSmall' => 60,
  45. 'MinRatio' => 1.3,
  46. 'TorUnique' => false
  47. ),
  48. POWER_TM => array(
  49. 'Name' => 'Titty Monster',
  50. 'Price' => 100000,
  51. 'MinUpload' => 1.5*1024,
  52. 'MinDownload' => 500,
  53. 'MinUploads' => 500,
  54. 'NonSmall' => 160,
  55. 'MinRatio' => 1.5,
  56. 'TorUnique' => true
  57. )
  58. );
  59. $To = -1;
  60. $DB->query("
  61. SELECT PermissionID, BonusPoints, Warned, Uploaded, Downloaded, (Uploaded / Downloaded) AS Ratio, Enabled, COUNT(torrents.ID) AS Uploads, COUNT(DISTINCT torrents.GroupID) AS Groups
  62. FROM users_main
  63. JOIN users_info ON users_main.ID = users_info.UserID
  64. JOIN torrents ON torrents.UserID = users_main.ID
  65. WHERE users_main.ID = $UserID");
  66. if ($DB->has_results()) {
  67. list($PermID, $BP, $Warned, $Upload, $Download, $Ratio, $Enabled, $Uploads, $Groups) = $DB->next_record();
  68. switch ($PermID) {
  69. case USER:
  70. $To = MEMBER;
  71. break;
  72. case MEMBER:
  73. $To = POWER;
  74. break;
  75. case POWER:
  76. $To = ELITE;
  77. break;
  78. case ELITE:
  79. $To = TORRENT_MASTER;
  80. break;
  81. case TORRENT_MASTER:
  82. $To = POWER_TM;
  83. break;
  84. default:
  85. $To = -1;
  86. }
  87. if ($To == -1) {
  88. $Err[] = "Your user class is not eligible for promotions";
  89. } elseif ($Enabled != 1) {
  90. $Err[] = "This account is disabled, how did you get here?";
  91. } else {
  92. if ($Classes[$To]['NonSmall'] > 0) {
  93. $DB->query("
  94. SELECT COUNT(torrents.ID)
  95. FROM torrents
  96. JOIN torrents_group ON torrents.GroupID = torrents_group.ID
  97. WHERE (torrents_group.CategoryID != 3
  98. OR (torrents_group.CategoryID = 3 AND torrents_group.Pages >= 50))
  99. AND torrents.UserID = $UserID");
  100. if ($DB->has_results()) {
  101. list($NonSmall) = $DB->next_record();
  102. if ($NonSmall < $Classes[$To]['NonSmall']) {
  103. $Err[] = "You do not have enough large uploads.";
  104. }
  105. } else {
  106. $Err[] = "You do not have enough large uploads.";
  107. }
  108. }
  109. if ($Warned) {
  110. $Err[] = "You cannot be promoted while warned";
  111. }
  112. if ($LoggedUser['DisablePromotion']) {
  113. $Err[] = "You have been banned from purchasing promotions";
  114. }
  115. if ($BP < $Classes[$To]['Price']) {
  116. $Err[] = "Not enough points";
  117. }
  118. if ($Ratio < $Classes[$To]['MinRatio']) {
  119. $Err[] = "Your ratio is too low to be promoted. The minimum ratio required for this promotion is ".$Classes[$To]['MinRatio'].".";
  120. }
  121. if ($Upload < $Classes[$To]['MinUpload']*$GiB) {
  122. if ($Classes[$To]['MinUpload'] >= 1024) {
  123. $Amount = $Classes[$To]['MinUpload']/1024;
  124. $Unit = 'TiB';
  125. } else {
  126. $Amount = $Classes[$To]['MinUpload'];
  127. $Unit = 'GiB';
  128. }
  129. $Err[] = "You have not uploaded enough to be promoted. The minimum uploaded amount for this promotion is ".$Amount."".$Unit.".";
  130. }
  131. if ($Download < $Classes[$To]['MinDownload']*$GiB) {
  132. $Err[] = "You have not downloaded enough to be promoted. The minimum downloaded amount for this promotion is ".$Classes[$To]['MinDownload']."GiB.";
  133. }
  134. if ($Uploads < $Classes[$To]['MinUploads']) {
  135. $Err[] = "You have not uploaded enough torrents to be promoted. The minimum number of uploaded torrents for this promotion is ".$Classes[$To]['MinUploads'].".";
  136. }
  137. if ($Classes[$To]['UniqueTor'] && $Groups < $Classes[$To]['MinUploads']) {
  138. $Err[] = "You have not uploaded to enough unique torrent groups to be promoted. The minimum number of unique groups for this promotion is ".$Classes[$To]['MinUploads'].".";
  139. }
  140. if (!isset($Err)) {
  141. $DB->query("
  142. UPDATE users_main
  143. SET
  144. BonusPoints = BonusPoints - ".$Classes[$To]['Price'].",
  145. PermissionID = $To
  146. WHERE ID = $UserID");
  147. $DB->query("
  148. UPDATE users_info
  149. SET AdminComment = CONCAT('".sqltime()." - Class changed to ".Users::make_class_string($To)." via store purchase\n\n', AdminComment)
  150. WHERE UserID = $UserID");
  151. $Cache->delete_value("user_info_$UserID");
  152. $Cache->delete_value("user_info_heavy_$UserID");
  153. }
  154. }
  155. }
  156. View::show_header('Store'); ?>
  157. <div>
  158. <h2>Purchase <?=isset($Err)?"Failed":"Successful"?>
  159. </h2>
  160. <div class="box">
  161. <p>
  162. <?=isset($Err)?"Error: ".implode("<br />Error: ", $Err):"You have been promoted to ".$Classes[$To]['Name']."!"?>
  163. </p>
  164. <p>
  165. <a href="/store.php">Back to Store</a>
  166. </p>
  167. </div>
  168. </div>
  169. <?php
  170. View::show_footer();