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.

takenewgroup.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?
  2. #declare(strict_types = 1);
  3. /***************************************************************
  4. * This page handles the backend of the "new group" function
  5. * which splits a torrent off into a new group.
  6. ****************************************************************/
  7. authorize();
  8. if (!check_perms('torrents_edit')) {
  9. error(403);
  10. }
  11. $OldGroupID = $_POST['oldgroupid'];
  12. $TorrentID = $_POST['torrentid'];
  13. $ArtistName = db_string(trim($_POST['artist']));
  14. $Title = db_string(trim($_POST['title']));
  15. $Year = db_string(trim($_POST['year']));
  16. if (!is_number($OldGroupID) || !is_number($TorrentID) || !is_number($Year) || !$OldGroupID || !$TorrentID || !$Year || empty($Title) || empty($ArtistName)) {
  17. error(0);
  18. }
  19. //Everything is legit, let's just confim they're not retarded
  20. if (empty($_POST['confirm'])) {
  21. View::show_header();
  22. ?>
  23. <div class="center">
  24. <div class="header">
  25. <h2>Split Confirm!</h2>
  26. </div>
  27. <div class="box pad">
  28. <form class="confirm_form" name="torrent_group" action="torrents.php" method="post">
  29. <input type="hidden" name="action" value="newgroup" />
  30. <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
  31. <input type="hidden" name="confirm" value="true" />
  32. <input type="hidden" name="torrentid" value="<?=$TorrentID?>" />
  33. <input type="hidden" name="oldgroupid" value="<?=$OldGroupID?>" />
  34. <input type="hidden" name="artist" value="<?=display_str($_POST['artist'])?>" />
  35. <input type="hidden" name="title" value="<?=display_str($_POST['title'])?>" />
  36. <input type="hidden" name="year" value="<?=$Year?>" />
  37. <h3>You are attempting to split the torrent <a href="torrents.php?torrentid=<?=$TorrentID?>"><?=$TorrentID?></a> off into a new group:</h3>
  38. <ul><li><?=display_str($_POST['artist'])?> - <?=display_str($_POST['title'])?> [<?=$Year?>]</li></ul>
  39. <input type="submit" value="Confirm" />
  40. </form>
  41. </div>
  42. </div>
  43. <?
  44. View::show_footer();
  45. } else {
  46. $DB->query("
  47. SELECT ArtistID, Name
  48. FROM artists_group
  49. WHERE Name = '$ArtistName'");
  50. if (!$DB->has_results()) {
  51. $DB->query("
  52. INSERT INTO artists_group (Name)
  53. VALUES ('$ArtistName')");
  54. $ArtistID = $DB->inserted_id();
  55. } else {
  56. list($ArtistID, $ArtistName) = $DB->next_record();
  57. }
  58. $DB->query("
  59. SELECT CategoryID
  60. FROM torrents_group
  61. WHERE ID = $OldGroupID");
  62. list($CategoryID) = $DB->next_record();
  63. $DB->query("
  64. INSERT INTO torrents_group
  65. (CategoryID, Name, Year, Time, WikiBody, WikiImage)
  66. VALUES
  67. ('$CategoryID', '$Title', '$Year', NOW(), '', '')");
  68. $GroupID = $DB->inserted_id();
  69. $DB->query("
  70. INSERT INTO torrents_artists
  71. (GroupID, ArtistID, UserID)
  72. VALUES
  73. ('$GroupID', '$ArtistID', '$LoggedUser[ID]')");
  74. $DB->query("
  75. UPDATE torrents
  76. SET GroupID = '$GroupID'
  77. WHERE ID = '$TorrentID'");
  78. // Delete old group if needed
  79. $DB->query("
  80. SELECT ID
  81. FROM torrents
  82. WHERE GroupID = '$OldGroupID'");
  83. if (!$DB->has_results()) {
  84. Torrents::delete_group($OldGroupID);
  85. } else {
  86. Torrents::update_hash($OldGroupID);
  87. }
  88. Torrents::update_hash($GroupID);
  89. $Cache->delete_value("torrent_download_$TorrentID");
  90. Misc::write_log("Torrent $TorrentID was edited by " . $LoggedUser['Username']);
  91. header("Location: torrents.php?id=$GroupID");
  92. }
  93. ?>