<?php
    $_id = isset($_GET['i']) ? trim($_GET['i']) : '';

    $community_forums = mysqli_query_logged("SELECT * FROM community_forums, community_sections, community WHERE community_forums.forum_id = " . sq($_id) . " AND community_forums.forum_deleted = '0' AND community_forums.section_id = community_sections.section_id AND community_sections.community_id = community.community_id");
    if (!$community_forums_row = mysqli_fetch_assoc($community_forums))    
    {
        header('Location: ./?s=communities');
        die;        
    }

    $community_threads = mysqli_query_logged("SELECT * FROM community_threads WHERE forum_id = '" . $community_forums_row['forum_id'] . "' ORDER BY thread_sticky DESC, thread_last_posted_on DESC LIMIT 0, " . COMMUNITY_THREADS_PER_PAGE * 2);
    while ($community_threads_row = mysqli_fetch_assoc($community_threads))
    {
        //if ($community_threads_row['thread_sticky'] == 0)
        //{
            mysqli_query_logged("REPLACE INTO community_threads_pointers SET thread_id = '" . $community_threads_row['thread_id'] . "', user_id = '" . $GLOBALS['auth']['id'] . "', message_id = '" . $community_threads_row['thread_last_message_id'] . "'");
        //}
    }
        
    header('Location: ./?s=community&i=' . $community_forums_row['community_id']);
    die;
?>