ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAdvancedMDSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
35 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
36 
38 {
39  protected $lng;
40  protected $tpl;
41  protected $ctrl;
42  protected $tabs;
43 
50  public function __construct()
51  {
52  global $tpl,$lng,$ilCtrl,$ilTabs;
53 
54  $this->ctrl = $ilCtrl;
55  $this->lng = $lng;
56  $this->lng->loadLanguageModule('meta');
57  $this->tpl = $tpl;
58  $this->tabs_gui = $ilTabs;
59  }
60 
68  public function executeCommand()
69  {
70  $next_class = $this->ctrl->getNextClass($this);
71  $cmd = $this->ctrl->getCmd();
72 
73  $this->setSubTabs();
74  switch($next_class)
75  {
76  default:
77  if(!$cmd)
78  {
79  $cmd = 'showRecords';
80  }
81  $this->$cmd();
82  }
83  }
84 
92  public function showRecords()
93  {
94  $this->record_objs = $this->getRecordObjects();
95  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.show_records.html','Services/AdvancedMetaData');
96 
97  include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordTableGUI.php");
98  $table_gui = new ilAdvancedMDRecordTableGUI($this, "showRecords");
99  $table_gui->setTitle($this->lng->txt("md_record_list_table"));
100  $table_gui->parseRecords($this->record_objs);
101  $table_gui->addCommandButton("updateRecords", $this->lng->txt("save"));
102  $table_gui->addCommandButton('createRecord',$this->lng->txt('add'));
103  $table_gui->addMultiCommand("exportRecords",$this->lng->txt('export'));
104  $table_gui->addMultiCommand("confirmDeleteRecords", $this->lng->txt("delete"));
105  $table_gui->setSelectAllCheckbox("record_id");
106  $this->tpl->setVariable('RECORD_TABLE',$table_gui->getHTML());
107 
108  if(!$this->initFormSubstitutions())
109  {
110  return true;
111  }
112  if (is_object($this->form))
113  {
114  $this->tpl->setVariable('SUBSTITUTION_TABLE',$this->form->getHTML());
115  }
116  return true;
117  }
118 
125  public function updateSubstitutions()
126  {
127  foreach(ilAdvancedMDRecord::_getActivatedObjTypes() as $obj_type)
128  {
129  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
131  $sub->resetSubstitutions(array());
132  $sub->enableDescription($_POST['enabled_desc_'.$obj_type]);
133  $sub->enableFieldNames((int) $_POST['enabled_field_names_'.$obj_type]);
134 
135  asort($_POST['position'][$obj_type],SORT_NUMERIC);
136  foreach($_POST['position'][$obj_type] as $field_id => $pos)
137  {
138  if(isset($_POST['show'][$obj_type][$field_id]) and $_POST['show'][$obj_type][$field_id])
139  {
140  $newline = $bold = false;
141  if(isset($_POST['bold'][$obj_type][$field_id]) and $_POST['bold'][$obj_type][$field_id])
142  {
143  $bold = true;
144  }
145  if(isset($_POST['newline'][$obj_type][$field_id]) and $_POST['newline'][$obj_type][$field_id])
146  {
147  $newline = true;
148  }
149  $sub->appendSubstitution($field_id,$bold,$newline);
150  }
151  }
152  $sub->update();
153  }
154 
155 
156  /*
157  foreach(ilAdvancedMDRecord::_getAllRecordsByObjectType() as $obj_type => $visible_record)
158  {
159  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
160  $sub = ilAdvancedMDSubstitution::_getInstanceByObjectType($obj_type);
161  $sub->setSubstitutionString(($_POST['substitution_'.$obj_type]));
162  $sub->enableDescription($_POST['enabled_desc_'.$obj_type]);
163  $sub->update();
164  }
165  */
166  ilUtil::sendInfo($this->lng->txt('settings_saved'));
167  $this->showRecords();
168  return true;
169  }
170 
176  public function exportRecords()
177  {
178  if(!isset($_POST['record_id']))
179  {
180  ilUtil::sendInfo($this->lng->txt('select_one'));
181  $this->showRecords();
182  return false;
183  }
184  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordXMLWriter.php');
185  $xml_writer = new ilAdvancedMDRecordXMLWriter($_POST['record_id']);
186  $xml_writer->write();
187 
188  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
189  $export_files = new ilAdvancedMDRecordExportFiles();
190  $export_files->create($xml_writer->xmlDumpMem());
191 
192  ilUtil::sendInfo($this->lng->txt('md_adv_records_exported'));
193  $this->showFiles();
194  }
195 
203  public function showFiles()
204  {
205 
206  $this->tabs_gui->setSubTabActive('md_adv_file_list');
207 
208  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
210  $file_data = $files->readFilesInfo();
211 
212  include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFilesTableGUI.php");
213  $table_gui = new ilAdvancedMDRecordExportFilesTableGUI($this, "showFiles");
214  $table_gui->setTitle($this->lng->txt("md_record_export_table"));
215  $table_gui->parseFiles($file_data);
216  $table_gui->addMultiCommand("downloadFile",$this->lng->txt('download'));
217  $table_gui->addMultiCommand("confirmDeleteFiles", $this->lng->txt("delete"));
218  $table_gui->addCommandButton('showFiles',$this->lng->txt('cancel'));
219  $table_gui->setSelectAllCheckbox("file_id");
220 
221  $this->tpl->setContent($table_gui->getHTML());
222  }
223 
231  public function downloadFile()
232  {
233  if(!isset($_POST['file_id']) or count($_POST['file_id']) != 1)
234  {
235  ilUtil::sendInfo($this->lng->txt('md_adv_select_one_file'));
236  $this->showFiles();
237  return false;
238  }
239 
240  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
242  $abs_path = $files->getAbsolutePathByFileId((int) $_POST['file_id'][0]);
243 
244  ilUtil::deliverFile($abs_path,'ilias_meta_data_record.xml','application/xml');
245  }
246 
253  public function confirmDeleteFiles()
254  {
255  if(!isset($_POST['file_id']))
256  {
257  ilUtil::sendInfo($this->lng->txt('select_one'));
258  $this->showFiles();
259  return false;
260  }
261 
262  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
263  $c_gui = new ilConfirmationGUI();
264 
265  // set confirm/cancel commands
266  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFiles"));
267  $c_gui->setHeaderText($this->lng->txt("md_adv_delete_files_sure"));
268  $c_gui->setCancel($this->lng->txt("cancel"), "showFiles");
269  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFiles");
270 
271  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
273  $file_data = $files->readFilesInfo();
274 
275 
276  // add items to delete
277  foreach($_POST["file_id"] as $file_id)
278  {
279  $info = $file_data[$file_id];
280  $c_gui->addItem("file_id[]", $file_id, is_array($info['name']) ? implode(',',$info['name']) : 'No Records');
281  }
282  $this->tpl->setContent($c_gui->getHTML());
283  }
284 
292  public function deleteFiles()
293  {
294  if(!isset($_POST['file_id']))
295  {
296  ilUtil::sendInfo($this->lng->txt('select_one'));
297  $this->editFiles();
298  return false;
299  }
300 
301  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
303 
304  foreach($_POST['file_id'] as $file_id)
305  {
306  $files->deleteByFileId((int) $file_id);
307  }
308  ilUtil::sendInfo($this->lng->txt('md_adv_deleted_files'));
309  $this->showFiles();
310  }
311 
318  public function confirmDeleteRecords()
319  {
320  if(!isset($_POST['record_id']))
321  {
322  ilUtil::sendInfo($this->lng->txt('select_one'));
323  $this->showRecords();
324  return false;
325  }
326 
327  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
328  $c_gui = new ilConfirmationGUI();
329 
330  // set confirm/cancel commands
331  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteRecords"));
332  $c_gui->setHeaderText($this->lng->txt("md_adv_delete_record_sure"));
333  $c_gui->setCancel($this->lng->txt("cancel"), "showRecords");
334  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteRecords");
335 
336  // add items to delete
337  foreach($_POST["record_id"] as $record_id)
338  {
339  $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
340  $c_gui->addItem("record_id[]", $record_id, $record->getTitle() ? $record->getTitle() : 'No Title');
341  }
342  $this->tpl->setContent($c_gui->getHTML());
343  }
344 
351  public function deleteRecords()
352  {
353  if(!isset($_POST['record_id']))
354  {
355  ilUtil::sendInfo($this->lng->txt('select_one'));
356  $this->showRecords();
357  return false;
358  }
359  foreach($_POST['record_id'] as $record_id)
360  {
361  $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
362  $record->delete();
363  }
364  ilUtil::sendInfo($this->lng->txt('md_adv_deleted_records'));
365  $this->showRecords();
366  return true;
367  }
368 
376  public function updateRecords()
377  {
378  foreach($this->getRecordObjects() as $record_obj)
379  {
380  $new_types = isset($_POST['obj_types'][$record_obj->getRecordId()]) ?
381  $_POST['obj_types'][$record_obj->getRecordId()] :
382  array();
383  $record_obj->setAssignedObjectTypes($new_types);
384  $record_obj->setActive(isset($_POST['active'][$record_obj->getRecordId()]));
385  $record_obj->update();
386  }
387  ilUtil::sendInfo($this->lng->txt('settings_saved'));
388  $this->showRecords();
389  }
390 
397  public function confirmDeleteFields()
398  {
399  if(!isset($_POST['field_id']))
400  {
401  ilUtil::sendInfo($this->lng->txt('select_one'));
402  $this->editRecord();
403  return false;
404  }
405  $this->ctrl->saveParameter($this,'record_id');
406 
407  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
408  $c_gui = new ilConfirmationGUI();
409 
410  // set confirm/cancel commands
411  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFields"));
412  $c_gui->setHeaderText($this->lng->txt("md_adv_delete_fields_sure"));
413  $c_gui->setCancel($this->lng->txt("cancel"), "showRecords");
414  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFields");
415 
416  // add items to delete
417  foreach($_POST["field_id"] as $field_id)
418  {
420  $c_gui->addItem("field_id[]", $field_id, $field->getTitle() ? $field->getTitle() : 'No Title');
421  }
422  $this->tpl->setContent($c_gui->getHTML());
423  }
424 
432  public function deleteFields()
433  {
434  if(!isset($_POST['field_id']))
435  {
436  ilUtil::sendInfo($this->lng->txt('select_one'));
437  $this->editRecord();
438  return false;
439  }
440  foreach($_POST["field_id"] as $field_id)
441  {
443  $field->delete();
444  }
445  ilUtil::sendInfo($this->lng->txt('md_adv_deleted_fields'));
446  $this->editRecord();
447  }
448 
456  public function editRecord()
457  {
458  // reset session
459  $_SESSION['num_values'] = 5;
460 
461  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.edit_record.html','Services/AdvancedMetaData');
462  $this->ctrl->saveParameter($this,'record_id');
463  $this->initRecordObject();
464  $this->initForm('edit');
465  $this->tpl->setVariable('EDIT_RECORD_TABLE',$this->form->getHTML());
466 
467  // show field table
468  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
469  $fields = ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($this->record->getRecordId());
470 
471  include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldTableGUI.php");
472  $table_gui = new ilAdvancedMDFieldTableGUI($this, "editRecord");
473  $table_gui->setTitle($this->lng->txt("md_adv_field_table"));
474  $table_gui->parseDefinitions($fields);
475  $table_gui->addCommandButton("updateFields", $this->lng->txt("save"));
476  $table_gui->addCommandButton('createField',$this->lng->txt('add'));
477  $table_gui->addCommandButton('showRecords',$this->lng->txt('cancel'));
478  $table_gui->addMultiCommand("confirmDeleteFields", $this->lng->txt("delete"));
479  $table_gui->setSelectAllCheckbox("field_id");
480 
481  $this->tpl->setVariable('FIELDS_TABLE',$table_gui->getHTML());
482  }
483 
490  public function updateFields()
491  {
492  if(!isset($_GET['record_id']) or !$_GET['record_id'])
493  {
494  ilUtil::sendInfo($this->lng->txt('select_one'));
495  $this->showRecords();
496  return false;
497  }
498 
499  if(!isset($_POST['position']) or !is_array($_POST['position']))
500  {
501  $this->showRecords();
502  return false;
503  }
504  // sort by position
505  asort($_POST['position'],SORT_NUMERIC);
506  $counter = 1;
507 
508  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
509  foreach($_POST['position'] as $field_id => $pos)
510  {
512  $definition->setPosition($counter++);
513  $definition->enableSearchable(isset($_POST['searchable'][$field_id]) ? true : false);
514  $definition->update();
515  }
516 
517  ilUtil::sendInfo($this->lng->txt('settings_saved'));
518  $this->editRecord();
519  return true;
520  }
521 
529  public function updateRecord()
530  {
531  global $ilErr;
532 
533  if(!isset($_GET['record_id']) or !$_GET['record_id'])
534  {
535  ilUtil::sendInfo($this->lng->txt('select_one'));
536  $this->showRecords();
537  return false;
538  }
539  $this->initRecordObject();
540  $this->loadRecordFormData();
541 
542  if(!$this->record->validate())
543  {
544  ilUtil::sendInfo($this->lng->txt($ilErr->getMessage()));
545  $this->editRecord();
546  return false;
547  }
548  $this->record->update();
549  ilUtil::sendInfo($this->lng->txt('settings_saved'));
550  $this->showRecords();
551  return true;
552  }
553 
554 
562  public function createRecord()
563  {
564  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.new_record.html','Services/AdvancedMetaData');
565 
566  $this->initRecordObject();
567  $this->initForm('create');
568  $this->tpl->setVariable('NEW_RECORD_TABLE',$this->form->getHTML());
569 
570  // Import Table
571  $this->initImportForm();
572  $this->tpl->setVariable('IMPORT_RECORD_TABLE',$this->import_form->getHTML());
573  return true;
574  }
575 
581  protected function initImportForm()
582  {
583  if(is_object($this->import_form))
584  {
585  return true;
586  }
587 
588  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
589  $this->import_form = new ilPropertyFormGUI();
590  $this->import_form->setMultipart(true);
591  $this->import_form->setFormAction($this->ctrl->getFormAction($this));
592 
593  // add file property
594  $file = new ilFileInputGUI($this->lng->txt('file'),'file');
595  $file->setSuffixes(array('xml'));
596  $file->setRequired(true);
597  $this->import_form->addItem($file);
598 
599  $this->import_form->setTitle($this->lng->txt('md_adv_import_record'));
600  $this->import_form->addCommandButton('importRecord',$this->lng->txt('import'));
601  $this->import_form->addCommandButton('editRecord',$this->lng->txt('cancel'));
602  }
603 
611  public function importRecord()
612  {
613  $this->initImportForm();
614  if(!$this->import_form->checkInput())
615  {
616  $this->import_form->setValuesByPost();
617  $this->createRecord();
618  return false;
619  }
620 
621  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordImportFiles.php');
622  $import_files = new ilAdvancedMDRecordImportFiles();
623  if(!$create_time = $import_files->moveUploadedFile($_FILES['file']['tmp_name']))
624  {
625  $this->createRecord();
626  return false;
627  }
628 
629  try
630  {
631  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordParser.php');
632  $parser = new ilAdvancedMDRecordParser($import_files->getImportFileByCreationDate($create_time));
633 
634  // Validate
636  $parser->startParsing();
637 
638  // Insert
639  $parser->setMode(ilAdvancedMDRecordParser::MODE_INSERT);
640  $parser->startParsing();
641  ilUtil::sendInfo($this->lng->txt('md_adv_added_new_record'));
642  $this->showRecords();
643  }
644  catch(ilSAXParserException $exc)
645  {
646  ilUtil::sendInfo($exc->getMessage());
647  $this->createRecord();
648  }
649 
650  // Finally delete import file
651  $import_files->deleteFileByCreationDate($create_time);
652  return true;
653  }
654 
655 
663  public function saveRecord()
664  {
665  global $ilErr;
666 
667  $this->initRecordObject();
668  $this->loadRecordFormData();
669 
670  if(!$this->record->validate())
671  {
672  ilUtil::sendInfo($this->lng->txt($ilErr->getMessage()));
673  $this->createRecord();
674  return false;
675  }
676  $this->record->save();
677  ilUtil::sendInfo($this->lng->txt('md_adv_added_new_record'));
678  $this->showRecords();
679  }
680 
687  public function editField()
688  {
689  $this->ctrl->saveParameter($this,'record_id');
690  $this->ctrl->saveParameter($this,'field_id');
691 
692  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId((int) $_GET['field_id']);
693  $this->initFieldForm('edit');
694  $this->tpl->setContent($this->form->getHTML());
695  }
696 
703  public function updateField()
704  {
705  global $ilErr;
706 
707  $this->ctrl->saveParameter($this,'record_id');
708 
709  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId((int) $_GET['field_id']);
710  $this->loadFieldFormData();
711 
712  if(!$this->field_definition->validate())
713  {
714  ilUtil::sendInfo($this->lng->txt($ilErr->getMessage()));
715  $this->editField();
716  return false;
717  }
718  $this->field_definition->update();
719  ilUtil::sendInfo($this->lng->txt('settings_saved'));
720  $this->editRecord();
721  }
722 
729  public function createField()
730  {
731  $this->ctrl->saveParameter($this,'record_id');
732 
733  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
734  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId(0);
735  $this->initFieldForm('create');
736  $this->tpl->setContent($this->form->getHTML());
737  }
738 
745  public function addValue()
746  {
747  ++$_SESSION['num_values'];
748 
749  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId(isset($_GET['field_id']) ? (int) $_GET['field_id'] : 0);
750  $this->loadFieldFormData();
751 
752  if(isset($_GET['field_id']) and $_GET['field_id'])
753  {
754  $this->editField();
755  }
756  else
757  {
758  $this->createField();
759  }
760  }
761 
767  public function saveField()
768  {
769  global $ilErr;
770 
771  $this->ctrl->saveParameter($this,'record_id');
772  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId(0);
773  $this->loadFieldFormData();
774 
775  if(!$this->field_definition->validate())
776  {
777  ilUtil::sendInfo($this->lng->txt($ilErr->getMessage()));
778  $this->createField();
779  return false;
780  }
781  $this->field_definition->add();
782  ilUtil::sendInfo($this->lng->txt('save_settings'));
783  $this->editRecord();
784  }
785 
786 
792  protected function initFieldForm($a_mode)
793  {
794  if(is_object($this->field_form))
795  {
796  return true;
797  }
798 
799  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
800 
801  $this->form = new ilPropertyFormGUI();
802  $this->form->setFormAction($this->ctrl->getFormAction($this));
803 
804  // title
805  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
806  $title->setValue($this->field_definition->getTitle());
807  $title->setSize(20);
808  $title->setMaxLength(70);
809  $title->setRequired(true);
810  $this->form->addItem($title);
811 
812  // desc
813  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
814  $desc->setValue($this->field_definition->getDescription());
815  $desc->setRows(3);
816  $desc->setCols(50);
817  $this->form->addItem($desc);
818 
819  // Searchable
820  $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_searchable'),'searchable');
821  $check->setChecked($this->field_definition->isSearchable());
822  $check->setValue(1);
823  $this->form->addItem($check);
824 
825  // field type
826  $radio = new ilRadioGroupInputGUI($this->lng->txt('field_type'), "field_type");
827  $radio->setValue($this->field_definition->getFieldType() ?
828  $this->field_definition->getFieldType() :
830  $radio->setRequired(true);
831 
832  $radio_option = new ilRadioOption($this->lng->txt("udf_type_text"),ilAdvancedMDFieldDefinition::TYPE_TEXT);
833  $radio->addOption($radio_option);
834 
835  $radio_option = new ilRadioOption($this->lng->txt("udf_type_date"),ilAdvancedMDFieldDefinition::TYPE_DATE);
836  $radio->addOption($radio_option);
837 
838  $radio_option = new ilRadioOption($this->lng->txt("udf_type_datetime"),ilAdvancedMDFieldDefinition::TYPE_DATETIME);
839  $radio->addOption($radio_option);
840 
841  $radio_option = new ilRadioOption($this->lng->txt("udf_type_select"),ilAdvancedMDFieldDefinition::TYPE_SELECT);
842  $radio->addOption($radio_option);
843 
844  $values = $this->field_definition->getFieldValues();
845 
846  $max_values = max(count($values),$_SESSION['num_values'] ? $_SESSION['num_values'] : 5);
847  $_SESSION['num_values'] = $max_values;
848  for($i = 1; $i <= $max_values;$i++)
849  {
850  $title = new ilTextInputGUI($this->lng->txt('udf_value').' '.$i,'value_'.$i);
851  $title->setValue(isset($values[$i - 1]) ? $values[$i - 1] : '');
852  $title->setSize(20);
853  $title->setMaxLength(70);
854  $radio_option->addSubItem($title);
855  }
856  $this->form->addItem($radio);
857 
858  switch($a_mode)
859  {
860  case 'create':
861  $this->form->setTitle($this->lng->txt('md_adv_create_field'));
862  $this->form->addCommandButton('saveField',$this->lng->txt('create'));
863  $this->form->addCommandButton('addValue',$this->lng->txt('md_adv_add_value'));
864  $this->form->addCommandButton('editRecord',$this->lng->txt('cancel'));
865 
866  return true;
867 
868  case 'edit':
869  $this->form->setTitle($this->lng->txt('md_adv_edit_field'));
870  $this->form->addCommandButton('updateField',$this->lng->txt('save'));
871  $this->form->addCommandButton('addValue',$this->lng->txt('md_adv_add_value'));
872  $this->form->addCommandButton('editRecord',$this->lng->txt('cancel'));
873 
874  return true;
875  }
876  }
877 
883  protected function initForm($a_mode)
884  {
885  if(is_object($this->form))
886  {
887  return true;
888  }
889 
890  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
891 
892  $this->form = new ilPropertyFormGUI();
893  $this->form->setFormAction($this->ctrl->getFormAction($this));
894 
895  // title
896  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
897  $title->setValue($this->record->getTitle());
898  $title->setSize(20);
899  $title->setMaxLength(70);
900  $title->setRequired(true);
901  $this->form->addItem($title);
902 
903  // desc
904  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'desc');
905  $desc->setValue($this->record->getDescription());
906  $desc->setRows(3);
907  $desc->setCols(50);
908  $this->form->addItem($desc);
909 
910  // active
911  $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_active'),'active');
912  $check->setChecked($this->record->isActive());
913  $check->setValue(1);
914  $this->form->addItem($check);
915 
917  $section->setTitle($this->lng->txt('md_obj_types'));
918  $this->form->addItem($section);
919 
921  {
922  $check = new ilCheckboxInputGUI($this->lng->txt('objs_'.$type),'obj_types[]');
923  $check->setChecked(in_array($type,$this->record->getAssignedObjectTypes()) ? true : false);
924  $check->setValue($type);
925  $this->form->addItem($check);
926  }
927 
928 
929  switch($a_mode)
930  {
931  case 'create':
932  $this->form->setTitle($this->lng->txt('md_adv_create_record'));
933  $this->form->addCommandButton('saveRecord',$this->lng->txt('add'));
934  $this->form->addCommandButton('showRecords',$this->lng->txt('cancel'));
935 
936  return true;
937 
938  case 'edit':
939  $this->form->setTitle($this->lng->txt('md_adv_edit_record'));
940  $this->form->addCommandButton('updateRecord',$this->lng->txt('save'));
941  $this->form->addCommandButton('showRecords',$this->lng->txt('cancel'));
942 
943  return true;
944  }
945  }
946 
952  protected function initFormSubstitutions()
953  {
954  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
955 
956  if(!$visible_records = ilAdvancedMDRecord::_getAllRecordsByObjectType())
957  {
958  return true;
959  }
960 
961  $this->form = new ilPropertyFormGUI();
962  $this->form->setFormAction($this->ctrl->getFormAction($this));
963  #$this->form->setTableWidth('100%');
964 
965  // substitution
966  foreach($visible_records as $obj_type => $records)
967  {
968  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
970 
971  // Show section
973  $section->setSectionIcon(ilUtil::getImagePath('icon_'.$obj_type.'_s.gif'),$this->lng->txt('objs_'.$obj_type));
974  $section->setTitle($this->lng->txt('objs_'.$obj_type));
975  $this->form->addItem($section);
976 
977  $check = new ilCheckboxInputGUI($this->lng->txt('description'),'enabled_desc_'.$obj_type);
978  $check->setValue(1);
979  $check->setOptionTitle($this->lng->txt('md_adv_desc_show'));
980  $check->setChecked($sub->isDescriptionEnabled() ? true : false);
981  $this->form->addItem($check);
982 
983  $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_field_names'),'enabled_field_names_'.$obj_type);
984  $check->setValue(1);
985  $check->setOptionTitle($this->lng->txt('md_adv_fields_show'));
986  $check->setChecked($sub->enabledFieldNames() ? true : false);
987  $this->form->addItem($check);
988 
989  #$area = new ilTextAreaInputGUI($this->lng->txt('md_adv_substitution'),'substitution_'.$obj_type);
990  #$area->setUseRte(true);
991  #$area->setRteTagSet('standard');
992  #$area->setValue(ilUtil::prepareFormOutput($sub->getSubstitutionString()));
993  #$area->setRows(5);
994  #$area->setCols(80);
995  #$this->form->addItem($area);
996 
998  $definitions = $sub->sortDefinitions($definitions);
999 
1000  $counter = 1;
1001  foreach($definitions as $definition_id)
1002  {
1004 
1005  if($def->isDeleted())
1006  {
1007  continue;
1008  }
1009 
1010  $title = ilAdvancedMDRecord::_lookupTitle($def->getRecordId());
1011  $title = $def->getTitle().' ('.$title.')';
1012 
1013  $check = new ilCheckboxInputGUI($title,'show['.$obj_type.']['.$definition_id.']');
1014  $check->setValue(1);
1015  $check->setOptionTitle($this->lng->txt('md_adv_show'));
1016  $check->setChecked($sub->isSubstituted($definition_id));
1017 
1018  $pos = new ilTextInputGUI($this->lng->txt('position'),'position['.$obj_type.']['.$definition_id.']');
1019  $pos->setSize(3);
1020  $pos->setMaxLength(4);
1021  $pos->setValue(sprintf('%.1f',$counter++));
1022  $check->addSubItem($pos);
1023 
1024  $bold = new ilCheckboxInputGUI($this->lng->txt('bold'),'bold['.$obj_type.']['.$definition_id.']');
1025  $bold->setValue(1);
1026  $bold->setChecked($sub->isBold($definition_id));
1027  $check->addSubItem($bold);
1028 
1029  $bold = new ilCheckboxInputGUI($this->lng->txt('newline'),'newline['.$obj_type.']['.$definition_id.']');
1030  $bold->setValue(1);
1031  $bold->setChecked($sub->hasNewline($definition_id));
1032  $check->addSubItem($bold);
1033 
1034 
1035  $this->form->addItem($check);
1036  }
1037 
1038 
1039  // placeholder
1040  /*
1041  $custom = new ilCustomInputGUI($this->lng->txt('md_adv_placeholders'));
1042  $tpl = new ilTemplate('tpl.placeholder_info.html',true,true,'Services/AdvancedMetaData');
1043  foreach($records as $record)
1044  {
1045  foreach(ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record->getRecordId()) as $definition)
1046  {
1047  $tpl->setCurrentBlock('field');
1048  $tpl->setVariable('FIELD_NAME',$definition->getTitle());
1049  $tpl->setVariable('MODULE_VARS','[IF_F_'.$definition->getFieldId().']...[F_'.$definition->getFieldId().']'.
1050  '[/IF_F_'.$definition->getFieldId().']');
1051  $tpl->parseCurrentBlock();
1052  }
1053 
1054  $tpl->setCurrentBlock('record');
1055  $tpl->setVariable('PLACEHOLDER_FOR',$this->lng->txt('md_adv_placeholder_for'));
1056  $tpl->setVariable('TITLE',$record->getTitle());
1057  $tpl->parseCurrentBlock();
1058  }
1059  $custom->setHTML($tpl->get());
1060  $this->form->addItem($custom);
1061  */
1062  }
1063  $this->form->setTitle($this->lng->txt('md_adv_substitution_table'));
1064  $this->form->addCommandButton('updateSubstitutions',$this->lng->txt('save'));
1065  return true;
1066  }
1067 
1073  protected function loadRecordFormData()
1074  {
1075  $this->record->setActive(ilUtil::stripSlashes($_POST['active']));
1076  $this->record->setTitle(ilUtil::stripSlashes($_POST['title']));
1077  $this->record->setDescription(ilUtil::stripSlashes($_POST['desc']));
1078  $this->record->setAssignedObjectTypes(isset($_POST['obj_types']) ? $_POST['obj_types'] : array());
1079  }
1080 
1086  protected function loadFieldFormData()
1087  {
1088  $this->field_definition->setRecordId((int) $_GET['record_id']);
1089  $this->field_definition->setTitle(ilUtil::stripSlashes($_POST['title']));
1090  $this->field_definition->setDescription(ilUtil::stripSlashes($_POST['description']));
1091  $this->field_definition->enableSearchable(isset($_POST['searchable']) ? true : false);
1092  $this->field_definition->setFieldType(ilUtil::stripSlashes($_POST['field_type']));
1093  $this->field_definition->setFieldValues(array());
1094 
1095  for($i = 1; $i <= $_SESSION['num_values'];$i++)
1096  {
1097  if(isset($_POST['value_'.$i]))
1098  {
1099  $this->field_definition->appendFieldValue($_POST['value_'.$i]);
1100  }
1101  }
1102  }
1103 
1109  protected function initRecordObject()
1110  {
1111  if(is_object($this->record))
1112  {
1113  return $this->record;
1114  }
1115 
1116  $record_id = isset($_GET['record_id']) ?
1117  $_GET['record_id'] :
1118  0;
1119  return $this->record = ilAdvancedMDRecord::_getInstanceByRecordId($_GET['record_id']);
1120  }
1121 
1127  protected function setSubTabs()
1128  {
1129  $this->tabs_gui->clearSubTabs();
1130 
1131  $this->tabs_gui->addSubTabTarget("md_adv_record_list",
1132  $this->ctrl->getLinkTarget($this, "showRecords"),
1133  '',
1134  '',
1135  '',
1136  true);
1137 
1138  $this->tabs_gui->addSubTabTarget("md_adv_file_list",
1139  $this->ctrl->getLinkTarget($this, "showFiles"),
1140  "showFiles",
1141  array(),
1142  '',
1143  false);
1144 
1145  }
1146 
1152  protected function getRecordObjects()
1153  {
1154  if(!isset($this->record_objs))
1155  {
1156  return $this->record_objs = ilAdvancedMDRecord::_getRecords();
1157  }
1158  return $this->record_objs;
1159  }
1160 
1161 }
1162 ?>