protected function initializeForPage() {
    switch ($this->page) {
      case 'help':
        break;
        
      case 'pane':
        $start = new DateTime(date('Y-m-d H:i:s', time()), $this->timezone);
        $start->setTime(0,0,0);
        $end = clone $start;
        $end->setTime(23,59,59);
        
        $type     = $this->getArg('type', 'static');
        $calendar = $this->getArg('calendar', $this->getDefaultFeed($type));

        $feed = $this->getFeed($calendar, $type);
        $feed->setStartDate($start);
        $feed->setEndDate($end);
        $iCalEvents = $feed->items();
                
        $events = array();
        foreach($iCalEvents as $iCalEvent) {
          $events[] = array(
            'url'      => $this->detailURL($iCalEvent, array(), false, true),
            'title'    => $iCalEvent->get_summary().':',
            'subtitle' => $this->timeText($iCalEvent, true),
          );
        }
        
        $this->assign('events', $events);
        break;
      
      case 'resources':
        if ($resourceFeeds = $this->getFeeds('resource')) {
          $resources = array();
          foreach ($resourceFeeds as $calendar=>$resource) {

            $feed = $this->getFeed($calendar, 'resource');
            $availability = 'Available';
            if ($event = $feed->getNextEvent()) {
                $now = time();
                if ($event->overlaps(new TimeRange($now, $now))) {
                    $availability = 'In use';
                } elseif ($event->overlaps(new TimeRange($now + 900, $now + 1800))) {
                    $availability = 'In use at ' . $this->timeText($event, true);
                }
            }
                
            $resources[$calendar] = array(
              'title' => $resource['TITLE'],
              'subtitle'=>$availability,
              'url'   => $this->buildBreadcrumbURL('day', array(
                'type'     => 'resource', 
                'calendar' => $calendar
              ))
            );
          }
          $this->assign('resources', $resources);
        } else {
            $this->redirectTo('index');
        }
        break;
      case 'user':
        if ($userFeeds = $this->getFeeds('user')) {
          $userCalendars = array();
          foreach ($userFeeds as $id=>$calendar) {
            $userCalendars[$id] = array(
              'title' => $calendar['TITLE'],
              'url'   => $this->buildBreadcrumbURL('day', array(
                'type'     => 'user', 
                'calendar' => $id
              )),
            );
          }
          $this->assign('userCalendars', $userCalendars);
        } else {
            $this->redirectTo('index');
        }
      
        break;

      case 'index':
        if ($userCalendar = $this->getDefaultFeed('user')) {
            $this->assign('selectedFeed', 'user|' . $userCalendar);
            $feed = $this->getFeed($userCalendar, 'user');
            $feeds = $this->getFeeds('user');
            $upcomingEvents = array();
            if ($event = $feed->getNextEvent(true)) {
                $upcomingEvents[] = array(
                    'title'=>$event->get_summary(),
                    'subtitle'=>$this->timeText($event),
                    'url'=>$this->detailURL($event, array(
                        'type'=>'user',
                        'calendar'=>$userCalendar
                     ))
                );
            } else {
                $upcomingEvents[] = array(
                    'title'=>'No remaining events for today'
                );
            }
            
            $upcomingEvents[] = array(
                'title'=>'My calendar',
                'url'=>$this->dayURL(time(), 'user', $userCalendar)
            );
            if (count($feeds)>1) {
                $upcomingEvents[] = array(
                    'title'=>'Other calendars',
                    'url'=>$this->buildBreadcrumbURL('user', array())
                );
            }
            $this->assign('upcomingEvents', $upcomingEvents);
        }
        
        if ($resourceFeeds = $this->getFeeds('resource')) {
            $resources = array(
                array(
                    'title'=>'Resources',
                    'url'  =>$this->buildBreadcrumbURL('resources', array())
                )
            );
            $this->assign('resources', $resources);
        }

        $this->loadPageConfigFile('index','calendarPages');
        $this->assign('today',         mktime(0,0,0));
        $this->assign('searchOptions', $this->searchOptions);
        $this->assign('feeds',  $this->getFeedsByType());
        break;
      
      case 'categories':
        $categories = array();
        $type       = $this->getArg('type', 'static');
        $calendar   = $this->getArg('calendar', $this->getDefaultFeed($type));
        $feed       = $this->getFeed($calendar, $type);
        $categoryObjects = $feed->getEventCategories();

        foreach ($categoryObjects as $categoryObject) {
          $categories[] = array(
            'title'   => $this->ucname($categoryObject->get_name()),
            'url'     => $this->categoryURL($categoryObject),
          );
        }
        
        $this->assign('categories', $categories);
        break;
      
      case 'category':
        $type    = $this->getArg('type', 'static');
        $calendar= $this->getArg('calendar', $this->getDefaultFeed($type));
        $catid   = $this->getArg('catid', '');
        $name    = $this->getArg('name', '');
        $current = $this->getArg('time', time());
        $next    = $current + DAY_SECONDS;
        $prev    = $current - DAY_SECONDS;

        $this->setBreadcrumbTitle($name);
        $this->setBreadcrumbLongTitle($name);

        $this->assign('category', $this->ucname($name));
        
        $dayRange = new DayRange(time());
        
        $this->assign('current', $current);
        $this->assign('next',    $next);
        $this->assign('prev',    $prev);
        $this->assign('nextURL', $this->categoryDayURL($next, $catid, $name, false));
        $this->assign('prevURL', $this->categoryDayURL($prev, $catid, $name, false));
        $this->assign('isToday', $dayRange->contains(new TimeRange($current)));

        $events = array();
        
        if (strlen($catid) > 0) {
            $feed = $this->getFeed($type, $user); // this allows us to have multiple feeds in the future
            $start = new DateTime(date('Y-m-d H:i:s', $current), $this->timezone);
            $start->setTime(0,0,0);
            $end = clone $start;
            $end->setTime(23,59,59);
    
            $feed->setStartDate($start);
            $feed->setEndDate($end);
            $feed->addFilter('category', $catid);
            $iCalEvents = $feed->items();
          
          foreach($iCalEvents as $iCalEvent) {
            $subtitle = $this->timeText($iCalEvent);
            if ($briefLocation = $iCalEvent->get_location()) {
              $subtitle .= " | $briefLocation";
            }
          
            $events[] = array(
              'url'      => $this->detailURL($iCalEvent, array(
                'catid'    => $catid,
                'calendar' => $calendar,
                'type'     => $type
              )),
              'title'    => $iCalEvent->get_summary(),
              'subtitle' => $subtitle,
            );
          }
        }
        
        $this->assign('events', $events);        
        break;
        
      case 'list':
        $current  = $this->getArg('time', time());
        $type     = $this->getArg('type', 'static');
        $calendar = $this->getArg('calendar', $this->getDefaultFeed($type));
        $limit    = $this->getArg('limit', 20);
        $feed     = $this->getFeed($calendar, $type);
        
        $this->setPageTitle($this->getFeedTitle($calendar, $type));
        $this->setBreadcrumbTitle('List');
        $this->setBreadcrumbLongTitle($this->getFeedTitle($calendar, $type));
        
        $start = new DateTime(date('Y-m-d H:i:s', $current), $this->timezone);
        $start->setTime(0,0,0);

        $feed->setStartDate($start);
        $iCalEvents = $feed->items(0, $limit);
                        
        $events = array();
        foreach($iCalEvents as $iCalEvent) {
          $subtitle = $this->timeText($iCalEvent);
          if ($briefLocation = $iCalEvent->get_location()) {
            $subtitle .= " | $briefLocation";
          }

          $events[] = array(
            'url'      => $this->detailURL($iCalEvent, array(
              'calendar' => $calendar,
              'type'     => $type
            )),
            'title'    => $iCalEvent->get_summary(),
            'subtitle' => $subtitle
          );
        }

        $this->assign('feedTitle', $this->getFeedTitle($calendar, $type));
        $this->assign('calendar', $calendar);
        $this->assign('current', $current);
        $this->assign('events',  $events);        
        break;
        
      case 'day':  
        $current = $this->getArg('time', time());
        $type    = $this->getArg('type', 'static');
        $calendar= $this->getArg('calendar', $this->getDefaultFeed($type));
        $next    = strtotime("+1 day", $current);
        $prev    = strtotime("-1 day", $current);
        
        $feed = $this->getFeed($calendar, $type);
        
        $start = new DateTime(date('Y-m-d H:i:s', $current), $this->timezone);
        $start->setTime(0,0,0);
        $end = clone $start;
        $end->setTime(23,59,59);

        $feed->setStartDate($start);
        $feed->setEndDate($end);
        $iCalEvents = $feed->items();
                
        $events = array();
        foreach($iCalEvents as $iCalEvent) {
          $subtitle = $this->timeText($iCalEvent, true);
            if ($briefLocation = $iCalEvent->get_location()) {
              $subtitle .= " | $briefLocation";
            }
        
          $events[] = array(
            'url'      => $this->detailURL($iCalEvent, array('calendar'=>$calendar,'type'=>$type)),
            'title'    => $iCalEvent->get_summary(),
            'subtitle' => $subtitle
          );
        }

        $this->assign('feedTitle', $this->getFeedTitle($calendar, $type));
        $this->assign('type',    $type);
        $this->assign('calendar',$calendar);
        $this->assign('current', $current);
        $this->assign('next',    $next);
        $this->assign('prev',    $prev);
        $this->assign('nextURL', $this->dayURL($next, $type, $calendar, false));
        $this->assign('prevURL', $this->dayURL($prev, $type, $calendar, false));
        $this->assign('events',  $events);        
        break;
        
      case 'detail':  
        $calendarFields = $this->loadPageConfigFile('detail', 'detailFields');
        $type = $this->getArg('type', 'static');
        $calendar = $this->getArg('calendar', $this->getDefaultFeed($type));
        
        $feed = $this->getFeed($calendar, $type);
        
        if ($filter = $this->getArg('filter')) {
            $feed->addFilter('search', $filter);
        }

        if ($catid = $this->getArg('catid')) {
            $feed->addFilter('category', $catid);
        }
        
        $time = $this->getArg('time', time());

        if ($event = $feed->getItem($this->getArg('id'), $time)) {
          $this->assign('event', $event);
        } else {
          throw new Exception("Event not found");
        }
            
        // build the list of attributes
        $allKeys = array_keys($calendarFields);

        $fields = array();
        foreach ($calendarFields as $key => $info) {
          $field = array();
          
          $value = $event->get_attribute($key);
          if (empty($value)) { continue; }

          if (isset($info['label'])) {
            $field['label'] = $info['label'];
          }
          
          if (isset($info['class'])) {
            $field['class'] = $info['class'];
          }
          
          if (is_array($value)) {		
            $fieldValues = array();
            foreach ($value as $item) {
              $fieldValue = '';
              $fieldValueUrl = null;
              
              if (isset($info['type'])) {
                $fieldValue  = $this->valueForType($info['type'], $item);
                $fieldValueUrl = $this->urlForType($info['type'], $item);
              } else {
                $fieldValue = $item;
              }
              
              if (isset($fieldValueUrl)) {
                $fieldValue = '<a href="'.$fieldValueUrl.'">'.$fieldValue.'</a>';
              }
              
              $fieldValues[] = $fieldValue;
            }
            $field['title'] = implode(', ', $fieldValues);
          
          } else {
            if (isset($info['type'])) {
              $field['title'] = $this->valueForType($info['type'], $value);
              $field['url']   = $this->urlForType($info['type'], $value);
            } else {
              $field['title'] = nl2br($value);
            }
          }
          
          $fields[] = $field;
        }        

        $this->assign('fields', $fields);
        //error_log(print_r($fields, true));
        break;
        
      case 'search':
        if ($filter = $this->getArg('filter')) {
          $searchTerms    = trim($filter);
          $timeframeKey   = $this->getArg('timeframe', 0);
          $searchOption   = $this->searchOptions[$timeframeKey];
          $type           = $this->getArg('type', 'static');
          $searchCalendar = $this->getArg('calendar', $this->getDefaultFeed($type));
          
          if (preg_match("/^(.*?)\|(.*?)$/", $searchCalendar, $bits)) {
            $type     = $bits[1];
            $calendar = $bits[2];
          } else {
            $calendar = $searchCalendar;
          }
          
          $feed         = $this->getFeed($calendar, $type);
          
          list($start, $end) = $this->getDatesForSearchOption($searchOption);          
          $feed->setStartDate($start);
          $feed->setEndDate($end);
          $feed->addFilter('search', $searchTerms);
          $iCalEvents = $feed->items();

          $events = array();
          foreach($iCalEvents as $iCalEvent) {
            $subtitle = $this->timeText($iCalEvent);
            if ($briefLocation = $iCalEvent->get_location()) {
              $subtitle .= " | $briefLocation";
            }
        
            $events[] = array(
              'url'       => $this->detailURL($iCalEvent, array(
              'calendar'  => $calendar,
              'type'      => $type,
              'filter'    => $searchTerms, 
              'timeframe' => $timeframeKey)),
              'title'     => $iCalEvent->get_summary(),
              'subtitle'  => $subtitle
            );
          }
                    
          $this->assign('events'        , $events);        
          $this->assign('searchTerms'   , $searchTerms);        
          $this->assign('selectedOption', $timeframeKey);
          $this->assign('searchOptions' , $this->searchOptions);
          $this->assign('feeds'         , $this->getFeedsByType());
          $this->assign('searchCalendar', $searchCalendar);

        } else {
          $this->redirectTo('index');
        }
        break;
        
      case 'year':
        $year      = $this->getArg('year', null);
        $type      = $this->getArg('type', 'static');
        $calendar  = $this->getArg('calendar', $this->getDefaultFeed($type));
        $month     = $this->getArg('month', 1); // default to january
        
        if (!$year) {
            $year = date('m') < $month ? date('Y') - 1 : date('Y');
        }
        
        $start = new DateTime(sprintf("%d%02d01", $year, $month), $this->timezone);
        $end   = new DateTime(sprintf("%d%02d01", $year+1, $month), $this->timezone);
        
        $feed = $this->getFeed($calendar, $type);
        $feed->setStartDate($start);
        $feed->setEndDate($end);
        $feed->addFilter('year', $year);
        $iCalEvents = $feed->items();

        $events = array();
        foreach($iCalEvents as $iCalEvent) {
          $events[] = array(
            'title'    => $iCalEvent->get_summary(),
            'subtitle' => date('l F j', $iCalEvent->get_start()),
          );
        }

        $current =  $year   .'&nbsp;-&nbsp;'.($year+1);
        $next    = ($year+1).'&nbsp;-&nbsp;'.($year+2);
        $prev    = ($year-1).'&nbsp;-&nbsp;'. $year;

        if ((date('Y')+1) > $year) {
          $this->assign('next',    $next);
          $this->assign('nextURL', $this->yearURL($year+1, $month, $type, $calendar, false));
        }
        if ($year > intval(date('Y'))) {
          $this->assign('prev',    $prev);
          $this->assign('prevURL', $this->yearURL($year-1, $month, $type, $calendar, false));
        }

        $this->assign('current', $current);
        $this->assign('events',  $events);        
        $this->assign('feedTitle', $this->getFeedTitle($calendar, $type));
        break;
    }
  }
 protected function initializeForPage()
 {
     switch ($this->page) {
         case 'help':
             break;
         case 'pane':
             $start = new DateTime(date('Y-m-d H:i:s', time()), $this->timezone);
             $start->setTime(0, 0, 0);
             $end = clone $start;
             $end->setTime(23, 59, 59);
             $type = $this->getArg('type', 'static');
             $calendar = $this->getArg('calendar', $this->getDefaultFeed($type));
             $options = array('type' => $type, 'calendar' => $calendar, 'start' => $start, 'end' => $end);
             $iCalEvents = $this->searchItems('', null, $options);
             $options['noBreadcrumbs'] = true;
             $events = array();
             foreach ($iCalEvents as $iCalEvent) {
                 $events[] = $this->linkforItem($iCalEvent, $options, false);
             }
             $this->assign('events', $events);
             break;
         case 'resources':
             if ($resourceFeeds = $this->getFeeds('resource')) {
                 $resources = array();
                 foreach ($resourceFeeds as $calendar => $resource) {
                     $feed = $this->getFeed($calendar, 'resource');
                     $availability = $this->getLocalizedString('RESOURCE_AVAILABLE');
                     if ($event = $feed->getNextEvent()) {
                         $now = time();
                         if ($event->overlaps(new TimeRange($now, $now))) {
                             $availability = $this->getLocalizedString('RESOURCE_IN_USE');
                         } elseif ($event->overlaps(new TimeRange($now + 900, $now + 1800))) {
                             $availability = $this->getLocalizedString('RESOURCE_IN_USE_TIME', $this->timeText($event, true));
                         }
                     }
                     $resources[$calendar] = array('title' => $resource['TITLE'], 'subtitle' => $availability, 'url' => $this->buildBreadcrumbURL('day', array('type' => 'resource', 'calendar' => $calendar)));
                 }
                 $this->assign('resources', $resources);
             } else {
                 $this->redirectTo('index');
             }
             break;
         case 'user':
             if ($userFeeds = $this->getFeeds('user')) {
                 $userCalendars = array();
                 foreach ($userFeeds as $id => $calendar) {
                     $userCalendars[$id] = array('title' => $calendar['TITLE'], 'url' => $this->buildBreadcrumbURL('day', array('type' => 'user', 'calendar' => $id)));
                 }
                 $this->assign('userCalendars', $userCalendars);
             } else {
                 $this->redirectTo('index');
             }
             break;
         case 'index':
             if ($userCalendar = $this->getDefaultFeed('user')) {
                 $this->assign('selectedFeed', 'user|' . $userCalendar);
                 $feed = $this->getFeed($userCalendar, 'user');
                 $feeds = $this->getFeeds('user');
                 $upcomingEvents = array();
                 if ($event = $feed->getNextEvent(true)) {
                     $upcomingEvents[] = $this->linkForItem($event, array('type' => 'user', 'calendar' => $userCalendar));
                 } else {
                     $upcomingEvents[] = array('title' => $this->getLocalizedString('NO_EVENTS_REMAINING'));
                 }
                 $upcomingEvents[] = array('title' => $this->getLocalizedString('MY_CALENDAR'), 'url' => $this->dayURL(time(), 'user', $userCalendar));
                 if (count($feeds) > 1) {
                     $upcomingEvents[] = array('title' => $this->getLocalizedString('OTHER_CALENDARS'), 'url' => $this->buildBreadcrumbURL('user', array()));
                 }
                 $this->assign('upcomingEvents', $upcomingEvents);
             }
             if ($resourceFeeds = $this->getFeeds('resource')) {
                 $resources = array(array('title' => $this->getLocalizedString('RESOURCES'), 'url' => $this->buildBreadcrumbURL('resources', array())));
                 $this->assign('resources', $resources);
             }
             $this->loadPageConfigFile('index', 'calendarPages');
             $this->assign('today', mktime(0, 0, 0));
             $this->assign('dateFormat', $this->getLocalizedString("LONG_DATE_FORMAT"));
             $this->assign('placeholder', $this->getLocalizedString('SEARCH_TEXT'));
             $this->assign('searchOptions', $this->searchOptions());
             $this->assign('feeds', $this->getFeedsByType());
             break;
         case 'categories':
             $categories = array();
             $type = $this->getArg('type', 'static');
             $calendar = $this->getArg('calendar', $this->getDefaultFeed($type));
             $feed = $this->getFeed($calendar, $type);
             $categoryObjects = $feed->getEventCategories();
             foreach ($categoryObjects as $categoryObject) {
                 $categories[] = $this->linkForCategory($categoryObject);
             }
             $this->assign('categories', $categories);
             break;
         case 'category':
             $type = $this->getArg('type', 'static');
             $calendar = $this->getArg('calendar', $this->getDefaultFeed($type));
             $catid = $this->getArg('catid', '');
             $name = $this->getArg('name', '');
             $current = $this->getArg('time', time(), FILTER_VALIDATE_INT);
             $next = strtotime("+1 day", $current);
             $prev = strtotime("-1 day", $current);
             $this->setBreadcrumbTitle($name);
             $this->setBreadcrumbLongTitle($name);
             // wouldn't this already be formatted from the url building stage?
             $catname = $this->formatTitle($name);
             $this->assign('category', $catname);
             $this->setLogData($catid, $catname);
             $dayRange = new DayRange(time());
             $this->assign('current', $current);
             $this->assign('next', $next);
             $this->assign('prev', $prev);
             $this->assign('nextURL', $this->categoryDayURL($next, $catid, $name, false));
             $this->assign('prevURL', $this->categoryDayURL($prev, $catid, $name, false));
             $this->assign('titleDateFormat', $this->getLocalizedString('MEDIUM_DATE_FORMAT'));
             $this->assign('linkDateFormat', $this->getLocalizedString('SHORT_DATE_FORMAT'));
             $this->assign('isToday', $dayRange->contains(new TimeRange($current)));
             $events = array();
             if (strlen($catid) > 0) {
                 $feed = $this->getFeed($calendar, $type);
                 // this allows us to have multiple feeds in the future
                 $start = new DateTime(date('Y-m-d H:i:s', $current), $this->timezone);
                 $start->setTime(0, 0, 0);
                 $end = clone $start;
                 $end->setTime(23, 59, 59);
                 $feed->setStartDate($start);
                 $feed->setEndDate($end);
                 $feed->addFilter('category', $catid);
                 $iCalEvents = $feed->items();
                 foreach ($iCalEvents as $iCalEvent) {
                     $events[] = $this->linkForItem($iCalEvent, array('catid' => $catid, 'calendar' => $calendar, 'type' => $type));
                 }
             }
             $this->assign('events', $events);
             break;
         case 'list':
             $current = $this->getArg('time', time(), FILTER_VALIDATE_INT);
             $type = $this->getArg('type', 'static');
             $calendar = $this->getArg('calendar', $this->getDefaultFeed($type));
             $limit = $this->getArg('limit', 20);
             $feed = $this->getFeed($calendar, $type);
             $title = $this->getFeedTitle($calendar, $type);
             $this->setLogData($type . ':' . $calendar, $title);
             $this->setPageTitle($title);
             $this->setBreadcrumbTitle('List');
             $this->setBreadcrumbLongTitle($title);
             $start = new DateTime(date('Y-m-d H:i:s', $current), $this->timezone);
             $start->setTime(0, 0, 0);
             $feed->setStartDate($start);
             $iCalEvents = $feed->items(0, $limit);
             $events = array();
             foreach ($iCalEvents as $iCalEvent) {
                 $events[] = $this->linkForItem($iCalEvent, array('calendar' => $calendar, 'type' => $type));
             }
             $this->assign('feedTitle', $this->getFeedTitle($calendar, $type));
             $this->assign('calendar', $calendar);
             $this->assign('current', $current);
             $this->assign('events', $events);
             $this->assign('titleDateFormat', $this->getLocalizedString('MEDIUM_DATE_FORMAT'));
             $this->assign('linkDateFormat', $this->getLocalizedString('SHORT_DATE_FORMAT'));
             break;
         case 'day':
             $current = $this->getArg('time', time(), FILTER_VALIDATE_INT);
             $type = $this->getArg('type', 'static');
             $calendar = $this->getArg('calendar', $this->getDefaultFeed($type));
             $next = strtotime("+1 day", $current);
             $prev = strtotime("-1 day", $current);
             $feed = $this->getFeed($calendar, $type);
             $title = $this->getFeedTitle($calendar, $type);
             $this->setLogData($type . ':' . $calendar, $title);
             $start = new DateTime(date('Y-m-d H:i:s', $current), $this->timezone);
             $start->setTime(0, 0, 0);
             $end = clone $start;
             $end->setTime(23, 59, 59);
             $feed->setStartDate($start);
             $feed->setEndDate($end);
             $iCalEvents = $feed->items();
             $events = array();
             foreach ($iCalEvents as $iCalEvent) {
                 $events[] = $this->linkForItem($iCalEvent, array('calendar' => $calendar, 'type' => $type));
             }
             $dayRange = new DayRange(time());
             $this->assign('feedTitle', $title);
             $this->assign('type', $type);
             $this->assign('calendar', $calendar);
             $this->assign('current', $current);
             $this->assign('next', $next);
             $this->assign('prev', $prev);
             $this->assign('nextURL', $this->dayURL($next, $type, $calendar, false));
             $this->assign('prevURL', $this->dayURL($prev, $type, $calendar, false));
             $this->assign('titleDateFormat', $this->getLocalizedString('MEDIUM_DATE_FORMAT'));
             $this->assign('linkDateFormat', $this->getLocalizedString('SHORT_DATE_FORMAT'));
             $this->assign('isToday', $dayRange->contains(new TimeRange($current)));
             $this->assign('events', $events);
             break;
         case 'detail':
             $calendarFields = $this->getModuleSections('page-detail');
             $type = $this->getArg('type', 'static');
             $calendar = $this->getArg('calendar', $this->getDefaultFeed($type));
             $feed = $this->getFeed($calendar, $type);
             if ($filter = $this->getArg('filter')) {
                 $feed->addFilter('search', $filter);
             }
             if ($catid = $this->getArg('catid')) {
                 $feed->addFilter('category', $catid);
             }
             $time = $this->getArg('time', time(), FILTER_VALIDATE_INT);
             if ($event = $feed->getItem($this->getArg('id'), $time)) {
                 $this->assign('event', $event);
             } else {
                 throw new KurogoUserException($this->getLocalizedString('ERROR_NOT_FOUND'));
             }
             $this->setLogData($event->get_uid(), $event->get_summary());
             // build the list of attributes
             $allKeys = array_keys($calendarFields);
             $fields = array();
             foreach ($calendarFields as $key => $info) {
                 $field = array();
                 $value = $event->get_attribute($key);
                 if (empty($value)) {
                     continue;
                 }
                 if (isset($info['label'])) {
                     $field['label'] = $info['label'];
                 }
                 if (isset($info['class'])) {
                     $field['class'] = $info['class'];
                 }
                 if (is_array($value)) {
                     $fieldValues = array();
                     foreach ($value as $item) {
                         $fieldValue = '';
                         $fieldValueUrl = null;
                         if (isset($info['type'])) {
                             $fieldValue = $this->valueForType($info['type'], $item);
                             $fieldValueUrl = $this->urlForType($info['type'], $item);
                         } else {
                             $fieldValue = $item;
                         }
                         if (isset($fieldValueUrl)) {
                             $fieldValue = '<a href="' . $fieldValueUrl . '">' . $fieldValue . '</a>';
                         }
                         $fieldValues[] = $fieldValue;
                     }
                     $field['title'] = implode(', ', $fieldValues);
                 } else {
                     if (isset($info['type'])) {
                         $field['title'] = $this->valueForType($info['type'], $value);
                         $field['url'] = $this->urlForType($info['type'], $value);
                     } elseif (isset($info['module'])) {
                         $field = array_merge($field, Kurogo::moduleLinkForValue($info['module'], $value, $this, $event));
                     } else {
                         $field['title'] = nl2br($value);
                     }
                 }
                 if (isset($info['urlfunc'])) {
                     $urlFunction = create_function('$value,$event', $info['urlfunc']);
                     $field['url'] = $urlFunction($value, $event);
                 }
                 $fields[] = $field;
             }
             $this->assign('fields', $fields);
             //error_log(print_r($fields, true));
             break;
         case 'search':
             if ($filter = $this->getArg('filter')) {
                 $searchTerms = trim($filter);
                 $timeframe = $this->getArg('timeframe', 0);
                 $type = $this->getArg('type', 'static');
                 $searchCalendar = $this->getArg('calendar', $this->getDefaultFeed($type));
                 if (preg_match("/^(.*?)\\|(.*?)\$/", $searchCalendar, $bits)) {
                     $type = $bits[1];
                     $calendar = $bits[2];
                 } else {
                     $calendar = $searchCalendar;
                 }
                 $options = array('type' => $type, 'calendar' => $calendar, 'timeframe' => $timeframe);
                 $this->setLogData($searchTerms);
                 $iCalEvents = $this->searchItems($searchTerms, null, $options);
                 $events = array();
                 foreach ($iCalEvents as $iCalEvent) {
                     $events[] = $this->linkForItem($iCalEvent, array('filter' => $searchTerms, 'timeframe' => $timeframe, 'calendar' => $calendar, 'type' => $type));
                 }
                 $this->assign('events', $events);
                 $this->assign('searchTerms', $searchTerms);
                 $this->assign('selectedOption', $timeframe);
                 $this->assign('searchOptions', $this->searchOptions());
                 $this->assign('feeds', $this->getFeedsByType());
                 $this->assign('searchCalendar', $searchCalendar);
             } else {
                 $this->redirectTo('index');
             }
             break;
         case 'year':
             $type = $this->getArg('type', 'static');
             $calendar = $this->getArg('calendar', $this->getDefaultFeed($type));
             // Figure out when the calendar year starts; default to January 1
             // Allow setting either per-calendar with config or override with url parameter
             $defaultStartMonth = $this->getOptionalModuleVar(strtoupper($calendar) . '_CALENDAR_START_MONTH', 1);
             $defaultStartDay = $this->getOptionalModuleVar(strtoupper($calendar) . '_CALENDAR_START_DAY', 1);
             $month = intval($this->getArg('month', $defaultStartMonth));
             $day = intval($this->getArg('day', $defaultStartDay));
             // Figure out which year we are currently in based on year start month and day:
             $currentYear = intval(date('Y'));
             $yearStartForCurrentYear = new DateTime(sprintf("%d%02d%02d", $currentYear, $month, $day), $this->timezone);
             if (time() < intval($yearStartForCurrentYear->format('U'))) {
                 $currentYear--;
                 // today's date is before the start date for the current year
             }
             // Which year to view; default to current year based on year start month and day:
             $year = intval($this->getArg('year', $currentYear));
             $start = new DateTime(sprintf("%d%02d%02d", $year, $month, $day), $this->timezone);
             $end = new DateTime(sprintf("%d%02d%02d", $year + 1, $month, $day), $this->timezone);
             $feed = $this->getFeed($calendar, $type);
             $feed->setStartDate($start);
             $feed->setEndDate($end);
             $feed->addFilter('year', $year);
             $iCalEvents = $feed->items();
             $title = $this->getFeedTitle($calendar, $type);
             $this->setLogData($type . ':' . $calendar, $title);
             $events = array();
             foreach ($iCalEvents as $iCalEvent) {
                 $events[] = array('title' => $iCalEvent->get_summary(), 'subtitle' => date('l F j', $iCalEvent->get_start()));
             }
             $current = $year . '&nbsp;-&nbsp;' . ($year + 1);
             $next = $year + 1 . '&nbsp;-&nbsp;' . ($year + 2);
             $prev = $year - 1 . '&nbsp;-&nbsp;' . $year;
             // How many years into the future and past to page:
             $maxNextYears = $this->getOptionalModuleVar(strtoupper($calendar) . '_CALENDAR_MAX_NEXT_YEARS', 1);
             $maxPrevYears = $this->getOptionalModuleVar(strtoupper($calendar) . '_CALENDAR_MAX_PREV_YEARS', 1);
             if ($year < $currentYear + $maxNextYears) {
                 $this->assign('next', $next);
                 $this->assign('nextURL', $this->yearURL($year + 1, $month, $day, $type, $calendar, false));
             }
             if ($year > $currentYear - $maxPrevYears) {
                 $this->assign('prev', $prev);
                 $this->assign('prevURL', $this->yearURL($year - 1, $month, $day, $type, $calendar, false));
             }
             $this->assign('current', $current);
             $this->assign('events', $events);
             $this->assign('feedTitle', $title);
             break;
     }
 }
 protected function initializeDetail()
 {
     $feedID = $this->getArg('groupID');
     $locationID = $this->getArg('id');
     // specified date for events
     $current = $this->getArg('time', time(), FILTER_VALIDATE_INT);
     $next = strtotime("+1 day", $current);
     $prev = strtotime("-1 day", $current);
     $model = $this->loadFeed($feedID);
     $location = $model->getLocation($locationID);
     if ($location->hasAttribute('maploc') && ($link = Kurogo::moduleLinkForValue('map', $location->getAttribute('maploc'), $this))) {
         $link['title'] = $this->getLocalizedString('VIEW_ON_MAP');
         $this->assign('location', array($link));
     }
     if ($location->hasAttribute('events')) {
         $events = $location->getTodaysEvents($current);
         $eventLinks = array();
         foreach ($events as $event) {
             $eventLink = $this->linkForSchedule($event, array('section' => $locationID, 'groupID' => $feedID));
             $eventLinks[] = $eventLink;
         }
     }
     $nextURL = $this->buildBreadcrumbURL('detail', array('id' => $locationID, 'groupID' => $feedID, 'time' => $next), false);
     $prevURL = $this->buildBreadcrumbURL('detail', array('id' => $locationID, 'groupID' => $feedID, 'time' => $prev), false);
     $dayRange = new DayRange(time());
     $this->assign('title', $location->getTitle());
     $this->assign('description', $location->getDescription());
     $this->assign('current', $current);
     $this->assign('events', $eventLinks);
     $this->assign('next', $next);
     $this->assign('prev', $prev);
     $this->assign('nextURL', $nextURL);
     $this->assign('prevURL', $prevURL);
     $this->assign('titleDateFormat', $this->getLocalizedString('MEDIUM_DATE_FORMAT'));
     $this->assign('linkDateFormat', $this->getLocalizedString('SHORT_DAY_FORMAT'));
     $this->assign('isToday', $dayRange->contains(new TimeRange($current)));
 }