ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAdvancedMDSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
15 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
16 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
17 
19 {
20  protected $lng;
21  protected $tpl;
22  protected $ctrl;
23  protected $tabs;
24 
31  public function __construct()
32  {
33  global $tpl,$lng,$ilCtrl,$ilTabs;
34 
35  $this->ctrl = $ilCtrl;
36  $this->lng = $lng;
37  $this->lng->loadLanguageModule('meta');
38  $this->tpl = $tpl;
39  $this->tabs_gui = $ilTabs;
40  }
41 
49  public function executeCommand()
50  {
51  $next_class = $this->ctrl->getNextClass($this);
52  $cmd = $this->ctrl->getCmd();
53 
54  $this->setSubTabs();
55  switch($next_class)
56  {
57  default:
58  if(!$cmd)
59  {
60  $cmd = 'showRecords';
61  }
62  $this->$cmd();
63  }
64  }
65 
73  public function showRecords()
74  {
75  global $ilToolbar;
76 
77  $ilToolbar->addButton($this->lng->txt('add'),
78  $this->ctrl->getLinkTarget($this, "createRecord"));
79 
80  $this->record_objs = $this->getRecordObjects();
81  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.show_records.html','Services/AdvancedMetaData');
82 
83  include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordTableGUI.php");
84  $table_gui = new ilAdvancedMDRecordTableGUI($this, "showRecords");
85  $table_gui->setTitle($this->lng->txt("md_record_list_table"));
86  $table_gui->parseRecords($this->record_objs);
87  $table_gui->addCommandButton("updateRecords", $this->lng->txt("save"));
88  //$table_gui->addCommandButton('createRecord',$this->lng->txt('add'));
89  $table_gui->addMultiCommand("exportRecords",$this->lng->txt('export'));
90  $table_gui->addMultiCommand("confirmDeleteRecords", $this->lng->txt("delete"));
91  $table_gui->setSelectAllCheckbox("record_id");
92  $this->tpl->setVariable('RECORD_TABLE',$table_gui->getHTML());
93 
94  if(!$this->initFormSubstitutions())
95  {
96  return true;
97  }
98  if (is_object($this->form))
99  {
100  $this->tpl->setVariable('SUBSTITUTION_TABLE',$this->form->getHTML());
101  }
102  return true;
103  }
104 
111  public function updateSubstitutions()
112  {
113  foreach(ilAdvancedMDRecord::_getActivatedObjTypes() as $obj_type)
114  {
115  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
117  $sub->resetSubstitutions(array());
118  $sub->enableDescription($_POST['enabled_desc_'.$obj_type]);
119  $sub->enableFieldNames((int) $_POST['enabled_field_names_'.$obj_type]);
120 
121  if(isset($_POST['position'][$obj_type]))
122  {
123  asort($_POST['position'][$obj_type],SORT_NUMERIC);
124  foreach($_POST['position'][$obj_type] as $field_id => $pos)
125  {
126  if(isset($_POST['show'][$obj_type][$field_id]) and $_POST['show'][$obj_type][$field_id])
127  {
128  $newline = $bold = false;
129  if(isset($_POST['bold'][$obj_type][$field_id]) and $_POST['bold'][$obj_type][$field_id])
130  {
131  $bold = true;
132  }
133  if(isset($_POST['newline'][$obj_type][$field_id]) and $_POST['newline'][$obj_type][$field_id])
134  {
135  $newline = true;
136  }
137  $sub->appendSubstitution($field_id,$bold,$newline);
138  }
139  }
140  }
141 
142  $sub->update();
143  }
144 
145 
146  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
147  $this->showRecords();
148  return true;
149  }
150 
156  public function exportRecords()
157  {
158  if(!isset($_POST['record_id']))
159  {
160  ilUtil::sendFailure($this->lng->txt('select_one'));
161  $this->showRecords();
162  return false;
163  }
164  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordXMLWriter.php');
165  $xml_writer = new ilAdvancedMDRecordXMLWriter($_POST['record_id']);
166  $xml_writer->write();
167 
168  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
169  $export_files = new ilAdvancedMDRecordExportFiles();
170  $export_files->create($xml_writer->xmlDumpMem());
171 
172  ilUtil::sendSuccess($this->lng->txt('md_adv_records_exported'));
173  $this->showFiles();
174  }
175 
183  public function showFiles()
184  {
185 
186  $this->tabs_gui->setSubTabActive('md_adv_file_list');
187 
188  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
189  $files = new ilAdvancedMDRecordExportFiles();
190  $file_data = $files->readFilesInfo();
191 
192  include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFilesTableGUI.php");
193  $table_gui = new ilAdvancedMDRecordExportFilesTableGUI($this, "showFiles");
194  $table_gui->setTitle($this->lng->txt("md_record_export_table"));
195  $table_gui->parseFiles($file_data);
196  $table_gui->addMultiCommand("downloadFile",$this->lng->txt('download'));
197  $table_gui->addMultiCommand("confirmDeleteFiles", $this->lng->txt("delete"));
198  $table_gui->addCommandButton('showFiles',$this->lng->txt('cancel'));
199  $table_gui->setSelectAllCheckbox("file_id");
200 
201  $this->tpl->setContent($table_gui->getHTML());
202  }
203 
211  public function downloadFile()
212  {
213  if(!isset($_POST['file_id']) or count($_POST['file_id']) != 1)
214  {
215  ilUtil::sendFailure($this->lng->txt('md_adv_select_one_file'));
216  $this->showFiles();
217  return false;
218  }
219 
220  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
221  $files = new ilAdvancedMDRecordExportFiles();
222  $abs_path = $files->getAbsolutePathByFileId((int) $_POST['file_id'][0]);
223 
224  ilUtil::deliverFile($abs_path,'ilias_meta_data_record.xml','application/xml');
225  }
226 
233  public function confirmDeleteFiles()
234  {
235  if(!isset($_POST['file_id']))
236  {
237  ilUtil::sendFailure($this->lng->txt('select_one'));
238  $this->showFiles();
239  return false;
240  }
241 
242  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
243  $c_gui = new ilConfirmationGUI();
244 
245  // set confirm/cancel commands
246  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFiles"));
247  $c_gui->setHeaderText($this->lng->txt("md_adv_delete_files_sure"));
248  $c_gui->setCancel($this->lng->txt("cancel"), "showFiles");
249  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFiles");
250 
251  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
252  $files = new ilAdvancedMDRecordExportFiles();
253  $file_data = $files->readFilesInfo();
254 
255 
256  // add items to delete
257  foreach($_POST["file_id"] as $file_id)
258  {
259  $info = $file_data[$file_id];
260  $c_gui->addItem("file_id[]", $file_id, is_array($info['name']) ? implode(',',$info['name']) : 'No Records');
261  }
262  $this->tpl->setContent($c_gui->getHTML());
263  }
264 
272  public function deleteFiles()
273  {
274  if(!isset($_POST['file_id']))
275  {
276  ilUtil::sendFailure($this->lng->txt('select_one'));
277  $this->editFiles();
278  return false;
279  }
280 
281  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
282  $files = new ilAdvancedMDRecordExportFiles();
283 
284  foreach($_POST['file_id'] as $file_id)
285  {
286  $files->deleteByFileId((int) $file_id);
287  }
288  ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_files'));
289  $this->showFiles();
290  }
291 
298  public function confirmDeleteRecords()
299  {
300  if(!isset($_POST['record_id']))
301  {
302  ilUtil::sendFailure($this->lng->txt('select_one'));
303  $this->showRecords();
304  return false;
305  }
306 
307  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
308  $c_gui = new ilConfirmationGUI();
309 
310  // set confirm/cancel commands
311  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteRecords"));
312  $c_gui->setHeaderText($this->lng->txt("md_adv_delete_record_sure"));
313  $c_gui->setCancel($this->lng->txt("cancel"), "showRecords");
314  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteRecords");
315 
316  // add items to delete
317  foreach($_POST["record_id"] as $record_id)
318  {
319  $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
320  $c_gui->addItem("record_id[]", $record_id, $record->getTitle() ? $record->getTitle() : 'No Title');
321  }
322  $this->tpl->setContent($c_gui->getHTML());
323  }
324 
331  public function deleteRecords()
332  {
333  if(!isset($_POST['record_id']))
334  {
335  ilUtil::sendFailure($this->lng->txt('select_one'));
336  $this->showRecords();
337  return false;
338  }
339  foreach($_POST['record_id'] as $record_id)
340  {
341  $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
342  $record->delete();
343  }
344  ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_records'));
345  $this->showRecords();
346  return true;
347  }
348 
356  public function updateRecords()
357  {
358  foreach($this->getRecordObjects() as $record_obj)
359  {
360  $obj_types = array();
361  if (is_array($_POST['obj_types'][$record_obj->getRecordId()]))
362  {
363  foreach ($_POST['obj_types'][$record_obj->getRecordId()] as $t)
364  {
365  $t = explode(":", $t);
366  $obj_types[] = array(
367  "obj_type" => ilUtil::stripSlashes($t[0]),
368  "sub_type" => ilUtil::stripSlashes($t[1])
369  );
370  }
371  }
372 
373  $record_obj->setAssignedObjectTypes($obj_types);
374  $record_obj->setActive(isset($_POST['active'][$record_obj->getRecordId()]));
375  $record_obj->update();
376  }
377  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
378  $this->showRecords();
379  }
380 
387  public function confirmDeleteFields()
388  {
389  if(!isset($_POST['field_id']))
390  {
391  ilUtil::sendFailure($this->lng->txt('select_one'));
392  $this->editRecord();
393  return false;
394  }
395  $this->ctrl->saveParameter($this,'record_id');
396 
397  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
398  $c_gui = new ilConfirmationGUI();
399 
400  // set confirm/cancel commands
401  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFields"));
402  $c_gui->setHeaderText($this->lng->txt("md_adv_delete_fields_sure"));
403  $c_gui->setCancel($this->lng->txt("cancel"), "showRecords");
404  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFields");
405 
406  // add items to delete
407  foreach($_POST["field_id"] as $field_id)
408  {
410  $c_gui->addItem("field_id[]", $field_id, $field->getTitle() ? $field->getTitle() : 'No Title');
411  }
412  $this->tpl->setContent($c_gui->getHTML());
413  }
414 
422  public function deleteFields()
423  {
424  if(!isset($_POST['field_id']))
425  {
426  ilUtil::sendFailure($this->lng->txt('select_one'));
427  $this->editRecord();
428  return false;
429  }
430  foreach($_POST["field_id"] as $field_id)
431  {
433  $field->delete();
434  }
435  ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_fields'));
436  $this->editRecord();
437  }
438 
446  public function editRecord()
447  {
448  // reset session
449  $_SESSION['num_values'] = 5;
450 
451  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.edit_record.html','Services/AdvancedMetaData');
452  $this->ctrl->saveParameter($this,'record_id');
453  $this->initRecordObject();
454  $this->initForm('edit');
455  $this->tpl->setVariable('EDIT_RECORD_TABLE',$this->form->getHTML());
456 
457  // show field table
458  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
459  $fields = ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($this->record->getRecordId());
460 
461  include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldTableGUI.php");
462  $table_gui = new ilAdvancedMDFieldTableGUI($this, "editRecord");
463  $table_gui->setTitle($this->lng->txt("md_adv_field_table"));
464  $table_gui->parseDefinitions($fields);
465  $table_gui->addCommandButton("updateFields", $this->lng->txt("save"));
466  $table_gui->addCommandButton('createField',$this->lng->txt('add'));
467  $table_gui->addCommandButton('showRecords',$this->lng->txt('cancel'));
468  $table_gui->addMultiCommand("confirmDeleteFields", $this->lng->txt("delete"));
469  $table_gui->setSelectAllCheckbox("field_id");
470 
471  $this->tpl->setVariable('FIELDS_TABLE',$table_gui->getHTML());
472  }
473 
480  public function updateFields()
481  {
482  if(!isset($_GET['record_id']) or !$_GET['record_id'])
483  {
484  ilUtil::sendFailure($this->lng->txt('select_one'));
485  $this->showRecords();
486  return false;
487  }
488 
489  if(!isset($_POST['position']) or !is_array($_POST['position']))
490  {
491  $this->showRecords();
492  return false;
493  }
494  // sort by position
495  asort($_POST['position'],SORT_NUMERIC);
496  $counter = 1;
497 
498  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
499  foreach($_POST['position'] as $field_id => $pos)
500  {
502  $definition->setPosition($counter++);
503  $definition->enableSearchable(isset($_POST['searchable'][$field_id]) ? true : false);
504  $definition->update();
505  }
506 
507  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
508  $this->editRecord();
509  return true;
510  }
511 
519  public function updateRecord()
520  {
521  global $ilErr;
522 
523  if(!isset($_GET['record_id']) or !$_GET['record_id'])
524  {
525  ilUtil::sendFailure($this->lng->txt('select_one'));
526  $this->showRecords();
527  return false;
528  }
529  $this->initRecordObject();
530  $this->loadRecordFormData();
531 
532  if(!$this->record->validate())
533  {
534  ilUtil::sendFailure($this->lng->txt($ilErr->getMessage()));
535  $this->editRecord();
536  return false;
537  }
538  $this->record->update();
539  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
540  $this->showRecords();
541  return true;
542  }
543 
544 
552  public function createRecord()
553  {
554  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.new_record.html','Services/AdvancedMetaData');
555 
556  $this->initRecordObject();
557  $this->initForm('create');
558  $this->tpl->setVariable('NEW_RECORD_TABLE',$this->form->getHTML());
559 
560  // Import Table
561  $this->initImportForm();
562  $this->tpl->setVariable('IMPORT_RECORD_TABLE',$this->import_form->getHTML());
563  return true;
564  }
565 
571  protected function initImportForm()
572  {
573  if(is_object($this->import_form))
574  {
575  return true;
576  }
577 
578  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
579  $this->import_form = new ilPropertyFormGUI();
580  $this->import_form->setMultipart(true);
581  $this->import_form->setFormAction($this->ctrl->getFormAction($this));
582 
583  // add file property
584  $file = new ilFileInputGUI($this->lng->txt('file'),'file');
585  $file->setSuffixes(array('xml'));
586  $file->setRequired(true);
587  $this->import_form->addItem($file);
588 
589  $this->import_form->setTitle($this->lng->txt('md_adv_import_record'));
590  $this->import_form->addCommandButton('importRecord',$this->lng->txt('import'));
591  $this->import_form->addCommandButton('editRecord',$this->lng->txt('cancel'));
592  }
593 
601  public function importRecord()
602  {
603  $this->initImportForm();
604  if(!$this->import_form->checkInput())
605  {
606  $this->import_form->setValuesByPost();
607  $this->createRecord();
608  return false;
609  }
610 
611  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordImportFiles.php');
612  $import_files = new ilAdvancedMDRecordImportFiles();
613  if(!$create_time = $import_files->moveUploadedFile($_FILES['file']['tmp_name']))
614  {
615  $this->createRecord();
616  return false;
617  }
618 
619  try
620  {
621  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordParser.php');
622  $parser = new ilAdvancedMDRecordParser($import_files->getImportFileByCreationDate($create_time));
623 
624  // Validate
626  $parser->startParsing();
627 
628  // Insert
629  $parser->setMode(ilAdvancedMDRecordParser::MODE_INSERT);
630  $parser->startParsing();
631  ilUtil::sendSuccess($this->lng->txt('md_adv_added_new_record'));
632  $this->showRecords();
633  }
634  catch(ilSAXParserException $exc)
635  {
636  ilUtil::sendFailure($exc->getMessage());
637  $this->createRecord();
638  }
639 
640  // Finally delete import file
641  $import_files->deleteFileByCreationDate($create_time);
642  return true;
643  }
644 
645 
653  public function saveRecord()
654  {
655  global $ilErr;
656 
657  $this->initRecordObject();
658  $this->loadRecordFormData();
659 
660  if(!$this->record->validate())
661  {
662  ilUtil::sendFailure($this->lng->txt($ilErr->getMessage()));
663  $this->createRecord();
664  return false;
665  }
666  $this->record->save();
667  ilUtil::sendSuccess($this->lng->txt('md_adv_added_new_record'));
668  $this->showRecords();
669  }
670 
677  public function editField()
678  {
679  $this->ctrl->saveParameter($this,'record_id');
680  $this->ctrl->saveParameter($this,'field_id');
681 
682  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId((int) $_GET['field_id']);
683  $this->initFieldForm('edit');
684  $this->tpl->setContent($this->form->getHTML());
685  }
686 
693  public function updateField()
694  {
695  global $ilErr;
696 
697  $this->ctrl->saveParameter($this,'record_id');
698 
699  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId((int) $_GET['field_id']);
700  $this->loadFieldFormData();
701 
702  if(!$this->field_definition->validate())
703  {
704  ilUtil::sendFailure($this->lng->txt($ilErr->getMessage()));
705  $this->editField();
706  return false;
707  }
708  $this->field_definition->update();
709  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
710  $this->editRecord();
711  }
712 
719  public function createField()
720  {
721  $this->ctrl->saveParameter($this,'record_id');
722 
723  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
724  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId(0);
725  $this->initFieldForm('create');
726  $this->tpl->setContent($this->form->getHTML());
727  }
728 
735  public function addValue()
736  {
737  ++$_SESSION['num_values'];
738 
739  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId(isset($_GET['field_id']) ? (int) $_GET['field_id'] : 0);
740  $this->loadFieldFormData();
741 
742  if(isset($_GET['field_id']) and $_GET['field_id'])
743  {
744  $this->editField();
745  }
746  else
747  {
748  $this->createField();
749  }
750  }
751 
757  public function saveField()
758  {
759  global $ilErr;
760 
761  $this->ctrl->saveParameter($this,'record_id');
762  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId(0);
763  $this->loadFieldFormData();
764 
765  if(!$this->field_definition->validate())
766  {
767  ilUtil::sendFailure($this->lng->txt($ilErr->getMessage()));
768  $this->createField();
769  return false;
770  }
771  $this->field_definition->add();
772  ilUtil::sendSuccess($this->lng->txt('save_settings'));
773  $this->editRecord();
774  }
775 
776 
782  protected function initFieldForm($a_mode)
783  {
784  if(is_object($this->field_form))
785  {
786  return true;
787  }
788 
789  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
790 
791  $this->form = new ilPropertyFormGUI();
792  $this->form->setFormAction($this->ctrl->getFormAction($this));
793 
794  // title
795  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
796  $title->setValue($this->field_definition->getTitle());
797  $title->setSize(20);
798  $title->setMaxLength(70);
799  $title->setRequired(true);
800  $this->form->addItem($title);
801 
802  // desc
803  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
804  $desc->setValue($this->field_definition->getDescription());
805  $desc->setRows(3);
806  $desc->setCols(50);
807  $this->form->addItem($desc);
808 
809  // Searchable
810  $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_searchable'),'searchable');
811  $check->setChecked($this->field_definition->isSearchable());
812  $check->setValue(1);
813  $this->form->addItem($check);
814 
815  // field type
816  $radio = new ilRadioGroupInputGUI($this->lng->txt('field_type'), "field_type");
817  $radio->setValue($this->field_definition->getFieldType() ?
818  $this->field_definition->getFieldType() :
820  $radio->setRequired(true);
821 
822  $radio_option = new ilRadioOption($this->lng->txt("udf_type_text"),ilAdvancedMDFieldDefinition::TYPE_TEXT);
823  $radio->addOption($radio_option);
824 
825  $radio_option = new ilRadioOption($this->lng->txt("udf_type_date"),ilAdvancedMDFieldDefinition::TYPE_DATE);
826  $radio->addOption($radio_option);
827 
828  $radio_option = new ilRadioOption($this->lng->txt("udf_type_datetime"),ilAdvancedMDFieldDefinition::TYPE_DATETIME);
829  $radio->addOption($radio_option);
830 
831  $radio_option = new ilRadioOption($this->lng->txt("udf_type_select"),ilAdvancedMDFieldDefinition::TYPE_SELECT);
832  $radio->addOption($radio_option);
833 
834  $values = $this->field_definition->getFieldValues();
835 
836  $max_values = max(count($values),$_SESSION['num_values'] ? $_SESSION['num_values'] : 5);
837  $_SESSION['num_values'] = $max_values;
838  for($i = 1; $i <= $max_values;$i++)
839  {
840  $title = new ilTextInputGUI($this->lng->txt('udf_value').' '.$i,'value_'.$i);
841  $title->setValue(isset($values[$i - 1]) ? $values[$i - 1] : '');
842  $title->setSize(20);
843  $title->setMaxLength(70);
844  $radio_option->addSubItem($title);
845  }
846  $this->form->addItem($radio);
847 
848  switch($a_mode)
849  {
850  case 'create':
851  $this->form->setTitle($this->lng->txt('md_adv_create_field'));
852  $this->form->addCommandButton('saveField',$this->lng->txt('create'));
853  $this->form->addCommandButton('addValue',$this->lng->txt('md_adv_add_value'));
854  $this->form->addCommandButton('editRecord',$this->lng->txt('cancel'));
855 
856  return true;
857 
858  case 'edit':
859  $this->form->setTitle($this->lng->txt('md_adv_edit_field'));
860  $this->form->addCommandButton('updateField',$this->lng->txt('save'));
861  $this->form->addCommandButton('addValue',$this->lng->txt('md_adv_add_value'));
862  $this->form->addCommandButton('editRecord',$this->lng->txt('cancel'));
863 
864  return true;
865  }
866  }
867 
873  protected function initForm($a_mode)
874  {
875  if(is_object($this->form))
876  {
877  return true;
878  }
879 
880  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
881 
882  $this->form = new ilPropertyFormGUI();
883  $this->form->setFormAction($this->ctrl->getFormAction($this));
884 
885  // title
886  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
887  $title->setValue($this->record->getTitle());
888  $title->setSize(20);
889  $title->setMaxLength(70);
890  $title->setRequired(true);
891  $this->form->addItem($title);
892 
893  // desc
894  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'desc');
895  $desc->setValue($this->record->getDescription());
896  $desc->setRows(3);
897  $desc->setCols(50);
898  $this->form->addItem($desc);
899 
900  // active
901  $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_active'),'active');
902  $check->setChecked($this->record->isActive());
903  $check->setValue(1);
904  $this->form->addItem($check);
905 
907  $section->setTitle($this->lng->txt('md_obj_types'));
908  $this->form->addItem($section);
909 
910  foreach(ilAdvancedMDRecord::_getAssignableObjectTypes(true) as $type)
911  {
912  $t = $type["obj_type"].":".$type["sub_type"];
913  $this->lng->loadLanguageModule($type["obj_type"]);
914  $check = new ilCheckboxInputGUI($type["text"],'obj_types[]');
915  $check->setChecked($this->record->isAssignedObjectType($type["obj_type"], $type["sub_type"]));
916  $check->setValue($t);
917  $this->form->addItem($check);
918  }
919 
920 
921  switch($a_mode)
922  {
923  case 'create':
924  $this->form->setTitle($this->lng->txt('md_adv_create_record'));
925  $this->form->addCommandButton('saveRecord',$this->lng->txt('add'));
926  $this->form->addCommandButton('showRecords',$this->lng->txt('cancel'));
927 
928  return true;
929 
930  case 'edit':
931  $this->form->setTitle($this->lng->txt('md_adv_edit_record'));
932  $this->form->addCommandButton('updateRecord',$this->lng->txt('save'));
933  $this->form->addCommandButton('showRecords',$this->lng->txt('cancel'));
934 
935  return true;
936  }
937  }
938 
944  protected function initFormSubstitutions()
945  {
946  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
947 
948  if(!$visible_records = ilAdvancedMDRecord::_getAllRecordsByObjectType())
949  {
950  return true;
951  }
952 
953  $this->form = new ilPropertyFormGUI();
954  $this->form->setFormAction($this->ctrl->getFormAction($this));
955  #$this->form->setTableWidth('100%');
956 
957  // substitution
958  foreach($visible_records as $obj_type => $records)
959  {
960  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
962 
963  // Show section
965  $section->setSectionIcon(ilUtil::getImagePath('icon_'.$obj_type.'_s.png'),$this->lng->txt('objs_'.$obj_type));
966  $section->setTitle($this->lng->txt('objs_'.$obj_type));
967  $this->form->addItem($section);
968 
969  $check = new ilCheckboxInputGUI($this->lng->txt('description'),'enabled_desc_'.$obj_type);
970  $check->setValue(1);
971  $check->setOptionTitle($this->lng->txt('md_adv_desc_show'));
972  $check->setChecked($sub->isDescriptionEnabled() ? true : false);
973  $this->form->addItem($check);
974 
975  $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_field_names'),'enabled_field_names_'.$obj_type);
976  $check->setValue(1);
977  $check->setOptionTitle($this->lng->txt('md_adv_fields_show'));
978  $check->setChecked($sub->enabledFieldNames() ? true : false);
979  $this->form->addItem($check);
980 
981  #$area = new ilTextAreaInputGUI($this->lng->txt('md_adv_substitution'),'substitution_'.$obj_type);
982  #$area->setUseRte(true);
983  #$area->setRteTagSet('standard');
984  #$area->setValue(ilUtil::prepareFormOutput($sub->getSubstitutionString()));
985  #$area->setRows(5);
986  #$area->setCols(80);
987  #$this->form->addItem($area);
988 
990  $definitions = $sub->sortDefinitions($definitions);
991 
992  $counter = 1;
993  foreach($definitions as $definition_id)
994  {
996 
997  if($def->isDeleted())
998  {
999  continue;
1000  }
1001 
1002  $title = ilAdvancedMDRecord::_lookupTitle($def->getRecordId());
1003  $title = $def->getTitle().' ('.$title.')';
1004 
1005  $check = new ilCheckboxInputGUI($title,'show['.$obj_type.']['.$definition_id.']');
1006  $check->setValue(1);
1007  $check->setOptionTitle($this->lng->txt('md_adv_show'));
1008  $check->setChecked($sub->isSubstituted($definition_id));
1009 
1010  $pos = new ilTextInputGUI($this->lng->txt('position'),'position['.$obj_type.']['.$definition_id.']');
1011  $pos->setSize(3);
1012  $pos->setMaxLength(4);
1013  $pos->setValue(sprintf('%.1f',$counter++));
1014  $check->addSubItem($pos);
1015 
1016  $bold = new ilCheckboxInputGUI($this->lng->txt('bold'),'bold['.$obj_type.']['.$definition_id.']');
1017  $bold->setValue(1);
1018  $bold->setChecked($sub->isBold($definition_id));
1019  $check->addSubItem($bold);
1020 
1021  $bold = new ilCheckboxInputGUI($this->lng->txt('newline'),'newline['.$obj_type.']['.$definition_id.']');
1022  $bold->setValue(1);
1023  $bold->setChecked($sub->hasNewline($definition_id));
1024  $check->addSubItem($bold);
1025 
1026 
1027  $this->form->addItem($check);
1028  }
1029 
1030 
1031  // placeholder
1032  /*
1033  $custom = new ilCustomInputGUI($this->lng->txt('md_adv_placeholders'));
1034  $tpl = new ilTemplate('tpl.placeholder_info.html',true,true,'Services/AdvancedMetaData');
1035  foreach($records as $record)
1036  {
1037  foreach(ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record->getRecordId()) as $definition)
1038  {
1039  $tpl->setCurrentBlock('field');
1040  $tpl->setVariable('FIELD_NAME',$definition->getTitle());
1041  $tpl->setVariable('MODULE_VARS','[IF_F_'.$definition->getFieldId().']...[F_'.$definition->getFieldId().']'.
1042  '[/IF_F_'.$definition->getFieldId().']');
1043  $tpl->parseCurrentBlock();
1044  }
1045 
1046  $tpl->setCurrentBlock('record');
1047  $tpl->setVariable('PLACEHOLDER_FOR',$this->lng->txt('md_adv_placeholder_for'));
1048  $tpl->setVariable('TITLE',$record->getTitle());
1049  $tpl->parseCurrentBlock();
1050  }
1051  $custom->setHTML($tpl->get());
1052  $this->form->addItem($custom);
1053  */
1054  }
1055  $this->form->setTitle($this->lng->txt('md_adv_substitution_table'));
1056  $this->form->addCommandButton('updateSubstitutions',$this->lng->txt('save'));
1057  return true;
1058  }
1059 
1065  protected function loadRecordFormData()
1066  {
1067  $this->record->setActive(ilUtil::stripSlashes($_POST['active']));
1068  $this->record->setTitle(ilUtil::stripSlashes($_POST['title']));
1069  $this->record->setDescription(ilUtil::stripSlashes($_POST['desc']));
1070  $obj_types = array();
1071  if (is_array($_POST['obj_types']))
1072  {
1073  foreach ($_POST['obj_types'] as $t)
1074  {
1075  $t = explode(":", $t);
1076  $obj_types[] = array(
1077  "obj_type" => ilUtil::stripSlashes($t[0]),
1078  "sub_type" => ilUtil::stripSlashes($t[1])
1079  );
1080  }
1081  }
1082  $this->record->setAssignedObjectTypes($obj_types);
1083  }
1084 
1090  protected function loadFieldFormData()
1091  {
1092  $this->field_definition->setRecordId((int) $_GET['record_id']);
1093  $this->field_definition->setTitle(ilUtil::stripSlashes($_POST['title']));
1094  $this->field_definition->setDescription(ilUtil::stripSlashes($_POST['description']));
1095  $this->field_definition->enableSearchable(isset($_POST['searchable']) ? true : false);
1096  $this->field_definition->setFieldType(ilUtil::stripSlashes($_POST['field_type']));
1097  $this->field_definition->setFieldValues(array());
1098 
1099  for($i = 1; $i <= $_SESSION['num_values'];$i++)
1100  {
1101  if(isset($_POST['value_'.$i]))
1102  {
1103  $this->field_definition->appendFieldValue($_POST['value_'.$i]);
1104  }
1105  }
1106  }
1107 
1113  protected function initRecordObject()
1114  {
1115  if(is_object($this->record))
1116  {
1117  return $this->record;
1118  }
1119 
1120  $record_id = isset($_GET['record_id']) ?
1121  $_GET['record_id'] :
1122  0;
1123  return $this->record = ilAdvancedMDRecord::_getInstanceByRecordId($_GET['record_id']);
1124  }
1125 
1131  protected function setSubTabs()
1132  {
1133  $this->tabs_gui->clearSubTabs();
1134 
1135  $this->tabs_gui->addSubTabTarget("md_adv_record_list",
1136  $this->ctrl->getLinkTarget($this, "showRecords"),
1137  '',
1138  '',
1139  '',
1140  true);
1141 
1142  $this->tabs_gui->addSubTabTarget("md_adv_file_list",
1143  $this->ctrl->getLinkTarget($this, "showFiles"),
1144  "showFiles",
1145  array(),
1146  '',
1147  false);
1148 
1149  }
1150 
1156  protected function getRecordObjects()
1157  {
1158  if(!isset($this->record_objs))
1159  {
1160  return $this->record_objs = ilAdvancedMDRecord::_getRecords();
1161  }
1162  return $this->record_objs;
1163  }
1164 
1165 }
1166 ?>