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