<?php
require_once '../startup.php';

include_once '_category.php';
include_once '_track.php';
include_once '_posts.php';

include FMF_LAYOUT . '/header.php';

$categories = root_category();

foreach($categories as $cat1) {
?>
    <div class="forum-category">
        <div class="forum-category-title">
            <div class="forum-category-title-info">
                <a href="/category/<?=$cat1['cat_id'];?>"><?=$cat1['cat_name'];?></a>
            </div>
            <div class="forum-category-count">Topics</div>
            <div class="forum-category-count">Posts</div>
            <div class="forum-category-latest forum-category-latest-header">Latest post</div>
        </div>
        <div class="forum-category-children">
            <?php
            foreach($cat1['children'] as $cat2) {
                $trackStatus = track_check_category(current_user_id(), $cat2['cat_id']);
            ?>
            <div class="forum-category-board">
                <div class="forum-category-board-indicator<?=($trackStatus ? ' unread' : '');?>" title="<?=($trackStatus ? 'There are unread posts' : 'No unread posts');?>"></div>
                <div class="forum-category-board-info">
                    <a href="/category/<?=$cat2['cat_id'];?>"><?=htmlentities($cat2['cat_name']);?></a>
                    <div class="forum-category-board-desc"><?=htmlentities($cat2['cat_description']);?></div>
                </div>
                <?php if($cat2['cat_type'] != 2) { ?>
                <div class="forum-category-count"><?=number_format($cat2['cat_count_topics']);?></div>
                <div class="forum-category-count"><?=number_format($cat2['cat_count_posts']);?></div>
                <div class="forum-category-latest">
                    <?php if($cat2['cat_last_post_id'] < 1) { ?>
                    No posts
                    <?php } else { $postInfo = post_info($cat2['cat_last_post_id']); ?>
                    <a href="/post/<?=$cat2['cat_last_post_id'];?>">#<?=$cat2['cat_last_post_id'];?></a><br/>
                    <time datetime="<?=date('c', $postInfo['post_created']);?>"><?=date(FMF_DATE_FORMAT, $postInfo['post_created']);?></time>
                    <?php } ?>
                </div>
                <?php } ?>
            </div>
            <?php } ?>
        </div>
    </div>
<?php
}

$extendedFooter = true;
include FMF_LAYOUT . '/footer.php';