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

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