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