3 # This program is in the public domain within the United States. Additionally,
4 # we waive copyright and related rights in the work worldwide through the CC0
5 # 1.0 Universal public domain dedication, which can be found at
6 # http://creativecommons.org/publicdomain/zero/1.0/
10 # This file generates a simple calendar which looks something like this:
13 # Sun Mon Tue Wed Thu Fri Sat
16 # 10 11 12 13 14 15 16
17 # 17 18 19 20 21 22 23
18 # 24 25 26 27 28 29 30
21 # The days with events have different CSS classes and can link to custom pages
22 # or javascript or whatever.
24 # The html and CSS is completely customizable without opening a php file.
28 require_once(__DIR__.'/'.'template.php');
30 function calendar_week(&$template) {
31 $template->sub('week');
34 function calendar_day($kind, &$template) {
35 $template->sub($kind);
36 $template->sub('day');
39 # php4 is broken, in that you cannot set a default value for a parameter that
40 # is passed by reference. So, this is set up to use the following screwy
43 # calendar('2006', '12', $events, ref($my_template))
44 function calendar($year, $month, $events = 0, $template = 0) {
46 $template = &$GLOBALS['wfpl_template'];
48 $template = &$template->ref;
51 if(strlen($year) == 2) {
55 $start_timestamp = strtotime("$year-$month-01 00:00");
58 $template->set('month_year', strftime('%B', $start_timestamp) . " " . $year);
60 # number of non-day slots at the begining of the month
61 $pre_non_days = date('w', $start_timestamp );
63 # first display empty cells so the 1st can be in the right column
64 while($cell < $pre_non_days) {
65 calendar_day('nonday', $template);
69 # do the days in this month
70 $days_count = date('t', $start_timestamp );
71 for($day = 1; $day <= $days_count; $day++ ) {
72 $template->set('day_number', $day);
73 if(($cell + 1) % 7 < 2) {
79 $template->set('day_page', $events[$day]);
80 calendar_day("busy_$type", $template);
82 calendar_day("empty_$type", $template);
87 calendar_week($template);
91 # fill the rest of the row with empty cells
94 calendar_day('nonday', $template);
97 calendar_week($template);