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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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` = '$group_id'
  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($group_id, $Free, $FreeType);
  36. }
  37. $Artists = $_POST['idols'];
  38. // Escape fields
  39. $workgroup = db_string($_POST['studio']);
  40. $location = db_string($_POST['series']);
  41. $published = db_string((int)$_POST['year']);
  42. $identifier = db_string($_POST['catalogue']);
  43. // Get some info for the group log
  44. $DB->query("
  45. SELECT
  46. `published`
  47. FROM
  48. `torrents_group`
  49. WHERE
  50. `id` = '$group_id'
  51. ");
  52. list($OldYear) = $DB->next_record();
  53. $DB->query("
  54. UPDATE
  55. `torrents_group`
  56. SET
  57. `published` = '$published',
  58. `identifier` = '$identifier',
  59. `workgroup` = '$workgroup',
  60. `location` = '$location'
  61. WHERE
  62. `id` = '$group_id'
  63. ");
  64. if ($OldYear !== $published) {
  65. $Message = db_string("Year changed from $OldYear to $published");
  66. $DB->query("
  67. INSERT INTO `group_log`(`GroupID`, `UserID`, `Time`, `Info`)
  68. VALUES(
  69. '$group_id',
  70. '$LoggedUser[ID]',
  71. NOW(),
  72. '$Message')
  73. ");
  74. }
  75. $DB->query("
  76. SELECT
  77. ag.`Name`
  78. FROM
  79. `artists_group` AS ag
  80. JOIN `torrents_artists` AS ta
  81. ON
  82. ag.`ArtistID` = ta.`ArtistID`
  83. WHERE
  84. ta.`GroupID` = '$group_id'
  85. ");
  86. while ($r = $DB->next_record(MYSQLI_ASSOC, true)) {
  87. $CurrArtists[] = $r['Name'];
  88. }
  89. foreach ($Artists as $Artist) {
  90. if (!in_array($Artist, $CurrArtists)) {
  91. $Artist = db_string($Artist);
  92. $DB->query("
  93. SELECT
  94. `ArtistID`
  95. FROM
  96. `artists_group`
  97. WHERE
  98. `Name` = '$Artist'
  99. ");
  100. if ($DB->has_results()) {
  101. list($ArtistID) = $DB->next_record();
  102. } else {
  103. $DB->query("
  104. INSERT INTO `artists_group`(`Name`)
  105. VALUES('$Artist')
  106. ");
  107. $ArtistID = $DB->inserted_id();
  108. }
  109. $DB->query("
  110. INSERT INTO `torrents_artists`(`GroupID`, `ArtistID`, `UserID`)
  111. VALUES(
  112. '$group_id',
  113. '$ArtistID',
  114. '$LoggedUser[ID]'
  115. )
  116. ON DUPLICATE KEY
  117. UPDATE
  118. `UserID` = '$LoggedUser[ID]'
  119. "); // Why does this even happen
  120. $Cache->delete_value('artist_groups_'.$ArtistID);
  121. }
  122. }
  123. foreach ($CurrArtists as $CurrArtist) {
  124. if (!in_array($CurrArtist, $Artists)) {
  125. $CurrArtist = db_string($CurrArtist);
  126. $DB->query("
  127. SELECT
  128. `ArtistID`
  129. FROM
  130. `artists_group`
  131. WHERE
  132. `Name` = '$CurrArtist'
  133. ");
  134. if ($DB->has_results()) {
  135. list($ArtistID) = $DB->next_record();
  136. $DB->query("
  137. DELETE
  138. FROM
  139. `torrents_artists`
  140. WHERE
  141. `ArtistID` = '$ArtistID'
  142. AND `GroupID` = '$group_id'
  143. ");
  144. $DB->query("
  145. SELECT
  146. `GroupID`
  147. FROM
  148. `torrents_artists`
  149. WHERE
  150. `ArtistID` = '$ArtistID'
  151. ");
  152. $Cache->delete_value('artist_groups_'.$ArtistID);
  153. if (!$DB->has_results()) {
  154. $DB->query("
  155. SELECT
  156. `RequestID`
  157. FROM
  158. `requests_artists`
  159. WHERE
  160. `ArtistID` = '$ArtistID'
  161. AND `ArtistID` != 0
  162. ");
  163. if (!$DB->has_results()) {
  164. Artists::delete_artist($ArtistID);
  165. }
  166. }
  167. }
  168. }
  169. }
  170. $DB->query("
  171. SELECT
  172. `ID`
  173. FROM
  174. `torrents`
  175. WHERE
  176. `GroupID` = '$group_id'
  177. ");
  178. while (list($TorrentID) = $DB->next_record()) {
  179. $Cache->delete_value("torrent_download_$TorrentID");
  180. }
  181. Torrents::update_hash($group_id);
  182. $Cache->delete_value("torrents_details_$group_id");
  183. header("Location: torrents.php?id=$group_id");