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

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