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

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