/**
  * init categories
  *
  * @access protected
  * @param
  * @return
  */
 protected function initCategories()
 {
     include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
     if (ilCalendarUserSettings::_getInstance()->getCalendarSelectionType() == ilCalendarUserSettings::CAL_SELECTION_MEMBERSHIP) {
         $this->mode = ilCalendarCategories::MODE_PERSONAL_DESKTOP_MEMBERSHIP;
     } else {
         $this->mode = ilCalendarCategories::MODE_PERSONAL_DESKTOP_ITEMS;
     }
     include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
     ilCalendarCategories::_getInstance()->initialize($this->mode, (int) $_GET['ref_id'], true);
 }
 /**
  * Constructor
  *
  * @access public
  * @param
  * 
  */
 public function __construct()
 {
     global $ilCtrl, $lng, $tpl, $ilTabs, $ilUser;
     $this->ctrl = $ilCtrl;
     $this->lng = $lng;
     $this->lng->loadLanguageModule('dateplaner');
     $this->tpl = $tpl;
     $this->tabs_gui = $ilTabs;
     include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
     $cats = ilCalendarCategories::_getInstance($ilUser->getId());
     include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
     if (ilCalendarUserSettings::_getInstance()->getCalendarSelectionType() == ilCalendarUserSettings::CAL_SELECTION_MEMBERSHIP) {
         $cats->initialize(ilCalendarCategories::MODE_PERSONAL_DESKTOP_MEMBERSHIP);
     } else {
         $cats->initialize(ilCalendarCategories::MODE_PERSONAL_DESKTOP_ITEMS);
     }
 }
 /**
  * init mini-calendar
  *
  * Used to display personal appointments and bookings in the minicalendar
  * copied from ilPDBlockCalendar
  *
  * @access protected
  */
 private function initCalendar()
 {
     global $ilUser;
     include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
     $cats = ilCalendarCategories::_getInstance($ilUser->getId());
     include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
     if (ilCalendarUserSettings::_getInstance()->getCalendarSelectionType() == ilCalendarUserSettings::CAL_SELECTION_MEMBERSHIP) {
         $cats->initialize(ilCalendarCategories::MODE_PERSONAL_DESKTOP_MEMBERSHIP);
     } else {
         $cats->initialize(ilCalendarCategories::MODE_PERSONAL_DESKTOP_ITEMS);
     }
     //if there was no calendar-category before or the calendar was deleted
     $categoriesInfo = $cats->getCategoriesInfo();
     if ($this->cal_cat_id == 0 || !isset($categoriesInfo[$this->cal_cat_id])) {
         //create a new calendar-category
         $this->cal_cat_id = $this->createBookingsCalendarCategory();
     }
 }
 /**
  * Constructor
  */
 function ilCalendarSelectionBlockGUI($a_seed)
 {
     global $ilCtrl, $lng;
     $this->lng = $lng;
     parent::__construct();
     $lng->loadLanguageModule('pd');
     $lng->loadLanguageModule('dateplaner');
     $this->setLimit(5);
     $this->allow_moving = false;
     $this->seed = $a_seed;
     $this->setTitle($lng->txt('cal_table_categories'));
     include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
     $sel_type = ilCalendarUserSettings::_getInstance()->getCalendarSelectionType();
     $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'calendar_mode', ilCalendarUserSettings::CAL_SELECTION_ITEMS);
     $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'seed', $this->seed->get(IL_CAL_DATE));
     $this->addBlockCommand($ilCtrl->getLinkTargetByClass("ilcalendarcategorygui", 'switchCalendarMode'), $lng->txt('pd_my_offers'), "", "", false, $sel_type == ilCalendarUserSettings::CAL_SELECTION_ITEMS);
     $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'calendar_mode', ilCalendarUserSettings::CAL_SELECTION_MEMBERSHIP);
     $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'seed', $this->seed->get(IL_CAL_DATE));
     $this->addBlockCommand($ilCtrl->getLinkTargetByClass("ilcalendarcategorygui", 'switchCalendarMode'), $lng->txt('pd_my_memberships'), "", "", false, $sel_type == ilCalendarUserSettings::CAL_SELECTION_MEMBERSHIP);
     $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'calendar_mode', "");
     $this->addBlockCommand($ilCtrl->getLinkTargetByClass("ilcalendarcategorygui", 'add'), $lng->txt('cal_add_calendar'));
 }
 /**
  * Switch calendar selection nmode 
  * @return
  */
 protected function switchCalendarMode()
 {
     include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
     ilCalendarUserSettings::_getInstance()->setCalendarSelectionType((int) $_GET['calendar_mode']);
     ilCalendarUserSettings::_getInstance()->save();
     $this->ctrl->returnToParent($this);
 }
 /**
  * initialize visible categories
  *
  * @access public
  * @param int mode 
  * @param int ref_id of root node
  * @return
  */
 public function initialize($a_mode, $a_source_ref_id = 0, $a_use_cache = false)
 {
     $this->setMode($a_mode);
     if ($a_use_cache) {
         // Read categories from cache
         if ($cats = ilCalendarCache::getInstance()->getEntry($this->user_id . ':' . $a_mode . ':categories:' . (int) $a_source_ref_id)) {
             if ($this->getMode() != self::MODE_CONSULTATION && $this->getMode() != self::MODE_PORTFOLIO_CONSULTATION) {
                 $this->wakeup($cats);
                 return;
             }
         }
     }
     switch ($this->getMode()) {
         case self::MODE_REMOTE_ACCESS:
             include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
             if (ilCalendarUserSettings::_getInstance()->getCalendarSelectionType() == ilCalendarUserSettings::CAL_SELECTION_MEMBERSHIP) {
                 $this->readPDCalendars();
             } else {
                 $this->readSelectedItemCalendars();
             }
             break;
         case self::MODE_REMOTE_SELECTED:
             $this->readSelectedCalendar($a_source_ref_id);
             break;
         case self::MODE_PERSONAL_DESKTOP_MEMBERSHIP:
             $this->readPDCalendars();
             break;
         case self::MODE_PERSONAL_DESKTOP_ITEMS:
             $this->readSelectedItemCalendars();
             break;
         case self::MODE_REPOSITORY:
             $this->root_ref_id = $a_source_ref_id;
             $this->root_obj_id = ilObject::_lookupObjId($this->root_ref_id);
             $this->readReposCalendars();
             break;
         case self::MODE_MANAGE:
             $this->readPDCalendars();
             $this->readSelectedItemCalendars();
             break;
         case self::MODE_CONSULTATION:
             #$this->readPrivateCalendars();
             $this->setTargetRefId($a_source_ref_id);
             $this->readConsultationHoursCalendar($a_source_ref_id);
             break;
         case self::MODE_PORTFOLIO_CONSULTATION:
             $this->readConsultationHoursCalendar();
             break;
     }
     if ($a_use_cache) {
         // Store in cache
         ilCalendarCache::getInstance()->storeEntry($this->user_id . ':' . $a_mode . ':categories:' . (int) $a_source_ref_id, $this->sleep(), $this->user_id, $a_mode, 'categories');
     }
 }
 /**
  * Insert property html
  *
  */
 function render()
 {
     global $lng, $ilUser;
     $tpl = new ilTemplate("tpl.prop_datetime.html", true, true, "Services/Form");
     if (is_object($this->getDate())) {
         $date_info = $this->getDate()->get(IL_CAL_FKT_GETDATE, '', 'UTC');
     } else {
         $date_info = array('year' => $_POST[$this->getPostVar()]['date']['y'], 'mon' => $_POST[$this->getPostVar()]['date']['m'], 'mday' => $_POST[$this->getPostVar()]['date']['d']);
     }
     $lng->loadLanguageModule("jscalendar");
     require_once "./Services/Calendar/classes/class.ilCalendarUtil.php";
     ilCalendarUtil::initJSCalendar();
     if (strlen($this->getActivationPostVar())) {
         $tpl->setCurrentBlock('prop_date_activation');
         $tpl->setVariable('CHECK_ENABLED_DATE', $this->getActivationPostVar());
         $tpl->setVariable('TXT_DATE_ENABLED', $this->activation_title);
         $tpl->setVariable('CHECKED_ENABLED', $this->activation_checked ? 'checked="checked"' : '');
         $tpl->setVariable('CHECKED_DISABLED', $this->getDisabled() ? 'disabled="disabled" ' : '');
         $tpl->parseCurrentBlock();
     }
     if ($this->getShowDate()) {
         $tpl->setCurrentBlock("prop_date");
         $tpl->setVariable("IMG_DATE_CALENDAR", ilUtil::getImagePath("calendar.png"));
         $tpl->setVariable("TXT_DATE_CALENDAR", $lng->txt("open_calendar"));
         $tpl->setVariable("DATE_ID", $this->getPostVar());
         $tpl->setVariable("INPUT_FIELDS_DATE", $this->getPostVar() . "[date]");
         include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
         $tpl->setVariable('DATE_FIRST_DAY', ilCalendarUserSettings::_getInstance()->getWeekStart());
         $tpl->setVariable("DATE_SELECT", ilUtil::makeDateSelect($this->getPostVar() . "[date]", $date_info['year'], $date_info['mon'], $date_info['mday'], $this->startyear, true, array('disabled' => $this->getDisabled()), $this->getShowEmpty()));
         $tpl->parseCurrentBlock();
     }
     return $tpl->get();
 }
 /**
  * Insert property html
  *
  */
 function render()
 {
     global $lng, $ilUser;
     $tpl = new ilTemplate("tpl.prop_datetime.html", true, true, "Services/Form");
     $lng->loadLanguageModule("jscalendar");
     require_once "./Services/Calendar/classes/class.ilCalendarUtil.php";
     ilCalendarUtil::initJSCalendar();
     if (strlen($this->getActivationPostVar())) {
         $tpl->setCurrentBlock('prop_date_activation');
         $tpl->setVariable('CHECK_ENABLED_DATE', $this->getActivationPostVar());
         $tpl->setVariable('TXT_DATE_ENABLED', $this->activation_title);
         $tpl->setVariable('CHECKED_ENABLED', $this->activation_checked ? 'checked="checked"' : '');
         $tpl->setVariable('CHECKED_DISABLED', $this->getDisabled() ? 'disabled="disabled" ' : '');
         $tpl->parseCurrentBlock();
     }
     if ($this->getMode() == self::MODE_SELECT) {
         if (is_a($this->getDate(), 'ilDate')) {
             $date_info = $this->getDate()->get(IL_CAL_FKT_GETDATE, '', 'UTC');
         } elseif (is_a($this->getDate(), 'ilDateTime')) {
             $date_info = $this->getDate()->get(IL_CAL_FKT_GETDATE, '', $ilUser->getTimeZone());
         } else {
             $this->setDate(new ilDateTime(time(), IL_CAL_UNIX));
             $date_info = $this->getDate()->get(IL_CAL_FKT_GETDATE, '', $ilUser->getTimeZone());
         }
         // display invalid input again
         if (is_array($this->invalid_input)) {
             $date_info['year'] = $this->invalid_input['y'];
             $date_info['mon'] = $this->invalid_input['m'];
             $date_info['mday'] = $this->invalid_input['d'];
         }
     }
     if ($this->getMode() == self::MODE_SELECT) {
         $tpl->setCurrentBlock("prop_date_input_select_setup");
         $tpl->setVariable("INPUT_FIELDS_DATE", $this->getPostVar() . "[date]");
         $tpl->parseCurrentBlock();
         $tpl->setCurrentBlock("prop_date");
         $tpl->setVariable("DATE_SELECT", ilUtil::makeDateSelect($this->getPostVar() . "[date]", $date_info['year'], $date_info['mon'], $date_info['mday'], $this->startyear, true, array('disabled' => $this->getDisabled()), $this->getShowEmpty()));
     } else {
         $value = $this->getDate();
         if ($value) {
             $value = substr($this->getDate()->get(IL_CAL_DATETIME), 0, 10);
             $day = substr($value, 8, 2);
             $month = substr($value, 5, 2);
             $year = substr($value, 0, 4);
         }
         switch ($ilUser->getDateFormat()) {
             case ilCalendarSettings::DATE_FORMAT_DMY:
                 if ($value) {
                     $value = date("d.m.Y", mktime(0, 0, 0, $month, $day, $year));
                 }
                 $format = "%d.%m.%Y";
                 $input_hint = $lng->txt("dd_mm_yyyy");
                 break;
             case ilCalendarSettings::DATE_FORMAT_YMD:
                 if ($value) {
                     $value = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));
                 }
                 $format = "%Y-%m-%d";
                 $input_hint = $lng->txt("yyyy_mm_dd");
                 break;
             case ilCalendarSettings::DATE_FORMAT_MDY:
                 if ($value) {
                     $value = date("m/d/Y", mktime(0, 0, 0, $month, $day, $year));
                 }
                 $format = "%m/%d/%Y";
                 $input_hint = $lng->txt("mm_dd_yyyy");
                 break;
         }
         $tpl->setCurrentBlock("prop_date_input_field");
         $tpl->setVariable("DATE_ID", $this->getPostVar());
         $tpl->setVariable("DATE_VALUE", $value);
         $tpl->setVariable("DISABLED", $this->getDisabled() ? " disabled=\"disabled\"" : "");
         $tpl->parseCurrentBlock();
         $tpl->setCurrentBlock("prop_date_input_field_info");
         $tpl->setVariable("TXT_INPUT_FORMAT", $input_hint);
         $tpl->parseCurrentBlock();
         $tpl->setCurrentBlock("prop_date_input_field_setup");
         $tpl->setVariable("DATE_ID", $this->getPostVar());
         $tpl->setVariable("DATE_FIELD_FORMAT", $format);
         $tpl->parseCurrentBlock();
     }
     $tpl->setCurrentBlock("prop_date");
     include_once "./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php";
     $tpl->setVariable("IMG_DATE_CALENDAR", ilGlyphGUI::get(ilGlyphGUI::CALENDAR, $lng->txt("open_calendar")));
     $tpl->setVariable("DATE_ID", $this->getPostVar());
     include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
     $tpl->setVariable('DATE_FIRST_DAY', ilCalendarUserSettings::_getInstance()->getWeekStart());
     $tpl->parseCurrentBlock();
     if ($this->getShowTime()) {
         if ($this->getMode() == self::MODE_INPUT) {
             $value = $this->getDate();
             if ($value) {
                 if (!$this->getShowSeconds()) {
                     $value = substr($value->get(IL_CAL_DATETIME), 11, 5);
                     if ($ilUser->getTimeFormat() == ilCalendarSettings::TIME_FORMAT_12) {
                         $value = date("g:ia", mktime(substr($value, 0, 2), substr($value, 3, 2)));
                     }
                 } else {
                     $value = substr($value->get(IL_CAL_DATETIME), 11, 8);
                     if ($ilUser->getTimeFormat() == ilCalendarSettings::TIME_FORMAT_12) {
                         $value = date("g:i:sa", mktime(substr($value, 0, 2), substr($value, 3, 2), substr($value, 6, 2)));
                     }
                 }
             }
             $tpl->setCurrentBlock("prop_time_input_field");
             $tpl->setVariable("DATE_ID", $this->getPostVar());
             $tpl->setVariable("TIME_VALUE", $value);
             $tpl->setVariable("DISABLED", $this->getDisabled() ? " disabled=\"disabled\"" : "");
             $tpl->parseCurrentBlock();
         }
         $tpl->setCurrentBlock("prop_time");
         if ($this->getMode() == self::MODE_SELECT) {
             $tpl->setVariable("TIME_SELECT", ilUtil::makeTimeSelect($this->getPostVar() . "[time]", !$this->getShowSeconds(), $date_info['hours'], $date_info['minutes'], $date_info['seconds'], true, array('minute_steps' => $this->getMinuteStepSize(), 'disabled' => $this->getDisabled())));
         }
         $tpl->setVariable("TXT_TIME", $this->getShowSeconds() ? "(" . $lng->txt("hh_mm_ss") . ")" : "(" . $lng->txt("hh_mm") . ")");
         $tpl->parseCurrentBlock();
     }
     return $tpl->get();
 }
 /**
  * Insert property html
  *
  */
 public function render()
 {
     global $lng, $ilUser;
     $tpl = new ilTemplate("tpl.prop_datetime_duration.html", true, true, "Services/Form");
     // Init start
     if (is_a($this->getStart(), 'ilDate')) {
         $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE, '', 'UTC');
     } elseif (is_a($this->getStart(), 'ilDateTime')) {
         $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE, '', $ilUser->getTimeZone());
     } else {
         $this->setStart(new ilDateTime(time(), IL_CAL_UNIX));
         $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE, '', $ilUser->getTimeZone());
     }
     // display invalid input again
     if (is_array($this->invalid_input['start'])) {
         $start_info['year'] = $this->invalid_input['start']['y'];
         $start_info['mon'] = $this->invalid_input['start']['m'];
         $start_info['mday'] = $this->invalid_input['start']['d'];
     }
     // Init end
     if (is_a($this->getEnd(), 'ilDate')) {
         $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE, '', 'UTC');
     } elseif (is_a($this->getEnd(), 'ilDateTime')) {
         $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE, '', $ilUser->getTimeZone());
     } else {
         $this->setEnd(new ilDateTime(time(), IL_CAL_UNIX));
         $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE, '', $ilUser->getTimeZone());
     }
     // display invalid input again
     if (is_array($this->invalid_input['end'])) {
         $end_info['year'] = $this->invalid_input['end']['y'];
         $end_info['mon'] = $this->invalid_input['end']['m'];
         $end_info['mday'] = $this->invalid_input['end']['d'];
     }
     $lng->loadLanguageModule("jscalendar");
     require_once "./Services/Calendar/classes/class.ilCalendarUtil.php";
     ilCalendarUtil::initJSCalendar();
     if (strlen($this->getActivationPostVar())) {
         $tpl->setCurrentBlock('prop_date_activation');
         $tpl->setVariable('CHECK_ENABLED_DATE', $this->getActivationPostVar());
         $tpl->setVariable('TXT_DATE_ENABLED', $this->activation_title);
         $tpl->setVariable('CHECKED_ENABLED', $this->activation_checked ? 'checked="checked"' : '');
         $tpl->setVariable('CHECKED_DISABLED', $this->getDisabled() ? 'disabled="disabled" ' : '');
         $tpl->parseCurrentBlock();
     }
     if (strlen($this->getStartText())) {
         $tpl->setVariable('TXT_START', $this->getStartText());
     }
     if (strlen($this->getEndText())) {
         $tpl->setVariable('TXT_END', $this->getEndText());
     }
     // Toggle fullday
     if ($this->enabledToggleFullTime()) {
         $tpl->setCurrentBlock('toggle_fullday');
         $tpl->setVariable('FULLDAY_POSTVAR', $this->getPostVar());
         $tpl->setVariable('FULLDAY_TOGGLE_NAME', $this->getPostVar() . '[fulltime]');
         $tpl->setVariable('FULLDAY_TOGGLE_CHECKED', $this->toggle_fulltime_checked ? 'checked="checked"' : '');
         $tpl->setVariable('FULLDAY_TOGGLE_DISABLED', $this->getDisabled() ? 'disabled="disabled"' : '');
         $tpl->setVariable('TXT_TOGGLE_FULLDAY', $this->toggle_fulltime_txt);
         $tpl->parseCurrentBlock();
     }
     $tpl->setVariable('POST_VAR', $this->getPostVar());
     include_once "./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php";
     $tpl->setVariable("IMG_START_CALENDAR", ilGlyphGUI::get(ilGlyphGUI::CALENDAR, $lng->txt("open_calendar")));
     $tpl->setVariable("START_ID", $this->getPostVar());
     $tpl->setVariable("DATE_ID_START", $this->getPostVar());
     $tpl->setVariable("INPUT_FIELDS_START", $this->getPostVar() . "[start][date]");
     include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
     $tpl->setVariable('DATE_FIRST_DAY', ilCalendarUserSettings::_getInstance()->getWeekStart());
     $tpl->setVariable("START_SELECT", ilUtil::makeDateSelect($this->getPostVar() . "[start][date]", $start_info['year'], $start_info['mon'], $start_info['mday'], $this->getStartYear(), true, array('disabled' => $this->getDisabled(), 'select_attributes' => array('onchange' => 'ilUpdateEndDate();')), $this->getShowEmpty()));
     include_once "./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php";
     $tpl->setVariable("IMG_END_CALENDAR", ilGlyphGUI::get(ilGlyphGUI::CALENDAR, $lng->txt("open_calendar")));
     $tpl->setVariable("END_ID", $this->getPostVar());
     $tpl->setVariable("DATE_ID_END", $this->getPostVar());
     $tpl->setVariable("INPUT_FIELDS_END", $this->getPostVar() . "[end][date]");
     $tpl->setVariable("END_SELECT", ilUtil::makeDateSelect($this->getPostVar() . "[end][date]", $end_info['year'], $end_info['mon'], $end_info['mday'], $this->getStartYear(), true, array('disabled' => $this->getDisabled()), $this->getShowEmpty()));
     if ($this->getShowTime()) {
         $tpl->setCurrentBlock("show_start_time");
         $tpl->setVariable("START_TIME_SELECT", ilUtil::makeTimeSelect($this->getPostVar() . "[start][time]", !$this->getShowSeconds(), $start_info['hours'], $start_info['minutes'], $start_info['seconds'], true, array('minute_steps' => $this->getMinuteStepSize(), 'disabled' => $this->getDisabled(), 'select_attributes' => array('onchange' => 'ilUpdateEndDate();'))));
         $tpl->setVariable("TXT_START_TIME", $this->getShowSeconds() ? "(" . $lng->txt("hh_mm_ss") . ")" : "(" . $lng->txt("hh_mm") . ")");
         $tpl->parseCurrentBlock();
         $tpl->setCurrentBlock("show_end_time");
         $tpl->setVariable("END_TIME_SELECT", ilUtil::makeTimeSelect($this->getPostVar() . "[end][time]", !$this->getShowSeconds(), $end_info['hours'], $end_info['minutes'], $end_info['seconds'], true, array('minute_steps' => $this->getMinuteStepSize(), 'disabled' => $this->getDisabled())));
         $tpl->setVariable("TXT_END_TIME", $this->getShowSeconds() ? "(" . $lng->txt("hh_mm_ss") . ")" : "(" . $lng->txt("hh_mm") . ")");
         $tpl->parseCurrentBlock();
     }
     if ($this->getShowTime()) {
         $tpl->setVariable("DELIM", "<br />");
     }
     return $tpl->get();
 }