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