ILIAS  Release_4_1_x_branch Revision 61804
 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  if(isset($_POST['position'][$obj_type]))
136  {
137  asort($_POST['position'][$obj_type],SORT_NUMERIC);
138  foreach($_POST['position'][$obj_type] as $field_id => $pos)
139  {
140  if(isset($_POST['show'][$obj_type][$field_id]) and $_POST['show'][$obj_type][$field_id])
141  {
142  $newline = $bold = false;
143  if(isset($_POST['bold'][$obj_type][$field_id]) and $_POST['bold'][$obj_type][$field_id])
144  {
145  $bold = true;
146  }
147  if(isset($_POST['newline'][$obj_type][$field_id]) and $_POST['newline'][$obj_type][$field_id])
148  {
149  $newline = true;
150  }
151  $sub->appendSubstitution($field_id,$bold,$newline);
152  }
153  }
154  }
155 
156  $sub->update();
157  }
158 
159 
160  /*
161  foreach(ilAdvancedMDRecord::_getAllRecordsByObjectType() as $obj_type => $visible_record)
162  {
163  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
164  $sub = ilAdvancedMDSubstitution::_getInstanceByObjectType($obj_type);
165  $sub->setSubstitutionString(($_POST['substitution_'.$obj_type]));
166  $sub->enableDescription($_POST['enabled_desc_'.$obj_type]);
167  $sub->update();
168  }
169  */
170  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
171  $this->showRecords();
172  return true;
173  }
174 
180  public function exportRecords()
181  {
182  if(!isset($_POST['record_id']))
183  {
184  ilUtil::sendFailure($this->lng->txt('select_one'));
185  $this->showRecords();
186  return false;
187  }
188  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordXMLWriter.php');
189  $xml_writer = new ilAdvancedMDRecordXMLWriter($_POST['record_id']);
190  $xml_writer->write();
191 
192  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
193  $export_files = new ilAdvancedMDRecordExportFiles();
194  $export_files->create($xml_writer->xmlDumpMem());
195 
196  ilUtil::sendSuccess($this->lng->txt('md_adv_records_exported'));
197  $this->showFiles();
198  }
199 
207  public function showFiles()
208  {
209 
210  $this->tabs_gui->setSubTabActive('md_adv_file_list');
211 
212  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
214  $file_data = $files->readFilesInfo();
215 
216  include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFilesTableGUI.php");
217  $table_gui = new ilAdvancedMDRecordExportFilesTableGUI($this, "showFiles");
218  $table_gui->setTitle($this->lng->txt("md_record_export_table"));
219  $table_gui->parseFiles($file_data);
220  $table_gui->addMultiCommand("downloadFile",$this->lng->txt('download'));
221  $table_gui->addMultiCommand("confirmDeleteFiles", $this->lng->txt("delete"));
222  $table_gui->addCommandButton('showFiles',$this->lng->txt('cancel'));
223  $table_gui->setSelectAllCheckbox("file_id");
224 
225  $this->tpl->setContent($table_gui->getHTML());
226  }
227 
235  public function downloadFile()
236  {
237  if(!isset($_POST['file_id']) or count($_POST['file_id']) != 1)
238  {
239  ilUtil::sendFailure($this->lng->txt('md_adv_select_one_file'));
240  $this->showFiles();
241  return false;
242  }
243 
244  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
246  $abs_path = $files->getAbsolutePathByFileId((int) $_POST['file_id'][0]);
247 
248  ilUtil::deliverFile($abs_path,'ilias_meta_data_record.xml','application/xml');
249  }
250 
257  public function confirmDeleteFiles()
258  {
259  if(!isset($_POST['file_id']))
260  {
261  ilUtil::sendFailure($this->lng->txt('select_one'));
262  $this->showFiles();
263  return false;
264  }
265 
266  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
267  $c_gui = new ilConfirmationGUI();
268 
269  // set confirm/cancel commands
270  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFiles"));
271  $c_gui->setHeaderText($this->lng->txt("md_adv_delete_files_sure"));
272  $c_gui->setCancel($this->lng->txt("cancel"), "showFiles");
273  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFiles");
274 
275  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
277  $file_data = $files->readFilesInfo();
278 
279 
280  // add items to delete
281  foreach($_POST["file_id"] as $file_id)
282  {
283  $info = $file_data[$file_id];
284  $c_gui->addItem("file_id[]", $file_id, is_array($info['name']) ? implode(',',$info['name']) : 'No Records');
285  }
286  $this->tpl->setContent($c_gui->getHTML());
287  }
288 
296  public function deleteFiles()
297  {
298  if(!isset($_POST['file_id']))
299  {
300  ilUtil::sendFailure($this->lng->txt('select_one'));
301  $this->editFiles();
302  return false;
303  }
304 
305  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
307 
308  foreach($_POST['file_id'] as $file_id)
309  {
310  $files->deleteByFileId((int) $file_id);
311  }
312  ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_files'));
313  $this->showFiles();
314  }
315 
322  public function confirmDeleteRecords()
323  {
324  if(!isset($_POST['record_id']))
325  {
326  ilUtil::sendFailure($this->lng->txt('select_one'));
327  $this->showRecords();
328  return false;
329  }
330 
331  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
332  $c_gui = new ilConfirmationGUI();
333 
334  // set confirm/cancel commands
335  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteRecords"));
336  $c_gui->setHeaderText($this->lng->txt("md_adv_delete_record_sure"));
337  $c_gui->setCancel($this->lng->txt("cancel"), "showRecords");
338  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteRecords");
339 
340  // add items to delete
341  foreach($_POST["record_id"] as $record_id)
342  {
343  $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
344  $c_gui->addItem("record_id[]", $record_id, $record->getTitle() ? $record->getTitle() : 'No Title');
345  }
346  $this->tpl->setContent($c_gui->getHTML());
347  }
348 
355  public function deleteRecords()
356  {
357  if(!isset($_POST['record_id']))
358  {
359  ilUtil::sendFailure($this->lng->txt('select_one'));
360  $this->showRecords();
361  return false;
362  }
363  foreach($_POST['record_id'] as $record_id)
364  {
365  $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
366  $record->delete();
367  }
368  ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_records'));
369  $this->showRecords();
370  return true;
371  }
372 
380  public function updateRecords()
381  {
382  foreach($this->getRecordObjects() as $record_obj)
383  {
384  $new_types = isset($_POST['obj_types'][$record_obj->getRecordId()]) ?
385  $_POST['obj_types'][$record_obj->getRecordId()] :
386  array();
387  $record_obj->setAssignedObjectTypes($new_types);
388  $record_obj->setActive(isset($_POST['active'][$record_obj->getRecordId()]));
389  $record_obj->update();
390  }
391  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
392  $this->showRecords();
393  }
394 
401  public function confirmDeleteFields()
402  {
403  if(!isset($_POST['field_id']))
404  {
405  ilUtil::sendFailure($this->lng->txt('select_one'));
406  $this->editRecord();
407  return false;
408  }
409  $this->ctrl->saveParameter($this,'record_id');
410 
411  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
412  $c_gui = new ilConfirmationGUI();
413 
414  // set confirm/cancel commands
415  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFields"));
416  $c_gui->setHeaderText($this->lng->txt("md_adv_delete_fields_sure"));
417  $c_gui->setCancel($this->lng->txt("cancel"), "showRecords");
418  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFields");
419 
420  // add items to delete
421  foreach($_POST["field_id"] as $field_id)
422  {
424  $c_gui->addItem("field_id[]", $field_id, $field->getTitle() ? $field->getTitle() : 'No Title');
425  }
426  $this->tpl->setContent($c_gui->getHTML());
427  }
428 
436  public function deleteFields()
437  {
438  if(!isset($_POST['field_id']))
439  {
440  ilUtil::sendFailure($this->lng->txt('select_one'));
441  $this->editRecord();
442  return false;
443  }
444  foreach($_POST["field_id"] as $field_id)
445  {
447  $field->delete();
448  }
449  ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_fields'));
450  $this->editRecord();
451  }
452 
460  public function editRecord()
461  {
462  // reset session
463  $_SESSION['num_values'] = 5;
464 
465  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.edit_record.html','Services/AdvancedMetaData');
466  $this->ctrl->saveParameter($this,'record_id');
467  $this->initRecordObject();
468  $this->initForm('edit');
469  $this->tpl->setVariable('EDIT_RECORD_TABLE',$this->form->getHTML());
470 
471  // show field table
472  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
473  $fields = ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($this->record->getRecordId());
474 
475  include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldTableGUI.php");
476  $table_gui = new ilAdvancedMDFieldTableGUI($this, "editRecord");
477  $table_gui->setTitle($this->lng->txt("md_adv_field_table"));
478  $table_gui->parseDefinitions($fields);
479  $table_gui->addCommandButton("updateFields", $this->lng->txt("save"));
480  $table_gui->addCommandButton('createField',$this->lng->txt('add'));
481  $table_gui->addCommandButton('showRecords',$this->lng->txt('cancel'));
482  $table_gui->addMultiCommand("confirmDeleteFields", $this->lng->txt("delete"));
483  $table_gui->setSelectAllCheckbox("field_id");
484 
485  $this->tpl->setVariable('FIELDS_TABLE',$table_gui->getHTML());
486  }
487 
494  public function updateFields()
495  {
496  if(!isset($_GET['record_id']) or !$_GET['record_id'])
497  {
498  ilUtil::sendFailure($this->lng->txt('select_one'));
499  $this->showRecords();
500  return false;
501  }
502 
503  if(!isset($_POST['position']) or !is_array($_POST['position']))
504  {
505  $this->showRecords();
506  return false;
507  }
508  // sort by position
509  asort($_POST['position'],SORT_NUMERIC);
510  $counter = 1;
511 
512  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
513  foreach($_POST['position'] as $field_id => $pos)
514  {
516  $definition->setPosition($counter++);
517  $definition->enableSearchable(isset($_POST['searchable'][$field_id]) ? true : false);
518  $definition->update();
519  }
520 
521  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
522  $this->editRecord();
523  return true;
524  }
525 
533  public function updateRecord()
534  {
535  global $ilErr;
536 
537  if(!isset($_GET['record_id']) or !$_GET['record_id'])
538  {
539  ilUtil::sendFailure($this->lng->txt('select_one'));
540  $this->showRecords();
541  return false;
542  }
543  $this->initRecordObject();
544  $this->loadRecordFormData();
545 
546  if(!$this->record->validate())
547  {
548  ilUtil::sendFailure($this->lng->txt($ilErr->getMessage()));
549  $this->editRecord();
550  return false;
551  }
552  $this->record->update();
553  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
554  $this->showRecords();
555  return true;
556  }
557 
558 
566  public function createRecord()
567  {
568  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.new_record.html','Services/AdvancedMetaData');
569 
570  $this->initRecordObject();
571  $this->initForm('create');
572  $this->tpl->setVariable('NEW_RECORD_TABLE',$this->form->getHTML());
573 
574  // Import Table
575  $this->initImportForm();
576  $this->tpl->setVariable('IMPORT_RECORD_TABLE',$this->import_form->getHTML());
577  return true;
578  }
579 
585  protected function initImportForm()
586  {
587  if(is_object($this->import_form))
588  {
589  return true;
590  }
591 
592  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
593  $this->import_form = new ilPropertyFormGUI();
594  $this->import_form->setMultipart(true);
595  $this->import_form->setFormAction($this->ctrl->getFormAction($this));
596 
597  // add file property
598  $file = new ilFileInputGUI($this->lng->txt('file'),'file');
599  $file->setSuffixes(array('xml'));
600  $file->setRequired(true);
601  $this->import_form->addItem($file);
602 
603  $this->import_form->setTitle($this->lng->txt('md_adv_import_record'));
604  $this->import_form->addCommandButton('importRecord',$this->lng->txt('import'));
605  $this->import_form->addCommandButton('editRecord',$this->lng->txt('cancel'));
606  }
607 
615  public function importRecord()
616  {
617  $this->initImportForm();
618  if(!$this->import_form->checkInput())
619  {
620  $this->import_form->setValuesByPost();
621  $this->createRecord();
622  return false;
623  }
624 
625  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordImportFiles.php');
626  $import_files = new ilAdvancedMDRecordImportFiles();
627  if(!$create_time = $import_files->moveUploadedFile($_FILES['file']['tmp_name']))
628  {
629  $this->createRecord();
630  return false;
631  }
632 
633  try
634  {
635  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordParser.php');
636  $parser = new ilAdvancedMDRecordParser($import_files->getImportFileByCreationDate($create_time));
637 
638  // Validate
640  $parser->startParsing();
641 
642  // Insert
643  $parser->setMode(ilAdvancedMDRecordParser::MODE_INSERT);
644  $parser->startParsing();
645  ilUtil::sendSuccess($this->lng->txt('md_adv_added_new_record'));
646  $this->showRecords();
647  }
648  catch(ilSAXParserException $exc)
649  {
650  ilUtil::sendFailure($exc->getMessage());
651  $this->createRecord();
652  }
653 
654  // Finally delete import file
655  $import_files->deleteFileByCreationDate($create_time);
656  return true;
657  }
658 
659 
667  public function saveRecord()
668  {
669  global $ilErr;
670 
671  $this->initRecordObject();
672  $this->loadRecordFormData();
673 
674  if(!$this->record->validate())
675  {
676  ilUtil::sendFailure($this->lng->txt($ilErr->getMessage()));
677  $this->createRecord();
678  return false;
679  }
680  $this->record->save();
681  ilUtil::sendSuccess($this->lng->txt('md_adv_added_new_record'));
682  $this->showRecords();
683  }
684 
691  public function editField()
692  {
693  $this->ctrl->saveParameter($this,'record_id');
694  $this->ctrl->saveParameter($this,'field_id');
695 
696  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId((int) $_GET['field_id']);
697  $this->initFieldForm('edit');
698  $this->tpl->setContent($this->form->getHTML());
699  }
700 
707  public function updateField()
708  {
709  global $ilErr;
710 
711  $this->ctrl->saveParameter($this,'record_id');
712 
713  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId((int) $_GET['field_id']);
714  $this->loadFieldFormData();
715 
716  if(!$this->field_definition->validate())
717  {
718  ilUtil::sendFailure($this->lng->txt($ilErr->getMessage()));
719  $this->editField();
720  return false;
721  }
722  $this->field_definition->update();
723  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
724  $this->editRecord();
725  }
726 
733  public function createField()
734  {
735  $this->ctrl->saveParameter($this,'record_id');
736 
737  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
738  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId(0);
739  $this->initFieldForm('create');
740  $this->tpl->setContent($this->form->getHTML());
741  }
742 
749  public function addValue()
750  {
751  ++$_SESSION['num_values'];
752 
753  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId(isset($_GET['field_id']) ? (int) $_GET['field_id'] : 0);
754  $this->loadFieldFormData();
755 
756  if(isset($_GET['field_id']) and $_GET['field_id'])
757  {
758  $this->editField();
759  }
760  else
761  {
762  $this->createField();
763  }
764  }
765 
771  public function saveField()
772  {
773  global $ilErr;
774 
775  $this->ctrl->saveParameter($this,'record_id');
776  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId(0);
777  $this->loadFieldFormData();
778 
779  if(!$this->field_definition->validate())
780  {
781  ilUtil::sendFailure($this->lng->txt($ilErr->getMessage()));
782  $this->createField();
783  return false;
784  }
785  $this->field_definition->add();
786  ilUtil::sendSuccess($this->lng->txt('save_settings'));
787  $this->editRecord();
788  }
789 
790 
796  protected function initFieldForm($a_mode)
797  {
798  if(is_object($this->field_form))
799  {
800  return true;
801  }
802 
803  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
804 
805  $this->form = new ilPropertyFormGUI();
806  $this->form->setFormAction($this->ctrl->getFormAction($this));
807 
808  // title
809  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
810  $title->setValue($this->field_definition->getTitle());
811  $title->setSize(20);
812  $title->setMaxLength(70);
813  $title->setRequired(true);
814  $this->form->addItem($title);
815 
816  // desc
817  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
818  $desc->setValue($this->field_definition->getDescription());
819  $desc->setRows(3);
820  $desc->setCols(50);
821  $this->form->addItem($desc);
822 
823  // Searchable
824  $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_searchable'),'searchable');
825  $check->setChecked($this->field_definition->isSearchable());
826  $check->setValue(1);
827  $this->form->addItem($check);
828 
829  // field type
830  $radio = new ilRadioGroupInputGUI($this->lng->txt('field_type'), "field_type");
831  $radio->setValue($this->field_definition->getFieldType() ?
832  $this->field_definition->getFieldType() :
834  $radio->setRequired(true);
835 
836  $radio_option = new ilRadioOption($this->lng->txt("udf_type_text"),ilAdvancedMDFieldDefinition::TYPE_TEXT);
837  $radio->addOption($radio_option);
838 
839  $radio_option = new ilRadioOption($this->lng->txt("udf_type_date"),ilAdvancedMDFieldDefinition::TYPE_DATE);
840  $radio->addOption($radio_option);
841 
842  $radio_option = new ilRadioOption($this->lng->txt("udf_type_datetime"),ilAdvancedMDFieldDefinition::TYPE_DATETIME);
843  $radio->addOption($radio_option);
844 
845  $radio_option = new ilRadioOption($this->lng->txt("udf_type_select"),ilAdvancedMDFieldDefinition::TYPE_SELECT);
846  $radio->addOption($radio_option);
847 
848  $values = $this->field_definition->getFieldValues();
849 
850  $max_values = max(count($values),$_SESSION['num_values'] ? $_SESSION['num_values'] : 5);
851  $_SESSION['num_values'] = $max_values;
852  for($i = 1; $i <= $max_values;$i++)
853  {
854  $title = new ilTextInputGUI($this->lng->txt('udf_value').' '.$i,'value_'.$i);
855  $title->setValue(isset($values[$i - 1]) ? $values[$i - 1] : '');
856  $title->setSize(20);
857  $title->setMaxLength(70);
858  $radio_option->addSubItem($title);
859  }
860  $this->form->addItem($radio);
861 
862  switch($a_mode)
863  {
864  case 'create':
865  $this->form->setTitle($this->lng->txt('md_adv_create_field'));
866  $this->form->addCommandButton('saveField',$this->lng->txt('create'));
867  $this->form->addCommandButton('addValue',$this->lng->txt('md_adv_add_value'));
868  $this->form->addCommandButton('editRecord',$this->lng->txt('cancel'));
869 
870  return true;
871 
872  case 'edit':
873  $this->form->setTitle($this->lng->txt('md_adv_edit_field'));
874  $this->form->addCommandButton('updateField',$this->lng->txt('save'));
875  $this->form->addCommandButton('addValue',$this->lng->txt('md_adv_add_value'));
876  $this->form->addCommandButton('editRecord',$this->lng->txt('cancel'));
877 
878  return true;
879  }
880  }
881 
887  protected function initForm($a_mode)
888  {
889  if(is_object($this->form))
890  {
891  return true;
892  }
893 
894  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
895 
896  $this->form = new ilPropertyFormGUI();
897  $this->form->setFormAction($this->ctrl->getFormAction($this));
898 
899  // title
900  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
901  $title->setValue($this->record->getTitle());
902  $title->setSize(20);
903  $title->setMaxLength(70);
904  $title->setRequired(true);
905  $this->form->addItem($title);
906 
907  // desc
908  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'desc');
909  $desc->setValue($this->record->getDescription());
910  $desc->setRows(3);
911  $desc->setCols(50);
912  $this->form->addItem($desc);
913 
914  // active
915  $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_active'),'active');
916  $check->setChecked($this->record->isActive());
917  $check->setValue(1);
918  $this->form->addItem($check);
919 
921  $section->setTitle($this->lng->txt('md_obj_types'));
922  $this->form->addItem($section);
923 
925  {
926  $check = new ilCheckboxInputGUI($this->lng->txt('objs_'.$type),'obj_types[]');
927  $check->setChecked(in_array($type,$this->record->getAssignedObjectTypes()) ? true : false);
928  $check->setValue($type);
929  $this->form->addItem($check);
930  }
931 
932 
933  switch($a_mode)
934  {
935  case 'create':
936  $this->form->setTitle($this->lng->txt('md_adv_create_record'));
937  $this->form->addCommandButton('saveRecord',$this->lng->txt('add'));
938  $this->form->addCommandButton('showRecords',$this->lng->txt('cancel'));
939 
940  return true;
941 
942  case 'edit':
943  $this->form->setTitle($this->lng->txt('md_adv_edit_record'));
944  $this->form->addCommandButton('updateRecord',$this->lng->txt('save'));
945  $this->form->addCommandButton('showRecords',$this->lng->txt('cancel'));
946 
947  return true;
948  }
949  }
950 
956  protected function initFormSubstitutions()
957  {
958  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
959 
960  if(!$visible_records = ilAdvancedMDRecord::_getAllRecordsByObjectType())
961  {
962  return true;
963  }
964 
965  $this->form = new ilPropertyFormGUI();
966  $this->form->setFormAction($this->ctrl->getFormAction($this));
967  #$this->form->setTableWidth('100%');
968 
969  // substitution
970  foreach($visible_records as $obj_type => $records)
971  {
972  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
974 
975  // Show section
977  $section->setSectionIcon(ilUtil::getImagePath('icon_'.$obj_type.'_s.gif'),$this->lng->txt('objs_'.$obj_type));
978  $section->setTitle($this->lng->txt('objs_'.$obj_type));
979  $this->form->addItem($section);
980 
981  $check = new ilCheckboxInputGUI($this->lng->txt('description'),'enabled_desc_'.$obj_type);
982  $check->setValue(1);
983  $check->setOptionTitle($this->lng->txt('md_adv_desc_show'));
984  $check->setChecked($sub->isDescriptionEnabled() ? true : false);
985  $this->form->addItem($check);
986 
987  $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_field_names'),'enabled_field_names_'.$obj_type);
988  $check->setValue(1);
989  $check->setOptionTitle($this->lng->txt('md_adv_fields_show'));
990  $check->setChecked($sub->enabledFieldNames() ? true : false);
991  $this->form->addItem($check);
992 
993  #$area = new ilTextAreaInputGUI($this->lng->txt('md_adv_substitution'),'substitution_'.$obj_type);
994  #$area->setUseRte(true);
995  #$area->setRteTagSet('standard');
996  #$area->setValue(ilUtil::prepareFormOutput($sub->getSubstitutionString()));
997  #$area->setRows(5);
998  #$area->setCols(80);
999  #$this->form->addItem($area);
1000 
1002  $definitions = $sub->sortDefinitions($definitions);
1003 
1004  $counter = 1;
1005  foreach($definitions as $definition_id)
1006  {
1008 
1009  if($def->isDeleted())
1010  {
1011  continue;
1012  }
1013 
1014  $title = ilAdvancedMDRecord::_lookupTitle($def->getRecordId());
1015  $title = $def->getTitle().' ('.$title.')';
1016 
1017  $check = new ilCheckboxInputGUI($title,'show['.$obj_type.']['.$definition_id.']');
1018  $check->setValue(1);
1019  $check->setOptionTitle($this->lng->txt('md_adv_show'));
1020  $check->setChecked($sub->isSubstituted($definition_id));
1021 
1022  $pos = new ilTextInputGUI($this->lng->txt('position'),'position['.$obj_type.']['.$definition_id.']');
1023  $pos->setSize(3);
1024  $pos->setMaxLength(4);
1025  $pos->setValue(sprintf('%.1f',$counter++));
1026  $check->addSubItem($pos);
1027 
1028  $bold = new ilCheckboxInputGUI($this->lng->txt('bold'),'bold['.$obj_type.']['.$definition_id.']');
1029  $bold->setValue(1);
1030  $bold->setChecked($sub->isBold($definition_id));
1031  $check->addSubItem($bold);
1032 
1033  $bold = new ilCheckboxInputGUI($this->lng->txt('newline'),'newline['.$obj_type.']['.$definition_id.']');
1034  $bold->setValue(1);
1035  $bold->setChecked($sub->hasNewline($definition_id));
1036  $check->addSubItem($bold);
1037 
1038 
1039  $this->form->addItem($check);
1040  }
1041 
1042 
1043  // placeholder
1044  /*
1045  $custom = new ilCustomInputGUI($this->lng->txt('md_adv_placeholders'));
1046  $tpl = new ilTemplate('tpl.placeholder_info.html',true,true,'Services/AdvancedMetaData');
1047  foreach($records as $record)
1048  {
1049  foreach(ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record->getRecordId()) as $definition)
1050  {
1051  $tpl->setCurrentBlock('field');
1052  $tpl->setVariable('FIELD_NAME',$definition->getTitle());
1053  $tpl->setVariable('MODULE_VARS','[IF_F_'.$definition->getFieldId().']...[F_'.$definition->getFieldId().']'.
1054  '[/IF_F_'.$definition->getFieldId().']');
1055  $tpl->parseCurrentBlock();
1056  }
1057 
1058  $tpl->setCurrentBlock('record');
1059  $tpl->setVariable('PLACEHOLDER_FOR',$this->lng->txt('md_adv_placeholder_for'));
1060  $tpl->setVariable('TITLE',$record->getTitle());
1061  $tpl->parseCurrentBlock();
1062  }
1063  $custom->setHTML($tpl->get());
1064  $this->form->addItem($custom);
1065  */
1066  }
1067  $this->form->setTitle($this->lng->txt('md_adv_substitution_table'));
1068  $this->form->addCommandButton('updateSubstitutions',$this->lng->txt('save'));
1069  return true;
1070  }
1071 
1077  protected function loadRecordFormData()
1078  {
1079  $this->record->setActive(ilUtil::stripSlashes($_POST['active']));
1080  $this->record->setTitle(ilUtil::stripSlashes($_POST['title']));
1081  $this->record->setDescription(ilUtil::stripSlashes($_POST['desc']));
1082  $this->record->setAssignedObjectTypes(isset($_POST['obj_types']) ? $_POST['obj_types'] : array());
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 ?>