/home/wpollock1/public_html/PHP/calendar.php
1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2: <html lang="en"> <head>
3: <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4: <meta name="description" content="PHP calendar generator">
5: <meta name="author" content="Wayne Pollock">
6: <link rel="contents" href="../index.htm">
7: <link rel="previous" href="../index.htm">
8: <link rel="Icon" type="image/x-icon" href="../images/PHP.ico">
9: <link rel="stylesheet" href="../Styles.css" type="text/css">
10:
11: <title> PHP Calendar Generator </title>
12:
13: <style type="text/css">
14: <!--
15: #Cal A:visited {font-weight: bold; text-decoration: none; color: #800000; }
16: #Cal A:hover {font-weight: bold; text-decoration: underline; }
17: #Cal A:link {font-weight: bold; text-decoration: none; color: #444666; }
18: #Cal A:active {font-weight: bold; text-decoration: none; }
19: #Cal table tr td { border-color: "#AFC7E3; }
20: // -->
21: </style>
22:
23: <script type="text/JavaScript" src="../Common.js"> </script>
24:
25: </head>
26: <body>
27: <div class="Center">
28: <h1> PHP Calendar Generator </h1>
29: <h2></h2>
30: </div>
31:
32: <div class="Center">
33:
34: <?php error_reporting( E_ALL );
35:
36:
37: function array_to_URL ( $vars )
38: {
39: $encoded_vars = array();
40: foreach ( $vars as $name => $val )
41: { $encoded_vars[] = urlencode( $name ) . '=' . urlencode( $val );
42: }
43: return ( htmlentities( join( '&', $encoded_vars ) ) );
44: }
45:
46: list( $month, $year ) = explode( ',', date('m,Y') );
47: $month = intval( $month );
48: $year = intval( $year );
49: if ( isset( $_REQUEST['month'] ) )
50: { $month = intval($_REQUEST['month']);
51: // unset( $_REQUEST['month'] );
52: }
53: if ( isset( $_REQUEST['year'] ) )
54: { $year = intval($_REQUEST['year']);
55: // unset( $_REQUEST['year'] );
56: }
57:
58: $opts = $_REQUEST;
59:
60: pc_calendar( $month, $year, $opts );
61: ?>
62:
63: <?php
64: // Script to produce a monthly calendar.
65: // Written 8/2004 by Wayne Pollock, Tampa Florida USA.
66: // Adapted from "pc_calendar" from "PHP Cookbook" by Sklar and Trachtenberg,
67: // (C) 2003 O'Reilly and Assoc., pages 72-73.
68:
69: function pc_calendar ( $month, $year, $opts = '' )
70: {
71: // Set default options:
72:
73: $border_thickness_def = 1;
74: $border_color_def = 'black';
75: $header_bg_color_def = '#AFC7E3'; // light blue
76: $header_fg_color_def = 'black';
77: $day_fg_color_def = 'black';
78: $day_bg_color_def = 'white';
79: $today_bg_color_def = '#CCFFCC';
80: $today_fg_color_def = 'black';
81:
82: if ( ! is_array( $opts ) ) { $opts = array(); }
83: if ( ! isset( $opts['today_bg_color'] ) )
84: { $opts['today_bg_color'] = "$today_bg_color_def"; }
85: if ( ! isset( $opts['today_fg_color'] ) )
86: { $opts['today_fg_color'] = "$today_fg_color_def"; }
87: if ( ! isset( $opts['month_link'] ) )
88: { $opts['month_link'] = '<a href="' . $_SERVER['PHP_SELF'] .
89: '?month=%d&year=%d">%s</a>';
90: }
91: if ( ! isset( $opts['border_thickness'] ) )
92: { $opts['border_thickness'] = "$border_thickness_def";
93: }
94: if ( ! isset( $opts['border_color'] ) )
95: { $opts['border_color'] = "$border_color_def";
96: }
97: if ( ! isset( $opts['header_bg_color'] ) )
98: { $opts['header_bg_color'] = "$header_bg_color_def";
99: }
100: if ( ! isset( $opts['header_fg_color'] ) )
101: { $opts['header_fg_color'] = "$header_fg_color_def";
102: }
103: if ( ! isset( $opts['day_bg_color'] ) )
104: { $opts['day_bg_color'] = "$day_bg_color_def";
105: }
106: if ( ! isset( $opts['day_fg_color'] ) )
107: { $opts['day_fg_color'] = "$day_fg_color_def";
108: }
109:
110: $today = mktime( 0, 0, 0, $month, 1, $year );
111: list( $this_month, $this_year, $this_day ) =
112: explode( ',', strftime( '%m,%Y,%d' ) );
113:
114: $day_highlight = ( ($this_month == $month) && ($this_year == $year) );
115:
116: list( $prev_month, $prev_year ) =
117: explode( ',', strftime( '%m,%Y', mktime( 0, 0, 0, $month-1, 1, $year ) ) );
118: $prev_month_link = sprintf( $opts['month_link'], intval($prev_month),
119: intval($prev_year), '<' );
120:
121: list( $next_month, $next_year ) =
122: explode( ',', strftime( '%m,%Y', mktime( 0, 0, 0, $month+1, 1, $year ) ) );
123: $next_month_link = sprintf( $opts['month_link'], intval($next_month),
124: intval($next_year), '>' );
125:
126: printf( '<table border="%d" cellspacing="0" cellpadding="2" class="Center"' .
127: 'summary="Monthly calendar for current month with links to prev, next"' .
128: ' style="border-color:%s;" id="Cal">',
129: $opts['border_thickness'], $opts['border_color'] );
130:
131: ?>
132:
133: <caption></caption>
134: <colgroup span="7" width="*"></colgroup>
135: <thead>
136: <?php printf( '<tr style="font-size:150%%;" bgcolor="%s">', $opts['header_bg_color'] );
137: printf( '<th style="color:%s;"><b>%s</b></th>',
138: $opts['header_fg_color'], $prev_month_link );
139: printf( '<th colspan="5" style="color:%s;"><b>%s</b>', $opts['header_fg_color'],
140: strftime( '%B %Y', $today ) );
141: ?>
142: </th>
143: <?php printf( '<th style="color:%s;"><b>%s</b></th>',
144: $opts['header_fg_color'], $next_month_link ); ?>
145: </tr>
146:
147: <?php
148: $total_days_in_month = date( 't', $today );
149:
150: // Print column headers (days of the week):
151: printf( '<tr style="font-size:150%%;" bgcolor="%s">', $opts['header_bg_color'] );
152: $week_day_names = array( 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' );
153: foreach ( $week_day_names as $day )
154: { printf( '<th style="color:%s;"><b>%s</b></th>', $opts['header_fg_color'], $day );
155: }
156:
157: printf( '</tr></thead><tbody><tr bgcolor="%s">', $opts['day_bg_color'] );
158:
159: // Align the first day of the month under the right day:
160: $day_offset = date( 'w', $today );
161: if ( $day_offset > 0 )
162: { for ( $i = 0; $i < $day_offset; ++$i )
163: { printf( '<td bgcolor="%s" ' .
164: 'style="text-align:center;color:%s;"> </td>',
165: $opts['day_bg_color'], $opts['day_fg_color'] );
166:
167: }
168: }
169:
170: $yesterday_secs = time() - (60 * 60 * 24 );
171:
172: // Display the days:
173: for ( $day = 1; $day <= $total_days_in_month; ++$day )
174: { $day_secs = mktime( 0, 0, 0, $month, $day, $year );
175: if ( ($day_secs >= $yesterday_secs) && $day_highlight && ($day == $this_day) )
176: { printf( '<td bgcolor="%s" ' .
177: 'style="font-size=120%%;text-align:center;color:%s;">%d</td>',
178: $opts['today_bg_color'], $opts['today_fg_color'], $day );
179: } else {
180: printf( '<td bgcolor="%s" ' .
181: 'style="text-align:center;color:%s;">%d</td>',
182: $opts['day_bg_color'], $opts['day_fg_color'], $day );
183: }
184:
185: // Check to see if we must start the next row (week):
186: ++$day_offset;
187: if ( $day_offset == 7 )
188: { $day_offset = 0;
189: print( "</tr>\n" );
190: if ( $day < $total_days_in_month ) { print( '<tr>' ); }
191: }
192: }
193: // Fill in the last row (week) with blanks:
194: $days_remaining = 7 - $day_offset;
195: if ( $days_remaining < 7 )
196: { for ( $i = 0; $i < $days_remaining; ++$i )
197: { printf( '<td bgcolor="%s" ' .
198: 'style="text-align:center;color:%s;"> </td>',
199: $opts['day_bg_color'], $opts['day_fg_color'] );
200: }
201: }
202: print( '</tr></tbody></table>' );
203: }
204: ?>
205:
206: </div>
207:
208: <div>
209: <script type="text/JavaScript"> <!--
210: addFooter( "Question: PHP Monthly Calendar" );
211: // --> </script>
212: <noscript>
213: <p> This page was last updated by Wayne Pollock. </p>
214: </noscript>
215:
216: </div></body></html>