/**
  * show appointment
  *
  * @access protected
  * @param array appointment
  */
 protected function showAppointment($a_app)
 {
     global $ilUser;
     $this->tpl->setCurrentBlock('panel_code');
     $this->tpl->setVariable('NUM', $this->num_appointments);
     $this->tpl->parseCurrentBlock();
     if (!$ilUser->prefs["screen_reader_optimization"]) {
         $this->tpl->setCurrentBlock('app');
     } else {
         $this->tpl->setCurrentBlock('scrd_app');
     }
     include_once './Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php';
     $this->tpl->setVariable('PANEL_DATA', ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($a_app));
     $this->tpl->setVariable('PANEL_NUM', $this->num_appointments);
     $this->tpl->setVariable('APP_ROWSPAN', $a_app['rowspan']);
     $this->tpl->setVariable('APP_TITLE', $a_app['event']->getPresentationTitle(false));
     switch ($this->user_settings->getTimeFormat()) {
         case ilCalendarSettings::TIME_FORMAT_24:
             $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE, 'H:i', $this->timezone);
             break;
         case ilCalendarSettings::TIME_FORMAT_12:
             $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE, 'h:ia', $this->timezone);
             break;
     }
     // add end time for screen readers
     if ($ilUser->prefs["screen_reader_optimization"]) {
         switch ($this->user_settings->getTimeFormat()) {
             case ilCalendarSettings::TIME_FORMAT_24:
                 $title .= "-" . $a_app['event']->getEnd()->get(IL_CAL_FKT_DATE, 'H:i', $this->timezone);
                 break;
             case ilCalendarSettings::TIME_FORMAT_12:
                 $title .= "-" . $a_app['event']->getEnd()->get(IL_CAL_FKT_DATE, 'h:ia', $this->timezone);
                 break;
         }
     }
     $title .= ' ' . $a_app['event']->getPresentationTitle(false);
     $this->tpl->setVariable('APP_TITLE', $title);
     $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
     $this->tpl->setVariable('APP_BGCOLOR', $color);
     $this->tpl->setVariable('APP_COLOR', ilCalendarUtil::calculateFontColor($color));
     $this->tpl->setVariable('APP_ADD_STYLES', $a_app['event']->getPresentationStyle());
     $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
     $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
     $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
     $this->tpl->setVariable('APP_EDIT_LINK', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'edit'));
     $this->tpl->parseCurrentBlock();
     $this->num_appointments++;
 }
 /**
  * show appointment
  *
  * @access protected
  * @param array appointment
  */
 protected function showAppointment($a_app)
 {
     global $ilUser;
     $this->tpl->setCurrentBlock('panel_code');
     $this->tpl->setVariable('NUM', $this->num_appointments);
     $this->tpl->parseCurrentBlock();
     if (!$ilUser->prefs["screen_reader_optimization"]) {
         $this->tpl->setCurrentBLock('not_empty');
     } else {
         $this->tpl->setCurrentBLock('scrd_not_empty');
     }
     include_once './Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php';
     $this->tpl->setVariable('PANEL_DATA', ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($a_app));
     $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
     $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
     $this->tpl->setVariable('APP_EDIT_LINK', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'edit'));
     $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
     $style = 'background-color: ' . $color . ';';
     $style .= 'color:' . ilCalendarUtil::calculateFontColor($color);
     $td_style = $style;
     if ($a_app['event']->isFullDay()) {
         $title = $a_app['event']->getPresentationTitle();
     } else {
         switch ($this->user_settings->getTimeFormat()) {
             case ilCalendarSettings::TIME_FORMAT_24:
                 $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE, 'H:i', $this->timezone);
                 break;
             case ilCalendarSettings::TIME_FORMAT_12:
                 $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE, 'h:ia', $this->timezone);
                 break;
         }
         // add end time for screen readers
         if ($ilUser->prefs["screen_reader_optimization"]) {
             switch ($this->user_settings->getTimeFormat()) {
                 case ilCalendarSettings::TIME_FORMAT_24:
                     $title .= "-" . $a_app['event']->getEnd()->get(IL_CAL_FKT_DATE, 'H:i', $this->timezone);
                     break;
                 case ilCalendarSettings::TIME_FORMAT_12:
                     $title .= "-" . $a_app['event']->getEnd()->get(IL_CAL_FKT_DATE, 'h:ia', $this->timezone);
                     break;
             }
         }
         $title .= ' ' . $a_app['event']->getPresentationTitle();
         $td_style .= $a_app['event']->getPresentationStyle();
     }
     $this->tpl->setVariable('APP_TITLE', $title);
     $this->tpl->setVariable('LINK_NUM', $this->num_appointments);
     $this->tpl->setVariable('LINK_STYLE', $style);
     if (!$ilUser->prefs["screen_reader_optimization"]) {
         // provide table cell attributes
         $this->tpl->parseCurrentBlock();
         $this->tpl->setCurrentBlock('day_cell');
         $this->tpl->setVariable('DAY_CELL_NUM', $this->num_appointments);
         $this->tpl->setVariable('TD_ROWSPAN', $a_app['rowspan']);
         $this->tpl->setVariable('TD_STYLE', $td_style);
         $this->tpl->setVariable('TD_CLASS', 'calevent');
         $this->tpl->parseCurrentBlock();
     } else {
         // screen reader: work on div attributes
         $this->tpl->setVariable('DIV_STYLE', $style);
         $this->tpl->parseCurrentBlock();
     }
     $this->num_appointments++;
 }
 /**
  * 
  * Show events
  *
  * @access protected
  */
 protected function showEvents(ilDate $date)
 {
     global $tree, $ilUser;
     $count = 0;
     foreach ($this->scheduler->getByDay($date, $this->timezone) as $item) {
         $this->tpl->setCurrentBlock('panel_code');
         $this->tpl->setVariable('NUM', $this->num_appointments);
         $this->tpl->parseCurrentBlock();
         // milestone icon
         if ($item['event']->isMilestone()) {
             $this->tpl->setCurrentBlock('fullday_ms_icon');
             $this->tpl->setVariable('ALT_FD_MS', $this->lng->txt("cal_milestone"));
             $this->tpl->setVariable('SRC_FD_MS', ilUtil::getImagePath("icon_ms.svg"));
             $this->tpl->parseCurrentBlock();
         }
         $this->tpl->setCurrentBlock('il_event');
         include_once './Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php';
         $this->tpl->setVariable('PANEL_DATA', ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($item));
         $this->tpl->setVariable('PANEL_NUM', $this->num_appointments);
         $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
         $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $item['event']->getEntryId());
         $this->tpl->setVariable('EVENT_EDIT_LINK', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'edit'));
         $this->tpl->setVariable('EVENT_NUM', $item['event']->getEntryId());
         $compl = $item['event']->isMilestone() && $item['event']->getCompletion() > 0 ? " (" . $item['event']->getCompletion() . "%)" : "";
         if ($item['event']->isFullDay()) {
             $title = $item['event']->getPresentationTitle() . $compl;
         } else {
             switch ($this->user_settings->getTimeFormat()) {
                 case ilCalendarSettings::TIME_FORMAT_24:
                     $title = $item['event']->getStart()->get(IL_CAL_FKT_DATE, 'H:i', $this->timezone);
                     break;
                 case ilCalendarSettings::TIME_FORMAT_12:
                     $title = $item['event']->getStart()->get(IL_CAL_FKT_DATE, 'h:ia', $this->timezone);
                     break;
             }
             $title .= ' ' . $item['event']->getPresentationTitle();
         }
         $this->tpl->setVariable('EVENT_TITLE', $title);
         $color = $this->app_colors->getColorByAppointment($item['event']->getEntryId());
         $this->tpl->setVariable('EVENT_BGCOLOR', $color);
         $this->tpl->setVariable('EVENT_ADD_STYLES', $item['event']->getPresentationStyle());
         $this->tpl->setVariable('EVENT_FONTCOLOR', ilCalendarUtil::calculateFontColor($color));
         $this->tpl->parseCurrentBlock();
         $this->num_appointments++;
         $count++;
     }
     return $count;
 }
 protected function renderSlots(ilBookingSchedule $schedule, array $object_ids, $title)
 {
     global $ilUser;
     // fix
     if (!$schedule->getRaster()) {
         $mytpl = new ilTemplate('tpl.booking_reservation_fix.html', true, true, 'Modules/BookingManager');
         $mytpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this));
         $mytpl->setVariable('TXT_TITLE', $this->lng->txt('book_reservation_title'));
         $mytpl->setVariable('TXT_INFO', $this->lng->txt('book_reservation_fix_info'));
         $mytpl->setVariable('TXT_OBJECT', $title);
         $mytpl->setVariable('TXT_CMD_BOOK', $this->lng->txt('book_confirm_booking'));
         $mytpl->setVariable('TXT_CMD_CANCEL', $this->lng->txt('cancel'));
         include_once 'Services/Calendar/classes/class.ilCalendarUserSettings.php';
         $user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
         $morning_aggr = $user_settings->getDayStart();
         $evening_aggr = $user_settings->getDayEnd();
         $hours = array();
         for ($i = $morning_aggr; $i <= $evening_aggr; $i++) {
             switch ($user_settings->getTimeFormat()) {
                 case ilCalendarSettings::TIME_FORMAT_24:
                     if ($morning_aggr > 0 && $i == $morning_aggr) {
                         $hours[$i] = sprintf('%02d:00', 0) . "-";
                     }
                     $hours[$i] .= sprintf('%02d:00', $i);
                     if ($evening_aggr < 23 && $i == $evening_aggr) {
                         $hours[$i] .= "-" . sprintf('%02d:00', 23);
                     }
                     break;
                 case ilCalendarSettings::TIME_FORMAT_12:
                     if ($morning_aggr > 0 && $i == $morning_aggr) {
                         $hours[$i] = date('h a', mktime(0, 0, 0, 1, 1, 2000)) . "-";
                     }
                     $hours[$i] .= date('h a', mktime($i, 0, 0, 1, 1, 2000));
                     if ($evening_aggr < 23 && $i == $evening_aggr) {
                         $hours[$i] .= "-" . date('h a', mktime(23, 0, 0, 1, 1, 2000));
                     }
                     break;
             }
         }
         if (isset($_GET['seed'])) {
             $find_first_open = false;
             $seed = new ilDate($_GET['seed'], IL_CAL_DATE);
         } else {
             $find_first_open = true;
             $seed = new ilDate(time(), IL_CAL_UNIX);
         }
         include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
         include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
         $week_start = $user_settings->getWeekStart();
         if (!$find_first_open) {
             $dates = array();
             $this->buildDatesBySchedule($week_start, $hours, $schedule, $object_ids, $seed, $dates);
         } else {
             $dates = array();
             $has_open_slot = $this->buildDatesBySchedule($week_start, $hours, $schedule, $object_ids, $seed, $dates);
             // find first open slot
             if (!$has_open_slot) {
                 // 1 year is limit for search
                 $limit = clone $seed;
                 $limit->increment(ilDate::YEAR, 1);
                 $limit = $limit->get(IL_CAL_UNIX);
                 while (!$has_open_slot && $seed->get(IL_CAL_UNIX) < $limit) {
                     $seed->increment(ilDate::WEEK, 1);
                     $dates = array();
                     $has_open_slot = $this->buildDatesBySchedule($week_start, $hours, $schedule, $object_ids, $seed, $dates);
                 }
             }
         }
         include_once 'Services/Calendar/classes/class.ilCalendarHeaderNavigationGUI.php';
         $navigation = new ilCalendarHeaderNavigationGUI($this, $seed, ilDateTime::WEEK, 'book');
         $mytpl->setVariable('NAVIGATION', $navigation->getHTML());
         foreach (ilCalendarUtil::_buildWeekDayList($seed, $week_start)->get() as $date) {
             $date_info = $date->get(IL_CAL_FKT_GETDATE, '', 'UTC');
             $mytpl->setCurrentBlock('weekdays');
             $mytpl->setVariable('TXT_WEEKDAY', ilCalendarUtil::_numericDayToString($date_info['wday']));
             $mytpl->setVariable('TXT_DATE', $date_info['mday'] . ' ' . ilCalendarUtil::_numericMonthToString($date_info['mon']));
             $mytpl->parseCurrentBlock();
         }
         include_once 'Services/Calendar/classes/class.ilCalendarAppointmentColors.php';
         include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
         $color = array();
         $all = ilCalendarAppointmentColors::_getColorsByType('crs');
         for ($loop = 0; $loop < 7; $loop++) {
             $col = $all[$loop];
             $fnt = ilCalendarUtil::calculateFontColor($col);
             $color[$loop + 1] = 'border-bottom: 1px solid ' . $col . '; background-color: ' . $col . '; color: ' . $fnt;
         }
         $counter = 0;
         foreach ($dates as $hour => $days) {
             $caption = $days;
             $caption = array_shift($caption);
             for ($loop = 1; $loop < 8; $loop++) {
                 if (!isset($days[$loop])) {
                     $mytpl->setCurrentBlock('dates');
                     $mytpl->setVariable('DUMMY', '&nbsp;');
                     $mytpl->parseCurrentBlock();
                 } else {
                     if (isset($days[$loop]['captions'])) {
                         foreach ($days[$loop]['captions'] as $slot_id => $slot_caption) {
                             $mytpl->setCurrentBlock('choice');
                             $mytpl->setVariable('TXT_DATE', $slot_caption);
                             $mytpl->setVariable('VALUE_DATE', $slot_id);
                             $mytpl->setVariable('DATE_COLOR', $color[$loop]);
                             $mytpl->parseCurrentBlock();
                         }
                         $mytpl->setCurrentBlock('dates');
                         $mytpl->setVariable('DUMMY', '');
                         $mytpl->parseCurrentBlock();
                     } else {
                         if (isset($days[$loop]['in_slot'])) {
                             $mytpl->setCurrentBlock('dates');
                             $mytpl->setVariable('DATE_COLOR', $color[$loop]);
                             $mytpl->parseCurrentBlock();
                         } else {
                             $mytpl->setCurrentBlock('dates');
                             $mytpl->setVariable('DUMMY', '&nbsp;');
                             $mytpl->parseCurrentBlock();
                         }
                     }
                 }
             }
             $mytpl->setCurrentBlock('slots');
             $mytpl->setVariable('TXT_HOUR', $caption);
             if ($counter % 2) {
                 $mytpl->setVariable('CSS_ROW', 'tblrow1');
             } else {
                 $mytpl->setVariable('CSS_ROW', 'tblrow2');
             }
             $mytpl->parseCurrentBlock();
             $counter++;
         }
     } else {
         // :TODO: inactive for now
     }
     return $mytpl->get();
 }
 /**
  * show appointment
  *
  * @access protected
  * @param array appointment
  */
 protected function showAppointment($a_app)
 {
     global $ilUser;
     $this->tpl->setCurrentBlock('panel_code');
     $this->tpl->setVariable('NUM', $this->num_appointments);
     $this->tpl->parseCurrentBlock();
     if (!$ilUser->prefs["screen_reader_optimization"]) {
         $this->tpl->setCurrentBlock('app');
     } else {
         $this->tpl->setCurrentBlock('scrd_app');
     }
     include_once './Services/Calendar/classes/class.ilCalendarAppointmentPanelGUI.php';
     $this->tpl->setVariable('PANEL_DATA', ilCalendarAppointmentPanelGUI::_getInstance($this->seed)->getHTML($a_app));
     $this->tpl->setVariable('PANEL_NUM', $this->num_appointments);
     $this->tpl->setVariable('APP_ROWSPAN', $a_app['rowspan']);
     $this->tpl->setVariable('APP_TITLE', $a_app['event']->getPresentationTitle(false));
     switch ($this->user_settings->getTimeFormat()) {
         case ilCalendarSettings::TIME_FORMAT_24:
             $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE, 'H:i', $this->timezone);
             break;
         case ilCalendarSettings::TIME_FORMAT_12:
             $title = $a_app['event']->getStart()->get(IL_CAL_FKT_DATE, 'h:ia', $this->timezone);
             break;
     }
     // add end time for screen readers
     if ($ilUser->prefs["screen_reader_optimization"]) {
         switch ($this->user_settings->getTimeFormat()) {
             case ilCalendarSettings::TIME_FORMAT_24:
                 $title .= "-" . $a_app['event']->getEnd()->get(IL_CAL_FKT_DATE, 'H:i', $this->timezone);
                 break;
             case ilCalendarSettings::TIME_FORMAT_12:
                 $title .= "-" . $a_app['event']->getEnd()->get(IL_CAL_FKT_DATE, 'h:ia', $this->timezone);
                 break;
         }
     }
     // booking
     if ($a_app['category_type'] == ilCalendarCategory::TYPE_CH) {
         include_once 'Services/Booking/classes/class.ilBookingEntry.php';
         $entry = new ilBookingEntry($a_app['event']->getContextId());
         if ($entry) {
             $title .= ' ' . $a_app['event']->getTitle();
             if ($entry->isOwner()) {
                 $max = (int) $entry->getNumberOfBookings();
                 $current = (int) $entry->getCurrentNumberOfBookings($a_app['event']->getEntryId());
                 if ($max > 1) {
                     $title .= ' (' . $current . '/' . $max . ')';
                 } else {
                     if ($current == $max) {
                         $title .= ' (' . $this->lng->txt('cal_booked_out') . ')';
                     } else {
                         $title .= ' (' . $this->lng->txt('cal_book_free') . ')';
                     }
                 }
             } else {
                 if ($entry->hasBooked($a_app['event']->getEntryId())) {
                     $title .= ' (' . $this->lng->txt('cal_date_booked') . ')';
                 }
             }
         }
     } else {
         $title .= ' ' . $a_app['event']->getPresentationTitle(false);
     }
     $this->tpl->setVariable('APP_TITLE', $title);
     $color = $this->app_colors->getColorByAppointment($a_app['event']->getEntryId());
     $this->tpl->setVariable('APP_BGCOLOR', $color);
     $this->tpl->setVariable('APP_COLOR', ilCalendarUtil::calculateFontColor($color));
     $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
     $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
     $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
     $this->tpl->setVariable('APP_EDIT_LINK', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'edit'));
     $this->tpl->parseCurrentBlock();
     $this->num_appointments++;
 }