<?php

$file = __FILE__;
include ("inc/inc_common.php");
include ("inc/inc_connect.php");
include ("inc/inc_admincheck.php");
include ("inc/inc_getdate.php");

if ($action == "set")
{
    $title = str_replace ( "'", "", $title);
    $ctime = $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 = $message;
        $preadd = $cday."/".$cmonth."/".$cyear." at ".$ctime."\n\n";
        $add="\n\n[IURL][LINK]=calendardayall.php?cday=$cday&cmonth=$cmonth&cyear=$cyear";
        $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.$message.$add15.$add.$add2;
        }
        else
        {
            $tsttxt = $preadd.$message.$add.$add2;
        }
        $groupid = $post;
        $topicname = "Calendar Entry: ".$title;
        $priority = 0;
        $R1 = "images/smilies/calendar.gif";

        include ("add_calendar_topic.php");

        $add="\n\n[IURL][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 $calendartable 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 $calendartable ( strAuthor, strName, strTitle, memMessage, intDay, intMonth, intYear, intTime, ynMainRow, intEventId, intTopicId ) values( '$gfcookie[1]', '$name', '$title', '$message2', '$cday', '$cmonth', '$cyear', '$ctime', '1', '$eventid', '$post' )";

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

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


include ("inc/inc_forumname.php");
$page = "Calendar Add";
$pagelink = $file."cmonth=$cmonth&cday=$cday&cyear=$cyear";
include("inc/inc_setonline.php");
$title = "$name1 Calendar - Add Event";
include ("inc/inc_head.php");
include ("inc/inc_body.php");
$title = "Add Event";
include ("inc/inc_title.php");
if (!isset($cmonth))
{
    $cmonth = $smonth;
}
if (!isset($cyear))
{
    $cyear = $year;
}
if ($cmonth == "")
{
    $cmonth = $smonth;
}
if ($cyear == "")
{
    $cyear = $year;
}
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=\"calendar.php\">Calendar</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=\"calendardayall.php?cmonth=$cmonth&cday=$cday&cyear=$cyear\">$cday/$cmonth/$cyear</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;Add Event</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...

print "<form method=post action=\"calendaradd.php?action=set\"><font face=$font size=2>";

print "Day: <input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"cday\" value=\"$cday\" size=3 style=\"background-image: url('images/textbox_background.gif')\">

Month: <input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"cmonth\" value=\"$cmonth\" size=3 style=\"background-image: url('images/textbox_background.gif')\">

Year: <input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"cyear\" value=\"$cyear\" size=3 style=\"background-image: url('images/textbox_background.gif')\"> Time: <input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"timehour\" value=\"00\" size=1 style=\"background-image: url('images/textbox_background.gif')\">:<input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"timemin\" value=\"00\" size=1 style=\"background-image: url('images/textbox_background.gif')\"><br><br>

<table border=0><tr><td align=right><font face=$font size=2>Title:</td>

<td><input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"title\" size=24 style=\"background-image: url('images/textbox_background.gif')\"><br></td></tr><tr>

<td align=right><font face=$font size=2>Message: </td><td><textarea onfocus=\"document.onkeypress=function(){};\" name=message style=\"background-image: url('images/textarea_background.gif')\"></textarea><br></td></tr></table>

Include Me: <input type=\"checkbox\" name=\"includeme\" value=\"ON\"><br><br>

Post this in:   <select size=1 name=\"post\">
                <option selected>No Forums</option>";


$result = mysql_query( "SELECT * FROM $grouptable WHERE ynGroupMaster = '0' AND intAllowCalendar = '1' ORDER BY intGroupId, intGroupOrder DESC" );
$num_rows = mysql_num_rows( $result );
//Display Records
while ( $a_row = mysql_fetch_object( $result ) )
{
    print "<option value=\"$a_row->intId\">$a_row->strName</option>";
}

print "</select><br><br>

<input type=\"submit\" value=\"Set Event\"></form>";

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