Gazelle/sections/artist/add_alias.php

55 lines
2.0 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
authorize();
if(!check_perms('torrents_edit')) { error(403); }
$ArtistID = $_POST['artistid'];
$Redirect = $_POST['redirect'];
2012-06-02 08:00:16 +00:00
$AliasName = normalise_artist_name($_POST['name']);
$DBAliasName = db_string($AliasName);
if(!$Redirect) { $Redirect = 0; }
2011-03-28 14:21:28 +00:00
2011-06-03 08:00:07 +00:00
if(!is_number($ArtistID) || !($Redirect === 0 || is_number($Redirect)) || !$ArtistID) {
2011-03-28 14:21:28 +00:00
error(0);
}
if($AliasName == '') {
error('Blank artist name');
}
/*
* In the case of foo, who released an album before changing his name to bar and releasing another
* the field shared to make them appear on the same artist page is the ArtistID
* 1. For a normal artist, there'll be one entry, with the ArtistID, the same name as the artist and a 0 redirect
* 2. For Celine Dion (C<EFBFBD>line Dion), there's two, same ArtistID, diff Names, one has a redirect to the alias of the first
* 3. For foo, there's two, same ArtistID, diff names, no redirect
*/
2012-06-02 08:00:16 +00:00
$DB->query("SELECT AliasID, ArtistID, Name FROM artists_alias WHERE Name = '".$DBAliasName."'");
2012-05-18 13:35:17 +00:00
if($DB->record_count()) {
while(list($CloneAliasID, $CloneArtistID, $CloneAliasName) = $DB->next_record(MYSQLI_NUM, false)) {
if(!strcasecmp($CloneAliasName, $AliasName)) {
break;
}
}
if($CloneAliasID) {
if($Redirect == 0) {
$DB->query("UPDATE artists_alias SET ArtistID='".$ArtistID."', Redirect=0 WHERE AliasID='".$CloneAliasID."'");
} else {
error('An alias by that name already exists <a href="artist.php?id='.$CloneArtistID.'">here</a>. You can try renaming that artist to this one.');
}
2011-03-28 14:21:28 +00:00
}
}
2012-05-18 13:35:17 +00:00
if(!$CloneAliasID) {
$DB->query("INSERT INTO artists_alias(ArtistID, Name, Redirect, UserID)
VALUES
2012-06-02 08:00:16 +00:00
(".$ArtistID.", '".$DBAliasName."', ".$Redirect.", ".$LoggedUser['ID'].")");
2012-05-18 13:35:17 +00:00
$AliasID = $DB->inserted_id();
2011-03-28 14:21:28 +00:00
2012-05-18 13:35:17 +00:00
$DB->query("SELECT Name FROM artists_group WHERE ArtistID=".$ArtistID);
list($ArtistName) = $DB->next_record();
2011-03-28 14:21:28 +00:00
2012-06-02 08:00:16 +00:00
write_log("The alias ".$AliasID." (".$DBAliasName.") was added to the artist ".$ArtistID." (".$ArtistName.") by user ".$LoggedUser['ID']." (".$LoggedUser['Username'].")");
2012-05-18 13:35:17 +00:00
}
2011-03-28 14:21:28 +00:00
header('Location: '.$_SERVER['HTTP_REFERER']);
?>