<?php
include ("inc/inc_common.php");

$reply = $tsttxt;

//make sure the user is logged in and check that they haven't been deleted since last post
if (isset($gfcookie[1]))
{
    $result = mysql_query( "SELECT * FROM tbluser WHERE strName = '$gfcookie[1]'" );
    $num_rows = mysql_num_rows( $result );
    //Dispay records
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $posts = $a_row->intPosts;
        $topics = $a_row->intTopics;
        $signature = $a_row->memSig;
    }
    if ( $num_rows == 0 )
    {
        //user is deleted
        header("Location: logout.php");
        exit;
    }
    else
    {
        //add 1 to post and topic count
        if ($posts == "")
        {
            $posts = "0";
        }

        if ($topics == "")
        {
            $topics = "0";
        }

        $posts ++;
        $topics ++;

        $date_array = getdate();
        $dateofpost = "$date_array[mday]/$date_array[mon]/$date_array[year]";
        $timeofpost = "$date_array[hours]:$date_array[minutes]:$date_array[seconds]";
        $epochtime = mktime($date_array);

        // send a message if star count has changed...
        include ("inc/inc_postmessage.php");

        $result = mysql_query(  "SELECT * FROM $forumtable WHERE ynTopicRow = 'Yes' ORDER BY intTopicId DESC LIMIT 0,1" );
        $num_rows = mysql_num_rows( $result );
        //Dispay records
        while ( $a_row = mysql_fetch_object( $result ) )
        {
            $newtopicid = $a_row->intTopicId;
        }
    }

    $newtopicid ++;

    $date_array = getdate();
    $dateofpost = "$date_array[mday]/$date_array[mon]/$date_array[year]";
    $timeofpost = "$date_array[hours]:$date_array[minutes]:$date_array[seconds]";
    $epochtime = mktime($date_array);


    $query = "UPDATE $userstable SET intPosts = '$posts', intTopics = '$topics', strLastPostTitle = '$topicname', strLastPostGroupId = '$groupid', strLastPostTopicId = '$newtopicid', strLastPostDate = '$dateofpost' WHERE strName = '$gfcookie[1]'";
    mysql_query( $query, $link )
    or die ( "Could not add data to \"tblUser\" table: "
    .mysql_error() );

    //find out what forum group this is in

    $result = mysql_query( "SELECT * FROM $grouptable WHERE intId = '$groupid'" );
    $num_rows = mysql_num_rows( $result );
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $thisforum = $a_row->intGroupId;
    }

    $query = "INSERT INTO $forumtable ( strName, strEmail, strAvatar, memSig, intPosts, strHomepage, strIp, ynShowEmail, strIcqNumber, strMsnName, strYahooId, strLocation, strForumComment, strDate, strTime, memPost, intTopicId, strTopicName, strEpochTime, ynPriority, intForumId, intForumGroup ) values( '$gfcookie[1]', '$gfcookie[2]', '$gfcookie[3]', '$signature', '$gfcookie[5]', '$gfcookie[6]', '$REMOTE_ADDR', '$gfcookie[9]', '$gfcookie[10]', '$gfcookie[11]', '$gfcookie[12]', '$gfcookie[13]', '$gfcookie[14]', '$dateofpost', '$timeofpost', '$reply', '$newtopicid', '$topicname', '$epochtime', '$priority', '$groupid', '$thisforum' )";

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

    $thisreplies = 0;

    $thislastpost = 0;

    $query = "UPDATE $forumtable SET intReplies = '$thisreplies', strLastPostName = '$gfcookie[1]', strLastPostTime = '$timeofpost', strLastPostDate = '$dateofpost', intLastPost = '$thislastpost', ynTopicRow = 'Yes', strSmilieUrl = '$R1' WHERE intTopicId = '$newtopicid'";
    mysql_query( $query, $link )
    or die ( "Could not add data to \"tblForum\" table: "
    .mysql_error() );

}
?>
