ILIAS  Release_4_2_x_branch Revision 61807
 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 
24 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
25 
36 {
37  const MAPPING_EXPORT = 1;
38  const MAPPING_IMPORT = 2;
39 
40 
41  protected $tpl;
42  protected $lng;
43  protected $ctrl;
44  protected $tabs_gui;
45 
46 
52  public function __construct()
53  {
54  global $lng,$tpl,$ilCtrl,$ilTabs;
55 
56  $this->tpl = $tpl;
57  $this->lng = $lng;
58  $this->lng->loadLanguageModule('ecs');
59  $this->ctrl = $ilCtrl;
60  $this->tabs_gui = $ilTabs;
61 
62  $this->initSettings();
63  }
64 
72  public function executeCommand()
73  {
74  $next_class = $this->ctrl->getNextClass($this);
75  $cmd = $this->ctrl->getCmd();
76 
77  $this->setSubTabs();
78  switch($next_class)
79  {
80  case 'ilecsmappingsettingsgui':
81  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingSettingsGUI.php';
82  $mapset = new ilECSMappingSettingsGUI($this, (int) $_REQUEST['server_id']);
83  $this->ctrl->setReturn($this,'communities');
84  $this->ctrl->forwardCommand($mapset);
85  break;
86 
87  default:
88  if(!$cmd)
89  {
90  $cmd = "overview";
91  }
92  $this->$cmd();
93  break;
94  }
95  return true;
96  }
97 
104  public function overview()
105  {
106  global $ilToolbar,$ilTabs;
107 
108  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
109 
110  $ilTabs->setSubTabActive('overview');
111  $ilToolbar->addButton(
112  $this->lng->txt('ecs_add_new_ecs'),
113  $this->ctrl->getLinkTarget($this,'create')
114  );
115 
117  $servers->readInactiveServers();
118 
119  include_once './Services/WebServices/ECS/classes/class.ilECSServerTableGUI.php';
120  $table = new ilECSServerTableGUI($this,'overview');
121  $table->initTable();
122  $table->parse($servers);
123  $this->tpl->setContent($table->getHTML());
124  return;
125  }
126 
130  protected function activate()
131  {
132  $this->initSettings($_REQUEST['server_id']);
133  $this->settings->setEnabledStatus(true);
134  $this->settings->update();
135  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
136  $this->ctrl->redirect($this,'overview');
137  }
138 
142  protected function deactivate()
143  {
144  $this->initSettings($_REQUEST['server_id']);
145  $this->settings->setEnabledStatus(false);
146  $this->settings->update();
147  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
148  $this->ctrl->redirect($this,'overview');
149  }
150 
156  protected function readAll()
157  {
158  include_once('Services/WebServices/ECS/classes/class.ilECSConnector.php');
159  include_once('Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
160  include_once('./Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php');
161  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
162 
163  try
164  {
165  foreach(ilECSServerSettings::getInstance()->getServers() as $server)
166  {
169 
170  include_once('./Services/WebServices/ECS/classes/class.ilECSTaskScheduler.php');
171  ilECSTaskScheduler::_getInstanceByServerId($server->getServerId())->startTaskExecution();
172 
173  ilUtil::sendInfo($this->lng->txt('ecs_remote_imported'));
174  $this->imported();
175  return true;
176  }
177  }
178  catch(ilECSConnectorException $e1)
179  {
180  ilUtil::sendInfo('Cannot connect to ECS server: '.$e1->getMessage());
181  $this->imported();
182  return false;
183  }
184  catch(ilException $e2)
185  {
186  ilUtil::sendInfo('Update failed: '.$e1->getMessage());
187  $this->imported();
188  return false;
189  }
190  }
191 
196  protected function create()
197  {
198  global $ilTabs;
199 
200  $this->initSettings(0);
201 
202  $ilTabs->clearTargets();
203  $ilTabs->clearSubTabs();
204  $ilTabs->setBackTarget($this->lng->txt('back'),$this->ctrl->getLinkTarget($this,'overview'));
205 
206  $this->initSettingsForm('create');
207  $this->tabs_gui->setSubTabActive('ecs_settings');
208 
209  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_settings.html','Services/WebServices/ECS');
210  $this->tpl->setVariable('SETTINGS_TABLE',$this->form->getHTML());
211  }
212 
216  protected function edit()
217  {
218  global $ilTabs;
219 
220  $this->initSettings((int) $_REQUEST['server_id']);
221  $this->ctrl->saveParameter($this,'server_id',(int) $_REQUEST['server_id']);
222 
223  $ilTabs->clearTargets();
224  $ilTabs->clearSubTabs();
225  $ilTabs->setBackTarget($this->lng->txt('back'),$this->ctrl->getLinkTarget($this,'overview'));
226 
227  $this->initSettingsForm();
228  $this->tabs_gui->setSubTabActive('ecs_settings');
229 
230  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_settings.html','Services/WebServices/ECS');
231  $this->tpl->setVariable('SETTINGS_TABLE',$this->form->getHTML());
232  }
233 
234  protected function cp()
235  {
236  $this->initSettings((int) $_REQUEST['server_id']);
237 
238  $copy = clone $this->settings;
239  $copy->save();
240 
241  $this->ctrl->setParameter($this,'server_id',$copy->getServerId());
242  ilUtil::sendSuccess($this->lng->txt('ecs_settings_cloned'),true);
243  $this->ctrl->redirect($this,'edit');
244  }
245 
249  protected function delete()
250  {
251  global $ilTabs;
252 
253  $this->initSettings((int) $_REQUEST['server_id']);
254 
255  $ilTabs->clearTargets();
256  $ilTabs->clearSubTabs();
257  $ilTabs->setBackTarget($this->lng->txt('back'),$this->ctrl->getLinkTarget($this,'overview'));
258 
259  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
260  $confirm = new ilConfirmationGUI();
261  $confirm->setFormAction($this->ctrl->getFormAction($this));
262  $confirm->setConfirm($this->lng->txt('delete'), 'doDelete');
263  $confirm->setCancel($this->lng->txt('cancel'), 'overview');
264  $confirm->setHeaderText($this->lng->txt('ecs_delete_setting'));
265 
266  $confirm->addItem('','',$this->settings->getServer());
267  $confirm->addHiddenItem('server_id', $this->settings->getServerId());
268 
269  $this->tpl->setContent($confirm->getHTML());
270  }
271 
275  protected function doDelete()
276  {
277  $this->initSettings($_REQUEST['server_id']);
278  $this->settings->delete();
279 
280  // Delete communities
281  include_once './Services/WebServices/ECS/classes/class.ilECSCommunitiesCache.php';
282  ilECSCommunitiesCache::delete((int) $_REQUEST['server_id']);
283 
284  include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php';
285  ilECSDataMappingSettings::delete((int) $_REQUEST['server_id']);
286 
287  include_once './Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php';
288  ilECSEventQueueReader::deleteServer((int) $_REQUEST['server_id']);
289 
290  include_once './Services/WebServices/ECS/classes/class.ilECSExport.php';
291  ilECSExport::deleteByServer((int) $_REQUEST['server_id']);
292 
293  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
294  ilECSImport::deleteByServer((int) $_REQUEST['server_id']);
295 
296  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
297  ilECSParticipantSettings::deleteByServer((int) $_REQUEST['server_id']);
298 
299  ilUtil::sendSuccess($this->lng->txt('ecs_setting_deleted'),true);
300  $this->ctrl->redirect($this,'overview');
301  }
302 
303 
309  protected function settings()
310  {
311  $this->initSettingsForm();
312  $this->tabs_gui->setSubTabActive('ecs_settings');
313 
314  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_settings.html','Services/WebServices/ECS');
315  $this->tpl->setVariable('SETTINGS_TABLE',$this->form->getHTML());
316  }
317 
323  protected function initSettingsForm($a_mode = 'update')
324  {
325  if(is_object($this->form))
326  {
327  return true;
328  }
329  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
330 
331  $this->form = new ilPropertyFormGUI();
332  $this->form->setFormAction($this->ctrl->getFormAction($this,'settings'));
333  $this->form->setTitle($this->lng->txt('ecs_connection_settings'));
334 
335  $ena = new ilCheckboxInputGUI($this->lng->txt('ecs_active'),'active');
336  $ena->setChecked($this->settings->isEnabled());
337  $ena->setValue(1);
338  $this->form->addItem($ena);
339 
340  $ser = new ilTextInputGUI($this->lng->txt('ecs_server_url'),'server');
341  $ser->setValue((string) $this->settings->getServer());
342  $ser->setRequired(true);
343  $this->form->addItem($ser);
344 
345  $pro = new ilSelectInputGUI($this->lng->txt('ecs_protocol'),'protocol');
346  // fixed to https
347  #$pro->setOptions(array(ilECSSetting::PROTOCOL_HTTP => $this->lng->txt('http'),
348  # ilECSSetting::PROTOCOL_HTTPS => $this->lng->txt('https')));
349  $pro->setOptions(array(ilECSSetting::PROTOCOL_HTTPS => 'HTTPS'));
350  $pro->setValue($this->settings->getProtocol());
351  $pro->setRequired(true);
352  $this->form->addItem($pro);
353 
354  $por = new ilTextInputGUI($this->lng->txt('ecs_port'),'port');
355  $por->setSize(5);
356  $por->setMaxLength(5);
357  $por->setValue((string) $this->settings->getPort());
358  $por->setRequired(true);
359  $this->form->addItem($por);
360 
361  $tcer = new ilRadioGroupInputGUI($this->lng->txt('ecs_auth_type'),'auth_type');
362  $tcer->setValue($this->settings->getAuthType());
363  $this->form->addItem($tcer);
364 
365  // Certificate based authentication
366  $cert_based = new ilRadioOption($this->lng->txt('ecs_auth_type_cert'), ilECSSetting::AUTH_CERTIFICATE);
367  $tcer->addOption($cert_based);
368 
369  $cli = new ilTextInputGUI($this->lng->txt('ecs_client_cert'),'client_cert');
370  $cli->setSize(60);
371  $cli->setValue((string) $this->settings->getClientCertPath());
372  $cli->setRequired(true);
373  $cert_based->addSubItem($cli);
374 
375  $key = new ilTextInputGUI($this->lng->txt('ecs_cert_key'),'key_path');
376  $key->setSize(60);
377  $key->setValue((string) $this->settings->getKeyPath());
378  $key->setRequired(true);
379  $cert_based->addSubItem($key);
380 
381  $cerp = new ilTextInputGUI($this->lng->txt('ecs_key_password'),'key_password');
382  $cerp->setSize(12);
383  $cerp->setValue((string) $this->settings->getKeyPassword());
384  $cerp->setInputType('password');
385  $cerp->setRequired(true);
386  $cert_based->addSubItem($cerp);
387 
388  $cer = new ilTextInputGUI($this->lng->txt('ecs_ca_cert'),'ca_cert');
389  $cer->setSize(60);
390  $cer->setValue((string) $this->settings->getCACertPath());
391  $cer->setRequired(true);
392  $cert_based->addSubItem($cer);
393 
394  // Apache auth
395  $apa_based = new ilRadioOption($this->lng->txt('ecs_auth_type_apache'), ilECSSetting::AUTH_APACHE);
396  $tcer->addOption($apa_based);
397 
398  $user = new ilTextInputGUI($this->lng->txt('ecs_apache_user'),'auth_user');
399  $user->setSize(32);
400  $user->setValue((string) $this->settings->getAuthUser());
401  $user->setRequired(true);
402  $apa_based->addSubItem($user);
403 
404  $pass = new ilPasswordInputGUI($this->lng->txt('ecs_apache_pass'), 'auth_pass');
405  $pass->setRetype(false);
406  $pass->setSize(16);
407  $pass->setMaxLength(32);
408  $pass->setValue((string) $this->settings->getAuthPass());
409  $pass->setRequired(true);
410  $apa_based->addSubItem($pass);
411 
412 
413  $ser = new ilNonEditableValueGUI($this->lng->txt('cert_serial'));
414  $ser->setValue($this->settings->getCertSerialNumber() ? $this->settings->getCertSerialNumber() : $this->lng->txt('ecs_no_value'));
415  $cert_based->addSubItem($ser);
416 
417  $loc = new ilFormSectionHeaderGUI();
418  $loc->setTitle($this->lng->txt('ecs_local_settings'));
419  $this->form->addItem($loc);
420 
421  $pol = new ilDurationInputGUI($this->lng->txt('ecs_polling'),'polling');
422  $pol->setShowDays(false);
423  $pol->setShowHours(false);
424  $pol->setShowMinutes(true);
425  $pol->setShowSeconds(true);
426  $pol->setSeconds($this->settings->getPollingTimeSeconds());
427  $pol->setMinutes($this->settings->getPollingTimeMinutes());
428  $pol->setRequired(true);
429  $pol->setInfo($this->lng->txt('ecs_polling_info'));
430  $this->form->addItem($pol);
431 
432  $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'));
433  $imp->setRequired(true);
434 
435  $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
436  $tpl->setVariable('SIZE',5);
437  $tpl->setVariable('MAXLENGTH',11);
438  $tpl->setVariable('POST_VAR','import_id');
439  $tpl->setVariable('PROPERTY_VALUE',$this->settings->getImportId());
440 
441  if($this->settings->getImportId())
442  {
443  $tpl->setVariable('COMPLETE_PATH',$this->buildPath($this->settings->getImportId()));
444  }
445 
446  $imp->setHTML($tpl->get());
447  $imp->setInfo($this->lng->txt('ecs_import_id_info'));
448  $this->form->addItem($imp);
449 
450  $loc = new ilFormSectionHeaderGUI();
451  $loc->setTitle($this->lng->txt('ecs_remote_user_settings'));
452  $this->form->addItem($loc);
453 
454  $role = new ilSelectInputGUI($this->lng->txt('ecs_role'),'global_role');
455  $role->setOptions($this->prepareRoleSelect());
456  $role->setValue($this->settings->getGlobalRole());
457  $role->setInfo($this->lng->txt('ecs_global_role_info'));
458  $role->setRequired(true);
459  $this->form->addItem($role);
460 
461  $duration = new ilDurationInputGUI($this->lng->txt('ecs_account_duration'),'duration');
462  $duration->setInfo($this->lng->txt('ecs_account_duration_info'));
463  $duration->setMonths($this->settings->getDuration());
464  $duration->setShowSeconds(false);
465  $duration->setShowMinutes(false);
466  $duration->setShowHours(false);
467  $duration->setShowDays(false);
468  $duration->setShowMonths(true);
469  $duration->setRequired(true);
470  $this->form->addItem($duration);
471 
472  // Email recipients
473  $loc = new ilFormSectionHeaderGUI();
474  $loc->setTitle($this->lng->txt('ecs_notifications'));
475  $this->form->addItem($loc);
476 
477  $rcp_user = new ilTextInputGUI($this->lng->txt('ecs_user_rcp'),'user_recipients');
478  $rcp_user->setValue((string) $this->settings->getUserRecipientsAsString());
479  $rcp_user->setInfo($this->lng->txt('ecs_user_rcp_info'));
480  $this->form->addItem($rcp_user);
481 
482  $rcp_econ = new ilTextInputGUI($this->lng->txt('ecs_econ_rcp'),'econtent_recipients');
483  $rcp_econ->setValue((string) $this->settings->getEContentRecipientsAsString());
484  $rcp_econ->setInfo($this->lng->txt('ecs_econ_rcp_info'));
485  $this->form->addItem($rcp_econ);
486 
487  $rcp_app = new ilTextInputGUI($this->lng->txt('ecs_approval_rcp'),'approval_recipients');
488  $rcp_app->setValue((string) $this->settings->getApprovalRecipientsAsString());
489  $rcp_app->setInfo($this->lng->txt('ecs_approval_rcp_info'));
490  $this->form->addItem($rcp_app);
491 
492  if($a_mode == 'update')
493  {
494  $this->form->addCommandButton('update',$this->lng->txt('save'));
495  }
496  else
497  {
498  $this->form->addCommandButton('save',$this->lng->txt('save'));
499  }
500  $this->form->addCommandButton('overview',$this->lng->txt('cancel'));
501  }
502 
508  protected function update()
509  {
510  $this->initSettings((int) $_REQUEST['server_id']);
511  $this->loadFromPost();
512 
513  if(!$error = $this->settings->validate())
514  {
515  $this->settings->update();
516  $this->initTaskScheduler();
517  $this->updateTitle();
518  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
519  }
520  else
521  {
522  ilUtil::sendInfo($this->lng->txt($error));
523  $this->edit();
524  }
525 
526  $this->overview();
527  return true;
528  }
529 
534  protected function save()
535  {
536  $this->initSettings(0);
537  $this->loadFromPost();
538 
539  if(!$error = $this->settings->validate())
540  {
541  $this->settings->save();
542  $this->initTaskScheduler();
543 
544  $this->updateTitle();
545  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
546  }
547  else
548  {
549  ilUtil::sendInfo($this->lng->txt($error));
550  $this->create();
551  }
552  $this->overview();
553  return true;
554  }
555 
559  protected function updateTitle()
560  {
561  try
562  {
563  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
565 
566  foreach($reader->getCommunities() as $community)
567  {
568  foreach($community->getParticipants() as $part)
569  {
570  if($part->isSelf())
571  {
572  $this->settings->setTitle($part->getParticipantName());
573  $this->settings->update();
574  return true;
575  }
576  }
577  }
578  }
579  catch(ilECSConnectorException $exc)
580  {
581  ilUtil::sendFailure($exc->getMessage());
582  }
583  $this->settings->setTitle('');
584  $this->settings->update();
585  }
586 
590  protected function loadFromPost()
591  {
592  $this->settings->setEnabledStatus((int) $_POST['active']);
593  //$this->settings->setTitle(ilUtil::stripSlashes($_POST['title']));
594  $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
595  $this->settings->setPort(ilUtil::stripSlashes($_POST['port']));
596  $this->settings->setProtocol(ilUtil::stripSlashes($_POST['protocol']));
597  $this->settings->setClientCertPath(ilUtil::stripSlashes($_POST['client_cert']));
598  $this->settings->setCACertPath(ilUtil::stripSlashes($_POST['ca_cert']));
599  $this->settings->setKeyPath(ilUtil::stripSlashes($_POST['key_path']));
600  $this->settings->setKeyPassword(ilUtil::stripSlashes($_POST['key_password']));
601  $this->settings->setImportId(ilUtil::stripSlashes($_POST['import_id']));
602  $this->settings->setPollingTimeMS((int) $_POST['polling']['mm'],(int) $_POST['polling']['ss']);
603  $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
604  $this->settings->setGlobalRole((int) $_POST['global_role']);
605  $this->settings->setDuration((int) $_POST['duration']['MM']);
606 
607  $this->settings->setUserRecipients(ilUtil::stripSlashes($_POST['user_recipients']));
608  $this->settings->setEContentRecipients(ilUtil::stripSlashes($_POST['econtent_recipients']));
609  $this->settings->setApprovalRecipients(ilUtil::stripSlashes($_POST['approval_recipients']));
610 
611  $this->settings->setAuthType((int) $_POST['auth_type']);
612  $this->settings->setAuthPass(ilUtil::stripSlashes($_POST['auth_pass']));
613  $this->settings->setAuthUser(ilUtil::stripSlashes($_POST['auth_user']));
614 
615  }
616 
623  public function communities()
624  {
625  $this->tabs_gui->setSubTabActive('ecs_communities');
626 
627  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_communities.html','Services/WebServices/ECS');
628 
629  $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this,'updateCommunities'));
630  $this->tpl->setVariable('TXT_SAVE',$this->lng->txt('save'));
631  $this->tpl->setVariable('TXT_CANCEL', $this->lng->txt('cancel'));
632 
633  include_once('Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
634  include_once('Services/WebServices/ECS/classes/class.ilECSCommunityTableGUI.php');
635 
636  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
637  $settings = ilECSServerSettings::getInstance();
638  $settings->readInactiveServers();
639 
640  foreach($settings->getServers() as $server)
641  {
642  // Try to read communities
643  try
644  {
646  foreach($reader->getCommunities() as $community)
647  {
648  $this->tpl->setCurrentBlock('table_community');
649  $table_gui = new ilECSCommunityTableGUI($server,$this,'communities',$community->getId());
650  $table_gui->setTitle($community->getTitle().' ('.$community->getDescription().')');
651  $table_gui->parse($community->getParticipants());
652  $this->tpl->setVariable('TABLE_COMM',$table_gui->getHTML());
653  $this->tpl->parseCurrentBlock();
654  }
655  }
656  catch(ilECSConnectorException $exc)
657  {
658  // Maybe server is not fully configured
659  continue;
660  }
661 
662  // Show section for each server
663  $this->tpl->setCurrentBlock('server');
664  $this->tpl->setVariable('TXT_SERVER_NAME',$server->getTitle());
665  $this->tpl->parseCurrentBlock();
666  }
667  }
668 
674  protected function validateImportTypes(&$import_types)
675  {
676  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
677 
678  $num_cms = 0;
679  foreach((array) $import_types as $sid => $server)
680  {
681  foreach((array) $server as $mid => $import_type)
682  {
683  if($import_type == ilECSParticipantSetting::IMPORT_CMS)
684  {
685  ++$num_cms;
686  }
687  }
688  }
689 
690  if($num_cms <= 1)
691  {
692  return true;
693  }
694  // Change to import type "UNCHANGED"
695  $new_types = array();
696  foreach((array) $import_types as $sid => $server)
697  {
698  foreach((array) $server as $mid => $import_type)
699  {
700  if($import_type == ilECSParticipantSetting::IMPORT_CMS)
701  {
702  $new_types[$sid][$mid] = ilECSParticipantSetting::IMPORT_UNCHANGED;
703  }
704  else
705  {
706  $new_types[$sid][$mid] = $import_type;
707  }
708  }
709  }
710  $import_types = $new_types;
711  return false;
712  }
713 
720  protected function updateCommunities()
721  {
722  global $ilLog;
723 
724  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
725  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
726 
727  // @TODO: Delete deprecated communities
728  $invalidImportTypes = false;
729  if(!$this->validateImportTypes($_POST['import_type']))
730  {
731  $invalidImportTypes = true;
732  }
733 
735  foreach($servers->getServers() as $server)
736  {
737  try {
738  // Read communities
739  $cReader = ilECSCommunityReader::getInstanceByServerId($server->getServerId());
740 
741  // Update community cache
742  foreach($cReader->getCommunities() as $community)
743  {
744  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityCache.php';
745  $cCache = ilECSCommunityCache::getInstance($server->getServerId(), $community->getId());
746  $cCache->setCommunityName($community->getTitle());
747  $cCache->setMids($community->getMids());
748  $cCache->setOwnId($community->getOwnId());
749  $cCache->update();
750  }
751  }
752  catch(Exception $e)
753  {
754  $GLOBALS['ilLog']->write(__METHOD__.': Cannot read ecs communities: '.$e->getMessage());
755  }
756  }
757 
758  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
759  foreach((array) $_POST['sci_mid'] as $sid => $tmp)
760  {
761  foreach((array) $_POST['sci_mid'][$sid] as $mid => $tmp)
762  {
763  $set = new ilECSParticipantSetting($sid, $mid);
764  $set->enableExport(array_key_exists($mid, (array) $_POST['export'][$sid]) ? true : false);
765  $set->enableImport(array_key_exists($mid, (array) $_POST['import'][$sid]) ? true : false);
766  $set->setImportType($_POST['import_type'][$sid][$mid]);
767 
768  // update title/cname
769  try {
770  $part = ilECSCommunityReader::getInstanceByServerId($sid)->getParticipantByMID($mid);
771  if($part instanceof ilECSParticipant)
772  {
773  $set->setTitle($part->getParticipantName());
774  }
775  $com = ilECSCommunityReader::getInstanceByServerId($sid)->getCommunityByMID($mid);
776  if($com instanceof ilECSCommunity)
777  {
778  $set->setCommunityName($com->getTitle());
779  }
780  }
781  catch(Exception $e)
782  {
783  $GLOBALS['ilLog']->write(__METHOD__.': Cannot read ecs communities: '.$e->getMessage());
784  }
785 
786  $set->update();
787  }
788  }
789  if($invalidImportTypes)
790  {
791  ilUtil::sendFailure($this->lng->txt('ecs_invalid_import_type_cms'),true);
792  }
793  else
794  {
795  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
796  }
797  $GLOBALS['ilCtrl']->redirect($this,'communities');
798 
799  // TODO: Do update of remote courses and ...
800 
801  return true;
802 
803  /*
804  $mids = $_POST['mid'] ? $_POST['mid'] : array();
805 
806  include_once('./Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php');
807  $part = ilECSParticipantSettings::_getInstance();
808 
809  foreach($part->getEnabledParticipants() as $mid)
810  {
811  if(!in_array($mid,$mids))
812  {
813  // Delete all remote courses
814  include_once('./Modules/RemoteCourse/classes/class.ilObjRemoteCourse.php');
815  #foreach(ilObjRemoteCourse::_lookupObjIdsByMID($mid) as $obj_id)
816  {
817  foreach(ilObject::_getAllReferences($obj_id) as $ref_id)
818  {
819  $to_delete = ilObjectFactory::getInstanceByRefId($ref_id,false);
820  $to_delete->delete();
821  }
822  }
823  }
824  }
825  */
826 
827  /*
828  try
829  {
830  // Update all exported econtent
831  include_once('./Services/WebServices/ECS/classes/class.ilECSEContentReader.php');
832  include_once('./Services/WebServices/ECS/classes/class.ilECSConnector.php');
833  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
834  $reader = new ilECSEContentReader();
835  $reader->read();
836  $all_content = $reader->getEContent();
837 
838  // read update events
839  foreach($all_content as $content)
840  {
841  if(ilECSExport::_isRemote($content->getEContentId()))
842  {
843  $ilLog->write(__METHOD__.': Ignoring remote EContent: '.$content->getTitle());
844  // Do not handle remote courses.
845  continue;
846  }
847  $members = array_intersect($mids,$content->getEligibleMembers());
848  if(!$members)
849  {
850  $ilLog->write(__METHOD__.': Deleting EContent: '.$content->getTitle());
851  $connector = new ilECSConnector();
852  $connector->deleteResource($content->getEContentId());
853 
854  ilECSExport::_deleteEContentIds(array($content->getEContentId()));
855  }
856  elseif(count($members) != count($content->getEligibleMembers()))
857  {
858  $ilLog->write(__METHOD__.': Update eligible members for EContent: '.$content->getTitle());
859  $content->setEligibleMembers($members);
860  $connector = new ilECSConnector();
861  $connector->updateResource($content->getEContentId(),json_encode($content));
862  }
863  }
864  }
865  catch(ilECSConnectorException $e)
866  {
867  ilUtil::sendInfo('Cannot connect to ECS server: '.$e->getMessage());
868  $this->communities();
869  return false;
870  }
871  catch(ilException $e)
872  {
873  ilUtil::sendInfo('Update failed: '.$e->getMessage());
874  $this->communities();
875  return false;
876  }
877 
878  */
879  return true;
880  }
881 
882 
888  protected function setMappingTabs($a_active)
889  {
890  global $ilTabs;
891 
892  $ilTabs->clearTargets();
893  $ilTabs->clearSubTabs();
894 
895  $ilTabs->setBackTarget(
896  $this->lng->txt('ecs_settings'),
897  $this->ctrl->getLinkTarget($this,'overview')
898  );
899  $ilTabs->addTab(
900  'import',
901  $this->lng->txt('ecs_tab_import'),
902  $this->ctrl->getLinkTarget($this,'importMappings')
903  );
904  $ilTabs->addTab(
905  'export',
906  $this->lng->txt('ecs_tab_export'),
907  $this->ctrl->getLinkTarget($this,'exportMappings')
908  );
909 
910 
911  switch($a_active)
912  {
913  case self::MAPPING_IMPORT:
914  $ilTabs->activateTab('import');
915  break;
916 
917  case self::MAPPING_EXPORT:
918  $ilTabs->activateTab('export');
919  break;
920  }
921  return true;
922  }
923 
929  public function importMappings()
930  {
931  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
932 
933  $this->setMappingTabs(self::MAPPING_IMPORT);
934 
936  if(!count($fields))
937  {
938  ilUtil::sendInfo($this->lng->txt('ecs_no_adv_md'));
939  return true;
940  }
941 
942  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
943  $settings = ilECSServerSettings::getInstance();
944  $settings->readInactiveServers();
945 
946  include_once './Services/Accordion/classes/class.ilAccordionGUI.php';
947  $acc = new ilAccordionGUI();
948 
949  // Iterate all servers
950  foreach($settings->getServers() as $server)
951  {
952  $acc->setOrientation(ilAccordionGUI::FIRST_OPEN);
953  $acc->setId('ecs_mapping_import_'.$server->getServerId());
954 
955  $form = $this->initMappingsForm($server->getServerId(),self::MAPPING_IMPORT);
956 
957  $acc->addItem(
958  $server->getTitle() ? $server->getTitle() : 'ECS',
959  '<br />'.$form->getHTML().'<br />'
960  );
961  }
962 
963  if($acc instanceof ilAccordionGUI)
964  {
965  $this->tpl->setContent($acc->getHTML());
966  }
967  return true;
968  }
969 
975  protected function exportMappings()
976  {
977  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
978 
979  $this->setMappingTabs(self::MAPPING_EXPORT);
980 
982  if(!count($fields))
983  {
984  ilUtil::sendInfo($this->lng->txt('ecs_no_adv_md'));
985  return true;
986  }
987 
988  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
989  $settings = ilECSServerSettings::getInstance();
990  $settings->readInactiveServers();
991 
992  include_once './Services/Accordion/classes/class.ilAccordionGUI.php';
993  $acc = new ilAccordionGUI();
994 
995  // Iterate all servers
996  foreach($settings->getServers() as $server)
997  {
998  $acc->setOrientation(ilAccordionGUI::FIRST_OPEN);
999  $acc->setId('ecs_mapping_import_'.$server->getServerId());
1000 
1001  $form = $this->initMappingsForm($server->getServerId(),self::MAPPING_EXPORT);
1002 
1003  $acc->addItem(
1004  $server->getTitle() ? $server->getTitle() : 'ECS',
1005  '<br />'.$form->getHTML().'<br />'
1006  );
1007  }
1008 
1009  if($acc instanceof ilAccordionGUI)
1010  {
1011  $this->tpl->setContent($acc->getHTML());
1012  }
1013  return true;
1014  }
1015 
1022  protected function saveImportMappings()
1023  {
1024  foreach((array) $_POST['mapping'] as $mtype => $mappings)
1025  {
1026  foreach((array) $mappings as $ecs_field => $advmd_id)
1027  {
1028  include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSetting.php';
1029  $map = new ilECSDataMappingSetting(
1030  (int) $_POST['ecs_mapping_server'],
1031  (int) $mtype,
1032  $ecs_field
1033  );
1034  $map->setAdvMDId($advmd_id);
1035  $map->save();
1036  }
1037  }
1038 
1039  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
1040  $this->ctrl->redirect($this,'importMappings');
1041  return true;
1042  }
1043 
1050  protected function saveExportMappings()
1051  {
1052  foreach((array) $_POST['mapping'] as $mtype => $mappings)
1053  {
1054  foreach((array) $mappings as $ecs_field => $advmd_id)
1055  {
1056  include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSetting.php';
1057  $map = new ilECSDataMappingSetting(
1058  (int) $_POST['ecs_mapping_server'],
1059  (int) $mtype,
1060  $ecs_field
1061  );
1062  $map->setAdvMDId($advmd_id);
1063  $map->save();
1064  }
1065  }
1066 
1067  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
1068  $this->ctrl->redirect($this,'exportMappings');
1069  return true;
1070  }
1071 
1080  protected function initMappingsForm($a_server_id,$mapping_type)
1081  {
1082  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
1083 
1084 
1085  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1086  $mapping_settings = ilECSDataMappingSettings::getInstanceByServerId($a_server_id);
1087 
1088  $form = new ilPropertyFormGUI();
1089 
1090  if($mapping_type == self::MAPPING_IMPORT)
1091  {
1092  $form->setTitle($this->lng->txt('ecs_mapping_tbl'));
1093  $form->addCommandButton('saveImportMappings',$this->lng->txt('save'));
1094  $form->addCommandButton('importMappings',$this->lng->txt('cancel'));
1095  }
1096  else
1097  {
1098  $form->setTitle($this->lng->txt('ecs_mapping_exp_tbl'));
1099  $form->addCommandButton('saveExportMappings',$this->lng->txt('save'));
1100  $form->addCommandButton('exportMappings',$this->lng->txt('cancel'));
1101  }
1102 
1103  $form->setFormAction($this->ctrl->getFormAction($this,'saveMappings'));
1104 
1105  if($mapping_type == self::MAPPING_IMPORT)
1106  {
1107  $assignments = new ilCheckboxGroupInputGUI('', 'mapping_type');
1108  $form->addItem($assignments);
1109 
1110  $option = new ilCheckboxInputGUI($this->lng->txt('ecs_mapping_crs'), 'mapping_type');
1112 
1113  $assignments->addOption($option);
1114  }
1115 
1116  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1118  $options = $this->prepareFieldSelection($fields);
1119 
1120  // get all optional ecourse fields
1121  include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
1123  foreach($optional as $field_name)
1124  {
1125  if($mapping_type == self::MAPPING_IMPORT)
1126  {
1127  $select = new ilSelectInputGUI(
1128  $this->lng->txt('ecs_field_'.$field_name),
1129  'mapping'.'['.ilECSDataMappingSetting::MAPPING_IMPORT_CRS.']['.$field_name.']'
1130  );
1131 
1132  $select->setValue(
1133  $mapping_settings->getMappingByECSName(
1135  $field_name)
1136  );
1137  $select->setOptions($options);
1138  $option->addSubItem($select);
1139  }
1140  else
1141  {
1142  $select = new ilSelectInputGUI(
1143  $this->lng->txt('ecs_field_'.$field_name),
1144  'mapping'.'['.ilECSDataMappingSetting::MAPPING_EXPORT.']['.$field_name.']'
1145  );
1146  $select->setValue(
1147  $mapping_settings->getMappingByECSName(
1149  $field_name)
1150  );
1151  $select->setOptions($options);
1152  $form->addItem($select);
1153  }
1154  }
1155 
1156  $server = new ilHiddenInputGUI('ecs_mapping_server');
1157  $server->setValue($a_server_id);
1158  $form->addItem($server);
1159 
1160  // Remote courses
1161  // no remote course settings for export
1162  if($mapping_type == self::MAPPING_EXPORT)
1163  {
1164  return $form;
1165  }
1166 
1167  $rcrs = new ilCheckboxInputGUI($this->lng->txt('ecs_mapping_rcrs'), 'mapping_type');
1169 
1170  $assignments->addOption($rcrs);
1171 
1172  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1174  $options = $this->prepareFieldSelection($fields);
1175 
1176  // get all optional econtent fields
1177  include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
1179  foreach($optional as $field_name)
1180  {
1181  $select = new ilSelectInputGUI(
1182  $this->lng->txt('ecs_field_'.$field_name),
1183  'mapping['.ilECSDataMappingSetting::MAPPING_IMPORT_RCRS.']['.$field_name.']');
1184  $select->setValue(
1185  $mapping_settings->getMappingByECSName(
1187  $field_name)
1188  );
1189  $select->setOptions($options);
1190  $rcrs->addSubItem($select);
1191  }
1192  return $form;
1193  }
1194 
1199  protected function categoryMapping()
1200  {
1201  $this->tabs_gui->setSubTabActive('ecs_category_mapping');
1202  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.category_mapping.html','Services/WebServices/ECS');
1203 
1204  $this->initRule();
1205  $this->initCategoryMappingForm();
1206 
1207 
1208  $this->tpl->setVariable('NEW_RULE_TABLE',$this->form->getHTML());
1209  if($html = $this->showRulesTable())
1210  {
1211  $this->tpl->setVariable('RULES_TABLE',$html);
1212  }
1213  }
1214 
1219  protected function addCategoryMapping()
1220  {
1221  $this->initRule();
1222 
1223  $this->initCategoryMappingForm('add');
1224  if($this->form->checkInput())
1225  {
1226  $this->rule->setContainerId($this->form->getInput('import_id'));
1227  $this->rule->setMappingType($this->form->getInput('type'));
1228  $this->rule->setMappingValue($this->form->getInput('mapping_value'));
1229  $this->rule->setFieldName($this->form->getInput('field'));
1230  $this->rule->setDateRangeStart($this->form->getItemByPostVar('dur_begin')->getDate());
1231  $this->rule->setDateRangeEnd($this->form->getItemByPostVar('dur_end')->getDate());
1232 
1233  if($err = $this->rule->validate())
1234  {
1235  ilUtil::sendInfo($this->lng->txt($err));
1236  $this->form->setValuesByPost();
1237  $this->categoryMapping();
1238  return false;
1239  }
1240  $this->rule->save();
1241  ilUtil::sendInfo($this->lng->txt('settings_saved'));
1242  unset($this->rule);
1243  $this->categoryMapping();
1244  return true;
1245  }
1246  ilUtil::sendInfo($this->lng->txt('err_check_input'));
1247  $this->form->setValuesByPost();
1248  $this->categoryMapping();
1249  return false;
1250  }
1251 
1256  protected function editCategoryMapping()
1257  {
1258  if(!$_REQUEST['rule_id'])
1259  {
1260  ilUtil::sendInfo($this->lng->txt('select_one'));
1261  $this->categoryMapping();
1262  return false;
1263  }
1264 
1265  $this->tabs_gui->setSubTabActive('ecs_category_mapping');
1266  $this->ctrl->saveParameter($this,'rule_id');
1267  $this->initRule((int) $_REQUEST['rule_id']);
1268 
1269  $this->initCategoryMappingForm('edit');
1270  $this->tpl->setContent($this->form->getHTML());
1271  return true;
1272  }
1273 
1278  protected function updateCategoryMapping()
1279  {
1280  if(!$_REQUEST['rule_id'])
1281  {
1282  ilUtil::sendInfo($this->lng->txt('select_one'));
1283  $this->categoryMapping();
1284  return false;
1285  }
1286  $this->ctrl->saveParameter($this,'rule_id');
1287  $this->initRule((int) $_REQUEST['rule_id']);
1288  $this->initCategoryMappingForm('edit');
1289  if($this->form->checkInput())
1290  {
1291  $this->rule->setContainerId($this->form->getInput('import_id'));
1292  $this->rule->setMappingType($this->form->getInput('type'));
1293  $this->rule->setMappingValue($this->form->getInput('mapping_value'));
1294  $this->rule->setFieldName($this->form->getInput('field'));
1295  $this->rule->setDateRangeStart($this->form->getItemByPostVar('dur_begin')->getDate());
1296  $this->rule->setDateRangeEnd($this->form->getItemByPostVar('dur_end')->getDate());
1297 
1298  if($err = $this->rule->validate())
1299  {
1300  ilUtil::sendInfo($this->lng->txt($err));
1301  $this->form->setValuesByPost();
1302  $this->editCategoryMapping();
1303  return false;
1304  }
1305  $this->rule->update();
1306  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
1307  $this->ctrl->redirect($this,'categoryMapping');
1308  return true;
1309  }
1310  ilUtil::sendInfo($this->lng->txt('err_check_input'));
1311  $this->form->setValuesByPost();
1312  $this->editCategoryMapping();
1313  return false;
1314 
1315  }
1316 
1320  protected function deleteCategoryMappings()
1321  {
1322  if(!is_array($_POST['rules']) or !$_POST['rules'])
1323  {
1324  ilUtil::sendInfo($this->lng->txt('no_checkbox'));
1325  $this->categoryMapping();
1326  return false;
1327  }
1328  foreach($_POST['rules'] as $rule_id)
1329  {
1330  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1331  $rule = new ilECSCategoryMappingRule($rule_id);
1332  $rule->delete();
1333  }
1334  ilUtil::sendInfo($this->lng->txt('settings_saved'));
1335  $this->categoryMapping();
1336  return true;
1337  }
1338 
1343  protected function showRulesTable()
1344  {
1345  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php';
1346 
1347  if(!$rules = ilECSCategoryMapping::getActiveRules())
1348  {
1349  return false;
1350  }
1351  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingTableGUI.php';
1352  $rule_table = new ilECSCategoryMappingTableGUI($this,'categoryMapping');
1353  $rule_table->parse($rules);
1354  return $rule_table->getHTML();
1355  }
1356 
1362  protected function initRule($a_rule_id = 0)
1363  {
1364  if(is_object($this->rule))
1365  {
1366  return $this->rule;
1367  }
1368 
1369  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1370  $this->rule = new ilECSCategoryMappingRule($a_rule_id);
1371  }
1372 
1377  protected function initCategoryMappingForm($a_mode = 'add')
1378  {
1379  global $ilDB;
1380 
1381  if(is_object($this->form))
1382  {
1383  return true;
1384  }
1385 
1386  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1387  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1388 
1389  $this->form = new ilPropertyFormGUI();
1390 
1391  if($a_mode == 'add')
1392  {
1393  $this->form->setTitle($this->lng->txt('ecs_new_category_mapping'));
1394  $this->form->setFormAction($this->ctrl->getFormAction($this,'categoryMapping'));
1395  $this->form->addCommandButton('addCategoryMapping',$this->lng->txt('save'));
1396  $this->form->addCommandButton('categoryMapping',$this->lng->txt('cancel'));
1397  }
1398  else
1399  {
1400  $this->form->setTitle($this->lng->txt('ecs_edit_category_mapping'));
1401  $this->form->setFormAction($this->ctrl->getFormAction($this,'editCategoryMapping'));
1402  $this->form->addCommandButton('updateCategoryMapping',$this->lng->txt('save'));
1403  $this->form->addCommandButton('categoryMapping',$this->lng->txt('cancel'));
1404  }
1405 
1406  $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'),'import_id');
1407  $imp->setRequired(true);
1408 
1409  $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
1410  $tpl->setVariable('SIZE',5);
1411  $tpl->setVariable('MAXLENGTH',11);
1412  $tpl->setVariable('POST_VAR','import_id');
1413  $tpl->setVariable('PROPERTY_VALUE',$this->rule->getContainerId());
1414 
1415  if($this->settings->getImportId())
1416  {
1417  $tpl->setVariable('COMPLETE_PATH',$this->buildPath($this->rule->getContainerId()));
1418  }
1419 
1420  $imp->setHTML($tpl->get());
1421  $imp->setInfo($this->lng->txt('ecs_import_id_info'));
1422  $this->form->addItem($imp);
1423 
1424  include_once('./Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php');
1426  foreach($fields as $field)
1427  {
1428  $options[$field] = $this->lng->txt('ecs_field_'.$field);
1429  }
1430  $select = new ilSelectInputGUI($this->lng->txt('ecs_attribute_name'),'field');
1431  $select->setValue($this->rule->getFieldName());
1432  $select->setRequired(true);
1433  $select->setOptions($options);
1434  $this->form->addItem($select);
1435 
1436  // Value
1437  $value = new ilRadioGroupInputGUI($this->lng->txt('ecs_cat_mapping_type'),'type');
1438  $value->setValue($this->rule->getMappingType());
1439  $value->setRequired(true);
1440 
1441  $fixed = new ilRadioOption($this->lng->txt('ecs_cat_mapping_fixed'),ilECSCategoryMappingRule::TYPE_FIXED);
1442  $fixed->setInfo($this->lng->txt('ecs_cat_mapping_fixed_info'));
1443 
1444  $fixed_val = new ilTextInputGUI($this->lng->txt('ecs_cat_mapping_values'),'mapping_value');
1445  $fixed_val->setValue($this->rule->getMappingValue());
1446  $fixed_val->setMaxLength(255);
1447  $fixed_val->setSize(40);
1448  $fixed->addSubItem($fixed_val);
1449 
1450  $value->addOption($fixed);
1451 
1452  $duration = new ilRadioOption($this->lng->txt('ecs_cat_mapping_duration'),ilECSCategoryMappingRule::TYPE_DURATION);
1453  $duration->setInfo($this->lng->txt('ecs_cat_mapping_duration_info'));
1454 
1455  $dur_start = new ilDateTimeInputGUI($this->lng->txt('from'),'dur_begin');
1456  $dur_start->setDate($this->rule->getDateRangeStart());
1457  $duration->addSubItem($dur_start);
1458 
1459  $dur_end = new ilDateTimeInputGUI($this->lng->txt('to'),'dur_end');
1460  $dur_end->setDate($this->rule->getDateRangeEnd());
1461  $duration->addSubItem($dur_end);
1462 
1463  $value->addOption($duration);
1464 
1465  $this->form->addItem($value);
1466 
1467  }
1468 
1469 
1475  protected function imported()
1476  {
1477  global $ilUser;
1478 
1479  $this->tabs_gui->setSubTabActive('ecs_import');
1480 
1481  $rcourses = ilUtil::_getObjectsByOperations('rcrs','visible',$ilUser->getId(),-1);
1482 
1483  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_imported.html','Services/WebServices/ECS');
1484 
1485  include_once './Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
1486  $tb = new ilToolbarGUI();
1487 
1488  if(count($rcourses))
1489  {
1490  $tb->addButton(
1491  $this->lng->txt('csv_export'),
1492  $this->ctrl->getLinkTarget($this,'exportImported')
1493  );
1494  }
1495  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
1496  if(ilECSServerSettings::getInstance()->activeServerExists())
1497  {
1498  $tb->addButton(
1499  $this->lng->txt('ecs_read_remote_links'),
1500  $this->ctrl->getLinkTarget($this,'readAll')
1501  );
1502  }
1503  $this->tpl->setVariable('ACTION_BUTTONS',$tb->getHTML());
1504 
1505  include_once('Services/WebServices/ECS/classes/class.ilECSImportedContentTableGUI.php');
1506 
1507  $table_gui = new ilECSImportedContentTableGUI($this,'imported');
1508 
1509  $table_gui->setTitle($this->lng->txt('ecs_imported_content'));
1510  $table_gui->parse($rcourses);
1511  $this->tpl->setVariable('TBL_IMPORTED',$table_gui->getHTML());
1512 
1513  return true;
1514  }
1515 
1522  protected function exportImported()
1523  {
1524  global $ilObjDataCache,$ilUser;
1525 
1526  $rcourses = ilUtil::_getObjectsByOperations('rcrs','visible',$ilUser->getId(),-1);
1527 
1528  // Read participants
1529  include_once('./Modules/RemoteCourse/classes/class.ilObjRemoteCourse.php');
1530  include_once('./Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
1531  try
1532  {
1534  }
1535  catch(ilECSConnectorException $e)
1536  {
1537  $reader = null;
1538  }
1539 
1540  // read obj_ids
1541  $ilObjDataCache->preloadReferenceCache($rcourses);
1542  $obj_ids = array();
1543  foreach($rcourses as $rcrs_ref_id)
1544  {
1545  $obj_id = $ilObjDataCache->lookupObjId($rcrs_ref_id);
1546  $obj_ids[$obj_id] = $obj_id;
1547  }
1548 
1549  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
1550  $writer = new ilCSVWriter();
1551 
1552  $writer->addColumn($this->lng->txt('title'));
1553  $writer->addColumn($this->lng->txt('description'));
1554  $writer->addColumn($this->lng->txt('ecs_imported_from'));
1555  $writer->addColumn($this->lng->txt('ecs_field_courseID'));
1556  $writer->addColumn($this->lng->txt('ecs_field_term'));
1557  $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
1558  $writer->addColumn($this->lng->txt('ecs_field_courseType'));
1559  $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
1560  $writer->addColumn($this->lng->txt('ecs_field_credits'));
1561  $writer->addColumn($this->lng->txt('ecs_field_room'));
1562  $writer->addColumn($this->lng->txt('ecs_field_cycle'));
1563  $writer->addColumn($this->lng->txt('ecs_field_begin'));
1564  $writer->addColumn($this->lng->txt('ecs_field_end'));
1565  $writer->addColumn($this->lng->txt('last_update'));
1566 
1567  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1569 
1570  foreach($obj_ids as $obj_id)
1571  {
1572  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1573  $values = ilAdvancedMDValues::_getValuesByObjId($obj_id);
1574 
1575  $writer->addRow();
1576  $writer->addColumn(ilObject::_lookupTitle($obj_id));
1577  $writer->addColumn(ilObject::_lookupDescription($obj_id));
1578 
1579  $mid = ilObjRemoteCourse::_lookupMID($obj_id);
1580  if($reader and ($participant = $reader->getParticipantByMID($mid)))
1581  {
1582  $writer->addColumn($participant->getParticipantName());
1583  }
1584  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'courseID');
1585  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1586 
1587  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'term');
1588  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1589 
1590  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'lecturer');
1591  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1592 
1593  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'courseType');
1594  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1595 
1596  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'semester_hours');
1597  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1598 
1599  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'credits');
1600  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1601 
1602  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'room');
1603  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1604 
1605  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'cycle');
1606  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1607 
1608  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'begin');
1609  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1610 
1611  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'end');
1612  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1613 
1614  $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
1615  }
1616  ilUtil::deliverData($writer->getCSVString(), date("Y_m_d")."_ecs_import.csv", "text/csv");
1617  }
1618 
1625  protected function released()
1626  {
1627  global $ilUser;
1628 
1629  $this->tabs_gui->setSubTabActive('ecs_released');
1630 
1631  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
1632  $exported = ilECSExport::getExportedIDs();
1633 
1634  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_released.html','Services/WebServices/ECS');
1635 
1636  include_once './Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
1637  $tb = new ilToolbarGUI();
1638 
1639  if(count($exported))
1640  {
1641  $tb->addButton(
1642  $this->lng->txt('csv_export'),
1643  $this->ctrl->getLinkTarget($this,'exportReleased')
1644  );
1645  }
1646  if($this->settings->isEnabled())
1647  {
1648  $tb->addButton(
1649  $this->lng->txt('ecs_read_remote_links'),
1650  $this->ctrl->getLinkTarget($this,'readAll')
1651  );
1652  }
1653  $this->tpl->setVariable('ACTION_BUTTONS',$tb->getHTML());
1654 
1655  include_once('Services/WebServices/ECS/classes/class.ilECSReleasedContentTableGUI.php');
1656  $table_gui = new ilECSReleasedContentTableGUI($this,'released');
1657 
1658  $table_gui->setTitle($this->lng->txt('ecs_released_content'));
1659  $table_gui->parse($exported);
1660  $this->tpl->setVariable('TABLE_REL',$table_gui->getHTML());
1661 
1662  return true;
1663 
1664  }
1665 
1672  protected function exportReleased()
1673  {
1674  global $ilObjDataCache;
1675 
1676  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
1677  $exported = ilECSExport::getExportedIds();
1678  $ilObjDataCache->preloadObjectCache($exported);
1679 
1680  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
1681  $writer = new ilCSVWriter();
1682 
1683  $writer->addColumn($this->lng->txt('title'));
1684  $writer->addColumn($this->lng->txt('description'));
1685  $writer->addColumn($this->lng->txt('ecs_field_courseID'));
1686  $writer->addColumn($this->lng->txt('ecs_field_term'));
1687  $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
1688  $writer->addColumn($this->lng->txt('ecs_field_courseType'));
1689  $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
1690  $writer->addColumn($this->lng->txt('ecs_field_credits'));
1691  $writer->addColumn($this->lng->txt('ecs_field_room'));
1692  $writer->addColumn($this->lng->txt('ecs_field_cycle'));
1693  $writer->addColumn($this->lng->txt('ecs_field_begin'));
1694  $writer->addColumn($this->lng->txt('ecs_field_end'));
1695  $writer->addColumn($this->lng->txt('last_update'));
1696 
1697  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1699 
1700  foreach($exported as $obj_id)
1701  {
1702  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1703  $values = ilAdvancedMDValues::_getValuesByObjId($obj_id);
1704 
1705  $writer->addRow();
1706  $writer->addColumn(ilObject::_lookupTitle($obj_id));
1707  $writer->addColumn(ilObject::_lookupDescription($obj_id));
1708 
1709  $field = $settings->getMappingByECSName('courseID');
1710  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1711 
1712  $field = $settings->getMappingByECSName('term');
1713  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1714 
1715  $field = $settings->getMappingByECSName('lecturer');
1716  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1717 
1718  $field = $settings->getMappingByECSName('courseType');
1719  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1720 
1721  $field = $settings->getMappingByECSName('semester_hours');
1722  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1723 
1724  $field = $settings->getMappingByECSName('credits');
1725  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1726 
1727  $field = $settings->getMappingByECSName('room');
1728  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1729 
1730  $field = $settings->getMappingByECSName('cycle');
1731  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1732 
1733  $field = $settings->getMappingByECSName('begin');
1734  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1735 
1736  $field = $settings->getMappingByECSName('end');
1737  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1738 
1739  $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
1740  }
1741 
1742  ilUtil::deliverData($writer->getCSVString(), date("Y_m_d")."_ecs_export.csv", "text/csv");
1743  }
1744 
1745 
1751  protected function prepareFieldSelection($fields)
1752  {
1753  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
1754 
1755  $options[0] = $this->lng->txt('ecs_ignore_field');
1756  foreach($fields as $field)
1757  {
1759  $title = ilAdvancedMDRecord::_lookupTitle($field->getRecordId());
1760  $options[$field->getFieldId()] = $title.': '.$field->getTitle();
1761  }
1762  return $options;
1763  }
1764 
1765 
1766 
1772  protected function initSettings($a_server_id = 1)
1773  {
1774  include_once('Services/WebServices/ECS/classes/class.ilECSSetting.php');
1775  $this->settings = ilECSSetting::getInstanceByServerId($a_server_id);
1776  }
1777 
1783  protected function setSubTabs()
1784  {
1785  $this->tabs_gui->clearSubTabs();
1786 
1787  $this->tabs_gui->addSubTabTarget("overview",
1788  $this->ctrl->getLinkTarget($this,'overview'),
1789  "overview",get_class($this));
1790 
1791  // Disable all other tabs, if server hasn't been configured.
1792  ilECSServerSettings::getInstance()->readInactiveServers();
1793  if(!ilECSServerSettings::getInstance()->serverExists())
1794  {
1795  return true;
1796  }
1797 
1798  $this->tabs_gui->addSubTabTarget("ecs_communities",
1799  $this->ctrl->getLinkTarget($this,'communities'),
1800  "communities",get_class($this));
1801 
1802  $this->tabs_gui->addSubTabTarget('ecs_mappings',
1803  $this->ctrl->getLinkTarget($this,'importMappings'),
1804  'importMappings',get_class($this));
1805 
1806  $this->tabs_gui->addSubTabTarget('ecs_category_mapping',
1807  $this->ctrl->getLinkTarget($this,'categoryMapping'));
1808 
1809  $this->tabs_gui->addSubTabTarget('ecs_import',
1810  $this->ctrl->getLinkTarget($this,'imported'));
1811 
1812  $this->tabs_gui->addSubTabTarget('ecs_released',
1813  $this->ctrl->getLinkTarget($this,'released'));
1814 
1815  }
1816 
1822  private function prepareRoleSelect()
1823  {
1824  global $rbacreview,$ilObjDataCache;
1825 
1826  $global_roles = ilUtil::_sortIds($rbacreview->getGlobalRoles(),
1827  'object_data',
1828  'title',
1829  'obj_id');
1830 
1831  $select[0] = $this->lng->txt('links_select_one');
1832  foreach($global_roles as $role_id)
1833  {
1834  $select[$role_id] = ilObject::_lookupTitle($role_id);
1835  }
1836  return $select;
1837  }
1838 
1839  private function buildPath($a_ref_id)
1840  {
1841  $loc = new ilLocatorGUI();
1842  $loc->setTextOnly(false);
1843  $loc->addContextItems($a_ref_id);
1844 
1845  return $loc->getHTML();
1846  }
1847 
1853  protected function initTaskScheduler()
1854  {
1855  global $ilDB,$ilSetting;
1856 
1857  #$ilDB->lockTables(array('name' => 'settings', 'type' => ilDB::LOCK_WRITE));
1858  $setting = new ilSetting('ecs');
1859  $setting->set(
1860  'next_execution_'.$this->settings->getServerId(),
1861  time() + (int) $this->settings->getPollingTime()
1862  );
1863  }
1864 
1865 }
1866 
1867 ?>