ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilECSSettingsGUI.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 {
35  protected $tpl;
36  protected $lng;
37  protected $ctrl;
38  protected $tabs_gui;
39 
40 
46  public function __construct()
47  {
48  global $lng,$tpl,$ilCtrl,$ilTabs;
49 
50  $this->tpl = $tpl;
51  $this->lng = $lng;
52  $this->lng->loadLanguageModule('ecs');
53  $this->ctrl = $ilCtrl;
54  $this->tabs_gui = $ilTabs;
55 
56  $this->initSettings();
57  }
58 
66  public function executeCommand()
67  {
68  $next_class = $this->ctrl->getNextClass($this);
69  $cmd = $this->ctrl->getCmd();
70 
71  $this->setSubTabs();
72  switch($next_class)
73  {
74  default:
75  if(!$cmd)
76  {
77  $cmd = "settings";
78  }
79  $this->$cmd();
80  break;
81  }
82  return true;
83  }
84 
85 
91  protected function readAll()
92  {
93  include_once('Services/WebServices/ECS/classes/class.ilECSConnector.php');
94  include_once('Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
95  include_once('./Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php');
96 
97  try
98  {
100 
101  include_once('./Services/WebServices/ECS/classes/class.ilECSTaskScheduler.php');
102  ilECSTaskScheduler::_getInstance()->startTaskExecution();
103 
104  ilUtil::sendInfo($this->lng->txt('ecs_remote_imported'));
105  $this->imported();
106  return true;
107  }
108  catch(ilECSConnectorException $e1)
109  {
110  ilUtil::sendInfo('Cannot connect to ECS server: '.$e1->getMessage());
111  $this->imported();
112  return false;
113  }
114  catch(ilException $e2)
115  {
116  ilUtil::sendInfo('Update failed: '.$e1->getMessage());
117  $this->imported();
118  return false;
119  }
120 
121 
122  }
123 
129  protected function settings()
130  {
131  $this->initSettingsForm();
132  $this->tabs_gui->setSubTabActive('ecs_settings');
133 
134  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_settings.html','Services/WebServices/ECS');
135  $this->tpl->setVariable('SETTINGS_TABLE',$this->form->getHTML());
136  }
137 
143  protected function initSettingsForm()
144  {
145  if(is_object($this->form))
146  {
147  return true;
148  }
149  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
150 
151  $this->form = new ilPropertyFormGUI();
152  $this->form->setFormAction($this->ctrl->getFormAction($this,'settings'));
153  $this->form->setTitle($this->lng->txt('ecs_connection_settings'));
154 
155  $ena = new ilCheckboxInputGUI($this->lng->txt('ecs_active'),'active');
156  $ena->setChecked($this->settings->isEnabled());
157  $ena->setValue(1);
158  $this->form->addItem($ena);
159 
160  $ser = new ilTextInputGUI($this->lng->txt('ecs_server_url'),'server');
161  $ser->setValue($this->settings->getServer());
162  $ser->setRequired(true);
163  $this->form->addItem($ser);
164 
165  $pro = new ilSelectInputGUI($this->lng->txt('ecs_protocol'),'protocol');
166  // fixed to https
167  #$pro->setOptions(array(ilECSSettings::PROTOCOL_HTTP => $this->lng->txt('http'),
168  # ilECSSettings::PROTOCOL_HTTPS => $this->lng->txt('https')));
169  $pro->setOptions(array(ilECSSettings::PROTOCOL_HTTPS => 'HTTPS'));
170  $pro->setValue($this->settings->getProtocol());
171  $pro->setRequired(true);
172  $this->form->addItem($pro);
173 
174  $por = new ilTextInputGUI($this->lng->txt('ecs_port'),'port');
175  $por->setSize(5);
176  $por->setMaxLength(5);
177  $por->setValue($this->settings->getPort());
178  $por->setRequired(true);
179  $this->form->addItem($por);
180 
181  $cer = new ilTextInputGUI($this->lng->txt('ecs_client_cert'),'client_cert');
182  $cer->setSize(60);
183  $cer->setValue($this->settings->getClientCertPath());
184  $cer->setRequired(true);
185  $this->form->addItem($cer);
186 
187  $cer = new ilTextInputGUI($this->lng->txt('ecs_cert_key'),'key_path');
188  $cer->setSize(60);
189  $cer->setValue($this->settings->getKeyPath());
190  $cer->setRequired(true);
191  $this->form->addItem($cer);
192 
193  $cer = new ilTextInputGUI($this->lng->txt('ecs_key_password'),'key_password');
194  $cer->setSize(12);
195  $cer->setValue($this->settings->getKeyPassword());
196  $cer->setInputType('password');
197  $cer->setRequired(true);
198  $this->form->addItem($cer);
199 
200  $cer = new ilTextInputGUI($this->lng->txt('ecs_ca_cert'),'ca_cert');
201  $cer->setSize(60);
202  $cer->setValue($this->settings->getCACertPath());
203  $cer->setRequired(true);
204  $this->form->addItem($cer);
205 
206  $ser = new ilNonEditableValueGUI($this->lng->txt('cert_serial'));
207  $ser->setValue($this->settings->getCertSerialNumber() ? $this->settings->getCertSerialNumber() : $this->lng->txt('ecs_no_value'));
208  $this->form->addItem($ser);
209 
210  $loc = new ilFormSectionHeaderGUI();
211  $loc->setTitle($this->lng->txt('ecs_local_settings'));
212  $this->form->addItem($loc);
213 
214  $pol = new ilDurationInputGUI($this->lng->txt('ecs_polling'),'polling');
215  $pol->setShowDays(false);
216  $pol->setShowHours(false);
217  $pol->setShowMinutes(true);
218  $pol->setShowSeconds(true);
219  $pol->setSeconds($this->settings->getPollingTimeSeconds());
220  $pol->setMinutes($this->settings->getPollingTimeMinutes());
221  $pol->setRequired(true);
222  $pol->setInfo($this->lng->txt('ecs_polling_info'));
223  $this->form->addItem($pol);
224 
225  $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'));
226  $imp->setRequired(true);
227 
228  $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
229  $tpl->setVariable('SIZE',5);
230  $tpl->setVariable('MAXLENGTH',11);
231  $tpl->setVariable('POST_VAR','import_id');
232  $tpl->setVariable('PROPERTY_VALUE',$this->settings->getImportId());
233 
234  if($this->settings->getImportId())
235  {
236  $tpl->setVariable('COMPLETE_PATH',$this->buildPath($this->settings->getImportId()));
237  }
238 
239  $imp->setHTML($tpl->get());
240  $imp->setInfo($this->lng->txt('ecs_import_id_info'));
241  $this->form->addItem($imp);
242 
243  $loc = new ilFormSectionHeaderGUI();
244  $loc->setTitle($this->lng->txt('ecs_remote_user_settings'));
245  $this->form->addItem($loc);
246 
247  $role = new ilSelectInputGUI($this->lng->txt('ecs_role'),'global_role');
248  $role->setOptions($this->prepareRoleSelect());
249  $role->setValue($this->settings->getGlobalRole());
250  $role->setInfo($this->lng->txt('ecs_global_role_info'));
251  $role->setRequired(true);
252  $this->form->addItem($role);
253 
254  $duration = new ilDurationInputGUI($this->lng->txt('ecs_account_duration'),'duration');
255  $duration->setInfo($this->lng->txt('ecs_account_duration_info'));
256  $duration->setMonths($this->settings->getDuration());
257  $duration->setShowSeconds(false);
258  $duration->setShowMinutes(false);
259  $duration->setShowHours(false);
260  $duration->setShowDays(false);
261  $duration->setShowMonths(true);
262  $duration->setRequired(true);
263  $this->form->addItem($duration);
264 
265  // Email recipients
266  $loc = new ilFormSectionHeaderGUI();
267  $loc->setTitle($this->lng->txt('ecs_notifications'));
268  $this->form->addItem($loc);
269 
270  $rcp_user = new ilTextInputGUI($this->lng->txt('ecs_user_rcp'),'user_recipients');
271  $rcp_user->setValue($this->settings->getUserRecipientsAsString());
272  $rcp_user->setInfo($this->lng->txt('ecs_user_rcp_info'));
273  $this->form->addItem($rcp_user);
274 
275  $rcp_econ = new ilTextInputGUI($this->lng->txt('ecs_econ_rcp'),'econtent_recipients');
276  $rcp_econ->setValue($this->settings->getEContentRecipientsAsString());
277  $rcp_econ->setInfo($this->lng->txt('ecs_econ_rcp_info'));
278  $this->form->addItem($rcp_econ);
279 
280  $rcp_app = new ilTextInputGUI($this->lng->txt('ecs_approval_rcp'),'approval_recipients');
281  $rcp_app->setValue($this->settings->getApprovalRecipientsAsString());
282  $rcp_app->setInfo($this->lng->txt('ecs_approval_rcp_info'));
283  $this->form->addItem($rcp_app);
284 
285  $this->form->addCommandButton('saveSettings',$this->lng->txt('save'));
286  $this->form->addCommandButton('settings',$this->lng->txt('cancel'));
287  }
288 
294  protected function saveSettings()
295  {
296  $this->settings->setEnabledStatus((int) $_POST['active']);
297  $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
298  $this->settings->setPort(ilUtil::stripSlashes($_POST['port']));
299  $this->settings->setProtocol(ilUtil::stripSlashes($_POST['protocol']));
300  $this->settings->setClientCertPath(ilUtil::stripSlashes($_POST['client_cert']));
301  $this->settings->setCACertPath(ilUtil::stripSlashes($_POST['ca_cert']));
302  $this->settings->setKeyPath(ilUtil::stripSlashes($_POST['key_path']));
303  $this->settings->setKeyPassword(ilUtil::stripSlashes($_POST['key_password']));
304  $this->settings->setImportId(ilUtil::stripSlashes($_POST['import_id']));
305  $this->settings->setPollingTimeMS((int) $_POST['polling']['mm'],(int) $_POST['polling']['ss']);
306  $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
307  $this->settings->setGlobalRole((int) $_POST['global_role']);
308  $this->settings->setDuration((int) $_POST['duration']['MM']);
309 
310  $this->settings->setUserRecipients(ilUtil::stripSlashes($_POST['user_recipients']));
311  $this->settings->setEContentRecipients(ilUtil::stripSlashes($_POST['econtent_recipients']));
312  $this->settings->setApprovalRecipients(ilUtil::stripSlashes($_POST['approval_recipients']));
313 
314  if(!$error = $this->settings->validate())
315  {
316  $this->settings->save();
317  ilUtil::sendInfo($this->lng->txt('settings_saved'));
318  }
319  else
320  {
321  ilUtil::sendInfo($this->lng->txt($error));
322  }
323 
324  $this->setSubTabs('ecs_settings');
325  $this->settings();
326  return true;
327  }
328 
335  public function communities()
336  {
337  $this->tabs_gui->setSubTabActive('ecs_communities');
338 
339  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_communities.html','Services/WebServices/ECS');
340 
341  $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this,'updateCommunities'));
342  $this->tpl->setVariable('IMAGE_DOWNRIGHT',ilUtil::getImagePath('arrow_downright.gif'));
343  $this->tpl->setVariable('TXT_SAVE',$this->lng->txt('ecs_enable_participant'));
344 
345  include_once('Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
346  include_once('Services/WebServices/ECS/classes/class.ilECSCommunityTableGUI.php');
347 
348  try
349  {
351 
352  foreach($reader->getCommunities() as $community)
353  {
354  $this->tpl->setCurrentBlock('table_community');
355  $table_gui = new ilECSCommunityTableGUI($this,'communities',$community->getId());
356 
357  $table_gui->setTitle($community->getTitle().' ('.$community->getDescription().')');
358  #$table_gui->parse($community->getParticipants());
359  $table_gui->parse($community->getParticipants());
360 
361  #$table_gui->setSelectAllCheckbox("mid");
362  $this->tpl->setVariable('TABLE_COMM',$table_gui->getHTML());
363  $this->tpl->parseCurrentBlock();
364  }
365  }
366  catch(ilECSConnectorException $exc)
367  {
368  ilUtil::sendInfo('Cannot connect to ECS server');
369  return true;
370  }
371  }
372 
379  protected function updateCommunities()
380  {
381  global $ilLog;
382 
383 
384  $mids = $_POST['mid'] ? $_POST['mid'] : array();
385 
386  include_once('./Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php');
388 
389  foreach($part->getEnabledParticipants() as $mid)
390  {
391  if(!in_array($mid,$mids))
392  {
393  // Delete all remote courses
394  include_once('./Modules/RemoteCourse/classes/class.ilObjRemoteCourse.php');
395  foreach(ilObjRemoteCourse::_lookupObjIdsByMID($mid) as $obj_id)
396  {
397  foreach(ilObject::_getAllReferences($obj_id) as $ref_id)
398  {
399  $to_delete = ilObjectFactory::getInstanceByRefId($ref_id,false);
400  $to_delete->delete();
401  }
402  }
403  }
404  }
405 
406 
407  try
408  {
409  // Update all exported econtent
410  include_once('./Services/WebServices/ECS/classes/class.ilECSEContentReader.php');
411  include_once('./Services/WebServices/ECS/classes/class.ilECSConnector.php');
412  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
413 
415  $reader->read();
416  $all_content = $reader->getEContent();
417 
418  // read update events
419  foreach($all_content as $content)
420  {
421  if(ilECSExport::_isRemote($content->getEContentId()))
422  {
423  $ilLog->write(__METHOD__.': Ignoring remote EContent: '.$content->getTitle());
424  // Do not handle remote courses.
425  continue;
426  }
427  $members = array_intersect($mids,$content->getEligibleMembers());
428  if(!$members)
429  {
430  $ilLog->write(__METHOD__.': Deleting EContent: '.$content->getTitle());
431  $connector = new ilECSConnector();
432  $connector->deleteResource($content->getEContentId());
433 
434  ilECSExport::_deleteEContentIds(array($content->getEContentId()));
435  }
436  elseif(count($members) != count($content->getEligibleMembers()))
437  {
438  $ilLog->write(__METHOD__.': Update eligible members for EContent: '.$content->getTitle());
439  $content->setEligibleMembers($members);
440  $connector = new ilECSConnector();
441  $connector->updateResource($content->getEContentId(),json_encode($content));
442  }
443  }
444  }
445  catch(ilECSConnectorException $e)
446  {
447  ilUtil::sendInfo('Cannot connect to ECS server: '.$e->getMessage());
448  $this->communities();
449  return false;
450  }
451  catch(ilException $e)
452  {
453  ilUtil::sendInfo('Update failed: '.$e1->getMessage());
454  $this->communities();
455  return false;
456  }
457 
458  $part->setEnabledParticipants($_POST['mid'] ? $_POST['mid'] : array());
459  $part->save();
460 
461  ilUtil::sendInfo($this->lng->txt('settings_saved'));
462  $this->communities();
463  return true;
464  }
465 
471  public function mappings()
472  {
473  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
474 
475  $this->tabs_gui->setSubTabActive('ecs_mappings');
476 
478  if(!count($fields))
479  {
480  ilUtil::sendInfo($this->lng->txt('ecs_no_adv_md'));
481  return true;
482  }
483 
484  $this->initMappingsForm();
485  $this->tpl->setContent($this->form->getHTML());
486  return true;
487  }
488 
495  protected function saveMappings()
496  {
497  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
498  $mapping_settings = ilECSDataMappingSettings::_getInstance();
499  $mapping_settings->setMappings($_POST['mapping']);
500  $mapping_settings->save();
501 
502  ilUtil::sendInfo($this->lng->txt('settings_saved'));
503  $this->mappings();
504  return true;
505  }
506 
512  protected function initMappingsForm()
513  {
514  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
515 
516  if(is_object($this->form))
517  {
518  return true;
519  }
520 
521  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
522  $mapping_settings = ilECSDataMappingSettings::_getInstance();
523 
524  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
526  $fields = array_unique(array_merge(ilAdvancedMDFieldDefinition::_getActiveDefinitionsByObjType('crs'),
528 
529 
530  $options = $this->prepareFieldSelection($fields);
531  $this->form = new ilPropertyFormGUI();
532  $this->form->setTitle($this->lng->txt('ecs_mapping_tbl'));
533  $this->form->setFormAction($this->ctrl->getFormAction($this,'saveMappings'));
534  $this->form->addCommandButton('saveMappings',$this->lng->txt('save'));
535  $this->form->addCommandButton('mappings',$this->lng->txt('cancel'));
536 
537  // get all optional fields
538  include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
540 
541  foreach($optional as $field_name)
542  {
543  $select = new ilSelectInputGUI($this->lng->txt('ecs_field_'.$field_name),'mapping['.$field_name.']');
544  $select->setValue($mapping_settings->getMappingByECSName($field_name));
545  $select->setOptions($options);
546  $this->form->addItem($select);
547  }
548  }
549 
554  protected function categoryMapping()
555  {
556  $this->tabs_gui->setSubTabActive('ecs_category_mapping');
557  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.category_mapping.html','Services/WebServices/ECS');
558 
559  $this->initRule();
560  $this->initCategoryMappingForm();
561 
562 
563  $this->tpl->setVariable('NEW_RULE_TABLE',$this->form->getHTML());
564  if($html = $this->showRulesTable())
565  {
566  $this->tpl->setVariable('RULES_TABLE',$html);
567  }
568  }
569 
574  protected function addCategoryMapping()
575  {
576  $this->initRule();
577 
578  $this->initCategoryMappingForm('add');
579  if($this->form->checkInput())
580  {
581  $this->rule->setContainerId($this->form->getInput('import_id'));
582  $this->rule->setMappingType($this->form->getInput('type'));
583  $this->rule->setMappingValue($this->form->getInput('mapping_value'));
584  $this->rule->setFieldName($this->form->getInput('field'));
585  $this->rule->setDateRangeStart($this->form->getItemByPostVar('dur_begin')->getDate());
586  $this->rule->setDateRangeEnd($this->form->getItemByPostVar('dur_end')->getDate());
587 
588  if($err = $this->rule->validate())
589  {
590  ilUtil::sendInfo($this->lng->txt($err));
591  $this->form->setValuesByPost();
592  $this->categoryMapping();
593  return false;
594  }
595  $this->rule->save();
596  ilUtil::sendInfo($this->lng->txt('settings_saved'));
597  unset($this->rule);
598  $this->categoryMapping();
599  return true;
600  }
601  ilUtil::sendInfo($this->lng->txt('err_check_input'));
602  $this->form->setValuesByPost();
603  $this->categoryMapping();
604  return false;
605  }
606 
611  protected function editCategoryMapping()
612  {
613  if(!$_REQUEST['rule_id'])
614  {
615  ilUtil::sendInfo($this->lng->txt('select_one'));
616  $this->categoryMapping();
617  return false;
618  }
619 
620  $this->tabs_gui->setSubTabActive('ecs_category_mapping');
621  $this->ctrl->saveParameter($this,'rule_id');
622  $this->initRule((int) $_REQUEST['rule_id']);
623 
624  $this->initCategoryMappingForm('edit');
625  $this->tpl->setContent($this->form->getHTML());
626  return true;
627  }
628 
633  protected function updateCategoryMapping()
634  {
635  if(!$_REQUEST['rule_id'])
636  {
637  ilUtil::sendInfo($this->lng->txt('select_one'));
638  $this->categoryMapping();
639  return false;
640  }
641  $this->ctrl->saveParameter($this,'rule_id');
642  $this->initRule((int) $_REQUEST['rule_id']);
643  $this->initCategoryMappingForm('edit');
644  if($this->form->checkInput())
645  {
646  $this->rule->setContainerId($this->form->getInput('import_id'));
647  $this->rule->setMappingType($this->form->getInput('type'));
648  $this->rule->setMappingValue($this->form->getInput('mapping_value'));
649  $this->rule->setFieldName($this->form->getInput('field'));
650  $this->rule->setDateRangeStart($this->form->getItemByPostVar('dur_begin')->getDate());
651  $this->rule->setDateRangeEnd($this->form->getItemByPostVar('dur_end')->getDate());
652 
653  if($err = $this->rule->validate())
654  {
655  ilUtil::sendInfo($this->lng->txt($err));
656  $this->form->setValuesByPost();
657  $this->editCategoryMapping();
658  return false;
659  }
660  $this->rule->update();
661  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
662  $this->ctrl->redirect($this,'categoryMapping');
663  return true;
664  }
665  ilUtil::sendInfo($this->lng->txt('err_check_input'));
666  $this->form->setValuesByPost();
667  $this->editCategoryMapping();
668  return false;
669 
670  }
671 
675  protected function deleteCategoryMappings()
676  {
677  if(!is_array($_POST['rules']) or !$_POST['rules'])
678  {
679  ilUtil::sendInfo($this->lng->txt('no_checkbox'));
680  $this->categoryMapping();
681  return false;
682  }
683  foreach($_POST['rules'] as $rule_id)
684  {
685  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
686  $rule = new ilECSCategoryMappingRule($rule_id);
687  $rule->delete();
688  }
689  ilUtil::sendInfo($this->lng->txt('settings_saved'));
690  $this->categoryMapping();
691  return true;
692  }
693 
698  protected function showRulesTable()
699  {
700  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php';
701 
703  {
704  return false;
705  }
706  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingTableGUI.php';
707  $rule_table = new ilECSCategoryMappingTableGUI($this,'categoryMapping');
708  $rule_table->parse($rules);
709  return $rule_table->getHTML();
710  }
711 
717  protected function initRule($a_rule_id = 0)
718  {
719  if(is_object($this->rule))
720  {
721  return $this->rule;
722  }
723 
724  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
725  $this->rule = new ilECSCategoryMappingRule($a_rule_id);
726  }
727 
732  protected function initCategoryMappingForm($a_mode = 'add')
733  {
734  if(is_object($this->form))
735  {
736  return true;
737  }
738 
739  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
740  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
741 
742  $this->form = new ilPropertyFormGUI();
743 
744  if($a_mode == 'add')
745  {
746  $this->form->setTitle($this->lng->txt('ecs_new_category_mapping'));
747  $this->form->setFormAction($this->ctrl->getFormAction($this,'categoryMapping'));
748  $this->form->addCommandButton('addCategoryMapping',$this->lng->txt('save'));
749  $this->form->addCommandButton('categoryMapping',$this->lng->txt('cancel'));
750  }
751  else
752  {
753  $this->form->setTitle($this->lng->txt('ecs_edit_category_mapping'));
754  $this->form->setFormAction($this->ctrl->getFormAction($this,'editCategoryMapping'));
755  $this->form->addCommandButton('updateCategoryMapping',$this->lng->txt('save'));
756  $this->form->addCommandButton('categoryMapping',$this->lng->txt('cancel'));
757  }
758 
759  $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'),'import_id');
760  $imp->setRequired(true);
761 
762  $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
763  $tpl->setVariable('SIZE',5);
764  $tpl->setVariable('MAXLENGTH',11);
765  $tpl->setVariable('POST_VAR','import_id');
766  $tpl->setVariable('PROPERTY_VALUE',$this->rule->getContainerId());
767 
768  if($this->settings->getImportId())
769  {
770  $tpl->setVariable('COMPLETE_PATH',$this->buildPath($this->rule->getContainerId()));
771  }
772 
773  $imp->setHTML($tpl->get());
774  $imp->setInfo($this->lng->txt('ecs_import_id_info'));
775  $this->form->addItem($imp);
776 
777  include_once('./Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php');
779  foreach($fields as $field)
780  {
781  $options[$field] = $this->lng->txt('ecs_field_'.$field);
782  }
783  $select = new ilSelectInputGUI($this->lng->txt('ecs_attribute_name'),'field');
784  $select->setValue($this->rule->getFieldName());
785  $select->setRequired(true);
786  $select->setOptions($options);
787  $this->form->addItem($select);
788 
789  // Value
790  $value = new ilRadioGroupInputGUI($this->lng->txt('ecs_cat_mapping_type'),'type');
791  $value->setValue($this->rule->getMappingType());
792  $value->setRequired(true);
793 
794  $fixed = new ilRadioOption($this->lng->txt('ecs_cat_mapping_fixed'),ilECSCategoryMappingRule::TYPE_FIXED);
795  $fixed->setInfo($this->lng->txt('ecs_cat_mapping_fixed_info'));
796 
797  $fixed_val = new ilTextInputGUI($this->lng->txt('ecs_cat_mapping_values'),'mapping_value');
798  $fixed_val->setValue($this->rule->getMappingValue());
799  $fixed_val->setMaxLength(255);
800  $fixed_val->setSize(40);
801  $fixed->addSubItem($fixed_val);
802 
803  $value->addOption($fixed);
804 
805  $duration = new ilRadioOption($this->lng->txt('ecs_cat_mapping_duration'),ilECSCategoryMappingRule::TYPE_DURATION);
806  $duration->setInfo($this->lng->txt('ecs_cat_mapping_duration_info'));
807 
808  $dur_start = new ilDateTimeInputGUI($this->lng->txt('from'),'dur_begin');
809  $dur_start->setDate($this->rule->getDateRangeStart());
810  $duration->addSubItem($dur_start);
811 
812  $dur_end = new ilDateTimeInputGUI($this->lng->txt('to'),'dur_end');
813  $dur_end->setDate($this->rule->getDateRangeEnd());
814  $duration->addSubItem($dur_end);
815 
816  $value->addOption($duration);
817 
818  $this->form->addItem($value);
819 
820  }
821 
822 
828  protected function imported()
829  {
830  global $ilUser;
831 
832  $this->tabs_gui->setSubTabActive('ecs_import');
833 
834  $rcourses = ilUtil::_getObjectsByOperations('rcrs','visible',$ilUser->getId(),-1);
835 
836  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_imported.html','Services/WebServices/ECS');
837 
838  include_once './Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
839  $tb = new ilToolbarGUI();
840 
841  if(count($rcourses))
842  {
843  $tb->addButton(
844  $this->lng->txt('csv_export'),
845  $this->ctrl->getLinkTarget($this,'exportImported')
846  );
847  }
848  if($this->settings->isEnabled())
849  {
850  $tb->addButton(
851  $this->lng->txt('ecs_read_remote_links'),
852  $this->ctrl->getLinkTarget($this,'readAll')
853  );
854  }
855  $this->tpl->setVariable('ACTION_BUTTONS',$tb->getHTML());
856 
857  include_once('Services/WebServices/ECS/classes/class.ilECSImportedContentTableGUI.php');
858 
859  $table_gui = new ilECSImportedContentTableGUI($this,'imported');
860 
861  $table_gui->setTitle($this->lng->txt('ecs_imported_content'));
862  $table_gui->parse($rcourses);
863  $this->tpl->setVariable('TBL_IMPORTED',$table_gui->getHTML());
864 
865  return true;
866  }
867 
874  protected function exportImported()
875  {
876  global $ilObjDataCache,$ilUser;
877 
878  $rcourses = ilUtil::_getObjectsByOperations('rcrs','visible',$ilUser->getId(),-1);
879 
880  // Read participants
881  include_once('./Modules/RemoteCourse/classes/class.ilObjRemoteCourse.php');
882  include_once('./Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
883  try
884  {
886  }
887  catch(ilECSConnectorException $e)
888  {
889  $reader = null;
890  }
891 
892  // read obj_ids
893  $ilObjDataCache->preloadReferenceCache($rcourses);
894  $obj_ids = array();
895  foreach($rcourses as $rcrs_ref_id)
896  {
897  $obj_id = $ilObjDataCache->lookupObjId($rcrs_ref_id);
898  $obj_ids[$obj_id] = $obj_id;
899  }
900 
901  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
902  $writer = new ilCSVWriter();
903 
904  $writer->addColumn($this->lng->txt('title'));
905  $writer->addColumn($this->lng->txt('description'));
906  $writer->addColumn($this->lng->txt('ecs_imported_from'));
907  $writer->addColumn($this->lng->txt('ecs_field_courseID'));
908  $writer->addColumn($this->lng->txt('ecs_field_term'));
909  $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
910  $writer->addColumn($this->lng->txt('ecs_field_courseType'));
911  $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
912  $writer->addColumn($this->lng->txt('ecs_field_credits'));
913  $writer->addColumn($this->lng->txt('ecs_field_room'));
914  $writer->addColumn($this->lng->txt('ecs_field_cycle'));
915  $writer->addColumn($this->lng->txt('ecs_field_begin'));
916  $writer->addColumn($this->lng->txt('ecs_field_end'));
917  $writer->addColumn($this->lng->txt('last_update'));
918 
919  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
921 
922  foreach($obj_ids as $obj_id)
923  {
924  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
925  $values = ilAdvancedMDValues::_getValuesByObjId($obj_id);
926 
927  $writer->addRow();
928  $writer->addColumn(ilObject::_lookupTitle($obj_id));
929  $writer->addColumn(ilObject::_lookupDescription($obj_id));
930 
931  $mid = ilObjRemoteCourse::_lookupMID($obj_id);
932  if($reader and ($participant = $reader->getParticipantByMID($mid)))
933  {
934  $writer->addColumn($participant->getParticipantName());
935  }
936  $field = $settings->getMappingByECSName('courseID');
937  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
938 
939  $field = $settings->getMappingByECSName('term');
940  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
941 
942  $field = $settings->getMappingByECSName('lecturer');
943  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
944 
945  $field = $settings->getMappingByECSName('courseType');
946  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
947 
948  $field = $settings->getMappingByECSName('semester_hours');
949  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
950 
951  $field = $settings->getMappingByECSName('credits');
952  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
953 
954  $field = $settings->getMappingByECSName('room');
955  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
956 
957  $field = $settings->getMappingByECSName('cycle');
958  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
959 
960  $field = $settings->getMappingByECSName('begin');
961  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
962 
963  $field = $settings->getMappingByECSName('end');
964  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
965 
966  $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
967  }
968  ilUtil::deliverData($writer->getCSVString(), date("Y_m_d")."_ecs_import.csv", "text/csv");
969  }
970 
977  protected function released()
978  {
979  global $ilUser;
980 
981  $this->tabs_gui->setSubTabActive('ecs_released');
982 
983  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
984  $exported = ilECSExport::_getExportedIDs();
985 
986  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_released.html','Services/WebServices/ECS');
987 
988  include_once './Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
989  $tb = new ilToolbarGUI();
990 
991  if(count($exported))
992  {
993  $tb->addButton(
994  $this->lng->txt('csv_export'),
995  $this->ctrl->getLinkTarget($this,'exportReleased')
996  );
997  }
998  if($this->settings->isEnabled())
999  {
1000  $tb->addButton(
1001  $this->lng->txt('ecs_read_remote_links'),
1002  $this->ctrl->getLinkTarget($this,'readAll')
1003  );
1004  }
1005  $this->tpl->setVariable('ACTION_BUTTONS',$tb->getHTML());
1006 
1007  include_once('Services/WebServices/ECS/classes/class.ilECSReleasedContentTableGUI.php');
1008  $table_gui = new ilECSReleasedContentTableGUI($this,'released');
1009 
1010  $table_gui->setTitle($this->lng->txt('ecs_released_content'));
1011  $table_gui->parse($exported);
1012  $this->tpl->setVariable('TABLE_REL',$table_gui->getHTML());
1013 
1014  return true;
1015 
1016  }
1017 
1024  protected function exportReleased()
1025  {
1026  global $ilObjDataCache;
1027 
1028  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
1029  $exported = ilECSExport::_getExportedIDs();
1030  $ilObjDataCache->preloadObjectCache($exported);
1031 
1032  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
1033  $writer = new ilCSVWriter();
1034 
1035  $writer->addColumn($this->lng->txt('title'));
1036  $writer->addColumn($this->lng->txt('description'));
1037  $writer->addColumn($this->lng->txt('ecs_field_courseID'));
1038  $writer->addColumn($this->lng->txt('ecs_field_term'));
1039  $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
1040  $writer->addColumn($this->lng->txt('ecs_field_courseType'));
1041  $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
1042  $writer->addColumn($this->lng->txt('ecs_field_credits'));
1043  $writer->addColumn($this->lng->txt('ecs_field_room'));
1044  $writer->addColumn($this->lng->txt('ecs_field_cycle'));
1045  $writer->addColumn($this->lng->txt('ecs_field_begin'));
1046  $writer->addColumn($this->lng->txt('ecs_field_end'));
1047  $writer->addColumn($this->lng->txt('last_update'));
1048 
1049  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1051 
1052  foreach($exported as $obj_id)
1053  {
1054  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1055  $values = ilAdvancedMDValues::_getValuesByObjId($obj_id);
1056 
1057  $writer->addRow();
1058  $writer->addColumn(ilObject::_lookupTitle($obj_id));
1059  $writer->addColumn(ilObject::_lookupDescription($obj_id));
1060 
1061  $field = $settings->getMappingByECSName('courseID');
1062  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1063 
1064  $field = $settings->getMappingByECSName('term');
1065  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1066 
1067  $field = $settings->getMappingByECSName('lecturer');
1068  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1069 
1070  $field = $settings->getMappingByECSName('courseType');
1071  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1072 
1073  $field = $settings->getMappingByECSName('semester_hours');
1074  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1075 
1076  $field = $settings->getMappingByECSName('credits');
1077  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1078 
1079  $field = $settings->getMappingByECSName('room');
1080  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1081 
1082  $field = $settings->getMappingByECSName('cycle');
1083  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1084 
1085  $field = $settings->getMappingByECSName('begin');
1086  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1087 
1088  $field = $settings->getMappingByECSName('end');
1089  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1090 
1091  $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
1092  }
1093 
1094  ilUtil::deliverData($writer->getCSVString(), date("Y_m_d")."_ecs_export.csv", "text/csv");
1095  }
1096 
1097 
1103  protected function prepareFieldSelection($fields)
1104  {
1105  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
1106 
1107  $options[0] = $this->lng->txt('ecs_ignore_field');
1108  foreach($fields as $field)
1109  {
1111  $title = ilAdvancedMDRecord::_lookupTitle($field->getRecordId());
1112  $options[$field->getFieldId()] = $title.': '.$field->getTitle();
1113  }
1114  return $options;
1115  }
1116 
1117 
1118 
1124  protected function initSettings()
1125  {
1126  include_once('Services/WebServices/ECS/classes/class.ilECSSettings.php');
1128  }
1129 
1135  protected function setSubTabs()
1136  {
1137  $this->tabs_gui->clearSubTabs();
1138 
1139  $this->tabs_gui->addSubTabTarget("ecs_settings",
1140  $this->ctrl->getLinkTarget($this,'settings'),
1141  "settings",get_class($this));
1142 
1143  // Disable all other tabs, if server hasn't been configured.
1144  if(!$this->settings->isEnabled())
1145  {
1146  return true;
1147  }
1148 
1149  $this->tabs_gui->addSubTabTarget("ecs_communities",
1150  $this->ctrl->getLinkTarget($this,'communities'),
1151  "communities",get_class($this));
1152 
1153  $this->tabs_gui->addSubTabTarget('ecs_mappings',
1154  $this->ctrl->getLinkTarget($this,'mappings'),
1155  'mappings',get_class($this));
1156 
1157  $this->tabs_gui->addSubTabTarget('ecs_category_mapping',
1158  $this->ctrl->getLinkTarget($this,'categoryMapping'));
1159 
1160  $this->tabs_gui->addSubTabTarget('ecs_import',
1161  $this->ctrl->getLinkTarget($this,'imported'));
1162 
1163  $this->tabs_gui->addSubTabTarget('ecs_released',
1164  $this->ctrl->getLinkTarget($this,'released'));
1165 
1166  }
1167 
1173  private function prepareRoleSelect()
1174  {
1175  global $rbacreview,$ilObjDataCache;
1176 
1177  $global_roles = ilUtil::_sortIds($rbacreview->getGlobalRoles(),
1178  'object_data',
1179  'title',
1180  'obj_id');
1181 
1182  $select[0] = $this->lng->txt('links_select_one');
1183  foreach($global_roles as $role_id)
1184  {
1185  $select[$role_id] = ilObject::_lookupTitle($role_id);
1186  }
1187  return $select;
1188  }
1189 
1190  private function buildPath($a_ref_id)
1191  {
1192  $loc = new ilLocatorGUI();
1193  $loc->setTextOnly(false);
1194  $loc->addContextItems($a_ref_id);
1195 
1196  return $loc->getHTML();
1197  }
1198 
1199 }
1200 
1201 ?>