public function __construct(ilDataCollectionRecord $record, ilDataCollectionField $field)
 {
     parent::__construct($record, $field);
     $dclTable = ilDataCollectionCache::getTableCache($this->getField()->getTableId());
     $this->dcl_obj_id = $dclTable->getCollectionObject()->getId();
     $this->properties = $field->getProperties();
 }
 /**
  * @param ilDataCollectionFieldListGUI $a_parent_obj
  * @param string                       $a_parent_cmd
  * @param string                       $table_id
  */
 public function __construct(ilDataCollectionFieldListGUI $a_parent_obj, $a_parent_cmd, $table_id)
 {
     global $lng, $ilCtrl;
     parent::__construct($a_parent_obj, $a_parent_cmd);
     $this->parent_obj = $a_parent_obj;
     $this->table = ilDataCollectionCache::getTableCache($table_id);
     $this->setId('dcl_field_list');
     $this->addColumn('', '', '1', true);
     $this->addColumn($lng->txt('dcl_order'), NULL, '30px');
     $this->addColumn($lng->txt('dcl_title'), NULL, 'auto');
     $this->addColumn($lng->txt('dcl_visible'), NULL, '30px');
     $this->addColumn($lng->txt('dcl_filter'), NULL, '30px');
     $this->addColumn($lng->txt('dcl_locked'), NULL, '30px', false, "", $lng->txt('dcl_locked_tooltip'));
     $this->addColumn($lng->txt('dcl_in_export'), NULL, '30px');
     $this->addColumn($lng->txt('dcl_description'), NULL, 'auto');
     $this->addColumn($lng->txt('dcl_field_datatype'), NULL, 'auto');
     $this->addColumn($lng->txt('dcl_required'), NULL, 'auto');
     $this->addColumn($lng->txt('dcl_unique'), NULL, 'auto');
     $this->addColumn($lng->txt('actions'), NULL, '30px');
     // Only add mutli command for custom fields
     if (count($this->table->getRecordFields())) {
         $this->setSelectAllCheckbox('dcl_field_ids[]');
         $this->addMultiCommand('confirmDeleteFields', $lng->txt('dcl_delete_fields'));
     }
     $ilCtrl->setParameterByClass('ildatacollectionfieldeditgui', 'table_id', $this->parent_obj->table_id);
     $ilCtrl->setParameterByClass('ildatacollectionfieldlistgui', 'table_id', $this->parent_obj->table_id);
     $this->setFormAction($ilCtrl->getFormActionByClass('ildatacollectionfieldlistgui'));
     $this->addCommandButton('save', $lng->txt('dcl_save'));
     $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
     $this->setFormName('field_list');
     //those two are important as we get our data as objects not as arrays.
     $this->setExternalSegmentation(true);
     $this->setExternalSorting(true);
     $this->setTopCommands(true);
     $this->setEnableHeader(true);
     $this->setShowRowsSelector(false);
     $this->setShowTemplates(false);
     $this->setEnableHeader(true);
     $this->setEnableTitle(true);
     $this->setDefaultOrderDirection('asc');
     $this->setData($this->table->getFields());
     require_once './Modules/DataCollection/classes/class.ilDataCollectionDatatype.php';
     //wird dies benötigt?
     $this->setTitle($lng->txt('dcl_table_list_fields'));
     $this->setRowTemplate('tpl.field_list_row.html', 'Modules/DataCollection');
     $this->setStyle('table', $this->getStyle('table') . ' ' . 'dcl_record_list');
 }
 /**
  * showRecord
  * a_val = 
  */
 public function renderRecord()
 {
     global $ilTabs, $tpl, $ilCtrl, $lng;
     $rctpl = new ilTemplate("tpl.record_view.html", true, true, "Modules/DataCollection");
     $ilTabs->setTabActive("id_content");
     $view_id = self::_getViewDefinitionId($this->record_obj);
     if (!$view_id) {
         $ilCtrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords");
     }
     // please do not use ilPageObjectGUI directly here, use derived class
     // ilDataCollectionRecordViewViewdefinitionGUI
     //$pageObj = new ilPageObjectGUI("dclf", $view_id);
     // see ilObjDataCollectionGUI->executeCommand about instantiation
     include_once "./Modules/DataCollection/classes/class.ilDataCollectionRecordViewViewdefinitionGUI.php";
     $pageObj = new ilDataCollectionRecordViewViewdefinitionGUI($this->record_obj->getTableId(), $view_id);
     include_once "./Services/Style/classes/class.ilObjStyleSheet.php";
     $pageObj->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(0, "dcl"));
     $html = $pageObj->getHTML();
     $rctpl->addCss("./Services/COPage/css/content.css");
     $rctpl->fillCssFiles();
     $table = ilDataCollectionCache::getTableCache($this->record_obj->getTableId());
     foreach ($table->getFields() as $field) {
         //ILIAS_Ref_Links
         $pattern = '/\\[dcliln field="' . preg_quote($field->getTitle(), "/") . '"\\](.*?)\\[\\/dcliln\\]/';
         if (preg_match($pattern, $html)) {
             $html = preg_replace($pattern, $this->record_obj->getRecordFieldSingleHTML($field->getId(), $this->setOptions("\$1")), $html);
         }
         //DataCollection Ref Links
         $pattern = '/\\[dclrefln field="' . preg_quote($field->getTitle(), "/") . '"\\](.*?)\\[\\/dclrefln\\]/';
         if (preg_match($pattern, $html)) {
             $this->currentField = $field;
             $html = preg_replace_callback($pattern, array($this, "doReplace"), $html);
         }
         $pattern = '/\\[ext tableOf="' . preg_quote($field->getTitle(), "/") . '" field="(.*?)"\\]/';
         if (preg_match($pattern, $html)) {
             $this->currentField = $field;
             $html = preg_replace_callback($pattern, array($this, "doExtReplace"), $html);
         }
         $html = str_ireplace("[" . $field->getTitle() . "]", $this->record_obj->getRecordFieldHTML($field->getId()), $html);
     }
     $rctpl->setVariable("CONTENT", $html);
     //Permanent Link
     include_once "./Services/PermanentLink/classes/class.ilPermanentLinkGUI.php";
     $perma_link = new ilPermanentLinkGUI("dcl", $_GET["ref_id"], "_" . $_GET['record_id']);
     $rctpl->setVariable("PERMA_LINK", $perma_link->getHTML());
     $tpl->setContent($rctpl->get());
 }
 protected function getLinkHTML($link_name = NULL, $value)
 {
     global $ilCtrl;
     if (!$value || $value == "-") {
         return "";
     }
     $record_field = $this;
     $ref_record = ilDataCollectionCache::getRecordCache($value);
     $objRefField = ilDataCollectionCache::getFieldCache($record_field->getField()->getFieldRef());
     $objRefTable = ilDataCollectionCache::getTableCache($objRefField->getTableId());
     if (!$link_name) {
         $link_name = $ref_record->getRecordFieldHTML($record_field->getField()->getFieldRef());
     }
     $ilCtrl->setParameterByClass("ildatacollectionrecordviewgui", "record_id", $ref_record->getId());
     $html = "<a href='" . $ilCtrl->getLinkTargetByClass("ilDataCollectionRecordViewGUI", "renderRecord") . "'>" . $link_name . "</a>";
     return $html;
 }
 public function save()
 {
     global $lng;
     $table = ilDataCollectionCache::getTableCache($_GET['table_id']);
     $fields =& $table->getFields();
     foreach ($fields as &$field) {
         $field->setVisible($_POST['visible'][$field->getId()] == "on");
         $field->setEditable($_POST['editable'][$field->getId()] == "on");
         $field->setFilterable($_POST['filterable'][$field->getId()] == "on");
         $field->setLocked($_POST['locked'][$field->getId()] == "on");
         $field->setOrder($_POST['order'][$field->getId()]);
         $field->doUpdate();
     }
     $table->buildOrderFields();
     ilUtil::sendSuccess($lng->txt("dcl_table_settings_saved"));
     $this->listFields();
 }
 public function __construct(ilDataCollectionFieldListGUI $a_parent_obj, $a_parent_cmd, $table_id)
 {
     global $lng, $tpl, $ilCtrl;
     parent::__construct($a_parent_obj, $a_parent_cmd);
     $this->parent_obj = $a_parent_obj;
     $this->setId("dcl_field_list");
     $this->addColumn($lng->txt("dcl_order"), null, "30px");
     $this->addColumn($lng->txt("dcl_title"), null, "auto");
     $this->addColumn($lng->txt("dcl_visible"), null, "30px");
     $this->addColumn($lng->txt("dcl_filter"), null, "30px");
     $this->addColumn($lng->txt("dcl_locked"), null, "30px");
     // ALWAYS EDITABLE FOR FIRST RELEASE
     //$this->addColumn($lng->txt("dcl_editable"),  "editable",  "30px");
     $this->addColumn($lng->txt("dcl_description"), null, "auto");
     $this->addColumn($lng->txt("dcl_field_datatype"), null, "auto");
     $this->addColumn($lng->txt("dcl_required"), null, "auto");
     $this->addColumn($lng->txt("dcl_unique"), null, "auto");
     $this->addColumn($lng->txt("actions"), null, "30px");
     $ilCtrl->setParameterByClass("ildatacollectionfieldeditgui", "table_id", $this->parent_obj->table_id);
     $ilCtrl->setParameterByClass("ildatacollectionfieldlistgui", "table_id", $this->parent_obj->table_id);
     //		$img = " <img src='".ilUtil::getImagePath("cmd_add_s.png")."' /> "; // Wirklich hässlich, doch leider wird der Text, der addHeaderCommand mitgeben wird, nicht mehr angezeigt, sobald man ein Bild mitsendet...
     //
     //		$this->addHeaderCommand(.$img);
     $this->setFormAction($ilCtrl->getFormActionByClass("ildatacollectionfieldlistgui"));
     $this->addCommandButton("save", $lng->txt("dcl_save"));
     $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
     $this->setFormName('field_list');
     //those two are important as we get our data as objects not as arrays.
     $this->setExternalSegmentation(true);
     $this->setExternalSorting(true);
     $this->setTopCommands(true);
     $this->setEnableHeader(true);
     $this->setShowRowsSelector(false);
     $this->setShowTemplates(false);
     $this->setEnableHeader(true);
     $this->setEnableTitle(true);
     $this->setDefaultOrderDirection("asc");
     $this->table = ilDataCollectionCache::getTableCache($table_id);
     $this->setData($this->table->getFields());
     require_once './Modules/DataCollection/classes/class.ilDataCollectionDatatype.php';
     //wird dies benötigt?
     $this->setTitle($lng->txt("dcl_table_list_fields"));
     $this->setRowTemplate("tpl.field_list_row.html", "Modules/DataCollection");
 }
 public function __construct(ilDataCollectionFieldListGUI $a_parent_obj, $a_parent_cmd, $table_id)
 {
     global $lng, $tpl, $ilCtrl;
     parent::__construct($a_parent_obj, $a_parent_cmd);
     $this->parent_obj = $a_parent_obj;
     $this->setId("dcl_field_list");
     $this->addColumn($lng->txt("dcl_order"), null, "30px");
     $this->addColumn($lng->txt("dcl_title"), null, "auto");
     $this->addColumn($lng->txt("dcl_visible"), null, "30px");
     $this->addColumn($lng->txt("dcl_filter"), null, "30px");
     $this->addColumn($lng->txt("dcl_locked"), null, "30px");
     $this->addColumn($lng->txt("dcl_in_export"), null, "30px");
     $this->addColumn($lng->txt("dcl_description"), null, "auto");
     $this->addColumn($lng->txt("dcl_field_datatype"), null, "auto");
     $this->addColumn($lng->txt("dcl_required"), null, "auto");
     $this->addColumn($lng->txt("dcl_unique"), null, "auto");
     $this->addColumn($lng->txt("actions"), null, "30px");
     $ilCtrl->setParameterByClass("ildatacollectionfieldeditgui", "table_id", $this->parent_obj->table_id);
     $ilCtrl->setParameterByClass("ildatacollectionfieldlistgui", "table_id", $this->parent_obj->table_id);
     $this->setFormAction($ilCtrl->getFormActionByClass("ildatacollectionfieldlistgui"));
     $this->addCommandButton("save", $lng->txt("dcl_save"));
     $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
     $this->setFormName('field_list');
     //those two are important as we get our data as objects not as arrays.
     $this->setExternalSegmentation(true);
     $this->setExternalSorting(true);
     $this->setTopCommands(true);
     $this->setEnableHeader(true);
     $this->setShowRowsSelector(false);
     $this->setShowTemplates(false);
     $this->setEnableHeader(true);
     $this->setEnableTitle(true);
     $this->setDefaultOrderDirection("asc");
     $this->table = ilDataCollectionCache::getTableCache($table_id);
     $this->setData($this->table->getFields());
     require_once './Modules/DataCollection/classes/class.ilDataCollectionDatatype.php';
     //wird dies benötigt?
     $this->setTitle($lng->txt("dcl_table_list_fields"));
     $this->setRowTemplate("tpl.field_list_row.html", "Modules/DataCollection");
 }
 /**
  * Constructor
  *
  * @param	object	$a_parent_obj
  * @param	int $table_id We need a table_id if no field_id is set (creation mode). We ignore the table_id by edit mode
  * @param	int $field_id The field_id of a existing fiel (edit mode) 
  */
 public function __construct(ilObjDataCollectionGUI $a_parent_obj, $table_id, $field_id)
 {
     global $ilCtrl;
     $this->obj_id = $a_parent_obj->obj_id;
     $this->parent_obj = $a_parent_obj;
     $this->table_id = $table_id;
     if (!$table_id) {
         $table_id = $_GET["table_id"];
     }
     if (!isset($field_id)) {
         $this->field_id = $_GET['field_id'];
     }
     if (isset($field_id)) {
         $this->field_obj = ilDataCollectionCache::getFieldCache($field_id);
     } else {
         $this->field_obj = ilDataCollectionCache::getFieldCache();
         if (!$table_id) {
             $ilCtrl->redirectByClass("ilDataCollectionGUI", "listFields");
         }
         $this->field_obj->setTableId($table_id);
         $ilCtrl->saveParameter($this, "table_id");
     }
     $this->table = ilDataCollectionCache::getTableCache($table_id);
 }
 public function checkValidity($value, $record_id = null)
 {
     //Don't check empty values
     if ($value == NULL) {
         return true;
     }
     if (!ilDataCollectionDatatype::checkValidity($this->getDatatypeId(), $value)) {
         throw new ilDataCollectionInputException(ilDataCollectionInputException::TYPE_EXCEPTION);
     }
     $properties = $this->getPropertyvalues();
     $length = ilDataCollectionField::PROPERTYID_LENGTH;
     $regex_id = ilDataCollectionField::PROPERTYID_REGEX;
     $url = ilDataCollectionField::PROPERTYID_URL;
     if ($this->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_TEXT) {
         $regex = $properties[$regex_id];
         if (substr($regex, 0, 1) != "/") {
             $regex = "/" . $regex;
         }
         if (substr($regex, -1) != "/") {
             $regex .= "/";
         }
         if ($properties[$length] < strlen($value) && is_numeric($properties[$length])) {
             throw new ilDataCollectionInputException(ilDataCollectionInputException::LENGTH_EXCEPTION);
         }
         if (!($properties[$regex_id] == NULL || @preg_match($regex, $value))) {
             throw new ilDataCollectionInputException(ilDataCollectionInputException::REGEX_EXCEPTION);
         }
         //email or url
         if ($properties[$url] && !(preg_match('~(^(news|(ht|f)tp(s?)\\://){1}\\S+)~i', $value) || preg_match("/^[a-z0-9!#\$%&'*+=?^_`{|}~-]+(?:\\.[a-z0-9!#\$%&'*+=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\$/i", $value))) {
             throw new ilDataCollectionInputException(ilDataCollectionInputException::NOT_URL);
         }
     }
     if ($this->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB and $value['name']) {
         $arrMimeType = explode('/', ilObjMediaObject::getMimeType($value['name']));
         if ($arrMimeType[0] != "image") {
             throw new ilDataCollectionInputException(ilDataCollectionInputException::NOT_IMAGE);
         }
     }
     if ($this->isUnique() && $record_id === null) {
         $table = ilDataCollectionCache::getTableCache($this->getTableId());
         foreach ($table->getRecords() as $record) {
             if ($record->getRecordFieldValue($this->getId()) == $value && ($record->getId() != $record_id || $record_id == 0)) {
                 throw new ilDataCollectionInputException(ilDataCollectionInputException::UNIQUE_EXCEPTION);
             }
             //for text it has to be case insensitive.
             if ($this->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_TEXT) {
                 if (strtolower($record->getRecordFieldValue($this->getId())) == strtolower($value) && ($record->getId() != $record_id || $record_id == 0)) {
                     throw new ilDataCollectionInputException(ilDataCollectionInputException::UNIQUE_EXCEPTION);
                 }
             }
             if ($this->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_DATETIME) {
                 $datestring = $value["date"] . " " . $value["time"];
                 //["y"]."-".$value["date"]['m']."-".$value["date"]['d']." 00:00:00";
                 if ($record->getRecordFieldValue($this->getId()) == $datestring && ($record->getId() != $record_id || $record_id == 0)) {
                     throw new ilDataCollectionInputException(ilDataCollectionInputException::UNIQUE_EXCEPTION);
                 }
             }
         }
     }
     return true;
 }
 /**
  * @param string          $a_entity
  * @param                 $a_types
  * @param array           $a_rec
  * @param ilImportMapping $a_mapping
  * @param string          $a_schema_version
  */
 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
 {
     switch ($a_entity) {
         case 'dcl':
             // Calling new_obj->create() will create the main table for us
             $new_obj = new ilObjDataCollection();
             $new_obj->setTitle($a_rec['title']);
             $new_obj->setDescription($a_rec['description']);
             $new_obj->setApproval($a_rec['approval']);
             $new_obj->setPublicNotes($a_rec['public_notes']);
             $new_obj->setNotification($a_rec['notification']);
             $new_obj->setPublicNotes($a_rec['public_notes']);
             $new_obj->setOnline(false);
             $new_obj->setRating($a_rec['rating']);
             $new_obj->create();
             $this->import_dc_object = $new_obj;
             $a_mapping->addMapping('Modules/DataCollection', 'dcl', $a_rec['id'], $new_obj->getId());
             break;
         case 'il_dcl_table':
             // If maintable, update. Other tables must be created as well
             $table = $this->count_imported_tables > 0 ? new ilDataCollectionTable() : ilDataCollectionCache::getTableCache($this->import_dc_object->getMainTableId());
             $table->setTitle($a_rec['title']);
             $table->setObjId($this->import_dc_object->getId());
             $table->setDescription($a_rec['description']);
             $table->setAddPerm($a_rec['add_perm']);
             $table->setEditPerm($a_rec['edit_perm']);
             $table->setDeletePerm($a_rec['delete_perm']);
             $table->setEditByOwner($a_rec['edit_by_owner']);
             $table->setLimited($a_rec['limited']);
             $table->setLimitStart($a_rec['limit_start']);
             $table->setLimitEnd($a_rec['limit_end']);
             $table->setIsVisible($a_rec['is_visible']);
             $table->setExportEnabled($a_rec['export_enabled']);
             $table->setDefaultSortField($a_rec['default_sort_field_id']);
             $table->setDefaultSortFieldOrder($a_rec['default_sort_field_order']);
             $table->setPublicCommentsEnabled($a_rec['public_comments']);
             $table->setViewOwnRecordsPerm($a_rec['view_own_records_perm']);
             if ($this->count_imported_tables > 0) {
                 $table->doCreate(false);
                 // false => Do not create views! They are imported later
             } else {
                 $table->doUpdate();
                 $this->count_imported_tables++;
                 // Delete views from maintable because we want to import them from the xml data
                 $set = $this->db->query('SELECT * FROM il_dcl_view WHERE table_id = ' . $this->db->quote($table->getId(), 'integer'));
                 $view_ids = array();
                 while ($row = $this->db->fetchObject($set)) {
                     $view_ids[] = $row->id;
                 }
                 if (count($view_ids)) {
                     $this->db->manipulate("DELETE FROM il_dcl_viewdefinition WHERE view_id IN (" . implode(',', $view_ids) . ")");
                 }
                 $this->db->manipulate("DELETE FROM il_dcl_view WHERE table_id = " . $this->db->quote($table->getId(), 'integer'));
             }
             $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['id'], $table->getId());
             break;
         case 'il_dcl_field':
             $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
             if ($new_table_id) {
                 $field = new ilDataCollectionField();
                 $field->setTableId($new_table_id);
                 $field->setDatatypeId($a_rec['datatype_id']);
                 $field->setTitle($a_rec['title']);
                 $field->setDescription($a_rec['description']);
                 $field->setRequired($a_rec['required']);
                 $field->setUnique($a_rec['is_unique']);
                 $field->setLocked($a_rec['is_locked']);
                 $field->doCreate();
                 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['id'], $field->getId());
                 // Check if this field was used as default order by, if so, update to new id
                 $table = ilDataCollectionCache::getTableCache($new_table_id);
                 if ($table && $table->getDefaultSortField() == $a_rec['id']) {
                     $table->setDefaultSortField($field->getId());
                     $table->doUpdate();
                 }
             }
             break;
         case 'il_dcl_record':
             $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
             if ($new_table_id) {
                 $record = new ilDataCollectionRecord();
                 $record->setTableId($new_table_id);
                 $datetime = new ilDateTime(time(), IL_CAL_UNIX);
                 $record->setCreateDate($datetime);
                 $record->setLastUpdate($datetime);
                 $record->setOwner($this->user->getId());
                 $record->setLastEditBy($this->user->getId());
                 $record->doCreate();
                 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['id'], $record->getId());
             }
             break;
         case 'il_dcl_view':
             $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
             if ($new_table_id) {
                 if ($a_rec['type'] == 0 && $a_rec['formtype'] == 0) {
                     // RecordViewViewDefinition: Create a new RecordViewViewdefinition. Note that the associated Page object is NOT created.
                     // Creation of the Page object is handled by the import of Services/COPage
                     $definition = new ilDataCollectionRecordViewViewdefinition();
                     $definition->setTableId($new_table_id);
                     $definition->create(true);
                     // DO not create DB entries for page object
                     // This mapping is needed for the import handled by Services/COPage
                     $a_mapping->addMapping('Services/COPage', 'pg', 'dclf:' . $a_rec['id'], 'dclf:' . $definition->getId());
                     $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_view', $a_rec['id'], $definition->getId());
                 } else {
                     // Other definitions - grab next ID from il_dcl_view
                     $view_id = $this->db->nextId("il_dcl_view");
                     $sql = "INSERT INTO il_dcl_view (id, table_id, type, formtype) VALUES (" . $this->db->quote($view_id, "integer") . ", " . $this->db->quote($new_table_id, "integer") . ", " . $this->db->quote($a_rec['type'], "integer") . ", " . $this->db->quote($a_rec['formtype'], "integer") . ")";
                     $this->db->manipulate($sql);
                     $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_view', $a_rec['id'], $view_id);
                 }
             }
             break;
         case 'il_dcl_viewdefinition':
             $new_view_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_view', $a_rec['view_id']);
             $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field']);
             $field = $new_field_id ? $new_field_id : $a_rec['field'];
             if ($new_view_id) {
                 $sql = 'INSERT INTO il_dcl_viewdefinition (view_id, field, field_order, is_set) VALUES (' . $this->db->quote($new_view_id, 'integer') . ', ' . $this->db->quote($field, 'text') . ', ' . $this->db->quote($a_rec['field_order'], 'integer') . ', ' . $this->db->quote($a_rec['is_set'], 'integer') . ')';
                 $this->db->manipulate($sql);
             }
             break;
         case 'il_dcl_field_prop':
             $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field_id']);
             if ($new_field_id) {
                 $prop = new ilDataCollectionFieldProp();
                 $prop->setFieldId($new_field_id);
                 $prop->setDatatypePropertyId($a_rec['datatype_prop_id']);
                 // For field references, we need to get the new field id of the referenced field
                 // If the field_id does not yet exist (e.g. referenced table not yet created), store temp info and fix before finishing import
                 $value = $a_rec['value'];
                 $refs = array(ilDataCollectionField::PROPERTYID_REFERENCE, ilDataCollectionField::PROPERTYID_N_REFERENCE);
                 $fix_refs = false;
                 if (in_array($prop->getDatatypePropertyId(), $refs)) {
                     $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['value']);
                     if ($new_field_id === false) {
                         $value = NULL;
                         $fix_refs = true;
                     }
                 }
                 $prop->setValue($value);
                 $prop->doCreate();
                 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_field_prop', $a_rec['id'], $prop->getId());
                 if ($fix_refs) {
                     $this->import_temp_refs_props[$prop->getId()] = $a_rec['value'];
                 }
             }
             break;
         case 'il_dcl_record_field':
             $record_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['record_id']);
             $field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field_id']);
             if ($record_id && $field_id) {
                 $record = ilDataCollectionCache::getRecordCache($record_id);
                 $field = ilDataCollectionCache::getFieldCache($field_id);
                 $record_field = new ilDataCollectionRecordField($record, $field);
                 // Created in constructor if not existing
                 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_record_field', $a_rec['id'], $record_field->getId());
                 $this->import_record_field_cache[$record_field->getId()] = $record_field;
             }
             break;
         case 'il_dcl_stloc1_value':
         case 'il_dcl_stloc2_value':
         case 'il_dcl_stloc3_value':
             $new_record_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record_field', $a_rec['record_field_id']);
             if ($new_record_field_id) {
                 /** @var ilDataCollectionRecordField $record_field */
                 $record_field = $this->import_record_field_cache[$new_record_field_id];
                 if (is_object($record_field)) {
                     // Need to rewrite internal references and lookup new objects if MOB or File
                     // For some fieldtypes it's better to reset the value, e.g. ILIAS_REF
                     switch ($record_field->getField()->getDatatypeId()) {
                         case ilDataCollectionDatatype::INPUTFORMAT_MOB:
                             // Check if we got a mapping from old object
                             $new_mob_id = $a_mapping->getMapping('Services/MediaObjects', 'mob', $a_rec['value']);
                             $value = $new_mob_id ? (int) $new_mob_id : NULL;
                             $this->import_temp_new_mob_ids[] = $new_mob_id;
                             break;
                         case ilDataCollectionDatatype::INPUTFORMAT_FILE:
                             $new_file_id = $a_mapping->getMapping('Modules/File', 'file', $a_rec['value']);
                             $value = $new_file_id ? (int) $new_file_id : NULL;
                             break;
                         case ilDataCollectionDatatype::INPUTFORMAT_REFERENCE:
                         case ilDataCollectioNDatatype::INPUTFORMAT_REFERENCELIST:
                             // If we are referencing to a record from a table that is not yet created, return value is always false because the record does exist neither
                             // Solution: Temporary store all references and fix them before finishing the import.
                             $new_record_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['value']);
                             if ($new_record_id === false) {
                                 $this->import_temp_refs[$new_record_field_id] = $a_rec['value'];
                             }
                             $value = $new_record_id ? (int) $new_record_id : NULL;
                             break;
                         case ilDataCollectionDatatype::INPUTFORMAT_ILIAS_REF:
                             $value = NULL;
                             break;
                         default:
                             $value = $a_rec['value'];
                             if ($a_entity == 'il_dcl_stloc3_value' && (is_null($value) || empty($value))) {
                                 $value = '0000-00-00 00:00:00';
                             }
                     }
                     $record_field->setValue($value, true);
                     $record_field->doUpdate();
                 }
             }
             break;
     }
 }
 private function emptyInfo()
 {
     global $lng;
     $this->table = ilDataCollectionCache::getTableCache($this->object->getMainTableId());
     $tables = $this->object->getTables();
     if (count($tables) == 1 && count($this->table->getRecordFields()) == 0 && count($this->table->getRecords()) == 0 && $this->object->getOnline()) {
         ilUtil::sendInfo($lng->txt("dcl_no_content_warning"), true);
     }
 }
 /**
  * Get all placeholders for table id
  * @param int $a_table_id
  * @param bool $a_verbose
  * @return array 
  */
 public static function getAvailablePlaceholders($a_table_id, $a_verbose = false)
 {
     $all = array();
     require_once "./Modules/DataCollection/classes/class.ilDataCollectionTable.php";
     $objTable = ilDataCollectionCache::getTableCache($a_table_id);
     $fields = $objTable->getFields($a_table_id);
     foreach ($fields as $field) {
         if (!$a_verbose) {
             $all[] = "[" . $field->getTitle() . "]";
             if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) {
                 $all[] = '[dclrefln field="' . $field->getTitle() . '"][/dclrefln]';
             }
             if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_ILIAS_REF) {
                 $all[] = '[dcliln field="' . $field->getTitle() . '"][/dcliln]';
             }
         } else {
             $all["[" . $field->getTitle() . "]"] = $field;
             if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) {
                 $all['[dclrefln field="' . $field->getTitle() . '"][/dclrefln]'] = $field;
             }
             if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_ILIAS_REF) {
                 $all['[dcliln field="' . $field->getTitle() . '"][/dcliln]'] = $field;
             }
         }
     }
     return $all;
 }
 /**
  * save
  *
  * @param string $a_mode values: create | edit
  */
 public function save($a_mode = "create")
 {
     global $ilCtrl, $ilTabs, $lng;
     if (!ilObjDataCollection::_checkAccess($this->obj_id)) {
         $this->accessDenied();
         return;
     }
     $ilTabs->activateTab("id_fields");
     $this->initForm($a_mode);
     if ($this->checkInput($a_mode)) {
         if ($a_mode != "update") {
             $this->table = ilDataCollectionCache::getTableCache();
         } elseif ($this->table_id) {
             $this->table = ilDataCollectionCache::getTableCache($this->table_id);
         } else {
             $ilCtrl->redirectByClass("ildatacollectionfieldeditgui", "listFields");
         }
         $this->table->setTitle($this->form->getInput("title"));
         $this->table->setObjId($this->obj_id);
         $this->table->setIsVisible($this->form->getInput("is_visible"));
         $this->table->setAddPerm($this->form->getInput("add_perm"));
         $this->table->setEditPerm($this->form->getInput("edit_perm"));
         $this->table->setDeletePerm($this->form->getInput("delete_perm"));
         $this->table->setEditByOwner($this->form->getInput("edit_by_owner"));
         $this->table->setExportEnabled($this->form->getInput("export_enabled"));
         $this->table->setDescription($this->form->getInput('description'));
         $this->table->setLimited($this->form->getInput("limited"));
         $limit_start = $this->form->getInput("limit_start");
         $limit_end = $this->form->getInput("limit_end");
         $this->table->setLimitStart($limit_start["date"] . " " . $limit_start["time"]);
         $this->table->setLimitEnd($limit_end["date"] . " " . $limit_end["time"]);
         if (!$this->table->hasPermissionToAddTable($this->parent_object->ref_id)) {
             $this->accessDenied();
             return;
         }
         if ($a_mode == "update") {
             $this->table->doUpdate();
             ilUtil::sendSuccess($lng->txt("dcl_msg_table_edited"), true);
             $ilCtrl->redirectByClass("ildatacollectiontableeditgui", "edit");
         } else {
             $this->table->doCreate();
             ilUtil::sendSuccess($lng->txt("dcl_msg_table_created"), true);
             $ilCtrl->setParameterByClass("ildatacollectionfieldlistgui", "table_id", $this->table->getId());
             $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
         }
     } else {
         global $tpl;
         $this->form->setValuesByPost();
         $tpl->setContent($this->form->getHTML());
     }
 }
 /**
  * Load table
  */
 private function loadTable()
 {
     if ($this->table == NULL) {
         $this->table = ilDataCollectionCache::getTableCache($this->getTableId());
     }
 }
Пример #15
0
 /**
  * @return ilDataCollectionTable[] Returns an array of tables of this collection with ids of the tables as keys.
  */
 public function getTables()
 {
     global $ilDB;
     $query = "SELECT id FROM il_dcl_table WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
     $set = $ilDB->query($query);
     $tables = array();
     while ($rec = $ilDB->fetchAssoc($set)) {
         $tables[$rec['id']] = ilDataCollectionCache::getTableCache($rec['id']);
     }
     return $tables;
 }
 /**
  * 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);
 }
 /**
  * Substitute field values in placehoders like [[Field Title]] from current record
  *
  * @param string $placeholder
  *
  * @throws ilException
  * @return string
  */
 protected function substituteFieldValue($placeholder)
 {
     if (isset(self::$cache_fields[$placeholder])) {
         $field = self::$cache_fields[$placeholder];
     } else {
         $table = ilDataCollectionCache::getTableCache($this->record->getTableId());
         // TODO May need caching per table in future
         $field_title = preg_replace('#^\\[\\[(.*)\\]\\]#', "\$1", $placeholder);
         $field = $table->getFieldByTitle($field_title);
         if ($field === NULL) {
             // Workaround for standardfields - title my be ID
             $field = $table->getField($field_title);
             if ($field === NULL) {
                 global $lng;
                 /**
                  * @var $lng ilLanguage
                  */
                 $lng->loadLanguageModule('dcl');
                 //					throw new ilException("Field with title '$field_title' not found");
                 throw new ilException(sprintf($lng->txt('dcl_err_formula_field_not_found'), $field_title));
             }
         }
         self::$cache_fields[$placeholder] = $field;
     }
     return $this->record->getRecordFieldHTML($field->getId());
 }
 /**
  * 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);
 }
 /**
  * @param bool $editComments
  */
 public function renderRecord($editComments = false)
 {
     global $ilTabs, $tpl, $ilCtrl, $lng;
     $rctpl = new ilTemplate("tpl.record_view.html", false, true, "Modules/DataCollection");
     $ilTabs->setTabActive("id_content");
     $view_id = self::_getViewDefinitionId($this->record_obj);
     if (!$view_id) {
         $ilCtrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords");
     }
     // see ilObjDataCollectionGUI->executeCommand about instantiation
     include_once "./Modules/DataCollection/classes/class.ilDataCollectionRecordViewViewdefinitionGUI.php";
     $pageObj = new ilDataCollectionRecordViewViewdefinitionGUI($this->record_obj->getTableId(), $view_id);
     include_once "./Services/Style/classes/class.ilObjStyleSheet.php";
     $pageObj->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(0, "dcl"));
     $html = $pageObj->getHTML();
     $rctpl->addCss("./Services/COPage/css/content.css");
     $rctpl->fillCssFiles();
     $table = ilDataCollectionCache::getTableCache($this->record_obj->getTableId());
     foreach ($table->getRecordFields() as $field) {
         //ILIAS_Ref_Links
         $pattern = '/\\[dcliln field="' . preg_quote($field->getTitle(), "/") . '"\\](.*?)\\[\\/dcliln\\]/';
         if (preg_match($pattern, $html)) {
             $html = preg_replace($pattern, $this->record_obj->getRecordFieldSingleHTML($field->getId(), $this->setOptions("\$1")), $html);
         }
         //DataCollection Ref Links
         $pattern = '/\\[dclrefln field="' . preg_quote($field->getTitle(), "/") . '"\\](.*?)\\[\\/dclrefln\\]/';
         if (preg_match($pattern, $html)) {
             $this->currentField = $field;
             $html = preg_replace_callback($pattern, array($this, "doReplace"), $html);
         }
         $pattern = '/\\[ext tableOf="' . preg_quote($field->getTitle(), "/") . '" field="(.*?)"\\]/';
         if (preg_match($pattern, $html)) {
             $this->currentField = $field;
             $html = preg_replace_callback($pattern, array($this, "doExtReplace"), $html);
         }
         $html = str_ireplace("[" . $field->getTitle() . "]", $this->record_obj->getRecordFieldSingleHTML($field->getId()), $html);
     }
     foreach ($table->getStandardFields() as $field) {
         $html = str_ireplace("[" . $field->getId() . "]", $this->record_obj->getRecordFieldSingleHTML($field->getId()), $html);
     }
     $rctpl->setVariable("CONTENT", $html);
     //Permanent Link
     $perma_link = new ilPermanentLinkGUI("dcl", $_GET["ref_id"], "_" . $_GET['record_id']);
     $tpl->setVariable('PRMLINK', $perma_link->getHTML());
     // Buttons for previous/next records
     if ($this->is_enabled_paging) {
         $prevNextLinks = $this->renderPrevNextLinks();
         $rctpl->setVariable('PREV_NEXT_RECORD_LINKS', $prevNextLinks);
         $ilCtrl->clearParameters($this);
         // #14083
         $rctpl->setVariable('FORM_ACTION', $ilCtrl->getFormAction($this));
         $rctpl->setVariable('RECORD', $lng->txt('dcl_record'));
         $rctpl->setVariable('RECORD_FROM_TOTAL', sprintf($lng->txt('dcl_record_from_total'), $this->current_record_position, count($this->record_ids)));
         $rctpl->setVariable('SELECT_OPTIONS', $this->renderSelectOptions());
     }
     // Edit Button
     if ($this->record_obj->hasPermissionToEdit((int) $_GET['ref_id'])) {
         $button = ilLinkButton::getInstance();
         $ilCtrl->setParameterByClass('ildatacollectionrecordeditgui', 'table_id', $this->table->getId());
         $ilCtrl->setParameterByClass('ildatacollectionrecordeditgui', 'redirect', ilDataCollectionRecordEditGUI::REDIRECT_DETAIL);
         $ilCtrl->saveParameterByClass('ildatacollectionrecordeditgui', 'record_id');
         $button->setUrl($ilCtrl->getLinkTargetByClass('ildatacollectionrecordeditgui', 'edit'));
         $button->setCaption($lng->txt('dcl_edit_record'), false);
         $rctpl->setVariable('EDIT_RECORD_BUTTON', $button->render());
     }
     // Comments
     if ($this->table->getPublicCommentsEnabled()) {
         $rctpl->setVariable('COMMENTS', $this->renderComments($editComments));
     }
     $tpl->setContent($rctpl->get());
 }
 /**
  * initEditCustomForm
  *
  * @param string $a_mode values: create | edit
  */
 public function initForm($a_mode = "create")
 {
     global $ilCtrl, $lng;
     include_once "./Services/Form/classes/class.ilPropertyFormGUI.php";
     $this->form = new ilPropertyFormGUI();
     if ($a_mode == "edit") {
         $this->form->setTitle($lng->txt('dcl_edit_field'));
         $hidden_prop = new ilHiddenInputGUI("field_id");
         $this->form->addItem($hidden_prop);
         $this->form->setFormAction($ilCtrl->getFormAction($this), "update");
         $this->form->addCommandButton('update', $lng->txt('dcl_update_field'));
     } else {
         $this->form->setTitle($lng->txt('dcl_new_field'));
         $hidden_prop = new ilHiddenInputGUI("table_id");
         $hidden_prop->setValue($this->field_obj->getTableId());
         $this->form->addItem($hidden_prop);
         $this->form->setFormAction($ilCtrl->getFormAction($this), "save");
         $this->form->addCommandButton('save', $lng->txt('dcl_create_field'));
     }
     $this->form->addCommandButton('cancel', $lng->txt('cancel'));
     $text_prop = new ilTextInputGUI($lng->txt("title"), "title");
     $text_prop->setRequired(true);
     $text_prop->setInfo(sprintf($lng->txt('fieldtitle_allow_chars'), ilDataCollectionField::_getTitleValidChars(false)));
     $text_prop->setValidationRegexp(ilDataCollectionField::_getTitleValidChars(true));
     $this->form->addItem($text_prop);
     $edit_datatype = new ilRadioGroupInputGUI($lng->txt('dcl_datatype'), 'datatype');
     foreach (ilDataCollectionDatatype::getAllDatatypes() as $datatype) {
         $opt = new ilRadioOption($lng->txt('dcl_' . $datatype['title']), $datatype['id']);
         foreach (ilDataCollectionDatatype::getProperties($datatype['id']) as $property) {
             //Type Reference: List Tabels
             if ($datatype['id'] == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE and $property['id'] == ilDataCollectionField::PROPERTYID_REFERENCE) {
                 $options = array();
                 // Get Tables
                 require_once "./Modules/DataCollection/classes/class.ilDataCollectionTable.php";
                 $tables = $this->parent_obj->getDataCollectionObject()->getTables();
                 foreach ($tables as $table) {
                     foreach ($table->getRecordFields() as $field) {
                         //referencing references may lead to endless loops.
                         if ($field->getDatatypeId() != ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) {
                             $options[$field->getId()] = $table->getTitle() . self::REFERENCE_SEPARATOR . $field->getTitle();
                         }
                     }
                 }
                 $table_selection = new ilSelectInputGUI('', 'prop_' . $property['id']);
                 $table_selection->setOptions($options);
                 //$table_selection->setValue($this->table_id);
                 $opt->addSubItem($table_selection);
             } elseif ($datatype['id'] == ilDataCollectionDatatype::INPUTFORMAT_REFERENCELIST and $property['id'] == ilDataCollectionField::PROPERTYID_N_REFERENCE) {
                 // Get Tables
                 require_once "./Modules/DataCollection/classes/class.ilDataCollectionTable.php";
                 $tables = $this->parent_obj->getDataCollectionObject()->getTables();
                 foreach ($tables as $table) {
                     foreach ($table->getRecordFields() as $field) {
                         //referencing references may lead to endless loops.
                         if ($field->getDatatypeId() != ilDataCollectionDatatype::INPUTFORMAT_REFERENCELIST) {
                             $options[$field->getId()] = $table->getTitle() . self::REFERENCE_SEPARATOR . $field->getTitle();
                         }
                     }
                 }
                 $table_selection = new ilSelectInputGUI('', 'prop_' . $property['id']);
                 $table_selection->setOptions($options);
                 $opt->addSubItem($table_selection);
             } elseif ($property['id'] == ilDataCollectionField::PROPERTYID_FORMULA_EXPRESSION) {
                 $table = ilDataCollectionCache::getTableCache((int) $_GET['table_id']);
                 $fields = array();
                 foreach ($table->getFieldsForFormula() as $f) {
                     $placeholder = $f->isStandardField() ? $f->getId() : $f->getTitle();
                     $fields[] = '<a class="dclPropExpressionField" data-placeholder="' . $placeholder . '">' . $f->getTitle() . '</a>';
                 }
                 $subitem = new ilTextAreaInputGUI($lng->txt('dcl_prop_expression'), 'prop_' . $property['id']);
                 $operators = implode(', ', array_keys(ilDclExpressionParser::getOperators()));
                 $functions = implode(', ', ilDclExpressionParser::getFunctions());
                 $subitem->setInfo(sprintf($lng->txt('dcl_prop_expression_info'), $operators, $functions, implode('<br>', $fields)));
                 $opt->addSubItem($subitem);
             } elseif ($property['datatype_id'] == $datatype['id']) {
                 //All other Types: List properties saved in propertie definition table
                 if ($property['inputformat'] == ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN) {
                     $subitem = new ilCheckboxInputGUI($lng->txt('dcl_' . $property['title']), 'prop_' . $property['id']);
                     $opt->addSubItem($subitem);
                 } elseif ($property['inputformat'] == ilDataCollectionDatatype::INPUTFORMAT_NUMBER) {
                     $subitem = new ilNumberInputGUI($lng->txt('dcl_' . $property['title']), 'prop_' . $property['id']);
                     // TODO: Nicer way to add additional info to fields (need changes in language-logic)
                     /*if($lng->txt('dcl_'.$property['title'].'_info') != '-dcl_'.$property['title'].'_info-') {
                     			$subitem->setInfo($lng->txt('dcl_'.$property['title'].'_info'));
                     		}*/
                     $subitem->setSize(5);
                     if ($property['title'] == 'length') {
                         $subitem->setMaxValue(4000);
                         $subitem->setInfo($lng->txt('dcl_' . $property['title'] . '_info'));
                     }
                     $opt->addSubItem($subitem);
                 } elseif ($property['inputformat'] == ilDataCollectionDatatype::INPUTFORMAT_NON_EDITABLE_VALUE) {
                     $subitem = new ilNonEditableValueGUI($lng->txt('dcl_' . $property['title']));
                     $subitem->setValue(implode(', ', ilDataCollectionDatatype::$mob_suffixes));
                     $opt->addSubItem($subitem);
                 } else {
                     $subitem = new ilTextInputGUI($lng->txt('dcl_' . $property['title']), 'prop_' . $property['id']);
                     // TODO: Nicer way to add additional info to fields (need changes in language-logic)
                     /*if($lng->txt('dcl_'.$property['title'].'_info') != '-dcl_'.$property['title'].'_info-') {
                     			$subitem->setInfo($lng->txt('dcl_'.$property['title'].'_info'));
                     		}*/
                     if ($property['title'] == 'regex') {
                         $subitem->setInfo($lng->txt('dcl_' . $property['title'] . '_info'));
                     }
                     $opt->addSubItem($subitem);
                 }
             }
         }
         $edit_datatype->addOption($opt);
     }
     $edit_datatype->setRequired(true);
     //you can't change type but we still need it in POST
     if ($a_mode == "edit") {
         $edit_datatype->setDisabled(true);
     }
     $this->form->addItem($edit_datatype);
     // Description
     $text_prop = new ilTextAreaInputGUI($lng->txt("dcl_field_description"), "description");
     $this->form->addItem($text_prop);
     // Required
     $cb = new ilCheckboxInputGUI($lng->txt("dcl_field_required"), "required");
     $this->form->addItem($cb);
     //Unique
     $cb = new ilCheckboxInputGUI($lng->txt("dcl_unique"), "unique");
     $this->form->addItem($cb);
 }
 public function cloneStructure($original_id)
 {
     $original = ilDataCollectionCache::getTableCache($original_id);
     $this->setEditByOwner($original->getEditByOwner());
     $this->setAddPerm($original->getAddPerm());
     $this->setEditPerm($original->getEditPerm());
     $this->setDeletePerm($original->getDeletePerm());
     $this->setLimited($original->getLimited());
     $this->setLimitStart($original->getLimitStart());
     $this->setLimitEnd($original->getLimitEnd());
     $this->setTitle($original->getTitle());
     $this->doCreate();
     //clone fields.
     foreach ($original->getRecordFields() as $field) {
         $new_field = new ilDataCollectionField();
         $new_field->setTableId($this->getId());
         $new_field->cloneStructure($field->getId());
     }
     if ($old_view_id = ilDataCollectionRecordViewViewdefinition::getIdByTableId($original_id)) {
         $old_view = new ilDataCollectionRecordViewViewdefinition($old_view_id);
         $old_view->setTableId($original_id);
         $viewdef = new ilDataCollectionRecordViewViewdefinition();
         $viewdef->setTableId($this->id);
         $viewdef->setXMLContent($old_view->getXMLContent(false));
         $viewdef->create();
     }
 }
 public function exportExcel()
 {
     global $ilCtrl, $lng;
     if (!($this->table_obj->getExportEnabled() || $this->table_obj->hasPermissionToFields($this->parent_obj->ref_id))) {
         echo $lng->txt("access_denied");
         exit;
     }
     require_once './Modules/DataCollection/classes/class.ilDataCollectionRecordListTableGUI.php';
     $list = new ilDataCollectionRecordListTableGUI($this, $ilCtrl->getCmd(), $this->table_obj);
     $table = ilDataCollectionCache::getTableCache($this->table_id);
     //        $list->setData($table->getRecords());
     $list->setExternalSorting(true);
     $list->exportData(ilTable2GUI::EXPORT_EXCEL, true);
     $this->listRecords();
 }
 private function loadTable()
 {
     include_once "class.ilDataCollectionTable.php";
     if ($this->table == NULL) {
         $this->table = ilDataCollectionCache::getTableCache($this->getTableId());
     }
 }
 /**
  * @param $field ilDataCollectionField
  * @param $value
  *
  * @return int
  */
 public function getReferenceFromValue($field, $value)
 {
     $field = ilDataCollectionCache::getFieldCache($field->getFieldRef());
     $table = ilDataCollectionCache::getTableCache($field->getTableId());
     $record_id = 0;
     foreach ($table->getRecords() as $record) {
         if ($record->getRecordField($field->getId())->getValue() == $value) {
             $record_id = $record->getId();
         }
     }
     return $record_id;
 }
 /**
  * addFilterInputFieldToTable This function adds the according filter item to the table gui passed as argument.
  * @param $field ilDataCollectionField The field which should be filterable.
  * @param &$table ilTable2GUI The table you want the filter to be added to.
  */
 static function addFilterInputFieldToTable(ilDataCollectionField $field, ilTable2GUI &$table)
 {
     global $lng;
     $type_id = $field->getDatatypeId();
     $input = NULL;
     switch ($type_id) {
         case ilDataCollectionDatatype::INPUTFORMAT_TEXT:
             $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_TEXT, false, $field->getId());
             $input->setSubmitFormOnEnter(true);
             break;
         case ilDataCollectionDatatype::INPUTFORMAT_NUMBER:
             $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_NUMBER_RANGE, false, $field->getId());
             $input->setSubmitFormOnEnter(true);
             break;
         case ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN:
             $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_SELECT, false, $field->getId());
             $input->setOptions(array("" => $lng->txt("dcl_any"), "not_checked" => $lng->txt("dcl_not_checked"), "checked" => $lng->txt("dcl_checked")));
             break;
         case ilDataCollectionDatatype::INPUTFORMAT_DATETIME:
             $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_DATE_RANGE, false, $field->getId());
             $input->setSubmitFormOnEnter(true);
             $input->setStartYear(date("Y") - 100);
             break;
         case ilDataCollectionDatatype::INPUTFORMAT_FILE:
             $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_TEXT, false, $field->getId());
             $input->setSubmitFormOnEnter(true);
             break;
         case ilDataCollectionDatatype::INPUTFORMAT_REFERENCE:
             $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_SELECT, false, $field->getId());
             $ref_field_id = $field->getFieldRef();
             $ref_field = ilDataCollectionCache::getFieldCache($ref_field_id);
             $ref_table = ilDataCollectionCache::getTableCache($ref_field->getTableId());
             $options = array();
             foreach ($ref_table->getRecords() as $record) {
                 $options[$record->getId()] = $record->getRecordFieldValue($ref_field_id);
             }
             // Sort by values ASC
             asort($options);
             $options = array('' => $lng->txt('dcl_any')) + $options;
             $input->setOptions($options);
             break;
         case ilDataCollectionDatatype::INPUTFORMAT_RATING:
             $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_SELECT, false, $field->getId());
             $options = array("" => $lng->txt("dcl_any"), 1 => ">1", 2 => ">2", 3 => ">3", 4 => ">4", 5 => "5");
             $input->setOptions($options);
             break;
         case ilDataCollectionDatatype::INPUTFORMAT_MOB:
             $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_TEXT, false, $field->getId());
             $input->setSubmitFormOnEnter(true);
             break;
         case ilDataCollectionDatatype::INPUTFORMAT_ILIAS_REF:
             $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_TEXT, false, $field->getId());
             $input->setSubmitFormOnEnter(true);
             break;
         case ilDataCollectionDatatype::INPUTFORMAT_REFERENCELIST:
             //FIXME
             $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_SELECT, false, $field->getId());
             $ref_field_id = $field->getFieldRef();
             $ref_field = ilDataCollectionCache::getFieldCache($ref_field_id);
             $ref_table = ilDataCollectionCache::getTableCache($ref_field->getTableId());
             $options = array();
             foreach ($ref_table->getRecords() as $record) {
                 $options[$record->getId()] = $record->getRecordFieldValue($ref_field_id);
             }
             // Sort by values ASC
             asort($options);
             $options = array('' => $lng->txt('dcl_any')) + $options;
             $input->setOptions($options);
             break;
     }
     if ($input != NULL) {
         $input->setTitle($field->getTitle());
     }
     return $input;
 }