Gazelle/sections/torrents/takenewgroup.php

109 lines
3.3 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
/***************************************************************
* This page handles the backend of the "new group" function
2013-02-22 08:00:24 +00:00
* which splits a torrent off into a new group.
2011-03-28 14:21:28 +00:00
****************************************************************/
authorize();
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'];
$TorrentID = $_POST['torrentid'];
$ArtistName = db_string(trim($_POST['artist']));
$Title = db_string(trim($_POST['title']));
$Year = trim($_POST['year']);
2013-05-01 08:00:16 +00:00
if (!is_number($OldGroupID) || !is_number($TorrentID) || !is_number($Year) || !$OldGroupID || !$TorrentID || !$Year || empty($Title) || empty($ArtistName)) {
2011-03-28 14:21:28 +00:00
error(0);
}
2013-02-16 08:00:57 +00:00
//Everything is legit, let's just confim they're not retarded
2013-05-01 08:00:16 +00:00
if (empty($_POST['confirm'])) {
2013-02-16 08:00:57 +00:00
View::show_header();
?>
<div class="center thin">
<div class="header">
<h2>Split Confirm!</h2>
</div>
<div class="box pad">
<form class="confirm_form" name="torrent_group" action="torrents.php" method="post">
<input type="hidden" name="action" value="newgroup" />
<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="artist" value="<?=display_str($_POST['artist'])?>" />
<input type="hidden" name="title" value="<?=display_str($_POST['title'])?>" />
<input type="hidden" name="year" value="<?=$Year?>" />
<h3>You are attempting to split the torrent <a href="torrents.php?torrentid=<?=$TorrentID?>"><?=$TorrentID?></a> off into a new group:</h3>
<ul><li><?=display_str($_POST['artist'])?> - <?=display_str($_POST['title'])?> [<?=$Year?>]</li></ul>
<input type="submit" value="Confirm" />
</form>
</div>
</div>
<?
View::show_footer();
2011-03-28 14:21:28 +00:00
} else {
2013-07-04 08:00:56 +00:00
$DB->query("
SELECT ArtistID, AliasID, Redirect, Name
FROM artists_alias
WHERE Name = '$ArtistName'");
2013-07-10 00:08:53 +00:00
if (!$DB->has_results()) {
2013-02-16 08:00:57 +00:00
$Redirect = 0;
2013-07-04 08:00:56 +00:00
$DB->query("
INSERT INTO artists_group (Name)
VALUES ('$ArtistName')");
2013-02-16 08:00:57 +00:00
$ArtistID = $DB->inserted_id();
2013-07-04 08:00:56 +00:00
$DB->query("
INSERT INTO artists_alias (ArtistID, Name)
VALUES ('$ArtistID', '$ArtistName')");
2013-02-16 08:00:57 +00:00
$AliasID = $DB->inserted_id();
} else {
list($ArtistID, $AliasID, $Redirect, $ArtistName) = $DB->next_record();
2013-05-01 08:00:16 +00:00
if ($Redirect) {
2013-02-16 08:00:57 +00:00
$AliasID = $Redirect;
}
2011-03-28 14:21:28 +00:00
}
2013-07-04 08:00:56 +00:00
$DB->query("
INSERT INTO torrents_group
2013-11-11 08:00:59 +00:00
(ArtistID, CategoryID, Name, Year, Time, WikiBody, WikiImage)
2013-02-16 08:00:57 +00:00
VALUES
2013-11-11 08:00:59 +00:00
($ArtistID, '1', '$Title', '$Year', '".sqltime()."', '', '')");
2013-02-16 08:00:57 +00:00
$GroupID = $DB->inserted_id();
2011-03-28 14:21:28 +00:00
2013-07-04 08:00:56 +00:00
$DB->query("
INSERT INTO torrents_artists
(GroupID, ArtistID, AliasID, Importance, UserID)
VALUES
('$GroupID', '$ArtistID', '$AliasID', '1', '$LoggedUser[ID]')");
2011-03-28 14:21:28 +00:00
2013-07-04 08:00:56 +00:00
$DB->query("
UPDATE torrents
SET GroupID = '$GroupID'
WHERE ID = '$TorrentID'");
2011-03-28 14:21:28 +00:00
2013-02-16 08:00:57 +00:00
// Delete old group if needed
2013-07-04 08:00:56 +00:00
$DB->query("
SELECT ID
FROM torrents
WHERE GroupID = '$OldGroupID'");
2013-07-10 00:08:53 +00:00
if (!$DB->has_results()) {
2013-02-16 08:00:57 +00:00
Torrents::delete_group($OldGroupID);
} else {
Torrents::update_hash($OldGroupID);
}
2011-03-28 14:21:28 +00:00
2013-02-16 08:00:57 +00:00
Torrents::update_hash($GroupID);
2011-03-28 14:21:28 +00:00
2013-07-04 08:00:56 +00:00
$Cache->delete_value("torrent_download_$TorrentID");
2011-03-28 14:21:28 +00:00
2013-02-16 08:00:57 +00:00
Misc::write_log("Torrent $TorrentID was edited by " . $LoggedUser['Username']);
2011-03-28 14:21:28 +00:00
2013-02-16 08:00:57 +00:00
header("Location: torrents.php?id=$GroupID");
}
2011-03-28 14:21:28 +00:00
?>