1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10: class Kronolith_View_Month
11: {
12: 13: 14:
15: public $month;
16:
17: 18: 19:
20: public $year;
21:
22: 23: 24:
25: public $date;
26:
27: 28: 29:
30: protected $_events = array();
31:
32: 33: 34:
35: protected $_currentCalendars = array();
36:
37: 38: 39:
40: protected $_daysInView;
41:
42: 43: 44:
45: protected $_startOfView;
46:
47: 48: 49:
50: protected $_startday;
51:
52: 53: 54: 55: 56: 57: 58:
59: public function __construct(Horde_Date $date)
60: {
61: global $prefs;
62:
63: $this->month = $date->month;
64: $this->year = $date->year;
65:
66:
67: $this->date = new Horde_Date($date);
68: $this->date->mday = 1;
69: $this->_startday = $this->date->dayOfWeek();
70: $this->_daysInView = Date_Calc::weeksInMonth($this->month, $this->year) * 7;
71: if (!$prefs->getValue('week_start_monday')) {
72: $this->_startOfView = 1 - $this->_startday;
73:
74:
75:
76: if ($this->_startday == Horde_Date::DATE_SUNDAY) {
77: $this->_daysInView -= 7;
78: }
79: $endday = new Horde_Date(array('mday' => Horde_Date_Utils::daysInMonth($this->month, $this->year),
80: 'month' => $this->month,
81: 'year' => $this->year));
82: $endday = $endday->dayOfWeek();
83: if ($endday == Horde_Date::DATE_SUNDAY) {
84: $this->_daysInView += 7;
85: }
86: } else {
87: if ($this->_startday == Horde_Date::DATE_SUNDAY) {
88: $this->_startOfView = -5;
89: } else {
90: $this->_startOfView = 2 - $this->_startday;
91: }
92: }
93:
94: $startDate = new Horde_Date(array('year' => $this->year,
95: 'month' => $this->month,
96: 'mday' => $this->_startOfView));
97: $endDate = new Horde_Date(array('year' => $this->year,
98: 'month' => $this->month,
99: 'mday' => $this->_startOfView + $this->_daysInView));
100:
101: if ($prefs->getValue('show_shared_side_by_side')) {
102: $allCalendars = Kronolith::listInternalCalendars();
103: $this->_currentCalendars = array();
104: foreach ($GLOBALS['display_calendars'] as $id) {
105: $this->_currentCalendars[$id] = $allCalendars[$id];
106: }
107: } else {
108: $this->_currentCalendars = array('internal_0' => true);
109: }
110:
111: try {
112: $this->_events = Kronolith::listEvents($startDate, $endDate);
113: } catch (Exception $e) {
114: $GLOBALS['notification']->push($e, 'horde.error');
115: $this->_events = array();
116: }
117: if (!is_array($this->_events)) {
118: $this->_events = array();
119: }
120: }
121:
122: public function html()
123: {
124: global $prefs;
125:
126: $sidebyside = $prefs->getValue('show_shared_side_by_side');
127: $twentyFour = $prefs->getValue('twentyFour');
128: $addLinks = Kronolith::getDefaultCalendar(Horde_Perms::EDIT) &&
129: ($GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') === true ||
130: $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') > Kronolith::countEvents());
131:
132: if ($sidebyside) {
133: require KRONOLITH_TEMPLATES . '/month/head_side_by_side.inc';
134: } else {
135: require KRONOLITH_TEMPLATES . '/month/head.inc';
136: }
137:
138: $html = '';
139: if (!$sidebyside && count($this->_currentCalendars)) {
140: $html .= '<tr>';
141: }
142:
143: $showLocation = Kronolith::viewShowLocation();
144: $showTime = Kronolith::viewShowTime();
145: $day_url = Horde::url('day.php');
146: $this_link = $this->link(0, true);
147: $new_url = Horde::url('new.php')->add('url', $this_link);
148: $new_img = Horde::img('new_small.png', '+');
149:
150: foreach ($this->_currentCalendars as $id => $cal) {
151: if ($sidebyside) {
152: $html .= '<tr>';
153: }
154:
155: $cell = 0;
156: for ($day = $this->_startOfView; $day < $this->_startOfView + $this->_daysInView; ++$day) {
157: $date = new Kronolith_Day($this->month, $day, $this->year);
158: $date->hour = $twentyFour ? 12 : 6;
159: $week = $date->weekOfYear();
160:
161: if ($cell % 7 == 0 && $cell != 0) {
162: if ($sidebyside) {
163: $html .= '<td>' . htmlspecialchars($cal->get('name')) . '</td>';
164: } else {
165: $html .= "</tr>\n<tr>";
166: }
167: }
168: if ($date->isToday()) {
169: $style = 'today';
170: } elseif ($date->month != $this->month) {
171: $style = 'othermonth';
172: } elseif ($date->dayOfWeek() == 0 || $date->dayOfWeek() == 6) {
173: $style = 'weekend';
174: } else {
175: $style = 'text';
176: }
177:
178: $html .= '<td class="' . $style . '" height="70" width="14%" valign="top"><div>';
179:
180: $html .= $day_url->add('date', $date->dateString())
181: ->link(array('class' => 'day'))
182: . $date->mday . '</a>';
183:
184: if ($addLinks) {
185: $new_url->add('date', $date->dateString());
186: if ($sidebyside) {
187: $new_url->add('calendar', $id);
188: }
189: $html .= $new_url->link(array('title' => _("Create a New Event"), 'class' => 'newEvent'))
190: . $new_img . '</a>';
191: }
192:
193: if ($date->dayOfWeek() == Horde_Date::DATE_MONDAY) {
194: $html .= Horde::url('week.php')
195: ->add('date', $date->dateString())
196: ->link(array('class' => 'week'))
197: . sprintf(_("Week %d"), $week) . '</a>';
198: }
199:
200: $html .= '</div><div class="clear"> </div>';
201:
202: $date_stamp = $date->dateString();
203: if (!empty($this->_events[$date_stamp])) {
204: foreach ($this->_events[$date_stamp] as $event) {
205: if (!$sidebyside || $event->calendar == $id) {
206: $html .= '<div class="month-eventbox"' . $event->getCSSColors() . '>'
207: . $event->getLink($date, true, $this_link);
208: if ($showTime) {
209: $html .= '<div class="event-time">' . htmlspecialchars($event->getTimeRange()) . '</div>';
210: }
211: if (!$event->isPrivate() && $showLocation) {
212: $html .= '<div class="event-location">' . htmlspecialchars($event->getLocation()) . '</div>';
213: }
214: $html .= '</div>';
215: }
216: }
217: }
218:
219: $html .= "</td>\n";
220: ++$cell;
221: }
222:
223: if ($sidebyside) {
224: $html .= '</tr>';
225: }
226: }
227: if (!$sidebyside && count($this->_currentCalendars)) {
228: $html .= '</tr>';
229: }
230:
231: echo $html . '</tbody></table>';
232: }
233:
234: public function getMonth($offset = 0)
235: {
236: $month = new Horde_Date($this->date);
237: $month->month += $offset;
238: return $month;
239: }
240:
241: public function link($offset = 0, $full = false)
242: {
243: $month = $this->getMonth($offset);
244: return Horde::url('month.php', $full)
245: ->add('date', $month->dateString());
246: }
247:
248: public function getName()
249: {
250: return 'Month';
251: }
252:
253: }
254: