Gazelle/sections/user/notify_handle.php

194 lines
4.8 KiB
PHP
Raw Permalink Normal View History

2011-03-28 14:21:28 +00:00
<?
2013-04-13 08:00:19 +00:00
if (!check_perms('site_torrents_notify')) {
error(403);
}
2011-03-28 14:21:28 +00:00
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;
2013-05-23 08:01:12 +00:00
$Users = '';
2011-03-28 14:21:28 +00:00
$HasFilter = false;
2013-04-13 08:00:19 +00:00
if ($_POST['formid'] && is_number($_POST['formid'])) {
2012-06-16 08:00:18 +00:00
$FormID = $_POST['formid'];
}
2013-04-13 08:00:19 +00:00
if ($_POST['artists'.$FormID]) {
2012-06-16 08:00:18 +00:00
$Artists = explode(',', $_POST['artists'.$FormID]);
2011-03-28 14:21:28 +00:00
$ParsedArtists = array();
2013-04-13 08:00:19 +00:00
foreach ($Artists as $Artist) {
2013-05-15 08:00:54 +00:00
if (trim($Artist) != '') {
2011-03-28 14:21:28 +00:00
$ParsedArtists[] = db_string(trim($Artist));
}
}
2013-04-13 08:00:19 +00:00
if (count($ParsedArtists) > 0) {
2013-05-15 08:00:54 +00:00
$ArtistList = '|'.implode('|', $ParsedArtists).'|';
2011-03-28 14:21:28 +00:00
$HasFilter = true;
}
}
2013-04-13 08:00:19 +00:00
if ($_POST['excludeva'.$FormID]) {
2011-03-28 14:21:28 +00:00
$ExcludeVA = '1';
$HasFilter = true;
} else {
$ExcludeVA = '0';
}
2013-04-13 08:00:19 +00:00
if ($_POST['newgroupsonly'.$FormID]) {
2011-03-28 14:21:28 +00:00
$NewGroupsOnly = '1';
$HasFilter = true;
} else {
$NewGroupsOnly = '0';
}
2013-04-13 08:00:19 +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]);
2013-04-13 08:00:19 +00:00
foreach ($Tags as $Tag) {
2011-03-28 14:21:28 +00:00
$TagList.=db_string(trim($Tag)).'|';
}
$HasFilter = true;
}
2013-04-13 08:00:19 +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]);
2013-04-13 08:00:19 +00:00
foreach ($Tags as $Tag) {
2011-03-28 14:21:28 +00:00
$NotTagList.=db_string(trim($Tag)).'|';
}
$HasFilter = true;
}
2013-04-13 08:00:19 +00:00
if ($_POST['categories'.$FormID]) {
2011-03-28 14:21:28 +00:00
$CategoryList = '|';
2013-04-13 08:00:19 +00:00
foreach ($_POST['categories'.$FormID] as $Category) {
2011-03-28 14:21:28 +00:00
$CategoryList.=db_string(trim($Category)).'|';
}
$HasFilter = true;
}
2013-04-13 08:00:19 +00:00
if ($_POST['releasetypes'.$FormID]) {
2011-03-28 14:21:28 +00:00
$ReleaseTypeList = '|';
2013-04-13 08:00:19 +00:00
foreach ($_POST['releasetypes'.$FormID] as $ReleaseType) {
2011-03-28 14:21:28 +00:00
$ReleaseTypeList.=db_string(trim($ReleaseType)).'|';
}
$HasFilter = true;
}
2013-04-13 08:00:19 +00:00
if ($_POST['formats'.$FormID]) {
2011-03-28 14:21:28 +00:00
$FormatList = '|';
2013-04-13 08:00:19 +00:00
foreach ($_POST['formats'.$FormID] as $Format) {
2011-03-28 14:21:28 +00:00
$FormatList.=db_string(trim($Format)).'|';
}
$HasFilter = true;
}
2013-04-13 08:00:19 +00:00
if ($_POST['bitrates'.$FormID]) {
2011-03-28 14:21:28 +00:00
$EncodingList = '|';
2013-04-13 08:00:19 +00:00
foreach ($_POST['bitrates'.$FormID] as $Bitrate) {
2011-03-28 14:21:28 +00:00
$EncodingList.=db_string(trim($Bitrate)).'|';
}
$HasFilter = true;
}
2013-04-13 08:00:19 +00:00
if ($_POST['media'.$FormID]) {
2011-03-28 14:21:28 +00:00
$MediaList = '|';
2013-04-13 08:00:19 +00:00
foreach ($_POST['media'.$FormID] as $Medium) {
2011-03-28 14:21:28 +00:00
$MediaList.=db_string(trim($Medium)).'|';
}
$HasFilter = true;
}
2013-04-13 08:00:19 +00:00
if ($_POST['fromyear'.$FormID] && is_number($_POST['fromyear'.$FormID])) {
2012-06-16 08:00:18 +00:00
$FromYear = trim($_POST['fromyear'.$FormID]);
2011-03-28 14:21:28 +00:00
$HasFilter = true;
2013-04-13 08:00:19 +00:00
if ($_POST['toyear'.$FormID] && is_number($_POST['toyear'.$FormID])) {
2012-06-16 08:00:18 +00:00
$ToYear = trim($_POST['toyear'.$FormID]);
2011-03-28 14:21:28 +00:00
} else {
2013-05-15 08:00:54 +00:00
$ToYear = date('Y') + 3;
}
}
2013-05-23 08:01:12 +00:00
if ($_POST['users'.$FormID]) {
$Usernames = explode(',', $_POST['users'.$FormID]);
$EscapedUsernames = array();
2013-05-24 08:00:59 +00:00
foreach ($Usernames as $Username) {
2013-05-23 08:01:12 +00:00
$EscapedUsernames[] = db_string(trim($Username));;
2013-05-15 08:00:54 +00:00
}
2013-05-23 08:01:12 +00:00
$DB->query("
2013-11-17 08:00:47 +00:00
SELECT ID, Paranoia
FROM users_main
WHERE Username IN ('" . implode("', '", $EscapedUsernames) . "')
AND ID != $LoggedUser[ID]");
2013-05-23 08:01:12 +00:00
while (list($UserID, $Paranoia) = $DB->next_record()) {
$Paranoia = unserialize($Paranoia);
if (!in_array('notifications', $Paranoia)) {
$Users .= '|' . $UserID . '|';
$HasFilter = true;
}
2011-03-28 14:21:28 +00:00
}
}
2013-04-13 08:00:19 +00:00
if (!$HasFilter) {
2011-03-28 14:21:28 +00:00
$Err = 'You must add at least one criterion to filter by';
2013-04-13 08:00:19 +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';
}
2013-04-13 08:00:19 +00:00
if ($Err) {
2011-03-28 14:21:28 +00:00
error($Err);
header('Location: user.php?action=notify');
die();
}
2013-05-23 08:01:12 +00:00
$ArtistList = str_replace('||', '|', $ArtistList);
$TagList = str_replace('||', '|', $TagList);
$NotTagList = str_replace('||', '|', $NotTagList);
$Users = str_replace('||', '|', $Users);
2011-03-28 14:21:28 +00:00
2013-04-13 08:00:19 +00:00
if ($_POST['id'.$FormID] && is_number($_POST['id'.$FormID])) {
2013-05-15 08:00:54 +00:00
$DB->query("
UPDATE users_notify_filters
SET
Artists='$ArtistList',
ExcludeVA='$ExcludeVA',
2013-06-25 08:00:52 +00:00
NewGroupsOnly='$NewGroupsOnly',
2013-05-15 08:00:54 +00:00
Tags='$TagList',
NotTags='$NotTagList',
ReleaseTypes='$ReleaseTypeList',
Categories='$CategoryList',
Formats='$FormatList',
Encodings='$EncodingList',
Media='$MediaList',
FromYear='$FromYear',
ToYear='$ToYear',
2013-05-23 08:01:12 +00:00
Users ='$Users'
2013-05-15 08:00:54 +00:00
WHERE ID='".$_POST['id'.$FormID]."'
AND UserID='$LoggedUser[ID]'");
2011-03-28 14:21:28 +00:00
} else {
2013-05-15 08:00:54 +00:00
$DB->query("
INSERT INTO users_notify_filters
2013-05-23 08:01:12 +00:00
(UserID, Label, Artists, ExcludeVA, NewGroupsOnly, Tags, NotTags, ReleaseTypes, Categories, Formats, Encodings, Media, FromYear, ToYear, Users)
2011-03-28 14:21:28 +00:00
VALUES
2013-05-23 08:01:12 +00:00
('$LoggedUser[ID]','".db_string($_POST['label'.$FormID])."','$ArtistList','$ExcludeVA','$NewGroupsOnly','$TagList', '$NotTagList', '$ReleaseTypeList','$CategoryList','$FormatList','$EncodingList','$MediaList', '$FromYear', '$ToYear', '$Users')");
2011-03-28 14:21:28 +00:00
}
$Cache->delete_value('notify_filters_'.$LoggedUser['ID']);
2013-04-13 08:00:19 +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');
?>