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_vote.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?
  2. //******************************************************************************//
  3. //--------------- Vote on a request --------------------------------------------//
  4. //This page is ajax!
  5. if (!check_perms('site_vote')) {
  6. error(403);
  7. }
  8. authorize();
  9. if (empty($_GET['id']) || !is_number($_GET['id'])) {
  10. error(0);
  11. }
  12. $RequestID = $_GET['id'];
  13. if (empty($_GET['amount']) || !is_number($_GET['amount']) || $_GET['amount'] < $MinimumVote) {
  14. $Amount = $MinimumVote;
  15. } else {
  16. $Amount = $_GET['amount'];
  17. }
  18. $Bounty = ($Amount * (1 - $RequestTax));
  19. $DB->query("
  20. SELECT TorrentID
  21. FROM requests
  22. WHERE ID = $RequestID");
  23. list($Filled) = $DB->next_record();
  24. if ($LoggedUser['BytesUploaded'] >= $Amount && $Filled === '0') {
  25. // Create vote!
  26. $DB->query("
  27. INSERT IGNORE INTO requests_votes
  28. (RequestID, UserID, Bounty)
  29. VALUES
  30. ($RequestID, ".$LoggedUser['ID'].", $Bounty)");
  31. if ($DB->affected_rows() < 1) {
  32. //Insert failed, probably a dupe vote, just increase their bounty.
  33. $DB->query("
  34. UPDATE requests_votes
  35. SET Bounty = (Bounty + $Bounty)
  36. WHERE UserID = ".$LoggedUser['ID']."
  37. AND RequestID = $RequestID");
  38. echo 'dupe';
  39. }
  40. $DB->query("
  41. UPDATE requests
  42. SET LastVote = NOW()
  43. WHERE ID = $RequestID");
  44. $Cache->delete_value("request_$RequestID");
  45. $Cache->delete_value("request_votes_$RequestID");
  46. $ArtistForm = Requests::get_artists($RequestID);
  47. foreach ($ArtistForm as $Artist) {
  48. $Cache->delete_value('artists_requests_'.$Artist['id']);
  49. }
  50. // Subtract amount from user
  51. $DB->query("
  52. UPDATE users_main
  53. SET Uploaded = (Uploaded - $Amount)
  54. WHERE ID = ".$LoggedUser['ID']);
  55. $Cache->delete_value('user_stats_'.$LoggedUser['ID']);
  56. Requests::update_sphinx_requests($RequestID);
  57. echo 'success';
  58. $DB->query("
  59. SELECT UserID
  60. FROM requests_votes
  61. WHERE RequestID = '$RequestID'
  62. AND UserID != '$LoggedUser[ID]'");
  63. $UserIDs = array();
  64. while (list($UserID) = $DB->next_record()) {
  65. $UserIDs[] = $UserID;
  66. }
  67. // NotificationsManager::notify_users($UserIDs, NotificationsManager::REQUESTALERTS, Format::get_size($Amount) . " of bounty has been added to a request you've voted on!", "requests.php?action=view&id=" . $RequestID);
  68. } elseif ($LoggedUser['BytesUploaded'] < $Amount) {
  69. echo 'bankrupt';
  70. }
  71. ?>