3 # Copyright (C) 2006 Jason Woofenden
5 # This file is part of wfpl.
7 # wfpl is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # wfpl is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with wfpl; see the file COPYING. If not, write to the
19 # Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 # This file generates a simple calendar which looks something like this:
26 # Sun Mon Tue Wed Thu Fri Sat
29 # 10 11 12 13 14 15 16
30 # 17 18 19 20 21 22 23
31 # 24 25 26 27 28 29 30
34 # The days with events have different CSS classes and can link to custom pages
35 # or javascript or whatever.
37 # The html and CSS is completely customizable without opening a php file.
42 # Thank you Oscar Merida for figuring out the necessary date() and strftime()
43 # calls: http://freshmeat.net/projects/simplephpcalendar/
47 require_once('code/wfpl/template.php');
49 function calendar_week(&$template) {
50 $template->sub('week');
53 function calendar_day($kind, &$template) {
54 $template->sub($kind);
55 $template->sub('day');
58 function calendar($year, $month, $events = 0, &$template = 0) {
60 $template = $GLOBALS['wfpl_template'];
63 if(strlen($year) == 2) {
67 $start_timestamp = strtotime("$year-$month-01 00:00");
70 $template->set('month_year', strftime('%B', $start_timestamp) . " " . $year);
72 # number of non-day slots at the begining of the month
73 $pre_non_days = date( 'w', $start_timestamp );
75 # first display empty cells so the 1st can be in the right column
76 while($cell < $pre_non_days) {
77 calendar_day('nonday', $template);
81 # do the days in this month
82 $days_count = date( 't', $start_timestamp );
83 for($day = 1; $day <= $days_count; $day++ ) {
84 $template->set('day_number', $day);
85 if(($cell + 1) % 7 < 2) {
91 $template->set('day_page', $events[$day]);
92 calendar_day("busy_$type", $template);
94 calendar_day("empty_$type", $template);
99 calendar_week($template);
103 # fill the rest of the row with empty cells
106 calendar_day('nonday', $template);
109 calendar_week($template);