ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
4include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
5include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
6include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDPermissionHelper.php');
7
17{
18 protected $lng;
19 protected $tpl;
20 protected $ctrl;
21 protected $tabs;
22 protected $permissions; // [ilAdvancedMDPermissionHelper]
23
30 public function __construct()
31 {
32 global $tpl,$lng,$ilCtrl,$ilTabs;
33
34 $this->ctrl = $ilCtrl;
35 $this->lng = $lng;
36 $this->lng->loadLanguageModule('meta');
37 $this->tpl = $tpl;
38 $this->tabs_gui = $ilTabs;
39
40 $this->permissions = ilAdvancedMDPermissionHelper::getInstance();
41 }
42
43 protected function getPermissions()
44 {
45 return $this->permissions;
46 }
47
55 public function executeCommand()
56 {
57 $next_class = $this->ctrl->getNextClass($this);
58 $cmd = $this->ctrl->getCmd();
59
60 $this->setSubTabs();
61 switch($next_class)
62 {
63 default:
64 if(!$cmd)
65 {
66 $cmd = 'showRecords';
67 }
68 $this->$cmd();
69 }
70 }
71
79 public function showRecords()
80 {
81 global $ilToolbar;
82
83 $perm = $this->getPermissions()->hasPermissions(
85 $_REQUEST["ref_id"],
86 array(
89 ));
90
92 {
93 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
94 $button = ilLinkButton::getInstance();
95 $button->setCaption("add");
96 $button->setUrl($this->ctrl->getLinkTarget($this, "createRecord"));
97 $ilToolbar->addButtonInstance($button);
98
100 {
101 $ilToolbar->addSeparator();
102 }
103 }
104
106 {
107 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
108 $button = ilLinkButton::getInstance();
109 $button->setCaption("import");
110 $button->setUrl($this->ctrl->getLinkTarget($this, "importRecords"));
111 $ilToolbar->addButtonInstance($button);
112 }
113
114 $this->record_objs = $this->getRecordObjects();
115 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.show_records.html','Services/AdvancedMetaData');
116
117 include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordTableGUI.php");
118 $table_gui = new ilAdvancedMDRecordTableGUI($this, "showRecords", $this->getPermissions());
119 $table_gui->setTitle($this->lng->txt("md_record_list_table"));
120 $table_gui->parseRecords($this->record_objs);
121
122 // permissions?
123 $table_gui->addCommandButton("updateRecords", $this->lng->txt("save"));
124 //$table_gui->addCommandButton('createRecord',$this->lng->txt('add'));
125 $table_gui->addMultiCommand("exportRecords",$this->lng->txt('export'));
126 $table_gui->addMultiCommand("confirmDeleteRecords", $this->lng->txt("delete"));
127 $table_gui->setSelectAllCheckbox("record_id");
128
129 $this->tpl->setVariable('RECORD_TABLE',$table_gui->getHTML());
130
131 return true;
132 }
133
134 public function showPresentation()
135 {
136 if($this->initFormSubstitutions())
137 {
138 if (is_object($this->form))
139 {
140 $this->tabs_gui->setSubTabActive('md_adv_presentation');
141 return $this->tpl->setContent($this->form->getHTML());
142 }
143 }
144 return $this->showRecords();
145 }
146
153 public function updateSubstitutions()
154 {
155 foreach(ilAdvancedMDRecord::_getActivatedObjTypes() as $obj_type)
156 {
157 $perm = null;
158 // :TODO: hardwired?
159 if(in_array($obj_type, array("crs", "cat")))
160 {
161 $perm = $this->getPermissions()->hasPermissions(
163 $obj_type,
164 array(
168 ));
169 }
170
171 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
173
175 {
176 $sub->enableDescription($_POST['enabled_desc_'.$obj_type]);
177 }
178
180 {
181 $sub->enableFieldNames((int) $_POST['enabled_field_names_'.$obj_type]);
182 }
183
185 $definitions = $sub->sortDefinitions($definitions);
186
187 // gather existing data
188 $counter = 1;
189 $old_sub = array();
190 foreach($definitions as $def)
191 {
192 $field_id = $def->getFieldId();
193 $old_sub[$field_id] = array(
194 "active" => $sub->isSubstituted($field_id),
195 "pos" => $counter++,
196 "bold" => $sub->isBold($field_id),
197 "newline" => $sub->hasNewline($field_id)
198 );
199 }
200
201 $sub->resetSubstitutions(array());
202
203 $new_sub = array();
204 foreach($definitions as $def)
205 {
206 $field_id = $def->getFieldId();
207 $old = $old_sub[$field_id];
208
209 $perm_def = $this->getSubstitutionFieldPermissions($obj_type, $field_id);
210 if($perm_def["show"])
211 {
212 $active = (isset($_POST['show'][$obj_type][$field_id]) && $_POST['show'][$obj_type][$field_id]);
213 }
214 else
215 {
216 $active = $old["active"];
217 }
218
219 if($active)
220 {
221 $new_sub[$field_id] = $old;
222
224 {
225 $new_sub[$field_id]["pos"] = (int)$_POST['position'][$obj_type][$field_id];
226 }
227 if($perm_def["bold"])
228 {
229 $new_sub[$field_id]["bold"] = (isset($_POST['bold'][$obj_type][$field_id]) && $_POST['bold'][$obj_type][$field_id]);
230 }
231 if($perm_def["newline"])
232 {
233 $new_sub[$field_id]["newline"] = (isset($_POST['newline'][$obj_type][$field_id]) && $_POST['newline'][$obj_type][$field_id]);
234 }
235 }
236 }
237
238 if(sizeof($new_sub))
239 {
240 $new_sub = ilUtil::sortArray($new_sub, "pos", "asc", true, true);
241 foreach($new_sub as $field_id => $field)
242 {
243 $sub->appendSubstitution($field_id, $field["bold"], $field["newline"]);
244 }
245 }
246
247 $sub->update();
248 }
249
250
251 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
252 $this->ctrl->redirect($this, "showPresentation");
253 }
254
260 public function exportRecords()
261 {
262 if(!isset($_POST['record_id']))
263 {
264 ilUtil::sendFailure($this->lng->txt('select_one'));
265 $this->showRecords();
266 return false;
267 }
268
269 // all records have to be exportable
270 $fail = array();
271 foreach($_POST['record_id'] as $record_id)
272 {
273 if(!$this->getPermissions()->hasPermission(
275 $record_id,
277 {
278 $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
279 $fail[] = $record->getTitle();
280 }
281 }
282 if($fail)
283 {
284 ilUtil::sendFailure($this->lng->txt('msg_no_perm_copy')." ".implode(", ", $fail), true);
285 $this->ctrl->redirect($this, "showRecords");
286 }
287
288 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordXMLWriter.php');
289 $xml_writer = new ilAdvancedMDRecordXMLWriter($_POST['record_id']);
290 $xml_writer->write();
291
292 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
293 $export_files = new ilAdvancedMDRecordExportFiles();
294 $export_files->create($xml_writer->xmlDumpMem());
295
296 ilUtil::sendSuccess($this->lng->txt('md_adv_records_exported'));
297 $this->showFiles();
298 }
299
307 public function showFiles()
308 {
309 $this->tabs_gui->setSubTabActive('md_adv_file_list');
310
311 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
312 $files = new ilAdvancedMDRecordExportFiles();
313 $file_data = $files->readFilesInfo();
314
315 include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFilesTableGUI.php");
316 $table_gui = new ilAdvancedMDRecordExportFilesTableGUI($this, "showFiles");
317 $table_gui->setTitle($this->lng->txt("md_record_export_table"));
318 $table_gui->parseFiles($file_data);
319 $table_gui->addMultiCommand("downloadFile",$this->lng->txt('download'));
320 $table_gui->addMultiCommand("confirmDeleteFiles", $this->lng->txt("delete"));
321 $table_gui->addCommandButton('showFiles',$this->lng->txt('cancel'));
322 $table_gui->setSelectAllCheckbox("file_id");
323
324 $this->tpl->setContent($table_gui->getHTML());
325 }
326
334 public function downloadFile()
335 {
336 if(!isset($_POST['file_id']) or count($_POST['file_id']) != 1)
337 {
338 ilUtil::sendFailure($this->lng->txt('md_adv_select_one_file'));
339 $this->showFiles();
340 return false;
341 }
342
343 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
344 $files = new ilAdvancedMDRecordExportFiles();
345 $abs_path = $files->getAbsolutePathByFileId((int) $_POST['file_id'][0]);
346
347 ilUtil::deliverFile($abs_path,'ilias_meta_data_record.xml','application/xml');
348 }
349
356 public function confirmDeleteFiles()
357 {
358 if(!isset($_POST['file_id']))
359 {
360 ilUtil::sendFailure($this->lng->txt('select_one'));
361 $this->showFiles();
362 return false;
363 }
364
365 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
366 $c_gui = new ilConfirmationGUI();
367
368 // set confirm/cancel commands
369 $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFiles"));
370 $c_gui->setHeaderText($this->lng->txt("md_adv_delete_files_sure"));
371 $c_gui->setCancel($this->lng->txt("cancel"), "showFiles");
372 $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFiles");
373
374 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
375 $files = new ilAdvancedMDRecordExportFiles();
376 $file_data = $files->readFilesInfo();
377
378
379 // add items to delete
380 foreach($_POST["file_id"] as $file_id)
381 {
382 $info = $file_data[$file_id];
383 $c_gui->addItem("file_id[]", $file_id, is_array($info['name']) ? implode(',',$info['name']) : 'No Records');
384 }
385 $this->tpl->setContent($c_gui->getHTML());
386 }
387
395 public function deleteFiles()
396 {
397 if(!isset($_POST['file_id']))
398 {
399 ilUtil::sendFailure($this->lng->txt('select_one'));
400 $this->editFiles();
401 return false;
402 }
403
404 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
405 $files = new ilAdvancedMDRecordExportFiles();
406
407 foreach($_POST['file_id'] as $file_id)
408 {
409 $files->deleteByFileId((int) $file_id);
410 }
411 ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_files'));
412 $this->showFiles();
413 }
414
421 public function confirmDeleteRecords()
422 {
423 if(!isset($_POST['record_id']))
424 {
425 ilUtil::sendFailure($this->lng->txt('select_one'));
426 $this->showRecords();
427 return false;
428 }
429
430 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
431 $c_gui = new ilConfirmationGUI();
432
433 // set confirm/cancel commands
434 $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteRecords"));
435 $c_gui->setHeaderText($this->lng->txt("md_adv_delete_record_sure"));
436 $c_gui->setCancel($this->lng->txt("cancel"), "showRecords");
437 $c_gui->setConfirm($this->lng->txt("confirm"), "deleteRecords");
438
439 // add items to delete
440 foreach($_POST["record_id"] as $record_id)
441 {
442 $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
443 $c_gui->addItem("record_id[]", $record_id, $record->getTitle() ? $record->getTitle() : 'No Title');
444 }
445 $this->tpl->setContent($c_gui->getHTML());
446 }
447
454 public function deleteRecords()
455 {
456 if(!isset($_POST['record_id']))
457 {
458 ilUtil::sendFailure($this->lng->txt('select_one'));
459 $this->showRecords();
460 return false;
461 }
462
463 // all records have to be deletable
464 $fail = array();
465 foreach($_POST['record_id'] as $record_id)
466 {
467 if(!$this->getPermissions()->hasPermission(
469 $record_id,
471 {
472 $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
473 $fail[] = $record->getTitle();
474 }
475 }
476 if($fail)
477 {
478 ilUtil::sendFailure($this->lng->txt('msg_no_perm_delete')." ".implode(", ", $fail), true);
479 $this->ctrl->redirect($this, "showRecords");
480 }
481
482 foreach($_POST['record_id'] as $record_id)
483 {
484 $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
485 $record->delete();
486 }
487 ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_records'), true);
488 $this->ctrl->redirect($this, "showRecords");
489 }
490
498 public function updateRecords()
499 {
500 foreach($this->getRecordObjects() as $record_obj)
501 {
502 $perm = $this->getPermissions()->hasPermissions(
504 $record_obj->getRecordId(),
505 array(
509 ));
510
512 {
513 $obj_types = array();
514 if (is_array($_POST['obj_types'][$record_obj->getRecordId()]))
515 {
516 foreach ($_POST['obj_types'][$record_obj->getRecordId()] as $t)
517 {
518 $t = explode(":", $t);
519 $obj_types[] = array(
520 "obj_type" => ilUtil::stripSlashes($t[0]),
521 "sub_type" => ilUtil::stripSlashes($t[1])
522 );
523 }
524 }
525 $record_obj->setAssignedObjectTypes($obj_types);
526 }
527
529 {
530 $record_obj->setActive(isset($_POST['active'][$record_obj->getRecordId()]));
531 }
532
533 $record_obj->update();
534 }
535 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
536 $this->ctrl->redirect($this, "showRecords");
537 }
538
545 public function confirmDeleteFields()
546 {
547 if(!isset($_POST['field_id']))
548 {
549 ilUtil::sendFailure($this->lng->txt('select_one'));
550 $this->editFields();
551 return false;
552 }
553
554 $this->ctrl->saveParameter($this,'record_id');
555
556 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
557 $c_gui = new ilConfirmationGUI();
558
559 // set confirm/cancel commands
560 $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFields"));
561 $c_gui->setHeaderText($this->lng->txt("md_adv_delete_fields_sure"));
562 $c_gui->setCancel($this->lng->txt("cancel"), "editFields");
563 $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFields");
564
565 // add items to delete
566 foreach($_POST["field_id"] as $field_id)
567 {
569 $c_gui->addItem("field_id[]", $field_id, $field->getTitle() ? $field->getTitle() : 'No Title');
570 }
571 $this->tpl->setContent($c_gui->getHTML());
572 }
573
581 public function deleteFields()
582 {
583 $this->ctrl->saveParameter($this,'record_id');
584
585 if(!isset($_POST['field_id']))
586 {
587 ilUtil::sendFailure($this->lng->txt('select_one'));
588 $this->editFields();
589 return false;
590 }
591
592 // all fields have to be deletable
593 $fail = array();
594 foreach($_POST['field_id'] as $field_id)
595 {
596 if(!$this->getPermissions()->hasPermission(
598 $field_id,
600 {
601 $field = ilAdvancedMDFieldDefinition::getInstance($field_id);
602 $fail[] = $field->getTitle();
603 }
604 }
605 if($fail)
606 {
607 ilUtil::sendFailure($this->lng->txt('msg_no_perm_delete')." ".implode(", ", $fail), true);
608 $this->ctrl->redirect($this, "editFields");
609 }
610
611 foreach($_POST["field_id"] as $field_id)
612 {
614 $field->delete();
615 }
616 ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_fields'), true);
617 $this->ctrl->redirect($this, "editFields");
618 }
619
627 public function editRecord()
628 {
629 $this->ctrl->saveParameter($this,'record_id');
630 $this->initRecordObject();
631 $this->initForm('edit');
632 $this->tpl->setContent($this->form->getHTML());
633
634 }
635
636 public function editFields()
637 {
638 global $ilToolbar;
639
640 $this->ctrl->saveParameter($this,'record_id');
641 $this->initRecordObject();
642
643 $perm = $this->getPermissions()->hasPermissions(
645 $this->record->getRecordId(),
646 array(
649 ));
650
652 {
653 // type selection
654 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
655 $types = new ilSelectInputGUI("", "ftype");
656 $options = array();
658 {
659 $field = ilAdvancedMDFieldDefinition::getInstance(null, $type);
660 $options[$type] = $this->lng->txt($field->getTypeTitle());
661 }
662 $types->setOptions($options);
663 $ilToolbar->addInputItem($types);
664
665 $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "createField"));
666
667 include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
668 $button = ilSubmitButton::getInstance();
669 $button->setCaption("add");
670 $button->setCommand("createField");
671 $ilToolbar->addButtonInstance($button);
672 }
673
674 // show field table
675 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
676 $fields = ilAdvancedMDFieldDefinition::getInstancesByRecordId($this->record->getRecordId());
677
678 include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldTableGUI.php");
680 $table_gui->setTitle($this->lng->txt("md_adv_field_table"));
681 $table_gui->parseDefinitions($fields);
682 if(sizeof($fields))
683 {
684 $table_gui->addCommandButton("updateFields", $this->lng->txt("save"));
685 }
686 $table_gui->addCommandButton("showRecords", $this->lng->txt('cancel'));
687 $table_gui->addMultiCommand("confirmDeleteFields", $this->lng->txt("delete"));
688 $table_gui->setSelectAllCheckbox("field_id");
689
690 $this->tpl->setContent($table_gui->getHTML());
691 }
692
699 public function updateFields()
700 {
701 $this->ctrl->saveParameter($this,'record_id');
702
703 if(!isset($_GET['record_id']) or !$_GET['record_id'])
704 {
705 ilUtil::sendFailure($this->lng->txt('select_one'));
706 $this->editFields();
707 return false;
708 }
709
710 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
712
713 if($this->getPermissions()->hasPermission(
715 $_GET['record_id'],
717 {
718 if(!isset($_POST['position']) or !is_array($_POST['position']))
719 {
720 $this->editFields();
721 return false;
722 }
723 // sort by position
724 asort($_POST['position'],SORT_NUMERIC);
725 $positions = array_flip(array_keys($_POST['position']));
726 foreach($fields as $field)
727 {
728 $field->setPosition($positions[$field->getFieldId()]);
729 $field->update();
730 }
731 }
732
733 foreach($fields as $field)
734 {
735 if($this->getPermissions()->hasPermission(
737 $field->getFieldId(),
740 {
741 $field->setSearchable(isset($_POST['searchable'][$field->getFieldId()]) ? true : false);
742 $field->update();
743 }
744 }
745
746
747 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
748 $this->ctrl->redirect($this, "editFields");
749 }
750
758 public function updateRecord()
759 {
760 global $ilErr;
761
762 if(!isset($_GET['record_id']) or !$_GET['record_id'])
763 {
764 ilUtil::sendFailure($this->lng->txt('select_one'));
765 $this->showRecords();
766 return false;
767 }
768 $this->initRecordObject();
769 $this->loadRecordFormData();
770
771 if(!$this->record->validate())
772 {
773 ilUtil::sendFailure($this->lng->txt($ilErr->getMessage()));
774 $this->editRecord();
775 return false;
776 }
777 $this->record->update();
778 ilUtil::sendSuccess($this->lng->txt('settings_saved'));
779 $this->showRecords();
780 return true;
781 }
782
783
791 public function createRecord()
792 {
793 $this->initRecordObject();
794 $this->initForm('create');
795 $this->tpl->setContent($this->form->getHTML());
796 return true;
797 }
798
799 public function importRecords()
800 {
801 // Import Table
802 $this->initImportForm();
803 $this->tpl->setContent($this->import_form->getHTML());
804 }
805
811 protected function initImportForm()
812 {
813 if(is_object($this->import_form))
814 {
815 return true;
816 }
817
818 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
819 $this->import_form = new ilPropertyFormGUI();
820 $this->import_form->setMultipart(true);
821 $this->import_form->setFormAction($this->ctrl->getFormAction($this));
822
823 // add file property
824 $file = new ilFileInputGUI($this->lng->txt('file'),'file');
825 $file->setSuffixes(array('xml'));
826 $file->setRequired(true);
827 $this->import_form->addItem($file);
828
829 $this->import_form->setTitle($this->lng->txt('md_adv_import_record'));
830 $this->import_form->addCommandButton('importRecord',$this->lng->txt('import'));
831 $this->import_form->addCommandButton('showRecords',$this->lng->txt('cancel'));
832 }
833
841 public function importRecord()
842 {
843 $this->initImportForm();
844 if(!$this->import_form->checkInput())
845 {
846 $this->import_form->setValuesByPost();
847 $this->createRecord();
848 return false;
849 }
850
851 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordImportFiles.php');
852 $import_files = new ilAdvancedMDRecordImportFiles();
853 if(!$create_time = $import_files->moveUploadedFile($_FILES['file']['tmp_name']))
854 {
855 $this->createRecord();
856 return false;
857 }
858
859 try
860 {
861 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordParser.php');
862 $parser = new ilAdvancedMDRecordParser($import_files->getImportFileByCreationDate($create_time));
863
864 // Validate
866 $parser->startParsing();
867
868 // Insert
870 $parser->startParsing();
871 ilUtil::sendSuccess($this->lng->txt('md_adv_added_new_record'), true);
872 $this->ctrl->redirect($this, "showRecords");
873 }
874 catch(ilSAXParserException $exc)
875 {
876 ilUtil::sendFailure($exc->getMessage(), true);
877 $this->ctrl->redirect($this, "importRecords");
878 }
879
880 // Finally delete import file
881 $import_files->deleteFileByCreationDate($create_time);
882 return true;
883 }
884
885
893 public function saveRecord()
894 {
895 global $ilErr;
896
897 $this->initRecordObject();
898 $this->loadRecordFormData();
899
900 if(!$this->record->validate())
901 {
902 ilUtil::sendFailure($this->lng->txt($ilErr->getMessage()));
903 $this->createRecord();
904 return false;
905 }
906 $this->record->save();
907 ilUtil::sendSuccess($this->lng->txt('md_adv_added_new_record'));
908 $this->showRecords();
909 }
910
917 public function editField(ilPropertyFormGUI $a_form = null)
918 {
919 if(!$_REQUEST["record_id"] || !$_REQUEST["field_id"])
920 {
921 return $this->editFields();
922 }
923
924 $this->ctrl->saveParameter($this,'record_id');
925 $this->ctrl->saveParameter($this,'field_id');
926
927 if(!$a_form)
928 {
929 $field_definition = ilAdvancedMDFieldDefinition::getInstance((int)$_REQUEST['field_id']);
930 $a_form = $this->initFieldForm($field_definition);
931 }
932 $this->tpl->setContent($a_form->getHTML());
933 }
934
941 public function updateField()
942 {
943 global $ilErr;
944
945 if(!$_REQUEST["record_id"] || !$_REQUEST["field_id"])
946 {
947 return $this->editFields();
948 }
949
950 $this->ctrl->saveParameter($this,'record_id');
951 $this->ctrl->saveParameter($this,'field_id');
952
953 $confirm = false;
954 $field_definition = ilAdvancedMDFieldDefinition::getInstance((int)$_REQUEST['field_id']);
955 $form = $this->initFieldForm($field_definition);
956 if($form->checkInput())
957 {
958 $field_definition->importDefinitionFormPostValues($form, $this->getPermissions());
959 if(!$field_definition->importDefinitionFormPostValuesNeedsConfirmation())
960 {
961 $field_definition->update();
962
963 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
964 $this->ctrl->redirect($this, "editFields");
965 }
966 else
967 {
968 $confirm = true;
969 }
970 }
971
972 $form->setValuesByPost();
973
974 // fields needs confirmation of updated settings
975 if($confirm)
976 {
977 ilUtil::sendInfo($this->lng->txt("md_adv_confirm_definition"));
978 $field_definition->prepareDefinitionFormConfirmation($form);
979 }
980
981 $this->editField($form);
982 }
983
990 public function createField(ilPropertyFormGUI $a_form = null)
991 {
992
993 if(!$_REQUEST["record_id"] || !$_REQUEST["ftype"])
994 {
995 return $this->editFields();
996 }
997
998 $this->ctrl->saveParameter($this,'record_id');
999 $this->ctrl->saveParameter($this,'ftype');
1000
1001 if(!$a_form)
1002 {
1003 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1004 $field_definition = ilAdvancedMDFieldDefinition::getInstance(null, $_REQUEST["ftype"]);
1005 $field_definition->setRecordId($_REQUEST["record_id"]);
1006 $a_form = $this->initFieldForm($field_definition);
1007 }
1008 $this->tpl->setContent($a_form->getHTML());
1009 }
1010
1016 public function saveField()
1017 {
1018 global $ilErr;
1019
1020 if(!$_REQUEST["record_id"] || !$_REQUEST["ftype"])
1021 {
1022 return $this->editFields();
1023 }
1024
1025 $this->ctrl->saveParameter($this,'record_id');
1026 $this->ctrl->saveParameter($this,'ftype');
1027
1028 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1029 $field_definition = ilAdvancedMDFieldDefinition::getInstance(null, $_REQUEST["ftype"]);
1030 $field_definition->setRecordId($_REQUEST["record_id"]);
1031 $form = $this->initFieldForm($field_definition);
1032
1033 if($form->checkInput())
1034 {
1035 $field_definition->importDefinitionFormPostValues($form, $this->getPermissions());
1036 $field_definition->save();
1037
1038 ilUtil::sendSuccess($this->lng->txt('save_settings'), true);
1039 $this->ctrl->redirect($this, "editFields");
1040 }
1041
1042 $form->setValuesByPost();
1043 $this->createField($form);
1044 }
1045
1051 protected function initFieldForm(ilAdvancedMDFieldDefinition $a_definition)
1052 {
1053 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1054
1055 $form = new ilPropertyFormGUI();
1056 $form->setFormAction($this->ctrl->getFormAction($this));
1057
1058 $type = new ilNonEditableValueGUI($this->lng->txt("type"));
1059 $type->setValue($this->lng->txt($a_definition->getTypeTitle()));
1060 $form->addItem($type);
1061
1062 $a_definition->addToFieldDefinitionForm($form, $this->getPermissions());
1063
1064 if(!$a_definition->getFieldId())
1065 {
1066 $form->setTitle($this->lng->txt('md_adv_create_field'));
1067 $form->addCommandButton('saveField',$this->lng->txt('create'));
1068 }
1069 else
1070 {
1071 $form->setTitle($this->lng->txt('md_adv_edit_field'));
1072 $form->addCommandButton('updateField',$this->lng->txt('save'));
1073 }
1074
1075 $form->addCommandButton('editFields',$this->lng->txt('cancel'));
1076
1077 return $form;
1078 }
1079
1085 protected function initForm($a_mode)
1086 {
1087 if(is_object($this->form))
1088 {
1089 return true;
1090 }
1091
1092 $perm = $this->getPermissions()->hasPermissions(
1094 $this->record->getRecordId(),
1095 array(
1103 ));
1104
1105 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1106
1107 $this->form = new ilPropertyFormGUI();
1108 $this->form->setFormAction($this->ctrl->getFormAction($this));
1109
1110
1111 // title
1112 $title = new ilTextInputGUI($this->lng->txt('title'),'title');
1113 $title->setValue($this->record->getTitle());
1114 $title->setSize(20);
1115 $title->setMaxLength(70);
1116 $title->setRequired(true);
1117 $this->form->addItem($title);
1118
1120 {
1121 $title->setDisabled(true);
1122 }
1123
1124 // desc
1125 $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'desc');
1126 $desc->setValue($this->record->getDescription());
1127 $desc->setRows(3);
1128 $desc->setCols(50);
1129 $this->form->addItem($desc);
1130
1132 {
1133 $desc->setDisabled(true);
1134 }
1135
1136 // active
1137 $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_active'),'active');
1138 $check->setChecked($this->record->isActive());
1139 $check->setValue(1);
1140 $this->form->addItem($check);
1141
1143 {
1144 $check->setDisabled(true);
1145 }
1146
1148 $section->setTitle($this->lng->txt('md_obj_types'));
1149 $this->form->addItem($section);
1150
1151 foreach(ilAdvancedMDRecord::_getAssignableObjectTypes(true) as $type)
1152 {
1153 $t = $type["obj_type"].":".$type["sub_type"];
1154 $this->lng->loadLanguageModule($type["obj_type"]);
1155 $check = new ilCheckboxInputGUI($type["text"],'obj_types[]');
1156 $check->setChecked($this->record->isAssignedObjectType($type["obj_type"], $type["sub_type"]));
1157 $check->setValue($t);
1158 $this->form->addItem($check);
1159
1161 {
1162 $check->setDisabled(true);
1163 }
1164 }
1165
1166 switch($a_mode)
1167 {
1168 case 'create':
1169 $this->form->setTitle($this->lng->txt('md_adv_create_record'));
1170 $this->form->addCommandButton('saveRecord',$this->lng->txt('add'));
1171 $this->form->addCommandButton('showRecords',$this->lng->txt('cancel'));
1172
1173 return true;
1174
1175 case 'edit':
1176 $this->form->setTitle($this->lng->txt('md_adv_edit_record'));
1177 $this->form->addCommandButton('updateRecord',$this->lng->txt('save'));
1178 $this->form->addCommandButton('showRecords',$this->lng->txt('cancel'));
1179
1180 return true;
1181 }
1182 }
1183
1184 protected function getSubstitutionFieldPermissions($a_obj_type, $a_field_id)
1185 {
1186 if($a_obj_type == "crs")
1187 {
1188 $perm = $this->getPermissions()->hasPermissions(
1190 $a_field_id,
1191 array(
1197 ));
1198 return array(
1202 );
1203 }
1204 else if($a_obj_type == "cat")
1205 {
1206 $perm = $this->getPermissions()->hasPermissions(
1208 $a_field_id,
1209 array(
1215 ));
1216 return array(
1220 );
1221 }
1222 }
1223
1229 protected function initFormSubstitutions()
1230 {
1231 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1232
1233 if(!$visible_records = ilAdvancedMDRecord::_getAllRecordsByObjectType())
1234 {
1235 return;
1236 }
1237
1238 $this->form = new ilPropertyFormGUI();
1239 $this->form->setFormAction($this->ctrl->getFormAction($this));
1240 #$this->form->setTableWidth('100%');
1241
1242 // substitution
1243 foreach($visible_records as $obj_type => $records)
1244 {
1245 $perm = null;
1246 // :TODO: hardwird ?
1247 if(in_array($obj_type, array("crs", "cat")))
1248 {
1249 $perm = $this->getPermissions()->hasPermissions(
1251 $obj_type,
1252 array(
1256 ));
1257 }
1258
1259 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
1261
1262 // Show section
1264 $section->setTitle($this->lng->txt('objs_'.$obj_type));
1265 $this->form->addItem($section);
1266
1267 $check = new ilCheckboxInputGUI($this->lng->txt('description'),'enabled_desc_'.$obj_type);
1268 $check->setValue(1);
1269 $check->setOptionTitle($this->lng->txt('md_adv_desc_show'));
1270 $check->setChecked($sub->isDescriptionEnabled() ? true : false);
1271 $this->form->addItem($check);
1272
1274 {
1275 $check->setDisabled(true);
1276 }
1277
1278 $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_field_names'),'enabled_field_names_'.$obj_type);
1279 $check->setValue(1);
1280 $check->setOptionTitle($this->lng->txt('md_adv_fields_show'));
1281 $check->setChecked($sub->enabledFieldNames() ? true : false);
1282 $this->form->addItem($check);
1283
1285 {
1286 $check->setDisabled(true);
1287 }
1288
1289 #$area = new ilTextAreaInputGUI($this->lng->txt('md_adv_substitution'),'substitution_'.$obj_type);
1290 #$area->setUseRte(true);
1291 #$area->setRteTagSet('standard');
1292 #$area->setValue(ilUtil::prepareFormOutput($sub->getSubstitutionString()));
1293 #$area->setRows(5);
1294 #$area->setCols(80);
1295 #$this->form->addItem($area);
1296
1297 if($perm)
1298 {
1300 }
1301
1303 $definitions = $sub->sortDefinitions($definitions);
1304
1305 $counter = 1;
1306 foreach($definitions as $def)
1307 {
1308 $definition_id = $def->getFieldId();
1309
1310 $perm = $this->getSubstitutionFieldPermissions($obj_type, $definition_id);
1311
1312 $title = ilAdvancedMDRecord::_lookupTitle($def->getRecordId());
1313 $title = $def->getTitle().' ('.$title.')';
1314
1315 $check = new ilCheckboxInputGUI($title,'show['.$obj_type.']['.$definition_id.']');
1316 $check->setValue(1);
1317 $check->setOptionTitle($this->lng->txt('md_adv_show'));
1318 $check->setChecked($sub->isSubstituted($definition_id));
1319
1320 if($perm && !$perm["show"])
1321 {
1322 $check->setDisabled(true);
1323 }
1324
1325 $pos = new ilNumberInputGUI($this->lng->txt('position'),'position['.$obj_type.']['.$definition_id.']');
1326 $pos->setSize(3);
1327 $pos->setMaxLength(4);
1328 $pos->allowDecimals(true);
1329 $pos->setValue(sprintf('%.1f',$counter++));
1330 $check->addSubItem($pos);
1331
1332 if($perm && !$perm_pos)
1333 {
1334 $pos->setDisabled(true);
1335 }
1336
1337 $bold = new ilCheckboxInputGUI($this->lng->txt('bold'),'bold['.$obj_type.']['.$definition_id.']');
1338 $bold->setValue(1);
1339 $bold->setChecked($sub->isBold($definition_id));
1340 $check->addSubItem($bold);
1341
1342 if($perm && !$perm["bold"])
1343 {
1344 $bold->setDisabled(true);
1345 }
1346
1347 $bold = new ilCheckboxInputGUI($this->lng->txt('newline'),'newline['.$obj_type.']['.$definition_id.']');
1348 $bold->setValue(1);
1349 $bold->setChecked($sub->hasNewline($definition_id));
1350 $check->addSubItem($bold);
1351
1352 if($perm && !$perm["newline"])
1353 {
1354 $bold->setDisabled(true);
1355 }
1356
1357
1358 $this->form->addItem($check);
1359 }
1360
1361
1362 // placeholder
1363 /*
1364 $custom = new ilCustomInputGUI($this->lng->txt('md_adv_placeholders'));
1365 $tpl = new ilTemplate('tpl.placeholder_info.html',true,true,'Services/AdvancedMetaData');
1366 foreach($records as $record)
1367 {
1368 foreach(ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record->getRecordId()) as $definition)
1369 {
1370 $tpl->setCurrentBlock('field');
1371 $tpl->setVariable('FIELD_NAME',$definition->getTitle());
1372 $tpl->setVariable('MODULE_VARS','[IF_F_'.$definition->getFieldId().']...[F_'.$definition->getFieldId().']'.
1373 '[/IF_F_'.$definition->getFieldId().']');
1374 $tpl->parseCurrentBlock();
1375 }
1376
1377 $tpl->setCurrentBlock('record');
1378 $tpl->setVariable('PLACEHOLDER_FOR',$this->lng->txt('md_adv_placeholder_for'));
1379 $tpl->setVariable('TITLE',$record->getTitle());
1380 $tpl->parseCurrentBlock();
1381 }
1382 $custom->setHTML($tpl->get());
1383 $this->form->addItem($custom);
1384 */
1385 }
1386 $this->form->setTitle($this->lng->txt('md_adv_substitution_table'));
1387 $this->form->addCommandButton('updateSubstitutions',$this->lng->txt('save'));
1388 return true;
1389 }
1390
1396 protected function loadRecordFormData()
1397 {
1398 $perm = $this->getPermissions()->hasPermissions(
1400 $this->record->getRecordId(),
1401 array(
1409 ));
1410
1412 {
1413 $this->record->setActive(ilUtil::stripSlashes($_POST['active']));
1414 }
1416 {
1417 $this->record->setTitle(ilUtil::stripSlashes($_POST['title']));
1418 }
1420 {
1421 $this->record->setDescription(ilUtil::stripSlashes($_POST['desc']));
1422 }
1424 {
1425 $obj_types = array();
1426 if (is_array($_POST['obj_types']))
1427 {
1428 foreach ($_POST['obj_types'] as $t)
1429 {
1430 $t = explode(":", $t);
1431 $obj_types[] = array(
1432 "obj_type" => ilUtil::stripSlashes($t[0]),
1433 "sub_type" => ilUtil::stripSlashes($t[1])
1434 );
1435 }
1436 }
1437 $this->record->setAssignedObjectTypes($obj_types);
1438 }
1439 }
1440
1446 protected function initRecordObject()
1447 {
1448 if(is_object($this->record))
1449 {
1450 return $this->record;
1451 }
1452
1453 $record_id = isset($_GET['record_id']) ?
1454 $_GET['record_id'] :
1455 0;
1456 return $this->record = ilAdvancedMDRecord::_getInstanceByRecordId($_GET['record_id']);
1457 }
1458
1464 protected function setSubTabs()
1465 {
1466 $this->tabs_gui->clearSubTabs();
1467
1468 $this->tabs_gui->addSubTabTarget("md_adv_record_list",
1469 $this->ctrl->getLinkTarget($this, "showRecords"),
1470 '',
1471 '',
1472 '',
1473 true);
1474
1475
1477 {
1478 $this->tabs_gui->addSubTabTarget("md_adv_presentation",
1479 $this->ctrl->getLinkTarget($this, "showPresentation"));
1480 }
1481
1482 $this->tabs_gui->addSubTabTarget("md_adv_file_list",
1483 $this->ctrl->getLinkTarget($this, "showFiles"),
1484 "showFiles");
1485 }
1486
1492 protected function getRecordObjects()
1493 {
1494 if(!isset($this->record_objs))
1495 {
1496 return $this->record_objs = ilAdvancedMDRecord::_getRecords();
1497 }
1498 return $this->record_objs;
1499 }
1500
1501}
1502?>
print $file
$section
Definition: Utf8Test.php:84
$_GET["client_id"]
static getInstance($a_field_id, $a_type=null)
Get definition instance by type.
static getInstancesByObjType($a_obj_type, $a_active_only=true)
addToFieldDefinitionForm(ilPropertyFormGUI $a_form, ilAdvancedMDPermissionHelper $a_permissions)
Add input elements to definition form.
static getInstancesByRecordId($a_record_id, $a_only_searchable=false)
Get definitions by record id.
SAX based XML parser for record import files.
static _lookupTitle($a_record_id)
Lookup title.
static _getAllRecordsByObjectType()
Get records by obj_type Note: this returns only records with no sub types! @access public.
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
static _getActivatedObjTypes()
get activated obj types
static _getRecords()
Get records.
static _getAssignableObjectTypes($a_include_text=false)
Get assignable object type.
getRecordObjects()
Get and cache record objects.
updateRecords()
Save records (assigned object typed)
editField(ilPropertyFormGUI $a_form=null)
Edit field.
initFieldForm(ilAdvancedMDFieldDefinition $a_definition)
init field form
initFormSubstitutions()
init form table 'substitutions'
deleteRecords()
Permanently delete records.
getSubstitutionFieldPermissions($a_obj_type, $a_field_id)
createField(ilPropertyFormGUI $a_form=null)
Show field type selection.
confirmDeleteFields()
show delete fields confirmation screen
static _getInstanceByObjectType($a_type)
Singleton: use this method to get an instance.
This class represents a checkbox property in a property form.
static getInstance($a_user_id=null, $a_ref_id=null)
Factory.
Confirmation screen class.
This class represents a file property in a property form.
This class represents a section header in a property form.
static getInstance()
Factory.
This class represents a non editable value in a property form.
This class represents a number property in a property form.
This class represents a property form user interface.
This class represents a selection list property in a property form.
static getInstance()
Factory.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
$_POST['username']
Definition: cron.php:12
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
$records
Definition: simple_test.php:17
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
if(!is_array($argv)) $options