Gazelle/sections/forums/subscribe.php

36 lines
1.2 KiB
PHP
Raw Normal View History

2012-09-12 08:00:27 +00:00
<?php
2013-01-12 08:00:39 +00:00
$ForumID = (int) ($_GET['forumid']);
if(empty($ForumID)) {
error(403);
}
$SubscribedForumIDs = $Cache->get("subscribed_forum_ids_".$LoggedUser['ID']);
if(empty($SubscribedForumIDs)) {
$SubscribedForumIDs = array();
$DB->query("SELECT ForumID FROM subscribed_forums WHERE UserID = $LoggedUser[ID]");
if($DB->record_count() > 0) {
$SubscribedForumIDs = $DB->collect('ForumID');
}
$Cache->cache_value("subscribed_forum_ids_".$LoggedUser['ID'], $SubscribedForumIDs, 0);
}
2012-09-12 08:00:27 +00:00
2013-01-12 08:00:39 +00:00
if($_GET['do'] == 'add') {
if(!in_array($ForumID, $SubscribedForumIDs)) {
$SubscribedForumIDs[] = $ForumID;
}
2012-09-12 08:00:27 +00:00
2013-01-12 08:00:39 +00:00
$DB->query("INSERT INTO subscribed_forums
(ForumID, UserID)
VALUES($ForumID, $LoggedUser[ID])");
$Cache->replace_value("subscribed_forum_ids_".$LoggedUser['ID'], $SubscribedForumIDs, 0);
2012-09-12 08:00:27 +00:00
}
2013-01-12 08:00:39 +00:00
elseif($_GET['do'] == 'remove') {
$SubscribedForumIDs = array_diff($SubscribedForumIDs, array($ForumID));
if(count($SubscribedForumIDs) > 0) {
$DB->query("DELETE FROM subscribed_forums WHERE UserID = $LoggedUser[ID] AND ForumID = $ForumID");
$Cache->delete_value("subscribed_forum_ids_".$LoggedUser['ID']);
}
2012-09-12 08:00:27 +00:00
}
2013-01-12 08:00:39 +00:00
2012-09-12 08:00:27 +00:00
header('Location: forums.php?action=viewforum&forumid=' . $ForumID);