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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. 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. <div class="center">
  23. <div class="header">
  24. <h2>Split Confirm!</h2>
  25. </div>
  26. <div class="box pad">
  27. <form class="confirm_form" name="torrent_group" action="torrents.php" method="post">
  28. <input type="hidden" name="action" value="newgroup" />
  29. <input type="hidden" name="auth"
  30. value="<?=$LoggedUser['AuthKey']?>" />
  31. <input type="hidden" name="confirm" value="true" />
  32. <input type="hidden" name="torrentid"
  33. value="<?=$TorrentID?>" />
  34. <input type="hidden" name="oldgroupid"
  35. value="<?=$OldGroupID?>" />
  36. <input type="hidden" name="artist"
  37. value="<?=display_str($_POST['artist'])?>" />
  38. <input type="hidden" name="title"
  39. value="<?=display_str($_POST['title'])?>" />
  40. <input type="hidden" name="year" value="<?=$Year?>" />
  41. <h3>You are attempting to split the torrent <a
  42. href="torrents.php?torrentid=<?=$TorrentID?>"><?=$TorrentID?></a> off into a new group:</h3>
  43. <ul>
  44. <li><?=display_str($_POST['artist'])?> -
  45. <?=display_str($_POST['title'])?>
  46. [<?=$Year?>]
  47. </li>
  48. </ul>
  49. <input type="submit" value="Confirm" />
  50. </form>
  51. </div>
  52. </div>
  53. <?php
  54. View::show_footer();
  55. } else {
  56. $DB->query("
  57. SELECT ArtistID, Name
  58. FROM artists_group
  59. WHERE Name = '$ArtistName'");
  60. if (!$DB->has_results()) {
  61. $DB->query("
  62. INSERT INTO artists_group (Name)
  63. VALUES ('$ArtistName')");
  64. $ArtistID = $DB->inserted_id();
  65. } else {
  66. list($ArtistID, $ArtistName) = $DB->next_record();
  67. }
  68. $DB->query("
  69. SELECT CategoryID
  70. FROM torrents_group
  71. WHERE ID = $OldGroupID");
  72. list($CategoryID) = $DB->next_record();
  73. $DB->query("
  74. INSERT INTO torrents_group
  75. (CategoryID, Name, Year, Time, WikiBody, WikiImage)
  76. VALUES
  77. ('$CategoryID', '$Title', '$Year', NOW(), '', '')");
  78. $GroupID = $DB->inserted_id();
  79. $DB->query("
  80. INSERT INTO torrents_artists
  81. (GroupID, ArtistID, UserID)
  82. VALUES
  83. ('$GroupID', '$ArtistID', '$LoggedUser[ID]')");
  84. $DB->query("
  85. UPDATE torrents
  86. SET GroupID = '$GroupID'
  87. WHERE ID = '$TorrentID'");
  88. // Delete old group if needed
  89. $DB->query("
  90. SELECT ID
  91. FROM torrents
  92. WHERE GroupID = '$OldGroupID'");
  93. if (!$DB->has_results()) {
  94. Torrents::delete_group($OldGroupID);
  95. } else {
  96. Torrents::update_hash($OldGroupID);
  97. }
  98. Torrents::update_hash($GroupID);
  99. $Cache->delete_value("torrent_download_$TorrentID");
  100. Misc::write_log("Torrent $TorrentID was edited by " . $LoggedUser['Username']);
  101. header("Location: torrents.php?id=$GroupID");
  102. }