ILIAS  Release_4_4_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  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  $server_title = new ilTextInputGUI($this->lng->txt('ecs_server_title'),'title');
338  $server_title->setValue($this->settings->getTitle());
339  $server_title->setSize(80);
340  $server_title->setMaxLength(128);
341  $server_title->setRequired(true);
342  $this->form->addItem($server_title);
343 
344  $ser = new ilTextInputGUI($this->lng->txt('ecs_server_url'),'server');
345  $ser->setValue((string) $this->settings->getServer());
346  $ser->setRequired(true);
347  $this->form->addItem($ser);
348 
349  $pro = new ilSelectInputGUI($this->lng->txt('ecs_protocol'),'protocol');
350  // fixed to https
351  #$pro->setOptions(array(ilECSSetting::PROTOCOL_HTTP => $this->lng->txt('http'),
352  # ilECSSetting::PROTOCOL_HTTPS => $this->lng->txt('https')));
353  $pro->setOptions(array(ilECSSetting::PROTOCOL_HTTPS => 'HTTPS'));
354  $pro->setValue($this->settings->getProtocol());
355  $pro->setRequired(true);
356  $this->form->addItem($pro);
357 
358  $por = new ilTextInputGUI($this->lng->txt('ecs_port'),'port');
359  $por->setSize(5);
360  $por->setMaxLength(5);
361  $por->setValue((string) $this->settings->getPort());
362  $por->setRequired(true);
363  $this->form->addItem($por);
364 
365  $tcer = new ilRadioGroupInputGUI($this->lng->txt('ecs_auth_type'),'auth_type');
366  $tcer->setValue($this->settings->getAuthType());
367  $this->form->addItem($tcer);
368 
369  // Certificate based authentication
370  $cert_based = new ilRadioOption($this->lng->txt('ecs_auth_type_cert'), ilECSSetting::AUTH_CERTIFICATE);
371  $tcer->addOption($cert_based);
372 
373  $cli = new ilTextInputGUI($this->lng->txt('ecs_client_cert'),'client_cert');
374  $cli->setSize(60);
375  $cli->setValue((string) $this->settings->getClientCertPath());
376  $cli->setRequired(true);
377  $cert_based->addSubItem($cli);
378 
379  $key = new ilTextInputGUI($this->lng->txt('ecs_cert_key'),'key_path');
380  $key->setSize(60);
381  $key->setValue((string) $this->settings->getKeyPath());
382  $key->setRequired(true);
383  $cert_based->addSubItem($key);
384 
385  $cerp = new ilTextInputGUI($this->lng->txt('ecs_key_password'),'key_password');
386  $cerp->setSize(12);
387  $cerp->setValue((string) $this->settings->getKeyPassword());
388  $cerp->setInputType('password');
389  $cerp->setRequired(true);
390  $cert_based->addSubItem($cerp);
391 
392  $cer = new ilTextInputGUI($this->lng->txt('ecs_ca_cert'),'ca_cert');
393  $cer->setSize(60);
394  $cer->setValue((string) $this->settings->getCACertPath());
395  $cer->setRequired(true);
396  $cert_based->addSubItem($cer);
397 
398  // Apache auth
399  $apa_based = new ilRadioOption($this->lng->txt('ecs_auth_type_apache'), ilECSSetting::AUTH_APACHE);
400  $tcer->addOption($apa_based);
401 
402  $user = new ilTextInputGUI($this->lng->txt('ecs_apache_user'),'auth_user');
403  $user->setSize(32);
404  $user->setValue((string) $this->settings->getAuthUser());
405  $user->setRequired(true);
406  $apa_based->addSubItem($user);
407 
408  $pass = new ilPasswordInputGUI($this->lng->txt('ecs_apache_pass'), 'auth_pass');
409  $pass->setRetype(false);
410  $pass->setSize(32);
411  $pass->setMaxLength(128);
412  $pass->setValue((string) $this->settings->getAuthPass());
413  $pass->setRequired(true);
414  $pass->setSkipSyntaxCheck(TRUE);
415  $apa_based->addSubItem($pass);
416 
417 
418  $ser = new ilNonEditableValueGUI($this->lng->txt('cert_serial'));
419  $ser->setValue($this->settings->getCertSerialNumber() ? $this->settings->getCertSerialNumber() : $this->lng->txt('ecs_no_value'));
420  $cert_based->addSubItem($ser);
421 
422  $loc = new ilFormSectionHeaderGUI();
423  $loc->setTitle($this->lng->txt('ecs_local_settings'));
424  $this->form->addItem($loc);
425 
426  $pol = new ilDurationInputGUI($this->lng->txt('ecs_polling'),'polling');
427  $pol->setShowDays(false);
428  $pol->setShowHours(false);
429  $pol->setShowMinutes(true);
430  $pol->setShowSeconds(true);
431  $pol->setSeconds($this->settings->getPollingTimeSeconds());
432  $pol->setMinutes($this->settings->getPollingTimeMinutes());
433  $pol->setRequired(true);
434  $pol->setInfo($this->lng->txt('ecs_polling_info'));
435  $this->form->addItem($pol);
436 
437  $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'));
438  $imp->setRequired(true);
439 
440  $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
441  $tpl->setVariable('SIZE',5);
442  $tpl->setVariable('MAXLENGTH',11);
443  $tpl->setVariable('POST_VAR','import_id');
444  $tpl->setVariable('PROPERTY_VALUE',$this->settings->getImportId());
445 
446  if($this->settings->getImportId())
447  {
448  $tpl->setVariable('COMPLETE_PATH',$this->buildPath($this->settings->getImportId()));
449  }
450 
451  $imp->setHTML($tpl->get());
452  $imp->setInfo($this->lng->txt('ecs_import_id_info'));
453  $this->form->addItem($imp);
454 
455  $loc = new ilFormSectionHeaderGUI();
456  $loc->setTitle($this->lng->txt('ecs_remote_user_settings'));
457  $this->form->addItem($loc);
458 
459  $role = new ilSelectInputGUI($this->lng->txt('ecs_role'),'global_role');
460  $role->setOptions($this->prepareRoleSelect());
461  $role->setValue($this->settings->getGlobalRole());
462  $role->setInfo($this->lng->txt('ecs_global_role_info'));
463  $role->setRequired(true);
464  $this->form->addItem($role);
465 
466  $duration = new ilDurationInputGUI($this->lng->txt('ecs_account_duration'),'duration');
467  $duration->setInfo($this->lng->txt('ecs_account_duration_info'));
468  $duration->setMonths($this->settings->getDuration());
469  $duration->setShowSeconds(false);
470  $duration->setShowMinutes(false);
471  $duration->setShowHours(false);
472  $duration->setShowDays(false);
473  $duration->setShowMonths(true);
474  $duration->setRequired(true);
475  $this->form->addItem($duration);
476 
477  // Email recipients
478  $loc = new ilFormSectionHeaderGUI();
479  $loc->setTitle($this->lng->txt('ecs_notifications'));
480  $this->form->addItem($loc);
481 
482  $rcp_user = new ilTextInputGUI($this->lng->txt('ecs_user_rcp'),'user_recipients');
483  $rcp_user->setValue((string) $this->settings->getUserRecipientsAsString());
484  $rcp_user->setInfo($this->lng->txt('ecs_user_rcp_info'));
485  $this->form->addItem($rcp_user);
486 
487  $rcp_econ = new ilTextInputGUI($this->lng->txt('ecs_econ_rcp'),'econtent_recipients');
488  $rcp_econ->setValue((string) $this->settings->getEContentRecipientsAsString());
489  $rcp_econ->setInfo($this->lng->txt('ecs_econ_rcp_info'));
490  $this->form->addItem($rcp_econ);
491 
492  $rcp_app = new ilTextInputGUI($this->lng->txt('ecs_approval_rcp'),'approval_recipients');
493  $rcp_app->setValue((string) $this->settings->getApprovalRecipientsAsString());
494  $rcp_app->setInfo($this->lng->txt('ecs_approval_rcp_info'));
495  $this->form->addItem($rcp_app);
496 
497  if($a_mode == 'update')
498  {
499  $this->form->addCommandButton('update',$this->lng->txt('save'));
500  }
501  else
502  {
503  $this->form->addCommandButton('save',$this->lng->txt('save'));
504  }
505  $this->form->addCommandButton('overview',$this->lng->txt('cancel'));
506  }
507 
513  protected function update()
514  {
515  $this->initSettings((int) $_REQUEST['server_id']);
516  $this->loadFromPost();
517 
518  if(!$error = $this->settings->validate())
519  {
520  $this->settings->update();
521  $this->initTaskScheduler();
522  #$this->updateTitle();
523  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
524  }
525  else
526  {
527  ilUtil::sendInfo($this->lng->txt($error));
528  $this->edit();
529  }
530 
531  $this->overview();
532  return true;
533  }
534 
539  protected function save()
540  {
541  $this->initSettings(0);
542  $this->loadFromPost();
543 
544  if(!$error = $this->settings->validate())
545  {
546  $this->settings->save();
547  $this->initTaskScheduler();
548 
549  #$this->updateTitle();
550  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
551  }
552  else
553  {
554  ilUtil::sendInfo($this->lng->txt($error));
555  return $this->create();
556  }
557  $GLOBALS['ilCtrl']->redirect($this,'overview');
558  return true;
559  }
560 
564  protected function updateTitle()
565  {
566  try
567  {
568  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
570 
571  foreach($reader->getCommunities() as $community)
572  {
573  foreach($community->getParticipants() as $part)
574  {
575  $GLOBALS['ilLog']->write(__METHOD__.': '.print_r($community,true));
576  if($part->isSelf())
577  {
578  $this->settings->setTitle($part->getParticipantName());
579  $this->settings->update();
580  return true;
581  }
582  }
583  }
584  }
585  catch(ilECSConnectorException $exc)
586  {
587  ilUtil::sendFailure($exc->getMessage());
588  }
589  $this->settings->setTitle('');
590  $this->settings->update();
591  }
592 
596  protected function loadFromPost()
597  {
598  $this->settings->setEnabledStatus((int) $_POST['active']);
599  $this->settings->setTitle(ilUtil::stripSlashes($_POST['title']));
600  $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
601  $this->settings->setPort(ilUtil::stripSlashes($_POST['port']));
602  $this->settings->setProtocol(ilUtil::stripSlashes($_POST['protocol']));
603  $this->settings->setClientCertPath(ilUtil::stripSlashes($_POST['client_cert']));
604  $this->settings->setCACertPath(ilUtil::stripSlashes($_POST['ca_cert']));
605  $this->settings->setKeyPath(ilUtil::stripSlashes($_POST['key_path']));
606  $this->settings->setKeyPassword(ilUtil::stripSlashes($_POST['key_password']));
607  $this->settings->setImportId(ilUtil::stripSlashes($_POST['import_id']));
608  $this->settings->setPollingTimeMS((int) $_POST['polling']['mm'],(int) $_POST['polling']['ss']);
609  $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
610  $this->settings->setGlobalRole((int) $_POST['global_role']);
611  $this->settings->setDuration((int) $_POST['duration']['MM']);
612 
613  $this->settings->setUserRecipients(ilUtil::stripSlashes($_POST['user_recipients']));
614  $this->settings->setEContentRecipients(ilUtil::stripSlashes($_POST['econtent_recipients']));
615  $this->settings->setApprovalRecipients(ilUtil::stripSlashes($_POST['approval_recipients']));
616 
617  $this->settings->setAuthType((int) $_POST['auth_type']);
618  $this->settings->setAuthPass(ilUtil::stripSlashes($_POST['auth_pass']));
619  $this->settings->setAuthUser(ilUtil::stripSlashes($_POST['auth_user']));
620 
621  }
622 
626  protected function refreshParticipants()
627  {
628  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
629  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
630  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
631  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
632 
634  $servers->readInactiveServers();
635  foreach($servers->getServers() as $server)
636  {
637  $creader = ilECSCommunityReader::getInstanceByServerId($server->getServerId());
638 
639  // read community
640  foreach(ilECSParticipantSettings::getAvailabeMids($server->getServerId()) as $mid)
641  {
642  if(!$creader->getParticipantByMID($mid))
643  {
644  $GLOBALS['ilLog']->write(__METHOD__.': Deleting deprecated participant '. $server->getServerId().' '. $mid);
645 
646  $part = new ilECSParticipantSetting($server->getServerId(),$mid);
647  $part->delete();
648  }
649  }
650  }
651  ilUtil::sendSuccess($this->lng->txt('settings_saved'),TRUE);
652  $this->ctrl->redirect($this,'communities');
653  }
654 
661  public function communities()
662  {
663  // add toolbar to refresh communities
664  $GLOBALS['ilToolbar']->addButton(
665  $this->lng->txt('ecs_refresh_participants'),
666  $this->ctrl->getLinkTarget($this,'refreshParticipants')
667  );
668 
669  $this->tabs_gui->setSubTabActive('ecs_communities');
670 
671  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_communities.html','Services/WebServices/ECS');
672 
673  $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this,'updateCommunities'));
674  $this->tpl->setVariable('TXT_SAVE',$this->lng->txt('save'));
675  $this->tpl->setVariable('TXT_CANCEL', $this->lng->txt('cancel'));
676 
677  include_once('Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
678  include_once('Services/WebServices/ECS/classes/class.ilECSCommunityTableGUI.php');
679 
680  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
681  $settings = ilECSServerSettings::getInstance();
682  $settings->readInactiveServers();
683 
684  foreach($settings->getServers() as $server)
685  {
686  // Try to read communities
687  try
688  {
690  foreach($reader->getCommunities() as $community)
691  {
692  $this->tpl->setCurrentBlock('table_community');
693  $table_gui = new ilECSCommunityTableGUI($server,$this,'communities',$community->getId());
694  $table_gui->setTitle($community->getTitle().' ('.$community->getDescription().')');
695  $table_gui->parse($community->getParticipants());
696  $this->tpl->setVariable('TABLE_COMM',$table_gui->getHTML());
697  $this->tpl->parseCurrentBlock();
698  }
699  }
700  catch(ilECSConnectorException $exc)
701  {
702  // Maybe server is not fully configured
703  continue;
704  }
705 
706  // Show section for each server
707  $this->tpl->setCurrentBlock('server');
708  $this->tpl->setVariable('TXT_SERVER_NAME',$server->getTitle());
709  $this->tpl->parseCurrentBlock();
710  }
711  }
712 
718  protected function validateImportTypes(&$import_types)
719  {
720  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
721 
722  $num_cms = 0;
723  foreach((array) $import_types as $sid => $server)
724  {
725  foreach((array) $server as $mid => $import_type)
726  {
727  if($import_type == ilECSParticipantSetting::IMPORT_CMS)
728  {
729  ++$num_cms;
730  }
731  }
732  }
733 
734  if($num_cms <= 1)
735  {
736  return true;
737  }
738  // Change to import type "UNCHANGED"
739  $new_types = array();
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  $new_types[$sid][$mid] = ilECSParticipantSetting::IMPORT_UNCHANGED;
747  }
748  else
749  {
750  $new_types[$sid][$mid] = $import_type;
751  }
752  }
753  }
754  $import_types = $new_types;
755  return false;
756  }
757 
764  protected function updateCommunities()
765  {
766  global $ilLog;
767 
768  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
769  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
770 
771  // @TODO: Delete deprecated communities
772  $invalidImportTypes = false;
773  if(!$this->validateImportTypes($_POST['import_type']))
774  {
775  $invalidImportTypes = true;
776  }
777 
779  foreach($servers->getServers() as $server)
780  {
781  try {
782  // Read communities
783  $cReader = ilECSCommunityReader::getInstanceByServerId($server->getServerId());
784 
785  // Update community cache
786  foreach($cReader->getCommunities() as $community)
787  {
788  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityCache.php';
789  $cCache = ilECSCommunityCache::getInstance($server->getServerId(), $community->getId());
790  $cCache->setCommunityName($community->getTitle());
791  $cCache->setMids($community->getMids());
792  $cCache->setOwnId($community->getOwnId());
793  $cCache->update();
794  }
795  }
796  catch(Exception $e)
797  {
798  $GLOBALS['ilLog']->write(__METHOD__.': Cannot read ecs communities: '.$e->getMessage());
799  }
800  }
801 
802  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
803  foreach((array) $_POST['sci_mid'] as $sid => $tmp)
804  {
805  foreach((array) $_POST['sci_mid'][$sid] as $mid => $tmp)
806  {
807  $set = new ilECSParticipantSetting($sid, $mid);
808  $set->enableExport(array_key_exists($mid, (array) $_POST['export'][$sid]) ? true : false);
809  $set->enableImport(array_key_exists($mid, (array) $_POST['import'][$sid]) ? true : false);
810  $set->setImportType($_POST['import_type'][$sid][$mid]);
811 
812  // update title/cname
813  try {
814  $part = ilECSCommunityReader::getInstanceByServerId($sid)->getParticipantByMID($mid);
815  if($part instanceof ilECSParticipant)
816  {
817  $set->setTitle($part->getParticipantName());
818  }
819  $com = ilECSCommunityReader::getInstanceByServerId($sid)->getCommunityByMID($mid);
820  if($com instanceof ilECSCommunity)
821  {
822  $set->setCommunityName($com->getTitle());
823  }
824  }
825  catch(Exception $e)
826  {
827  $GLOBALS['ilLog']->write(__METHOD__.': Cannot read ecs communities: '.$e->getMessage());
828  }
829 
830  $set->update();
831  }
832  }
833  if($invalidImportTypes)
834  {
835  ilUtil::sendFailure($this->lng->txt('ecs_invalid_import_type_cms'),true);
836  }
837  else
838  {
839  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
840  }
841  $GLOBALS['ilCtrl']->redirect($this,'communities');
842 
843  // TODO: Do update of remote courses and ...
844 
845  return true;
846  }
847 
848 
854  protected function setMappingTabs($a_active)
855  {
856  global $ilTabs;
857 
858  $ilTabs->clearTargets();
859  $ilTabs->clearSubTabs();
860 
861  $ilTabs->setBackTarget(
862  $this->lng->txt('ecs_settings'),
863  $this->ctrl->getLinkTarget($this,'overview')
864  );
865  $ilTabs->addTab(
866  'import',
867  $this->lng->txt('ecs_tab_import'),
868  $this->ctrl->getLinkTarget($this,'importMappings')
869  );
870  $ilTabs->addTab(
871  'export',
872  $this->lng->txt('ecs_tab_export'),
873  $this->ctrl->getLinkTarget($this,'exportMappings')
874  );
875 
876 
877  switch($a_active)
878  {
879  case self::MAPPING_IMPORT:
880  $ilTabs->activateTab('import');
881  break;
882 
883  case self::MAPPING_EXPORT:
884  $ilTabs->activateTab('export');
885  break;
886  }
887  return true;
888  }
889 
895  public function importMappings()
896  {
897  global $ilToolbar;
898 
899  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
900 
901  $this->setMappingTabs(self::MAPPING_IMPORT);
902 
904  if(!count($fields))
905  {
906  ilUtil::sendInfo($this->lng->txt('ecs_no_adv_md'));
907  return true;
908  }
909 
910  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
911  $settings = ilECSServerSettings::getInstance();
912  $settings->readInactiveServers();
913 
914  $sel_srv = (int)$_REQUEST["ecs_mapping_server"];
915  if(!$sel_srv)
916  {
917  $sel_srv = $_SESSION["ecs_sel_srv"];
918  }
919  else
920  {
921  $_SESSION["ecs_sel_srv"] = $sel_srv;
922  }
923 
924  // Iterate all servers
925  $options = array(0 => $this->lng->txt("please_choose"));
926  foreach($settings->getServers() as $server)
927  {
928  $title = $server->getTitle();
929  if(!$title)
930  {
931  $title = "ECS (".$server->getServerId().")";
932  }
933  $options[$server->getServerId()] = $title;
934  }
935 
936  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
937  $sel = new ilSelectInputGUI("", "ecs_mapping_server");
938  $sel->setOptions($options);
939  $sel->setValue($sel_srv);
940  $ilToolbar->addInputItem($sel);
941 
942  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "importMappings"));
943  $ilToolbar->addFormButton($this->lng->txt("submit"), "importMappings");
944 
945  if($sel_srv)
946  {
947  $form = $this->initMappingsForm($sel_srv, self::MAPPING_IMPORT);
948  $this->tpl->setContent($form->getHTML());
949  }
950 
951  return true;
952  }
953 
959  protected function exportMappings()
960  {
961  global $ilToolbar;
962 
963  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
964 
965  $this->setMappingTabs(self::MAPPING_EXPORT);
966 
968  if(!count($fields))
969  {
970  ilUtil::sendInfo($this->lng->txt('ecs_no_adv_md'));
971  return true;
972  }
973 
974  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
975  $settings = ilECSServerSettings::getInstance();
976  $settings->readInactiveServers();
977 
978  $sel_srv = (int)$_REQUEST["ecs_mapping_server"];
979  if(!$sel_srv)
980  {
981  $sel_srv = $_SESSION["ecs_sel_srv"];
982  }
983  else
984  {
985  $_SESSION["ecs_sel_srv"] = $sel_srv;
986  }
987 
988  // Iterate all servers
989  $options = array(0 => $this->lng->txt("please_choose"));
990  foreach($settings->getServers() as $server)
991  {
992  $title = $server->getTitle();
993  if(!$title)
994  {
995  $title = "ECS (".$server->getServerId().")";
996  }
997  $options[$server->getServerId()] = $title;
998  }
999 
1000  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1001  $sel = new ilSelectInputGUI("", "ecs_mapping_server");
1002  $sel->setOptions($options);
1003  $sel->setValue($sel_srv);
1004  $ilToolbar->addInputItem($sel);
1005 
1006  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "exportMappings"));
1007  $ilToolbar->addFormButton($this->lng->txt("submit"), "exportMappings");
1008 
1009  if($sel_srv)
1010  {
1011  $form = $this->initMappingsForm($sel_srv,self::MAPPING_EXPORT);
1012  $this->tpl->setContent($form->getHTML());
1013  }
1014 
1015  return true;
1016  }
1017 
1024  protected function saveImportMappings()
1025  {
1026  foreach((array) $_POST['mapping'] as $mtype => $mappings)
1027  {
1028  foreach((array) $mappings as $ecs_field => $advmd_id)
1029  {
1030  include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSetting.php';
1031  $map = new ilECSDataMappingSetting(
1032  (int) $_REQUEST['ecs_mapping_server'],
1033  (int) $mtype,
1034  $ecs_field
1035  );
1036  $map->setAdvMDId($advmd_id);
1037  $map->save();
1038  }
1039  }
1040 
1041  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
1042  $this->ctrl->setParameter($this, "ecs_mapping_server", (int)$_POST['ecs_mapping_server']);
1043  $this->ctrl->redirect($this,'importMappings');
1044  return true;
1045  }
1046 
1053  protected function saveExportMappings()
1054  {
1055  foreach((array) $_POST['mapping'] as $mtype => $mappings)
1056  {
1057  foreach((array) $mappings as $ecs_field => $advmd_id)
1058  {
1059  include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSetting.php';
1060  $map = new ilECSDataMappingSetting(
1061  (int) $_POST['ecs_mapping_server'],
1062  (int) $mtype,
1063  $ecs_field
1064  );
1065  $map->setAdvMDId($advmd_id);
1066  $map->save();
1067  }
1068  }
1069 
1070  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
1071  $this->ctrl->setParameter($this, "ecs_mapping_server", (int)$_POST['ecs_mapping_server']);
1072  $this->ctrl->redirect($this,'exportMappings');
1073  return true;
1074  }
1075 
1084  protected function initMappingsForm($a_server_id,$mapping_type)
1085  {
1086  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
1087 
1088  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1089  $mapping_settings = ilECSDataMappingSettings::getInstanceByServerId($a_server_id);
1090 
1091  $form = new ilPropertyFormGUI();
1092 
1093  if($mapping_type == self::MAPPING_IMPORT)
1094  {
1095  $form->setTitle($this->lng->txt('ecs_mapping_tbl'));
1096  $form->addCommandButton('saveImportMappings',$this->lng->txt('save'));
1097  $form->addCommandButton('importMappings',$this->lng->txt('cancel'));
1098  }
1099  else
1100  {
1101  $form->setTitle($this->lng->txt('ecs_mapping_exp_tbl'));
1102  $form->addCommandButton('saveExportMappings',$this->lng->txt('save'));
1103  $form->addCommandButton('exportMappings',$this->lng->txt('cancel'));
1104  }
1105 
1106  $form->setFormAction($this->ctrl->getFormAction($this,'saveMappings'));
1107 
1108  if($mapping_type == self::MAPPING_IMPORT)
1109  {
1110  $assignments = new ilCustomInputGUI($this->lng->txt('ecs_mapping_crs'));
1111  $form->addItem($assignments);
1112  }
1113 
1114  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1116  $options = $this->prepareFieldSelection($fields);
1117 
1118  // get all optional ecourse fields
1119  include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
1121  foreach($optional as $field_name)
1122  {
1123  if($mapping_type == self::MAPPING_IMPORT)
1124  {
1125  $select = new ilSelectInputGUI(
1126  $this->lng->txt('ecs_field_'.$field_name),
1127  'mapping'.'['.ilECSDataMappingSetting::MAPPING_IMPORT_CRS.']['.$field_name.']'
1128  );
1129 
1130  $select->setValue(
1131  $mapping_settings->getMappingByECSName(
1133  $field_name)
1134  );
1135  $select->setOptions($options);
1136  $assignments->addSubItem($select);
1137  }
1138  else
1139  {
1140  $select = new ilSelectInputGUI(
1141  $this->lng->txt('ecs_field_'.$field_name),
1142  'mapping'.'['.ilECSDataMappingSetting::MAPPING_EXPORT.']['.$field_name.']'
1143  );
1144  $select->setValue(
1145  $mapping_settings->getMappingByECSName(
1147  $field_name)
1148  );
1149  $select->setOptions($options);
1150  $form->addItem($select);
1151  }
1152  }
1153 
1154  $server = new ilHiddenInputGUI('ecs_mapping_server');
1155  $server->setValue($a_server_id);
1156  $form->addItem($server);
1157 
1158  // Remote courses
1159  // no remote course settings for export
1160  if($mapping_type == self::MAPPING_EXPORT)
1161  {
1162  return $form;
1163  }
1164 
1165  $rcrs = new ilCustomInputGUI($this->lng->txt('ecs_mapping_rcrs'));
1166  $form->addItem($rcrs);
1167 
1168  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1170  $options = $this->prepareFieldSelection($fields);
1171 
1172  // get all optional econtent fields
1173  include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
1175  foreach($optional as $field_name)
1176  {
1177  $select = new ilSelectInputGUI(
1178  $this->lng->txt('ecs_field_'.$field_name),
1179  'mapping['.ilECSDataMappingSetting::MAPPING_IMPORT_RCRS.']['.$field_name.']');
1180  $select->setValue(
1181  $mapping_settings->getMappingByECSName(
1183  $field_name)
1184  );
1185  $select->setOptions($options);
1186  $rcrs->addSubItem($select);
1187  }
1188  return $form;
1189  }
1190 
1195  protected function categoryMapping()
1196  {
1197  $this->tabs_gui->setSubTabActive('ecs_category_mapping');
1198  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.category_mapping.html','Services/WebServices/ECS');
1199 
1200  $this->initRule();
1201  $this->initCategoryMappingForm();
1202 
1203 
1204  $this->tpl->setVariable('NEW_RULE_TABLE',$this->form->getHTML());
1205  if($html = $this->showRulesTable())
1206  {
1207  $this->tpl->setVariable('RULES_TABLE',$html);
1208  }
1209  }
1210 
1215  protected function addCategoryMapping()
1216  {
1217  $this->initRule();
1218 
1219  $this->initCategoryMappingForm('add');
1220  if($this->form->checkInput())
1221  {
1222  $this->rule->setContainerId($this->form->getInput('import_id'));
1223  $this->rule->setFieldName($this->form->getInput('field'));
1224  $this->rule->setMappingType($this->form->getInput('type'));
1225 
1226  switch($this->form->getInput('type'))
1227  {
1229  $this->rule->setMappingValue($this->form->getInput('mapping_value'));
1230  break;
1231 
1233  $this->rule->setDateRangeStart($this->form->getItemByPostVar('dur_begin')->getDate());
1234  $this->rule->setDateRangeEnd($this->form->getItemByPostVar('dur_end')->getDate());
1235  break;
1236 
1238  $this->rule->setByType($this->form->getInput('by_type'));
1239  break;
1240  }
1241 
1242  if($err = $this->rule->validate())
1243  {
1244  ilUtil::sendInfo($this->lng->txt($err));
1245  $this->form->setValuesByPost();
1246  $this->categoryMapping();
1247  return false;
1248  }
1249 
1250  $this->rule->save();
1251  ilUtil::sendInfo($this->lng->txt('settings_saved'));
1252  unset($this->rule);
1253  $this->categoryMapping();
1254  return true;
1255  }
1256  ilUtil::sendInfo($this->lng->txt('err_check_input'));
1257  $this->form->setValuesByPost();
1258  $this->categoryMapping();
1259  return false;
1260  }
1261 
1266  protected function editCategoryMapping()
1267  {
1268  if(!$_REQUEST['rule_id'])
1269  {
1270  ilUtil::sendInfo($this->lng->txt('select_one'));
1271  $this->categoryMapping();
1272  return false;
1273  }
1274 
1275  $this->tabs_gui->setSubTabActive('ecs_category_mapping');
1276  $this->ctrl->saveParameter($this,'rule_id');
1277  $this->initRule((int) $_REQUEST['rule_id']);
1278 
1279  $this->initCategoryMappingForm('edit');
1280  $this->tpl->setContent($this->form->getHTML());
1281  return true;
1282  }
1283 
1288  protected function updateCategoryMapping()
1289  {
1290  if(!$_REQUEST['rule_id'])
1291  {
1292  ilUtil::sendInfo($this->lng->txt('select_one'));
1293  $this->categoryMapping();
1294  return false;
1295  }
1296  $this->ctrl->saveParameter($this,'rule_id');
1297  $this->initRule((int) $_REQUEST['rule_id']);
1298  $this->initCategoryMappingForm('edit');
1299  if($this->form->checkInput())
1300  {
1301  $this->rule->setContainerId($this->form->getInput('import_id'));
1302  $this->rule->setFieldName($this->form->getInput('field'));
1303  $this->rule->setMappingType($this->form->getInput('type'));
1304 
1305  switch($this->form->getInput('type'))
1306  {
1308  $this->rule->setMappingValue($this->form->getInput('mapping_value'));
1309  break;
1310 
1312  $this->rule->setDateRangeStart($this->form->getItemByPostVar('dur_begin')->getDate());
1313  $this->rule->setDateRangeEnd($this->form->getItemByPostVar('dur_end')->getDate());
1314  break;
1315 
1317  $this->rule->setByType($this->form->getInput('by_type'));
1318  break;
1319  }
1320 
1321  if($err = $this->rule->validate())
1322  {
1323  ilUtil::sendInfo($this->lng->txt($err));
1324  $this->form->setValuesByPost();
1325  $this->editCategoryMapping();
1326  return false;
1327  }
1328 
1329  $this->rule->update();
1330  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
1331  $this->ctrl->redirect($this,'categoryMapping');
1332  return true;
1333  }
1334  ilUtil::sendInfo($this->lng->txt('err_check_input'));
1335  $this->form->setValuesByPost();
1336  $this->editCategoryMapping();
1337  return false;
1338 
1339  }
1340 
1344  protected function deleteCategoryMappings()
1345  {
1346  if(!is_array($_POST['rules']) or !$_POST['rules'])
1347  {
1348  ilUtil::sendInfo($this->lng->txt('no_checkbox'));
1349  $this->categoryMapping();
1350  return false;
1351  }
1352  foreach($_POST['rules'] as $rule_id)
1353  {
1354  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1355  $rule = new ilECSCategoryMappingRule($rule_id);
1356  $rule->delete();
1357  }
1358  ilUtil::sendInfo($this->lng->txt('settings_saved'));
1359  $this->categoryMapping();
1360  return true;
1361  }
1362 
1367  protected function showRulesTable()
1368  {
1369  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php';
1370 
1371  if(!$rules = ilECSCategoryMapping::getActiveRules())
1372  {
1373  return false;
1374  }
1375  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingTableGUI.php';
1376  $rule_table = new ilECSCategoryMappingTableGUI($this,'categoryMapping');
1377  $rule_table->parse($rules);
1378  return $rule_table->getHTML();
1379  }
1380 
1386  protected function initRule($a_rule_id = 0)
1387  {
1388  if(is_object($this->rule))
1389  {
1390  return $this->rule;
1391  }
1392 
1393  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1394  $this->rule = new ilECSCategoryMappingRule($a_rule_id);
1395  }
1396 
1401  protected function initCategoryMappingForm($a_mode = 'add')
1402  {
1403  global $ilDB;
1404 
1405  if(is_object($this->form))
1406  {
1407  return true;
1408  }
1409 
1410  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1411  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1412 
1413  $this->form = new ilPropertyFormGUI();
1414 
1415  if($a_mode == 'add')
1416  {
1417  $this->form->setTitle($this->lng->txt('ecs_new_category_mapping'));
1418  $this->form->setFormAction($this->ctrl->getFormAction($this,'categoryMapping'));
1419  $this->form->addCommandButton('addCategoryMapping',$this->lng->txt('save'));
1420  $this->form->addCommandButton('categoryMapping',$this->lng->txt('cancel'));
1421  }
1422  else
1423  {
1424  $this->form->setTitle($this->lng->txt('ecs_edit_category_mapping'));
1425  $this->form->setFormAction($this->ctrl->getFormAction($this,'editCategoryMapping'));
1426  $this->form->addCommandButton('updateCategoryMapping',$this->lng->txt('save'));
1427  $this->form->addCommandButton('categoryMapping',$this->lng->txt('cancel'));
1428  }
1429 
1430  $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'),'import_id');
1431  $imp->setRequired(true);
1432 
1433  $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
1434  $tpl->setVariable('SIZE',5);
1435  $tpl->setVariable('MAXLENGTH',11);
1436  $tpl->setVariable('POST_VAR','import_id');
1437  $tpl->setVariable('PROPERTY_VALUE',$this->rule->getContainerId());
1438 
1439  if($this->settings->getImportId())
1440  {
1441  $tpl->setVariable('COMPLETE_PATH',$this->buildPath($this->rule->getContainerId()));
1442  }
1443 
1444  $imp->setHTML($tpl->get());
1445  $imp->setInfo($this->lng->txt('ecs_import_id_info'));
1446  $this->form->addItem($imp);
1447 
1448  include_once('./Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php');
1449  $select = new ilSelectInputGUI($this->lng->txt('ecs_attribute_name'),'field');
1450  $select->setValue($this->rule->getFieldName());
1451  $select->setRequired(true);
1452  $select->setOptions(ilECSCategoryMapping::getPossibleFields());
1453  $this->form->addItem($select);
1454 
1455  // Value
1456  $value = new ilRadioGroupInputGUI($this->lng->txt('ecs_cat_mapping_type'),'type');
1457  $value->setValue($this->rule->getMappingType());
1458  $value->setRequired(true);
1459 
1460  $fixed = new ilRadioOption($this->lng->txt('ecs_cat_mapping_fixed'),ilECSCategoryMappingRule::TYPE_FIXED);
1461  $fixed->setInfo($this->lng->txt('ecs_cat_mapping_fixed_info'));
1462 
1463  $fixed_val = new ilTextInputGUI($this->lng->txt('ecs_cat_mapping_values'),'mapping_value');
1464  $fixed_val->setValue($this->rule->getMappingValue());
1465  $fixed_val->setMaxLength(255);
1466  $fixed_val->setSize(40);
1467  $fixed_val->setRequired(true);
1468  $fixed->addSubItem($fixed_val);
1469 
1470  $value->addOption($fixed);
1471 
1472  $duration = new ilRadioOption($this->lng->txt('ecs_cat_mapping_duration'),ilECSCategoryMappingRule::TYPE_DURATION);
1473  $duration->setInfo($this->lng->txt('ecs_cat_mapping_duration_info'));
1474 
1475  $dur_start = new ilDateTimeInputGUI($this->lng->txt('from'),'dur_begin');
1476  $dur_start->setDate($this->rule->getDateRangeStart());
1477  $duration->addSubItem($dur_start);
1478 
1479  $dur_end = new ilDateTimeInputGUI($this->lng->txt('to'),'dur_end');
1480  $dur_end->setDate($this->rule->getDateRangeEnd());
1481  $duration->addSubItem($dur_end);
1482 
1483  $value->addOption($duration);
1484 
1485  $type = new ilRadioOption($this->lng->txt('ecs_cat_mapping_by_type'),ilECSCategoryMappingRule::TYPE_BY_TYPE);
1486  $type->setInfo($this->lng->txt('ecs_cat_mapping_by_type_info'));
1487 
1489 
1490  $types = new ilSelectInputGUI($this->lng->txt('type'), 'by_type');
1491  $types->setOptions($options);
1492  $types->setValue($this->rule->getByType());
1493  $types->setRequired(true);
1494  $type->addSubitem($types);
1495 
1496  $value->addOption($type);
1497 
1498  $this->form->addItem($value);
1499 
1500  }
1501 
1502 
1508  protected function imported()
1509  {
1510  global $ilUser, $ilToolbar;
1511 
1512  $this->tabs_gui->setSubTabActive('ecs_import');
1513 
1514  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
1515  if(ilECSServerSettings::getInstance()->activeServerExists())
1516  {
1517  $ilToolbar->addButton(
1518  $this->lng->txt('ecs_read_remote_links'),
1519  $this->ctrl->getLinkTarget($this,'readAll')
1520  );
1521 
1522  $ilToolbar->addSeparator();
1523  }
1524 
1525 
1526  $sel_type = $_REQUEST["otype"];
1527  if(!$sel_type)
1528  {
1529  $sel_type = "rcrs";
1530  }
1531 
1532  include_once './Services/WebServices/ECS/classes/class.ilECSUtils.php';
1534 
1535  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1536  $sel = new ilSelectInputGUI("", "otype");
1537  $sel->setOptions($options);
1538  $sel->setValue($sel_type);
1539  $ilToolbar->addInputItem($sel);
1540 
1541  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "imported"));
1542  $ilToolbar->addFormButton($this->lng->txt("submit"), "imported");
1543 
1544  $robjs = ilUtil::_getObjectsByOperations($sel_type,'visible',$ilUser->getId(),-1);
1545  if(count($robjs))
1546  {
1547  $ilToolbar->addSeparator();
1548 
1549  $ilToolbar->addButton(
1550  $this->lng->txt('csv_export'),
1551  $this->ctrl->getLinkTarget($this,'exportImported')
1552  );
1553  }
1554 
1555  include_once('Services/WebServices/ECS/classes/class.ilECSImportedContentTableGUI.php');
1556  $table_gui = new ilECSImportedContentTableGUI($this,'imported');
1557  $table_gui->setTitle($this->lng->txt('ecs_imported_content'));
1558  $table_gui->parse($robjs);
1559  $this->tpl->setContent($table_gui->getHTML());
1560 
1561  return true;
1562  }
1563 
1570  protected function exportImported()
1571  {
1572  global $ilObjDataCache,$ilUser;
1573 
1574  // :TODO: mind resource type and move to ilRemoteObjectBase...
1575 
1576  $rcourses = ilUtil::_getObjectsByOperations('rcrs','visible',$ilUser->getId(),-1);
1577 
1578  // Read participants
1579  include_once('./Modules/RemoteCourse/classes/class.ilObjRemoteCourse.php');
1580  include_once('./Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
1581  try
1582  {
1584  }
1585  catch(ilECSConnectorException $e)
1586  {
1587  $reader = null;
1588  }
1589 
1590  // read obj_ids
1591  $ilObjDataCache->preloadReferenceCache($rcourses);
1592  $obj_ids = array();
1593  foreach($rcourses as $rcrs_ref_id)
1594  {
1595  $obj_id = $ilObjDataCache->lookupObjId($rcrs_ref_id);
1596  $obj_ids[$obj_id] = $obj_id;
1597  }
1598 
1599  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
1600  $writer = new ilCSVWriter();
1601 
1602  $writer->addColumn($this->lng->txt('title'));
1603  $writer->addColumn($this->lng->txt('description'));
1604  $writer->addColumn($this->lng->txt('ecs_imported_from'));
1605  $writer->addColumn($this->lng->txt('ecs_field_courseID'));
1606  $writer->addColumn($this->lng->txt('ecs_field_term'));
1607  $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
1608  $writer->addColumn($this->lng->txt('ecs_field_courseType'));
1609  $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
1610  $writer->addColumn($this->lng->txt('ecs_field_credits'));
1611  $writer->addColumn($this->lng->txt('ecs_field_room'));
1612  $writer->addColumn($this->lng->txt('ecs_field_cycle'));
1613  $writer->addColumn($this->lng->txt('ecs_field_begin'));
1614  $writer->addColumn($this->lng->txt('ecs_field_end'));
1615  $writer->addColumn($this->lng->txt('last_update'));
1616 
1617  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1619 
1620  foreach($obj_ids as $obj_id)
1621  {
1622  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1623  $values = ilAdvancedMDValues::_getValuesByObjId($obj_id);
1624 
1625  $writer->addRow();
1626  $writer->addColumn(ilObject::_lookupTitle($obj_id));
1627  $writer->addColumn(ilObject::_lookupDescription($obj_id));
1628 
1629  $mid = ilObjRemoteCourse::_lookupMID($obj_id);
1630  if($reader and ($participant = $reader->getParticipantByMID($mid)))
1631  {
1632  $writer->addColumn($participant->getParticipantName());
1633  }
1634  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'courseID');
1635  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1636 
1637  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'term');
1638  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1639 
1640  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'lecturer');
1641  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1642 
1643  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'courseType');
1644  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1645 
1646  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'semester_hours');
1647  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1648 
1649  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'credits');
1650  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1651 
1652  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'room');
1653  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1654 
1655  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'cycle');
1656  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1657 
1658  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'begin');
1659  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1660 
1661  $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'end');
1662  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1663 
1664  $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
1665  }
1666  ilUtil::deliverData($writer->getCSVString(), date("Y_m_d")."_ecs_import.csv", "text/csv");
1667  }
1668 
1675  protected function released()
1676  {
1677  global $ilUser, $ilToolbar;
1678 
1679  $this->tabs_gui->setSubTabActive('ecs_released');
1680 
1681  if($this->settings->isEnabled())
1682  {
1683  $ilToolbar->addButton(
1684  $this->lng->txt('ecs_read_remote_links'),
1685  $this->ctrl->getLinkTarget($this,'readAll')
1686  );
1687 
1688  $ilToolbar->addSeparator();
1689  }
1690 
1691  $sel_type = $_REQUEST["otype"];
1692  if(!$sel_type)
1693  {
1694  $sel_type = "rcrs";
1695  }
1696 
1697  include "Services/WebServices/ECS/classes/class.ilECSUtils.php";
1699 
1700  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1701  $sel = new ilSelectInputGUI("", "otype");
1702  $sel->setOptions($options);
1703  $sel->setValue($sel_type);
1704  $ilToolbar->addInputItem($sel);
1705 
1706  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "released"));
1707  $ilToolbar->addFormButton($this->lng->txt("submit"), "released");
1708 
1709  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
1710  $exported = ilECSExport::getExportedIdsByType($sel_type);
1711  if(count($exported))
1712  {
1713  $ilToolbar->addSeparator();
1714 
1715  $ilToolbar->addButton(
1716  $this->lng->txt('csv_export'),
1717  $this->ctrl->getLinkTarget($this,'exportReleased')
1718  );
1719  }
1720 
1721  include_once('Services/WebServices/ECS/classes/class.ilECSReleasedContentTableGUI.php');
1722  $table_gui = new ilECSReleasedContentTableGUI($this,'released');
1723  $table_gui->setTitle($this->lng->txt('ecs_released_content'));
1724  $table_gui->parse($exported);
1725  $this->tpl->setContent($table_gui->getHTML());
1726 
1727  return true;
1728  }
1729 
1736  protected function exportReleased()
1737  {
1738  global $ilObjDataCache;
1739 
1740  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
1741  $exported = ilECSExport::getExportedIds();
1742  $ilObjDataCache->preloadObjectCache($exported);
1743 
1744  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
1745  $writer = new ilCSVWriter();
1746 
1747  $writer->addColumn($this->lng->txt('title'));
1748  $writer->addColumn($this->lng->txt('description'));
1749  $writer->addColumn($this->lng->txt('ecs_field_courseID'));
1750  $writer->addColumn($this->lng->txt('ecs_field_term'));
1751  $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
1752  $writer->addColumn($this->lng->txt('ecs_field_courseType'));
1753  $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
1754  $writer->addColumn($this->lng->txt('ecs_field_credits'));
1755  $writer->addColumn($this->lng->txt('ecs_field_room'));
1756  $writer->addColumn($this->lng->txt('ecs_field_cycle'));
1757  $writer->addColumn($this->lng->txt('ecs_field_begin'));
1758  $writer->addColumn($this->lng->txt('ecs_field_end'));
1759  $writer->addColumn($this->lng->txt('last_update'));
1760 
1761  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1763 
1764  foreach($exported as $obj_id)
1765  {
1766  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1767  $values = ilAdvancedMDValues::_getValuesByObjId($obj_id);
1768 
1769  $writer->addRow();
1770  $writer->addColumn(ilObject::_lookupTitle($obj_id));
1771  $writer->addColumn(ilObject::_lookupDescription($obj_id));
1772 
1773  $field = $settings->getMappingByECSName('courseID');
1774  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1775 
1776  $field = $settings->getMappingByECSName('term');
1777  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1778 
1779  $field = $settings->getMappingByECSName('lecturer');
1780  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1781 
1782  $field = $settings->getMappingByECSName('courseType');
1783  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1784 
1785  $field = $settings->getMappingByECSName('semester_hours');
1786  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1787 
1788  $field = $settings->getMappingByECSName('credits');
1789  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1790 
1791  $field = $settings->getMappingByECSName('room');
1792  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1793 
1794  $field = $settings->getMappingByECSName('cycle');
1795  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1796 
1797  $field = $settings->getMappingByECSName('begin');
1798  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1799 
1800  $field = $settings->getMappingByECSName('end');
1801  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1802 
1803  $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
1804  }
1805 
1806  ilUtil::deliverData($writer->getCSVString(), date("Y_m_d")."_ecs_export.csv", "text/csv");
1807  }
1808 
1809 
1815  protected function prepareFieldSelection($fields)
1816  {
1817  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
1818 
1819  $options[0] = $this->lng->txt('ecs_ignore_field');
1820  foreach($fields as $field)
1821  {
1823  $title = ilAdvancedMDRecord::_lookupTitle($field->getRecordId());
1824  $options[$field->getFieldId()] = $title.': '.$field->getTitle();
1825  }
1826  return $options;
1827  }
1828 
1829 
1830 
1836  protected function initSettings($a_server_id = 1)
1837  {
1838  include_once('Services/WebServices/ECS/classes/class.ilECSSetting.php');
1839  $this->settings = ilECSSetting::getInstanceByServerId($a_server_id);
1840  }
1841 
1847  protected function setSubTabs()
1848  {
1849  $this->tabs_gui->clearSubTabs();
1850 
1851  $this->tabs_gui->addSubTabTarget("overview",
1852  $this->ctrl->getLinkTarget($this,'overview'),
1853  "overview",get_class($this));
1854 
1855  // Disable all other tabs, if server hasn't been configured.
1856  ilECSServerSettings::getInstance()->readInactiveServers();
1857  if(!ilECSServerSettings::getInstance()->serverExists())
1858  {
1859  return true;
1860  }
1861 
1862  $this->tabs_gui->addSubTabTarget("ecs_communities",
1863  $this->ctrl->getLinkTarget($this,'communities'),
1864  "communities",get_class($this));
1865 
1866  $this->tabs_gui->addSubTabTarget('ecs_mappings',
1867  $this->ctrl->getLinkTarget($this,'importMappings'),
1868  'importMappings',get_class($this));
1869 
1870  $this->tabs_gui->addSubTabTarget('ecs_category_mapping',
1871  $this->ctrl->getLinkTarget($this,'categoryMapping'));
1872 
1873  $this->tabs_gui->addSubTabTarget('ecs_import',
1874  $this->ctrl->getLinkTarget($this,'imported'));
1875 
1876  $this->tabs_gui->addSubTabTarget('ecs_released',
1877  $this->ctrl->getLinkTarget($this,'released'));
1878 
1879  }
1880 
1886  private function prepareRoleSelect()
1887  {
1888  global $rbacreview,$ilObjDataCache;
1889 
1890  $global_roles = ilUtil::_sortIds($rbacreview->getGlobalRoles(),
1891  'object_data',
1892  'title',
1893  'obj_id');
1894 
1895  $select[0] = $this->lng->txt('links_select_one');
1896  foreach($global_roles as $role_id)
1897  {
1898  $select[$role_id] = ilObject::_lookupTitle($role_id);
1899  }
1900  return $select;
1901  }
1902 
1903  private function buildPath($a_ref_id)
1904  {
1905  $loc = new ilLocatorGUI();
1906  $loc->setTextOnly(false);
1907  $loc->addContextItems($a_ref_id);
1908 
1909  return $loc->getHTML();
1910  }
1911 
1917  protected function initTaskScheduler()
1918  {
1919  global $ilDB,$ilSetting;
1920 
1921  #$ilDB->lockTables(array('name' => 'settings', 'type' => ilDB::LOCK_WRITE));
1922  $setting = new ilSetting('ecs');
1923  $setting->set(
1924  'next_execution_'.$this->settings->getServerId(),
1925  time() + (int) $this->settings->getPollingTime()
1926  );
1927  }
1928 
1929 }
1930 
1931 ?>