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.

editgroupid.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?
  2. /***************************************************************
  3. * This page handles the backend of the "edit group ID" function
  4. * (found on edit.php). It simply changes the group ID of a
  5. * torrent.
  6. ****************************************************************/
  7. if (!check_perms('torrents_edit')) {
  8. error(403);
  9. }
  10. $OldGroupID = $_POST['oldgroupid'];
  11. $GroupID = $_POST['groupid'];
  12. $TorrentID = $_POST['torrentid'];
  13. if (!is_number($OldGroupID) || !is_number($GroupID) || !is_number($TorrentID) || !$OldGroupID || !$GroupID || !$TorrentID) {
  14. error(0);
  15. }
  16. if ($OldGroupID == $GroupID) {
  17. header('Location: '.$_SERVER['HTTP_REFERER']);
  18. die();
  19. }
  20. //Everything is legit, let's just confim they're not retarded
  21. if (empty($_POST['confirm'])) {
  22. $DB->query("
  23. SELECT Name
  24. FROM torrents_group
  25. WHERE ID = $OldGroupID");
  26. if (!$DB->has_results()) {
  27. //Trying to move to an empty group? I think not!
  28. set_message('The destination torrent group does not exist!');
  29. header('Location: '.$_SERVER['HTTP_REFERER']);
  30. die();
  31. }
  32. list($Name) = $DB->next_record();
  33. $DB->query("
  34. SELECT CategoryID, Name
  35. FROM torrents_group
  36. WHERE ID = $GroupID");
  37. list($CategoryID, $NewName) = $DB->next_record();
  38. $Artists = Artists::get_artists(array($OldGroupID, $GroupID));
  39. View::show_header();
  40. ?>
  41. <div class="thin">
  42. <div class="header">
  43. <h2>Torrent Group ID Change Confirmation</h2>
  44. </div>
  45. <div class="box pad">
  46. <form class="confirm_form" name="torrent_group" action="torrents.php" method="post">
  47. <input type="hidden" name="action" value="editgroupid" />
  48. <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
  49. <input type="hidden" name="confirm" value="true" />
  50. <input type="hidden" name="torrentid" value="<?=$TorrentID?>" />
  51. <input type="hidden" name="oldgroupid" value="<?=$OldGroupID?>" />
  52. <input type="hidden" name="groupid" value="<?=$GroupID?>" />
  53. <h3>You are attempting to move the torrent with ID <?=$TorrentID?> from the group:</h3>
  54. <ul>
  55. <li><?= Artists::display_artists($Artists[$OldGroupID], true, false)?> - <a href="torrents.php?id=<?=$OldGroupID?>"><?=$Name?></a></li>
  56. </ul>
  57. <h3>Into the group:</h3>
  58. <ul>
  59. <li><?= Artists::display_artists($Artists[$GroupID], true, false)?> - <a href="torrents.php?id=<?=$GroupID?>"><?=$NewName?></a></li>
  60. </ul>
  61. <input type="submit" value="Confirm" />
  62. </form>
  63. </div>
  64. </div>
  65. <?
  66. View::show_footer();
  67. } else {
  68. authorize();
  69. $DB->query("
  70. UPDATE torrents
  71. SET GroupID = '$GroupID'
  72. WHERE ID = $TorrentID");
  73. // Delete old torrent group if it's empty now
  74. $DB->query("
  75. SELECT COUNT(ID)
  76. FROM torrents
  77. WHERE GroupID = '$OldGroupID'");
  78. list($TorrentsInGroup) = $DB->next_record();
  79. if ($TorrentsInGroup == 0) {
  80. // TODO: votes etc!
  81. $DB->query("
  82. UPDATE comments
  83. SET PageID = '$GroupID'
  84. WHERE Page = 'torrents'
  85. AND PageID = '$OldGroupID'");
  86. $Cache->delete_value("torrent_comments_{$GroupID}_catalogue_0");
  87. $Cache->delete_value("torrent_comments_$GroupID");
  88. Torrents::delete_group($OldGroupID);
  89. } else {
  90. Torrents::update_hash($OldGroupID);
  91. }
  92. Torrents::update_hash($GroupID);
  93. Misc::write_log("Torrent $TorrentID was edited by " . $LoggedUser['Username']); // TODO: this is probably broken
  94. Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "merged group $OldGroupID", 0);
  95. $DB->query("
  96. UPDATE group_log
  97. SET GroupID = $GroupID
  98. WHERE GroupID = $OldGroupID");
  99. $Cache->delete_value("torrents_details_$GroupID");
  100. $Cache->delete_value("torrent_download_$TorrentID");
  101. header("Location: torrents.php?id=$GroupID");
  102. }
  103. ?>