Gazelle/sections/torrents/manage_artists.php

57 lines
2.3 KiB
PHP
Raw Normal View History

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