ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilUserImportParser.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25use ILIAS\User\Profile\Data as ProfileData;
26use ILIAS\Refinery\Factory as Refinery;
27
29{
30 public const IL_EXTRACT_ROLES = 1;
31 public const IL_USER_IMPORT = 2;
32 public const IL_VERIFY = 3;
33
34 public const IL_FAIL_ON_CONFLICT = 1;
35 public const IL_UPDATE_ON_CONFLICT = 2;
36 public const IL_IGNORE_ON_CONFLICT = 3;
37
38 public const IL_IMPORT_SUCCESS = 1;
39 public const IL_IMPORT_WARNING = 2;
40 public const IL_IMPORT_FAILURE = 3;
41
42 private const IL_USER_MAPPING_LOGIN = 1;
43 public const IL_USER_MAPPING_ID = 2;
44
45 private ILIAS $ilias;
52
54
55 private ?string $tmp_udf_name = null;
56 private ?string $tmp_udf_id = null;
57 private array $multi_values; // Missing array type.
58 private array $udf_data; // Missing array type.
59 private bool $auth_mode_set;
60 private ?string $current_pref_key = null;
61 private array $prefs; // Missing array type.
62 private string $current_role_action;
63 private string $current_role_type;
64 private string $current_role_id = '0';
65 private string $cdata;
66 private array $role_assign; // Missing array type.
67 private string $req_send_mail;
69 private int $mode;
70 private bool $approve_date_set = false;
71 private bool $time_limit_set = false;
72 private bool $time_limit_owner_set = false;
73
74 private bool $update_look_and_skin = false;
75 private int $folder_id;
76 private array $roles; // Missing array type.
77 private string $action; // "Insert","Update","Delete"
78 private array $required_fields = []; // Missing array type.
79 private array $contained_tags = [];
80 private array $protocol;
81 private array $logins;
82 private int $conflict_rule;
83 private bool $send_mail;
84
146 private int $error_level;
148 private ?string $current_user_password;
149 private ?string $currActive = null;
150 private int $user_count;
155 private array $user_mapping = [];
156 private int $mapping_mode;
157 private array $local_role_cache;
161 private ?array $personal_picture = null;
162 private array $parent_roles_cache;
163 private string $skin = '';
164 private string $style = '';
168 private array $user_styles;
169
170 private int $user_id;
174 private Refinery $refinery;
175
181 public function __construct(
182 string $a_xml_file = '',
183 int $a_mode = self::IL_USER_IMPORT,
184 int $a_conflict_rule = self::IL_FAIL_ON_CONFLICT
185 ) {
187 global $DIC;
188 $this->ilias = $DIC['ilias'];
189 $this->settings = $DIC['ilSetting'];
190 $this->object_data_cache = $DIC['ilObjDataCache'];
191 $this->rbac_review = $DIC['rbacreview'];
192 $this->rbac_admin = $DIC['rbacadmin'];
193 $this->access = $DIC['ilAccess'];
194 $this->user = $DIC['ilUser'];
195 $this->refinery = $DIC['refinery'];
196 $this->req_send_mail = (new UserGUIRequest(
197 $DIC['http'],
198 $this->refinery
199 ))->getSendMail();
200
201 $this->user_profile = LocalDIC::dic()[Profile::class];
202
203 $this->roles = [];
204 $this->mode = $a_mode;
205 $this->conflict_rule = $a_conflict_rule;
206 $this->error_level = self::IL_IMPORT_SUCCESS;
207 $this->protocol = [];
208 $this->logins = [];
209 $this->user_count = 0;
210 $this->local_role_cache = [];
211 $this->parent_roles_cache = [];
212 $this->send_mail = false;
213 $this->mapping_mode = self::IL_USER_MAPPING_LOGIN;
214
215 // get all active style instead of only assigned ones -> cannot transfer all to another otherwise
216 $this->user_styles = [];
217 $skins = ilStyleDefinition::getAllSkins();
218
219 if (is_array($skins)) {
220 foreach ($skins as $skin) {
221 foreach ($skin->getStyles() as $style) {
223 continue;
224 }
225 $this->user_styles [] = $skin->getId() . ':' . $style->getId();
226 }
227 }
228 }
229
230 $this->acc_mail = new ilAccountMail();
231 $this->acc_mail->useLangVariablesAsFallback(true);
232
233 $this->recommended_content_manager = new ilRecommendedContentManager();
234
235 parent::__construct($a_xml_file);
236 }
237
242 public function setFolderId(int $a_folder_id): void
243 {
244 $this->folder_id = $a_folder_id;
245 }
246
247 public function getFolderId(): int
248 {
249 return $this->folder_id;
250 }
251
259 public function setHandlers($a_xml_parser): void
260 {
261 xml_set_element_handler($a_xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
262 xml_set_character_data_handler($a_xml_parser, $this->handlerCharacterData(...));
263 }
264
270 public function setRoleAssignment(array $a_assign): void
271 {
272 $this->role_assign = $a_assign;
273 }
274
278 public function buildTag(string $type, string $name, ?array $attr = null): string // Missing array type.
279 {
280 $tag = '<';
281
282 if ($type === 'end') {
283 $tag .= '/';
284 }
285
286 $tag .= $name;
287
288 if (is_array($attr)) {
289 foreach ($attr as $k => $v) {
290 $tag .= " {$k}='{$v}'";
291 }
292 }
293
294 $tag .= '>';
295
296 return $tag;
297 }
298
299 public function handlerBeginTag(
300 $a_xml_parser,
301 string $a_name,
302 array $a_attribs
303 ): void {
304 switch ($this->mode) {
306 $this->extractRolesBeginTag($a_xml_parser, $a_name, $a_attribs);
307 break;
309 $this->importBeginTag($a_xml_parser, $a_name, $a_attribs);
310 break;
311 case self::IL_VERIFY:
312 $this->verifyBeginTag($a_xml_parser, $a_name, $a_attribs);
313 break;
314 }
315
316 $this->cdata = '';
317 }
318
322 public function extractRolesBeginTag(
323 $a_xml_parser,
324 string $a_name,
325 array $a_attribs
326 ): void {
327 switch ($a_name) {
328 case 'Role':
329 // detect numeric, ilias id (then extract role id) or alphanumeric
330 $current_role_id = $a_attribs['Id'];
331 if (($internal_id = ilUtil::__extractId($current_role_id, (int) IL_INST_ID)) > 0) {
332 $current_role_id = $internal_id;
333 }
334 $this->current_role_id = $this->refinery->kindlyTo()->string()->transform($current_role_id);
335 $this->current_role_type = $a_attribs['Type'];
336 break;
337 }
338 }
339
343 public function importBeginTag(
344 $a_xml_parser,
345 string $a_name,
346 array $a_attribs
347 ): void {
348 switch ($a_name) {
349 case 'Role':
350 $current_role_id = $a_attribs['Id'];
351 if (($internal_id = ilUtil::__extractId($current_role_id, (int) IL_INST_ID)) > 0) {
352 $current_role_id = $internal_id;
353 }
354 $this->current_role_id = (string) $current_role_id;
355 $this->current_role_type = $a_attribs['Type'];
356 $this->current_role_action = (!isset($a_attribs['Action'])) ? 'Assign' : $a_attribs['Action'];
357 break;
358
359 case 'PersonalPicture':
360 $this->personal_picture = [
361 'encoding' => $a_attribs['encoding'],
362 'imagetype' => $a_attribs['imagetype'],
363 'content' => ''
364 ];
365 break;
366
367 case 'Look':
368 $this->skin = $a_attribs['Skin'];
369 $this->style = $a_attribs['Style'];
370 break;
371
372 case 'User':
373 $this->contained_tags = [];
374
375 $this->acc_mail->reset();
376 $this->prefs = [];
377 $this->current_pref_key = null;
378 $this->auth_mode_set = false;
379 $this->approve_date_set = false;
380 $this->time_limit_set = false;
381 $this->time_limit_owner_set = false;
382 $this->update_look_and_skin = false;
383 $this->skin = '';
384 $this->style = '';
385 $this->personal_picture = null;
386 $this->user_count++;
387 $this->user_obj = new ilObjUser();
388
389 // user defined fields
390 $this->udf_data = [];
391
392 // if we have an object id, store it
393 $this->user_id = -1;
394 if (isset($a_attribs['Id']) && $this->getUserMappingMode() === self::IL_USER_MAPPING_ID) {
395 if (is_numeric($a_attribs['Id'])) {
396 $this->user_id = (int) $a_attribs['Id'];
397 } elseif (($id = (int) ilUtil::__extractId($a_attribs['Id'], (int) IL_INST_ID)) > 0) {
398 $this->user_id = $id;
399 }
400 }
401
402 $this->user_obj->setPref(
403 'skin',
404 $this->ilias->ini->readVariable('layout', 'skin')
405 );
406 $this->user_obj->setPref(
407 'style',
408 $this->ilias->ini->readVariable('layout', 'style')
409 );
410
411 if (isset($a_attribs['Language'])) {
412 $this->contained_tags[] = 'Language';
413 }
414 $this->user_obj->setLanguage($a_attribs['Language'] ?? '');
415 $this->user_obj->setImportId($a_attribs['Id'] ?? '');
416 $this->action = (is_null($a_attribs['Action'])) ? 'Insert' : $a_attribs['Action'];
417 $this->current_user_password = null;
418 $this->current_user_password_type = null;
419 $this->currActive = null;
420 $this->multi_values = [];
421 break;
422
423 case 'Password':
424 $this->current_user_password_type = $a_attribs['Type'];
425 break;
426 case 'AuthMode':
427 if (array_key_exists('type', $a_attribs)) {
428 switch ($a_attribs['type']) {
429 case 'saml':
430 case 'ldap':
431 if (strcmp('saml', $a_attribs['type']) === 0) {
433 if (count($list) === 1) {
434 $this->auth_mode_set = true;
435 $idp = current($list);
436 $this->user_obj->setAuthMode('saml_' . $idp->getIdpId());
437 }
438 break;
439 }
440 if (strcmp('ldap', $a_attribs['type']) === 0) {
441 // no server id provided => use default server
443 if (count($list) == 1) {
444 $this->auth_mode_set = true;
445 $ldap_id = current($list);
446 $this->user_obj->setAuthMode('ldap_' . $ldap_id);
447 }
448 }
449 break;
450
451 case 'default':
452 case 'local':
453 case 'shibboleth':
454 case 'script':
455 case 'soap':
456 case 'openid':
457 // begin-patch auth_plugin
458 default:
459 $this->auth_mode_set = true;
460 $this->user_obj->setAuthMode($a_attribs['type']);
461 break;
462 }
463 } else {
464 $this->logFailure(
465 $this->user_obj->getLogin(),
466 sprintf($this->lng->txt('usrimport_xml_element_inapplicable'), 'AuthMode', $this->stripTags($a_attribs['type']))
467 );
468 }
469 break;
470
471 case 'UserDefinedField':
472 $this->tmp_udf_id = $a_attribs['Id'];
473 $this->tmp_udf_name = $a_attribs['Name'];
474 break;
475
476 case 'AccountInfo':
477 $this->current_messenger_type = strtolower($a_attribs['Type']);
478 break;
479 case 'GMapInfo':
480 $this->user_obj->setLatitude($a_attribs['latitude']);
481 $this->user_obj->setLongitude($a_attribs['longitude']);
482 $this->user_obj->setLocationZoom($a_attribs['zoom']);
483 break;
484 case 'Pref':
485 $this->current_pref_key = $a_attribs['key'];
486 break;
487 }
488 }
489
493 public function verifyBeginTag(
494 $a_xml_parser,
495 string $a_name,
496 array $a_attribs
497 ): void {
498 switch ($a_name) {
499 case 'Role':
500 if ($a_attribs['Id'] == '') {
501 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_attribute_missing'), 'Role', 'Id'));
502 }
503 $this->current_role_id = $a_attribs['Id'];
504 $this->current_role_type = $a_attribs['Type'];
505 if ($this->current_role_type !== 'Global'
506 && $this->current_role_type !== 'Local') {
507 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_attribute_missing'), 'Role', 'Type'));
508 }
509 $this->current_role_action = (!isset($a_attribs['Action'])) ? 'Assign' : $a_attribs['Action'];
510 if ($this->current_role_action !== 'Assign'
511 && $this->current_role_action !== 'AssignWithParents'
512 && $this->current_role_action !== 'Detach') {
513 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_attribute_value_illegal'), 'Role', 'Action', $this->stripTags($a_attribs['Action'])));
514 }
515 if ($this->action === 'Insert'
516 && $this->current_role_action === 'Detach') {
517 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_attribute_value_inapplicable'), 'Role', 'Action', $this->stripTags($this->current_role_action), $this->stripTags($this->action)));
518 }
519 if ($this->action === 'Delete') {
520 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_element_inapplicable'), 'Role', 'Delete'));
521 }
522 break;
523
524 case 'User':
525 $this->user_count++;
526 $this->contained_tags = [];
527 $this->user_obj = new ilObjUser();
528 $this->user_obj->setLanguage($a_attribs['Language'] ?? '');
529 $this->user_obj->setImportId($a_attribs['Id'] ?? '');
530 $this->current_pref_key = null;
531 // if we have an object id, store it
532 $this->user_id = -1;
533
534 if (isset($a_attribs['Id']) && $this->getUserMappingMode() === self::IL_USER_MAPPING_ID) {
535 if (is_numeric($a_attribs['Id'])) {
536 $this->user_id = (int) $a_attribs['Id'];
537 } elseif (($id = (int) ilUtil::__extractId($a_attribs['Id'], (int) IL_INST_ID)) > 0) {
538 $this->user_id = $id;
539 }
540 }
541
542 $this->action = !isset($a_attribs['Action']) ? 'Insert' : $a_attribs['Action'];
543 if ($this->action !== 'Insert'
544 && $this->action !== 'Update'
545 && $this->action !== 'Delete') {
546 $this->logFailure($this->user_obj->getImportId(), sprintf($this->lng->txt('usrimport_xml_attribute_value_illegal'), 'User', 'Action', $this->stripTags($a_attribs['Action'])));
547 }
548 $this->current_user_password = null;
549 $this->current_user_password_type = null;
550 break;
551
552 case 'Password':
553 $this->current_user_password_type = $a_attribs['Type'];
554 break;
555 case 'AuthMode':
556 if (array_key_exists('type', $a_attribs)) {
557 switch ($a_attribs['type']) {
558 case 'saml':
559 case 'ldap':
560 if (strcmp('saml', $a_attribs['type']) === 0) {
562 if (count($list) !== 1) {
563 $this->logFailure(
564 $this->user_obj->getImportId(),
565 sprintf($this->lng->txt('usrimport_xml_attribute_value_illegal'), 'AuthMode', 'type', $this->stripTags($a_attribs['type']))
566 );
567 }
568 break;
569 }
570 if (strcmp('ldap', $a_attribs['type']) === 0) {
571 // no server id provided
573 if (count($list) != 1) {
574 $this->logFailure(
575 $this->user_obj->getImportId(),
576 sprintf($this->lng->txt('usrimport_xml_attribute_value_illegal'), 'AuthMode', 'type', $this->stripTags($a_attribs['type']))
577 );
578 }
579 }
580 break;
581
582 case 'default':
583 case 'local':
584 case 'shibboleth':
585 case 'script':
586 case 'soap':
587 case 'openid':
588 // begin-patch auth_plugin
589 default:
590 $this->user_obj->setAuthMode($a_attribs['type']);
591 break;
592 }
593 } else {
594 $this->logFailure($this->user_obj->getImportId(), sprintf($this->lng->txt('usrimport_xml_attribute_value_illegal'), 'AuthMode', 'type', ''));
595 }
596 break;
597 case 'Pref':
598 $this->current_pref_key = $a_attribs['key'];
599 break;
600 }
601 }
602
603 public function handlerEndTag(
604 $a_xml_parser,
605 string $a_name
606 ): void {
607 switch ($this->mode) {
608 case self::IL_EXTRACT_ROLES:
609 $this->extractRolesEndTag($a_xml_parser, $a_name);
610 break;
611 case self::IL_USER_IMPORT:
612 $this->importEndTag($a_xml_parser, $a_name);
613 break;
614 case self::IL_VERIFY:
615 $this->verifyEndTag($a_xml_parser, $a_name);
616 break;
617 }
618 }
619
623 public function extractRolesEndTag(
624 $a_xml_parser,
625 string $a_name
626 ): void {
627 switch ($a_name) {
628 case 'Role':
629 $this->roles[$this->current_role_id]['name'] = $this->cdata;
630 $this->roles[$this->current_role_id]['type'] =
631 $this->current_role_type;
632 break;
633 }
634 }
635
639 public function getRoleObject(int $a_role_id): ilObjRole
640 {
641 if (array_key_exists($a_role_id, $this->local_role_cache)) {
642 return $this->local_role_cache[$a_role_id];
643 } else {
644 $role_obj = new ilObjRole($a_role_id, false);
645 $role_obj->read();
646 $this->local_role_cache[$a_role_id] = $role_obj;
647 return $role_obj;
648 }
649 }
650
655 {
656 if (array_key_exists($a_role_id . '_courseMembersObject', $this->local_role_cache)) {
657 return $this->local_role_cache[$a_role_id . '_courseMembersObject'];
658 } else {
659 $course_refs = $this->rbac_review->getFoldersAssignedToRole($a_role_id, true);
660 $course_ref = $course_refs[0];
661 $course_obj = new ilObjCourse($course_ref, true);
662 $crsmembers_obj = ilCourseParticipants::_getInstanceByObjId($course_obj->getId());
663 $this->local_role_cache[$a_role_id . '_courseMembersObject'] = $crsmembers_obj;
664 return $crsmembers_obj;
665 }
666 }
667
671 public function assignToRole(ilObjUser $a_user_obj, int $a_role_id): void
672 {
673 // Do nothing, if the user is already assigned to the role.
674 // Specifically, we do not want to put a course object or
675 // group object on the personal desktop again, if a user
676 // has removed it from the personal desktop.
677 if ($this->rbac_review->isAssigned($a_user_obj->getId(), $a_role_id)) {
678 return;
679 }
680
681 // If it is a course role, use the ilCourseMember object to assign
682 // the user to the role
683
684 $this->rbac_admin->assignUser($a_role_id, $a_user_obj->getId(), true);
685 $obj_id = $this->rbac_review->getObjectOfRole($a_role_id);
686 switch (ilObject::_lookupType($obj_id)) {
687 case 'grp':
688 case 'crs':
689 $ref_ids = ilObject::_getAllReferences($obj_id);
690 $ref_id = current((array) $ref_ids);
691 if ($ref_id) {
692 // deactivated for now, see discussion at
693 // https://docu.ilias.de/goto_docu_wiki_wpage_5620_1357.html
694 //$this->recommended_content_manager->addObjectRecommendation($a_user_obj->getId(), $ref_id);
695 }
696 break;
697 default:
698 break;
699 }
700 }
701
707 public function getParentRoleIds(int $a_role_id): array
708 {
709 if (!array_key_exists($a_role_id, $this->parent_roles_cache)) {
710 $parent_role_ids = [];
711
712 $role_obj = $this->getRoleObject($a_role_id);
713 $short_role_title = substr($role_obj->getTitle(), 0, 12);
714 $folders = $this->rbac_review->getFoldersAssignedToRole($a_role_id, true);
715 if (count($folders) > 0) {
716 $all_parent_role_ids = $this->rbac_review->getParentRoleIds($folders[0]);
717 foreach ($all_parent_role_ids as $parent_role_id => $parent_role_data) {
718 if ($parent_role_id != $a_role_id) {
719 switch (substr($parent_role_data['title'], 0, 12)) {
720 case 'il_crs_admin':
721 case 'il_grp_admin':
722 if ($short_role_title === 'il_crs_admin' || $short_role_title === 'il_grp_admin') {
723 $parent_role_ids[] = $parent_role_id;
724 }
725 break;
726 case 'il_crs_tutor':
727 case 'il_grp_tutor':
728 if ($short_role_title === 'il_crs_tutor' || $short_role_title === 'il_grp_tutor') {
729 $parent_role_ids[] = $parent_role_id;
730 }
731 break;
732 case 'il_crs_membe':
733 case 'il_grp_membe':
734 if ($short_role_title === 'il_crs_membe' || $short_role_title === 'il_grp_membe') {
735 $parent_role_ids[] = $parent_role_id;
736 }
737 break;
738 default:
739 break;
740 }
741 }
742 }
743 }
744 $this->parent_roles_cache[$a_role_id] = $parent_role_ids;
745 }
746 return $this->parent_roles_cache[$a_role_id];
747 }
748
752 public function assignToRoleWithParents(
753 ilObjUser $a_user_obj,
754 int $a_role_id
755 ): void {
756 $this->assignToRole($a_user_obj, $a_role_id);
757
758 $parent_role_ids = $this->getParentRoleIds($a_role_id);
759 foreach ($parent_role_ids as $parent_role_id) {
760 $this->assignToRole($a_user_obj, $parent_role_id);
761 }
762 }
763
767 public function detachFromRole(
768 ilObjUser $a_user_obj,
769 int $a_role_id
770 ): void {
771 $this->rbac_admin->deassignUser($a_role_id, $a_user_obj->getId());
772
773 if (substr(ilObject::_lookupTitle($a_role_id), 0, 6) !== 'il_crs'
774 && substr(ilObject::_lookupTitle($a_role_id), 0, 6) !== 'il_grp') {
775 return;
776 }
777
779 $this->rbac_review->getObjectOfRole($a_role_id)
780 );
781 $ref_id = end($ref);
782 if (!$ref_id) {
783 return;
784 }
785 $this->recommended_content_manager->removeObjectRecommendation($a_user_obj->getId(), $ref_id);
786 }
787
788 private function tagContained(string $tagname): bool
789 {
790 return in_array($tagname, $this->contained_tags, true);
791 }
792
796 public function importEndTag(
797 $a_xml_parser,
798 string $a_name
799 ): void {
800 $this->contained_tags[] = $a_name;
801
802 switch ($a_name) {
803 case 'Role':
804 $this->roles[$this->current_role_id]['name'] = $this->cdata;
805 $this->roles[$this->current_role_id]['type'] = $this->current_role_type;
806 $this->roles[$this->current_role_id]['action'] = $this->current_role_action;
807 break;
808
809 case 'PersonalPicture':
810 switch ($this->personal_picture['encoding']) {
811 case 'Base64':
812 $this->personal_picture['content'] = base64_decode($this->cdata);
813 break;
814 case 'UUEncode':
815 $this->personal_picture['content'] = convert_uudecode($this->cdata);
816 break;
817 }
818 break;
819
820 case 'User':
821 $this->user_obj->setFullname();
822 // Fetch the user_id from the database, if we didn't have it in xml file
823 // fetch as well, if we are trying to insert -> recognize duplicates!
824 if ($this->user_id == -1 || $this->action === 'Insert') {
825 $user_id = ilObjUser::getUserIdByLogin($this->user_obj->getLogin());
826 } else {
828 }
829
830 if ($user_id === (int) ANONYMOUS_USER_ID || $user_id === (int) SYSTEM_USER_ID) {
831 return;
832 }
833
834 // Handle conflicts
835 switch ($this->conflict_rule) {
836 case self::IL_FAIL_ON_CONFLICT:
837 // do not change action
838 break;
839 case self::IL_UPDATE_ON_CONFLICT:
840 switch ($this->action) {
841 case 'Insert':
842 if ($user_id) {
843 $this->logWarning($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_action_replaced'), 'Insert', 'Update'));
844 $this->action = 'Update';
845 }
846 break;
847 case 'Update':
848 if (!$user_id) {
849 $this->logWarning($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_action_replaced'), 'Update', 'Insert'));
850 $this->action = 'Insert';
851 }
852 break;
853 case 'Delete':
854 if (!$user_id) {
855 $this->logWarning($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_action_ignored'), 'Delete'));
856 $this->action = 'Ignore';
857 }
858 break;
859 }
860 break;
861 case self::IL_IGNORE_ON_CONFLICT:
862 switch ($this->action) {
863 case 'Insert':
864 if ($user_id) {
865 $this->logWarning($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_action_ignored'), 'Insert'));
866 $this->action = 'Ignore';
867 }
868 break;
869 case 'Update':
870 if (!$user_id) {
871 $this->logWarning($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_action_ignored'), 'Update'));
872 $this->action = 'Ignore';
873 }
874 break;
875 case 'Delete':
876 if (!$user_id) {
877 $this->logWarning($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_action_ignored'), 'Delete'));
878 $this->action = 'Ignore';
879 }
880 break;
881 }
882 break;
883 }
884
885 // check external account conflict (if external account is already used)
886 // note: we cannot apply conflict rules in the same manner as to logins here
887 // so we ignore records with already existing external accounts.
888 //echo $this->userObj->getAuthMode().'h';
889 $am = ($this->user_obj->getAuthMode() === 'default' || $this->user_obj->getAuthMode() == '')
890 ? ilAuthUtils::_getAuthModeName($this->settings->get('auth_mode'))
891 : $this->user_obj->getAuthMode();
892 $loginForExternalAccount = ($this->user_obj->getExternalAccount() == '')
893 ? ''
894 : ilObjUser::_checkExternalAuthAccount($am, $this->user_obj->getExternalAccount());
895 switch ($this->action) {
896 case 'Insert':
897 if ($loginForExternalAccount != '') {
898 $this->logWarning(
899 $this->user_obj->getLogin(),
900 $this->lng->txt('usrimport_no_insert_ext_account_exists')
901 . ' (' . $this->stripTags($this->user_obj->getExternalAccount()) . ')'
902 );
903 $this->action = 'Ignore';
904 }
905 break;
906
907 case 'Update':
908 // this variable describes the ILIAS login which belongs to the given external account!!!
909 // it is NOT nescessarily the ILIAS login of the current user record !!
910 // so if we found an ILIAS login according to the authentication method
911 // check if the ILIAS login belongs to the current user record, otherwise somebody else is using it!
912 if ($loginForExternalAccount != '') {
913 // check if we changed the value!
914 $externalAccountHasChanged = $this->user_obj->getExternalAccount() != ilObjUser::_lookupExternalAccount($this->user_id);
915 // if it has changed and the external login
916 if ($externalAccountHasChanged && trim($loginForExternalAccount) != trim($this->user_obj->getLogin())) {
917 $this->logWarning(
918 $this->user_obj->getLogin(),
919 $this->lng->txt('usrimport_no_update_ext_account_exists')
920 . ' (' . $this->stripTags($this->user_obj->getExternalAccount()) . ')'
921 );
922 $this->action = 'Ignore';
923 }
924 }
925 break;
926 }
927
928 if (count($this->multi_values)) {
929 if (isset($this->multi_values['GeneralInterest'])) {
930 $this->user_obj->setGeneralInterests($this->multi_values['GeneralInterest']);
931 }
932 if (isset($this->multi_values['OfferingHelp'])) {
933 $this->user_obj->setOfferingHelp($this->multi_values['OfferingHelp']);
934 }
935 if (isset($this->multi_values['LookingForHelp'])) {
936 $this->user_obj->setLookingForHelp($this->multi_values['LookingForHelp']);
937 }
938 }
939
940 // Perform the action
941 switch ($this->action) {
942 case 'Insert':
943 if ($user_id) {
944 $this->logFailure($this->user_obj->getLogin(), $this->lng->txt('usrimport_cant_insert'));
945 } else {
946 if ($this->current_user_password !== null) {
947 switch (strtoupper($this->current_user_password_type)) {
948 case 'BCRYPT':
949 $this->user_obj->setPasswd($this->current_user_password, ilObjUser::PASSWD_CRYPTED);
950 $this->user_obj->setPasswordEncodingType('bcryptphp');
951 $this->user_obj->setPasswordSalt(null);
952 break;
953
954 case 'PLAIN':
955 $this->user_obj->setPasswd($this->current_user_password, ilObjUser::PASSWD_PLAIN);
956 $this->acc_mail->setUserPassword((string) $this->current_user_password);
957 break;
958
959 default:
960 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_attribute_value_illegal'), 'Type', 'Password', $this->stripTags($this->current_user_password_type)));
961 break;
962 }
963 } else {
964 // this does the trick for empty passwords
965 // since a MD5 string has always 32 characters,
966 // no hashed password combination will ever equal to
967 // an empty string
968 $this->user_obj->setPasswd('', ilObjUser::PASSWD_CRYPTED);
969 }
970
971 $this->user_obj->setTitle($this->user_obj->getFullname());
972 $this->user_obj->setDescription($this->user_obj->getEmail());
973
974 if (!$this->time_limit_owner_set) {
975 $this->user_obj->setTimeLimitOwner($this->getFolderId());
976 }
977
978 // default time limit settings
979 if (!$this->time_limit_set) {
980 $this->user_obj->setTimeLimitUnlimited(true);
981
982 if (!$this->approve_date_set) {
983 $this->user_obj->setApproveDate(date('Y-m-d H:i:s'));
984 }
985 }
986
987
988 $this->user_obj->setActive($this->currActive === 'true' || is_null($this->currActive));
989
990 // Finally before saving new user.
991 // Check if profile is incomplete
992
993 // #8759
994 if ($this->udf_data !== []) {
995 $this->user_obj = $this->addUDFDataToUser($this->user_obj);
996 }
997
998 if (!$this->user_obj->getLanguage()) {
999 $this->user_obj->setLanguage($this->lng->getDefaultLanguage());
1000 }
1001
1002 $this->user_obj->setProfileIncomplete($this->checkProfileIncomplete($this->user_obj));
1003 $this->user_obj->create();
1004
1005 //insert user data in table user_data
1006 $this->user_obj->saveAsNew();
1007
1008 if (count($this->prefs)) {
1009 foreach ($this->prefs as $key => $value) {
1010 if ($key !== 'mail_incoming_type' &&
1011 $key !== 'mail_signature' &&
1012 $key !== 'mail_linebreak'
1013 ) {
1014 $this->user_obj->setPref($key, $value);
1015 }
1016 }
1017 }
1018
1019 if (!is_array($this->prefs) || !array_key_exists('chat_osc_accept_msg', $this->prefs)) {
1020 $this->user_obj->setPref('chat_osc_accept_msg', $this->settings->get('chat_osc_accept_msg', 'n'));
1021 }
1022 if (!is_array($this->prefs) || !array_key_exists('chat_broadcast_typing', $this->prefs)) {
1023 $this->user_obj->setPref('chat_broadcast_typing', $this->settings->get('chat_broadcast_typing', 'n'));
1024 }
1025 if (!is_array($this->prefs) || !array_key_exists('bs_allow_to_contact_me', $this->prefs)) {
1026 $this->user_obj->setPref('bs_allow_to_contact_me', $this->settings->get('bs_allow_to_contact_me', 'n'));
1027 }
1028
1029 $this->user_obj->update();
1030
1031 // update mail preferences, to be extended
1032 $this->updateMailPreferences($this->user_obj->getId());
1033
1034 if (is_array($this->personal_picture)) {
1035 if (strlen($this->personal_picture['content'])) {
1036 $extension = 'jpg';
1037 if (preg_match('/.*(png|jpg|gif|jpeg)$/', $this->personal_picture['imagetype'], $matches)) {
1038 $extension = $matches[1];
1039 }
1040 $tmp_name = $this->saveTempImage($this->personal_picture['content'], ".{$extension}");
1041 if (strlen($tmp_name)) {
1042 $this->user_obj->uploadPersonalPicture($tmp_name);
1043 unlink($tmp_name);
1044 }
1045 }
1046 }
1047
1048 //set role entries
1049 foreach ($this->roles as $role_id => $role) {
1050 if (isset($this->role_assign[$role_id]) && $this->role_assign[$role_id]) {
1051 $this->assignToRole($this->user_obj, (int) $this->role_assign[$role_id]);
1052 }
1053 }
1054
1055 $this->sendAccountMail();
1056 $this->logSuccess($this->user_obj->getLogin(), $this->user_obj->getId(), 'Insert');
1057 // reset account mail object
1058 $this->acc_mail->reset();
1059 }
1060 break;
1061
1062 case 'Update':
1063 if (!$user_id) {
1064 $this->logFailure($this->user_obj->getLogin(), $this->lng->txt('usrimport_cant_update'));
1065 } else {
1066 $update_user = new ilObjUser($user_id);
1067 $update_user->read();
1068 if ($this->current_user_password != null) {
1069 switch (strtoupper($this->current_user_password_type)) {
1070 case 'BCRYPT':
1071 $update_user->setPasswd($this->current_user_password, ilObjUser::PASSWD_CRYPTED);
1072 $update_user->setPasswordEncodingType('bcryptphp');
1073 $update_user->setPasswordSalt(null);
1074 break;
1075
1076 case 'PLAIN':
1077 $update_user->setPasswd($this->current_user_password, ilObjUser::PASSWD_PLAIN);
1078 $this->acc_mail->setUserPassword((string) $this->current_user_password);
1079 break;
1080
1081 default:
1082 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_attribute_value_illegal'), 'Type', 'Password', $this->stripTags($this->current_user_password_type)));
1083 break;
1084 }
1085 }
1086 if ($this->tagContained('Firstname')) {
1087 $update_user->setFirstname($this->user_obj->getFirstname());
1088 }
1089 if ($this->tagContained('Lastname')) {
1090 $update_user->setLastname($this->user_obj->getLastname());
1091 }
1092 if ($this->tagContained('Title')) {
1093 $update_user->setUTitle($this->user_obj->getUTitle());
1094 }
1095 if ($this->tagContained('Gender')) {
1096 $update_user->setGender($this->user_obj->getGender());
1097 }
1098 if ($this->tagContained('Email')) {
1099 $update_user->setEmail($this->user_obj->getEmail());
1100 }
1101 if ($this->tagContained('SecondEmail')) {
1102 $update_user->setSecondEmail($this->user_obj->getSecondEmail());
1103 }
1104 if ($this->tagContained('Birthday')) {
1105 $update_user->setBirthday($this->user_obj->getBirthday());
1106 }
1107 if ($this->tagContained('Institution')) {
1108 $update_user->setInstitution($this->user_obj->getInstitution());
1109 }
1110 if ($this->tagContained('Street')) {
1111 $update_user->setStreet($this->user_obj->getStreet());
1112 }
1113 if ($this->tagContained('City')) {
1114 $update_user->setCity($this->user_obj->getCity());
1115 }
1116 if ($this->tagContained('PostalCode')) {
1117 $update_user->setZipcode($this->user_obj->getZipcode());
1118 }
1119 if ($this->tagContained('SelCountry') && mb_strlen($this->cdata) === 2) {
1120 $update_user->setCountry($this->user_obj->getCountry());
1121 }
1122 if ($this->tagContained('PhoneOffice')) {
1123 $update_user->setPhoneOffice($this->user_obj->getPhoneOffice());
1124 }
1125 if ($this->tagContained('PhoneHome')) {
1126 $update_user->setPhoneHome($this->user_obj->getPhoneHome());
1127 }
1128 if ($this->tagContained('PhoneMobile')) {
1129 $update_user->setPhoneMobile($this->user_obj->getPhoneMobile());
1130 }
1131 if ($this->tagContained('Fax')) {
1132 $update_user->setFax($this->user_obj->getFax());
1133 }
1134 if ($this->tagContained('Hobby')) {
1135 $update_user->setHobby($this->user_obj->getHobby());
1136 }
1137 if ($this->tagContained('GeneralInterest')) {
1138 $update_user->setGeneralInterests($this->user_obj->getGeneralInterests());
1139 }
1140 if ($this->tagContained('OfferingHelp')) {
1141 $update_user->setOfferingHelp($this->user_obj->getOfferingHelp());
1142 }
1143 if ($this->tagContained('LookingForHelp')) {
1144 $update_user->setLookingForHelp($this->user_obj->getLookingForHelp());
1145 }
1146 if ($this->tagContained('Comment')) {
1147 $update_user->setComment($this->user_obj->getComment());
1148 }
1149 if ($this->tagContained('Department')) {
1150 $update_user->setDepartment($this->user_obj->getDepartment());
1151 }
1152 if ($this->tagContained('Matriculation')) {
1153 $update_user->setMatriculation($this->user_obj->getMatriculation());
1154 }
1155 if (!is_null($this->currActive)) {
1156 $update_user->setActive($this->currActive === 'true', is_object($this->user) ? $this->user->getId() : 0);
1157 }
1158 if ($this->tagContained('ClientIP')) {
1159 $update_user->setClientIP($this->user_obj->getClientIP());
1160 }
1161 if ($this->time_limit_set) {
1162 $update_user->setTimeLimitUnlimited($this->user_obj->getTimeLimitUnlimited());
1163 }
1164 if ($this->tagContained('TimeLimitFrom')) {
1165 $update_user->setTimeLimitFrom($this->user_obj->getTimeLimitFrom());
1166 }
1167 if ($this->tagContained('TimeLimitUntil')) {
1168 $update_user->setTimeLimitUntil($this->user_obj->getTimeLimitUntil());
1169 }
1170 if ($this->tagContained('ApproveDate')) {
1171 $update_user->setApproveDate($this->user_obj->getApproveDate());
1172 }
1173 if ($this->tagContained('AgreeDate')) {
1174 $update_user->setAgreeDate($this->user_obj->getAgreeDate());
1175 }
1176 if ($this->tagContained('Language')) {
1177 $update_user->setLanguage($this->user_obj->getLanguage());
1178 }
1179 if ($this->tagContained('ExternalAccount')) {
1180 $update_user->setExternalAccount($this->user_obj->getExternalAccount());
1181 }
1182
1183 // Fixed: if auth_mode is not set, it was always overwritten with auth_default
1184 #if (! is_null($this->userObj->getAuthMode())) $updateUser->setAuthMode($this->userObj->getAuthMode());
1185 if ($this->auth_mode_set) {
1186 $update_user->setAuthMode($this->user_obj->getAuthMode());
1187 }
1188
1189 // Special handlin since it defaults to 7 (USER_FOLDER_ID)
1190 if ($this->time_limit_owner_set) {
1191 $update_user->setTimeLimitOwner($this->user_obj->getTimeLimitOwner());
1192 }
1193
1194 if (count($this->prefs)) {
1195 foreach ($this->prefs as $key => $value) {
1196 if ($key !== 'mail_incoming_type' &&
1197 $key !== 'mail_signature' &&
1198 $key !== 'mail_linebreak'
1199 ) {
1200 $update_user->setPref($key, $value);
1201 }
1202 }
1203 }
1204
1205 // save user preferences (skin and style)
1206 if ($this->update_look_and_skin) {
1207 $update_user->setPref('skin', $this->user_obj->getPref('skin'));
1208 $update_user->setPref('style', $this->user_obj->getPref('style'));
1209 }
1210
1211 // update mail preferences, to be extended
1212 $this->updateMailPreferences($update_user->getId());
1213
1214 // #8759
1215 if ($this->udf_data !== []) {
1216 $update_user = $this->addUDFDataToUser($update_user);
1217 }
1218
1219 $update_user->setProfileIncomplete($this->checkProfileIncomplete($update_user));
1220 $update_user->setFullname();
1221 $update_user->setTitle($update_user->getFullname());
1222 $update_user->setDescription($update_user->getEmail());
1223 $update_user->update();
1224
1225 // update login
1226 if ($this->tagContained('Login') && $this->user_id != -1) {
1227 try {
1228 $update_user->updateLogin($this->user_obj->getLogin(), Context::UserAdministration);
1229 } catch (ilUserException $e) {
1230 }
1231 }
1232
1233
1234 // if language has changed
1235
1236 if (is_array($this->personal_picture)) {
1237 if (strlen($this->personal_picture['content'])) {
1238 $extension = 'jpg';
1239 if (preg_match('/.*(png|jpg|gif|jpeg)$/', $this->personal_picture['imagetype'], $matches)) {
1240 $extension = $matches[1];
1241 }
1242 $tmp_name = $this->saveTempImage($this->personal_picture['content'], ".{$extension}");
1243 if (strlen($tmp_name)) {
1244 $update_user->uploadPersonalPicture($tmp_name);
1245 unlink($tmp_name);
1246 }
1247 }
1248 }
1249
1250
1251 //update role entries
1252 //-------------------
1253 foreach ($this->roles as $role_id => $role) {
1254 if (array_key_exists($role_id, $this->role_assign)) {
1255 switch ($role['action']) {
1256 case 'Assign':
1257 $this->assignToRole($update_user, (int) $this->role_assign[$role_id]);
1258 break;
1259 case 'AssignWithParents':
1260 $this->assignToRoleWithParents($update_user, (int) $this->role_assign[$role_id]);
1261 break;
1262 case 'Detach':
1263 $this->detachFromRole($update_user, (int) $this->role_assign[$role_id]);
1264 break;
1265 }
1266 }
1267 }
1268 $this->logSuccess($update_user->getLogin(), $user_id, 'Update');
1269 }
1270 break;
1271 case 'Delete':
1272 if (!$user_id) {
1273 $this->logFailure($this->user_obj->getLogin(), $this->lng->txt('usrimport_cant_delete'));
1274 } else {
1275 $deleteUser = new ilObjUser($user_id);
1276 $deleteUser->delete();
1277
1278 $this->logSuccess($this->user_obj->getLogin(), $user_id, 'Delete');
1279 }
1280 break;
1281 }
1282
1283 // init role array for next user
1284 $this->roles = [];
1285 break;
1286
1287 case 'Login':
1288 $this->user_obj->setLogin($this->getCDataWithoutTags($this->cdata));
1289 break;
1290
1291 case 'Password':
1292 $this->current_user_password = $this->cdata;
1293 break;
1294
1295 case 'Firstname':
1296 $this->user_obj->setFirstname($this->getCDataWithoutTags($this->cdata));
1297 break;
1298
1299 case 'Lastname':
1300 $this->user_obj->setLastname($this->getCDataWithoutTags($this->cdata));
1301 break;
1302
1303 case 'Title':
1304 $this->user_obj->setUTitle($this->getCDataWithoutTags($this->cdata));
1305 break;
1306
1307 case 'Gender':
1308 $this->user_obj->setGender($this->cdata);
1309 break;
1310
1311 case 'Email':
1312 $this->user_obj->setEmail($this->getCDataWithoutTags($this->cdata));
1313 break;
1314 case 'SecondEmail':
1315 $this->user_obj->setSecondEmail($this->getCDataWithoutTags($this->cdata));
1316 break;
1317 case 'Birthday':
1318 $birthday = $this->getCDataWithoutTags($this->cdata);
1319 if (strtotime($birthday) !== false) {
1320 $this->user_obj->setBirthday($birthday);
1321 }
1322 break;
1323 case 'Institution':
1324 $this->user_obj->setInstitution($this->getCDataWithoutTags($this->cdata));
1325 break;
1326
1327 case 'Street':
1328 $this->user_obj->setStreet($this->getCDataWithoutTags($this->cdata));
1329 break;
1330
1331 case 'City':
1332 $this->user_obj->setCity($this->getCDataWithoutTags($this->cdata));
1333 break;
1334
1335 case 'PostalCode':
1336 $this->user_obj->setZipcode($this->getCDataWithoutTags($this->cdata));
1337 break;
1338
1339 case 'Country':
1340 case 'SelCountry':
1341 if (mb_strlen($this->cdata) !== 2) {
1342 break;
1343 }
1344 $this->user_obj->setCountry($this->getCDataWithoutTags($this->cdata));
1345 break;
1346
1347 case 'PhoneOffice':
1348 $this->user_obj->setPhoneOffice($this->getCDataWithoutTags($this->cdata));
1349 break;
1350
1351 case 'PhoneHome':
1352 $this->user_obj->setPhoneHome($this->getCDataWithoutTags($this->cdata));
1353 break;
1354
1355 case 'PhoneMobile':
1356 $this->user_obj->setPhoneMobile($this->getCDataWithoutTags($this->cdata));
1357 break;
1358
1359 case 'Fax':
1360 $this->user_obj->setFax($this->getCDataWithoutTags($this->cdata));
1361 break;
1362
1363 case 'Hobby':
1364 $this->user_obj->setHobby($this->getCDataWithoutTags($this->cdata));
1365 break;
1366
1367 case 'GeneralInterest':
1368 case 'OfferingHelp':
1369 case 'LookingForHelp':
1370 $this->multi_values[$a_name][] = $this->getCDataWithoutTags($this->cdata);
1371 break;
1372
1373 case 'Comment':
1374 $this->user_obj->setComment($this->getCDataWithoutTags($this->cdata));
1375 break;
1376
1377 case 'Department':
1378 $this->user_obj->setDepartment($this->getCDataWithoutTags($this->cdata));
1379 break;
1380
1381 case 'Matriculation':
1382 $this->user_obj->setMatriculation($this->getCDataWithoutTags($this->cdata));
1383 break;
1384
1385 case 'Active':
1386 $this->currActive = $this->cdata;
1387 break;
1388
1389 case 'ClientIP':
1390 $this->user_obj->setClientIP($this->getCDataWithoutTags($this->cdata));
1391 break;
1392
1393 case 'TimeLimitOwner':
1394 $this->time_limit_owner_set = true;
1395 $this->user_obj->setTimeLimitOwner((int) $this->cdata);
1396 break;
1397
1398 case 'TimeLimitUnlimited':
1399 $this->time_limit_set = true;
1400 $this->user_obj->setTimeLimitUnlimited((bool) $this->cdata);
1401 break;
1402
1403 case 'TimeLimitFrom':
1404 if (is_numeric($this->cdata)) {
1405 // Treat cdata as a unix timestamp
1406 $this->user_obj->setTimeLimitFrom((int) $this->cdata);
1407 } else {
1408 // Try to convert cdata into unix timestamp, or ignore it
1409 $timestamp = strtotime($this->cdata);
1410 if ($timestamp !== false && trim($this->cdata) !== '0000-00-00 00:00:00') {
1411 $this->user_obj->setTimeLimitFrom($timestamp);
1412 } elseif ($this->cdata === '0000-00-00 00:00:00') {
1413 $this->user_obj->setTimeLimitFrom(null);
1414 }
1415 }
1416 break;
1417
1418 case 'TimeLimitUntil':
1419 if (is_numeric($this->cdata)) {
1420 // Treat cdata as a unix timestamp
1421 $this->user_obj->setTimeLimitUntil((int) $this->cdata);
1422 } else {
1423 // Try to convert cdata into unix timestamp, or ignore it
1424 $timestamp = strtotime($this->cdata);
1425 if ($timestamp !== false && trim($this->cdata) !== '0000-00-00 00:00:00') {
1426 $this->user_obj->setTimeLimitUntil($timestamp);
1427 } elseif ($this->cdata === '0000-00-00 00:00:00') {
1428 $this->user_obj->setTimeLimitUntil(null);
1429 }
1430 }
1431 break;
1432
1433 case 'ApproveDate':
1434 $this->approve_date_set = true;
1435 if (is_numeric($this->cdata)) {
1436 // Treat cdata as a unix timestamp
1437 $tmp_date = new ilDateTime($this->cdata, IL_CAL_UNIX);
1438 $this->user_obj->setApproveDate($tmp_date->get(IL_CAL_DATETIME));
1439 } else {
1440 // Try to convert cdata into unix timestamp, or ignore it
1441 $timestamp = strtotime($this->cdata);
1442 if ($timestamp !== false && trim($this->cdata) !== '0000-00-00 00:00:00') {
1443 $tmp_date = new ilDateTime($timestamp, IL_CAL_UNIX);
1444 $this->user_obj->setApproveDate($tmp_date->get(IL_CAL_DATETIME));
1445 } elseif ($this->cdata === '0000-00-00 00:00:00') {
1446 $this->user_obj->setApproveDate(null);
1447 }
1448 }
1449 break;
1450
1451 case 'AgreeDate':
1452 if (is_numeric($this->cdata)) {
1453 // Treat cdata as a unix timestamp
1454 $tmp_date = new ilDateTime($this->cdata, IL_CAL_UNIX);
1455 $this->user_obj->setAgreeDate($tmp_date->get(IL_CAL_DATETIME));
1456 } else {
1457 // Try to convert cdata into unix timestamp, or ignore it
1458 $timestamp = strtotime($this->cdata);
1459 if ($timestamp !== false && trim($this->cdata) !== '0000-00-00 00:00:00') {
1460 $tmp_date = new ilDateTime($timestamp, IL_CAL_UNIX);
1461 $this->user_obj->setAgreeDate($tmp_date->get(IL_CAL_DATETIME));
1462 } elseif ($this->cdata === '0000-00-00 00:00:00') {
1463 $this->user_obj->setAgreeDate(null);
1464 }
1465 }
1466 break;
1467
1468 case 'ExternalAccount':
1469 $this->user_obj->setExternalAccount($this->getCDataWithoutTags($this->cdata));
1470 break;
1471
1472 case 'Look':
1473 $this->update_look_and_skin = false;
1474 if ($this->skin !== '' && $this->style !== '') {
1475 if (is_array($this->user_styles)) {
1476 if (in_array($this->skin . ':' . $this->style, $this->user_styles)) {
1477 $this->user_obj->setPref('skin', $this->skin);
1478 $this->user_obj->setPref('style', $this->style);
1479 $this->update_look_and_skin = true;
1480 }
1481 }
1482 }
1483 break;
1484
1485 case 'UserDefinedField':
1486 $field_id = $this->fetchFieldIdFromImportId($this->tmp_udf_id);
1487
1488 if ($field_id === null) {
1489 $field_id = $this->fetchFieldIdFromName($this->tmp_udf_name);
1490 }
1491
1492 if ($field_id === null) {
1493 break;
1494 }
1495
1496 $this->udf_data[$field_id] = strip_tags($this->cdata, ilRTESettings::_getUsedHTMLTags('textarea'));
1497
1498 break;
1499 case 'AccountInfo':
1500 if ($this->current_messenger_type === 'external') {
1501 $this->user_obj->setExternalAccount($this->cdata);
1502 }
1503 break;
1504 case 'Pref':
1505 if ($this->current_pref_key != null && strlen(trim($this->cdata)) > 0
1506 && ilUserXMLWriter::isPrefExportable($this->current_pref_key)) {
1507 $this->prefs[$this->current_pref_key] = trim($this->cdata);
1508 }
1509 $this->current_pref_key = null;
1510 break;
1511 }
1512 }
1513
1518 public function saveTempImage(
1519 string $image_data,
1520 string $filename
1521 ): string {
1522 $tempname = ilFileUtils::ilTempnam() . $filename;
1523 $fh = fopen($tempname, 'wb');
1524 if ($fh == false) {
1525 return '';
1526 }
1527 fwrite($fh, $image_data);
1528 fclose($fh);
1529 return $tempname;
1530 }
1531
1535 public function verifyEndTag(
1536 $a_xml_parser,
1537 string $a_name
1538 ): void {
1539 $externalAccountHasChanged = false;
1540
1541 switch ($a_name) {
1542 case 'Role':
1543 $this->roles[$this->current_role_id]['name'] = $this->cdata;
1544 $this->roles[$this->current_role_id]['type'] = $this->current_role_type;
1545 $this->roles[$this->current_role_id]['action'] = $this->current_role_action;
1546 break;
1547
1548 case 'User':
1549 $this->user_obj->setFullname();
1550 if ($this->user_id != -1 && ($this->action === 'Update' || $this->action === 'Delete')) {
1552 $user_exists = !is_null(ilObjUser::_lookupLogin($user_id));
1553 } else {
1554 $user_id = ilObjUser::getUserIdByLogin($this->user_obj->getLogin());
1555 $user_exists = $user_id != 0;
1556 }
1557 if (is_null($this->user_obj->getLogin())) {
1558 $this->logFailure('---', sprintf($this->lng->txt('usrimport_xml_element_for_action_required'), 'Login', 'Insert'));
1559 }
1560
1561 if ($user_id === (int) ANONYMOUS_USER_ID || $user_id === (int) SYSTEM_USER_ID) {
1562 $this->logWarning($this->user_obj->getLogin(), $this->lng->txt('usrimport_xml_anonymous_or_root_not_allowed'));
1563 break;
1564 }
1565
1566 switch ($this->action) {
1567 case 'Insert':
1568 if ($user_exists and $this->conflict_rule === self::IL_FAIL_ON_CONFLICT) {
1569 $this->logWarning($this->user_obj->getLogin(), $this->lng->txt('usrimport_cant_insert'));
1570 }
1571 if (is_null($this->user_obj->getGender()) && $this->isFieldRequired('gender')) {
1572 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_element_for_action_required'), 'Gender', 'Insert'));
1573 }
1574 if (is_null($this->user_obj->getFirstname())) {
1575 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_element_for_action_required'), 'Firstname', 'Insert'));
1576 }
1577 if (is_null($this->user_obj->getLastname())) {
1578 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_element_for_action_required'), 'Lastname', 'Insert'));
1579 }
1580 if (count($this->roles) == 0) {
1581 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_element_for_action_required'), 'Role', 'Insert'));
1582 } else {
1583 $has_global_role = false;
1584 foreach ($this->roles as $role) {
1585 if ($role['type'] === 'Global') {
1586 $has_global_role = true;
1587 break;
1588 }
1589 }
1590 if (!$has_global_role) {
1591 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_global_role_for_action_required'), 'Insert'));
1592 }
1593 }
1594 break;
1595 case 'Update':
1596 if (!$user_exists) {
1597 $this->logWarning($this->user_obj->getLogin(), $this->lng->txt('usrimport_cant_update'));
1598 } elseif ($this->user_id != -1 && $this->tagContained('Login')) {
1599 // check if someone owns the new login name!
1600 $someonesId = ilObjUser::_lookupId($this->user_obj->getLogin());
1601
1602 if (is_numeric($someonesId) && $someonesId != $this->user_id) {
1603 $this->logFailure($this->user_obj->getLogin(), $this->lng->txt('usrimport_login_is_not_unique'));
1604 }
1605 }
1606 break;
1607 case 'Delete':
1608 if (!$user_exists) {
1609 $this->logWarning($this->user_obj->getLogin(), $this->lng->txt('usrimport_cant_delete'));
1610 }
1611 break;
1612 }
1613
1614 // init role array for next user
1615 $this->roles = [];
1616 break;
1617
1618 case 'Login':
1619 if (array_key_exists($this->cdata, $this->logins)) {
1620 $this->logWarning($this->cdata, $this->lng->txt('usrimport_login_is_not_unique'));
1621 } else {
1622 $this->logins[$this->cdata] = $this->cdata;
1623 }
1624 $this->user_obj->setLogin($this->stripTags($this->cdata));
1625 break;
1626
1627 case 'Password':
1628 switch ($this->current_user_password_type) {
1629 case 'BCRYPT':
1630 $this->user_obj->setPasswd($this->cdata, ilObjUser::PASSWD_CRYPTED);
1631 $this->user_obj->setPasswordEncodingType('bcryptphp');
1632 $this->user_obj->setPasswordSalt(null);
1633 break;
1634
1635 case 'PLAIN':
1636 $this->user_obj->setPasswd($this->cdata, ilObjUser::PASSWD_PLAIN);
1637 $this->acc_mail->setUserPassword((string) $this->current_user_password);
1638 break;
1639
1640 default:
1641 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_attribute_value_illegal'), 'Type', 'Password', $this->stripTags($this->current_user_password_type)));
1642 break;
1643 }
1644 break;
1645
1646 case 'Firstname':
1647 $this->user_obj->setFirstname($this->cdata);
1648 break;
1649
1650 case 'Lastname':
1651 $this->user_obj->setLastname($this->cdata);
1652 break;
1653
1654 case 'Title':
1655 $this->user_obj->setUTitle($this->cdata);
1656 break;
1657
1658 case 'Gender':
1659 if (!in_array(strtolower($this->cdata), ['n', 'm', 'f', ''])) {
1660 $this->logFailure(
1661 $this->user_obj->getLogin(),
1662 sprintf($this->lng->txt('usrimport_xml_element_content_illegal'), 'Gender', $this->stripTags($this->cdata))
1663 );
1664 }
1665 $this->user_obj->setGender($this->cdata);
1666 break;
1667
1668 case 'Email':
1669 $this->user_obj->setEmail($this->cdata);
1670 break;
1671 case 'SecondEmail':
1672 $this->user_obj->setSecondEmail($this->cdata);
1673 break;
1674 case 'Institution':
1675 $this->user_obj->setInstitution($this->cdata);
1676 break;
1677
1678 case 'Street':
1679 $this->user_obj->setStreet($this->cdata);
1680 break;
1681
1682 case 'City':
1683 $this->user_obj->setCity($this->cdata);
1684 break;
1685
1686 case 'PostalCode':
1687 $this->user_obj->setZipcode($this->cdata);
1688 break;
1689
1690 case 'Country':
1691 case 'SelCountry':
1692 if (mb_strlen($this->cdata) !== 2) {
1693 break;
1694 }
1695 $this->user_obj->setCountry($this->cdata);
1696 break;
1697
1698 case 'PhoneOffice':
1699 $this->user_obj->setPhoneOffice($this->cdata);
1700 break;
1701
1702 case 'PhoneHome':
1703 $this->user_obj->setPhoneHome($this->cdata);
1704 break;
1705
1706 case 'PhoneMobile':
1707 $this->user_obj->setPhoneMobile($this->cdata);
1708 break;
1709
1710 case 'Fax':
1711 $this->user_obj->setFax($this->cdata);
1712 break;
1713
1714 case 'Hobby':
1715 $this->user_obj->setHobby($this->cdata);
1716 break;
1717
1718 case 'GeneralInterest':
1719 case 'OfferingHelp':
1720 case 'LookingForHelp':
1721 $this->multi_values[$a_name][] = $this->cdata;
1722 break;
1723
1724 case 'Comment':
1725 $this->user_obj->setComment($this->cdata);
1726 break;
1727
1728 case 'Department':
1729 $this->user_obj->setDepartment($this->cdata);
1730 break;
1731
1732 case 'Matriculation':
1733 $this->user_obj->setMatriculation($this->cdata);
1734 break;
1735
1736 case 'ExternalAccount':
1737 $am = ($this->user_obj->getAuthMode() === 'default' || $this->user_obj->getAuthMode() == '')
1738 ? ilAuthUtils::_getAuthModeName($this->settings->get('auth_mode'))
1739 : $this->user_obj->getAuthMode();
1740 $loginForExternalAccount = (trim($this->cdata) == '')
1741 ? ''
1742 : ilObjUser::_checkExternalAuthAccount($am, trim($this->cdata));
1743 switch ($this->action) {
1744 case 'Insert':
1745 if ($loginForExternalAccount != '') {
1746 $this->logWarning($this->user_obj->getLogin(), $this->lng->txt('usrimport_no_insert_ext_account_exists') . ' (' . $this->stripTags($this->cdata) . ')');
1747 }
1748 break;
1749
1750 case 'Update':
1751 if ($loginForExternalAccount != '') {
1752 $externalAccountHasChanged = trim($this->cdata) != ilObjUser::_lookupExternalAccount($this->user_id);
1753 if ($externalAccountHasChanged && trim($loginForExternalAccount) != trim($this->user_obj->getLogin())) {
1754 $this->logWarning(
1755 $this->user_obj->getLogin(),
1756 $this->lng->txt('usrimport_no_update_ext_account_exists') . ' (' . $this->stripTags($this->cdata) . ' for ' . $this->stripTags($loginForExternalAccount) . ')'
1757 );
1758 }
1759 }
1760 break;
1761 }
1762 if ($externalAccountHasChanged) {
1763 $this->user_obj->setExternalAccount(trim($this->cdata));
1764 }
1765 break;
1766
1767 case 'Active':
1768 if ($this->cdata !== 'true'
1769 && $this->cdata !== 'false') {
1770 $this->logFailure(
1771 $this->user_obj->getLogin(),
1772 sprintf($this->lng->txt('usrimport_xml_element_content_illegal'), 'Active', $this->stripTags($this->cdata))
1773 );
1774 }
1775 $this->currActive = $this->cdata;
1776 break;
1777 case 'TimeLimitOwner':
1778 if (!preg_match('/\d+/', $this->cdata)) {
1779 $this->logFailure(
1780 $this->user_obj->getLogin(),
1781 sprintf($this->lng->txt('usrimport_xml_element_content_illegal'), 'TimeLimitOwner', $this->stripTags($this->cdata))
1782 );
1783 } elseif (!$this->access->checkAccess('cat_administrate_users', '', (int) $this->cdata)) {
1784 $this->logFailure(
1785 $this->user_obj->getLogin(),
1786 sprintf($this->lng->txt('usrimport_xml_element_content_illegal'), 'TimeLimitOwner', $this->stripTags($this->cdata))
1787 );
1788 } elseif ($this->object_data_cache->lookupType($this->object_data_cache->lookupObjId((int) $this->cdata)) !== 'cat' && !(int) $this->cdata == USER_FOLDER_ID) {
1789 $this->logFailure(
1790 $this->user_obj->getLogin(),
1791 sprintf($this->lng->txt('usrimport_xml_element_content_illegal'), 'TimeLimitOwner', $this->stripTags($this->cdata))
1792 );
1793 }
1794 $this->user_obj->setTimeLimitOwner((int) $this->cdata);
1795 break;
1796 case 'TimeLimitUnlimited':
1797 switch (strtolower($this->cdata)) {
1798 case 'true':
1799 case '1':
1800 $this->user_obj->setTimeLimitUnlimited(true);
1801 break;
1802 case 'false':
1803 case '0':
1804 $this->user_obj->setTimeLimitUnlimited(false);
1805 break;
1806 default:
1807 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_element_content_illegal'), 'TimeLimitUnlimited', $this->stripTags($this->cdata)));
1808 break;
1809 }
1810 break;
1811 case 'TimeLimitFrom':
1812 // Accept datetime or Unix timestamp
1813 if (strtotime($this->cdata) === false && !is_numeric($this->cdata)) {
1814 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_element_content_illegal'), 'TimeLimitFrom', $this->stripTags($this->cdata)));
1815 }
1816 $this->user_obj->setTimeLimitFrom((int) $this->cdata);
1817 break;
1818 case 'TimeLimitUntil':
1819 // Accept datetime or Unix timestamp
1820 if (strtotime($this->cdata) === false && !is_numeric($this->cdata)) {
1821 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_element_content_illegal'), 'TimeLimitUntil', $this->stripTags($this->cdata)));
1822 }
1823 $this->user_obj->setTimeLimitUntil((int) $this->cdata);
1824 break;
1825 case 'ApproveDate':
1826 // Accept datetime or Unix timestamp
1827 if (strtotime($this->cdata) === false && !is_numeric($this->cdata) && !$this->cdata === '0000-00-00 00:00:00') {
1828 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_element_content_illegal'), 'ApproveDate', $this->stripTags($this->cdata)));
1829 }
1830 break;
1831 case 'AgreeDate':
1832 // Accept datetime or Unix timestamp
1833 if (strtotime($this->cdata) === false && !is_numeric($this->cdata) && !$this->cdata === '0000-00-00 00:00:00') {
1834 $this->logFailure($this->user_obj->getLogin(), sprintf($this->lng->txt('usrimport_xml_element_content_illegal'), 'AgreeDate', $this->stripTags($this->cdata)));
1835 }
1836 break;
1837 case 'Pref':
1838 if ($this->current_pref_key != null) {
1839 $this->verifyPref($this->current_pref_key, $this->cdata);
1840 }
1841 }
1842 }
1843
1848 public function handlerCharacterData(
1849 $a_xml_parser,
1850 string $a_data
1851 ): void {
1852 if ($a_data !== "\n") {
1853 $a_data = preg_replace('/\t+/', ' ', $a_data);
1854 }
1855
1856 if (strlen($a_data) > 0) {
1857 $this->cdata .= $a_data;
1858 }
1859 }
1860
1864 public function getCollectedRoles(): array
1865 {
1866 return $this->roles;
1867 }
1868
1869 public function getUserCount(): int
1870 {
1871 return $this->user_count;
1872 }
1873
1877 public function logWarning(
1878 string $aLogin,
1879 string $aMessage
1880 ): void {
1881 if (!array_key_exists($aLogin, $this->protocol)) {
1882 $this->protocol[$aLogin] = [];
1883 }
1884 if ($aMessage) {
1885 $this->protocol[$aLogin][] = $aMessage;
1886 }
1887 if ($this->error_level === self::IL_IMPORT_SUCCESS) {
1888 $this->error_level = self::IL_IMPORT_WARNING;
1889 }
1890 }
1891
1895 public function logFailure(
1896 string $aLogin,
1897 string $aMessage
1898 ): void {
1899 if (!array_key_exists($aLogin, $this->protocol)) {
1900 $this->protocol[$aLogin] = [];
1901 }
1902 if ($aMessage) {
1903 $this->protocol[$aLogin][] = $aMessage;
1904 }
1905 $this->error_level = self::IL_IMPORT_FAILURE;
1906 }
1907
1911 public function logSuccess(
1912 string $aLogin,
1913 int $userid,
1914 string $action
1915 ): void {
1916 $this->user_mapping[$userid] = ['login' => $aLogin, 'action' => $action, 'message' => 'successful'];
1917 }
1918
1919
1927 public function getProtocol(): array
1928 {
1929 return $this->protocol;
1930 }
1931
1935 public function getProtocolAsHTML(string $a_log_title): string
1936 {
1937 $block = new ilTemplate('tpl.usr_import_log_block.html', true, true, 'components/ILIAS/User');
1938 $block->setVariable('TXT_LOG_TITLE', $a_log_title);
1939 $block->setVariable('TXT_MESSAGE_ID', $this->lng->txt('login'));
1940 $block->setVariable('TXT_MESSAGE_TEXT', $this->lng->txt('message'));
1941 foreach ($this->getProtocol() as $login => $messages) {
1942 $block->setCurrentBlock('log_row');
1943 $reason = '';
1944 foreach ($messages as $message) {
1945 if ($reason == '') {
1946 $reason = $message;
1947 } else {
1948 $reason .= '<br>' . $message;
1949 }
1950 }
1951 $block->setVariable('MESSAGE_ID', $login);
1952 $block->setVariable('MESSAGE_TEXT', $reason);
1953 $block->parseCurrentBlock();
1954 }
1955 return $block->get();
1956 }
1957
1961 public function isSuccess(): bool
1962 {
1963 return $this->error_level === self::IL_IMPORT_SUCCESS;
1964 }
1965
1970 public function getErrorLevel(): int
1971 {
1972 return $this->error_level;
1973 }
1974
1979 public function getUserMapping(): array
1980 {
1981 return $this->user_mapping;
1982 }
1983
1987 public function sendAccountMail(): void
1988 {
1989 if ($this->req_send_mail != '' ||
1990 ($this->isSendMail() && $this->user_obj->getEmail() != '')) {
1991 $this->acc_mail->setUser($this->user_obj);
1992 $this->acc_mail->send();
1993 }
1994 }
1995
1996 public function setSendMail(bool $value): void
1997 {
1998 $this->send_mail = $value;
1999 }
2000
2001 public function isSendMail(): bool
2002 {
2003 return $this->send_mail;
2004 }
2005
2011 public function setUserMappingMode(int $value): void
2012 {
2013 if ($value === self::IL_USER_MAPPING_ID || $value === self::IL_USER_MAPPING_LOGIN) {
2014 $this->mapping_mode = $value;
2015 } else {
2016 die('wrong argument using methode setUserMappingMethod in ' . __FILE__);
2017 }
2018 }
2019
2024 public function getUserMappingMode(): int
2025 {
2026 return $this->mapping_mode;
2027 }
2028
2032 private function readRequiredFields(): array
2033 {
2034 if (is_array($this->required_fields)) {
2035 return $this->required_fields;
2036 }
2037 foreach ($this->settings->getAll() as $field => $value) {
2038 if (strpos($field, 'require_') === 0 && $value == 1) {
2039 $value = substr($field, 8);
2040 $this->required_fields[$value] = $value;
2041 }
2042 }
2043 return $this->required_fields ?: [];
2044 }
2045
2050 private function checkProfileIncomplete(ilObjUser $user_obj): bool
2051 {
2052 return $this->user_profile->isProfileIncomplete($user_obj);
2053 }
2054
2061 private function isFieldRequired(string $fieldname): bool
2062 {
2063 $requiredFields = $this->readRequiredFields();
2064 $fieldname = strtolower(trim($fieldname));
2065 return array_key_exists($fieldname, $requiredFields);
2066 }
2067
2068 private function verifyPref(string $key, string $value): void
2069 {
2070 switch ($key) {
2071 case 'mail_linebreak':
2072 case 'language':
2073 case 'skin':
2074 case 'style':
2075 case 'ilPageEditor_HTMLMode':
2076 case 'ilPageEditor_JavaScript':
2077 case 'ilPageEditor_MediaMode':
2078 case 'tst_javascript':
2079 case 'tst_lastquestiontype':
2080 case 'tst_multiline_answers':
2081 case 'tst_use_previous_answers':
2082 case 'graphicalAnswerSetting':
2083 case 'priv_feed_pass':
2084 $this->logFailure('---', "Preference {$this->stripTags($key)} is not supported.");
2085 break;
2086 case 'public_city':
2087 case 'public_country':
2088 case 'public_department':
2089 case 'public_email':
2090 case 'public_second_email':
2091 case 'public_fax':
2092 case 'public_hobby':
2093 case 'public_institution':
2094 case 'public_matriculation':
2095 case 'public_phone':
2096 case 'public_phone_home':
2097 case 'public_phone_mobile':
2098 case 'public_phone_office':
2099 case 'public_street':
2100 case 'public_upload':
2101 case 'public_avatar':
2102 case 'public_zip':
2103 case 'public_interests_general':
2104 case 'public_interests_help_offered':
2105 case 'public_interests_help_looking':
2106 case 'send_info_mails':
2107 case 'bs_allow_to_contact_me':
2108 case 'chat_osc_accept_msg':
2109 case 'chat_broadcast_typing':
2110 case 'hide_own_online_status':
2111 if (!in_array($value, ['y', 'n', ''])) {
2112 $this->logFailure('---', "Wrong value '{$this->stripTags($value)}': Value 'y' or 'n' expected for preference {$this->stripTags($key)}.");
2113 }
2114 break;
2115 case 'public_profile':
2116 if (!in_array($value, ['y', 'n', 'g'])) {
2117 $this->logFailure('---', "Wrong value '{$this->stripTags($value)}': Value 'y', 'g' or 'n' expected for preference {$this->stripTags($key)}.");
2118 }
2119 break;
2120 case 'show_users_online':
2121 if (!in_array($value, ['y', 'n', 'associated'])) {
2122 $this->logFailure('---', "Wrong value '{$this->stripTags($value)}': Value 'y' or 'n' or 'associated' expected for preference {$this->stripTags($key)}.");
2123 }
2124 break;
2125 case 'mail_incoming_type':
2126 if (!in_array((int) $value, ['0','1','2'])) {
2127 $this->logFailure('---', "Wrong value '{$this->stripTags($value)}': Value '0' (LOCAL),'1' (EMAIL) or '2' (BOTH) expected for preference {$this->stripTags($key)}.");
2128 }
2129 break;
2130 case 'weekstart':
2131 if (!in_array($value, ['0','1'])) {
2132 $this->logFailure('---', "Wrong value '{$this->stripTags($value)}': Value '0' (Sunday) or '1' (Monday) expected for preference {$this->stripTags($key)}.");
2133 }
2134 break;
2135
2136 case 'mail_signature':
2137 break;
2138 case 'user_tz':
2139 try {
2141 return;
2142 } catch (ilTimeZoneException $tze) {
2143 $this->logFailure('---', "Wrong value '{$this->stripTags($value)}': Invalid timezone $value detected for preference {$this->stripTags($key)}.");
2144 }
2145 break;
2146 default:
2148 $this->logFailure('---', "Preference {$this->stripTags($key)} is not supported.");
2149 }
2150 break;
2151 }
2152 }
2153
2154 private function addUDFDataToUser(\ilObjUser $user): \ilObjUser
2155 {
2156 return $user->withProfileData(
2157 array_reduce(
2158 array_keys($this->udf_data),
2159 fn(ProfileData $c, string $v): ProfileData =>
2160 $c->withAdditionalFieldByIdentifier(
2161 $v,
2162 $this->udf_data[$v]
2163 ),
2164 $this->user_obj->getProfileData()
2165 )
2166 );
2167 }
2168
2169 private function updateMailPreferences(int $usr_id): void
2170 {
2171 if (array_key_exists('mail_incoming_type', $this->prefs) ||
2172 array_key_exists('mail_signature', $this->prefs) ||
2173 array_key_exists('mail_linebreak', $this->prefs)
2174 ) {
2175 $mailOptions = new ilMailOptions($usr_id);
2176
2177 $mailOptions->setSignature(array_key_exists('mail_signature', $this->prefs) ? $this->prefs['mail_signature'] : $mailOptions->getSignature());
2178 $mailOptions->setIncomingType(array_key_exists('mail_incoming_type', $this->prefs) ? (int) $this->prefs['mail_incoming_type'] : $mailOptions->getIncomingType());
2179 $mailOptions->updateOptions();
2180 }
2181 }
2182
2183 private function fetchFieldIdFromImportId(string $import_id): ?string
2184 {
2185 if ($import_id === '') {
2186 return null;
2187 }
2188
2189 $parts = explode('_', $import_id);
2190 if (($parts[0] ?? '') !== 'il'
2191 || ($parts[1] ?? '') !== 'udf'
2192 || ($parts[2] ?? '') === ''
2193 || $this->user_profile->getFieldByIdentifier($parts[2]) === null) {
2194 return null;
2195 }
2196 return $parts[2];
2197 }
2198
2199 private function fetchFieldIdFromName(string $name): ?string
2200 {
2201 foreach ($this->user_profile->getAllUserDefinedFields() as $field) {
2202 if ($field->getLabel($this->lng) === $name) {
2203 return $field->getIdentifier();
2204 }
2205 }
2206 return null;
2207 }
2208
2209 private function getCDataWithoutTags(): string
2210 {
2211 return $this->stripTags($this->cdata);
2212 }
2213
2214 private function stripTags(string $string): string
2215 {
2216 return $this->refinery->string()->stripTags()->transform($string);
2217 }
2218}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$filename
Definition: buildRTE.php:78
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:70
Builds data types.
Definition: Factory.php:36
const IL_CAL_UNIX
const IL_CAL_DATETIME
Class ilAccessHandler Checks access for ILIAS objects.
static _getAuthModeName($a_auth_key)
static _getInstanceByObjId(int $a_obj_id)
@classDescription Date and time handling
Class ilFileUtils.
static _getActiveServerList()
Get active server list.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjRole.
User class.
const PASSWD_CRYPTED
static _lookupExternalAccount(int $a_user_id)
const PASSWD_PLAIN
withProfileData(Data $profile_data)
static _lookupId(string|array $a_user_str)
static getUserIdByLogin(string $a_login)
static _lookupLogin(int $a_user_id)
static _checkExternalAuthAccount(string $a_auth, string $a_account, bool $tryFallback=true)
check whether external account and authentication method matches with a user
class ilObjectDataCache
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
static _getUsedHTMLTags(string $module='')
Class ilRbacAdmin Core functions for role based access control.
class ilRbacReview Contains Review functions of core Rbac.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getActiveIdpList()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(?string $path_to_file='', ?bool $throw_exception=false)
ILIAS Setting Class.
static _lookupActivatedStyle(string $a_skin, string $a_style)
lookup if a style is activated
special template class to simplify handling of ITX/PEAR
Class for TimeZone exceptions.
static _getInstance(string $a_tz='')
get instance by timezone
handlerBeginTag( $a_xml_parser, string $a_name, array $a_attribs)
setUserMappingMode(int $value)
write access to user mapping mode
setRoleAssignment(array $a_assign)
set import to local role assignemt
detachFromRole(ilObjUser $a_user_obj, int $a_role_id)
Detaches a user from a role.
addUDFDataToUser(\ilObjUser $user)
logSuccess(string $aLogin, int $userid, string $action)
Writes a success log message to the protocol.
getParentRoleIds(int $a_role_id)
Get array of parent role ids from cache.
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class @access private
buildTag(string $type, string $name, ?array $attr=null)
generate a tag with given name and attributes
importEndTag( $a_xml_parser, string $a_name)
getProtocolAsHTML(string $a_log_title)
Returns the protocol as a HTML table.
logFailure(string $aLogin, string $aMessage)
Writes a failure log message to the protocol.
isSuccess()
Returns true, if the import was successful.
extractRolesBeginTag( $a_xml_parser, string $a_name, array $a_attribs)
setFolderId(int $a_folder_id)
assign users to this folder (normally the usr_folder) But if called from local admin => the ref_id of...
assignToRole(ilObjUser $a_user_obj, int $a_role_id)
Assigns a user to a role.
isFieldRequired(string $fieldname)
determine if a field $fieldname is to a required field (global setting)
checkProfileIncomplete(ilObjUser $user_obj)
Check if profile is incomplete Will set the usr_data field profile_incomplete if any required field i...
verifyBeginTag( $a_xml_parser, string $a_name, array $a_attribs)
verifyPref(string $key, string $value)
assignToRoleWithParents(ilObjUser $a_user_obj, int $a_role_id)
Assigns a user to a role and to all parent roles.
getUserMappingMode()
read access to user mapping mode
ilRecommendedContentManager $recommended_content_manager
handlerEndTag( $a_xml_parser, string $a_name)
ilObjectDataCache $object_data_cache
extractRolesEndTag( $a_xml_parser, string $a_name)
sendAccountMail()
send account mail
getRoleObject(int $a_role_id)
Returns the parent object of the role folder object which contains the specified role.
handlerCharacterData( $a_xml_parser, string $a_data)
handler for character data
saveTempImage(string $image_data, string $filename)
Saves binary image data to a temporary image file and returns the name of the image file on success.
getErrorLevel()
Returns the error level.
getCourseMembersObjectForRole(int $a_role_id)
Returns the parent object of the role folder object which contains the specified role.
getProtocol()
The protocol is an associative array.
getUserMapping()
returns a map user_id <=> login
logWarning(string $aLogin, string $aMessage)
Writes a warning log message to the protocol.
int $error_level
This variable is used to report the error level of the validation process or the importing process.
importBeginTag( $a_xml_parser, string $a_name, array $a_attribs)
fetchFieldIdFromImportId(string $import_id)
verifyEndTag( $a_xml_parser, string $a_name)
handler for end of element when in verify mode.
static isPrefExportable(string $key)
returns wether a key from db is exportable or not
static __extractId(string $ilias_id, int $inst_id)
extract ref id from role title, e.g.
const USER_FOLDER_ID
Definition: constants.php:33
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
Definition: constants.php:26
const IL_INST_ID
Definition: constants.php:40
const ANONYMOUS_USER_ID
Definition: constants.php:27
$c
Definition: deliver.php:25
$ref_id
Definition: ltiauth.php:66
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
Class ilObjForumAdministration.
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26