Gazelle/sections/forums/sticky_post.php

46 lines
1.2 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
enforce_login();
authorize();
2013-05-05 08:00:31 +00:00
if (!check_perms('site_moderate_forums')) {
2011-03-28 14:21:28 +00:00
error(403);
}
$ThreadID = $_GET['threadid'];
$PostID = $_GET['postid'];
$Delete = !empty($_GET['remove']);
2013-05-05 08:00:31 +00:00
if (!$ThreadID || !$PostID || !is_number($ThreadID) || !is_number($PostID)) {
2011-03-28 14:21:28 +00:00
error(404);
}
2013-05-05 08:00:31 +00:00
$DB->query("
SELECT
CEIL(COUNT(ID)/".POSTS_PER_PAGE.") AS Pages,
CEIL(SUM(IF(ID<=$PostID,1,0))/".POSTS_PER_PAGE.") AS Page
2012-06-08 08:00:23 +00:00
FROM forums_posts
WHERE TopicID=$ThreadID
GROUP BY TopicID");
2013-05-05 08:00:31 +00:00
if ($DB->record_count()) {
2012-06-08 08:00:23 +00:00
list($Pages,$Page) = $DB->next_record();
2013-05-05 08:00:31 +00:00
if ($Delete) {
$DB->query("
UPDATE forums_topics
SET StickyPostID = 0
WHERE ID = $ThreadID");
2012-06-08 08:00:23 +00:00
} else {
2013-05-05 08:00:31 +00:00
$DB->query("
UPDATE forums_topics
SET StickyPostID = $PostID
WHERE ID = $ThreadID");
2012-06-08 08:00:23 +00:00
}
$Cache->delete_value('thread_'.$ThreadID.'_info');
2013-05-05 08:00:31 +00:00
$ThisCatalogue = floor((POSTS_PER_PAGE * $Page - POSTS_PER_PAGE) / THREAD_CATALOGUE);
$LastCatalogue = floor((POSTS_PER_PAGE * $Pages - POSTS_PER_PAGE) / THREAD_CATALOGUE);
for ($i = $ThisCatalogue; $i <= $LastCatalogue; $i++) {
2013-06-27 08:01:06 +00:00
$Cache->delete_value('thread_'.$ThreadID.'_catalogue_'.$i);
2012-06-08 08:00:23 +00:00
}
2011-03-28 14:21:28 +00:00
}
header('Location: forums.php?action=viewthread&threadid='.$ThreadID);