<?php
$file = __FILE__;
include ("inc/inc_common.php");
include ("inc/inc_connect.php");
include ("inc/inc_admincheck.php");
include ("inc/inc_getdate.php");
if ($groupid == "")
{
    // Get a forum ID

    $result = mysql_query( "SELECT * FROM $forumtable WHERE intTopicId = '$topicid' AND ynTopicRow = 'YES'" );
    $num_rows = mysql_num_rows( $result );
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $groupid = $a_row->intForumId;
    }
}
include ("inc/inc_forumname.php");
$page = "Viewing $userid's Profile";
$pagelink = $file."?userid=".$userid;
include("inc/inc_setonline.php");
$title = $userid."'s Profile";
include ("inc/inc_head.php");
include ("inc/inc_body.php");
$result = mysql_query( "SELECT * FROM $userstable WHERE strName = '$userid'" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    if ($a_row->strAvatar == "NONE")
    {
        $title = "$userid";
    }
    else
    {
        $title = "<table border=0 width=\"100%\" cellpadding=0 cellspacing=0><tr><td width=50% valign=\"top\" align=\"right\">
        <img src=\"$a_row->strAvatar\"><br><br></td>
        <td>
        <b><font face=\"$font\" size=$fontsizec>$a_row->strName</font><bR><br></b>
        </td></tr></table></td>";
        // I know, I know, cop out...
        // Those of you who are following through the code will have noticed that I deleberatly 'broke' the table above by adding two </td> tags.
        // This is because the gap at the bottom of the table is too big without it.
    }
}

include ("inc/inc_title.php");

print "</centeR><table border=0 width=\"100%\" cellpadding=1 cellspacing=0><tr><td  width=\"30%\">
<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;$userid's&nbsp;Profile</a></td></tr>
</table>
</td><td><center>"; //"

print "<br>";

if (isset($gfcookie[1]))
{
    print "
    <a OnClick=\"return confirm('Are you sure you want to log out?')\" href=\"logout.php\"><img border=0 src=\"images/log_off.gif\"></a>";
}
else
{
    print "
    <a href=\"register.php\"><img border=0 src=\"images/register.gif\"></a>
    <a href=\"login.php\"><img border=0 src=\"images/login.gif\"></a>";
}

print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

print "<a href=\"members.php?groupid=$groupid\"><img border=\"0\" src=\"images/members_list.gif\"></a>
<a href=\"search.php\"><img border=\"0\" src=\"images/search.gif\"></a>&nbsp;&nbsp;";

if ($gfcookie[1] == "$userid")
{
    print "<a href=\"buddymenu.php\"><image src=\"images/buddy_list.gif\" border=0></a>&nbsp;&nbsp;";
}

if (isset($gfcookie[1]))
{
    print "<a href=\"active_topics.php\"><img border=0 src=\"images/active_topics.gif\"></a>";
}

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


$result = mysql_query( "SELECT * FROM $userstable WHERE strName = '$userid' LIMIT 0,1" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    print "<br><table border=0 width=\"100%\" cellpadding=0 cellspacing=0>
    <tr><td width=\"50%\" align=\"center\" valign=\"top\">
    <table border=0 width=\"100%\" cellpadding=0 cellspacing=0><tr><td align=\"center\" valign=\"top\">
    ";
    if ($a_row->ynShowEmail != "ON" AND $mailsent != 1)
    {
        print "<table border=1 width=\"75%\" cellspacing=0 cellpadding=5 bgcolor=\"$fgcolour\"><tr><td align=\"center\">
        <form method=\"POST\" action=\"profilesendmail.php\"><font face=\"$font\" size=\"$fontsize\" color=\"$fontcolor\">
        <br><b>Send $userid An Email</b><br><br>
        Subject:<input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"emailsubject\" size=25 style=\"background-image: url('images/textbox_background.gif')\"><br>
        <textarea onfocus=\"document.onkeypress=function(){};\" name=\"emailmessage\" rows=6 cols=25 style=\"background-image: url('images/textarea_background.gif')\"></textarea><br><br><input type=\"submit\" value=\"Send Now\" name=\"forum\"><font size=\"$fontsizea\"><br><br>This email will be sent via the forum, and will not display your email address.
        <input type=\"hidden\" value=\"$userid\" name=\"userid\">
        <input type=\"hidden\" value=\"$groupid\" name=\"groupid\"></form></td></tr></table>
        </td></tr>
        <tr><td><br><br></td></tr>";
    }
    if ($mailsent == 1)
    {
        print "<table border=1 width=\"75%\" cellspacing=0 cellpadding=5 bgcolor=\"$fgcolour\"><tr><td align=\"center\">
        <br><br>
        <font face=\"$font\" size=\"$fontsize\" color=\"$fontcolor\"><b>Your mail to $userid has been sent.<br>
        Thank you.<br><br></b><font size=\"$fontsizea\"><a href=\"profile.php?userid=$userid&groupid=$groupid\">Email again</a><br><br><br>
        </td></tr></table>
        </td></tr>
        <tr><td><br><br></td></tr>";
    }
    print "<tr><td align=\"center\"><table border=1 width=\"75%\" cellspacing=0 cellpadding=5 bgcolor=\"$fgcolour\"><tr><td align=\"center\"><font face=\"$font\" size=$fontsize color=\"$fontcolor\"><b>Recent Forum Posts By $userid</b><br><br>";

    $resultb=mysql_query("SELECT * FROM $forumtable WHERE strName = '$userid' ORDER BY intId DESC LIMIT 0,10");
    $num_rowsb = mysql_num_rows( $resultb );
    while ( $b_row = mysql_fetch_object( $resultb ) )
    {
        if ($b_row->ynGalleryRow != "Yes")
        {
            print "<a href=\"topic.php?topicid=$b_row->intTopicId#post$b_row->intId\">$b_row->strTopicName</a><br>";
        }
        if ($b_row->ynGalleryRow == "Yes" AND $b_row->ynTopicRow != "Yes")
        {
            print "<a href=\"gallerypicture.php?imageid=$b_row->intId&topicid=$b_row->intTopicId&imtitle=$b_row->strTopicName\">$b_row->strTopicName</a><br>";

        }
        if ($b_row->ynGalleryRow == "Yes" AND $b_row->ynTopicRow == "Yes")
        {
            print "<a href=\"gallery.php?topicid=$b_row->intTopicId&groupid=$b_row->intForumGroup\">$b_row->strTopicName</a><br>";
        }
    }
    if ($num_rowsb == 0)
    {
        print "<b>$userid has never posted!</b>";
    }


    print "<br></td></tr></table><br>";

    if (isset($gfcookie[1]))
    {
        print "<a href=\"addbuddy.php?topicid=prof&buddyname=$userid\"><image src=\"images/add_buddy.gif\" border=0></a><br>";
    }
    if ($a_row->strIcqNumber != "")
    {
        print "<a title=\"$a_row->strName's ICQ# is $a_row->strIcqNumber\" href=\"http://wwp.icq.com/scripts/search.dll?to=$a_row->strIcqNumber\"><image border=0 src=\"images/p_icq.GIF\">";
    }
    if ($a_row->strMsnName != "")
    {
        print "<a title=\"$a_row->strName's MSN contact is $a_row->strMsnName\" href=\"http://members.msn.com/$a_row->strMsnName\" target=\"_blank\"><img border=0 src=\"images/p_msn.GIF\"></a>";
    }


    if ($a_row->strYahooId != "")
    {
        print "<a title=\"$a_row->strName's Yahoo ID is $a_row->strYahooId\" href=\"http://members.yahoo.com/interests?.kw=$a_row->strYahooId&.oc=t&.sb=1&SEARCH=Find+People&.cb=1\" target=\"_blank\"><image border=0 src=\"images/p_yim.GIF\">";
    }



    print "</td></tr></table></td>
    <td valign=\"top\">
    <table border=1 width=\"85%\" cellspacing=0 cellpadding=0 bgcolor=\"$fgcolour\"><tr><td valign=\"top\"><br>

    <table border=0 width=\"100%\" cellspacing=0 cellpadding=2 style=\"font-family: $font; font-size: $fontpoint; color: $fontcolor\">";
    if ($a_row->strForename != "" AND $a_row->strSurname != "")
    {
        print "<tr><td align=\"right\" width=\"45%\">Name:&nbsp;</td><td>$a_row->strForename $a_row->strSurname</td></tr>";
    }

    print "<tr><td align=\"right\">Member Number:&nbsp;</td><td>$a_row->intId</td></tr><tr>
    <td align=\"right\" width=\"45%\">Posts:&nbsp;</td><td>$a_row->intPosts</td>
    </tr>
    <tr>
    <td align=\"right\" width=\"45%\">Topics Started:&nbsp;</td><td>$a_row->intTopics</td>
    </tr>";

    if ($a_row->strLocation != "")
    {
        print "<tr><td align=\"right\">Location:&nbsp;</td><td>$a_row->strLocation</td></tr>";
    }

    if ($a_row->memBiography != "")
    {
        $postthis = $a_row->memBiography;
        include ("formatposts.php");
        print "<tr><td align=\"right\" valign=\"top\">Biography:&nbsp;<br></td><td>$postthis<br><bR></td></tr>";
    }

    if ($a_row->strHomepage != "")
    {
        print "<tr><td align=\"right\" valign=\"top\">Homepage:&nbsp;</td><td><a href=\"$a_row->strHomepage\" target=\"_blank\">$a_row->strHomepage</a></td></tr>";
    }

    if ($a_row->strHardware != "")
    {
        print "<tr><td align=\"right\" valign=\"top\">Hardware:&nbsp;</td><td>$a_row->strHardware</a></td></tr>";
    }

    if ($a_row->strConnection != "")
    {
        print "<tr><td align=\"right\" valign=\"top\">Connection:&nbsp;</td><td>$a_row->strConnection</a></td></tr>";
    }

    if ($a_row->strOccupation != "")
    {
        print "<tr><td align=\"right\" valign=\"top\">Occupation:&nbsp;</td><td>$a_row->strOccupation</a></td></tr>";
    }

    if ($a_row->strProfile1Answer != "")
    {
        print "<tr><td align=\"right\" valign=\"top\">$a_row->strProfile1:&nbsp;</td><td>$a_row->strProfile1Answer</a></td></tr>";
    }

    if ($a_row->strProfile2Answer != "")
    {
        print "<tr><td align=\"right\" valign=\"top\">$a_row->strProfile2:&nbsp;</td><td>$a_row->strProfile2Answer</a></td></tr>";
    }


    if ($a_row->strProfile3Answer != "")
    {
        print "<tr><td align=\"right\" valign=\"top\">$a_row->strProfile3:&nbsp;</td><td>$a_row->strProfile3Answer</a></td></tr>";
    }

    if ($a_row->strProfile4Answer != "")
    {
        print "<tr><td align=\"right\" valign=\"top\">$a_row->strProfile4:&nbsp;</td><td>$a_row->strProfile4Answer</a></td></tr>";
    }



    if ($a_row->strIcqNumber != "")
    {
        print "<tr><td align=\"right\" valign=\"top\">ICQ#:&nbsp;</td><td>$a_row->strIcqNumber</a></td></tr>";
    }

    if ($a_row->strMsnName != "")
    {
        print "<tr><td align=\"right\" valign=\"top\">MSN ID:&nbsp;</td><td>$a_row->strMsnName</a></td></tr>";
    }

    if ($a_row->strYahooId != "")
    {
        print "<tr><td align=\"right\" valign=\"top\">Yahoo! Id:&nbsp;</td><td>$a_row->strYahooId</a></td></tr>";
    }

    $resultb=mysql_query("SELECT * FROM $buddytable WHERE strName = '$userid'");
    $num_rowsb = mysql_num_rows( $resultb );

    $resultc=mysql_query("SELECT * FROM $buddytable WHERE strBuddyName = '$userid'");
    $num_rowsc = mysql_num_rows( $resultc );
    print "<tr><td align=\"right\" valign=\"top\">Number Of Buddies:&nbsp;</td><td>$num_rowsb</a></td></tr>
    <tr><td align=\"right\" valign=\"top\">Buddies Of $userid:&nbsp;</td><td>$num_rowsc</a></td></tr>";

    if ($a_row->intPosts > 0 AND $showquotes == 1)
    {
        print "<tr><td align=\"right\" valign=\"top\">Random Quote:&nbsp;</td><td>";
        include ("inc/inc_randomquote.php");
        print "</td></tr>";
    }

    print "<tr><td align=\"right\" valign=\"top\">Mostly Posts In:&nbsp;</td><td>The ";
    include ("inc/inc_busytime.php");
    print "</td></tr>";

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

    //Show admin sections to admins only. This part of the site has various levels of admin security...
    //set it so that no-one can see the details of someone with a higher admin rating than themselves...

    $admingo = 0;
    if ($cAdminLevel == $a_row->intAdminLevel AND $gfcookie[1] == $a_row->strName)
    {
        $admingo = 1;
    }

    if ($cAdminLevel > $a_row->intAdminLevel)
    {
        $admingo = 1;
    }

    if ($admingo == 1)
    {
        if ($cAdminLevel > 1)
        {


            print "</table><table border=0 cellpadding=0 cellspacing=0><tr><td width=100% align=\"center\"><font face=\"$font\" size=$fontsize color=\"$fontcolor\">";

            //print additional information for admin users...

            print "<hr>
            <br>Admin:&nbsp;$a_row->intAdminLevel";
        }
        if ($cAdminLevel > 3)
        {
            print "<br>Password:&nbsp;$a_row->strPassword";
        }
        if ($cAdminLevel > 1)
        {
            print "<br>IP:&nbsp;$a_row->strIp (<a target=\"_blank\" href=\"ipcheck.php?name=$userid\">Check for variable IP</a>)
            <br>Forum Comment:&nbsp;$a_row->strForumComment
            <br>Signature:&nbsp;$a_row->memSig<br>
            Avatar URL:&nbsp;$a_row->strAvatar<br>
            Email: $a_row->strEmail<br><br>";

            //show moderators the option to remove offensive items from this registration

            print "<center><a OnClick=\"return confirm('Are you sure you want to delete this avatar?')\" href=\"removeavatar.php?userid=$userid\">Remove Avatar</a>&nbsp;&nbsp;&nbsp;

            <a href=\"changeavatar.php?userid=$userid\">Change Avatar URL</a>&nbsp;&nbsp;&nbsp

            <a OnClick=\"return confirm('Are you sure you want to delete this signature?')\" href=\"removesig.php?userid=$userid\">Remove Signature</a>&nbsp;&nbsp;&nbsp;

            <a href=\"changesignature.php?userid=$userid&sig=$a_row->memSig\">Change Signature</a>&nbsp;&nbsp;&nbsp

            <a OnClick=\"return confirm('Are you sure you want to delete this photo?')\" href=\"removephoto.php?userid=$userid\">Remove Photo</a><br>

            <a OnClick=\"return confirm('Are you sure you want to delete this biography?')\" href=\"removebiog.php?userid=$userid\">Remove Biography</a>&nbsp;&nbsp;&nbsp;

            <a OnClick=\"return confirm('Are you sure you want to delete this homepage link?')\" href=\"removehome.php?userid=$userid&link=$a_row->strHomepage\">Remove Homepage</a><br>";
        }

        if ($cAdminLevel > 3)
        {
            //show admin users the options to set member properties, or ban this user and delete all their posts...
            print "<a OnClick=\"return confirm('Are you ABSOLUTLEY sure you want to delete this member?')\" href=\"deletemember.php?userid=$userid\">Delete this member</a>&nbsp;&nbsp;&nbsp;
            <a OnClick=\"return confirm('Are you ABSOLUTLEY sure you want to delete all posts from this member?')\" href=\"purge.php?userid=$userid\">Purge All Posts</a>&nbsp;&nbsp;&nbsp;";
        }
        if ($cAdminLevel > 4)
        {
            print "<a OnClick=\"return confirm('Are you ABSOLUTLEY sure you want to delete this member and ban his IP?')\" href=\"banip.php?userid=$userid\">Delete Member And Ban IP</a><br>
            <a href=\"forumcomment.php?userid=$userid&com=$a_row->strForumComment\">Set Forum Comment</a>&nbsp;&nbsp;&nbsp;";

        }
        if ($cAdminLevel > 2)
        {
            print "<a href=\"adminlevel.php?userid=$userid\">Set Admin Level</a><br>";
        }
    }


    print "</table></td></tr></table><br>

    <table border=1 width=\"85%\" cellspacing=0 cellpadding=0 bgcolor=\"$fgcolour\"><tr><td valign=\"top\"><br><font face=\"$font\" size=$fontsize color=\"$fontcolor\"><center>";

    if ($a_row->strPhoto == "")
    {
        print "<b>There is no photo of $userid.</b>";
    }
    else
    {
        print "<a title=\"See $a_row->strName's photo in full\" href=\"profilephoto.php?photourl=$a_row->strPhoto&username=$a_row->strName&userid=$userid&groupid=$groupid\"><img src=\"$a_row->strPhoto\" width=150></a>";
    }
    print "<br><br></td></tr></table></td></tr></table></td></tr></table>";
}

include ("inc/inc_footer.php");