public function performPasteIntoMultipleObjectsObject() { global $rbacsystem, $rbacadmin, $rbacreview, $log, $tree, $ilObjDataCache, $ilUser; $command = $_SESSION['clipboard']['cmd']; if (!in_array($command, array('cut', 'link', 'copy'))) { $message = __METHOD__ . ": cmd was neither 'cut', 'link' nor 'copy'; may be a hack attempt!"; $this->ilias->raiseError($message, $this->ilias->error_obj->WARNING); } if ($command == 'cut') { if (isset($_POST['node']) && (int) $_POST['node']) { $_POST['nodes'] = array($_POST['node']); } } if (!is_array($_POST['nodes']) || !count($_POST['nodes'])) { ilUtil::sendFailure($this->lng->txt('select_at_least_one_object')); switch ($command) { case 'cut': $this->showPasteTreeObject(); break; case 'copy': $this->showPasteTreeObject(); break; case 'link': $this->showPasteTreeObject(); break; } return; } // this loop does all checks $folder_objects_cache = array(); foreach ($_SESSION['clipboard']['ref_ids'] as $ref_id) { $obj_data = ilObjectFactory::getInstanceByRefId($ref_id); $current_parent_id = $tree->getParentId($obj_data->getRefId()); foreach ($_POST['nodes'] as $folder_ref_id) { if (!array_key_exists($folder_ref_id, $folder_objects_cache)) { $folder_objects_cache[$folder_ref_id] = ilObjectFactory::getInstanceByRefId($folder_ref_id); } // CHECK ACCESS if (!$rbacsystem->checkAccess('create', $folder_ref_id, $obj_data->getType())) { $no_paste[] = sprintf($this->lng->txt('msg_no_perm_paste_object_in_folder'), $obj_data->getTitle() . ' [' . $obj_data->getRefId() . ']', $folder_objects_cache[$folder_ref_id]->getTitle() . ' [' . $folder_objects_cache[$folder_ref_id]->getRefId() . ']'); } // CHECK IF REFERENCE ALREADY EXISTS if ($folder_ref_id == $current_parent_id) { $exists[] = sprintf($this->lng->txt('msg_obj_exists_in_folder'), $obj_data->getTitle() . ' [' . $obj_data->getRefId() . ']', $folder_objects_cache[$folder_ref_id]->getTitle() . ' [' . $folder_objects_cache[$folder_ref_id]->getRefId() . ']'); } // CHECK IF PASTE OBJECT SHALL BE CHILD OF ITSELF if ($tree->isGrandChild($ref_id, $folder_ref_id) || $ref_id == $folder_ref_id) { $is_child[] = sprintf($this->lng->txt('msg_paste_object_not_in_itself'), $obj_data->getTitle() . ' [' . $obj_data->getRefId() . ']'); } // CHECK IF OBJECT IS ALLOWED TO CONTAIN PASTED OBJECT AS SUBOBJECT if (!in_array($obj_data->getType(), array_keys($this->objDefinition->getSubObjects($folder_objects_cache[$folder_ref_id]->getType())))) { $not_allowed_subobject[] = sprintf($this->lng->txt('msg_obj_may_not_contain_objects_of_type'), $folder_objects_cache[$folder_ref_id]->getTitle() . ' [' . $folder_objects_cache[$folder_ref_id]->getRefId() . ']', $GLOBALS['lng']->txt('obj_' . $obj_data->getType())); } } } //////////////////////////// // process checking results if (count($exists) && $command != "copy") { $error .= implode('<br />', $exists); } if (count($is_child)) { $error .= $error != '' ? '<br />' : ''; $error .= implode('<br />', $is_child); } if (count($not_allowed_subobject)) { $error .= $error != '' ? '<br />' : ''; $error .= implode('<br />', $not_allowed_subobject); } if (count($no_paste)) { $error .= $error != '' ? '<br />' : ''; $error .= implode('<br />', $no_paste); } if ($error != '') { ilUtil::sendFailure($error); switch ($command) { case 'cut': $this->showPasteTreeObject(); break; case 'copy': $this->showPasteTreeObject(); break; case 'link': $this->showPasteTreeObject(); break; } return; } // log pasteObject call $log->write(__METHOD__ . ", cmd: " . $command); //////////////////////////////////////////////////////// // everything ok: now paste the objects to new location // to prevent multiple actions via back/reload button $ref_ids = $_SESSION['clipboard']['ref_ids']; unset($_SESSION['clipboard']['ref_ids']); // BEGIN ChangeEvent: Record paste event. require_once 'Services/Tracking/classes/class.ilChangeEvent.php'; // END ChangeEvent: Record paste event. // process COPY command if ($command == 'copy') { foreach ($_POST['nodes'] as $folder_ref_id) { foreach ($ref_ids as $ref_id) { $revIdMapping = array(); $oldNode_data = $tree->getNodeData($ref_id); if ($oldNode_data['parent'] == $folder_ref_id) { require_once 'Modules/File/classes/class.ilObjFileAccess.php'; $newTitle = ilObjFileAccess::_appendNumberOfCopyToFilename($oldNode_data['title'], null); $newRef = $this->cloneNodes($ref_id, $folder_ref_id, $refIdMapping, $newTitle); } else { $newRef = $this->cloneNodes($ref_id, $folder_ref_id, $refIdMapping, null); } // BEGIN ChangeEvent: Record copy event. $old_parent_data = $tree->getParentNodeData($ref_id); $newNode_data = $tree->getNodeData($newRef); ilChangeEvent::_recordReadEvent($oldNode_data['type'], $ref_id, $oldNode_data['obj_id'], $ilUser->getId()); ilChangeEvent::_recordWriteEvent($newNode_data['obj_id'], $ilUser->getId(), 'add', $ilObjDataCache->lookupObjId($folder_ref_id)); ilChangeEvent::_catchupWriteEvents($newNode_data['obj_id'], $ilUser->getId()); // END PATCH ChangeEvent: Record cut event. } } ilUtil::sendSuccess($this->lng->txt('msg_cloned'), true); } // END COPY // process CUT command if ($command == 'cut') { foreach ($_POST['nodes'] as $folder_ref_id) { foreach ($ref_ids as $ref_id) { // Store old parent $old_parent = $tree->getParentId($ref_id); $tree->moveTree($ref_id, $folder_ref_id); $rbacadmin->adjustMovedObjectPermissions($ref_id, $old_parent); include_once './Services/AccessControl/classes/class.ilConditionHandler.php'; ilConditionHandler::_adjustMovedObjectConditions($ref_id); // BEGIN ChangeEvent: Record cut event. $node_data = $tree->getNodeData($ref_id); $old_parent_data = $tree->getNodeData($old_parent); ilChangeEvent::_recordWriteEvent($node_data['obj_id'], $ilUser->getId(), 'remove', $old_parent_data['obj_id']); ilChangeEvent::_recordWriteEvent($node_data['obj_id'], $ilUser->getId(), 'add', $ilObjDataCache->lookupObjId($folder_ref_id)); ilChangeEvent::_catchupWriteEvents($node_data['obj_id'], $ilUser->getId()); // END PATCH ChangeEvent: Record cut event. } // prevent multiple iterations for cut cmommand break; } ilUtil::sendSuccess($this->lng->txt('msg_cut_copied'), true); } // END CUT // process LINK command if ($command == 'link') { $linked_to_folders = array(); include_once "Services/AccessControl/classes/class.ilRbacLog.php"; $rbac_log_active = ilRbacLog::isActive(); foreach ($_POST['nodes'] as $folder_ref_id) { $linked_to_folders[] = $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($folder_ref_id)); foreach ($ref_ids as $ref_id) { // get node data $top_node = $tree->getNodeData($ref_id); // get subnodes of top nodes $subnodes[$ref_id] = $tree->getSubtree($top_node); } // now move all subtrees to new location foreach ($subnodes as $key => $subnode) { // first paste top_node.... $obj_data = ilObjectFactory::getInstanceByRefId($key); $new_ref_id = $obj_data->createReference(); $obj_data->putInTree($folder_ref_id); $obj_data->setPermissions($folder_ref_id); // rbac log if ($rbac_log_active) { $rbac_log_roles = $rbacreview->getParentRoleIds($new_ref_id, false); $rbac_log = ilRbacLog::gatherFaPa($new_ref_id, array_keys($rbac_log_roles), true); ilRbacLog::add(ilRbacLog::LINK_OBJECT, $new_ref_id, $rbac_log, $key); } // BEGIN ChangeEvent: Record link event. $node_data = $tree->getNodeData($new_ref_id); ilChangeEvent::_recordWriteEvent($node_data['obj_id'], $ilUser->getId(), 'add', $ilObjDataCache->lookupObjId($folder_ref_id)); ilChangeEvent::_catchupWriteEvents($node_data['obj_id'], $ilUser->getId()); // END PATCH ChangeEvent: Record link event. } $log->write(__METHOD__ . ', link finished'); } ilUtil::sendSuccess(sprintf($this->lng->txt('mgs_objects_linked_to_the_following_folders'), implode(', ', $linked_to_folders)), true); } // END LINK // clear clipboard $this->clearObject(); $this->ctrl->returnToParent($this); }
/** * Prepend Copy info if object with same name exists in that container * * @access public * @param int copy_id * */ public function appendCopyInfo($a_target_id, $a_copy_id) { global $tree; include_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php'; $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id); if (!$cp_options->isRootNode($this->getRefId())) { return $this->getTitle(); } $nodes = $tree->getChilds($a_target_id); $title_unique = false; require_once 'Modules/File/classes/class.ilObjFileAccess.php'; $numberOfCopy = 1; $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), $numberOfCopy); while (!$title_unique) { $found = 0; foreach ($nodes as $node) { if ($title == $node['title'] and $this->getType() == $node['type']) { $found++; } } if ($found > 0) { $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), ++$numberOfCopy); } else { break; } } return $title; }
/** * paste object from clipboard to current place * Depending on the chosen command the object(s) are linked, copied or moved * * @access public */ function pasteObject() { global $rbacsystem, $rbacadmin, $rbacreview, $log, $tree; global $ilUser, $lng; // BEGIN ChangeEvent: Record paste event. require_once 'Services/Tracking/classes/class.ilChangeEvent.php'; // END ChangeEvent: Record paste event. //var_dump($_SESSION["clipboard"]);exit; if (!in_array($_SESSION["clipboard"]["cmd"], array("cut", "link", "copy"))) { $message = get_class($this) . "::pasteObject(): cmd was neither 'cut','link' or 'copy'; may be a hack attempt!"; $this->ilias->raiseError($message, $this->ilias->error_obj->WARNING); } // this loop does all checks foreach ($_SESSION["clipboard"]["ref_ids"] as $ref_id) { $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($ref_id); // CHECK ACCESS if (!$rbacsystem->checkAccess('create', $this->object->getRefId(), $obj_data->getType())) { $no_paste[] = $ref_id; $no_paste_titles[] = $obj_data->getTitle(); } // CHECK IF REFERENCE ALREADY EXISTS if ($this->object->getRefId() == $this->tree->getParentId($obj_data->getRefId())) { $exists[] = $ref_id; break; } // CHECK IF PASTE OBJECT SHALL BE CHILD OF ITSELF if ($this->tree->isGrandChild($ref_id, $this->object->getRefId())) { $is_child[] = $ref_id; } // CHECK IF OBJECT IS ALLOWED TO CONTAIN PASTED OBJECT AS SUBOBJECT $obj_type = $obj_data->getType(); if (!in_array($obj_type, array_keys($this->objDefinition->getSubObjects($this->object->getType())))) { $not_allowed_subobject[] = $obj_data->getType(); } } //////////////////////////// // process checking results // BEGIN WebDAV: Copying an object into the same container is allowed if (count($exists) && $_SESSION["clipboard"]["cmd"] != "copy") { $this->ilias->raiseError($this->lng->txt("msg_obj_exists"), $this->ilias->error_obj->MESSAGE); } if (count($is_child)) { $this->ilias->raiseError($this->lng->txt("msg_not_in_itself") . " " . implode(',', $is_child), $this->ilias->error_obj->MESSAGE); } if (count($not_allowed_subobject)) { $this->ilias->raiseError($this->lng->txt("msg_may_not_contain") . " " . implode(',', $not_allowed_subobject), $this->ilias->error_obj->MESSAGE); } if (count($no_paste)) { $this->ilias->raiseError($this->lng->txt("msg_no_perm_paste") . " " . implode(',', $no_paste), $this->ilias->error_obj->MESSAGE); } // log pasteObject call $log->write("ilObjectGUI::pasteObject(), cmd: " . $_SESSION["clipboard"]["cmd"]); //////////////////////////////////////////////////////// // everything ok: now paste the objects to new location // to prevent multiple actions via back/reload button $ref_ids = $_SESSION["clipboard"]["ref_ids"]; unset($_SESSION["clipboard"]["ref_ids"]); // BEGIN WebDAV: Support a copy command in the repository // process COPY command if ($_SESSION["clipboard"]["cmd"] == "copy") { foreach ($ref_ids as $ref_id) { $revIdMapping = array(); $oldNode_data = $tree->getNodeData($ref_id); if ($oldNode_data['parent'] == $this->object->getRefId()) { require_once 'Modules/File/classes/class.ilObjFileAccess.php'; $newTitle = ilObjFileAccess::_appendNumberOfCopyToFilename($oldNode_data['title'], null); $newRef = $this->cloneNodes($ref_id, $this->object->getRefId(), $refIdMapping, $newTitle); } else { $newRef = $this->cloneNodes($ref_id, $this->object->getRefId(), $refIdMapping, null); } // BEGIN ChangeEvent: Record copy event. $old_parent_data = $tree->getParentNodeData($ref_id); $newNode_data = $tree->getNodeData($newRef); ilChangeEvent::_recordReadEvent($oldNode_data['type'], $ref_id, $oldNode_data['obj_id'], $ilUser->getId()); ilChangeEvent::_recordWriteEvent($newNode_data['obj_id'], $ilUser->getId(), 'add', $this->object->getId()); ilChangeEvent::_catchupWriteEvents($newNode_data['obj_id'], $ilUser->getId()); // END ChangeEvent: Record copy event. } $log->write("ilObjectGUI::pasteObject(), copy finished"); } // END WebDAV: Support a Copy command in the repository // process CUT command if ($_SESSION["clipboard"]["cmd"] == "cut") { foreach ($ref_ids as $ref_id) { // Store old parent $old_parent = $tree->getParentId($ref_id); $this->tree->moveTree($ref_id, $this->object->getRefId()); $rbacadmin->adjustMovedObjectPermissions($ref_id, $old_parent); include_once './Services/AccessControl/classes/class.ilConditionHandler.php'; ilConditionHandler::_adjustMovedObjectConditions($ref_id); // BEGIN ChangeEvent: Record cut event. $node_data = $tree->getNodeData($ref_id); $old_parent_data = $tree->getNodeData($old_parent); ilChangeEvent::_recordWriteEvent($node_data['obj_id'], $ilUser->getId(), 'remove', $old_parent_data['obj_id']); ilChangeEvent::_recordWriteEvent($node_data['obj_id'], $ilUser->getId(), 'add', $this->object->getId()); ilChangeEvent::_catchupWriteEvents($node_data['obj_id'], $ilUser->getId()); // END PATCH ChangeEvent: Record cut event. } } // END CUT // process LINK command if ($_SESSION["clipboard"]["cmd"] == "link") { foreach ($ref_ids as $ref_id) { // get node data $top_node = $this->tree->getNodeData($ref_id); // get subnodes of top nodes $subnodes[$ref_id] = $this->tree->getSubtree($top_node); } // now move all subtrees to new location foreach ($subnodes as $key => $subnode) { // first paste top_node.... $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($key); $new_ref_id = $obj_data->createReference(); $obj_data->putInTree($_GET["ref_id"]); $obj_data->setPermissions($_GET["ref_id"]); // BEGIN ChangeEvent: Record link event. $node_data = $tree->getNodeData($new_ref_id); ilChangeEvent::_recordWriteEvent($node_data['obj_id'], $ilUser->getId(), 'add', $this->object->getId()); ilChangeEvent::_catchupWriteEvents($node_data['obj_id'], $ilUser->getId()); // END PATCH ChangeEvent: Record link event. } $log->write("ilObjectGUI::pasteObject(), link finished"); // inform other objects in hierarchy about link operation //$this->object->notify("link",$this->object->getRefId(),$_SESSION["clipboard"]["parent_non_rbac_id"],$this->object->getRefId(),$subnodes); } // END LINK // save cmd for correct message output after clearing the clipboard $last_cmd = $_SESSION["clipboard"]["cmd"]; // clear clipboard $this->clearObject(); if ($last_cmd == "cut") { ilUtil::sendSuccess($this->lng->txt("msg_cut_copied"), true); } else { if ($last_cmd == "copy") { ilUtil::sendSuccess($this->lng->txt("msg_cloned"), true); } else { if ($last_command == 'link') { ilUtil::sendSuccess($this->lng->txt("msg_linked"), true); } } } $this->ctrl->returnToParent($this); }