/**
  * Fill row
  * @staticvar int $counter
  * @param array $set 
  */
 public function fillRow($set)
 {
     global $ilCtrl;
     $ilCtrl->setParameter($this->getParentObject(), 'server_id', $set['server_id']);
     $ilCtrl->setParameterByClass('ilecsmappingsettingsgui', 'server_id', $set['server_id']);
     if ($set['active']) {
         $this->tpl->setVariable('IMAGE_OK', ilUtil::getImagePath('icon_ok.svg'));
         $this->tpl->setVariable('TXT_OK', $this->lng->txt('ecs_activated'));
     } else {
         $this->tpl->setVariable('IMAGE_OK', ilUtil::getImagePath('icon_not_ok.svg'));
         $this->tpl->setVariable('TXT_OK', $this->lng->txt('ecs_inactivated'));
     }
     $this->tpl->setVariable('VAL_TITLE', ilECSSetting::getInstanceByServerId($set['server_id'])->getTitle());
     $this->tpl->setVariable('LINK_EDIT', $ilCtrl->getLinkTarget($this->getParentObject(), 'edit'));
     $this->tpl->setVariable('TXT_SRV_ADDR', $this->lng->txt('ecs_server_addr'));
     if (ilECSSetting::getInstanceByServerId($set['server_id'])->getServer()) {
         $this->tpl->setVariable('VAL_DESC', ilECSSetting::getInstanceByServerId($set['server_id'])->getServer());
     } else {
         $this->tpl->setVariable('VAL_DESC', $this->lng->txt('ecs_not_configured'));
     }
     $dt = ilECSSetting::getInstanceByServerId($set['server_id'])->fetchCertificateExpiration();
     if ($dt != NULL) {
         $this->tpl->setVariable('TXT_CERT_VALID', $this->lng->txt('ecs_cert_valid_until'));
         $now = new ilDateTime(time(), IL_CAL_UNIX);
         $now->increment(IL_CAL_MONTH, 2);
         if (ilDateTime::_before($dt, $now)) {
             $this->tpl->setCurrentBlock('invalid');
             $this->tpl->setVariable('VAL_ICERT', ilDatePresentation::formatDate($dt));
             $this->tpl->parseCurrentBlock();
         } else {
             $this->tpl->setCurrentBlock('valid');
             $this->tpl->setVariable('VAL_VCERT', ilDatePresentation::formatDate($dt));
             $this->tpl->parseCurrentBlock();
         }
     }
     // Actions
     include_once './Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
     $list = new ilAdvancedSelectionListGUI();
     $list->setSelectionHeaderClass('small');
     $list->setItemLinkClass('small');
     $list->setId('actl_' . $set['server_id']);
     $list->setListTitle($this->lng->txt('actions'));
     if (ilECSSetting::getInstanceByServerId($set['server_id'])->isEnabled()) {
         $list->addItem($this->lng->txt('ecs_deactivate'), '', $ilCtrl->getLinkTarget($this->getParentObject(), 'deactivate'));
     } else {
         $list->addItem($this->lng->txt('ecs_activate'), '', $ilCtrl->getLinkTarget($this->getParentObject(), 'activate'));
     }
     $list->addItem($this->lng->txt('edit'), '', $ilCtrl->getLinkTarget($this->getParentObject(), 'edit'));
     $list->addItem($this->lng->txt('copy'), '', $ilCtrl->getLinkTarget($this->getParentObject(), 'cp'));
     $list->addItem($this->lng->txt('delete'), '', $ilCtrl->getLinkTarget($this->getParentObject(), 'delete'));
     $this->tpl->setVariable('ACTIONS', $list->getHTML());
     $ilCtrl->clearParameters($this->getParentObject());
 }
 /**
  * validate
  *
  * @access public
  * @return
  */
 public function validate()
 {
     global $ilErr, $lng;
     $success = true;
     $ilErr->setMessage('');
     if (!strlen($this->getTitle())) {
         $success = false;
         $ilErr->appendMessage($lng->txt('err_missing_title'));
     }
     if (ilDateTime::_before($this->getEnd(), $this->getStart(), '')) {
         $success = false;
         $ilErr->appendMessage($lng->txt('err_end_before_start'));
     }
     return $success;
 }
 /**
  * Lookup registration info
  * @global ilDB $ilDB
  * @global ilObjUser $ilUser
  * @global ilLanguage $lng
  * @param int $a_obj_id
  * @return array
  */
 public static function lookupRegistrationInfo($a_obj_id)
 {
     global $ilDB, $ilUser, $lng;
     $query = 'SELECT sub_limitation_type, sub_start, sub_end, sub_mem_limit, sub_max_members FROM crs_settings ' . 'WHERE obj_id = ' . $ilDB->quote($a_obj_id);
     $res = $ilDB->query($query);
     $info = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $info['reg_info_start'] = new ilDateTime($row->sub_start, IL_CAL_UNIX);
         $info['reg_info_end'] = new ilDateTime($row->sub_end, IL_CAL_UNIX);
         $info['reg_info_type'] = $row->sub_limitation_type;
         $info['reg_info_max_members'] = $row->sub_max_members;
         $info['reg_info_mem_limit'] = $row->sub_mem_limit;
     }
     $registration_possible = true;
     // Limited registration
     if ($info['reg_info_type'] == ilCourseConstants::SUBSCRIPTION_LIMITED) {
         $dt = new ilDateTime(time(), IL_CAL_UNIX);
         if (ilDateTime::_before($dt, $info['reg_info_start'])) {
             $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_start');
             $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_start']);
         } elseif (ilDateTime::_before($dt, $info['reg_info_end'])) {
             $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_end');
             $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_end']);
         } else {
             $registration_possible = false;
             $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_period');
             $info['reg_info_list_prop']['value'] = $lng->txt('crs_list_reg_noreg');
         }
     } else {
         if ($info['reg_info_type'] == ilCourseConstants::SUBSCRIPTION_UNLIMITED) {
             $registration_possible = true;
         } else {
             $registration_possible = false;
             $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_period');
             $info['reg_info_list_prop']['value'] = $lng->txt('crs_list_reg_noreg');
         }
     }
     if ($info['reg_info_mem_limit'] && $registration_possible) {
         // Check if users are on waiting list
         // @todo
         // Check for free places
         $part = ilCourseParticipant::_getInstanceByObjId($a_obj_id, $ilUser->getId());
         if ($part->getNumberOfMembers() <= $info['reg_info_max_members']) {
             $info['reg_info_list_prop_limit']['property'] = $lng->txt('crs_list_reg_limit_places');
             $info['reg_info_list_prop_limit']['value'] = max(0, $info['reg_info_max_members'] - $part->getNumberOfMembers());
         } else {
             $info['reg_info_list_prop_limit']['property'] = '';
             $info['reg_info_list_prop_limit']['value'] = $lng->txt('crs_list_reg_limit_full');
         }
     }
     return $info;
 }
 /**
  * Sync external calendars
  */
 protected function synchroniseExternalCalendars()
 {
     global $ilUser;
     if (!ilCalendarSettings::_getInstance()->isWebCalSyncEnabled()) {
         return false;
     }
     // @todo make this thread safe
     $limit = new ilDateTime(time(), IL_CAL_UNIX);
     $limit->increment(IL_CAL_HOUR, -1 * ilCalendarSettings::_getInstance()->getWebCalSyncHours());
     $cats = ilCalendarCategories::_getInstance($ilUser->getId());
     foreach ($cats->getCategoriesInfo() as $cat_id => $info) {
         if ($info['remote']) {
             // Check for execution
             $category = new ilCalendarCategory($cat_id);
             if (ilDateTime::_before($category->getRemoteSyncLastExecution(), $limit)) {
                 // update in any case to avoid multiple updates of invalid calendar sources.
                 $category->setRemoteSyncLastExecution(new ilDateTime(time(), IL_CAL_UNIX));
                 $category->update();
                 include_once './Services/Calendar/classes/class.ilCalendarRemoteReader.php';
                 $remote = new ilCalendarRemoteReader($category->getRemoteUrl());
                 $remote->setUser($category->getRemoteUser());
                 $remote->setPass($category->getRemotePass());
                 $remote->read();
                 $remote->import($category);
                 break;
             }
         }
     }
 }
 /**
  * Lookup registration info
  * @global ilDB $ilDB
  * @global ilObjUser $ilUser
  * @global ilLanguage $lng
  * @param int $a_obj_id
  * @return array
  */
 public static function lookupRegistrationInfo($a_obj_id)
 {
     global $ilDB, $ilUser, $lng;
     $query = 'SELECT registration_type, registration_enabled, registration_unlimited,  registration_start, ' . 'registration_end, registration_mem_limit, registration_max_members FROM grp_settings ' . 'WHERE obj_id = ' . $ilDB->quote($a_obj_id);
     $res = $ilDB->query($query);
     $info = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $info['reg_info_start'] = new ilDateTime($row->registration_start, IL_CAL_DATETIME);
         $info['reg_info_end'] = new ilDateTime($row->registration_end, IL_CAL_DATETIME);
         $info['reg_info_type'] = $row->registration_type;
         $info['reg_info_max_members'] = $row->registration_max_members;
         $info['reg_info_mem_limit'] = $row->registration_mem_limit;
         $info['reg_info_unlimited'] = $row->registration_unlimited;
         $info['reg_info_max_members'] = 0;
         if ($info['reg_info_mem_limit']) {
             $info['reg_info_max_members'] = $row->registration_max_members;
         }
         $info['reg_info_enabled'] = $row->registration_enabled;
     }
     $registration_possible = $info['reg_info_enabled'];
     // Limited registration (added $registration_possible, see bug 0010157)
     if (!$info['reg_info_unlimited'] && $registration_possible) {
         $dt = new ilDateTime(time(), IL_CAL_UNIX);
         if (ilDateTime::_before($dt, $info['reg_info_start'])) {
             $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_start');
             $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_start']);
         } elseif (ilDateTime::_before($dt, $info['reg_info_end'])) {
             $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_end');
             $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_end']);
         } else {
             $registration_possible = false;
             $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_period');
             $info['reg_info_list_prop']['value'] = $lng->txt('grp_list_reg_noreg');
         }
     } else {
         // added !$registration_possible, see bug 0010157
         if (!$registration_possible) {
             $registration_possible = false;
             $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_period');
             $info['reg_info_list_prop']['value'] = $lng->txt('grp_list_reg_noreg');
         }
     }
     if ($info['reg_info_mem_limit'] && $registration_possible) {
         // Check if users are on waiting list
         // @todo
         // Check for free places
         include_once './Modules/Group/classes/class.ilGroupParticipants.php';
         $part = ilGroupParticipants::_getInstanceByObjId($a_obj_id);
         if ($part->getCountMembers() <= $info['reg_info_max_members']) {
             $info['reg_info_list_prop_limit']['property'] = $lng->txt('grp_list_reg_limit_places');
             $info['reg_info_list_prop_limit']['value'] = max(0, $info['reg_info_max_members'] - $part->getCountMembers());
         } else {
             $info['reg_info_list_prop_limit']['property'] = '';
             $info['reg_info_list_prop_limit']['value'] = $lng->txt('grp_list_reg_limit_full');
         }
     }
     return $info;
 }
 /**
  * get the data for a users overview table
  * 
  * @return	array	list of box data
  */
 public function getOverviewData()
 {
     $data = array();
     // get the basic box data
     for ($box = 0; $box <= $this->getLastBox(); $box++) {
         $data[$box] = array("box" => (int) $box, "capacity" => (int) $this->getBoxCapacity($box), "count" => (int) $this->countCardsInBox($box), "last_trained" => new ilDateTime());
     }
     // get the last trained date of all boxes
     // for each box this is taken from the latest last trained date
     // of all cards with box as last status
     foreach ((array) $this->getUsedCards() as $usage) {
         $box = $usage->getLastStatus();
         if (isset($data[$box]) and ilDateTime::_before($data[$box]["last_trained"], $usage->getLastChecked())) {
             $data[$box]["last_trained"] = $usage->getLastChecked();
         }
     }
     return array_values($data);
 }
 /**
  * Check whether an date is within a date duration given by start and end
  * @param ilDateTime $dt
  * @param ilDateTime $start
  * @param ilDateTime $end
  * @param type $a_compare_field
  * @param type $a_tz
  */
 public static function _within(ilDateTime $dt, ilDateTime $start, ilDateTime $end, $a_compare_field = '', $a_tz = '')
 {
     return (ilDateTime::_after($dt, $start, $a_compare_field, $a_tz) or ilDateTime::_equals($dt, $start, $a_compare_field, $a_tz)) && (ilDateTime::_before($dt, $end, $a_compare_field, $a_tz) or ilDateTime::_equals($dt, $end, $a_compare_field, $a_tz));
 }
 /**
  * get activation
  *
  * @return	boolean		true/false for active or not
  */
 function getActive($a_check_scheduled_activation = false)
 {
     if ($a_check_scheduled_activation && !$this->active) {
         include_once "./Services/Calendar/classes/class.ilDateTime.php";
         $start = new ilDateTime($this->getActivationStart(), IL_CAL_DATETIME);
         $end = new ilDateTime($this->getActivationEnd(), IL_CAL_DATETIME);
         $now = new ilDateTime(time(), IL_CAL_UNIX);
         if (!ilDateTime::_before($now, $start) && !ilDateTime::_after($now, $end)) {
             return true;
         }
     }
     return $this->active;
 }
 /**
  * Apply limits (count or until)
  *
  * @access protected
  * @param object ilDateList
  * 
  */
 protected function applyLimits(ilDateList $list)
 {
     $list->sort();
     #echo "list: ";
     #echo $list;
     #echo '<br />';
     // Check valid dates before starting time
     foreach ($list->get() as $check_date) {
         if (ilDateTime::_before($check_date, $this->event->getStart(), IL_CAL_DAY)) {
             #echo 'Removed: '.$check_date.'<br/>';
             $list->remove($check_date);
         }
     }
     #echo 'Until date '.$this->recurrence->getFrequenceUntilDate();
     // Check count if given
     if ($this->recurrence->getFrequenceUntilCount()) {
         foreach ($list->get() as $res) {
             // check smaller than since the start time counts as one
             if (count($this->valid_dates->get()) < $this->recurrence->getFrequenceUntilCount()) {
                 $this->valid_dates->add($res);
             } else {
                 $this->limit_reached = true;
                 return false;
             }
         }
         return true;
     } elseif ($this->recurrence->getFrequenceUntilDate()) {
         #echo 'Until date '.$this->recurrence->getFrequenceUntilDate();
         $date = $this->recurrence->getFrequenceUntilDate();
         foreach ($list->get() as $res) {
             #echo 'Check date '.$res;
             if (ilDateTime::_after($res, $date, IL_CAL_DAY)) {
                 #echo 'Limit reached';
                 $this->limit_reached = true;
                 return false;
             }
             $this->valid_dates->add($res);
         }
         return true;
     }
     $this->valid_dates->merge($list);
     return true;
 }
 /**
  * Save object
  * @access    public
  */
 public function save()
 {
     /**
      * @var $rbacsystem    $rbacsystem
      * @var $lng           $lng
      * @var $objDefinition ilObjectDefinition
      */
     global $rbacsystem, $objDefinition, $lng;
     $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
     // create permission is already checked in createObject. This check here is done to prevent hacking attempts
     if (!$rbacsystem->checkAccess("create", (int) $_GET["ref_id"], $new_type)) {
         $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
     }
     $this->ctrl->setParameter($this, "new_type", $new_type);
     if (isset($_POST['tpl_id']) && (int) $_POST['tpl_id'] > 0) {
         $tpl_id = (int) $_POST['tpl_id'];
     } else {
         $this->ilias->raiseError($this->lng->txt("no_template_id_given"), $this->ilias->error_obj->MESSAGE);
     }
     include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
     $templates = ilSettingsTemplate::getAllSettingsTemplates("xavc");
     foreach ($templates as $template) {
         if ($template['id'] == $tpl_id) {
             $form = $this->initCreateForm($template);
             $selected_template = $template;
             $template_settings = array();
             if ($template['id']) {
                 $objTemplate = new ilSettingsTemplate($template['id']);
                 $template_settings = $objTemplate->getSettings();
             }
         }
     }
     if ($form->checkInput()) {
         if ($form->getInput('creation_type') == 'existing_vc' && $template_settings['reuse_existing_rooms']['hide'] == '0') {
             try {
                 $location = $objDefinition->getLocation($new_type);
                 $this->pluginObj->includeClass('class.ilAdobeConnectUserUtil.php');
                 $ilAdobeConnectUser = new ilAdobeConnectUserUtil($this->user->getId());
                 $xavc_login = $ilAdobeConnectUser->getXAVCLogin();
                 $folder_id = $ilAdobeConnectUser->ensureUserFolderExistance($xavc_login);
                 $sco_ids = ilObjAdobeConnect::getScosByFolderId($folder_id);
                 $title = $sco_ids[$form->getInput('available_rooms')]['sco_name'];
                 $description = $sco_ids[$form->getInput('available_rooms')]['description'];
                 // create and insert object in objecttree
                 $class_name = "ilObj" . $objDefinition->getClassName($new_type);
                 include_once $location . "/class." . $class_name . ".php";
                 /** @var $newObj ilObjAdobeConnect */
                 $newObj = new $class_name();
                 $newObj->setType($new_type);
                 $newObj->setTitle(ilUtil::stripSlashes($title));
                 $newObj->setDescription(ilUtil::stripSlashes($description));
                 $newObj->create();
                 $newObj->createReference();
                 $newObj->putInTree($_GET["ref_id"]);
                 $newObj->setPermissions($_GET["ref_id"]);
                 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
                 $this->afterSave($newObj);
                 return;
             } catch (Exception $e) {
                 ilUtil::sendFailure($e->getMessage(), true);
             }
         } else {
             global $ilUser;
             $owner = $ilUser->getId();
             if (strlen($form->getInput('owner')) > 1) {
                 if (ilObjUser::_lookupId($form->getInput('owner')) > 0) {
                     $owner = ilObjUser::_lookupId($form->getInput('owner'));
                 } else {
                     ilUtil::sendFailure($this->lng->txt('user_not_found'));
                     $owner = 0;
                 }
             }
             if ($template_settings['duration']['hide'] == '1') {
                 $durationValid = true;
             } else {
                 if ($form->getInput('time_type_selection') == 'permanent_room' && ilAdobeConnectServer::getSetting('enable_perm_room', '1')) {
                     $duration['hh'] = 2;
                     $duration['mm'] = 0;
                 } else {
                     $duration = $form->getInput("duration");
                 }
                 if ($duration['hh'] * 60 + $duration['mm'] < 10) {
                     $form->getItemByPostVar('duration')->setAlert($this->pluginObj->txt('min_duration_error'));
                     $durationValid = false;
                 } else {
                     $durationValid = true;
                 }
             }
             if ($template_settings['start_date']['hide'] == '1') {
                 $time_mismatch = false;
             } else {
                 if ($durationValid) {
                     require_once dirname(__FILE__) . '/class.ilAdobeConnectServer.php';
                     $serverConfig = ilAdobeConnectServer::_getInstance();
                     $minTime = new ilDateTime(time() + $serverConfig->getScheduleLeadTime() * 60 * 60, IL_CAL_UNIX);
                     $newStartDate = $form->getItemByPostVar("start_date")->getDate();
                     $time_mismatch = false;
                     if (ilDateTime::_before($newStartDate, $minTime) && $form->getInput('time_type_selection') != 'permanent_room') {
                         ilUtil::sendFailure(sprintf($this->pluginObj->txt('xavc_lead_time_mismatch_create'), ilDatePresentation::formatDate($minTime)), true);
                         $time_mismatch = true;
                     }
                 }
             }
             if (!$time_mismatch && $owner > 0) {
                 try {
                     if ($durationValid) {
                         $location = $objDefinition->getLocation($new_type);
                         // create and insert object in objecttree
                         $class_name = "ilObj" . $objDefinition->getClassName($new_type);
                         include_once $location . "/class." . $class_name . ".php";
                         /** @var $newObj ilObjAdobeConnect */
                         $newObj = new $class_name();
                         $newObj->setType($new_type);
                         $newObj->setTitle(ilUtil::stripSlashes($_POST["title"]));
                         $newObj->setDescription(ilUtil::stripSlashes($_POST["desc"]));
                         $newObj->setOwner($owner);
                         $newObj->create();
                         $newObj->createReference();
                         $newObj->putInTree($_GET["ref_id"]);
                         $newObj->setPermissions($_GET["ref_id"]);
                         ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
                         $this->afterSave($newObj);
                         return;
                     }
                 } catch (Exception $e) {
                     ilUtil::sendFailure($e->getMessage(), true);
                 }
             }
         }
         $form->setValuesByPost();
         if (ilAdobeConnectServer::getSetting('show_free_slots')) {
             $this->showCreationForm($form);
         } else {
             $this->tpl->setContent($form->getHtml());
         }
     } else {
         $form->setValuesByPost();
         $this->tpl->setContent($form->getHTML());
         return;
     }
 }
 /**
  * Get subitems of container
  * @param bool $a_admin_panel_enabled[optional]
  * @param bool $a_include_side_block[optional]
  * @return array 
  */
 public function getSubItems($a_admin_panel_enabled = false, $a_include_side_block = false)
 {
     global $ilUser;
     // Caching
     if (is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block])) {
         return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
     }
     // Results are stored in $this->items
     parent::getSubItems($a_admin_panel_enabled, $a_include_side_block);
     // No sessions
     if (!is_array($this->items['sess']) or !$this->items['sess']) {
         return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
     }
     // No session limit
     if (!$this->isSessionLimitEnabled() or $a_admin_panel_enabled) {
         return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
     }
     if ($a_include_side_block) {
         return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
     }
     // @todo move to gui class
     if (isset($_GET['crs_prev_sess'])) {
         $ilUser->writePref('crs_sess_show_prev_' . $this->getId(), (string) (int) $_GET['crs_prev_sess']);
     }
     if (isset($_GET['crs_next_sess'])) {
         $ilUser->writePref('crs_sess_show_next_' . $this->getId(), (string) (int) $_GET['crs_next_sess']);
     }
     $sessions = ilUtil::sortArray($this->items['sess'], 'start', 'ASC', true, false);
     $today = new ilDate(date('Ymd', time()), IL_CAL_DATE);
     $previous = $current = $next = array();
     foreach ($sessions as $key => $item) {
         $start = new ilDateTime($item['start'], IL_CAL_UNIX);
         $end = new ilDateTime($item['end'], IL_CAL_UNIX);
         if (ilDateTime::_within($today, $start, $end, IL_CAL_DAY)) {
             $current[] = $item;
         } elseif (ilDateTime::_before($start, $today, IL_CAL_DAY)) {
             $previous[] = $item;
         } elseif (ilDateTime::_after($start, $today, IL_CAL_DAY)) {
             $next[] = $item;
         }
     }
     $num_previous_remove = max(count($previous) - $this->getNumberOfPreviousSessions(), 0);
     while ($num_previous_remove--) {
         if (!$ilUser->getPref('crs_sess_show_prev_' . $this->getId())) {
             array_shift($previous);
         }
         $this->items['sess_link']['prev']['value'] = 1;
     }
     $num_next_remove = max(count($next) - $this->getNumberOfNextSessions(), 0);
     while ($num_next_remove--) {
         if (!$ilUser->getPref('crs_sess_show_next_' . $this->getId())) {
             array_pop($next);
         }
         // @fixme
         $this->items['sess_link']['next']['value'] = 1;
     }
     $sessions = array_merge($previous, $current, $next);
     $this->items['sess'] = $sessions;
     $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block] = $this->items;
     return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
 }
 /**
  * show informations about the registration period
  *
  * @access protected
  */
 protected function fillRegistrationPeriod()
 {
     include_once './Services/Calendar/classes/class.ilDateTime.php';
     $now = new ilDateTime(time(), IL_CAL_UNIX, 'UTC');
     if ($this->container->getSubscriptionUnlimitedStatus()) {
         $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_period'));
         $reg->setValue($this->lng->txt('mem_unlimited'));
         $this->form->addItem($reg);
         return true;
     } elseif ($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED) {
         return true;
     }
     $start = new ilDateTime($this->container->getSubscriptionStart(), IL_CAL_UNIX, 'UTC');
     $end = new ilDateTime($this->container->getSubscriptionEnd(), IL_CAL_UNIX, 'UTC');
     if (ilDateTime::_before($now, $start)) {
         $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'Services/Membership');
         $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_start'));
         $tpl->setVariable('FIRST', ilDatePresentation::formatDate($start));
         $tpl->setVariable('TXT_END', $this->lng->txt('mem_end'));
         $tpl->setVariable('END', ilDatePresentation::formatDate($end));
         $warning = $this->lng->txt('mem_reg_not_started');
     } elseif (ilDateTime::_after($now, $end)) {
         $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'Services/Membership');
         $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_start'));
         $tpl->setVariable('FIRST', ilDatePresentation::formatDate($start));
         $tpl->setVariable('TXT_END', $this->lng->txt('mem_end'));
         $tpl->setVariable('END', ilDatePresentation::formatDate($end));
         $warning = $this->lng->txt('mem_reg_expired');
     } else {
         $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'Services/Membership');
         $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_end'));
         $tpl->setVariable('FIRST', ilDatePresentation::formatDate($end));
     }
     $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
     $reg->setHtml($tpl->get());
     if (strlen($warning)) {
         // Disable registration
         $this->enableRegistration(false);
         ilUtil::sendFailure($warning);
         #$reg->setAlert($warning);
     }
     $this->form->addItem($reg);
     return true;
 }
 /**
  * fill data section
  *
  * @access public
  * 
  */
 public function show()
 {
     global $tpl, $ilUser;
     $this->tpl = new ilTemplate('tpl.month_view.html', true, true, 'Services/Calendar');
     include_once './Services/YUI/classes/class.ilYuiUtil.php';
     ilYuiUtil::initDragDrop();
     ilYuiUtil::initPanel();
     $navigation = new ilCalendarHeaderNavigationGUI($this, $this->seed, ilDateTime::MONTH);
     $this->tpl->setVariable('NAVIGATION', $navigation->getHTML());
     for ($i = (int) $this->user_settings->getWeekStart(); $i < 7 + (int) $this->user_settings->getWeekStart(); $i++) {
         $this->tpl->setCurrentBlock('month_header_col');
         $this->tpl->setVariable('TXT_WEEKDAY', ilCalendarUtil::_numericDayToString($i, true));
         $this->tpl->parseCurrentBlock();
     }
     if (isset($_GET["bkid"])) {
         $user_id = $_GET["bkid"];
         $disable_empty = true;
         $no_add = true;
     } else {
         if ($ilUser->getId() == ANONYMOUS_USER_ID) {
             $user_id = $ilUser->getId();
             $disable_empty = false;
             $no_add = true;
         } else {
             $user_id = $ilUser->getId();
             $disable_empty = false;
             $no_add = false;
         }
     }
     $is_portfolio_embedded = false;
     if (ilCalendarCategories::_getInstance()->getMode() == ilCalendarCategories::MODE_PORTFOLIO_CONSULTATION) {
         $no_add = true;
         $is_portfolio_embedded = true;
     }
     include_once 'Services/Calendar/classes/class.ilCalendarSchedule.php';
     $this->scheduler = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_MONTH, $user_id);
     $this->scheduler->addSubitemCalendars(true);
     if (sizeof($this->schedule_filters)) {
         foreach ($this->schedule_filters as $filter) {
             $this->scheduler->addFilter($filter);
         }
     }
     $this->scheduler->calculate();
     include_once 'Services/Calendar/classes/class.ilCalendarSettings.php';
     $settings = ilCalendarSettings::_getInstance();
     $counter = 0;
     foreach (ilCalendarUtil::_buildMonthDayList($this->seed->get(IL_CAL_FKT_DATE, 'm'), $this->seed->get(IL_CAL_FKT_DATE, 'Y'), $this->user_settings->getWeekStart())->get() as $date) {
         $counter++;
         $has_events = (bool) $this->showEvents($date);
         if (!$no_add) {
             include_once "Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php";
             $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
             $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'idate', $date->get(IL_CAL_DATE));
             $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
             $new_app_url = $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'add');
             if ($settings->getEnableGroupMilestones()) {
                 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
                 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
                 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'idate', $date->get(IL_CAL_DATE));
                 $new_ms_url = $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'addMilestone');
                 $this->tpl->setCurrentBlock("new_ms");
                 $this->tpl->setVariable('DD_ID', $date->get(IL_CAL_UNIX));
                 $this->tpl->setVariable('DD_TRIGGER', ilGlyphGUI::get(ilGlyphGUI::ADD));
                 $this->tpl->setVariable('URL_DD_NEW_APP', $new_app_url);
                 $this->tpl->setVariable('TXT_DD_NEW_APP', $this->lng->txt('cal_new_app'));
                 $this->tpl->setVariable('URL_DD_NEW_MS', $new_ms_url);
                 $this->tpl->setVariable('TXT_DD_NEW_MS', $this->lng->txt('cal_new_ms'));
                 $this->tpl->parseCurrentBlock();
             } else {
                 $this->tpl->setCurrentBlock("new_app");
                 $this->tpl->setVariable('ADD_LINK', $new_app_url);
                 $this->tpl->setVariable('NEW_SRC', ilGlyphGUI::get(ilGlyphGUI::ADD, $this->lng->txt('cal_new_app')));
                 $this->tpl->parseCurrentBlock();
             }
         }
         $day = $date->get(IL_CAL_FKT_DATE, 'j');
         $month = $date->get(IL_CAL_FKT_DATE, 'n');
         if ($day == 1) {
             $month_day = '1 ' . ilCalendarUtil::_numericMonthToString($month, false);
         } else {
             $month_day = $day;
         }
         if (!$is_portfolio_embedded && (!$disable_empty || $has_events)) {
             $this->tpl->setCurrentBlock('month_day_link');
             $this->ctrl->clearParametersByClass('ilcalendardaygui');
             $this->ctrl->setParameterByClass('ilcalendardaygui', 'seed', $date->get(IL_CAL_DATE));
             $this->tpl->setVariable('OPEN_DAY_VIEW', $this->ctrl->getLinkTargetByClass('ilcalendardaygui', ''));
             $this->ctrl->clearParametersByClass('ilcalendardaygui');
         } else {
             $this->tpl->setCurrentBlock('month_day_no_link');
         }
         $this->tpl->setVariable('MONTH_DAY', $month_day);
         $this->tpl->parseCurrentBlock();
         $this->tpl->setCurrentBlock('month_col');
         include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
         if (ilCalendarUtil::_isToday($date)) {
             $this->tpl->setVariable('TD_CLASS', 'caltoday');
         } elseif (ilDateTime::_equals($date, $this->seed, IL_CAL_MONTH)) {
             $this->tpl->setVariable('TD_CLASS', 'calstd');
         } elseif (ilDateTime::_before($date, $this->seed, IL_CAL_MONTH)) {
             $this->tpl->setVariable('TD_CLASS', 'calprev');
         } else {
             $this->tpl->setVariable('TD_CLASS', 'calnext');
         }
         $this->tpl->parseCurrentBlock();
         if ($counter and !($counter % 7)) {
             $this->tpl->setCurrentBlock('month_row');
             $this->tpl->parseCurrentBlock();
         }
     }
 }
Exemple #14
0
 /**
  * @see ilMembershipRegistrationCodes::register()
  * @param int user_id
  * @param int role
  * @param bool force registration and do not check registration constraints.
  */
 public function register($a_user_id, $a_role = IL_GRP_MEMBER, $a_force_registration = false)
 {
     include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
     include_once "./Modules/Group/classes/class.ilGroupParticipants.php";
     $part = ilGroupParticipants::_getInstanceByObjId($this->getId());
     if ($part->isAssigned($a_user_id)) {
         return true;
     }
     if (!$a_force_registration) {
         // Availability
         if (!$this->isRegistrationEnabled()) {
             include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
             if (!ilObjGroupAccess::_usingRegistrationCode()) {
                 throw new ilMembershipRegistrationException('Cant registrate to group ' . $this->getId() . ', group subscription is deactivated.', '456');
             }
         }
         // Time Limitation
         if (!$this->isRegistrationUnlimited()) {
             $start = $this->getRegistrationStart();
             $end = $this->getRegistrationEnd();
             $time = new ilDateTime(time(), IL_CAL_UNIX);
             if (!(ilDateTime::_after($time, $start) and ilDateTime::_before($time, $end))) {
                 throw new ilMembershipRegistrationException('Cant registrate to group ' . $this->getId() . ', group is out of registration time.', '789');
             }
         }
         // Max members
         if ($this->isMembershipLimited()) {
             $free = max(0, $this->getMaxMembers() - $part->getCountMembers());
             include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
             $waiting_list = new ilGroupWaitingList($this->getId());
             if ($this->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers())) {
                 $this->lng->loadLanguageModule("grp");
                 $waiting_list->addToList($a_user_id);
                 $info = sprintf($this->lng->txt('grp_added_to_list'), $this->getTitle(), $waiting_list->getPosition($a_user_id));
                 include_once './Modules/Group/classes/class.ilGroupParticipants.php';
                 include_once './Modules/Group/classes/class.ilGroupMembershipMailNotification.php';
                 $participants = ilGroupParticipants::_getInstanceByObjId($this->getId());
                 $participants->sendNotification(ilGroupMembershipMailNotification::TYPE_WAITING_LIST_MEMBER, $a_user_id);
                 throw new ilMembershipRegistrationException($info, '124');
             }
             if (!$free or $waiting_list->getCountUsers()) {
                 throw new ilMembershipRegistrationException('Cant registrate to group ' . $this->getId() . ', membership is limited.', '123');
             }
         }
     }
     $part->add($a_user_id, $a_role);
     $part->sendNotification($part->TYPE_NOTIFICATION_REGISTRATION, $a_user_id);
     return true;
 }
 /**
  * Check if value matches
  * @param	mixed	$a_value	Econtent value
  * @param	int		$a_type		Parameter type
  * @return
  */
 protected function matchesValue($a_value, $a_type)
 {
     global $ilLog;
     switch ($a_type) {
         case self::ATTR_ARRAY:
             $values = explode(',', $a_value);
             $ilLog->write(__METHOD__ . ': Checking for value: ' . $a_value);
             $ilLog->write(__METHOD__ . ': Checking against attribute values: ' . $this->getMappingValue());
             break;
         case self::ATTR_INT:
             $ilLog->write(__METHOD__ . ': Checking for value: ' . $a_value);
             $ilLog->write(__METHOD__ . ': Checking against attribute values: ' . $this->getMappingValue());
             $values = array($a_value);
             break;
         case self::ATTR_STRING:
             $values = array($a_value);
             break;
     }
     $values = explode(',', $a_value);
     foreach ($values as $value) {
         $value = trim($value);
         switch ($this->getMappingType()) {
             case self::TYPE_FIXED:
                 foreach ($this->getMappingAsArray() as $attribute_value) {
                     $attribute_value = trim($attribute_value);
                     if (strcasecmp($attribute_value, $value) == 0) {
                         return true;
                     }
                 }
                 break;
             case self::TYPE_DURATION:
                 include_once './Services/Calendar/classes/class.ilDateTime.php';
                 $tmp_date = new ilDate($a_value, IL_CAL_UNIX);
                 return ilDateTime::_after($tmp_date, $this->getDateRangeStart()) and ilDateTime::_before($tmp_date, $this->getDateRangeEnd());
         }
     }
     return false;
 }
 /**
  * Add mini version of monthly overview
  * (Maybe extracted to another class, if used in pd calendar tab
  */
 function addMiniMonth($a_tpl)
 {
     global $ilCtrl, $lng, $ilUser;
     // weekdays
     include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
     $a_tpl->setCurrentBlock('month_header_col');
     $a_tpl->setVariable('TXT_WEEKDAY', $lng->txt("cal_week_abbrev"));
     $a_tpl->parseCurrentBlock();
     for ($i = (int) $this->user_settings->getWeekStart(); $i < 7 + (int) $this->user_settings->getWeekStart(); $i++) {
         $a_tpl->setCurrentBlock('month_header_col');
         $a_tpl->setVariable('TXT_WEEKDAY', ilCalendarUtil::_numericDayToString($i, false));
         $a_tpl->parseCurrentBlock();
     }
     include_once 'Services/Calendar/classes/class.ilCalendarSchedule.php';
     $this->scheduler = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_MONTH);
     $this->scheduler->calculate();
     $counter = 0;
     foreach (ilCalendarUtil::_buildMonthDayList($this->seed->get(IL_CAL_FKT_DATE, 'm'), $this->seed->get(IL_CAL_FKT_DATE, 'Y'), $this->user_settings->getWeekStart())->get() as $date) {
         $counter++;
         //$this->showEvents($date);
         $a_tpl->setCurrentBlock('month_col');
         if (count($this->scheduler->getByDay($date, $ilUser->getTimeZone()))) {
             $a_tpl->setVariable('DAY_CLASS', 'calminiapp');
             #$a_tpl->setVariable('TD_CLASS','calminiapp');
         }
         include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
         if (ilCalendarUtil::_isToday($date)) {
             $a_tpl->setVariable('TD_CLASS', 'calminitoday');
         } elseif (ilDateTime::_equals($date, $this->seed, IL_CAL_MONTH)) {
             $a_tpl->setVariable('TD_CLASS', 'calministd');
         } elseif (ilDateTime::_before($date, $this->seed, IL_CAL_MONTH)) {
             $a_tpl->setVariable('TD_CLASS', 'calminiprev');
         } else {
             $a_tpl->setVariable('TD_CLASS', 'calmininext');
         }
         $day = $date->get(IL_CAL_FKT_DATE, 'j');
         $month = $date->get(IL_CAL_FKT_DATE, 'n');
         $month_day = $day;
         $ilCtrl->clearParametersByClass('ilcalendardaygui');
         $ilCtrl->setParameterByClass('ilcalendardaygui', 'seed', $date->get(IL_CAL_DATE));
         $a_tpl->setVariable('OPEN_DAY_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendardaygui', ''));
         $ilCtrl->clearParametersByClass('ilcalendardaygui');
         $a_tpl->setVariable('MONTH_DAY', $month_day);
         //$this->tpl->setVariable('NEW_SRC',ilUtil::getImagePath('new.png','calendar'));
         //$this->tpl->setVariable('NEW_ALT',$this->lng->txt('cal_new_app'));
         //$this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
         //$this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$date->get(IL_CAL_DATE));
         //$this->tpl->setVariable('ADD_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
         //$this->tpl->setVariable('OPEN_SRC',ilUtil::getImagePath('open.png','calendar'));
         $a_tpl->parseCurrentBlock();
         if ($counter and !($counter % 7)) {
             $a_tpl->setCurrentBlock('month_row');
             $ilCtrl->clearParametersByClass('ilcalendarweekgui');
             $ilCtrl->setParameterByClass('ilcalendarweekgui', 'seed', $date->get(IL_CAL_DATE));
             $a_tpl->setVariable('OPEN_WEEK_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendarweekgui', ''));
             $ilCtrl->clearParametersByClass('ilcalendarweekgui');
             $a_tpl->setVariable('TD_CLASS', 'calminiweek');
             $a_tpl->setVariable('WEEK', $date->get(IL_CAL_FKT_DATE, 'W'));
             $a_tpl->parseCurrentBlock();
         }
     }
     $a_tpl->setCurrentBlock('mini_month');
     $a_tpl->setVariable('TXT_MONTH_OVERVIEW', $lng->txt("cal_month_overview"));
     $a_tpl->setVariable('TXT_MONTH', $lng->txt('month_' . $this->seed->get(IL_CAL_FKT_DATE, 'm') . '_long') . ' ' . $this->seed->get(IL_CAL_FKT_DATE, 'Y'));
     $myseed = clone $this->seed;
     $ilCtrl->setParameterByClass('ilcalendarmonthgui', 'seed', $myseed->get(IL_CAL_DATE));
     $a_tpl->setVariable('OPEN_MONTH_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendarmonthgui', ''));
     $myseed->increment(ilDateTime::MONTH, -1);
     $ilCtrl->setParameter($this->getParentObject(), 'seed', $myseed->get(IL_CAL_DATE));
     //$a_tpl->setVariable('BL_TYPE', $this->getBlockType());
     //$a_tpl->setVariable('BL_ID', $this->getBlockId());
     $a_tpl->setVariable('PREV_MONTH', $ilCtrl->getLinkTarget($this->getParentObject(), ""));
     $myseed->increment(ilDateTime::MONTH, 2);
     $ilCtrl->setParameter($this->getParentObject(), 'seed', $myseed->get(IL_CAL_DATE));
     $a_tpl->setVariable('NEXT_MONTH', $ilCtrl->getLinkTarget($this->getParentObject(), ""));
     $ilCtrl->setParameter($this->getParentObject(), 'seed', "");
     $a_tpl->parseCurrentBlock();
 }
 /**
  * Add mini version of monthly overview
  * (Maybe extracted to another class, if used in pd calendar tab
  */
 function addMiniMonth($a_tpl)
 {
     global $ilCtrl, $lng, $ilUser;
     // weekdays
     include_once 'Services/Calendar/classes/class.ilCalendarUtil.php';
     $a_tpl->setCurrentBlock('month_header_col');
     $a_tpl->setVariable('TXT_WEEKDAY', $lng->txt("cal_week_abbrev"));
     $a_tpl->parseCurrentBlock();
     for ($i = (int) $this->user_settings->getWeekStart(); $i < 7 + (int) $this->user_settings->getWeekStart(); $i++) {
         $a_tpl->setCurrentBlock('month_header_col');
         $a_tpl->setVariable('TXT_WEEKDAY', ilCalendarUtil::_numericDayToString($i, false));
         $a_tpl->parseCurrentBlock();
     }
     if (isset($_GET["bkid"])) {
         $user_id = $_GET["bkid"];
         $disable_empty = true;
     } else {
         $user_id = $ilUser->getId();
         $disable_empty = false;
     }
     include_once 'Services/Calendar/classes/class.ilCalendarSchedule.php';
     $this->scheduler = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_MONTH, $user_id);
     $this->scheduler->addSubitemCalendars(true);
     $this->scheduler->calculate();
     $counter = 0;
     foreach (ilCalendarUtil::_buildMonthDayList($this->seed->get(IL_CAL_FKT_DATE, 'm'), $this->seed->get(IL_CAL_FKT_DATE, 'Y'), $this->user_settings->getWeekStart())->get() as $date) {
         $counter++;
         $events = $this->scheduler->getByDay($date, $ilUser->getTimeZone());
         $has_events = (bool) count($events);
         if ($has_events || !$disable_empty) {
             $a_tpl->setCurrentBlock('month_col_link');
         } else {
             $a_tpl->setCurrentBlock('month_col_no_link');
         }
         if ($disable_empty) {
             if (!$has_events) {
                 $a_tpl->setVariable('DAY_CLASS', 'calminiinactive');
             } else {
                 $week_has_events = true;
                 include_once 'Services/Booking/classes/class.ilBookingEntry.php';
                 foreach ($events as $event) {
                     $booking = new ilBookingEntry($event['event']->getContextId());
                     if ($booking->hasBooked($event['event']->getEntryId())) {
                         $a_tpl->setVariable('DAY_CLASS', 'calminiapp');
                         break;
                     }
                 }
             }
         } elseif ($has_events) {
             $week_has_events = true;
             $a_tpl->setVariable('DAY_CLASS', 'calminiapp');
         }
         $day = $date->get(IL_CAL_FKT_DATE, 'j');
         $month = $date->get(IL_CAL_FKT_DATE, 'n');
         $month_day = $day;
         $ilCtrl->clearParametersByClass('ilcalendardaygui');
         $ilCtrl->setParameterByClass('ilcalendardaygui', 'seed', $date->get(IL_CAL_DATE));
         $a_tpl->setVariable('OPEN_DAY_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendardaygui', ''));
         $ilCtrl->clearParametersByClass('ilcalendardaygui');
         $a_tpl->setVariable('MONTH_DAY', $month_day);
         $a_tpl->parseCurrentBlock();
         $a_tpl->setCurrentBlock('month_col');
         include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
         if (ilCalendarUtil::_isToday($date)) {
             $a_tpl->setVariable('TD_CLASS', 'calminitoday');
         } elseif (ilDateTime::_equals($date, $this->seed, IL_CAL_MONTH)) {
             $a_tpl->setVariable('TD_CLASS', 'calministd');
         } elseif (ilDateTime::_before($date, $this->seed, IL_CAL_MONTH)) {
             $a_tpl->setVariable('TD_CLASS', 'calminiprev');
         } else {
             $a_tpl->setVariable('TD_CLASS', 'calmininext');
         }
         $a_tpl->parseCurrentBlock();
         if ($counter and !($counter % 7)) {
             if (!$disable_empty || $week_has_events) {
                 $a_tpl->setCurrentBlock('month_row_link');
                 $ilCtrl->clearParametersByClass('ilcalendarweekgui');
                 $ilCtrl->setParameterByClass('ilcalendarweekgui', 'seed', $date->get(IL_CAL_DATE));
                 $a_tpl->setVariable('OPEN_WEEK_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendarweekgui', ''));
                 $ilCtrl->clearParametersByClass('ilcalendarweekgui');
             } else {
                 $a_tpl->setCurrentBlock('month_row_no_link');
                 $a_tpl->setVariable('WEEK_CLASS', 'calminiinactive');
             }
             $a_tpl->setVariable('WEEK', $date->get(IL_CAL_FKT_DATE, 'W'));
             $a_tpl->parseCurrentBlock();
             $a_tpl->setCurrentBlock('month_row');
             $a_tpl->setVariable('TD_CLASS', 'calminiweek');
             $a_tpl->parseCurrentBlock();
             $week_has_events = false;
         }
     }
     $a_tpl->setCurrentBlock('mini_month');
     $a_tpl->setVariable('TXT_MONTH_OVERVIEW', $lng->txt("cal_month_overview"));
     $a_tpl->setVariable('TXT_MONTH', $lng->txt('month_' . $this->seed->get(IL_CAL_FKT_DATE, 'm') . '_long') . ' ' . $this->seed->get(IL_CAL_FKT_DATE, 'Y'));
     $myseed = clone $this->seed;
     $ilCtrl->setParameterByClass('ilcalendarmonthgui', 'seed', $myseed->get(IL_CAL_DATE));
     $a_tpl->setVariable('OPEN_MONTH_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendarmonthgui', ''));
     $myseed->increment(ilDateTime::MONTH, -1);
     $ilCtrl->setParameter($this, 'seed', $myseed->get(IL_CAL_DATE));
     $a_tpl->setVariable('BL_TYPE', $this->getBlockType());
     $a_tpl->setVariable('BL_ID', $this->getBlockId());
     $a_tpl->setVariable('PREV_MONTH', $ilCtrl->getLinkTarget($this, "setSeed"));
     $a_tpl->setVariable('PREV_MONTH_ASYNC', $ilCtrl->getLinkTarget($this, "setSeed", "", true));
     $myseed->increment(ilDateTime::MONTH, 2);
     $ilCtrl->setParameter($this, 'seed', $myseed->get(IL_CAL_DATE));
     $a_tpl->setVariable('NEXT_MONTH', $ilCtrl->getLinkTarget($this, "setSeed"));
     $a_tpl->setVariable('NEXT_MONTH_ASYNC', $ilCtrl->getLinkTarget($this, "setSeed", "", true));
     $ilCtrl->setParameter($this, 'seed', "");
     $a_tpl->parseCurrentBlock();
 }
 /**
  * Query usr_data
  * @return array ('cnt', 'set') 
  */
 public function query()
 {
     global $ilDB;
     $ut_join = "";
     if (is_array($this->additional_fields)) {
         foreach ($this->additional_fields as $f) {
             if (!in_array($f, $this->default_fields)) {
                 if ($f == "online_time") {
                     $this->default_fields[] = "ut_online.online_time";
                     $ut_join = " LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id";
                 } else {
                     $this->default_fields[] = $f;
                 }
             }
         }
     }
     // count query
     $count_query = "SELECT count(usr_id) cnt" . " FROM usr_data";
     $all_multi_fields = array("interests_general", "interests_help_offered", "interests_help_looking");
     $multi_fields = array();
     $sql_fields = array();
     foreach ($this->default_fields as $idx => $field) {
         if (!$field) {
             continue;
         }
         if (in_array($field, $all_multi_fields)) {
             $multi_fields[] = $field;
         } else {
             if (!stristr($field, ".")) {
                 $sql_fields[] = "usr_data." . $field;
             } else {
                 $sql_fields[] = $field;
             }
         }
     }
     // basic query
     $query = "SELECT " . implode($sql_fields, ",") . " FROM usr_data" . $ut_join;
     // filter
     $query .= " WHERE usr_data.usr_id <> " . $ilDB->quote(ANONYMOUS_USER_ID, "integer");
     // User filter
     if ($this->users and is_array($this->users)) {
         $query .= ' AND ' . $ilDB->in('usr_data.usr_id', $this->users, false, 'integer');
     }
     $count_query .= " WHERE usr_data.usr_id <> " . $ilDB->quote(ANONYMOUS_USER_ID, "integer");
     $where = " AND";
     if ($this->first_letter != "") {
         $add = $where . " (" . $ilDB->upper($ilDB->substr("usr_data.lastname", 1, 1)) . " = " . $ilDB->upper($ilDB->quote($this->first_letter, "text")) . ") ";
         $query .= $add;
         $count_query .= $add;
         $where = " AND";
     }
     if ($this->text_filter != "") {
         $add = $where . " (" . $ilDB->like("usr_data.login", "text", "%" . $this->text_filter . "%") . " " . "OR " . $ilDB->like("usr_data.firstname", "text", "%" . $this->text_filter . "%") . " " . "OR " . $ilDB->like("usr_data.lastname", "text", "%" . $this->text_filter . "%") . " " . "OR " . $ilDB->like("usr_data.email", "text", "%" . $this->text_filter . "%") . ") ";
         $query .= $add;
         $count_query .= $add;
         $where = " AND";
     }
     if ($this->activation != "") {
         if ($this->activation == "inactive") {
             $add = $where . " usr_data.active = " . $ilDB->quote(0, "integer") . " ";
         } else {
             $add = $where . " usr_data.active = " . $ilDB->quote(1, "integer") . " ";
         }
         $query .= $add;
         $count_query .= $add;
         $where = " AND";
     }
     if ($this->last_login instanceof ilDateTime) {
         if (ilDateTime::_before($this->last_login, new ilDateTime(time(), IL_CAL_UNIX), IL_CAL_DAY)) {
             $add = $where . " usr_data.last_login < " . $ilDB->quote($this->last_login->get(IL_CAL_DATETIME), "timestamp");
             $query .= $add;
             $count_query .= $add;
             $where = " AND";
         }
     }
     if ($this->limited_access) {
         $add = $where . " usr_data.time_limit_unlimited= " . $ilDB->quote(0, "integer");
         $query .= $add;
         $count_query .= $add;
         $where = " AND";
     }
     if ($this->no_courses) {
         $add = $where . " usr_data.usr_id NOT IN (" . "SELECT DISTINCT ud.usr_id " . "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) " . "JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) " . "WHERE od.title LIKE 'il_crs_%')";
         $query .= $add;
         $count_query .= $add;
         $where = " AND";
     }
     if ($this->no_groups) {
         $add = $where . " usr_data.usr_id NOT IN (" . "SELECT DISTINCT ud.usr_id " . "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) " . "JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) " . "WHERE od.title LIKE 'il_grp_%')";
         $query .= $add;
         $count_query .= $add;
         $where = " AND";
     }
     if ($this->crs_grp > 0) {
         $cgtype = ilObject::_lookupType($this->crs_grp, true);
         $add = $where . " usr_data.usr_id IN (" . "SELECT DISTINCT ud.usr_id " . "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) " . "JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) " . "WHERE od.title = " . $ilDB->quote("il_" . $cgtype . "_member_" . $this->crs_grp, "text") . ")";
         $query .= $add;
         $count_query .= $add;
         $where = " AND";
     }
     if ($this->role > 0) {
         $add = $where . " usr_data.usr_id IN (" . "SELECT DISTINCT ud.usr_id " . "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) " . "WHERE rbac_ua.rol_id = " . $ilDB->quote($this->role, "integer") . ")";
         $query .= $add;
         $count_query .= $add;
         $where = " AND";
     }
     if ($this->user_folder) {
         $add = $where . " " . $ilDB->in('usr_data.time_limit_owner', $this->user_folder, false, 'integer');
         $query .= $add;
         $count_query .= $add;
         $where = " AND";
     }
     // order by
     switch ($this->order_field) {
         case "access_until":
             if ($this->order_dir == "desc") {
                 $query .= " ORDER BY usr_data.active DESC, usr_data.time_limit_unlimited DESC, usr_data.time_limit_until DESC";
             } else {
                 $query .= " ORDER BY usr_data.active ASC, usr_data.time_limit_unlimited ASC, usr_data.time_limit_until ASC";
             }
             break;
         case "online_time":
             if ($this->order_dir == "desc") {
                 $query .= " ORDER BY ut_online.online_time DESC";
             } else {
                 $query .= " ORDER BY ut_online.online_time ASC";
             }
             break;
         default:
             if (!in_array($this->order_field, $this->default_fields)) {
                 $this->order_field = "login";
             }
             if ($this->order_dir != "asc" && $this->order_dir != "desc") {
                 $this->order_dir = "asc";
             }
             $query .= " ORDER BY usr_data." . $this->order_field . " " . strtoupper($this->order_dir);
             break;
     }
     // count query
     $set = $ilDB->query($count_query);
     $cnt = 0;
     if ($rec = $ilDB->fetchAssoc($set)) {
         $cnt = $rec["cnt"];
     }
     $offset = (int) $this->offset;
     $limit = (int) $this->limit;
     // #9866: validate offset against rowcount
     if ($offset >= $cnt) {
         $offset = 0;
     }
     $ilDB->setLimit($limit, $offset);
     if (sizeof($multi_fields)) {
         $usr_ids = array();
     }
     // set query
     $set = $ilDB->query($query);
     $result = array();
     while ($rec = $ilDB->fetchAssoc($set)) {
         $result[] = $rec;
         if (sizeof($multi_fields)) {
             $usr_ids[] = $rec["usr_id"];
         }
     }
     // add multi-field-values to user-data
     if (sizeof($multi_fields) && sizeof($usr_ids)) {
         $usr_multi = array();
         $set = $ilDB->query("SELECT * FROM usr_data_multi" . " WHERE " . $ilDB->in("usr_id", $usr_ids, "", "integer"));
         while ($row = $ilDB->fetchAssoc($set)) {
             $usr_multi[$row["usr_id"]][$row["field_id"]][] = $row["value"];
         }
         foreach ($result as $idx => $item) {
             if (isset($usr_multi[$item["usr_id"]])) {
                 $result[$idx] = array_merge($item, $usr_multi[$item["usr_id"]]);
             }
         }
     }
     return array("cnt" => $cnt, "set" => $result);
 }
 public static function getOpenRoomBooking($a_group_id)
 {
     $now = new ilDateTime(time(), IL_CAL_UNIX);
     $earlier = clone $now;
     $later = clone $now;
     $later->increment(IL_CAL_DAY, 5);
     $booking = self::lookupNextBooking($earlier, $later, $a_group_id);
     if (!$booking['open'] instanceof ilDateTime) {
         return 0;
     }
     if (ilDateTime::_before($booking['open'], $now) and ilDateTime::_after($booking['closed'], $now)) {
         return $booking['id'];
     }
     return 0;
 }
 /**
  * validate group settings
  *
  * @access public
  * @return bool
  */
 public function validate()
 {
     global $ilErr;
     if (!$this->getTitle()) {
         $this->title = '';
         $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_TITLE));
     }
     if (!$this->getGroupType()) {
         $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_GROUP_TYPE));
     }
     if ($this->getRegistrationType() == GRP_REGISTRATION_PASSWORD and !strlen($this->getPassword())) {
         $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_PASSWORD));
     }
     if (ilDateTime::_before($this->getRegistrationEnd(), $this->getRegistrationStart())) {
         $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_REG_TIME_LIMIT));
     }
     if ($this->isMembershipLimited() and (!is_numeric($this->getMaxMembers()) or $this->getMaxMembers() <= 0)) {
         $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MAX_MEMBERS));
     }
     return strlen($ilErr->getMessage()) == 0;
 }
 /**
  * Get subitems of container
  * @param bool $a_admin_panel_enabled[optional]
  * @param bool $a_include_side_block[optional]
  * @return array 
  */
 public function getSubItems($a_admin_panel_enabled = false, $a_include_side_block = false)
 {
     global $ilUser;
     // Caching
     if (is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block])) {
         return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
     }
     // Results are stored in $this->items
     parent::getSubItems($a_admin_panel_enabled, $a_include_side_block);
     $limit_sess = false;
     if (!$a_admin_panel_enabled && !$a_include_side_block && $this->items['sess'] && is_array($this->items['sess']) && $this->isSessionLimitEnabled() && $this->getViewMode() == ilContainer::VIEW_SESSIONS) {
         $limit_sess = true;
     }
     if (!$limit_sess) {
         return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
     }
     // do session limit
     // @todo move to gui class
     if (isset($_GET['crs_prev_sess'])) {
         $ilUser->writePref('crs_sess_show_prev_' . $this->getId(), (string) (int) $_GET['crs_prev_sess']);
     }
     if (isset($_GET['crs_next_sess'])) {
         $ilUser->writePref('crs_sess_show_next_' . $this->getId(), (string) (int) $_GET['crs_next_sess']);
     }
     $sessions = ilUtil::sortArray($this->items['sess'], 'start', 'ASC', true, false);
     $today = new ilDate(date('Ymd', time()), IL_CAL_DATE);
     $previous = $current = $next = array();
     foreach ($sessions as $key => $item) {
         $start = new ilDateTime($item['start'], IL_CAL_UNIX);
         $end = new ilDateTime($item['end'], IL_CAL_UNIX);
         if (ilDateTime::_within($today, $start, $end, IL_CAL_DAY)) {
             $current[] = $item;
         } elseif (ilDateTime::_before($start, $today, IL_CAL_DAY)) {
             $previous[] = $item;
         } elseif (ilDateTime::_after($start, $today, IL_CAL_DAY)) {
             $next[] = $item;
         }
     }
     $num_previous_remove = max(count($previous) - $this->getNumberOfPreviousSessions(), 0);
     while ($num_previous_remove--) {
         if (!$ilUser->getPref('crs_sess_show_prev_' . $this->getId())) {
             array_shift($previous);
         }
         $this->items['sess_link']['prev']['value'] = 1;
     }
     $num_next_remove = max(count($next) - $this->getNumberOfNextSessions(), 0);
     while ($num_next_remove--) {
         if (!$ilUser->getPref('crs_sess_show_next_' . $this->getId())) {
             array_pop($next);
         }
         // @fixme
         $this->items['sess_link']['next']['value'] = 1;
     }
     $sessions = array_merge($previous, $current, $next);
     $this->items['sess'] = $sessions;
     // #15389 - see ilContainer::getSubItems()
     include_once 'Services/Container/classes/class.ilContainerSorting.php';
     $sort = ilContainerSorting::_getInstance($this->getId());
     $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block] = $sort->sortItems($this->items);
     return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
 }
 /**
  * cancel calendar booking for user
  * @param	int	$a_entry_id
  * @param	int	$a_user_id
  */
 public function cancelBooking($a_entry_id, $a_user_id = false)
 {
     global $ilUser, $ilDB;
     if (!$a_user_id) {
         $a_user_id = $ilUser->getId();
     }
     // @todo do not send mails about past consultation hours
     $entry = new ilCalendarEntry($a_entry_id);
     $past = ilDateTime::_before($entry->getStart(), new ilDateTime(time(), IL_CAL_UNIX));
     if ($this->hasBooked($a_entry_id, $a_user_id) && !$past) {
         include_once 'Services/Calendar/classes/class.ilCalendarMailNotification.php';
         $mail = new ilCalendarMailNotification();
         $mail->setAppointmentId($a_entry_id);
         $mail->setRecipients(array($a_user_id));
         $mail->setType(ilCalendarMailNotification::TYPE_BOOKING_CANCELLATION);
         $mail->send();
     }
     $this->deleteBooking($a_entry_id, $a_user_id);
     return true;
 }