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.
41 require_once('code/wfpl/template.php');
43 function calendar_week(&$template) {
44 $template->sub('week');
47 function calendar_day($kind, &$template) {
48 $template->sub($kind);
49 $template->sub('day');
52 # php4 is broken, in that you cannot set a default value for a parameter that
53 # is passed by reference. So, this is set up to use the following screwy
56 # calendar('2006', '12', $events, ref($my_template))
57 function calendar($year, $month, $events = 0, $template = 0) {
59 $template = &$GLOBALS['wfpl_template'];
61 $template = &$template->ref;
64 if(strlen($year) == 2) {
68 $start_timestamp = strtotime("$year-$month-01 00:00");
71 $template->set('month_year', strftime('%B', $start_timestamp) . " " . $year);
73 # number of non-day slots at the begining of the month
74 $pre_non_days = date( 'w', $start_timestamp );
76 # first display empty cells so the 1st can be in the right column
77 while($cell < $pre_non_days) {
78 calendar_day('nonday', $template);
82 # do the days in this month
83 $days_count = date( 't', $start_timestamp );
84 for($day = 1; $day <= $days_count; $day++ ) {
85 $template->set('day_number', $day);
86 if(($cell + 1) % 7 < 2) {
92 $template->set('day_page', $events[$day]);
93 calendar_day("busy_$type", $template);
95 calendar_day("empty_$type", $template);
100 calendar_week($template);
104 # fill the rest of the row with empty cells
107 calendar_day('nonday', $template);
110 calendar_week($template);