File: Year.php

package info (click to toggle)
kronolith2 2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 7,936 kB
  • ctags: 3,577
  • sloc: php: 14,001; xml: 1,494; sql: 489; makefile: 68
file content (193 lines) | stat: -rw-r--r-- 7,943 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php

require_once KRONOLITH_BASE . '/lib/Day.php';

/**
 * The Kronolith_View_Year:: class provides an API for viewing years.
 *
 * $Horde: kronolith/lib/Views/Year.php,v 1.12.2.2 2008/01/29 22:52:28 chuck Exp $
 *
 * @author  Chuck Hagenbuch <chuck@horde.org>
 * @author  Jan Schneider <jan@horde.org>
 * @since   Kronolith 2.2
 * @package Kronolith
 */
class Kronolith_View_Year {

    var $year;
    var $_events = array();

    function Kronolith_View_Year($year = null, $events = null)
    {
        if ($year === null) {
            $year = date('Y');
        }
        $this->year = $year;

        if ($events !== null) {
            $this->_events = $events;
        } else {
            $startDate = new Horde_Date(array('year' => $year,
                                              'month' => 1,
                                              'mday' => 1));
            $endDate = new Horde_Date(array('year' => $year,
                                            'month' => 12,
                                            'mday' => 31,
                                            'hour' => 23,
                                            'min' => 59,
                                            'sec' => 59));
            $startDate->correct();
            $endDate->correct();

            $this->_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']);
        }

        if (is_a($this->_events, 'PEAR_Error')) {
            $GLOBALS['notification']->push($this->_events, 'horde.error');
            $this->_events = array();
        }
        if (!is_array($this->_events)) {
            $this->_events = array();
        }
    }

    function html()
    {
        global $prefs;

        $today = mktime(0, 0, 0);
        $timestamp = mktime(1, 1, 1, 1, 1, $this->year);
        $prevstamp = mktime(1, 1, 1, 1, 1, $this->year - 1);
        $nextstamp = mktime(1, 1, 1, 1, 1, $this->year + 1);

        require KRONOLITH_TEMPLATES . '/year/head.inc';

        $html = '<table class="nopadding" cellspacing="5" width="100%"><tr>';
        for ($month = 1; $month <= 12; ++$month) {
            $html .= '<td valign="top">';

            // Heading for each month.
            $mtitle = strftime('%B', mktime(1, 1, 1, $month, 1, $this->year));
            $url = Util::addParameter(Horde::applicationUrl('month.php'), array('month' => $month, 'year' => date('Y', $timestamp)));
            $html .= '<h2 class="smallheader"><a class="smallheader" href="' . $url . '">' . $mtitle . '</a></h2>' .
                '<table class="nopadding monthgrid" cellspacing="0" width="100%"><thead><tr class="item">';
            if (!$prefs->getValue('week_start_monday')) {
                $html .= '<th>' . _("Su"). '</th>';
            }
            $html .= '<th>' . _("Mo") . '</th>' .
                '<th>' . _("Tu") . '</th>' .
                '<th>' . _("We") . '</th>' .
                '<th>' . _("Th") . '</th>' .
                '<th>' . _("Fr") . '</th>' .
                '<th>' . _("Sa") . '</th>';
            if ($prefs->getValue('week_start_monday')) {
                $html .= '<th>' . _("Su") . '</th>';
            }
            $html .= '</tr></thead><tbody><tr>';

            $startday = new Horde_Date(array('mday' => 1,
                                             'month' => $month,
                                             'year' => $this->year));
            $startday = $startday->dayOfWeek();

            $daysInView = Date_Calc::weeksInMonth($month, $this->year) * 7;
            if (!$prefs->getValue('week_start_monday')) {
                $startOfView = 1 - $startday;

                // We may need to adjust the number of days in the
                // view if we're starting weeks on Sunday.
                if ($startday == HORDE_DATE_SUNDAY) {
                    $daysInView -= 7;
                }
                $endday = new Horde_Date(array('mday' => Horde_Date::daysInMonth($month, $this->year),
                                               'month' => $month,
                                               'year' => $this->year));
                $endday = $endday->dayOfWeek();
                if ($endday == HORDE_DATE_SUNDAY) {
                    $daysInView += 7;
                }
            } else {
                if ($startday == HORDE_DATE_SUNDAY) {
                    $startOfView = -5;
                } else {
                    $startOfView = 2 - $startday;
                }
            }

            $currentCalendars = array(true);
            $eventCategories = array();

            foreach ($currentCalendars as $id => $cal) {
                $cell = 0;
                for ($day = $startOfView; $day < $startOfView + $daysInView; ++$day) {
                    $date = new Horde_Date(array('year' => $this->year, 'month' => $month, 'mday' => $day));
                    $daystamp = $date->timestamp();
                    $date->hour = $prefs->getValue('twentyFour') ? 12 : 6;
                    $timestamp = $date->timestamp();
                    $week = $date->weekOfYear();

                    if ($cell % 7 == 0 && $cell != 0) {
                        $html .= "</tr>\n<tr>";
                    }
                    if (date('n', $daystamp) != $month) {
                        $style = 'monthgrid';
                    } elseif (date('w', $daystamp) == 0 || date('w', $daystamp) == 6) {
                        $style = 'weekend';
                    } else {
                        $style = 'text';
                    }

                    /* Set up the link to the day view. */
                    $url = Horde::applicationUrl('day.php', true);
                    $url = Util::addParameter($url, array('timestamp' => $daystamp));

                    if (date('n', $daystamp) != $month) {
                        $cellday = '&nbsp;';
                    } elseif (!empty($this->_events[$daystamp])) {
                        /* There are events; create a cell with tooltip to list
                         * them. */
                        $day_events = '';
                        foreach ($this->_events[$daystamp] as $event) {
                            $day_events .= date($prefs->getValue('twentyFour') ? 'G:i' : 'g:ia', $event->start->timestamp()) . ' - ' . date($prefs->getValue('twentyFour') ? 'G:i' : 'g:ia', $event->end->timestamp()) .
                                (($event->getLocation()) ? ' (' . $event->getLocation() . ')' : '') .
                                ' ' . $event->getTitle() . "\n";
                        }
                        /* Bold the cell if there are events. */
                        $cellday = '<strong>' . Horde::linkTooltip($url, _("View Day"), '', '', '', $day_events) . date('j', $daystamp) . '</a></strong>';

                        /* Set the background color to distinguish the day */
                        $style = 'year-event';
                    } else {
                        /* No events, plain link to the day. */
                        $cellday = Horde::linkTooltip($url, _("View Day")) . date('j', $daystamp) . '</a>';
                    }
                    if ($today == $daystamp && date('n', $daystamp) == $month) {
                        $style .= ' today';
                    }

                    $html .= '<td align="center" class="' . $style . '" height="10" width="5%" valign="top">' .
                        $cellday . '</td>';
                    ++$cell;
                }
            }

            $html .= '</tr></tbody></table></td>';
            if ($month % 3 == 0 && $month != 12) {
                $html .= '</tr><tr>';
            }
        }

        echo $html . '</tr></table>';
    }

    function link($offset = 0, $full = false)
    {
        return Horde::applicationUrl(Util::addParameter('year.php', 'year', $this->year + $offset), $full);
    }

    function getName()
    {
        return 'Year';
    }

}