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

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