ILIAS  release_4-3 Revision
 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  default:
88  if(!$cmd || $cmd == 'view')
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->setContent($this->form->getHTML());
210  }
211 
215  protected function edit()
216  {
217  global $ilTabs;
218 
219  $this->initSettings((int) $_REQUEST['server_id']);
220  $this->ctrl->saveParameter($this,'server_id',(int) $_REQUEST['server_id']);
221 
222  $ilTabs->clearTargets();
223  $ilTabs->clearSubTabs();
224  $ilTabs->setBackTarget($this->lng->txt('back'),$this->ctrl->getLinkTarget($this,'overview'));
225 
226  $this->initSettingsForm();
227  $this->tabs_gui->setSubTabActive('ecs_settings');
228 
229  $this->tpl->setContent($this->form->getHTML());
230  }
231 
232  protected function cp()
233  {
234  $this->initSettings((int) $_REQUEST['server_id']);
235 
236  $copy = clone $this->settings;
237  $copy->save();
238 
239  $this->ctrl->setParameter($this,'server_id',$copy->getServerId());
240  ilUtil::sendSuccess($this->lng->txt('ecs_settings_cloned'),true);
241  $this->ctrl->redirect($this,'edit');
242  }
243 
247  protected function delete()
248  {
249  global $ilTabs;
250 
251  $this->initSettings((int) $_REQUEST['server_id']);
252 
253  $ilTabs->clearTargets();
254  $ilTabs->clearSubTabs();
255  $ilTabs->setBackTarget($this->lng->txt('back'),$this->ctrl->getLinkTarget($this,'overview'));
256 
257  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
258  $confirm = new ilConfirmationGUI();
259  $confirm->setFormAction($this->ctrl->getFormAction($this));
260  $confirm->setConfirm($this->lng->txt('delete'), 'doDelete');
261  $confirm->setCancel($this->lng->txt('cancel'), 'overview');
262  $confirm->setHeaderText($this->lng->txt('ecs_delete_setting'));
263 
264  $confirm->addItem('','',$this->settings->getServer());
265  $confirm->addHiddenItem('server_id', $this->settings->getServerId());
266 
267  $this->tpl->setContent($confirm->getHTML());
268  }
269 
273  protected function doDelete()
274  {
275  $this->initSettings($_REQUEST['server_id']);
276  $this->settings->delete();
277 
278  // Delete communities
279  include_once './Services/WebServices/ECS/classes/class.ilECSCommunitiesCache.php';
280  ilECSCommunitiesCache::delete((int) $_REQUEST['server_id']);
281 
282  include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php';
283  ilECSDataMappingSettings::delete((int) $_REQUEST['server_id']);
284 
285  include_once './Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php';
286  ilECSEventQueueReader::deleteServer((int) $_REQUEST['server_id']);
287 
288  include_once './Services/WebServices/ECS/classes/class.ilECSExport.php';
289  ilECSExport::deleteByServer((int) $_REQUEST['server_id']);
290 
291  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
292  ilECSImport::deleteByServer((int) $_REQUEST['server_id']);
293 
294  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
295  ilECSParticipantSettings::deleteByServer((int) $_REQUEST['server_id']);
296 
297  ilUtil::sendSuccess($this->lng->txt('ecs_setting_deleted'),true);
298  $this->ctrl->redirect($this,'overview');
299  }
300 
301 
307  protected function settings()
308  {
309  $this->initSettingsForm();
310  $this->tabs_gui->setSubTabActive('ecs_settings');
311 
312  $this->tpl->setContent($this->form->getHTML());
313  }
314 
320  protected function initSettingsForm($a_mode = 'update')
321  {
322  if(is_object($this->form))
323  {
324  return true;
325  }
326  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
327 
328  $this->form = new ilPropertyFormGUI();
329  $this->form->setFormAction($this->ctrl->getFormAction($this,'settings'));
330  $this->form->setTitle($this->lng->txt('ecs_connection_settings'));
331 
332  $ena = new ilCheckboxInputGUI($this->lng->txt('ecs_active'),'active');
333  $ena->setChecked($this->settings->isEnabled());
334  $ena->setValue(1);
335  $this->form->addItem($ena);
336 
337  $ser = new ilTextInputGUI($this->lng->txt('ecs_server_url'),'server');
338  $ser->setValue((string) $this->settings->getServer());
339  $ser->setRequired(true);
340  $this->form->addItem($ser);
341 
342  $pro = new ilSelectInputGUI($this->lng->txt('ecs_protocol'),'protocol');
343  // fixed to https
344  #$pro->setOptions(array(ilECSSetting::PROTOCOL_HTTP => $this->lng->txt('http'),
345  # ilECSSetting::PROTOCOL_HTTPS => $this->lng->txt('https')));
346  $pro->setOptions(array(ilECSSetting::PROTOCOL_HTTPS => 'HTTPS'));
347  $pro->setValue($this->settings->getProtocol());
348  $pro->setRequired(true);
349  $this->form->addItem($pro);
350 
351  $por = new ilTextInputGUI($this->lng->txt('ecs_port'),'port');
352  $por->setSize(5);
353  $por->setMaxLength(5);
354  $por->setValue((string) $this->settings->getPort());
355  $por->setRequired(true);
356  $this->form->addItem($por);
357 
358  $tcer = new ilRadioGroupInputGUI($this->lng->txt('ecs_auth_type'),'auth_type');
359  $tcer->setValue($this->settings->getAuthType());
360  $this->form->addItem($tcer);
361 
362  // Certificate based authentication
363  $cert_based = new ilRadioOption($this->lng->txt('ecs_auth_type_cert'), ilECSSetting::AUTH_CERTIFICATE);
364  $tcer->addOption($cert_based);
365 
366  $cli = new ilTextInputGUI($this->lng->txt('ecs_client_cert'),'client_cert');
367  $cli->setSize(60);
368  $cli->setValue((string) $this->settings->getClientCertPath());
369  $cli->setRequired(true);
370  $cert_based->addSubItem($cli);
371 
372  $key = new ilTextInputGUI($this->lng->txt('ecs_cert_key'),'key_path');
373  $key->setSize(60);
374  $key->setValue((string) $this->settings->getKeyPath());
375  $key->setRequired(true);
376  $cert_based->addSubItem($key);
377 
378  $cerp = new ilTextInputGUI($this->lng->txt('ecs_key_password'),'key_password');
379  $cerp->setSize(12);
380  $cerp->setValue((string) $this->settings->getKeyPassword());
381  $cerp->setInputType('password');
382  $cerp->setRequired(true);
383  $cert_based->addSubItem($cerp);
384 
385  $cer = new ilTextInputGUI($this->lng->txt('ecs_ca_cert'),'ca_cert');
386  $cer->setSize(60);
387  $cer->setValue((string) $this->settings->getCACertPath());
388  $cer->setRequired(true);
389  $cert_based->addSubItem($cer);
390 
391  // Apache auth
392  $apa_based = new ilRadioOption($this->lng->txt('ecs_auth_type_apache'), ilECSSetting::AUTH_APACHE);
393  $tcer->addOption($apa_based);
394 
395  $user = new ilTextInputGUI($this->lng->txt('ecs_apache_user'),'auth_user');
396  $user->setSize(32);
397  $user->setValue((string) $this->settings->getAuthUser());
398  $user->setRequired(true);
399  $apa_based->addSubItem($user);
400 
401  $pass = new ilPasswordInputGUI($this->lng->txt('ecs_apache_pass'), 'auth_pass');
402  $pass->setRetype(false);
403  $pass->setSize(16);
404  $pass->setMaxLength(32);
405  $pass->setValue((string) $this->settings->getAuthPass());
406  $pass->setRequired(true);
407  $apa_based->addSubItem($pass);
408 
409 
410  $ser = new ilNonEditableValueGUI($this->lng->txt('cert_serial'));
411  $ser->setValue($this->settings->getCertSerialNumber() ? $this->settings->getCertSerialNumber() : $this->lng->txt('ecs_no_value'));
412  $cert_based->addSubItem($ser);
413 
414  $loc = new ilFormSectionHeaderGUI();
415  $loc->setTitle($this->lng->txt('ecs_local_settings'));
416  $this->form->addItem($loc);
417 
418  $pol = new ilDurationInputGUI($this->lng->txt('ecs_polling'),'polling');
419  $pol->setShowDays(false);
420  $pol->setShowHours(false);
421  $pol->setShowMinutes(true);
422  $pol->setShowSeconds(true);
423  $pol->setSeconds($this->settings->getPollingTimeSeconds());
424  $pol->setMinutes($this->settings->getPollingTimeMinutes());
425  $pol->setRequired(true);
426  $pol->setInfo($this->lng->txt('ecs_polling_info'));
427  $this->form->addItem($pol);
428 
429  $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'));
430  $imp->setRequired(true);
431 
432  $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
433  $tpl->setVariable('SIZE',5);
434  $tpl->setVariable('MAXLENGTH',11);
435  $tpl->setVariable('POST_VAR','import_id');
436  $tpl->setVariable('PROPERTY_VALUE',$this->settings->getImportId());
437 
438  if($this->settings->getImportId())
439  {
440  $tpl->setVariable('COMPLETE_PATH',$this->buildPath($this->settings->getImportId()));
441  }
442 
443  $imp->setHTML($tpl->get());
444  $imp->setInfo($this->lng->txt('ecs_import_id_info'));
445  $this->form->addItem($imp);
446 
447  $loc = new ilFormSectionHeaderGUI();
448  $loc->setTitle($this->lng->txt('ecs_remote_user_settings'));
449  $this->form->addItem($loc);
450 
451  $role = new ilSelectInputGUI($this->lng->txt('ecs_role'),'global_role');
452  $role->setOptions($this->prepareRoleSelect());
453  $role->setValue($this->settings->getGlobalRole());
454  $role->setInfo($this->lng->txt('ecs_global_role_info'));
455  $role->setRequired(true);
456  $this->form->addItem($role);
457 
458  $duration = new ilDurationInputGUI($this->lng->txt('ecs_account_duration'),'duration');
459  $duration->setInfo($this->lng->txt('ecs_account_duration_info'));
460  $duration->setMonths($this->settings->getDuration());
461  $duration->setShowSeconds(false);
462  $duration->setShowMinutes(false);
463  $duration->setShowHours(false);
464  $duration->setShowDays(false);
465  $duration->setShowMonths(true);
466  $duration->setRequired(true);
467  $this->form->addItem($duration);
468 
469  // Email recipients
470  $loc = new ilFormSectionHeaderGUI();
471  $loc->setTitle($this->lng->txt('ecs_notifications'));
472  $this->form->addItem($loc);
473 
474  $rcp_user = new ilTextInputGUI($this->lng->txt('ecs_user_rcp'),'user_recipients');
475  $rcp_user->setValue((string) $this->settings->getUserRecipientsAsString());
476  $rcp_user->setInfo($this->lng->txt('ecs_user_rcp_info'));
477  $this->form->addItem($rcp_user);
478 
479  $rcp_econ = new ilTextInputGUI($this->lng->txt('ecs_econ_rcp'),'econtent_recipients');
480  $rcp_econ->setValue((string) $this->settings->getEContentRecipientsAsString());
481  $rcp_econ->setInfo($this->lng->txt('ecs_econ_rcp_info'));
482  $this->form->addItem($rcp_econ);
483 
484  $rcp_app = new ilTextInputGUI($this->lng->txt('ecs_approval_rcp'),'approval_recipients');
485  $rcp_app->setValue((string) $this->settings->getApprovalRecipientsAsString());
486  $rcp_app->setInfo($this->lng->txt('ecs_approval_rcp_info'));
487  $this->form->addItem($rcp_app);
488 
489  if($a_mode == 'update')
490  {
491  $this->form->addCommandButton('update',$this->lng->txt('save'));
492  }
493  else
494  {
495  $this->form->addCommandButton('save',$this->lng->txt('save'));
496  }
497  $this->form->addCommandButton('overview',$this->lng->txt('cancel'));
498  }
499 
505  protected function update()
506  {
507  $this->initSettings((int) $_REQUEST['server_id']);
508  $this->loadFromPost();
509 
510  if(!$error = $this->settings->validate())
511  {
512  $this->settings->update();
513  $this->initTaskScheduler();
514  $this->updateTitle();
515  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
516  }
517  else
518  {
519  ilUtil::sendInfo($this->lng->txt($error));
520  $this->edit();
521  }
522 
523  $this->overview();
524  return true;
525  }
526 
531  protected function save()
532  {
533  $this->initSettings(0);
534  $this->loadFromPost();
535 
536  if(!$error = $this->settings->validate())
537  {
538  $this->settings->save();
539  $this->initTaskScheduler();
540 
541  $this->updateTitle();
542  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
543  }
544  else
545  {
546  ilUtil::sendInfo($this->lng->txt($error));
547  return $this->create();
548  }
549  $GLOBALS['ilCtrl']->redirect($this,'overview');
550  return true;
551  }
552 
556  protected function updateTitle()
557  {
558  try
559  {
560  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
562 
563  foreach($reader->getCommunities() as $community)
564  {
565  foreach($community->getParticipants() as $part)
566  {
567  if($part->isSelf())
568  {
569  $this->settings->setTitle($part->getParticipantName());
570  $this->settings->update();
571  return true;
572  }
573  }
574  }
575  }
576  catch(ilECSConnectorException $exc)
577  {
578  ilUtil::sendFailure($exc->getMessage());
579  }
580  $this->settings->setTitle('');
581  $this->settings->update();
582  }
583 
587  protected function loadFromPost()
588  {
589  $this->settings->setEnabledStatus((int) $_POST['active']);
590  //$this->settings->setTitle(ilUtil::stripSlashes($_POST['title']));
591  $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
592  $this->settings->setPort(ilUtil::stripSlashes($_POST['port']));
593  $this->settings->setProtocol(ilUtil::stripSlashes($_POST['protocol']));
594  $this->settings->setClientCertPath(ilUtil::stripSlashes($_POST['client_cert']));
595  $this->settings->setCACertPath(ilUtil::stripSlashes($_POST['ca_cert']));
596  $this->settings->setKeyPath(ilUtil::stripSlashes($_POST['key_path']));
597  $this->settings->setKeyPassword(ilUtil::stripSlashes($_POST['key_password']));
598  $this->settings->setImportId(ilUtil::stripSlashes($_POST['import_id']));
599  $this->settings->setPollingTimeMS((int) $_POST['polling']['mm'],(int) $_POST['polling']['ss']);
600  $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
601  $this->settings->setGlobalRole((int) $_POST['global_role']);
602  $this->settings->setDuration((int) $_POST['duration']['MM']);
603 
604  $this->settings->setUserRecipients(ilUtil::stripSlashes($_POST['user_recipients']));
605  $this->settings->setEContentRecipients(ilUtil::stripSlashes($_POST['econtent_recipients']));
606  $this->settings->setApprovalRecipients(ilUtil::stripSlashes($_POST['approval_recipients']));
607 
608  $this->settings->setAuthType((int) $_POST['auth_type']);
609  $this->settings->setAuthPass(ilUtil::stripSlashes($_POST['auth_pass']));
610  $this->settings->setAuthUser(ilUtil::stripSlashes($_POST['auth_user']));
611 
612  }
613 
620  public function communities()
621  {
622  $this->tabs_gui->setSubTabActive('ecs_communities');
623 
624  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_communities.html','Services/WebServices/ECS');
625 
626  $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this,'updateCommunities'));
627  $this->tpl->setVariable('TXT_SAVE',$this->lng->txt('save'));
628  $this->tpl->setVariable('TXT_CANCEL', $this->lng->txt('cancel'));
629 
630  include_once('Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
631  include_once('Services/WebServices/ECS/classes/class.ilECSCommunityTableGUI.php');
632 
633  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
634  $settings = ilECSServerSettings::getInstance();
635  $settings->readInactiveServers();
636 
637  foreach($settings->getServers() as $server)
638  {
639  // Try to read communities
640  try
641  {
643  foreach($reader->getCommunities() as $community)
644  {
645  $this->tpl->setCurrentBlock('table_community');
646  $table_gui = new ilECSCommunityTableGUI($server,$this,'communities',$community->getId());
647  $table_gui->setTitle($community->getTitle().' ('.$community->getDescription().')');
648  $table_gui->parse($community->getParticipants());
649  $this->tpl->setVariable('TABLE_COMM',$table_gui->getHTML());
650  $this->tpl->parseCurrentBlock();
651  }
652  }
653  catch(ilECSConnectorException $exc)
654  {
655  // Maybe server is not fully configured
656  continue;
657  }
658 
659  // Show section for each server
660  $this->tpl->setCurrentBlock('server');
661  $this->tpl->setVariable('TXT_SERVER_NAME',$server->getTitle());
662  $this->tpl->parseCurrentBlock();
663  }
664  }
665 
671  protected function validateImportTypes(&$import_types)
672  {
673  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
674 
675  $num_cms = 0;
676  foreach((array) $import_types as $sid => $server)
677  {
678  foreach((array) $server as $mid => $import_type)
679  {
680  if($import_type == ilECSParticipantSetting::IMPORT_CMS)
681  {
682  ++$num_cms;
683  }
684  }
685  }
686 
687  if($num_cms <= 1)
688  {
689  return true;
690  }
691  // Change to import type "UNCHANGED"
692  $new_types = array();
693  foreach((array) $import_types as $sid => $server)
694  {
695  foreach((array) $server as $mid => $import_type)
696  {
697  if($import_type == ilECSParticipantSetting::IMPORT_CMS)
698  {
699  $new_types[$sid][$mid] = ilECSParticipantSetting::IMPORT_UNCHANGED;
700  }
701  else
702  {
703  $new_types[$sid][$mid] = $import_type;
704  }
705  }
706  }
707  $import_types = $new_types;
708  return false;
709  }
710 
717  protected function updateCommunities()
718  {
719  global $ilLog;
720 
721  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
722  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
723 
724  // @TODO: Delete deprecated communities
725  $invalidImportTypes = false;
726  if(!$this->validateImportTypes($_POST['import_type']))
727  {
728  $invalidImportTypes = true;
729  }
730 
732  foreach($servers->getServers() as $server)
733  {
734  try {
735  // Read communities
736  $cReader = ilECSCommunityReader::getInstanceByServerId($server->getServerId());
737 
738  // Update community cache
739  foreach($cReader->getCommunities() as $community)
740  {
741  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityCache.php';
742  $cCache = ilECSCommunityCache::getInstance($server->getServerId(), $community->getId());
743  $cCache->setCommunityName($community->getTitle());
744  $cCache->setMids($community->getMids());
745  $cCache->setOwnId($community->getOwnId());
746  $cCache->update();
747  }
748  }
749  catch(Exception $e)
750  {
751  $GLOBALS['ilLog']->write(__METHOD__.': Cannot read ecs communities: '.$e->getMessage());
752  }
753  }
754 
755  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
756  foreach((array) $_POST['sci_mid'] as $sid => $tmp)
757  {
758  foreach((array) $_POST['sci_mid'][$sid] as $mid => $tmp)
759  {
760  $set = new ilECSParticipantSetting($sid, $mid);
761  $set->enableExport(array_key_exists($mid, (array) $_POST['export'][$sid]) ? true : false);
762  $set->enableImport(array_key_exists($mid, (array) $_POST['import'][$sid]) ? true : false);
763  $set->setImportType($_POST['import_type'][$sid][$mid]);
764 
765  // update title/cname
766  try {
767  $part = ilECSCommunityReader::getInstanceByServerId($sid)->getParticipantByMID($mid);
768  if($part instanceof ilECSParticipant)
769  {
770  $set->setTitle($part->getParticipantName());
771  }
772  $com = ilECSCommunityReader::getInstanceByServerId($sid)->getCommunityByMID($mid);
773  if($com instanceof ilECSCommunity)
774  {
775  $set->setCommunityName($com->getTitle());
776  }
777  }
778  catch(Exception $e)
779  {
780  $GLOBALS['ilLog']->write(__METHOD__.': Cannot read ecs communities: '.$e->getMessage());
781  }
782 
783  $set->update();
784  }
785  }
786  if($invalidImportTypes)
787  {
788  ilUtil::sendFailure($this->lng->txt('ecs_invalid_import_type_cms'),true);
789  }
790  else
791  {
792  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
793  }
794  $GLOBALS['ilCtrl']->redirect($this,'communities');
795 
796  // TODO: Do update of remote courses and ...
797 
798  return true;
799  }
800 
801 
807  protected function setMappingTabs($a_active)
808  {
809  global $ilTabs;
810 
811  $ilTabs->clearTargets();
812  $ilTabs->clearSubTabs();
813 
814  $ilTabs->setBackTarget(
815  $this->lng->txt('ecs_settings'),
816  $this->ctrl->getLinkTarget($this,'overview')
817  );
818  $ilTabs->addTab(
819  'import',
820  $this->lng->txt('ecs_tab_import'),
821  $this->ctrl->getLinkTarget($this,'importMappings')
822  );
823  $ilTabs->addTab(
824  'export',
825  $this->lng->txt('ecs_tab_export'),
826  $this->ctrl->getLinkTarget($this,'exportMappings')
827  );
828 
829 
830  switch($a_active)
831  {
832  case self::MAPPING_IMPORT:
833  $ilTabs->activateTab('import');
834  break;
835 
836  case self::MAPPING_EXPORT:
837  $ilTabs->activateTab('export');
838  break;
839  }
840  return true;
841  }
842 
848  public function importMappings()
849  {
850  global $ilToolbar;
851 
852  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
853 
854  $this->setMappingTabs(self::MAPPING_IMPORT);
855 
857  if(!count($fields))
858  {
859  ilUtil::sendInfo($this->lng->txt('ecs_no_adv_md'));
860  return true;
861  }
862 
863  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
864  $settings = ilECSServerSettings::getInstance();
865  $settings->readInactiveServers();
866 
867  $sel_srv = (int)$_REQUEST["ecs_mapping_server"];
868  if(!$sel_srv)
869  {
870  $sel_srv = $_SESSION["ecs_sel_srv"];
871  }
872  else
873  {
874  $_SESSION["ecs_sel_srv"] = $sel_srv;
875  }
876 
877  // Iterate all servers
878  $options = array(0 => $this->lng->txt("please_choose"));
879  foreach($settings->getServers() as $server)
880  {
881  $title = $server->getTitle();
882  if(!$title)
883  {
884  $title = "ECS (".$server->getServerId().")";
885  }
886  $options[$server->getServerId()] = $title;
887  }
888 
889  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
890  $sel = new ilSelectInputGUI("", "ecs_mapping_server");
891  $sel->setOptions($options);
892  $sel->setValue($sel_srv);
893  $ilToolbar->addInputItem($sel);
894 
895  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "importMappings"));
896  $ilToolbar->addFormButton($this->lng->txt("submit"), "importMappings");
897 
898  if($sel_srv)
899  {
900  $form = $this->initMappingsForm($sel_srv, self::MAPPING_IMPORT);
901  $this->tpl->setContent($form->getHTML());
902  }
903 
904  return true;
905  }
906 
912  protected function exportMappings()
913  {
914  global $ilToolbar;
915 
916  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
917 
918  $this->setMappingTabs(self::MAPPING_EXPORT);
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, "exportMappings"));
960  $ilToolbar->addFormButton($this->lng->txt("submit"), "exportMappings");
961 
962  if($sel_srv)
963  {
964  $form = $this->initMappingsForm($sel_srv,self::MAPPING_EXPORT);
965  $this->tpl->setContent($form->getHTML());
966  }
967 
968  return true;
969  }
970 
977  protected function saveImportMappings()
978  {
979  foreach((array) $_POST['mapping'] as $mtype => $mappings)
980  {
981  foreach((array) $mappings as $ecs_field => $advmd_id)
982  {
983  include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSetting.php';
984  $map = new ilECSDataMappingSetting(
985  (int) $_POST['ecs_mapping_server'],
986  (int) $mtype,
987  $ecs_field
988  );
989  $map->setAdvMDId($advmd_id);
990  $map->save();
991  }
992  }
993 
994  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
995  $this->ctrl->setParameter($this, "ecs_mapping_server", (int)$_POST['ecs_mapping_server']);
996  $this->ctrl->redirect($this,'importMappings');
997  return true;
998  }
999 
1006  protected function saveExportMappings()
1007  {
1008  foreach((array) $_POST['mapping'] as $mtype => $mappings)
1009  {
1010  foreach((array) $mappings as $ecs_field => $advmd_id)
1011  {
1012  include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSetting.php';
1013  $map = new ilECSDataMappingSetting(
1014  (int) $_POST['ecs_mapping_server'],
1015  (int) $mtype,
1016  $ecs_field
1017  );
1018  $map->setAdvMDId($advmd_id);
1019  $map->save();
1020  }
1021  }
1022 
1023  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
1024  $this->ctrl->setParameter($this, "ecs_mapping_server", (int)$_POST['ecs_mapping_server']);
1025  $this->ctrl->redirect($this,'exportMappings');
1026  return true;
1027  }
1028 
1037  protected function initMappingsForm($a_server_id,$mapping_type)
1038  {
1039  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
1040 
1041  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1042  $mapping_settings = ilECSDataMappingSettings::getInstanceByServerId($a_server_id);
1043 
1044  $form = new ilPropertyFormGUI();
1045 
1046  if($mapping_type == self::MAPPING_IMPORT)
1047  {
1048  $form->setTitle($this->lng->txt('ecs_mapping_tbl'));
1049  $form->addCommandButton('saveImportMappings',$this->lng->txt('save'));
1050  $form->addCommandButton('importMappings',$this->lng->txt('cancel'));
1051  }
1052  else
1053  {
1054  $form->setTitle($this->lng->txt('ecs_mapping_exp_tbl'));
1055  $form->addCommandButton('saveExportMappings',$this->lng->txt('save'));
1056  $form->addCommandButton('exportMappings',$this->lng->txt('cancel'));
1057  }
1058 
1059  $form->setFormAction($this->ctrl->getFormAction($this,'saveMappings'));
1060 
1061  if($mapping_type == self::MAPPING_IMPORT)
1062  {
1063  $assignments = new ilCustomInputGUI($this->lng->txt('ecs_mapping_crs'));
1064  $form->addItem($assignments);
1065  }
1066 
1067  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1069  $options = $this->prepareFieldSelection($fields);
1070 
1071  // get all optional ecourse fields
1072  include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
1074  foreach($optional as $field_name)
1075  {
1076  if($mapping_type == self::MAPPING_IMPORT)
1077  {
1078  $select = new ilSelectInputGUI(
1079  $this->lng->txt('ecs_field_'.$field_name),
1080  'mapping'.'['.ilECSDataMappingSetting::MAPPING_IMPORT_CRS.']['.$field_name.']'
1081  );
1082 
1083  $select->setValue(
1084  $mapping_settings->getMappingByECSName(
1086  $field_name)
1087  );
1088  $select->setOptions($options);
1089  $assignments->addSubItem($select);
1090  }
1091  else
1092  {
1093  $select = new ilSelectInputGUI(
1094  $this->lng->txt('ecs_field_'.$field_name),
1095  'mapping'.'['.ilECSDataMappingSetting::MAPPING_EXPORT.']['.$field_name.']'
1096  );
1097  $select->setValue(
1098  $mapping_settings->getMappingByECSName(
1100  $field_name)
1101  );
1102  $select->setOptions($options);
1103  $form->addItem($select);
1104  }
1105  }
1106 
1107  $server = new ilHiddenInputGUI('ecs_mapping_server');
1108  $server->setValue($a_server_id);
1109  $form->addItem($server);
1110 
1111  // Remote courses
1112  // no remote course settings for export
1113  if($mapping_type == self::MAPPING_EXPORT)
1114  {
1115  return $form;
1116  }
1117 
1118  $rcrs = new ilCustomInputGUI($this->lng->txt('ecs_mapping_rcrs'));
1119  $form->addItem($rcrs);
1120 
1121  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1123  $options = $this->prepareFieldSelection($fields);
1124 
1125  // get all optional econtent fields
1126  include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
1128  foreach($optional as $field_name)
1129  {
1130  $select = new ilSelectInputGUI(
1131  $this->lng->txt('ecs_field_'.$field_name),
1132  'mapping['.ilECSDataMappingSetting::MAPPING_IMPORT_RCRS.']['.$field_name.']');
1133  $select->setValue(
1134  $mapping_settings->getMappingByECSName(
1136  $field_name)
1137  );
1138  $select->setOptions($options);
1139  $rcrs->addSubItem($select);
1140  }
1141  return $form;
1142  }
1143 
1148  protected function categoryMapping()
1149  {
1150  $this->tabs_gui->setSubTabActive('ecs_category_mapping');
1151  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.category_mapping.html','Services/WebServices/ECS');
1152 
1153  $this->initRule();
1154  $this->initCategoryMappingForm();
1155 
1156 
1157  $this->tpl->setVariable('NEW_RULE_TABLE',$this->form->getHTML());
1158  if($html = $this->showRulesTable())
1159  {
1160  $this->tpl->setVariable('RULES_TABLE',$html);
1161  }
1162  }
1163 
1168  protected function addCategoryMapping()
1169  {
1170  $this->initRule();
1171 
1172  $this->initCategoryMappingForm('add');
1173  if($this->form->checkInput())
1174  {
1175  $this->rule->setContainerId($this->form->getInput('import_id'));
1176  $this->rule->setFieldName($this->form->getInput('field'));
1177  $this->rule->setMappingType($this->form->getInput('type'));
1178 
1179  switch($this->form->getInput('type'))
1180  {
1182  $this->rule->setMappingValue($this->form->getInput('mapping_value'));
1183  break;
1184 
1186  $this->rule->setDateRangeStart($this->form->getItemByPostVar('dur_begin')->getDate());
1187  $this->rule->setDateRangeEnd($this->form->getItemByPostVar('dur_end')->getDate());
1188  break;
1189 
1191  $this->rule->setByType($this->form->getInput('by_type'));
1192  break;
1193  }
1194 
1195  if($err = $this->rule->validate())
1196  {
1197  ilUtil::sendInfo($this->lng->txt($err));
1198  $this->form->setValuesByPost();
1199  $this->categoryMapping();
1200  return false;
1201  }
1202 
1203  $this->rule->save();
1204  ilUtil::sendInfo($this->lng->txt('settings_saved'));
1205  unset($this->rule);
1206  $this->categoryMapping();
1207  return true;
1208  }
1209  ilUtil::sendInfo($this->lng->txt('err_check_input'));
1210  $this->form->setValuesByPost();
1211  $this->categoryMapping();
1212  return false;
1213  }
1214 
1219  protected function editCategoryMapping()
1220  {
1221  if(!$_REQUEST['rule_id'])
1222  {
1223  ilUtil::sendInfo($this->lng->txt('select_one'));
1224  $this->categoryMapping();
1225  return false;
1226  }
1227 
1228  $this->tabs_gui->setSubTabActive('ecs_category_mapping');
1229  $this->ctrl->saveParameter($this,'rule_id');
1230  $this->initRule((int) $_REQUEST['rule_id']);
1231 
1232  $this->initCategoryMappingForm('edit');
1233  $this->tpl->setContent($this->form->getHTML());
1234  return true;
1235  }
1236 
1241  protected function updateCategoryMapping()
1242  {
1243  if(!$_REQUEST['rule_id'])
1244  {
1245  ilUtil::sendInfo($this->lng->txt('select_one'));
1246  $this->categoryMapping();
1247  return false;
1248  }
1249  $this->ctrl->saveParameter($this,'rule_id');
1250  $this->initRule((int) $_REQUEST['rule_id']);
1251  $this->initCategoryMappingForm('edit');
1252  if($this->form->checkInput())
1253  {
1254  $this->rule->setContainerId($this->form->getInput('import_id'));
1255  $this->rule->setFieldName($this->form->getInput('field'));
1256  $this->rule->setMappingType($this->form->getInput('type'));
1257 
1258  switch($this->form->getInput('type'))
1259  {
1261  $this->rule->setMappingValue($this->form->getInput('mapping_value'));
1262  break;
1263 
1265  $this->rule->setDateRangeStart($this->form->getItemByPostVar('dur_begin')->getDate());
1266  $this->rule->setDateRangeEnd($this->form->getItemByPostVar('dur_end')->getDate());
1267  break;
1268 
1270  $this->rule->setByType($this->form->getInput('by_type'));
1271  break;
1272  }
1273 
1274  if($err = $this->rule->validate())
1275  {
1276  ilUtil::sendInfo($this->lng->txt($err));
1277  $this->form->setValuesByPost();
1278  $this->editCategoryMapping();
1279  return false;
1280  }
1281 
1282  $this->rule->update();
1283  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
1284  $this->ctrl->redirect($this,'categoryMapping');
1285  return true;
1286  }
1287  ilUtil::sendInfo($this->lng->txt('err_check_input'));
1288  $this->form->setValuesByPost();
1289  $this->editCategoryMapping();
1290  return false;
1291 
1292  }
1293 
1297  protected function deleteCategoryMappings()
1298  {
1299  if(!is_array($_POST['rules']) or !$_POST['rules'])
1300  {
1301  ilUtil::sendInfo($this->lng->txt('no_checkbox'));
1302  $this->categoryMapping();
1303  return false;
1304  }
1305  foreach($_POST['rules'] as $rule_id)
1306  {
1307  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1308  $rule = new ilECSCategoryMappingRule($rule_id);
1309  $rule->delete();
1310  }
1311  ilUtil::sendInfo($this->lng->txt('settings_saved'));
1312  $this->categoryMapping();
1313  return true;
1314  }
1315 
1320  protected function showRulesTable()
1321  {
1322  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php';
1323 
1324  if(!$rules = ilECSCategoryMapping::getActiveRules())
1325  {
1326  return false;
1327  }
1328  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingTableGUI.php';
1329  $rule_table = new ilECSCategoryMappingTableGUI($this,'categoryMapping');
1330  $rule_table->parse($rules);
1331  return $rule_table->getHTML();
1332  }
1333 
1339  protected function initRule($a_rule_id = 0)
1340  {
1341  if(is_object($this->rule))
1342  {
1343  return $this->rule;
1344  }
1345 
1346  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1347  $this->rule = new ilECSCategoryMappingRule($a_rule_id);
1348  }
1349 
1354  protected function initCategoryMappingForm($a_mode = 'add')
1355  {
1356  global $ilDB;
1357 
1358  if(is_object($this->form))
1359  {
1360  return true;
1361  }
1362 
1363  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1364  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1365 
1366  $this->form = new ilPropertyFormGUI();
1367 
1368  if($a_mode == 'add')
1369  {
1370  $this->form->setTitle($this->lng->txt('ecs_new_category_mapping'));
1371  $this->form->setFormAction($this->ctrl->getFormAction($this,'categoryMapping'));
1372  $this->form->addCommandButton('addCategoryMapping',$this->lng->txt('save'));
1373  $this->form->addCommandButton('categoryMapping',$this->lng->txt('cancel'));
1374  }
1375  else
1376  {
1377  $this->form->setTitle($this->lng->txt('ecs_edit_category_mapping'));
1378  $this->form->setFormAction($this->ctrl->getFormAction($this,'editCategoryMapping'));
1379  $this->form->addCommandButton('updateCategoryMapping',$this->lng->txt('save'));
1380  $this->form->addCommandButton('categoryMapping',$this->lng->txt('cancel'));
1381  }
1382 
1383  $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'),'import_id');
1384  $imp->setRequired(true);
1385 
1386  $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
1387  $tpl->setVariable('SIZE',5);
1388  $tpl->setVariable('MAXLENGTH',11);
1389  $tpl->setVariable('POST_VAR','import_id');
1390  $tpl->setVariable('PROPERTY_VALUE',$this->rule->getContainerId());
1391 
1392  if($this->settings->getImportId())
1393  {
1394  $tpl->setVariable('COMPLETE_PATH',$this->buildPath($this->rule->getContainerId()));
1395  }
1396 
1397  $imp->setHTML($tpl->get());
1398  $imp->setInfo($this->lng->txt('ecs_import_id_info'));
1399  $this->form->addItem($imp);
1400 
1401  include_once('./Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php');
1402  $select = new ilSelectInputGUI($this->lng->txt('ecs_attribute_name'),'field');
1403  $select->setValue($this->rule->getFieldName());
1404  $select->setRequired(true);
1405  $select->setOptions(ilECSCategoryMapping::getPossibleFields());
1406  $this->form->addItem($select);
1407 
1408  // Value
1409  $value = new ilRadioGroupInputGUI($this->lng->txt('ecs_cat_mapping_type'),'type');
1410  $value->setValue($this->rule->getMappingType());
1411  $value->setRequired(true);
1412 
1413  $fixed = new ilRadioOption($this->lng->txt('ecs_cat_mapping_fixed'),ilECSCategoryMappingRule::TYPE_FIXED);
1414  $fixed->setInfo($this->lng->txt('ecs_cat_mapping_fixed_info'));
1415 
1416  $fixed_val = new ilTextInputGUI($this->lng->txt('ecs_cat_mapping_values'),'mapping_value');
1417  $fixed_val->setValue($this->rule->getMappingValue());
1418  $fixed_val->setMaxLength(255);
1419  $fixed_val->setSize(40);
1420  $fixed_val->setRequired(true);
1421  $fixed->addSubItem($fixed_val);
1422 
1423  $value->addOption($fixed);
1424 
1425  $duration = new ilRadioOption($this->lng->txt('ecs_cat_mapping_duration'),ilECSCategoryMappingRule::TYPE_DURATION);
1426  $duration->setInfo($this->lng->txt('ecs_cat_mapping_duration_info'));
1427 
1428  $dur_start = new ilDateTimeInputGUI($this->lng->txt('from'),'dur_begin');
1429  $dur_start->setDate($this->rule->getDateRangeStart());
1430  $duration->addSubItem($dur_start);
1431 
1432  $dur_end = new ilDateTimeInputGUI($this->lng->txt('to'),'dur_end');
1433  $dur_end->setDate($this->rule->getDateRangeEnd());
1434  $duration->addSubItem($dur_end);
1435 
1436  $value->addOption($duration);
1437 
1438  $type = new ilRadioOption($this->lng->txt('ecs_cat_mapping_by_type'),ilECSCategoryMappingRule::TYPE_BY_TYPE);
1439  $type->setInfo($this->lng->txt('ecs_cat_mapping_by_type_info'));
1440 
1441  $options = ilECSUtils::getPossibleRemoteTypes(true);
1442 
1443  $types = new ilSelectInputGUI($this->lng->txt('type'), 'by_type');
1444  $types->setOptions($options);
1445  $types->setValue($this->rule->getByType());
1446  $types->setRequired(true);
1447  $type->addSubitem($types);
1448 
1449  $value->addOption($type);
1450 
1451  $this->form->addItem($value);
1452 
1453  }
1454 
1455 
1461  protected function imported()
1462  {
1463  global $ilUser, $ilToolbar;
1464 
1465  $this->tabs_gui->setSubTabActive('ecs_import');
1466 
1467  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
1468  if(ilECSServerSettings::getInstance()->activeServerExists())
1469  {
1470  $ilToolbar->addButton(
1471  $this->lng->txt('ecs_read_remote_links'),
1472  $this->ctrl->getLinkTarget($this,'readAll')
1473  );
1474 
1475  $ilToolbar->addSeparator();
1476  }
1477 
1478 
1479  $sel_type = $_REQUEST["otype"];
1480  if(!$sel_type)
1481  {
1482  $sel_type = "rcrs";
1483  }
1484 
1485  include_once './Services/WebServices/ECS/classes/class.ilECSUtils.php';
1486  $options = ilECSUtils::getPossibleRemoteTypes(true);
1487 
1488  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1489  $sel = new ilSelectInputGUI("", "otype");
1490  $sel->setOptions($options);
1491  $sel->setValue($sel_type);
1492  $ilToolbar->addInputItem($sel);
1493 
1494  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "imported"));
1495  $ilToolbar->addFormButton($this->lng->txt("submit"), "imported");
1496 
1497  $robjs = ilUtil::_getObjectsByOperations($sel_type,'visible',$ilUser->getId(),-1);
1498  if(count($robjs))
1499  {
1500  $ilToolbar->addSeparator();
1501 
1502  $ilToolbar->addButton(
1503  $this->lng->txt('csv_export'),
1504  $this->ctrl->getLinkTarget($this,'exportImported')
1505  );
1506  }
1507 
1508  include_once('Services/WebServices/ECS/classes/class.ilECSImportedContentTableGUI.php');
1509  $table_gui = new ilECSImportedContentTableGUI($this,'imported');
1510  $table_gui->setTitle($this->lng->txt('ecs_imported_content'));
1511  $table_gui->parse($robjs);
1512  $this->tpl->setContent($table_gui->getHTML());
1513 
1514  return true;
1515  }
1516 
1523  protected function exportImported()
1524  {
1525  global $ilObjDataCache,$ilUser;
1526 
1527  // :TODO: mind resource type and move to ilRemoteObjectBase...
1528 
1529  $rcourses = ilUtil::_getObjectsByOperations('rcrs','visible',$ilUser->getId(),-1);
1530 
1531  // Read participants
1532  include_once('./Modules/RemoteCourse/classes/class.ilObjRemoteCourse.php');
1533  include_once('./Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
1534  try
1535  {
1537  }
1538  catch(ilECSConnectorException $e)
1539  {
1540  $reader = null;
1541  }
1542 
1543  // read obj_ids
1544  $ilObjDataCache->preloadReferenceCache($rcourses);
1545  $obj_ids = array();
1546  foreach($rcourses as $rcrs_ref_id)
1547  {
1548  $obj_id = $ilObjDataCache->lookupObjId($rcrs_ref_id);
1549  $obj_ids[$obj_id] = $obj_id;
1550  }
1551 
1552  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
1553  $writer = new ilCSVWriter();
1554 
1555  $writer->addColumn($this->lng->txt('title'));
1556  $writer->addColumn($this->lng->txt('description'));
1557  $writer->addColumn($this->lng->txt('ecs_imported_from'));
1558  $writer->addColumn($this->lng->txt('ecs_field_courseID'));
1559  $writer->addColumn($this->lng->txt('ecs_field_term'));
1560  $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
1561  $writer->addColumn($this->lng->txt('ecs_field_courseType'));
1562  $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
1563  $writer->addColumn($this->lng->txt('ecs_field_credits'));
1564  $writer->addColumn($this->lng->txt('ecs_field_room'));
1565  $writer->addColumn($this->lng->txt('ecs_field_cycle'));
1566  $writer->addColumn($this->lng->txt('ecs_field_begin'));
1567  $writer->addColumn($this->lng->txt('ecs_field_end'));
1568  $writer->addColumn($this->lng->txt('last_update'));
1569 
1570  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1572 
1573  foreach($obj_ids as $obj_id)
1574  {
1575  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1576  $values = ilAdvancedMDValues::_getValuesByObjId($obj_id);
1577 
1578  $writer->addRow();
1579  $writer->addColumn(ilObject::_lookupTitle($obj_id));
1580  $writer->addColumn(ilObject::_lookupDescription($obj_id));
1581 
1582  $mid = ilObjRemoteCourse::_lookupMID($obj_id);
1583  if($reader and ($participant = $reader->getParticipantByMID($mid)))
1584  {
1585  $writer->addColumn($participant->getParticipantName());
1586  }
1587  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'courseID');
1588  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1589 
1590  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'term');
1591  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1592 
1593  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'lecturer');
1594  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1595 
1596  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'courseType');
1597  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1598 
1599  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'semester_hours');
1600  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1601 
1602  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'credits');
1603  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1604 
1605  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'room');
1606  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1607 
1608  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'cycle');
1609  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1610 
1611  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'begin');
1612  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1613 
1614  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'end');
1615  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1616 
1617  $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
1618  }
1619  ilUtil::deliverData($writer->getCSVString(), date("Y_m_d")."_ecs_import.csv", "text/csv");
1620  }
1621 
1628  protected function released()
1629  {
1630  global $ilUser, $ilToolbar;
1631 
1632  $this->tabs_gui->setSubTabActive('ecs_released');
1633 
1634  if($this->settings->isEnabled())
1635  {
1636  $ilToolbar->addButton(
1637  $this->lng->txt('ecs_read_remote_links'),
1638  $this->ctrl->getLinkTarget($this,'readAll')
1639  );
1640 
1641  $ilToolbar->addSeparator();
1642  }
1643 
1644  $sel_type = $_REQUEST["otype"];
1645  if(!$sel_type)
1646  {
1647  $sel_type = "rcrs";
1648  }
1649 
1650  include "Services/WebServices/ECS/classes/class.ilECSUtils.php";
1651  $options = ilECSUtils::getPossibleReleaseTypes(true);
1652 
1653  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1654  $sel = new ilSelectInputGUI("", "otype");
1655  $sel->setOptions($options);
1656  $sel->setValue($sel_type);
1657  $ilToolbar->addInputItem($sel);
1658 
1659  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "released"));
1660  $ilToolbar->addFormButton($this->lng->txt("submit"), "released");
1661 
1662  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
1663  $exported = ilECSExport::getExportedIdsByType($sel_type);
1664  if(count($exported))
1665  {
1666  $ilToolbar->addSeparator();
1667 
1668  $ilToolbar->addButton(
1669  $this->lng->txt('csv_export'),
1670  $this->ctrl->getLinkTarget($this,'exportReleased')
1671  );
1672  }
1673 
1674  include_once('Services/WebServices/ECS/classes/class.ilECSReleasedContentTableGUI.php');
1675  $table_gui = new ilECSReleasedContentTableGUI($this,'released');
1676  $table_gui->setTitle($this->lng->txt('ecs_released_content'));
1677  $table_gui->parse($exported);
1678  $this->tpl->setContent($table_gui->getHTML());
1679 
1680  return true;
1681  }
1682 
1689  protected function exportReleased()
1690  {
1691  global $ilObjDataCache;
1692 
1693  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
1694  $exported = ilECSExport::getExportedIds();
1695  $ilObjDataCache->preloadObjectCache($exported);
1696 
1697  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
1698  $writer = new ilCSVWriter();
1699 
1700  $writer->addColumn($this->lng->txt('title'));
1701  $writer->addColumn($this->lng->txt('description'));
1702  $writer->addColumn($this->lng->txt('ecs_field_courseID'));
1703  $writer->addColumn($this->lng->txt('ecs_field_term'));
1704  $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
1705  $writer->addColumn($this->lng->txt('ecs_field_courseType'));
1706  $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
1707  $writer->addColumn($this->lng->txt('ecs_field_credits'));
1708  $writer->addColumn($this->lng->txt('ecs_field_room'));
1709  $writer->addColumn($this->lng->txt('ecs_field_cycle'));
1710  $writer->addColumn($this->lng->txt('ecs_field_begin'));
1711  $writer->addColumn($this->lng->txt('ecs_field_end'));
1712  $writer->addColumn($this->lng->txt('last_update'));
1713 
1714  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1716 
1717  foreach($exported as $obj_id)
1718  {
1719  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1720  $values = ilAdvancedMDValues::_getValuesByObjId($obj_id);
1721 
1722  $writer->addRow();
1723  $writer->addColumn(ilObject::_lookupTitle($obj_id));
1724  $writer->addColumn(ilObject::_lookupDescription($obj_id));
1725 
1726  $field = $settings->getMappingByECSName('courseID');
1727  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1728 
1729  $field = $settings->getMappingByECSName('term');
1730  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1731 
1732  $field = $settings->getMappingByECSName('lecturer');
1733  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1734 
1735  $field = $settings->getMappingByECSName('courseType');
1736  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1737 
1738  $field = $settings->getMappingByECSName('semester_hours');
1739  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1740 
1741  $field = $settings->getMappingByECSName('credits');
1742  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1743 
1744  $field = $settings->getMappingByECSName('room');
1745  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1746 
1747  $field = $settings->getMappingByECSName('cycle');
1748  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1749 
1750  $field = $settings->getMappingByECSName('begin');
1751  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1752 
1753  $field = $settings->getMappingByECSName('end');
1754  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1755 
1756  $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
1757  }
1758 
1759  ilUtil::deliverData($writer->getCSVString(), date("Y_m_d")."_ecs_export.csv", "text/csv");
1760  }
1761 
1762 
1768  protected function prepareFieldSelection($fields)
1769  {
1770  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
1771 
1772  $options[0] = $this->lng->txt('ecs_ignore_field');
1773  foreach($fields as $field)
1774  {
1776  $title = ilAdvancedMDRecord::_lookupTitle($field->getRecordId());
1777  $options[$field->getFieldId()] = $title.': '.$field->getTitle();
1778  }
1779  return $options;
1780  }
1781 
1782 
1783 
1789  protected function initSettings($a_server_id = 1)
1790  {
1791  include_once('Services/WebServices/ECS/classes/class.ilECSSetting.php');
1792  $this->settings = ilECSSetting::getInstanceByServerId($a_server_id);
1793  }
1794 
1800  protected function setSubTabs()
1801  {
1802  $this->tabs_gui->clearSubTabs();
1803 
1804  $this->tabs_gui->addSubTabTarget("overview",
1805  $this->ctrl->getLinkTarget($this,'overview'),
1806  "overview",get_class($this));
1807 
1808  // Disable all other tabs, if server hasn't been configured.
1809  ilECSServerSettings::getInstance()->readInactiveServers();
1810  if(!ilECSServerSettings::getInstance()->serverExists())
1811  {
1812  return true;
1813  }
1814 
1815  $this->tabs_gui->addSubTabTarget("ecs_communities",
1816  $this->ctrl->getLinkTarget($this,'communities'),
1817  "communities",get_class($this));
1818 
1819  $this->tabs_gui->addSubTabTarget('ecs_mappings',
1820  $this->ctrl->getLinkTarget($this,'importMappings'),
1821  'importMappings',get_class($this));
1822 
1823  $this->tabs_gui->addSubTabTarget('ecs_category_mapping',
1824  $this->ctrl->getLinkTarget($this,'categoryMapping'));
1825 
1826  $this->tabs_gui->addSubTabTarget('ecs_import',
1827  $this->ctrl->getLinkTarget($this,'imported'));
1828 
1829  $this->tabs_gui->addSubTabTarget('ecs_released',
1830  $this->ctrl->getLinkTarget($this,'released'));
1831 
1832  }
1833 
1839  private function prepareRoleSelect()
1840  {
1841  global $rbacreview,$ilObjDataCache;
1842 
1843  $global_roles = ilUtil::_sortIds($rbacreview->getGlobalRoles(),
1844  'object_data',
1845  'title',
1846  'obj_id');
1847 
1848  $select[0] = $this->lng->txt('links_select_one');
1849  foreach($global_roles as $role_id)
1850  {
1851  $select[$role_id] = ilObject::_lookupTitle($role_id);
1852  }
1853  return $select;
1854  }
1855 
1856  private function buildPath($a_ref_id)
1857  {
1858  $loc = new ilLocatorGUI();
1859  $loc->setTextOnly(false);
1860  $loc->addContextItems($a_ref_id);
1861 
1862  return $loc->getHTML();
1863  }
1864 
1870  protected function initTaskScheduler()
1871  {
1872  global $ilDB,$ilSetting;
1873 
1874  #$ilDB->lockTables(array('name' => 'settings', 'type' => ilDB::LOCK_WRITE));
1875  $setting = new ilSetting('ecs');
1876  $setting->set(
1877  'next_execution_'.$this->settings->getServerId(),
1878  time() + (int) $this->settings->getPollingTime()
1879  );
1880  }
1881 
1882 }
1883 
1884 ?>