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.

freeleechpool.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?
  2. if (isset($_POST['donation'])) {
  3. $Donation = $_POST['donation'];
  4. if (!is_numeric($Donation) || $Donation < 1) {
  5. error('Invalid donation');
  6. }
  7. $UserID = $LoggedUser['ID'];
  8. $DB->query("
  9. SELECT BonusPoints
  10. FROM users_main
  11. WHERE ID = $UserID");
  12. if ($DB->has_results()) {
  13. list($Points) = $DB->next_record();
  14. if ($Points >= $Donation) {
  15. $PoolTipped = false;
  16. $DB->query("
  17. UPDATE users_main
  18. SET BonusPoints = BonusPoints - $Donation
  19. WHERE ID = $UserID");
  20. $DB->query("
  21. UPDATE misc
  22. SET First = First + $Donation
  23. WHERE Name = 'FreeleechPool'");
  24. $Cache->delete_value('user_info_heavy_'.$UserID);
  25. // Check to see if we're now over the target pool size
  26. $DB->query("
  27. SELECT First, Second
  28. FROM misc
  29. WHERE Name = 'FreeleechPool'");
  30. if ($DB->has_results()) {
  31. list($Pool, $Target) = $DB->next_record();
  32. if ($Pool > $Target) {
  33. $PoolTipped = true;
  34. $NumTorrents = rand(2, 6);
  35. $Torrents = array();
  36. for ($i = 0; $i < $NumTorrents; $i++) {
  37. $TorrentSize = intval($Pool * (($i==$NumTorrents-1)?1:(rand(10,80)/100)) * 100000);
  38. $DB->query("
  39. SELECT ID, Size
  40. FROM torrents
  41. WHERE Size < $TorrentSize
  42. AND Size > ($TorrentSize * 0.9)
  43. AND Seeders > 0
  44. AND FreeLeechType = '0'
  45. ORDER BY Seeders ASC, Size DESC
  46. LIMIT 1");
  47. if ($DB->has_results()) {
  48. list($TorrentID, $Size) = $DB->next_record();
  49. $DB->query("
  50. INSERT INTO shop_freeleeches
  51. (TorrentID, ExpiryTime)
  52. VALUES($TorrentID, NOW() + INTERVAL 2 DAY)");
  53. Torrents::freeleech_torrents($TorrentID, 1, 3);
  54. $Pool -= $TorrentSize/100000;
  55. } else {
  56. // Failed to find a torrent. Maybe try again with a new value, maybe move on
  57. if (rand(1,5) > 1) { $i--; }
  58. }
  59. }
  60. $Target = rand(10000, 100000);
  61. $DB->query("
  62. UPDATE misc
  63. SET First = 0,
  64. Second = $Target
  65. WHERE Name = 'FreeleechPool'");
  66. }
  67. }
  68. $Cache->delete_value('shop_freeleech_list');
  69. } else {
  70. error("Not enough points to donate");
  71. }
  72. }
  73. View::show_header('Store'); ?>
  74. <div class="thin">
  75. <h2 id="general">Donation Successful</h2>
  76. <div class="box pad" style="padding: 10px 10px 10px 20px;">
  77. <p>You donated <?=number_format($Donation)?> <?=BONUS_POINTS?> to the Freeleech Pool</p>
  78. <? if ($PoolTipped) { ?>
  79. <p>Your donation triggered a freeleech!</p>
  80. <? } ?>
  81. <p><a href="/store.php">Back to Store</a></p>
  82. </div>
  83. </div>
  84. <? View::show_footer();
  85. } else {
  86. $DB->query("
  87. SELECT First
  88. FROM misc
  89. WHERE Name = 'FreeleechPool'");
  90. if ($DB->has_results()) {
  91. list($Pool) = $DB->next_record();
  92. } else {
  93. $Pool = 0;
  94. }
  95. View::show_header('Store'); ?>
  96. <div class="thin">
  97. <div class="box pad" style="padding: 10px 10px 10px 20px; text-align: center;">
  98. <form action="store.php" method="POST">
  99. <input type="hidden" name="item" value="freeleechpool">
  100. <strong>
  101. There are currently <?=number_format($Pool)?> <?=BONUS_POINTS?> in the Freeleech Pool
  102. </strong>
  103. <br><br>
  104. <input type="text" name="donation" value="">
  105. <input type="submit" value="Donate">
  106. </form>
  107. <p><a href="/store.php">Back to Store</a></p>
  108. </div>
  109. </div>
  110. <? View::show_footer();
  111. }
  112. ?>