<?php
    $_id = isset($_GET['i']) ? intval($_GET['i']) : 0;
    
    $community = 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_row = mysqli_fetch_assoc($community))    
    {
        header('Location: ./?s=communities');
        die;        
    }
    
    require_once('include/functions/community_permissions.php');
    community_permissions($community_row['community_id'], $community_row['section_id'], $community_row['forum_id']);
    
    if (!$GLOBALS['auth']['community']['forum_automate'])
    {
        make_cookie('notice', 'You do not have access to un/automate this forum.');
        header('Location: ./?s=community_thread&i=' . $community_row['thread_id']);
        die;
    }

    $automate = false;
    if (isset($_GET['automate']))
    {
        $automate = 1;
    }
    elseif (isset($_GET['unautomate']))
    {
        $automate = 0;
    }
    if ($automate !== false)
    {
        mysqli_query_logged("UPDATE community_forums SET forum_automated = '" . $automate . "' WHERE forum_id = '" . $community_row['forum_id'] . "'");
    }

    header('Location: ./?s=community_forum&i=' . $community_row['forum_id']);
    die;
?>