Пример #1
0
 protected function _render(Horde_Date $day = null)
 {
     $this->_start = new Horde_Date($day);
     $this->_start->mday = 1;
     $this->_days = Horde_Date_Utils::daysInMonth($day->month, $day->year);
     $this->_end = new Horde_Date($this->_start);
     $this->_end->hour = 23;
     $this->_end->min = $this->_end->sec = 59;
     $this->_end->mday = $this->_days;
 }
Пример #2
0
 /**
  *
  * @global Horde_Prefs $prefs
  * @param Horde_Date $date
  *
  * @return Kronolith_View_Month
  */
 public function __construct(Horde_Date $date)
 {
     global $prefs;
     $this->month = $date->month;
     $this->year = $date->year;
     // Need to calculate the start and length of the view.
     $this->date = new Horde_Date($date);
     $this->date->mday = 1;
     $this->_startday = $this->date->dayOfWeek();
     $this->_daysInView = Date_Calc::weeksInMonth($this->month, $this->year) * 7;
     if (!$prefs->getValue('week_start_monday')) {
         $this->_startOfView = 1 - $this->_startday;
         // We may need to adjust the number of days in the view if
         // we're starting weeks on Sunday.
         if ($this->_startday == Horde_Date::DATE_SUNDAY) {
             $this->_daysInView -= 7;
         }
         $endday = new Horde_Date(array('mday' => Horde_Date_Utils::daysInMonth($this->month, $this->year), 'month' => $this->month, 'year' => $this->year));
         $endday = $endday->dayOfWeek();
         if ($endday == Horde_Date::DATE_SUNDAY) {
             $this->_daysInView += 7;
         }
     } else {
         if ($this->_startday == Horde_Date::DATE_SUNDAY) {
             $this->_startOfView = -5;
         } else {
             $this->_startOfView = 2 - $this->_startday;
         }
     }
     $startDate = new Horde_Date(array('year' => $this->year, 'month' => $this->month, 'mday' => $this->_startOfView));
     $endDate = new Horde_Date(array('year' => $this->year, 'month' => $this->month, 'mday' => $this->_startOfView + $this->_daysInView));
     if ($prefs->getValue('show_shared_side_by_side')) {
         $allCalendars = Kronolith::listInternalCalendars();
         $this->_currentCalendars = array();
         foreach ($GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS) as $id) {
             $this->_currentCalendars[$id] = $allCalendars[$id];
         }
     } else {
         $this->_currentCalendars = array('internal_0' => true);
     }
     try {
         $this->_events = Kronolith::listEvents($startDate, $endDate);
     } catch (Exception $e) {
         $GLOBALS['notification']->push($e, 'horde.error');
         $this->_events = array();
     }
     if (!is_array($this->_events)) {
         $this->_events = array();
     }
 }
Пример #3
0
 /**
  *
  * @global Horde_Prefs $prefs
  * @param Horde_Date $date
  *
  * @return Kronolith_View_Month
  */
 public function __construct(Horde_Date $date)
 {
     global $prefs;
     $this->month = $date->month;
     $this->year = $date->year;
     // Need to calculate the start and length of the view.
     $this->date = new Horde_Date($date);
     $this->date->mday = 1;
     $this->_startday = $this->date->dayOfWeek();
     if (!$prefs->getValue('week_start_monday')) {
         $this->_startOfView = 1 - $this->_startday;
     } else {
         if ($this->_startday == Horde_Date::DATE_SUNDAY) {
             $this->_startOfView = -5;
         } else {
             $this->_startOfView = 2 - $this->_startday;
         }
     }
     $startDate = new Horde_Date($this->year, $this->month, $this->_startOfView);
     $this->_endDate = new Horde_Date($this->year, $this->month, Horde_Date_Utils::daysInMonth($this->month, $this->year) + 1);
     $this->_endDate->mday += (7 - ($this->_endDate->format('w') - $prefs->getValue('week_start_monday'))) % 7;
     if ($prefs->getValue('show_shared_side_by_side')) {
         $allCalendars = Kronolith::listInternalCalendars();
         $this->_currentCalendars = array();
         foreach ($GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS) as $id) {
             $this->_currentCalendars[$id] = $allCalendars[$id];
         }
     } else {
         $this->_currentCalendars = array('internal_0' => true);
     }
     try {
         $this->_events = Kronolith::listEvents($startDate, $this->_endDate);
     } catch (Exception $e) {
         $GLOBALS['notification']->push($e, 'horde.error');
         $this->_events = array();
     }
     if (!is_array($this->_events)) {
         $this->_events = array();
     }
 }
Пример #4
0
 public function __construct($title, &$vars)
 {
     parent::__construct($vars, $title);
     // FIXME: Generate a list of clients from Turba?
     //$clients =
     $now = time();
     if (!$vars->exists('startdate')) {
         // Default to the beginning of the previous calendar month
         $startdate = array('day' => 1, 'month' => date('n', $now), 'year' => date('Y', $now), 'hour' => 0, 'minute' => 0, 'second' => 0);
         $vars->set('startdate', $startdate);
     }
     if (!$vars->exists('enddate')) {
         // Default to the end of the previous calendar month
         $month = date('n', $now);
         $year = date('Y', $now);
         $lastday = Horde_Date_Utils::daysInMonth($month, $year);
         $enddate = array('day' => $lastday, 'month' => $month, 'year' => $year, 'hour' => 23, 'minute' => 59, 'second' => 59);
         $vars->set('enddate', $enddate);
     }
     try {
         $accountcodes = Operator::getAccountCodes(true);
     } catch (Exception $e) {
         $GLOBALS['notification']->push($e);
         $accountcodes = array();
     }
     // Parameters for Horde_Form_datetime
     $start_year = date('Y', $now) - 5;
     $end_year = '';
     $picker = true;
     $format_in = null;
     $format_out = '%x';
     $show_seconds = true;
     $params = array($start_year, $end_year, $picker, $format_in, $format_out, $show_seconds);
     $this->addVariable(_("Account Code"), 'accountcode', 'enum', false, false, null, array($accountcodes));
     $this->addVariable(_("Destination Context"), 'dcontext', 'text', false, false, _("An empty destination context will match all destination contexts."));
     $this->addVariable(_("Start Date & Time"), 'startdate', 'datetime', true, false, null, $params);
     $this->addVariable(_("End Date & Time"), 'enddate', 'datetime', true, false, null, $params);
 }
Пример #5
0
 /**
  * Corrects any over- or underflows in any of the date's members.
  *
  * @param integer $mask  We may not want to correct some overflows.
  * @param integer $down  Whether to correct the date up or down.
  */
 protected function _correct($mask = self::MASK_ALLPARTS, $down = false)
 {
     if ($mask & self::MASK_SECOND) {
         if ($this->_sec < 0 || $this->_sec > 59) {
             $mask |= self::MASK_MINUTE;
             $this->_min += (int) ($this->_sec / 60);
             $this->_sec %= 60;
             if ($this->_sec < 0) {
                 $this->_min--;
                 $this->_sec += 60;
             }
         }
     }
     if ($mask & self::MASK_MINUTE) {
         if ($this->_min < 0 || $this->_min > 59) {
             $mask |= self::MASK_HOUR;
             $this->_hour += (int) ($this->_min / 60);
             $this->_min %= 60;
             if ($this->_min < 0) {
                 $this->_hour--;
                 $this->_min += 60;
             }
         }
     }
     if ($mask & self::MASK_HOUR) {
         if ($this->_hour < 0 || $this->_hour > 23) {
             $mask |= self::MASK_DAY;
             $this->_mday += (int) ($this->_hour / 24);
             $this->_hour %= 24;
             if ($this->_hour < 0) {
                 $this->_mday--;
                 $this->_hour += 24;
             }
         }
     }
     if ($mask & self::MASK_MONTH) {
         $this->_correctMonth();
         /* When correcting the month, always correct the day too. Months
          * have different numbers of days. */
         if (isset($this->_mday)) {
             $mask |= self::MASK_DAY;
         }
     }
     if ($mask & self::MASK_DAY) {
         while ($this->_mday > 366 + 31) {
             if (Horde_Date_Utils::isLeapYear($this->_year) && $this->_month <= 2 || Horde_Date_Utils::isLeapYear($this->_year + 1) && $this->_month > 2) {
                 $this->_mday -= 366;
             } else {
                 $this->_mday -= 365;
             }
             $this->_year++;
         }
         while ($this->_mday > 28 && $this->_mday > Horde_Date_Utils::daysInMonth($this->_month, $this->_year)) {
             if ($down) {
                 $this->_mday -= Horde_Date_Utils::daysInMonth($this->_month + 1, $this->_year) - Horde_Date_Utils::daysInMonth($this->_month, $this->_year);
             } else {
                 $this->_mday -= Horde_Date_Utils::daysInMonth($this->_month, $this->_year);
                 $this->_month++;
             }
             $this->_correctMonth();
         }
         while ($this->_mday < 1) {
             --$this->_month;
             $this->_correctMonth();
             $this->_mday += Horde_Date_Utils::daysInMonth($this->_month, $this->_year);
         }
     }
 }
Пример #6
0
 /**
  * Adds rules from this ruleset to a VTIMEZONE component.
  *
  * @param Horde_Icalendar_Vtimezone $tz  A VTIMEZONE component.
  * @param string $tzid                   The timezone ID of the component.
  * @param string $name                   A timezone name abbreviation.
  *                                       May contain a placeholder that is
  *                                       replaced the Rules' "Letter(s)"
  *                                       entry.
  * @param array $startOffset             An offset hash describing the
  *                                       base offset of a timezone.
  * @param Horde_Date $start              Start of the period to add rules
  *                                       for.
  * @param Horde_Date $end                End of the period to add rules
  *                                       for.
  */
 public function addRules(Horde_Icalendar_Vtimezone $tz, $tzid, $name, $startOffset, Horde_Date $start, Horde_Date $end = null)
 {
     $offset = $startOffset;
     foreach ($this->_rules as $rule) {
         $year = $rule[3];
         if ($year[0] == 'o') {
             // TO is "only"
             $rule[3] = $rule[2];
         }
         if ($rule[3][0] != 'm' && $rule[3] < $start->year) {
             // TO is not maximum and is before the searched period
             continue;
         }
         if ($end && $rule[2][0] != 'm' && $rule[2] > $end->year) {
             // FROM is not "minimum" and is after the searched period
             break;
         }
         if ($rule[2][0] != 'm' && $rule[2] < $start->year) {
             $rule[2] = $start->year;
         }
         if ($rule[8] == 0) {
             $component = new Horde_Icalendar_Standard();
             $component->setAttribute('TZOFFSETFROM', $offset);
             $component->setAttribute('TZOFFSETTO', $startOffset);
             $offset = $startOffset;
         } else {
             $component = new Horde_Icalendar_Daylight();
             $component->setAttribute('TZOFFSETFROM', $offset);
             $offset = $this->_getOffset($startOffset, $rule[8]);
             $component->setAttribute('TZOFFSETTO', $offset);
         }
         $month = Horde_Timezone::getMonth($rule[5]);
         // Retrieve time of rule start.
         preg_match('/(\\d+)(?::(\\d+))?(?::(\\d+))?(w|s|u)?/', $rule[7], $match);
         if (!isset($match[2])) {
             $match[2] = 0;
         }
         if ($rule[2] == $rule[3] && preg_match('/^\\d+$/', $rule[6])) {
             // Rule lasts only for a single year and starts on a specific
             // date.
             $rdate = new Horde_Date(array('year' => $rule[2], 'month' => Horde_Timezone::getMonth($rule[5]), 'mday' => $rule[6], 'hour' => $match[1], 'min' => $match[2], 'sec' => 0));
             $component->setAttribute('DTSTART', $rdate);
         } elseif (substr($rule[6], 0, 4) == 'last') {
             // Rule starts on the last of a certain weekday of the month.
             $weekday = $this->_weekdays[substr($rule[6], 4, 3)];
             $last = new Horde_Date(array('year' => $rule[2], 'month' => $month, 'mday' => Horde_Date_Utils::daysInMonth($month, $rule[2]), 'hour' => $match[1], 'min' => $match[2], 'sec' => 0));
             while ($last->dayOfWeek() != $weekday) {
                 $last->mday--;
             }
             $component->setAttribute('DTSTART', $last);
             if ($rule[3][0] == 'm') {
                 $until = '';
             } else {
                 $last = new Horde_Date(array('year' => $rule[3], 'month' => $month, 'mday' => Horde_Date_Utils::daysInMonth($month, $rule[2]), 'hour' => $match[1], 'min' => $match[2], 'sec' => 0), $tzid);
                 while ($last->dayOfWeek() != $weekday) {
                     $last->mday--;
                 }
                 $last->setTimezone('UTC');
                 $until = ';UNTIL=' . $last->format('Ymd\\THIs') . 'Z';
             }
             $component->setAttribute('RRULE', 'FREQ=YEARLY;BYDAY=-1' . Horde_String::upper(substr($rule[6], 4, 2)) . ';BYMONTH=' . $month . $until);
         } elseif (strpos($rule[6], '>=')) {
             // Rule starts on a certain weekday after a certain day of
             // month.
             list($weekday, $day) = explode('>=', $rule[6]);
             $weekdayInt = $this->_weekdays[substr($weekday, 0, 3)];
             $first = new Horde_Date(array('year' => $rule[2], 'month' => $month, 'mday' => $day, 'hour' => $match[1], 'min' => $match[2], 'sec' => 0));
             while ($first->dayOfWeek() != $weekdayInt) {
                 $first->mday++;
             }
             $component->setAttribute('DTSTART', $first);
             if ($rule[3][0] == 'm') {
                 $until = '';
             } else {
                 $last = new Horde_Date(array('year' => $rule[3], 'month' => $month, 'mday' => $day, 'hour' => $match[1], 'min' => $match[2], 'sec' => 0), $tzid);
                 while ($last->dayOfWeek() != $weekday) {
                     $last->mday++;
                 }
                 $last->setTimezone('UTC');
                 $until = ';UNTIL=' . $last->format('Ymd\\THIs') . 'Z';
             }
             for ($days = array(), $i = $day, $lastDay = min(Horde_Date_Utils::daysInMonth($month, $rule[2]), $i + 6); $day > 1 && $i <= $lastDay; $i++) {
                 $days[] = $i;
             }
             $component->setAttribute('RRULE', 'FREQ=YEARLY;BYMONTH=' . $month . ($days ? ';BYMONTHDAY=' . implode(',', $days) : '') . ';BYDAY=1' . Horde_String::upper(substr($weekday, 0, 2)) . $until);
         } elseif (strpos($rule[6], '<=')) {
             // Rule starts on a certain weekday before a certain day of
             // month.
             list($weekday, $day) = explode('>=', $rule[6]);
             $weekdayInt = $this->_weekdays[substr($weekday, 0, 3)];
             $last = new Horde_Date(array('year' => $rule[2], 'month' => $month, 'mday' => $day, 'hour' => $match[1], 'min' => $match[2], 'sec' => 0));
             while ($last->dayOfWeek() != $weekdayInt) {
                 $last->mday--;
             }
             $component->setAttribute('DTSTART', $last);
             if ($rule[3][0] == 'm') {
                 $until = '';
             } else {
                 $last = new Horde_Date(array('year' => $rule[3], 'month' => $month, 'mday' => $day, 'hour' => $match[1], 'min' => $match[2], 'sec' => 0), $tzid);
                 while ($last->dayOfWeek() != $weekday) {
                     $last->mday--;
                 }
                 $last->setTimezone('UTC');
                 $until = ';UNTIL=' . $last->format('Ymd\\THIs') . 'Z';
             }
             for ($days = array(), $i = 1; $i <= $day; $i++) {
                 $days[] = $i;
             }
             $component->setAttribute('RRULE', 'FREQ=YEARLY;BYMONTH=' . $month . ';BYMONTHDAY=' . implode(',', $days) . ';BYDAY=-1' . Horde_String::upper(substr($weekday, 0, 2)) . $until);
         }
         $component->setAttribute('TZNAME', sprintf($name, $rule[9]));
         $tz->addComponent($component);
     }
 }
Пример #7
0
 /**
  * Get the children of this gallery.
  *
  * @param integer $perm    The permissions to limit to.
  * @param integer $from    The child to start at.
  * @param integer $to      The child to end with.
  * @param boolean $noauto  Whether or not to automatically drill down to the
  *                         first grouping with more then one group.
  *
  * @return array A mixed array of Ansel_Gallery_Decorator_Date and
  *               Ansel_Image objects.
  */
 public function getGalleryChildren($perm = Horde_Perms::SHOW, $from = 0, $to = 0, $noauto = false)
 {
     // Cache the results
     static $children = array();
     $fullkey = md5($noauto . $perm . $this->_gallery->id . serialize($this->_date) . 0 . 0);
     $cache_key = md5($noauto . $perm . $this->_gallery->id . serialize($this->_date) . $from . $to);
     if (!empty($children[$cache_key])) {
         return $children[$cache_key];
     } elseif (!empty($children[$fullkey])) {
         return $this->_getArraySlice($children[$fullkey], $from, $to, true);
     }
     $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
     // Get a list of all the subgalleries
     $this->_loadSubGalleries();
     $params = array('fields' => array('image_id', 'image_original_date'));
     if (count($this->_subGalleries)) {
         $params['gallery_id'] = array_merge($this->_subGalleries, array($this->_gallery->id));
     } else {
         $params['gallery_id'] = $this->_gallery->id;
     }
     $sorted_dates = array();
     // See how specific the date is
     if (!count($this->_date) || empty($this->_date['year'])) {
         // All available images - grouped by year
         $images = $ansel_storage->listImages($params);
         $dates = array();
         foreach ($images as $key => $image) {
             $dates[date('Y', $image['image_original_date'])][] = $key;
         }
         $keys = array_keys($dates);
         // Drill down further if we only have a single group
         if (!$noauto && count($keys) == 1) {
             $this->_date['year'] = array_pop($keys);
             return $this->getGalleryChildren($perm, $from, $to, $noauto);
         }
         sort($keys, SORT_NUMERIC);
         foreach ($keys as $key) {
             $sorted_dates[$key] = $dates[$key];
         }
         $display_unit = 'year';
     } elseif (empty($this->_date['month'])) {
         // Specific year - grouped by month
         $start = new Horde_Date(array('year' => $this->_date['year'], 'month' => 1, 'day' => 1));
         // Last second of the year
         $end = new Horde_Date($start);
         $end->mday = 31;
         $end->month = 12;
         $end->hour = 23;
         $end->min = 59;
         $end->sec = 59;
         // Get the image ids and dates
         $params['filter'] = array(array('property' => 'originalDate', 'op' => '<=', 'value' => (int) $end->timestamp()), array('property' => 'originalDate', 'op' => '>=', 'value' => (int) $start->timestamp()));
         $images = $ansel_storage->listImages($params);
         $dates = array();
         foreach ($images as $key => $image) {
             $dates[date('n', $image['image_original_date'])][] = $key;
         }
         $keys = array_keys($dates);
         // Only 1 date grouping here, automatically drill down
         if (!$noauto && count($keys) == 1) {
             $this->_date['month'] = array_pop($keys);
             return $this->getGalleryChildren($perm, $from, $to, $noauto);
         }
         sort($keys, SORT_NUMERIC);
         foreach ($keys as $key) {
             $sorted_dates[$key] = $dates[$key];
         }
         $display_unit = 'month';
     } elseif (empty($this->_date['day'])) {
         // A single month - group by day
         $start = new Horde_Date(array('year' => $this->_date['year'], 'month' => $this->_date['month'], 'day' => 1));
         // Last second of the month
         $end = new Horde_Date($start);
         $end->mday = Horde_Date_Utils::daysInMonth($end->month, $end->year);
         $end->hour = 23;
         $end->min = 59;
         $end->sec = 59;
         $params['filter'] = array(array('property' => 'originalDate', 'op' => '<=', 'value' => (int) $end->timestamp()), array('property' => 'originalDate', 'op' => '>=', 'value' => (int) $start->timestamp()));
         $images = $ansel_storage->listImages($params);
         $dates = array();
         foreach ($images as $key => $image) {
             $dates[date('d', $image['image_original_date'])][] = $key;
         }
         $keys = array_keys($dates);
         // Only a single grouping, go deeper
         if (!$noauto && count($keys) == 1) {
             $this->_date['day'] = array_pop($keys);
             return $this->getGalleryChildren($perm, $from, $to, $noauto);
         }
         sort($keys, SORT_NUMERIC);
         foreach ($keys as $key) {
             $sorted_dates[$key] = $dates[$key];
         }
         $dates = $sorted_dates;
         $display_unit = 'day';
     } else {
         // We are down to a specific day
         $start = new Horde_Date($this->_date);
         // Last second of this day
         $end = new Horde_Date($start->timestamp());
         $end->hour = 23;
         $end->min = 59;
         $end->sec = 59;
         // Filter for this day
         $params['filter'] = array(array('property' => 'originalDate', 'op' => '<=', 'value' => (int) $end->timestamp()), array('property' => 'originalDate', 'op' => '>=', 'value' => (int) $start->timestamp()));
         // Only get what we need
         $params['offset'] = $from;
         $params['limit'] = $to;
         // Default to asking for just image_ids
         unset($params['fields']);
         // Get the image list
         $images = $ansel_storage->listImages($params);
         if ($images) {
             $results = $ansel_storage->getImages(array('ids' => $images, 'preserve' => true));
         } else {
             $results = array();
         }
         if ($this->_gallery->get('has_subgalleries')) {
             $images = array();
             foreach ($results as $id => $image) {
                 $image->gallery = $this->_gallery->id;
                 $images[$id] = $image;
             }
             $children[$cache_key] = $images;
         } else {
             $children[$cache_key] = $results;
         }
         return $children[$cache_key];
     }
     $results = array();
     foreach ($sorted_dates as $key => $images) {
         /* Get the new date parameter */
         switch ($display_unit) {
             case 'year':
                 $date = array('year' => $key);
                 break;
             case 'month':
                 $date = array('year' => $this->_date['year'], 'month' => (int) $key);
                 break;
             case 'day':
                 $date = array('year' => (int) $this->_date['year'], 'month' => (int) $this->_date['month'], 'day' => (int) $key);
         }
         $obj = new Ansel_Gallery_Decorator_Date($this->_gallery, $images);
         $obj->setDate($date);
         $results[$key] = $obj;
     }
     $children[$cache_key] = $results;
     if ($from > 0 || $to > 0) {
         return $this->_getArraySlice($results, $from, $to, true);
     }
     return $results;
 }
Пример #8
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>';
 }
Пример #9
0
 /**
  * Finds a date matching a rule definition.
  *
  * @param array $rule      A rule definition hash from addRules().
  * @param integer $year    A year when the rule should be applied.
  *
  * @return Horde_Date  The first matching date.
  */
 protected function _getFirstMatch($rule, $year)
 {
     $month = Horde_Timezone::getMonth($rule[5]);
     if (preg_match('/^\\d+$/', $rule[6])) {
         // Rule starts on a specific date.
         $date = new Horde_Date(array('year' => $year, 'month' => $month, 'mday' => $rule[6]));
     } elseif (substr($rule[6], 0, 4) == 'last') {
         // Rule starts on the last of a certain weekday of the month.
         $weekday = $this->_weekdays[substr($rule[6], 4, 3)];
         $date = new Horde_Date(array('year' => $year, 'month' => $month, 'mday' => Horde_Date_Utils::daysInMonth($month, $rule[2])));
         while ($date->dayOfWeek() != $weekday) {
             $date->mday--;
         }
     } elseif (strpos($rule[6], '>=')) {
         // Rule starts on a certain weekday after a certain day of month.
         list($weekday, $day) = explode('>=', $rule[6]);
         $weekdayInt = $this->_weekdays[substr($weekday, 0, 3)];
         $date = new Horde_Date(array('year' => $year, 'month' => $month, 'mday' => $day));
         while ($date->dayOfWeek() != $weekdayInt) {
             $date->mday++;
         }
     } elseif (strpos($rule[6], '<=')) {
         // Rule starts on a certain weekday before a certain day of month.
         list($weekday, $day) = explode('>=', $rule[6]);
         $weekdayInt = $this->_weekdays[substr($weekday, 0, 3)];
         $date = new Horde_Date(array('year' => $year, 'month' => $month, 'mday' => $day));
         while ($date->dayOfWeek() != $weekdayInt) {
             $date->mday--;
         }
     } else {
         throw new Horde_Timezone_Exception('Cannot parse rule ' . $rule[6]);
     }
     return $date;
 }
Пример #10
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>';
 }