/** * handler for begin of element */ function verifyBeginTag($a_xml_parser, $a_name, $a_attribs) { global $lng; switch ($a_name) { case "Role": if (is_null($a_attribs['Id']) || $a_attribs['Id'] == "") { $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_missing"), "Role", "Id")); } $this->current_role_id = $a_attribs["Id"]; $this->current_role_type = $a_attribs["Type"]; if ($this->current_role_type != 'Global' && $this->current_role_type != 'Local') { $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_missing"), "Role", "Type")); } $this->current_role_action = is_null($a_attribs["Action"]) ? "Assign" : $a_attribs["Action"]; if ($this->current_role_action != "Assign" && $this->current_role_action != "AssignWithParents" && $this->current_role_action != "Detach") { $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "Role", "Action", $a_attribs["Action"])); } if ($this->action == "Insert" && $this->current_role_action == "Detach") { $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_inapplicable"), "Role", "Action", $this->current_role_action, $this->action)); } if ($this->action == "Delete") { $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_inapplicable"), "Role", "Delete")); } break; case "User": $this->userCount++; $this->userObj = new ilObjUser(); $this->userObj->setLanguage($a_attribs["Language"]); $this->userObj->setImportId($a_attribs["Id"]); $this->currentPrefKey = null; // if we have an object id, store it $this->user_id = -1; if (!is_null($a_attribs["Id"]) && $this->getUserMappingMode() == IL_USER_MAPPING_ID) { if (is_numeric($a_attribs["Id"])) { $this->user_id = $a_attribs["Id"]; } elseif ($id = ilUtil::__extractId($a_attribs["Id"], IL_INST_ID)) { $this->user_id = $id; } } $this->action = is_null($a_attribs["Action"]) ? "Insert" : $a_attribs["Action"]; if ($this->action != "Insert" && $this->action != "Update" && $this->action != "Delete") { $this->logFailure($this->userObj->getImportId(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "User", "Action", $a_attribs["Action"])); } $this->currPassword = null; $this->currPasswordType = null; break; case "Password": $this->currPasswordType = $a_attribs["Type"]; break; case "AuthMode": if (array_key_exists("type", $a_attribs)) { switch ($a_attribs["type"]) { case "default": case "local": case "ldap": case "radius": case "shibboleth": case "script": case "cas": case "soap": case "openid": $this->userObj->setAuthMode($a_attribs["type"]); break; default: $this->logFailure($this->userObj->getImportId(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "AuthMode", "type", $a_attribs["type"])); break; } } else { $this->logFailure($this->userObj->getImportId(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "AuthMode", "type", "")); } break; case 'Pref': $this->currentPrefKey = $a_attribs["key"]; break; } }
/** * return user data for given user ids * * @param array of internal ids or numerics $a_internalids */ public static function _getUserData($a_internalids) { global $ilDB; $ids = array(); if (is_array($a_internalids)) { foreach ($a_internalids as $internalid) { if (is_numeric($internalid)) { $ids[] = $internalid; } else { $parsedid = ilUtil::__extractId($internalid, IL_INST_ID); if (is_numeric($parsedid) && $parsedid > 0) { $ids[] = $parsedid; } } } } if (count($ids) == 0) { $ids[] = -1; } $query = "SELECT usr_data.*, usr_pref.value AS language\n\t\t FROM usr_data\n\t\t LEFT JOIN usr_pref\n\t\t ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s\n\t\t WHERE " . $ilDB->in("usr_data.usr_id", $ids, false, "integer"); $values[] = "language"; $types[] = "text"; $query .= " ORDER BY usr_data.lastname, usr_data.firstname "; $data = array(); $result = $ilDB->queryF($query, $types, $values); while ($row = $ilDB->fetchAssoc($result)) { $data[] = $row; } return $data; }
function __save() { if ($this->group_imported) { return true; } $this->__initGroupObject(); $this->group_obj->setImportId($this->group_data["id"]); $this->group_obj->setTitle($this->group_data["title"]); $this->group_obj->setDescription($this->group_data["description"]); $ownerChanged = false; if (isset($this->group_data["owner"])) { $owner = $this->group_data["owner"]; if (!is_numeric($owner)) { $owner = ilUtil::__extractId($owner, IL_INST_ID); } if (is_numeric($owner) && $owner > 0) { $this->group_obj->setOwner($owner); $ownerChanged = true; } } /** * mode can be create or update */ if ($this->mode == ilGroupXMLParser::$CREATE) { $this->group_obj->create(); $this->group_obj->createReference(); $this->group_obj->putInTree($this->__getParentId()); $this->group_obj->setPermissions($this->__getParentId()); $this->group_obj->initGroupStatus($this->group_data["type"] == "open" ? GRP_TYPE_PUBLIC : GRP_TYPE_CLOSED); } else { switch ($this->group_data['type']) { case 'open': $grp_status = GRP_TYPE_PUBLIC; break; case 'closed': $grp_status = GRP_TYPE_CLOSED; break; } $this->group_obj->updateOwner(); if ($this->group_obj->getGroupStatus() != $grp_status) { $this->group_obj->setGroupType($grp_status); $this->group_obj->updateGroupType(); } } // SET GROUP SPECIFIC DATA switch ($this->group_data['registration_type']) { case 'direct': case 'enabled': $flag = GRP_REGISTRATION_DIRECT; break; case 'disabled': $flag = GRP_REGISTRATION_DEACTIVATED; break; case 'confirmation': $flag = GRP_REGISTRATION_REQUEST; break; case 'password': $flag = GRP_REGISTRATION_PASSWORD; break; default: $flag = GRP_REGISTRATION_DIRECT; } $this->group_obj->setRegistrationType($flag); $end = new ilDateTime(time(), IL_CAL_UNIX); if ($this->group_data['expiration_end']) { $end = new ilDateTime($this->group_data['expiration_end'], IL_CAL_UNIX); } $start = clone $end; if ($this->group_data['expiration_start']) { $start = new ilDateTime($this->group_data['expiration_start'], IL_CAL_UNIX); } $this->group_obj->setRegistrationStart($start); $this->group_obj->setRegistrationEnd($end); $this->group_obj->setPassword($this->group_data['password']); $this->group_obj->enableUnlimitedRegistration(!isset($this->group_data['expiration_end'])); $this->group_obj->enableMembershipLimitation($this->group_data['max_members_enabled']); $this->group_obj->setMaxMembers($this->group_data['max_members'] ? $this->group_data['max_members'] : 0); $this->group_obj->enableWaitingList($this->group_data['waiting_list_enabled']); if ($this->mode == ilGroupXMLParser::$CREATE) { $this->group_obj->initGroupStatus($this->group_data["type"] == "open" ? 0 : 1); } $this->group_obj->update(); // ASSIGN ADMINS/MEMBERS $this->__assignMembers(); $this->__pushParentId($this->group_obj->getRefId()); $this->group_imported = true; return true; }
/** * * define ("IL_FAIL_ON_CONFLICT", 1); * define ("IL_UPDATE_ON_CONFLICT", 2); * define ("IL_IGNORE_ON_CONFLICT", 3); */ function importUsers($sid, $folder_id, $usr_xml, $conflict_rule, $send_account_mail) { $this->initAuth($sid); $this->initIlias(); if (!$this->__checkSession($sid)) { return $this->__raiseError($this->__getMessage(), $this->__getMessageCode()); } include_once './Services/User/classes/class.ilUserImportParser.php'; include_once './Services/AccessControl/classes/class.ilObjRole.php'; include_once './Services/Object/classes/class.ilObjectFactory.php'; global $rbacreview, $rbacsystem, $tree, $lng, $ilUser, $ilLog; // this takes time but is nescessary $error = false; // validate to prevent wrong XMLs $this->dom = @domxml_open_mem($usr_xml, DOMXML_LOAD_VALIDATING, $error); if ($error) { $msg = array(); if (is_array($error)) { foreach ($error as $err) { $msg[] = "(" . $err["line"] . "," . $err["col"] . "): " . $err["errormessage"]; } } else { $msg[] = $error; } $msg = join("\n", $msg); return $this->__raiseError($msg, "Client"); } switch ($conflict_rule) { case 2: $conflict_rule = IL_UPDATE_ON_CONFLICT; break; case 3: $conflict_rule = IL_IGNORE_ON_CONFLICT; break; default: $conflict_rule = IL_FAIL_ON_CONFLICT; } // folder id 0, means to check permission on user basis! // must have create user right in time_limit_owner property (which is ref_id of container) if ($folder_id != 0) { // determine where to import if ($folder_id == -1) { $folder_id = USER_FOLDER_ID; } // get folder $import_folder = ilObjectFactory::getInstanceByRefId($folder_id, false); // id does not exist if (!$import_folder) { return $this->__raiseError('Wrong reference id.', 'Server'); } // folder is not a folder, can also be a category if ($import_folder->getType() != "usrf" && $import_folder->getType() != "cat") { return $this->__raiseError('Folder must be a usr folder or a category.', 'Server'); } // check access to folder if (!$rbacsystem->checkAccess('create_usr', $folder_id)) { return $this->__raiseError('Missing permission for creating users within ' . $import_folder->getTitle(), 'Server'); } } // first verify $importParser = new ilUserImportParser("", IL_VERIFY, $conflict_rule); $importParser->setUserMappingMode(IL_USER_MAPPING_ID); $importParser->setXMLContent($usr_xml); $importParser->startParsing(); switch ($importParser->getErrorLevel()) { case IL_IMPORT_SUCCESS: break; case IL_IMPORT_WARNING: return $this->__getImportProtocolAsXML($importParser->getProtocol("User Import Log - Warning")); break; case IL_IMPORT_FAILURE: return $this->__getImportProtocolAsXML($importParser->getProtocol("User Import Log - Failure")); } // verify is ok, so get role assignments $importParser = new ilUserImportParser("", IL_EXTRACT_ROLES, $conflict_rule); $importParser->setXMLContent($usr_xml); $importParser->setUserMappingMode(IL_USER_MAPPING_ID); $importParser->startParsing(); $roles = $importParser->getCollectedRoles(); //print_r($roles); // roles to be assigned, skip if one is not allowed! $permitted_roles = array(); foreach ($roles as $role_id => $role) { if (!is_numeric($role_id)) { // check if internal id $internalId = ilUtil::__extractId($role_id, IL_INST_ID); if (is_numeric($internalId)) { $role_id = $internalId; $role_name = $role_id; } /* else // perhaps it is a rolename { $role = ilSoapUserAdministration::__getRoleForRolename ($role_id); $role_name = $role->title; $role_id = $role->role_id; }*/ } if ($this->isPermittedRole($folder_id, $role_id)) { $permitted_roles[$role_id] = $role_id; } else { $role_name = ilObject::_lookupTitle($role_id); return $this->__raiseError("Could not find role " . $role_name . ". Either you use an invalid/deleted role " . "or you try to assign a local role into the non-standard user folder and this role is not in its subtree.", 'Server'); } } $global_roles = $rbacreview->getGlobalRoles(); //print_r ($global_roles); foreach ($permitted_roles as $role_id => $role_name) { if ($role_id != "") { if (in_array($role_id, $global_roles)) { if ($role_id == SYSTEM_ROLE_ID && !in_array(SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId())) || $folder_id != USER_FOLDER_ID && $folder_id != 0 && !ilObjRole::_getAssignUsersStatus($role_id)) { return $this->__raiseError($lng->txt("usrimport_with_specified_role_not_permitted") . " {$role_name} ({$role_id})", 'Server'); } } else { $rolf = $rbacreview->getFoldersAssignedToRole($role_id, true); if ($rbacreview->isDeleted($rolf[0]) || !$rbacsystem->checkAccess('write', $tree->getParentId($rolf[0]))) { return $this->__raiseError($lng->txt("usrimport_with_specified_role_not_permitted") . " {$role_name} ({$role_id})", "Server"); } } } } //print_r ($permitted_roles); $importParser = new ilUserImportParser("", IL_USER_IMPORT, $conflict_rule); $importParser->setSendMail($send_account_mail); $importParser->setUserMappingMode(IL_USER_MAPPING_ID); $importParser->setFolderId($folder_id); $importParser->setXMLContent($usr_xml); $importParser->setRoleAssignment($permitted_roles); $importParser->startParsing(); if ($importParser->getErrorLevel() != IL_IMPORT_FAILURE) { return $this->__getUserMappingAsXML($importParser->getUserMapping()); } return $this->__getImportProtocolAsXML($importParser->getProtocol()); }
private function parseUserID($id, $role_type) { if (strcasecmp($role_type, "user") == 0) { $user_id = !is_numeric($id) ? ilUtil::__extractId($id, IL_INST_ID) : $id; if (!is_numeric($user_id)) { return $this->__raiseError('ID must be either numeric or ILIAS conform id for type \'user\'', 'Client'); } } elseif (strcasecmp($role_type, "user_login") == 0) { $user_id = ilObjUser::_lookupId($id); if (!$user_id) { return $this->__raiseError('User with login \'' . $id . '\' does not exist!', 'Client'); } } return $user_id; }
/** * 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 * @throws ilFileException when obj id != - 1 and if it it does not match the id in the xml * or deflation mode is not supported */ function handlerBeginTag($a_xml_parser, $a_name, $a_attribs) { global $ilErr; global $ilLog; switch ($a_name) { case 'File': if (isset($a_attribs["obj_id"])) { $read_obj_id = ilUtil::__extractId($a_attribs["obj_id"], IL_INST_ID); if ($this->obj_id != -1 && (int) $read_obj_id != -1 && (int) $this->obj_id != (int) $read_obj_id) { throw new ilFileException("Object IDs (xml {$read_obj_id} and argument " . $this->obj_id . ") do not match!", ilFileException::$ID_MISMATCH); } } if (isset($a_attribs["type"])) { $this->file->setFileType($a_attribs["type"]); } $this->file->setVersion($this->file->getVersion() + 1); break; case 'Content': $this->tmpFilename = ilUtil::ilTempnam(); $this->mode = ilFileXMLParser::$CONTENT_NOT_COMPRESSED; $this->isReadingFile = true; #echo $a_attribs["mode"]; if (isset($a_attribs["mode"])) { if ($a_attribs["mode"] == "GZIP") { if (!function_exists("gzread")) { throw new ilFileException("Deflating with gzip is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH); } $this->mode = ilFileXMLParser::$CONTENT_GZ_COMPRESSED; } elseif ($a_attribs["mode"] == "ZLIB") { if (!function_exists("gzuncompress")) { throw new ilFileException("Deflating with zlib (compress/uncompress) is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH); } $this->mode = ilFileXMLParser::$CONTENT_ZLIB_COMPRESSED; } elseif ($a_attribs["mode"] == "COPY") { $this->mode = ilFileXMLParser::$CONTENT_COPY; } elseif ($a_attribs['mode'] == 'REST') { $this->mode = ilFileXMLParser::$CONTENT_REST; } // end-patch fm } } }
/** * 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) { switch ($a_name) { case 'Objects': $this->curr_obj = -1; break; case 'Object': ++$this->curr_obj; $this->__addProperty('type', $a_attribs['type']); $this->__addProperty('obj_id', is_numeric($a_attribs['obj_id']) ? (int) $a_attribs["obj_id"] : ilUtil::__extractId($a_attribs["obj_id"], IL_INST_ID)); break; case 'Title': break; case 'Description': break; case 'Owner': break; case 'CreateDate': break; case 'LastUpdate': break; case 'ImportId': break; case 'References': $this->time_target = array(); $this->ref_id = $a_attribs["ref_id"]; $this->parent_id = $a_attribs['parent_id']; break; case 'TimeTarget': $this->time_target['timing_type'] = $a_attribs['type']; break; case 'Timing': $this->time_target['timing_visibility'] = $a_attribs['visibility']; if (isset($a_attribs['starting_time'])) { $this->time_target['starting_time'] = $a_attribs['starting_time']; } if (isset($a_attribs['ending_time'])) { $this->time_target['ending_time'] = $a_attribs['ending_time']; } if ($a_attribs['ending_time'] < $a_attribs['starting_time']) { throw new ilObjectXMLException('Starting time must be earlier than ending time.'); } break; case 'Suggestion': $this->time_target['changeable'] = $a_attribs['changeable']; if (isset($a_attribs['starting_time'])) { $this->time_target['suggestion_start'] = $a_attribs['starting_time']; } if (isset($a_attribs['ending_time'])) { $this->time_target['suggestion_end'] = $a_attribs['ending_time']; } if (isset($a_attribs['earliest_start'])) { $this->time_target['earliest_start'] = $a_attribs['earliest_start']; } if (isset($a_attribs['latest_end'])) { $this->time_target['latest_end'] = $a_attribs['latest_end']; } if ($a_attribs['latest_end'] < $a_attribs['earliest_start']) { throw new ilObjectXMLException('Earliest start time must be earlier than latest ending time.'); } if ($a_attribs['ending_time'] < $a_attribs['starting_time']) { throw new ilObjectXMLException('Starting time must be earlier than ending time.'); } break; } }
/** * 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 * @throws ilExerciseException when obj id != - 1 and if it it does not match the id in the xml */ function handlerBeginTag($a_xml_parser, $a_name, $a_attribs) { global $ilErr; switch ($a_name) { case 'Exercise': if (isset($a_attribs["obj_id"])) { $read_obj_id = ilUtil::__extractId($a_attribs["obj_id"], IL_INST_ID); if ($this->obj_id != -1 && (int) $read_obj_id != -1 && (int) $this->obj_id != (int) $read_obj_id) { throw new ilExerciseException("Object IDs (xml {$read_obj_id} and argument " . $this->obj_id . ") do not match!", ilExerciseException::$ID_MISMATCH); } } break; case 'Member': $this->usr_action = $a_attribs["action"]; $this->usr_id = ilUtil::__extractId($a_attribs["usr_id"], IL_INST_ID); break; case 'File': $this->file_action = $a_attribs["action"]; break; case 'Content': $this->mode = ilExerciseXMLParser::$CONTENT_NOT_COMPRESSED; if ($a_attribs["mode"] == "GZIP") { if (!function_exists("gzdecode")) { throw new ilExerciseException("Deflating with gzip is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH); } $this->mode = ilExerciseXMLParser::$CONTENT_GZ_COMPRESSED; } elseif ($a_attribs["mode"] == "ZLIB") { if (!function_exists("gzuncompress")) { throw new ilExerciseException("Deflating with zlib (compress/uncompress) is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH); } $this->mode = ilExerciseXMLParser::$CONTENT_ZLIB_COMPRESSED; } break; case 'Marking': $this->status = $a_attribs["status"]; if ($this->status == ilExerciseXMLWriter::$STATUS_NOT_GRADED) { $this->status = "notgraded"; } elseif ($this->status == ilExerciseXMLWriter::$STATUS_PASSED) { $this->status = "passed"; } else { $this->status = "failed"; } break; } }