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


$reply = $tsttxt;

//figure out the date and times

$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);


$result = mysql_query( "SELECT * FROM $userstable 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 count
    if ($posts == "")
    {
        $posts = "0";
    }
    $posts ++;

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


    $query = "UPDATE $userstable SET intPosts = '$posts', strLastPostTitle = '$topictitle', strLastPostGroupId = '$groupid', strLastPostTopicId = '$topicid', 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;
    }

    //add the new post to the database
    $query = "INSERT INTO $forumtable ( strName, strEmail, strAvatar, memSig, intPosts, strHomepage, strIp, ynShowEmail, strIcqNumber, strMsnName, strYahooId, strLocation, strForumComment, strDate, strTime, memPost, intTopicId, strEpochTime, intForumId, strTopicName, 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', '$topicid', '$epochtime', '$groupid', '$topictitle', '$thisforum' )";

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

    //find the first post in the topic and take the number of replies - add one and put them back along with last poster details...


    $result = mysql_query( "SELECT * FROM $forumtable WHERE intTopicId = '$topicid' ORDER BY intId Limit 0,1" );
    $num_rows = mysql_num_rows( $result );
    //Dispay records
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $thisreplies = $a_row->intReplies;
        $thisid = $a_row->intTopicId;
    }
    if (!isset($thisreplies))
    {
        $thisreplies = "0";
    }
    $thisreplies++;


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

    $query = "UPDATE $forumtable SET intReplies = '$thisreplies', strLastPostName = '$gfcookie[1]', strLastPostTime = '$timeofpost', strLastPostDate = '$dateofpost', intLastPost = '$thislastpost', strEpochTime = '$epochtime' WHERE intTopicId = '$topicid'";
    mysql_query( $query, $link )
    or die ( "Could not add data to \"tblMain\" table: "
    .mysql_error() );
}

?>