ILIAS  Release_5_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 
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'], (int) $_REQUEST['mid']);
83  $this->ctrl->setReturn($this,'communities');
84  $this->ctrl->forwardCommand($mapset);
85  break;
86 
87  case 'ilecsparticipantsettingsgui':
88  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettingsGUI.php';
89  $part = new ilECSParticipantSettingsGUI(
90  (int) $_REQUEST['server_id'],
91  (int) $_REQUEST['mid']
92  );
93  $this->ctrl->setReturn($this,'communities');
94  $this->ctrl->forwardCommand($part);
95  break;
96 
97  default:
98  if(!$cmd || $cmd == 'view')
99  {
100  $cmd = "overview";
101  }
102  $this->$cmd();
103  break;
104  }
105  return true;
106  }
107 
114  public function overview()
115  {
116  global $ilToolbar,$ilTabs;
117 
118  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
119 
120  $ilTabs->setSubTabActive('overview');
121  $ilToolbar->addButton(
122  $this->lng->txt('ecs_add_new_ecs'),
123  $this->ctrl->getLinkTarget($this,'create')
124  );
125 
127  $servers->readInactiveServers();
128 
129  include_once './Services/WebServices/ECS/classes/class.ilECSServerTableGUI.php';
130  $table = new ilECSServerTableGUI($this,'overview');
131  $table->initTable();
132  $table->parse($servers);
133  $this->tpl->setContent($table->getHTML());
134  return;
135  }
136 
140  protected function activate()
141  {
142  $this->initSettings($_REQUEST['server_id']);
143  $this->settings->setEnabledStatus(true);
144  $this->settings->update();
145  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
146  $this->ctrl->redirect($this,'overview');
147  }
148 
152  protected function deactivate()
153  {
154  $this->initSettings($_REQUEST['server_id']);
155  $this->settings->setEnabledStatus(false);
156  $this->settings->update();
157  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
158  $this->ctrl->redirect($this,'overview');
159  }
160 
166  protected function readAll()
167  {
168  include_once('Services/WebServices/ECS/classes/class.ilECSConnector.php');
169  include_once('Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
170  include_once('./Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php');
171  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
172 
173  try
174  {
175  foreach(ilECSServerSettings::getInstance()->getServers() as $server)
176  {
179 
180  include_once('./Services/WebServices/ECS/classes/class.ilECSTaskScheduler.php');
181  ilECSTaskScheduler::_getInstanceByServerId($server->getServerId())->startTaskExecution();
182 
183  ilUtil::sendInfo($this->lng->txt('ecs_remote_imported'));
184  $this->imported();
185  return true;
186  }
187  }
188  catch(ilECSConnectorException $e1)
189  {
190  ilUtil::sendInfo('Cannot connect to ECS server: '.$e1->getMessage());
191  $this->imported();
192  return false;
193  }
194  catch(ilException $e2)
195  {
196  ilUtil::sendInfo('Update failed: '.$e1->getMessage());
197  $this->imported();
198  return false;
199  }
200  }
201 
206  protected function create()
207  {
208  global $ilTabs;
209 
210  $this->initSettings(0);
211 
212  $ilTabs->clearTargets();
213  $ilTabs->clearSubTabs();
214  $ilTabs->setBackTarget($this->lng->txt('back'),$this->ctrl->getLinkTarget($this,'overview'));
215 
216  $this->initSettingsForm('create');
217  $this->tabs_gui->setSubTabActive('ecs_settings');
218 
219  $this->tpl->setContent($this->form->getHTML());
220  }
221 
225  protected function edit()
226  {
227  global $ilTabs;
228 
229  $this->initSettings((int) $_REQUEST['server_id']);
230  $this->ctrl->saveParameter($this,'server_id',(int) $_REQUEST['server_id']);
231 
232  $ilTabs->clearTargets();
233  $ilTabs->clearSubTabs();
234  $ilTabs->setBackTarget($this->lng->txt('back'),$this->ctrl->getLinkTarget($this,'overview'));
235 
236  $this->initSettingsForm();
237  $this->tabs_gui->setSubTabActive('ecs_settings');
238 
239  $this->tpl->setContent($this->form->getHTML());
240  }
241 
242  protected function cp()
243  {
244  $this->initSettings((int) $_REQUEST['server_id']);
245 
246  $copy = clone $this->settings;
247  $copy->save();
248 
249  $this->ctrl->setParameter($this,'server_id',$copy->getServerId());
250  ilUtil::sendSuccess($this->lng->txt('ecs_settings_cloned'),true);
251  $this->ctrl->redirect($this,'edit');
252  }
253 
257  protected function delete()
258  {
259  global $ilTabs;
260 
261  $this->initSettings((int) $_REQUEST['server_id']);
262 
263  $ilTabs->clearTargets();
264  $ilTabs->clearSubTabs();
265  $ilTabs->setBackTarget($this->lng->txt('back'),$this->ctrl->getLinkTarget($this,'overview'));
266 
267  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
268  $confirm = new ilConfirmationGUI();
269  $confirm->setFormAction($this->ctrl->getFormAction($this));
270  $confirm->setConfirm($this->lng->txt('delete'), 'doDelete');
271  $confirm->setCancel($this->lng->txt('cancel'), 'overview');
272  $confirm->setHeaderText($this->lng->txt('ecs_delete_setting'));
273 
274  $confirm->addItem('','',$this->settings->getServer());
275  $confirm->addHiddenItem('server_id', $this->settings->getServerId());
276 
277  $this->tpl->setContent($confirm->getHTML());
278  }
279 
283  protected function doDelete()
284  {
285  $this->initSettings($_REQUEST['server_id']);
286  $this->settings->delete();
287 
288  // Delete communities
289  include_once './Services/WebServices/ECS/classes/class.ilECSCommunitiesCache.php';
290  ilECSCommunitiesCache::delete((int) $_REQUEST['server_id']);
291 
292  include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php';
293  ilECSDataMappingSettings::delete((int) $_REQUEST['server_id']);
294 
295  include_once './Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php';
296  ilECSEventQueueReader::deleteServer((int) $_REQUEST['server_id']);
297 
298  include_once './Services/WebServices/ECS/classes/class.ilECSExport.php';
299  ilECSExport::deleteByServer((int) $_REQUEST['server_id']);
300 
301  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
302  ilECSImport::deleteByServer((int) $_REQUEST['server_id']);
303 
304  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
305  ilECSParticipantSettings::deleteByServer((int) $_REQUEST['server_id']);
306 
307  ilUtil::sendSuccess($this->lng->txt('ecs_setting_deleted'),true);
308  $this->ctrl->redirect($this,'overview');
309  }
310 
311 
317  protected function settings()
318  {
319  $this->initSettingsForm();
320  $this->tabs_gui->setSubTabActive('ecs_settings');
321 
322  $this->tpl->setContent($this->form->getHTML());
323  }
324 
330  protected function initSettingsForm($a_mode = 'update')
331  {
332  if(is_object($this->form))
333  {
334  return true;
335  }
336  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
337 
338  $this->form = new ilPropertyFormGUI();
339  $this->form->setFormAction($this->ctrl->getFormAction($this,'settings'));
340  $this->form->setTitle($this->lng->txt('ecs_connection_settings'));
341 
342  $ena = new ilCheckboxInputGUI($this->lng->txt('ecs_active'),'active');
343  $ena->setChecked($this->settings->isEnabled());
344  $ena->setValue(1);
345  $this->form->addItem($ena);
346 
347  $server_title = new ilTextInputGUI($this->lng->txt('ecs_server_title'),'title');
348  $server_title->setValue($this->settings->getTitle());
349  $server_title->setSize(80);
350  $server_title->setMaxLength(128);
351  $server_title->setRequired(true);
352  $this->form->addItem($server_title);
353 
354  $ser = new ilTextInputGUI($this->lng->txt('ecs_server_url'),'server');
355  $ser->setValue((string) $this->settings->getServer());
356  $ser->setRequired(true);
357  $this->form->addItem($ser);
358 
359  $pro = new ilSelectInputGUI($this->lng->txt('ecs_protocol'),'protocol');
360  // fixed to https
361  #$pro->setOptions(array(ilECSSetting::PROTOCOL_HTTP => $this->lng->txt('http'),
362  # ilECSSetting::PROTOCOL_HTTPS => $this->lng->txt('https')));
363  $pro->setOptions(array(ilECSSetting::PROTOCOL_HTTPS => 'HTTPS'));
364  $pro->setValue($this->settings->getProtocol());
365  $pro->setRequired(true);
366  $this->form->addItem($pro);
367 
368  $por = new ilTextInputGUI($this->lng->txt('ecs_port'),'port');
369  $por->setSize(5);
370  $por->setMaxLength(5);
371  $por->setValue((string) $this->settings->getPort());
372  $por->setRequired(true);
373  $this->form->addItem($por);
374 
375  $tcer = new ilRadioGroupInputGUI($this->lng->txt('ecs_auth_type'),'auth_type');
376  $tcer->setValue($this->settings->getAuthType());
377  $this->form->addItem($tcer);
378 
379  // Certificate based authentication
380  $cert_based = new ilRadioOption($this->lng->txt('ecs_auth_type_cert'), ilECSSetting::AUTH_CERTIFICATE);
381  $tcer->addOption($cert_based);
382 
383  $cli = new ilTextInputGUI($this->lng->txt('ecs_client_cert'),'client_cert');
384  $cli->setSize(60);
385  $cli->setValue((string) $this->settings->getClientCertPath());
386  $cli->setRequired(true);
387  $cert_based->addSubItem($cli);
388 
389  $key = new ilTextInputGUI($this->lng->txt('ecs_cert_key'),'key_path');
390  $key->setSize(60);
391  $key->setValue((string) $this->settings->getKeyPath());
392  $key->setRequired(true);
393  $cert_based->addSubItem($key);
394 
395  $cerp = new ilTextInputGUI($this->lng->txt('ecs_key_password'),'key_password');
396  $cerp->setSize(12);
397  $cerp->setValue((string) $this->settings->getKeyPassword());
398  $cerp->setInputType('password');
399  $cerp->setRequired(true);
400  $cert_based->addSubItem($cerp);
401 
402  $cer = new ilTextInputGUI($this->lng->txt('ecs_ca_cert'),'ca_cert');
403  $cer->setSize(60);
404  $cer->setValue((string) $this->settings->getCACertPath());
405  $cer->setRequired(true);
406  $cert_based->addSubItem($cer);
407 
408  // Apache auth
409  $apa_based = new ilRadioOption($this->lng->txt('ecs_auth_type_apache'), ilECSSetting::AUTH_APACHE);
410  $tcer->addOption($apa_based);
411 
412  $user = new ilTextInputGUI($this->lng->txt('ecs_apache_user'),'auth_user');
413  $user->setSize(32);
414  $user->setValue((string) $this->settings->getAuthUser());
415  $user->setRequired(true);
416  $apa_based->addSubItem($user);
417 
418  $pass = new ilPasswordInputGUI($this->lng->txt('ecs_apache_pass'), 'auth_pass');
419  $pass->setRetype(false);
420  $pass->setSize(32);
421  $pass->setMaxLength(128);
422  $pass->setValue((string) $this->settings->getAuthPass());
423  $pass->setRequired(true);
424  $pass->setSkipSyntaxCheck(TRUE);
425  $apa_based->addSubItem($pass);
426 
427 
428  $ser = new ilNonEditableValueGUI($this->lng->txt('cert_serial'));
429  $ser->setValue($this->settings->getCertSerialNumber() ? $this->settings->getCertSerialNumber() : $this->lng->txt('ecs_no_value'));
430  $cert_based->addSubItem($ser);
431 
432  $loc = new ilFormSectionHeaderGUI();
433  $loc->setTitle($this->lng->txt('ecs_local_settings'));
434  $this->form->addItem($loc);
435 
436  $pol = new ilDurationInputGUI($this->lng->txt('ecs_polling'),'polling');
437  $pol->setShowDays(false);
438  $pol->setShowHours(false);
439  $pol->setShowMinutes(true);
440  $pol->setShowSeconds(true);
441  $pol->setSeconds($this->settings->getPollingTimeSeconds());
442  $pol->setMinutes($this->settings->getPollingTimeMinutes());
443  $pol->setRequired(true);
444  $pol->setInfo($this->lng->txt('ecs_polling_info'));
445  $this->form->addItem($pol);
446 
447  $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'));
448  $imp->setRequired(true);
449 
450  $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
451  $tpl->setVariable('SIZE',5);
452  $tpl->setVariable('MAXLENGTH',11);
453  $tpl->setVariable('POST_VAR','import_id');
454  $tpl->setVariable('PROPERTY_VALUE',$this->settings->getImportId());
455 
456  if($this->settings->getImportId())
457  {
458  $tpl->setVariable('COMPLETE_PATH',$this->buildPath($this->settings->getImportId()));
459  }
460 
461  $imp->setHTML($tpl->get());
462  $imp->setInfo($this->lng->txt('ecs_import_id_info'));
463  $this->form->addItem($imp);
464 
465  $loc = new ilFormSectionHeaderGUI();
466  $loc->setTitle($this->lng->txt('ecs_remote_user_settings'));
467  $this->form->addItem($loc);
468 
469  $role = new ilSelectInputGUI($this->lng->txt('ecs_role'),'global_role');
470  $role->setOptions($this->prepareRoleSelect());
471  $role->setValue($this->settings->getGlobalRole());
472  $role->setInfo($this->lng->txt('ecs_global_role_info'));
473  $role->setRequired(true);
474  $this->form->addItem($role);
475 
476  $duration = new ilDurationInputGUI($this->lng->txt('ecs_account_duration'),'duration');
477  $duration->setInfo($this->lng->txt('ecs_account_duration_info'));
478  $duration->setMonths($this->settings->getDuration());
479  $duration->setShowSeconds(false);
480  $duration->setShowMinutes(false);
481  $duration->setShowHours(false);
482  $duration->setShowDays(false);
483  $duration->setShowMonths(true);
484  $duration->setRequired(true);
485  $this->form->addItem($duration);
486 
487  // Email recipients
488  $loc = new ilFormSectionHeaderGUI();
489  $loc->setTitle($this->lng->txt('ecs_notifications'));
490  $this->form->addItem($loc);
491 
492  $rcp_user = new ilTextInputGUI($this->lng->txt('ecs_user_rcp'),'user_recipients');
493  $rcp_user->setValue((string) $this->settings->getUserRecipientsAsString());
494  $rcp_user->setInfo($this->lng->txt('ecs_user_rcp_info'));
495  $this->form->addItem($rcp_user);
496 
497  $rcp_econ = new ilTextInputGUI($this->lng->txt('ecs_econ_rcp'),'econtent_recipients');
498  $rcp_econ->setValue((string) $this->settings->getEContentRecipientsAsString());
499  $rcp_econ->setInfo($this->lng->txt('ecs_econ_rcp_info'));
500  $this->form->addItem($rcp_econ);
501 
502  $rcp_app = new ilTextInputGUI($this->lng->txt('ecs_approval_rcp'),'approval_recipients');
503  $rcp_app->setValue((string) $this->settings->getApprovalRecipientsAsString());
504  $rcp_app->setInfo($this->lng->txt('ecs_approval_rcp_info'));
505  $this->form->addItem($rcp_app);
506 
507  if($a_mode == 'update')
508  {
509  $this->form->addCommandButton('update',$this->lng->txt('save'));
510  }
511  else
512  {
513  $this->form->addCommandButton('save',$this->lng->txt('save'));
514  }
515  $this->form->addCommandButton('overview',$this->lng->txt('cancel'));
516  }
517 
523  protected function update()
524  {
525  $this->initSettings((int) $_REQUEST['server_id']);
526  $this->loadFromPost();
527 
528  if(!$error = $this->settings->validate())
529  {
530  $this->settings->update();
531  $this->initTaskScheduler();
532  #$this->updateTitle();
533  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
534  }
535  else
536  {
537  ilUtil::sendInfo($this->lng->txt($error));
538  $this->edit();
539  }
540 
541  $this->overview();
542  return true;
543  }
544 
549  protected function save()
550  {
551  $this->initSettings(0);
552  $this->loadFromPost();
553 
554  if(!$error = $this->settings->validate())
555  {
556  $this->settings->save();
557  $this->initTaskScheduler();
558 
559  #$this->updateTitle();
560  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
561  }
562  else
563  {
564  ilUtil::sendInfo($this->lng->txt($error));
565  return $this->create();
566  }
567  $GLOBALS['ilCtrl']->redirect($this,'overview');
568  return true;
569  }
570 
574  protected function updateTitle()
575  {
576  try
577  {
578  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
580 
581  foreach($reader->getCommunities() as $community)
582  {
583  foreach($community->getParticipants() as $part)
584  {
585  $GLOBALS['ilLog']->write(__METHOD__.': '.print_r($community,true));
586  if($part->isSelf())
587  {
588  $this->settings->setTitle($part->getParticipantName());
589  $this->settings->update();
590  return true;
591  }
592  }
593  }
594  }
595  catch(ilECSConnectorException $exc)
596  {
597  ilUtil::sendFailure($exc->getMessage());
598  }
599  $this->settings->setTitle('');
600  $this->settings->update();
601  }
602 
606  protected function loadFromPost()
607  {
608  $this->settings->setEnabledStatus((int) $_POST['active']);
609  $this->settings->setTitle(ilUtil::stripSlashes($_POST['title']));
610  $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
611  $this->settings->setPort(ilUtil::stripSlashes($_POST['port']));
612  $this->settings->setProtocol(ilUtil::stripSlashes($_POST['protocol']));
613  $this->settings->setClientCertPath(ilUtil::stripSlashes($_POST['client_cert']));
614  $this->settings->setCACertPath(ilUtil::stripSlashes($_POST['ca_cert']));
615  $this->settings->setKeyPath(ilUtil::stripSlashes($_POST['key_path']));
616  $this->settings->setKeyPassword(ilUtil::stripSlashes($_POST['key_password']));
617  $this->settings->setImportId(ilUtil::stripSlashes($_POST['import_id']));
618  $this->settings->setPollingTimeMS((int) $_POST['polling']['mm'],(int) $_POST['polling']['ss']);
619  $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
620  $this->settings->setGlobalRole((int) $_POST['global_role']);
621  $this->settings->setDuration((int) $_POST['duration']['MM']);
622 
623  $this->settings->setUserRecipients(ilUtil::stripSlashes($_POST['user_recipients']));
624  $this->settings->setEContentRecipients(ilUtil::stripSlashes($_POST['econtent_recipients']));
625  $this->settings->setApprovalRecipients(ilUtil::stripSlashes($_POST['approval_recipients']));
626 
627  $this->settings->setAuthType((int) $_POST['auth_type']);
628  $this->settings->setAuthPass(ilUtil::stripSlashes($_POST['auth_pass']));
629  $this->settings->setAuthUser(ilUtil::stripSlashes($_POST['auth_user']));
630 
631  }
632 
636  protected function refreshParticipants()
637  {
638  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
639  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
640  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
641  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
642 
644  $servers->readInactiveServers();
645  foreach($servers->getServers() as $server)
646  {
647 
648  // read community
649  try {
650 
651  $creader = ilECSCommunityReader::getInstanceByServerId($server->getServerId());
652  foreach(ilECSParticipantSettings::getAvailabeMids($server->getServerId()) as $mid)
653  {
654  if(!$creader->getParticipantByMID($mid))
655  {
656  $GLOBALS['ilLog']->write(__METHOD__.': Deleting deprecated participant '. $server->getServerId().' '. $mid);
657 
658  $part = new ilECSParticipantSetting($server->getServerId(),$mid);
659  $part->delete();
660  }
661  }
662  }
663  catch(ilECSConnectorException $e)
664  {
665  ilUtil::sendFailure($server->getServer().': '. $e->getMessage(),TRUE);
666  }
667  }
668  ilUtil::sendSuccess($this->lng->txt('settings_saved'),TRUE);
669  $this->ctrl->redirect($this,'communities');
670  }
671 
678  public function communities()
679  {
680  // add toolbar to refresh communities
681  $GLOBALS['ilToolbar']->addButton(
682  $this->lng->txt('ecs_refresh_participants'),
683  $this->ctrl->getLinkTarget($this,'refreshParticipants')
684  );
685 
686  $this->tabs_gui->setSubTabActive('ecs_communities');
687 
688  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_communities.html','Services/WebServices/ECS');
689 
690  $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this,'updateCommunities'));
691  $this->tpl->setVariable('TXT_SAVE',$this->lng->txt('save'));
692  $this->tpl->setVariable('TXT_CANCEL', $this->lng->txt('cancel'));
693 
694  include_once('Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
695  include_once('Services/WebServices/ECS/classes/class.ilECSCommunityTableGUI.php');
696 
697  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
698  $settings = ilECSServerSettings::getInstance();
699  #$settings->readInactiveServers();
700 
701  foreach($settings->getServers() as $server)
702  {
703  // Try to read communities
704  try
705  {
707  foreach($reader->getCommunities() as $community)
708  {
709  $this->tpl->setCurrentBlock('table_community');
710  $table_gui = new ilECSCommunityTableGUI($server,$this,'communities',$community->getId());
711  $table_gui->setTitle($community->getTitle().' ('.$community->getDescription().')');
712  $table_gui->parse($community->getParticipants());
713  $this->tpl->setVariable('TABLE_COMM',$table_gui->getHTML());
714  $this->tpl->parseCurrentBlock();
715  }
716  }
717  catch(ilECSConnectorException $exc)
718  {
719  // Maybe server is not fully configured
720  continue;
721  }
722 
723  // Show section for each server
724  $this->tpl->setCurrentBlock('server');
725  $this->tpl->setVariable('TXT_SERVER_NAME',$server->getTitle());
726  $this->tpl->parseCurrentBlock();
727  }
728  }
729 
735  protected function validateImportTypes(&$import_types)
736  {
737  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
738 
739  $num_cms = 0;
740  foreach((array) $import_types as $sid => $server)
741  {
742  foreach((array) $server as $mid => $import_type)
743  {
744  if($import_type == ilECSParticipantSetting::IMPORT_CMS)
745  {
746  ++$num_cms;
747  }
748  }
749  }
750 
751  if($num_cms <= 1)
752  {
753  return true;
754  }
755  // Change to import type "UNCHANGED"
756  $new_types = array();
757  foreach((array) $import_types as $sid => $server)
758  {
759  foreach((array) $server as $mid => $import_type)
760  {
761  if($import_type == ilECSParticipantSetting::IMPORT_CMS)
762  {
763  $new_types[$sid][$mid] = ilECSParticipantSetting::IMPORT_UNCHANGED;
764  }
765  else
766  {
767  $new_types[$sid][$mid] = $import_type;
768  }
769  }
770  }
771  $import_types = $new_types;
772  return false;
773  }
774 
781  protected function updateCommunities()
782  {
783  global $ilLog;
784 
785  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
786  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
787 
788  // @TODO: Delete deprecated communities
789  $invalidImportTypes = false;
790  if(!$this->validateImportTypes($_POST['import_type']))
791  {
792  $invalidImportTypes = true;
793  }
794 
796  foreach($servers->getServers() as $server)
797  {
798  try {
799  // Read communities
800  $cReader = ilECSCommunityReader::getInstanceByServerId($server->getServerId());
801 
802  // Update community cache
803  foreach($cReader->getCommunities() as $community)
804  {
805  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityCache.php';
806  $cCache = ilECSCommunityCache::getInstance($server->getServerId(), $community->getId());
807  $cCache->setCommunityName($community->getTitle());
808  $cCache->setMids($community->getMids());
809  $cCache->setOwnId($community->getOwnId());
810  $cCache->update();
811  }
812  }
813  catch(Exception $e)
814  {
815  $GLOBALS['ilLog']->write(__METHOD__.': Cannot read ecs communities: '.$e->getMessage());
816  }
817  }
818 
819  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
820  foreach((array) $_POST['sci_mid'] as $sid => $tmp)
821  {
822  foreach((array) $_POST['sci_mid'][$sid] as $mid => $tmp)
823  {
824  $set = new ilECSParticipantSetting($sid, $mid);
825  #$set->enableExport(array_key_exists($mid, (array) $_POST['export'][$sid]) ? true : false);
826  #$set->enableImport(array_key_exists($mid, (array) $_POST['import'][$sid]) ? true : false);
827  $set->setImportType($_POST['import_type'][$sid][$mid]);
828 
829  // update title/cname
830  try {
831  $part = ilECSCommunityReader::getInstanceByServerId($sid)->getParticipantByMID($mid);
832  if($part instanceof ilECSParticipant)
833  {
834  $set->setTitle($part->getParticipantName());
835  }
836  $com = ilECSCommunityReader::getInstanceByServerId($sid)->getCommunityByMID($mid);
837  if($com instanceof ilECSCommunity)
838  {
839  $set->setCommunityName($com->getTitle());
840  }
841  }
842  catch(Exception $e)
843  {
844  $GLOBALS['ilLog']->write(__METHOD__.': Cannot read ecs communities: '.$e->getMessage());
845  }
846 
847  $set->update();
848  }
849  }
850  if($invalidImportTypes)
851  {
852  ilUtil::sendFailure($this->lng->txt('ecs_invalid_import_type_cms'),true);
853  }
854  else
855  {
856  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
857  }
858  $GLOBALS['ilCtrl']->redirect($this,'communities');
859 
860  // TODO: Do update of remote courses and ...
861 
862  return true;
863  }
864 
865 
871  protected function setMappingTabs($a_active)
872  {
873  global $ilTabs;
874 
875  $ilTabs->clearTargets();
876  $ilTabs->clearSubTabs();
877 
878  $ilTabs->setBackTarget(
879  $this->lng->txt('ecs_settings'),
880  $this->ctrl->getLinkTarget($this,'overview')
881  );
882  $ilTabs->addTab(
883  'import',
884  $this->lng->txt('ecs_tab_import'),
885  $this->ctrl->getLinkTarget($this,'importMappings')
886  );
887  $ilTabs->addTab(
888  'export',
889  $this->lng->txt('ecs_tab_export'),
890  $this->ctrl->getLinkTarget($this,'exportMappings')
891  );
892 
893 
894  switch($a_active)
895  {
896  case self::MAPPING_IMPORT:
897  $ilTabs->activateTab('import');
898  break;
899 
900  case self::MAPPING_EXPORT:
901  $ilTabs->activateTab('export');
902  break;
903  }
904  return true;
905  }
906 
912  public function importMappings()
913  {
914  global $ilToolbar;
915 
916  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
917 
918  $this->setMappingTabs(self::MAPPING_IMPORT);
919 
921  if(!count($fields))
922  {
923  ilUtil::sendInfo($this->lng->txt('ecs_no_adv_md'));
924  return true;
925  }
926 
927  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
928  $settings = ilECSServerSettings::getInstance();
929  $settings->readInactiveServers();
930 
931  $sel_srv = (int)$_REQUEST["ecs_mapping_server"];
932  if(!$sel_srv)
933  {
934  $sel_srv = $_SESSION["ecs_sel_srv"];
935  }
936  else
937  {
938  $_SESSION["ecs_sel_srv"] = $sel_srv;
939  }
940 
941  // Iterate all servers
942  $options = array(0 => $this->lng->txt("please_choose"));
943  foreach($settings->getServers() as $server)
944  {
945  $title = $server->getTitle();
946  if(!$title)
947  {
948  $title = "ECS (".$server->getServerId().")";
949  }
950  $options[$server->getServerId()] = $title;
951  }
952 
953  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
954  $sel = new ilSelectInputGUI("", "ecs_mapping_server");
955  $sel->setOptions($options);
956  $sel->setValue($sel_srv);
957  $ilToolbar->addInputItem($sel);
958 
959  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "importMappings"));
960  $ilToolbar->addFormButton($this->lng->txt("submit"), "importMappings");
961 
962  if($sel_srv)
963  {
964  $form = $this->initMappingsForm($sel_srv, self::MAPPING_IMPORT);
965  $this->tpl->setContent($form->getHTML());
966  }
967 
968  return true;
969  }
970 
976  protected function exportMappings()
977  {
978  global $ilToolbar;
979 
980  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
981 
982  $this->setMappingTabs(self::MAPPING_EXPORT);
983 
985  if(!count($fields))
986  {
987  ilUtil::sendInfo($this->lng->txt('ecs_no_adv_md'));
988  return true;
989  }
990 
991  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
992  $settings = ilECSServerSettings::getInstance();
993  $settings->readInactiveServers();
994 
995  $sel_srv = (int)$_REQUEST["ecs_mapping_server"];
996  if(!$sel_srv)
997  {
998  $sel_srv = $_SESSION["ecs_sel_srv"];
999  }
1000  else
1001  {
1002  $_SESSION["ecs_sel_srv"] = $sel_srv;
1003  }
1004 
1005  // Iterate all servers
1006  $options = array(0 => $this->lng->txt("please_choose"));
1007  foreach($settings->getServers() as $server)
1008  {
1009  $title = $server->getTitle();
1010  if(!$title)
1011  {
1012  $title = "ECS (".$server->getServerId().")";
1013  }
1014  $options[$server->getServerId()] = $title;
1015  }
1016 
1017  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1018  $sel = new ilSelectInputGUI("", "ecs_mapping_server");
1019  $sel->setOptions($options);
1020  $sel->setValue($sel_srv);
1021  $ilToolbar->addInputItem($sel);
1022 
1023  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "exportMappings"));
1024  $ilToolbar->addFormButton($this->lng->txt("submit"), "exportMappings");
1025 
1026  if($sel_srv)
1027  {
1028  $form = $this->initMappingsForm($sel_srv,self::MAPPING_EXPORT);
1029  $this->tpl->setContent($form->getHTML());
1030  }
1031 
1032  return true;
1033  }
1034 
1041  protected function saveImportMappings()
1042  {
1043  foreach((array) $_POST['mapping'] as $mtype => $mappings)
1044  {
1045  foreach((array) $mappings as $ecs_field => $advmd_id)
1046  {
1047  include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSetting.php';
1048  $map = new ilECSDataMappingSetting(
1049  (int) $_REQUEST['ecs_mapping_server'],
1050  (int) $mtype,
1051  $ecs_field
1052  );
1053  $map->setAdvMDId($advmd_id);
1054  $map->save();
1055  }
1056  }
1057 
1058  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
1059  $this->ctrl->setParameter($this, "ecs_mapping_server", (int)$_POST['ecs_mapping_server']);
1060  $this->ctrl->redirect($this,'importMappings');
1061  return true;
1062  }
1063 
1070  protected function saveExportMappings()
1071  {
1072  foreach((array) $_POST['mapping'] as $mtype => $mappings)
1073  {
1074  foreach((array) $mappings as $ecs_field => $advmd_id)
1075  {
1076  include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSetting.php';
1077  $map = new ilECSDataMappingSetting(
1078  (int) $_POST['ecs_mapping_server'],
1079  (int) $mtype,
1080  $ecs_field
1081  );
1082  $map->setAdvMDId($advmd_id);
1083  $map->save();
1084  }
1085  }
1086 
1087  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
1088  $this->ctrl->setParameter($this, "ecs_mapping_server", (int)$_POST['ecs_mapping_server']);
1089  $this->ctrl->redirect($this,'exportMappings');
1090  return true;
1091  }
1092 
1101  protected function initMappingsForm($a_server_id,$mapping_type)
1102  {
1103  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
1104 
1105  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1106  $mapping_settings = ilECSDataMappingSettings::getInstanceByServerId($a_server_id);
1107 
1108  $form = new ilPropertyFormGUI();
1109 
1110  if($mapping_type == self::MAPPING_IMPORT)
1111  {
1112  $form->setTitle($this->lng->txt('ecs_mapping_tbl'));
1113  $form->addCommandButton('saveImportMappings',$this->lng->txt('save'));
1114  $form->addCommandButton('importMappings',$this->lng->txt('cancel'));
1115  }
1116  else
1117  {
1118  $form->setTitle($this->lng->txt('ecs_mapping_exp_tbl'));
1119  $form->addCommandButton('saveExportMappings',$this->lng->txt('save'));
1120  $form->addCommandButton('exportMappings',$this->lng->txt('cancel'));
1121  }
1122 
1123  $form->setFormAction($this->ctrl->getFormAction($this,'saveMappings'));
1124 
1125  if($mapping_type == self::MAPPING_IMPORT)
1126  {
1127  $assignments = new ilCustomInputGUI($this->lng->txt('ecs_mapping_crs'));
1128  $form->addItem($assignments);
1129  }
1130 
1131  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1133  $options = $this->prepareFieldSelection($fields);
1134 
1135  // get all optional ecourse fields
1136  include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
1138  foreach($optional as $field_name)
1139  {
1140  if($mapping_type == self::MAPPING_IMPORT)
1141  {
1142  $select = new ilSelectInputGUI(
1143  $this->lng->txt('ecs_field_'.$field_name),
1144  'mapping'.'['.ilECSDataMappingSetting::MAPPING_IMPORT_CRS.']['.$field_name.']'
1145  );
1146 
1147  $select->setValue(
1148  $mapping_settings->getMappingByECSName(
1150  $field_name)
1151  );
1152  $select->setOptions($options);
1153  $assignments->addSubItem($select);
1154  }
1155  else
1156  {
1157  $select = new ilSelectInputGUI(
1158  $this->lng->txt('ecs_field_'.$field_name),
1159  'mapping'.'['.ilECSDataMappingSetting::MAPPING_EXPORT.']['.$field_name.']'
1160  );
1161  $select->setValue(
1162  $mapping_settings->getMappingByECSName(
1164  $field_name)
1165  );
1166  $select->setOptions($options);
1167  $form->addItem($select);
1168  }
1169  }
1170 
1171  $server = new ilHiddenInputGUI('ecs_mapping_server');
1172  $server->setValue($a_server_id);
1173  $form->addItem($server);
1174 
1175  // Remote courses
1176  // no remote course settings for export
1177  if($mapping_type == self::MAPPING_EXPORT)
1178  {
1179  return $form;
1180  }
1181 
1182  $rcrs = new ilCustomInputGUI($this->lng->txt('ecs_mapping_rcrs'));
1183  $form->addItem($rcrs);
1184 
1185  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1187  $options = $this->prepareFieldSelection($fields);
1188 
1189  // get all optional econtent fields
1190  include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
1192  foreach($optional as $field_name)
1193  {
1194  $select = new ilSelectInputGUI(
1195  $this->lng->txt('ecs_field_'.$field_name),
1196  'mapping['.ilECSDataMappingSetting::MAPPING_IMPORT_RCRS.']['.$field_name.']');
1197  $select->setValue(
1198  $mapping_settings->getMappingByECSName(
1200  $field_name)
1201  );
1202  $select->setOptions($options);
1203  $rcrs->addSubItem($select);
1204  }
1205  return $form;
1206  }
1207 
1212  protected function categoryMapping()
1213  {
1214  $this->tabs_gui->setSubTabActive('ecs_category_mapping');
1215  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.category_mapping.html','Services/WebServices/ECS');
1216 
1217  $this->initRule();
1218  $this->initCategoryMappingForm();
1219 
1220 
1221  $this->tpl->setVariable('NEW_RULE_TABLE',$this->form->getHTML());
1222  if($html = $this->showRulesTable())
1223  {
1224  $this->tpl->setVariable('RULES_TABLE',$html);
1225  }
1226  }
1227 
1232  protected function addCategoryMapping()
1233  {
1234  $this->initRule();
1235 
1236  $this->initCategoryMappingForm('add');
1237  if($this->form->checkInput())
1238  {
1239  $this->rule->setContainerId($this->form->getInput('import_id'));
1240  $this->rule->setFieldName($this->form->getInput('field'));
1241  $this->rule->setMappingType($this->form->getInput('type'));
1242 
1243  switch($this->form->getInput('type'))
1244  {
1246  $this->rule->setMappingValue($this->form->getInput('mapping_value'));
1247  break;
1248 
1250  $this->rule->setDateRangeStart($this->form->getItemByPostVar('dur_begin')->getDate());
1251  $this->rule->setDateRangeEnd($this->form->getItemByPostVar('dur_end')->getDate());
1252  break;
1253 
1255  $this->rule->setByType($this->form->getInput('by_type'));
1256  break;
1257  }
1258 
1259  if($err = $this->rule->validate())
1260  {
1261  ilUtil::sendInfo($this->lng->txt($err));
1262  $this->form->setValuesByPost();
1263  $this->categoryMapping();
1264  return false;
1265  }
1266 
1267  $this->rule->save();
1268  ilUtil::sendInfo($this->lng->txt('settings_saved'));
1269  unset($this->rule);
1270  $this->categoryMapping();
1271  return true;
1272  }
1273  ilUtil::sendInfo($this->lng->txt('err_check_input'));
1274  $this->form->setValuesByPost();
1275  $this->categoryMapping();
1276  return false;
1277  }
1278 
1283  protected function editCategoryMapping()
1284  {
1285  if(!$_REQUEST['rule_id'])
1286  {
1287  ilUtil::sendInfo($this->lng->txt('select_one'));
1288  $this->categoryMapping();
1289  return false;
1290  }
1291 
1292  $this->tabs_gui->setSubTabActive('ecs_category_mapping');
1293  $this->ctrl->saveParameter($this,'rule_id');
1294  $this->initRule((int) $_REQUEST['rule_id']);
1295 
1296  $this->initCategoryMappingForm('edit');
1297  $this->tpl->setContent($this->form->getHTML());
1298  return true;
1299  }
1300 
1305  protected function updateCategoryMapping()
1306  {
1307  if(!$_REQUEST['rule_id'])
1308  {
1309  ilUtil::sendInfo($this->lng->txt('select_one'));
1310  $this->categoryMapping();
1311  return false;
1312  }
1313  $this->ctrl->saveParameter($this,'rule_id');
1314  $this->initRule((int) $_REQUEST['rule_id']);
1315  $this->initCategoryMappingForm('edit');
1316  if($this->form->checkInput())
1317  {
1318  $this->rule->setContainerId($this->form->getInput('import_id'));
1319  $this->rule->setFieldName($this->form->getInput('field'));
1320  $this->rule->setMappingType($this->form->getInput('type'));
1321 
1322  switch($this->form->getInput('type'))
1323  {
1325  $this->rule->setMappingValue($this->form->getInput('mapping_value'));
1326  break;
1327 
1329  $this->rule->setDateRangeStart($this->form->getItemByPostVar('dur_begin')->getDate());
1330  $this->rule->setDateRangeEnd($this->form->getItemByPostVar('dur_end')->getDate());
1331  break;
1332 
1334  $this->rule->setByType($this->form->getInput('by_type'));
1335  break;
1336  }
1337 
1338  if($err = $this->rule->validate())
1339  {
1340  ilUtil::sendInfo($this->lng->txt($err));
1341  $this->form->setValuesByPost();
1342  $this->editCategoryMapping();
1343  return false;
1344  }
1345 
1346  $this->rule->update();
1347  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
1348  $this->ctrl->redirect($this,'categoryMapping');
1349  return true;
1350  }
1351  ilUtil::sendInfo($this->lng->txt('err_check_input'));
1352  $this->form->setValuesByPost();
1353  $this->editCategoryMapping();
1354  return false;
1355 
1356  }
1357 
1361  protected function deleteCategoryMappings()
1362  {
1363  if(!is_array($_POST['rules']) or !$_POST['rules'])
1364  {
1365  ilUtil::sendInfo($this->lng->txt('no_checkbox'));
1366  $this->categoryMapping();
1367  return false;
1368  }
1369  foreach($_POST['rules'] as $rule_id)
1370  {
1371  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1372  $rule = new ilECSCategoryMappingRule($rule_id);
1373  $rule->delete();
1374  }
1375  ilUtil::sendInfo($this->lng->txt('settings_saved'));
1376  $this->categoryMapping();
1377  return true;
1378  }
1379 
1384  protected function showRulesTable()
1385  {
1386  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php';
1387 
1388  if(!$rules = ilECSCategoryMapping::getActiveRules())
1389  {
1390  return false;
1391  }
1392  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingTableGUI.php';
1393  $rule_table = new ilECSCategoryMappingTableGUI($this,'categoryMapping');
1394  $rule_table->parse($rules);
1395  return $rule_table->getHTML();
1396  }
1397 
1403  protected function initRule($a_rule_id = 0)
1404  {
1405  if(is_object($this->rule))
1406  {
1407  return $this->rule;
1408  }
1409 
1410  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1411  $this->rule = new ilECSCategoryMappingRule($a_rule_id);
1412  }
1413 
1418  protected function initCategoryMappingForm($a_mode = 'add')
1419  {
1420  global $ilDB;
1421 
1422  if(is_object($this->form))
1423  {
1424  return true;
1425  }
1426 
1427  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1428  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1429 
1430  $this->form = new ilPropertyFormGUI();
1431 
1432  if($a_mode == 'add')
1433  {
1434  $this->form->setTitle($this->lng->txt('ecs_new_category_mapping'));
1435  $this->form->setFormAction($this->ctrl->getFormAction($this,'categoryMapping'));
1436  $this->form->addCommandButton('addCategoryMapping',$this->lng->txt('save'));
1437  $this->form->addCommandButton('categoryMapping',$this->lng->txt('cancel'));
1438  }
1439  else
1440  {
1441  $this->form->setTitle($this->lng->txt('ecs_edit_category_mapping'));
1442  $this->form->setFormAction($this->ctrl->getFormAction($this,'editCategoryMapping'));
1443  $this->form->addCommandButton('updateCategoryMapping',$this->lng->txt('save'));
1444  $this->form->addCommandButton('categoryMapping',$this->lng->txt('cancel'));
1445  }
1446 
1447  $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'),'import_id');
1448  $imp->setRequired(true);
1449 
1450  $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
1451  $tpl->setVariable('SIZE',5);
1452  $tpl->setVariable('MAXLENGTH',11);
1453  $tpl->setVariable('POST_VAR','import_id');
1454  $tpl->setVariable('PROPERTY_VALUE',$this->rule->getContainerId());
1455 
1456  if($this->settings->getImportId())
1457  {
1458  $tpl->setVariable('COMPLETE_PATH',$this->buildPath($this->rule->getContainerId()));
1459  }
1460 
1461  $imp->setHTML($tpl->get());
1462  $imp->setInfo($this->lng->txt('ecs_import_id_info'));
1463  $this->form->addItem($imp);
1464 
1465  include_once('./Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php');
1466  $select = new ilSelectInputGUI($this->lng->txt('ecs_attribute_name'),'field');
1467  $select->setValue($this->rule->getFieldName());
1468  $select->setRequired(true);
1469  $select->setOptions(ilECSCategoryMapping::getPossibleFields());
1470  $this->form->addItem($select);
1471 
1472  // Value
1473  $value = new ilRadioGroupInputGUI($this->lng->txt('ecs_cat_mapping_type'),'type');
1474  $value->setValue($this->rule->getMappingType());
1475  $value->setRequired(true);
1476 
1477  $fixed = new ilRadioOption($this->lng->txt('ecs_cat_mapping_fixed'),ilECSCategoryMappingRule::TYPE_FIXED);
1478  $fixed->setInfo($this->lng->txt('ecs_cat_mapping_fixed_info'));
1479 
1480  $fixed_val = new ilTextInputGUI($this->lng->txt('ecs_cat_mapping_values'),'mapping_value');
1481  $fixed_val->setValue($this->rule->getMappingValue());
1482  $fixed_val->setMaxLength(255);
1483  $fixed_val->setSize(40);
1484  $fixed_val->setRequired(true);
1485  $fixed->addSubItem($fixed_val);
1486 
1487  $value->addOption($fixed);
1488 
1489  $duration = new ilRadioOption($this->lng->txt('ecs_cat_mapping_duration'),ilECSCategoryMappingRule::TYPE_DURATION);
1490  $duration->setInfo($this->lng->txt('ecs_cat_mapping_duration_info'));
1491 
1492  $dur_start = new ilDateTimeInputGUI($this->lng->txt('from'),'dur_begin');
1493  $dur_start->setDate($this->rule->getDateRangeStart());
1494  $duration->addSubItem($dur_start);
1495 
1496  $dur_end = new ilDateTimeInputGUI($this->lng->txt('to'),'dur_end');
1497  $dur_end->setDate($this->rule->getDateRangeEnd());
1498  $duration->addSubItem($dur_end);
1499 
1500  $value->addOption($duration);
1501 
1502  $type = new ilRadioOption($this->lng->txt('ecs_cat_mapping_by_type'),ilECSCategoryMappingRule::TYPE_BY_TYPE);
1503  $type->setInfo($this->lng->txt('ecs_cat_mapping_by_type_info'));
1504 
1506 
1507  $types = new ilSelectInputGUI($this->lng->txt('type'), 'by_type');
1508  $types->setOptions($options);
1509  $types->setValue($this->rule->getByType());
1510  $types->setRequired(true);
1511  $type->addSubitem($types);
1512 
1513  $value->addOption($type);
1514 
1515  $this->form->addItem($value);
1516 
1517  }
1518 
1519 
1525  protected function imported()
1526  {
1527  global $ilUser, $ilToolbar;
1528 
1529  $this->tabs_gui->setSubTabActive('ecs_import');
1530 
1531  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
1532  if(ilECSServerSettings::getInstance()->activeServerExists())
1533  {
1534  $ilToolbar->addButton(
1535  $this->lng->txt('ecs_read_remote_links'),
1536  $this->ctrl->getLinkTarget($this,'readAll')
1537  );
1538 
1539  $ilToolbar->addSeparator();
1540  }
1541 
1542 
1543  $sel_type = $_REQUEST["otype"];
1544  if(!$sel_type)
1545  {
1546  $sel_type = "rcrs";
1547  }
1548 
1549  include_once './Services/WebServices/ECS/classes/class.ilECSUtils.php';
1551 
1552  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1553  $sel = new ilSelectInputGUI("", "otype");
1554  $sel->setOptions($options);
1555  $sel->setValue($sel_type);
1556  $ilToolbar->addInputItem($sel);
1557 
1558  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "imported"));
1559  $ilToolbar->addFormButton($this->lng->txt("submit"), "imported");
1560 
1561  $robjs = ilUtil::_getObjectsByOperations($sel_type,'visible',$ilUser->getId(),-1);
1562  if(count($robjs))
1563  {
1564  $ilToolbar->addSeparator();
1565 
1566  $ilToolbar->addButton(
1567  $this->lng->txt('csv_export'),
1568  $this->ctrl->getLinkTarget($this,'exportImported')
1569  );
1570  }
1571 
1572  include_once('Services/WebServices/ECS/classes/class.ilECSImportedContentTableGUI.php');
1573  $table_gui = new ilECSImportedContentTableGUI($this,'imported');
1574  $table_gui->setTitle($this->lng->txt('ecs_imported_content'));
1575  $table_gui->parse($robjs);
1576  $this->tpl->setContent($table_gui->getHTML());
1577 
1578  return true;
1579  }
1580 
1587  protected function exportImported()
1588  {
1589  global $ilObjDataCache,$ilUser;
1590 
1591  // :TODO: mind resource type and move to ilRemoteObjectBase...
1592 
1593  $rcourses = ilUtil::_getObjectsByOperations('rcrs','visible',$ilUser->getId(),-1);
1594 
1595  // Read participants
1596  include_once('./Modules/RemoteCourse/classes/class.ilObjRemoteCourse.php');
1597  include_once('./Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
1598  try
1599  {
1601  }
1602  catch(ilECSConnectorException $e)
1603  {
1604  $reader = null;
1605  }
1606 
1607  // read obj_ids
1608  $ilObjDataCache->preloadReferenceCache($rcourses);
1609  $obj_ids = array();
1610  foreach($rcourses as $rcrs_ref_id)
1611  {
1612  $obj_id = $ilObjDataCache->lookupObjId($rcrs_ref_id);
1613  $obj_ids[$obj_id] = $obj_id;
1614  }
1615 
1616  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
1617  $writer = new ilCSVWriter();
1618 
1619  $writer->addColumn($this->lng->txt('title'));
1620  $writer->addColumn($this->lng->txt('description'));
1621  $writer->addColumn($this->lng->txt('ecs_imported_from'));
1622  $writer->addColumn($this->lng->txt('ecs_field_courseID'));
1623  $writer->addColumn($this->lng->txt('ecs_field_term'));
1624  $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
1625  $writer->addColumn($this->lng->txt('ecs_field_courseType'));
1626  $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
1627  $writer->addColumn($this->lng->txt('ecs_field_credits'));
1628  $writer->addColumn($this->lng->txt('ecs_field_room'));
1629  $writer->addColumn($this->lng->txt('ecs_field_cycle'));
1630  $writer->addColumn($this->lng->txt('ecs_field_begin'));
1631  $writer->addColumn($this->lng->txt('ecs_field_end'));
1632  $writer->addColumn($this->lng->txt('last_update'));
1633 
1634  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1636 
1637  foreach($obj_ids as $obj_id)
1638  {
1639  include_once "Services/WebServices/ECS/classes/class.ilECSUtils.php";
1640  $values = ilECSUtils::getAdvancedMDValuesForObjId($obj_id);
1641 
1642  $writer->addRow();
1643  $writer->addColumn(ilObject::_lookupTitle($obj_id));
1644  $writer->addColumn(ilObject::_lookupDescription($obj_id));
1645 
1646  $mid = ilObjRemoteCourse::_lookupMID($obj_id);
1647  if($reader and ($participant = $reader->getParticipantByMID($mid)))
1648  {
1649  $writer->addColumn($participant->getParticipantName());
1650  }
1651  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'courseID');
1652  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1653 
1654  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'term');
1655  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1656 
1657  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'lecturer');
1658  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1659 
1660  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'courseType');
1661  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1662 
1663  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'semester_hours');
1664  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1665 
1666  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'credits');
1667  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1668 
1669  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'room');
1670  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1671 
1672  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'cycle');
1673  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1674 
1675  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'begin');
1676  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1677 
1678  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'end');
1679  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1680 
1681  $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
1682  }
1683  ilUtil::deliverData($writer->getCSVString(), date("Y_m_d")."_ecs_import.csv", "text/csv");
1684  }
1685 
1692  protected function released()
1693  {
1694  global $ilUser, $ilToolbar;
1695 
1696  $this->tabs_gui->setSubTabActive('ecs_released');
1697 
1698  if($this->settings->isEnabled())
1699  {
1700  $ilToolbar->addButton(
1701  $this->lng->txt('ecs_read_remote_links'),
1702  $this->ctrl->getLinkTarget($this,'readAll')
1703  );
1704 
1705  $ilToolbar->addSeparator();
1706  }
1707 
1708  $sel_type = $_REQUEST["otype"];
1709  if(!$sel_type)
1710  {
1711  $sel_type = "rcrs";
1712  }
1713 
1714  include_once "Services/WebServices/ECS/classes/class.ilECSUtils.php";
1716 
1717  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1718  $sel = new ilSelectInputGUI("", "otype");
1719  $sel->setOptions($options);
1720  $sel->setValue($sel_type);
1721  $ilToolbar->addInputItem($sel);
1722 
1723  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "released"));
1724  $ilToolbar->addFormButton($this->lng->txt("submit"), "released");
1725 
1726  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
1727  $exported = ilECSExport::getExportedIdsByType($sel_type);
1728  if(count($exported))
1729  {
1730  $ilToolbar->addSeparator();
1731 
1732  $ilToolbar->addButton(
1733  $this->lng->txt('csv_export'),
1734  $this->ctrl->getLinkTarget($this,'exportReleased')
1735  );
1736  }
1737 
1738  include_once('Services/WebServices/ECS/classes/class.ilECSReleasedContentTableGUI.php');
1739  $table_gui = new ilECSReleasedContentTableGUI($this,'released');
1740  $table_gui->setTitle($this->lng->txt('ecs_released_content'));
1741  $table_gui->parse($exported);
1742  $this->tpl->setContent($table_gui->getHTML());
1743 
1744  return true;
1745  }
1746 
1753  protected function exportReleased()
1754  {
1755  global $ilObjDataCache;
1756 
1757  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
1758  $exported = ilECSExport::getExportedIds();
1759  $ilObjDataCache->preloadObjectCache($exported);
1760 
1761  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
1762  $writer = new ilCSVWriter();
1763 
1764  $writer->addColumn($this->lng->txt('title'));
1765  $writer->addColumn($this->lng->txt('description'));
1766  $writer->addColumn($this->lng->txt('ecs_field_courseID'));
1767  $writer->addColumn($this->lng->txt('ecs_field_term'));
1768  $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
1769  $writer->addColumn($this->lng->txt('ecs_field_courseType'));
1770  $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
1771  $writer->addColumn($this->lng->txt('ecs_field_credits'));
1772  $writer->addColumn($this->lng->txt('ecs_field_room'));
1773  $writer->addColumn($this->lng->txt('ecs_field_cycle'));
1774  $writer->addColumn($this->lng->txt('ecs_field_begin'));
1775  $writer->addColumn($this->lng->txt('ecs_field_end'));
1776  $writer->addColumn($this->lng->txt('last_update'));
1777 
1778  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1780 
1781  foreach($exported as $obj_id)
1782  {
1783  include_once "Services/WebServices/ECS/classes/class.ilECSUtils.php";
1784  $values = ilECSUtils::getAdvancedMDValuesForObjId($obj_id);
1785 
1786  $writer->addRow();
1787  $writer->addColumn(ilObject::_lookupTitle($obj_id));
1788  $writer->addColumn(ilObject::_lookupDescription($obj_id));
1789 
1790  $field = $settings->getMappingByECSName(0, 'courseID');
1791  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1792 
1793  $field = $settings->getMappingByECSName(0,'term');
1794  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1795 
1796  $field = $settings->getMappingByECSName(0,'lecturer');
1797  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1798 
1799  $field = $settings->getMappingByECSName(0,'courseType');
1800  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1801 
1802  $field = $settings->getMappingByECSName(0,'semester_hours');
1803  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1804 
1805  $field = $settings->getMappingByECSName(0,'credits');
1806  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1807 
1808  $field = $settings->getMappingByECSName(0,'room');
1809  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1810 
1811  $field = $settings->getMappingByECSName(0,'cycle');
1812  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1813 
1814  $field = $settings->getMappingByECSName(0,'begin');
1815  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1816 
1817  $field = $settings->getMappingByECSName(0,'end');
1818  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1819 
1820  $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
1821  }
1822 
1823  ilUtil::deliverData($writer->getCSVString(), date("Y_m_d")."_ecs_export.csv", "text/csv");
1824  }
1825 
1826 
1832  protected function prepareFieldSelection($fields)
1833  {
1834  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
1835 
1836  $options[0] = $this->lng->txt('ecs_ignore_field');
1837  foreach($fields as $field)
1838  {
1839  $title = ilAdvancedMDRecord::_lookupTitle($field->getRecordId());
1840  $options[$field->getFieldId()] = $title.': '.$field->getTitle();
1841  }
1842  return $options;
1843  }
1844 
1845 
1846 
1852  protected function initSettings($a_server_id = 1)
1853  {
1854  include_once('Services/WebServices/ECS/classes/class.ilECSSetting.php');
1855  $this->settings = ilECSSetting::getInstanceByServerId($a_server_id);
1856  }
1857 
1863  protected function setSubTabs()
1864  {
1865  $this->tabs_gui->clearSubTabs();
1866 
1867  $this->tabs_gui->addSubTabTarget("overview",
1868  $this->ctrl->getLinkTarget($this,'overview'),
1869  "overview",get_class($this));
1870 
1871  // Disable all other tabs, if server hasn't been configured.
1872  #ilECSServerSettings::getInstance()->readInactiveServers();
1873  if(!ilECSServerSettings::getInstance()->serverExists())
1874  {
1875  return true;
1876  }
1877 
1878  $this->tabs_gui->addSubTabTarget("ecs_communities",
1879  $this->ctrl->getLinkTarget($this,'communities'),
1880  "communities",get_class($this));
1881 
1882  $this->tabs_gui->addSubTabTarget('ecs_mappings',
1883  $this->ctrl->getLinkTarget($this,'importMappings'),
1884  'importMappings',get_class($this));
1885 
1886  $this->tabs_gui->addSubTabTarget('ecs_category_mapping',
1887  $this->ctrl->getLinkTarget($this,'categoryMapping'));
1888 
1889  $this->tabs_gui->addSubTabTarget('ecs_import',
1890  $this->ctrl->getLinkTarget($this,'imported'));
1891 
1892  $this->tabs_gui->addSubTabTarget('ecs_released',
1893  $this->ctrl->getLinkTarget($this,'released'));
1894 
1895  }
1896 
1902  private function prepareRoleSelect()
1903  {
1904  global $rbacreview,$ilObjDataCache;
1905 
1906  $global_roles = ilUtil::_sortIds($rbacreview->getGlobalRoles(),
1907  'object_data',
1908  'title',
1909  'obj_id');
1910 
1911  $select[0] = $this->lng->txt('links_select_one');
1912  foreach($global_roles as $role_id)
1913  {
1914  $select[$role_id] = ilObject::_lookupTitle($role_id);
1915  }
1916  return $select;
1917  }
1918 
1919  private function buildPath($a_ref_id)
1920  {
1921  $loc = new ilLocatorGUI();
1922  $loc->setTextOnly(false);
1923  $loc->addContextItems($a_ref_id);
1924 
1925  return $loc->getHTML();
1926  }
1927 
1933  protected function initTaskScheduler()
1934  {
1935  global $ilDB,$ilSetting;
1936 
1937  #$ilDB->lockTables(array('name' => 'settings', 'type' => ilDB::LOCK_WRITE));
1938  $setting = new ilSetting('ecs');
1939  $setting->set(
1940  'next_execution_'.$this->settings->getServerId(),
1941  time() + (int) $this->settings->getPollingTime()
1942  );
1943  }
1944 
1945 }
1946 
1947 ?>