1: <?php
2: 3: 4: 5: 6: 7: 8:
9: class Kronolith_View_Year
10: {
11: public $year;
12: protected $_events = array();
13:
14: 15: 16: 17: 18: 19:
20: public function __construct(Horde_Date $date)
21: {
22: $this->year = $date->year;
23: $startDate = new Horde_Date(array('year' => $this->year,
24: 'month' => 1,
25: 'mday' => 1));
26: $endDate = new Horde_Date(array('year' => $this->year,
27: 'month' => 12,
28: 'mday' => 31));
29:
30: try {
31: $this->_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']);
32: } catch (Exception $e) {
33: $GLOBALS['notification']->push($e, 'horde.error');
34: $this->_events = array();
35: }
36: if (!is_array($this->_events)) {
37: $this->_events = array();
38: }
39: }
40:
41: public function html()
42: {
43: global $prefs;
44:
45: require KRONOLITH_TEMPLATES . '/year/head.inc';
46:
47: $html = '<table class="nopadding" cellspacing="5" width="100%"><tr>';
48: for ($month = 1; $month <= 12; ++$month) {
49: $html .= '<td valign="top">';
50:
51:
52: $date = new Horde_Date(sprintf('%04d%02d01010101', $this->year, $month));
53: $mtitle = $date->strftime('%B');
54: $html .= '<h2 class="smallheader"><a class="smallheader" href="'
55: . Horde::url('month.php')
56: ->add('date', $date->dateString())
57: . '">' . $mtitle . '</a></h2>'
58: . '<table class="nopadding monthgrid" cellspacing="0" width="100%"><thead><tr class="item">';
59: if (!$prefs->getValue('week_start_monday')) {
60: $html .= '<th>' . _("Su"). '</th>';
61: }
62: $html .= '<th>' . _("Mo") . '</th>' .
63: '<th>' . _("Tu") . '</th>' .
64: '<th>' . _("We") . '</th>' .
65: '<th>' . _("Th") . '</th>' .
66: '<th>' . _("Fr") . '</th>' .
67: '<th>' . _("Sa") . '</th>';
68: if ($prefs->getValue('week_start_monday')) {
69: $html .= '<th>' . _("Su") . '</th>';
70: }
71: $html .= '</tr></thead><tbody><tr>';
72:
73: $startday = new Horde_Date(array('mday' => 1,
74: 'month' => $month,
75: 'year' => $this->year));
76: $startday = $startday->dayOfWeek();
77:
78: $daysInView = Date_Calc::weeksInMonth($month, $this->year) * 7;
79: if (!$prefs->getValue('week_start_monday')) {
80: $startOfView = 1 - $startday;
81:
82:
83:
84: if ($startday == Horde_Date::DATE_SUNDAY) {
85: $daysInView -= 7;
86: }
87: $endday = new Horde_Date(array('mday' => Horde_Date_Utils::daysInMonth($month, $this->year),
88: 'month' => $month,
89: 'year' => $this->year));
90: $endday = $endday->dayOfWeek();
91: if ($endday == Horde_Date::DATE_SUNDAY) {
92: $daysInView += 7;
93: }
94: } else {
95: if ($startday == Horde_Date::DATE_SUNDAY) {
96: $startOfView = -5;
97: } else {
98: $startOfView = 2 - $startday;
99: }
100: }
101:
102: $currentCalendars = array(true);
103: foreach ($currentCalendars as $id => $cal) {
104: $cell = 0;
105: for ($day = $startOfView; $day < $startOfView + $daysInView; ++$day) {
106: $date = new Kronolith_Day($month, $day, $this->year);
107: $date->hour = $prefs->getValue('twentyFour') ? 12 : 6;
108: $week = $date->weekOfYear();
109:
110: if ($cell % 7 == 0 && $cell != 0) {
111: $html .= "</tr>\n<tr>";
112: }
113: if ($date->month != $month) {
114: $style = 'monthgrid';
115: } elseif ($date->dayOfWeek() == 0 || $date->dayOfWeek() == 6) {
116: $style = 'weekend';
117: } else {
118: $style = 'text';
119: }
120:
121:
122: $url = Horde::url('day.php', true)
123: ->add('date', $date->dateString());
124:
125: if ($date->month != $month) {
126: $cellday = ' ';
127: } elseif (!empty($this->_events[$date->dateString()])) {
128: 129:
130: $day_events = '';
131: foreach ($this->_events[$date->dateString()] as $event) {
132: if ($event->status == Kronolith::STATUS_CONFIRMED) {
133: 134:
135: $style = 'year-event';
136: }
137:
138: if ($event->isAllDay()) {
139: $day_events .= _("All day");
140: } else {
141: $day_events .= $event->start->strftime($prefs->getValue('twentyFour') ? '%R' : '%I:%M%p') . '-' . $event->end->strftime($prefs->getValue('twentyFour') ? '%R' : '%I:%M%p');
142: }
143: $day_events .= ':'
144: . ($event->getLocation() ? ' (' . $event->getLocation() . ')' : '')
145: . ' ' . $event->getTitle() . "\n";
146: }
147:
148: $cellday = '<strong>' . Horde::linkTooltip($url, _("View Day"), '', '', '', $day_events) . $date->mday . '</a></strong>';
149: } else {
150:
151: $cellday = Horde::linkTooltip($url, _("View Day")) . $date->mday . '</a>';
152: }
153: if ($date->isToday() && $date->month == $month) {
154: $style .= ' today';
155: }
156:
157: $html .= '<td align="center" class="' . $style . '" height="10" width="5%" valign="top">' .
158: $cellday . '</td>';
159: ++$cell;
160: }
161: }
162:
163: $html .= '</tr></tbody></table></td>';
164: if ($month % 3 == 0 && $month != 12) {
165: $html .= '</tr><tr>';
166: }
167: }
168:
169: echo $html . '</tr></table>';
170: }
171:
172: public function link($offset = 0, $full = false)
173: {
174: return Horde::url('year.php', $full)
175: ->add('date', ($this->year + $offset) . '0101');
176: }
177:
178: public function getName()
179: {
180: return 'Year';
181: }
182:
183: }
184: