Gazelle/sections/torrents/add_alias.php

86 lines
2.3 KiB
PHP
Raw Permalink 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'];
2012-11-20 08:00:19 +00:00
if (!is_number($GroupID) || !$GroupID) {
2011-03-28 14:21:28 +00:00
error(0);
}
2013-11-11 08:00:59 +00:00
$DB->query("
SELECT Name
FROM torrents_group
WHERE ID = $GroupID");
if (!$DB->has_results()) {
error(404);
}
list($GroupName) = $DB->next_record(MYSQLI_NUM, false);
2011-03-28 14:21:28 +00:00
$Changed = false;
2012-11-20 08:00:19 +00:00
for ($i = 0; $i < count($AliasNames); $i++) {
2012-10-11 08:00:15 +00:00
$AliasName = Artists::normalise_artist_name($AliasNames[$i]);
2011-03-28 14:21:28 +00:00
$Importance = $Importances[$i];
2013-02-22 08:00:24 +00:00
2013-07-04 08:00:56 +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;
}
2013-02-22 08:00:24 +00:00
2012-11-20 08:00:19 +00:00
if (strlen($AliasName) > 0) {
2013-07-04 08:00:56 +00:00
$DB->query("
SELECT AliasID, ArtistID, Redirect, Name
FROM artists_alias
WHERE Name = '".db_string($AliasName)."'");
2012-11-20 08:00:19 +00:00
while (list($AliasID, $ArtistID, $Redirect, $FoundAliasName) = $DB->next_record(MYSQLI_NUM, false)) {
if (!strcasecmp($AliasName, $FoundAliasName)) {
if ($Redirect) {
2012-06-16 08:00:18 +00:00
$AliasID = $Redirect;
}
break;
}
}
2012-11-20 08:00:19 +00:00
if (!$AliasID) {
2011-04-29 13:49:03 +00:00
$AliasName = db_string($AliasName);
2013-07-04 08:00:56 +00:00
$DB->query("
INSERT INTO artists_group (Name)
VALUES ('$AliasName')");
2011-03-28 14:21:28 +00:00
$ArtistID = $DB->inserted_id();
2013-07-04 08:00:56 +00:00
$DB->query("
INSERT INTO artists_alias (ArtistID, Name)
VALUES ('$ArtistID', '$AliasName')");
2011-03-28 14:21:28 +00:00
$AliasID = $DB->inserted_id();
}
2013-02-22 08:00:24 +00:00
2013-07-04 08:00:56 +00:00
$DB->query("
SELECT Name
FROM artists_group
WHERE ArtistID = $ArtistID");
2012-07-25 08:00:15 +00:00
list($ArtistName) = $DB->next_record(MYSQLI_NUM, false);
2013-02-22 08:00:24 +00:00
2013-07-04 08:00:56 +00:00
$DB->query("
INSERT IGNORE INTO torrents_artists
(GroupID, ArtistID, AliasID, Importance, UserID)
VALUES
('$GroupID', '$ArtistID', '$AliasID', '$Importance', '$UserID')");
2013-02-22 08:00:24 +00:00
2012-02-23 08:00:18 +00:00
if ($DB->affected_rows()) {
2011-03-28 14:21:28 +00:00
$Changed = true;
2013-07-04 08:00:56 +00:00
Misc::write_log("Artist $ArtistID ($ArtistName) was added to the group $GroupID ($GroupName) as ".$ArtistTypes[$Importance].' by user '.$LoggedUser['ID'].' ('.$LoggedUser['Username'].')');
Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "added artist $ArtistName as ".$ArtistTypes[$Importance], 0);
2011-03-28 14:21:28 +00:00
}
}
}
2012-11-20 08:00:19 +00:00
if ($Changed) {
2013-07-04 08:00:56 +00:00
$Cache->delete_value("torrents_details_$GroupID");
$Cache->delete_value("groups_artists_$GroupID"); // Delete group artist cache
2012-10-11 08:00:15 +00:00
Torrents::update_hash($GroupID);
2011-03-28 14:21:28 +00:00
}
header('Location: '.$_SERVER['HTTP_REFERER']);
?>