2011-03-28 14:21:28 +00:00
< ?
2013-05-01 08:00:16 +00:00
if ( empty ( $_POST [ 'importance' ]) || empty ( $_POST [ 'artists' ]) || empty ( $_POST [ 'groupid' ]) || ! is_number ( $_POST [ 'importance' ]) || ! is_number ( $_POST [ 'groupid' ])) {
2011-03-28 14:21:28 +00:00
error ( 0 );
}
2013-05-01 08:00:16 +00:00
if ( ! check_perms ( 'torrents_edit' )) {
2011-03-28 14:21:28 +00:00
error ( 403 );
}
authorize ();
2012-02-23 08:00:18 +00:00
$GroupID = $_POST [ 'groupid' ];
2013-06-19 08:01:09 +00:00
$Artists = explode ( ',' , $_POST [ 'artists' ]);
2012-02-23 08:00:18 +00:00
$CleanArtists = array ();
$ArtistIDs = array ();
$ArtistsString = '0' ;
2013-05-01 08:00:16 +00:00
foreach ( $Artists as $i => $Artist ) {
2013-06-19 08:01:09 +00:00
list ( $Importance , $ArtistID ) = explode ( ';' , $Artist );
2013-05-01 08:00:16 +00:00
if ( is_number ( $ArtistID ) && is_number ( $Importance )) {
2012-02-23 08:00:18 +00:00
$CleanArtists [] = array ( $Importance , $ArtistID );
$ArtistIDs [] = $ArtistID ;
2011-03-28 14:21:28 +00:00
}
}
2013-05-01 08:00:16 +00:00
if ( count ( $CleanArtists ) > 0 ) {
2013-06-19 08:01:09 +00:00
$ArtistsString = implode ( ',' , $ArtistIDs );
2013-05-01 08:00:16 +00:00
if ( $_POST [ 'manager_action' ] == 'delete' ) {
2013-06-19 08:01:09 +00:00
$DB -> query ( "
SELECT Name
FROM torrents_group
WHERE ID = '".$_POST[' groupid ']."' " );
2011-03-28 14:21:28 +00:00
list ( $GroupName ) = $DB -> next_record ();
2013-06-19 08:01:09 +00:00
$DB -> query ( "
SELECT ArtistID , Name
FROM artists_group
WHERE ArtistID IN ( $ArtistsString ) " );
2012-07-25 08:00:15 +00:00
$ArtistNames = $DB -> to_array ( 'ArtistID' , MYSQLI_ASSOC , false );
2012-11-20 08:00:19 +00:00
foreach ( $CleanArtists as $Artist ) {
2013-06-19 08:01:09 +00:00
list ( $Importance , $ArtistID ) = $Artist ;
Misc :: write_log ( 'Artist (' . $ArtistTypes [ $Importance ] . " ) $ArtistID ( " . $ArtistNames [ $ArtistID ][ 'Name' ] . " ) was removed from the group " . $_POST [ 'groupid' ] . " ( $GroupName ) by user " . $LoggedUser [ 'ID' ] . ' (' . $LoggedUser [ 'Username' ] . ')' );
2012-10-11 08:00:15 +00:00
Torrents :: write_group_log ( $GroupID , 0 , $LoggedUser [ 'ID' ], " Removed artist " . $ArtistNames [ $ArtistID ][ 'Name' ] . " ( " . $ArtistTypes [ $Importance ] . " ) " , 0 );
2013-06-19 08:01:09 +00:00
$DB -> query ( "
DELETE FROM torrents_artists
WHERE GroupID = '$GroupID'
AND ArtistID = '$ArtistID'
AND Importance = '$Importance' " );
$Cache -> delete_value ( " artist_groups_ $ArtistID " );
2011-03-28 14:21:28 +00:00
}
2013-05-01 08:00:16 +00:00
$DB -> query ( "
SELECT ArtistID
FROM requests_artists
2013-06-19 08:01:09 +00:00
WHERE ArtistID IN ( $ArtistsString )
2013-05-01 08:00:16 +00:00
UNION
SELECT ArtistID
FROM torrents_artists
2013-06-19 08:01:09 +00:00
WHERE ArtistID IN ( $ArtistsString ) " );
2011-03-28 14:21:28 +00:00
$Items = $DB -> collect ( 'ArtistID' );
2012-02-23 08:00:18 +00:00
$EmptyArtists = array_diff ( $ArtistIDs , $Items );
2013-05-01 08:00:16 +00:00
foreach ( $EmptyArtists as $ArtistID ) {
2012-10-11 08:00:15 +00:00
Artists :: delete_artist ( $ArtistID );
2011-03-28 14:21:28 +00:00
}
} else {
2013-06-19 08:01:09 +00:00
$DB -> query ( "
UPDATE IGNORE torrents_artists
SET Importance = '".$_POST[' importance ']."'
WHERE GroupID = '$GroupID'
AND ArtistID IN ( $ArtistsString ) " );
2011-03-28 14:21:28 +00:00
}
2013-06-19 08:01:09 +00:00
$Cache -> delete_value ( " groups_artists_ $GroupID " );
2012-11-20 08:00:19 +00:00
Torrents :: update_hash ( $GroupID );
2013-06-19 08:01:09 +00:00
header ( " Location: torrents.php?id= $GroupID " );
2011-03-28 14:21:28 +00:00
}
?>