/**
  * Clone Advanced Meta Data
  *
  * @access public
  * @static
  *
  * @param int source obj_id
  * @param int target obj_id
  */
 public static function _cloneValues($a_source_id, $a_target_id)
 {
     global $ilLog;
     include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php';
     include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php';
     if (!count($defs = ilAdvancedMDFieldDefinition::_getActiveDefinitionsByObjType(ilObject::_lookupType($a_source_id)))) {
         $ilLog->write(__METHOD__ . ': No advanced meta data found.');
         return true;
     }
     $ilLog->write(__METHOD__ . ': Start cloning advanced meta data.');
     foreach (self::_getValuesByObjId($a_source_id) as $field_id => $value) {
         if (!in_array($field_id, $defs)) {
             continue;
         }
         $new_value = new ilAdvancedMDValue($field_id, $a_target_id);
         $new_value->setValue($value);
         $new_value->save();
     }
     return true;
 }
 /**
  * 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::_getActiveDefinitionsByObjType('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::_getActiveDefinitionsByObjType('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 true;
     }
     $this->form = new ilPropertyFormGUI();
     $this->form->setFormAction($this->ctrl->getFormAction($this));
     #$this->form->setTableWidth('100%');
     // substitution
     foreach ($visible_records as $obj_type => $records) {
         include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php';
         $sub = ilAdvancedMDSubstitution::_getInstanceByObjectType($obj_type);
         // Show section
         $section = new ilFormSectionHeaderGUI();
         $section->setSectionIcon(ilUtil::getImagePath('icon_' . $obj_type . '_s.png'), $this->lng->txt('objs_' . $obj_type));
         $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);
         $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);
         #$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);
         $definitions = ilAdvancedMDFieldDefinition::_getActiveDefinitionsByObjType($obj_type);
         $definitions = $sub->sortDefinitions($definitions);
         $counter = 1;
         foreach ($definitions as $definition_id) {
             $def = ilAdvancedMDFieldDefinition::_getInstanceByFieldId($definition_id);
             if ($def->isDeleted()) {
                 continue;
             }
             $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));
             $pos = new ilTextInputGUI($this->lng->txt('position'), 'position[' . $obj_type . '][' . $definition_id . ']');
             $pos->setSize(3);
             $pos->setMaxLength(4);
             $pos->setValue(sprintf('%.1f', $counter++));
             $check->addSubItem($pos);
             $bold = new ilCheckboxInputGUI($this->lng->txt('bold'), 'bold[' . $obj_type . '][' . $definition_id . ']');
             $bold->setValue(1);
             $bold->setChecked($sub->isBold($definition_id));
             $check->addSubItem($bold);
             $bold = new ilCheckboxInputGUI($this->lng->txt('newline'), 'newline[' . $obj_type . '][' . $definition_id . ']');
             $bold->setValue(1);
             $bold->setChecked($sub->hasNewline($definition_id));
             $check->addSubItem($bold);
             $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;
 }