2011-03-28 14:21:28 +00:00
< ?
$ArtistID = db_string ( $_GET [ 'artistid' ]);
$GroupID = db_string ( $_GET [ 'groupid' ]);
2012-02-23 08:00:18 +00:00
$Importance = db_string ( $_GET [ 'importance' ]);
2011-03-28 14:21:28 +00:00
2013-05-01 08:00:16 +00:00
if ( ! is_number ( $ArtistID ) || ! is_number ( $GroupID ) || ! is_number ( $Importance )) {
2011-03-28 14:21:28 +00:00
error ( 404 );
}
2013-05-01 08:00:16 +00:00
if ( ! check_perms ( 'torrents_edit' )) {
2011-03-28 14:21:28 +00:00
error ( 403 );
}
2013-07-04 08:00:56 +00:00
$DB -> query ( "
DELETE FROM torrents_artists
WHERE GroupID = '$GroupID'
AND ArtistID = '$ArtistID'
AND Importance = '$Importance' " );
$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 );
2011-03-28 14:21:28 +00:00
2013-07-04 08:00:56 +00:00
$DB -> query ( "
SELECT Name
FROM torrents_group
WHERE ID = $GroupID " );
2013-11-11 08:00:59 +00:00
if ( ! $DB -> has_results ()) {
error ( 404 );
}
2012-07-25 08:00:15 +00:00
list ( $GroupName ) = $DB -> next_record ( MYSQLI_NUM , false );
2011-03-28 14:21:28 +00:00
2013-07-04 08:00:56 +00:00
// Get a count of how many groups or requests use this artist ID
$DB -> query ( "
SELECT ag . ArtistID
2013-11-17 08:00:47 +00:00
FROM artists_group AS ag
2013-07-04 08:00:56 +00:00
LEFT JOIN requests_artists AS ra ON ag . ArtistID = ra . ArtistID
WHERE ra . ArtistID IS NOT NULL
AND ag . ArtistID = $ArtistID " );
2011-03-28 14:21:28 +00:00
$ReqCount = $DB -> record_count ();
2013-07-04 08:00:56 +00:00
$DB -> query ( "
SELECT ag . ArtistID
2013-11-17 08:00:47 +00:00
FROM artists_group AS ag
2013-07-04 08:00:56 +00:00
LEFT JOIN torrents_artists AS ta ON ag . ArtistID = ta . ArtistID
WHERE ta . ArtistID IS NOT NULL
AND ag . ArtistID = $ArtistID " );
2011-03-28 14:21:28 +00:00
$GroupCount = $DB -> record_count ();
2013-05-01 08:00:16 +00:00
if (( $ReqCount + $GroupCount ) == 0 ) {
2013-07-04 08:00:56 +00:00
// The only group to use this artist
2012-10-11 08:00:15 +00:00
Artists :: delete_artist ( $ArtistID );
2011-03-28 14:21:28 +00:00
}
2013-07-04 08:00:56 +00:00
$Cache -> delete_value ( " torrents_details_ $GroupID " ); // Delete torrent group cache
$Cache -> delete_value ( " groups_artists_ $GroupID " ); // Delete group artist cache
Misc :: write_log ( 'Artist (' . $ArtistTypes [ $Importance ] . " ) $ArtistID ( $ArtistName ) was removed from the group $GroupID ( $GroupName ) by user " . $LoggedUser [ 'ID' ] . ' (' . $LoggedUser [ 'Username' ] . ')' );
Torrents :: write_group_log ( $GroupID , 0 , $LoggedUser [ 'ID' ], " removed artist $ArtistName ( " . $ArtistTypes [ $Importance ] . ')' , 0 );
2011-03-28 14:21:28 +00:00
2012-10-11 08:00:15 +00:00
Torrents :: update_hash ( $GroupID );
2013-07-04 08:00:56 +00:00
$Cache -> delete_value ( " artist_groups_ $ArtistID " );
2011-03-28 14:21:28 +00:00
header ( 'Location: ' . $_SERVER [ 'HTTP_REFERER' ]);
?>