<?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 = "Show Gallery $name4 ($topicid)";
$pagelink = $file."?topicid=".$topicid;
$page = str_replace("'", "&acute;", $page);
$page = str_replace("\"", "&quot;", $page);
include("inc/inc_setonline.php");
$title = "$name1 - $name2 - $name3 - $name4";
include ("inc/inc_head.php");
include ("inc/inc_body.php");
$title = $name4;
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>
</table>
</td><td><center>";

include ("inc/inc_navigation.php");
//add some icons to the navigation...

print "&nbsp;&nbsp;&nbsp;&nbsp;
<a href=\"#replyhere\">
<img border=0 src=\"images/post_reply.gif\"></a>

<a href=\"new_gallery.php?groupid=$groupid\">
<img border=0 src=\"images/new_post.gif\"></a>

<a href=\"topics.php?groupid=$groupid\">
<img border=0 src=\"images/topics.gif\"></a>";
include ("inc/inc_newmailsdisplay.php");
print "</td></tr></table><br><center>";


//end of include files...



// Add one to the number of views...

$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 ) )
{
    if ( $a_row->strTopicName != "" )
    {
        $thistitle = $a_row->strTopicName;
    }
    $thisid = $a_row->intId;
    $topicid = $a_row->intTopicId;
    $thisviews = $a_row->intViews;
    $vote = $a_row->intVoteId;
    $hbh = $a_row->intHbhForum;
    $hbhname = $a_row->strName;
    $openforum = $a_row->intOpenForum;
}
if ($thisviews == "")
{
    $thisviews = "0";
}
$thisviews ++;
$query = "UPDATE $forumtable SET intViews = '$thisviews' WHERE intTopicId = '$topicid'";
mysql_query( $query, $link ) or die ( "Error with $query   --   $link  : ".mysql_error() );



//start active topics code - tell the database that this user looked at this topic at this time...

if (isset($gfcookie[1]))
{
    //purge any older records

    $query = "DELETE FROM $topicsreadtable WHERE strName = '$gfcookie[1]' AND intTopicId = '$topicid'";
    mysql_query( $query, $link )
    or die ( "Could not add data to \"tblactivetopics\" table: "
    .mysql_error() );

    //now add the new one...

    $query = "INSERT INTO $topicsreadtable
    ( strName, intTopicId, datLastTime )
    values( '$gfcookie[1]', '$topicid', '$epoch' )";

    mysql_query( $query, $link )
    or die ( "Could not add data to \"tblactivetopics\" table: ".mysql_error() );
}


if ($noimage == "nope")
{
    print "<center><font face=\"$font\" size=$fontsize><b>You must include an image to post in this gallery!</b><br><br>";
}

if ($noimage == "notfound")
{
    print "<center><font face=\"$font\" size=$fontsize><b>Sorry, this image cannot be found. Please check your URL and try again.</b><br><br>";
}

if ($noimage == "file")
{
    print "<center><font face=\"$font\" size=$fontsize><b>Sorry, you may only use .jpg or .gif files on this forum.</b><br><br>";
}



//Dispay Pictures
$thumbsperrow ++;
$count=$thumbsperrow;
$rowcount=0;

$result = mysql_query( "SELECT * FROM $forumtable WHERE intTopicId = '$topicid' ORDER BY intId" );
$num_rows = mysql_num_rows( $result );
$topicposts = $num_rows;
while ( $a_row = mysql_fetch_object( $result ) )
{
    if ($a_row->ynTopicRow == "Yes")
    {
        $postthis = $a_row->memPost;
        include ("formatposts.php");
        print "<br><br><table border=1 cellpadding=10 cellspacing=0 bordercolor=\"$bordercolor\" bgcolor=\"$fgcolour\"><tr><td><center><font face=\"$font\" size=$fontsize>$postthis<br></td></tr></table><br>

        <table border=1 cellpadding=0 cellspacing=0 bordercolor=\"$bordercolor\">";
        $nopics = 1;
        continue;
    }
    $nopics = 0;



    //check to show hidden posts to moderators...
    $hide = "no";
    if ($a_row->intPostHidden > 0)
    {
        if ($cAdminLevel == 0)
        {
            continue;
        }
        else
        {
            if ($a_row->intPostHidden == 1)
            {
                $hide = "Deleted by $a_row->strHider";
            }
            else
            {
                $hide = "Original post";
            }
        }
    }

    //need to set a 'sucess' string to 0 to stop a deleted user inheriting the details of the person before them...

    $sucess = 0;

    $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;
    }
    $sucess = 1;

    if ( $sucess == 0 )
    {
        $posts = 0;
        $forumcomment = "Deleted";
        $forumnumber = 0;
    }


    //Draw Table Of Thumbnails (150 pixels wide max)

    if ($count == $thumbsperrow)
    {
        $count = 1;
        print "</tr><tr>";
        $rowcount ++;
    }
    else
    {
        print "<td>&nbsp;</td>";
    }
    $imtitle = str_replace("&", "and", $a_row->strTopicName);
    print "<td width=150 valign=\"bottom\"><centeR>
    <a href=\"gallerypicture.php?imageid=$a_row->intId&groupid=$groupid&topicid=$topicid&imtitle=$imtitle\" title=\"&quot;$imtitle&quot; by $a_row->strName\">";

    if (!file_exists($a_row->strGalleryThumb))
    {
        //no thumbnail - what should we do?

        if ($usemainforthumb == 1)
        {
            //use the main picture...
            print "<image src=\"$a_row->strGalleryImage\" border=0 width=150>";
        }
        else
        {
            //display a 'no image' picture
            print "<image src=\"images/nothumb.jpg\" border=0 width=150>";
        }
    }
    else
    {
        print "<image src=\"$a_row->strGalleryThumb\" border=0 width=150>";
    }


    print "</a><br>
    <font size=\"$fontsize\" face=\"$font\">$a_row->strName";
    if ($galleryrate == 1)
    {
        print "<br><font size=\"$fontsizea\" color=\"$ratecolor\">Current Rating: ";
        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>";
    $locked = $a_row->ynLocked;
    $locker = $a_row->strLockedBy;
    $count ++;
}

if ($rowcount > 1)
{
    while ($count < $thumbsperrow)
    {
        print "<td>&nbsp;</td><td>&nbsp;</td>";
        $count++;
    }
}

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

if ($nopics == 1)
{
    print "<font size=$fontsize face=\"$font\">There are currently no pictures in this Gallery.<br>";
}

print "<br><a name=\"replyhere\"></a>";

if ($noimage == "nope")
{
    print "<center><font face=\"$font\" size=$fontsize><b>You must include an image to post in this gallery!</b><br><br>";
}

if ($noimage == "notfound")
{
    print "<center><font face=\"$font\" size=$fontsize><b>Sorry, this image cannot be found. Please check your URL and try again.</b><br><br>";
}

if ($noimage == "file")
{
    print "<center><font face=\"$font\" size=$fontsize><b>Sorry, you may only use .jpg or .gif files on this forum.</b><br><br>";
}

if ($locked == "Yes")
{
    print "<br><font face=$font size=3><center>This thread has been locked by $locker. You cannot post a reply.<br><br><br><br>";
}
else
{
    if (!isset($gfcookie[1]))
    {
        print "<br><font face=$font size=3><center>You must log in or register to post an image!<br><br>";
        print "<br><br>";
    }
    else
    {
        print "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" width=\"60%\" bgcolor=\"$fgcolour\">
        <tr>
        <td width=\"100%\">
        <p align=\"center\"><br><b>
        <font face=\"$font\" size=\"$fontsize\">
        Post An Image
        </font></b></p>
        <form method=\"POST\" action=\"add_gallery_image.php\" name=\"post\" ENCTYPE=\"multipart/form-data\">
        <center>
        <table border=0 cellspacing=0 cellpadding=0>

        <tr><td><center>
        <font face=\"$font\" size=\"$fontsize\">Image Title&nbsp;</td><td>
        <input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"imagetitle\" style=\"background-image: url('images/textbox_background.gif')\" size=34></td></tr>

        <tr><td><center>
        <font face=\"$font\" size=\"$fontsize\">Image URL&nbsp;</td><td>
        <input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"imageurl\" value=\"http://yourhost.com/yourimage.jpg\" size=34 style=\"background-image: url('images/textbox_background.gif')\">&nbsp;<font face=\"$font\" size=\"$fontsizea\"><a href=\"readme6.htm\" target=\"_blank\">Read Me</a></td></tr>

        <tr><td><center>
        <font face=\"$font\" size=\"$fontsize\">Thumbnail URL&nbsp;</td><td>
        <input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"thumburl\" value=\"http://yourhost.com/yourimage.jpg\" size=34 style=\"background-image: url('images/textbox_background.gif')\">&nbsp;<font face=\"$font\" size=\"$fontsizea\"><a href=\"readme7.htm\" target=\"_blank\">Read Me</a></td></tr>";

        if ($allowgalleryupload == 1)
        {
            print "<tr><td><center>
            <font face=\"$font\" size=\"$fontsize\">Upload Image&nbsp;</td><td>
            <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"9999100000\">
            <input type=\"file\" name=\"file\" style=\"background-image: url('images/textbox_background.gif')\">&nbsp;<font face=\"$font\" size=\"$fontsizea\"><a href=\"readme8.htm\" target=\"_blank\">Read Me</a></td></tr>";
        }

        print "</table><br><table border=0 cellpadding=0 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=\"$bordercolor\" width=\"100%\">
        <tr><td width=\"40%\">";

        include("inc_smilies.php");

        print "<td><script language=javascript><!--

        function markSelection ( txtObj ) {
        if ( txtObj.createTextRange ) {
        txtObj.caretPos = document.selection.createRange().duplicate();
        isSelected = true;
        }
        }

        function insertTag ( txtName, tag, enclose ) {
        var closeTag = tag;
        if ( enclose ) {
        var attribSplit = tag.indexOf ( ' ' );
        if ( tag.indexOf ( ' ' ) > -1 )
        closeTag = tag.substring ( 0, attribSplit );
        }
        if ( isSelected ) {
        var txtObj = eval ( \"document.forms[0].\" + txtName );
        if (txtObj.createTextRange && txtObj.caretPos) {
        var caretPos = txtObj.caretPos;
        caretPos.text = ( ( enclose ) ? \"[\"+tag+\"]\"+caretPos.text+\"[/\"+closeTag+\"]\" : \"\"+tag+\"\"+caretPos.text );
        markSelection ( txtObj );
        if ( txtObj.caretPos.text=='' ) {
        isSelected=false;
        txtObj.focus();
        }
        }
        } else {
        // placeholder for loss of focus handler
        }
        }

        //-->
        </script>

        <textarea onfocus=\"document.onkeypress=function(){};\" rows=\"11\" cols=\"36\" style=\"background-image: url('images/big_area_background.gif')\" name=\"tsttxt\" ONSELECT=\"markSelection(this);\" ONCLICK=\"markSelection(this);\" ONKEYUP=\"markSelection(this);\"></textarea><br>";

        include ("inc_buttons.php");
        print "<input type=\"hidden\" name=\"topicid\" value=\"$topicid\">
        <input type=\"hidden\" name=\"groupid\" value=\"$groupid\">
        <input type=\"hidden\" name=\"topictitle\" value=\"$thistitle\">
        <br>
        <p align=\"center\">

        <input type=\"submit\" value=\"Post This!\"></p>

        </td>
        <td width=\"20%\">&nbsp;</td>
        </tr>
        </table>

        </form>
        <p align=\"center\">&nbsp;</td>
        </tr>
        </table>";
    }
}
if ($yesedit == 1)
{
    print "<font face=\"$font\" size=$fontsize><br>Moderator Options<br><br>
    Lock Topic &nbsp;&nbsp;
    Post Reply & Lock Topic &nbsp;&nbsp;
    Unlock Topic";
    if ($vote != 0)
    {
        print "&nbsp;&nbsp;&nbsp;
        Lock Vote&nbsp;&nbsp;&nbsp;
        Unlock Vote";
    }
}


print "<bR><br>";
include("inc/inc_teleporter.php");
include("inc/inc_footer.php");

$topicposts--;
$query = "UPDATE $forumtable SET intReplies = $topicposts WHERE intTopicId = '$topicid'";
mysql_query( $query, $link ) or die ( "Could not add data to \"tblForum\" table: "
.mysql_error() );
mysql_close( $link);
?>