Oppaitime'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

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