Gazelle/sections/torrents/merge.php

100 lines
3.8 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
if(!check_perms('torrents_edit')) { error(403); }
$GroupID = $_POST['groupid'];
$OldGroupID = $GroupID;
$NewGroupID = db_string($_POST['targetgroupid']);
if(!$GroupID || !is_number($GroupID)) { error(404); }
if(!$NewGroupID || !is_number($NewGroupID)) { error(404); }
if($NewGroupID == $GroupID) {
error('Old group ID is the same as new group ID!');
}
$DB->query("SELECT CategoryID, Name FROM torrents_group WHERE ID='$NewGroupID'");
2011-03-28 14:21:28 +00:00
if($DB->record_count()==0) {
error('Target group does not exist.');
}
list($CategoryID, $NewName) = $DB->next_record();
if($Categories[$CategoryID-1] != 'Music') {
error('Only music groups can be merged.');
}
2012-01-24 08:00:19 +00:00
$DB->query("SELECT Name FROM torrents_group WHERE ID = ".$GroupID);
list($Name) = $DB->next_record();
2011-03-28 14:21:28 +00:00
//Everything is legit, let's just confim they're not retarded
if(empty($_POST['confirm'])) {
$Artists = get_artists(array($GroupID, $NewGroupID));
show_header();
?>
<div class="center thin">
2012-08-19 08:00:19 +00:00
<div class="header">
<h2>Merge Confirm!</h2>
</div>
2011-03-28 14:21:28 +00:00
<div class="box pad">
2012-09-15 08:00:25 +00:00
<form class="confirm_form" name="torrent_group" action="torrents.php" method="post">
2011-03-28 14:21:28 +00:00
<input type="hidden" name="action" value="merge" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
<input type="hidden" name="confirm" value="true" />
<input type="hidden" name="groupid" value="<?=$GroupID?>" />
<input type="hidden" name="targetgroupid" value="<?=$NewGroupID?>" />
2012-08-19 08:00:19 +00:00
<h3>You are attempting to merge the group:</h3>
2011-03-28 14:21:28 +00:00
<ul><li><?= display_artists($Artists[$GroupID], true, false)?> - <a href="torrents.php?id=<?=$GroupID?>"><?=$Name?></a></li></ul>
2012-08-19 08:00:19 +00:00
<h3>Into the group:</h3>
2011-03-28 14:21:28 +00:00
<ul><li><?= display_artists($Artists[$NewGroupID], true, false)?> - <a href="torrents.php?id=<?=$NewGroupID?>"><?=$NewName?></a></li></ul>
<input type="submit" value="Confirm" />
</form>
</div>
</div>
<?
show_footer();
} else {
authorize();
$DB->query("UPDATE torrents SET GroupID='$NewGroupID' WHERE GroupID='$GroupID'");
$DB->query("UPDATE wiki_torrents SET PageID='$NewGroupID' WHERE PageID='$GroupID'");
$DB->query("UPDATE torrents_comments SET GroupID='$NewGroupID' WHERE GroupID='$GroupID'");
delete_group($GroupID);
2012-01-24 08:00:19 +00:00
write_group_log($NewGroupID, 0, $LoggedUser['ID'], "Merged Group ".$GroupID." (".$Name.") to ".$NewGroupID." (".$NewName.")", 0);
$DB->query("UPDATE group_log SET GroupID = ".$NewGroupID." WHERE GroupID = ".$GroupID);
2011-03-28 14:21:28 +00:00
$GroupID=$NewGroupID;
//Collages
$DB->query("SELECT CollageID FROM collages_torrents WHERE GroupID='$OldGroupID'"); //Select all collages that contain edited group
while(list($CollageID) = $DB->next_record()) {
$DB->query("UPDATE IGNORE collages_torrents SET GroupID='$NewGroupID' WHERE GroupID='$OldGroupID' AND CollageID='$CollageID'"); //Change collage groupid to new ID
$DB->query("DELETE FROM collages_torrents WHERE GroupID='$OldGroupID' AND CollageID='$CollageID'");
$Cache->delete_value('collage_'.$CollageID);
}
2012-02-20 08:00:22 +00:00
//Requests
$DB->query("SELECT ID FROM requests WHERE GroupID='$OldGroupID'");
$Requests = $DB->collect('ID');
$DB->query("UPDATE requests SET GroupID = 'NewGroupID' WHERE GroupID = '$OldGroupID'");
foreach ($Requests as $RequestID) {
$Cache->delete_value('request_'.$RequestID);
}
2011-03-28 14:21:28 +00:00
$DB->query("SELECT ID FROM torrents WHERE GroupID='$OldGroupID'");
while(list($TorrentID) = $DB->next_record()) {
$Cache->delete_value('torrent_download_'.$TorrentID);
}
$Cache->delete_value('torrents_details_'.$GroupID);
$DB->query("SELECT DISTINCT ArtistID FROM torrents_artists WHERE GroupID IN ('$GroupID', '$OldGroupID')");
while(list($ArtistID) = $DB->next_record()) {
$Cache->delete_value('artist_'.$ArtistID);
}
$Cache->delete_value('torrent_comments_'.$GroupID.'_catalogue_0');
2012-06-17 08:00:18 +00:00
$Cache->delete_value('torrent_comments_'.$GroupID);
2011-03-28 14:21:28 +00:00
$Cache->delete_value('groups_artists_'.$GroupID);
update_hash($GroupID);
header('Location: torrents.php?id='.$GroupID);
}
2012-09-15 08:00:25 +00:00
?>