Gazelle/sections/torrents/add_alias.php

83 lines
2.7 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
authorize();
$UserID = $LoggedUser['ID'];
$GroupID = db_string($_POST['groupid']);
$Importances = $_POST['importance'];
$AliasNames = $_POST['aliasname'];
if(!is_number($GroupID) || !$GroupID) {
error(0);
}
$Changed = false;
for($i = 0; $i < count($AliasNames); $i++) {
2011-07-04 08:00:07 +00:00
$AliasName = normalise_artist_name($AliasNames[$i]);
2011-03-28 14:21:28 +00:00
$Importance = $Importances[$i];
2012-02-19 08:00:19 +00:00
if($Importance!='1' && $Importance!='2' && $Importance!='3' && $Importance!='4' && $Importance!='5' && $Importance!='6' && $Importance!='7') {
2011-03-28 14:21:28 +00:00
break;
}
if(strlen($AliasName) > 0) {
2011-04-29 13:49:03 +00:00
$DB->query("SELECT AliasID, ArtistID, Redirect, Name FROM artists_alias WHERE Name LIKE '".db_string($AliasName,true)."'");
2011-03-28 14:21:28 +00:00
if($DB->record_count() == 0) {
2011-04-29 13:49:03 +00:00
$AliasName = db_string($AliasName);
2011-03-28 14:21:28 +00:00
$DB->query("INSERT INTO artists_group (Name) VALUES ('$AliasName')");
$ArtistID = $DB->inserted_id();
$DB->query("INSERT INTO artists_alias (ArtistID, Name) VALUES ('$ArtistID', '$AliasName')");
$AliasID = $DB->inserted_id();
} else {
list($AliasID, $ArtistID, $Redirect, $AliasName) = $DB->next_record();
if($Redirect) {
$AliasID = $Redirect;
}
}
$DB->query("SELECT Name FROM torrents_group WHERE ID=".$GroupID);
list($GroupName) = $DB->next_record();
$DB->query("SELECT Name FROM artists_group WHERE ArtistID=".$ArtistID);
list($ArtistName) = $DB->next_record();
$DB->query("SELECT AliasID FROM torrents_artists WHERE GroupID='$GroupID' AND ArtistID='$ArtistID'");
if($DB->record_count() == 0) {
$Changed = true;
$DB->query("INSERT INTO torrents_artists
(GroupID, ArtistID, AliasID, Importance, UserID) VALUES
('$GroupID', '$ArtistID', '$AliasID', '$Importance', '$UserID')");
$DB->query("INSERT INTO torrents_group (ID, NumArtists)
SELECT ta.GroupID, COUNT(ta.ArtistID)
FROM torrents_artists AS ta
WHERE ta.GroupID='$GroupID'
AND ta.Importance='1'
GROUP BY ta.GroupID
ON DUPLICATE KEY UPDATE
NumArtists=VALUES(NumArtists);");
write_log("Artist ".$ArtistID." (".$ArtistName.") was added to the group ".$GroupID." (".$GroupName.") by user ".$LoggedUser['ID']." (".$LoggedUser['Username'].")");
2012-01-24 08:00:19 +00:00
write_group_log($GroupID, 0, $LoggedUser['ID'], "added artist ".$ArtistName, 0);
2011-03-28 14:21:28 +00:00
} else {
list($OldAliasID) = $DB->next_record();
if($OldAliasID == 0) {
$Changed = true;
$DB->query('UPDATE torrents_artists SET AliasID='.$AliasID.' WHERE GroupID='.$GroupID.' AND ArtistID='.$ArtistID);
}
}
}
}
if($Changed) {
$Cache->delete_value('torrents_details_'.$GroupID);
$Cache->delete_value('groups_artists_'.$GroupID); // Delete group artist cache
$Cache->delete_value('artist_'.$ArtistID);
update_hash($GroupID);
}
header('Location: '.$_SERVER['HTTP_REFERER']);
?>