<?php

if ($button == "Filter results")
{
    setcookie( "gfcookie[16]", $ago, time()+60*60*24*7 );
    setcookie( "gfcookie[17]", $filter, time()+60*60*24*7 );
}

if (isset($gfcookie[16]) AND $button != "Filter results")
{
    $ago = $gfcookie[16];
    $filter = $gfcookie[17];
}


$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 = "Active Topics";
$pagelink = $file;
include("inc/inc_setonline.php");
$title = "$name1 Active Topics";
include ("inc/inc_head.php");
include ("inc/inc_body.php");
$title = "Active Topics";
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 color=\"$fontcolor\"><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 color=\"$fontcolor\"><image src=\"images/open_folder_icon.gif\">&nbsp;Active&nbsp;Topics</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...
$activecounter = 0;

print "<form method=\"POST\" action=\"active_topics.php\">
<font size=$fontsize>Show me active topics from : <select name=\"filter\" size=1>";

$result = mysql_query( "SELECT * FROM $grouptable ORDER BY intGroupId" );
$num_rows = mysql_num_rows( $result );

//Dispay records
while ( $a_row = mysql_fetch_object( $result ) )
{
    if ($a_row->ynGroupMaster == "2")
    {
        print "<OPTION VALUE=\"0\">All Forums</option>\n";
        continue;
    }

    if ($a_row->ynGroupMaster == "1")
    {
        print "<OPTION VALUE=\"0\">$a_row->strName</option>\n";
        continue;
    }

    if ($a_row->ynGroupMaster == "0")
    {
        print "<OPTION VALUE=\"$a_row->intId\">-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$a_row->strName</option>\n";
    }
}
if ($ago == "")
{
    $ago = 1029600;
}
print "</select>&nbsp;&nbsp;in the last&nbsp;&nbsp;<select name=\"ago\" size=1>";

print "<option";
if ($ago == 3600)
{
    print " selected";
}
print " value=\"3600\">One Hour</option><option";
if ($ago == 7200)
{
    print " selected";
}
print " value=\"7200\">Two Hours</option><option";
if ($ago == 10800)
{
    print " selected";
}
print " value=\"10800\">Three Hours</option><option";
if ($ago == 14400)
{
    print " selected";
}
print " value=\"14400\">Four Hours</option><option";
if ($ago == 18000)
{
    print " selected";
}
print " value=\"18000\">Five Hours</option><option";
if ($ago == 21600)
{
    print " selected";
}
print " value=\"21600\">Six Hours</option><option";
if ($ago == 43200)
{
    print " selected";
}
print " value=\"43200\">Twelve Hours</option><option";
if ($ago == 86400)
{
    print " selected";
}
print " value=\"86400\">One Day</option><option";
if ($ago == 172800)
{
    print " selected";
}
print " value=\"172800\">Two Days</option><option";
if ($ago == 259200)
{
    print " selected";
}
print " value=\"259200\">Three Days</option><option";
if ($ago == 345600)
{
    print " selected";
}
print " value=\"345600\">Four Days</option><option";
if ($ago == 432000)
{
    print " selected";
}
print " value=\"432000\">Five Days</option><option";
if ($ago == 518400)
{
    print " selected";
}
print " value=\"518400\">Six Days</option><option";
if ($ago == 604800)
{
    print " selected";
}
print " value=\"604800\">One Week</option><option";
if ($ago == 1029600)
{
    print " selected";
}
print " value=\"1029600\">Two Weeks</option><option";
if ($ago == 2678400)
{
    print " selected";
}
print " value=\"2678400\">One Month</option><option";
if ($ago == 31536000000)
{
    print " selected";
}
print " value=\"31536000000\">Millenium</option>
</select>&nbsp;&nbsp;
<input type=\"submit\" value=\"Filter results\" name=\"button\">
</form>
<table border=1 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 width=90% align=center>
  <tr>

    <td width=3% bgcolor=$fgcolour align=center><font face=$font size=$fontsize color=\"$fontcolor\">
    <img  src=\"images/smilies/smile[1].gif\"></a></font></td>

    <td width=24% bgcolor=$fgcolour align=center>
    <b><font face=$font size=$fontsize color=\"$fontcolor\">Topic Title</font></b></td>

    <td width=25% bgcolor=$fgcolour align=center>
    <b><font face=$font size=$fontsize color=\"$fontcolor\">In Forum</font></b></td>

    <td width=22% bgcolor=$fgcolour align=center>
    <b><font face=$font size=$fontsize color=\"$fontcolor\">Author</font></b></td>

    <td width=30% bgcolor=$fgcolour align=center><b>
    <font face=$font size=$fontsize color=\"$fontcolor\">Last Post</font></b></td>

  </tr>";



$now = $epoch - $ago;
if ($cAdminLevel > 2)
{
    if (isset($filter) AND $filter != 0)
    {
        $result = mysql_query( "SELECT * FROM $forumtable WHERE ynTopicRow = 'Yes' AND intForumId = '$filter' AND strEpochTime > '$now' ORDER BY strEpochTime DESC" );
    }
    else
    {
        $result = mysql_query( "SELECT * FROM $forumtable WHERE ynTopicRow = 'Yes' AND strEpochTime > '$now' ORDER BY strEpochTime DESC" );
    }
}
else
{
    if (isset($filter) AND $filter != 0)
    {
         $result = mysql_query( "SELECT * FROM $forumtable WHERE ynTopicRow = 'Yes' AND intPostHidden != '1' AND intForumId = '$filter' AND strEpochTime > '$now' ORDER BY strEpochTime DESC" );
    }
    else
    {
        $result = mysql_query( "SELECT * FROM $forumtable WHERE ynTopicRow = 'Yes' AND intPostHidden != '1' AND strEpochTime > '$now' ORDER BY strEpochTime DESC" );
    }
}
$counter = 0;
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    $resultd = mysql_query( "SELECT * FROM $topicsreadtable WHERE intTopicId = '$a_row->intTopicId' AND strName = '$gfcookie[1]'" );
    $num_rowsd = mysql_num_rows( $resultd );
    if ($num_rowsd == 0)
    {
        //new posts...
        $active = 1;
    }
    if ($a_row->strLastPostName == $gfcookie[1])
    {
        $active = 0;
    }
    $lastposted = $a_row->strEpochTime;

    $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)
    {
        $checkid = 0;
        $counter ++;
        $countthis = 0;
        while ($countthis < $counter)
        {
            if ($checkarray[$countthis] == $a_row->intTopicId)
            {
                $checkid = 1;
            }
            $countthis ++;
        }
        $checkarray[$counter] = $a_row->intTopicId;

        if ($checkid == 1)
        {
            continue;
        }

        $smiley = $a_row->strSmilieUrl;
        if ($smiley == "")
        {
            $smiley = "images/1px_spacer.gif";
        }
        $activecounter ++;

        $groupid = $a_row->intForumId;

        $resultd=mysql_query("SELECT * FROM $grouptable WHERE intId = '$groupid'");
        $num_rowsd = mysql_num_rows( $resultd );
        while ( $d_row = mysql_fetch_object( $resultd ) )
        {
            $subforumname = $d_row->strName;
            $maingroupid = $d_row->intGroupId;
            $skippah = $d_row->intId;
        }
        $resultd=mysql_query("SELECT * FROM $grouptable WHERE intGroupId = '$maingroupid' AND ynGroupMaster = '1'");
        $num_rowsd = mysql_num_rows( $resultd );
        while ( $d_row = mysql_fetch_object( $resultd ) )
        {
            $mainforumname = $d_row->strName;
            $skippeh = $d_row->intId;
        }
        $skip = 0;
        for ($i = 0; $i <= $subcount; $i++)
        {
            if ($nosub[$i] == $skippah OR $nosub[$i] == $skippeh)
            {
                $skip = 1;
                break;
            }
        }
        if ($skip == 1)
        {
            continue;
        }

    if ($a_row->intPostHidden == 1 AND $cAdminLevel < 2)
    {
        //post is deleted - continue
        continue;
    }

        print "<tr><td><center><img src=\"$smiley\"></td>

        <td><font face=$font size=$fontsize color=\"$fontcolor\">&nbsp;
        <a title=\"Read this topic\" href=\"topic.php?topicid=$a_row->intTopicId&groupid=$groupid\">
        $a_row->strTopicName</a></td>

        <td><font face=$font size=$fontsize color=\"$fontcolor\">&nbsp;";





        print "$mainforumname - $subforumname</td>

        <td><font face=$font size=$fontsize color=\"$fontcolor\"><center>
        $a_row->strName</td>

        <td><font face=$font size=$fontsize color=\"$fontcolor\">
        By $a_row->strLastPostName on the $a_row->strLastPostDate at ";

        $time = $a_row->strLastPostTime;
        include ("inc/inc_time.php");

        print "$time$am</td>

        </tr>";
    }
    $active = 0;
}
if ( $activecounter == 0 )
{
    //there are no active topics

    if (isset($filter) AND $filter != '0')
    {
        print "</table><br><font face=$font size=$fontsize color=\"$fontcolor\"><B><center>No-one has posted in this sub-forum since you were last online.</b>";
    }
    else
    {
        print "</table><br><font face=$font size=$fontsize color=\"$fontcolor\"><B><center>No-one has posted since you were last online.</b>";
    }
}
else
{
    print "</table>";
}

include("inc/inc_footer.php");
?>