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.

promotion.php 5.6KB

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