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

$result = mysql_query( "SELECT * FROM $calendartable WHERE intId = $id" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{

    $cday = $a_row->intDay;
    $cmonth = $a_row->intMonth;
    $cyear = $a_row->intYear;
    $title = $a_row->strTitle;
    $post = $a_row->intTopicId;
}

// add to the forum if the id is set...

if ( $post > 0 )
{
    $result = mysql_query( "SELECT * FROM $forumtable WHERE intTopicId = '$post' AND ynTopicRow = 'Yes'" );
    $num_rows = mysql_num_rows( $result );
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $groupid = $a_row->intForumId;
        $topictitle = $a_row->strTopicName;
    }



    $topicid = $post;
    $tsttxt = $gfcookie[1]." has backed out of this event.";
    include ("add_calendar_reply.php");
}



$result = mysql_query( "SELECT * FROM $calendartable WHERE strTitle = '$title' AND intDay = '$cday' AND intMonth = '$cmonth' AND intYear = '$cyear' AND strName = '$gfcookie[1]'" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    $main = $a_row->ynMainRow;
}


if ( $main == 1 )
{
    $query = "UPDATE $calendartable SET strName = '' WHERE intId = '$id'";
}
else
{
    $query = "DELETE FROM $calendartable WHERE strTitle = '$title' AND intDay = '$cday' AND intMonth = '$cmonth' AND intYear = '$cyear' AND strName = '$gfcookie[1]'";
}


                mysql_query( $query, $link )
                or die ( "Could not delete from \"tblcalendar\" table: "
        .mysql_error() );

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