ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilECSMappingSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
5 
6 /*
7  * Class for ECS node and directory mapping settings
8  *
9  * @author Stefan Meyer <smeyer.ilias@gmx.de>
10  * @version $ID$
11  *
12  * @ingroup ServicesWebServicesECS
13  * @ilCtrl_isCalledBy ilECSMappingSettingsGUI: ilECSSettingsGUI
14  */
16 {
17  const TAB_DIRECTORY = 1;
18  const TAB_COURSE = 2;
19 
20  private $container = null;
21  private $server = null;
22  private $mid = null;
23 
24  protected $lng = null;
25  protected $ctrl = null;
26 
31  public function __construct($settingsContainer, $server_id, $mid)
32  {
33  global $lng,$ilCtrl;
34 
35  $this->container = $settingsContainer;
36  $this->server = ilECSSetting::getInstanceByServerId($server_id);
37  $this->mid = $mid;
38  $this->lng = $lng;
39  $this->lng->loadLanguageModule('ecs');
40  $this->ctrl = $ilCtrl;
41  }
42 
47  public function getContainer()
48  {
49  return $this->container;
50  }
51 
56  public function getServer()
57  {
58  return $this->server;
59  }
60 
65  public function getMid()
66  {
67  return $this->mid;
68  }
69 
73  public function executeCommand()
74  {
75  global $ilCtrl;
76 
77  $GLOBALS['tpl']->setTitle($this->lng->txt('ecs_campus_connect_title'));
78 
79  $this->ctrl->saveParameter($this,'server_id');
80  $this->ctrl->saveParameter($this,'mid');
81  $this->ctrl->saveParameter($this,'tid');
82 
83  $next_class = $this->ctrl->getNextClass($this);
84  $cmd = $this->ctrl->getCmd();
85 
86  $this->setTabs();
87  switch($next_class)
88  {
89  default:
90  if(!$cmd)
91  {
92  $cmd = "cStart";
93  }
94  $this->$cmd();
95  break;
96  }
97 
98  $GLOBALS['tpl']->setTitle($this->getServer()->getTitle());
99  $GLOBALS['tpl']->setDescription('');
100 
101  return true;
102  }
103 
107  public function cancel()
108  {
109  $GLOBALS['ilCtrl']->returnToParent($this);
110  }
111 
112 
113 
114 
115 
116 
121  protected function cStart()
122  {
123  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
124  if(ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(),$this->getMid())->isCourseAllocationEnabled())
125  {
126  return $this->cInitOverview();
127  }
128  return $this->cSettings();
129  }
130 
135  protected function dStart()
136  {
137  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
138  if(ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(),$this->getMid())->isDirectoryMappingEnabled())
139  {
140  return $this->dTrees();
141  }
142  return $this->dSettings();
143  }
144 
148  protected function cInitOverview($form = null, $current_attribute = null)
149  {
150  global $ilTabs;
151 
152  $current_node = (array) (($_REQUEST['lnodes']) ? $_REQUEST['lnodes'] : ROOT_FOLDER_ID);
153  $current_node = end($current_node);
154 
155  $this->ctrl->setParameter($this,'lnodes',$current_node);
156 
157  $this->setSubTabs(self::TAB_COURSE);
158  $ilTabs->activateTab('ecs_crs_allocation');
159  $ilTabs->activateSubTab('cInitTree');
160 
161  $GLOBALS['tpl']->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_cmap_overview.html','Services/WebServices/ECS');
162 
163  $explorer = $this->cShowLocalExplorer();
164  if(!$form instanceof ilPropertyFormGUI)
165  {
166  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMappingRule.php';
167  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseAttributes.php';
168 
169  if($current_attribute === null)
170  {
171  // check request
172  $current_attribute = (string) $_REQUEST['ecs_ca'];
173  if(!$current_attribute)
174  {
176  $this->getServer()->getServerId(),
177  $this->getMid(),
178  $current_node
179  );
180 
181  $current_attribute =
182  $existing ?
183  $existing :
184  '';
185  /*
186  ilECSCourseAttributes::getInstance(
187  $this->getServer()->getServerId(),
188  $this->getMid())->getFirstAttributeName()
189  );
190  */
191  }
192  }
193  $form = $this->cInitMappingForm($current_node,$current_attribute);
194  }
195 
196  $GLOBALS['tpl']->setVariable('TFORM_ACTION',$this->ctrl->getFormAction($this));
197  $GLOBALS['tpl']->setVariable('LOCAL_EXPLORER',$explorer->getOutput());
198  $GLOBALS['tpl']->setVariable('MAPPING_FORM',$form->getHTML());
199  }
200 
204  protected function cAddAttribute()
205  {
206  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseAttributes.php';
207  $next_attribute = ilECSCourseAttributes::getInstance($this->getServer()->getServerId(), $this->getMid())->getNextAttributeName((string) $_REQUEST['ecs_ca']);
208  $this->cInitOverview(NULL, $next_attribute);
209  }
210 
214  protected function cDeleteAttribute()
215  {
216  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseAttributes.php';
217  $prev_attribute = ilECSCourseAttributes::getInstance($this->getServer()->getServerId(), $this->getMid())->getPreviousAttributeName((string) $_REQUEST['ecs_ca']);
218  $this->cInitOverview(NULL, $prev_attribute);
219  }
220 
224  protected function cShowLocalExplorer()
225  {
226  global $tree;
227 
228  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingLocalExplorer.php';
229  $explorer = new ilECSNodeMappingLocalExplorer(
230  $this->ctrl->getLinkTarget($this,'cInitOverview'),
231  $this->getServer()->getServerId(),
232  $this->getMid()
233  );
234  $explorer->setPostVar('lnodes[]');
235 
236  $lnodes = (array) $_REQUEST['lnodes'];
237  $checked_node = array_pop($lnodes);
238  if((int) $_REQUEST['lid'])
239  {
240  $checked_node = (int) $_REQUEST['lid'];
241  }
242 
243  if($checked_node)
244  {
245  $explorer->setCheckedItems(array($checked_node));
246  }
247  else
248  {
249  $explorer->setCheckedItems(array(ROOT_FOLDER_ID));
250  }
251  $explorer->setTargetGet('lref_id');
252  $explorer->setSessionExpandVariable('lexpand');
253  $explorer->setExpand((int) $_GET['lexpand']);
254  $explorer->setExpandTarget($this->ctrl->getLinkTarget($this,'cInitOverview'));
255  $explorer->setOutput(0);
256  return $explorer;
257  }
258 
262  protected function cInitMappingForm($current_node,$current_attribute)
263  {
264  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseAttributes.php';
265  $attributes_obj = ilECSCourseAttributes::getInstance($this->getServer()->getServerId(), $this->getMid());
266 
267  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
268  $form = new ilPropertyFormGUI();
269  $form->setTableWidth("100%");
270  $this->ctrl->setParameter($this,'ecs_ca',$current_attribute);
271  $form->setFormAction($this->ctrl->getFormAction($this));
272  $this->ctrl->setParameter($this,'ecs_ca','');
273 
274  $form->setTitle($this->lng->txt('ecs_cmap_mapping_form_title') .' '.ilObject::_lookupTitle(ilObject::_lookupObjId($current_node)));
275 
276  // Iterate through all current attributes
277  $attributes = $attributes_obj->getAttributeSequence($current_attribute);
278  foreach($attributes as $att_name)
279  {
280  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMappingRule.php';
281  $rule = ilECSCourseMappingRule::getInstanceByAttribute($this->getServer()->getServerId(), $this->getMid(), $current_node, $att_name);
282 
284  $section->setTitle($this->lng->txt('ecs_cmap_att_'.$att_name));
285 
286  // Filter
287  $form->addItem($section);
288 
289  $isfilter = new ilRadioGroupInputGUI($this->lng->txt('ecs_cmap_form_filter'),$att_name.'_is_filter');
290  $isfilter->setValue($rule->isFilterEnabled() ? 1 : 0);
291 
292  $all_values = new ilRadioOption($this->lng->txt('ecs_cmap_form_all_values'),0);
293  $isfilter->addOption($all_values);
294 
295  $use_filter = new ilRadioOption($this->lng->txt('ecs_cmap_form_filter_by_values'),1);
296  $filter = new ilTextInputGUI('',$att_name.'_filter');
297  $filter->setInfo($this->lng->txt('ecs_cmap_form_filter_info'));
298  $filter->setSize(50);
299  $filter->setMaxLength(512);
300  $filter->setRequired(true);
301  $filter->setValue($rule->getFilter());
302  $use_filter->addSubItem($filter);
303 
304  $isfilter->addOption($use_filter);
305 
306  $form->addItem($isfilter);
307 
308  // Create subdirs
309  $subdirs = new ilCheckboxInputGUI($this->lng->txt('ecs_cmap_form_create_subdirs'),$att_name.'_subdirs');
310  $subdirs->setChecked($rule->isSubdirCreationEnabled());
311  $subdirs->setValue(1);
312 
313  // Subdir types (disabled in spec)
314  /*
315  $subdir_type = new ilRadioGroupInputGUI($this->lng->txt('ecs_cmap_form_subdir_type'), $att_name.'_subdir_type');
316  $subdir_type->setValue($rule->getSubDirectoryType());
317 
318  $value = new ilRadioOption($this->lng->txt('ecs_cmap_form_subdir_value'), ilECSCourseMappingRule::SUBDIR_VALUE);
319  $subdir_type->addOption($value);
320 
321  $name = new ilRadioOption($this->lng->txt('ecs_cmap_form_subdir_name'), ilECSCourseMappingRule::SUBDIR_ATTRIBUTE_NAME);
322  $subdir_type->addOption($name);
323 
324  $subdirs->addSubItem($subdir_type);
325  */
326  $form->addItem($subdirs);
327 
328  // Directory relations
329  /*
330  $upper_attributes = ilECSCourseAttributes::getInstance(
331  $this->getServer()->getServerId(),
332  $this->getMid())->getUpperAttributes($att_name);
333 
334  if($upper_attributes)
335  {
336  $dir_relation = new ilRadioGroupInputGUI($this->lng->txt('ecs_cmap_form_dir_relation'),$att_name.'_dir_relation');
337 
338  $current_dir = new ilRadioOption($this->lng->txt('ecs_cmap_form_current_dir'),'');
339  $dir_relation->addOption($current_dir);
340  }
341  foreach($upper_attributes as $subdir_name)
342  {
343  $subdir = new ilRadioOption($this->lng->txt('ecs_cmap_att_'.$subdir_name),$subdir_name);
344  $dir_relation->addOption($subdir);
345  }
346  if($upper_attributes)
347  {
348  $dir_relation->setValue((string) $rule->getDirectory());
349  $form->addItem($dir_relation);
350  }
351  */
352  }
353 
354  // add list of attributes
355  $hidden_atts = new ilHiddenInputGUI('attributes');
356  $hidden_atts->setValue(implode(',',$attributes));
357  $form->addItem($hidden_atts);
358 
359 
360  if($current_attribute)
361  {
362  $form->addCommandButton('cSaveOverview',$this->lng->txt('save'));
363  }
364 
365  if($attributes_obj->getNextAttributeName($current_attribute))
366  {
367  $form->addCommandButton('cAddAttribute', $this->lng->txt('ecs_cmap_add_attribute_btn'));
368  }
369  if($attributes_obj->getPreviousAttributeName($current_attribute))
370  {
371  $form->addCommandButton('cDeleteAttribute', $this->lng->txt('ecs_cmap_delete_attribute_btn'));
372  }
374  $this->getServer()->getServerId(),
375  $this->getMid(),
376  $current_node
377  ))
378  {
379  $form->addCommandButton('cDeleteRulesOfNode', $this->lng->txt('ecs_cmap_delete_rule'));
380  }
381 
382  #$form->addCommandButton('cInitOverview', $this->lng->txt('cancel'));
383 
384  $form->setShowTopButtons(false);
385 
386  return $form;
387  }
388 
392  protected function cSaveOverview()
393  {
394  $current_node = (int) $_REQUEST['lnodes'];
395  $current_att = (string) $_REQUEST['ecs_ca'];
396  $form = $this->cInitMappingForm($current_node, $current_att);
397 
398  if($form->checkInput())
399  {
400  // save ...
401  $all_attributes = explode(',',$form->getInput('attributes'));
402  foreach((array) $all_attributes as $att_name)
403  {
405  $this->getServer()->getServerId(),
406  $this->getMid(),
407  $current_node,
408  $att_name);
409  $rule->setServerId($this->getServer()->getServerId());
410  $rule->setMid($this->getMid());
411  $rule->setRefId($current_node);
412  $rule->setAttribute($att_name);
413  $rule->enableFilter($form->getInput($att_name.'_is_filter'));
414  $rule->setFilter($form->getInput($att_name.'_filter'));
415  $rule->enableSubdirCreation($form->getInput($att_name.'_subdirs'));
416  //$rule->setSubDirectoryType($form->getInput($att_name.'_subdir_type'));
417  //$rule->setDirectory($form->getInput($att_name.'_dir_relation'));
418 
419  if($rule->getRuleId())
420  {
421  $rule->update();
422  }
423  else
424  {
425  $rule->save();
426  }
427  }
428 
429  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
430  $this->ctrl->setParameter($this,'lnodes',$current_node);
431  $this->ctrl->redirect($this,'cInitOverview');
432  }
433 
434  $form->setValuesByPost();
435  ilUtil::sendFailure($this->lng->txt('err_check_input'));
436  $this->cInitOverview($form, $current_att);
437  }
438 
439  protected function cDeleteRulesOfNode()
440  {
441  $current_node = (int) $_REQUEST['lnodes'];
442 
443  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMappingRule.php';
445  $this->getServer()->getServerId(),
446  $this->getMid(),
447  $current_node);
448 
449  foreach($rules as $rid)
450  {
451  $rule = new ilECSCourseMappingRule($rid);
452  $rule->delete();
453  }
454  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
455  $this->ctrl->redirect($this,'cInitOverview');
456  }
457 
458 
459 
460 
466  protected function cSettings(ilPropertyFormGUI $form = NULL)
467  {
468  global $ilTabs;
469 
470  $this->setSubTabs(self::TAB_COURSE);
471  $ilTabs->activateTab('ecs_crs_allocation');
472  $ilTabs->activateSubTab('cSettings');
473 
474  if(!$form instanceof ilPropertyFormGUI)
475  {
476  $form = $this->initFormCSettings();
477  }
478 
479  $GLOBALS['tpl']->setContent($form->getHTML());
480 
481  return true;
482  }
483 
487  protected function initFormCSettings()
488  {
489  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
490 
491  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
492  $form = new ilPropertyFormGUI();
493  $form->setFormAction($this->ctrl->getFormAction($this));
494  $form->setTitle($this->lng->txt('settings'));
495 
496  // individual course allocation
497  $check = new ilCheckboxInputGUI($this->lng->txt('ecs_cmap_enable'), 'enabled');
498  $check->setChecked(ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(),$this->getMid())->isCourseAllocationEnabled());
499  $form->addItem($check);
500 
501 
502  // add default container
503  $imp = new ilCustomInputGUI($this->lng->txt('ecs_cmap_def_cat'),'default_cat');
504  $imp->setRequired(true);
505 
506  $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
507  $tpl->setVariable('SIZE',5);
508  $tpl->setVariable('MAXLENGTH',11);
509  $tpl->setVariable('POST_VAR','default_cat');
510 
511  $default = ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(),$this->getMid())->getDefaultCourseCategory();
512  $tpl->setVariable('PROPERTY_VALUE',$default);
513 
514  if($default)
515  {
516  include_once './Services/Tree/classes/class.ilPathGUI.php';
517  $path = new ilPathGUI();
518  $path->enableTextOnly(false);
519  $path->enableHideLeaf(false);
520  $tpl->setVariable('COMPLETE_PATH',$path->getPath(ROOT_FOLDER_ID, $default));
521  }
522 
523  $imp->setHtml($tpl->get());
524  $imp->setInfo($this->lng->txt('ecs_cmap_def_cat_info'));
525  $form->addItem($imp);
526 
527  // all in one category
528  $allinone = new ilCheckboxInputGUI($this->lng->txt('ecs_cmap_all_in_one'),'allinone');
529  $allinone->setChecked(ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(),$this->getMid())->isAllInOneCategoryEnabled());
530  $allinone->setInfo($this->lng->txt('ecs_cmap_all_in_one_info'));
531 
532  $allinone_cat = new ilCustomInputGUI($this->lng->txt('ecs_cmap_all_in_one_cat'),'allinone_cat');
533  $allinone_cat->setRequired(true);
534 
535  $tpl = new ilTemplate('tpl.ecs_import_id_form.html',true,true,'Services/WebServices/ECS');
536  $tpl->setVariable('SIZE',5);
537  $tpl->setVariable('MAXLENGTH',11);
538  $tpl->setVariable('POST_VAR','allinone_cat');
539 
540  $cat = ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(),$this->getMid())->getAllInOneCategory();
541  $tpl->setVariable('PROPERTY_VALUE',$cat);
542  if($cat)
543  {
544  include_once './Services/Tree/classes/class.ilPathGUI.php';
545  $path = new ilPathGUI();
546  $path->enableTextOnly(false);
547  $path->enableHideLeaf(false);
548  $tpl->setVariable('COMPLETE_PATH',$path->getPath(ROOT_FOLDER_ID, $default));
549  }
550 
551  $allinone_cat->setHtml($tpl->get());
552  $allinone->addSubItem($allinone_cat);
553  $form->addItem($allinone);
554 
555  // multiple attributes
556  $multiple = new ilCheckboxInputGUI($this->lng->txt('ecs_cmap_multiple_atts'),'multiple');
557  $multiple->setChecked(ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(),$this->getMid())->isAttributeMappingEnabled());
558 
559  // attribute selection
560  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php';
561  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseAttributes.php';
562  $attributes = new ilSelectInputGUI($this->lng->txt('ecs_cmap_attributes'),'atts');
563  $attributes->setMulti(true);
564  $attributes->setValue(
566  $this->getServer()->getServerId(),
567  $this->getMid()
568  )->getAttributeValues());
569  $attributes->setRequired(true);
571  $multiple->addSubItem($attributes);
572 
573  $form->addItem($multiple);
574 
575  // role mapping
576  $rm = new ilFormSectionHeaderGUI();
577  $rm->setTitle($this->lng->txt('ecs_role_mappings'));
578  $form->addItem($rm);
579 
580  $mapping_defs = ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(),$this->getMid())->getRoleMappings();
581 
582  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php';
583  foreach(ilECSMappingUtils::getRoleMappingInfo() as $name => $info)
584  {
585  $role_map = new ilTextInputGUI($this->lng->txt($info['lang']),$name);
586  $role_map->setValue($mapping_defs[$name]);
587  $role_map->setSize(32);
588  $role_map->setMaxLength(64);
589  $role_map->setRequired($info['required']);
590  $form->addItem($role_map);
591  }
592 
593 
594  $form->addCommandButton('cUpdateSettings',$this->lng->txt('save'));
595  $form->addCommandButton('cSettings', $this->lng->txt('cancel'));
596 
597  return $form;
598  }
599 
604  protected function dSettings(ilPropertyFormGUI $form = NULL)
605  {
606  global $ilTabs;
607 
608  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignments.php';
609  $this->setSubTabs(self::TAB_DIRECTORY);
610  $ilTabs->activateTab('ecs_dir_allocation');
611  $ilTabs->activateSubTab('dSettings');
612 
613  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
614  if(!$form instanceof ilPropertyFormGUI)
615  {
616  $form = $this->initFormDSettings();
617  }
618 
619  $GLOBALS['tpl']->setContent($form->getHTML());
620 
621  return true;
622  }
623 
627  protected function cUpdateSettings()
628  {
629  $form = $this->initFormCSettings();
630  if($form->checkInput())
631  {
632  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
633  $settings = ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(),$this->getMid());
634  $settings->enableCourseAllocation($form->getInput('enabled'));
635  $settings->setDefaultCourseCategory($form->getInput('default_cat'));
636  $settings->enableAllInOne($form->getInput('allinone'));
637  $settings->setAllInOneCategory($form->getInput('allinone_cat'));
638  $settings->enableAttributeMapping($form->getInput('multiple'));
639 
640  $role_mappings = array();
641  foreach(ilECSMappingUtils::getRoleMappingInfo() as $name => $info)
642  {
643  $role_mappings[$name] = $form->getInput($name);
644  }
645  $settings->setRoleMappings($role_mappings);
646  $settings->update();
647 
648  // store attribute settings
649  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseAttributes.php';
650  $attributes = new ilECSCourseAttributes($this->getServer()->getServerId(),$this->getMid());
651  $attributes->delete();
652 
653  $form_atts = $form->getInput('atts');
654 
655  foreach($form_atts as $name)
656  {
657  if(!$name)
658  {
659  continue;
660  }
661 
662  $att = new ilECSCourseAttribute();
663  $att->setServerId($this->getServer()->getServerId());
664  $att->setMid($this->getMid());
665  $att->setName($name);
666  $att->save();
667  }
668 
669  //$att = new ilECSCourseAttribute();
670  //$att->setName($a_name)
671 
672  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
673  $GLOBALS['ilCtrl']->redirect($this,'cSettings');
674  }
675  ilUtil::sendFailure($this->lng->txt('err_check_input'));
676  $form->setValuesByPost();
677  $this->cSettings($form);
678  }
679 
684  protected function cAttributes()
685  {
686  global $ilTabs;
687 
688  $this->setSubTabs(self::TAB_COURSE);
689  $ilTabs->setTabActive('ecs_crs_allocation');
690  $ilTabs->setSubTabActive('cAttributes');
691 
692  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseAttributesTableGUI.php';
693  $table = new ilECSCourseAttributesTableGUI(
694  $this,
695  'attributes',
696  $this->getServer()->getServerId(),
697  $this->getMid()
698  );
699  $table->init();
700  $table->parse(
702  $this->getServer()->getServerId(),
703  $this->getMid())->getAttributes());
704 
705  $GLOBALS['tpl']->setContent($table->getHTML());
706  }
707 
708 
709 
713  protected function dUpdateSettings()
714  {
715  global $ilCtrl;
716 
717  $form = $this->initFormDSettings();
718  if($form->checkInput())
719  {
720  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
721  $settings = ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(),$this->getMid());
722  $settings->enableDirectoryMapping((bool) $form->getInput('active'));
723  $settings->enableEmptyContainerCreation(!$form->getInput('empty'));
724  $settings->update();
725  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
726  }
727  else
728  {
729  ilUtil::sendFailure($this->lng->txt('err_check_input'),true);
730  $form->setValuesByPost();
731  }
732  $ilCtrl->redirect($this,'dSettings');
733  }
734 
738  protected function initFormDSettings()
739  {
740  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
741  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
742 
743  $form = new ilPropertyFormGUI();
744  $form->setFormAction($this->ctrl->getFormAction($this));
745  $form->setTitle($this->lng->txt('general_settings'));
746 
747  $active = new ilCheckboxInputGUI($this->lng->txt('ecs_node_mapping_activate'), 'active');
748  $active->setChecked(ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(),$this->getMid())->isDirectoryMappingEnabled());
749  $form->addItem($active);
750 
751  $create_empty = new ilCheckboxInputGUI($this->lng->txt('ecs_node_mapping_create_empty'), 'empty');
752  $create_empty->setChecked(!ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(),$this->getMid())->isEmptyContainerCreationEnabled());
753  $create_empty->setInfo($this->lng->txt('ecs_node_mapping_create_empty_info'));
754  $form->addItem($create_empty);
755 
756  $form->addCommandButton('dUpdateSettings',$this->lng->txt('save'));
757  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
758 
759  return $form;
760  }
761 
765  protected function dTrees()
766  {
767  global $ilToolbar;
768 
769  $this->setSubTabs(self::TAB_DIRECTORY);
770  $GLOBALS['ilTabs']->activateSubTab('dTrees');
771  $GLOBALS['ilTabs']->activateTab('ecs_dir_allocation');
772 
773  $ilToolbar->addButton(
774  $this->lng->txt('ecs_sync_trees'),
775  $this->ctrl->getLinkTarget($this, 'dSynchronizeTrees'));
776 
777  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingTreeTableGUI.php';
778 
779  $dtreeTable = new ilECSNodeMappingTreeTableGUI(
780  $this->getServer()->getServerId(),
781  $this->getMid(),
782  $this,
783  'dtree');
784 
785 
786  $dtreeTable->parse();
787  $GLOBALS['tpl']->setContent($dtreeTable->getHTML());
788  return true;
789  }
790 
794  protected function dConfirmDeleteTree()
795  {
796  $this->setSubTabs(self::TAB_DIRECTORY);
797  $GLOBALS['ilTabs']->activateSubTab('dTrees');
798  $GLOBALS['ilTabs']->activateTab('ecs_dir_allocation');
799 
800  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
801  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
802 
803  $confirm = new ilConfirmationGUI();
804  $confirm->setFormAction($this->ctrl->getFormAction($this));
805  $confirm->setHeaderText($this->lng->txt('ecs_confirm_delete_tree'));
806 
807  $confirm->addItem(
808  'tid',
809  (int) $_REQUEST['tid'],
811  $this->getServer()->getServerId(),
812  $this->getMid(),
813  (int) $_REQUEST['tid']
814  )
815  );
816  $confirm->setConfirm($this->lng->txt('delete'), 'dDeleteTree');
817  $confirm->setCancel($this->lng->txt('cancel'), 'dTrees');
818 
819  $GLOBALS['tpl']->setContent($confirm->getHTML());
820  }
821 
825  protected function dDeleteTree()
826  {
827  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
828  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
829 
830  $GLOBALS['ilLog']->write('Deleting tree');
831 
832  $tree = new ilECSCmsTree((int) $_REQUEST['tid']);
833  $tree->deleteTree($tree->getNodeData(ilECSCmsTree::lookupRootId((int) $_REQUEST['tid'])));
834 
835 
836 
837  // also delete import information
838  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
840  $this->getServer()->getServerId(),
841  $this->getMid(),
843  $this->getServer()->getServerId(),
844  $this->getMid(),
845  (int) $_REQUEST['tid']
846  )
847  );
848 
849  $data = new ilECSCmsData();
850  $data->setServerId($this->getServer()->getServerId());
851  $data->setMid($this->getMid());
852  $data->setTreeId((int) $_REQUEST['tid']);
853  $data->deleteTree();
854 
855 
856  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignments.php';
858  $this->getServer()->getServerId(),
859  $this->getMid(),
860  (int) $_REQUEST['tid']
861  );
862 
863  ilUtil::sendSuccess($this->lng->txt('ecs_cms_tree_deleted'),true);
864  $this->ctrl->redirect($this,'dTrees');
865  }
866 
870  protected function dEditTree(ilPropertyFormGUI $form = null)
871  {
872  $GLOBALS['tpl']->addBlockFile('ADM_CONTENT','adm_content','tpl.ecs_edit_tree.html','Services/WebServices/ECS');
873 
874  $this->ctrl->saveParameter($this,'cid');
875 
876  $GLOBALS['ilTabs']->clearTargets();
877  $GLOBALS['ilTabs']->setBack2Target(
878  $this->lng->txt('ecs_back_settings'),
879  $this->ctrl->getLinkTarget($this,'cancel')
880  );
881  $GLOBALS['ilTabs']->setBackTarget(
882  $this->lng->txt('ecs_cms_dir_tree'),
883  $this->ctrl->getLinkTarget($this,'dTrees')
884  );
885 
886  $GLOBALS['tpl']->setVariable('LEGEND',$GLOBALS['lng']->txt('ecs_status_legend'));
887  $GLOBALS['tpl']->setVariable('PENDING_UNMAPPED',$GLOBALS['lng']->txt('ecs_status_pending_unmapped'));
888  $GLOBALS['tpl']->setVariable('PENDING_UNMAPPED_DISCON',$GLOBALS['lng']->txt('ecs_status_pending_unmapped_discon'));
889  $GLOBALS['tpl']->setVariable('PENDING_UNMAPPED_NONDISCON',$GLOBALS['lng']->txt('ecs_status_pending_unmapped_nondiscon'));
890  $GLOBALS['tpl']->setVariable('MAPPED',$GLOBALS['lng']->txt('ecs_status_mapped'));
891  $GLOBALS['tpl']->setVariable('DELETED',$GLOBALS['lng']->txt('ecs_status_deleted'));
892 
893  $form = $this->dInitFormTreeSettings($form);
894  $GLOBALS['tpl']->setVariable('GENERAL_FORM',$form->getHTML());
895  $GLOBALS['tpl']->setVariable('TFORM_ACTION',$this->ctrl->getFormAction($this,'dEditTree'));
896 
897  $explorer = $this->dShowLocalExplorer();
898  $this->dShowCmsExplorer($explorer);
899  }
900 
904  protected function dInitFormTreeSettings(ilPropertyFormGUI $form = null)
905  {
906  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php';
907  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
908 
909  if($form instanceof ilPropertyFormGUI)
910  {
911  return $form;
912  }
913 
914  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignment.php';
915  $assignment = new ilECSNodeMappingAssignment(
916  $this->getServer()->getServerId(),
917  $this->getMid(),
918  (int) $_REQUEST['tid'],
919  0
920  );
921 
922  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
923  $form = new ilPropertyFormGUI();
924  $form->setFormAction($this->ctrl->getFormAction($this,'dEditTree'));
925  $form->setTitle($this->lng->txt('general_settings'));
926  $form->addCommandButton('dUpdateTreeSettings', $this->lng->txt('save'));
927  $form->addCommandButton('dTrees', $this->lng->txt('cancel'));
928  $form->setTableWidth('30%');
929 
930  // CMS id (readonly)
931  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
932  $cmsid = new ilNumberInputGUI($this->lng->txt('ecs_cms_id'), 'cmsid');
933  $cmsid->setValue(
935  );
936  $cmsid->setDisabled(true);
937  $cmsid->setSize(7);
938  $cmsid->setMaxLength(12);
939  $form->addItem($cmsid);
940 
941 
942  $mapping_status = ilECSMappingUtils::lookupMappingStatus(
943  $this->getServer()->getServerId(),
944  $this->getMid(),
945  (int) $_REQUEST['tid']);
946  $mapping_advanced = ($mapping_status != ilECSMappingUtils::MAPPED_MANUAL ? true : false);
947 
948  // Status (readonly)
949  $status = new ilNonEditableValueGUI($this->lng->txt('status'), '');
950  $status->setValue(ilECSMappingUtils::mappingStatusToString($mapping_status));
951  $form->addItem($status);
952 
953  // title update
954  $title = new ilCheckboxInputGUI($this->lng->txt('ecs_title_updates'), 'title');
955  $title->setValue(1);
956  $title->setChecked($assignment->isTitleUpdateEnabled());
957  #$title->setInfo($this->lng->txt('ecs_title_update_info'));
958  $form->addItem($title);
959 
960 
961  $position = new ilCheckboxInputGUI($this->lng->txt('ecs_position_updates'), 'position');
962  $position->setDisabled(!$mapping_advanced);
963  $position->setChecked($mapping_advanced && $assignment->isPositionUpdateEnabled());
964  $position->setValue(1);
965  #$position->setInfo($this->lng->txt('ecs_position_update_info'));
966  $form->addItem($position);
967 
968  $tree = new ilCheckboxInputGUI($this->lng->txt('ecs_tree_updates'), 'tree');
969  $tree->setDisabled(!$mapping_advanced);
970  $tree->setChecked($mapping_advanced && $assignment->isTreeUpdateEnabled());
971  $tree->setValue(1);
972  #$tree->setInfo($this->lng->txt('ecs_tree_update_info'));
973  $form->addItem($tree);
974 
975  return $form;
976  }
977 
982  protected function dUpdateTreeSettings()
983  {
984  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignment.php';
985  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
986  $assignment = new ilECSNodeMappingAssignment(
987  $this->getServer()->getServerId(),
988  $this->getMid(),
989  (int) $_REQUEST['tid'],
990  0
991  );
992  $assignment->setRefId(0);
993  $assignment->setObjId(0);
994 
995  $form = $this->dInitFormTreeSettings();
996  if($form->checkInput())
997  {
998  $assignment->enableTitleUpdate($form->getInput('title'));
999  $assignment->enableTreeUpdate($form->getInput('tree'));
1000  $assignment->enablePositionUpdate($form->getInput('position'));
1001  $assignment->update();
1002 
1003  ilUtil::sendSuccess($this->lng->txt('settings_saved',true));
1004  $this->ctrl->redirect($this,'dEditTree');
1005  }
1006 
1007  $form->setValuesByPost();
1008  ilUtil::sendFailure($this->lng->txt('err_check_input'));
1009  $this->dEditTree($form);
1010  return true;
1011  }
1012 
1016  protected function dSynchronizeTree()
1017  {
1018  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTreeSynchronizer.php';
1019  $sync = new ilECSCmsTreeSynchronizer(
1020  $this->getServer(),
1021  $this->mid,
1022  (int) $_REQUEST['tid']
1023  );
1024  $sync->sync();
1025  ilUtil::sendSuccess($this->lng->txt('ecs_cms_tree_synchronized'),true);
1026  $this->ctrl->redirect($this,'dTrees');
1027  }
1028 
1029  protected function dSynchronizeTrees()
1030  {
1031  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSDirectoryTreeConnector.php';
1032 
1033  try
1034  {
1035  $connector = new ilECSDirectoryTreeConnector($this->getServer());
1036  $res = $connector->getDirectoryTrees();
1037  foreach((array) $res->getLinkIds() as $cms_id)
1038  {
1039  include_once './Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php';
1040  include_once './Services/WebServices/ECS/classes/class.ilECSEvent.php';
1041  $event = new ilECSEventQueueReader($this->getServer()->getServerId());
1042  $event->add(
1044  $cms_id,
1046  );
1047  }
1048  $this->ctrl->redirect($this,'dTrees');
1049  }
1050  catch(Exception $e)
1051  {
1052  ilUtil::sendFailure($e->getMessage(),true);
1053  $this->ctrl->redirect($this,'dTrees');
1054  }
1055  }
1056 
1060  protected function dShowLocalExplorer()
1061  {
1062  global $tree;
1063 
1064  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingLocalExplorer.php';
1065  $explorer = new ilECSNodeMappingLocalExplorer(
1066  $this->ctrl->getLinkTarget($this,'dEditTree'),
1067  $this->getServer()->getServerId(),
1068  $this->getMid()
1069  );
1070  $explorer->setPostVar('lnodes[]');
1071 
1072  $lnodes = (array) $_REQUEST['lnodes'];
1073  $checked_node = array_pop($lnodes);
1074  if((int) $_REQUEST['lid'])
1075  {
1076  $checked_node = (int) $_REQUEST['lid'];
1077  }
1078 
1079  if($checked_node)
1080  {
1081  $explorer->setCheckedItems(array($checked_node));
1082  }
1083  else
1084  {
1085  $explorer->setCheckedItems(array(ROOT_FOLDER_ID));
1086  }
1087  $explorer->setTargetGet('lref_id');
1088  $explorer->setSessionExpandVariable('lexpand');
1089  $explorer->setExpand((int) $_GET['lexpand']);
1090  $explorer->setExpandTarget($this->ctrl->getLinkTarget($this,'dEditTree'));
1091  $explorer->setOutput(0);
1092  $GLOBALS['tpl']->setVariable('LOCAL_EXPLORER',$explorer->getOutput());
1093 
1094  return $explorer;
1095  }
1096 
1100  protected function dShowCmsExplorer(ilExplorer $localExplorer)
1101  {
1102  global $tree;
1103 
1104  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
1105  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingCmsExplorer.php';
1106  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignments.php';
1107 
1108  $explorer = new ilECSNodeMappingCmsExplorer(
1109  $this->ctrl->getLinkTarget($this,'dEditTree'),
1110  $this->getServer()->getServerId(),
1111  $this->getMid(),
1112  (int) $_REQUEST['tid']
1113  );
1114  $explorer->setRoot(ilECSCmsTree::lookupRootId((int) $_REQUEST['tid']));
1115  $explorer->setTree(
1116  new ilECSCmsTree(
1117  (int) $_REQUEST['tid']
1118  )
1119  );
1120  $explorer->setPostVar('rnodes[]');
1121 
1122  // Read checked items from mapping of checked items in local explorer
1123  $active_node = $tree->getRootId();
1124  foreach($localExplorer->getCheckedItems() as $ref_id)
1125  {
1126  $explorer->setCheckedItems(
1128  $this->getServer()->getServerId(),
1129  $this->getMid(),
1130  (int) $_REQUEST['tid'],
1131  $ref_id
1132  )
1133  );
1134  $active_node = $ref_id;
1135  }
1136 
1137 
1138  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignments.php';
1139  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
1140  $cmsTree = new ilECSCmsTree((int) $_REQUEST['tid']);
1142  $this->getServer()->getServerId(),
1143  $this->getMid(),
1144  (int) $_REQUEST['tid'],
1145  $active_node
1146  ) as $cs_id)
1147  {
1148  foreach($cmsTree->getPathId($cs_id) as $path_id)
1149  {
1150  #$explorer->setExpand($path_id);
1151  }
1152  }
1153 
1154  $explorer->setTargetGet('rref_id');
1155  $explorer->setSessionExpandVariable('rexpand');
1156 
1157  #if((int) $_REQUEST['rexpand'])
1158  {
1159  $explorer->setExpand((int) $_GET['rexpand']);
1160  }
1161  $explorer->setExpandTarget($this->ctrl->getLinkTarget($this,'dEditTree'));
1162  $explorer->setOutput(0);
1163  $GLOBALS['tpl']->setVariable('REMOTE_EXPLORER',$explorer->getOutput());
1164 
1165  }
1166 
1171  protected function dInitEditTree()
1172  {
1173  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
1175  $this->getServer()->getServerId(),
1176  $this->getMid(),
1177  (int) $_REQUEST['tid']
1178  );
1179  return $this->dEditTree();
1180  }
1181 
1182 
1186  protected function dMap()
1187  {
1188  if(!$_POST['lnodes'])
1189  {
1190  ilUtil::sendFailure($this->lng->txt('select_one'),true);
1191  $this->ctrl->redirect($this,'dEditTree');
1192  }
1193 
1194  $ref_id = end($_POST['lnodes']);
1195 
1196  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignments.php';
1198  $this->getServer()->getServerId(),
1199  $this->getMid(),
1200  (int) $_REQUEST['tid'],
1201  $ref_id
1202  );
1203 
1204 
1205  $nodes = (array) $_POST['rnodes'];
1206  $nodes = (array) array_reverse($nodes);
1207 
1208  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignment.php';
1209  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignments.php';
1210  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
1211  foreach($nodes as $cms_id)
1212  {
1213  $assignment = new ilECSNodeMappingAssignment(
1214  $this->getServer()->getServerId(),
1215  $this->getMid(),
1216  (int) $_REQUEST['tid'],
1217  (int) $cms_id
1218  );
1219  $assignment->setRefId($ref_id);
1220  $assignment->setObjId(ilObject::_lookupObjId($ref_id));
1221  $assignment->enablePositionUpdate(false);
1222  $assignment->enableTreeUpdate(false);
1223  $assignment->enableTitleUpdate(ilECSNodeMappingAssignments::lookupDefaultTitleUpdate(
1224  $this->getServer()->getServerId(),
1225  $this->getMid(),
1226  (int) $_REQUEST['tid']
1227  ));
1228  $assignment->update();
1229 
1230  // Delete subitems mappings for cms subtree
1231  $cmsTree = new ilECSCmsTree((int) $_REQUEST['tid']);
1232  $childs = $cmsTree->getSubTreeIds($cms_id);
1233 
1235  $this->getServer()->getServerId(),
1236  $this->getMid(),
1237  (int) $_REQUEST['tid'],
1238  $childs
1239  );
1240 
1241  }
1242 
1244  $this->getServer()->getServerId(),
1245  $this->getMid(),
1246  (int) $_REQUEST['tid']
1247  );
1248 
1249  // Save parameter cid
1250  $this->ctrl->setParameter($this,'lid',(int) $ref_id);
1251 
1252  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
1253  $this->ctrl->redirect($this,'dEditTree');
1254  }
1255 
1259  protected function dMappingOverview()
1260  {
1261  $this->setSubTabs(self::TAB_DIRECTORY);
1262  $GLOBALS['ilTabs']->activateSubTab('dMappingOverview');
1263  $GLOBALS['ilTabs']->activateTab('ecs_dir_allocation');
1264  }
1265 
1266 
1267 
1272  protected function setTabs()
1273  {
1274  global $ilTabs;
1275 
1276  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
1277 
1278  $ilTabs->clearTargets();
1279  $ilTabs->setBackTarget(
1280  $this->lng->txt('ecs_back_settings'),
1281  $this->ctrl->getParentReturn($this)
1282  );
1283  // Directories are only visible for import type campus managment.
1284  if(ilECSParticipantSettings::loookupCmsMid($this->getServer()->getServerId()) == $this->getMid())
1285  {
1286  $ilTabs->addTab(
1287  'ecs_dir_allocation',
1288  $this->lng->txt('ecs_dir_alloc'),
1289  $this->ctrl->getLinkTarget($this,'dSettings')
1290  );
1291  }
1292 
1293  $ilTabs->addTab(
1294  'ecs_crs_allocation',
1295  $this->lng->txt('ecs_crs_alloc'),
1296  $this->ctrl->getLinkTarget($this,'cStart')
1297  );
1298  }
1299 
1305  protected function setSubTabs($a_tab)
1306  {
1307  global $ilTabs;
1308 
1309  if($a_tab == self::TAB_DIRECTORY)
1310  {
1311  $ilTabs->addSubTab(
1312  'dMappingOverview',
1313  $this->lng->txt('ecs_cc_mapping_overview'),
1314  $this->ctrl->getLinkTarget($this,'dMappingOverview')
1315  );
1316  $ilTabs->addSubTab(
1317  'dTrees',
1318  $this->lng->txt('ecs_cms_dir_tree'),
1319  $this->ctrl->getLinkTarget($this,'dTrees')
1320  );
1321  $ilTabs->addSubTab(
1322  'dSettings',
1323  $this->lng->txt('settings'),
1324  $this->ctrl->getLinkTarget($this,'dSettings')
1325  );
1326  }
1327  if($a_tab == self::TAB_COURSE)
1328  {
1329  // Check if attributes are available
1330  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseAttributes.php';
1331  $atts = ilECSCourseAttributes::getInstance($this->getServer()->getServerId(), $this->getMid());
1332 
1333  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
1334  if(ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(),$this->getMid())->isCourseAllocationEnabled())
1335  {
1336  $ilTabs->addSubTab(
1337  'cInitTree',
1338  $this->lng->txt('ecs_cmap_overview'),
1339  $this->ctrl->getLinkTarget($this,'cInitOverview')
1340  );
1341  }
1342 
1343  $ilTabs->addSubTab(
1344  'cSettings',
1345  $this->lng->txt('settings'),
1346  $this->ctrl->getLinkTarget($this,'cSettings')
1347  );
1348 
1349  }
1350  }
1351 }
1352 ?>