Gazelle/sections/user/notify_handle.php

163 lines
4.0 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
if(!check_perms('site_torrents_notify')){ error(403); }
authorize();
2012-06-16 08:00:18 +00:00
$FormID = '';
2011-03-28 14:21:28 +00:00
$ArtistList = '';
$TagList = '';
$NotTagList = '';
$ReleaseTypeList = '';
$CategoryList = '';
$FormatList = '';
$EncodingList = '';
$MediaList = '';
$FromYear = 0;
$ToYear = 0;
$HasFilter = false;
2012-06-16 08:00:18 +00:00
if($_POST['formid'] && is_number($_POST['formid'])) {
$FormID = $_POST['formid'];
}
if($_POST['artists'.$FormID]){
$Artists = explode(',', $_POST['artists'.$FormID]);
2011-03-28 14:21:28 +00:00
$ParsedArtists = array();
foreach($Artists as $Artist){
if(trim($Artist) != "") {
$ParsedArtists[] = db_string(trim($Artist));
}
}
if(count($ParsedArtists) > 0) {
$ArtistList = '|'.implode("|", $ParsedArtists).'|';
$HasFilter = true;
}
}
2012-06-16 08:00:18 +00:00
if($_POST['excludeva'.$FormID]){
2011-03-28 14:21:28 +00:00
$ExcludeVA = '1';
$HasFilter = true;
} else {
$ExcludeVA = '0';
}
2012-06-16 08:00:18 +00:00
if($_POST['newgroupsonly'.$FormID]){
2011-03-28 14:21:28 +00:00
$NewGroupsOnly = '1';
$HasFilter = true;
} else {
$NewGroupsOnly = '0';
}
2012-06-16 08:00:18 +00:00
if($_POST['tags'.$FormID]){
2011-03-28 14:21:28 +00:00
$TagList = '|';
2012-06-16 08:00:18 +00:00
$Tags = explode(',', $_POST['tags'.$FormID]);
2011-03-28 14:21:28 +00:00
foreach($Tags as $Tag){
$TagList.=db_string(trim($Tag)).'|';
}
$HasFilter = true;
}
2012-06-16 08:00:18 +00:00
if($_POST['nottags'.$FormID]){
2011-03-28 14:21:28 +00:00
$NotTagList = '|';
2012-06-16 08:00:18 +00:00
$Tags = explode(',', $_POST['nottags'.$FormID]);
2011-03-28 14:21:28 +00:00
foreach($Tags as $Tag){
$NotTagList.=db_string(trim($Tag)).'|';
}
$HasFilter = true;
}
2012-06-16 08:00:18 +00:00
if($_POST['categories'.$FormID]){
2011-03-28 14:21:28 +00:00
$CategoryList = '|';
2012-06-16 08:00:18 +00:00
foreach($_POST['categories'.$FormID] as $Category){
2011-03-28 14:21:28 +00:00
$CategoryList.=db_string(trim($Category)).'|';
}
$HasFilter = true;
}
2012-06-16 08:00:18 +00:00
if($_POST['releasetypes'.$FormID]){
2011-03-28 14:21:28 +00:00
$ReleaseTypeList = '|';
2012-06-16 08:00:18 +00:00
foreach($_POST['releasetypes'.$FormID] as $ReleaseType){
2011-03-28 14:21:28 +00:00
$ReleaseTypeList.=db_string(trim($ReleaseType)).'|';
}
$HasFilter = true;
}
2012-06-16 08:00:18 +00:00
if($_POST['formats'.$FormID]){
2011-03-28 14:21:28 +00:00
$FormatList = '|';
2012-06-16 08:00:18 +00:00
foreach($_POST['formats'.$FormID] as $Format){
2011-03-28 14:21:28 +00:00
$FormatList.=db_string(trim($Format)).'|';
}
$HasFilter = true;
}
2012-06-16 08:00:18 +00:00
if($_POST['bitrates'.$FormID]){
2011-03-28 14:21:28 +00:00
$EncodingList = '|';
2012-06-16 08:00:18 +00:00
foreach($_POST['bitrates'.$FormID] as $Bitrate){
2011-03-28 14:21:28 +00:00
$EncodingList.=db_string(trim($Bitrate)).'|';
}
$HasFilter = true;
}
2012-06-16 08:00:18 +00:00
if($_POST['media'.$FormID]){
2011-03-28 14:21:28 +00:00
$MediaList = '|';
2012-06-16 08:00:18 +00:00
foreach($_POST['media'.$FormID] as $Medium){
2011-03-28 14:21:28 +00:00
$MediaList.=db_string(trim($Medium)).'|';
}
$HasFilter = true;
}
2012-06-16 08:00:18 +00:00
if($_POST['fromyear'.$FormID] && is_number($_POST['fromyear'.$FormID])){
$FromYear = trim($_POST['fromyear'.$FormID]);
2011-03-28 14:21:28 +00:00
$HasFilter = true;
2012-06-16 08:00:18 +00:00
if($_POST['toyear'.$FormID] && is_number($_POST['toyear'.$FormID])) {
$ToYear = trim($_POST['toyear'.$FormID]);
2011-03-28 14:21:28 +00:00
} else {
$ToYear = date('Y')+3;
}
}
if(!$HasFilter){
$Err = 'You must add at least one criterion to filter by';
2012-06-16 08:00:18 +00:00
} elseif(!$_POST['label'.$FormID] && !$_POST['id'.$FormID]) {
2011-03-28 14:21:28 +00:00
$Err = 'You must add a label for the filter set';
}
if($Err){
error($Err);
header('Location: user.php?action=notify');
die();
}
$ArtistList = str_replace('||','|',$ArtistList);
$TagList = str_replace('||','|',$TagList);
$NotTagList = str_replace('||','|',$NotTagList);
2012-06-16 08:00:18 +00:00
if($_POST['id'.$FormID] && is_number($_POST['id'.$FormID])){
2011-03-28 14:21:28 +00:00
$DB->query("UPDATE users_notify_filters SET
Artists='$ArtistList',
ExcludeVA='$ExcludeVA',
NewGroupsOnly='$NewGroupsOnly',
Tags='$TagList',
NotTags='$NotTagList',
ReleaseTypes='$ReleaseTypeList',
Categories='$CategoryList',
Formats='$FormatList',
Encodings='$EncodingList',
Media='$MediaList',
FromYear='$FromYear',
ToYear='$ToYear'
2012-06-16 08:00:18 +00:00
WHERE ID='".$_POST['id'.$FormID]."' AND UserID='$LoggedUser[ID]'");
2011-03-28 14:21:28 +00:00
} else {
2013-02-22 08:00:24 +00:00
$DB->query("INSERT INTO users_notify_filters
2011-03-28 14:21:28 +00:00
(UserID, Label, Artists, ExcludeVA, NewGroupsOnly, Tags, NotTags, ReleaseTypes, Categories, Formats, Encodings, Media, FromYear, ToYear)
VALUES
2012-06-16 08:00:18 +00:00
('$LoggedUser[ID]','".db_string($_POST['label'.$FormID])."','$ArtistList','$ExcludeVA','$NewGroupsOnly','$TagList', '$NotTagList', '$ReleaseTypeList','$CategoryList','$FormatList','$EncodingList','$MediaList', '$FromYear', '$ToYear')");
2011-03-28 14:21:28 +00:00
}
$Cache->delete_value('notify_filters_'.$LoggedUser['ID']);
2012-06-16 08:00:18 +00:00
if(($Notify = $Cache->get_value('notify_artists_'.$LoggedUser['ID'])) !== FALSE && $Notify['ID'] == $_POST['id'.$FormID]) {
2011-03-28 14:21:28 +00:00
$Cache->delete_value('notify_artists_'.$LoggedUser['ID']);
}
header('Location: user.php?action=notify');
?>