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 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 IS NULL,
  37. Visible = 1
  38. WHERE ID = $RequestID");
  39. $CategoryName = $Categories[$CategoryID - 1];
  40. if ($CategoryName != 'Other') {
  41. $ArtistForm = Requests::get_artists($RequestID);
  42. $ArtistName = Artists::display_artists($ArtistForm, false, true);
  43. $FullName = $ArtistName.$Title;
  44. } else {
  45. $FullName = $Title;
  46. }
  47. $RequestVotes = Requests::get_votes_array($RequestID);
  48. //Remove Filler portion of bounty
  49. if (intval($RequestVotes['TotalBounty']*(1/4)) > $Uploaded) {
  50. // If we can't take it all out of upload, attempt to take the rest out of bonus points
  51. $DB->query("
  52. UPDATE users_main
  53. SET Uploaded = 0
  54. WHERE ID = $FillerID");
  55. if (intval($RequestVotes['TotalBounty']*(1/4)-$Uploaded) > $BonusPoints) {
  56. // If we can't take the rest as bonus points, turn the remaining bit to download
  57. $DB->query("
  58. UPDATE users_main
  59. SET BonusPoints = 0
  60. WHERE ID = $FillerID");
  61. $DB->query('
  62. UPDATE users_main
  63. SET Downloaded = Downloaded + '.intval($RequestVotes['TotalBounty']*(1/4) - $Uploaded - $BonusPoints*1000)."
  64. WHERE ID = $FillerID");
  65. } else {
  66. $DB->query('
  67. UPDATE users_main
  68. SET BonusPoints = BonusPoints - '.intval(($RequestVotes['TotalBounty']*(1/4) - $Uploaded)/1000)."
  69. WHERE ID = $FillerID");
  70. }
  71. } else {
  72. $DB->query('
  73. UPDATE users_main
  74. SET Uploaded = Uploaded - '.intval($RequestVotes['TotalBounty']*(1/4))."
  75. WHERE ID = $FillerID");
  76. }
  77. $DB->query("
  78. SELECT
  79. Uploaded,
  80. BonusPoints
  81. FROM users_main
  82. WHERE ID = $UploaderID");
  83. list($UploaderUploaded, $UploaderBonusPoints) = $DB->next_record();
  84. //Remove Uploader portion of bounty
  85. if (intval($RequestVotes['TotalBounty']*(3/4)) > $UploaderUploaded) {
  86. // If we can't take it all out of upload, attempt to take the rest out of bonus points
  87. $DB->query("
  88. UPDATE users_main
  89. SET Uploaded = 0
  90. WHERE ID = $UploaderID");
  91. if (intval($RequestVotes['TotalBounty']*(3/4) - $UploaderUploaded) > $UploaderBonusPoints) {
  92. // If we can't take the rest as bonus points, turn the remaining bit to download
  93. $DB->query("
  94. UPDATE users_main
  95. SET BonusPoints = 0
  96. WHERE ID = $UploaderID");
  97. $DB->query('
  98. UPDATE users_main
  99. SET Downloaded = Downloaded + '.intval($RequestVotes['TotalBounty']*(3/4) - $UploaderUploaded - $UploaderBonusPoints*1000)."
  100. WHERE ID = $UploaderID");
  101. } else {
  102. $DB->query('
  103. UPDATE users_main
  104. SET BonusPoints = BonusPoints - '.intval(($RequestVotes['TotalBounty']*(3/4) - $UploaderUploaded)/1000)."
  105. WHERE ID = $UploaderID");
  106. }
  107. } else {
  108. $DB->query('
  109. UPDATE users_main
  110. SET Uploaded = Uploaded - '.intval($RequestVotes['TotalBounty']*(3/4))."
  111. WHERE ID = $UploaderID");
  112. }
  113. 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.");
  114. if ($UploaderID != $FillerID) {
  115. 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.");
  116. }
  117. $Cache->delete_value("user_stats_$FillerID");
  118. if ($UserID !== $LoggedUser['ID']) {
  119. 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]');
  120. }
  121. 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']);
  122. $Cache->delete_value("request_$RequestID");
  123. $Cache->delete_value("request_artists_$RequestID");
  124. if ($GroupID) {
  125. $Cache->delete_value("requests_group_$GroupID");
  126. }
  127. Requests::update_sphinx_requests($RequestID);
  128. if (!empty($ArtistForm)) {
  129. foreach ($ArtistForm as $Artist) {
  130. $Cache->delete_value('artists_requests_'.$Artist['id']);
  131. }
  132. }
  133. $SphQL = new SphinxqlQuery();
  134. $SphQL->raw_query("
  135. UPDATE requests, requests_delta
  136. SET torrentid = 0, fillerid = 0
  137. WHERE id = $RequestID", false);
  138. header("Location: requests.php?action=view&id=$RequestID");
  139. ?>