<?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 = "Members";
$pagelink = $file;
include("inc/inc_setonline.php");
$title = "Members";
include ("inc/inc_head.php");
include ("inc/inc_body.php");
$title = "Members";
include ("inc/inc_title.php");
if ($groupid == "")
{
    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;Members</td></tr>
    </table>
    </td><td><center>";
}
else
{
    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/folder_icon.gif\">&nbsp;<a href=\"forums.php\">$name2</a></td></tr>
    <tr><td><font face=\"$font\" size=$fontsize>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<image src=\"images/folder_line.gif\">
    <image src=\"images/folder_icon.gif\">&nbsp;<a href=\"topics.php?groupid=$groupid\">$name3</a></td></tr><tr><td><font face=\"$font\" size=$fontsize>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<image src=\"images/folder_line.gif\">
    <image src=\"images/open_folder_icon.gif\">&nbsp;Members</a></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...


if ( $filter == "")
{
    $filter = "strName";
}

print "<center><form method=POST action=\"members.php?groupid=$groupid\">
<font face=$font size=2>Sort&nbsp;&nbsp;&nbsp;<select size=1 name=filter>
                 <option selected value=strName>Alphabetically</option>
                 <option value=intId>Date Of Joining</option>
                 <option value=admin>Admin Level</option>
                 <option value=photos>With Photos</option>
                 <option value=intPosts>Posts</option>
                 <option value=intTopics>Topics Started</option>
</select>&nbsp;&nbsp;&nbsp;<input type=\"submit\" value=\"Sort\">&nbsp;&nbsp;";

if ($showonline != 1)
{
    if ($showphotos == 1)
    {
        print "<a href=\"members.php?filter=$filter&showphotos=0&showonline=$showonline\">No Photos</a>";
    }
    else
    {
        print "<a href=\"members.php?filter=$filter&showphotos=1&showonline=$showonline\">Show Photos</a>";
    }
}



print "</form><br><br>

<table border=1 cellpadding=4 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=#111111 bgcolor=$fgcolour>
<td><center><font face=$font size=2>View Profile</td>
<td><center><font face=$font size=2>User Name</td>
<td><center><font face=$font size=2>Admin Level</td>
<td><center><font face=$font size=2>Posts</td>
<td><center><font face=$font size=2>Topics</td>
<td><center><font face=$font size=2>Join Date</td>
<td><center><font face=$font size=2>Birthday</td>
<td><center><font face=$font size=2>Last Online</td>
<td><center><font face=$font size=2>Last Post</td>
<td><center><font face=$font size=2>Photo</td></tr>";

if ($membersperpage == 0)
{
    $membersperpage = 999999;
}

if (!isset($limitstart ))
{
    $limitstart = 0;
}

$result = mysql_query( "SELECT * FROM $userstable WHERE ynBanIp != 'Yes' ORDER BY $filter LIMIT $limitstart, $membersperpage" );

if ( $filter == "photos" )
{
    $result = mysql_query( "SELECT * FROM $userstable WHERE ynBanIp != 'Yes' ORDER BY strPhoto DESC LIMIT $limitstart, $membersperpage" );
}
if ( $filter == "admin" )
{
    $result = mysql_query( "SELECT * FROM $userstable WHERE ynBanIp != 'Yes' ORDER BY intAdminLevel DESC LIMIT $limitstart, $membersperpage" );
}
if ( $filter == "intPosts" )
{
    $result = mysql_query( "SELECT * FROM $userstable WHERE ynBanIp != 'Yes' ORDER BY intPosts DESC LIMIT $limitstart, $membersperpage" );
}
if ( $filter == "intTopics" )
{
    $result = mysql_query( "SELECT * FROM $userstable WHERE ynBanIp != 'Yes' ORDER BY intTopics DESC LIMIT $limitstart, $membersperpage" );
}
$epochtime = mktime($date_array);
$timeonline = "Never!";
$num_rows = mysql_num_rows( $result );
//Dispay records
while ( $a_row = mysql_fetch_object( $result ) )
{
    if ( $a_row->strLastOnline == "")
    {
        $timeonlinetext = "Never!";
    }
    else
    {
        $timeonline = ($epoch - $a_row->strLastOnline);
        $timeonline = $timeonline / 86400;
        $timeonline = round($timeonline, 1);
        //sort out wierd bug where negative values are returned...

        if ( $timeonline < 0 )
        {
            $timeonline = $timeonline*-1;
        }
        $timeonlinetext = "$timeonline days ago";
        if ( $timeonline > 0.99 )
        {
            if ($timeonline < 2 )
            {
                $timeonlinetext = "1 day ago";
            }
        }
        if ($timeonline < 0.0035) //5 minutes
        {
            $timeonlinetext = "Online now!";
        }
    }

    if ( $a_row->ynShowOnline == "" )
    {
        //keep this users online status secret...
        $timeonline = "";
        $timeonlinetext = "Hidden!";
    }

    if ($showonline == 1)
    {
        $onlinenow = $epoch - $a_row->strLastOnline;
        if ( $onlinenow > 300 )
        {
            continue;
        }
    }


    if ( $counter == 1)
    {
        $counter = 0;
    print "<tr><td><center><a href=\"profile.php?userid=$a_row->strName&groupid=$groupid\"><img src=\"images/profile_icon.gif\" border=0></a></td>";
    print "<td><center><font face=$font size=2>$a_row->strName</td>";
    print "<td><center><font face=$font size=2>$a_row->intAdminLevel</td>";
    print "<td><center><font face=$font size=2>$a_row->intPosts</td>";
    print "<td><center><font face=$font size=2>$a_row->intTopics</td>";
    print "<td><center><font face=$font size=2>$a_row->datRegistrationDate</td>";

    if ( $a_row->intBirthDay == 0 )
    {
        print "<td><center><font face=$font size=2>Unknown</td>";
    }
    else
    {
        if ( $a_row->intBirthDay == $date_array[mday] )
            {
                if ( $a_row->intBirthMonth == $date_array[mon] )
                {
                    print "<td><center><font face=$font size=2 color=red>Today!</td></font>";
                }
            }
            else
            {
                print "<td><center><font face=$font size=2>$a_row->intBirthDay/$a_row->intBirthMonth</td>";
            }
    }

    print "<td><center><font face=$font size=2>$timeonlinetext</td>";

    if ( $a_row->strLastPostTitle == "" )
    {
        print "<td><center><font face=$font size=2>Never Posted!</td>";
    }
    else
    {
        print "<td><center><font face=$font size=2><a href=\"topic.php?&groupid=$a_row->strLastPostGroupId&topicid=$a_row->strLastPostTopicId\">$a_row->strLastPostTitle</a> - $a_row->strLastPostDate</td>";
    }

    print "<td><center><font face=$font size=2>";
    if ($a_row->strPhoto == "")
    {
        print "No";
    }
    else
    {
        if ($showphotos == 1)
        {
            print "<a href=\"profilephoto.php?photourl=$a_row->strPhoto&username=$a_row->strName&memberpage=1&showphotos=1&showonline=showonline\"><img src=\"$a_row->strPhoto\" border=0 width=100></a>";
        }
        else
        {
            print "<a href=\"profilephoto.php?photourl=$a_row->strPhoto&username=$a_row->strName&memberpage=1&showphotos=0&showonline=showonline\">Yes</a>";
        }
    }

    print "</td></tr>";
    }
    else
    {
        $counter = 1;
        print "<tr bgcolor=$afgcolour><td><center><a href=\"profile.php?userid=$a_row->strName&groupid=$groupid\"><img src=\"images/profile_icon.gif\" border=0></a></td>";
        print "<td><center><font face=$font size=2>$a_row->strName</td>";
        print "<td><center><font face=$font size=2>$a_row->intAdminLevel</td>";
        print "<td><center><font face=$font size=2>$a_row->intPosts</td>";
        print "<td><center><font face=$font size=2>$a_row->intTopics</td>";
        print "<td><center><font face=$font size=2>$a_row->datRegistrationDate</td>";

        if ( $a_row->intBirthDay == 0 )
        {
            print "<td><center><font face=$font size=2>Unknown</td>";
        }
        else
        {
            if ( $a_row->intBirthDay == $date_array[mday] )
                {
                    if ( $a_row->intBirthMonth == $date_array[mon] )
                    {
                        print "<td><center><font face=$font size=2 color=red>Today!</td></font>";
                    }
                }
                else
                {
                    print "<td><center><font face=$font size=2>$a_row->intBirthDay/$a_row->intBirthMonth</td>";
                }
        }

            print "<td><center><font face=$font size=2>$timeonlinetext</td>";

            if ( $a_row->strLastPostTitle == "" )
            {
                print "<td><center><font face=$font size=2>Never Posted!</td>";
            }
            else
            {
                print "<td><center><font face=$font size=2><a href=\"topic.php?&groupid=$a_row->strLastPostGroupId&topicid=$a_row->strLastPostTopicId\">$a_row->strLastPostTitle</a> - $a_row->strLastPostDate</td>";
        }

        print "<td><center><font face=$font size=2>";
        if ($a_row->strPhoto == "")
        {
            print "No";
        }
        else
        {
            if ($showphotos == 1)
            {
                print "<a href=\"profilephoto.php?photourl=$a_row->strPhoto&username=$a_row->strName&memberpage=1&showphotos=1&showonline=showonline\"><img src=\"$a_row->strPhoto\" border=0 width=100></a>";
            }
            else
            {
                print "<a href=\"profilephoto.php?photourl=$a_row->strPhoto&username=$a_row->strName&memberpage=1&showphotos=0&showonline=showonline\">Yes</a>";
            }
        }

        print "</td></tr>";
    }



}
print "</table>";

if ($membersperpage != 0)
{
    $result = mysql_query( "SELECT * FROM $userstable WHERE ynBanIp != 'Yes'" );
    $num_rows = mysql_num_rows( $result );


    $pages = floor($num_rows / $membersperpage);
    $pages ++;
    if ($pages > 1)
    {
        if (!isset($pagenum))
        {
            $pagenum = 1;
        }

        $nextpage = $pagenum + 1;
        $prevpage = $pagenum - 1;

        print "<br><br>";
        if ($pagenum != 1 AND $pagenum != 2)
        {
            print "<a href=\"members.php?limitstart=0\">First Page</a> ";
        }
        if ($pagenum != 1)
        {
            $tlimstart = $limitstart - $membersperpage;
            print "<a href=\"members.php?limitstart=$tlimstart&pagenum=$prevpage\">Previous Page</a> ";
        }
        $count = 0;
        while ($count < $pages)
        {
            $tlimstart = $count * $membersperpage;
            $count++;

            if ($count == $pagenum)
            {
                print "$count ";
            }
            else
            {
                print "<a href=\"members.php?limitstart=$tlimstart&pagenum=$count\">$count</a> ";
            }
        }
        if ($pagenum < $pages)
        {
            $limstartb = $limitstart + $membersperpage;
            print "<a href=\"members.php?limitstart=$limstartb&pagenum=$nextpage\">Next Page</a> ";
        }
        if ($pagenum < ($pages - 1))
        {
            print "<a href=\"members.php?limitstart=$tlimstart&pagenum=$count\">Last Page</a>";
        }
        print "<br><br>";
}
}

include ("inc/inc_birthday.php");
include ("inc/inc_footer.php");

?>