function subcats($forum_id)
{
    global $settings, $locale, $userdata, $lastvisited, $cache_subcats;
    $access = '';
    // Pimped: access
    $aresult = dbquery("SELECT forum_access FROM " . DB_FORUMS . " WHERE forum_parent='" . (int) $_GET['forum_id'] . "' ORDER BY forum_order ASC");
    while ($adata = dbarray($aresult)) {
        if ($access != '') {
            $access .= "|";
        }
        $access .= $adata['forum_access'];
    }
    $a_result = dbquery("SELECT f.forum_id, f.forum_name, f.forum_description, f.forum_moderators, f.forum_lastpost, f.forum_image, f.forum_postcount, f.forum_threadcount, f.forum_lastuser, u.user_name, u.user_status FROM " . DB_FORUMS . " f LEFT JOIN " . DB_USERS . " u on f.forum_lastuser=u.user_id WHERE " . groupaccess('f.forum_access', $access) . " AND forum_parent='" . (int) $_GET['forum_id'] . "' ORDER BY forum_order");
    if (dbrows($a_result) != 0) {
        echo "<table cellpadding='0' cellspacing='1' width='100%' class='tbl-border forum_idx_table'>\n<tr>\n";
        echo "<td width='1%' class='tbl2' style='white-space:nowrap'>&nbsp;</td>\n";
        echo "<td class='tbl2' " . ($settings['forum_cat_icons'] == "1" ? "colspan='2' " : "") . ">" . $locale['413'] . "</td>\n";
        echo "<td align='center' width='1%' class='tbl2' style='white-space:nowrap'>" . $locale['402'] . "</td>\n";
        echo "<td align='center' width='1%' class='tbl2' style='white-space:nowrap'>" . $locale['403'] . "</td>\n";
        echo "<td width='1%' class='tbl2' style='white-space:nowrap'>" . $locale['404'] . "</td>\n";
        echo "</tr>\n";
        while ($a_data = dbarray($a_result)) {
            $cache_subcats[] = $a_data['forum_id'];
            // Pimped
            echo "<tr>\n";
            $moderators = '';
            if ($a_data['forum_moderators']) {
                $mod_groups = explode(".", $a_data['forum_moderators']);
                foreach ($mod_groups as $mod_group) {
                    if ($moderators) {
                        $moderators .= ", ";
                    }
                    $moderators .= $mod_group < nMEMBER ? group_link($mod_group, getgroupname($mod_group)) : getgroupname($mod_group);
                    // Pimped: group_link()
                }
            }
            if ($a_data['forum_lastpost'] > $lastvisited) {
                $forum_match = "\\|" . $a_data['forum_lastpost'] . "\\|" . $a_data['forum_id'];
                if (iMEMBER && preg_match("({$forum_match}\\.|{$forum_match}\$)", $userdata['user_threads'])) {
                    $fim = "<img src='" . get_image("folder") . "' alt='" . $locale['561'] . "' />";
                } else {
                    $fim = "<img src='" . get_image("foldernew") . "' alt='" . $locale['560'] . "' />";
                }
            } else {
                $fim = "<img src='" . get_image("folder") . "' alt='" . $locale['561'] . "' />";
            }
            echo "<td align='center' width='1%' class='tbl2' style='white-space:nowrap'>{$fim}</td>\n";
            if ($settings['forum_cat_icons'] == "1") {
                echo "<td align='center' width='1%' class='tbl1' style='white-space:nowrap'>";
                if ($a_data['forum_image'] != '' && file_exists(IMAGES_FC . $a_data['forum_image'])) {
                    echo "<img src='" . IMAGES_FC . $a_data['forum_image'] . "' border='0' alt='' title='" . $a_data['forum_name'] . "' />";
                } else {
                    echo "<img src='" . IMAGES_FC . "default.png' border='0' alt='' title='" . $a_data['forum_name'] . "' />";
                }
                echo "</td>";
            }
            echo "<td class='tbl1 forum_name'><!--forum_name--><a href='" . make_url(FORUM . "viewforum.php?forum_id=" . $a_data['forum_id'], BASEDIR . "forum-" . $a_data['forum_id'] . "-", $a_data['forum_name'], ".html") . "'>" . $a_data['forum_name'] . "</a><br />\n";
            // Pimped: make_url
            if ($a_data['forum_description'] || $moderators) {
                echo "<span class='small'>" . $a_data['forum_description'] . ($a_data['forum_description'] && $moderators ? "<br />\n" : "");
                echo ($moderators ? "<strong>" . $locale['411'] . "</strong>" . $moderators . "</span>\n" : "</span>\n") . "<br />\n";
            }
            whoishere_show("index", $a_data['forum_id']);
            // Pimped: Who is here
            echo "</td>\n";
            echo "<td align='center' width='1%' class='tbl2' style='white-space:nowrap'>" . $a_data['forum_threadcount'] . "</td>\n";
            echo "<td align='center' width='1%' class='tbl1' style='white-space:nowrap'>" . $a_data['forum_postcount'] . "</td>\n";
            echo "<td width='1%' class='tbl2' style='white-space:nowrap'>";
            if ($a_data['forum_lastpost'] == 0) {
                echo $locale['405'] . "</td>\n</tr>\n";
            } else {
                // Pimped ->
                $thread_data = dbarray(dbquery("SELECT t.thread_id, t.thread_subject, t.thread_lastpostid FROM " . DB_THREADS . " t\r\n\t\t\t\tleft join " . DB_POSTS . " p on p.post_id=t.thread_lastpostid\r\n\t\t\t\tWHERE t.thread_lastpost='" . $a_data['forum_lastpost'] . "'"));
                echo "<a href='" . make_url(FORUM . "viewthread.php?thread_id=" . $thread_data['thread_id'], BASEDIR . "forum-thread-" . $thread_data['thread_id'] . "-", $thread_data['thread_subject'], ".html") . "#post_" . $thread_data['thread_lastpostid'] . "' title='" . $thread_data['thread_subject'] . "'>" . trimlink($thread_data['thread_subject'], 35) . "</a><br />";
                // Pimped: make_url
                echo showdate("forumdate", $a_data['forum_lastpost']) . "<br />\n";
                echo "<span class='small'>" . $locale['406'] . profile_link($a_data['forum_lastuser'], $a_data['user_name'], $a_data['user_status']) . "</span></td>\n";
                echo "</tr>\n";
                // Pimped Sub Cats <--
            }
        }
        echo "</table>";
        echo "<div style='margin:5px'></div>";
    }
}
    }
    // Pimped: make_url xy
    if (iMEMBER && $can_post) {
        echo "<td align='right' style='padding:0px 0px 4px 0px'>\n<!--pre_forum_buttons-->\n";
        if (!$fdata['thread_locked'] && $can_reply) {
            echo "<a href='" . make_url(FORUM . "post.php?action=reply&amp;forum_id=" . $fdata['forum_id'] . "&amp;thread_id=" . $_GET['thread_id'], FORUM . "post.php?action=reply&amp;forum_id=" . $fdata['forum_id'] . "&amp;thread_id=" . $_GET['thread_id'], "", "") . "'><img src='" . get_image("reply") . "' alt='" . $locale['565'] . "' style='border:0px' /></a>\n";
            // Pimped: make_url, but no seo url-rewrite
        }
        if ($can_post) {
            echo "<a href='" . make_url(FORUM . "post.php?action=newthread&amp;forum_id=" . (int) $fdata['forum_id'], BASEDIR . "forum-newthread-" . (int) $fdata['forum_id'], "", ".html") . "'><img src='" . get_image("newthread") . "' alt='" . $locale['566'] . "' style='border:0px' /></a>\n</td>\n";
            // Pimped: make_url
        }
    }
    echo "</tr>\n</table>\n";
} else {
    whoishere_show("thread", $_GET['thread_id'], false);
    // Pimped: Who is here
}
// Thread Ratings
if ($settings['forum_ratings']) {
    require_once INCLUDES_RATING . "ratings_type_stars.php";
    showratings("F", (int) $_GET['thread_id']);
}
if ($rows != 0) {
    dbquery("UPDATE " . DB_THREADS . " SET thread_postcount='{$rows}', thread_lastpostid='{$last_post}', thread_views=thread_views+1 WHERE thread_id='" . (int) $_GET['thread_id'] . "'");
    if ($_GET['rowstart'] == 0 && $fdata['thread_poll'] == "1") {
        if (iMEMBER) {
            $presult = dbquery("SELECT tfp.forum_poll_title, tfp.forum_poll_votes, tfv.forum_vote_user_id FROM " . DB_FORUM_POLLS . " tfp\r\n\t\t\t\tLEFT JOIN " . DB_FORUM_POLL_VOTERS . " tfv\r\n\t\t\t\tON tfp.thread_id=tfv.thread_id AND forum_vote_user_id='" . (int) $userdata['user_id'] . "'\r\n\t\t\t\tWHERE tfp.thread_id='" . (int) $_GET['thread_id'] . "'");
        } else {
            $presult = dbquery("SELECT tfp.forum_poll_title, tfp.forum_poll_votes FROM " . DB_FORUM_POLLS . " tfp\r\n\t\t\t\tWHERE tfp.thread_id='" . (int) $_GET['thread_id'] . "'");
        }
 if ($settings['forum_cat_icons'] == "1") {
     echo "<td align='center' width='1%' class='tbl1' style='white-space:nowrap'>";
     if ($data['forum_image'] != '' && file_exists(IMAGES_FC . $data['forum_image'])) {
         echo "<img src='" . IMAGES_FC . $data['forum_image'] . "' border='0' alt='' title='" . $data['forum_name'] . "' />";
     } else {
         echo "<img src='" . IMAGES_FC . "default.png' border='0' alt='' title='" . $data['forum_name'] . "' />";
     }
     echo "</td>";
 }
 echo "<td class='tbl1 forum_name'><!--forum_name--><a href='" . make_url(FORUM . "viewforum.php?forum_id=" . $data['forum_id'], BASEDIR . "forum-" . $data['forum_id'] . "-", $data['forum_name'], ".html") . "'>" . $data['forum_name'] . "</a><br />\n";
 // Pimped: make_url
 if ($data['forum_description'] || $moderators) {
     echo "<span class='small'>" . $data['forum_description'] . ($data['forum_description'] && $moderators ? "<br />\n" : "");
     echo ($moderators ? "<strong>" . $locale['411'] . "</strong>" . $moderators . "</span>\n" : "</span>\n") . "<br />\n";
 }
 whoishere_show("index", $data['forum_id']);
 // Pimped: Who is here
 // Pimped --> Sub-Cats
 $parent_result = dbquery("SELECT forum_id, forum_name, forum_parent FROM " . DB_FORUMS . " WHERE " . groupaccess('forum_access') . " AND forum_parent='" . $data['forum_id'] . "' ORDER BY forum_order");
 # caching needed
 $i = dbrows($parent_result);
 if ($i > 0) {
     echo "<span class='side'>&nbsp;&nbsp;<strong>" . $locale['412'] . "</strong>&nbsp;";
     while ($parent_data = dbarray($parent_result)) {
         $i--;
         if ($parent_data['forum_id'] != $data['forum_id']) {
             echo "<a href='" . make_url(FORUM . "viewforum.php?forum_id=" . $parent_data['forum_id'], BASEDIR . "forum-" . $parent_data['forum_id'] . "-", $parent_data['forum_name'], ".html") . "'>" . $parent_data['forum_name'] . "</a>";
             // Pimped: make_url
             if ($i > 0) {
                 echo ", ";
             }