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