ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilAdvancedMDSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
8 
17 {
18  public const CONTEXT_ADMINISTRATION = 1;
19  public const CONTEXT_OBJECT = 2;
20 
21  protected const TAB_RECORD_SETTINGS = 'editRecord';
22  protected const TAB_TRANSLATION = 'translations';
23 
28  private $context = null;
29 
33  protected $lng;
34 
35  protected $tpl;
36 
40  protected $ctrl;
41 
45  protected $tabs_gui;
46  protected $permissions; // [ilAdvancedMDPermissionHelper]
47  protected $ref_id = null;
48  protected $obj_id = null; // [int]
49  protected $obj_type = null; // [string]
50  protected $sub_type = null; // [string]
51 
55  protected $request;
56 
60  protected $ui_factory;
61 
65  protected $ui_renderer;
66 
70  protected $toolbar;
71 
75  private $logger = null;
76 
80  private $active_language = '';
81 
85  protected $record;
86 
87 
94  public function __construct($a_ref_id = null, $a_obj_type = null, $a_sub_type = null)
95  {
96  global $DIC;
97 
98  $tpl = $DIC['tpl'];
99  $lng = $DIC['lng'];
100  $ilCtrl = $DIC['ilCtrl'];
101  $ilTabs = $DIC->tabs();
102 
103  $this->ctrl = $ilCtrl;
104  $this->lng = $lng;
105  $this->lng->loadLanguageModule('meta');
106  $this->tpl = $tpl;
107  $this->tabs_gui = $ilTabs;
108 
109  $this->toolbar = $DIC->toolbar();
110  $this->ui_factory = $DIC->ui()->factory();
111  $this->ui_renderer = $DIC->ui()->renderer();
112  $this->request = $DIC->http()->request();
113 
114  $this->logger = $GLOBALS['DIC']->logger()->amet();
115 
116  $this->ref_id = $a_ref_id;
117  if ($this->ref_id) {
118  $this->obj_id = ilObject::_lookupObjId($a_ref_id);
119  }
120 
121  if (!$this->ref_id) {
122  $this->context = self::CONTEXT_ADMINISTRATION;
123  } else {
124  $this->context = self::CONTEXT_OBJECT;
125  }
126 
127 
128  $this->obj_type = $a_obj_type;
129  $this->sub_type = $a_sub_type
130  ? $a_sub_type
131  : "-";
132 
133  if (
134  $this->obj_id &&
135  !$this->obj_type) {
136  $this->obj_type = ilObject::_lookupType($this->obj_id);
137  }
138 
139  $this->permissions = ilAdvancedMDPermissionHelper::getInstance();
140  }
141 
146  {
147  return $this->permissions;
148  }
149 
157  public function executeCommand()
158  {
159  $next_class = $this->ctrl->getNextClass($this);
160  $cmd = $this->ctrl->getCmd();
161  switch ($next_class) {
162 
163  case strtolower(ilAdvancedMDRecordTranslationGUI::class):
164  $record = $this->initRecordObject();
165  $this->setRecordSubTabs(1, true);
166  $int_gui = new \ilAdvancedMDRecordTranslationGUI($record);
167  $this->ctrl->forwardCommand($int_gui);
168  break;
169 
170  case "ilpropertyformgui":
171  $this->initRecordObject();
172  $this->initForm(
173  $this->record->getRecordId() > 0 ? 'edit' : 'create'
174  );
175  $GLOBALS['DIC']->ctrl()->forwardCommand($this->form);
176  break;
177 
178  default:
179  if (!$cmd) {
180  $cmd = 'showRecords';
181  }
182  $this->$cmd();
183  }
184  }
185 
193  public function showRecords()
194  {
195  global $DIC;
196 
197  $ilToolbar = $DIC['ilToolbar'];
198  $ilAccess = $DIC['ilAccess'];
199 
200  $this->setSubTabs($this->context);
201 
202  $perm = $this->getPermissions()->hasPermissions(
204  $_REQUEST["ref_id"],
205  array(
208  )
209  );
210 
212  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
213  $button = ilLinkButton::getInstance();
214  $button->setCaption("add");
215  $button->setUrl($this->ctrl->getLinkTarget($this, "createRecord"));
216  $ilToolbar->addButtonInstance($button);
217 
219  $ilToolbar->addSeparator();
220  }
221  }
222 
224  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
225  $button = ilLinkButton::getInstance();
226  $button->setCaption("import");
227  $button->setUrl($this->ctrl->getLinkTarget($this, "importRecords"));
228  $ilToolbar->addButtonInstance($button);
229  }
230 
231  include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordTableGUI.php");
232  $table_gui = new ilAdvancedMDRecordTableGUI($this, "showRecords", $this->getPermissions(), (bool) $this->obj_id);
233  $table_gui->setTitle($this->lng->txt("md_record_list_table"));
234  $table_gui->setData($this->getParsedRecordObjects());
235 
236  // permissions?
237  //$table_gui->addCommandButton('createRecord',$this->lng->txt('add'));
238  $table_gui->addMultiCommand("exportRecords", $this->lng->txt('export'));
239  $table_gui->setSelectAllCheckbox("record_id");
240 
241  if ($ilAccess->checkAccess('write', '', $_REQUEST["ref_id"])) {
242  $table_gui->addMultiCommand("confirmDeleteRecords", $this->lng->txt("delete"));
243  $table_gui->addCommandButton("updateRecords", $this->lng->txt("save"));
244  }
245 
246  $DIC->ui()->mainTemplate()->setContent($table_gui->getHTML());
247  return true;
248  }
249 
253  protected function showPresentation()
254  {
255  $this->setSubTabs($this->context);
256  if ($this->initFormSubstitutions()) {
257  if (is_object($this->form)) {
258  $this->tabs_gui->setSubTabActive('md_adv_presentation');
259  return $this->tpl->setContent($this->form->getHTML());
260  }
261  }
262  return $this->showRecords();
263  }
264 
271  public function updateSubstitutions()
272  {
273  global $DIC;
274 
275  $ilAccess = $DIC['ilAccess'];
276 
277  if (!$ilAccess->checkAccess('write', '', $_REQUEST["ref_id"])) {
278  $this->ctrl->redirect($this, "showPresentation");
279  }
280 
282  $perm = null;
283 
284  if (in_array($obj_type, $this->permissions->getAllowedObjectTypes())) {
285  $perm = $this->getPermissions()->hasPermissions(
287  $obj_type,
288  array(
292  )
293  );
294  }
295 
296  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
298 
300  $sub->enableDescription($_POST['enabled_desc_' . $obj_type]);
301  }
302 
304  $sub->enableFieldNames((int) $_POST['enabled_field_names_' . $obj_type]);
305  }
306 
307  $definitions = ilAdvancedMDFieldDefinition::getInstancesByObjType($obj_type);
308  $definitions = $sub->sortDefinitions($definitions);
309 
310  // gather existing data
311  $counter = 1;
312  $old_sub = array();
313  foreach ($definitions as $def) {
314  $field_id = $def->getFieldId();
315  $old_sub[$field_id] = array(
316  "active" => $sub->isSubstituted($field_id),
317  "pos" => $counter++,
318  "bold" => $sub->isBold($field_id),
319  "newline" => $sub->hasNewline($field_id)
320  );
321  }
322 
323  $sub->resetSubstitutions(array());
324 
325  $new_sub = array();
326  foreach ($definitions as $def) {
327  $field_id = $def->getFieldId();
328  $old = $old_sub[$field_id];
329 
330  $perm_def = $this->getSubstitutionFieldPermissions($obj_type, $field_id);
331  if ($perm_def["show"]) {
332  $active = (isset($_POST['show'][$obj_type][$field_id]) && $_POST['show'][$obj_type][$field_id]);
333  } else {
334  $active = $old["active"];
335  }
336 
337  if ($active) {
338  $new_sub[$field_id] = $old;
339 
341  $new_sub[$field_id]["pos"] = (int) $_POST['position'][$obj_type][$field_id];
342  }
343  if ($perm_def["bold"]) {
344  $new_sub[$field_id]["bold"] = (isset($_POST['bold'][$obj_type][$field_id]) && $_POST['bold'][$obj_type][$field_id]);
345  }
346  if ($perm_def["newline"]) {
347  $new_sub[$field_id]["newline"] = (isset($_POST['newline'][$obj_type][$field_id]) && $_POST['newline'][$obj_type][$field_id]);
348  }
349  }
350  }
351 
352  if (sizeof($new_sub)) {
353  $new_sub = ilUtil::sortArray($new_sub, "pos", "asc", true, true);
354  foreach ($new_sub as $field_id => $field) {
355  $sub->appendSubstitution($field_id, $field["bold"], $field["newline"]);
356  }
357  }
358 
359  $sub->update();
360  }
361 
362 
363  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
364  $this->ctrl->redirect($this, "showPresentation");
365  }
366 
372  public function exportRecords()
373  {
374  if (!isset($_POST['record_id'])) {
375  ilUtil::sendFailure($this->lng->txt('select_one'));
376  $this->showRecords();
377  return false;
378  }
379 
380  // all records have to be exportable
381  $fail = array();
382  foreach ($_POST['record_id'] as $record_id) {
383  if (!$this->getPermissions()->hasPermission(
385  $record_id,
387  )) {
389  $fail[] = $record->getTitle();
390  }
391  }
392  if ($fail) {
393  ilUtil::sendFailure($this->lng->txt('msg_no_perm_copy') . " " . implode(", ", $fail), true);
394  $this->ctrl->redirect($this, "showRecords");
395  }
396 
397  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordXMLWriter.php');
398  $xml_writer = new ilAdvancedMDRecordXMLWriter($_POST['record_id']);
399  $xml_writer->write();
400 
401  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
402  $export_files = new ilAdvancedMDRecordExportFiles($this->obj_id);
403  $export_files->create($xml_writer->xmlDumpMem());
404 
405  ilUtil::sendSuccess($this->lng->txt('md_adv_records_exported'));
406  $this->showFiles();
407  }
408 
412  protected function showFiles()
413  {
414  $this->setSubTabs($this->context);
415  $this->tabs_gui->setSubTabActive('md_adv_file_list');
416 
417  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
418  $files = new ilAdvancedMDRecordExportFiles($this->obj_id);
419  $file_data = $files->readFilesInfo();
420 
421  include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFilesTableGUI.php");
422  $table_gui = new ilAdvancedMDRecordExportFilesTableGUI($this, "showFiles");
423  $table_gui->setTitle($this->lng->txt("md_record_export_table"));
424  $table_gui->parseFiles($file_data);
425  $table_gui->addMultiCommand("downloadFile", $this->lng->txt('download'));
426 
427  if ($GLOBALS['DIC']->access()->checkAccess('write', '', $this->ref_id)) {
428  $table_gui->addMultiCommand("confirmDeleteFiles", $this->lng->txt("delete"));
429  }
430  $table_gui->setSelectAllCheckbox("file_id");
431 
432  $this->tpl->setContent($table_gui->getHTML());
433  }
434 
442  public function downloadFile()
443  {
444  if (!isset($_POST['file_id']) or count($_POST['file_id']) != 1) {
445  ilUtil::sendFailure($this->lng->txt('md_adv_select_one_file'));
446  $this->showFiles();
447  return false;
448  }
449 
450  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
451  $files = new ilAdvancedMDRecordExportFiles($this->obj_id);
452  $abs_path = $files->getAbsolutePathByFileId((int) $_POST['file_id'][0]);
453 
454  ilUtil::deliverFile($abs_path, 'ilias_meta_data_record.xml', 'application/xml');
455  }
456 
463  public function confirmDeleteFiles()
464  {
465  if (!isset($_POST['file_id'])) {
466  ilUtil::sendFailure($this->lng->txt('select_one'));
467  $this->showFiles();
468  return false;
469  }
470 
471  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
472  $c_gui = new ilConfirmationGUI();
473 
474  // set confirm/cancel commands
475  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFiles"));
476  $c_gui->setHeaderText($this->lng->txt("md_adv_delete_files_sure"));
477  $c_gui->setCancel($this->lng->txt("cancel"), "showFiles");
478  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFiles");
479 
480  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
481  $files = new ilAdvancedMDRecordExportFiles($this->obj_id);
482  $file_data = $files->readFilesInfo();
483 
484 
485  // add items to delete
486  foreach ($_POST["file_id"] as $file_id) {
487  $info = $file_data[$file_id];
488  $c_gui->addItem("file_id[]", $file_id, is_array($info['name']) ? implode(',', $info['name']) : 'No Records');
489  }
490  $this->tpl->setContent($c_gui->getHTML());
491  }
492 
500  public function deleteFiles()
501  {
502  if (!isset($_POST['file_id'])) {
503  ilUtil::sendFailure($this->lng->txt('select_one'));
504  $this->editFiles();
505  return false;
506  }
507 
508  if (!$GLOBALS['DIC']->access()->checkAccess('write', '', $this->ref_id)) {
509  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
510  $GLOBALS['DIC']->ctrl()->redirect($this, 'showFiles');
511  }
512 
513  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
514  $files = new ilAdvancedMDRecordExportFiles($this->obj_id);
515 
516  foreach ($_POST['file_id'] as $file_id) {
517  $files->deleteByFileId((int) $file_id);
518  }
519  ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_files'));
520  $this->showFiles();
521  }
522 
529  public function confirmDeleteRecords()
530  {
531  $this->initRecordObject();
532  $this->setRecordSubTabs();
533 
534  if (!isset($_POST['record_id'])) {
535  ilUtil::sendFailure($this->lng->txt('select_one'));
536  $this->showRecords();
537  return false;
538  }
539 
540  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
541  $c_gui = new ilConfirmationGUI();
542 
543  // set confirm/cancel commands
544  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteRecords"));
545  $c_gui->setHeaderText($this->lng->txt("md_adv_delete_record_sure"));
546  $c_gui->setCancel($this->lng->txt("cancel"), "showRecords");
547  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteRecords");
548 
549  // add items to delete
550  foreach ($_POST["record_id"] as $record_id) {
552  $c_gui->addItem("record_id[]", $record_id, $record->getTitle() ? $record->getTitle() : 'No Title');
553  }
554  $this->tpl->setContent($c_gui->getHTML());
555  }
556 
563  public function deleteRecords()
564  {
565  if (!isset($_POST['record_id'])) {
566  ilUtil::sendFailure($this->lng->txt('select_one'));
567  $this->showRecords();
568  return false;
569  }
570 
571  // all records have to be deletable
572  $fail = array();
573  foreach ($_POST['record_id'] as $record_id) {
574  // must not delete global records in local context
575  if ($this->context == self::CONTEXT_OBJECT) {
577  if (!$record->getParentObject()) {
578  $fail[] = $record->getTitle();
579  }
580  }
581 
582  if (!$this->getPermissions()->hasPermission(
584  $record_id,
586  )) {
588  $fail[] = $record->getTitle();
589  }
590  }
591  if ($fail) {
592  ilUtil::sendFailure($this->lng->txt('msg_no_perm_delete') . " " . implode(", ", $fail), true);
593  $this->ctrl->redirect($this, "showRecords");
594  }
595 
596  foreach ($_POST['record_id'] as $record_id) {
598  $record->delete();
599  }
600  ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_records'), true);
601  $this->ctrl->redirect($this, "showRecords");
602  }
603 
611  public function updateRecords()
612  {
613  // sort positions and renumber
614  $positions = $_POST['pos'];
615  asort($positions, SORT_NUMERIC);
616 
617  $sorted_positions = [];
618  $i = 1;
619  foreach ($positions as $record_id => $pos) {
620  $sorted_positions[$record_id] = $i++;
621  }
622  $selected_global = array();
623  foreach ($this->getParsedRecordObjects() as $item) {
624  $perm = $this->getPermissions()->hasPermissions(
626  $item['id'],
627  array(
631  )
632  );
633 
634  if ($this->context == self::CONTEXT_ADMINISTRATION) {
635  $record_obj = ilAdvancedMDRecord::_getInstanceByRecordId($item['id']);
636 
638  $obj_types = array();
639  if (is_array($_POST['obj_types'][$record_obj->getRecordId()])) {
640  foreach ($_POST['obj_types'][$record_obj->getRecordId()] as $type => $status) {
641  if ($status) {
642  $type = explode(":", $type);
643  $obj_types[] = array(
644  "obj_type" => ilUtil::stripSlashes($type[0]),
645  "sub_type" => ilUtil::stripSlashes($type[1]),
646  "optional" => ((int) $status == 2)
647  );
648  }
649  }
650  }
651  $record_obj->setAssignedObjectTypes($obj_types);
652  }
653 
655  $record_obj->setActive(isset($_POST['active'][$record_obj->getRecordId()]));
656  }
657 
658  $record_obj->setGlobalPosition((int) $sorted_positions[$record_obj->getRecordId()]);
659  $record_obj->update();
661  // global, optional record
662  if ($item['readonly'] &&
663  $item['optional'] &&
664  $_POST['active'][$item['id']]) {
665  $selected_global[] = $item['id'];
666  } elseif ($item['local']) {
667  $record_obj = ilAdvancedMDRecord::_getInstanceByRecordId($item['id']);
668  $record_obj->setActive(isset($_POST['active'][$item['id']]));
669  $record_obj->update();
670  }
671  }
672 
673  // save local sorting
674  if ($this->context == self::CONTEXT_OBJECT) {
675  global $DIC;
676 
677  $local_position = new \ilAdvancedMDRecordObjectOrdering($item['id'], $this->obj_id, $DIC->database());
678  $local_position->setPosition((int) $sorted_positions[$item['id']]);
679  $local_position->save();
680  }
681  }
682 
683  if ($this->obj_type) {
684  ilAdvancedMDRecord::saveObjRecSelection($this->obj_id, $this->sub_type, $selected_global);
685  }
686 
687  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
688  $this->ctrl->redirect($this, "showRecords");
689  }
690 
697  public function confirmDeleteFields()
698  {
699  if (!isset($_POST['field_id'])) {
700  ilUtil::sendFailure($this->lng->txt('select_one'));
701  $this->editFields();
702  return false;
703  }
704 
705  $this->initRecordObject();
706  $this->setRecordSubTabs(2);
707 
708  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
709  $c_gui = new ilConfirmationGUI();
710 
711  // set confirm/cancel commands
712  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFields"));
713  $c_gui->setHeaderText($this->lng->txt("md_adv_delete_fields_sure"));
714  $c_gui->setCancel($this->lng->txt("cancel"), "editFields");
715  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFields");
716 
717  // add items to delete
718  foreach ($_POST["field_id"] as $field_id) {
719  $field = ilAdvancedMDFieldDefinition::getInstance($field_id);
720  $c_gui->addItem("field_id[]", $field_id, $field->getTitle() ? $field->getTitle() : 'No Title');
721  }
722  $this->tpl->setContent($c_gui->getHTML());
723  }
724 
732  public function deleteFields()
733  {
734  $this->ctrl->saveParameter($this, 'record_id');
735 
736  if (!isset($_POST['field_id'])) {
737  ilUtil::sendFailure($this->lng->txt('select_one'));
738  $this->editFields();
739  return false;
740  }
741 
742  // all fields have to be deletable
743  $fail = array();
744  foreach ($_POST['field_id'] as $field_id) {
745  if (!$this->getPermissions()->hasPermission(
747  $field_id,
749  )) {
750  $field = ilAdvancedMDFieldDefinition::getInstance($field_id);
751  $fail[] = $field->getTitle();
752  }
753  }
754  if ($fail) {
755  ilUtil::sendFailure($this->lng->txt('msg_no_perm_delete') . " " . implode(", ", $fail), true);
756  $this->ctrl->redirect($this, "editFields");
757  }
758 
759  foreach ($_POST["field_id"] as $field_id) {
760  $field = ilAdvancedMDFieldDefinition::getInstance($field_id);
761  $field->delete();
762  }
763  ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_fields'), true);
764  $this->ctrl->redirect($this, "editFields");
765  }
766 
774  public function editRecord(ilPropertyFormGUI $form = null)
775  {
776  $record_id = $this->request->getQueryParams()['record_id'] ?? 0;
777  if (!$record_id) {
778  $this->ctrl->redirect($this, 'showRecords');
779  }
780  $this->initRecordObject();
781  $this->setRecordSubTabs(1, true);
782  $this->tabs_gui->activateTab(self::TAB_RECORD_SETTINGS);
783 
784  if (!$form instanceof ilPropertyFormGUI) {
785  $this->initLanguage($record_id);
786  $this->showLanguageSwitch($record_id, 'editRecord');
787  $this->initForm('edit');
788  }
789  $this->tpl->setContent($this->form->getHTML());
790  }
791 
792  protected function editFields()
793  {
794  global $DIC;
795 
796  $record_id = $this->request->getQueryParams()['record_id'] ?? 0;
797 
798  $this->ctrl->saveParameter($this, 'record_id');
799  $this->initRecordObject();
800  $this->setRecordSubTabs();
801  $this->initLanguage($record_id);
802  $this->showLanguageSwitch($record_id, 'editFields');
803 
804 
805  $perm = $this->getPermissions()->hasPermissions(
807  $this->record->getRecordId(),
808  array(
811  )
812  );
813 
814  $filter_warn = array();
816  // type selection
817  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
818  $types = new ilSelectInputGUI("", "ftype");
819  $options = array();
821  $field = ilAdvancedMDFieldDefinition::getInstance(null, $type);
822  $options[$type] = $this->lng->txt($field->getTypeTitle());
823 
824  if (!$field->isFilterSupported()) {
825  $filter_warn[] = $this->lng->txt($field->getTypeTitle());
826  }
827  }
828  $types->setOptions($options);
829 
830  if (count($this->toolbar->getItems())) {
831  $this->toolbar->addSeparator();
832  }
833  $this->toolbar->addInputItem($types);
834 
835  $this->toolbar->setFormAction($this->ctrl->getFormAction($this, "createField"));
836 
837  include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
838  $button = ilSubmitButton::getInstance();
839  $button->setCaption("add");
840  $button->setCommand("createField");
841  $this->toolbar->addButtonInstance($button);
842  }
843 
844  // #17092
845  if (sizeof($filter_warn)) {
846  ilUtil::sendInfo(sprintf($this->lng->txt("md_adv_field_filter_warning"), implode(", ", $filter_warn)));
847  }
848 
849  // show field table
850  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
851  $fields = ilAdvancedMDFieldDefinition::getInstancesByRecordId($this->record->getRecordId(), false, $this->active_language);
852 
853  include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldTableGUI.php");
854  $table_gui = new ilAdvancedMDFieldTableGUI(
855  $this,
856  'editFields',
857  $this->getPermissions(),
859  $this->active_language
860  );
861  $table_gui->setTitle($this->lng->txt("md_adv_field_table"));
862  $table_gui->parseDefinitions($fields);
863  if (sizeof($fields)) {
864  $table_gui->addCommandButton("updateFields", $this->lng->txt("save"));
865  }
866  $table_gui->addCommandButton("showRecords", $this->lng->txt('cancel'));
867  $table_gui->addMultiCommand("confirmDeleteFields", $this->lng->txt("delete"));
868  $table_gui->setSelectAllCheckbox("field_id");
869 
870  $this->tpl->setContent($table_gui->getHTML());
871  }
872 
879  public function updateFields()
880  {
881  $this->ctrl->saveParameter($this, 'record_id');
882 
883  if (!isset($_GET['record_id']) or !$_GET['record_id']) {
884  ilUtil::sendFailure($this->lng->txt('select_one'));
885  $this->editFields();
886  return false;
887  }
888 
889  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
891 
892  if ($this->getPermissions()->hasPermission(
894  $_GET['record_id'],
896  )) {
897  if (!isset($_POST['position']) or !is_array($_POST['position'])) {
898  $this->editFields();
899  return false;
900  }
901  // sort by position
902  asort($_POST['position'], SORT_NUMERIC);
903  $positions = array_flip(array_keys($_POST['position']));
904  foreach ($fields as $field) {
905  $field->setPosition($positions[$field->getFieldId()]);
906  $field->update();
907  }
908  }
909 
910  foreach ($fields as $field) {
911  if ($this->getPermissions()->hasPermission(
913  $field->getFieldId(),
916  )) {
917  $field->setSearchable(isset($_POST['searchable'][$field->getFieldId()]) ? true : false);
918  $field->update();
919  }
920  }
921 
922  if ($this->request->getQueryParams()['mdlang']) {
923  $this->ctrl->setParameter($this, 'mdlang', $this->request->getQueryParams()['mdlang']);
924  }
925  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
926  $this->ctrl->redirect($this, "editFields");
927  }
928 
936  public function updateRecord()
937  {
938  $record_id = $this->request->getQueryParams()['record_id'] ?? 0;
939  if (!$record_id) {
940  $this->ctrl->redirect($this, 'showRecords');
941  }
942  $this->initRecordObject();
943  $this->initLanguage($record_id);
944  $this->showLanguageSwitch($record_id, 'editRecord');
945 
946  $this->initForm('edit');
947  if (!$this->form->checkInput()) {
948  ilUtil::sendFailure($this->lng->txt('err_check_input'));
949  $this->form->setValuesByPost();
950  $this->editRecord($this->form);
951  return false;
952  }
953 
954  $this->loadRecordFormData();
955  $this->record->update();
956 
957  $translations = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->record->getRecordId());
958  $translations->updateTranslations(
959  $this->active_language,
960  $this->form->getInput('title'),
961  $this->form->getInput('desc')
962  );
963 
964  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
965  $this->ctrl->redirect($this, 'editRecord');
966  return true;
967  }
968 
969 
977  public function createRecord(ilPropertyFormGUI $form = null)
978  {
979  $this->initRecordObject();
980  $this->setRecordSubTabs();
981  if (!$form instanceof ilPropertyFormGUI) {
982  $this->initForm('create');
983  }
984  $this->tpl->setContent($this->form->getHTML());
985  return true;
986  }
987 
988  protected function importRecords()
989  {
990  $this->initRecordObject();
991  $this->setRecordSubtabs();
992 
993  // Import Table
994  $this->initImportForm();
995  $this->tpl->setContent($this->import_form->getHTML());
996  }
997 
1001  protected function setRecordSubTabs(int $level = 1, bool $show_settings = false)
1002  {
1003  $this->tabs_gui->clearTargets();
1004  $this->tabs_gui->clearSubTabs();
1005 
1006  if ($level == 1) {
1007  $this->tabs_gui->setBackTarget(
1008  $this->lng->txt('md_adv_record_list'),
1009  $this->ctrl->getLinkTarget($this, 'showRecords')
1010  );
1011 
1012  if ($show_settings) {
1013  $this->tabs_gui->addTab(
1014  self::TAB_RECORD_SETTINGS,
1015  $this->lng->txt('settings'),
1016  $this->ctrl->getLinkTarget($this, self::TAB_RECORD_SETTINGS)
1017  );
1018  $this->ctrl->setParameterByClass(
1019  strtolower(\ilAdvancedMDRecordTranslationGUI::class),
1020  'record_id',
1021  $this->record->getRecordId()
1022  );
1023  $this->lng->loadLanguageModule('obj');
1024  $this->tabs_gui->addTab(
1025  self::TAB_TRANSLATION,
1026  $this->lng->txt('obj_multilinguality'),
1027  $this->ctrl->getLinkTargetByClass(
1028  strtolower(\ilAdvancedMDRecordTranslationGUI::class),
1029  ''
1030  )
1031  );
1032  }
1033  }
1034  if ($level == 2) {
1035  $this->tabs_gui->setBack2Target(
1036  $this->lng->txt('md_adv_record_list'),
1037  $this->ctrl->getLinkTarget($this, 'showRecords')
1038  );
1039  $this->tabs_gui->setBackTarget(
1040  $this->lng->txt('md_adv_field_list'),
1041  $this->ctrl->getLinkTarget($this, 'editFields')
1042  );
1043  }
1044  }
1045 
1051  protected function initImportForm()
1052  {
1053  if (is_object($this->import_form)) {
1054  return true;
1055  }
1056 
1057  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1058  $this->import_form = new ilPropertyFormGUI();
1059  $this->import_form->setMultipart(true);
1060  $this->import_form->setFormAction($this->ctrl->getFormAction($this));
1061 
1062  // add file property
1063  $file = new ilFileInputGUI($this->lng->txt('file'), 'file');
1064  $file->setSuffixes(array('xml'));
1065  $file->setRequired(true);
1066  $this->import_form->addItem($file);
1067 
1068  $this->import_form->setTitle($this->lng->txt('md_adv_import_record'));
1069  $this->import_form->addCommandButton('importRecord', $this->lng->txt('import'));
1070  $this->import_form->addCommandButton('showRecords', $this->lng->txt('cancel'));
1071  }
1072 
1080  public function importRecord()
1081  {
1082  $this->initImportForm();
1083  if (!$this->import_form->checkInput()) {
1084  $this->import_form->setValuesByPost();
1085  $this->importRecords();
1086  return false;
1087  }
1088 
1089  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordImportFiles.php');
1090  $import_files = new ilAdvancedMDRecordImportFiles();
1091  if (!$create_time = $import_files->moveUploadedFile($_FILES['file']['tmp_name'])) {
1092  $this->createRecord();
1093  return false;
1094  }
1095 
1096  try {
1097  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordParser.php');
1098  $parser = new ilAdvancedMDRecordParser($import_files->getImportFileByCreationDate($create_time));
1099 
1100  // local import?
1101  if ($this->context == self::CONTEXT_OBJECT) {
1102  $parser->setContext($this->obj_id, $this->obj_type, $this->sub_type);
1103  }
1104 
1105  // Validate
1107  $parser->startParsing();
1108 
1109  // Insert
1110  $parser->setMode(ilAdvancedMDRecordParser::MODE_INSERT);
1111  $parser->startParsing();
1112  ilUtil::sendSuccess($this->lng->txt('md_adv_added_new_record'), true);
1113  $this->ctrl->redirect($this, "showRecords");
1114  } catch (ilSAXParserException $exc) {
1115  ilUtil::sendFailure($exc->getMessage(), true);
1116  $this->ctrl->redirect($this, "importRecords");
1117  }
1118 
1119  // Finally delete import file
1120  $import_files->deleteFileByCreationDate($create_time);
1121  return true;
1122  }
1123 
1124 
1132  public function saveRecord()
1133  {
1134  $this->initRecordObject();
1135  $this->initForm('create');
1136  if (!$this->form->checkInput()) {
1137  ilUtil::sendFailure($this->lng->txt('err_check_input'));
1138  $this->createRecord($this->form);
1139  return false;
1140  }
1141 
1142  $record = $this->loadRecordFormData();
1143  if ($this->obj_type) {
1144  $this->record->setAssignedObjectTypes(array(
1145  array(
1146  "obj_type" => $this->obj_type,
1147  "sub_type" => $this->sub_type,
1148  "optional" => false
1149  )));
1150  }
1151 
1152  $record->setDefaultLanguage($this->lng->getDefaultLanguage());
1153  $record->save();
1154 
1155  $translations = ilAdvancedMDRecordTranslations::getInstanceByRecordId($record->getRecordId());
1156  $translations->addTranslationEntry($record->getDefaultLanguage(), true);
1157  $translations->updateTranslations(
1158  $record->getDefaultLanguage(),
1159  $this->form->getInput('title'),
1160  $this->form->getInput('desc')
1161  );
1162  ilUtil::sendSuccess($this->lng->txt('md_adv_added_new_record'), true);
1163  $this->ctrl->redirect($this, 'showRecords');
1164  }
1165 
1172  public function editField(ilPropertyFormGUI $a_form = null)
1173  {
1174  $record_id = (int) ($this->request->getQueryParams()['record_id'] ?? 0);
1175  $field_id = (int) ($this->request->getQueryParams()['field_id'] ?? 0);
1176  if (!$record_id || !$field_id) {
1177  return $this->editFields();
1178  }
1179  $this->ctrl->saveParameter($this, 'field_id');
1180  $this->ctrl->saveParameter($this, 'record_id');
1181  $this->initRecordObject();
1182  $this->setRecordSubTabs(2);
1183 
1184  $field_definition = ilAdvancedMDFieldDefinition::getInstance((int) $field_id);
1185 
1186  if (!$a_form instanceof ilPropertyFormGUI) {
1187  $this->initLanguage($this->record->getRecordId());
1188  $this->showLanguageSwitch($this->record->getRecordId(), 'editField');
1189  $a_form = $this->initFieldForm($field_definition);
1190  }
1191  $table = null;
1192  if ($field_definition->hasComplexOptions()) {
1193  $table = $field_definition->getComplexOptionsOverview($this, "editField");
1194  }
1195  $this->tpl->setContent($a_form->getHTML() . $table);
1196  }
1197 
1204  public function updateField()
1205  {
1206  $record_id = $this->request->getQueryParams()['record_id'] ?? 0;
1207  $field_id = $this->request->getQueryParams()['field_id'] ?? 0;
1208  $this->ctrl->saveParameter($this, 'record_id');
1209  $this->ctrl->saveParameter($this, 'field_id');
1210 
1211  if (!$record_id || !$field_id) {
1212  return $this->editFields();
1213  }
1214 
1215  $this->initRecordObject();
1216  $this->initLanguage($record_id);
1217  $this->showLanguageSwitch($record_id, 'editField');
1218 
1219  $confirm = false;
1220  $field_definition = ilAdvancedMDFieldDefinition::getInstance((int) $field_id);
1221  $form = $this->initFieldForm($field_definition);
1222  if ($form->checkInput()) {
1223  $field_definition->importDefinitionFormPostValues($form, $this->getPermissions(), $this->active_language);
1224  if (!$field_definition->importDefinitionFormPostValuesNeedsConfirmation()) {
1225  $field_definition->update();
1226  $translations = ilAdvancedMDFieldTranslations::getInstanceByRecordId($this->record->getRecordId());
1227  $translations->updateFromForm($field_id, $this->active_language, $form);
1228 
1229  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
1230  $this->ctrl->redirect($this, 'editField');
1231  } else {
1232  $confirm = true;
1233  }
1234  }
1235 
1236  $form->setValuesByPost();
1237 
1238  // fields needs confirmation of updated settings
1239  if ($confirm) {
1240  ilUtil::sendInfo($this->lng->txt("md_adv_confirm_definition"));
1241  $field_definition->prepareDefinitionFormConfirmation($form);
1242  }
1243 
1244  $this->editField($form);
1245  }
1246 
1253  public function createField(ilPropertyFormGUI $a_form = null)
1254  {
1255  $this->initRecordObject();
1256  $this->ctrl->saveParameter($this, 'ftype');
1257  $this->setRecordSubTabs(2);
1258 
1259  if (!$_REQUEST["record_id"] || !$_REQUEST["ftype"]) {
1260  return $this->editFields();
1261  }
1262 
1263 
1264  if (!$a_form) {
1265  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1266  $field_definition = ilAdvancedMDFieldDefinition::getInstance(null, $_REQUEST["ftype"]);
1267  $field_definition->setRecordId($_REQUEST["record_id"]);
1268  $a_form = $this->initFieldForm($field_definition);
1269  }
1270  $this->tpl->setContent($a_form->getHTML());
1271  }
1272 
1278  public function saveField()
1279  {
1280  $record_id = $this->request->getQueryParams()['record_id'];
1281  $ftype = $this->request->getQueryParams()['ftype'];
1282 
1283  if (!$record_id || !$ftype) {
1284  return $this->editFields();
1285  }
1286 
1287  $this->initRecordObject();
1288  $this->initLanguage($record_id);
1289  $this->ctrl->saveParameter($this, 'ftype');
1290 
1291  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1292  $field_definition = ilAdvancedMDFieldDefinition::getInstance(null, $ftype);
1293  $field_definition->setRecordId($record_id);
1294  $form = $this->initFieldForm($field_definition);
1295 
1296  if ($form->checkInput()) {
1297  $field_definition->importDefinitionFormPostValues($form, $this->getPermissions(), $this->active_language);
1298  $field_definition->save();
1299 
1300  $translations = ilAdvancedMDFieldTranslations::getInstanceByRecordId($record_id);
1301  $translations->read();
1302  $translations->updateFromForm($field_definition->getFieldId(), $this->active_language, $form);
1303 
1304  ilUtil::sendSuccess($this->lng->txt('save_settings'), true);
1305  $this->ctrl->redirect($this, "editFields");
1306  }
1307 
1308  $form->setValuesByPost();
1309  $this->createField($form);
1310  }
1311 
1317  protected function initFieldForm(ilAdvancedMDFieldDefinition $a_definition)
1318  {
1319  $is_creation_mode = $a_definition->getFieldId() ? false : true;
1320 
1321  $form = new ilPropertyFormGUI();
1322  $form->setFormAction($this->ctrl->getFormAction($this));
1323 
1324  $translations = ilAdvancedMDFieldTranslations::getInstanceByRecordId($this->record->getRecordId());
1325  if ($is_creation_mode) {
1326  $form->setDescription($a_definition->getDescription());
1327  } else {
1328  $form->setDescription($translations->getFormTranslationInfo(
1329  $a_definition->getFieldId(),
1331  ));
1332  }
1333  $type = new ilNonEditableValueGUI($this->lng->txt("type"));
1334  $type->setValue($this->lng->txt($a_definition->getTypeTitle()));
1335  $form->addItem($type);
1336  $a_definition->addToFieldDefinitionForm($form, $this->getPermissions(), $this->active_language);
1337 
1338  if ($is_creation_mode) {
1339  $form->setTitle($this->lng->txt('md_adv_create_field'));
1340  $form->addCommandButton('saveField', $this->lng->txt('create'));
1341  } else {
1342  $form->setTitle($this->lng->txt('md_adv_edit_field'));
1343  $form->addCommandButton('updateField', $this->lng->txt('save'));
1344  }
1345 
1346  $form->addCommandButton('editFields', $this->lng->txt('cancel'));
1347 
1348  return $form;
1349  }
1350 
1356  protected function initForm($a_mode)
1357  {
1358  if (is_object($this->form)) {
1359  return true;
1360  }
1361 
1362  $perm = $this->getPermissions()->hasPermissions(
1364  $this->record->getRecordId(),
1365  array(
1373  )
1374  );
1375 
1376  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1377 
1378  $this->form = new ilPropertyFormGUI();
1379 
1380  $translations = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->record->getRecordId());
1381  $this->form->setDescription($translations->getFormTranslationInfo($this->active_language));
1382  $this->form->setFormAction($this->ctrl->getFormAction($this));
1383 
1384 
1385  // title
1386  $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
1387  $title->setValue($this->record->getTitle());
1388  $title->setSize(20);
1389  $title->setMaxLength(70);
1390  $title->setRequired(true);
1391 
1393  $title->setDisabled(true);
1394  }
1395  $this->form->addItem($title);
1396  $translations->modifyTranslationInfoForTitle($this->form, $title, $this->active_language);
1397 
1398 
1399  // desc
1400  $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'desc');
1401  $desc->setValue($this->record->getDescription());
1402  $desc->setRows(3);
1403 
1405  $desc->setDisabled(true);
1406  }
1407  $this->form->addItem($desc);
1408  $translations->modifyTranslationInfoForDescription($this->form, $desc, $this->active_language);
1409 
1410  // active
1411  $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_active'), 'active');
1412  $check->setChecked($this->record->isActive());
1413  $check->setValue(1);
1414  $this->form->addItem($check);
1415 
1417  $check->setDisabled(true);
1418  }
1419 
1420  if (!$this->obj_type) {
1421  // scope
1422  $scope = new ilCheckboxInputGUI($this->lng->txt('md_adv_scope'), 'scope');
1423  $scope->setInfo($this->lng->txt('md_adv_scope_info'));
1424  $scope->setChecked($this->record->enabledScope());
1425  $scope->setValue(1);
1426  $this->form->addItem($scope);
1427 
1428  $subitems = new ilRepositorySelector2InputGUI(
1429  $this->lng->txt('md_adv_scope_objects'),
1430  "scope_containers",
1431  true
1432  );
1433  $subitems->setValue($this->record->getScopeRefIds());
1434  $exp = $subitems->getExplorerGUI();
1435 
1436  $definition = $GLOBALS['DIC']['objDefinition'];
1437  $white_list = [];
1438  foreach ($definition->getAllRepositoryTypes() as $type) {
1439  if ($definition->isContainer($type)) {
1440  $white_list[] = $type;
1441  }
1442  }
1443 
1444 
1445  $exp->setTypeWhiteList($white_list);
1446  $exp->setSkipRootNode(false);
1447  $exp->setRootId(ROOT_FOLDER_ID);
1448  $scope->addSubItem($subitems);
1449  }
1450 
1451  if (!$this->obj_type) {
1453  $section->setTitle($this->lng->txt('md_obj_types'));
1454  $this->form->addItem($section);
1455 
1456  // see ilAdvancedMDRecordTableGUI::fillRow()
1457  $options = array(
1458  0 => $this->lng->txt("meta_obj_type_inactive"),
1459  1 => $this->lng->txt("meta_obj_type_mandatory"),
1460  2 => $this->lng->txt("meta_obj_type_optional")
1461  );
1462 
1463 
1465  $t = $type["obj_type"] . ":" . $type["sub_type"];
1466  $this->lng->loadLanguageModule($type["obj_type"]);
1467 
1468  $type_options = $options;
1469  switch ($type["obj_type"]) {
1470  case "orgu":
1471  // currently only optional records for org unit (types)
1472  unset($type_options[1]);
1473  break;
1474  case "prg":
1475  // currently only optional records for study programme (types)
1476  unset($type_options[1]);
1477  break;
1478  case "rcrs":
1479  // optional makes no sense for ecs-courses
1480  unset($type_options[2]);
1481  break;
1482  }
1483 
1484  $value = 0;
1485  if ($a_mode == "edit") {
1486  foreach ($this->record->getAssignedObjectTypes() as $item) {
1487  if ($item["obj_type"] == $type["obj_type"] &&
1488  $item["sub_type"] == $type["sub_type"]) {
1489  $value = $item["optional"]
1490  ? 2
1491  : 1;
1492  }
1493  }
1494  }
1495 
1496  $sel_name = 'obj_types__' . $t;
1497  $check = new ilSelectInputGUI($type['text'], $sel_name);
1498  //$check = new ilSelectInputGUI($type["text"], 'obj_types[' . $t . ']');
1499  $check->setOptions($type_options);
1500  $check->setValue($value);
1501  $this->form->addItem($check);
1502 
1504  $check->setDisabled(true);
1505  }
1506  }
1507  }
1508 
1509  switch ($a_mode) {
1510  case 'create':
1511  $this->form->setTitle($this->lng->txt('md_adv_create_record'));
1512  $this->form->addCommandButton('saveRecord', $this->lng->txt('add'));
1513  $this->form->addCommandButton('showRecords', $this->lng->txt('cancel'));
1514 
1515  return true;
1516 
1517  case 'edit':
1518  $this->form->setTitle($this->lng->txt('md_adv_edit_record'));
1519  $this->form->addCommandButton('updateRecord', $this->lng->txt('save'));
1520  $this->form->addCommandButton('showRecords', $this->lng->txt('cancel'));
1521 
1522  return true;
1523  }
1524  }
1525 
1526  protected function getSubstitutionFieldPermissions($a_obj_type, $a_field_id)
1527  {
1528  if ($a_obj_type == "crs") {
1529  $perm = $this->getPermissions()->hasPermissions(
1531  $a_field_id,
1532  array(
1538  )
1539  );
1540  return array(
1544  );
1545  } elseif ($a_obj_type == "cat") {
1546  $perm = $this->getPermissions()->hasPermissions(
1548  $a_field_id,
1549  array(
1555  )
1556  );
1557  return array(
1561  );
1562  } elseif ($a_obj_type == "sess") {
1563  $perm = $this->getPermissions()->hasPermissions(
1565  $a_field_id,
1566  array(
1572  )
1573  );
1574  return array(
1578  );
1579  } elseif ($a_obj_type == "grp") {
1580  $perm = $this->getPermissions()->hasPermissions(
1582  $a_field_id,
1583  array(
1589  )
1590  );
1591  return array(
1595  );
1596  } elseif ($a_obj_type == "iass") {
1597  $perm = $this->getPermissions()->hasPermissions(
1599  $a_field_id,
1600  array(
1606  )
1607  );
1608  return array(
1612  );
1613  } elseif ($a_obj_type == "exc") {
1614  $perm = $this->getPermissions()->hasPermissions(
1616  $a_field_id,
1617  array(
1623  )
1624  );
1625  return array(
1629  );
1630  }
1631  }
1632 
1638  protected function initFormSubstitutions()
1639  {
1640  global $DIC;
1641 
1642  $ilAccess = $DIC['ilAccess'];
1643 
1644  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1645 
1646  if (!$visible_records = ilAdvancedMDRecord::_getAllRecordsByObjectType()) {
1647  return;
1648  }
1649 
1650  $this->form = new ilPropertyFormGUI();
1651  $this->form->setFormAction($this->ctrl->getFormAction($this));
1652  #$this->form->setTableWidth('100%');
1653 
1654  // substitution
1655  foreach ($visible_records as $obj_type => $records) {
1656  $perm = null;
1657 
1658  if (in_array($obj_type, $this->permissions->getAllowedObjectTypes())) {
1659  $perm = $this->getPermissions()->hasPermissions(
1661  $obj_type,
1662  array(
1666  )
1667  );
1668  }
1669 
1671 
1672  // Show section
1674  $section->setTitle($this->lng->txt('objs_' . $obj_type));
1675  $this->form->addItem($section);
1676 
1677  $check = new ilCheckboxInputGUI($this->lng->txt('description'), 'enabled_desc_' . $obj_type);
1678  $check->setValue(1);
1679  $check->setOptionTitle($this->lng->txt('md_adv_desc_show'));
1680  $check->setChecked($sub->isDescriptionEnabled() ? true : false);
1681  $this->form->addItem($check);
1682 
1684  $check->setDisabled(true);
1685  }
1686 
1687  $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_field_names'), 'enabled_field_names_' . $obj_type);
1688  $check->setValue(1);
1689  $check->setOptionTitle($this->lng->txt('md_adv_fields_show'));
1690  $check->setChecked($sub->enabledFieldNames() ? true : false);
1691  $this->form->addItem($check);
1692 
1694  $check->setDisabled(true);
1695  }
1696 
1697  #$area = new ilTextAreaInputGUI($this->lng->txt('md_adv_substitution'),'substitution_'.$obj_type);
1698  #$area->setUseRte(true);
1699  #$area->setRteTagSet('standard');
1700  #$area->setValue(ilUtil::prepareFormOutput($sub->getSubstitutionString()));
1701  #$area->setRows(5);
1702  #$area->setCols(80);
1703  #$this->form->addItem($area);
1704 
1705  if ($perm) {
1707  }
1708 
1710  $definitions = $sub->sortDefinitions($definitions);
1711 
1712  $counter = 1;
1713  foreach ($definitions as $def) {
1714  $definition_id = $def->getFieldId();
1715 
1716  $perm = $this->getSubstitutionFieldPermissions($obj_type, $definition_id);
1717 
1718  $title = ilAdvancedMDRecord::_lookupTitle($def->getRecordId());
1719  $title = $def->getTitle() . ' (' . $title . ')';
1720 
1721  $check = new ilCheckboxInputGUI($title, 'show[' . $obj_type . '][' . $definition_id . ']');
1722  $check->setValue(1);
1723  $check->setOptionTitle($this->lng->txt('md_adv_show'));
1724  $check->setChecked($sub->isSubstituted($definition_id));
1725 
1726  if ($perm && !$perm["show"]) {
1727  $check->setDisabled(true);
1728  }
1729 
1730  $pos = new ilNumberInputGUI($this->lng->txt('position'), 'position[' . $obj_type . '][' . $definition_id . ']');
1731  $pos->setSize(3);
1732  $pos->setMaxLength(4);
1733  $pos->allowDecimals(true);
1734  $pos->setValue(sprintf('%.1f', $counter++));
1735  $check->addSubItem($pos);
1736 
1737  if ($perm && !$perm_pos) {
1738  $pos->setDisabled(true);
1739  }
1740 
1741  $bold = new ilCheckboxInputGUI($this->lng->txt('bold'), 'bold[' . $obj_type . '][' . $definition_id . ']');
1742  $bold->setValue(1);
1743  $bold->setChecked($sub->isBold($definition_id));
1744  $check->addSubItem($bold);
1745 
1746  if ($perm && !$perm["bold"]) {
1747  $bold->setDisabled(true);
1748  }
1749 
1750  $bold = new ilCheckboxInputGUI($this->lng->txt('newline'), 'newline[' . $obj_type . '][' . $definition_id . ']');
1751  $bold->setValue(1);
1752  $bold->setChecked($sub->hasNewline($definition_id));
1753  $check->addSubItem($bold);
1754 
1755  if ($perm && !$perm["newline"]) {
1756  $bold->setDisabled(true);
1757  }
1758 
1759 
1760  $this->form->addItem($check);
1761  }
1762 
1763 
1764  // placeholder
1765  /*
1766  $custom = new ilCustomInputGUI($this->lng->txt('md_adv_placeholders'));
1767  $tpl = new ilTemplate('tpl.placeholder_info.html',true,true,'Services/AdvancedMetaData');
1768  foreach($records as $record)
1769  {
1770  foreach(ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record->getRecordId()) as $definition)
1771  {
1772  $tpl->setCurrentBlock('field');
1773  $tpl->setVariable('FIELD_NAME',$definition->getTitle());
1774  $tpl->setVariable('MODULE_VARS','[IF_F_'.$definition->getFieldId().']...[F_'.$definition->getFieldId().']'.
1775  '[/IF_F_'.$definition->getFieldId().']');
1776  $tpl->parseCurrentBlock();
1777  }
1778 
1779  $tpl->setCurrentBlock('record');
1780  $tpl->setVariable('PLACEHOLDER_FOR',$this->lng->txt('md_adv_placeholder_for'));
1781  $tpl->setVariable('TITLE',$record->getTitle());
1782  $tpl->parseCurrentBlock();
1783  }
1784  $custom->setHTML($tpl->get());
1785  $this->form->addItem($custom);
1786  */
1787  }
1788  $this->form->setTitle($this->lng->txt('md_adv_substitution_table'));
1789 
1790  if ($ilAccess->checkAccess('write', '', $_REQUEST["ref_id"])) {
1791  $this->form->addCommandButton('updateSubstitutions', $this->lng->txt('save'));
1792  }
1793 
1794  return true;
1795  }
1796 
1801  {
1802  $translations = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->record->getRecordId());
1803 
1804  $perm = $this->getPermissions()->hasPermissions(
1806  $this->record->getRecordId(),
1807  array(
1815  )
1816  );
1817 
1819  $this->record->setActive(ilUtil::stripSlashes($_POST['active']));
1820  }
1822  if (
1823  $translations->getDefaultTranslation() == null ||
1824  $translations->getDefaultTranslation()->getLangKey() == $this->active_language
1825  ) {
1826  $this->record->setTitle(ilUtil::stripSlashes($_POST['title']));
1827  }
1828  }
1830  if (
1831  $translations->getDefaultTranslation() == null ||
1832  $translations->getDefaultTranslation()->getLangKey() == $this->active_language) {
1833  $this->record->setDescription(ilUtil::stripSlashes($_POST['desc']));
1834  }
1835  }
1836 
1837  if (!$this->obj_type) {
1839  $obj_types = [];
1841  $t = $type["obj_type"] . ":" . $type["sub_type"];
1842  $value = $this->form->getInput('obj_types__' . $t);
1843  if (!$value) {
1844  continue;
1845  }
1846  $obj_types[] = [
1847  'obj_type' => $type['obj_type'],
1848  'sub_type' => $type['sub_type'],
1849  'optional' => ($value > 1)
1850  ];
1851  }
1852  $this->record->setAssignedObjectTypes($obj_types);
1853  }
1854  }
1855 
1856  $scopes = [];
1857  foreach ((array) $_POST['scope_containers_sel'] as $ref_id) {
1858  $scope = new ilAdvancedMDRecordScope();
1859  $scope->setRefId($ref_id);
1860  $scopes[] = $scope;
1861  }
1862  $this->record->setScopes($_POST['scope'] ? $scopes : []);
1863  $this->record->enableScope($_POST['scope'] ? true : false);
1864  return $this->record;
1865  }
1866 
1873  protected function initRecordObject()
1874  {
1875  if (!$this->record instanceof ilAdvancedMDRecord) {
1876  $record_id = $this->request->getQueryParams()['record_id'] ?? 0;
1877  $this->record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
1878  $this->ctrl->saveParameter($this, 'record_id');
1879 
1880  // bind to parent object (aka local adv md)
1881  if (!$record_id &&
1882  $this->obj_id) {
1883  $this->record->setParentObject($this->obj_id);
1884  }
1885  }
1886  return $this->record;
1887  }
1888 
1894  protected function setSubTabs(int $context)
1895  {
1896  if ($context == self::CONTEXT_OBJECT) {
1897  return;
1898  }
1899 
1900  $this->tabs_gui->clearSubTabs();
1901 
1902  $this->tabs_gui->addSubTabTarget(
1903  "md_adv_record_list",
1904  $this->ctrl->getLinkTarget($this, "showRecords"),
1905  '',
1906  '',
1907  '',
1908  true
1909  );
1910 
1911 
1913  $this->tabs_gui->addSubTabTarget(
1914  "md_adv_presentation",
1915  $this->ctrl->getLinkTarget($this, "showPresentation")
1916  );
1917  }
1918 
1919  $this->tabs_gui->addSubTabTarget(
1920  "md_adv_file_list",
1921  $this->ctrl->getLinkTarget($this, "showFiles"),
1922  "showFiles"
1923  );
1924  }
1925 
1931  protected function getParsedRecordObjects()
1932  {
1933  $res = array();
1934 
1935  if ($this->context == self::CONTEXT_OBJECT) {
1936  $selected = ilAdvancedMDRecord::getObjRecSelection($this->obj_id, $this->sub_type);
1937  }
1938 
1939  $records = ilAdvancedMDRecord::_getRecords();
1940  $orderings = new ilAdvancedMDRecordObjectOrderings();
1941  $records = $orderings->sortRecords($records, $this->obj_id);
1942 
1943  $position = 0;
1944  foreach ($records as $record) {
1945  $parent_id = $record->getParentObject();
1946 
1947  if ($this->context == self::CONTEXT_ADMINISTRATION) {
1948  if ($parent_id) {
1949  continue;
1950  }
1951  } else {
1952  // does not match current object
1953  if ($parent_id && $parent_id != $this->obj_id) {
1954  continue;
1955  }
1956 
1957  // inactive records only in administration
1958  if (!$parent_id && !$record->isActive()) {
1959  continue;
1960  }
1961  // scope needs to match in object context
1962  if (
1964  $this->ref_id,
1965  $record->getScopes()
1966  )
1967  ) {
1968  continue;
1969  }
1970  }
1971 
1972  $tmp_arr = array();
1973  $tmp_arr['id'] = $record->getRecordId();
1974  $tmp_arr['active'] = $record->isActive();
1975  $tmp_arr['title'] = $record->getTitle();
1976  $tmp_arr['description'] = $record->getDescription();
1977  $tmp_arr['fields'] = array();
1978  $tmp_arr['obj_types'] = $record->getAssignedObjectTypes();
1979  $position += 10;
1980  $tmp_arr['position'] = $position;
1981 
1982  $tmp_arr['perm'] = $this->permissions->hasPermissions(
1984  $record->getRecordId(),
1985  array(
1991  )
1992  );
1993 
1994  if ($this->obj_type) {
1995  $tmp_arr["readonly"] = !(bool) $parent_id;
1996  $tmp_arr["local"] = $parent_id;
1997 
1998  // local records are never optional
1999  $assigned = $optional = false;
2000  foreach ($tmp_arr['obj_types'] as $idx => $item) {
2001  if ($item["obj_type"] == $this->obj_type &&
2002  $item["sub_type"] == $this->sub_type) {
2003  $assigned = true;
2004  $optional = $item["optional"];
2005  $tmp_arr['obj_types'][$idx]['context'] = true;
2006  break;
2007  }
2008  }
2009  if (!$assigned) {
2010  continue;
2011  }
2012  $tmp_arr['optional'] = $optional;
2013  if ($optional) {
2014  // in object context "active" means selected record
2015  $tmp_arr['active'] = in_array($record->getRecordId(), $selected);
2016  }
2017  }
2018 
2019  $res[] = $tmp_arr;
2020  }
2021 
2022  return $res;
2023  }
2024 
2025 
2026  //
2027  // complex options
2028  //
2029 
2030  public function editComplexOption(ilPropertyFormGUI $a_form = null)
2031  {
2032  $field_definition = ilAdvancedMDFieldDefinition::getInstance((int) $_REQUEST['field_id']);
2033  if (!$field_definition->hasComplexOptions()) {
2034  $this->ctrl->redirect($this, "editField");
2035  }
2036 
2037  if (!$a_form) {
2038  $a_form = $this->initComplexOptionForm($field_definition);
2039  }
2040 
2041  $this->tpl->setContent($a_form->getHTML());
2042  }
2043 
2045  {
2046  $this->ctrl->saveParameter($this, "record_id");
2047  $this->ctrl->saveParameter($this, "field_id");
2048  $this->ctrl->saveParameter($this, "oid");
2049 
2050  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
2051  $form = new ilPropertyFormGUI();
2052  $form->setTitle($this->lng->txt("md_adv_edit_complex_option"));
2053  $form->setFormAction($this->ctrl->getFormAction($this, "updateComplexOption"));
2054 
2055  $a_def->initOptionForm($form, $_REQUEST["oid"]);
2056 
2057  $form->addCommandButton("updateComplexOption", $this->lng->txt("save"));
2058  $form->addCommandButton("editField", $this->lng->txt("cancel"));
2059 
2060  return $form;
2061  }
2062 
2063  public function updateComplexOption()
2064  {
2065  $field_definition = ilAdvancedMDFieldDefinition::getInstance((int) $_REQUEST['field_id']);
2066  if ($field_definition->hasComplexOptions()) {
2067  $form = $this->initComplexOptionForm($field_definition);
2068  if ($form->checkInput() &&
2069  $field_definition->updateComplexOption($form, $_REQUEST["oid"])) {
2070  $field_definition->update();
2071  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
2072  }
2073  }
2074 
2075  $this->ctrl->redirect($this, "editField");
2076  }
2077 
2081  protected function initLanguage(int $record_id)
2082  {
2083  $translations = ilAdvancedMDRecordTranslations::getInstanceByRecordId($record_id);
2084  // read active language
2085  $default = '';
2086  foreach ($translations->getTranslations() as $translation) {
2087  if ($translation->getLangKey() == $translations->getDefaultLanguage()) {
2088  $default = $translation->getLangKey();
2089  }
2090  }
2091  $active = $this->request->getQueryParams()['mdlang'] ?? $default;
2092  $this->active_language = $active;
2093  }
2094 
2098  protected function showLanguageSwitch(int $record_id, string $target) : void
2099  {
2100  $translations = ilAdvancedMDRecordTranslations::getInstanceByRecordId($record_id);
2101 
2102  if (count($translations->getTranslations()) <= 1) {
2103  return;
2104  }
2105  $actions = [];
2106  foreach ($translations->getTranslations() as $translation) {
2107  $this->ctrl->setParameter($this, 'mdlang', $translation->getLangKey());
2108  $actions[$translation->getLangKey()] = $this->ctrl->getLinkTarget(
2109  $this,
2110  $target
2111  );
2112  }
2113  $this->ctrl->setParameter($this, 'mdlang', $this->active_language);
2114  $view_control = $this->ui_factory->viewControl()->mode(
2115  $actions,
2116  $this->lng->txt('meta_aria_language_selection')
2117  )->withActive($this->active_language);
2118  $this->toolbar->addComponent($view_control);
2119  }
2120 }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
Scope restrictions for advanced md records.
static getInstance($a_user_id=null, $a_ref_id=null)
Factory.
initComplexOptionForm(ilAdvancedMDFieldDefinition $a_def)
setSubTabs(int $context)
Set sub tabs.
static _getRecords()
Get records.
This class represents a property form user interface.
$type
const ROOT_FOLDER_ID
Definition: constants.php:30
deleteRecords()
Permanently delete records.
$_GET["client_id"]
updateRecords()
Save records (assigned object typed)
This class represents a section header in a property form.
This class represents a file property in a property form.
getSubstitutionFieldPermissions($a_obj_type, $a_field_id)
editRecord(ilPropertyFormGUI $form=null)
Edit one record.
createRecord(ilPropertyFormGUI $form=null)
Show.
setValue($a_value)
Set Value.
This class represents a checkbox property in a property form.
getParsedRecordObjects()
Get and cache record objects.
setRecordSubTabs(int $level=1, bool $show_settings=false)
Set subtabs for record editing/creation.
static isFilteredByScope($a_ref_id, array $scopes)
Check if a given ref id is not filtered by scope restriction.
static saveObjRecSelection($a_obj_id, $a_sub_type="", array $a_records=null, $a_delete_before=true)
Save repository object record selection.
static _getInstanceByObjectType($a_type)
Singleton: use this method to get an instance.
editComplexOption(ilPropertyFormGUI $a_form=null)
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$section
Definition: Utf8Test.php:83
setChecked($a_checked)
Set Checked.
confirmDeleteFiles()
confirm delete files
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
Advanced metadata permission helper.
foreach($_POST as $key=> $value) $res
showLanguageSwitch(int $record_id, string $target)
This class represents a number property in a property form.
static getInstancesByObjType($a_obj_type, $a_active_only=true)
static _lookupObjId($a_id)
setValue($a_value)
Set Value.
global $DIC
Definition: goto.php:24
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static _getAllRecordsByObjectType()
Get records by obj_type Note: this returns only records with no sub types! public.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static _lookupTitle($a_record_id)
Lookup title.
createField(ilPropertyFormGUI $a_form=null)
Show field type selection.
static getValidTypes()
Get all valid types.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
editField(ilPropertyFormGUI $a_form=null)
Edit field.
setSize($a_size)
Set Size.
setContext($a_obj_id, $a_obj_type, $a_sub_type=null)
static _getAssignableObjectTypes($a_include_text=false)
Get assignable object type.
updateSubstitutions()
Update substitution.
This class represents a non editable value in a property form.
This class represents a text area property in a property form.
static getInstance($a_field_id, $a_type=null, string $language='')
Get definition instance by type.
initFormSubstitutions()
init form table &#39;substitutions&#39;
static _getActivatedObjTypes()
get activated obj types
initFieldForm(ilAdvancedMDFieldDefinition $a_definition)
init field form
SAX based XML parser for record import files.
addToFieldDefinitionForm(ilPropertyFormGUI $a_form, ilAdvancedMDPermissionHelper $a_permissions, string $language='')
Add input elements to definition form.
setSuffixes($a_suffixes)
Set Accepted Suffixes.
static getInstancesByRecordId($a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
$_POST["username"]
static getObjRecSelection($a_obj_id, $a_sub_type="")
Get repository object record selection.
confirmDeleteFields()
show delete fields confirmation screen
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
$i
Definition: metadata.php:24
__construct($a_ref_id=null, $a_obj_type=null, $a_sub_type=null)
Constructor.
Confirmation screen class.