• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/AdvancedMetaData/classes/class.ilAdvancedMDSettingsGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00034 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
00035 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
00036 
00037 class ilAdvancedMDSettingsGUI
00038 {
00039         protected $lng;
00040         protected $tpl;
00041         protected $ctrl;
00042         protected $tabs;
00043         
00050         public function __construct()
00051         {
00052                 global $tpl,$lng,$ilCtrl,$ilTabs;
00053                 
00054                 $this->ctrl = $ilCtrl;
00055                 $this->lng = $lng;
00056                 $this->lng->loadLanguageModule('meta');
00057                 $this->tpl = $tpl;
00058                 $this->tabs_gui = $ilTabs;
00059         }
00060         
00068         public function executeCommand()
00069         {
00070                 $next_class = $this->ctrl->getNextClass($this);
00071                 $cmd = $this->ctrl->getCmd();
00072                 
00073                 $this->setSubTabs();
00074                 switch($next_class)
00075                 {
00076                         default:
00077                                 if(!$cmd)
00078                                 {
00079                                         $cmd = 'showRecords';
00080                                 }
00081                                 $this->$cmd();
00082                 }               
00083         }
00084         
00092         public function showRecords()
00093         {
00094                 $this->record_objs = $this->getRecordObjects();
00095                 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.show_records.html','Services/AdvancedMetaData');
00096 
00097                 include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordTableGUI.php");
00098                 $table_gui = new ilAdvancedMDRecordTableGUI($this, "showRecords");
00099                 $table_gui->setTitle($this->lng->txt("md_record_list_table"));
00100                 $table_gui->parseRecords($this->record_objs);
00101                 $table_gui->addCommandButton("updateRecords", $this->lng->txt("save"));
00102                 $table_gui->addCommandButton('createRecord',$this->lng->txt('add'));
00103                 $table_gui->addMultiCommand("exportRecords",$this->lng->txt('export'));
00104                 $table_gui->addMultiCommand("confirmDeleteRecords", $this->lng->txt("delete"));
00105                 $table_gui->setSelectAllCheckbox("record_id");
00106                 $this->tpl->setVariable('RECORD_TABLE',$table_gui->getHTML());
00107                 
00108                 if(!$this->initFormSubstitutions())
00109                 {
00110                         return true;
00111                 }
00112                 if (is_object($this->form))
00113                 {
00114                         $this->tpl->setVariable('SUBSTITUTION_TABLE',$this->form->getHTML());
00115                 }
00116                 return true;
00117         }
00118         
00125         public function updateSubstitutions()
00126         {
00127                 foreach(ilAdvancedMDRecord::_getActivatedObjTypes() as $obj_type)
00128                 {
00129                         include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
00130                         $sub = ilAdvancedMDSubstitution::_getInstanceByObjectType($obj_type);
00131                         $sub->resetSubstitutions(array());
00132                         $sub->enableDescription($_POST['enabled_desc_'.$obj_type]);
00133                         $sub->enableFieldNames(true);
00134                         asort($_POST['position'][$obj_type],SORT_NUMERIC);
00135                         foreach($_POST['position'][$obj_type] as $field_id => $pos)
00136                         {
00137                                 if(isset($_POST['show'][$obj_type][$field_id]) and $_POST['show'][$obj_type][$field_id])
00138                                 {
00139                                         $newline = $bold = false;
00140                                         if(isset($_POST['bold'][$obj_type][$field_id]) and $_POST['bold'][$obj_type][$field_id])
00141                                         {
00142                                                 $bold = true;
00143                                         }
00144                                         if(isset($_POST['newline'][$obj_type][$field_id]) and $_POST['newline'][$obj_type][$field_id])
00145                                         {
00146                                                 $newline = true;
00147                                         }
00148                                         $sub->appendSubstitution($field_id,$bold,$newline);
00149                                 }                       
00150                         }
00151                         $sub->update();
00152                 }
00153                 
00154                 
00155                 /*
00156                 foreach(ilAdvancedMDRecord::_getAllRecordsByObjectType() as $obj_type => $visible_record)
00157                 {
00158                         include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
00159                         $sub = ilAdvancedMDSubstitution::_getInstanceByObjectType($obj_type);
00160                         $sub->setSubstitutionString(($_POST['substitution_'.$obj_type]));
00161                         $sub->enableDescription($_POST['enabled_desc_'.$obj_type]);
00162                         $sub->update();
00163                 }
00164                 */
00165                 ilUtil::sendInfo($this->lng->txt('settings_saved'));
00166                 $this->showRecords();
00167                 return true;
00168         }
00169         
00175         public function exportRecords()
00176         {
00177                 if(!isset($_POST['record_id']))
00178                 {
00179                         ilUtil::sendInfo($this->lng->txt('select_one'));
00180                         $this->showRecords();
00181                         return false;
00182                 }
00183                 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordXMLWriter.php');
00184                 $xml_writer = new ilAdvancedMDRecordXMLWriter($_POST['record_id']);
00185                 $xml_writer->write();
00186                 
00187                 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
00188                 $export_files = new ilAdvancedMDRecordExportFiles();
00189                 $export_files->create($xml_writer->xmlDumpMem());
00190                 
00191                 ilUtil::sendInfo($this->lng->txt('md_adv_records_exported'));
00192                 $this->showFiles();
00193         }
00194         
00202         public function showFiles()
00203         {
00204                 
00205                 $this->tabs_gui->setSubTabActive('md_adv_file_list');
00206                 
00207                 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
00208                 $files = new ilAdvancedMDRecordExportFiles();
00209                 $file_data = $files->readFilesInfo();
00210 
00211                 include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFilesTableGUI.php");
00212                 $table_gui = new ilAdvancedMDRecordExportFilesTableGUI($this, "showFiles");
00213                 $table_gui->setTitle($this->lng->txt("md_record_export_table"));
00214                 $table_gui->parseFiles($file_data);
00215                 $table_gui->addMultiCommand("downloadFile",$this->lng->txt('download'));
00216                 $table_gui->addMultiCommand("confirmDeleteFiles", $this->lng->txt("delete"));
00217                 $table_gui->addCommandButton('showFiles',$this->lng->txt('cancel'));
00218                 $table_gui->setSelectAllCheckbox("file_id");
00219                 
00220                 $this->tpl->setContent($table_gui->getHTML());
00221         }
00222         
00230         public function downloadFile()
00231         {
00232                 if(!isset($_POST['file_id']) or count($_POST['file_id']) != 1)
00233                 {
00234                         ilUtil::sendInfo($this->lng->txt('md_adv_select_one_file'));
00235                         $this->showFiles();
00236                         return false;
00237                 }
00238                 
00239                 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
00240                 $files = new ilAdvancedMDRecordExportFiles();
00241                 $abs_path = $files->getAbsolutePathByFileId((int) $_POST['file_id'][0]);
00242                 
00243                 ilUtil::deliverFile($abs_path,'ilias_meta_data_record.xml','application/xml');
00244         }
00245         
00252         public function confirmDeleteFiles()
00253         {
00254                 if(!isset($_POST['file_id']))
00255                 {
00256                         ilUtil::sendInfo($this->lng->txt('select_one'));
00257                         $this->showFiles();
00258                         return false;
00259                 }
00260         
00261                 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
00262                 $c_gui = new ilConfirmationGUI();
00263                 
00264                 // set confirm/cancel commands
00265                 $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFiles"));
00266                 $c_gui->setHeaderText($this->lng->txt("md_adv_delete_files_sure"));
00267                 $c_gui->setCancel($this->lng->txt("cancel"), "showFiles");
00268                 $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFiles");
00269 
00270                 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
00271                 $files = new ilAdvancedMDRecordExportFiles();
00272                 $file_data = $files->readFilesInfo();
00273 
00274 
00275                 // add items to delete
00276                 foreach($_POST["file_id"] as $file_id)
00277                 {
00278                         $info = $file_data[$file_id];
00279                         $c_gui->addItem("file_id[]", $file_id, is_array($info['name']) ? implode(',',$info['name']) : 'No Records');
00280                 }
00281                 $this->tpl->setContent($c_gui->getHTML());
00282         }
00283         
00291         public function deleteFiles()
00292         {
00293                 if(!isset($_POST['file_id']))
00294                 {
00295                         ilUtil::sendInfo($this->lng->txt('select_one'));
00296                         $this->editFiles();
00297                         return false;
00298                 }
00299 
00300                 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
00301                 $files = new ilAdvancedMDRecordExportFiles();
00302                 
00303                 foreach($_POST['file_id'] as $file_id)
00304                 {
00305                         $files->deleteByFileId((int) $file_id);
00306                 }
00307                 ilUtil::sendInfo($this->lng->txt('md_adv_deleted_files'));
00308                 $this->showFiles();
00309         }
00310         
00317         public function confirmDeleteRecords()
00318         {
00319                 if(!isset($_POST['record_id']))
00320                 {
00321                         ilUtil::sendInfo($this->lng->txt('select_one'));
00322                         $this->showRecords();
00323                         return false;
00324                 }
00325 
00326                 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
00327                 $c_gui = new ilConfirmationGUI();
00328                 
00329                 // set confirm/cancel commands
00330                 $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteRecords"));
00331                 $c_gui->setHeaderText($this->lng->txt("md_adv_delete_record_sure"));
00332                 $c_gui->setCancel($this->lng->txt("cancel"), "showRecords");
00333                 $c_gui->setConfirm($this->lng->txt("confirm"), "deleteRecords");
00334 
00335                 // add items to delete
00336                 foreach($_POST["record_id"] as $record_id)
00337                 {
00338                         $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
00339                         $c_gui->addItem("record_id[]", $record_id, $record->getTitle() ? $record->getTitle() : 'No Title');
00340                 }
00341                 $this->tpl->setContent($c_gui->getHTML());
00342         }
00343         
00350         public function deleteRecords()
00351         {
00352                 if(!isset($_POST['record_id']))
00353                 {
00354                         ilUtil::sendInfo($this->lng->txt('select_one'));
00355                         $this->showRecords();
00356                         return false;
00357                 }
00358                 foreach($_POST['record_id'] as $record_id)
00359                 {
00360                         $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
00361                         $record->delete();                      
00362                 }
00363                 ilUtil::sendInfo($this->lng->txt('md_adv_deleted_records'));
00364                 $this->showRecords();
00365                 return true;    
00366         }
00367         
00375         public function updateRecords()
00376         {
00377                 foreach($this->getRecordObjects() as $record_obj)
00378                 {
00379                         $new_types = isset($_POST['obj_types'][$record_obj->getRecordId()]) ?
00380                                 $_POST['obj_types'][$record_obj->getRecordId()] :
00381                                 array();
00382                         $record_obj->setAssignedObjectTypes($new_types);
00383                         $record_obj->setActive(isset($_POST['active'][$record_obj->getRecordId()]));
00384                         $record_obj->update();
00385                 }
00386                 ilUtil::sendInfo($this->lng->txt('settings_saved'));
00387                 $this->showRecords();
00388         }
00389         
00396         public function confirmDeleteFields()
00397         {
00398                 if(!isset($_POST['field_id']))
00399                 {
00400                         ilUtil::sendInfo($this->lng->txt('select_one'));
00401                         $this->editRecord();
00402                         return false;
00403                 }
00404                 $this->ctrl->saveParameter($this,'record_id');
00405                 
00406                 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
00407                 $c_gui = new ilConfirmationGUI();
00408                 
00409                 // set confirm/cancel commands
00410                 $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFields"));
00411                 $c_gui->setHeaderText($this->lng->txt("md_adv_delete_fields_sure"));
00412                 $c_gui->setCancel($this->lng->txt("cancel"), "showRecords");
00413                 $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFields");
00414 
00415                 // add items to delete
00416                 foreach($_POST["field_id"] as $field_id)
00417                 {
00418                         $field = ilAdvancedMDFieldDefinition::_getInstanceByFieldId($field_id);
00419                         $c_gui->addItem("field_id[]", $field_id, $field->getTitle() ? $field->getTitle() : 'No Title');
00420                 }
00421                 $this->tpl->setContent($c_gui->getHTML());
00422         }
00423         
00431         public function deleteFields()
00432         {
00433                 if(!isset($_POST['field_id']))
00434                 {
00435                         ilUtil::sendInfo($this->lng->txt('select_one'));
00436                         $this->editRecord();
00437                         return false;
00438                 }
00439                 foreach($_POST["field_id"] as $field_id)
00440                 {
00441                         $field = ilAdvancedMDFieldDefinition::_getInstanceByFieldId($field_id);
00442                         $field->delete();
00443                 }               
00444                 ilUtil::sendInfo($this->lng->txt('md_adv_deleted_fields'));
00445                 $this->editRecord();
00446         }
00447         
00455         public function editRecord()
00456         {
00457                 // reset session
00458                 $_SESSION['num_values'] = 5;
00459                 
00460                 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.edit_record.html','Services/AdvancedMetaData');
00461                 $this->ctrl->saveParameter($this,'record_id');
00462                 $this->initRecordObject();
00463                 $this->initForm('edit');
00464                 $this->tpl->setVariable('EDIT_RECORD_TABLE',$this->form->getHTML());
00465                 
00466                 // show field table
00467                 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
00468                 $fields = ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($this->record->getRecordId());
00469 
00470                 include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldTableGUI.php");
00471                 $table_gui = new ilAdvancedMDFieldTableGUI($this, "editRecord");
00472                 $table_gui->setTitle($this->lng->txt("md_adv_field_table"));
00473                 $table_gui->parseDefinitions($fields);
00474                 $table_gui->addCommandButton("updateFields", $this->lng->txt("save"));
00475                 $table_gui->addCommandButton('createField',$this->lng->txt('add'));
00476                 $table_gui->addCommandButton('showRecords',$this->lng->txt('cancel'));
00477                 $table_gui->addMultiCommand("confirmDeleteFields", $this->lng->txt("delete"));
00478                 $table_gui->setSelectAllCheckbox("field_id");
00479                 
00480                 $this->tpl->setVariable('FIELDS_TABLE',$table_gui->getHTML());
00481         }
00482         
00489         public function updateFields()
00490         {
00491                 if(!isset($_GET['record_id']) or !$_GET['record_id'])
00492                 {
00493                         ilUtil::sendInfo($this->lng->txt('select_one'));
00494                         $this->showRecords();
00495                         return false;
00496                 }
00497 
00498                 if(!isset($_POST['position']) or !is_array($_POST['position']))
00499                 {
00500                         $this->showRecords();
00501                         return false;
00502                 }
00503                 // sort by position
00504                 asort($_POST['position'],SORT_NUMERIC);
00505                 $counter = 1;
00506                 
00507                 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
00508                 foreach($_POST['position'] as $field_id => $pos)
00509                 {
00510                         $definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId($field_id);
00511                         $definition->setPosition($counter++);
00512                         $definition->enableSearchable(isset($_POST['searchable'][$field_id]) ? true : false);
00513                         $definition->update();
00514                 }
00515                 
00516                 ilUtil::sendInfo($this->lng->txt('settings_saved'));
00517                 $this->editRecord();
00518                 return true;            
00519         }
00520 
00528         public function updateRecord()
00529         {
00530                 global $ilErr;
00531                 
00532                 if(!isset($_GET['record_id']) or !$_GET['record_id'])
00533                 {
00534                         ilUtil::sendInfo($this->lng->txt('select_one'));
00535                         $this->showRecords();
00536                         return false;
00537                 }
00538                 $this->initRecordObject();
00539                 $this->loadRecordFormData();
00540                 
00541                 if(!$this->record->validate())
00542                 {
00543                         ilUtil::sendInfo($this->lng->txt($ilErr->getMessage()));
00544                         $this->editRecord();
00545                         return false;
00546                 }
00547                 $this->record->update();
00548                 ilUtil::sendInfo($this->lng->txt('settings_saved'));
00549                 $this->showRecords();
00550                 return true;
00551         }
00552         
00553 
00561         public function createRecord()
00562         {
00563                 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.new_record.html','Services/AdvancedMetaData');
00564                 
00565                 $this->initRecordObject();
00566                 $this->initForm('create');
00567                 $this->tpl->setVariable('NEW_RECORD_TABLE',$this->form->getHTML());
00568                 
00569                 // Import Table
00570                 $this->initImportForm();
00571                 $this->tpl->setVariable('IMPORT_RECORD_TABLE',$this->import_form->getHTML());
00572                 return true;
00573         }
00574         
00580         protected function initImportForm()
00581         {
00582                 if(is_object($this->import_form))
00583                 {
00584                         return true;
00585                 }
00586                 
00587                 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
00588                 $this->import_form = new ilPropertyFormGUI();
00589                 $this->import_form->setFormAction($this->ctrl->getFormAction($this));
00590                 
00591                 // add file property
00592                 $file = new ilFileInputGUI($this->lng->txt('file'),'file');
00593                 $file->setSuffixes(array('xml'));
00594                 $file->setRequired(true);
00595                 $this->import_form->addItem($file);
00596                 
00597                 $this->import_form->setTitle($this->lng->txt('md_adv_import_record'));
00598                 $this->import_form->addCommandButton('importRecord',$this->lng->txt('import'));
00599                 $this->import_form->addCommandButton('editRecord',$this->lng->txt('cancel'));
00600         }
00601         
00609         public function importRecord()
00610         {
00611                 $this->initImportForm();
00612                 if(!$this->import_form->checkInput())
00613                 {
00614                         $this->import_form->setValuesByPost();
00615                         $this->createRecord();
00616                         return false;
00617                 }
00618                 
00619                 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordImportFiles.php');
00620                 $import_files = new ilAdvancedMDRecordImportFiles();
00621                 if(!$create_time = $import_files->moveUploadedFile($_FILES['file']['tmp_name']))
00622                 {
00623                         $this->createRecord();
00624                         return false;
00625                 }
00626                 
00627                 try
00628                 {
00629                         include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordParser.php');
00630                         $parser = new ilAdvancedMDRecordParser($import_files->getImportFileByCreationDate($create_time));
00631                         
00632                         // Validate
00633                         $parser->setMode(ilAdvancedMDRecordParser::MODE_INSERT_VALIDATION);
00634                         $parser->startParsing();
00635                         
00636                         // Insert
00637                         $parser->setMode(ilAdvancedMDRecordParser::MODE_INSERT);
00638                         $parser->startParsing();
00639                         ilUtil::sendInfo($this->lng->txt('md_adv_added_new_record'));
00640                         $this->showRecords();
00641                 }
00642                 catch(ilSAXParserException $exc)
00643                 {
00644                         ilUtil::sendInfo($exc->getMessage());
00645                         $this->createRecord();
00646                 }
00647 
00648                 // Finally delete import file
00649                 $import_files->deleteFileByCreationDate($create_time);
00650                 return true;
00651         }
00652         
00653         
00661         public function saveRecord()
00662         {
00663                 global $ilErr;
00664                 
00665                 $this->initRecordObject();
00666                 $this->loadRecordFormData();
00667                 
00668                 if(!$this->record->validate())
00669                 {
00670                         ilUtil::sendInfo($this->lng->txt($ilErr->getMessage()));
00671                         $this->createRecord();
00672                         return false;
00673                 }
00674                 $this->record->save();
00675                 ilUtil::sendInfo($this->lng->txt('md_adv_added_new_record'));
00676                 $this->showRecords();
00677         }
00678         
00685         public function editField()
00686         {
00687                  $this->ctrl->saveParameter($this,'record_id');
00688                  $this->ctrl->saveParameter($this,'field_id');
00689                  
00690                  $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId((int) $_GET['field_id']);
00691                  $this->initFieldForm('edit');
00692                  $this->tpl->setContent($this->form->getHTML());
00693         }
00694         
00701         public function updateField()
00702         {
00703                 global $ilErr;
00704                 
00705                 $this->ctrl->saveParameter($this,'record_id');
00706                  
00707                 $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId((int) $_GET['field_id']);
00708                 $this->loadFieldFormData();
00709                 
00710                 if(!$this->field_definition->validate())
00711                 {
00712                         ilUtil::sendInfo($this->lng->txt($ilErr->getMessage()));
00713                         $this->editField();
00714                         return false;
00715                 }
00716                 $this->field_definition->update();
00717                 ilUtil::sendInfo($this->lng->txt('settings_saved'));
00718                 $this->editRecord();
00719         }
00720         
00727         public function createField()
00728         {
00729                 $this->ctrl->saveParameter($this,'record_id');
00730 
00731                 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
00732                 $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId(0);
00733                 $this->initFieldForm('create');
00734                 $this->tpl->setContent($this->form->getHTML()); 
00735         }
00736         
00743         public function addValue()
00744         {
00745                 ++$_SESSION['num_values'];
00746                 
00747                 $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId(isset($_GET['field_id']) ? (int) $_GET['field_id'] : 0);
00748                 $this->loadFieldFormData();
00749                 
00750                 if(isset($_GET['field_id']) and $_GET['field_id'])
00751                 {
00752                         $this->editField();
00753                 }
00754                 else
00755                 {
00756                         $this->createField();
00757                 }
00758         }
00759         
00765         public function saveField()
00766         {
00767                 global $ilErr;
00768                 
00769                 $this->ctrl->saveParameter($this,'record_id');
00770                 $this->field_definition = ilAdvancedMDFieldDefinition::_getInstanceByFieldId(0);
00771                 $this->loadFieldFormData();
00772                 
00773                 if(!$this->field_definition->validate())
00774                 {
00775                         ilUtil::sendInfo($this->lng->txt($ilErr->getMessage()));
00776                         $this->createField();
00777                         return false;
00778                 }
00779                 $this->field_definition->add();
00780                 ilUtil::sendInfo($this->lng->txt('save_settings'));
00781                 $this->editRecord();
00782         }
00783         
00784         
00790         protected function initFieldForm($a_mode)
00791         {
00792                 if(is_object($this->field_form))
00793                 {
00794                         return true;
00795                 }
00796         
00797                 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
00798 
00799                 $this->form = new ilPropertyFormGUI();
00800                 $this->form->setFormAction($this->ctrl->getFormAction($this));
00801                 
00802                 // title
00803                 $title = new ilTextInputGUI($this->lng->txt('title'),'title');
00804                 $title->setValue($this->field_definition->getTitle());
00805                 $title->setSize(20);
00806                 $title->setMaxLength(70);
00807                 $title->setRequired(true);
00808                 $this->form->addItem($title);
00809                 
00810                 // desc
00811                 $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
00812                 $desc->setValue($this->field_definition->getDescription());
00813                 $desc->setRows(3);
00814                 $desc->setCols(50);
00815                 $this->form->addItem($desc);
00816                 
00817                 // Searchable
00818                 $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_searchable'),'searchable');
00819                 $check->setChecked($this->field_definition->isSearchable());
00820                 $check->setValue(1);
00821                 $this->form->addItem($check);
00822                 
00823                 // field type
00824                 $radio = new ilRadioGroupInputGUI($this->lng->txt('field_type'), "field_type");
00825                 $radio->setValue($this->field_definition->getFieldType() ? 
00826                         $this->field_definition->getFieldType() : 
00827                         ilAdvancedMDFieldDefinition::TYPE_TEXT);
00828                 $radio->setRequired(true);
00829 
00830                 $radio_option = new ilRadioOption($this->lng->txt("udf_type_text"),ilAdvancedMDFieldDefinition::TYPE_TEXT);
00831                 $radio->addOption($radio_option);
00832 
00833                 $radio_option = new ilRadioOption($this->lng->txt("udf_type_date"),ilAdvancedMDFieldDefinition::TYPE_DATE);
00834                 $radio->addOption($radio_option);
00835 
00836                 $radio_option = new ilRadioOption($this->lng->txt("udf_type_select"),ilAdvancedMDFieldDefinition::TYPE_SELECT);
00837                 $radio->addOption($radio_option);
00838                 
00839                 $values = $this->field_definition->getFieldValues();
00840                 
00841                 $max_values = max(count($values),$_SESSION['num_values'] ? $_SESSION['num_values'] : 5);
00842                 $_SESSION['num_values'] = $max_values;
00843                 for($i = 1; $i <= $max_values;$i++)
00844                 {
00845                         $title = new ilTextInputGUI($this->lng->txt('udf_value').' '.$i,'value_'.$i);
00846                         $title->setValue(isset($values[$i - 1]) ? $values[$i - 1] : '');
00847                         $title->setSize(20);
00848                         $title->setMaxLength(70);
00849                         $radio_option->addSubItem($title);
00850                 }
00851                 $this->form->addItem($radio);
00852                 
00853                 switch($a_mode)
00854                 {
00855                         case 'create':
00856                                 $this->form->setTitle($this->lng->txt('md_adv_create_field'));
00857                                 $this->form->addCommandButton('saveField',$this->lng->txt('create'));
00858                                 $this->form->addCommandButton('addValue',$this->lng->txt('md_adv_add_value'));
00859                                 $this->form->addCommandButton('editRecord',$this->lng->txt('cancel'));
00860                 
00861                                 return true;
00862                         
00863                         case 'edit':
00864                                 $this->form->setTitle($this->lng->txt('md_adv_edit_field'));
00865                                 $this->form->addCommandButton('updateField',$this->lng->txt('save'));
00866                                 $this->form->addCommandButton('addValue',$this->lng->txt('md_adv_add_value'));
00867                                 $this->form->addCommandButton('editRecord',$this->lng->txt('cancel'));
00868                                 
00869                                 return true;
00870                 }
00871         }
00872         
00878         protected function initForm($a_mode)
00879         {
00880                 if(is_object($this->form))
00881                 {
00882                         return true;
00883                 }
00884         
00885                 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
00886 
00887                 $this->form = new ilPropertyFormGUI();
00888                 $this->form->setFormAction($this->ctrl->getFormAction($this));
00889                 
00890                 // title
00891                 $title = new ilTextInputGUI($this->lng->txt('title'),'title');
00892                 $title->setValue($this->record->getTitle());
00893                 $title->setSize(20);
00894                 $title->setMaxLength(70);
00895                 $title->setRequired(true);
00896                 $this->form->addItem($title);
00897                 
00898                 // desc
00899                 $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'desc');
00900                 $desc->setValue($this->record->getDescription());
00901                 $desc->setRows(3);
00902                 $desc->setCols(50);
00903                 $this->form->addItem($desc);
00904                 
00905                 // active
00906                 $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_active'),'active');
00907                 $check->setChecked($this->record->isActive());
00908                 $check->setValue(1);
00909                 $this->form->addItem($check);
00910                 
00911                 $section = new ilFormSectionHeaderGUI();
00912                 $section->setTitle($this->lng->txt('md_obj_types'));
00913                 $this->form->addItem($section);
00914                 
00915                 foreach(ilAdvancedMDRecord::_getAssignableObjectTypes() as $type)
00916                 {
00917                         $check = new ilCheckboxInputGUI($this->lng->txt('objs_'.$type),'obj_types[]');
00918                         $check->setChecked(in_array($type,$this->record->getAssignedObjectTypes()) ? true : false);
00919                         $check->setValue($type);
00920                         $this->form->addItem($check);
00921                 }
00922                 
00923                 
00924                 switch($a_mode)
00925                 {
00926                         case 'create':
00927                                 $this->form->setTitle($this->lng->txt('md_adv_create_record'));
00928                                 $this->form->addCommandButton('saveRecord',$this->lng->txt('add'));
00929                                 $this->form->addCommandButton('showRecords',$this->lng->txt('cancel'));
00930                 
00931                                 return true;
00932                         
00933                         case 'edit':
00934                                 $this->form->setTitle($this->lng->txt('md_adv_edit_record'));
00935                                 $this->form->addCommandButton('updateRecord',$this->lng->txt('save'));
00936                                 $this->form->addCommandButton('showRecords',$this->lng->txt('cancel'));
00937                                 
00938                                 return true;
00939                 }
00940         }
00941         
00947         protected function initFormSubstitutions()
00948         {
00949                 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
00950 
00951                 if(!$visible_records = ilAdvancedMDRecord::_getAllRecordsByObjectType())
00952                 {
00953                         return true;
00954                 }
00955 
00956                 $this->form = new ilPropertyFormGUI();
00957                 $this->form->setFormAction($this->ctrl->getFormAction($this));
00958                 $this->form->setTableWidth('100%');
00959 
00960                 // substitution
00961                 foreach($visible_records as $obj_type => $records)
00962                 {
00963                         include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
00964                         $sub = ilAdvancedMDSubstitution::_getInstanceByObjectType($obj_type);
00965                         
00966                         // Show section
00967                         $section = new ilFormSectionHeaderGUI();
00968                         $section->setSectionIcon(ilUtil::getImagePath('icon_'.$obj_type.'_s.gif'),$this->lng->txt('objs_'.$obj_type));
00969                         $section->setTitle($this->lng->txt('objs_'.$obj_type));
00970                         $this->form->addItem($section);
00971                         
00972                         $check = new ilCheckboxInputGUI($this->lng->txt('description'),'enabled_desc_'.$obj_type);
00973                         $check->setValue(1);
00974                         $check->setOptionTitle($this->lng->txt('md_adv_desc_show'));
00975                         $check->setChecked($sub->isDescriptionEnabled() ? true : false);
00976                         $this->form->addItem($check);
00977                         
00978                         #$area = new ilTextAreaInputGUI($this->lng->txt('md_adv_substitution'),'substitution_'.$obj_type);
00979                         #$area->setUseRte(true);
00980                         #$area->setRteTagSet('standard');
00981                         #$area->setValue(ilUtil::prepareFormOutput($sub->getSubstitutionString()));
00982                         #$area->setRows(5);
00983                         #$area->setCols(80);
00984                         #$this->form->addItem($area);
00985 
00986                         $definitions = ilAdvancedMDFieldDefinition::_getActiveDefinitionsByObjType($obj_type);
00987                         $definitions = $sub->sortDefinitions($definitions);
00988                         
00989                         $counter = 1;
00990                         foreach($definitions as $definition_id)
00991                         {
00992                                 $def = ilAdvancedMDFieldDefinition::_getInstanceByFieldId($definition_id);
00993                                 
00994                                 $title = ilAdvancedMDRecord::_lookupTitle($def->getRecordId());
00995                                 $title = $def->getTitle().' ('.$title.')';
00996                                 
00997                                 $check = new ilCheckboxInputGUI($title,'show['.$obj_type.']['.$definition_id.']');
00998                                 $check->setValue(1);
00999                                 $check->setOptionTitle($this->lng->txt('md_adv_show'));
01000                                 $check->setChecked($sub->isSubstituted($definition_id));
01001                                 
01002                                 $pos = new ilTextInputGUI($this->lng->txt('position'),'position['.$obj_type.']['.$definition_id.']');
01003                                 $pos->setSize(3);
01004                                 $pos->setMaxLength(4);
01005                                 $pos->setValue(sprintf('%.1f',$counter++));
01006                                 $check->addSubItem($pos);
01007                                 
01008                                 $bold = new ilCheckboxInputGUI($this->lng->txt('bold'),'bold['.$obj_type.']['.$definition_id.']');
01009                                 $bold->setValue(1);
01010                                 $bold->setChecked($sub->isBold($definition_id));
01011                                 $check->addSubItem($bold);
01012 
01013                                 $bold = new ilCheckboxInputGUI($this->lng->txt('newline'),'newline['.$obj_type.']['.$definition_id.']');
01014                                 $bold->setValue(1);
01015                                 $bold->setChecked($sub->hasNewline($definition_id));
01016                                 $check->addSubItem($bold);
01017 
01018 
01019                                 $this->form->addItem($check);
01020                         }
01021                         
01022                         
01023                         // placeholder
01024                         /*
01025                         $custom = new ilCustomInputGUI($this->lng->txt('md_adv_placeholders'));
01026                         $tpl = new ilTemplate('tpl.placeholder_info.html',true,true,'Services/AdvancedMetaData');
01027                         foreach($records as $record)
01028                         {
01029                                 foreach(ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record->getRecordId()) as $definition)
01030                                 {
01031                                         $tpl->setCurrentBlock('field');
01032                                         $tpl->setVariable('FIELD_NAME',$definition->getTitle());
01033                                         $tpl->setVariable('MODULE_VARS','[IF_F_'.$definition->getFieldId().']...[F_'.$definition->getFieldId().']'.
01034                                                 '[/IF_F_'.$definition->getFieldId().']');
01035                                         $tpl->parseCurrentBlock();
01036                                 }
01037                                 
01038                                 $tpl->setCurrentBlock('record');
01039                                 $tpl->setVariable('PLACEHOLDER_FOR',$this->lng->txt('md_adv_placeholder_for'));
01040                                 $tpl->setVariable('TITLE',$record->getTitle());
01041                                 $tpl->parseCurrentBlock();
01042                         }
01043                         $custom->setHTML($tpl->get());
01044                         $this->form->addItem($custom);
01045                         */
01046                 }
01047                 $this->form->setTitle($this->lng->txt('md_adv_substitution_table'));
01048                 $this->form->addCommandButton('updateSubstitutions',$this->lng->txt('save'));
01049                 return true;
01050         }
01051         
01057         protected function loadRecordFormData()
01058         {
01059                 $this->record->setActive(ilUtil::stripSlashes($_POST['active']));
01060                 $this->record->setTitle(ilUtil::stripSlashes($_POST['title']));
01061                 $this->record->setDescription(ilUtil::stripSlashes($_POST['desc']));
01062                 $this->record->setAssignedObjectTypes(isset($_POST['obj_types']) ? $_POST['obj_types'] : array());
01063         }
01064         
01070         protected function loadFieldFormData()
01071         {
01072                 $this->field_definition->setRecordId((int) $_GET['record_id']);
01073                 $this->field_definition->setTitle(ilUtil::stripSlashes($_POST['title']));
01074                 $this->field_definition->setDescription(ilUtil::stripSlashes($_POST['description']));
01075                 $this->field_definition->enableSearchable(isset($_POST['searchable']) ? true : false);
01076                 $this->field_definition->setFieldType(ilUtil::stripSlashes($_POST['field_type']));
01077                 $this->field_definition->setFieldValues(array());
01078                 
01079                 for($i = 1; $i <= $_SESSION['num_values'];$i++)
01080                 {
01081                         if(isset($_POST['value_'.$i]))
01082                         {
01083                                 $this->field_definition->appendFieldValue($_POST['value_'.$i]);
01084                         }
01085                 }
01086         }
01087         
01093         protected function initRecordObject()
01094         {
01095                 if(is_object($this->record))
01096                 {
01097                         return $this->record;
01098                 }
01099                 
01100                 $record_id = isset($_GET['record_id']) ?
01101                         $_GET['record_id'] :
01102                         0; 
01103                 return $this->record = ilAdvancedMDRecord::_getInstanceByRecordId($_GET['record_id']);
01104         }
01105 
01111         protected function setSubTabs()
01112         {
01113                 $this->tabs_gui->clearSubTabs();
01114 
01115                 $this->tabs_gui->addSubTabTarget("md_adv_record_list",
01116                                                                  $this->ctrl->getLinkTarget($this, "showRecords"),
01117                                                                  '',
01118                                                                  '',
01119                                                                  '',
01120                                                                  true);
01121                         
01122                 $this->tabs_gui->addSubTabTarget("md_adv_file_list",
01123                                                                  $this->ctrl->getLinkTarget($this, "showFiles"),
01124                                                                  "showFiles",
01125                                                                  array(),
01126                                                                  '',
01127                                                                  false);
01128                 
01129         }
01130         
01136         protected function getRecordObjects()
01137         {
01138                 if(!isset($this->record_objs))
01139                 {
01140                         return $this->record_objs = ilAdvancedMDRecord::_getRecords();
01141                 }
01142                 return $this->record_objs;
01143         }
01144         
01145 }
01146 ?>

Generated on Fri Dec 13 2013 17:56:55 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1