ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
24include_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 global $ilAccess;
75 $next_class = $this->ctrl->getNextClass($this);
76 $cmd = $this->ctrl->getCmd();
77
78 $this->setSubTabs();
79 switch($next_class)
80 {
81 case 'ilecsmappingsettingsgui':
82 include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingSettingsGUI.php';
83 $mapset = new ilECSMappingSettingsGUI($this, (int) $_REQUEST['server_id'], (int) $_REQUEST['mid']);
84 $this->ctrl->setReturn($this,'communities');
85 $this->ctrl->forwardCommand($mapset);
86 break;
87
88 case 'ilecsparticipantsettingsgui':
89 include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettingsGUI.php';
91 (int) $_REQUEST['server_id'],
92 (int) $_REQUEST['mid']
93 );
94 $this->ctrl->setReturn($this,'communities');
95 $this->ctrl->forwardCommand($part);
96 break;
97
98 default:
99
100 if(!$ilAccess->checkAccess('write','',$_REQUEST["ref_id"]) && $cmd != "overview" && $cmd != "communities")
101 {
102 $this->ctrl->redirect($this, "overview");
103 }
104
105 if(!$cmd || $cmd == 'view')
106 {
107 $cmd = "overview";
108 }
109 $this->$cmd();
110 break;
111 }
112 return true;
113 }
114
121 public function overview()
122 {
123 global $ilToolbar,$ilTabs, $ilAccess;
124
125 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
126
127 $ilTabs->setSubTabActive('overview');
128 if($ilAccess->checkAccess('write','',$_REQUEST["ref_id"]))
129 {
130 $ilToolbar->addButton(
131 $this->lng->txt('ecs_add_new_ecs'),
132 $this->ctrl->getLinkTarget($this,'create')
133 );
134 }
135
137 $servers->readInactiveServers();
138
139 include_once './Services/WebServices/ECS/classes/class.ilECSServerTableGUI.php';
140 $table = new ilECSServerTableGUI($this,'overview');
141 $table->initTable();
142 $table->parse($servers);
143 $this->tpl->setContent($table->getHTML());
144 return;
145 }
146
150 protected function activate()
151 {
152 $this->initSettings($_REQUEST['server_id']);
153 $this->settings->setEnabledStatus(true);
154 $this->settings->update();
155 ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
156 $this->ctrl->redirect($this,'overview');
157 }
158
162 protected function deactivate()
163 {
164 $this->initSettings($_REQUEST['server_id']);
165 $this->settings->setEnabledStatus(false);
166 $this->settings->update();
167 ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
168 $this->ctrl->redirect($this,'overview');
169 }
170
176 protected function readAll()
177 {
178 include_once('Services/WebServices/ECS/classes/class.ilECSConnector.php');
179 include_once('Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
180 include_once('./Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php');
181 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
182
183 try
184 {
185 foreach(ilECSServerSettings::getInstance()->getServers() as $server)
186 {
189
190 include_once('./Services/WebServices/ECS/classes/class.ilECSTaskScheduler.php');
191 ilECSTaskScheduler::_getInstanceByServerId($server->getServerId())->startTaskExecution();
192
193 ilUtil::sendInfo($this->lng->txt('ecs_remote_imported'));
194 $this->imported();
195 return true;
196 }
197 }
198 catch(ilECSConnectorException $e1)
199 {
200 ilUtil::sendInfo('Cannot connect to ECS server: '.$e1->getMessage());
201 $this->imported();
202 return false;
203 }
204 catch(ilException $e2)
205 {
206 ilUtil::sendInfo('Update failed: '.$e1->getMessage());
207 $this->imported();
208 return false;
209 }
210 }
211
216 protected function create()
217 {
218 global $ilTabs;
219
220 $this->initSettings(0);
221
222 $ilTabs->clearTargets();
223 $ilTabs->clearSubTabs();
224 $ilTabs->setBackTarget($this->lng->txt('back'),$this->ctrl->getLinkTarget($this,'overview'));
225
226 $this->initSettingsForm('create');
227 $this->tabs_gui->setSubTabActive('ecs_settings');
228
229 $this->tpl->setContent($this->form->getHTML());
230 }
231
235 protected function edit()
236 {
237 global $ilTabs;
238
239 $this->initSettings((int) $_REQUEST['server_id']);
240 $this->ctrl->saveParameter($this,'server_id',(int) $_REQUEST['server_id']);
241
242 $ilTabs->clearTargets();
243 $ilTabs->clearSubTabs();
244 $ilTabs->setBackTarget($this->lng->txt('back'),$this->ctrl->getLinkTarget($this,'overview'));
245
246 $this->initSettingsForm();
247 $this->tabs_gui->setSubTabActive('ecs_settings');
248
249 $this->tpl->setContent($this->form->getHTML());
250 }
251
252 protected function cp()
253 {
254 $this->initSettings((int) $_REQUEST['server_id']);
255
256 $copy = clone $this->settings;
257 $copy->save();
258
259 $this->ctrl->setParameter($this,'server_id',$copy->getServerId());
260 ilUtil::sendSuccess($this->lng->txt('ecs_settings_cloned'),true);
261 $this->ctrl->redirect($this,'edit');
262 }
263
267 protected function delete()
268 {
269 global $ilTabs;
270
271 $this->initSettings((int) $_REQUEST['server_id']);
272
273 $ilTabs->clearTargets();
274 $ilTabs->clearSubTabs();
275 $ilTabs->setBackTarget($this->lng->txt('back'),$this->ctrl->getLinkTarget($this,'overview'));
276
277 include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
278 $confirm = new ilConfirmationGUI();
279 $confirm->setFormAction($this->ctrl->getFormAction($this));
280 $confirm->setConfirm($this->lng->txt('delete'), 'doDelete');
281 $confirm->setCancel($this->lng->txt('cancel'), 'overview');
282 $confirm->setHeaderText($this->lng->txt('ecs_delete_setting'));
283
284 $confirm->addItem('','',$this->settings->getServer());
285 $confirm->addHiddenItem('server_id', $this->settings->getServerId());
286
287 $this->tpl->setContent($confirm->getHTML());
288 }
289
293 protected function doDelete()
294 {
295 $this->initSettings($_REQUEST['server_id']);
296 $this->settings->delete();
297
298 // Delete communities
299 include_once './Services/WebServices/ECS/classes/class.ilECSCommunitiesCache.php';
300 ilECSCommunitiesCache::delete((int) $_REQUEST['server_id']);
301
302 include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php';
304
305 include_once './Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php';
307
308 include_once './Services/WebServices/ECS/classes/class.ilECSExport.php';
309 ilECSExport::deleteByServer((int) $_REQUEST['server_id']);
310
311 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
312 ilECSImport::deleteByServer((int) $_REQUEST['server_id']);
313
314 include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
316
317 ilUtil::sendSuccess($this->lng->txt('ecs_setting_deleted'),true);
318 $this->ctrl->redirect($this,'overview');
319 }
320
321
327 protected function settings()
328 {
329 $this->initSettingsForm();
330 $this->tabs_gui->setSubTabActive('ecs_settings');
331
332 $this->tpl->setContent($this->form->getHTML());
333 }
334
340 protected function initSettingsForm($a_mode = 'update')
341 {
342 if(is_object($this->form))
343 {
344 return true;
345 }
346 include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
347
348 $this->form = new ilPropertyFormGUI();
349 $this->form->setFormAction($this->ctrl->getFormAction($this,'settings'));
350 $this->form->setTitle($this->lng->txt('ecs_connection_settings'));
351
352 $ena = new ilCheckboxInputGUI($this->lng->txt('ecs_active'),'active');
353 $ena->setChecked($this->settings->isEnabled());
354 $ena->setValue(1);
355 $this->form->addItem($ena);
356
357 $server_title = new ilTextInputGUI($this->lng->txt('ecs_server_title'),'title');
358 $server_title->setValue($this->settings->getTitle());
359 $server_title->setSize(80);
360 $server_title->setMaxLength(128);
361 $server_title->setRequired(true);
362 $this->form->addItem($server_title);
363
364 $ser = new ilTextInputGUI($this->lng->txt('ecs_server_url'),'server');
365 $ser->setValue((string) $this->settings->getServer());
366 $ser->setRequired(true);
367 $this->form->addItem($ser);
368
369 $pro = new ilSelectInputGUI($this->lng->txt('ecs_protocol'),'protocol');
370 // fixed to https
371 #$pro->setOptions(array(ilECSSetting::PROTOCOL_HTTP => $this->lng->txt('http'),
372 # ilECSSetting::PROTOCOL_HTTPS => $this->lng->txt('https')));
373 $pro->setOptions(array(ilECSSetting::PROTOCOL_HTTPS => 'HTTPS'));
374 $pro->setValue($this->settings->getProtocol());
375 $pro->setRequired(true);
376 $this->form->addItem($pro);
377
378 $por = new ilTextInputGUI($this->lng->txt('ecs_port'),'port');
379 $por->setSize(5);
380 $por->setMaxLength(5);
381 $por->setValue((string) $this->settings->getPort());
382 $por->setRequired(true);
383 $this->form->addItem($por);
384
385 $tcer = new ilRadioGroupInputGUI($this->lng->txt('ecs_auth_type'),'auth_type');
386 $tcer->setValue($this->settings->getAuthType());
387 $this->form->addItem($tcer);
388
389 // Certificate based authentication
390 $cert_based = new ilRadioOption($this->lng->txt('ecs_auth_type_cert'), ilECSSetting::AUTH_CERTIFICATE);
391 $tcer->addOption($cert_based);
392
393 $cli = new ilTextInputGUI($this->lng->txt('ecs_client_cert'),'client_cert');
394 $cli->setSize(60);
395 $cli->setValue((string) $this->settings->getClientCertPath());
396 $cli->setRequired(true);
397 $cert_based->addSubItem($cli);
398
399 $key = new ilTextInputGUI($this->lng->txt('ecs_cert_key'),'key_path');
400 $key->setSize(60);
401 $key->setValue((string) $this->settings->getKeyPath());
402 $key->setRequired(true);
403 $cert_based->addSubItem($key);
404
405 $cerp = new ilTextInputGUI($this->lng->txt('ecs_key_password'),'key_password');
406 $cerp->setSize(12);
407 $cerp->setValue((string) $this->settings->getKeyPassword());
408 $cerp->setInputType('password');
409 $cerp->setRequired(true);
410 $cert_based->addSubItem($cerp);
411
412 $cer = new ilTextInputGUI($this->lng->txt('ecs_ca_cert'),'ca_cert');
413 $cer->setSize(60);
414 $cer->setValue((string) $this->settings->getCACertPath());
415 $cer->setRequired(true);
416 $cert_based->addSubItem($cer);
417
418 // Apache auth
419 $apa_based = new ilRadioOption($this->lng->txt('ecs_auth_type_apache'), ilECSSetting::AUTH_APACHE);
420 $tcer->addOption($apa_based);
421
422 $user = new ilTextInputGUI($this->lng->txt('ecs_apache_user'),'auth_user');
423 $user->setSize(32);
424 $user->setValue((string) $this->settings->getAuthUser());
425 $user->setRequired(true);
426 $apa_based->addSubItem($user);
427
428 $pass = new ilPasswordInputGUI($this->lng->txt('ecs_apache_pass'), 'auth_pass');
429 $pass->setRetype(false);
430 $pass->setSize(32);
431 $pass->setMaxLength(128);
432 $pass->setValue((string) $this->settings->getAuthPass());
433 $pass->setRequired(true);
434 $pass->setSkipSyntaxCheck(TRUE);
435 $apa_based->addSubItem($pass);
436
437
438 $ser = new ilNonEditableValueGUI($this->lng->txt('cert_serial'));
439 $ser->setValue($this->settings->getCertSerialNumber() ? $this->settings->getCertSerialNumber() : $this->lng->txt('ecs_no_value'));
440 $cert_based->addSubItem($ser);
441
442 $loc = new ilFormSectionHeaderGUI();
443 $loc->setTitle($this->lng->txt('ecs_local_settings'));
444 $this->form->addItem($loc);
445
446 $pol = new ilDurationInputGUI($this->lng->txt('ecs_polling'),'polling');
447 $pol->setShowDays(false);
448 $pol->setShowHours(false);
449 $pol->setShowMinutes(true);
450 $pol->setShowSeconds(true);
451 $pol->setSeconds($this->settings->getPollingTimeSeconds());
452 $pol->setMinutes($this->settings->getPollingTimeMinutes());
453 $pol->setRequired(true);
454 $pol->setInfo($this->lng->txt('ecs_polling_info'));
455 $this->form->addItem($pol);
456
457 $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'));
458 $imp->setRequired(true);
459
460 $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
461 $tpl->setVariable('SIZE',5);
462 $tpl->setVariable('MAXLENGTH',11);
463 $tpl->setVariable('POST_VAR','import_id');
464 $tpl->setVariable('PROPERTY_VALUE',$this->settings->getImportId());
465
466 if($this->settings->getImportId())
467 {
468 $tpl->setVariable('COMPLETE_PATH',$this->buildPath($this->settings->getImportId()));
469 }
470
471 $imp->setHTML($tpl->get());
472 $imp->setInfo($this->lng->txt('ecs_import_id_info'));
473 $this->form->addItem($imp);
474
475 $loc = new ilFormSectionHeaderGUI();
476 $loc->setTitle($this->lng->txt('ecs_remote_user_settings'));
477 $this->form->addItem($loc);
478
479 $role = new ilSelectInputGUI($this->lng->txt('ecs_role'),'global_role');
480 $role->setOptions($this->prepareRoleSelect());
481 $role->setValue($this->settings->getGlobalRole());
482 $role->setInfo($this->lng->txt('ecs_global_role_info'));
483 $role->setRequired(true);
484 $this->form->addItem($role);
485
486 $duration = new ilDurationInputGUI($this->lng->txt('ecs_account_duration'),'duration');
487 $duration->setInfo($this->lng->txt('ecs_account_duration_info'));
488 $duration->setMonths($this->settings->getDuration());
489 $duration->setShowSeconds(false);
490 $duration->setShowMinutes(false);
491 $duration->setShowHours(false);
492 $duration->setShowDays(false);
493 $duration->setShowMonths(true);
494 $duration->setRequired(true);
495 $this->form->addItem($duration);
496
497 // Email recipients
498 $loc = new ilFormSectionHeaderGUI();
499 $loc->setTitle($this->lng->txt('ecs_notifications'));
500 $this->form->addItem($loc);
501
502 $rcp_user = new ilTextInputGUI($this->lng->txt('ecs_user_rcp'),'user_recipients');
503 $rcp_user->setValue((string) $this->settings->getUserRecipientsAsString());
504 $rcp_user->setInfo($this->lng->txt('ecs_user_rcp_info'));
505 $this->form->addItem($rcp_user);
506
507 $rcp_econ = new ilTextInputGUI($this->lng->txt('ecs_econ_rcp'),'econtent_recipients');
508 $rcp_econ->setValue((string) $this->settings->getEContentRecipientsAsString());
509 $rcp_econ->setInfo($this->lng->txt('ecs_econ_rcp_info'));
510 $this->form->addItem($rcp_econ);
511
512 $rcp_app = new ilTextInputGUI($this->lng->txt('ecs_approval_rcp'),'approval_recipients');
513 $rcp_app->setValue((string) $this->settings->getApprovalRecipientsAsString());
514 $rcp_app->setInfo($this->lng->txt('ecs_approval_rcp_info'));
515 $this->form->addItem($rcp_app);
516
517 if($a_mode == 'update')
518 {
519 $this->form->addCommandButton('update',$this->lng->txt('save'));
520 }
521 else
522 {
523 $this->form->addCommandButton('save',$this->lng->txt('save'));
524 }
525 $this->form->addCommandButton('overview',$this->lng->txt('cancel'));
526 }
527
533 protected function update()
534 {
535 $this->initSettings((int) $_REQUEST['server_id']);
536 $this->loadFromPost();
537
538 if(!$error = $this->settings->validate())
539 {
540 $this->settings->update();
541 $this->initTaskScheduler();
542 #$this->updateTitle();
543 ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
544 }
545 else
546 {
547 ilUtil::sendInfo($this->lng->txt($error));
548 $this->edit();
549 }
550
551 $this->overview();
552 return true;
553 }
554
559 protected function save()
560 {
561 $this->initSettings(0);
562 $this->loadFromPost();
563
564 if(!$error = $this->settings->validate())
565 {
566 $this->settings->save();
567 $this->initTaskScheduler();
568
569 #$this->updateTitle();
570 ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
571 }
572 else
573 {
574 ilUtil::sendInfo($this->lng->txt($error));
575 return $this->create();
576 }
577 $GLOBALS['ilCtrl']->redirect($this,'overview');
578 return true;
579 }
580
584 protected function updateTitle()
585 {
586 try
587 {
588 include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
590
591 foreach($reader->getCommunities() as $community)
592 {
593 foreach($community->getParticipants() as $part)
594 {
595 $GLOBALS['ilLog']->write(__METHOD__.': '.print_r($community,true));
596 if($part->isSelf())
597 {
598 $this->settings->setTitle($part->getParticipantName());
599 $this->settings->update();
600 return true;
601 }
602 }
603 }
604 }
605 catch(ilECSConnectorException $exc)
606 {
607 ilUtil::sendFailure($exc->getMessage());
608 }
609 $this->settings->setTitle('');
610 $this->settings->update();
611 }
612
616 protected function loadFromPost()
617 {
618 $this->settings->setEnabledStatus((int) $_POST['active']);
619 $this->settings->setTitle(ilUtil::stripSlashes($_POST['title']));
620 $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
621 $this->settings->setPort(ilUtil::stripSlashes($_POST['port']));
622 $this->settings->setProtocol(ilUtil::stripSlashes($_POST['protocol']));
623 $this->settings->setClientCertPath(ilUtil::stripSlashes($_POST['client_cert']));
624 $this->settings->setCACertPath(ilUtil::stripSlashes($_POST['ca_cert']));
625 $this->settings->setKeyPath(ilUtil::stripSlashes($_POST['key_path']));
626 $this->settings->setKeyPassword(ilUtil::stripSlashes($_POST['key_password']));
627 $this->settings->setImportId(ilUtil::stripSlashes($_POST['import_id']));
628 $this->settings->setPollingTimeMS((int) $_POST['polling']['mm'],(int) $_POST['polling']['ss']);
629 $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
630 $this->settings->setGlobalRole((int) $_POST['global_role']);
631 $this->settings->setDuration((int) $_POST['duration']['MM']);
632
633 $this->settings->setUserRecipients(ilUtil::stripSlashes($_POST['user_recipients']));
634 $this->settings->setEContentRecipients(ilUtil::stripSlashes($_POST['econtent_recipients']));
635 $this->settings->setApprovalRecipients(ilUtil::stripSlashes($_POST['approval_recipients']));
636
637 $this->settings->setAuthType((int) $_POST['auth_type']);
638 $this->settings->setAuthPass(ilUtil::stripSlashes($_POST['auth_pass']));
639 $this->settings->setAuthUser(ilUtil::stripSlashes($_POST['auth_user']));
640
641 }
642
646 protected function refreshParticipants()
647 {
648 include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
649 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
650 include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
651 include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
652
654 $servers->readInactiveServers();
655 foreach($servers->getServers() as $server)
656 {
657
658 // read community
659 try {
660
661 $creader = ilECSCommunityReader::getInstanceByServerId($server->getServerId());
662 foreach(ilECSParticipantSettings::getAvailabeMids($server->getServerId()) as $mid)
663 {
664 if(!$creader->getParticipantByMID($mid))
665 {
666 $GLOBALS['ilLog']->write(__METHOD__.': Deleting deprecated participant '. $server->getServerId().' '. $mid);
667
668 $part = new ilECSParticipantSetting($server->getServerId(),$mid);
669 $part->delete();
670 }
671 }
672 }
674 {
675 ilUtil::sendFailure($server->getServer().': '. $e->getMessage(),TRUE);
676 }
677 }
678 ilUtil::sendSuccess($this->lng->txt('settings_saved'),TRUE);
679 $this->ctrl->redirect($this,'communities');
680 }
681
688 public function communities()
689 {
690 global $ilAccess;
691 // add toolbar to refresh communities
692 if($ilAccess->checkAccess('write','',$_REQUEST["ref_id"]))
693 {
694 $GLOBALS['ilToolbar']->addButton(
695 $this->lng->txt('ecs_refresh_participants'),
696 $this->ctrl->getLinkTarget($this,'refreshParticipants')
697 );
698 }
699
700
701 $this->tabs_gui->setSubTabActive('ecs_communities');
702
703 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_communities.html','Services/WebServices/ECS');
704
705 $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this,'updateCommunities'));
706
707 if($ilAccess->checkAccess('write','',$_REQUEST["ref_id"]))
708 {
709 $this->tpl->setCurrentBlock("submit_buttons");
710 $this->tpl->setVariable('TXT_SAVE',$this->lng->txt('save'));
711 $this->tpl->setVariable('TXT_CANCEL', $this->lng->txt('cancel'));
712 $this->tpl->parseCurrentBlock();
713 }
714
715 include_once('Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
716 include_once('Services/WebServices/ECS/classes/class.ilECSCommunityTableGUI.php');
717
718 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
720 #$settings->readInactiveServers();
721
722 foreach($settings->getServers() as $server)
723 {
724 // Try to read communities
725 try
726 {
728 foreach($reader->getCommunities() as $community)
729 {
730 $this->tpl->setCurrentBlock('table_community');
731 $table_gui = new ilECSCommunityTableGUI($server,$this,'communities',$community->getId());
732 $table_gui->setTitle($community->getTitle().' ('.$community->getDescription().')');
733 $table_gui->parse($community->getParticipants());
734 $this->tpl->setVariable('TABLE_COMM',$table_gui->getHTML());
735 $this->tpl->parseCurrentBlock();
736 }
737 }
738 catch(ilECSConnectorException $exc)
739 {
740 // Maybe server is not fully configured
741 continue;
742 }
743
744 // Show section for each server
745 $this->tpl->setCurrentBlock('server');
746 $this->tpl->setVariable('TXT_SERVER_NAME',$server->getTitle());
747 $this->tpl->parseCurrentBlock();
748 }
749 }
750
756 protected function validateImportTypes(&$import_types)
757 {
758 include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
759
760 $num_cms = 0;
761 foreach((array) $import_types as $sid => $server)
762 {
763 foreach((array) $server as $mid => $import_type)
764 {
765 if($import_type == ilECSParticipantSetting::IMPORT_CMS)
766 {
767 ++$num_cms;
768 }
769 }
770 }
771
772 if($num_cms <= 1)
773 {
774 return true;
775 }
776 // Change to import type "UNCHANGED"
777 $new_types = array();
778 foreach((array) $import_types as $sid => $server)
779 {
780 foreach((array) $server as $mid => $import_type)
781 {
782 if($import_type == ilECSParticipantSetting::IMPORT_CMS)
783 {
784 $new_types[$sid][$mid] = ilECSParticipantSetting::IMPORT_UNCHANGED;
785 }
786 else
787 {
788 $new_types[$sid][$mid] = $import_type;
789 }
790 }
791 }
792 $import_types = $new_types;
793 return false;
794 }
795
802 protected function updateCommunities()
803 {
804 global $ilLog;
805
806 include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
807 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
808
809 // @TODO: Delete deprecated communities
810 $invalidImportTypes = false;
811 if(!$this->validateImportTypes($_POST['import_type']))
812 {
813 $invalidImportTypes = true;
814 }
815
817 foreach($servers->getServers() as $server)
818 {
819 try {
820 // Read communities
821 $cReader = ilECSCommunityReader::getInstanceByServerId($server->getServerId());
822
823 // Update community cache
824 foreach($cReader->getCommunities() as $community)
825 {
826 include_once './Services/WebServices/ECS/classes/class.ilECSCommunityCache.php';
827 $cCache = ilECSCommunityCache::getInstance($server->getServerId(), $community->getId());
828 $cCache->setCommunityName($community->getTitle());
829 $cCache->setMids($community->getMids());
830 $cCache->setOwnId($community->getOwnId());
831 $cCache->update();
832 }
833 }
834 catch(Exception $e)
835 {
836 $GLOBALS['ilLog']->write(__METHOD__.': Cannot read ecs communities: '.$e->getMessage());
837 }
838 }
839
840 include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
841 foreach((array) $_POST['sci_mid'] as $sid => $tmp)
842 {
843 foreach((array) $_POST['sci_mid'][$sid] as $mid => $tmp)
844 {
845 $set = new ilECSParticipantSetting($sid, $mid);
846 #$set->enableExport(array_key_exists($mid, (array) $_POST['export'][$sid]) ? true : false);
847 #$set->enableImport(array_key_exists($mid, (array) $_POST['import'][$sid]) ? true : false);
848 $set->setImportType($_POST['import_type'][$sid][$mid]);
849
850 // update title/cname
851 try {
852 $part = ilECSCommunityReader::getInstanceByServerId($sid)->getParticipantByMID($mid);
853 if($part instanceof ilECSParticipant)
854 {
855 $set->setTitle($part->getParticipantName());
856 }
857 $com = ilECSCommunityReader::getInstanceByServerId($sid)->getCommunityByMID($mid);
858 if($com instanceof ilECSCommunity)
859 {
860 $set->setCommunityName($com->getTitle());
861 }
862 }
863 catch(Exception $e)
864 {
865 $GLOBALS['ilLog']->write(__METHOD__.': Cannot read ecs communities: '.$e->getMessage());
866 }
867
868 $set->update();
869 }
870 }
871 if($invalidImportTypes)
872 {
873 ilUtil::sendFailure($this->lng->txt('ecs_invalid_import_type_cms'),true);
874 }
875 else
876 {
877 ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
878 }
879 $GLOBALS['ilCtrl']->redirect($this,'communities');
880
881 // TODO: Do update of remote courses and ...
882
883 return true;
884 }
885
886
892 protected function setMappingTabs($a_active)
893 {
894 global $ilTabs, $ilAccess;
895
896 $ilTabs->clearTargets();
897 $ilTabs->clearSubTabs();
898
899 $ilTabs->setBackTarget(
900 $this->lng->txt('ecs_settings'),
901 $this->ctrl->getLinkTarget($this,'overview')
902 );
903 if($ilAccess->checkAccess('write','',$_REQUEST["ref_id"]))
904 {
905 $ilTabs->addTab(
906 'import',
907 $this->lng->txt('ecs_tab_import'),
908 $this->ctrl->getLinkTarget($this,'importMappings')
909 );
910 }
911 $ilTabs->addTab(
912 'export',
913 $this->lng->txt('ecs_tab_export'),
914 $this->ctrl->getLinkTarget($this,'exportMappings')
915 );
916
917
918 switch($a_active)
919 {
921 $ilTabs->activateTab('import');
922 break;
923
925 $ilTabs->activateTab('export');
926 break;
927 }
928 return true;
929 }
930
936 public function importMappings()
937 {
938 global $ilToolbar;
939
940 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
941
942 $this->setMappingTabs(self::MAPPING_IMPORT);
943
945 if(!count($fields))
946 {
947 ilUtil::sendInfo($this->lng->txt('ecs_no_adv_md'));
948 return true;
949 }
950
951 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
953 $settings->readInactiveServers();
954
955 $sel_srv = (int)$_REQUEST["ecs_mapping_server"];
956 if(!$sel_srv)
957 {
958 $sel_srv = $_SESSION["ecs_sel_srv"];
959 }
960 else
961 {
962 $_SESSION["ecs_sel_srv"] = $sel_srv;
963 }
964
965 // Iterate all servers
966 $options = array(0 => $this->lng->txt("please_choose"));
967 foreach($settings->getServers() as $server)
968 {
969 $title = $server->getTitle();
970 if(!$title)
971 {
972 $title = "ECS (".$server->getServerId().")";
973 }
974 $options[$server->getServerId()] = $title;
975 }
976
977 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
978 $sel = new ilSelectInputGUI("", "ecs_mapping_server");
979 $sel->setOptions($options);
980 $sel->setValue($sel_srv);
981 $ilToolbar->addInputItem($sel);
982
983 $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "importMappings"));
984 $ilToolbar->addFormButton($this->lng->txt("submit"), "importMappings");
985
986 if($sel_srv)
987 {
988 $form = $this->initMappingsForm($sel_srv, self::MAPPING_IMPORT);
989 $this->tpl->setContent($form->getHTML());
990 }
991
992 return true;
993 }
994
1000 protected function exportMappings()
1001 {
1002 global $ilToolbar;
1003
1004 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1005
1006 $this->setMappingTabs(self::MAPPING_EXPORT);
1007
1009 if(!count($fields))
1010 {
1011 ilUtil::sendInfo($this->lng->txt('ecs_no_adv_md'));
1012 return true;
1013 }
1014
1015 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
1017 $settings->readInactiveServers();
1018
1019 $sel_srv = (int)$_REQUEST["ecs_mapping_server"];
1020 if(!$sel_srv)
1021 {
1022 $sel_srv = $_SESSION["ecs_sel_srv"];
1023 }
1024 else
1025 {
1026 $_SESSION["ecs_sel_srv"] = $sel_srv;
1027 }
1028
1029 // Iterate all servers
1030 $options = array(0 => $this->lng->txt("please_choose"));
1031 foreach($settings->getServers() as $server)
1032 {
1033 $title = $server->getTitle();
1034 if(!$title)
1035 {
1036 $title = "ECS (".$server->getServerId().")";
1037 }
1038 $options[$server->getServerId()] = $title;
1039 }
1040
1041 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1042 $sel = new ilSelectInputGUI("", "ecs_mapping_server");
1043 $sel->setOptions($options);
1044 $sel->setValue($sel_srv);
1045 $ilToolbar->addInputItem($sel);
1046
1047 $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "exportMappings"));
1048 $ilToolbar->addFormButton($this->lng->txt("submit"), "exportMappings");
1049
1050 if($sel_srv)
1051 {
1052 $form = $this->initMappingsForm($sel_srv,self::MAPPING_EXPORT);
1053 $this->tpl->setContent($form->getHTML());
1054 }
1055
1056 return true;
1057 }
1058
1065 protected function saveImportMappings()
1066 {
1067 foreach((array) $_POST['mapping'] as $mtype => $mappings)
1068 {
1069 foreach((array) $mappings as $ecs_field => $advmd_id)
1070 {
1071 include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSetting.php';
1072 $map = new ilECSDataMappingSetting(
1073 (int) $_REQUEST['ecs_mapping_server'],
1074 (int) $mtype,
1075 $ecs_field
1076 );
1077 $map->setAdvMDId($advmd_id);
1078 $map->save();
1079 }
1080 }
1081
1082 ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
1083 $this->ctrl->setParameter($this, "ecs_mapping_server", (int)$_POST['ecs_mapping_server']);
1084 $this->ctrl->redirect($this,'importMappings');
1085 return true;
1086 }
1087
1094 protected function saveExportMappings()
1095 {
1096 foreach((array) $_POST['mapping'] as $mtype => $mappings)
1097 {
1098 foreach((array) $mappings as $ecs_field => $advmd_id)
1099 {
1100 include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSetting.php';
1101 $map = new ilECSDataMappingSetting(
1102 (int) $_POST['ecs_mapping_server'],
1103 (int) $mtype,
1104 $ecs_field
1105 );
1106 $map->setAdvMDId($advmd_id);
1107 $map->save();
1108 }
1109 }
1110
1111 ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
1112 $this->ctrl->setParameter($this, "ecs_mapping_server", (int)$_POST['ecs_mapping_server']);
1113 $this->ctrl->redirect($this,'exportMappings');
1114 return true;
1115 }
1116
1125 protected function initMappingsForm($a_server_id,$mapping_type)
1126 {
1127 include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
1128
1129 include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1130 $mapping_settings = ilECSDataMappingSettings::getInstanceByServerId($a_server_id);
1131
1132 $form = new ilPropertyFormGUI();
1133
1134 if($mapping_type == self::MAPPING_IMPORT)
1135 {
1136 $form->setTitle($this->lng->txt('ecs_mapping_tbl'));
1137 $form->addCommandButton('saveImportMappings',$this->lng->txt('save'));
1138 $form->addCommandButton('importMappings',$this->lng->txt('cancel'));
1139 }
1140 else
1141 {
1142 $form->setTitle($this->lng->txt('ecs_mapping_exp_tbl'));
1143 $form->addCommandButton('saveExportMappings',$this->lng->txt('save'));
1144 $form->addCommandButton('exportMappings',$this->lng->txt('cancel'));
1145 }
1146
1147 $form->setFormAction($this->ctrl->getFormAction($this,'saveMappings'));
1148
1149 if($mapping_type == self::MAPPING_IMPORT)
1150 {
1151 $assignments = new ilCustomInputGUI($this->lng->txt('ecs_mapping_crs'));
1152 $form->addItem($assignments);
1153 }
1154
1155 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1157 $options = $this->prepareFieldSelection($fields);
1158
1159 // get all optional ecourse fields
1160 include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
1162 foreach($optional as $field_name)
1163 {
1164 if($mapping_type == self::MAPPING_IMPORT)
1165 {
1166 $select = new ilSelectInputGUI(
1167 $this->lng->txt('ecs_field_'.$field_name),
1168 'mapping'.'['.ilECSDataMappingSetting::MAPPING_IMPORT_CRS.']['.$field_name.']'
1169 );
1170
1171 $select->setValue(
1172 $mapping_settings->getMappingByECSName(
1174 $field_name)
1175 );
1176 $select->setOptions($options);
1177 $assignments->addSubItem($select);
1178 }
1179 else
1180 {
1181 $select = new ilSelectInputGUI(
1182 $this->lng->txt('ecs_field_'.$field_name),
1183 'mapping'.'['.ilECSDataMappingSetting::MAPPING_EXPORT.']['.$field_name.']'
1184 );
1185 $select->setValue(
1186 $mapping_settings->getMappingByECSName(
1188 $field_name)
1189 );
1190 $select->setOptions($options);
1191 $form->addItem($select);
1192 }
1193 }
1194
1195 $server = new ilHiddenInputGUI('ecs_mapping_server');
1196 $server->setValue($a_server_id);
1197 $form->addItem($server);
1198
1199 // Remote courses
1200 // no remote course settings for export
1201 if($mapping_type == self::MAPPING_EXPORT)
1202 {
1203 return $form;
1204 }
1205
1206 $rcrs = new ilCustomInputGUI($this->lng->txt('ecs_mapping_rcrs'));
1207 $form->addItem($rcrs);
1208
1209 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1211 $options = $this->prepareFieldSelection($fields);
1212
1213 // get all optional econtent fields
1214 include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
1216 foreach($optional as $field_name)
1217 {
1218 $select = new ilSelectInputGUI(
1219 $this->lng->txt('ecs_field_'.$field_name),
1220 'mapping['.ilECSDataMappingSetting::MAPPING_IMPORT_RCRS.']['.$field_name.']');
1221 $select->setValue(
1222 $mapping_settings->getMappingByECSName(
1224 $field_name)
1225 );
1226 $select->setOptions($options);
1227 $rcrs->addSubItem($select);
1228 }
1229 return $form;
1230 }
1231
1236 protected function categoryMapping()
1237 {
1238 $this->tabs_gui->setSubTabActive('ecs_category_mapping');
1239 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.category_mapping.html','Services/WebServices/ECS');
1240
1241 $this->initRule();
1242 $this->initCategoryMappingForm();
1243
1244
1245 $this->tpl->setVariable('NEW_RULE_TABLE',$this->form->getHTML());
1246 if($html = $this->showRulesTable())
1247 {
1248 $this->tpl->setVariable('RULES_TABLE',$html);
1249 }
1250 }
1251
1256 protected function addCategoryMapping()
1257 {
1258 $this->initRule();
1259
1260 $this->initCategoryMappingForm('add');
1261 if($this->form->checkInput())
1262 {
1263 $this->rule->setContainerId($this->form->getInput('import_id'));
1264 $this->rule->setFieldName($this->form->getInput('field'));
1265 $this->rule->setMappingType($this->form->getInput('type'));
1266
1267 switch($this->form->getInput('type'))
1268 {
1270 $this->rule->setMappingValue($this->form->getInput('mapping_value'));
1271 break;
1272
1274 $this->rule->setDateRangeStart($this->form->getItemByPostVar('dur_begin')->getDate());
1275 $this->rule->setDateRangeEnd($this->form->getItemByPostVar('dur_end')->getDate());
1276 break;
1277
1279 $this->rule->setByType($this->form->getInput('by_type'));
1280 break;
1281 }
1282
1283 if($err = $this->rule->validate())
1284 {
1285 ilUtil::sendInfo($this->lng->txt($err));
1286 $this->form->setValuesByPost();
1287 $this->categoryMapping();
1288 return false;
1289 }
1290
1291 $this->rule->save();
1292 ilUtil::sendInfo($this->lng->txt('settings_saved'));
1293 unset($this->rule);
1294 $this->categoryMapping();
1295 return true;
1296 }
1297 ilUtil::sendInfo($this->lng->txt('err_check_input'));
1298 $this->form->setValuesByPost();
1299 $this->categoryMapping();
1300 return false;
1301 }
1302
1307 protected function editCategoryMapping()
1308 {
1309 if(!$_REQUEST['rule_id'])
1310 {
1311 ilUtil::sendInfo($this->lng->txt('select_one'));
1312 $this->categoryMapping();
1313 return false;
1314 }
1315
1316 $this->tabs_gui->setSubTabActive('ecs_category_mapping');
1317 $this->ctrl->saveParameter($this,'rule_id');
1318 $this->initRule((int) $_REQUEST['rule_id']);
1319
1320 $this->initCategoryMappingForm('edit');
1321 $this->tpl->setContent($this->form->getHTML());
1322 return true;
1323 }
1324
1329 protected function updateCategoryMapping()
1330 {
1331 if(!$_REQUEST['rule_id'])
1332 {
1333 ilUtil::sendInfo($this->lng->txt('select_one'));
1334 $this->categoryMapping();
1335 return false;
1336 }
1337 $this->ctrl->saveParameter($this,'rule_id');
1338 $this->initRule((int) $_REQUEST['rule_id']);
1339 $this->initCategoryMappingForm('edit');
1340 if($this->form->checkInput())
1341 {
1342 $this->rule->setContainerId($this->form->getInput('import_id'));
1343 $this->rule->setFieldName($this->form->getInput('field'));
1344 $this->rule->setMappingType($this->form->getInput('type'));
1345
1346
1347 switch($this->form->getInput('type'))
1348 {
1350 $this->rule->setMappingValue($this->form->getInput('mapping_value'));
1351 break;
1352
1354 $this->rule->setDateRangeStart($this->form->getItemByPostVar('dur_begin')->getDate());
1355 $this->rule->setDateRangeEnd($this->form->getItemByPostVar('dur_end')->getDate());
1356 break;
1357
1359 $this->rule->setByType($this->form->getInput('by_type'));
1360 break;
1361 }
1362
1363 if($err = $this->rule->validate())
1364 {
1365 ilUtil::sendInfo($this->lng->txt($err));
1366 $this->form->setValuesByPost();
1367 $this->editCategoryMapping();
1368 return false;
1369 }
1370
1371 $this->rule->update();
1372 ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
1373 $this->ctrl->redirect($this,'categoryMapping');
1374 return true;
1375 }
1376 ilUtil::sendInfo($this->lng->txt('err_check_input'));
1377 $this->form->setValuesByPost();
1378 $this->editCategoryMapping();
1379 return false;
1380
1381 }
1382
1386 protected function deleteCategoryMappings()
1387 {
1388 if(!is_array($_POST['rules']) or !$_POST['rules'])
1389 {
1390 ilUtil::sendInfo($this->lng->txt('no_checkbox'));
1391 $this->categoryMapping();
1392 return false;
1393 }
1394 foreach($_POST['rules'] as $rule_id)
1395 {
1396 include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1397 $rule = new ilECSCategoryMappingRule($rule_id);
1398 $rule->delete();
1399 }
1400 ilUtil::sendInfo($this->lng->txt('settings_saved'));
1401 $this->categoryMapping();
1402 return true;
1403 }
1404
1409 protected function showRulesTable()
1410 {
1411 include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php';
1412
1414 {
1415 return false;
1416 }
1417 include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingTableGUI.php';
1418 $rule_table = new ilECSCategoryMappingTableGUI($this,'categoryMapping');
1419 $rule_table->parse($rules);
1420 return $rule_table->getHTML();
1421 }
1422
1428 protected function initRule($a_rule_id = 0)
1429 {
1430 if(is_object($this->rule))
1431 {
1432 return $this->rule;
1433 }
1434
1435 include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1436 $this->rule = new ilECSCategoryMappingRule($a_rule_id);
1437 }
1438
1443 protected function initCategoryMappingForm($a_mode = 'add')
1444 {
1445 global $ilDB;
1446
1447 if(is_object($this->form))
1448 {
1449 return true;
1450 }
1451
1452 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1453 include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
1454
1455 $this->form = new ilPropertyFormGUI();
1456
1457 if($a_mode == 'add')
1458 {
1459 $this->form->setTitle($this->lng->txt('ecs_new_category_mapping'));
1460 $this->form->setFormAction($this->ctrl->getFormAction($this,'categoryMapping'));
1461 $this->form->addCommandButton('addCategoryMapping',$this->lng->txt('save'));
1462 $this->form->addCommandButton('categoryMapping',$this->lng->txt('cancel'));
1463 }
1464 else
1465 {
1466 $this->form->setTitle($this->lng->txt('ecs_edit_category_mapping'));
1467 $this->form->setFormAction($this->ctrl->getFormAction($this,'editCategoryMapping'));
1468 $this->form->addCommandButton('updateCategoryMapping',$this->lng->txt('save'));
1469 $this->form->addCommandButton('categoryMapping',$this->lng->txt('cancel'));
1470 }
1471
1472 $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'),'import_id');
1473 $imp->setRequired(true);
1474
1475 $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
1476 $tpl->setVariable('SIZE',5);
1477 $tpl->setVariable('MAXLENGTH',11);
1478 $tpl->setVariable('POST_VAR','import_id');
1479 $tpl->setVariable('PROPERTY_VALUE',$this->rule->getContainerId());
1480
1481 if($this->settings->getImportId())
1482 {
1483 $tpl->setVariable('COMPLETE_PATH',$this->buildPath($this->rule->getContainerId()));
1484 }
1485
1486 $imp->setHTML($tpl->get());
1487 $imp->setInfo($this->lng->txt('ecs_import_id_info'));
1488 $this->form->addItem($imp);
1489
1490 include_once('./Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php');
1491 $select = new ilSelectInputGUI($this->lng->txt('ecs_attribute_name'),'field');
1492 $select->setValue($this->rule->getFieldName());
1493 $select->setRequired(true);
1494 $select->setOptions(ilECSCategoryMapping::getPossibleFields());
1495 $this->form->addItem($select);
1496
1497 // Value
1498 $value = new ilRadioGroupInputGUI($this->lng->txt('ecs_cat_mapping_type'),'type');
1499 $value->setValue($this->rule->getMappingType());
1500 $value->setRequired(true);
1501
1502 $fixed = new ilRadioOption($this->lng->txt('ecs_cat_mapping_fixed'),ilECSCategoryMappingRule::TYPE_FIXED);
1503 $fixed->setInfo($this->lng->txt('ecs_cat_mapping_fixed_info'));
1504
1505 $fixed_val = new ilTextInputGUI($this->lng->txt('ecs_cat_mapping_values'),'mapping_value');
1506 $fixed_val->setValue($this->rule->getMappingValue());
1507 $fixed_val->setMaxLength(255);
1508 $fixed_val->setSize(40);
1509 $fixed_val->setRequired(true);
1510 $fixed->addSubItem($fixed_val);
1511
1512 $value->addOption($fixed);
1513
1514 $duration = new ilRadioOption($this->lng->txt('ecs_cat_mapping_duration'),ilECSCategoryMappingRule::TYPE_DURATION);
1515 $duration->setInfo($this->lng->txt('ecs_cat_mapping_duration_info'));
1516
1517 $dur_start = new ilDateTimeInputGUI($this->lng->txt('from'),'dur_begin');
1518 $dur_start->setDate($this->rule->getDateRangeStart());
1519 $duration->addSubItem($dur_start);
1520
1521 $dur_end = new ilDateTimeInputGUI($this->lng->txt('to'),'dur_end');
1522 $dur_end->setDate($this->rule->getDateRangeEnd());
1523 $duration->addSubItem($dur_end);
1524
1525 $value->addOption($duration);
1526
1527 $type = new ilRadioOption($this->lng->txt('ecs_cat_mapping_by_type'),ilECSCategoryMappingRule::TYPE_BY_TYPE);
1528 $type->setInfo($this->lng->txt('ecs_cat_mapping_by_type_info'));
1529
1531
1532 $types = new ilSelectInputGUI($this->lng->txt('type'), 'by_type');
1533 $types->setOptions($options);
1534 $types->setValue($this->rule->getByType());
1535 $types->setRequired(true);
1536 $type->addSubitem($types);
1537
1538 $value->addOption($type);
1539
1540 $this->form->addItem($value);
1541
1542 }
1543
1544
1550 protected function imported()
1551 {
1552 global $ilUser, $ilToolbar;
1553
1554 $this->tabs_gui->setSubTabActive('ecs_import');
1555
1556 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
1557 if(ilECSServerSettings::getInstance()->activeServerExists())
1558 {
1559 $ilToolbar->addButton(
1560 $this->lng->txt('ecs_read_remote_links'),
1561 $this->ctrl->getLinkTarget($this,'readAll')
1562 );
1563
1564 $ilToolbar->addSeparator();
1565 }
1566
1567
1568 $sel_type = $_REQUEST["otype"];
1569 if(!$sel_type)
1570 {
1571 $sel_type = "rcrs";
1572 }
1573
1574 include_once './Services/WebServices/ECS/classes/class.ilECSUtils.php';
1576
1577 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1578 $sel = new ilSelectInputGUI("", "otype");
1579 $sel->setOptions($options);
1580 $sel->setValue($sel_type);
1581 $ilToolbar->addInputItem($sel);
1582
1583 $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "imported"));
1584 $ilToolbar->addFormButton($this->lng->txt("submit"), "imported");
1585
1586 $robjs = ilUtil::_getObjectsByOperations($sel_type,'visible',$ilUser->getId(),-1);
1587 if(count($robjs))
1588 {
1589 $ilToolbar->addSeparator();
1590
1591 $ilToolbar->addButton(
1592 $this->lng->txt('csv_export'),
1593 $this->ctrl->getLinkTarget($this,'exportImported')
1594 );
1595 }
1596
1597 include_once('Services/WebServices/ECS/classes/class.ilECSImportedContentTableGUI.php');
1598 $table_gui = new ilECSImportedContentTableGUI($this,'imported');
1599 $table_gui->setTitle($this->lng->txt('ecs_imported_content'));
1600 $table_gui->parse($robjs);
1601 $this->tpl->setContent($table_gui->getHTML());
1602
1603 return true;
1604 }
1605
1612 protected function exportImported()
1613 {
1614 global $ilObjDataCache,$ilUser;
1615
1616 // :TODO: mind resource type and move to ilRemoteObjectBase...
1617
1618 $rcourses = ilUtil::_getObjectsByOperations('rcrs','visible',$ilUser->getId(),-1);
1619
1620 // Read participants
1621 include_once('./Modules/RemoteCourse/classes/class.ilObjRemoteCourse.php');
1622 include_once('./Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
1623 try
1624 {
1626 }
1627 catch(ilECSConnectorException $e)
1628 {
1629 $reader = null;
1630 }
1631
1632 // read obj_ids
1633 $ilObjDataCache->preloadReferenceCache($rcourses);
1634 $obj_ids = array();
1635 foreach($rcourses as $rcrs_ref_id)
1636 {
1637 $obj_id = $ilObjDataCache->lookupObjId($rcrs_ref_id);
1638 $obj_ids[$obj_id] = $obj_id;
1639 }
1640
1641 include_once('Services/Utilities/classes/class.ilCSVWriter.php');
1642 $writer = new ilCSVWriter();
1643
1644 $writer->addColumn($this->lng->txt('title'));
1645 $writer->addColumn($this->lng->txt('description'));
1646 $writer->addColumn($this->lng->txt('ecs_imported_from'));
1647 $writer->addColumn($this->lng->txt('ecs_field_courseID'));
1648 $writer->addColumn($this->lng->txt('ecs_field_term'));
1649 $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
1650 $writer->addColumn($this->lng->txt('ecs_field_courseType'));
1651 $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
1652 $writer->addColumn($this->lng->txt('ecs_field_credits'));
1653 $writer->addColumn($this->lng->txt('ecs_field_room'));
1654 $writer->addColumn($this->lng->txt('ecs_field_cycle'));
1655 $writer->addColumn($this->lng->txt('ecs_field_begin'));
1656 $writer->addColumn($this->lng->txt('ecs_field_end'));
1657 $writer->addColumn($this->lng->txt('last_update'));
1658
1659 include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1661
1662 foreach($obj_ids as $obj_id)
1663 {
1664 include_once "Services/WebServices/ECS/classes/class.ilECSUtils.php";
1665 $values = ilECSUtils::getAdvancedMDValuesForObjId($obj_id);
1666
1667 $writer->addRow();
1668 $writer->addColumn(ilObject::_lookupTitle($obj_id));
1669 $writer->addColumn(ilObject::_lookupDescription($obj_id));
1670
1671 $mid = ilObjRemoteCourse::_lookupMID($obj_id);
1672 if($reader and ($participant = $reader->getParticipantByMID($mid)))
1673 {
1674 $writer->addColumn($participant->getParticipantName());
1675 }
1676 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'courseID');
1677 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1678
1679 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'term');
1680 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1681
1682 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'lecturer');
1683 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1684
1685 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'courseType');
1686 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1687
1688 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'semester_hours');
1689 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1690
1691 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'credits');
1692 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1693
1694 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'room');
1695 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1696
1697 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'cycle');
1698 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1699
1700 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'begin');
1701 $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1702
1703 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'end');
1704 $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1705
1706 $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
1707 }
1708 ilUtil::deliverData($writer->getCSVString(), date("Y_m_d")."_ecs_import.csv", "text/csv");
1709 }
1710
1717 protected function released()
1718 {
1719 global $ilUser, $ilToolbar;
1720
1721 $this->tabs_gui->setSubTabActive('ecs_released');
1722
1723 if($this->settings->isEnabled())
1724 {
1725 $ilToolbar->addButton(
1726 $this->lng->txt('ecs_read_remote_links'),
1727 $this->ctrl->getLinkTarget($this,'readAll')
1728 );
1729
1730 $ilToolbar->addSeparator();
1731 }
1732
1733 $sel_type = $_REQUEST["otype"];
1734 if(!$sel_type)
1735 {
1736 $sel_type = "rcrs";
1737 }
1738
1739 include_once "Services/WebServices/ECS/classes/class.ilECSUtils.php";
1741
1742 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1743 $sel = new ilSelectInputGUI("", "otype");
1744 $sel->setOptions($options);
1745 $sel->setValue($sel_type);
1746 $ilToolbar->addInputItem($sel);
1747
1748 $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "released"));
1749 $ilToolbar->addFormButton($this->lng->txt("submit"), "released");
1750
1751 include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
1752 $exported = ilECSExport::getExportedIdsByType($sel_type);
1753 if(count($exported))
1754 {
1755 $ilToolbar->addSeparator();
1756
1757 $ilToolbar->addButton(
1758 $this->lng->txt('csv_export'),
1759 $this->ctrl->getLinkTarget($this,'exportReleased')
1760 );
1761 }
1762
1763 include_once('Services/WebServices/ECS/classes/class.ilECSReleasedContentTableGUI.php');
1764 $table_gui = new ilECSReleasedContentTableGUI($this,'released');
1765 $table_gui->setTitle($this->lng->txt('ecs_released_content'));
1766 $table_gui->parse($exported);
1767 $this->tpl->setContent($table_gui->getHTML());
1768
1769 return true;
1770 }
1771
1778 protected function exportReleased()
1779 {
1780 global $ilObjDataCache;
1781
1782 include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
1783 $exported = ilECSExport::getExportedIds();
1784 $ilObjDataCache->preloadObjectCache($exported);
1785
1786 include_once('Services/Utilities/classes/class.ilCSVWriter.php');
1787 $writer = new ilCSVWriter();
1788
1789 $writer->addColumn($this->lng->txt('title'));
1790 $writer->addColumn($this->lng->txt('description'));
1791 $writer->addColumn($this->lng->txt('ecs_field_courseID'));
1792 $writer->addColumn($this->lng->txt('ecs_field_term'));
1793 $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
1794 $writer->addColumn($this->lng->txt('ecs_field_courseType'));
1795 $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
1796 $writer->addColumn($this->lng->txt('ecs_field_credits'));
1797 $writer->addColumn($this->lng->txt('ecs_field_room'));
1798 $writer->addColumn($this->lng->txt('ecs_field_cycle'));
1799 $writer->addColumn($this->lng->txt('ecs_field_begin'));
1800 $writer->addColumn($this->lng->txt('ecs_field_end'));
1801 $writer->addColumn($this->lng->txt('last_update'));
1802
1803 include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
1805
1806 foreach($exported as $obj_id)
1807 {
1808 include_once "Services/WebServices/ECS/classes/class.ilECSUtils.php";
1809 $values = ilECSUtils::getAdvancedMDValuesForObjId($obj_id);
1810
1811 $writer->addRow();
1812 $writer->addColumn(ilObject::_lookupTitle($obj_id));
1813 $writer->addColumn(ilObject::_lookupDescription($obj_id));
1814
1815 $field = $settings->getMappingByECSName(0, 'courseID');
1816 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1817
1818 $field = $settings->getMappingByECSName(0,'term');
1819 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1820
1821 $field = $settings->getMappingByECSName(0,'lecturer');
1822 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1823
1824 $field = $settings->getMappingByECSName(0,'courseType');
1825 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1826
1827 $field = $settings->getMappingByECSName(0,'semester_hours');
1828 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1829
1830 $field = $settings->getMappingByECSName(0,'credits');
1831 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1832
1833 $field = $settings->getMappingByECSName(0,'room');
1834 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1835
1836 $field = $settings->getMappingByECSName(0,'cycle');
1837 $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
1838
1839 $field = $settings->getMappingByECSName(0,'begin');
1840 $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1841
1842 $field = $settings->getMappingByECSName(0,'end');
1843 $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
1844
1845 $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
1846 }
1847
1848 ilUtil::deliverData($writer->getCSVString(), date("Y_m_d")."_ecs_export.csv", "text/csv");
1849 }
1850
1851
1857 protected function prepareFieldSelection($fields)
1858 {
1859 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
1860
1861 $options[0] = $this->lng->txt('ecs_ignore_field');
1862 foreach($fields as $field)
1863 {
1864 $title = ilAdvancedMDRecord::_lookupTitle($field->getRecordId());
1865 $options[$field->getFieldId()] = $title.': '.$field->getTitle();
1866 }
1867 return $options;
1868 }
1869
1870
1871
1877 protected function initSettings($a_server_id = 1)
1878 {
1879 include_once('Services/WebServices/ECS/classes/class.ilECSSetting.php');
1880 $this->settings = ilECSSetting::getInstanceByServerId($a_server_id);
1881 }
1882
1888 protected function setSubTabs()
1889 {
1890 global $ilAccess;
1891 $this->tabs_gui->clearSubTabs();
1892
1893 $this->tabs_gui->addSubTabTarget("overview",
1894 $this->ctrl->getLinkTarget($this,'overview'),
1895 "overview",get_class($this));
1896
1897 // Disable all other tabs, if server hasn't been configured.
1898 #ilECSServerSettings::getInstance()->readInactiveServers();
1899 if(!ilECSServerSettings::getInstance()->serverExists())
1900 {
1901 return true;
1902 }
1903
1904 $this->tabs_gui->addSubTabTarget("ecs_communities",
1905 $this->ctrl->getLinkTarget($this,'communities'),
1906 "communities",get_class($this));
1907
1908 if(!$ilAccess->checkAccess('write','',$_REQUEST["ref_id"]))
1909 {
1910 return true;
1911 }
1912
1913 $this->tabs_gui->addSubTabTarget('ecs_mappings',
1914 $this->ctrl->getLinkTarget($this,'importMappings'),
1915 'importMappings',get_class($this));
1916
1917 $this->tabs_gui->addSubTabTarget('ecs_category_mapping',
1918 $this->ctrl->getLinkTarget($this,'categoryMapping'));
1919
1920 $this->tabs_gui->addSubTabTarget('ecs_import',
1921 $this->ctrl->getLinkTarget($this,'imported'));
1922
1923 $this->tabs_gui->addSubTabTarget('ecs_released',
1924 $this->ctrl->getLinkTarget($this,'released'));
1925
1926 }
1927
1933 private function prepareRoleSelect()
1934 {
1935 global $rbacreview,$ilObjDataCache;
1936
1937 $global_roles = ilUtil::_sortIds($rbacreview->getGlobalRoles(),
1938 'object_data',
1939 'title',
1940 'obj_id');
1941
1942 $select[0] = $this->lng->txt('links_select_one');
1943 foreach($global_roles as $role_id)
1944 {
1945 $select[$role_id] = ilObject::_lookupTitle($role_id);
1946 }
1947 return $select;
1948 }
1949
1950 private function buildPath($a_ref_id)
1951 {
1952 $loc = new ilLocatorGUI();
1953 $loc->setTextOnly(false);
1954 $loc->addContextItems($a_ref_id);
1955
1956 return $loc->getHTML();
1957 }
1958
1964 protected function initTaskScheduler()
1965 {
1966 global $ilDB,$ilSetting;
1967
1968 #$ilDB->lockTables(array('name' => 'settings', 'type' => ilDB::LOCK_WRITE));
1969 $setting = new ilSetting('ecs');
1970 $setting->set(
1971 'next_execution_'.$this->settings->getServerId(),
1972 time() + (int) $this->settings->getPollingTime()
1973 );
1974 }
1975
1976}
1977
1978?>
$_SESSION["AccountId"]
static getInstancesByObjType($a_obj_type, $a_active_only=true)
static _lookupTitle($a_record_id)
Lookup title.
Helper class to generate CSV files.
This class represents a checkbox property in a property form.
Confirmation screen class.
This class represents a custom property in a property form.
This class represents a date/time property in a property form.
This class represents a duration (typical hh:mm:ss) property in a property form.
Defines a rule for the assignment of ECS remote courses to categories.
static getActiveRules()
get active rules
static delete($a_server_id)
Delete comunities by server id.
static getInstance($a_sid, $a_cid)
Get instance.
static getInstanceByServerId($a_server_id)
Get instance by server id.
static _getInstance()
get singleton instance
static _getInstance()
Get Singleton instance.
static delete($a_server_id)
Delete server @global ilDB $ilDB.
static getInstanceByServerId($a_server_id)
Get singleton instance.
static deleteServer($a_server_id)
Delete by server id @global ilDB $ilDB.
static handleExportReset(ilECSSetting $server)
Handle export reset.
static handleImportReset(ilECSSetting $server)
Reread all imported econtent.
static deleteByServer($a_server_id)
Delete by server id @global ilDB $ilDB.
static getExportedIds()
Get exported ids @global ilDB $ilDB.
static getExportedIdsByType($a_type)
Get exported ids by type @global ilDB $ilDB.
static deleteByServer($a_server_id)
Delete by server id @global ilDB $ilDB.
static getAvailabeMids($a_server_id)
Get all available mids @global $ilDB.
static deleteByServer($a_server_id)
Delete by server @global $ilDB.
static getInstance()
Get singleton instance.
Description of ilECSServerTableGUI.
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
updateCategoryMapping()
update category mapping
validateImportTypes(&$import_types)
Validate import types.
edit()
Edit server setting.
executeCommand()
Execute command.
initCategoryMappingForm($a_mode='add')
Init category mapping form.
editCategoryMapping()
Edit category mapping.
refreshParticipants()
Refresh participants.
create()
Create new settings @global ilTabs $ilTabs.
overview()
List available servers.
released()
Show released materials.
saveExportMappings()
Save mappings.
updateTitle()
Update configuration title.
initTaskScheduler()
Init next task execution @global <type> $ilDB @global <type> $ilSetting.
prepareFieldSelection($fields)
get options for field selection
activate()
activate server
communities()
show communities
exportMappings()
Show mapping settings (EContent-Data <-> (Remote)Course.
loadFromPost()
Load from post.
readAll()
Read all importable econtent.
initRule($a_rule_id=0)
Init rule.
prepareRoleSelect()
get global role array
updateCommunities()
update whitelist
showRulesTable()
Show rules table.
initMappingsForm($a_server_id, $mapping_type)
init mapping form
exportImported()
csv export of imported remote courses
initSettingsForm($a_mode='update')
init settings form
setMappingTabs($a_active)
Handle tabs for ECS data mapping.
addCategoryMapping()
save category mapping
deactivate()
activate server
imported()
Show imported materials.
importMappings()
Show mapping settings (EContent-Data <-> (Remote)Course.
saveImportMappings()
Save mappings.
initSettings($a_server_id=1)
Init settings.
exportReleased()
export released
deleteCategoryMappings()
Delete selected category mappings.
categoryMapping()
Category mappings.
static _getInstanceByServerId($a_server_id)
get singleton instance Private access use ilECSTaskScheduler::start() or ilECSTaskScheduler::startTas...
static getPossibleRemoteTypes($a_with_captions=false)
Get all possible remote object types.
static getAdvancedMDValuesForObjId($a_obj_id)
Get advanced metadata values for object id.
static getPossibleReleaseTypes($a_with_captions=false)
Get all possible release object types.
static _getOptionalECourseFields()
get optional econtent fields These fields might be mapped against AdvancedMetaData field definitions
static _getOptionalEContentFields()
get optional econtent fields These fields might be mapped against AdvancedMetaData field definitions
Base class for ILIAS Exception handling.
This class represents a section header in a property form.
formatUnixTime($ut, $with_time=false)
This class represents a hidden form property in a property form.
locator handling class
This class represents a non editable value in a property form.
static _lookupMID($a_obj_id)
static _lookupTitle($a_id)
lookup object title
static _lookupDescription($a_id)
lookup object description
This class represents a password property in a property form.
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
static _sortIds($a_ids, $a_table, $a_field, $a_id_name)
Function that sorts ids by a given table field using WHERE IN E.g: __sort(array(6,...
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
static _getObjectsByOperations($a_obj_type, $a_operation, $a_usr_id=0, $limit=0)
Get all objects of a specific type and check access This function is not recursive,...
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$_POST['username']
Definition: cron.php:12
$server
$html
Definition: example_001.php:87
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $ilCtrl
Definition: ilias.php:18
global $ilSetting
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
global $ilDB
if(!is_array($argv)) $options
global $ilUser
Definition: imgupload.php:15