Author: Chuck Hagenbuch (chuck@horde.org)
Inheritance: extends Horde_Date
Exemplo n.º 1
0
 /**
  *
  * @param Horde_Date $date  The day for this view
  * @param array $events     An array of Kronolith_Event objects
  *
  * @return Kronolith_View_Day
  */
 public function __construct(Horde_Date $date, array $events = null)
 {
     parent::__construct($date->month, $date->mday, $date->year);
     $this->sidebyside = $GLOBALS['prefs']->getValue('show_shared_side_by_side');
     if ($this->sidebyside) {
         $allCalendars = Kronolith::listInternalCalendars();
         foreach ($GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS) as $cid) {
             $this->_currentCalendars[$cid] = $allCalendars[$cid];
             $this->all_day_events[$cid] = array();
         }
     } else {
         $this->_currentCalendars = array(0);
     }
     if ($events === null) {
         try {
             $events = Kronolith::listEvents($this, new Horde_Date(array('year' => $this->year, 'month' => $this->month, 'mday' => $this->mday)));
             $this->events = array_shift($events);
         } catch (Exception $e) {
             $GLOBALS['notification']->push($e, 'horde.error');
             $this->events = array();
         }
     } else {
         $this->events = $events;
     }
     if (!is_array($this->events)) {
         $this->events = array();
     }
 }
Exemplo n.º 2
0
 /**
  */
 protected function _content()
 {
     $GLOBALS['page_output']->addScriptFile('tooltips.js', 'horde');
     $now = new Horde_Date($_SERVER['REQUEST_TIME']);
     $today = date('j');
     $startDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j')));
     $endDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j') + $this->_params['days']));
     try {
         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");
             }
             list($type, $calendar) = explode('_', $this->_params['calendar'], 2);
             $driver = Kronolith::getDriver($type, $calendar);
             $all_events = Kronolith::sortEvents($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>';
     }
     $html = '';
     $iMax = $today + $this->_params['days'];
     $firstday = true;
     $totalevents = 0;
     for ($i = $today; $i < $iMax; ++$i) {
         $day = new Kronolith_Day(date('n'), $i);
         $date_stamp = $day->dateString();
         if (empty($all_events[$date_stamp])) {
             continue;
         }
         $firstevent = true;
         $tomorrow = $day->getTomorrow();
         foreach ($all_events[$date_stamp] as $event) {
             if (!empty($this->_params['maxevents']) && $totalevents >= $this->_params['maxevents']) {
                 break 2;
             }
             if ($event->start->compareDate($day) < 0) {
                 $event->start = $day;
             }
             if ($event->end->compareDate($tomorrow) >= 0) {
                 $event->end = $tomorrow;
             }
             if ($event->end->compareDateTime($now) < 0) {
                 continue;
             }
             if (!empty($this->_params['alarms']) && !$event->alarm) {
                 continue;
             }
             $event_active = $event->start->compareDateTime($now) < 0 && $event->end->compareDateTime($now) > 0;
             if ($firstevent) {
                 $html .= '<tr><td colspan="3" class="control"><strong>';
                 if ($day->isToday()) {
                     $dayname = _("Today");
                 } elseif ($day->isTomorrow()) {
                     $dayname = _("Tomorrow");
                 } elseif ($day->diff() < 7) {
                     $dayname = $day->strftime('%A');
                 } else {
                     $dayname = $day->strftime($GLOBALS['prefs']->getValue('date_format'));
                 }
                 $url = Horde::url('day.php', true)->setRaw(false)->add('date', $day->dateString());
                 if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
                     $url->add('display_cal', $this->_params['calendar']);
                 }
                 $html .= $url->link(array('title' => sprintf(_("Goto %s"), $dayname))) . $dayname . '</a></strong></td></tr>';
                 $firstevent = false;
                 $firstday = false;
             }
             $html .= '<tr class="linedRow"><td class="text nowrap" valign="top">';
             if ($event_active) {
                 $html .= '<strong>';
             }
             if ($event->isAllDay()) {
                 $time = _("All day");
             } else {
                 $time = $event->start->format($GLOBALS['prefs']->getValue('twentyFour') ? 'H:i' : 'h:ia') . '-' . $event->end->format($GLOBALS['prefs']->getValue('twentyFour') ? 'H:i' : 'h:ia');
             }
             $html .= $time;
             if ($event_active) {
                 $html .= '</strong>';
             }
             $html .= '&nbsp;</td>';
             $html .= '<td class="text" valign="top"' . $event->getCSSColors() . '>';
             if ($event_active) {
                 $html .= '<strong>';
             }
             $html .= ' ' . $event->getLink(null, true, null, true, true);
             if ($event_active) {
                 $html .= '</strong>';
             }
             $html .= '</td></tr>';
             $totalevents++;
         }
     }
     if (empty($html)) {
         return '<em>' . _("No events to display") . '</em>';
     }
     return '<table cellspacing="0" width="100%">' . $html . '</table>';
 }
Exemplo n.º 3
0
Arquivo: Day.php Projeto: horde/horde
 public function diff($other = null)
 {
     $other = new Kronolith_Day();
     return abs($this->toDays() - $other->toDays());
 }
Exemplo n.º 4
0
 /**
  */
 protected function _content()
 {
     global $page_output;
     $page_output->addScriptFile('tooltips.js', 'horde');
     $now = new Horde_Date($_SERVER['REQUEST_TIME']);
     $today = date('j');
     $current_month = '';
     $startDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j')));
     $endDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n') + $this->_params['months'], 'mday' => date('j') - 1));
     try {
         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");
             }
             list($type, $calendar) = explode('_', $this->_params['calendar'], 2);
             $driver = Kronolith::getDriver($type, $calendar);
             $all_events = $driver->listEvents($startDate, $endDate, array('show_recurrence' => true, 'has_alarm' => !empty($this->_params['alarms']), 'cover_dates' => false));
         } else {
             $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS), array('has_alarm' => !empty($this->_params['alarms']), 'cover_dates' => false));
         }
     } catch (Exception $e) {
         return '<em>' . $e->getMessage() . '</em>';
     }
     /* How many days do we need to check. */
     $days = Date_Calc::dateDiff($startDate->mday, $startDate->month, $startDate->year, $endDate->mday, $endDate->month, $endDate->year);
     /* Loop through the days. */
     $totalevents = 0;
     $html = '';
     for ($i = 0; $i < $days; ++$i) {
         $day = new Kronolith_Day($startDate->month, $today + $i);
         $date_stamp = $day->dateString();
         if (empty($all_events[$date_stamp])) {
             continue;
         }
         if (!empty($this->_params['maxevents']) && $totalevents >= $this->_params['maxevents']) {
             break;
         }
         /* Output month header. */
         if ($current_month != $day->month) {
             $html .= '<tr><td colspan="4" class="control"><strong>' . $day->strftime('%B') . '</strong></td></tr>';
         }
         $firstevent = true;
         $tomorrow = $day->getTomorrow();
         foreach ($all_events[$date_stamp] as $event) {
             $isMultiDay = false;
             if ($event->start->compareDate($day) < 0) {
                 $event->start = new Horde_Date($day);
             }
             if ($event->end->compareDate($tomorrow) >= 1) {
                 $isMultiDay = true;
             }
             if ($event->end->compareDate($now) < 0 && !$event->isAllDay() || !empty($this->_params['alarms']) && !$event->alarm) {
                 continue;
             }
             if ($firstevent || $isMultiDay) {
                 $html .= '<tr';
                 if ($current_month == $day->month) {
                     $html .= ' class="upcomingday"';
                 }
                 $html .= '><td class="text" valign="top" align="right"><strong>';
                 if ($day->isToday()) {
                     $html .= _("Today");
                 } elseif ($day->isTomorrow()) {
                     $html .= _("Tomorrow");
                 } else {
                     $html .= $day->mday;
                 }
                 if ($isMultiDay) {
                     $endDay = new Kronolith_Day($event->end->month, $event->end->mday);
                     $html .= ' - ';
                     if ($endDay->isTomorrow()) {
                         $html .= _("Tomorrow");
                     } else {
                         $html .= $event->end->mday;
                     }
                 }
                 $html .= '</strong>&nbsp;</td>';
                 $firstevent = $isMultiDay;
             } else {
                 $html .= '<tr><td class="text">&nbsp;</td>';
             }
             $html .= '<td class="text" nowrap="nowrap" valign="top">';
             if ($event->start->compareDate($now) < 0 && $event->end->compareDate($now) > 0) {
                 $html .= '<strong>' . htmlspecialchars($event->getLocation()) . '</strong>';
             } else {
                 $html .= htmlspecialchars($event->getLocation());
             }
             if ($event->start->compareDate($now) < 0 && $event->end->compareDate($now) > 0) {
                 $html .= '<strong>';
             }
             $html .= $event->getLink(null, true, null, true);
             if ($event->start->compareDate($now) < 0 && $event->end->compareDate($now) > 0) {
                 $html .= '</strong>';
             }
             $html .= '</td></tr>';
             $totalevents++;
         }
         $current_month = $day->strftime('%m');
     }
     if (empty($html)) {
         return '<em>' . _("No events to display") . '</em>';
     }
     return '<table cellspacing="0" width="100%">' . $html . '</table>';
 }
Exemplo n.º 5
0
 /**
  */
 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>';
 }
Exemplo n.º 6
0
 public function html()
 {
     global $prefs;
     $html = '<table id="kronolith-view-year" class="kronolith-minical"><tr>';
     for ($month = 1; $month <= 12; ++$month) {
         $html .= '<td>';
         // Heading for each month.
         $date = new Horde_Date(sprintf('%04d%02d01010101', $this->year, $month));
         $html .= '<table><thead><tr class="kronolith-minical-nav"><th colspan="7">' . Horde::url('month.php')->add('date', $date->dateString())->link() . $date->strftime('%B') . '</a></th></tr><tr><th class="kronolith-minical-empty">&nbsp;</th>';
         if (!$prefs->getValue('week_start_monday')) {
             $html .= '<th>' . _("Su") . '</th>';
         }
         $html .= '<th>' . _("Mo") . '</th>' . '<th>' . _("Tu") . '</th>' . '<th>' . _("We") . '</th>' . '<th>' . _("Th") . '</th>' . '<th>' . _("Fr") . '</th>' . '<th>' . _("Sa") . '</th>';
         if ($prefs->getValue('week_start_monday')) {
             $html .= '<th>' . _("Su") . '</th>';
         }
         $html .= '</tr></thead><tbody><tr><td class="kronolith-minical-week">';
         $startday = new Horde_Date(array('mday' => 1, 'month' => $month, 'year' => $this->year));
         $startday = $startday->dayOfWeek();
         $daysInView = Date_Calc::weeksInMonth($month, $this->year) * 7;
         if (!$prefs->getValue('week_start_monday')) {
             $startOfView = 1 - $startday;
             // We may need to adjust the number of days in the
             // view if we're starting weeks on Sunday.
             if ($startday == Horde_Date::DATE_SUNDAY) {
                 $daysInView -= 7;
             }
             $endday = new Horde_Date(array('mday' => Horde_Date_Utils::daysInMonth($month, $this->year), 'month' => $month, 'year' => $this->year));
             $endday = $endday->dayOfWeek();
             if ($endday == Horde_Date::DATE_SUNDAY) {
                 $daysInView += 7;
             }
         } else {
             if ($startday == Horde_Date::DATE_SUNDAY) {
                 $startOfView = -5;
             } else {
                 $startOfView = 2 - $startday;
             }
         }
         $currentCalendars = array(true);
         foreach ($currentCalendars as $id => $cal) {
             $cell = 0;
             for ($day = $startOfView; $day < $startOfView + $daysInView; ++$day) {
                 $date = new Kronolith_Day($month, $day, $this->year);
                 $date->hour = $prefs->getValue('twentyFour') ? 12 : 6;
                 $week = $date->weekOfYear();
                 if ($cell % 7 == 0) {
                     if ($cell != 0) {
                         $html .= "</tr>\n<tr><td class=\"kronolith-minical-week\">";
                     }
                     $html .= (int) $date->weekOfYear() . '</td>';
                 }
                 if ($date->month != $month) {
                     $style = 'kronolith-other-month';
                 } else {
                     $style = '';
                 }
                 /* Set up the link to the day view. */
                 $url = Horde::url('day.php', true)->add('date', $date->dateString());
                 if ($date->month == $month && !empty($this->_events[$date->dateString()])) {
                     /* There are events; create a cell with tooltip to list
                      * them. */
                     $day_events = '';
                     foreach ($this->_events[$date->dateString()] as $event) {
                         if ($event->status == Kronolith::STATUS_CONFIRMED) {
                             /* Set the background color to distinguish the
                              * day */
                             $style = 'year-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');
                         }
                         $day_events .= ':' . ($event->getLocation() ? ' (' . $event->getLocation() . ')' : '') . ' ' . $event->getTitle() . "\n";
                     }
                     /* Bold the cell if there are events. */
                     $cellday = '<strong>' . Horde::linkTooltip($url, _("View Day"), '', '', '', $day_events) . $date->mday . '</a></strong>';
                 } else {
                     /* No events, plain link to the day. */
                     $cellday = Horde::linkTooltip($url, _("View Day")) . $date->mday . '</a>';
                 }
                 if ($date->isToday() && $date->month == $month) {
                     $style .= ' kronolith-today';
                 }
                 $html .= '<td align="center" class="' . $style . '" height="10" width="5%" valign="top">' . $cellday . '</td>';
                 ++$cell;
             }
         }
         $html .= '</tr></tbody></table></td>';
         if ($month % 3 == 0 && $month != 12) {
             $html .= '</tr><tr>';
         }
     }
     echo $html . '</tr></table>';
 }
Exemplo n.º 7
0
 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', '+');
     foreach ($this->_currentCalendars as $id => $cal) {
         if ($sidebyside) {
             $html .= '<tr>';
         }
         $cell = 0;
         for ($day = $this->_startOfView; $day < $this->_startOfView + $this->_daysInView; ++$day) {
             $date = new Kronolith_Day($this->month, $day, $this->year);
             $date->hour = $twentyFour ? 12 : 6;
             $week = $date->weekOfYear();
             if ($cell % 7 == 0) {
                 $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>';
 }