BioTorrents.de’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.

nonwikiedit.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. #declare(strict_types=1);
  3. authorize();
  4. //Set by system
  5. if (!$_POST['groupid'] || !is_number($_POST['groupid'])) {
  6. error(404);
  7. }
  8. $GroupID = $_POST['groupid'];
  9. //Usual perm checks
  10. if (!check_perms('torrents_edit')) {
  11. $DB->query("
  12. SELECT UserID
  13. FROM torrents
  14. WHERE GroupID = $GroupID");
  15. if (!in_array($LoggedUser['ID'], $DB->collect('UserID'))) {
  16. error(403);
  17. }
  18. }
  19. if (check_perms('torrents_freeleech') && (isset($_POST['freeleech']) xor isset($_POST['neutralleech']) xor isset($_POST['unfreeleech']))) {
  20. if (isset($_POST['freeleech'])) {
  21. $Free = 1;
  22. } elseif (isset($_POST['neutralleech'])) {
  23. $Free = 2;
  24. } else {
  25. $Free = 0;
  26. }
  27. if (isset($_POST['freeleechtype']) && in_array($_POST['freeleechtype'], array(0, 1, 2, 3))) {
  28. $FreeType = $_POST['freeleechtype'];
  29. } else {
  30. error(404);
  31. }
  32. Torrents::freeleech_groups($GroupID, $Free, $FreeType);
  33. }
  34. $Artists = $_POST['idols'];
  35. //Escape fields
  36. $Studio = db_string($_POST['studio']);
  37. $Series = db_string($_POST['series']);
  38. $Year = db_string((int)$_POST['year']);
  39. $CatalogueNumber = db_string($_POST['catalogue']);
  40. // Get some info for the group log
  41. $DB->query("
  42. SELECT Year
  43. FROM torrents_group
  44. WHERE ID = $GroupID");
  45. list($OldYear) = $DB->next_record();
  46. $DB->query("
  47. UPDATE torrents_group
  48. SET
  49. Year = '$Year',
  50. CatalogueNumber = '".$CatalogueNumber."',
  51. Studio = '$Studio',
  52. Series = '$Series',
  53. WHERE ID = $GroupID");
  54. if ($OldYear != $Year) {
  55. $DB->query("
  56. INSERT INTO group_log (GroupID, UserID, Time, Info)
  57. VALUES ('$GroupID', ".$LoggedUser['ID'].", NOW(), '".db_string("Year changed from $OldYear to $Year")."')");
  58. }
  59. $DB->query("
  60. SELECT ag.Name
  61. FROM artists_group AS ag
  62. JOIN torrents_artists AS ta ON ag.ArtistID = ta.ArtistID
  63. WHERE ta.GroupID = ".$GroupID);
  64. while ($r = $DB->next_record(MYSQLI_ASSOC, true)) {
  65. $CurrArtists[] = $r['Name'];
  66. }
  67. foreach ($Artists as $Artist) {
  68. if (!in_array($Artist, $CurrArtists)) {
  69. $DB->query("
  70. SELECT ArtistID
  71. FROM artists_group
  72. WHERE Name = '".db_string($Artist)."'");
  73. if ($DB->has_results()) {
  74. list($ArtistID) = $DB->next_record();
  75. } else {
  76. $DB->query("
  77. INSERT INTO artists_group
  78. (Name)
  79. VALUES
  80. ('".db_string($Artist)."')");
  81. $ArtistID = $DB->inserted_id();
  82. }
  83. $DB->query("
  84. INSERT INTO torrents_artists
  85. (GroupID, ArtistID, UserID)
  86. VALUES
  87. (".$GroupID.", ".$ArtistID.", ".$LoggedUser['ID'].")
  88. ON DUPLICATE KEY UPDATE UserID=".$LoggedUser['ID']); // Why does this even happen
  89. $Cache->delete_value('artist_groups_'.$ArtistID);
  90. }
  91. }
  92. foreach ($CurrArtists as $CurrArtist) {
  93. if (!in_array($CurrArtist, $Artists)) {
  94. $DB->query("
  95. SELECT ArtistID
  96. FROM artists_group
  97. WHERE Name = '".db_string($CurrArtist)."'");
  98. if ($DB->has_results()) {
  99. list($ArtistID) = $DB->next_record();
  100. $DB->query("
  101. DELETE FROM torrents_artists
  102. WHERE ArtistID = ".$ArtistID."
  103. AND GroupID = ".$GroupID);
  104. $DB->query("
  105. SELECT GroupID
  106. FROM torrents_artists
  107. WHERE ArtistID = ".$ArtistID);
  108. $Cache->delete_value('artist_groups_'.$ArtistID);
  109. if (!$DB->has_results()) {
  110. $DB->query("
  111. SELECT RequestID
  112. FROM requests_artists
  113. WHERE ArtistID = ".$ArtistID."
  114. AND ArtistID != 0");
  115. if (!$DB->has_results()) {
  116. Artists::delete_artist($ArtistID);
  117. }
  118. }
  119. }
  120. }
  121. }
  122. $DB->query("
  123. SELECT ID
  124. FROM torrents
  125. WHERE GroupID = '$GroupID'");
  126. while (list($TorrentID) = $DB->next_record()) {
  127. $Cache->delete_value("torrent_download_$TorrentID");
  128. }
  129. Torrents::update_hash($GroupID);
  130. $Cache->delete_value("torrents_details_$GroupID");
  131. header("Location: torrents.php?id=$GroupID");