<?php

$file = __FILE__;
include ("inc/inc_common.php");
include ("inc/inc_connect.php");
include ("inc/inc_admincheck.php");
include ("inc/inc_getdate.php");
include ("inc/inc_forumname.php");
$page = "Calendar";
$pagelink = $file."cmonth=$cmonth&cday=$cday&cyear=$cyear";
include("inc/inc_setonline.php");
$title = "$name1 Calendar";
include ("inc/inc_head.php");
include ("inc/inc_body.php");
$title = "Calendar";
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/open_folder_icon.gif\">&nbsp;$cday/$cmonth/$cyear</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...

//check incoming date for validity

if (checkdate($cmonth, 20, $cyear) == false)
{
    $cmonth = $smonth;
    $cyear = $cyear;
}

//expand month...

if ( $cmonth == 1 )
{
    $fullmonth = "January";
}
if ( $cmonth == 2 )
{
    $fullmonth = "Febuary";
}
if ( $cmonth == 3 )
{
    $fullmonth = "March";
}
if ( $cmonth == 4 )
{
    $fullmonth = "April";
}
if ( $cmonth == 5 )
{
    $fullmonth = "May";
}
if ( $cmonth == 6 )
{
    $fullmonth = "June";
}
if ( $cmonth == 7 )
{
    $fullmonth = "July";
}
if ( $cmonth == 8 )
{
    $fullmonth = "August";
}
if ( $cmonth == 9 )
{
    $fullmonth = "September";
}
if ( $cmonth == 10 )
{
    $fullmonth = "October";
}
if ( $cmonth == 11 )
{
    $fullmonth = "November";
}
if ( $cmonth == 12 )
{
    $fullmonth = "December";
}

if ( $cday == "1" )
{
    $th = "st";
}
if ( $cday == "2" )
{
    $th = "nd";
}
if ( $cday == "3" )
{
    $th = "rd";
}
if ( $cday == "21" )
{
    $th = "st";
}
if ( $cday == "22" )
{
    $th = "nd";
}
if ( $cday == "23" )
{
    $th = "rd";
}
if ( $cday == "31" )
{
    $th = "st";
}

if (!isset($th))
{
    $th = "th";
}
$involved = 0;
print "<table border=1 cellpadding=0 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=#111111 width=65% bgcolor=$fgcolour><tr>
<td width=100%><center><font face=$font size=3><br><b>$cday$th of $fullmonth, $cyear</b><br><br></td></tr></table><br>";

$result = mysql_query( "SELECT * FROM $calendartable WHERE intDay = '$cday' AND intMonth = '$cmonth' AND intYear = '$cyear' AND ynMainRow = '1' ORDER BY intTime" );
$num_rows = mysql_num_rows( $result );
//Dispay records
while ( $a_row = mysql_fetch_object( $result ) )
{
    print "<table border=1 cellpadding=0 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=#111111 width=65% bgcolor=$fgcolour><tr>
    <td width=100%><br><center><font face=$font size=2><b>";

    if ( $a_row->ynSport == 1 )
    {
        print "$a_row->strHomeTeam vs $a_row->strAwayTeam";
        if ( $a_row->strLeague == "" )
        {
            //no league
        }
        else
        {
            print " in $a_row->strLeague";
        }
    }




    print "$a_row->strTitle</b>&nbsp;&nbsp;&nbsp;$a_row->intTime<br><br></td></tr></table>
    <table border=1 cellpadding=0 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=#111111 width=65% bgcolor=$fgcolour><tr>
    <td width=25%><center><font face=$font size=2><br>Entered by <a href=\"profile.php?target=calendar&cday=$cday&cmonth=$cmonth&year=$year&userid=$a_row->strAuthor\">$a_row->strAuthor</a><br><br>Involved:";

    $resultb = mysql_query( "SELECT * FROM $calendartable WHERE intDay = '$cday' AND intMonth = '$cmonth' AND intYear = '$cyear' AND strTitle = '$a_row->strTitle'" );
    $num_rowsb = mysql_num_rows( $result );
    while ( $b_row = mysql_fetch_object( $resultb ) )
    {
        if ($b_row->strName == "")
        {
            //no name
        }
        else
        {
            if ($b_row->ynEmail == 1)
            {
                print "<br><a href=\"profile.php?target=calendar&cday=$cday&cmonth=$cmonth&year=$year&userid=$b_row->strName\">$b_row->strName</a> (R$b_row->intHoursBefore)";
            }
            else
            {
                print "<br><a href=\"profile.php?target=calendar&cday=$cday&cmonth=$cmonth&year=$year&userid=$b_row->strName\">$b_row->strName";
            }
            if ($b_row->strName == $gfcookie[1])
            {
                //viewer is involved...
                $invloved = 1;
                $vid = $b_row->intId;
            }
        }
    }
    print "<br><br></td>";
    $postthis = $a_row->memMessage;
    include ("formatposts.php");
    print "<td width=75% bgcolor=$afgcolour valign=top><font face=$font size=2><br>$postthis<br><br>";

    if ( $a_row->strResult == "" )
    {
        //no results...
    }
    else
    {
        print "<b>We $a_row->strResult! $a_row->intHomeScore to $a_row->intAwayScore.</b><br><br>";
    }
    print "</td></tr></table>";
    print "<table border=1 cellpadding=0 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=#111111 width=65% bgcolor=$fgcolour><tr>
    <td width=100%><center><font face=$font size=2>";

    $done = 0;

    if ( $a_row->intYear < $year )
    {
        $done = 1;
    }

    if ( $a_row->intYear == $year )
    {
        if ( $a_row->intMonth < $smonth )
        {
          $done = 1;
        }
    }

    if ( $a_row->intYear == $year )
    {
        if ( $a_row->intMonth == $smonth )
        {
            if ( $a_row->intDay < $sday )
            {
                $done = 1;
            }
        }
    }

    if ( $done == 0 )
    {
        if ( $invloved == 1 AND $usereminders == 1)
        {
            print "<a href=\"calendarremind.php?id=$vid\">Remind Me</a>&nbsp;&nbsp;&nbsp;";
         }

        if ($invloved == 1)
        {
            print "<a href=\"calendarremove.php?id=$a_row->intId\">Remove Me</a>&nbsp;&nbsp;&nbsp;";
        }
        else
        {
            print "<a href=\"calendarinclude.php?id=$a_row->intId\">Add Me</a> ";
        }
    }
    else
    {
        if ( $a_row->strReviewer == "" )
        {
            if ( $invloved == 1 )
            {
                if ( $a_row->ynSport == 1 )
                {
                    print "<a href=\"calendarsportreview.php?id=$a_row->intId\">Review & Results</a>&nbsp;&nbsp;&nbsp;";
                }
                else
                {
                    print "<a href=\"calendarreview.php?id=$a_row->intId\">Review</a>&nbsp;&nbsp;&nbsp;";
                }
            }
        }
        else
        {
            print "<a href=\"calendarreadreview.php?id=$a_row->intId\">Read Review</a>";
        }
    }

    //work out if the user can edit this calendar entry...

    if ($cAdminLevel > 0)
    {
        print "&nbsp;&nbsp;&nbsp;<a href=\"calendaredit.php?id=$a_row->intId\">Edit This Entry</a>";
    }
    else
    {
        if ($gfcookie[1] == "$a_row->strName")
        {
            print "&nbsp;&nbsp;&nbsp;<a href=\"calendaredit.php?id=$a_row->intId\">Edit This Entry</a>";
        }
    }

    //work out if this user can delete the calendar entry.

    if ($cAdminLevel > 1)
    {
        print   "&nbsp;&nbsp;&nbsp;<a OnClick=\"return confirm('Are you sure you want to delete this entry?')\" href=\"calendardelete.php?cday=$cday&cmonth=$cmonth&year=$year&id=$a_row->intId\">Delete This Entry</a>";
    }

    print "</td></tr></table><br>";
}
print "<font face=$font size=2><a href=\"calendaradd.php?cday=$cday&cmonth=$cmonth&year=$year\">Add New</a>&nbsp;&nbsp;&nbsp;<a href=\"calendarsportadd.php?cday=$cday&cmonth=$cmonth&year=$year\">Add Sport Event</a>";

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