<?php
    $GLOBALS['highlight'] = 'forum';

    $_back = isset($_GET['b']) ? str_replace('@', '&', trim(strval($_GET['b']))) : '';
    $_back_old = isset($_GET['b']) ? trim(strval($_GET['b'])) : '';
    $_id = isset($_GET['i']) ? intval($_GET['i']) : 0;
    
    $community = mysqli_query_logged("SELECT * FROM community_threads, community_forums, community_sections, community WHERE community_threads.thread_id = " . sq($_id) . " AND community_threads.forum_id = community_forums.forum_id AND community_forums.section_id = community_sections.section_id AND community_sections.community_id = community.community_id");
    if (!$community_row = mysqli_fetch_assoc($community))    
    {
        make_cookie('This thread does not exists.');
        header('Location: ./?s=communities');
        die;        
    }

    require_once('include/functions/community_banned.php');
    community_banned($community_row['community_id']);
    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']['thread_move'])
    {
        make_cookie('notice', 'You do not have permission to move this thread.');
        header('Location: ./?s=community_thread&i=' . $community_row['thread_id']);
        die;
    }

    include('include/parts/header.php');

    echo box_outside_top('<a href="?s=community">Communities</a> - <a href="?s=community&i=' . $community_row['community_id'] . '">' . htmlspecialchars($community_row['community_name']) . '</a> - <a href="?s=community_forum&i=' . $community_row['forum_id'] . '">' . htmlspecialchars($community_row['forum_name_' . language()]) . '</a> - Move Thread');
    echo box_inside_top();
    echo 'To where do you want to move this message?';
    echo box_inside_bottom();
    echo box_outside_bottom();

    $i = 0;
    $community_sections = mysqli_query_logged("SELECT * FROM community_sections WHERE community_id = '" . $community_row['community_id'] . "' AND section_deleted = '0' ORDER BY section_order_id");
    while ($community_sections_row = mysqli_fetch_array($community_sections))
    {
        echo box_outside_top($community_sections_row['section_name_' . language()]);
        $j = 0;
        $community_forums = mysqli_query_logged("SELECT * FROM community_forums WHERE section_id = '" . $community_sections_row['section_id'] . "' AND forum_deleted = '0' ORDER BY forum_order_id");
        while ($community_forums_row = mysqli_fetch_array($community_forums))
        {
            if ($j++)
            {
                echo '<div style="padding: 5px 0px 0px 0px;"></div>';
            }
            echo box_inside_top();
            echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr>';
            echo '<td>';
            echo '<div style="font-size: 14px;"><span style="font-weight: bold;"><a href="?a=community_thread_move&i=' . $community_row['thread_id'] . '&x=' . $community_forums_row['forum_id'] . '&b=' . $_back_old . '">' . htmlspecialchars($community_forums_row['forum_name_' . language()]) . '</a></span>' . ($community_forums_row['forum_locked'] ? ' LOCKED' : '') . '</div>';
            echo '<div style="font-size: 11px;">' . htmlspecialchars($community_forums_row['forum_description_' . language()]) . '</div>';
            echo '</td>';
            echo '</tr></table>';
            echo box_inside_bottom();
        }
        echo box_outside_bottom();
    }

    include('include/parts/footer.php');
?>