#native_company# #native_desc#
#native_cta#

Project Calendar

By John Newbury
on October 6, 2004

Version: 1.0.2

Type: Full Script

Category: Calendars/Dates

License: GNU General Public License

Description: First attempt at a usable, upgradeable calendar module.

<?php
// Current Version - 1.0.2
// Version 1.0.0 -Created May 10th, 2003 By Jim Stewart - Base Calendar
// Version 1.0.1 -Added Next and Prev Buttons.
// upgraded form variables for php 4.3.7 - John Newbury [email protected]
// you may choose to change method GET to POST


class Calendar{
    
    
    function CreateMonthValues($Month,$Year){
        $DayCount=1;
        $NewTimeStamp=mktime(0,0,0,$Month,1,$Year);
            $Date=getdate($NewTimeStamp);
        $MonthToPrint=$Date["month"];
        $Offset=$Date["wday"];
        $MonthNumber=$Date["mon"];
        $DaytoPrint=$Date["mday"];
        If ($MonthNumber=="12"){
            $NextMonth="1";
        }else{
            $NextMonth=$MonthNumber+"1";
        };
        
        While($MonthNumber<>$NextMonth){
            $Date=getdate($NewTimeStamp);
                $DayCount++;
                $MonthNumber=$Date["mon"];
            $NewTimeStamp=$NewTimeStamp+"86400";
        };
        
        $CalendarValues=array($MonthToPrint,($DayCount-2),$Offset);
        return $CalendarValues;
    }




};

// register variables upgrade for php 4.3 & up , John Newbury www.smc-grp.com


$Month = $_GET[Month];
$Year = $_GET[Year];
$Submit = $_GET[Submit];

function NextLink($Month,$Year){
    if($Month=="12"){
        $Month="1";
        $Year=$Year+1;
    }else{
        $Month=$Month+1;
        $Year;
    };
    
    $String="<form action='Calendar.php' method='GET'><input type='hidden' name='Month' value='$Month'><input type='hidden' name='Year' value='$Year'><input type='submit' style='font-family: Century Gothic; background-color: #FFFFFF; border: 1 solid #000080' name='Submit' value='Next'></form>";
    return $String;
};

function PrevLink($Month,$Year){
    if($Month=="1"){
        $Month="12";
        $Year=$Year-1;
    }else{
        $Month=$Month-1;
        $Year;
    };

    $String2="<form action='Calendar.php'method='GET'><input type='hidden' name='Month' value='$Month'><input type='hidden' name='Year' value='$Year'><input type='submit' style='font-family: Century Gothic; background-color: #FFFFFF; border: 1 solid #AD0800' name='Submit' value='Prev'></form>";
    return $String2;
};



//Check for Input Variables
If($Submit){
    $Month=$Month;
    $Year=$Year;
}else{

$ThisMonth=getdate(time());
$Month=$ThisMonth["mon"];
$Today=$ThisMonth["mday"];
$Year=$ThisMonth["year"];

};

$cellheadbgcolor="#99CCFF";
$celldaysbgcolor="#EEEEEE";
$tablebordercolor="#000080";
$cellbordercolor="#FFFFFF";
$todaybgcolor="#880000";



$Calendar=new Calendar;
$NextLink=NextLink($Month, $Year);
$PrevLink=PrevLink($Month, $Year);
$Values=$Calendar->CreateMonthValues($Month, $Year);
$MonthName=$Values[0];
$NoOfDays=$Values[1];
$OffsetDays=$Values[2];
$DaysOfWeek=array('Sun','Mon','Tues','Wed','Thurs','Fri','Sat');
$FirstDayToPrint=7-$OffsetDays;
$StartDay="1";
$PrintDay="1";


//Start Table
Print"<table align='center' width='35%' cellpadding='0' cellspacing='0' border='1' bordercolor='$tablebordercolor'>n";
    Print"<tr>n";
        Print"<td colspan='1' align='left' bordercolor='$cellbordercolor'>$PrevLink</td><td colspan='5' bgcolor='#EEEEEE' align='center' bordercolor='$cellbordercolor'><font size='5'>$MonthName $Year</font></td><td colspan='1' align='right' bordercolor='$cellbordercolor'>$NextLink</td>n";
        Print"</tr>n<tr>n";
        foreach($DaysOfWeek as $head){
            Print"<td width='5%' align='center' bordercolor='$cellbordercolor' bgcolor='$cellheadbgcolor'>$head</td>n";
        };
        Print"</tr>n";
//start days
    //Resolve Blank Days in Beginning of Month
    while($OffsetDays>0){

        Print"<td width='5%' align='center' bordercolor='$cellbordercolor' bgcolor='$celldaysbgcolor'>&nbsp;</td>n";
        $OffsetDays--;
    };
    while($FirstDayToPrint>0){
            //Check For Today
            if($StartDay==($Today-1)){
                $celldaysbgcolor="#9999FF";
            }else{
                $celldaysbgcolor="#EEEEEE";
            };
        Print"<td width='5%' align='center' bordercolor='$cellbordercolor' bgcolor='$celldaysbgcolor'>$PrintDay</td>n";
        $StartDay++;
        $FirstDayToPrint--;
        $PrintDay=$StartDay;
        
    };
    print"</tr>n";
    //Finish Month
    While($StartDay<=$NoOfDays){
        
        $columns="7";
        print"<tr>n";
        while($columns>0){
                //Check For Today
                if($PrintDay==($Today-1)){
                    $celldaysbgcolor="#9999FF";
                }else{
                    $celldaysbgcolor="#EEEEEE";
                };

            if($StartDay>$NoOfDays){
                $PrintDay=" ";
                
            }else{
                $PrintDay="$StartDay";
            };
            print"<td width='5%' align='center' bordercolor='$cellbordercolor' bgcolor='$celldaysbgcolor'>$PrintDay</td>n";
            $columns--;
            $StartDay++;
        };
        Print"</tr>n";
    };
    
    
    
    

?>