/**
  * init mapping form
  *
  * @param int $a_server_id
  * @return ilPropertyFormGUI $form
  *
  * @access protected
  */
 protected function initMappingsForm($a_server_id, $mapping_type)
 {
     include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
     include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php';
     $mapping_settings = ilECSDataMappingSettings::getInstanceByServerId($a_server_id);
     $form = new ilPropertyFormGUI();
     if ($mapping_type == self::MAPPING_IMPORT) {
         $form->setTitle($this->lng->txt('ecs_mapping_tbl'));
         $form->addCommandButton('saveImportMappings', $this->lng->txt('save'));
         $form->addCommandButton('importMappings', $this->lng->txt('cancel'));
     } else {
         $form->setTitle($this->lng->txt('ecs_mapping_exp_tbl'));
         $form->addCommandButton('saveExportMappings', $this->lng->txt('save'));
         $form->addCommandButton('exportMappings', $this->lng->txt('cancel'));
     }
     $form->setFormAction($this->ctrl->getFormAction($this, 'saveMappings'));
     if ($mapping_type == self::MAPPING_IMPORT) {
         $assignments = new ilCustomInputGUI($this->lng->txt('ecs_mapping_crs'));
         $form->addItem($assignments);
     }
     include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php';
     $fields = ilAdvancedMDFieldDefinition::getInstancesByObjType('crs');
     $options = $this->prepareFieldSelection($fields);
     // get all optional ecourse fields
     include_once './Services/WebServices/ECS/classes/class.ilECSUtils.php';
     $optional = ilECSUtils::_getOptionalECourseFields();
     foreach ($optional as $field_name) {
         if ($mapping_type == self::MAPPING_IMPORT) {
             $select = new ilSelectInputGUI($this->lng->txt('ecs_field_' . $field_name), 'mapping' . '[' . ilECSDataMappingSetting::MAPPING_IMPORT_CRS . '][' . $field_name . ']');
             $select->setValue($mapping_settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_CRS, $field_name));
             $select->setOptions($options);
             $assignments->addSubItem($select);
         } else {
             $select = new ilSelectInputGUI($this->lng->txt('ecs_field_' . $field_name), 'mapping' . '[' . ilECSDataMappingSetting::MAPPING_EXPORT . '][' . $field_name . ']');
             $select->setValue($mapping_settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT, $field_name));
             $select->setOptions($options);
             $form->addItem($select);
         }
     }
     $server = new ilHiddenInputGUI('ecs_mapping_server');
     $server->setValue($a_server_id);
     $form->addItem($server);
     // Remote courses
     // no remote course settings for export
     if ($mapping_type == self::MAPPING_EXPORT) {
         return $form;
     }
     $rcrs = new ilCustomInputGUI($this->lng->txt('ecs_mapping_rcrs'));
     $form->addItem($rcrs);
     include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php';
     $fields = ilAdvancedMDFieldDefinition::getInstancesByObjType('rcrs');
     $options = $this->prepareFieldSelection($fields);
     // get all optional econtent fields
     include_once './Services/WebServices/ECS/classes/class.ilECSUtils.php';
     $optional = ilECSUtils::_getOptionalEContentFields();
     foreach ($optional as $field_name) {
         $select = new ilSelectInputGUI($this->lng->txt('ecs_field_' . $field_name), 'mapping[' . ilECSDataMappingSetting::MAPPING_IMPORT_RCRS . '][' . $field_name . ']');
         $select->setValue($mapping_settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, $field_name));
         $select->setOptions($options);
         $rcrs->addSubItem($select);
     }
     return $form;
 }
 /**
  * init form table 'substitutions'
  *
  * @access protected
  */
 protected function initFormSubstitutions()
 {
     include_once "./Services/Form/classes/class.ilPropertyFormGUI.php";
     if (!($visible_records = ilAdvancedMDRecord::_getAllRecordsByObjectType())) {
         return;
     }
     $this->form = new ilPropertyFormGUI();
     $this->form->setFormAction($this->ctrl->getFormAction($this));
     #$this->form->setTableWidth('100%');
     // substitution
     foreach ($visible_records as $obj_type => $records) {
         $perm = null;
         // :TODO: hardwird ?
         if (in_array($obj_type, array("crs", "cat"))) {
             $perm = $this->getPermissions()->hasPermissions(ilAdvancedMDPermissionHelper::CONTEXT_SUBSTITUTION, $obj_type, array(ilAdvancedMDPermissionHelper::ACTION_SUBSTITUTION_SHOW_DESCRIPTION, ilAdvancedMDPermissionHelper::ACTION_SUBSTITUTION_SHOW_FIELDNAMES, ilAdvancedMDPermissionHelper::ACTION_SUBSTITUTION_FIELD_POSITIONS));
         }
         include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php';
         $sub = ilAdvancedMDSubstitution::_getInstanceByObjectType($obj_type);
         // Show section
         $section = new ilFormSectionHeaderGUI();
         $section->setTitle($this->lng->txt('objs_' . $obj_type));
         $this->form->addItem($section);
         $check = new ilCheckboxInputGUI($this->lng->txt('description'), 'enabled_desc_' . $obj_type);
         $check->setValue(1);
         $check->setOptionTitle($this->lng->txt('md_adv_desc_show'));
         $check->setChecked($sub->isDescriptionEnabled() ? true : false);
         $this->form->addItem($check);
         if ($perm && !$perm[ilAdvancedMDPermissionHelper::ACTION_SUBSTITUTION_SHOW_DESCRIPTION]) {
             $check->setDisabled(true);
         }
         $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_field_names'), 'enabled_field_names_' . $obj_type);
         $check->setValue(1);
         $check->setOptionTitle($this->lng->txt('md_adv_fields_show'));
         $check->setChecked($sub->enabledFieldNames() ? true : false);
         $this->form->addItem($check);
         if ($perm && !$perm[ilAdvancedMDPermissionHelper::ACTION_SUBSTITUTION_SHOW_FIELDNAMES]) {
             $check->setDisabled(true);
         }
         #$area = new ilTextAreaInputGUI($this->lng->txt('md_adv_substitution'),'substitution_'.$obj_type);
         #$area->setUseRte(true);
         #$area->setRteTagSet('standard');
         #$area->setValue(ilUtil::prepareFormOutput($sub->getSubstitutionString()));
         #$area->setRows(5);
         #$area->setCols(80);
         #$this->form->addItem($area);
         if ($perm) {
             $perm_pos = $perm[ilAdvancedMDPermissionHelper::ACTION_SUBSTITUTION_FIELD_POSITIONS];
         }
         $definitions = ilAdvancedMDFieldDefinition::getInstancesByObjType($obj_type);
         $definitions = $sub->sortDefinitions($definitions);
         $counter = 1;
         foreach ($definitions as $def) {
             $definition_id = $def->getFieldId();
             $perm = $this->getSubstitutionFieldPermissions($obj_type, $definition_id);
             $title = ilAdvancedMDRecord::_lookupTitle($def->getRecordId());
             $title = $def->getTitle() . ' (' . $title . ')';
             $check = new ilCheckboxInputGUI($title, 'show[' . $obj_type . '][' . $definition_id . ']');
             $check->setValue(1);
             $check->setOptionTitle($this->lng->txt('md_adv_show'));
             $check->setChecked($sub->isSubstituted($definition_id));
             if ($perm && !$perm["show"]) {
                 $check->setDisabled(true);
             }
             $pos = new ilNumberInputGUI($this->lng->txt('position'), 'position[' . $obj_type . '][' . $definition_id . ']');
             $pos->setSize(3);
             $pos->setMaxLength(4);
             $pos->allowDecimals(true);
             $pos->setValue(sprintf('%.1f', $counter++));
             $check->addSubItem($pos);
             if ($perm && !$perm_pos) {
                 $pos->setDisabled(true);
             }
             $bold = new ilCheckboxInputGUI($this->lng->txt('bold'), 'bold[' . $obj_type . '][' . $definition_id . ']');
             $bold->setValue(1);
             $bold->setChecked($sub->isBold($definition_id));
             $check->addSubItem($bold);
             if ($perm && !$perm["bold"]) {
                 $bold->setDisabled(true);
             }
             $bold = new ilCheckboxInputGUI($this->lng->txt('newline'), 'newline[' . $obj_type . '][' . $definition_id . ']');
             $bold->setValue(1);
             $bold->setChecked($sub->hasNewline($definition_id));
             $check->addSubItem($bold);
             if ($perm && !$perm["newline"]) {
                 $bold->setDisabled(true);
             }
             $this->form->addItem($check);
         }
         // placeholder
         /*
         $custom = new ilCustomInputGUI($this->lng->txt('md_adv_placeholders'));
         $tpl = new ilTemplate('tpl.placeholder_info.html',true,true,'Services/AdvancedMetaData');
         foreach($records as $record)
         {
         	foreach(ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record->getRecordId()) as $definition)
         	{
         		$tpl->setCurrentBlock('field');
         		$tpl->setVariable('FIELD_NAME',$definition->getTitle());
         		$tpl->setVariable('MODULE_VARS','[IF_F_'.$definition->getFieldId().']...[F_'.$definition->getFieldId().']'.
         			'[/IF_F_'.$definition->getFieldId().']');
         		$tpl->parseCurrentBlock();
         	}
         	
         	$tpl->setCurrentBlock('record');
         	$tpl->setVariable('PLACEHOLDER_FOR',$this->lng->txt('md_adv_placeholder_for'));
         	$tpl->setVariable('TITLE',$record->getTitle());
         	$tpl->parseCurrentBlock();
         }
         $custom->setHTML($tpl->get());
         $this->form->addItem($custom);
         */
     }
     $this->form->setTitle($this->lng->txt('md_adv_substitution_table'));
     $this->form->addCommandButton('updateSubstitutions', $this->lng->txt('save'));
     return true;
 }