/**
  * init Form
  *
  * @param string $a_mode values: create | edit
  */
 public function initForm()
 {
     global $lng, $ilCtrl;
     //table_id
     $hidden_prop = new ilHiddenInputGUI("table_id");
     $hidden_prop->setValue($this->table_id);
     $this->form->addItem($hidden_prop);
     $ilCtrl->setParameter($this, "record_id", $this->record_id);
     $this->form->setFormAction($ilCtrl->getFormAction($this));
     $allFields = $this->table->getRecordFields();
     foreach ($allFields as $field) {
         $item = ilDataCollectionDatatype::getInputField($field);
         if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) {
             $fieldref = $field->getFieldRef();
             $reffield = ilDataCollectionCache::getFieldCache($fieldref);
             $options = array();
             if (!$field->isNRef()) {
                 $options[""] = '--';
             }
             $reftable = ilDataCollectionCache::getTableCache($reffield->getTableId());
             foreach ($reftable->getRecords() as $record) {
                 // If the referenced field is MOB or FILE, we display the filename in the dropdown
                 if ($reffield->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE) {
                     $file_obj = new ilObjFile($record->getRecordFieldValue($fieldref), false);
                     $options[$record->getId()] = $file_obj->getFileName();
                 } else {
                     if ($reffield->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB) {
                         $media_obj = new ilObjMediaObject($record->getRecordFieldValue($fieldref), false);
                         $options[$record->getId()] = $media_obj->getTitle();
                     } else {
                         $options[$record->getId()] = $record->getRecordFieldValue($fieldref);
                     }
                 }
             }
             $item->setOptions($options);
         }
         if ($this->record_id) {
             $record = ilDataCollectionCache::getRecordCache($this->record_id);
         }
         $item->setRequired($field->getRequired());
         //WORKAROUND. If field is from type file: if it's required but already has a value it is no longer required as the old value is taken as default without the form knowing about it.
         if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE || $field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB && ($this->record_id && $record->getId() != 0 && ($record->getRecordFieldValue($field->getId()) != "-" || $record->getRecordFieldValue($field->getId()) != ""))) {
             $item->setRequired(false);
         }
         if (!ilObjDataCollection::_hasWriteAccess($this->parent_obj->ref_id) && $field->getLocked()) {
             $item->setDisabled(true);
         }
         $this->form->addItem($item);
     }
     // Add possibility to change the owner in edit mode
     if ($this->record_id) {
         $ownerField = $this->table->getField('owner');
         $inputfield = ilDataCollectionDatatype::getInputField($ownerField);
         $this->form->addItem($inputfield);
     }
     // save and cancel commands
     if (isset($this->record_id)) {
         $this->form->setTitle($lng->txt("dcl_update_record"));
         $this->form->addCommandButton("save", $lng->txt("dcl_update_record"));
         $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
     } else {
         $this->form->setTitle($lng->txt("dcl_add_new_record"));
         $this->form->addCommandButton("save", $lng->txt("save"));
         $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
     }
     $ilCtrl->setParameter($this, "table_id", $this->table_id);
     $ilCtrl->setParameter($this, "record_id", $this->record_id);
 }
 /**
  * init Form
  */
 public function initForm()
 {
     $this->form = new ilPropertyFormGUI();
     $prefix = $this->ctrl->isAsynch() ? 'dclajax' : 'dcl';
     // Used by datacolleciton.js to select input elements
     $this->form->setId($prefix . $this->table_id . $this->record_id);
     $hidden_prop = new ilHiddenInputGUI("table_id");
     $hidden_prop->setValue($this->table_id);
     $this->form->addItem($hidden_prop);
     if ($this->record_id) {
         $hidden_prop = new ilHiddenInputGUI("record_id");
         $hidden_prop->setValue($this->record_id);
         $this->form->addItem($hidden_prop);
     }
     $this->ctrl->setParameter($this, "record_id", $this->record_id);
     $this->form->setFormAction($this->ctrl->getFormAction($this));
     $allFields = $this->table->getRecordFields();
     $inline_css = '';
     foreach ($allFields as $field) {
         $item = ilDataCollectionDatatype::getInputField($field);
         if ($item === NULL) {
             continue;
             // Fields calculating values at runtime, e.g. ilDataCollectionFormulaField do not have input
         }
         if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) {
             $fieldref = $field->getFieldRef();
             $reffield = ilDataCollectionCache::getFieldCache($fieldref);
             $options = array();
             if (!$field->isNRef()) {
                 $options[""] = $this->lng->txt('dcl_please_select');
             }
             $reftable = ilDataCollectionCache::getTableCache($reffield->getTableId());
             foreach ($reftable->getRecords() as $record) {
                 // If the referenced field is MOB or FILE, we display the filename in the dropdown
                 switch ($reffield->getDatatypeId()) {
                     case ilDataCollectionDatatype::INPUTFORMAT_FILE:
                         $file_obj = new ilObjFile($record->getRecordFieldValue($fieldref), false);
                         $options[$record->getId()] = $file_obj->getFileName();
                         break;
                     case ilDataCollectionDatatype::INPUTFORMAT_MOB:
                         $media_obj = new ilObjMediaObject($record->getRecordFieldValue($fieldref), false);
                         $options[$record->getId()] = $media_obj->getTitle();
                         break;
                     case ilDataCollectionDatatype::INPUTFORMAT_DATETIME:
                         $options[$record->getId()] = $record->getRecordFieldSingleHTML($fieldref);
                         break;
                     default:
                         $options[$record->getId()] = $record->getRecordFieldValue($fieldref);
                         break;
                 }
             }
             asort($options);
             $item->setOptions($options);
             if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) {
                 // FSX use this to apply to MultiSelectInputGUI
                 //					if (!$field->isNRef()) { // addCustomAttribute only defined for single selects
                 if ($reftable->hasPermissionToAddRecord($_GET['ref_id'])) {
                     $item->addCustomAttribute('data-ref="1"');
                     $item->addCustomAttribute('data-ref-table-id="' . $reftable->getId() . '"');
                     $item->addCustomAttribute('data-ref-field-id="' . $reffield->getId() . '"');
                 }
                 //					}
             }
             if ($item instanceof ilMultiSelectInputGUI) {
                 $item->setWidth(400);
                 $item->setHeight(100);
                 $inline_css .= 'div#' . $item->getFieldId() . '{resize:both;} ';
             }
         }
         if ($this->record_id) {
             $record = ilDataCollectionCache::getRecordCache($this->record_id);
         }
         $item->setRequired($field->getRequired());
         //WORKAROUND. If field is from type file: if it's required but already has a value it is no longer required as the old value is taken as default without the form knowing about it.
         if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE || $field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB) {
             if ($this->record_id and $record->getId()) {
                 $field_value = $record->getRecordFieldValue($field->getId());
                 if ($field_value) {
                     $item->setRequired(false);
                 }
             }
             // If this is an ajax request to return the form, input files are currently not supported
             if ($this->ctrl->isAsynch()) {
                 $item->setDisabled(true);
             }
         }
         if (!ilObjDataCollection::_hasWriteAccess($this->parent_obj->ref_id) && $field->getLocked()) {
             $item->setDisabled(true);
         }
         $this->form->addItem($item);
     }
     $this->tpl->addInlineCss($inline_css);
     // Add possibility to change the owner in edit mode
     if ($this->record_id) {
         $ownerField = $this->table->getField('owner');
         $inputfield = ilDataCollectionDatatype::getInputField($ownerField);
         $this->form->addItem($inputfield);
     }
     // save and cancel commands
     if ($this->record_id) {
         $this->form->setTitle($this->lng->txt("dcl_update_record"));
         $this->form->addCommandButton("save", $this->lng->txt("dcl_update_record"));
         if (!$this->ctrl->isAsynch()) {
             $this->form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
         }
     } else {
         $this->form->setTitle($this->lng->txt("dcl_add_new_record"));
         $this->form->addCommandButton("save", $this->lng->txt("save"));
         if (!$this->ctrl->isAsynch()) {
             $this->form->addCommandButton("cancelSave", $this->lng->txt("cancel"));
         }
     }
     $this->ctrl->setParameter($this, "table_id", $this->table_id);
     $this->ctrl->setParameter($this, "record_id", $this->record_id);
 }