/home/wpollock1/public_html/PHP/calendar.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="description" content="PHP calendar generator">
<meta name="author" content="Wayne Pollock">
<link rel="contents" href="../index.htm">
<link rel="previous" href="../index.htm">
<link rel="Icon" type="image/x-icon" href="../images/PHP.ico">
<link rel="stylesheet" href="../Styles.css" type="text/css">
<title> PHP Calendar Generator </title>
<style type="text/css">
<!--
#Cal A:visited {font-weight: bold; text-decoration: none; color: #800000; }
#Cal A:hover {font-weight: bold; text-decoration: underline; }
#Cal A:link {font-weight: bold; text-decoration: none; color: #444666; }
#Cal A:active {font-weight: bold; text-decoration: none; }
#Cal table tr td { border-color: "#AFC7E3; }
// -->
</style>
<script type="text/JavaScript" src="../Common.js"> </script>
</head>
<body>
<div class="Center">
<h1> PHP Calendar Generator </h1>
<h2></h2>
</div>
<div class="Center">
<?php error_reporting( E_ALL );
function array_to_URL ( $vars )
{
$encoded_vars = array();
foreach ( $vars as $name => $val )
{ $encoded_vars[] = urlencode( $name ) . '=' . urlencode( $val );
}
return ( htmlentities( join( '&', $encoded_vars ) ) );
}
list( $month, $year ) = explode( ',', date('m,Y') );
$month = intval( $month );
$year = intval( $year );
if ( isset( $_REQUEST['month'] ) )
{ $month = intval($_REQUEST['month']);
// unset( $_REQUEST['month'] );
}
if ( isset( $_REQUEST['year'] ) )
{ $year = intval($_REQUEST['year']);
// unset( $_REQUEST['year'] );
}
$opts = $_REQUEST;
pc_calendar( $month, $year, $opts );
?>
<?php
// Script to produce a monthly calendar.
// Written 8/2004 by Wayne Pollock, Tampa Florida USA.
// Adapted from "pc_calendar" from "PHP Cookbook" by Sklar and Trachtenberg,
// (C) 2003 O'Reilly and Assoc., pages 72-73.
function pc_calendar ( $month, $year, $opts = '' )
{
// Set default options:
$border_thickness_def = 1;
$border_color_def = 'black';
$header_bg_color_def = '#AFC7E3'; // light blue
$header_fg_color_def = 'black';
$day_fg_color_def = 'black';
$day_bg_color_def = 'white';
$today_bg_color_def = '#CCFFCC';
$today_fg_color_def = 'black';
if ( ! is_array( $opts ) ) { $opts = array(); }
if ( ! isset( $opts['today_bg_color'] ) )
{ $opts['today_bg_color'] = "$today_bg_color_def"; }
if ( ! isset( $opts['today_fg_color'] ) )
{ $opts['today_fg_color'] = "$today_fg_color_def"; }
if ( ! isset( $opts['month_link'] ) )
{ $opts['month_link'] = '<a href="' . $_SERVER['PHP_SELF'] .
'?month=%d&year=%d">%s</a>';
}
if ( ! isset( $opts['border_thickness'] ) )
{ $opts['border_thickness'] = "$border_thickness_def";
}
if ( ! isset( $opts['border_color'] ) )
{ $opts['border_color'] = "$border_color_def";
}
if ( ! isset( $opts['header_bg_color'] ) )
{ $opts['header_bg_color'] = "$header_bg_color_def";
}
if ( ! isset( $opts['header_fg_color'] ) )
{ $opts['header_fg_color'] = "$header_fg_color_def";
}
if ( ! isset( $opts['day_bg_color'] ) )
{ $opts['day_bg_color'] = "$day_bg_color_def";
}
if ( ! isset( $opts['day_fg_color'] ) )
{ $opts['day_fg_color'] = "$day_fg_color_def";
}
$today = mktime( 0, 0, 0, $month, 1, $year );
list( $this_month, $this_year, $this_day ) =
explode( ',', strftime( '%m,%Y,%d' ) );
$day_highlight = ( ($this_month == $month) && ($this_year == $year) );
list( $prev_month, $prev_year ) =
explode( ',', strftime( '%m,%Y', mktime( 0, 0, 0, $month-1, 1, $year ) ) );
$prev_month_link = sprintf( $opts['month_link'], intval($prev_month),
intval($prev_year), '<' );
list( $next_month, $next_year ) =
explode( ',', strftime( '%m,%Y', mktime( 0, 0, 0, $month+1, 1, $year ) ) );
$next_month_link = sprintf( $opts['month_link'], intval($next_month),
intval($next_year), '>' );
printf( '<table border="%d" cellspacing="0" cellpadding="2" class="Center"' .
'summary="Monthly calendar for current month with links to prev, next"' .
' style="border-color:%s;" id="Cal">',
$opts['border_thickness'], $opts['border_color'] );
?>
<caption></caption>
<colgroup span="7" width="*"></colgroup>
<thead>
<?php printf( '<tr style="font-size:150%%;" bgcolor="%s">', $opts['header_bg_color'] );
printf( '<th style="color:%s;"><b>%s</b></th>',
$opts['header_fg_color'], $prev_month_link );
printf( '<th colspan="5" style="color:%s;"><b>%s</b>', $opts['header_fg_color'],
strftime( '%B %Y', $today ) );
?>
</th>
<?php printf( '<th style="color:%s;"><b>%s</b></th>',
$opts['header_fg_color'], $next_month_link ); ?>
</tr>
<?php
$total_days_in_month = date( 't', $today );
// Print column headers (days of the week):
printf( '<tr style="font-size:150%%;" bgcolor="%s">', $opts['header_bg_color'] );
$week_day_names = array( 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' );
foreach ( $week_day_names as $day )
{ printf( '<th style="color:%s;"><b>%s</b></th>', $opts['header_fg_color'], $day );
}
printf( '</tr></thead><tbody><tr bgcolor="%s">', $opts['day_bg_color'] );
// Align the first day of the month under the right day:
$day_offset = date( 'w', $today );
if ( $day_offset > 0 )
{ for ( $i = 0; $i < $day_offset; ++$i )
{ printf( '<td bgcolor="%s" ' .
'style="text-align:center;color:%s;"> </td>',
$opts['day_bg_color'], $opts['day_fg_color'] );
}
}
$yesterday_secs = time() - (60 * 60 * 24 );
// Display the days:
for ( $day = 1; $day <= $total_days_in_month; ++$day )
{ $day_secs = mktime( 0, 0, 0, $month, $day, $year );
if ( ($day_secs >= $yesterday_secs) && $day_highlight && ($day == $this_day) )
{ printf( '<td bgcolor="%s" ' .
'style="font-size=120%%;text-align:center;color:%s;">%d</td>',
$opts['today_bg_color'], $opts['today_fg_color'], $day );
} else {
printf( '<td bgcolor="%s" ' .
'style="text-align:center;color:%s;">%d</td>',
$opts['day_bg_color'], $opts['day_fg_color'], $day );
}
// Check to see if we must start the next row (week):
++$day_offset;
if ( $day_offset == 7 )
{ $day_offset = 0;
print( "</tr>\n" );
if ( $day < $total_days_in_month ) { print( '<tr>' ); }
}
}
// Fill in the last row (week) with blanks:
$days_remaining = 7 - $day_offset;
if ( $days_remaining < 7 )
{ for ( $i = 0; $i < $days_remaining; ++$i )
{ printf( '<td bgcolor="%s" ' .
'style="text-align:center;color:%s;"> </td>',
$opts['day_bg_color'], $opts['day_fg_color'] );
}
}
print( '</tr></tbody></table>' );
}
?>
</div>
<div>
<script type="text/JavaScript"> <!--
addFooter( "Question: PHP Monthly Calendar" );
// --> </script>
<noscript>
<p> This page was last updated by Wayne Pollock. </p>
</noscript>
</div></body></html>