ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
20  protected $ctrl;
21 
25  protected $tree;
26 
30  protected $tabs;
31 
35  protected $toolbar;
36 
40  protected $tpl;
41 
45  protected $obj_definition;
46 
50  protected $obj_data_cache;
51 
55  protected $access;
56 
60  protected $error;
61 
65  protected $rbacsystem;
66 
70  protected $user;
71 
75  protected $rbacreview;
76 
77  const SOURCE_SELECTION = 1;
78  const TARGET_SELECTION = 2;
79  const SEARCH_SOURCE = 3;
80 
81  const SUBMODE_COMPLETE = 1;
83 
84  // tabs
88 
89  // group selection of source or target
91 
92 
93  private $mode = 0;
94  private $sub_mode = self::SUBMODE_COMPLETE;
95 
96  private $lng;
97 
98  private $parent_obj = null;
99 
100  private $type = '';
101 
102  private $sources = array();
103 
104  // begin-patch multi copy
105  private $targets = array();
106  private $targets_copy_id = array();
107  // end-patch multi copy
108 
112  private $log = null;
113 
114 
119  public function __construct($a_parent_gui)
120  {
121  global $DIC;
122 
123  $this->ctrl = $DIC->ctrl();
124  $this->tree = $DIC->repositoryTree();
125  $this->tabs = $DIC->tabs();
126  $this->toolbar = $DIC->toolbar();
127  $this->tpl = $DIC["tpl"];
128  $this->obj_definition = $DIC["objDefinition"];
129  $this->obj_data_cache = $DIC["ilObjDataCache"];
130  $this->access = $DIC->access();
131  $this->error = $DIC["ilErr"];
132  $this->rbacsystem = $DIC->rbac()->system();
133  $this->user = $DIC->user();
134  $this->rbacreview = $DIC->rbac()->review();
135  $this->log = $DIC["ilLog"];
136  $ilCtrl = $DIC->ctrl();
137  $lng = $DIC->language();
138 
139  $this->lng = $lng;
140  $this->lng->loadLanguageModule('search');
141  $this->lng->loadLanguageModule('obj');
142 
143  $this->parent_obj = $a_parent_gui;
144 
145  $this->log = ilLoggerFactory::getLogger('obj');
146  }
147 
152  public function executeCommand()
153  {
155 
156  $this->init();
157  $this->initTabs();
158 
159  $next_class = $ilCtrl->getNextClass($this);
160  $cmd = $ilCtrl->getCmd();
161 
162  switch ($next_class) {
163  default:
164  $this->$cmd();
165  break;
166  }
167  }
168 
173  protected function init()
174  {
176 
177  if ((int) $_REQUEST['smode']) {
178  $this->setSubMode((int) $_REQUEST['smode']);
179  $GLOBALS['ilCtrl']->setParameter($this, 'smode', $this->getSubMode());
180  ilLoggerFactory::getLogger('obj')->debug('Submode is: ' . $this->getSubMode());
181  }
182 
183  // save sources
184  if ($_REQUEST['source_ids']) {
185  $this->setSource(explode('_', $_REQUEST['source_ids']));
186  $GLOBALS['ilCtrl']->setParameter($this, 'source_ids', implode('_', $this->getSources()));
187  ilLoggerFactory::getLogger('obj')->debug('Multiple sources: ' . implode('_', $this->getSources()));
188  }
189  if ($_REQUEST['source_id']) {
190  $this->setSource(array((int) $_REQUEST['source_id']));
191  $GLOBALS['ilCtrl']->setParameter($this, 'source_ids', implode('_', $this->getSources()));
192  ilLoggerFactory::getLogger('obj')->debug('source_id is set: ' . implode('_', $this->getSources()));
193  }
194  if ($this->getFirstSource()) {
195  $this->setType(
197  );
198  }
199 
200  // creation screen: copy section
201  if ($_REQUEST['new_type']) {
202  $this->setMode(self::SEARCH_SOURCE);
203  $this->setType($_REQUEST['new_type']);
204  $this->setTarget((int) $_GET['ref_id']);
205 
206  $GLOBALS['ilCtrl']->setParameter($this, 'new_type', $this->getType());
207  $GLOBALS['ilCtrl']->setParameterByClass(get_class($this->getParentObject()), 'new_type', $this->getType());
208  $GLOBALS['ilCtrl']->setParameterByClass(get_class($this->getParentObject()), 'cpfl', 1);
209  $GLOBALS['ilCtrl']->setReturnByClass(get_class($this->getParentObject()), 'create');
210 
211  ilLoggerFactory::getLogger('obj')->debug('Copy from object creation for type: ' . $this->getType());
212  return true;
213  }
214  // adopt content, and others?
215  elseif ($_REQUEST['selectMode'] == self::SOURCE_SELECTION) {
216  $this->setMode(self::SOURCE_SELECTION);
217 
218  $ilCtrl->setParameterByClass(get_class($this->parent_obj), 'selectMode', self::SOURCE_SELECTION);
219  $this->setTarget((int) $_GET['ref_id']);
220  $ilCtrl->setReturnByClass(get_class($this->parent_obj), '');
221 
222  ilLoggerFactory::getLogger('obj')->debug('Source selection mode. Target is: ' . $this->getFirstTarget());
223  } elseif ($_REQUEST['selectMode'] == self::TARGET_SELECTION) {
224  $this->setMode(self::TARGET_SELECTION);
225  $ilCtrl->setReturnByClass(get_class($this->parent_obj), '');
226  ilLoggerFactory::getLogger('obj')->debug('Target selection mode.');
227  }
228 
229 
230  // save targets
231  if ($_REQUEST['target_ids']) {
232  $this->setTargets(explode('_', $_REQUEST['target_ids']));
233  ilLoggerFactory::getLogger('obj')->debug('targets are: ' . print_r($this->getTargets(), true));
234  }
235  }
236 
241  protected function initTabs()
242  {
243  $GLOBALS['lng']->loadLanguageModule('cntr');
244  $GLOBALS['ilTabs']->clearTargets();
245  $GLOBALS['ilTabs']->setBackTarget(
246  $GLOBALS['lng']->txt('tab_back_to_repository'),
247  $GLOBALS['ilCtrl']->getParentReturn($this->parent_obj)
248  );
249  }
250 
256  protected function setTabs($a_tab_group, $a_active_tab)
257  {
258  if ($a_tab_group == self::TAB_GROUP_SC_SELECTION) {
259  if ($this->getSubMode() == self::SUBMODE_CONTENT_ONLY) {
260  if ($this->getMode() == self::SOURCE_SELECTION) {
261  $GLOBALS['ilTabs']->addTab(
262  self::TAB_SELECTION_SOURCE_TREE,
263  $GLOBALS['lng']->txt('cntr_copy_repo_tree'),
264  $GLOBALS['ilCtrl']->getLinkTarget($this, 'initSourceSelection')
265  );
266  $GLOBALS['ilTabs']->addTab(
267  self::TAB_SELECTION_MEMBERSHIP,
268  $GLOBALS['lng']->txt('cntr_copy_crs_grp'),
269  $GLOBALS['ilCtrl']->getLinkTarget($this, 'showSourceSelectionMembership')
270  );
271  }
272  }
273  }
274  $GLOBALS['ilTabs']->activateTab($a_active_tab);
275  }
276 
277 
282  protected function adoptContent()
283  {
284  $GLOBALS['ilCtrl']->setParameter($this, 'smode', self::SUBMODE_CONTENT_ONLY);
285  $GLOBALS['ilCtrl']->setParameter($this, 'selectMode', self::SOURCE_SELECTION);
286 
287 
288  $this->setSubMode(self::SUBMODE_CONTENT_ONLY);
289  $this->setMode(self::SOURCE_SELECTION);
290  $this->setTarget((int) $_GET['ref_id']);
291 
292 
293  return $this->initSourceSelection();
294  }
295 
300  protected function initTargetSelection()
301  {
303  $tree = $this->tree;
304  $ilCtrl->setParameter($this, 'selectMode', self::TARGET_SELECTION);
305  // empty session on init
306  $_SESSION['paste_copy_repexpand'] = array();
307 
308  // copy opened nodes from repository explorer
309  $_SESSION['paste_copy_repexpand'] = is_array($_SESSION['repexpand']) ? $_SESSION['repexpand'] : array();
310 
311  // begin-patch mc
312  $this->setTargets(array());
313  // cognos-blu-patch: end
314 
315  // open current position
316 
317  foreach ($this->getSources() as $source_id) {
318  if ($source_id) {
319  $path = $tree->getPathId($source_id);
320  foreach ((array) $path as $node_id) {
321  if (!in_array($node_id, $_SESSION['paste_copy_repexpand'])) {
322  $_SESSION['paste_copy_repexpand'][] = $node_id;
323  }
324  }
325  }
326  }
327 
328  $ilCtrl->setReturnByClass(get_class($this->parent_obj), '');
329  $this->showTargetSelectionTree();
330  }
331 
336  protected function initSourceSelection()
337  {
339  $tree = $this->tree;
340 
341  // empty session on init
342  $_SESSION['paste_copy_repexpand'] = array();
343 
344  // copy opened nodes from repository explorer
345  $_SESSION['paste_copy_repexpand'] = is_array($_SESSION['repexpand']) ? $_SESSION['repexpand'] : array();
346 
347  $this->setTabs(self::TAB_GROUP_SC_SELECTION, self::TAB_SELECTION_SOURCE_TREE);
348 
349 
350  // open current position
351  // begin-patch mc
352  foreach ($this->getTargets() as $target_ref_id) {
353  $path = $tree->getPathId($target_ref_id);
354  foreach ((array) $path as $node_id) {
355  if (!in_array($node_id, $_SESSION['paste_copy_repexpand'])) {
356  $_SESSION['paste_copy_repexpand'][] = $node_id;
357  }
358  }
359  }
360  // end-patch multi copy
361  $ilCtrl->setReturnByClass(get_class($this->parent_obj), '');
362  $this->showSourceSelectionTree();
363  }
364 
365 
369  protected function showSourceSelectionMembership()
370  {
371  ilUtil::sendInfo($this->lng->txt('msg_copy_clipboard_source'));
372  $this->setTabs(self::TAB_GROUP_SC_SELECTION, self::TAB_SELECTION_MEMBERSHIP);
373 
374  include_once './Services/Object/classes/class.ilObjectCopyCourseGroupSelectionTableGUI.php';
375  $cgs = new ilObjectCopyCourseGroupSelectionTableGUI($this, 'showSourceSelectionMembership', 'copy_selection_membership');
376  $cgs->init();
377  $cgs->setObjects(
378  array_merge(
379  ilParticipants::_getMembershipByType($GLOBALS['ilUser']->getId(), 'crs', false),
380  ilParticipants::_getMembershipByType($GLOBALS['ilUser']->getId(), 'grp', false)
381  )
382  );
383  $cgs->parse();
384 
385  $GLOBALS['tpl']->setContent($cgs->getHTML());
386  }
387 
388 
392  public function showTargetSelectionTree()
393  {
394  $ilTabs = $this->tabs;
395  $ilToolbar = $this->toolbar;
397  $tree = $this->tree;
398  $tpl = $this->tpl;
399  $objDefinition = $this->obj_definition;
400  $lng = $this->lng;
401 
402  $this->tpl = $tpl;
403 
404  if ($objDefinition->isContainer($this->getType())) {
405  ilUtil::sendInfo($this->lng->txt('msg_copy_clipboard_container'));
406  } else {
407  ilUtil::sendInfo($this->lng->txt('msg_copy_clipboard'));
408  }
409 
410  //
411  include_once("./Services/Repository/classes/class.ilRepositorySelectorExplorerGUI.php");
412  $exp = new ilRepositorySelectorExplorerGUI($this, "showTargetSelectionTree");
413  $exp->setTypeWhiteList(array("root", "cat", "grp", "crs", "fold"));
414  // begin-patch mc
415  $exp->setSelectMode("target", true);
416  // end-patch multi copy
417  if ($exp->handleCommand()) {
418  return;
419  }
420  $output = $exp->getHTML();
421 
422  // toolbars
423  $t = new ilToolbarGUI();
424  $t->setFormAction($ilCtrl->getFormAction($this, "saveTarget"));
425  if ($objDefinition->isContainer($this->getType())) {
426  $t->addFormButton($lng->txt("btn_next"), "saveTarget");
427  } else {
428  $t->addFormButton($lng->txt("paste"), "saveTarget");
429  }
430  $t->addSeparator();
431  $t->addFormButton($lng->txt("obj_insert_into_clipboard"), "keepObjectsInClipboard");
432  $t->addFormButton($lng->txt("cancel"), "cancel");
433  $t->setCloseFormTag(false);
434  $t->setLeadingImage(ilUtil::getImagePath("arrow_upright.svg"), " ");
435  $output = $t->getHTML() . $output;
436  $t->setLeadingImage(ilUtil::getImagePath("arrow_downright.svg"), " ");
437  $t->setCloseFormTag(true);
438  $t->setOpenFormTag(false);
439  $output.= "<br />" . $t->getHTML();
440 
441  $this->tpl->setContent($output);
442 
443  return;
444  }
445 
449  public function showSourceSelectionTree()
450  {
451  $ilTabs = $this->tabs;
452  $ilToolbar = $this->toolbar;
454  $tree = $this->tree;
455  $tpl = $this->tpl;
456  $objDefinition = $this->obj_definition;
457 
458  $this->tpl = $tpl;
459  $this->tpl->addBlockfile(
460  'ADM_CONTENT',
461  'adm_content',
462  'tpl.paste_into_multiple_objects.html',
463  "Services/Object"
464  );
465 
466  ilUtil::sendInfo($this->lng->txt('msg_copy_clipboard_source'));
467  include_once './Services/Object/classes/class.ilPasteIntoMultipleItemsExplorer.php';
470  'ilias.php?baseClass=ilRepositoryGUI&amp;cmd=goto',
471  'paste_copy_repexpand'
472  );
473  $exp->setRequiredFormItemPermission('visible,read,copy');
474 
475  $ilCtrl->setParameter($this, 'selectMode', self::SOURCE_SELECTION);
476  $exp->setExpandTarget($ilCtrl->getLinkTarget($this, 'showSourceSelectionTree'));
477  $exp->setTargetGet('ref_id');
478  $exp->setPostVar('source');
479  $exp->setCheckedItems($this->getSources());
480 
481  // Filter to container
482  foreach (array('cat','root','fold') as $container) {
483  $exp->removeFormItemForType($container);
484  }
485 
486 
487  if ($_GET['paste_copy_repexpand'] == '') {
488  $expanded = $tree->readRootId();
489  } else {
490  $expanded = $_GET['paste_copy_repexpand'];
491  }
492 
493  $this->tpl->setVariable('FORM_TARGET', '_self');
494  $this->tpl->setVariable('FORM_ACTION', $ilCtrl->getFormAction($this, 'copySelection'));
495 
496  $exp->setExpand($expanded);
497  // build html-output
498  $exp->setOutput(0);
499  $output = $exp->getOutput();
500 
501  $this->tpl->setVariable('OBJECT_TREE', $output);
502 
503  $this->tpl->setVariable('CMD_SUBMIT', 'saveSource');
504  $this->tpl->setVariable('TXT_SUBMIT', $this->lng->txt('btn_next'));
505 
506  $ilToolbar->addButton($this->lng->txt('cancel'), $ilCtrl->getLinkTarget($this, 'cancel'));
507  }
508 
513  protected function saveTarget()
514  {
515  $objDefinition = $this->obj_definition;
516  $tree = $this->tree;
518 
519 
520  // begin-patch mc
521  if (is_array($_REQUEST['target']) and $_REQUEST['target']) {
522  $this->setTargets($_REQUEST['target']);
523  $GLOBALS['ilCtrl']->setParameter($this, 'target_ids', implode('_', $this->getTargets()));
524  }
525  // paste from clipboard
526  elseif ((int) $_REQUEST['target']) {
527  $this->setTarget($_REQUEST['target']);
528  $GLOBALS['ilCtrl']->setParameter($this, 'target_ids', implode('_', $this->getTargets()));
529  }
530  // end-patch multi copy
531  else {
532  $ilCtrl->setParameter($this, 'selectMode', self::TARGET_SELECTION);
533  ilUtil::sendFailure($this->lng->txt('select_one'));
534  $this->showTargetSelectionTree();
535  return false;
536  }
537 
538  // validate allowed subtypes
539  foreach ($this->getSources() as $source_ref_id) {
540  foreach ((array) $this->getTargets() as $target_ref_id) {
541  $target_type = ilObject::_lookupType($target_ref_id, true);
542  $target_class_name = ilObjectFactory::getClassByType($target_type);
543  $target_object = new $target_class_name($target_ref_id);
544  $possible_subtypes = $target_object->getPossibleSubObjects();
545 
546  $source_type = ilObject::_lookupType($source_ref_id, true);
547 
548  if (!array_key_exists($source_type, (array) $possible_subtypes)) {
550  sprintf(
551  $this->lng->txt('msg_obj_may_not_contain_objects_of_type'),
552  $this->lng->txt('obj_' . $target_type),
553  $this->lng->txt('obj_' . $source_type)
554  )
555  );
556  $this->showTargetSelectionTree();
557  return false;
558  }
559  }
560  }
561 
562  if ((count($this->getSources()) == 1) && $objDefinition->isContainer($this->getType())) {
563  // check, if object should be copied into itself
564  // begin-patch mc
565  $is_child = array();
566  foreach ($this->getTargets() as $target_ref_id) {
567  if ($tree->isGrandChild($this->getFirstSource(), $target_ref_id)) {
569  }
570  if ($this->getFirstSource() == $target_ref_id) {
572  }
573  }
574  // end-patch multi copy
575  if (count($is_child) > 0) {
576  ilUtil::sendFailure($this->lng->txt("msg_not_in_itself") . " " . implode(',', $is_child));
577  $this->showTargetSelectionTree();
578  return false;
579  }
580 
581  $this->showItemSelection();
582  } else {
583  if (count($this->getSources()) == 1) {
584  $this->copySingleObject();
585  } else {
586  $this->copyMultipleNonContainer($this->getSources());
587  }
588  }
589  }
590 
596  public function setMode($a_mode)
597  {
598  $this->mode = $a_mode;
599  }
600 
605  public function getMode()
606  {
607  return $this->mode;
608  }
609 
610  public function setSubMode($a_mode)
611  {
612  $this->sub_mode = $a_mode;
613  }
614 
615  public function getSubMode()
616  {
617  return $this->sub_mode;
618  }
619 
624  public function getParentObject()
625  {
626  return $this->parent_obj;
627  }
628 
634  public function getType()
635  {
636  return $this->type;
637  }
638 
645  public function setType($type)
646  {
647  $this->type = $type;
648  }
649 
655  public function setSource(array $a_source_ids)
656  {
657  $this->sources = $a_source_ids;
658  }
659 
665  public function getSource()
666  {
667  return $this->getSources();
668  }
669 
674  public function getSources()
675  {
676  return (array) $this->sources;
677  }
678 
679  public function getFirstSource()
680  {
681  if (count($this->sources)) {
682  return $this->sources[0];
683  }
684  return 0;
685  }
686 
687  // begin-patch mc
688 
693  public function setTarget($a_ref_id)
694  {
695  $this->setTargets(array($a_ref_id));
696  }
697 
698 
704  public function setTargets(array $a_target)
705  {
706  $this->targets = $a_target;
707  }
708 
713  public function getTargets()
714  {
715  return (array) $this->targets;
716  }
717 
722  public function getFirstTarget()
723  {
724  if (array_key_exists(0, $this->getTargets())) {
725  $targets = $this->getTargets();
726  return $targets[0];
727  }
728  return 0;
729  }
730  // end-patch multi copy
731 
735  protected function cancel()
736  {
738  $ilCtrl->setReturnByClass(get_class($this->parent_obj), 'cancel');
739  $ilCtrl->returnToParent($this);
740  }
741 
745  public function keepObjectsInClipboard()
746  {
747  ilUtil::sendSuccess($this->lng->txt("obj_inserted_clipboard"), true);
749  $_SESSION['clipboard']['cmd'] = "copy";
750  $_SESSION['clipboard']['ref_ids'] = $this->getSources();
751  $ilCtrl->returnToParent($this);
752  }
753 
754 
759  protected function searchSource()
760  {
761  $tree = $this->tree;
762  $ilObjDataCache = $this->obj_data_cache;
763  $lng = $this->lng;
765  $tpl = $this->tpl;
766 
767  if (isset($_POST['tit'])) {
768  ilUtil::sendInfo($this->lng->txt('wizard_search_list'));
769  $_SESSION['source_query'] = $_POST['tit'];
770  } else {
771  $_POST['tit'] = $_SESSION['source_query'];
772  }
773 
774  $this->initFormSearch();
775  $this->form->setValuesByPost();
776 
777  if (!$this->form->checkInput()) {
778  ilUtil::sendFailure($lng->txt('msg_no_search_string'), true);
779  $ilCtrl->returnToParent($this);
780  return false;
781  }
782 
783  include_once './Services/Search/classes/class.ilQueryParser.php';
784  $query_parser = new ilQueryParser($this->form->getInput('tit'));
785  $query_parser->setMinWordLength(1, true);
786  $query_parser->setCombination(QP_COMBINATION_AND);
787  $query_parser->parse();
788  if (!$query_parser->validate()) {
789  ilUtil::sendFailure($query_parser->getMessage(), true);
790  $ilCtrl->returnToParent($this);
791  }
792 
793  // only like search since fulltext does not support search with less than 3 characters
794  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
795  $object_search = new ilLikeObjectSearch($query_parser);
796  $object_search->setFilter(array($_REQUEST['new_type']));
797  $res = $object_search->performSearch();
798  $res->setRequiredPermission('copy');
799  $res->filter(ROOT_FOLDER_ID, true);
800 
801  if (!count($results = $res->getResultsByObjId())) {
802  ilUtil::sendFailure($this->lng->txt('search_no_match'), true);
803  $ilCtrl->returnToParent($this);
804  }
805 
806 
807  include_once './Services/Object/classes/class.ilObjectCopySearchResultTableGUI.php';
808  $table = new ilObjectCopySearchResultTableGUI($this, 'searchSource', $this->getType());
809  $table->setFormAction($GLOBALS['ilCtrl']->getFormAction($this));
810  $table->setSelectedReference($this->getFirstSource());
811  $table->parseSearchResults($results);
812  $tpl->setContent($table->getHTML());
813  }
814 
819  protected function saveSource()
820  {
821  $objDefinition = $this->obj_definition;
822 
823  if (isset($_POST['source'])) {
824  $this->setSource(array((int) $_REQUEST['source']));
825  $this->setType(ilObject::_lookupType((int) $_REQUEST['source'], true));
826  $GLOBALS['ilCtrl']->setParameter($this, 'source_id', (int) $_REQUEST['source']);
827  } else {
828  ilUtil::sendFailure($this->lng->txt('select_one'));
829  $this->searchSource();
830  return false;
831  }
832 
833  // validate allowed subtypes
834  foreach ($this->getSources() as $source_ref_id) {
835  foreach ((array) $this->getTargets() as $target_ref_id) {
836  $target_type = ilObject::_lookupType($target_ref_id, true);
837  $target_class_name = ilObjectFactory::getClassByType($target_type);
838  $target_object = new $target_class_name($target_ref_id);
839  $possible_subtypes = $target_object->getPossibleSubObjects();
840 
841  $source_type = ilObject::_lookupType($source_ref_id, true);
842 
843  if (!array_key_exists($source_type, $possible_subtypes)) {
844  #ilLoggerFactory::getLogger('obj')->debug('Source type: '. $source_type);
845  #ilLoggerFactory::getLogger('obj')->debug('Target type: '. $target_type);
846  #ilLoggerFactory::getLogger('obj')->debug('Submode: '. $this->getSubMode());
847 
848  // adopt content mode
849  if (
850  $this->getSubMode() != self::SUBMODE_CONTENT_ONLY and
851  ($source_type != 'crs' or $target_type != 'crs')
852  ) {
854  sprintf(
855  $this->lng->txt('msg_obj_may_not_contain_objects_of_type'),
856  $this->lng->txt('obj_' . $target_type),
857  $this->lng->txt('obj_' . $source_type)
858  )
859  );
860  $this->searchSource();
861  return false;
862  }
863  }
864  }
865  }
866 
867 
868  if ($objDefinition->isContainer($this->getType())) {
869  $this->showItemSelection();
870  } else {
871  $this->copySingleObject();
872  }
873  }
874 
878  protected function saveSourceMembership()
879  {
880  $objDefinition = $this->obj_definition;
881 
882  if (!isset($_REQUEST['source'])) {
883  ilUtil::sendFailure($this->lng->txt('select_one'));
884  $GLOBALS['ilCtrl']->redirect($this, 'showSourceSelectionMembership');
885  return false;
886  }
887 
888  $this->setSource(array((int) $_REQUEST['source']));
889  $this->setType(ilObject::_lookupType((int) $this->getFirstSource(), true));
890  $GLOBALS['ilCtrl']->setParameter($this, 'source_id', (int) $_REQUEST['source']);
891 
892  if ($objDefinition->isContainer($this->getType())) {
893  $this->showItemSelection();
894  } else {
895  $this->copySingleObject();
896  }
897  }
898 
903  protected function showItemSelection()
904  {
905  $tpl = $this->tpl;
906 
907  if (!count($this->getSources())) {
908  ilUtil::sendFailure($this->lng->txt('select_one'));
909  $this->searchSource();
910  return false;
911  }
912 
913  ilLoggerFactory::getLogger('obj')->debug('Source(s): ' . print_r($this->getSources(), true));
914  ilLoggerFactory::getLogger('obj')->debug('Target(s): ' . print_r($this->getTargets(), true));
915 
916  ilUtil::sendInfo($this->lng->txt($this->getType() . '_copy_threads_info'));
917  include_once './Services/Object/classes/class.ilObjectCopySelectionTableGUI.php';
918 
919  $tpl->addJavaScript('./Services/CopyWizard/js/ilContainer.js');
920  $tpl->setVariable('BODY_ATTRIBUTES', 'onload="ilDisableChilds(\'cmd\');"');
921 
922  switch ($this->getMode()) {
923  case self::SOURCE_SELECTION:
924  $back_cmd = 'showSourceSelectionTree';
925  break;
926 
927  case self::TARGET_SELECTION:
928  $back_cmd = 'showTargetSelectionTree';
929  break;
930 
931  case self::SEARCH_SOURCE:
932  $back_cmd = 'searchSource';
933  break;
934  }
935 
936  $table = new ilObjectCopySelectionTableGUI($this, 'showItemSelection', $this->getType(), $back_cmd);
937  $table->parseSource($this->getFirstSource());
938 
939  $tpl->setContent($table->getHTML());
940  }
941 
946  protected function copySingleObject()
947  {
948  include_once('./Services/Link/classes/class.ilLink.php');
949  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
950 
951  $ilAccess = $this->access;
957 
958  // Source defined
959  if (!count($this->getSources())) {
960  ilUtil::sendFailure($this->lng->txt('select_one'), true);
961  $ilCtrl->returnToParent($this);
962  }
963 
964  $this->copyMultipleNonContainer($this->getSources());
965  return;
966  }
967 
973  public function copyMultipleNonContainer($a_sources)
974  {
975  $ilAccess = $this->access;
976  $objDefinition = $this->obj_definition;
981 
982 
983  include_once('./Services/Link/classes/class.ilLink.php');
984  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
985 
986  // check permissions
987  foreach ($a_sources as $source_ref_id) {
988  $source_type = ilObject::_lookupType($source_ref_id, true);
989 
990  // Create permission
991  // begin-patch mc
992  foreach ($this->getTargets() as $target_ref_id) {
993  if (!$rbacsystem->checkAccess('create', $target_ref_id, $source_type)) {
994  $this->log->notice('Permission denied for target_id: ' . $target_ref_id . ' source_type: ' . $source_type . ' CREATE');
995  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
996  $ilCtrl->returnToParent($this);
997  }
998  }
999 
1000  // Copy permission
1001  if (!$ilAccess->checkAccess('copy', '', $source_ref_id)) {
1002  $this->log->notice('Permission denied for source_ref_id: ' . $source_ref_id . ' COPY');
1003  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
1004  $ilCtrl->returnToParent($this);
1005  }
1006 
1007  // check that these objects are really not containers
1008  if ($objDefinition->isContainer($source_type) and $this->getSubMode() != self::SUBMODE_CONTENT_ONLY) {
1009  ilUtil::sendFailure($this->lng->txt('cntr_container_only_on_their_own'), true);
1010  $ilCtrl->returnToParent($this);
1011  }
1012  }
1013 
1014  reset($a_sources);
1015 
1016 
1017  ilLoggerFactory::getLogger('obj')->debug('Copy multiple non containers. Sources: ' . print_r($a_sources, true));
1018 
1019  // clone
1020  foreach ($a_sources as $source_ref_id) {
1021  ilLoggerFactory::getLogger('obj')->debug('Copying source ref_id : ' . $source_ref_id);
1022 
1023  // begin-patch mc
1024  foreach ($this->getTargets() as $target_ref_id) {
1025  // Save wizard options
1027  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
1028  $wizard_options->saveOwner($ilUser->getId());
1029  $wizard_options->saveRoot((int) $source_ref_id);
1030  $wizard_options->read();
1031 
1032  $orig = ilObjectFactory::getInstanceByRefId((int) $source_ref_id);
1033  $new_obj = $orig->cloneObject($target_ref_id, $copy_id);
1034 
1035  // Delete wizard options
1036  $wizard_options->deleteAll();
1037 
1038  // rbac log
1039  include_once "Services/AccessControl/classes/class.ilRbacLog.php";
1040  if (ilRbacLog::isActive()) {
1041  $rbac_log_roles = $rbacreview->getParentRoleIds($new_obj->getRefId(), false);
1042  $rbac_log = ilRbacLog::gatherFaPa($new_obj->getRefId(), array_keys($rbac_log_roles), true);
1043  ilRbacLog::add(ilRbacLog::COPY_OBJECT, $new_obj->getRefId(), $rbac_log, (int) $source_ref_id);
1044  }
1045  }
1046  }
1047 
1048  unset($_SESSION["clipboard"]["ref_ids"]);
1049  unset($_SESSION["clipboard"]["cmd"]);
1050 
1051  if (count($a_sources) == 1) {
1052  ilLoggerFactory::getLogger('obj')->info('Object copy completed.');
1053  ilUtil::sendSuccess($this->lng->txt("object_duplicated"), true);
1054  ilUtil::redirect(ilLink::_getLink($new_obj->getRefId()));
1055  } else {
1056  ilLoggerFactory::getLogger('obj')->info('Object copy completed.');
1057  ilUtil::sendSuccess($this->lng->txt("objects_duplicated"), true);
1059  }
1060  }
1061 
1065  protected function copyContainerToTargets()
1066  {
1067  $ilCtrl = $this->ctrl;
1068 
1069  ilLoggerFactory::getLogger('obj')->debug('Copy container to targets: ' . print_r($_REQUEST, true));
1070  ilLoggerFactory::getLogger('obj')->debug('Source(s): ' . print_r($this->getSources(), true));
1071  ilLoggerFactory::getLogger('obj')->debug('Target(s): ' . print_r($this->getTargets(), true));
1072 
1073 
1074  $last_target = 0;
1075  $result = 1;
1076  foreach ($this->getTargets() as $target_ref_id) {
1077  $result = $this->copyContainer($target_ref_id);
1078  $last_target = $target_ref_id;
1079  }
1080 
1081  unset($_SESSION["clipboard"]["ref_ids"]);
1082  unset($_SESSION["clipboard"]["cmd"]);
1083 
1084  include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
1085  if (ilCopyWizardOptions::_isFinished($result['copy_id'])) {
1086  ilLoggerFactory::getLogger('obj')->info('Object copy completed.');
1087  ilUtil::sendSuccess($this->lng->txt("object_duplicated"), true);
1088  $link = ilLink::_getLink($result['ref_id']);
1089  $GLOBALS['DIC']->ctrl()->redirectToUrl($link);
1090  } else {
1091  // show progress
1092  ilLoggerFactory::getLogger('obj')->debug('Object copy in progress.');
1093  return $this->showCopyProgress();
1094  }
1095  }
1096 
1100  protected function showCopyProgress()
1101  {
1102  include_once './Services/Object/classes/class.ilObjectCopyProgressTableGUI.php';
1103  $progress = new ilObjectCopyProgressTableGUI(
1104  $this,
1105  'showCopyProgress',
1106  (int) $_GET['ref_id']
1107  );
1108  $progress->setObjectInfo($this->targets_copy_id);
1109  $progress->parse();
1110  $progress->init();
1111  $progress->setRedirectionUrl($GLOBALS['ilCtrl']->getParentReturn($this->parent_obj));
1112 
1113  $GLOBALS['tpl']->setContent($progress->getHTML());
1114  }
1115 
1119  protected function updateProgress()
1120  {
1121  $json = new stdClass();
1122  $json->percentage = null;
1123  $json->performed_steps = null;
1124 
1125  include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
1126  $options = ilCopyWizardOptions::_getInstance((int) $_REQUEST['copy_id']);
1127  $json->required_steps = $options->getRequiredSteps();
1128  $json->id = (int) $_REQUEST['copy_id'];
1129 
1130  ilLoggerFactory::getLogger('obj')->debug('Update copy progress: ' . json_encode($json));
1131 
1132  echo json_encode($json);
1133  exit;
1134  }
1135 
1136 
1141  protected function copyContainer($a_target)
1142  {
1143  $ilLog = $this->log;
1144  $ilCtrl = $this->ctrl;
1145 
1146  include_once('./Services/Link/classes/class.ilLink.php');
1147  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
1148 
1149  $ilAccess = $this->access;
1150  $ilErr = $this->error;
1152  $tree = $this->tree;
1153  $ilUser = $this->user;
1154  $ilCtrl = $this->ctrl;
1155 
1156  // Workaround for course in course copy
1157 
1160 
1161  if ($this->getSubMode() != self::SUBMODE_CONTENT_ONLY) {
1162  if (!$rbacsystem->checkAccess('create', $a_target, $this->getType())) {
1163  $this->log->notice('Permission denied for target: ' . $a_target . ' type: ' . $this->getType() . ' CREATE');
1164  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
1165  $ilCtrl->returnToParent($this);
1166  }
1167  }
1168  if (!$this->getFirstSource()) {
1169  ilUtil::sendFailure($this->lng->txt('select_one'), true);
1170  $ilCtrl->returnToParent($this);
1171  return false;
1172  }
1173 
1174  $options = $_POST['cp_options'] ? $_POST['cp_options'] : array();
1175 
1176 
1177  ilLoggerFactory::getLogger('obj')->debug('Copy container (sources): ' . print_r($this->getSources(), true));
1178 
1180  $result = $orig->cloneAllObject(
1181  $_COOKIE['PHPSESSID'],
1182  $_COOKIE['ilClientId'],
1183  $this->getType(),
1184  $a_target,
1185  $this->getFirstSource(),
1186  $options,
1187  false,
1188  $this->getSubMode()
1189  );
1190 
1191  $this->targets_copy_id[$a_target] = $result['copy_id'];
1192 
1193  return $result;
1194  }
1195 
1196 
1197 
1205  public function showSourceSearch($a_tplvar)
1206  {
1207  $tpl = $this->tpl;
1208 
1209  // Disabled for performance
1210  #if(!$this->sourceExists())
1211  #{
1212  # return false;
1213  #}
1214 
1215  $this->unsetSession();
1216  $this->initFormSearch();
1217 
1218  if ($a_tplvar) {
1219  $tpl->setVariable($a_tplvar, $this->form->getHTML());
1220  } else {
1221  return $this->form;
1222  }
1223  }
1224 
1225 
1230  protected function sourceExists()
1231  {
1232  $ilUser = $this->user;
1233 
1234  return (bool) ilUtil::_getObjectsByOperations($this->getType(), 'copy', $ilUser->getId(), 1);
1235  }
1236 
1241  protected function initFormSearch()
1242  {
1243  $lng = $this->lng;
1244  $ilCtrl = $this->ctrl;
1245 
1246  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1247  $this->form = new ilPropertyFormGUI();
1248  $this->form->setTableWidth('600px');
1249 
1250  $ilCtrl->setParameter($this, 'new_type', $this->getType());
1251 
1252  #$ilCtrl->setParameter($this, 'cp_mode', self::SOURCE_SELECTION);
1253  $this->form->setFormAction($ilCtrl->getFormAction($this));
1254  $this->form->setTitle($lng->txt($this->getType() . '_copy'));
1255 
1256  $this->form->addCommandButton('searchSource', $lng->txt('btn_next'));
1257  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
1258 
1259  $tit = new ilTextInputGUI($lng->txt('title'), 'tit');
1260  $tit->setSize(40);
1261  $tit->setMaxLength(70);
1262  $tit->setRequired(true);
1263  $tit->setInfo($lng->txt('wizard_title_info'));
1264  $this->form->addItem($tit);
1265  }
1266 
1271  protected function unsetSession()
1272  {
1273  unset($_SESSION['source_query']);
1274  $this->setSource(array());
1275  }
1276 }
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.
$_COOKIE['client_id']
Definition: server.php:9
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:48
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.
global $DIC
Definition: saml.php:7
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.
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)
user()
Definition: user.php:4
$container
Definition: wac.php:13
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.
foreach($_POST as $key=> $value) $res
if(isset($_POST['submit'])) $form
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.
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.
$results
Definition: svg-scanner.php:47
static add($a_action, $a_ref_id, array $a_diff, $a_source_ref_id=false)
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
if(empty($password)) $table
Definition: pwgen.php:24
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)
showSourceSelectionMembership()
show target selection membership
searchSource()
Search source.
$_POST["username"]
setType($type)
Sets $type.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20