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.

take_unfill.php 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?
  2. //******************************************************************************//
  3. //--------------- Take unfill request ------------------------------------------//
  4. authorize();
  5. $RequestID = $_POST['id'];
  6. if (!is_number($RequestID)) {
  7. error(0);
  8. }
  9. $DB->query("
  10. SELECT
  11. r.CategoryID,
  12. r.UserID,
  13. r.FillerID,
  14. r.Title,
  15. u.Uploaded,
  16. u.BonusPoints,
  17. r.GroupID,
  18. t.UserID
  19. FROM requests AS r
  20. LEFT JOIN torrents AS t ON t.ID = TorrentID
  21. LEFT JOIN users_main AS u ON u.ID = FillerID
  22. WHERE r.ID = $RequestID");
  23. list($CategoryID, $UserID, $FillerID, $Title, $Uploaded, $BonusPoints, $GroupID, $UploaderID) = $DB->next_record();
  24. if (!$UploaderID) {
  25. // If the torrent was deleted and we don't know who the uploader was, just assume it was the filler
  26. $UploaderID = $FillerID;
  27. }
  28. if ((($LoggedUser['ID'] !== $UserID && $LoggedUser['ID'] !== $FillerID) && !check_perms('site_moderate_requests')) || $FillerID === '0') {
  29. error(403);
  30. }
  31. // Unfill
  32. $DB->query("
  33. UPDATE requests
  34. SET TorrentID = 0,
  35. FillerID = 0,
  36. TimeFilled = NULL,
  37. Visible = 1
  38. WHERE ID = $RequestID");
  39. $CategoryName = $Categories[$CategoryID - 1];
  40. $ArtistForm = Requests::get_artists($RequestID);
  41. $ArtistName = Artists::display_artists($ArtistForm, false, true);
  42. $FullName = $ArtistName.$Title;
  43. $RequestVotes = Requests::get_votes_array($RequestID);
  44. //Remove Filler portion of bounty
  45. if (intval($RequestVotes['TotalBounty']*(1/4)) > $Uploaded) {
  46. // If we can't take it all out of upload, attempt to take the rest out of bonus points
  47. $DB->query("
  48. UPDATE users_main
  49. SET Uploaded = 0
  50. WHERE ID = $FillerID");
  51. if (intval($RequestVotes['TotalBounty']*(1/4)-$Uploaded) > $BonusPoints) {
  52. // If we can't take the rest as bonus points, turn the remaining bit to download
  53. $DB->query("
  54. UPDATE users_main
  55. SET BonusPoints = 0
  56. WHERE ID = $FillerID");
  57. $DB->query('
  58. UPDATE users_main
  59. SET Downloaded = Downloaded + '.intval($RequestVotes['TotalBounty']*(1/4) - $Uploaded - $BonusPoints*1000)."
  60. WHERE ID = $FillerID");
  61. } else {
  62. $DB->query('
  63. UPDATE users_main
  64. SET BonusPoints = BonusPoints - '.intval(($RequestVotes['TotalBounty']*(1/4) - $Uploaded)/1000)."
  65. WHERE ID = $FillerID");
  66. }
  67. } else {
  68. $DB->query('
  69. UPDATE users_main
  70. SET Uploaded = Uploaded - '.intval($RequestVotes['TotalBounty']*(1/4))."
  71. WHERE ID = $FillerID");
  72. }
  73. $DB->query("
  74. SELECT
  75. Uploaded,
  76. BonusPoints
  77. FROM users_main
  78. WHERE ID = $UploaderID");
  79. list($UploaderUploaded, $UploaderBonusPoints) = $DB->next_record();
  80. //Remove Uploader portion of bounty
  81. if (intval($RequestVotes['TotalBounty']*(3/4)) > $UploaderUploaded) {
  82. // If we can't take it all out of upload, attempt to take the rest out of bonus points
  83. $DB->query("
  84. UPDATE users_main
  85. SET Uploaded = 0
  86. WHERE ID = $UploaderID");
  87. if (intval($RequestVotes['TotalBounty']*(3/4) - $UploaderUploaded) > $UploaderBonusPoints) {
  88. // If we can't take the rest as bonus points, turn the remaining bit to download
  89. $DB->query("
  90. UPDATE users_main
  91. SET BonusPoints = 0
  92. WHERE ID = $UploaderID");
  93. $DB->query('
  94. UPDATE users_main
  95. SET Downloaded = Downloaded + '.intval($RequestVotes['TotalBounty']*(3/4) - $UploaderUploaded - $UploaderBonusPoints*1000)."
  96. WHERE ID = $UploaderID");
  97. } else {
  98. $DB->query('
  99. UPDATE users_main
  100. SET BonusPoints = BonusPoints - '.intval(($RequestVotes['TotalBounty']*(3/4) - $UploaderUploaded)/1000)."
  101. WHERE ID = $UploaderID");
  102. }
  103. } else {
  104. $DB->query('
  105. UPDATE users_main
  106. SET Uploaded = Uploaded - '.intval($RequestVotes['TotalBounty']*(3/4))."
  107. WHERE ID = $UploaderID");
  108. }
  109. Misc::send_pm($FillerID, 0, 'A request you filled has been unfilled', "The request \"[url=".site_url()."requests.php?action=view&amp;id=$RequestID]$FullName"."[/url]\" was unfilled by [url=".site_url().'user.php?id='.$LoggedUser['ID'].']'.$LoggedUser['Username'].'[/url] for the reason: [quote]'.$_POST['reason']."[/quote]\nIf you feel like this request was unjustly unfilled, please [url=".site_url()."reports.php?action=report&amp;type=request&amp;id=$RequestID]report the request[/url] and explain why this request should not have been unfilled.");
  110. if ($UploaderID != $FillerID) {
  111. Misc::send_pm($UploaderID, 0, 'A request filled with your torrent has been unfilled', "The request \"[url=".site_url()."requests.php?action=view&amp;id=$RequestID]$FullName"."[/url]\" was unfilled by [url=".site_url().'user.php?id='.$LoggedUser['ID'].']'.$LoggedUser['Username'].'[/url] for the reason: [quote]'.$_POST['reason']."[/quote]\nIf you feel like this request was unjustly unfilled, please [url=".site_url()."reports.php?action=report&amp;type=request&amp;id=$RequestID]report the request[/url] and explain why this request should not have been unfilled.");
  112. }
  113. $Cache->delete_value("user_stats_$FillerID");
  114. if ($UserID !== $LoggedUser['ID']) {
  115. Misc::send_pm($UserID, 0, 'A request you created has been unfilled', "The request \"[url=".site_url()."requests.php?action=view&amp;id=$RequestID]$FullName"."[/url]\" was unfilled by [url=".site_url().'user.php?id='.$LoggedUser['ID'].']'.$LoggedUser['Username']."[/url] for the reason: [quote]".$_POST['reason'].'[/quote]');
  116. }
  117. Misc::write_log("Request $RequestID ($FullName), with a ".Format::get_size($RequestVotes['TotalBounty']).' bounty, was unfilled by user '.$LoggedUser['ID'].' ('.$LoggedUser['Username'].') for the reason: '.$_POST['reason']);
  118. $Cache->delete_value("request_$RequestID");
  119. $Cache->delete_value("request_artists_$RequestID");
  120. if ($GroupID) {
  121. $Cache->delete_value("requests_group_$GroupID");
  122. }
  123. Requests::update_sphinx_requests($RequestID);
  124. if (!empty($ArtistForm)) {
  125. foreach ($ArtistForm as $Artist) {
  126. $Cache->delete_value('artists_requests_'.$Artist['id']);
  127. }
  128. }
  129. $SphQL = new SphinxqlQuery();
  130. $SphQL->raw_query("
  131. UPDATE requests, requests_delta
  132. SET torrentid = 0, fillerid = 0
  133. WHERE id = $RequestID", false);
  134. header("Location: requests.php?action=view&id=$RequestID");
  135. ?>