1: <?php
2: 3: 4:
5: class Kronolith_Block_Month extends Horde_Core_Block
6: {
7: 8:
9: private $_share = null;
10:
11: 12:
13: public function __construct($app, $params = array())
14: {
15: parent::__construct($app, $params);
16:
17: $this->_name = _("This Month");
18: }
19:
20: 21:
22: protected function _params()
23: {
24: $params = array(
25: 'calendar' => array(
26: 'name' => _("Calendar"),
27: 'type' => 'enum',
28: 'default' => '__all'
29: )
30: );
31:
32: $params['calendar']['values']['__all'] = _("All Visible");
33: foreach (Kronolith::listCalendars(Horde_Perms::SHOW, true) as $id => $cal) {
34: $params['calendar']['values'][$id] = $cal->name();
35: }
36:
37: return $params;
38: }
39:
40: 41:
42: protected function _title()
43: {
44: $title = _("All Calendars");
45: $url = Horde::url($GLOBALS['registry']->getInitialPage(), true);
46: if (isset($this->_params['calendar']) &&
47: $this->_params['calendar'] != '__all') {
48: $calendars = Kronolith::listCalendars();
49: if (isset($calendars[$this->_params['calendar']])) {
50: $title = htmlspecialchars($calendars[$this->_params['calendar']]->name());
51: } else {
52: $title = _("Calendar not found");
53: }
54: $url->add('display_cal', $this->_params['calendar']);
55: }
56: $date = new Horde_Date(time());
57:
58: return $title . ', ' . $url->link() . $date->strftime('%B, %Y') . '</a>';
59: }
60:
61: 62:
63: protected function _content()
64: {
65: global $prefs;
66:
67: if (isset($this->_params['calendar']) &&
68: $this->_params['calendar'] != '__all') {
69: $calendars = Kronolith::listCalendars();
70: if (!isset($calendars[$this->_params['calendar']])) {
71: return _("Calendar not found");
72: }
73: if (!$calendars[$this->_params['calendar']]->hasPermission(Horde_Perms::READ)) {
74: return _("Permission Denied");
75: }
76: }
77:
78: $year = date('Y');
79: $month = date('m');
80: $startday = new Horde_Date(array('mday' => 1,
81: 'month' => $month,
82: 'year' => $year));
83: $startday = $startday->dayOfWeek();
84: $daysInView = Date_Calc::weeksInMonth($month, $year) * 7;
85: if (!$prefs->getValue('week_start_monday')) {
86: $startOfView = 1 - $startday;
87:
88:
89:
90: if ($startday == Horde_Date::DATE_SUNDAY) {
91: $daysInView -= 7;
92: }
93: $endday = new Horde_Date(array('mday' => Horde_Date_Utils::daysInMonth($month, $year),
94: 'month' => $month,
95: 'year' => $year));
96: $endday = $endday->dayOfWeek();
97: if ($endday == Horde_Date::DATE_SUNDAY) {
98: $daysInView += 7;
99: }
100: } else {
101: if ($startday == Horde_Date::DATE_SUNDAY) {
102: $startOfView = -5;
103: } else {
104: $startOfView = 2 - $startday;
105: }
106: }
107:
108: $startDate = new Horde_Date(array('year' => $year, 'month' => $month, 'mday' => $startOfView));
109: $endDate = new Horde_Date(array('year' => $year, 'month' => $month, 'mday' => $startOfView + $daysInView,
110: 'hour' => 23, 'min' => 59, 'sec' => 59));
111:
112:
113: $html = '<table cellspacing="1" class="block-monthgrid" width="100%"><tr>';
114:
115:
116: $weekdays = array(_("Mo"), _("Tu"), _("We"), _("Th"), _("Fr"), _("Sa"));
117: if (!$prefs->getValue('week_start_monday')) {
118: array_unshift($weekdays, _("Su"));
119: } else {
120: $weekdays[] = _("Su");
121: }
122: foreach ($weekdays as $weekday) {
123: $html .= '<th class="item">' . $weekday . '</th>';
124: }
125:
126: try {
127: if (isset($this->_params['calendar']) &&
128: $this->_params['calendar'] != '__all') {
129: list($type, $calendar) = explode('_', $this->_params['calendar'], 2);
130: $driver = Kronolith::getDriver($type, $calendar);
131: $all_events = $driver->listEvents($startDate, $endDate, true);
132: } else {
133: $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']);
134: }
135: } catch (Exception $e) {
136: return '<em>' . $e->getMessage() . '</em>';
137: }
138:
139: $weeks = array();
140: $weekday = 0;
141: $week = -1;
142: for ($day = $startOfView; $day < $startOfView + $daysInView; ++$day) {
143: if ($weekday == 7) {
144: $weekday = 0;
145: }
146: if ($weekday == 0) {
147: ++$week;
148: $html .= '</tr><tr>';
149: }
150:
151: $date_ob = new Kronolith_Day($month, $day, $year);
152: if ($date_ob->isToday()) {
153: $td_class = 'today';
154: } elseif ($date_ob->month != $month) {
155: $td_class = 'othermonth';
156: } elseif ($date_ob->dayOfWeek() == 0 || $date_ob->dayOfWeek() == 6) {
157: $td_class = 'weekend';
158: } else {
159: $td_class = 'text';
160: }
161: $html .= '<td align="center" class="' . $td_class . '">';
162:
163:
164: $url = Horde::url('day.php', true)
165: ->add('date', $date_ob->dateString());
166: if (isset($this->_params['calendar']) &&
167: $this->_params['calendar'] != '__all') {
168: $url->add('display_cal', $this->_params['calendar']);
169: }
170:
171: $date_stamp = $date_ob->dateString();
172: if (empty($all_events[$date_stamp])) {
173:
174: $cell = Horde::linkTooltip($url, _("View Day")) . $date_ob->mday . '</a>';
175: } else {
176: 177:
178: $day_events = '';
179: foreach ($all_events[$date_stamp] as $event) {
180: if ($event->isAllDay()) {
181: $day_events .= _("All day");
182: } else {
183: $day_events .= $event->start->strftime($prefs->getValue('twentyFour') ? '%R' : '%I:%M%p') . '-' . $event->end->strftime($prefs->getValue('twentyFour') ? '%R' : '%I:%M%p');
184: }
185: $location = $event->getLocation();
186: $day_events .= ':'
187: . ($location ? ' (' . htmlspecialchars($location) . ')' : '')
188: . ' ' . $event->getTitle() . "\n";
189: }
190: $cell = Horde::linkTooltip($url, _("View Day"), '', '', '', $day_events) . $date_ob->mday . '</a>';
191: }
192:
193:
194: if (!empty($all_events[$date_stamp])) {
195: $cell = '<strong>' . $cell . '</strong>';
196: }
197:
198: $html .= $cell . '</td>';
199: ++$weekday;
200: }
201:
202: return $html . '</tr></table>';
203: }
204:
205: }
206: