ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
15 {
16  const SOURCE_SELECTION = 1;
17  const TARGET_SELECTION = 2;
18  const SEARCH_SOURCE = 3;
19 
20  private $mode = 0;
21 
22  private $lng;
23 
24  private $parent_obj = null;
25 
26  private $type = '';
27  private $source = 0;
28  private $target = 0;
29 
30 
35  public function __construct($a_parent_gui)
36  {
37  global $ilCtrl,$lng;
38 
39  $this->lng = $lng;
40  $this->lng->loadLanguageModule('search');
41  $this->lng->loadLanguageModule('obj');
42 
43  $this->parent_obj = $a_parent_gui;
44 
45  // this parameter may be filled in "manage" view
46  $ilCtrl->saveParameter($this, array("source_ids"));
47  }
48 
53  public function executeCommand()
54  {
55  global $ilCtrl;
56 
57  $this->init();
58 
59  $next_class = $ilCtrl->getNextClass($this);
60  $cmd = $ilCtrl->getCmd();
61 
62 
63  switch($next_class)
64  {
65  default:
66  $this->$cmd();
67  break;
68  }
69  }
70 
75  protected function init()
76  {
77  global $ilCtrl;
78 
79  if($_REQUEST['new_type'])
80  {
81  $this->setMode(self::SEARCH_SOURCE);
82 
83  $ilCtrl->setParameter($this,'new_type',$this->getType());
84  $ilCtrl->setParameterByClass(get_class($this->parent_obj), 'new_type', $this->getType());
85  $ilCtrl->setParameterByClass(get_class($this->parent_obj), 'cpfl', 1);
86  $ilCtrl->setReturnByClass(get_class($this->parent_obj), 'create');
87  }
88  elseif($_REQUEST['selectMode'] == self::SOURCE_SELECTION)
89  {
90  $this->setMode(self::SOURCE_SELECTION);
91 
92  $ilCtrl->setParameterByClass(get_class($this->parent_obj), 'selectMode', self::SOURCE_SELECTION);
93  $this->setTarget((int) $_GET['ref_id']);
94  $ilCtrl->setReturnByClass(get_class($this->parent_obj), '');
95  }
96  else
97  {
98  $this->setMode(self::TARGET_SELECTION);
99  $ilCtrl->setReturnByClass(get_class($this->parent_obj),'');
100 
101  if ($_GET["source_ids"] == "")
102  {
103  $this->setType(
105  );
106  }
107  }
108  }
109 
114  protected function initTargetSelection()
115  {
116  global $ilCtrl, $tree;
117 
118  // empty session on init
119  $_SESSION['paste_copy_repexpand'] = array();
120 
121  // copy opened nodes from repository explorer
122  $_SESSION['paste_copy_repexpand'] = is_array($_SESSION['repexpand']) ? $_SESSION['repexpand'] : array();
123 
124 
125  $this->setMode(self::TARGET_SELECTION);
126  $this->setTarget(0);
127 
128  // note that source_id is empty, if source_ids are given
129  if ($_GET['source_id'] > 0)
130  {
131  // open current position
132  $path = $tree->getPathId((int)$_GET['source_id']);
133  foreach((array)$path as $node_id)
134  {
135  if(!in_array($node_id, $_SESSION['paste_copy_repexpand']))
136  $_SESSION['paste_copy_repexpand'][] = $node_id;
137  }
138 
139  $this->setSource((int) $_GET['source_id']);
140 
141  $this->setType(
143  );
144  }
145 
146  $ilCtrl->setReturnByClass(get_class($this->parent_obj),'');
147 
148  $this->showTargetSelectionTree();
149  }
150 
155  protected function initSourceSelection()
156  {
157  global $ilCtrl,$tree;
158 
159  // empty session on init
160  $_SESSION['paste_copy_repexpand'] = array();
161 
162  // copy opened nodes from repository explorer
163  $_SESSION['paste_copy_repexpand'] = is_array($_SESSION['repexpand']) ? $_SESSION['repexpand'] : array();
164 
165  $this->setMode(self::SOURCE_SELECTION);
166  $this->setSource(0);
167  $this->setTarget((int) $_GET['ref_id']);
168 
169  // open current position
170  $path = $tree->getPathId($this->getTarget());
171  foreach((array) $path as $node_id)
172  {
173  if(!in_array($node_id, $_SESSION['paste_copy_repexpand']))
174  $_SESSION['paste_copy_repexpand'][] = $node_id;
175  }
176 
177  $ilCtrl->setReturnByClass(get_class($this->parent_obj),'');
178  $this->showSourceSelectionTree();
179  }
180 
184  public function showTargetSelectionTree()
185  {
186  global $ilTabs, $ilToolbar, $ilCtrl, $tree, $tpl, $objDefinition, $lng;
187 
188  $this->tpl = $tpl;
189 
190  ilUtil::sendInfo($this->lng->txt('msg_copy_clipboard'));
191 
192  //
193  include_once("./Services/Repository/classes/class.ilRepositorySelectorExplorerGUI.php");
194  $exp = new ilRepositorySelectorExplorerGUI($this, "showTargetSelectionTree");
195  $exp->setTypeWhiteList(array("root", "cat", "grp", "crs", "fold"));
196  $exp->setSelectMode("target", false);
197  if ($exp->handleCommand())
198  {
199  return;
200  }
201  $output = $exp->getHTML();
202 
203  // toolbars
204  $t = new ilToolbarGUI();
205  $t->setFormAction($ilCtrl->getFormAction($this, "saveTarget"));
206  if($objDefinition->isContainer($this->getType()))
207  {
208  $t->addFormButton($lng->txt("btn_next"), "saveTarget");
209  }
210  else
211  {
212  $t->addFormButton($lng->txt("copy"), "saveTarget");
213  }
214  $t->addSeparator();
215  $t->addFormButton($lng->txt("obj_insert_into_clipboard"), "keepObjectsInClipboard");
216  $t->addFormButton($lng->txt("cancel"), "cancel");
217  $t->setCloseFormTag(false);
218  $t->setLeadingImage(ilUtil::getImagePath("arrow_upright.png"), " ");
219  $output = $t->getHTML().$output;
220  $t->setLeadingImage(ilUtil::getImagePath("arrow_downright.png"), " ");
221  $t->setCloseFormTag(true);
222  $t->setOpenFormTag(false);
223  $output.= "<br />".$t->getHTML();
224 
225  $this->tpl->setContent($output);
226 
227  return;
228 
229  // old implementation
230 
231  $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.paste_into_multiple_objects.html',
232  "Services/Object");
233 
234  include_once './Services/Object/classes/class.ilPasteIntoMultipleItemsExplorer.php';
237  'ilias.php?baseClass=ilRepositoryGUI&amp;cmd=goto', 'paste_copy_repexpand');
238 
239  // Target selection should check for create permission
240  $required_perm = 'visible';
241  $create_perm = 'create_'.ilObject::_lookupType($this->getSource(), true);
242  if($create_perm)
243  {
244  $required_perm .= (','.$create_perm);
245  }
246  $exp->setRequiredFormItemPermission($required_perm);
247  $exp->setExpandTarget($ilCtrl->getLinkTarget($this, 'showTargetSelectionTree'));
248  $exp->setTargetGet('ref_id');
249  $exp->setPostVar('target');
250  $exp->highlightNode($_GET['ref_id']);
251  $exp->setCheckedItems(array((int) $_POST['target']));
252 
253  // Filter to container
254  foreach(array('cat','root','crs','grp','fold') as $container)
255  {
256  /*
257  if($this->getType() == 'crs' and $container == 'crs')
258  {
259  continue;
260  }
261  */
262  $sub = $objDefinition->getSubObjects($container);
263  if(!isset($sub[$this->getType()]))
264  {
265  $exp->removeFormItemForType($container);
266  }
267  }
268 
269  if($_GET['paste_copy_repexpand'] == '')
270  {
271  $expanded = $tree->readRootId();
272  }
273  else
274  {
275  $expanded = $_GET['paste_copy_repexpand'];
276  }
277 
278  $this->tpl->setVariable('FORM_TARGET', '_self');
279  $this->tpl->setVariable('FORM_ACTION', $ilCtrl->getFormAction($this, 'copySelection'));
280 
281  $exp->setExpand($expanded);
282  // build html-output
283  $exp->setOutput(0);
284  $output = $exp->getOutput();
285 
286  $this->tpl->setVariable('OBJECT_TREE', $output);
287 
288  $this->tpl->setVariable('CMD_SUBMIT', 'saveTarget');
289 
290  if($objDefinition->isContainer($this->getType()))
291  {
292  $this->tpl->setVariable('TXT_SUBMIT',$this->lng->txt('btn_next'));
293  }
294  else
295  {
296  if(!$objDefinition->isPlugin($this->getType()))
297  {
298  $submit = $this->lng->txt('obj_'.$this->getType().'_duplicate');
299  }
300  else
301  {
302  // get plugin instance
303  include_once "Services/Component/classes/class.ilPlugin.php";
304  $plugin = ilPlugin::getPluginObject(IL_COMP_SERVICE, "Repository", "robj",
305  ilPlugin::lookupNameForId(IL_COMP_SERVICE, "Repository", "robj", $this->getType()));
306  $submit = $plugin->txt('obj_'.$this->getType().'_duplicate');
307  }
308  $this->tpl->setVariable('TXT_SUBMIT', $submit);
309  }
310 
311  $ilToolbar->addButton($this->lng->txt('cancel'), $ilCtrl->getLinkTarget($this,'cancel'));
312  }
313 
317  public function showSourceSelectionTree()
318  {
319  global $ilTabs, $ilToolbar, $ilCtrl, $tree, $tpl, $objDefinition;
320 
321  $this->tpl = $tpl;
322  $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.paste_into_multiple_objects.html',
323  "Services/Object");
324 
325  ilUtil::sendInfo($this->lng->txt('msg_copy_clipboard_source'));
326  include_once './Services/Object/classes/class.ilPasteIntoMultipleItemsExplorer.php';
329  'ilias.php?baseClass=ilRepositoryGUI&amp;cmd=goto', 'paste_copy_repexpand');
330  $exp->setRequiredFormItemPermission('visible,read,copy');
331 
332  $ilCtrl->setParameter($this, 'selectMode', self::SOURCE_SELECTION);
333  $exp->setExpandTarget($ilCtrl->getLinkTarget($this, 'showSourceSelectionTree'));
334  $exp->setTargetGet('ref_id');
335  $exp->setPostVar('source');
336  $exp->setCheckedItems(array($this->getSource()));
337  #$exp->setNotSelectableItems(array($this->getTarget()));
338 
339  // Filter to container
340  foreach(array('cat','root','grp','fold') as $container)
341  {
342  $exp->removeFormItemForType($container);
343  }
344 
345 
346  if($_GET['paste_copy_repexpand'] == '')
347  {
348  $expanded = $tree->readRootId();
349  }
350  else
351  {
352  $expanded = $_GET['paste_copy_repexpand'];
353  }
354 
355  $this->tpl->setVariable('FORM_TARGET', '_self');
356  $this->tpl->setVariable('FORM_ACTION', $ilCtrl->getFormAction($this, 'copySelection'));
357 
358  $exp->setExpand($expanded);
359  // build html-output
360  $exp->setOutput(0);
361  $output = $exp->getOutput();
362 
363  $this->tpl->setVariable('OBJECT_TREE', $output);
364 
365  $this->tpl->setVariable('CMD_SUBMIT', 'saveSource');
366  $this->tpl->setVariable('TXT_SUBMIT', $this->lng->txt('btn_next'));
367 
368  $ilToolbar->addButton($this->lng->txt('cancel'), $ilCtrl->getLinkTarget($this,'cancel'));
369  }
370 
375  protected function saveTarget()
376  {
377  global $objDefinition, $tree;
378 
379 
380  if(isset($_REQUEST['target']))
381  {
382  $this->setTarget((int) $_REQUEST['target']);
383  }
384  else
385  {
386  ilUtil::sendFailure($this->lng->txt('select_one'));
387  $this->showTargetSelectionTree();
388  return false;
389  }
390 
391  if($_GET["source_ids"] == "" && $objDefinition->isContainer($this->getType()))
392  {
393  // check, if object should be copied into itself
394  $is_child = array();
395  if ($tree->isGrandChild($this->getSource(), $this->getTarget()))
396  {
398  }
399  if ($this->getSource() == $this->getTarget())
400  {
402  }
403  if (count($is_child) > 0)
404  {
405  ilUtil::sendFailure($this->lng->txt("msg_not_in_itself")." ".implode(',',$is_child));
406  $this->showTargetSelectionTree();
407  return false;
408  }
409 
410  $this->showItemSelection();
411  }
412  else
413  {
414  if ($_GET["source_ids"] == "")
415  {
416  $this->copySingleObject();
417  }
418  else
419  {
420  $source_ids = explode("_", $_GET["source_ids"]);
421  $this->copyMultipleNonContainer($source_ids);
422  }
423  }
424  }
425 
431  public function setMode($a_mode)
432  {
433  $this->mode = $a_mode;
434  }
435 
440  public function getMode()
441  {
442  return $this->mode;
443  }
444 
449  public function getParentObject()
450  {
451  return $this->parent_obj;
452  }
453 
459  public function getType()
460  {
461  return $this->type;
462  }
463 
470  public function setType($type)
471  {
472  $this->type = $type;
473  }
474 
480  public function setSource($a_source_id)
481  {
482  $_SESSION['copy_source'] = $a_source_id;
483  }
484 
489  public function getSource()
490  {
491  if ($_GET["source_ids"] != "")
492  {
493  return "";
494  }
495  return $_SESSION['copy_source'];
496  }
497 
503  public function setTarget($a_target)
504  {
505  $_SESSION['copy_target'] = $a_target;
506  }
507 
512  public function getTarget()
513  {
514  return $_SESSION['copy_target'];
515  }
516 
520  protected function cancel()
521  {
522  global $ilCtrl;
523  $ilCtrl->returnToParent($this);
524  }
525 
530  {
531  global $ilCtrl;
532  $_SESSION['clipboard']['cmd'] = "copy";
533  if ($_GET["source_ids"] == "")
534  {
535  $_SESSION['clipboard']['ref_ids'] = array((int) $this->getSource());
536  }
537  else
538  {
539  $_SESSION['clipboard']['ref_ids'] = explode("_", $_GET["source_ids"]);
540  }
541  $ilCtrl->returnToParent($this);
542  }
543 
544 
549  protected function searchSource()
550  {
551  global $tree,$ilObjDataCache,$lng,$ilCtrl,$tpl;
552 
553  if(isset($_POST['tit']))
554  {
555  ilUtil::sendInfo($this->lng->txt('wizard_search_list'));
556  $_SESSION['source_query'] = $_POST['tit'];
557  }
558  else
559  {
560  $_POST['tit'] = $_SESSION['source_query'];
561  }
562 
563  $this->initFormSearch();
564  $this->form->setValuesByPost();
565 
566  if(!$this->form->checkInput())
567  {
568  ilUtil::sendFailure($lng->txt('msg_no_search_string'),true);
569  $ilCtrl->returnToParent($this);
570  return false;
571  }
572 
573  include_once './Services/Search/classes/class.ilQueryParser.php';
574  $query_parser = new ilQueryParser($this->form->getInput('tit'));
575  $query_parser->setMinWordLength(1,true);
576  $query_parser->setCombination(QP_COMBINATION_AND);
577  $query_parser->parse();
578  if(!$query_parser->validate())
579  {
580  ilUtil::sendFailure($query_parser->getMessage(),true);
581  $ilCtrl->returnToParent($this);
582  }
583 
584  // only like search since fulltext does not support search with less than 3 characters
585  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
586  $object_search = new ilLikeObjectSearch($query_parser);
587  $object_search->setFilter(array($_REQUEST['new_type']));
588  $res = $object_search->performSearch();
589  $res->setRequiredPermission('copy');
590  $res->filter(ROOT_FOLDER_ID,true);
591 
592  if(!count($results = $res->getResultsByObjId()))
593  {
594  ilUtil::sendFailure($this->lng->txt('search_no_match'),true);
595  $ilCtrl->returnToParent($this);
596  }
597 
598  include_once './Services/Object/classes/class.ilObjectCopySearchResultTableGUI.php';
599  $table = new ilObjectCopySearchResultTableGUI($this,'searchSource',$_REQUEST['new_type']);
600  $table->setSelectedReference($this->getSource());
601  $table->parseSearchResults($results);
602  $tpl->setContent($table->getHTML());
603  }
604 
609  protected function saveSource()
610  {
611  global $objDefinition;
612 
613  if(isset($_POST['source']))
614  {
615  $this->setSource($_POST['source']);
616  }
617  else
618  {
619  ilUtil::sendFailure($this->lng->txt('select_one'));
620  $this->searchSource();
621  return false;
622  }
623 
624  if($objDefinition->isContainer($this->getType()))
625  {
626  $this->showItemSelection();
627  }
628  else
629  {
630  $this->copySingleObject();
631  }
632  }
633 
634 
635 
640  protected function showItemSelection()
641  {
642  global $tpl;
643 
644  if(!$this->getSource())
645  {
646  ilUtil::sendFailure($this->lng->txt('select_one'));
647  $this->searchSource();
648  return false;
649  }
650 
651  ilUtil::sendInfo($this->lng->txt($this->getType().'_copy_threads_info'));
652  include_once './Services/Object/classes/class.ilObjectCopySelectionTableGUI.php';
653 
654  $tpl->addJavaScript('./Services/CopyWizard/js/ilContainer.js');
655  $tpl->setVariable('BODY_ATTRIBUTES','onload="ilDisableChilds(\'cmd\');"');
656 
657  switch($this->getMode())
658  {
659  case self::SOURCE_SELECTION:
660  $back_cmd = 'showSourceSelectionTree';
661  break;
662 
663  case self::TARGET_SELECTION:
664  $back_cmd = 'showTargetSelectionTree';
665  break;
666 
667  case self::SEARCH_SOURCE:
668  $back_cmd = 'searchSource';
669  break;
670  }
671 
672  $table = new ilObjectCopySelectionTableGUI($this,'showItemSelection',$this->getType(),$back_cmd);
673  $table->parseSource($this->getSource());
674 
675  $tpl->setContent($table->getHTML());
676  }
677 
682  protected function copySingleObject()
683  {
684  include_once('./Services/Link/classes/class.ilLink.php');
685  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
686 
687  global $ilAccess,$ilErr,$rbacsystem,$ilUser,$ilCtrl,$rbacreview;
688 
689  // Source defined
690  if(!$this->getSource())
691  {
692  ilUtil::sendFailure($this->lng->txt('select_one'),true);
693  $ilCtrl->returnToParent($this);
694  }
695 
696  $this->copyMultipleNonContainer(array($this->getSource()));
697 
698  return;
699 
700  // old implementation
701 
702 
703 
704  // Create permission
705  if(!$rbacsystem->checkAccess('create', $this->getTarget(), $this->getType()))
706  {
707  ilUtil::sendFailure($this->lng->txt('permission_denied'),true);
708  $ilCtrl->returnToParent($this);
709  }
710  // Source defined
711  if(!$this->getSource())
712  {
713  ilUtil::sendFailure($this->lng->txt('select_one'),true);
714  $ilCtrl->returnToParent($this);
715  }
716  // Copy permission
717  if(!$ilAccess->checkAccess('copy','',$this->getSource()))
718  {
719  ilUtil::sendFailure($this->lng->txt('permission_denied'),true);
720  $ilCtrl->returnToParent($this);
721  }
722 
723  // Save wizard options
725  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
726  $wizard_options->saveOwner($ilUser->getId());
727  $wizard_options->saveRoot((int) $this->getSource());
728 
729  /*
730  $options = $_POST['cp_options'] ? $_POST['cp_options'] : array();
731  foreach($options as $source_id => $option)
732  {
733  $wizard_options->addEntry($source_id,$option);
734  }
735  */
736 
737  $wizard_options->read();
738 
739  $orig = ilObjectFactory::getInstanceByRefId((int) $this->getSource());
740  $new_obj = $orig->cloneObject($this->getTarget(),$copy_id);
741 
742  // Delete wizard options
743  $wizard_options->deleteAll();
744 
745  // rbac log
746  include_once "Services/AccessControl/classes/class.ilRbacLog.php";
747  if(ilRbacLog::isActive())
748  {
749  $rbac_log_roles = $rbacreview->getParentRoleIds($new_obj->getRefId(), false);
750  $rbac_log = ilRbacLog::gatherFaPa($new_obj->getRefId(), array_keys($rbac_log_roles), true);
751  ilRbacLog::add(ilRbacLog::COPY_OBJECT, $new_obj->getRefId(), $rbac_log, (int)$this->getSource());
752  }
753 
754  ilUtil::sendSuccess($this->lng->txt("object_duplicated"),true);
755  ilUtil::redirect(ilLink::_getLink($new_obj->getRefId()));
756  }
757 
763  function copyMultipleNonContainer($a_sources)
764  {
765  global $ilAccess,$objDefinition,$rbacsystem,$ilUser,$ilCtrl,$rbacreview;
766 
767 
768  include_once('./Services/Link/classes/class.ilLink.php');
769  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
770 
771  // check permissions
772  foreach ($a_sources as $source_ref_id)
773  {
774  $source_type = ilObject::_lookupType($source_ref_id, true);
775 
776  // Create permission
777  if(!$rbacsystem->checkAccess('create', $this->getTarget(), $source_type))
778  {
779  ilUtil::sendFailure($this->lng->txt('permission_denied'),true);
780  $ilCtrl->returnToParent($this);
781  }
782 
783  // Copy permission
784  if(!$ilAccess->checkAccess('copy','',$source_ref_id))
785  {
786  ilUtil::sendFailure($this->lng->txt('permission_denied'),true);
787  $ilCtrl->returnToParent($this);
788  }
789 
790  // check that these objects are really not containers
791  if($objDefinition->isContainer($source_type))
792  {
793  ilUtil::sendFailure($this->lng->txt('cntr_container_only_on_their_own'),true);
794  $ilCtrl->returnToParent($this);
795  }
796  }
797 
798  reset($a_sources);
799 
800  // clone
801  foreach ($a_sources as $source_ref_id)
802  {
803  // Save wizard options
805  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
806  $wizard_options->saveOwner($ilUser->getId());
807  $wizard_options->saveRoot((int) $source_ref_id);
808 
809  $wizard_options->read();
810 
811  $orig = ilObjectFactory::getInstanceByRefId((int) $source_ref_id);
812  $new_obj = $orig->cloneObject($this->getTarget(),$copy_id);
813 
814  // Delete wizard options
815  $wizard_options->deleteAll();
816 
817  // rbac log
818  include_once "Services/AccessControl/classes/class.ilRbacLog.php";
819  if(ilRbacLog::isActive())
820  {
821  $rbac_log_roles = $rbacreview->getParentRoleIds($new_obj->getRefId(), false);
822  $rbac_log = ilRbacLog::gatherFaPa($new_obj->getRefId(), array_keys($rbac_log_roles), true);
823  ilRbacLog::add(ilRbacLog::COPY_OBJECT, $new_obj->getRefId(), $rbac_log, (int)$source_ref_id);
824  }
825  }
826 
827  unset($_SESSION["clipboard"]["ref_ids"]);
828  unset($_SESSION["clipboard"]["cmd"]);
829 
830  if (count($a_sources) == 1)
831  {
832  ilUtil::sendSuccess($this->lng->txt("object_duplicated"),true);
833  ilUtil::redirect(ilLink::_getLink($new_obj->getRefId()));
834  }
835  else
836  {
837  ilUtil::sendSuccess($this->lng->txt("objects_duplicated"),true);
839  }
840 
841  }
842 
843 
848  protected function copyContainer()
849  {
850  global $ilLog, $ilCtrl;
851 
852  include_once('./Services/Link/classes/class.ilLink.php');
853  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
854 
855  global $ilAccess,$ilErr,$rbacsystem,$tree,$ilUser,$ilCtrl;
856 
857  // Workaround for course in course copy
858 
860  $source_type = ilObject::_lookupType(ilObject::_lookupObjId($this->getSource()));
861 
862  if($target_type != $source_type or $target_type != 'crs')
863  {
864  if(!$rbacsystem->checkAccess('create', $this->getTarget(),$this->getType()))
865  {
866  ilUtil::sendFailure($this->lng->txt('permission_denied'),true);
867  $ilCtrl->returnToParent($this);
868  }
869  }
870  if(!$this->getSource())
871  {
872  ilUtil::sendFailure($this->lng->txt('select_one'),true);
873  $ilCtrl->returnToParent($this);
874  return false;
875  }
876 
877  $options = $_POST['cp_options'] ? $_POST['cp_options'] : array();
879  $result = $orig->cloneAllObject($_COOKIE['PHPSESSID'], $_COOKIE['ilClientId'], $this->getType(), $this->getTarget(), $this->getSource(), $options);
880 
881 
882  unset($_SESSION["clipboard"]["ref_ids"]);
883  unset($_SESSION["clipboard"]["cmd"]);
884 
885  // Check if copy is in progress
886  if ($result == $this->getTarget())
887  {
888  ilUtil::sendInfo($this->lng->txt("object_copy_in_progress"),true);
889  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
890  $this->getTarget());
891  $ilCtrl->redirectByClass("ilrepositorygui", "");
892  }
893  else
894  {
895  ilUtil::sendSuccess($this->lng->txt("object_duplicated"),true);
896  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
897  $result);
898  $ilCtrl->redirectByClass("ilrepositorygui", "");
899  }
900  }
901 
902 
903 
911  public function showSourceSearch($a_tplvar)
912  {
913  global $tpl;
914 
915  // Disabled for performance
916  #if(!$this->sourceExists())
917  #{
918  # return false;
919  #}
920 
921  $this->unsetSession();
922  $this->initFormSearch();
923 
924  if($a_tplvar)
925  {
926  $tpl->setVariable($a_tplvar,$this->form->getHTML());
927  }
928  else
929  {
930  return $this->form;
931  }
932  }
933 
934 
939  protected function sourceExists()
940  {
941  global $ilUser;
942 
943  return (bool) ilUtil::_getObjectsByOperations($this->getType(),'copy',$ilUser->getId(),1);
944  }
945 
950  protected function initFormSearch()
951  {
952  global $lng,$ilCtrl;
953 
954  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
955  $this->form = new ilPropertyFormGUI();
956  $this->form->setTableWidth('600px');
957  $ilCtrl->setParameter($this,'new_type',$this->getType());
958  #$ilCtrl->setParameter($this, 'cp_mode', self::SOURCE_SELECTION);
959  $this->form->setFormAction($ilCtrl->getFormAction($this));
960  $this->form->setTitle($lng->txt($this->getType().'_copy'));
961 
962  $this->form->addCommandButton('searchSource', $lng->txt('btn_next'));
963 
964  $tit = new ilTextInputGUI($lng->txt('title'),'tit');
965  $tit->setSize(40);
966  $tit->setMaxLength(70);
967  $tit->setRequired(true);
968  $tit->setInfo($lng->txt('wizard_title_info'));
969  $this->form->addItem($tit);
970  }
971 
976  protected function unsetSession()
977  {
978  unset($_SESSION['source_query']);
979  $this->setSource(0);
980  }
981 }
982 ?>