3 # Copyright (C) 2006 Jason Woofenden
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # This file generates a simple calendar which looks something like this:
23 # Sun Mon Tue Wed Thu Fri Sat
26 # 10 11 12 13 14 15 16
27 # 17 18 19 20 21 22 23
28 # 24 25 26 27 28 29 30
31 # The days with events have different CSS classes and can link to custom pages
32 # or javascript or whatever.
34 # The html and CSS is completely customizable without opening a php file.
38 require_once('code/wfpl/template.php');
40 function calendar_week(&$template) {
41 $template->sub('week');
44 function calendar_day($kind, &$template) {
45 $template->sub($kind);
46 $template->sub('day');
49 # php4 is broken, in that you cannot set a default value for a parameter that
50 # is passed by reference. So, this is set up to use the following screwy
53 # calendar('2006', '12', $events, ref($my_template))
54 function calendar($year, $month, $events = 0, $template = 0) {
56 $template = &$GLOBALS['wfpl_template'];
58 $template = &$template->ref;
61 if(strlen($year) == 2) {
65 $start_timestamp = strtotime("$year-$month-01 00:00");
68 $template->set('month_year', strftime('%B', $start_timestamp) . " " . $year);
70 # number of non-day slots at the begining of the month
71 $pre_non_days = date('w', $start_timestamp );
73 # first display empty cells so the 1st can be in the right column
74 while($cell < $pre_non_days) {
75 calendar_day('nonday', $template);
79 # do the days in this month
80 $days_count = date('t', $start_timestamp );
81 for($day = 1; $day <= $days_count; $day++ ) {
82 $template->set('day_number', $day);
83 if(($cell + 1) % 7 < 2) {
89 $template->set('day_page', $events[$day]);
90 calendar_day("busy_$type", $template);
92 calendar_day("empty_$type", $template);
97 calendar_week($template);
101 # fill the rest of the row with empty cells
104 calendar_day('nonday', $template);
107 calendar_week($template);