/** */ protected function _content() { global $prefs; if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') { $calendars = Kronolith::listCalendars(); if (!isset($calendars[$this->_params['calendar']])) { return _("Calendar not found"); } if (!$calendars[$this->_params['calendar']]->hasPermission(Horde_Perms::READ)) { return _("Permission Denied"); } } $year = date('Y'); $month = date('m'); $startday = new Horde_Date(array('mday' => 1, 'month' => $month, 'year' => $year)); $startday = $startday->dayOfWeek(); if (!$prefs->getValue('week_start_monday')) { $startOfView = 1 - $startday; $endday = new Horde_Date(array('mday' => Horde_Date_Utils::daysInMonth($month, $year), 'month' => $month, 'year' => $year)); } else { if ($startday == Horde_Date::DATE_SUNDAY) { $startOfView = -5; } else { $startOfView = 2 - $startday; } } $startDate = new Horde_Date($year, $month, $startOfView); $endDate = new Horde_Date($year, $month, Horde_Date_Utils::daysInMonth($month, $year) + 1); $endDate->mday += (7 - ($endDate->format('w') - $prefs->getValue('week_start_monday'))) % 7; /* Table start. and current month indicator. */ $html = '<table cellspacing="1" class="monthgrid" width="100%"><tr>'; /* Set up the weekdays. */ $weekdays = array(_("Mo"), _("Tu"), _("We"), _("Th"), _("Fr"), _("Sa")); if (!$prefs->getValue('week_start_monday')) { array_unshift($weekdays, _("Su")); } else { $weekdays[] = _("Su"); } foreach ($weekdays as $weekday) { $html .= '<th class="item">' . $weekday . '</th>'; } try { if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') { list($type, $calendar) = explode('_', $this->_params['calendar'], 2); $driver = Kronolith::getDriver($type, $calendar); $all_events = $driver->listEvents($startDate, $endDate, array('show_recurrence' => true)); } else { $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS)); } } catch (Exception $e) { return '<em>' . $e->getMessage() . '</em>'; } $weekday = 0; $week = -1; $weekStart = $prefs->getValue('week_start_monday'); for ($date_ob = new Kronolith_Day($month, $startOfView, $year); $date_ob->compareDate($endDate) < 0; $date_ob->mday++) { if ($weekday == 7) { $weekday = 0; } if ($weekday == 0) { ++$week; $html .= '</tr><tr>'; } if ($date_ob->isToday()) { $td_class = 'kronolith-today'; } elseif ($date_ob->month != $month) { $td_class = 'kronolith-othermonth'; } elseif ($date_ob->dayOfWeek() == 0 || $date_ob->dayOfWeek() == 6) { $td_class = 'kronolith-weekend'; } else { $td_class = ''; } $html .= '<td align="center" class="' . $td_class . '">'; /* Set up the link to the day view. */ $url = Horde::url('day.php', true)->add('date', $date_ob->dateString()); if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') { $url->add('display_cal', $this->_params['calendar']); } $date_stamp = $date_ob->dateString(); if (empty($all_events[$date_stamp])) { /* No events, plain link to the day. */ $cell = Horde::linkTooltip($url, _("View Day")) . $date_ob->mday . '</a>'; } else { /* There are events; create a cell with tooltip to * list them. */ $day_events = ''; foreach ($all_events[$date_stamp] as $event) { if ($event->isAllDay()) { $day_events .= _("All day"); } else { $day_events .= $event->start->strftime($prefs->getValue('twentyFour') ? '%R' : '%I:%M%p') . '-' . $event->end->strftime($prefs->getValue('twentyFour') ? '%R' : '%I:%M%p'); } $location = $event->getLocation(); $day_events .= ':' . ($location ? ' (' . htmlspecialchars($location) . ')' : '') . ' ' . $event->getTitle() . "\n"; } $cell = Horde::linkTooltip($url, _("View Day"), '', '', '', $day_events) . $date_ob->mday . '</a>'; } /* Bold the cell if there are events. */ if (!empty($all_events[$date_stamp])) { $cell = '<strong>' . $cell . '</strong>'; } $html .= $cell . '</td>'; ++$weekday; } return $html . '</tr></table>'; }
public function html() { global $prefs; $sidebyside = $prefs->getValue('show_shared_side_by_side'); $twentyFour = $prefs->getValue('twentyFour'); $addLinks = Kronolith::getDefaultCalendar(Horde_Perms::EDIT) && ($GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') === true || $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') > Kronolith::countEvents()); if ($sidebyside) { require KRONOLITH_TEMPLATES . '/month/head_side_by_side.inc'; } else { require KRONOLITH_TEMPLATES . '/month/head.inc'; } $html = ''; if (!$sidebyside && count($this->_currentCalendars)) { $html .= '<tr>'; } $showLocation = Kronolith::viewShowLocation(); $showTime = Kronolith::viewShowTime(); $day_url = Horde::url('day.php'); $this_link = $this->link(0, true); $new_url = Horde::url('new.php')->add('url', $this_link); $new_img = Horde::img('new_small.png', '+'); $weekOffset = $prefs->getValue('week_start_monday') ? 0 : 1; $weekStart = $prefs->getValue('week_start_monday'); foreach ($this->_currentCalendars as $id => $cal) { if ($sidebyside) { $html .= '<tr>'; } $cell = 0; $date = new Kronolith_Day($this->month, $this->_startOfView, $this->year); $date->hour = $twentyFour ? 12 : 6; for (; $date->compareDate($this->_endDate) < 0; $date->mday++) { if ($cell % 7 == 0) { $week = $date->add(array('day' => $weekOffset))->weekOfYear(); $weeklink = Horde::url('week.php')->add('date', $date->dateString())->link(array('class' => 'kronolith-weeklink')) . ($sidebyside ? sprintf(_("Week %d"), $week) : $week) . '</a>'; if ($sidebyside) { $html .= sprintf('<td class="kronolith-first-col">%s<br />%s</td>', $weeklink, htmlspecialchars(Kronolith::getLabel($cal))); } else { if ($cell != 0) { $html .= "</tr>\n<tr>"; } $html .= '<td class="kronolith-first-col">' . $weeklink . '</td>'; } } if ($date->isToday()) { $style = ' class="kronolith-today"'; } elseif ($date->month != $this->month) { $style = ' class="kronolith-other-month"'; } elseif ($date->dayOfWeek() == 0 || $date->dayOfWeek() == 6) { $style = ' class="kronolith-weekend"'; } else { $style = ''; } $html .= '<td' . $style . '><div class="kronolith-day">'; $html .= $day_url->add('date', $date->dateString())->link() . $date->mday . '</a>'; if ($addLinks) { $new_url->add('date', $date->dateString()); if ($sidebyside) { $new_url->add('calendar', $id); } $html .= $new_url->link(array('title' => _("Create a New Event"), 'class' => 'newEvent')) . $new_img . '</a>'; } $html .= '</div>'; $date_stamp = $date->dateString(); if (!empty($this->_events[$date_stamp])) { foreach ($this->_events[$date_stamp] as $event) { if (!$sidebyside || $event->calendar == $id) { $html .= '<div class="kronolith-event"' . $event->getCSSColors() . '>'; if ($showTime && !$event->isAllDay()) { $html .= '<span class="kronolith-time">' . htmlspecialchars($event->getTimeRange()) . '</span>'; } $html .= $event->getLink($date, true, $this_link); if (!$event->isPrivate() && $showLocation) { $html .= '<span class="kronolith-location">' . htmlspecialchars($event->getLocation()) . '</span>'; } $html .= '</div>'; } } } $html .= "</td>\n"; ++$cell; } if ($sidebyside) { $html .= '</tr>'; } } if (!$sidebyside && count($this->_currentCalendars)) { $html .= '</tr>'; } echo $html . '</tbody></table>'; }