ILIAS  Release_3_10_x_branch Revision 61812
 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 
34 {
35  protected $tpl;
36  protected $lng;
37  protected $ctrl;
38  protected $tabs_gui;
39 
40 
46  public function __construct()
47  {
48  global $lng,$tpl,$ilCtrl,$ilTabs;
49 
50  $this->tpl = $tpl;
51  $this->lng = $lng;
52  $this->lng->loadLanguageModule('ecs');
53  $this->ctrl = $ilCtrl;
54  $this->tabs_gui = $ilTabs;
55 
56  $this->initSettings();
57  }
58 
66  public function executeCommand()
67  {
68  $next_class = $this->ctrl->getNextClass($this);
69  $cmd = $this->ctrl->getCmd();
70 
71  $this->setSubTabs();
72  switch($next_class)
73  {
74  default:
75  if(!$cmd)
76  {
77  $cmd = "settings";
78  }
79  $this->$cmd();
80  break;
81  }
82  return true;
83  }
84 
85 
91  protected function readAll()
92  {
93  include_once('Services/WebServices/ECS/classes/class.ilECSConnector.php');
94  include_once('Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
95  include_once('./Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php');
96 
97  try
98  {
100 
101  include_once('./Services/WebServices/ECS/classes/class.ilECSTaskScheduler.php');
102  ilECSTaskScheduler::_getInstance()->startTaskExecution();
103 
104  ilUtil::sendInfo($this->lng->txt('ecs_remote_imported'));
105  $this->imported();
106  return true;
107  }
108  catch(ilECSConnectorException $e1)
109  {
110  ilUtil::sendInfo('Cannot connect to ECS server: '.$e1->getMessage());
111  $this->imported();
112  return false;
113  }
114  catch(ilException $e2)
115  {
116  ilUtil::sendInfo('Update failed: '.$e1->getMessage());
117  $this->imported();
118  return false;
119  }
120 
121 
122  }
123 
129  protected function settings()
130  {
131  $this->initSettingsForm();
132  $this->tabs_gui->setSubTabActive('ecs_settings');
133 
134  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_settings.html','Services/WebServices/ECS');
135  $this->tpl->setVariable('SETTINGS_TABLE',$this->form->getHTML());
136  }
137 
143  protected function initSettingsForm()
144  {
145  if(is_object($this->form))
146  {
147  return true;
148  }
149  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
150 
151  $this->form = new ilPropertyFormGUI();
152  $this->form->setFormAction($this->ctrl->getFormAction($this,'settings'));
153  $this->form->setTitle($this->lng->txt('ecs_connection_settings'));
154 
155  $ena = new ilCheckboxInputGUI($this->lng->txt('ecs_active'),'active');
156  $ena->setChecked($this->settings->isEnabled());
157  $ena->setValue(1);
158  $this->form->addItem($ena);
159 
160  $ser = new ilTextInputGUI($this->lng->txt('ecs_server_url'),'server');
161  $ser->setValue($this->settings->getServer());
162  $ser->setRequired(true);
163  $this->form->addItem($ser);
164 
165  $pro = new ilSelectInputGUI($this->lng->txt('ecs_protocol'),'protocol');
166  // fixed to https
167  #$pro->setOptions(array(ilECSSettings::PROTOCOL_HTTP => $this->lng->txt('http'),
168  # ilECSSettings::PROTOCOL_HTTPS => $this->lng->txt('https')));
169  $pro->setOptions(array(ilECSSettings::PROTOCOL_HTTPS => 'HTTPS'));
170  $pro->setValue($this->settings->getProtocol());
171  $pro->setRequired(true);
172  $this->form->addItem($pro);
173 
174  $por = new ilTextInputGUI($this->lng->txt('ecs_port'),'port');
175  $por->setSize(5);
176  $por->setMaxLength(5);
177  $por->setValue($this->settings->getPort());
178  $por->setRequired(true);
179  $this->form->addItem($por);
180 
181  $cer = new ilTextInputGUI($this->lng->txt('ecs_client_cert'),'client_cert');
182  $cer->setSize(60);
183  $cer->setValue($this->settings->getClientCertPath());
184  $cer->setRequired(true);
185  $this->form->addItem($cer);
186 
187  $cer = new ilTextInputGUI($this->lng->txt('ecs_cert_key'),'key_path');
188  $cer->setSize(60);
189  $cer->setValue($this->settings->getKeyPath());
190  $cer->setRequired(true);
191  $this->form->addItem($cer);
192 
193  $cer = new ilTextInputGUI($this->lng->txt('ecs_key_password'),'key_password');
194  $cer->setSize(12);
195  $cer->setValue($this->settings->getKeyPassword());
196  $cer->setInputType('password');
197  $cer->setRequired(true);
198  $this->form->addItem($cer);
199 
200  $cer = new ilTextInputGUI($this->lng->txt('ecs_ca_cert'),'ca_cert');
201  $cer->setSize(60);
202  $cer->setValue($this->settings->getCACertPath());
203  $cer->setRequired(true);
204  $this->form->addItem($cer);
205 
206  $ser = new ilNonEditableValueGUI($this->lng->txt('cert_serial'));
207  $ser->setValue($this->settings->getCertSerialNumber() ? $this->settings->getCertSerialNumber() : $this->lng->txt('ecs_no_value'));
208  $this->form->addItem($ser);
209 
210  $loc = new ilFormSectionHeaderGUI();
211  $loc->setTitle($this->lng->txt('ecs_local_settings'));
212  $this->form->addItem($loc);
213 
214  $pol = new ilDurationInputGUI($this->lng->txt('ecs_polling'),'polling');
215  $pol->setShowDays(false);
216  $pol->setShowHours(false);
217  $pol->setShowMinutes(true);
218  $pol->setShowSeconds(true);
219  $pol->setSeconds($this->settings->getPollingTimeSeconds());
220  $pol->setMinutes($this->settings->getPollingTimeMinutes());
221  $pol->setRequired(true);
222  $pol->setInfo($this->lng->txt('ecs_polling_info'));
223  $this->form->addItem($pol);
224 
225  $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'));
226  $imp->setRequired(true);
227 
228  $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
229  $tpl->setVariable('SIZE',5);
230  $tpl->setVariable('MAXLENGTH',11);
231  $tpl->setVariable('POST_VAR','import_id');
232  $tpl->setVariable('PROPERTY_VALUE',$this->settings->getImportId());
233 
234  if($this->settings->getImportId())
235  {
236  $tpl->setVariable('COMPLETE_PATH',$this->buildPath($this->settings->getImportId()));
237  }
238 
239  $imp->setHTML($tpl->get());
240  $imp->setInfo($this->lng->txt('ecs_import_id_info'));
241  $this->form->addItem($imp);
242 
243  $loc = new ilFormSectionHeaderGUI();
244  $loc->setTitle($this->lng->txt('ecs_remote_user_settings'));
245  $this->form->addItem($loc);
246 
247  $role = new ilSelectInputGUI($this->lng->txt('ecs_role'),'global_role');
248  $role->setOptions($this->prepareRoleSelect());
249  $role->setValue($this->settings->getGlobalRole());
250  $role->setInfo($this->lng->txt('ecs_global_role_info'));
251  $role->setRequired(true);
252  $this->form->addItem($role);
253 
254  $duration = new ilDurationInputGUI($this->lng->txt('ecs_account_duration'),'duration');
255  $duration->setInfo($this->lng->txt('ecs_account_duration_info'));
256  $duration->setMonths($this->settings->getDuration());
257  $duration->setShowSeconds(false);
258  $duration->setShowMinutes(false);
259  $duration->setShowHours(false);
260  $duration->setShowDays(false);
261  $duration->setShowMonths(true);
262  $duration->setRequired(true);
263  $this->form->addItem($duration);
264 
265  // Email recipients
266  $loc = new ilFormSectionHeaderGUI();
267  $loc->setTitle($this->lng->txt('ecs_notifications'));
268  $this->form->addItem($loc);
269 
270  $rcp_user = new ilTextInputGUI($this->lng->txt('ecs_user_rcp'),'user_recipients');
271  $rcp_user->setValue($this->settings->getUserRecipientsAsString());
272  $rcp_user->setInfo($this->lng->txt('ecs_user_rcp_info'));
273  $this->form->addItem($rcp_user);
274 
275  $rcp_econ = new ilTextInputGUI($this->lng->txt('ecs_econ_rcp'),'econtent_recipients');
276  $rcp_econ->setValue($this->settings->getEContentRecipientsAsString());
277  $rcp_econ->setInfo($this->lng->txt('ecs_econ_rcp_info'));
278  $this->form->addItem($rcp_econ);
279 
280  $rcp_app = new ilTextInputGUI($this->lng->txt('ecs_approval_rcp'),'approval_recipients');
281  $rcp_app->setValue($this->settings->getApprovalRecipientsAsString());
282  $rcp_app->setInfo($this->lng->txt('ecs_approval_rcp_info'));
283  $this->form->addItem($rcp_app);
284 
285  $this->form->addCommandButton('saveSettings',$this->lng->txt('save'));
286  $this->form->addCommandButton('settings',$this->lng->txt('cancel'));
287  }
288 
294  protected function saveSettings()
295  {
296  $this->settings->setEnabledStatus((int) $_POST['active']);
297  $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
298  $this->settings->setPort(ilUtil::stripSlashes($_POST['port']));
299  $this->settings->setProtocol(ilUtil::stripSlashes($_POST['protocol']));
300  $this->settings->setClientCertPath(ilUtil::stripSlashes($_POST['client_cert']));
301  $this->settings->setCACertPath(ilUtil::stripSlashes($_POST['ca_cert']));
302  $this->settings->setKeyPath(ilUtil::stripSlashes($_POST['key_path']));
303  $this->settings->setKeyPassword(ilUtil::stripSlashes($_POST['key_password']));
304  $this->settings->setImportId(ilUtil::stripSlashes($_POST['import_id']));
305  $this->settings->setPollingTimeMS((int) $_POST['polling']['mm'],(int) $_POST['polling']['ss']);
306  $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
307  $this->settings->setGlobalRole((int) $_POST['global_role']);
308  $this->settings->setDuration((int) $_POST['duration']['MM']);
309 
310  $this->settings->setUserRecipients(ilUtil::stripSlashes($_POST['user_recipients']));
311  $this->settings->setEContentRecipients(ilUtil::stripSlashes($_POST['econtent_recipients']));
312  $this->settings->setApprovalRecipients(ilUtil::stripSlashes($_POST['approval_recipients']));
313 
314  if(!$error = $this->settings->validate())
315  {
316  $this->settings->save();
317  ilUtil::sendInfo($this->lng->txt('settings_saved'));
318  }
319  else
320  {
321  ilUtil::sendInfo($this->lng->txt($error));
322  }
323 
324  $this->setSubTabs('ecs_settings');
325  $this->settings();
326  return true;
327  }
328 
335  public function communities()
336  {
337  $this->tabs_gui->setSubTabActive('ecs_communities');
338 
339  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_communities.html','Services/WebServices/ECS');
340 
341  $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this,'updateCommunities'));
342  $this->tpl->setVariable('IMAGE_DOWNRIGHT',ilUtil::getImagePath('arrow_downright.gif'));
343  $this->tpl->setVariable('TXT_SAVE',$this->lng->txt('ecs_enable_participant'));
344 
345  include_once('Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
346  include_once('Services/WebServices/ECS/classes/class.ilECSCommunityTableGUI.php');
347 
348  try
349  {
351 
352  foreach($reader->getCommunities() as $community)
353  {
354  $this->tpl->setCurrentBlock('table_community');
355  $table_gui = new ilECSCommunityTableGUI($this,'communities',$community->getId());
356 
357  $table_gui->setTitle($community->getTitle().' ('.$community->getDescription().')');
358  #$table_gui->parse($community->getParticipants());
359  $table_gui->parse($community->getParticipants());
360 
361  #$table_gui->setSelectAllCheckbox("mid");
362  $this->tpl->setVariable('TABLE_COMM',$table_gui->getHTML());
363  $this->tpl->parseCurrentBlock();
364  }
365  }
366  catch(ilECSConnectorException $exc)
367  {
368  ilUtil::sendInfo('Cannot connect to ECS server');
369  return true;
370  }
371  }
372 
379  protected function updateCommunities()
380  {
381  global $ilLog;
382 
383 
384  $mids = $_POST['mid'] ? $_POST['mid'] : array();
385 
386  include_once('./Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php');
388 
389  foreach($part->getEnabledParticipants() as $mid)
390  {
391  if(!in_array($mid,$mids))
392  {
393  // Delete all remote courses
394  include_once('./Modules/RemoteCourse/classes/class.ilObjRemoteCourse.php');
395  foreach(ilObjRemoteCourse::_lookupObjIdsByMID($mid) as $obj_id)
396  {
397  foreach(ilObject::_getAllReferences($obj_id) as $ref_id)
398  {
399  $to_delete = ilObjectFactory::getInstanceByRefId($ref_id,false);
400  $to_delete->delete();
401  }
402  }
403  }
404  }
405 
406 
407  try
408  {
409  // Update all exported econtent
410  include_once('./Services/WebServices/ECS/classes/class.ilECSEContentReader.php');
411  include_once('./Services/WebServices/ECS/classes/class.ilECSConnector.php');
412  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
413 
415  $reader->read();
416  $all_content = $reader->getEContent();
417 
418  // read update events
419  foreach($all_content as $content)
420  {
421  if(ilECSExport::_isRemote($content->getEContentId()))
422  {
423  $ilLog->write(__METHOD__.': Ignoring remote EContent: '.$content->getTitle());
424  // Do not handle remote courses.
425  continue;
426  }
427  $members = array_intersect($mids,$content->getEligibleMembers());
428  if(!$members)
429  {
430  $ilLog->write(__METHOD__.': Deleting EContent: '.$content->getTitle());
431  $connector = new ilECSConnector();
432  $connector->deleteResource($content->getEContentId());
433 
434  ilECSExport::_deleteEContentIds(array($content->getEContentId()));
435  }
436  elseif(count($members) != count($content->getEligibleMembers()))
437  {
438  $ilLog->write(__METHOD__.': Update eligible members for EContent: '.$content->getTitle());
439  $content->setEligibleMembers($members);
440  $connector = new ilECSConnector();
441  $connector->updateResource($content->getEContentId(),json_encode($content));
442  }
443  }
444  }
445  catch(ilECSConnectorException $e)
446  {
447  ilUtil::sendInfo('Cannot connect to ECS server: '.$e1->getMessage());
448  $this->communities();
449  return false;
450  }
451  catch(ilException $e)
452  {
453  ilUtil::sendInfo('Update failed: '.$e1->getMessage());
454  $this->communities();
455  return false;
456  }
457 
458  $part->setEnabledParticipants($_POST['mid'] ? $_POST['mid'] : array());
459  $part->save();
460 
461  ilUtil::sendInfo($this->lng->txt('settings_saved'));
462  $this->communities();
463  return true;
464  }
465 
471  public function mappings()
472  {
473  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
474 
475  $this->tabs_gui->setSubTabActive('ecs_mappings');
476 
478  if(!count($fields))
479  {
480  ilUtil::sendInfo($this->lng->txt('ecs_no_adv_md'));
481  return true;
482  }
483 
484  $this->initMappingsForm();
485  $this->tpl->setContent($this->form->getHTML());
486  return true;
487  }
488 
495  protected function saveMappings()
496  {
497  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
498  $mapping_settings = ilECSDataMappingSettings::_getInstance();
499  $mapping_settings->setMappings($_POST['mapping']);
500  $mapping_settings->save();
501 
502  ilUtil::sendInfo($this->lng->txt('settings_saved'));
503  $this->mappings();
504  return true;
505  }
506 
512  protected function initMappingsForm()
513  {
514  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
515 
516  if(is_object($this->form))
517  {
518  return true;
519  }
520 
521  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
522  $mapping_settings = ilECSDataMappingSettings::_getInstance();
523 
524  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
526  $fields = array_unique(array_merge(ilAdvancedMDFieldDefinition::_getActiveDefinitionsByObjType('crs'),
528 
529 
530  $options = $this->prepareFieldSelection($fields);
531  $this->form = new ilPropertyFormGUI();
532  $this->form->setTitle($this->lng->txt('ecs_mapping_tbl'));
533  $this->form->setFormAction($this->ctrl->getFormAction($this,'saveMappings'));
534  $this->form->addCommandButton('saveMappings',$this->lng->txt('save'));
535  $this->form->addCommandButton('mappings',$this->lng->txt('cancel'));
536 
537  // get all optional fields
538  include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
540 
541  foreach($optional as $field_name)
542  {
543  $select = new ilSelectInputGUI($this->lng->txt('ecs_field_'.$field_name),'mapping['.$field_name.']');
544  $select->setValue($mapping_settings->getMappingByECSName($field_name));
545  $select->setOptions($options);
546  $this->form->addItem($select);
547  }
548  }
549 
555  protected function imported()
556  {
557  global $ilUser;
558 
559  $this->tabs_gui->setSubTabActive('ecs_import');
560 
561  $rcourses = ilUtil::_getObjectsByOperations('rcrs','visible',$ilUser->getId(),-1);
562 
563  if(count($rcourses))
564  {
565  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
566  $this->tpl->setCurrentBlock("btn_cell");
567  $this->tpl->setVariable("BTN_LINK", $this->ctrl->getLinkTarget($this, "exportImported"));
568  $this->tpl->setVariable("BTN_TXT", $this->lng->txt("csv_export"));
569  $this->tpl->parseCurrentBlock();
570  }
571 
572 
573  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_imported.html','Services/WebServices/ECS');
574  $this->tpl->addBlockfile('BUTTONS','buttons','tpl.buttons.html');
575 
576  if($this->settings->isEnabled())
577  {
578  $this->tpl->setCurrentBlock("btn_cell");
579  $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,'readAll'));
580  $this->tpl->setVariable("BTN_TXT",$this->lng->txt('ecs_read_remote_links'));
581  $this->tpl->parseCurrentBlock();
582  }
583 
584 
585  include_once('Services/WebServices/ECS/classes/class.ilECSImportedContentTableGUI.php');
586 
587  $this->tpl->setCurrentBlock('table_community');
588  $table_gui = new ilECSImportedContentTableGUI($this,'imported');
589 
590  $table_gui->setTitle($this->lng->txt('ecs_imported_content'));
591  $table_gui->parse($rcourses);
592  $this->tpl->setVariable('TABLE_IMP',$table_gui->getHTML());
593  $this->tpl->parseCurrentBlock();
594 
595  return true;
596  }
597 
604  protected function exportImported()
605  {
606  global $ilObjDataCache,$ilUser;
607 
608  $rcourses = ilUtil::_getObjectsByOperations('rcrs','visible',$ilUser->getId(),-1);
609 
610  // Read participants
611  include_once('./Modules/RemoteCourse/classes/class.ilObjRemoteCourse.php');
612  include_once('./Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
613  try
614  {
616  }
617  catch(ilECSConnectorException $e)
618  {
619  $reader = null;
620  }
621 
622  // read obj_ids
623  $ilObjDataCache->preloadReferenceCache($rcourses);
624  $obj_ids = array();
625  foreach($rcourses as $rcrs_ref_id)
626  {
627  $obj_id = $ilObjDataCache->lookupObjId($rcrs_ref_id);
628  $obj_ids[$obj_id] = $obj_id;
629  }
630 
631  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
632  $writer = new ilCSVWriter();
633 
634  $writer->addColumn($this->lng->txt('title'));
635  $writer->addColumn($this->lng->txt('description'));
636  $writer->addColumn($this->lng->txt('ecs_imported_from'));
637  $writer->addColumn($this->lng->txt('ecs_field_courseID'));
638  $writer->addColumn($this->lng->txt('ecs_field_term'));
639  $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
640  $writer->addColumn($this->lng->txt('ecs_field_courseType'));
641  $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
642  $writer->addColumn($this->lng->txt('ecs_field_credits'));
643  $writer->addColumn($this->lng->txt('ecs_field_room'));
644  $writer->addColumn($this->lng->txt('ecs_field_cycle'));
645  $writer->addColumn($this->lng->txt('ecs_field_begin'));
646  $writer->addColumn($this->lng->txt('ecs_field_end'));
647  $writer->addColumn($this->lng->txt('last_update'));
648 
649  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
651 
652  foreach($obj_ids as $obj_id)
653  {
654  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
655  $values = ilAdvancedMDValues::_getValuesByObjId($obj_id);
656 
657  $writer->addRow();
658  $writer->addColumn(ilObject::_lookupTitle($obj_id));
659  $writer->addColumn(ilObject::_lookupDescription($obj_id));
660 
661  $mid = ilObjRemoteCourse::_lookupMID($obj_id);
662  if($reader and ($participant = $reader->getParticipantByMID($mid)))
663  {
664  $writer->addColumn($participant->getParticipantName());
665  }
666  $field = $settings->getMappingByECSName('courseID');
667  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
668 
669  $field = $settings->getMappingByECSName('term');
670  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
671 
672  $field = $settings->getMappingByECSName('lecturer');
673  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
674 
675  $field = $settings->getMappingByECSName('courseType');
676  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
677 
678  $field = $settings->getMappingByECSName('semester_hours');
679  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
680 
681  $field = $settings->getMappingByECSName('credits');
682  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
683 
684  $field = $settings->getMappingByECSName('room');
685  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
686 
687  $field = $settings->getMappingByECSName('cycle');
688  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
689 
690  $field = $settings->getMappingByECSName('begin');
691  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
692 
693  $field = $settings->getMappingByECSName('end');
694  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
695 
696  $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
697  }
698  ilUtil::deliverData($writer->getCSVString(), date("Y_m_d")."_ecs_import.csv", "text/csv");
699  }
700 
707  protected function released()
708  {
709  global $ilUser;
710 
711  $this->tabs_gui->setSubTabActive('ecs_released');
712 
713  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
714  $exported = ilECSExport::_getExportedIDs();
715 
716  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_released.html','Services/WebServices/ECS');
717 
718  if(count($exported))
719  {
720  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
721  $this->tpl->setCurrentBlock("btn_cell");
722  $this->tpl->setVariable("BTN_LINK", $this->ctrl->getLinkTarget($this, "exportReleased"));
723  $this->tpl->setVariable("BTN_TXT", $this->lng->txt("csv_export"));
724  $this->tpl->parseCurrentBlock();
725  }
726 
727  if($this->settings->isEnabled())
728  {
729  $this->tpl->setCurrentBlock("btn_cell");
730  $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,'readAll'));
731  $this->tpl->setVariable("BTN_TXT",$this->lng->txt('ecs_read_remote_links'));
732  $this->tpl->parseCurrentBlock();
733  }
734 
735 
736  include_once('Services/WebServices/ECS/classes/class.ilECSReleasedContentTableGUI.php');
737  $table_gui = new ilECSReleasedContentTableGUI($this,'released');
738 
739  $table_gui->setTitle($this->lng->txt('ecs_released_content'));
740  $table_gui->parse($exported);
741  $this->tpl->setVariable('TABLE_REL',$table_gui->getHTML());
742 
743  return true;
744 
745  }
746 
753  protected function exportReleased()
754  {
755  global $ilObjDataCache;
756 
757  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
758  $exported = ilECSExport::_getExportedIDs();
759  $ilObjDataCache->preloadObjectCache($exported);
760 
761  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
762  $writer = new ilCSVWriter();
763 
764  $writer->addColumn($this->lng->txt('title'));
765  $writer->addColumn($this->lng->txt('description'));
766  $writer->addColumn($this->lng->txt('ecs_field_courseID'));
767  $writer->addColumn($this->lng->txt('ecs_field_term'));
768  $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
769  $writer->addColumn($this->lng->txt('ecs_field_courseType'));
770  $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
771  $writer->addColumn($this->lng->txt('ecs_field_credits'));
772  $writer->addColumn($this->lng->txt('ecs_field_room'));
773  $writer->addColumn($this->lng->txt('ecs_field_cycle'));
774  $writer->addColumn($this->lng->txt('ecs_field_begin'));
775  $writer->addColumn($this->lng->txt('ecs_field_end'));
776  $writer->addColumn($this->lng->txt('last_update'));
777 
778  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
780 
781  foreach($exported as $obj_id)
782  {
783  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
784  $values = ilAdvancedMDValues::_getValuesByObjId($obj_id);
785 
786  $writer->addRow();
787  $writer->addColumn(ilObject::_lookupTitle($obj_id));
788  $writer->addColumn(ilObject::_lookupDescription($obj_id));
789 
790  $field = $settings->getMappingByECSName('courseID');
791  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
792 
793  $field = $settings->getMappingByECSName('term');
794  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
795 
796  $field = $settings->getMappingByECSName('lecturer');
797  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
798 
799  $field = $settings->getMappingByECSName('courseType');
800  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
801 
802  $field = $settings->getMappingByECSName('semester_hours');
803  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
804 
805  $field = $settings->getMappingByECSName('credits');
806  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
807 
808  $field = $settings->getMappingByECSName('room');
809  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
810 
811  $field = $settings->getMappingByECSName('cycle');
812  $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
813 
814  $field = $settings->getMappingByECSName('begin');
815  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
816 
817  $field = $settings->getMappingByECSName('end');
818  $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field],true) : '');
819 
820  $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
821  }
822 
823  ilUtil::deliverData($writer->getCSVString(), date("Y_m_d")."_ecs_export.csv", "text/csv");
824  }
825 
826 
832  protected function prepareFieldSelection($fields)
833  {
834  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
835 
836  $options[0] = $this->lng->txt('ecs_ignore_field');
837  foreach($fields as $field)
838  {
840  $title = ilAdvancedMDRecord::_lookupTitle($field->getRecordId());
841  $options[$field->getFieldId()] = $title.': '.$field->getTitle();
842  }
843  return $options;
844  }
845 
846 
847 
853  protected function initSettings()
854  {
855  include_once('Services/WebServices/ECS/classes/class.ilECSSettings.php');
857  }
858 
864  protected function setSubTabs()
865  {
866  $this->tabs_gui->clearSubTabs();
867 
868  $this->tabs_gui->addSubTabTarget("ecs_settings",
869  $this->ctrl->getLinkTarget($this,'settings'),
870  "settings",get_class($this));
871 
872  // Disable all other tabs, if server hasn't been configured.
873  if(!$this->settings->isEnabled())
874  {
875  return true;
876  }
877 
878  $this->tabs_gui->addSubTabTarget("ecs_communities",
879  $this->ctrl->getLinkTarget($this,'communities'),
880  "communities",get_class($this));
881 
882  $this->tabs_gui->addSubTabTarget('ecs_mappings',
883  $this->ctrl->getLinkTarget($this,'mappings'),
884  'mappings',get_class($this));
885 
886  $this->tabs_gui->addSubTabTarget('ecs_import',
887  $this->ctrl->getLinkTarget($this,'imported'));
888 
889  $this->tabs_gui->addSubTabTarget('ecs_released',
890  $this->ctrl->getLinkTarget($this,'released'));
891 
892  }
893 
899  private function prepareRoleSelect()
900  {
901  global $rbacreview,$ilObjDataCache;
902 
903  $global_roles = ilUtil::_sortIds($rbacreview->getGlobalRoles(),
904  'object_data',
905  'title',
906  'obj_id');
907 
908  $select[0] = $this->lng->txt('links_select_one');
909  foreach($global_roles as $role_id)
910  {
911  $select[$role_id] = ilObject::_lookupTitle($role_id);
912  }
913  return $select;
914  }
915 
916  private function buildPath($a_ref_id)
917  {
918  // TODO: Implement another class for creating the path
919  include_once './classes/class.ilLocatorGUI.php';
920 
921  $loc = new ilLocatorGUI();
922  $loc->setTextOnly(false);
923  $loc->addContextItems($a_ref_id);
924 
925  return $loc->getHTML();
926  }
927 
928 }
929 
930 ?>