ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilObjectCopyGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
16 {
17  const SOURCE_SELECTION = 1;
18  const TARGET_SELECTION = 2;
19  const SEARCH_SOURCE = 3;
20 
21  const SUBMODE_COMPLETE = 1;
23 
24  // tabs
28 
29  // group selection of source or target
31 
32 
33  private $mode = 0;
34  private $sub_mode = self::SUBMODE_COMPLETE;
35 
36  private $lng;
37 
38  private $parent_obj = null;
39 
40  private $type = '';
41 
42  private $sources = array();
43 
44  // begin-patch multi copy
45  private $targets = array();
46  private $targets_copy_id = array();
47  // end-patch multi copy
48 
52  private $log = null;
53 
54 
59  public function __construct($a_parent_gui)
60  {
61  global $ilCtrl,$lng;
62 
63  $this->lng = $lng;
64  $this->lng->loadLanguageModule('search');
65  $this->lng->loadLanguageModule('obj');
66 
67  $this->parent_obj = $a_parent_gui;
68 
69  $this->log = ilLoggerFactory::getLogger('obj');
70  }
71 
76  public function executeCommand()
77  {
78  global $ilCtrl;
79 
80  $this->init();
81  $this->initTabs();
82 
83  $next_class = $ilCtrl->getNextClass($this);
84  $cmd = $ilCtrl->getCmd();
85 
86  switch($next_class)
87  {
88  default:
89  $this->$cmd();
90  break;
91  }
92  }
93 
98  protected function init()
99  {
100  global $ilCtrl;
101 
102  if((int) $_REQUEST['smode'])
103  {
104  $this->setSubMode((int) $_REQUEST['smode']);
105  $GLOBALS['ilCtrl']->setParameter($this,'smode',$this->getSubMode());
106  ilLoggerFactory::getLogger('obj')->debug('Submode is: '. $this->getSubMode());
107  }
108 
109  // save sources
110  if($_REQUEST['source_ids'])
111  {
112  $this->setSource(explode('_',$_REQUEST['source_ids']));
113  $GLOBALS['ilCtrl']->setParameter($this,'source_ids', implode('_', $this->getSources()));
114  ilLoggerFactory::getLogger('obj')->debug('Multiple sources: ' . implode('_',$this->getSources()));
115  }
116  if($_REQUEST['source_id'])
117  {
118  $this->setSource(array((int) $_REQUEST['source_id']));
119  $GLOBALS['ilCtrl']->setParameter($this,'source_ids', implode('_', $this->getSource()));
120  ilLoggerFactory::getLogger('obj')->debug('source_id is set: '. implode('_',$this->getSources()));
121  }
122  if($this->getFirstSource())
123  {
124  $this->setType(
126  );
127  }
128 
129  // creation screen: copy section
130  if($_REQUEST['new_type'])
131  {
132  $this->setMode(self::SEARCH_SOURCE);
133  $this->setType($_REQUEST['new_type']);
134  $this->setTarget((int) $_GET['ref_id']);
135 
136  $GLOBALS['ilCtrl']->setParameter($this, 'new_type', $this->getType());
137  $GLOBALS['ilCtrl']->setParameterByClass(get_class($this->getParentObject()),'new_type', $this->getType());
138  $GLOBALS['ilCtrl']->setParameterByClass(get_class($this->getParentObject()),'cpfl', 1);
139  $GLOBALS['ilCtrl']->setReturnByClass(get_class($this->getParentObject()),'create');
140 
141  ilLoggerFactory::getLogger('obj')->debug('Copy from object creation for type: '. $this->getType());
142  return TRUE;
143  }
144  // adopt content, and others?
145  elseif($_REQUEST['selectMode'] == self::SOURCE_SELECTION)
146  {
147  $this->setMode(self::SOURCE_SELECTION);
148 
149  $ilCtrl->setParameterByClass(get_class($this->parent_obj), 'selectMode', self::SOURCE_SELECTION);
150  $this->setTarget((int) $_GET['ref_id']);
151  $ilCtrl->setReturnByClass(get_class($this->parent_obj), '');
152 
153  ilLoggerFactory::getLogger('obj')->debug('Source selection mode. Target is: '. $this->getFirstTarget());
154  }
155  elseif($_REQUEST['selectMode'] == self::TARGET_SELECTION)
156  {
157  $this->setMode(self::TARGET_SELECTION);
158  $ilCtrl->setReturnByClass(get_class($this->parent_obj),'');
159  ilLoggerFactory::getLogger('obj')->debug('Target selection mode.');
160  }
161 
162 
163  // save targets
164  if($_REQUEST['target_ids'])
165  {
166  $this->setTargets(explode('_',$_REQUEST['target_ids']));
167  ilLoggerFactory::getLogger('obj')->debug('targets are: '. print_r($this->getTargets(),TRUE));
168  }
169 
170  }
171 
176  protected function initTabs()
177  {
178  $GLOBALS['lng']->loadLanguageModule('cntr');
179  $GLOBALS['ilTabs']->clearTargets();
180  $GLOBALS['ilTabs']->setBackTarget(
181  $GLOBALS['lng']->txt('tab_back_to_repository'),
182  $GLOBALS['ilCtrl']->getParentReturn($this->parent_obj)
183  );
184  }
185 
191  protected function setTabs($a_tab_group, $a_active_tab)
192  {
193  if($a_tab_group == self::TAB_GROUP_SC_SELECTION)
194  {
195  if($this->getSubMode() == self::SUBMODE_CONTENT_ONLY)
196  {
197  if($this->getMode() == self::SOURCE_SELECTION)
198  {
199  $GLOBALS['ilTabs']->addTab(
200  self::TAB_SELECTION_SOURCE_TREE,
201  $GLOBALS['lng']->txt('cntr_copy_repo_tree'),
202  $GLOBALS['ilCtrl']->getLinkTarget($this,'initSourceSelection')
203  );
204  $GLOBALS['ilTabs']->addTab(
205  self::TAB_SELECTION_MEMBERSHIP,
206  $GLOBALS['lng']->txt('cntr_copy_crs_grp'),
207  $GLOBALS['ilCtrl']->getLinkTarget($this,'showSourceSelectionMembership')
208  );
209  }
210  }
211  }
212  $GLOBALS['ilTabs']->activateTab($a_active_tab);
213  }
214 
215 
220  protected function adoptContent()
221  {
222  $GLOBALS['ilCtrl']->setParameter($this,'smode',self::SUBMODE_CONTENT_ONLY);
223  $GLOBALS['ilCtrl']->setParameter($this,'selectMode',self::SOURCE_SELECTION);
224 
225 
226  $this->setSubMode(self::SUBMODE_CONTENT_ONLY);
227  $this->setMode(self::SOURCE_SELECTION);
228  $this->setTarget((int) $_GET['ref_id']);
229 
230 
231  return $this->initSourceSelection();
232  }
233 
238  protected function initTargetSelection()
239  {
240  global $ilCtrl, $tree;
241  $ilCtrl->setParameter($this, 'selectMode', self::TARGET_SELECTION);
242  // empty session on init
243  $_SESSION['paste_copy_repexpand'] = array();
244 
245  // copy opened nodes from repository explorer
246  $_SESSION['paste_copy_repexpand'] = is_array($_SESSION['repexpand']) ? $_SESSION['repexpand'] : array();
247 
248  // begin-patch mc
249  $this->setTargets(array());
250  // cognos-blu-patch: end
251 
252  // open current position
253 
254  foreach($this->getSource() as $source_id)
255  {
256  if($source_id)
257  {
258  $path = $tree->getPathId($source_id);
259  foreach((array) $path as $node_id)
260  {
261  if(!in_array($node_id, $_SESSION['paste_copy_repexpand']))
262  {
263  $_SESSION['paste_copy_repexpand'][] = $node_id;
264  }
265  }
266 
267  }
268  }
269 
270  $ilCtrl->setReturnByClass(get_class($this->parent_obj),'');
271  $this->showTargetSelectionTree();
272  }
273 
278  protected function initSourceSelection()
279  {
280  global $ilCtrl,$tree;
281 
282  // empty session on init
283  $_SESSION['paste_copy_repexpand'] = array();
284 
285  // copy opened nodes from repository explorer
286  $_SESSION['paste_copy_repexpand'] = is_array($_SESSION['repexpand']) ? $_SESSION['repexpand'] : array();
287 
288  $this->setTabs(self::TAB_GROUP_SC_SELECTION, self::TAB_SELECTION_SOURCE_TREE);
289 
290 
291  // open current position
292  // begin-patch mc
293  foreach($this->getTargets() as $target_ref_id)
294  {
295  $path = $tree->getPathId($target_ref_id);
296  foreach((array) $path as $node_id)
297  {
298  if(!in_array($node_id, $_SESSION['paste_copy_repexpand']))
299  {
300  $_SESSION['paste_copy_repexpand'][] = $node_id;
301  }
302  }
303  }
304  // end-patch multi copy
305  $ilCtrl->setReturnByClass(get_class($this->parent_obj),'');
306  $this->showSourceSelectionTree();
307  }
308 
309 
313  protected function showSourceSelectionMembership()
314  {
315  ilUtil::sendInfo($this->lng->txt('msg_copy_clipboard_source'));
316  $this->setTabs(self::TAB_GROUP_SC_SELECTION, self::TAB_SELECTION_MEMBERSHIP);
317 
318  include_once './Services/Object/classes/class.ilObjectCopyCourseGroupSelectionTableGUI.php';
319  $cgs = new ilObjectCopyCourseGroupSelectionTableGUI($this, 'showSourceSelectionMembership','copy_selection_membership');
320  $cgs->init();
321  $cgs->setObjects(
322  array_merge(
323  ilParticipants::_getMembershipByType($GLOBALS['ilUser']->getId(), 'crs', FALSE),
324  ilParticipants::_getMembershipByType($GLOBALS['ilUser']->getId(), 'grp', FALSE)
325  )
326  );
327  $cgs->parse();
328 
329  $GLOBALS['tpl']->setContent($cgs->getHTML());
330  }
331 
332 
336  public function showTargetSelectionTree()
337  {
338  global $ilTabs, $ilToolbar, $ilCtrl, $tree, $tpl, $objDefinition, $lng;
339 
340  $this->tpl = $tpl;
341 
342  if($objDefinition->isContainer($this->getType()))
343  {
344  ilUtil::sendInfo($this->lng->txt('msg_copy_clipboard_container'));
345  }
346  else
347  {
348  ilUtil::sendInfo($this->lng->txt('msg_copy_clipboard'));
349  }
350 
351  //
352  include_once("./Services/Repository/classes/class.ilRepositorySelectorExplorerGUI.php");
353  $exp = new ilRepositorySelectorExplorerGUI($this, "showTargetSelectionTree");
354  $exp->setTypeWhiteList(array("root", "cat", "grp", "crs", "fold"));
355  // begin-patch mc
356  $exp->setSelectMode("target", TRUE);
357  // end-patch multi copy
358  if ($exp->handleCommand())
359  {
360  return;
361  }
362  $output = $exp->getHTML();
363 
364  // toolbars
365  $t = new ilToolbarGUI();
366  $t->setFormAction($ilCtrl->getFormAction($this, "saveTarget"));
367  if($objDefinition->isContainer($this->getType()))
368  {
369  $t->addFormButton($lng->txt("btn_next"), "saveTarget");
370  }
371  else
372  {
373  $t->addFormButton($lng->txt("paste"), "saveTarget");
374  }
375  $t->addSeparator();
376  $t->addFormButton($lng->txt("obj_insert_into_clipboard"), "keepObjectsInClipboard");
377  $t->addFormButton($lng->txt("cancel"), "cancel");
378  $t->setCloseFormTag(false);
379  $t->setLeadingImage(ilUtil::getImagePath("arrow_upright.svg"), " ");
380  $output = $t->getHTML().$output;
381  $t->setLeadingImage(ilUtil::getImagePath("arrow_downright.svg"), " ");
382  $t->setCloseFormTag(true);
383  $t->setOpenFormTag(false);
384  $output.= "<br />".$t->getHTML();
385 
386  $this->tpl->setContent($output);
387 
388  return;
389  }
390 
394  public function showSourceSelectionTree()
395  {
396  global $ilTabs, $ilToolbar, $ilCtrl, $tree, $tpl, $objDefinition;
397 
398  $this->tpl = $tpl;
399  $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.paste_into_multiple_objects.html',
400  "Services/Object");
401 
402  ilUtil::sendInfo($this->lng->txt('msg_copy_clipboard_source'));
403  include_once './Services/Object/classes/class.ilPasteIntoMultipleItemsExplorer.php';
406  'ilias.php?baseClass=ilRepositoryGUI&amp;cmd=goto', 'paste_copy_repexpand');
407  $exp->setRequiredFormItemPermission('visible,read,copy');
408 
409  $ilCtrl->setParameter($this, 'selectMode', self::SOURCE_SELECTION);
410  $exp->setExpandTarget($ilCtrl->getLinkTarget($this, 'showSourceSelectionTree'));
411  $exp->setTargetGet('ref_id');
412  $exp->setPostVar('source');
413  $exp->setCheckedItems($this->getSource());
414 
415  // Filter to container
416  foreach(array('cat','root','fold') as $container)
417  {
418  $exp->removeFormItemForType($container);
419  }
420 
421 
422  if($_GET['paste_copy_repexpand'] == '')
423  {
424  $expanded = $tree->readRootId();
425  }
426  else
427  {
428  $expanded = $_GET['paste_copy_repexpand'];
429  }
430 
431  $this->tpl->setVariable('FORM_TARGET', '_self');
432  $this->tpl->setVariable('FORM_ACTION', $ilCtrl->getFormAction($this, 'copySelection'));
433 
434  $exp->setExpand($expanded);
435  // build html-output
436  $exp->setOutput(0);
437  $output = $exp->getOutput();
438 
439  $this->tpl->setVariable('OBJECT_TREE', $output);
440 
441  $this->tpl->setVariable('CMD_SUBMIT', 'saveSource');
442  $this->tpl->setVariable('TXT_SUBMIT', $this->lng->txt('btn_next'));
443 
444  $ilToolbar->addButton($this->lng->txt('cancel'), $ilCtrl->getLinkTarget($this,'cancel'));
445  }
446 
451  protected function saveTarget()
452  {
453  global $objDefinition, $tree, $ilCtrl;
454 
455 
456  // begin-patch mc
457  if(is_array($_REQUEST['target']) and $_REQUEST['target'])
458  {
459  $this->setTargets($_REQUEST['target']);
460  $GLOBALS['ilCtrl']->setParameter($this,'target_ids', implode('_', $this->getTargets()));
461  }
462  // paste from clipboard
463  elseif((int) $_REQUEST['target'])
464  {
465  $this->setTarget($_REQUEST['target']);
466  $GLOBALS['ilCtrl']->setParameter($this,'target_ids', implode('_', $this->getTargets()));
467  }
468  // end-patch multi copy
469  else
470  {
471  $ilCtrl->setParameter($this, 'selectMode', self::TARGET_SELECTION);
472  ilUtil::sendFailure($this->lng->txt('select_one'));
473  $this->showTargetSelectionTree();
474  return false;
475  }
476 
477  // validate allowed subtypes
478  foreach($this->getSources() as $source_ref_id)
479  {
480  foreach((array) $this->getTargets() as $target_ref_id)
481  {
482  $target_type = ilObject::_lookupType($target_ref_id, TRUE);
483  $target_class_name = ilObjectFactory::getClassByType($target_type);
484  $target_object = new $target_class_name($target_ref_id);
485  $possible_subtypes = $target_object->getPossibleSubObjects();
486 
487  $source_type = ilObject::_lookupType($source_ref_id, TRUE);
488 
489  if(!array_key_exists($source_type, (array) $possible_subtypes))
490  {
492  sprintf(
493  $this->lng->txt('msg_obj_may_not_contain_objects_of_type'),
494  $this->lng->txt('obj_'.$target_type),
495  $this->lng->txt('obj_'.$source_type))
496  );
497  $this->showTargetSelectionTree();
498  return FALSE;
499  }
500  }
501  }
502 
503  if(count($this->getSource() == 1) && $objDefinition->isContainer($this->getType()))
504  {
505  // check, if object should be copied into itself
506  // begin-patch mc
507  $is_child = array();
508  foreach($this->getTargets() as $target_ref_id)
509  {
510  if ($tree->isGrandChild($this->getFirstSource(), $target_ref_id))
511  {
513  }
514  if ($this->getFirstSource() == $target_ref_id)
515  {
517  }
518  }
519  // end-patch multi copy
520  if (count($is_child) > 0)
521  {
522  ilUtil::sendFailure($this->lng->txt("msg_not_in_itself")." ".implode(',',$is_child));
523  $this->showTargetSelectionTree();
524  return false;
525  }
526 
527  $this->showItemSelection();
528  }
529  else
530  {
531  if(count($this->getSource()) == 1)
532  {
533  $this->copySingleObject();
534  }
535  else
536  {
537  $this->copyMultipleNonContainer($this->getSource());
538  }
539  }
540  }
541 
547  public function setMode($a_mode)
548  {
549  $this->mode = $a_mode;
550  }
551 
556  public function getMode()
557  {
558  return $this->mode;
559  }
560 
561  public function setSubMode($a_mode)
562  {
563  $this->sub_mode = $a_mode;
564  }
565 
566  public function getSubMode()
567  {
568  return $this->sub_mode;
569  }
570 
575  public function getParentObject()
576  {
577  return $this->parent_obj;
578  }
579 
585  public function getType()
586  {
587  return $this->type;
588  }
589 
596  public function setType($type)
597  {
598  $this->type = $type;
599  }
600 
606  public function setSource(array $a_source_ids)
607  {
608  $this->sources = $a_source_ids;
609  }
610 
616  public function getSource()
617  {
618  return $this->getSources();
619  }
620 
625  public function getSources()
626  {
627  return (array) $this->sources;
628  }
629 
630  public function getFirstSource()
631  {
632  if(count($this->sources))
633  {
634  return $this->sources[0];
635  }
636  return 0;
637  }
638 
639  // begin-patch mc
640 
645  public function setTarget($a_ref_id)
646  {
647  $this->setTargets(array($a_ref_id));
648  }
649 
650 
656  public function setTargets(array $a_target)
657  {
658  $this->targets = $a_target;
659  }
660 
665  public function getTargets()
666  {
667  return (array) $this->targets;
668  }
669 
674  public function getFirstTarget()
675  {
676  if(array_key_exists(0, $this->getTargets()))
677  {
678  $targets = $this->getTargets();
679  return $targets[0];
680  }
681  return 0;
682  }
683  // end-patch multi copy
684 
688  protected function cancel()
689  {
690  global $ilCtrl;
691  $ilCtrl->setReturnByClass(get_class($this->parent_obj),'cancel');
692  $ilCtrl->returnToParent($this);
693  }
694 
699  {
700  global $ilCtrl;
701  $_SESSION['clipboard']['cmd'] = "copy";
702  $_SESSION['clipboard']['ref_ids'] = $this->getSource();
703  $ilCtrl->returnToParent($this);
704  }
705 
706 
711  protected function searchSource()
712  {
713  global $tree,$ilObjDataCache,$lng,$ilCtrl,$tpl;
714 
715  if(isset($_POST['tit']))
716  {
717  ilUtil::sendInfo($this->lng->txt('wizard_search_list'));
718  $_SESSION['source_query'] = $_POST['tit'];
719  }
720  else
721  {
722  $_POST['tit'] = $_SESSION['source_query'];
723  }
724 
725  $this->initFormSearch();
726  $this->form->setValuesByPost();
727 
728  if(!$this->form->checkInput())
729  {
730  ilUtil::sendFailure($lng->txt('msg_no_search_string'),true);
731  $ilCtrl->returnToParent($this);
732  return false;
733  }
734 
735  include_once './Services/Search/classes/class.ilQueryParser.php';
736  $query_parser = new ilQueryParser($this->form->getInput('tit'));
737  $query_parser->setMinWordLength(1,true);
738  $query_parser->setCombination(QP_COMBINATION_AND);
739  $query_parser->parse();
740  if(!$query_parser->validate())
741  {
742  ilUtil::sendFailure($query_parser->getMessage(),true);
743  $ilCtrl->returnToParent($this);
744  }
745 
746  // only like search since fulltext does not support search with less than 3 characters
747  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
748  $object_search = new ilLikeObjectSearch($query_parser);
749  $object_search->setFilter(array($_REQUEST['new_type']));
750  $res = $object_search->performSearch();
751  $res->setRequiredPermission('copy');
752  $res->filter(ROOT_FOLDER_ID,true);
753 
754  if(!count($results = $res->getResultsByObjId()))
755  {
756  ilUtil::sendFailure($this->lng->txt('search_no_match'),true);
757  $ilCtrl->returnToParent($this);
758  }
759 
760 
761  include_once './Services/Object/classes/class.ilObjectCopySearchResultTableGUI.php';
762  $table = new ilObjectCopySearchResultTableGUI($this,'searchSource',$this->getType());
763  $table->setFormAction($GLOBALS['ilCtrl']->getFormAction($this));
764  $table->setSelectedReference($this->getFirstSource());
765  $table->parseSearchResults($results);
766  $tpl->setContent($table->getHTML());
767  }
768 
773  protected function saveSource()
774  {
775  global $objDefinition;
776 
777  if(isset($_POST['source']))
778  {
779  $this->setSource(array((int) $_REQUEST['source']));
780  $this->setType(ilObject::_lookupType((int) $_REQUEST['source'], TRUE));
781  $GLOBALS['ilCtrl']->setParameter($this,'source_id',(int) $_REQUEST['source']);
782  }
783  else
784  {
785  ilUtil::sendFailure($this->lng->txt('select_one'));
786  $this->searchSource();
787  return false;
788  }
789 
790  // validate allowed subtypes
791  foreach($this->getSources() as $source_ref_id)
792  {
793  foreach((array) $this->getTargets() as $target_ref_id)
794  {
795  $target_type = ilObject::_lookupType($target_ref_id, TRUE);
796  $target_class_name = ilObjectFactory::getClassByType($target_type);
797  $target_object = new $target_class_name($target_ref_id);
798  $possible_subtypes = $target_object->getPossibleSubObjects();
799 
800  $source_type = ilObject::_lookupType($source_ref_id, TRUE);
801 
802  if(!array_key_exists($source_type, $possible_subtypes))
803  {
804  #ilLoggerFactory::getLogger('obj')->debug('Source type: '. $source_type);
805  #ilLoggerFactory::getLogger('obj')->debug('Target type: '. $target_type);
806  #ilLoggerFactory::getLogger('obj')->debug('Submode: '. $this->getSubMode());
807 
808  // adopt content mode
809  if(
810  $this->getSubMode() != self::SUBMODE_CONTENT_ONLY and
811  ($source_type != 'crs' or $target_type != 'crs')
812  )
813  {
815  sprintf(
816  $this->lng->txt('msg_obj_may_not_contain_objects_of_type'),
817  $this->lng->txt('obj_'.$target_type),
818  $this->lng->txt('obj_'.$source_type))
819  );
820  $this->searchSource();
821  return FALSE;
822 
823  }
824  }
825  }
826  }
827 
828 
829  if($objDefinition->isContainer($this->getType()))
830  {
831  $this->showItemSelection();
832  }
833  else
834  {
835  $this->copySingleObject();
836  }
837  }
838 
842  protected function saveSourceMembership()
843  {
844  global $objDefinition;
845 
846  if(!isset($_REQUEST['source']))
847  {
848  ilUtil::sendFailure($this->lng->txt('select_one'));
849  $GLOBALS['ilCtrl']->redirect($this,'showSourceSelectionMembership');
850  return FALSE;
851  }
852 
853  $this->setSource(array((int) $_REQUEST['source']));
854  $this->setType(ilObject::_lookupType((int) $this->getFirstSource(), TRUE));
855  $GLOBALS['ilCtrl']->setParameter($this,'source_id',(int) $_REQUEST['source']);
856 
857  if($objDefinition->isContainer($this->getType()))
858  {
859  $this->showItemSelection();
860  }
861  else
862  {
863  $this->copySingleObject();
864  }
865  }
866 
871  protected function showItemSelection()
872  {
873  global $tpl;
874 
875  if(!count($this->getSource()))
876  {
877  ilUtil::sendFailure($this->lng->txt('select_one'));
878  $this->searchSource();
879  return false;
880  }
881 
882  ilLoggerFactory::getLogger('obj')->debug('Source(s): '. print_r($this->getSources(),TRUE));
883  ilLoggerFactory::getLogger('obj')->debug('Target(s): '. print_r($this->getTargets(),TRUE));
884 
885  ilUtil::sendInfo($this->lng->txt($this->getType().'_copy_threads_info'));
886  include_once './Services/Object/classes/class.ilObjectCopySelectionTableGUI.php';
887 
888  $tpl->addJavaScript('./Services/CopyWizard/js/ilContainer.js');
889  $tpl->setVariable('BODY_ATTRIBUTES','onload="ilDisableChilds(\'cmd\');"');
890 
891  switch($this->getMode())
892  {
893  case self::SOURCE_SELECTION:
894  $back_cmd = 'showSourceSelectionTree';
895  break;
896 
897  case self::TARGET_SELECTION:
898  $back_cmd = 'showTargetSelectionTree';
899  break;
900 
901  case self::SEARCH_SOURCE:
902  $back_cmd = 'searchSource';
903  break;
904  }
905 
906  $table = new ilObjectCopySelectionTableGUI($this,'showItemSelection',$this->getType(),$back_cmd);
907  $table->parseSource($this->getFirstSource());
908 
909  $tpl->setContent($table->getHTML());
910  }
911 
916  protected function copySingleObject()
917  {
918  include_once('./Services/Link/classes/class.ilLink.php');
919  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
920 
921  global $ilAccess,$ilErr,$rbacsystem,$ilUser,$ilCtrl,$rbacreview;
922 
923  // Source defined
924  if(!count($this->getSource()))
925  {
926  ilUtil::sendFailure($this->lng->txt('select_one'),true);
927  $ilCtrl->returnToParent($this);
928  }
929 
930  $this->copyMultipleNonContainer($this->getSource());
931  return;
932  }
933 
939  function copyMultipleNonContainer($a_sources)
940  {
941  global $ilAccess,$objDefinition,$rbacsystem,$ilUser,$ilCtrl,$rbacreview;
942 
943 
944  include_once('./Services/Link/classes/class.ilLink.php');
945  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
946 
947  // check permissions
948  foreach ($a_sources as $source_ref_id)
949  {
950  $source_type = ilObject::_lookupType($source_ref_id, true);
951 
952  // Create permission
953  // begin-patch mc
954  foreach($this->getTargets() as $target_ref_id)
955  {
956  if(!$rbacsystem->checkAccess('create', $target_ref_id, $source_type))
957  {
958  $this->log->notice('Permission denied for target_id: ' . $target_ref_id.' source_type: ' . $source_type.' CREATE');
959  ilUtil::sendFailure($this->lng->txt('permission_denied'),true);
960  $ilCtrl->returnToParent($this);
961  }
962  }
963 
964  // Copy permission
965  if(!$ilAccess->checkAccess('copy','',$source_ref_id))
966  {
967  $this->log->notice('Permission denied for source_ref_id: ' . $source_ref_id.' COPY');
968  ilUtil::sendFailure($this->lng->txt('permission_denied'),true);
969  $ilCtrl->returnToParent($this);
970  }
971 
972  // check that these objects are really not containers
973  if($objDefinition->isContainer($source_type) and $this->getSubMode() != self::SUBMODE_CONTENT_ONLY)
974  {
975  ilUtil::sendFailure($this->lng->txt('cntr_container_only_on_their_own'),true);
976  $ilCtrl->returnToParent($this);
977  }
978  }
979 
980  reset($a_sources);
981 
982 
983  ilLoggerFactory::getLogger('obj')->debug('Copy multiple non containers. Sources: ' . print_r($a_sources,TRUE));
984 
985  // clone
986  foreach ($a_sources as $source_ref_id)
987  {
988  ilLoggerFactory::getLogger('obj')->debug('Copying source ref_id : ' . $source_ref_id);
989 
990  // begin-patch mc
991  foreach($this->getTargets() as $target_ref_id)
992  {
993  // Save wizard options
995  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
996  $wizard_options->saveOwner($ilUser->getId());
997  $wizard_options->saveRoot((int) $source_ref_id);
998  $wizard_options->read();
999 
1000  $orig = ilObjectFactory::getInstanceByRefId((int) $source_ref_id);
1001  $new_obj = $orig->cloneObject($target_ref_id,$copy_id);
1002 
1003  // Delete wizard options
1004  $wizard_options->deleteAll();
1005 
1006  // rbac log
1007  include_once "Services/AccessControl/classes/class.ilRbacLog.php";
1008  if(ilRbacLog::isActive())
1009  {
1010  $rbac_log_roles = $rbacreview->getParentRoleIds($new_obj->getRefId(), false);
1011  $rbac_log = ilRbacLog::gatherFaPa($new_obj->getRefId(), array_keys($rbac_log_roles), true);
1012  ilRbacLog::add(ilRbacLog::COPY_OBJECT, $new_obj->getRefId(), $rbac_log, (int)$source_ref_id);
1013  }
1014  }
1015  }
1016 
1017  unset($_SESSION["clipboard"]["ref_ids"]);
1018  unset($_SESSION["clipboard"]["cmd"]);
1019 
1020  if (count($a_sources) == 1)
1021  {
1022  ilLoggerFactory::getLogger('obj')->info('Object copy completed.');
1023  ilUtil::sendSuccess($this->lng->txt("object_duplicated"),true);
1024  ilUtil::redirect(ilLink::_getLink($new_obj->getRefId()));
1025  }
1026  else
1027  {
1028  ilLoggerFactory::getLogger('obj')->info('Object copy completed.');
1029  ilUtil::sendSuccess($this->lng->txt("objects_duplicated"),true);
1031  }
1032 
1033  }
1034 
1038  protected function copyContainerToTargets()
1039  {
1040  global $ilCtrl;
1041 
1042  ilLoggerFactory::getLogger('obj')->debug('Copy container to targets: '. print_r($_REQUEST,TRUE));
1043  ilLoggerFactory::getLogger('obj')->debug('Source(s): '. print_r($this->getSources(),TRUE));
1044  ilLoggerFactory::getLogger('obj')->debug('Target(s): '. print_r($this->getTargets(),TRUE));
1045 
1046 
1047  $last_target = 0;
1048  $result = 1;
1049  foreach($this->getTargets() as $target_ref_id)
1050  {
1051  $result = $this->copyContainer($target_ref_id);
1052  $last_target = $target_ref_id;
1053  }
1054 
1055  unset($_SESSION["clipboard"]["ref_ids"]);
1056  unset($_SESSION["clipboard"]["cmd"]);
1057 
1058  include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
1060  {
1061  ilLoggerFactory::getLogger('obj')->info('Object copy completed.');
1062  ilUtil::sendSuccess($this->lng->txt("object_duplicated"),true);
1063  $ilCtrl->setParameterByClass(
1064  "ilrepositorygui",
1065  "ref_id",
1066  $result['ref_id']
1067  );
1068  $ilCtrl->redirectByClass("ilrepositorygui", "");
1069  }
1070  else
1071  {
1072  // show progress
1073  ilLoggerFactory::getLogger('obj')->debug('Object copy in progress.');
1074  return $this->showCopyProgress();
1075  }
1076  }
1077 
1081  protected function showCopyProgress()
1082  {
1083  include_once './Services/Object/classes/class.ilObjectCopyProgressTableGUI.php';
1084  $progress = new ilObjectCopyProgressTableGUI(
1085  $this,
1086  'showCopyProgress',
1087  (int) $_GET['ref_id']
1088  );
1089  $progress->setObjectInfo($this->targets_copy_id);
1090  $progress->parse();
1091  $progress->init();
1092  $progress->setRedirectionUrl($GLOBALS['ilCtrl']->getParentReturn($this->parent_obj));
1093 
1094  $GLOBALS['tpl']->setContent($progress->getHTML());
1095  }
1096 
1100  protected function updateProgress()
1101  {
1102  $json = new stdClass();
1103  $json->percentage = null;
1104  $json->performed_steps = null;
1105 
1106  include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
1107  $options = ilCopyWizardOptions::_getInstance((int) $_REQUEST['copy_id']);
1108  $json->required_steps = $options->getRequiredSteps();
1109  $json->id = (int) $_REQUEST['copy_id'];
1110 
1111  ilLoggerFactory::getLogger('obj')->debug('Update copy progress: '. json_encode($json));
1112 
1113  echo json_encode($json);
1114  exit;
1115  }
1116 
1117 
1122  protected function copyContainer($a_target)
1123  {
1124  global $ilLog, $ilCtrl;
1125 
1126  include_once('./Services/Link/classes/class.ilLink.php');
1127  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
1128 
1129  global $ilAccess,$ilErr,$rbacsystem,$tree,$ilUser,$ilCtrl;
1130 
1131  // Workaround for course in course copy
1132 
1135 
1136  if($this->getSubMode() != self::SUBMODE_CONTENT_ONLY)
1137  {
1138  if(!$rbacsystem->checkAccess('create', $a_target,$this->getType()))
1139  {
1140  $this->log->notice('Permission denied for target: '. $a_target.' type: ' . $this->getType().' CREATE');
1141  ilUtil::sendFailure($this->lng->txt('permission_denied'),true);
1142  $ilCtrl->returnToParent($this);
1143  }
1144  }
1145  if(!$this->getFirstSource())
1146  {
1147  ilUtil::sendFailure($this->lng->txt('select_one'),true);
1148  $ilCtrl->returnToParent($this);
1149  return false;
1150  }
1151 
1152  $options = $_POST['cp_options'] ? $_POST['cp_options'] : array();
1153 
1154 
1155  ilLoggerFactory::getLogger('obj')->debug('Copy container (sources): '. print_r($this->getSources(),TRUE));
1156 
1158  $result = $orig->cloneAllObject(
1159  $_COOKIE['PHPSESSID'],
1160  $_COOKIE['ilClientId'],
1161  $this->getType(),
1162  $a_target,
1163  $this->getFirstSource(),
1164  $options,
1165  FALSE,
1166  $this->getSubMode()
1167  );
1168 
1169  $this->targets_copy_id[$a_target] = $result['copy_id'];
1170 
1171  return $result;
1172  }
1173 
1174 
1175 
1183  public function showSourceSearch($a_tplvar)
1184  {
1185  global $tpl;
1186 
1187  // Disabled for performance
1188  #if(!$this->sourceExists())
1189  #{
1190  # return false;
1191  #}
1192 
1193  $this->unsetSession();
1194  $this->initFormSearch();
1195 
1196  if($a_tplvar)
1197  {
1198  $tpl->setVariable($a_tplvar,$this->form->getHTML());
1199  }
1200  else
1201  {
1202  return $this->form;
1203  }
1204  }
1205 
1206 
1211  protected function sourceExists()
1212  {
1213  global $ilUser;
1214 
1215  return (bool) ilUtil::_getObjectsByOperations($this->getType(),'copy',$ilUser->getId(),1);
1216  }
1217 
1222  protected function initFormSearch()
1223  {
1224  global $lng,$ilCtrl;
1225 
1226  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1227  $this->form = new ilPropertyFormGUI();
1228  $this->form->setTableWidth('600px');
1229 
1230  $ilCtrl->setParameter($this,'new_type',$this->getType());
1231 
1232  #$ilCtrl->setParameter($this, 'cp_mode', self::SOURCE_SELECTION);
1233  $this->form->setFormAction($ilCtrl->getFormAction($this));
1234  $this->form->setTitle($lng->txt($this->getType().'_copy'));
1235 
1236  $this->form->addCommandButton('searchSource', $lng->txt('btn_next'));
1237  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
1238 
1239  $tit = new ilTextInputGUI($lng->txt('title'),'tit');
1240  $tit->setSize(40);
1241  $tit->setMaxLength(70);
1242  $tit->setRequired(true);
1243  $tit->setInfo($lng->txt('wizard_title_info'));
1244  $this->form->addItem($tit);
1245  }
1246 
1251  protected function unsetSession()
1252  {
1253  unset($_SESSION['source_query']);
1254  $this->setSource(array());
1255  }
1256 }
1257 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static getClassByType($a_obj_type)
Get class by type.
global $ilErr
Definition: raiseError.php:16
getSources()
Get sources.
$path
Definition: aliased.php:25
adoptContent()
Adopt content (crs in crs, grp in grp, crs in grp or grp in crs)
setTargets(array $a_target)
Set target id.
__construct($a_parent_gui)
Constructor.
updateProgress()
Update progress.
$_SESSION["AccountId"]
$target_type
Definition: goto.php:50
Explorer for selecting repository items.
$result
This class represents a property form user interface.
GUI class for the workflow of copying objects.
setMode($a_mode)
set copy mode
initSourceSelection()
Init source selection.
init()
Init return, mode.
$_GET["client_id"]
initTargetSelection()
Init copy from repository/search list commands.
saveSource()
select source object
setTarget($a_ref_id)
Set single object target.
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
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, instead it parses the serialized rbac_pa entries.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$cmd
Definition: sahs_server.php:35
initFormSearch()
Init search form.
keepObjectsInClipboard()
Keep objects in clipboard.
showCopyProgress()
Show progress for copying.
copyContainer($a_target)
Copy a container.
static _lookupTitle($a_id)
lookup object title
saveSourceMembership()
Save selected source from membership screen.
static isActive()
getFirstTarget()
Get first target.
getType()
Returns $type.
getSource()
Get source id.
setSource(array $a_source_ids)
Set source id.
static gatherFaPa($a_ref_id, array $a_role_ids, $a_add_action=false)
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static _isFinished($a_copy_id)
check if copy is finished
initTabs()
Init tabs General.
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
getParentObject()
Get parent gui object.
getMode()
get copy mode
static _getInstance($a_copy_id)
Get instance of copy wizard options.
cancel()
Cancel workflow.
if(!is_array($argv)) $options
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static _lookupObjId($a_id)
setSize($a_size)
Set Size.
unsetSession()
Unset session variables.
This class represents a text property in a property form.
const COPY_OBJECT
$ilUser
Definition: imgupload.php:18
static _allocateCopyId()
Allocate a copy for further entries.
setTabs($a_tab_group, $a_active_tab)
Set tabs.
copySingleObject()
Start cloning a single (not container) object.
getTargets()
Get copy target.
$results
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
executeCommand()
Control class handling.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
showTargetSelectionTree()
Show target selection.
showSourceSelectionTree()
Show target selection.
copyContainerToTargets()
Copy to multiple targets.
copyMultipleNonContainer($a_sources)
Copy multiple non container.
static add($a_action, $a_ref_id, array $a_diff, $a_source_ref_id=false)
$_COOKIE['ilClientId']
Definition: BPMN2Parser.php:15
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static getLogger($a_component_id)
Get component logger.
const QP_COMBINATION_AND
saveTarget()
Save target selection.
setMinWordLength($a_length, $a_force=false)
sourceExists()
Check if there is any source object.
showSourceSearch($a_tplvar)
Show init screen Normally shown below the create and import form when creating a new object...
static redirect($a_script)
http redirect to other script
showSourceSelectionMembership()
show target selection membership
searchSource()
Search source.
$_POST["username"]
setType($type)
Sets $type.