Gazelle/sections/torrents/takenewgroup.php

66 lines
2.2 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
/***************************************************************
* This page handles the backend of the "new group" function
* which splits a torrent off into a new group.
****************************************************************/
authorize();
if(!check_perms('torrents_edit')) { error(403); }
$OldGroupID = $_POST['oldgroupid'];
$TorrentID = $_POST['torrentid'];
$ArtistName = db_string(trim($_POST['artist']));
$Title = db_string(trim($_POST['title']));
$Year = trim($_POST['year']);
$SearchText = db_string(trim($_POST['artist']) . ' ' . trim($_POST['title']) . ' ' . trim($_POST['year']));
if(!is_number($OldGroupID) || !is_number($TorrentID) || !is_number($Year) || !$OldGroupID || !$TorrentID || !$Year || empty($Title) || empty($ArtistName)) {
error(0);
}
2012-06-02 08:00:16 +00:00
$DB->query("SELECT ArtistID, AliasID, Redirect, Name FROM artists_alias WHERE Name = '$ArtistName'");
2011-03-28 14:21:28 +00:00
if($DB->record_count() == 0) {
$Redirect = 0;
$DB->query("INSERT INTO artists_group (Name) VALUES ('$ArtistName')");
$ArtistID = $DB->inserted_id();
$DB->query("INSERT INTO artists_alias (ArtistID, Name) VALUES ('$ArtistID', '$ArtistName')");
list($AliasID) = $DB->next_record();
} else {
list($ArtistID, $AliasID, $Redirect, $ArtistName) = $DB->next_record();
if($Redirect) {
$AliasID = $Redirect;
}
}
$DB->query("INSERT INTO torrents_group
(ArtistID, NumArtists, CategoryID, Name, Year, Time, WikiBody, WikiImage, SearchText)
VALUES
($ArtistID, '1', '1', '$Title', '$Year', '".sqltime()."', '', '', '$SearchText')");
$GroupID = $DB->inserted_id();
$DB->query("INSERT INTO torrents_artists
(GroupID, ArtistID, AliasID, Importance, UserID) VALUES
('$GroupID', '$ArtistID', '$AliasID', '1', '$LoggedUser[ID]')");
$DB->query("UPDATE torrents SET
GroupID='$GroupID'
WHERE ID='$TorrentID'");
// Delete old group if needed
$DB->query("SELECT ID FROM torrents WHERE GroupID='$OldGroupID'");
if($DB->record_count() == 0) {
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);
2011-03-28 14:21:28 +00:00
$Cache->delete_value('torrent_download_'.$TorrentID);
2012-10-11 08:00:15 +00:00
Misc::write_log("Torrent $TorrentID was edited by " . $LoggedUser['Username']);
2011-03-28 14:21:28 +00:00
header("Location: torrents.php?id=$GroupID");
?>