/** * Clone single (not container object) * Method is overwritten in ilContainerGUI * * @access public */ public function cloneAllObject() { include_once './Services/Link/classes/class.ilLink.php'; include_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php'; global $ilErr, $ilUser; $new_type = $_REQUEST['new_type']; if (!$this->checkPermissionBool("create", "", $new_type)) { $ilErr->raiseError($this->lng->txt('permission_denied')); } if (!(int) $_REQUEST['clone_source']) { ilUtil::sendFailure($this->lng->txt('select_one')); $this->createObject(); return false; } if (!$this->checkPermissionBool("write", "", $new_type, (int) $_REQUEST['clone_source'])) { $ilErr->raiseError($this->lng->txt('permission_denied')); } // Save wizard options $copy_id = ilCopyWizardOptions::_allocateCopyId(); $wizard_options = ilCopyWizardOptions::_getInstance($copy_id); $wizard_options->saveOwner($ilUser->getId()); $wizard_options->saveRoot((int) $_REQUEST['clone_source']); $options = $_POST['cp_options'] ? $_POST['cp_options'] : array(); foreach ($options as $source_id => $option) { $wizard_options->addEntry($source_id, $option); } $wizard_options->read(); $orig = ilObjectFactory::getInstanceByRefId((int) $_REQUEST['clone_source']); $new_obj = $orig->cloneObject((int) $_GET['ref_id'], $copy_id); // Delete wizard options $wizard_options->deleteAll(); ilUtil::sendSuccess($this->lng->txt("object_duplicated"), true); ilUtil::redirect(ilLink::_getLink($new_obj->getRefId())); }
/** * Move node: target has been selected, execute */ function performPasteIntoMultipleObjects() { global $objDefinition, $ilAccess, $ilUser; $mode = $_SESSION['clipboard']['cmd']; $source_node_id = $_SESSION['clipboard']['source_id']; $target_node_id = $_REQUEST['node']; if (!$source_node_id) { ilUtil::sendFailure($this->lng->txt('select_at_least_one_object'), true); $this->ctrl->redirect($this); } if (!$target_node_id) { ilUtil::sendFailure($this->lng->txt('select_at_least_one_object'), true); $this->ctrl->redirect($this, "showMoveIntoObjectTree"); } // object instances $source_obj_id = $this->tree->lookupObjectId($source_node_id); $source_object = ilObjectFactory::getInstanceByObjId($source_obj_id); if (!$_SESSION['clipboard']['wsp2repo']) { $target_obj_id = $this->tree->lookupObjectId($target_node_id); } else { $target_obj_id = ilObject::_lookupObjId($target_node_id); } $target_object = ilObjectFactory::getInstanceByObjId($target_obj_id); // sanity checks $fail = array(); if ($source_node_id == $target_node_id) { $fail[] = sprintf($this->lng->txt('msg_obj_exists_in_folder'), $source_object->getTitle(), $target_object->getTitle()); } if (!in_array($source_object->getType(), array_keys($objDefinition->getSubObjects($target_object->getType())))) { $fail[] = sprintf($this->lng->txt('msg_obj_may_not_contain_objects_of_type'), $target_object->getTitle(), $source_object->getType()); } // if object is shared permission to copy has been checked above $owner = $this->tree->lookupOwner($source_node_id); if ($mode == "copy" && $ilUser->getId() == $owner && !$this->checkPermissionBool('copy', '', '', $source_node_id)) { $fail[] = $this->lng->txt('permission_denied'); } if (!$_SESSION['clipboard']['wsp2repo']) { if ($mode == "cut" && $this->tree->isGrandChild($source_node_id, $target_node_id)) { $fail[] = sprintf($this->lng->txt('msg_paste_object_not_in_itself'), $source_object->getTitle()); } if (!$this->checkPermissionBool('create', '', $source_object->getType(), $target_node_id)) { $fail[] = sprintf($this->lng->txt('msg_no_perm_paste_object_in_folder'), $source_object->getTitle(), $target_object->getTitle()); } } else { if (!$ilAccess->checkAccess('create', '', $target_node_id, $source_object->getType())) { $fail[] = sprintf($this->lng->txt('msg_no_perm_paste_object_in_folder'), $source_object->getTitle(), $target_object->getTitle()); } } if (sizeof($fail)) { ilUtil::sendFailure(implode("<br />", $fail), true); $this->ctrl->redirect($this); } // move the node if ($mode == "cut") { if (!$_SESSION['clipboard']['wsp2repo']) { $this->tree->moveTree($source_node_id, $target_node_id); } else { $parent_id = $this->tree->getParentId($source_node_id); // remove from personal workspace $this->getAccessHandler()->removePermission($source_node_id); $this->tree->deleteReference($source_node_id); $source_node = $this->tree->getNodeData($source_node_id); $this->tree->deleteTree($source_node); // add to repository $source_object->createReference(); $source_object->putInTree($target_node_id); $source_object->setPermissions($target_node_id); $source_node_id = $parent_id; } } else { if ($mode == "copy") { include_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php'; $copy_id = ilCopyWizardOptions::_allocateCopyId(); $wizard_options = ilCopyWizardOptions::_getInstance($copy_id); $wizard_options->saveOwner($ilUser->getId()); $wizard_options->saveRoot($source_node_id); $wizard_options->read(); $new_obj = $source_object->cloneObject($target_node_id, $copy_id, !$_SESSION['clipboard']['wsp2repo']); // insert into workspace tree if ($new_obj && !$_SESSION['clipboard']['wsp2repo']) { $new_obj_node_id = $this->tree->insertObject($target_node_id, $new_obj->getId()); $this->getAccessHandler()->setPermissions($target_node_id, $new_obj_node_id); } $wizard_options->deleteAll(); } } // redirect to target if not repository if (!$_SESSION['clipboard']['wsp2repo']) { $redirect_node = $target_node_id; } else { // reload current folder $redirect_node = $this->node_id; } unset($_SESSION['clipboard']['cmd']); unset($_SESSION['clipboard']['source_id']); unset($_SESSION['clipboard']['wsp2repo']); unset($_SESSION['clipboard']['shared']); ilUtil::sendSuccess($this->lng->txt('msg_cut_copied'), true); $this->ctrl->setParameter($this, "wsp_id", $redirect_node); $this->ctrl->redirect($this); }
/** * copy object in repository * $sid session id * $settings_xml contains copy wizard settings following ilias_copy_wizard_settings.dtd */ function copyObject($sid, $copy_settings_xml) { $this->initAuth($sid); $this->initIlias(); if (!$this->__checkSession($sid)) { return $this->__raiseError($this->__getMessage(), $this->__getMessageCode()); } include_once './webservice/soap/classes/class.ilSoapUtils.php'; global $rbacreview, $objDefinition, $rbacsystem, $lng, $ilUser; include_once './webservice/soap/classes/class.ilCopyWizardSettingsXMLParser.php'; $xml_parser = new ilCopyWizardSettingsXMLParser($copy_settings_xml); try { $xml_parser->startParsing(); } catch (ilSaxParserException $se) { return $this->__raiseError($se->getMessage(), "Client"); } // checking copy permissions, objects and create permissions if (!$rbacsystem->checkAccess('copy', $xml_parser->getSourceId())) { return $this->__raiseError("Missing copy permissions for object with reference id " . $xml_parser->getSourceId(), 'Client'); } // checking copy permissions, objects and create permissions $source_id = $xml_parser->getSourceId(); $target_id = $xml_parser->getTargetId(); // does source object exist if (!($source_object_type = ilObjectFactory::getTypeByRefId($source_id, false))) { return $this->__raiseError('No valid source given.', 'Client'); } // does target object exist if (!($target_object_type = ilObjectFactory::getTypeByRefId($xml_parser->getTargetId(), false))) { return $this->__raiseError('No valid target given.', 'Client'); } $canAddType = $this->canAddType($source_object_type, $target_object_type, $target_id); if ($this->isFault($canAddType)) { return $canAddType; } // if is container object than clone with sub items $options = $xml_parser->getOptions(); // print_r($options); $source_object = ilObjectFactory::getInstanceByRefId($source_id); if ($source_object instanceof ilContainer) { // get client id from sid $clientid = substr($sid, strpos($sid, "::") + 2); $sessionid = str_replace("::" . $clientid, "", $sid); // call container clone return $source_object->cloneAllObject($sessionid, $clientid, $source_object_type, $target_id, $source_id, $options, true); } else { // create copy wizard settings $copy_id = ilCopyWizardOptions::_allocateCopyId(); $wizard_options = ilCopyWizardOptions::_getInstance($copy_id); $wizard_options->saveOwner($ilUser->getId()); $wizard_options->saveRoot($source_id); foreach ($options as $source_id => $option) { $wizard_options->addEntry($source_id, $option); } $wizard_options->read(); // call object clone $newObject = $source_object->cloneObject($xml_parser->getTargetId(), $copy_id); return is_object($newObject) ? $newObject->getRefId() : -1; } }
/** * clone all objects according to this container * * @param string $session_id * @param string $client_id * @param string $new_type * @param int $ref_id * @param int $clone_source * @param array $options * @return new refid if clone has finished or parameter ref id if cloning is still in progress */ public function cloneAllObject($session_id, $client_id, $new_type, $ref_id, $clone_source, $options, $soap_call = false) { global $ilLog; include_once './Services/Link/classes/class.ilLink.php'; include_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php'; global $ilAccess, $ilErr, $rbacsystem, $tree, $ilUser; // Save wizard options $copy_id = ilCopyWizardOptions::_allocateCopyId(); $wizard_options = ilCopyWizardOptions::_getInstance($copy_id); $wizard_options->saveOwner($ilUser->getId()); $wizard_options->saveRoot($clone_source); // add entry for source container $wizard_options->initContainer($clone_source, $ref_id); foreach ($options as $source_id => $option) { $wizard_options->addEntry($source_id, $option); } $wizard_options->read(); $wizard_options->storeTree($clone_source); // Special handling for course in existing courses if ($new_type == 'crs' and ilObject::_lookupType(ilObject::_lookupObjId($ref_id)) == 'crs') { $ilLog->write(__METHOD__ . ': Copy course in course...'); $ilLog->write(__METHOD__ . ': Added mapping, source ID: ' . $clone_source . ', target ID: ' . $ref_id); $wizard_options->read(); $wizard_options->dropFirstNode(); $wizard_options->appendMapping($clone_source, $ref_id); } #print_r($options); // Duplicate session to avoid logout problems with backgrounded SOAP calls $new_session_id = ilSession::_duplicate($session_id); // Start cloning process using soap call include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php'; $soap_client = new ilSoapClient(); $soap_client->setResponseTimeout(30); $soap_client->enableWSDL(true); $ilLog->write(__METHOD__ . ': Trying to call Soap client...'); if ($soap_client->init()) { $ilLog->write(__METHOD__ . ': Calling soap clone method...'); $res = $soap_client->call('ilClone', array($new_session_id . '::' . $client_id, $copy_id)); } else { $ilLog->write(__METHOD__ . ': SOAP call failed. Calling clone method manually. '); $wizard_options->disableSOAP(); $wizard_options->read(); include_once './webservice/soap/include/inc.soap_functions.php'; $res = ilSoapFunctions::ilClone($new_session_id . '::' . $client_id, $copy_id); } // Check if copy is in progress or if this has been called by soap (don't wait for finishing) if ($soap_call || ilCopyWizardOptions::_isFinished($copy_id)) { return $res; } else { return $ref_id; } }
/** * Start cloning a single (not container) object * @return */ protected function copySingleObject() { include_once './Services/Link/classes/class.ilLink.php'; include_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php'; global $ilAccess, $ilErr, $rbacsystem, $ilUser, $ilCtrl, $rbacreview; // Create permission if (!$rbacsystem->checkAccess('create', $this->getTarget(), $this->getType())) { ilUtil::sendFailure($this->lng->txt('permission_denied'), true); $ilCtrl->returnToParent($this); } // Source defined if (!$this->getSource()) { ilUtil::sendFailure($this->lng->txt('select_one'), true); $ilCtrl->returnToParent($this); } // Copy permission if (!$ilAccess->checkAccess('copy', '', $this->getSource())) { ilUtil::sendFailure($this->lng->txt('permission_denied'), true); $ilCtrl->returnToParent($this); } // Save wizard options $copy_id = ilCopyWizardOptions::_allocateCopyId(); $wizard_options = ilCopyWizardOptions::_getInstance($copy_id); $wizard_options->saveOwner($ilUser->getId()); $wizard_options->saveRoot((int) $this->getSource()); /* $options = $_POST['cp_options'] ? $_POST['cp_options'] : array(); foreach($options as $source_id => $option) { $wizard_options->addEntry($source_id,$option); } */ $wizard_options->read(); $orig = ilObjectFactory::getInstanceByRefId((int) $this->getSource()); $new_obj = $orig->cloneObject($this->getTarget(), $copy_id); // Delete wizard options $wizard_options->deleteAll(); // rbac log include_once "Services/AccessControl/classes/class.ilRbacLog.php"; if (ilRbacLog::isActive()) { $rbac_log_roles = $rbacreview->getParentRoleIds($new_obj->getRefId(), false); $rbac_log = ilRbacLog::gatherFaPa($new_obj->getRefId(), array_keys($rbac_log_roles), true); ilRbacLog::add(ilRbacLog::COPY_OBJECT, $new_obj->getRefId(), $rbac_log, (int) $this->getSource()); } ilUtil::sendSuccess($this->lng->txt("object_duplicated"), true); ilUtil::redirect(ilLink::_getLink($new_obj->getRefId())); }
/** * Copy multiple non container * * @param array $a_sources array of source ref ids */ function copyMultipleNonContainer($a_sources) { global $ilAccess, $objDefinition, $rbacsystem, $ilUser, $ilCtrl, $rbacreview; include_once './Services/Link/classes/class.ilLink.php'; include_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php'; // check permissions foreach ($a_sources as $source_ref_id) { $source_type = ilObject::_lookupType($source_ref_id, true); // Create permission if (!$rbacsystem->checkAccess('create', $this->getTarget(), $source_type)) { ilUtil::sendFailure($this->lng->txt('permission_denied'), true); $ilCtrl->returnToParent($this); } // Copy permission if (!$ilAccess->checkAccess('copy', '', $source_ref_id)) { ilUtil::sendFailure($this->lng->txt('permission_denied'), true); $ilCtrl->returnToParent($this); } // check that these objects are really not containers if ($objDefinition->isContainer($source_type)) { ilUtil::sendFailure($this->lng->txt('cntr_container_only_on_their_own'), true); $ilCtrl->returnToParent($this); } } reset($a_sources); // clone foreach ($a_sources as $source_ref_id) { // Save wizard options $copy_id = ilCopyWizardOptions::_allocateCopyId(); $wizard_options = ilCopyWizardOptions::_getInstance($copy_id); $wizard_options->saveOwner($ilUser->getId()); $wizard_options->saveRoot((int) $source_ref_id); $wizard_options->read(); $orig = ilObjectFactory::getInstanceByRefId((int) $source_ref_id); $new_obj = $orig->cloneObject($this->getTarget(), $copy_id); // Delete wizard options $wizard_options->deleteAll(); // rbac log include_once "Services/AccessControl/classes/class.ilRbacLog.php"; if (ilRbacLog::isActive()) { $rbac_log_roles = $rbacreview->getParentRoleIds($new_obj->getRefId(), false); $rbac_log = ilRbacLog::gatherFaPa($new_obj->getRefId(), array_keys($rbac_log_roles), true); ilRbacLog::add(ilRbacLog::COPY_OBJECT, $new_obj->getRefId(), $rbac_log, (int) $source_ref_id); } } unset($_SESSION["clipboard"]["ref_ids"]); unset($_SESSION["clipboard"]["cmd"]); if (count($a_sources) == 1) { ilUtil::sendSuccess($this->lng->txt("object_duplicated"), true); ilUtil::redirect(ilLink::_getLink($new_obj->getRefId())); } else { ilUtil::sendSuccess($this->lng->txt("objects_duplicated"), true); ilUtil::redirect(ilLink::_getLink($this->getTarget())); } }