Gazelle/sections/torrents/editgroupid.php

116 lines
3.6 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
/***************************************************************
* This page handles the backend of the "edit group ID" function
2013-02-22 08:00:24 +00:00
* (found on edit.php). It simply changes the group ID of a
* torrent.
2011-03-28 14:21:28 +00:00
****************************************************************/
2013-05-01 08:00:16 +00:00
if (!check_perms('torrents_edit')) {
error(403);
}
2011-03-28 14:21:28 +00:00
$OldGroupID = $_POST['oldgroupid'];
$GroupID = $_POST['groupid'];
$TorrentID = $_POST['torrentid'];
2013-05-01 08:00:16 +00:00
if (!is_number($OldGroupID) || !is_number($GroupID) || !is_number($TorrentID) || !$OldGroupID || !$GroupID || !$TorrentID) {
2011-03-28 14:21:28 +00:00
error(0);
}
2013-05-01 08:00:16 +00:00
if ($OldGroupID == $GroupID) {
2011-03-28 14:21:28 +00:00
header('Location: '.$_SERVER['HTTP_REFERER']);
die();
}
//Everything is legit, let's just confim they're not retarded
2013-05-01 08:00:16 +00:00
if (empty($_POST['confirm'])) {
2013-07-04 08:00:56 +00:00
$DB->query("
SELECT Name
FROM torrents_group
WHERE ID = $OldGroupID");
2013-07-10 00:08:53 +00:00
if (!$DB->has_results()) {
2011-03-28 14:21:28 +00:00
//Trying to move to an empty group? I think not!
2013-07-04 08:00:56 +00:00
set_message('That group does not exist!');
2011-03-28 14:21:28 +00:00
header('Location: '.$_SERVER['HTTP_REFERER']);
die();
}
list($Name) = $DB->next_record();
2013-07-04 08:00:56 +00:00
$DB->query("
SELECT CategoryID, Name
FROM torrents_group
WHERE ID = $GroupID");
list($CategoryID, $NewName) = $DB->next_record();
2013-07-04 08:00:56 +00:00
if ($Categories[$CategoryID - 1] != 'Music') {
error('Target must be a music group.');
}
2012-10-11 08:00:15 +00:00
$Artists = Artists::get_artists(array($OldGroupID, $GroupID));
2013-02-22 08:00:24 +00:00
2012-10-11 08:00:15 +00:00
View::show_header();
2011-03-28 14:21:28 +00:00
?>
<div class="thin">
2012-08-19 08:00:19 +00:00
<div class="header">
<h2>Change Group Confirm!</h2>
</div>
<div class="box pad">
2012-09-15 08:00:25 +00:00
<form class="confirm_form" name="torrent_group" action="torrents.php" method="post">
2012-08-19 08:00:19 +00:00
<input type="hidden" name="action" value="editgroupid" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
<input type="hidden" name="confirm" value="true" />
<input type="hidden" name="torrentid" value="<?=$TorrentID?>" />
<input type="hidden" name="oldgroupid" value="<?=$OldGroupID?>" />
<input type="hidden" name="groupid" value="<?=$GroupID?>" />
<h3>You are attempting to move the torrent with ID <?=$TorrentID?> from the group:</h3>
2013-07-04 08:00:56 +00:00
<ul>
<li><?= Artists::display_artists($Artists[$OldGroupID], true, false)?> - <a href="torrents.php?id=<?=$OldGroupID?>"><?=$Name?></a></li>
</ul>
2012-08-19 08:00:19 +00:00
<h3>Into the group:</h3>
2013-07-04 08:00:56 +00:00
<ul>
<li><?= Artists::display_artists($Artists[$GroupID], true, false)?> - <a href="torrents.php?id=<?=$GroupID?>"><?=$NewName?></a></li>
</ul>
2012-08-19 08:00:19 +00:00
<input type="submit" value="Confirm" />
</form>
</div>
2011-03-28 14:21:28 +00:00
</div>
<?
2012-10-11 08:00:15 +00:00
View::show_footer();
2011-03-28 14:21:28 +00:00
} else {
authorize();
$DB->query("UPDATE torrents
2013-07-04 08:00:56 +00:00
SET GroupID = '$GroupID'
WHERE ID = $TorrentID");
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Delete old torrent group if it's empty now
2013-07-04 08:00:56 +00:00
$DB->query("
SELECT COUNT(ID)
FROM torrents
WHERE GroupID = '$OldGroupID'");
2011-03-28 14:21:28 +00:00
list($TorrentsInGroup) = $DB->next_record();
2013-05-01 08:00:16 +00:00
if ($TorrentsInGroup == 0) {
2013-08-28 23:08:41 +00:00
// TODO: votes etc!
2013-07-04 08:00:56 +00:00
$DB->query("
2013-08-28 23:08:41 +00:00
UPDATE comments
SET PageID = '$GroupID'
WHERE Page = 'torrents' AND PageID = '$OldGroupID'");
2013-07-04 08:00:56 +00:00
$Cache->delete_value("torrent_comments_{$GroupID}_catalogue_0");
$Cache->delete_value("torrent_comments_$GroupID");
2012-10-11 08:00:15 +00:00
Torrents::delete_group($OldGroupID);
2011-03-28 14:21:28 +00:00
} else {
2012-10-11 08:00:15 +00:00
Torrents::update_hash($OldGroupID);
2011-03-28 14:21:28 +00:00
}
2012-10-11 08:00:15 +00:00
Torrents::update_hash($GroupID);
2013-02-22 08:00:24 +00:00
2012-10-11 08:00:15 +00:00
Misc::write_log("Torrent $TorrentID was edited by " . $LoggedUser['Username']); // TODO: this is probably broken
2013-07-04 08:00:56 +00:00
Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "merged group $OldGroupID", 0);
$DB->query("
UPDATE group_log
SET GroupID = $GroupID
WHERE GroupID = $OldGroupID");
2013-02-22 08:00:24 +00:00
2013-07-04 08:00:56 +00:00
$Cache->delete_value("torrents_details_$GroupID");
$Cache->delete_value("torrent_download_$TorrentID");
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
header("Location: torrents.php?id=$GroupID");
}
2013-05-01 08:00:16 +00:00
?>