<?php

$file = __FILE__;
include ("inc/inc_common.php");
include ("inc/inc_connect.php");
include ("inc/inc_admincheck.php");
include ("inc/inc_getdate.php");
include ("inc/inc_forumname.php");
$page = "Forums Page";
$pagelink = $file;
include("inc/inc_setonline.php");
$title = "$name1 Forums";
include ("inc/inc_head.php");
include ("inc/inc_body.php");
$title = "$name1 Forums";
include ("inc/inc_title.php");

print "</centeR><table border=0 width=\"100%\" cellpadding=1 cellspacing=0><tr><td  width=\"20%\">
<table border=0 cellpadding=1 cellspacing=0><tr><td>
<font face=\"$font\" size=$fontsize><image src=\"images/folder_icon.gif\">&nbsp;<a href=\"index.php\">$name1&nbsp;Home</a>
</td></tr>
<tr><td><image src=\"images/folder_line.gif\">
<font face=\"$font\" size=$fontsize><image src=\"images/open_folder_icon.gif\">&nbsp;All&nbsp;Forums</td></tr>
</table>
</td><td><center>";

include ("inc/inc_navigation.php");
include ("inc/inc_newmailsdisplay.php");
print "</td></tr></table><br><center>";

//end of include files...


$grimforumname = $name1;

print "<br><br><table border=1 cellpadding=2 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=#111111 width=\"85%\" bgcolor=$fgcolour>
  <tr><td width=100%><font face=$font size=4>&nbsp;<b>$grimforumname</td></tr></table>";

$result = mysql_query( "SELECT * FROM $grouptable WHERE ynGroupMaster = '1' ORDER BY intGroupOrder" );
$num_rows = mysql_num_rows( $result );

//Dispay records
while ( $a_row = mysql_fetch_object( $result ) )
{
    $skip = 0;
    for ($i = 0; $i <= $subcount; $i++)
    {
        if ($nosub[$i] == $a_row->intId)
        {
            $skip = 1;
            break;
        }
    }
    if ($skip == 1)
    {
        continue;
    }
    $passprot = 0;
    $active = 0;
    print "<table border=1 cellpadding=2 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=#111111 width=85% bgcolor=$fgcolour><tr><td width=100%><font face=$font size=3>&nbsp;<b>$a_row->strName</td></tr></table>";

    $groupid = $a_row->intGroupId;

    print "<table border=1 cellpadding=2 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=#111111 width=\"85%\" bgcolor=$fgcolour>";

    $resultb = mysql_query( "SELECT * FROM $grouptable WHERE ynGroupMaster = '0' AND intGroupId = '$groupid' ORDER BY strName" );
    $num_rowsb = mysql_num_rows( $resultb );

    while ( $b_row = mysql_fetch_object( $resultb ) )
        {
            $skip = 0;
            for ($i = 0; $i <= $subcount; $i++)
            {
                if ($nosub[$i] == $b_row->intId)
                {
                    $skip = 1;
                    break;
                }
            }
            if ($skip == 1)
            {
                continue;
            }

            if ( $b_row->strPassword == "NONE")
            {
            $posticon = "no_new_posts_icon";
            if (isset($gfcookie[1]))
            {
                $resultc = mysql_query( "SELECT * FROM $forumtable WHERE intForumId = '$b_row->intId' AND ynTopicRow = 'Yes'" );
                $num_rowsc = mysql_num_rows( $resultc );
                while ( $c_row = mysql_fetch_object( $resultc ) )
                {

                    $resultd = mysql_query( "SELECT * FROM $topicsreadtable WHERE intTopicId = '$c_row->intTopicId' AND strName = '$gfcookie[1]'" );
                    $read = mysql_num_rows( $resultd );
                    if ($read == 0)
                    {
                        //new posts...
                        $active = 1;
                    }
                    if ($c_row->strLastPostName == $gfcookie[1])
                    {
                        $active = 0;
                    }
                    $lastposted = $c_row->strEpochTime;
                }
                if ($num_rowsc == 0)
                {
                    //nothing there!
                    $active = 0;
                }
                $resultc = mysql_query( "SELECT * FROM $userstable WHERE strName = '$gfcookie[1]'" );
                $num_rowsc = mysql_num_rows( $resultc );
                while ( $c_row = mysql_fetch_object( $resultc ) )
                {
                    if ($c_row->intEpochRegistration > $lastposted)
                    {
                        $active = 0;
                    }
                }

            }

            if ($active == 1)
            {
                $posticon = "hot_topic_new_posts_icon";
            }
        }
        else
        {
            $posticon = "password_required_icon";
            $passprot = 1;
        }


            if ( $b_row->intGroupId == "$groupid" )
            {
                if ($passprot == 1)
                {
                    $passprot = 0;

                   print "<tr>
                    <td width = 2% bgcolor=$bgcolour><center><image src=\"images/$posticon.gif\" border=0></td>

                    <td width = 17% bgcolor=$bgcolour>
                    <font face=$font size=$fontsize color=\"$fontcolor\">

                    &nbsp;<b><a href=\"topicpass.php?groupid=$b_row->intId\">$b_row->strName</a></b>&nbsp;";

                    if ($showmoderators == 1)
                    {
                        $counter = 0;
                        print "<br>&nbsp;<font size=$fontsizea>Moderators:";
                        $resultd = mysql_query( "SELECT * FROM $userstable WHERE strForumsModerated != '' ORDER BY strName" );
                        $num_rowsd = mysql_num_rows( $resultd );
                        while ( $d_row = mysql_fetch_object( $resultd ) )
                        {
                            $fmod = explode(",", $d_row->strForumsModerated);
                            $count = 0;
                            while ($count < 100)
                            {
                                if ($b_row->intId == $fmod[$count])
                                {

                                    print "&nbsp;<a title=\"See $d_row->strName's Profile\" href=\"profile.php?userid=$d_row->strName\">$d_row->strName</a>";
                                    $counter ++;
                                    break;
                                }

                                if ($fmod[$count] == "")
                                {
                                    break;
                                }

                                $count ++;
                            }
                        }
                        if ($counter == 0)
                        {
                            print "&nbsp;None";
                        }
                        print ".";
                    }



                    print "<td width=38% bgcolor=$bgcolour>
                    <font face=$font size=$fontsize color=\"$fontcolor\">
                    &nbsp;$b_row->strComments
                    </td>";
                    $topiccount = 0;
                    $postcount = 0;
                    $resultd = mysql_query( "SELECT * FROM $forumtable WHERE intForumId = '$b_row->intId' AND intPostHidden = '0' AND intEdited = '0'" );
                    $num_rowsd = mysql_num_rows( $resultd );
                    while ( $d_row = mysql_fetch_object( $resultd ) )
                    {
                        if ($d_row->intPostHidden == 1)
                        {
                            continue;
                        }
                        if ($d_row->ynTopicRow == "Yes")
                        {
                            $topiccount ++;
                        }
                        else
                        {
                            $postcount ++;
                        }

                    }
                    print "<td width=\"13%\" bgcolor=\"$bgcolour\">
                    <font face=$font size=$fontsizea color=\"$fontcolor\">
                    &nbsp;$postcount posts in $topiccount topics</td>
                    <td width=30% bgcolor=$bgcolour>
                    <font face=$font size=$fontsizea color=\"$fontcolor\"><centeR>
                    &nbsp;";

                    $resultd=mysql_query("SELECT * FROM $forumtable where intForumId = '$b_row->intId' AND ynTopicRow = 'Yes' ORDER BY strEpochTime DESC LIMIT 0,1 ");
                    $num_rowsd = mysql_num_rows( $resultd );
                    while ( $d_row = mysql_fetch_object( $resultd ) )
                    {
                        print "Last post in \"<a title=\"Read this topic\" href=\"topic.php?topicid=$d_row->intTopicId\">$d_row->strTopicName</a>\" by <a title=\"See $d_row->strLastPostName's Profile\" href=\"profile.php?userid=$d_row->strLastPostName&groupid=$groupid\">$d_row->strLastPostName</a>";

                        if ($showlastposttime == 1)
                        {
                            print " at $time$am on the $d_row->strLastPostDate";
                        }
                        print ".";
                    }
                    if ($num_rowsd == 0)
                    {
                        print "No Posts!";
                    }

                    print "</td>";

                    if ($showsecondicon == 1)
                    {
                        print "<td width = 2% bgcolor=$bgcolour><center><image src=\"images/$posticon.gif\" border=0></td>";
                    }
                    print "</tr>";
                }
                else
                {
                    print "<tr>
                    <td width = 2% bgcolor=$bgcolour><center><image src=\"images/$posticon.gif\" border=0></td>

                    <td width = 17% bgcolor=$bgcolour>
                    <font face=$font size=$fontsize color=\"$fontcolor\">

                    &nbsp;<b><a href=\"topics.php?groupid=$b_row->intId\">$b_row->strName</a></b>&nbsp;";

                    if ($showmoderators == 1)
                    {
                        $counter = 0;
                        print "<br>&nbsp;<font size=$fontsizea>Moderators:";
                        $resultd = mysql_query( "SELECT * FROM $userstable WHERE strForumsModerated != '' ORDER BY strName" );
                        $num_rowsd = mysql_num_rows( $resultd );
                        while ( $d_row = mysql_fetch_object( $resultd ) )
                        {
                            $fmod = explode(",", $d_row->strForumsModerated);
                            $count = 0;
                            while ($count < 100)
                            {
                                if ($b_row->intId == $fmod[$count])
                                {

                                    print "&nbsp;<a title=\"See $d_row->strName's Profile\" href=\"profile.php?userid=$d_row->strName\">$d_row->strName</a>";
                                    $counter ++;
                                    break;
                                }

                                if ($fmod[$count] == "")
                                {
                                    break;
                                }

                                $count ++;
                            }
                        }
                        if ($counter == 0)
                        {
                            print "&nbsp;None";
                        }
                        print ".";
                    }



                    print "<td width=38% bgcolor=$bgcolour>
                    <font face=$font size=$fontsize color=\"$fontcolor\">
                    &nbsp;$b_row->strComments
                    </td>";
                    $topiccount = 0;
                    $postcount = 0;
                    $resultd = mysql_query( "SELECT * FROM $forumtable WHERE intForumId = '$b_row->intId' AND intPostHidden = '0' AND intEdited = '0'" );
                    $num_rowsd = mysql_num_rows( $resultd );
                    while ( $d_row = mysql_fetch_object( $resultd ) )
                    {
                        if ($d_row->ynTopicRow == "Yes")
                        {
                            $topiccount ++;
                        }
                        else
                        {
                            $postcount ++;
                        }
                    }
                    print "<td width=\"13%\" bgcolor=\"$bgcolour\">
                    <font face=$font size=$fontsizea color=\"$fontcolor\">
                    &nbsp;$postcount posts in $topiccount topics</td>
                    <td width=30% bgcolor=$bgcolour>
                    <font face=$font size=$fontsizea color=\"$fontcolor\"><centeR>
                    &nbsp;";

                    $resultd=mysql_query("SELECT * FROM $forumtable where intForumId = '$b_row->intId' AND ynTopicRow = 'Yes' ORDER BY strEpochTime DESC LIMIT 0,1 ");
                    $num_rowsd = mysql_num_rows( $resultd );
                    while ( $d_row = mysql_fetch_object( $resultd ) )
                    {
                        print "Last post in \"<a title=\"Read this topic\" href=\"topic.php?topicid=$d_row->intTopicId\">$d_row->strTopicName</a>\" by <a title=\"See $d_row->strLastPostName's Profile\" href=\"profile.php?userid=$d_row->strLastPostName&groupid=$groupid\">$d_row->strLastPostName</a>";

                        if ($showlastposttime == 1)
                        {
                            print " at $time$am on the $d_row->strLastPostDate";
                        }
                        print ".";
                    }
                    if ($num_rowsd == 0)
                    {
                        print "No Posts!";
                    }

                    print "</td>";

                    if ($showsecondicon == 1)
                    {
                        print "<td width = 2% bgcolor=$bgcolour><center><image src=\"images/$posticon.gif\" border=0></td>";
                    }
                    print "</tr>";
                }
            }
        }

    print "</table>";
    }

if (isset($gfcookie[1]))
{
    print "<table border=0 cellpadding=2 cellspacing=0 style=\"border-collapse: collapse\" width=85%><tr><td width=100% align=\"right\"><font size=$fontsize face=\"$font\"><a href=\"forumsub.php\">Change which forums I can see</a></td></tr></table>";
}

print "<br><table border=0 width=40%><tr><td width=33%><center><image src=\"images/hot_topic_new_posts_icon.gif\" border=0></td>";
print "<td width=33%><center><image src=\"images/no_new_posts_icon.gif\" border=0></td>";
print "<td width=33%><center><image src=\"images/password_required_icon.gif\" border=0></td></tr><tr>";
print "<td><font face=\"$font\" size=$fontsize color=\"$fontcolor\"><center>New Replies</td><td><font face=$font size=$fontsize color=\"$fontcolor\"><center>No New Replies</td><td><font face=$font size=$fontsize color=\"$fontcolor\"><center>Password Protected Forum</td></tr></table>";

include("inc/inc_birthday.php");

include ("inc/inc_footer.php");

?>