1: <?php
2: 3: 4:
5: class Kronolith_Block_Monthlist extends Horde_Core_Block
6: {
7: 8:
9: public function __construct($app, $params = array())
10: {
11: parent::__construct($app, $params);
12:
13: $this->_name = _("Upcoming Events");
14: }
15:
16: 17:
18: protected function _params()
19: {
20: $params = array(
21: 'calendar' => array(
22: 'name' => _("Calendar"),
23: 'type' => 'enum',
24: 'default' => '__all'),
25: 'months' => array(
26: 'name' => _("Months Ahead"),
27: 'type' => 'int',
28: 'default' => 2),
29: 'maxevents' => array(
30: 'name' => _("Maximum number of events to display (0 = no limit)"),
31: 'type' => 'int',
32: 'default' => 0),
33: 'alarms' => array(
34: 'name' => _("Show only events that have an alarm set?"),
35: 'type' => 'checkbox',
36: 'default' => 0
37: )
38: );
39:
40: $params['calendar']['values']['__all'] = _("All Visible");
41: foreach (Kronolith::listCalendars(Horde_Perms::SHOW, true) as $id => $cal) {
42: $params['calendar']['values'][$id] = $cal->name();
43: }
44:
45: return $params;
46: }
47:
48: 49:
50: protected function _title()
51: {
52: $url = Horde::url($GLOBALS['registry']->getInitialPage(), true);
53: if (isset($this->_params['calendar']) &&
54: $this->_params['calendar'] != '__all') {
55: $url->add('display_cal', $this->_params['calendar']);
56: }
57: return $url->link() . _("Upcoming Events") . '</a>';
58: }
59:
60: 61:
62: protected function _content()
63: {
64: global $registry, $prefs;
65:
66: Horde::addScriptFile('tooltips.js', 'horde');
67:
68: $now = new Horde_Date($_SERVER['REQUEST_TIME']);
69: $today = date('j');
70: $current_month = '';
71:
72: $startDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j')));
73: $endDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n') + $this->_params['months'], 'mday' => date('j') - 1));
74:
75: try {
76: if (isset($this->_params['calendar']) &&
77: $this->_params['calendar'] != '__all') {
78: $calendars = Kronolith::listCalendars();
79: if (!isset($calendars[$this->_params['calendar']])) {
80: return _("Calendar not found");
81: }
82: if (!$calendars[$this->_params['calendar']]->hasPermission(Horde_Perms::READ)) {
83: return _("Permission Denied");
84: }
85: list($type, $calendar) = explode('_', $this->_params['calendar'], 2);
86: $driver = Kronolith::getDriver($type, $calendar);
87: $all_events = $driver->listEvents($startDate, $endDate, true);
88: } else {
89: $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']);
90: }
91: } catch (Exception $e) {
92: return '<em>' . $e->getMessage() . '</em>';
93: }
94:
95:
96: $days = Date_Calc::dateDiff($startDate->mday, $startDate->month, $startDate->year,
97: $endDate->mday, $endDate->month, $endDate->year);
98:
99:
100: $totalevents = 0;
101:
102: $html = '';
103: for ($i = 0; $i < $days; ++$i) {
104: $day = new Kronolith_Day($startDate->month, $today + $i);
105: $date_stamp = $day->dateString();
106: if (empty($all_events[$date_stamp])) {
107: continue;
108: }
109:
110: if (!empty($this->_params['maxevents']) &&
111: $totalevents >= $this->_params['maxevents']) {
112: break;
113: }
114:
115:
116: if ($current_month != $day->month) {
117: $html .= '<tr><td colspan="4" class="control"><strong>' . $day->strftime('%B') . '</strong></td></tr>';
118: }
119:
120: $firstevent = true;
121: $tomorrow = $day->getTomorrow();
122: foreach ($all_events[$date_stamp] as $event) {
123: if ($event->start->compareDate($day) < 0) {
124: $event->start = new Horde_Date($day);
125: }
126: if ($event->end->compareDate($tomorrow) >= 0) {
127: $event->end = $tomorrow;
128: }
129: if (($event->end->compareDate($now) < 0 && !$event->isAllDay()) ||
130: (!empty($this->_params['alarms']) && !$event->alarm)) {
131: continue;
132: }
133:
134: if ($firstevent) {
135: $html .= '<tr';
136: if ($current_month == $day->month) {
137: $html .= ' class="block-upcomingday"';
138: }
139: $html .= '><td class="text" valign="top" align="right"><strong>';
140: if ($day->isToday()) {
141: $html .= _("Today");
142: } elseif ($day->isTomorrow()) {
143: $html .= _("Tomorrow");
144: } else {
145: $html .= $day->mday;
146: }
147: $html .= '</strong> </td>';
148: $firstevent = false;
149: } else {
150: $html .= '<tr><td class="text"> </td>';
151: }
152:
153: $html .= '<td class="text" nowrap="nowrap" valign="top">';
154: if ($event->start->compareDate($now) < 0 &&
155: $event->end->compareDate($now) > 0) {
156: $html .= '<strong>' . htmlspecialchars($event->getLocation()) . '</strong>';
157: } else {
158: $html .= htmlspecialchars($event->getLocation());
159: }
160: if ($event->start->compareDate($now) < 0 &&
161: $event->end->compareDate($now) > 0) {
162: $html .= '<strong>';
163: }
164: $html .= $event->getLink(null, true, null, true);
165: if ($event->start->compareDate($now) < 0 &&
166: $event->end->compareDate($now) > 0) {
167: $html .= '</strong>';
168: }
169: $html .= '</td></tr>';
170:
171: $totalevents++;
172: }
173:
174: $current_month = $day->strftime('%m');
175: }
176:
177: if (empty($html)) {
178: return '<em>' . _("No events to display") . '</em>';
179: }
180:
181: return '<table cellspacing="0" width="100%">' . $html . '</table>';
182: }
183:
184: }
185: