<?php
/**
* SASHA :: inc/lib/lib.calendar.php
*
* This contains all of the calendar classes.
*
* @package SASHA
* @copyright (C) 2006-2010 Gordon P. Hemsley
* @license docs/LICENSE BSD License
* @version $Id: lib.calendar.php 78 2010-01-04 23:32:19Z gphemsley $
*/
/**
* Calendar
*
* Base class for Calendar
*
* @package SASHA
* @subpackage Calendar
*/
class Calendar
{
var $date_U, $date_r;
var $year, $month, $week, $day, $weekday;
function __construct( $year, $month, $day )
{
$this->year = (int) $year;
$this->month = (int) $month;
$this->day = (int) $day;
$this->date_U = mktime( 0, 0, 0, $this->month, $this->day, $this->year );
$this->date_r = date( 'r', mktime( 0, 0, 0, $this->month, $this->day, $this->year ) );
$this->week = (int) date( 'W', $this->date_U );
$this->weekday = (int) date( 'w', $this->date_U );
}
}
/**
* Calendar_Yearly
*
* Class for creating a yearly calendar.
*
* @package Calendar
*/
class Calendar_Yearly extends Calendar
{
}
/**
* Calendar_Monthly
*
* Class for creating a monthly calendar.
*
* @package Calendar
*/
class Calendar_Monthly extends Calendar
{
var $last_month_length, $this_month_length, $next_month_length;
var $first_day_U;
function __construct( $year, $month, $day )
{
parent::__construct( $year, $month, $day );
$this->last_month_length = (int) date( 't', mktime( 0, 0, 0, $this->month - 1, 1, $this->year ) );
$this->this_month_length = (int) date( 't', $this->date_U );
$this->next_month_length = (int) date( 't', mktime( 0, 0, 0, $this->month + 1, 1, $this->year ) );
$this->first_day_U = mktime( 0, 0, 0, $this->month, 1, $this->year );
}
function output_calendar( $week = TRUE, $bottom_days = TRUE, $small = FALSE )
{
$small_class = ( $small ) ? ' small' : '';
print "\t" . '<table class="month' . $small_class . '">' . "\n";
print "\t\t" . '<caption>' . date( 'F Y', $this->date_U ) . '</caption>' . "\n";
if( $week )
{
print "\t\t" . '<colgroup class="weekofyear">' . "\n";
print "\t\t\t" . '<col />' . "\n";
print "\t\t" . '</colgroup>' . "\n";
}
print "\t\t" . '<colgroup>' . "\n";
print "\t\t\t" . '<col span="5" class="weekdays" />' . "\n";
print "\t\t\t" . '<col span="2" class="weekend" />' . "\n";
print "\t\t" . '</colgroup>' . "\n";
if( $week )
{
print "\t\t" . '<colgroup class="weekofyear">' . "\n";
print "\t\t\t" . '<col />' . "\n";
print "\t\t" . '</colgroup>' . "\n";
}
print "\t\t" . '<thead>' . "\n";
print "\t\t\t" . '<tr>' . "\n";
if( $week )
{
print "\t\t\t\t" . '<th>#</th>' . "\n";
}
print "\t\t\t\t" . '<th><abbr title="Monday">Mon</abbr></th>' . "\n";
print "\t\t\t\t" . '<th><abbr title="Tuesday">Tues</abbr></th>' . "\n";
print "\t\t\t\t" . '<th><abbr title="Wednesday">Wed</abbr></th>' . "\n";
print "\t\t\t\t" . '<th><abbr title="Thursday">Thurs</abbr></th>' . "\n";
print "\t\t\t\t" . '<th><abbr title="Friday">Fri</abbr></th>' . "\n";
print "\t\t\t\t" . '<th><abbr title="Saturday">Sat</abbr></th>' . "\n";
print "\t\t\t\t" . '<th><abbr title="Sunday">Sun</abbr></th>' . "\n";
if( $week )
{
print "\t\t\t\t" . '<th>#</th>' . "\n";
}
print "\t\t\t" . '</tr>' . "\n";
print "\t\t" . '</thead>' . "\n";
if( $bottom_days )
{
print "\t\t" . '<tfoot>' . "\n";
print "\t\t\t" . '<tr>' . "\n";
if( $week )
{
print "\t\t\t\t" . '<th>#</th>' . "\n";
}
print "\t\t\t\t" . '<th><abbr title="Monday">Mon</abbr></th>' . "\n";
print "\t\t\t\t" . '<th><abbr title="Tuesday">Tues</abbr></th>' . "\n";
print "\t\t\t\t" . '<th><abbr title="Wednesday">Wed</abbr></th>' . "\n";
print "\t\t\t\t" . '<th><abbr title="Thursday">Thurs</abbr></th>' . "\n";
print "\t\t\t\t" . '<th><abbr title="Friday">Fri</abbr></th>' . "\n";
print "\t\t\t\t" . '<th><abbr title="Saturday">Sat</abbr></th>' . "\n";
print "\t\t\t\t" . '<th><abbr title="Sunday">Sun</abbr></th>' . "\n";
if( $week )
{
print "\t\t\t\t" . '<th>#</th>' . "\n";
}
print "\t\t\t" . '</tr>' . "\n";
print "\t\t" . '</tfoot>' . "\n";
}
print "\t\t" . '<tbody>' . "\n";
// Loop through the weeks of the month
for( $i = $this->this_month_length + 7, $day = 0; $i > 0; $i -= 7, $day += 7 )
{
print "\t\t\t" . '<tr>' . "\n";
if( $week )
{
$week_number = date( 'W', mktime( 0, 0, 0, $this->month, $day + 1, $this->year ) );
print "\t\t\t\t" . '<th>' . $week_number . '</th>' . "\n";
}
// Loop through the days of the week
for( $j = 1; $j <= 7; $j++ )
{
$week_day = date( 'N', mktime( 0, 0, 0, $this->month, $day + $j, $this->year ) );
$current_day = date( 'd', mktime( 0, 0, 0, $this->month, $day + $j, $this->year ) );
if( ( ( $day - $j ) < 0 ) && ( ( $week_day - $j ) > 0 ) )
{
$this_day_U = strtotime( ( $week_day - $j ) . ' days ago', $this->first_day_U );
$week_day = date( 'N', $this_day_U );
$current_day = date( 'd', $this_day_U );
print "\t\t\t\t" . '<td class="lastmonth" title="Last Month">' . $current_day . '</td>' . "\n";
$day--;
}
elseif( ( $day + $j ) > $this->this_month_length )
{
print "\t\t\t\t" . '<td class="nextmonth" title="Next Month">' . $current_day . '</td>' . "\n";
}
elseif( $current_day == date( 'd' ) )
{
print "\t\t\t\t" . '<td class="today" title="Today">' . $current_day . '</td>' . "\n";
}
else
{
print "\t\t\t\t" . '<td title="This Month">' . $current_day . '</td>' . "\n";
}
}
if( $week )
{
print "\t\t\t\t" . '<th>' . $week_number . '</th>' . "\n";
}
print "\t\t\t" . '</tr>' . "\n";
}
print "\t\t" . '</tbody>' . "\n";
print "\t" . '</table>' . "\n";
}
}
/**
* Calendar_Weekly
*
* Class for creating a weekly calendar.
*
* @package Calendar
*/
class Calendar_Weekly extends Calendar
{
}
/**
* Calendar_Daily
*
* Class for creating a daily calendar.
*
* @package Calendar
*/
class Calendar_Daily extends Calendar
{
}
?>