Gazelle/sections/artist/add_alias.php

91 lines
2.9 KiB
PHP
Raw Permalink Normal View History

2011-03-28 14:21:28 +00:00
<?
authorize();
2013-05-05 08:00:31 +00:00
if (!check_perms('torrents_edit')) {
error(403);
}
2011-03-28 14:21:28 +00:00
$ArtistID = $_POST['artistid'];
$Redirect = $_POST['redirect'];
2012-10-11 08:00:15 +00:00
$AliasName = Artists::normalise_artist_name($_POST['name']);
2012-06-02 08:00:16 +00:00
$DBAliasName = db_string($AliasName);
2013-05-05 08:00:31 +00:00
if (!$Redirect) {
$Redirect = 0;
}
2011-03-28 14:21:28 +00:00
2013-05-05 08:00:31 +00:00
if (!is_number($ArtistID) || !($Redirect === 0 || is_number($Redirect)) || !$ArtistID) {
2011-03-28 14:21:28 +00:00
error(0);
}
2013-05-05 08:00:31 +00:00
if ($AliasName == '') {
2012-06-16 08:00:18 +00:00
error('Blank artist name.');
2011-03-28 14:21:28 +00:00
}
/*
* 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
*/
2013-05-05 08:00:31 +00:00
$DB->query("
SELECT AliasID, ArtistID, Name, Redirect
FROM artists_alias
2013-07-12 08:00:46 +00:00
WHERE Name = '$DBAliasName'");
2013-07-10 00:08:53 +00:00
if ($DB->has_results()) {
2013-05-05 08:00:31 +00:00
while (list($CloneAliasID, $CloneArtistID, $CloneAliasName, $CloneRedirect) = $DB->next_record(MYSQLI_NUM, false)) {
if (!strcasecmp($CloneAliasName, $AliasName)) {
2012-05-18 13:35:17 +00:00
break;
}
}
2013-05-05 08:00:31 +00:00
if ($CloneAliasID) {
if ($ArtistID == $CloneArtistID && $Redirect == 0) {
if ($CloneRedirect != 0) {
$DB->query("
UPDATE artists_alias
2013-07-13 08:00:46 +00:00
SET ArtistID = '$ArtistID', Redirect = 0
2013-07-12 08:00:46 +00:00
WHERE AliasID = '$CloneAliasID'");
2012-10-11 08:00:15 +00:00
Misc::write_log("Redirection for the alias $CloneAliasID ($DBAliasName) for the artist $ArtistID was removed by user $LoggedUser[ID] ($LoggedUser[Username])");
2012-06-16 08:00:18 +00:00
} else {
error('No changes were made as the target alias did not redirect anywhere.');
}
2012-05-18 13:35:17 +00:00
} 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
}
}
2013-05-05 08:00:31 +00:00
if (!$CloneAliasID) {
if ($Redirect) {
2013-07-12 08:00:46 +00:00
$DB->query("
SELECT ArtistID, Redirect
FROM artists_alias
WHERE AliasID = $Redirect");
2013-07-10 00:08:53 +00:00
if (!$DB->has_results()) {
2012-06-17 08:00:18 +00:00
error('Cannot redirect to a nonexistent artist alias.');
}
list($FoundArtistID, $FoundRedirect) = $DB->next_record();
2013-05-05 08:00:31 +00:00
if ($ArtistID != $FoundArtistID) {
2012-06-17 08:00:18 +00:00
error('Redirection must target an alias for the current artist.');
}
2013-05-05 08:00:31 +00:00
if ($FoundRedirect != 0) {
2012-06-17 08:00:18 +00:00
$Redirect = $FoundRedirect;
}
2012-06-16 08:00:18 +00:00
}
2013-05-05 08:00:31 +00:00
$DB->query("
2013-07-13 08:00:46 +00:00
INSERT INTO artists_alias
(ArtistID, Name, Redirect, UserID)
VALUES
($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
2013-07-12 08:00:46 +00:00
$DB->query("
SELECT Name
FROM artists_group
WHERE ArtistID = $ArtistID");
2012-06-16 08:00:18 +00:00
list($ArtistName) = $DB->next_record(MYSQLI_NUM, false);
2011-03-28 14:21:28 +00:00
2013-07-13 08:00:46 +00:00
Misc::write_log("The alias $AliasID ($DBAliasName) was added to the artist $ArtistID (".db_string($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']);
?>