<?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 Image $imageid from Gallery $name4 ($topicid)";
$pagelink = $file."?topicid=".$topicid;
include("inc/inc_setonline.php");
$title = "$name1 - $name2 - $name3 - $name4";
include ("inc/inc_head.php");
include ("inc/inc_body.php");
$title = stripslashes($imtitle);
$title = htmlspecialchars($title);
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/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;<a href=\"gallery.php?groupid=$groupid&topicid=$topicid\">$name4</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...

$result=mysql_query("SELECT * FROM $forumtable WHERE intId = '$imageid'");
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    $resultb = mysql_query( "SELECT * FROM $userstable WHERE strName = '$a_row->strName'" );
    $num_rowsb = mysql_num_rows( $result );
    while ( $b_row = mysql_fetch_object( $resultb ) )
    {
        $posts = $b_row->intPosts;
        $forumcomment = "$b_row->strForumComment<br>";
        $forumnumber = $b_row->intId;
        $avatar = "$b_row->strAvatar";
        $location = "$b_row->strLocation";
        $msn = "$b_row->strMsnName";
        $yahoo = "$b_row->strYahooId";
        $icq = "$b_row->strIcqNumber";
        $adlevel = $b_row->intAdminLevel;
    }
    print "<table border=1 cellpadding=0 cellspacing=0 bordercolor=\"$bordercolor\">
    <tr><td bgcolor=\"$fgcolour\">
    <table border=0 cellspacing=0 cellpadding=2 width=\"100%\"><tr><td valign=\"center\">
    <center><font size=\"$fontsize\" face=\"$font\">
    <b>
    <a title=\"See $a_row->strName's Profile\" href=\"profile.php?userid=$a_row->strName&groupid=$groupid\">$a_row->strName</a></b>
    &nbsp;</td><td valign=\"center\">";

    if ($posts >= $stars5 )
    {
      $stars = 5;
    }
    if ($posts < $stars5 )
    {
        $stars = 4;
    }
    if ($posts < $stars4 )
    {

        $stars = 3;
    }
    if ($posts < $stars3 )
    {
        $stars = 2;
    }
    if ($posts < $stars2 )
    {
        $stars = 1;
    }
    if ($showstars == 1)
    {
        print "<img border=0 alt=\" $a_row->strName has posted $posts times \" src=\"images/$stars\t_star_rating.gif\">&nbsp;</td><td valign=\"center\"><font size=$fontsizea face=\"$font\">";
    }

    if ($showlocation == 1)
    {
        if ($location != "")
        {
            print "$location</td><td valign=\"center\"><font size=$fontsizea face=\"$font\">";
        }
    }

    if ($showposts == "1")
    {
        //see if you have one 'post' or many 'posts'...
        if ($posts == 1)
        {
            print "1 Post&nbsp;</td><td valign=\"center\"><font size=$fontsizea face=\"$font\">";
        }
        else
        {
            print "$posts Posts&nbsp;</td><td valign=\"center\"><font size=$fontsizea face=\"$font\">";
        }
    }

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

    print "Posted at $time$am on the $a_row->strDate</td></tr></table>
    </td></tr>";


    $size = getimagesize ("$a_row->strGalleryImage");

    if ( $size[0] > $maximagewidth )
    {
        print "<tr><td><centeR>
        <a href=\"gallery.php?groupid=$groupid&topicid=$topicid\"><img border=0 alt=\"$a_row->strImageTitle\" src=\"$a_row->strGalleryImage\" width=\"$maximagewidth\"></a></td></tr><tr><td>";
    }
    else
    {
        print "<tr><td><centeR>
        <a href=\"gallery.php?groupid=$groupid&topicid=$topicid\"><img border=0 alt=\"$a_row->strImageTitle\" src=\"$a_row->strGalleryImage\"></a></td></tr><tr><td>";
    }




    if ($galleryrate == 1)
    {
        //start rate topic code - added 20/3/03...
        print "<table border=0 cellpadding=2 cellspacing=0 width=\"100%\"><tr><td>
        <font size=$fontsizea face=\"$font\" color=\"$ratecolor\">";
        $ratethis = "This Picture";
        if (!isset($gfcookie[1]))
        {
            print "Log in to Rate $ratethis!";
        }
        else
        {
            //has this person already rated?
            $resultb=mysql_query("SELECT * FROM $ratedtable WHERE strName = '$gfcookie[1]' AND intRateId = '$a_row->intId'");
            $num_rowsrate = mysql_num_rows( $resultb );
            if ($num_rowsrate == 0)
            {
               print "Rate $ratethis: &nbsp;<a href=\"ratetopic.php?topicid=$a_row->intId&rate=bad&imageid=$a_row->intId&groupid=$groupid&topicid=$topicid&gobackto=$topicid&gallery=1\"><font color=\"$ratecolor\">I don't like it</a> * <a href=\"ratetopic.php?topicid=$a_row->intId&rate=okay&imageid=$a_row->intId&groupid=$groupid&topicid=$topicid&gobackto=$topicid&gallery=1\"><font color=\"$ratecolor\">It's okay</a> * <a href=\"ratetopic.php?topicid=$a_row->intId&rate=good&imageid=$a_row->intId&groupid=$groupid&topicid=$topicid&gallery=1\"><font color=\"$ratecolor\">I like it</a>";
            }
            else
            {
                if ($gfcookie[1] == $a_row->strName)
                {
                    print "Current Rating of $ratethis: $a_row->intRating";
                }
                else
                {
                    print "You have already rated $ratethis.";
                }
            }
        }
        print "</td>

        <td align=\"right\" valign=\"center\"><font size=$fontsizea color=\"$ratecolor\">Current Rating:&nbsp;";

        if ($a_row->intRating < -24)
        {
            print "<IMG SRC=\"images/smilies/cry-anim[1].gif\">";
        }
        if ($a_row->intRating < 0 AND $a_row->intRating > -25)
        {
            print "<IMG SRC=\"images/smilies/worry[1].gif\">";
        }
        if ($a_row->intRating == 0)
        {
            print "<IMG SRC=\"images/smilies/indiff[1].gif\">";
        }
        if ($a_row->intRating < 5 AND $a_row->intRating > 0)
        {
            print "<IMG SRC=\"images/smilies/smile[1].gif\">";
        }
        if ($a_row->intRating > 5)
        {
            print "<IMG SRC=\"images/smilies/teeth[1].gif\">";
        }

        print "</td></tr></table>";
        //end rate topic code.
        print "</td></tr><tr><td><table border=0 cellpadding=2 cellspacing=0 width=\"100%\"><tr><td>";
    }

    if ($gfcookie[1] == "$a_row->strName" OR $cAdminLevel > 0)
    {
        print "<font face=$font size=$fontsizea>";
        $yesedit = 0;
        if ($cAdminLevel > 0)
        {
            $yesedit = 1;
        }
        if ($gfcookie[1] == "$a_row->strName")
        {
            $yesedit = 1;
        }
        if ($yesedit > 0)
        {
            if ($hide != "no")
            {
                print "<a title=\"Delete $a_row->strName's picture\" OnClick=\"return confirm('Are you sure you want to delete $a_row->strName's post?')\" href=\"deletepost.php?delid=$a_row->intId&topicid=$a_row->intTopicId&groupid=$groupid\"><img border=0 src=\"images/delete_sm.gif\"></a>";
            }
            else
            {
                if ($cAdminLevel > 0)
                {
                    //Give Option To Undelete
                    print "<a title=\"Undelete $a_row->strName's picture\" OnClick=\"return confirm('Are you sure you want to UNdelete $a_row->strName's post?')\" href=\"deletepost.php?delid=$a_row->intId&topicid=$a_row->intTopicId&groupid=$groupid&undelete=1\"><img border=0 src=\"images/delete_sm.gif\"></a>";
                }
            }
        }
    }
    print "</td><td align=\"right\" valign=\"top\">";
    if ($cAdminLevel > 1)
    {
        print "<font face=\"$font\" size=$fontsizea>IP=$a_row->strIp&nbsp;";
    }
    else
    {
        if (isset($gfcookie[1]))
        {
            if ($a_row->intId == $reportid)
            {
                print "<font face=\"$font\" size=$fontsizea>Thankyou&nbsp;";
            }
            else
            {
                print "<font face=\"$font\" size=$fontsizea>
                <a href=\"report.php?topic=$topicid&postid=$a_row->intId&groupid=$groupid\">
                Report This Picture
                </a>&nbsp;";
            }
        }
    }

    print "</td></tr></table>";
    $postthis = $a_row->memPost;
    include ("formatposts.php");
    print "<table border=0 cellspacing=0 cellpadding=2 width=\"100%\"><tr><td valign=\"center\"><tr><td align=\"center\"><font size=\"$fontsize\" face=\"$font\"><br>$postthis";

    print "</a></i></b></u><font size=2 face=$font><left></li></ul>";

    if ( $a_row->memSig != "")
    {
        //browser break issue...
        $browser = $HTTP_USER_AGENT;
        $pos = strpos($browser, "MSIE");
        if ($pos === false)
        {
           print "<br>";
        }
        print " $sigseperator<br>";

        //format the signature...

        $postthis = $a_row->memSig;
        include ("formatposts.php");

        print "$postthis";
    }

    print "<bR><bR></td></tr></table></td></tr></table><a name=\"bottom\">";
    $id = $a_row->intId;
}

print "<centeR><font size=$fontsize face=\"$font\"><br>";

if ($gallerycomments == 1)
{
    print "<a href=\"#addcomment\">Add a comment about \"$title\"</a><bR>";
}

print "<a href=\"gallery.php?groupid=$groupid&topicid=$topicid\">Return to $name4 gallery</a>.<br>";

//comments section
if ($gallerycomments == 1)
{
    print "<br><br><b><font size=$fontsizeb>Comments</b><br><font size=$fontsize><br>";
    $result=mysql_query("SELECT * FROM $gallerycommentstable where intTieTo = '$id' ORDER BY intId");
    $num_rows = mysql_num_rows( $result );
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $postthis = $a_row->memComment;

        if ($allowgallerycommentformatting == 1)
        {
            include ("formatposts.php");
        }
        else
        {
            include ("formatpostssmall.php");
        }
        print "<b><a title=\"See $a_row->strName's Profile\" href=\"profile.php?userid=$a_row->strName&groupid=$groupid\">$a_row->strName</a></b> says: $postthis<bR><br>";
    }

    print "<br><a name=\"addcomment\"><br><b>Add A Comment</b><br><br>
    <form method=\"POST\" action=\"add_gallery_comment.php\">
    <textarea onfocus=\"document.onkeypress=function(){};\" rows=\"11\" cols=\"36\" style=\"background-image: url('images/big_area_background.gif')\" name=\"comment\"></textarea><br><br>

    <input type=\"hidden\" value=\"$id\" name=\"tieto\">
    <input type=\"hidden\" value=\"$imageid\" name=\"imageid\">
    <input type=\"hidden\" value=\"$groupid\" name=\"groupid\">
    <input type=\"hidden\" value=\"$topicid\" name=\"topicid\">
    <input type=\"hidden\" value=\"$imtitle\" name=\"imtitle\">

    <input type=\"submit\" value=\"Add This Comment\"><br><font size=\"$fontsizea\">";

    if ($allowgallerycommentformatting == 1)
    {
        print "Comment Formatting Is ON.";
    }
    else
    {
        print "Comment Formatting Is OFF.";
    }
    print "</form>";

}

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