/**
  * Check if course allocation is activated for one recipient of the 
  * @param ilECSSetting $server
  * @param type $a_content_id
  */
 public function checkAllocationActivation(ilECSSetting $server, $a_content_id)
 {
     try {
         include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseConnector.php';
         $crs_reader = new ilECSCourseConnector($server);
         $details = $crs_reader->getCourse($a_content_id, true);
         $this->mid = $details->getMySender();
         // Check if import is enabled
         include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
         $part = ilECSParticipantSetting::getInstance($this->getServer()->getServerId(), $this->getMid());
         if (!$part->isImportEnabled()) {
             $GLOBALS['ilLog']->write(__METHOD__ . ': Import disabled for mid ' . $this->getMid());
             return false;
         }
         // Check course allocation setting
         include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
         $gl_settings = ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid());
         $enabled = $gl_settings->isCourseAllocationEnabled();
         if (!$enabled) {
             $GLOBALS['ilLog']->write(__METHOD__ . ': Course allocation disabled for ' . $this->getMid());
         }
         return $enabled;
     } catch (ilECSConnectorException $e) {
         $GLOBALS['ilLog']->write(__METHOD__ . ': Reading course details failed with message ' . $e->getMessage());
         return false;
     }
 }
 /**
  * Fill row
  *
  * @access public
  * @param array row data
  * 
  */
 public function fillRow($a_set)
 {
     global $ilCtrl;
     $this->tpl->setVariable('S_ID', $this->getServer()->getServerId());
     $this->tpl->setVariable('M_ID', $a_set['mid']);
     $this->tpl->setVariable('VAL_ID', $this->getServer()->getServerId() . '_' . $a_set['mid']);
     $this->tpl->setVariable('VAL_ORG', (string) $a_set['org']);
     $this->tpl->setVariable('VAL_CHECKED', $a_set['checked'] ? 'checked="checked"' : '');
     $this->tpl->setVariable('VAL_TITLE', $a_set['participants']);
     $this->tpl->setVariable('VAL_DESC', $a_set['description']);
     $this->tpl->setVariable('VAL_EMAIL', $a_set['email']);
     $this->tpl->setVariable('VAL_DNS', $a_set['dns']);
     $this->tpl->setVariable('VAL_ABR', $a_set['abr']);
     $this->tpl->setVariable('TXT_EMAIL', $this->lng->txt('ecs_email'));
     $this->tpl->setVariable('TXT_DNS', $this->lng->txt('ecs_dns'));
     $this->tpl->setVariable('TXT_ABR', $this->lng->txt('ecs_abr'));
     $this->tpl->setVariable('TXT_ID', $this->lng->txt('ecs_unique_id'));
     $this->tpl->setVariable('TXT_ORG', $this->lng->txt('organization'));
     include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
     $part = new ilECSParticipantSetting($this->getServer()->getServerId(), $a_set['mid']);
     if ($part->isExportEnabled()) {
         foreach ($part->getExportTypes() as $obj_type) {
             $this->tpl->setCurrentBlock('obj_erow');
             $this->tpl->setVariable('TXT_OBJ_EINFO', $this->lng->txt('objs_' . $obj_type));
             $this->tpl->parseCurrentBlock();
         }
     } else {
         $this->lng->loadLanguageModule('administration');
         $this->tpl->setVariable('TXT_OBJ_EINFO', $this->lng->txt('disabled'));
     }
     if ($part->isImportEnabled()) {
         foreach ($part->getImportTypes() as $obj_type) {
             $this->tpl->setCurrentBlock('obj_irow');
             $this->tpl->setVariable('TXT_OBJ_IINFO', $this->lng->txt('objs_' . $obj_type));
             $this->tpl->parseCurrentBlock();
         }
     } else {
         $this->lng->loadLanguageModule('administration');
         $this->tpl->setVariable('TXT_OBJ_IINFO', $this->lng->txt('disabled'));
     }
     // :TODO: what types are to be supported?
     $sel = ilUtil::formSelect($part->getImportType(), 'import_type[' . $this->getServer()->getServerId() . '][' . $a_set['mid'] . ']', array(ilECSParticipantSetting::IMPORT_RCRS => $this->lng->txt('obj_rcrs'), ilECSParticipantSetting::IMPORT_CRS => $this->lng->txt('obj_crs'), ilECSParticipantSetting::IMPORT_CMS => $this->lng->txt('ecs_import_cms')), false, true);
     $this->tpl->setVariable('IMPORT_SEL', $sel);
     include_once './Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
     $list = new ilAdvancedSelectionListGUI();
     $list->setItemLinkClass('small');
     $list->setSelectionHeaderClass('small');
     $list->setId('actl_' . $a_set['server_id'] . '_' . $a_set['mid']);
     $list->setListTitle($this->lng->txt('actions'));
     $ilCtrl->setParameter($this->getParentObject(), 'server_id', $this->getServer()->getServerId());
     $ilCtrl->setParameter($this->getParentObject(), 'mid', $a_set['mid']);
     $list->addItem($this->lng->txt('edit'), '', $ilCtrl->getLinkTargetByClass('ilecsparticipantsettingsgui', 'settings'));
     switch ($part->getImportType()) {
         case ilECSParticipantSetting::IMPORT_RCRS:
             // Do nothing
             break;
         case ilECSParticipantSetting::IMPORT_CRS:
             // Possible action => Edit course allocation
             $ilCtrl->setParameter($this->getParentObject(), 'server_id', $this->getServer()->getServerId());
             $ilCtrl->setParameter($this->getParentObject(), 'mid', $a_set['mid']);
             $list->addItem($this->lng->txt('ecs_crs_alloc_set'), '', $ilCtrl->getLinkTargetByClass('ilecsmappingsettingsgui', 'cStart'));
             break;
         case ilECSParticipantSetting::IMPORT_CMS:
             $ilCtrl->setParameter($this->getParentObject(), 'server_id', $this->getServer()->getServerId());
             $ilCtrl->setParameter($this->getParentObject(), 'mid', $a_set['mid']);
             // Possible action => Edit course allocation, edit node mapping
             $list->addItem($this->lng->txt('ecs_dir_alloc_set'), '', $ilCtrl->getLinkTargetByClass('ilecsmappingsettingsgui', 'dStart'));
             $list->addItem($this->lng->txt('ecs_crs_alloc_set'), '', $ilCtrl->getLinkTargetByClass('ilecsmappingsettingsgui', 'cStart'));
             break;
     }
     $this->tpl->setVariable('ACTIONS', $list->getHTML());
 }
 /**
  * update whitelist
  *
  * @access protected
  * 
  */
 protected function updateCommunities()
 {
     global $ilLog;
     include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
     include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
     // @TODO: Delete deprecated communities
     $invalidImportTypes = false;
     if (!$this->validateImportTypes($_POST['import_type'])) {
         $invalidImportTypes = true;
     }
     $servers = ilECSServerSettings::getInstance();
     foreach ($servers->getServers() as $server) {
         try {
             // Read communities
             $cReader = ilECSCommunityReader::getInstanceByServerId($server->getServerId());
             // Update community cache
             foreach ($cReader->getCommunities() as $community) {
                 include_once './Services/WebServices/ECS/classes/class.ilECSCommunityCache.php';
                 $cCache = ilECSCommunityCache::getInstance($server->getServerId(), $community->getId());
                 $cCache->setCommunityName($community->getTitle());
                 $cCache->setMids($community->getMids());
                 $cCache->setOwnId($community->getOwnId());
                 $cCache->update();
             }
         } catch (Exception $e) {
             $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot read ecs communities: ' . $e->getMessage());
         }
     }
     include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
     foreach ((array) $_POST['sci_mid'] as $sid => $tmp) {
         foreach ((array) $_POST['sci_mid'][$sid] as $mid => $tmp) {
             $set = new ilECSParticipantSetting($sid, $mid);
             $set->enableExport(array_key_exists($mid, (array) $_POST['export'][$sid]) ? true : false);
             $set->enableImport(array_key_exists($mid, (array) $_POST['import'][$sid]) ? true : false);
             $set->setImportType($_POST['import_type'][$sid][$mid]);
             // update title/cname
             try {
                 $part = ilECSCommunityReader::getInstanceByServerId($sid)->getParticipantByMID($mid);
                 if ($part instanceof ilECSParticipant) {
                     $set->setTitle($part->getParticipantName());
                 }
                 $com = ilECSCommunityReader::getInstanceByServerId($sid)->getCommunityByMID($mid);
                 if ($com instanceof ilECSCommunity) {
                     $set->setCommunityName($com->getTitle());
                 }
             } catch (Exception $e) {
                 $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot read ecs communities: ' . $e->getMessage());
             }
             $set->update();
         }
     }
     if ($invalidImportTypes) {
         ilUtil::sendFailure($this->lng->txt('ecs_invalid_import_type_cms'), true);
     } else {
         ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
     }
     $GLOBALS['ilCtrl']->redirect($this, 'communities');
     // TODO: Do update of remote courses and ...
     return true;
 }
 /**
  * Fill ECS export settings "multiple servers"
  * 
  * to be used in ilObject->initEditForm()
  * 
  * @param ilPropertyFormGUI $a_form
  */
 public function addSettingsToForm(ilPropertyFormGUI $a_form, $a_type)
 {
     global $lng;
     if (!$this->isActive()) {
         return;
     }
     $obj_id = $this->content_obj->getId();
     // Return if no participant is enabled for export and the current object is not released
     include_once './Services/WebServices/ECS/classes/class.ilECSExport.php';
     include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
     $exportablePart = ilECSParticipantSettings::getExportableParticipants();
     if (!$exportablePart and !ilECSExport::_isExported($obj_id)) {
         return true;
     }
     $lng->loadLanguageModule('ecs');
     // show ecs property form section
     $ecs = new ilFormSectionHeaderGUI();
     $ecs->setTitle($lng->txt('ecs_' . $a_type . '_export'));
     $a_form->addItem($ecs);
     // release or not
     $exp = new ilRadioGroupInputGUI($lng->txt('ecs_' . $a_type . '_export_obj_settings'), 'ecs_export');
     $exp->setRequired(true);
     $exp->setValue(ilECSExport::_isExported($obj_id) ? 1 : 0);
     $off = new ilRadioOption($lng->txt('ecs_' . $a_type . '_export_disabled'), 0);
     $exp->addOption($off);
     $on = new ilRadioOption($lng->txt('ecs_' . $a_type . '_export_enabled'), 1);
     $exp->addOption($on);
     $a_form->addItem($exp);
     // Show all exportable participants
     $publish_for = new ilCheckboxGroupInputGUI($lng->txt('ecs_publish_for'), 'ecs_sid');
     // @TODO: Active checkboxes for recipients
     //$publish_for->setValue((array) $members);
     // Read receivers
     $receivers = array();
     include_once './Services/WebServices/ECS/classes/class.ilECSEContentDetails.php';
     foreach (ilECSExport::getExportServerIds($obj_id) as $sid) {
         $exp = new ilECSExport($sid, $obj_id);
         $participants = null;
         $details = ilECSEContentDetails::getInstance($sid, $exp->getEContentId(), $this->getECSObjectType());
         if ($details instanceof ilECSEContentDetails) {
             $participants = $details->getReceivers();
         }
         if ($participants) {
             foreach ($participants as $mid) {
                 $receivers[] = $sid . '_' . $mid;
             }
         }
     }
     $publish_for->setValue($receivers);
     foreach ($exportablePart as $pInfo) {
         include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
         $partSetting = new ilECSParticipantSetting($pInfo['sid'], $pInfo['mid']);
         $com = new ilCheckboxInputGUI($partSetting->getCommunityName() . ': ' . $partSetting->getTitle(), 'sid_mid');
         $com->setValue($pInfo['sid'] . '_' . $pInfo['mid']);
         $publish_for->addOption($com);
     }
     $on->addSubItem($publish_for);
     return true;
 }
 /**
  * Delete
  */
 public function delete()
 {
     global $ilDB;
     // --- cascading delete
     include_once 'Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
     ilECSCmsData::deleteByServerId($this->getServerId());
     include_once 'Services/WebServices/ECS/classes/class.ilECSCommunityCache.php';
     ilECSCommunityCache::deleteByServerId($this->getServerId());
     include_once 'Services/WebServices/ECS/classes/class.ilECSDataMappingSetting.php';
     ilECSDataMappingSetting::deleteByServerId($this->getServerId());
     include_once 'Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php';
     ilECSEventQueueReader::deleteByServerId($this->getServerId());
     include_once 'Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignment.php';
     ilECSNodeMappingAssignment::deleteByServerId($this->getServerId());
     include_once 'Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
     ilECSParticipantSetting::deleteByServerId($this->getServerId());
     include_once 'Services/WebServices/ECS/classes/class.ilECSExport.php';
     ilECSExport::deleteByServerId($this->getServerId());
     // resetting server id to flag items in imported list
     include_once 'Services/WebServices/ECS/classes/class.ilECSImport.php';
     ilECSImport::resetServerId($this->getServerId());
     $ilDB->manipulate('DELETE FROM ecs_server ' . 'WHERE server_id = ' . $ilDB->quote($this->getServerId(), 'integer'));
     $this->server_id = NULL;
     return true;
 }
 /**
  * get full remote link 
  * Including ecs generated hash and auth mode
  *
  * @return string
  * @throws ilECSConnectorException
  */
 public function getFullRemoteLink()
 {
     global $ilUser;
     include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
     $server_id = ilECSImport::lookupServerId($this->getId());
     $server = ilECSSetting::getInstanceByServerId($server_id);
     include_once './Services/WebServices/ECS/classes/class.ilECSUser.php';
     $user = new ilECSUser($ilUser);
     $ecs_user_data = $user->toGET();
     $GLOBALS['ilLog']->write(__METHOD__ . ': Using ecs user data ' . $ecs_user_data);
     // check token mechanism enabled
     include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
     $part = new ilECSParticipantSetting($server_id, $this->getMID());
     if (!$part->isTokenEnabled()) {
         return $this->getRemoteLink();
     }
     $auth_hash = $this->createAuthResource($this->getRemoteLink() . $user->toREALM());
     $ecs_url_hash = 'ecs_hash_url=' . urlencode($server->getServerURI() . '/sys/auths/' . $auth_hash);
     if (strpos($this->getRemoteLink(), '?')) {
         $link = $this->getRemoteLink() . '&ecs_hash=' . $auth_hash . $ecs_user_data . '&' . $ecs_url_hash;
     } else {
         $link = $this->getRemoteLink() . '?ecs_hash=' . $auth_hash . $ecs_user_data . '&' . $ecs_url_hash;
     }
     $GLOBALS['ilLog']->write(__METHOD__ . ': ECS full link: ' . $link);
     return $link;
 }