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.5KB

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