Gazelle/sections/torrents/takechangecategory.php

127 lines
3.6 KiB
PHP
Raw Normal View History

2013-03-02 08:00:34 +00:00
<?
/***************************************************************
* Temp handler for changing the category for a single torrent.
****************************************************************/
authorize();
if (!check_perms('users_mod')) {
error(403);
}
$OldGroupID = $_POST['oldgroupid'];
$TorrentID = $_POST['torrentid'];
$Title = db_string(trim($_POST['title']));
$OldCategoryID = $_POST['oldcategoryid'];
$NewCategoryID = $_POST['newcategoryid'];
if (!is_number($OldGroupID) || !is_number($TorrentID) || !$OldGroupID || !$TorrentID || empty($Title)) {
error(0);
}
switch ($Categories[$NewCategoryID-1]) {
case 'Music':
$ArtistName = db_string(trim($_POST['artist']));
$Year = trim($_POST['year']);
$ReleaseType = trim($_POST['releasetype']);
if (empty($Year) || empty($ArtistName) || !is_number($Year) || empty($ReleaseType) || !is_number($ReleaseType)) {
error(0);
}
$SearchText = "$ArtistName $Title $Year";
2013-06-19 08:01:09 +00:00
$DB->query("
SELECT ArtistID, AliasID, Redirect, Name
FROM artists_alias
WHERE Name LIKE '$ArtistName'");
2013-07-10 00:08:53 +00:00
if (!$DB->has_results()) {
2013-03-02 08:00:34 +00:00
$Redirect = 0;
2013-06-19 08:01:09 +00:00
$DB->query("
INSERT INTO artists_group (Name)
VALUES ('$ArtistName')");
2013-03-02 08:00:34 +00:00
$ArtistID = $DB->inserted_id();
2013-06-19 08:01:09 +00:00
$DB->query("
INSERT INTO artists_alias (ArtistID, Name)
VALUES ('$ArtistID', '$ArtistName')");
2013-03-02 08:00:34 +00:00
$AliasID = $DB->inserted_id();
} else {
list($ArtistID, $AliasID, $Redirect, $ArtistName) = $DB->next_record();
if ($Redirect) {
$AliasID = $ArtistID;
}
}
2013-06-19 08:01:09 +00:00
$DB->query("
INSERT INTO torrents_group
(ArtistID, NumArtists, CategoryID, Name, Year, ReleaseType, Time, WikiBody, WikiImage, SearchText)
2013-03-02 08:00:34 +00:00
VALUES
2013-06-19 08:01:09 +00:00
($ArtistID, '1', '1', '$Title', '$Year', '$ReleaseType', '".sqltime()."', '', '', '$SearchText')");
2013-03-02 08:00:34 +00:00
$GroupID = $DB->inserted_id();
2013-06-19 08:01:09 +00:00
$DB->query("
INSERT INTO torrents_artists
(GroupID, ArtistID, AliasID, Importance, UserID)
VALUES
('$GroupID', '$ArtistID', '$AliasID', '1', '$LoggedUser[ID]')");
2013-03-02 08:00:34 +00:00
break;
case 'Audiobooks':
case 'Comedy':
$Year = trim($_POST['year']);
if (empty($Year) || !is_number($Year)) {
error(0);
}
$SearchText = "$Title $Year";
2013-06-19 08:01:09 +00:00
$DB->query("
INSERT INTO torrents_group
(CategoryID, Name, Year, Time, WikiBody, WikiImage, SearchText)
2013-03-02 08:00:34 +00:00
VALUES
2013-06-19 08:01:09 +00:00
($NewCategoryID, '$Title', '$Year', '".sqltime()."', '', '', '$SearchText')");
2013-03-02 08:00:34 +00:00
$GroupID = $DB->inserted_id();
break;
case 'Applications':
case 'Comics':
case 'E-Books':
case 'E-Learning Videos':
$SearchText = $Title;
2013-06-19 08:01:09 +00:00
$DB->query("
INSERT INTO torrents_group
(CategoryID, Name, Time, WikiBody, WikiImage, SearchText)
2013-03-02 08:00:34 +00:00
VALUES
2013-06-19 08:01:09 +00:00
($NewCategoryID, '$Title', '".sqltime()."', '', '', '$SearchText')");
2013-03-02 08:00:34 +00:00
$GroupID = $DB->inserted_id();
break;
}
2013-06-19 08:01:09 +00:00
$DB->query("
UPDATE torrents
SET GroupID = '$GroupID'
WHERE ID = '$TorrentID'");
2013-03-02 08:00:34 +00:00
// Delete old group if needed
2013-06-19 08:01:09 +00:00
$DB->query("
SELECT ID
FROM torrents
WHERE GroupID = '$OldGroupID'");
2013-07-10 00:08:53 +00:00
if (!$DB->has_results()) {
2013-08-28 23:08:41 +00:00
// TODO: votes etc.
2013-06-19 08:01:09 +00:00
$DB->query("
2013-08-28 23:08:41 +00:00
UPDATE comments
SET PageID = '$GroupID'
WHERE Page = 'torrents'
AND PageID = '$OldGroupID'");
2013-03-02 08:00:34 +00:00
Torrents::delete_group($OldGroupID);
2013-06-19 08:01:09 +00:00
$Cache->delete_value("torrent_comments_{$GroupID}_catalogue_0");
2013-03-02 08:00:34 +00:00
} else {
Torrents::update_hash($OldGroupID);
}
Torrents::update_hash($GroupID);
2013-06-19 08:01:09 +00:00
$Cache->delete_value("torrent_download_$TorrentID");
2013-03-02 08:00:34 +00:00
Misc::write_log("Torrent $TorrentID was edited by $LoggedUser[Username]");
Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "merged from group $OldGroupID", 0);
2013-06-19 08:01:09 +00:00
$DB->query("
UPDATE group_log
SET GroupID = $GroupID
WHERE GroupID = $OldGroupID");
2013-03-02 08:00:34 +00:00
header("Location: torrents.php?id=$GroupID");
?>