/** * handler for begin of element * * @param resource $a_xml_parser xml parser * @param string $a_name element name * @param array $a_attribs element attributes array */ function handlerBeginTag($a_xml_parser, $a_name, $a_attribs) { global $objDefinition, $ilAccess, $tree; switch ($a_name) { case 'Settings': $this->options = array(); $this->source_id = (int) $a_attribs["source_id"]; if (ilObject::_isInTrash($this->source_id)) { throw new ilSaxParserException("Source id " . $this->source_id . " is in trash"); } $this->target_id = (int) $a_attribs["target_id"]; if (ilObject::_isInTrash($this->target_id)) { throw new ilSaxParserException("target id" . $this->target_id . " is in trash"); } $this->default_action = ilCopyWizardSettingsXMLParser::getActionForString($a_attribs["default_action"]); break; case 'Option': $id = (int) $a_attribs["id"]; if (ilObject::_isInTrash($id)) { throw new ilSaxParserException("Id {$id} is in trash"); } if (!$tree->isInTree($id)) { throw new ilSaxParserException("Id {$id} does not exist"); } $action = ilCopyWizardSettingsXMLParser::getActionForString($a_attribs["action"]); $type = ilObjectFactory::getTypeByRefId($id); switch ($action) { case ilCopyWizardOptions::COPY_WIZARD_COPY: $perm_copy = $ilAccess->checkAccess('copy', '', $id); $copy = $objDefinition->allowCopy($type); if ($perm_copy && $copy) { $this->options[$id] = array("type" => $action); } elseif ($copy && !$perm_copy) { throw new ilSaxParserException("Missing copy permission for object " . $id); } elseif (!$copy) { throw new ilSaxParserException("Copy for object " . $id . " of type " . $type . " is not supported"); } break; case ilCopyWizardOptions::COPY_WIZARD_LINK: $perm_link = $ilAccess->checkAccess('write', '', $id); $link = $objDefinition->allowLink($type); if ($perm_link && $link) { $this->options[$id] = array("type" => $action); } elseif ($copy && !$perm_link) { throw new ilSaxParserException("Missing write permission for object " . $id); } elseif (!$link) { throw new ilSaxParserException("Link for object " . $id . " of type " . $type . " is not supported"); } break; } } }
/** * 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; } }