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

$title = str_replace ( "'", "", $title);
$time = $timehour.":".$timemin.":00";
$message = str_replace ( "'", "", $message);

if ($includeme == "ON")
{
    $name = $gfcookie[1];
}

if ($post == "No Forums")
{
    $message2 = $message;
}
else
{
    //post on selected forum.
    $reply = $home." vs ".$away."[br][br]".$message;
    $preadd = $day."/".$month."/".$year." at ".$time."\n\n";
    $add="\n\n[CURL][LINK]=calendardayall.php?cday=$day&cmonth=$month&cyear=$year";
    $add2="[/LINK]Take a look at this calendar entry[/URL].";
    $add15="\n\n".$gfcookie[1]." is involved in this event.";

    if ($includeme == "ON")
    {
        $tsttxt = $preadd.$reply.$add15.$add.$add2;
    }
    else
    {
        $tsttxt = $preadd.$reply.$add.$add2;
    }

    $groupid = $post;
    $topicname = "Calendar Entry: ".$home." vs ".$away." : ".$title;
    $priority = 0;
    $R1 = "images/smilies/calendar.gif";
    include ("add_calendar_topic.php");

    $add="\n\n[CURL][LINK]=topic.php?topicid=".$newtopicid;
    $add2="[/LINK]Take a look at this calendar entry on the forum[/URL].";
    $message2 = $message.$add.$add2;
}

//find out the event id...
$eventid = 0;
$result = mysql_query( "SELECT * FROM tblcalendar WHERE ynMainRow = '1' ORDER BY intEventId" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    $eventid = $a_row->intEventId;
}
$eventid ++;

//add the data

$query = "INSERT INTO tblcalendar ( strAuthor, strName, strTitle, memMessage, intDay, intMonth, intYear, intTime, ynMainRow, intEventId, strHomeTeam, strAwayTeam, strLeague, ynSport, intTopicId ) values( '$gfcookie[1]', '$name', '$title', '$message2', '$day', '$month', '$year', '$time', '1', '$eventid', '$home', '$away', '$league', '1', '$post' )";

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

header("Location: calendardayall.php?cday=$day&cmonth=$month&cyear=$year");
exit;