ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilUserImportParser.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24define("IL_EXTRACT_ROLES", 1);
25define("IL_USER_IMPORT", 2);
26define("IL_VERIFY", 3);
27
28define("IL_FAIL_ON_CONFLICT", 1);
29define("IL_UPDATE_ON_CONFLICT", 2);
30define("IL_IGNORE_ON_CONFLICT", 3);
31
32define("IL_IMPORT_SUCCESS", 1);
33define("IL_IMPORT_WARNING", 2);
34define("IL_IMPORT_FAILURE", 3);
35
36define("IL_USER_MAPPING_LOGIN", 1);
37define("IL_USER_MAPPING_ID", 2);
38
39require_once("./Services/Xml/classes/class.ilSaxParser.php");
40require_once('Services/User/classes/class.ilUserXMLWriter.php');
41
42
51{
52 public $approve_date_set = false;
53 public $time_limit_set = false;
54 public $time_limit_owner_set = false;
55
59 public $updateLookAndSkin = false;
60 public $folder_id;
61 public $roles;
66 public $action;
75 public $protocol;
85 public $logins;
86
95
96
103
166
175
184
190 public $user_mapping = [];
191
199
208
214
223
227 public $skin;
228
232 public $style;
233
238
242 public $hideSkin;
243
248
254 public $user_id;
255
260 private $userObj;
261
268
273
278
288 public function __construct($a_xml_file = '', $a_mode = IL_USER_IMPORT, $a_conflict_rule = IL_FAIL_ON_CONFLICT)
289 {
290 global $DIC;
291
292 $global_settings = $DIC->settings();
293
294 $this->roles = array();
295 $this->mode = $a_mode;
296 $this->conflict_rule = $a_conflict_rule;
297 $this->error_level = IL_IMPORT_SUCCESS;
298 $this->protocol = array();
299 $this->logins = array();
300 $this->userCount = 0;
301 $this->localRoleCache = array();
302 $this->parentRolesCache = array();
303 $this->send_mail = false;
304 $this->mapping_mode = IL_USER_MAPPING_LOGIN;
305
306 $this->user_settings_config = new ilUserSettingsConfig();
307
308 // get all active style instead of only assigned ones -> cannot transfer all to another otherwise
309 $this->userStyles = array();
310 include_once './Services/Style/System/classes/class.ilStyleDefinition.php';
311 $skins = ilStyleDefinition::getAllSkins();
312
313 if (is_array($skins)) {
314 foreach ($skins as $skin) {
315 foreach ($skin->getStyles() as $style) {
316 include_once("./Services/Style/System/classes/class.ilSystemStyleSettings.php");
318 continue;
319 }
320 $this->userStyles [] = $skin->getId() . ":" . $style->getId();
321 }
322 }
323 }
324
325 $this->hideSkin = (!$this->user_settings_config->isVisible("skin_style"));
326 $this->disableSkin = (!$this->user_settings_config->isChangeable("skin_style"));
327
328 include_once("Services/Mail/classes/class.ilAccountMail.php");
329 $this->acc_mail = new ilAccountMail();
330 $this->acc_mail->setAttachConfiguredFiles(true);
331 $this->acc_mail->useLangVariablesAsFallback(true);
332
333 $this->recommended_content_manager = new ilRecommendedContentManager();
334
335 parent::__construct($a_xml_file);
336 }
337
343 public function setFolderId($a_folder_id)
344 {
345 $this->folder_id = $a_folder_id;
346 }
347
348 public function getFolderId()
349 {
350 return $this->folder_id;
351 }
352
358 public function setHandlers($a_xml_parser)
359 {
360 xml_set_object($a_xml_parser, $this);
361 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
362 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
363 }
364
368 public function startParsing()
369 {
370 parent::startParsing();
371 }
372
378 public function setRoleAssignment($a_assign)
379 {
380 $this->role_assign = $a_assign;
381 }
382
390 public function buildTag($type, $name, $attr = "")
391 {
392 $tag = "<";
393
394 if ($type == "end") {
395 $tag .= "/";
396 }
397
398 $tag .= $name;
399
400 if (is_array($attr)) {
401 foreach ($attr as $k => $v) {
402 $tag .= " " . $k . "=\"$v\"";
403 }
404 }
405
406 $tag .= ">";
407
408 return $tag;
409 }
410
414 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
415 {
416 switch ($this->mode) {
417 case IL_EXTRACT_ROLES:
418 $this->extractRolesBeginTag($a_xml_parser, $a_name, $a_attribs);
419 break;
420 case IL_USER_IMPORT:
421 $this->importBeginTag($a_xml_parser, $a_name, $a_attribs);
422 break;
423 case IL_VERIFY:
424 $this->verifyBeginTag($a_xml_parser, $a_name, $a_attribs);
425 break;
426 }
427
428 $this->cdata = "";
429 }
430
434 public function extractRolesBeginTag($a_xml_parser, $a_name, $a_attribs)
435 {
436 switch ($a_name) {
437 case "Role":
438 // detect numeric, ilias id (then extract role id) or alphanumeric
439 $this->current_role_id = $a_attribs["Id"];
440 if ($internal_id = ilUtil::__extractId($this->current_role_id, IL_INST_ID)) {
441 $this->current_role_id = $internal_id;
442 }
443 $this->current_role_type = $a_attribs["Type"];
444
445 break;
446 }
447 }
451 public function importBeginTag($a_xml_parser, $a_name, $a_attribs)
452 {
453 global $DIC;
454
455 $ilias = $DIC['ilias'];
456 $lng = $DIC['lng'];
457
458 switch ($a_name) {
459 case "Role":
460 $this->current_role_id = $a_attribs["Id"];
461 if ($internal_id = ilUtil::__extractId($this->current_role_id, IL_INST_ID)) {
462 $this->current_role_id = $internal_id;
463 }
464 $this->current_role_type = $a_attribs["Type"];
465 $this->current_role_action = (is_null($a_attribs["Action"])) ? "Assign" : $a_attribs["Action"];
466 break;
467
468 case "PersonalPicture":
469 $this->personalPicture = array(
470 "encoding" => $a_attribs["encoding"],
471 "imagetype" => $a_attribs["imagetype"],
472 "content" => ""
473 );
474 break;
475
476 case "Look":
477 $this->skin = $a_attribs["Skin"];
478 $this->style = $a_attribs["Style"];
479 break;
480
481 case "User":
482 $this->acc_mail->reset();
483 $this->prefs = array();
484 $this->currentPrefKey = null;
485 $this->auth_mode_set = false;
486 $this->approve_date_set = false;
487 $this->time_limit_set = false;
488 $this->time_limit_owner_set = false;
489 $this->updateLookAndSkin = false;
490 $this->skin = "";
491 $this->style = "";
492 $this->personalPicture = null;
493 $this->userCount++;
494 $this->userObj = new ilObjUser();
495
496 // user defined fields
497 $this->udf_data = array();
498
499 // if we have an object id, store it
500 $this->user_id = -1;
501 if (!is_null($a_attribs["Id"]) && $this->getUserMappingMode() == IL_USER_MAPPING_ID) {
502 if (is_numeric($a_attribs["Id"])) {
503 $this->user_id = $a_attribs["Id"];
504 } elseif ($id = ilUtil::__extractId($a_attribs["Id"], IL_INST_ID)) {
505 $this->user_id = $id;
506 }
507 }
508
509 $this->userObj->setPref(
510 "skin",
511 $ilias->ini->readVariable("layout", "skin")
512 );
513 $this->userObj->setPref(
514 "style",
515 $ilias->ini->readVariable("layout", "style")
516 );
517
518 $this->userObj->setLanguage($a_attribs["Language"]);
519 $this->userObj->setImportId($a_attribs["Id"]);
520 $this->action = (is_null($a_attribs["Action"])) ? "Insert" : $a_attribs["Action"];
521 $this->currPassword = null;
522 $this->currPasswordType = null;
523 $this->currActive = null;
524 $this->multi_values = array();
525 break;
526
527 case 'Password':
528 $this->currPasswordType = $a_attribs['Type'];
529 break;
530 case "AuthMode":
531 if (array_key_exists("type", $a_attribs)) {
532 switch ($a_attribs["type"]) {
533 case "saml":
534 case "ldap":
535 if (strcmp('saml', $a_attribs['type']) === 0) {
537 if (count($list) === 1) {
538 $this->auth_mode_set = true;
539 $idp = current($list);
540 $this->userObj->setAuthMode('saml_' . $idp->getIdpId());
541 }
542 break;
543 }
544 if (strcmp('ldap', $a_attribs['type']) === 0) {
545 // no server id provided => use default server
546 include_once './Services/LDAP/classes/class.ilLDAPServer.php';
548 if (count($list) == 1) {
549 $this->auth_mode_set = true;
550 $ldap_id = current($list);
551 $this->userObj->setAuthMode('ldap_' . $ldap_id);
552 }
553 }
554 break;
555
556 case "default":
557 case "local":
558 case "radius":
559 case "shibboleth":
560 case "script":
561 case "cas":
562 case "soap":
563 case "openid":
564 // begin-patch auth_plugin
565 default:
566 $this->auth_mode_set = true;
567 $this->userObj->setAuthMode($a_attribs["type"]);
568 break;
569 }
570 } else {
571 $this->logFailure(
572 $this->userObj->getLogin(),
573 sprintf($lng->txt("usrimport_xml_element_inapplicable"), "AuthMode", $this->stripTags($a_attribs["type"]))
574 );
575 }
576 break;
577
578 case 'UserDefinedField':
579 $this->tmp_udf_id = $a_attribs['Id'];
580 $this->tmp_udf_name = $a_attribs['Name'];
581 break;
582
583 case 'AccountInfo':
584 $this->current_messenger_type = strtolower($a_attribs["Type"]);
585 break;
586 case 'GMapInfo':
587 $this->userObj->setLatitude($a_attribs["latitude"]);
588 $this->userObj->setLongitude($a_attribs["longitude"]);
589 $this->userObj->setLocationZoom($a_attribs["zoom"]);
590 break;
591 case 'Pref':
592 $this->currentPrefKey = $a_attribs["key"];
593 break;
594 }
595 }
599 public function verifyBeginTag($a_xml_parser, $a_name, $a_attribs)
600 {
601 global $DIC;
602
603 $lng = $DIC['lng'];
604
605 switch ($a_name) {
606 case "Role":
607 if (is_null($a_attribs['Id'])
608 || $a_attribs['Id'] == "") {
609 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_missing"), "Role", "Id"));
610 }
611 $this->current_role_id = $a_attribs["Id"];
612 $this->current_role_type = $a_attribs["Type"];
613 if ($this->current_role_type != 'Global'
614 && $this->current_role_type != 'Local') {
615 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_missing"), "Role", "Type"));
616 }
617 $this->current_role_action = (is_null($a_attribs["Action"])) ? "Assign" : $a_attribs["Action"];
618 if ($this->current_role_action != "Assign"
619 && $this->current_role_action != "AssignWithParents"
620 && $this->current_role_action != "Detach") {
621 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "Role", "Action", $this->stripTags($a_attribs["Action"])));
622 }
623 if ($this->action == "Insert"
624 && $this->current_role_action == "Detach") {
625 $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)));
626 }
627 if ($this->action == "Delete") {
628 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_inapplicable"), "Role", "Delete"));
629 }
630 break;
631
632 case "User":
633 $this->userCount++;
634 $this->userObj = new ilObjUser();
635 $this->userObj->setLanguage($a_attribs["Language"]);
636 $this->userObj->setImportId($a_attribs["Id"]);
637 $this->currentPrefKey = null;
638 // if we have an object id, store it
639 $this->user_id = -1;
640
641 if (!is_null($a_attribs["Id"]) && $this->getUserMappingMode() == IL_USER_MAPPING_ID) {
642 if (is_numeric($a_attribs["Id"])) {
643 $this->user_id = $a_attribs["Id"];
644 } elseif ($id = ilUtil::__extractId($a_attribs["Id"], IL_INST_ID)) {
645 $this->user_id = $id;
646 }
647 }
648
649 $this->action = (is_null($a_attribs["Action"])) ? "Insert" : $a_attribs["Action"];
650 if ($this->action != "Insert"
651 && $this->action != "Update"
652 && $this->action != "Delete") {
653 $this->logFailure($this->userObj->getImportId(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "User", "Action", $this->stripTags($a_attribs["Action"])));
654 }
655 $this->currPassword = null;
656 $this->currPasswordType = null;
657 break;
658
659 case 'Password':
660 $this->currPasswordType = $a_attribs['Type'];
661 break;
662 case "AuthMode":
663 if (array_key_exists("type", $a_attribs)) {
664 switch ($a_attribs["type"]) {
665 case "saml":
666 case "ldap":
667 if (strcmp('saml', $a_attribs['type']) === 0) {
669 if (count($list) !== 1) {
670 $this->logFailure(
671 $this->userObj->getImportId(),
672 sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "AuthMode", "type", $this->stripTags($a_attribs['type']))
673 );
674 }
675 break;
676 }
677 if (strcmp('ldap', $a_attribs['type']) === 0) {
678 // no server id provided
679 include_once './Services/LDAP/classes/class.ilLDAPServer.php';
681 if (count($list) != 1) {
682 $this->logFailure(
683 $this->userObj->getImportId(),
684 sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "AuthMode", "type", $this->stripTags($a_attribs['type']))
685 );
686 }
687 }
688 break;
689
690 case "default":
691 case "local":
692 case "radius":
693 case "shibboleth":
694 case "script":
695 case "cas":
696 case "soap":
697 case "openid":
698 // begin-patch auth_plugin
699 default:
700 $this->userObj->setAuthMode($a_attribs["type"]);
701 break;
702 }
703 } else {
704 $this->logFailure($this->userObj->getImportId(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "AuthMode", "type", ""));
705 }
706 break;
707 case 'Pref':
708 $this->currentPrefKey = $a_attribs["key"];
709 break;
710
711 }
712 }
713
717 public function handlerEndTag($a_xml_parser, $a_name)
718 {
719 switch ($this->mode) {
720 case IL_EXTRACT_ROLES:
721 $this->extractRolesEndTag($a_xml_parser, $a_name);
722 break;
723 case IL_USER_IMPORT:
724 $this->importEndTag($a_xml_parser, $a_name);
725 break;
726 case IL_VERIFY:
727 $this->verifyEndTag($a_xml_parser, $a_name);
728 break;
729 }
730 }
731
735 public function extractRolesEndTag($a_xml_parser, $a_name)
736 {
737 switch ($a_name) {
738 case "Role":
739 $this->roles[$this->current_role_id]["name"] = $this->cdata;
740 $this->roles[$this->current_role_id]["type"] =
741 $this->current_role_type;
742 break;
743 }
744 }
745
749 public function getRoleObject($a_role_id)
750 {
751 if (array_key_exists($a_role_id, $this->localRoleCache)) {
752 return $this->localRoleCache[$a_role_id];
753 } else {
754 $role_obj = new ilObjRole($a_role_id, false);
755 $role_obj->read();
756 $this->localRoleCache[$a_role_id] = $role_obj;
757 return $role_obj;
758 }
759 }
763 public function getCourseMembersObjectForRole($a_role_id)
764 {
765 global $DIC;
766
767 $rbacreview = $DIC['rbacreview'];
768 $rbacadmin = $DIC['rbacadmin'];
769 $tree = $DIC['tree'];
770
771 if (array_key_exists($a_role_id . '_courseMembersObject', $this->localRoleCache)) {
772 return $this->localRoleCache[$a_role_id . '_courseMembersObject'];
773 } else {
774 require_once("Modules/Course/classes/class.ilObjCourse.php");
775 require_once("Modules/Course/classes/class.ilCourseParticipants.php");
776 $course_refs = $rbacreview->getFoldersAssignedToRole($a_role_id, true);
777 $course_ref = $course_refs[0];
778 $course_obj = new ilObjCourse($course_ref, true);
779 $crsmembers_obj = ilCourseParticipants::_getInstanceByObjId($course_obj->getId());
780 $this->localRoleCache[$a_role_id . '_courseMembersObject'] = $crsmembers_obj;
781 return $crsmembers_obj;
782 }
783 }
784
788 public function assignToRole($a_user_obj, $a_role_id)
789 {
790 require_once "./Services/AccessControl/classes/class.ilObjRole.php";
791 include_once('./Services/Object/classes/class.ilObject.php');
792 #require_once "Modules/Course/classes/class.ilObjCourse.php";
793 #require_once "Modules/Course/classes/class.ilCourseParticipants.php";
794
795 global $DIC;
796
797 $rbacreview = $DIC['rbacreview'];
798 $rbacadmin = $DIC['rbacadmin'];
799 $tree = $DIC['tree'];
800
801 // Do nothing, if the user is already assigned to the role.
802 // Specifically, we do not want to put a course object or
803 // group object on the personal desktop again, if a user
804 // has removed it from the personal desktop.
805 if ($rbacreview->isAssigned($a_user_obj->getId(), $a_role_id)) {
806 return;
807 }
808
809 // If it is a course role, use the ilCourseMember object to assign
810 // the user to the role
811
812 $rbacadmin->assignUser($a_role_id, $a_user_obj->getId(), true);
813 $obj_id = $rbacreview->getObjectOfRole($a_role_id);
814 switch ($type = ilObject::_lookupType($obj_id)) {
815 case 'grp':
816 case 'crs':
817 $ref_ids = ilObject::_getAllReferences($obj_id);
818 $ref_id = current((array) $ref_ids);
819 if ($ref_id) {
820 // deactivated for now, see discussion at
821 // https://docu.ilias.de/goto_docu_wiki_wpage_5620_1357.html
822 //$this->recommended_content_manager->addObjectRecommendation($a_user_obj->getId(), $ref_id);
823 }
824 break;
825 default:
826 break;
827 }
828 }
833 public function getParentRoleIds($a_role_id)
834 {
835 global $DIC;
836
837 $rbacreview = $DIC['rbacreview'];
838
839 if (!array_key_exists($a_role_id, $this->parentRolesCache)) {
840 $parent_role_ids = array();
841
842 $role_obj = $this->getRoleObject($a_role_id);
843 $short_role_title = substr($role_obj->getTitle(), 0, 12);
844 $folders = $rbacreview->getFoldersAssignedToRole($a_role_id, true);
845 if (count($folders) > 0) {
846 $all_parent_role_ids = $rbacreview->getParentRoleIds($folders[0]);
847 foreach ($all_parent_role_ids as $parent_role_id => $parent_role_data) {
848 if ($parent_role_id != $a_role_id) {
849 switch (substr($parent_role_data['title'], 0, 12)) {
850 case 'il_crs_admin':
851 case 'il_grp_admin':
852 if ($short_role_title == 'il_crs_admin' || $short_role_title == 'il_grp_admin') {
853 $parent_role_ids[] = $parent_role_id;
854 }
855 break;
856 case 'il_crs_tutor':
857 case 'il_grp_tutor':
858 if ($short_role_title == 'il_crs_tutor' || $short_role_title == 'il_grp_tutor') {
859 $parent_role_ids[] = $parent_role_id;
860 }
861 break;
862 case 'il_crs_membe':
863 case 'il_grp_membe':
864 if ($short_role_title == 'il_crs_membe' || $short_role_title == 'il_grp_membe') {
865 $parent_role_ids[] = $parent_role_id;
866 }
867 break;
868 default:
869 break;
870 }
871 }
872 }
873 }
874 $this->parentRolesCache[$a_role_id] = $parent_role_ids;
875 }
876 return $this->parentRolesCache[$a_role_id];
877 }
881 public function assignToRoleWithParents($a_user_obj, $a_role_id)
882 {
883 $this->assignToRole($a_user_obj, $a_role_id);
884
885 $parent_role_ids = $this->getParentRoleIds($a_role_id);
886 foreach ($parent_role_ids as $parent_role_id) {
887 $this->assignToRole($a_user_obj, $parent_role_id);
888 }
889 }
893 public function detachFromRole($a_user_obj, $a_role_id)
894 {
895 global $DIC;
896
897 $rbacreview = $DIC['rbacreview'];
898 $rbacadmin = $DIC['rbacadmin'];
899 $tree = $DIC['tree'];
900
901 $rbacadmin->deassignUser($a_role_id, $a_user_obj->getId());
902
903 if (substr(ilObject::_lookupTitle($a_role_id), 0, 6) == 'il_crs' or
904 substr(ilObject::_lookupTitle($a_role_id), 0, 6) == 'il_grp') {
905 $obj = $rbacreview->getObjectOfRole($a_role_id);
906 $ref = ilObject::_getAllReferences($obj);
907 $ref_id = end($ref);
908 $this->recommended_content_manager->removeObjectRecommendation($a_user_obj->getId(), $ref_id);
909 }
910 }
911
915 public function importEndTag($a_xml_parser, $a_name)
916 {
917 global $DIC;
918
919 $ilias = $DIC['ilias'];
920 $rbacadmin = $DIC['rbacadmin'];
921 $rbacreview = $DIC['rbacreview'];
922 $ilUser = $DIC['ilUser'];
923 $lng = $DIC['lng'];
924 $ilSetting = $DIC['ilSetting'];
925
926 switch ($a_name) {
927 case "Role":
928 $this->roles[$this->current_role_id]["name"] = $this->cdata;
929 $this->roles[$this->current_role_id]["type"] = $this->current_role_type;
930 $this->roles[$this->current_role_id]["action"] = $this->current_role_action;
931 break;
932
933 case "PersonalPicture":
934 switch ($this->personalPicture["encoding"]) {
935 case "Base64":
936 $this->personalPicture["content"] = base64_decode($this->cdata);
937 break;
938 case "UUEncode":
939 $this->personalPicture["content"] = convert_uudecode($this->cdata);
940 break;
941 }
942 break;
943
944 case "User":
945 $this->userObj->setFullname();
946 // Fetch the user_id from the database, if we didn't have it in xml file
947 // fetch as well, if we are trying to insert -> recognize duplicates!
948 if ($this->user_id == -1 || $this->action == "Insert") {
949 $user_id = ilObjUser::getUserIdByLogin($this->userObj->getLogin());
950 } else {
952 }
953
954 if ($user_id === (int) ANONYMOUS_USER_ID || $user_id === (int) SYSTEM_USER_ID) {
955 return;
956 }
957
958 // Handle conflicts
959 switch ($this->conflict_rule) {
961 // do not change action
962 break;
964 switch ($this->action) {
965 case "Insert":
966 if ($user_id) {
967 $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_replaced"), "Insert", "Update"));
968 $this->action = "Update";
969 }
970 break;
971 case "Update":
972 if (!$user_id) {
973 $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_replaced"), "Update", "Insert"));
974 $this->action = "Insert";
975 }
976 break;
977 case "Delete":
978 if (!$user_id) {
979 $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_ignored"), "Delete"));
980 $this->action = "Ignore";
981 }
982 break;
983 }
984 break;
986 switch ($this->action) {
987 case "Insert":
988 if ($user_id) {
989 $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_ignored"), "Insert"));
990 $this->action = "Ignore";
991 }
992 break;
993 case "Update":
994 if (!$user_id) {
995 $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_ignored"), "Update"));
996 $this->action = "Ignore";
997 }
998 break;
999 case "Delete":
1000 if (!$user_id) {
1001 $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_ignored"), "Delete"));
1002 $this->action = "Ignore";
1003 }
1004 break;
1005 }
1006 break;
1007 }
1008
1009 // check external account conflict (if external account is already used)
1010 // note: we cannot apply conflict rules in the same manner as to logins here
1011 // so we ignore records with already existing external accounts.
1012 //echo $this->userObj->getAuthMode().'h';
1013 $am = ($this->userObj->getAuthMode() == "default" || $this->userObj->getAuthMode() == "")
1014 ? ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode'))
1015 : $this->userObj->getAuthMode();
1016 $loginForExternalAccount = ($this->userObj->getExternalAccount() == "")
1017 ? ""
1018 : ilObjUser::_checkExternalAuthAccount($am, $this->userObj->getExternalAccount());
1019 switch ($this->action) {
1020 case "Insert":
1021 if ($loginForExternalAccount != "") {
1022 $this->logWarning(
1023 $this->userObj->getLogin(),
1024 $lng->txt('usrimport_no_insert_ext_account_exists')
1025 . ' (' . $this->stripTags($this->userObj->getExternalAccount()) . ')'
1026 );
1027 $this->action = "Ignore";
1028 }
1029 break;
1030
1031 case "Update":
1032 // this variable describes the ILIAS login which belongs to the given external account!!!
1033 // it is NOT nescessarily the ILIAS login of the current user record !!
1034 // so if we found an ILIAS login according to the authentication method
1035 // check if the ILIAS login belongs to the current user record, otherwise somebody else is using it!
1036 if ($loginForExternalAccount != "") {
1037 // check if we changed the value!
1038 $externalAccountHasChanged = $this->userObj->getExternalAccount() != ilObjUser::_lookupExternalAccount($this->user_id);
1039 // if it has changed and the external login
1040 if ($externalAccountHasChanged && trim($loginForExternalAccount) != trim($this->userObj->getLogin())) {
1041 $this->logWarning(
1042 $this->userObj->getLogin(),
1043 $lng->txt('usrimport_no_update_ext_account_exists')
1044 . ' (' . $this->stripTags($this->userObj->getExternalAccount()) . ')'
1045 );
1046 $this->action = "Ignore";
1047 }
1048 }
1049 break;
1050 }
1051
1052 if (sizeof($this->multi_values)) {
1053 if (isset($this->multi_values["GeneralInterest"])) {
1054 $this->userObj->setGeneralInterests($this->multi_values["GeneralInterest"]);
1055 }
1056 if (isset($this->multi_values["OfferingHelp"])) {
1057 $this->userObj->setOfferingHelp($this->multi_values["OfferingHelp"]);
1058 }
1059 if (isset($this->multi_values["LookingForHelp"])) {
1060 $this->userObj->setLookingForHelp($this->multi_values["LookingForHelp"]);
1061 }
1062 }
1063
1064 // Perform the action
1065 switch ($this->action) {
1066 case "Insert":
1067 if ($user_id) {
1068 $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_cant_insert"));
1069 } else {
1070 if (!strlen($this->currPassword) == 0) {
1071 switch (strtoupper($this->currPasswordType)) {
1072 case "BCRYPT":
1073 $this->userObj->setPasswd($this->currPassword, IL_PASSWD_CRYPTED);
1074 $this->userObj->setPasswordEncodingType('bcryptphp');
1075 $this->userObj->setPasswordSalt(null);
1076 break;
1077
1078 case "PLAIN":
1079 $this->userObj->setPasswd($this->currPassword, IL_PASSWD_PLAIN);
1080 $this->acc_mail->setUserPassword($this->currPassword);
1081 break;
1082
1083 default:
1084 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "Type", "Password", $this->stripTags($this->currPasswordType)));
1085 break;
1086
1087 }
1088 } else {
1089 // this does the trick for empty passwords
1090 // since a MD5 string has always 32 characters,
1091 // no hashed password combination will ever equal to
1092 // an empty string
1093 $this->userObj->setPasswd("", IL_PASSWD_CRYPTED);
1094 }
1095
1096 $this->userObj->setTitle($this->userObj->getFullname());
1097 $this->userObj->setDescription($this->userObj->getEmail());
1098
1099 if (!$this->time_limit_owner_set) {
1100 $this->userObj->setTimeLimitOwner($this->getFolderId());
1101 }
1102
1103 // default time limit settings
1104 if (!$this->time_limit_set) {
1105 $this->userObj->setTimeLimitUnlimited(1);
1106 $this->userObj->setTimeLimitMessage(0);
1107
1108 if (!$this->approve_date_set) {
1109 $this->userObj->setApproveDate(date("Y-m-d H:i:s"));
1110 }
1111 }
1112
1113
1114 $this->userObj->setActive($this->currActive == 'true' || is_null($this->currActive));
1115
1116 // Finally before saving new user.
1117 // Check if profile is incomplete
1118
1119 // #8759
1120 if (count($this->udf_data)) {
1121 $this->userObj->setUserDefinedData($this->udf_data);
1122 }
1123
1124 if (!$this->userObj->getLanguage()) {
1125 $this->userObj->setLanguage($this->lng->getDefaultLanguage());
1126 }
1127
1128 $this->userObj->setProfileIncomplete($this->checkProfileIncomplete($this->userObj));
1129 $this->userObj->create();
1130
1131 //insert user data in table user_data
1132 $this->userObj->saveAsNew(false);
1133
1134 // Set default prefs
1135 $this->userObj->setPref('hits_per_page', $ilSetting->get('hits_per_page', 30));
1136 //$this->userObj->setPref('show_users_online',$ilSetting->get('show_users_online','y'));
1137
1138 if (count($this->prefs)) {
1139 foreach ($this->prefs as $key => $value) {
1140 if ($key != "mail_incoming_type" &&
1141 $key != "mail_signature" &&
1142 $key != "mail_linebreak"
1143 ) {
1144 $this->userObj->setPref($key, $value);
1145 }
1146 }
1147 }
1148
1149 if (!is_array($this->prefs) || array_search('chat_osc_accept_msg', $this->prefs) === false) {
1150 $this->userObj->setPref('chat_osc_accept_msg', $ilSetting->get('chat_osc_accept_msg', 'n'));
1151 }
1152 if (!is_array($this->prefs) || array_search('bs_allow_to_contact_me', $this->prefs) === false) {
1153 $this->userObj->setPref('bs_allow_to_contact_me', $ilSetting->get('bs_allow_to_contact_me', 'n'));
1154 }
1155
1156 $this->userObj->writePrefs();
1157
1158 // update mail preferences, to be extended
1159 $this->updateMailPreferences($this->userObj->getId());
1160
1161 if (is_array($this->personalPicture)) {
1162 if (strlen($this->personalPicture["content"])) {
1163 $extension = "jpg";
1164 if (preg_match("/.*(png|jpg|gif|jpeg)$/", $this->personalPicture["imagetype"], $matches)) {
1165 $extension = $matches[1];
1166 }
1167 $tmp_name = $this->saveTempImage($this->personalPicture["content"], ".$extension");
1168 if (strlen($tmp_name)) {
1169 ilObjUser::_uploadPersonalPicture($tmp_name, $this->userObj->getId());
1170 unlink($tmp_name);
1171 }
1172 }
1173 }
1174
1175 //set role entries
1176 foreach ($this->roles as $role_id => $role) {
1177 if ($this->role_assign[$role_id]) {
1178 $this->assignToRole($this->userObj, $this->role_assign[$role_id]);
1179 }
1180 }
1181
1182 if (count($this->udf_data)) {
1183 include_once './Services/User/classes/class.ilUserDefinedData.php';
1184 $udd = new ilUserDefinedData($this->userObj->getId());
1185 foreach ($this->udf_data as $field => $value) {
1186 $udd->set("f_" . $field, $value);
1187 }
1188 $udd->update();
1189 }
1190
1191 $this->sendAccountMail();
1192 $this->logSuccess($this->userObj->getLogin(), $this->userObj->getId(), "Insert");
1193 // reset account mail object
1194 $this->acc_mail->reset();
1195 }
1196 break;
1197
1198 case "Update":
1199 if (!$user_id) {
1200 $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_cant_update"));
1201 } else {
1202 $updateUser = new ilObjUser($user_id);
1203 $updateUser->read();
1204 $updateUser->readPrefs();
1205 if ($this->currPassword != null) {
1206 switch (strtoupper($this->currPasswordType)) {
1207 case "BCRYPT":
1208 $updateUser->setPasswd($this->currPassword, IL_PASSWD_CRYPTED);
1209 $updateUser->setPasswordEncodingType('bcryptphp');
1210 $updateUser->setPasswordSalt(null);
1211 break;
1212
1213 case "PLAIN":
1214 $updateUser->setPasswd($this->currPassword, IL_PASSWD_PLAIN);
1215 $this->acc_mail->setUserPassword($this->currPassword);
1216 break;
1217
1218 default:
1219 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "Type", "Password", $this->stripTags($this->currPasswordType)));
1220 break;
1221 }
1222 }
1223 if (!is_null($this->userObj->getFirstname())) {
1224 $updateUser->setFirstname($this->userObj->getFirstname());
1225 }
1226 if (!is_null($this->userObj->getLastname())) {
1227 $updateUser->setLastname($this->userObj->getLastname());
1228 }
1229 if (!is_null($this->userObj->getUTitle())) {
1230 $updateUser->setUTitle($this->userObj->getUTitle());
1231 }
1232 if (!is_null($this->userObj->getGender())) {
1233 $updateUser->setGender($this->userObj->getGender());
1234 }
1235 if (!is_null($this->userObj->getEmail())) {
1236 $updateUser->setEmail($this->userObj->getEmail());
1237 }
1238 if (!is_null($this->userObj->getSecondEmail())) {
1239 $updateUser->setSecondEmail($this->userObj->getSecondEmail());
1240 }
1241 if (!is_null($this->userObj->getBirthday())) {
1242 $updateUser->setBirthday($this->userObj->getBirthday());
1243 }
1244 if (!is_null($this->userObj->getInstitution())) {
1245 $updateUser->setInstitution($this->userObj->getInstitution());
1246 }
1247 if (!is_null($this->userObj->getStreet())) {
1248 $updateUser->setStreet($this->userObj->getStreet());
1249 }
1250 if (!is_null($this->userObj->getCity())) {
1251 $updateUser->setCity($this->userObj->getCity());
1252 }
1253 if (!is_null($this->userObj->getZipCode())) {
1254 $updateUser->setZipCode($this->userObj->getZipCode());
1255 }
1256 if (!is_null($this->userObj->getCountry())) {
1257 $updateUser->setCountry($this->userObj->getCountry());
1258 }
1259 if (!is_null($this->userObj->getSelectedCountry())) {
1260 $updateUser->setSelectedCountry($this->userObj->getSelectedCountry());
1261 }
1262 if (!is_null($this->userObj->getPhoneOffice())) {
1263 $updateUser->setPhoneOffice($this->userObj->getPhoneOffice());
1264 }
1265 if (!is_null($this->userObj->getPhoneHome())) {
1266 $updateUser->setPhoneHome($this->userObj->getPhoneHome());
1267 }
1268 if (!is_null($this->userObj->getPhoneMobile())) {
1269 $updateUser->setPhoneMobile($this->userObj->getPhoneMobile());
1270 }
1271 if (!is_null($this->userObj->getFax())) {
1272 $updateUser->setFax($this->userObj->getFax());
1273 }
1274 if (!is_null($this->userObj->getHobby())) {
1275 $updateUser->setHobby($this->userObj->getHobby());
1276 }
1277 if (!is_null($this->userObj->getGeneralInterests())) {
1278 $updateUser->setGeneralInterests($this->userObj->getGeneralInterests());
1279 }
1280 if (!is_null($this->userObj->getOfferingHelp())) {
1281 $updateUser->setOfferingHelp($this->userObj->getOfferingHelp());
1282 }
1283 if (!is_null($this->userObj->getLookingForHelp())) {
1284 $updateUser->setLookingForHelp($this->userObj->getLookingForHelp());
1285 }
1286 if (!is_null($this->userObj->getComment())) {
1287 $updateUser->setComment($this->userObj->getComment());
1288 }
1289 if (!is_null($this->userObj->getDepartment())) {
1290 $updateUser->setDepartment($this->userObj->getDepartment());
1291 }
1292 if (!is_null($this->userObj->getMatriculation())) {
1293 $updateUser->setMatriculation($this->userObj->getMatriculation());
1294 }
1295 if (!is_null($this->currActive)) {
1296 $updateUser->setActive($this->currActive == "true", is_object($ilUser) ? $ilUser->getId() : 0);
1297 }
1298 if (!is_null($this->userObj->getClientIP())) {
1299 $updateUser->setClientIP($this->userObj->getClientIP());
1300 }
1301 if (!is_null($this->userObj->getTimeLimitUnlimited())) {
1302 $updateUser->setTimeLimitUnlimited($this->userObj->getTimeLimitUnlimited());
1303 }
1304 if (!is_null($this->userObj->getTimeLimitFrom())) {
1305 $updateUser->setTimeLimitFrom($this->userObj->getTimeLimitFrom());
1306 }
1307 if (!is_null($this->userObj->getTimeLimitUntil())) {
1308 $updateUser->setTimeLimitUntil($this->userObj->getTimeLimitUntil());
1309 }
1310 if (!is_null($this->userObj->getTimeLimitMessage())) {
1311 $updateUser->setTimeLimitMessage($this->userObj->getTimeLimitMessage());
1312 }
1313 if (!is_null($this->userObj->getApproveDate())) {
1314 $updateUser->setApproveDate($this->userObj->getApproveDate());
1315 }
1316 if (!is_null($this->userObj->getAgreeDate())) {
1317 $updateUser->setAgreeDate($this->userObj->getAgreeDate());
1318 }
1319 if (!is_null($this->userObj->getLanguage())) {
1320 $updateUser->setLanguage($this->userObj->getLanguage());
1321 }
1322 if (!is_null($this->userObj->getExternalAccount())) {
1323 $updateUser->setExternalAccount($this->userObj->getExternalAccount());
1324 }
1325
1326 // Fixed: if auth_mode is not set, it was always overwritten with auth_default
1327 #if (! is_null($this->userObj->getAuthMode())) $updateUser->setAuthMode($this->userObj->getAuthMode());
1328 if ($this->auth_mode_set) {
1329 $updateUser->setAuthMode($this->userObj->getAuthMode());
1330 }
1331
1332 // Special handlin since it defaults to 7 (USER_FOLDER_ID)
1333 if ($this->time_limit_owner_set) {
1334 $updateUser->setTimeLimitOwner($this->userObj->getTimeLimitOwner());
1335 }
1336
1337
1338 if (count($this->prefs)) {
1339 foreach ($this->prefs as $key => $value) {
1340 if ($key != "mail_incoming_type" &&
1341 $key != "mail_signature" &&
1342 $key != "mail_linebreak"
1343 ) {
1344 $updateUser->setPref($key, $value);
1345 }
1346 }
1347 }
1348
1349 // save user preferences (skin and style)
1350 if ($this->updateLookAndSkin) {
1351 $updateUser->setPref("skin", $this->userObj->getPref("skin"));
1352 $updateUser->setPref("style", $this->userObj->getPref("style"));
1353 }
1354
1355
1356 $updateUser->writePrefs();
1357
1358 // update mail preferences, to be extended
1359 $this->updateMailPreferences($updateUser->getId());
1360
1361 // #8759
1362 if (count($this->udf_data)) {
1363 $updateUser->setUserDefinedData($this->udf_data);
1364 }
1365
1366 $updateUser->setProfileIncomplete($this->checkProfileIncomplete($updateUser));
1367 $updateUser->setFullname();
1368 $updateUser->setTitle($updateUser->getFullname());
1369 $updateUser->setDescription($updateUser->getEmail());
1370 $updateUser->update();
1371
1372 if (count($this->udf_data)) {
1373 include_once './Services/User/classes/class.ilUserDefinedData.php';
1374 $udd = new ilUserDefinedData($updateUser->getId());
1375 foreach ($this->udf_data as $field => $value) {
1376 $udd->set("f_" . $field, $value);
1377 }
1378 $udd->update();
1379 }
1380
1381 // update login
1382 if (!is_null($this->userObj->getLogin()) && $this->user_id != -1) {
1383 try {
1384 $updateUser->updateLogin($this->userObj->getLogin());
1385 } catch (ilUserException $e) {
1386 }
1387 }
1388
1389
1390 // if language has changed
1391
1392 if (is_array($this->personalPicture)) {
1393 if (strlen($this->personalPicture["content"])) {
1394 $extension = "jpg";
1395 if (preg_match("/.*(png|jpg|gif|jpeg)$/", $this->personalPicture["imagetype"], $matches)) {
1396 $extension = $matches[1];
1397 }
1398 $tmp_name = $this->saveTempImage($this->personalPicture["content"], ".$extension");
1399 if (strlen($tmp_name)) {
1400 ilObjUser::_uploadPersonalPicture($tmp_name, $updateUser->getId());
1401 unlink($tmp_name);
1402 }
1403 }
1404 }
1405
1406
1407 //update role entries
1408 //-------------------
1409 foreach ($this->roles as $role_id => $role) {
1410 if (array_key_exists($role_id, $this->role_assign)) {
1411 switch ($role["action"]) {
1412 case "Assign":
1413 $this->assignToRole($updateUser, $this->role_assign[$role_id]);
1414 break;
1415 case "AssignWithParents":
1416 $this->assignToRoleWithParents($updateUser, $this->role_assign[$role_id]);
1417 break;
1418 case "Detach":
1419 $this->detachFromRole($updateUser, $this->role_assign[$role_id]);
1420 break;
1421 }
1422 }
1423 }
1424 $this->logSuccess($updateUser->getLogin(), $user_id, "Update");
1425 }
1426 break;
1427 case "Delete":
1428 if (!$user_id) {
1429 $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_cant_delete"));
1430 } else {
1431 $deleteUser = new ilObjUser($user_id);
1432 $deleteUser->delete();
1433
1434 $this->logSuccess($this->userObj->getLogin(), $user_id, "Delete");
1435 }
1436 break;
1437 }
1438
1439 // init role array for next user
1440 $this->roles = array();
1441 break;
1442
1443 case "Login":
1444 $this->userObj->setLogin($this->getCDataWithoutTags($this->cdata));
1445 break;
1446
1447 case "Password":
1448 $this->currPassword = $this->cdata;
1449 break;
1450
1451 case "Firstname":
1452 $this->userObj->setFirstname($this->getCDataWithoutTags($this->cdata));
1453 break;
1454
1455 case "Lastname":
1456 $this->userObj->setLastname($this->getCDataWithoutTags($this->cdata));
1457 break;
1458
1459 case "Title":
1460 $this->userObj->setUTitle($this->getCDataWithoutTags($this->cdata));
1461 break;
1462
1463 case "Gender":
1464 $this->userObj->setGender($this->cdata);
1465 break;
1466
1467 case "Email":
1468 $this->userObj->setEmail($this->getCDataWithoutTags($this->cdata));
1469 break;
1470 case "SecondEmail":
1471 $this->userObj->setSecondEmail($this->getCDataWithoutTags($this->cdata));
1472 break;
1473 case "Birthday":
1474 $birthday = $this->getCDataWithoutTags($this->cdata);
1475 if (strtotime($birthday) !== false) {
1476 $this->userObj->setBirthday($birthday);
1477 }
1478 break;
1479 case "Institution":
1480 $this->userObj->setInstitution($this->getCDataWithoutTags($this->cdata));
1481 break;
1482
1483 case "Street":
1484 $this->userObj->setStreet($this->getCDataWithoutTags($this->cdata));
1485 break;
1486
1487 case "City":
1488 $this->userObj->setCity($this->getCDataWithoutTags($this->cdata));
1489 break;
1490
1491 case "PostalCode":
1492 $this->userObj->setZipCode($this->getCDataWithoutTags($this->cdata));
1493 break;
1494
1495 case "Country":
1496 $this->userObj->setCountry($this->getCDataWithoutTags($this->cdata));
1497 break;
1498
1499 case "SelCountry":
1500 $this->userObj->setSelectedCountry($this->getCDataWithoutTags($this->cdata));
1501 break;
1502
1503 case "PhoneOffice":
1504 $this->userObj->setPhoneOffice($this->getCDataWithoutTags($this->cdata));
1505 break;
1506
1507 case "PhoneHome":
1508 $this->userObj->setPhoneHome($this->getCDataWithoutTags($this->cdata));
1509 break;
1510
1511 case "PhoneMobile":
1512 $this->userObj->setPhoneMobile($this->getCDataWithoutTags($this->cdata));
1513 break;
1514
1515 case "Fax":
1516 $this->userObj->setFax($this->getCDataWithoutTags($this->cdata));
1517 break;
1518
1519 case "Hobby":
1520 $this->userObj->setHobby($this->getCDataWithoutTags($this->cdata));
1521 break;
1522
1523 case "GeneralInterest":
1524 case "OfferingHelp":
1525 case "LookingForHelp":
1526 $this->multi_values[$a_name][] = $this->getCDataWithoutTags($this->cdata);
1527 break;
1528
1529 case "Comment":
1530 $this->userObj->setComment($this->getCDataWithoutTags($this->cdata));
1531 break;
1532
1533 case "Department":
1534 $this->userObj->setDepartment($this->getCDataWithoutTags($this->cdata));
1535 break;
1536
1537 case "Matriculation":
1538 $this->userObj->setMatriculation($this->getCDataWithoutTags($this->cdata));
1539 break;
1540
1541 case "Active":
1542 $this->currActive = $this->cdata;
1543 break;
1544
1545 case "ClientIP":
1546 $this->userObj->setClientIP($this->getCDataWithoutTags($this->cdata));
1547 break;
1548
1549 case "TimeLimitOwner":
1550 $this->time_limit_owner_set = true;
1551 $this->userObj->setTimeLimitOwner($this->cdata);
1552 break;
1553
1554 case "TimeLimitUnlimited":
1555 $this->time_limit_set = true;
1556 $this->userObj->setTimeLimitUnlimited($this->cdata);
1557 break;
1558
1559 case "TimeLimitFrom":
1560 if (is_numeric($this->cdata)) {
1561 // Treat cdata as a unix timestamp
1562 $this->userObj->setTimeLimitFrom($this->cdata);
1563 } else {
1564 // Try to convert cdata into unix timestamp, or ignore it
1565 $timestamp = strtotime($this->cdata);
1566 if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00") {
1567 $this->userObj->setTimeLimitFrom($timestamp);
1568 } elseif ($this->cdata == "0000-00-00 00:00:00") {
1569 $this->userObj->setTimeLimitFrom(null);
1570 }
1571 }
1572 break;
1573
1574 case "TimeLimitUntil":
1575 if (is_numeric($this->cdata)) {
1576 // Treat cdata as a unix timestamp
1577 $this->userObj->setTimeLimitUntil($this->cdata);
1578 } else {
1579 // Try to convert cdata into unix timestamp, or ignore it
1580 $timestamp = strtotime($this->cdata);
1581 if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00") {
1582 $this->userObj->setTimeLimitUntil($timestamp);
1583 } elseif ($this->cdata == "0000-00-00 00:00:00") {
1584 $this->userObj->setTimeLimitUntil(null);
1585 }
1586 }
1587 break;
1588
1589 case "TimeLimitMessage":
1590 $this->userObj->setTimeLimitMessage($this->cdata);
1591 break;
1592
1593 case "ApproveDate":
1594 $this->approve_date_set = true;
1595 if (is_numeric($this->cdata)) {
1596 // Treat cdata as a unix timestamp
1597 $tmp_date = new ilDateTime($this->cdata, IL_CAL_UNIX);
1598 $this->userObj->setApproveDate($tmp_date->get(IL_CAL_DATETIME));
1599 } else {
1600 // Try to convert cdata into unix timestamp, or ignore it
1601 $timestamp = strtotime($this->cdata);
1602 if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00") {
1603 $tmp_date = new ilDateTime($timestamp, IL_CAL_UNIX);
1604 $this->userObj->setApproveDate($tmp_date->get(IL_CAL_DATETIME));
1605 } elseif ($this->cdata == "0000-00-00 00:00:00") {
1606 $this->userObj->setApproveDate(null);
1607 }
1608 }
1609 break;
1610
1611 case "AgreeDate":
1612 if (is_numeric($this->cdata)) {
1613 // Treat cdata as a unix timestamp
1614 $tmp_date = new ilDateTime($this->cdata, IL_CAL_UNIX);
1615 $this->userObj->setAgreeDate($tmp_date->get(IL_CAL_DATETIME));
1616 } else {
1617 // Try to convert cdata into unix timestamp, or ignore it
1618 $timestamp = strtotime($this->cdata);
1619 if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00") {
1620 $tmp_date = new ilDateTime($timestamp, IL_CAL_UNIX);
1621 $this->userObj->setAgreeDate($tmp_date->get(IL_CAL_DATETIME));
1622 } elseif ($this->cdata == "0000-00-00 00:00:00") {
1623 $this->userObj->setAgreeDate(null);
1624 }
1625 }
1626 break;
1627
1628 case "ExternalAccount":
1629 $this->userObj->setExternalAccount($this->getCDataWithoutTags($this->cdata));
1630 break;
1631
1632 case "Look":
1633 $this->updateLookAndSkin = false;
1634 if (!$this->hideSkin) {
1635 // TODO: what to do with disabled skins? is it possible to change the skin via import?
1636 if ((strlen($this->skin) > 0) && (strlen($this->style) > 0)) {
1637 if (is_array($this->userStyles)) {
1638 if (in_array($this->skin . ":" . $this->style, $this->userStyles)) {
1639 $this->userObj->setPref("skin", $this->skin);
1640 $this->userObj->setPref("style", $this->style);
1641 $this->updateLookAndSkin = true;
1642 }
1643 }
1644 }
1645 }
1646 break;
1647
1648 case 'UserDefinedField':
1649 include_once './Services/User/classes/class.ilUserDefinedFields.php';
1651
1652 $field_id = $udf->fetchFieldIdFromImportId($this->tmp_udf_id);
1653
1654 if ($field_id === 0) {
1655 $field_id = $udf->fetchFieldIdFromName($this->tmp_udf_name);
1656 }
1657
1658 if ($field_id === 0) {
1659 break;
1660 }
1661
1662 $this->udf_data[$field_id] = strip_tags($this->cdata, ilObjAdvancedEditing::_getUsedHTMLTags('textarea'));
1663
1664 break;
1665 case 'AccountInfo':
1666 if ($this->current_messenger_type == "external") {
1667 $this->userObj->setExternalAccount($this->cdata);
1668 }
1669 break;
1670 case 'Pref':
1671 if ($this->currentPrefKey != null && strlen(trim($this->cdata)) > 0
1672 && ilUserXMLWriter::isPrefExportable($this->currentPrefKey)) {
1673 $this->prefs[$this->currentPrefKey] = trim($this->cdata);
1674 }
1675 $this->currentPrefKey = null;
1676 break;
1677 }
1678 }
1679
1684 public function saveTempImage($image_data, $filename)
1685 {
1686 $tempname = ilUtil::ilTempnam() . $filename;
1687 $fh = fopen($tempname, "wb");
1688 if ($fh == false) {
1689 return "";
1690 }
1691 $imagefile = fwrite($fh, $image_data);
1692 fclose($fh);
1693 return $tempname;
1694 }
1695
1699 public function verifyEndTag($a_xml_parser, $a_name)
1700 {
1701 global $DIC;
1702
1703 $lng = $DIC['lng'];
1704 $ilAccess = $DIC['ilAccess'];
1705 $ilSetting = $DIC['ilSetting'];
1706 $ilObjDataCache = $DIC['ilObjDataCache'];
1707
1708 switch ($a_name) {
1709 case "Role":
1710 $this->roles[$this->current_role_id]["name"] = $this->cdata;
1711 $this->roles[$this->current_role_id]["type"] = $this->current_role_type;
1712 $this->roles[$this->current_role_id]["action"] = $this->current_role_action;
1713 break;
1714
1715 case "User":
1716 $this->userObj->setFullname();
1717 if ($this->user_id != -1 && ($this->action == "Update" || $this->action == "Delete")) {
1719 $user_exists = !is_null(ilObjUser::_lookupLogin($this->user_id));
1720 } else {
1721 $user_id = ilObjUser::getUserIdByLogin($this->userObj->getLogin());
1722 $user_exists = $user_id != 0;
1723 }
1724
1725 if (is_null($this->userObj->getLogin())) {
1726 $this->logFailure("---", sprintf($lng->txt("usrimport_xml_element_for_action_required"), "Login", "Insert"));
1727 }
1728
1729 if ($user_id === (int) ANONYMOUS_USER_ID || $user_id === (int) SYSTEM_USER_ID) {
1730 $this->logWarning($this->userObj->getLogin(), $lng->txt('usrimport_xml_anonymous_or_root_not_allowed'));
1731 break;
1732 }
1733
1734 switch ($this->action) {
1735 case "Insert":
1736 if ($user_exists and $this->conflict_rule == IL_FAIL_ON_CONFLICT) {
1737 $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_cant_insert"));
1738 }
1739 if (is_null($this->userObj->getGender()) && $this->isFieldRequired("gender")) {
1740 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_for_action_required"), "Gender", "Insert"));
1741 }
1742 if (is_null($this->userObj->getFirstname())) {
1743 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_for_action_required"), "Firstname", "Insert"));
1744 }
1745 if (is_null($this->userObj->getLastname())) {
1746 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_for_action_required"), "Lastname", "Insert"));
1747 }
1748 if (count($this->roles) == 0) {
1749 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_for_action_required"), "Role", "Insert"));
1750 } else {
1751 $has_global_role = false;
1752 foreach ($this->roles as $role) {
1753 if ($role['type'] == 'Global') {
1754 $has_global_role = true;
1755 break;
1756 }
1757 }
1758 if (!$has_global_role) {
1759 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_global_role_for_action_required"), "Insert"));
1760 }
1761 }
1762 break;
1763 case "Update":
1764 if (!$user_exists) {
1765 $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_cant_update"));
1766 } elseif ($this->user_id != -1 && !is_null($this->userObj->getLogin())) {
1767 // check if someone owns the new login name!
1768 $someonesId = ilObjUser::_lookupId($this->userObj->getLogin());
1769
1770 if (is_numeric($someonesId) && $someonesId != $this->user_id) {
1771 $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_login_is_not_unique"));
1772 }
1773 }
1774 break;
1775 case "Delete":
1776 if (!$user_exists) {
1777 $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_cant_delete"));
1778 }
1779 break;
1780 }
1781
1782 // init role array for next user
1783 $this->roles = array();
1784 break;
1785
1786 case "Login":
1787 if (array_key_exists($this->cdata, $this->logins)) {
1788 $this->logWarning($this->cdata, $lng->txt("usrimport_login_is_not_unique"));
1789 } else {
1790 $this->logins[$this->cdata] = $this->cdata;
1791 }
1792 $this->userObj->setLogin($this->stripTags($this->cdata));
1793 break;
1794
1795 case "Password":
1796 switch ($this->currPasswordType) {
1797 case "BCRYPT":
1798 $this->userObj->setPasswd($this->cdata, IL_PASSWD_CRYPTED);
1799 $this->userObj->setPasswordEncodingType('bcryptphp');
1800 $this->userObj->setPasswordSalt(null);
1801 break;
1802
1803 case "PLAIN":
1804 $this->userObj->setPasswd($this->cdata, IL_PASSWD_PLAIN);
1805 $this->acc_mail->setUserPassword($this->currPassword);
1806 break;
1807
1808 default:
1809 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "Type", "Password", $this->stripTags($this->currPasswordType)));
1810 break;
1811 }
1812 break;
1813
1814 case "Firstname":
1815 $this->userObj->setFirstname($this->cdata);
1816 break;
1817
1818 case "Lastname":
1819 $this->userObj->setLastname($this->cdata);
1820 break;
1821
1822 case "Title":
1823 $this->userObj->setUTitle($this->cdata);
1824 break;
1825
1826 case "Gender":
1827 if (!in_array(strtolower($this->cdata), ['n', 'm', 'f'])) {
1828 $this->logFailure(
1829 $this->userObj->getLogin(),
1830 sprintf($lng->txt("usrimport_xml_element_content_illegal"), "Gender", $this->stripTags($this->cdata))
1831 );
1832 }
1833 $this->userObj->setGender($this->cdata);
1834 break;
1835
1836 case "Email":
1837 $this->userObj->setEmail($this->cdata);
1838 break;
1839 case "SecondEmail":
1840 $this->userObj->setSecondEmail($this->cdata);
1841 break;
1842 case "Institution":
1843 $this->userObj->setInstitution($this->cdata);
1844 break;
1845
1846 case "Street":
1847 $this->userObj->setStreet($this->cdata);
1848 break;
1849
1850 case "City":
1851 $this->userObj->setCity($this->cdata);
1852 break;
1853
1854 case "PostalCode":
1855 $this->userObj->setZipCode($this->cdata);
1856 break;
1857
1858 case "Country":
1859 $this->userObj->setCountry($this->cdata);
1860 break;
1861
1862 case "SelCountry":
1863 $this->userObj->setSelectedCountry($this->cdata);
1864 break;
1865
1866 case "PhoneOffice":
1867 $this->userObj->setPhoneOffice($this->cdata);
1868 break;
1869
1870 case "PhoneHome":
1871 $this->userObj->setPhoneHome($this->cdata);
1872 break;
1873
1874 case "PhoneMobile":
1875 $this->userObj->setPhoneMobile($this->cdata);
1876 break;
1877
1878 case "Fax":
1879 $this->userObj->setFax($this->cdata);
1880 break;
1881
1882 case "Hobby":
1883 $this->userObj->setHobby($this->cdata);
1884 break;
1885
1886 case "GeneralInterest":
1887 case "OfferingHelp":
1888 case "LookingForHelp":
1889 $this->multi_values[$a_name][] = $this->cdata;
1890 break;
1891
1892 case "Comment":
1893 $this->userObj->setComment($this->cdata);
1894 break;
1895
1896 case "Department":
1897 $this->userObj->setDepartment($this->cdata);
1898 break;
1899
1900 case "Matriculation":
1901 $this->userObj->setMatriculation($this->cdata);
1902 break;
1903
1904 case "ExternalAccount":
1905 $am = ($this->userObj->getAuthMode() == "default" || $this->userObj->getAuthMode() == "")
1906 ? ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode'))
1907 : $this->userObj->getAuthMode();
1908 $loginForExternalAccount = (trim($this->cdata) == "")
1909 ? ""
1910 : ilObjUser::_checkExternalAuthAccount($am, trim($this->cdata));
1911 switch ($this->action) {
1912 case "Insert":
1913 if ($loginForExternalAccount != "") {
1914 $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_no_insert_ext_account_exists") . " (" . $this->stripTags($this->cdata) . ")");
1915 }
1916 break;
1917
1918 case "Update":
1919 if ($loginForExternalAccount != "") {
1920 $externalAccountHasChanged = trim($this->cdata) != ilObjUser::_lookupExternalAccount($this->user_id);
1921 if ($externalAccountHasChanged && trim($loginForExternalAccount) != trim($this->userObj->getLogin())) {
1922 $this->logWarning(
1923 $this->userObj->getLogin(),
1924 $lng->txt("usrimport_no_update_ext_account_exists") . " (" . $this->stripTags($this->cdata) . " for " . $this->stripTags($loginForExternalAccount) . ")"
1925 );
1926 }
1927 }
1928 break;
1929
1930 }
1931 if ($externalAccountHasChanged) {
1932 $this->userObj->setExternalAccount(trim($this->cdata));
1933 }
1934 break;
1935
1936 case "Active":
1937 if ($this->cdata != "true"
1938 && $this->cdata != "false") {
1939 $this->logFailure(
1940 $this->userObj->getLogin(),
1941 sprintf($lng->txt("usrimport_xml_element_content_illegal"), "Active", $this->stripTags($this->cdata))
1942 );
1943 }
1944 $this->currActive = $this->cdata;
1945 break;
1946 case "TimeLimitOwner":
1947 if (!preg_match("/\d+/", $this->cdata)) {
1948 $this->logFailure(
1949 $this->userObj->getLogin(),
1950 sprintf($lng->txt("usrimport_xml_element_content_illegal"), "TimeLimitOwner", $this->stripTags($this->cdata))
1951 );
1952 } elseif (!$ilAccess->checkAccess('cat_administrate_users', '', $this->cdata)) {
1953 $this->logFailure(
1954 $this->userObj->getLogin(),
1955 sprintf($lng->txt("usrimport_xml_element_content_illegal"), "TimeLimitOwner", $this->stripTags($this->cdata))
1956 );
1957 } elseif ($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($this->cdata)) != 'cat' && !(int) $this->cdata == USER_FOLDER_ID) {
1958 $this->logFailure(
1959 $this->userObj->getLogin(),
1960 sprintf($lng->txt("usrimport_xml_element_content_illegal"), "TimeLimitOwner", $this->stripTags($this->cdata))
1961 );
1962 }
1963 $this->userObj->setTimeLimitOwner($this->cdata);
1964 break;
1965 case "TimeLimitUnlimited":
1966 switch (strtolower($this->cdata)) {
1967 case "true":
1968 case "1":
1969 $this->userObj->setTimeLimitUnlimited(1);
1970 break;
1971 case "false":
1972 case "0":
1973 $this->userObj->setTimeLimitUnlimited(0);
1974 break;
1975 default:
1976 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"), "TimeLimitUnlimited", $this->stripTags($this->cdata)));
1977 break;
1978 }
1979 break;
1980 case "TimeLimitFrom":
1981 // Accept datetime or Unix timestamp
1982 if (strtotime($this->cdata) === false && !is_numeric($this->cdata)) {
1983 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"), "TimeLimitFrom", $this->stripTags($this->cdata)));
1984 }
1985 $this->userObj->setTimeLimitFrom($this->cdata);
1986 break;
1987 case "TimeLimitUntil":
1988 // Accept datetime or Unix timestamp
1989 if (strtotime($this->cdata) === false && !is_numeric($this->cdata)) {
1990 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"), "TimeLimitUntil", $this->stripTags($this->cdata)));
1991 }
1992 $this->userObj->setTimeLimitUntil($this->cdata);
1993 break;
1994 case "TimeLimitMessage":
1995 switch (strtolower($this->cdata)) {
1996 case "1":
1997 $this->userObj->setTimeLimitMessage(1);
1998 break;
1999 case "0":
2000 $this->userObj->setTimeLimitMessage(0);
2001 break;
2002 default:
2003 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"), "TimeLimitMessage", $this->stripTags($this->cdata)));
2004 break;
2005 }
2006 break;
2007 case "ApproveDate":
2008 // Accept datetime or Unix timestamp
2009 if (strtotime($this->cdata) === false && !is_numeric($this->cdata) && !$this->cdata == "0000-00-00 00:00:00") {
2010 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"), "ApproveDate", $this->stripTags($this->cdata)));
2011 }
2012 break;
2013 case "AgreeDate":
2014 // Accept datetime or Unix timestamp
2015 if (strtotime($this->cdata) === false && !is_numeric($this->cdata) && !$this->cdata == "0000-00-00 00:00:00") {
2016 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"), "AgreeDate", $this->stripTags($this->cdata)));
2017 }
2018 break;
2019 case "Pref":
2020 if ($this->currentPrefKey != null) {
2021 $this->verifyPref($this->currentPrefKey, $this->cdata);
2022 }
2023 $this->currentPrefKey == null;
2024 }
2025 }
2026
2030 public function handlerCharacterData($a_xml_parser, $a_data)
2031 {
2032 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
2033 // TODO: Mit Alex klären, ob das noch benötigt wird $a_data = preg_replace("/\n/","",$a_data);
2034 // TODO: Mit Alex klären, ob das noch benötigt wird $a_data = preg_replace("/\t+/","",$a_data);
2035 if ($a_data != "\n") {
2036 $a_data = preg_replace("/\t+/", " ", $a_data);
2037 }
2038
2039 if (strlen($a_data) > 0) {
2040 $this->cdata .= $a_data;
2041 }
2042 }
2043
2047 public function getCollectedRoles()
2048 {
2049 return $this->roles;
2050 }
2054 public function getUserCount()
2055 {
2056 return $this->userCount;
2057 }
2058
2065 public function logWarning($aLogin, $aMessage)
2066 {
2067 if (!array_key_exists($aLogin, $this->protocol)) {
2068 $this->protocol[$aLogin] = array();
2069 }
2070 if ($aMessage) {
2071 $this->protocol[$aLogin][] = $aMessage;
2072 }
2073 if ($this->error_level == IL_IMPORT_SUCCESS) {
2074 $this->error_level = IL_IMPORT_WARNING;
2075 }
2076 }
2083 public function logFailure($aLogin, $aMessage)
2084 {
2085 if (!array_key_exists($aLogin, $this->protocol)) {
2086 $this->protocol[$aLogin] = array();
2087 }
2088 if ($aMessage) {
2089 $this->protocol[$aLogin][] = $aMessage;
2090 }
2091 $this->error_level = IL_IMPORT_FAILURE;
2092 }
2093
2101 public function logSuccess($aLogin, $userid, $action)
2102 {
2103 $this->user_mapping[$userid] = array("login" => $aLogin, "action" => $action, "message" => "successful");
2104 }
2105
2106
2115 public function getProtocol()
2116 {
2117 return $this->protocol;
2118 }
2122 public function getProtocolAsHTML($a_log_title) : string
2123 {
2124 global $DIC;
2125
2126 $lng = $DIC['lng'];
2127
2128 $block = new ilTemplate("tpl.usr_import_log_block.html", true, true, "Services/User");
2129 $block->setVariable("TXT_LOG_TITLE", $a_log_title);
2130 $block->setVariable("TXT_MESSAGE_ID", $lng->txt("login"));
2131 $block->setVariable("TXT_MESSAGE_TEXT", $lng->txt("message"));
2132 foreach ($this->getProtocol() as $login => $messages) {
2133 $block->setCurrentBlock("log_row");
2134 $reason = "";
2135 foreach ($messages as $message) {
2136 if ($reason == "") {
2137 $reason = $message;
2138 } else {
2139 $reason = $reason . "<br>" . $message;
2140 }
2141 }
2142 $block->setVariable("MESSAGE_ID", $login);
2143 $block->setVariable("MESSAGE_TEXT", $reason);
2144 $block->parseCurrentBlock();
2145 }
2146 return $block->get();
2147 }
2148
2152 public function isSuccess()
2153 {
2154 return $this->error_level == IL_IMPORT_SUCCESS;
2155 }
2156
2161 public function getErrorLevel()
2162 {
2163 return $this->error_level;
2164 }
2165
2171 public function getUserMapping()
2172 {
2173 return $this->user_mapping;
2174 }
2175
2179 public function sendAccountMail()
2180 {
2181 if ($_POST["send_mail"] != "" ||
2182 ($this->isSendMail() && $this->userObj->getEmail() != "")) {
2183 $this->acc_mail->setUser($this->userObj);
2184 $this->acc_mail->send();
2185 }
2186 }
2187
2193 public function setSendMail($value)
2194 {
2195 $this->send_mail = $value ? true: false;
2196 }
2197
2203 public function isSendMail()
2204 {
2205 return $this->send_mail;
2206 }
2207
2213 public function setUserMappingMode($value)
2214 {
2215 if ($value == IL_USER_MAPPING_ID || $value == IL_USER_MAPPING_LOGIN) {
2216 $this->mapping_mode = $value;
2217 } else {
2218 die("wrong argument using methode setUserMappingMethod in " . __FILE__);
2219 }
2220 }
2221
2227 public function getUserMappingMode()
2228 {
2229 return $this->mapping_mode;
2230 }
2231
2238 private function readRequiredFields()
2239 {
2240 global $DIC;
2241
2242 $ilSetting = $DIC['ilSetting'];
2243
2244 if (is_array($this->required_fields)) {
2245 return $this->required_fields;
2246 }
2247 foreach ($ilSetting->getAll() as $field => $value) {
2248 if (substr($field, 0, 8) == 'require_' and $value == 1) {
2249 $value = substr($field, 8);
2250 $this->required_fields[$value] = $value;
2251 }
2252 }
2253 return $this->required_fields ? $this->required_fields : array();
2254 }
2255
2264 private function checkProfileIncomplete($user_obj)
2265 {
2266 include_once "Services/User/classes/class.ilUserProfile.php";
2267 return ilUserProfile::isProfileIncomplete($user_obj);
2268 }
2269
2276 protected function isFieldRequired($fieldname)
2277 {
2278 $requiredFields = $this->readRequiredFields();
2279 $fieldname = strtolower(trim($fieldname));
2280 return array_key_exists($fieldname, $requiredFields);
2281 }
2282
2283 private function verifyPref($key, $value)
2284 {
2285 switch ($key) {
2286 case 'mail_linebreak':
2287 case 'hits_per_page':
2288 if (!is_numeric($value) || $value < 0) {
2289 $this->logFailure("---", "Wrong value '{$this->stripTags($value)}': Positiv numeric value expected for preference {$this->stripTags($key)}.");
2290 }
2291 break;
2292 case 'language':
2293 case 'skin':
2294 case 'style':
2295 case 'ilPageEditor_HTMLMode':
2296 case 'ilPageEditor_JavaScript':
2297 case 'ilPageEditor_MediaMode':
2298 case 'tst_javascript':
2299 case 'tst_lastquestiontype':
2300 case 'tst_multiline_answers':
2301 case 'tst_use_previous_answers':
2302 case 'graphicalAnswerSetting':
2303 case 'priv_feed_pass':
2304 $this->logFailure("---", "Preference {$this->stripTags($key)} is not supported.");
2305 break;
2306 case 'public_city':
2307 case 'public_country':
2308 case 'public_department':
2309 case 'public_email':
2310 case 'public_second_email':
2311 case 'public_fax':
2312 case 'public_hobby':
2313 case 'public_institution':
2314 case 'public_matriculation':
2315 case 'public_phone':
2316 case 'public_phone_home':
2317 case 'public_phone_mobile':
2318 case 'public_phone_office':
2319 case 'public_street':
2320 case 'public_upload':
2321 case 'public_zip':
2322 case 'public_interests_general':
2323 case 'public_interests_help_offered':
2324 case 'public_interests_help_looking':
2325 case 'send_info_mails':
2326 case 'hide_own_online_status':
2327 if (!in_array($value, array('y', 'n'))) {
2328 $this->logFailure("---", "Wrong value '{$this->stripTags($value)}': Value 'y' or 'n' expected for preference {$this->stripTags($key)}.");
2329 }
2330 break;
2331 case 'bs_allow_to_contact_me':
2332 if (!in_array($value, array('y', 'n'))) {
2333 $this->logFailure("---", "Wrong value '{$this->stripTags($value)}': Value 'y' or 'n' expected for preference {$this->stripTags($key)}.");
2334 }
2335 break;
2336 case 'chat_osc_accept_msg':
2337 if (!in_array($value, array('y', 'n'))) {
2338 $this->logFailure("---", "Wrong value '{$this->stripTags($value)}': Value 'y' or 'n' expected for preference {$this->stripTags($key)}.");
2339 }
2340 break;
2341 case 'public_profile':
2342 if (!in_array($value, array('y', 'n', 'g'))) {
2343 $this->logFailure("---", "Wrong value '{$this->stripTags($value)}': Value 'y', 'g' or 'n' expected for preference {$this->stripTags($key)}.");
2344 }
2345 break;
2346 case 'show_users_online':
2347 if (!in_array($value, array('y', 'n', 'associated'))) {
2348 $this->logFailure("---", "Wrong value '{$this->stripTags($value)}': Value 'y' or 'n' or 'associated' expected for preference {$this->stripTags($key)}.");
2349 }
2350 break;
2351 case 'mail_incoming_type':
2352 if (!in_array((int) $value, array("0","1","2"))) {
2353 $this->logFailure("---", "Wrong value '{$this->stripTags($value)}': Value \"0\" (LOCAL),\"1\" (EMAIL) or \"2\" (BOTH) expected for preference {$this->stripTags($key)}.");
2354 }
2355 break;
2356 case 'weekstart':
2357 if (!in_array($value, array("0","1"))) {
2358 $this->logFailure("---", "Wrong value '{$this->stripTags($value)}': Value \"0\" (Sunday) or \"1\" (Monday) expected for preference {$this->stripTags($key)}.");
2359 }
2360 break;
2361
2362 case 'mail_signature':
2363 break;
2364 case 'user_tz':
2365 include_once('Services/Calendar/classes/class.ilTimeZone.php');
2366 try {
2367 $tz = ilTimeZone::_getInstance($value);
2368 return true;
2369 } catch (ilTimeZoneException $tze) {
2370 $this->logFailure("---", "Wrong value '{$this->stripTags($value)}': Invalid timezone $value detected for preference {$this->stripTags($key)}.");
2371 }
2372 break;
2373 default:
2375 $this->logFailure("---", "Preference {$this->stripTags($key)} is not supported.");
2376 }
2377 break;
2378 }
2379 }
2380
2381 private function updateMailPreferences($usr_id)
2382 {
2383 if (array_key_exists("mail_incoming_type", $this->prefs) ||
2384 array_key_exists("mail_signature", $this->prefs) ||
2385 array_key_exists("mail_linebreak", $this->prefs)
2386 ) {
2387 include_once("Services/Mail/classes/class.ilMailOptions.php");
2388 $mailOptions = new ilMailOptions($usr_id);
2389
2390 $mailOptions->setLinebreak(array_key_exists("mail_linebreak", $this->prefs) ? $this->prefs["mail_linebreak"] : $mailOptions->getLinebreak());
2391 $mailOptions->setSignature(array_key_exists("mail_signature", $this->prefs) ? $this->prefs["mail_signature"] : $mailOptions->getSignature());
2392 $mailOptions->setIncomingType(array_key_exists("mail_incoming_type", $this->prefs) ? $this->prefs["mail_incoming_type"] : $mailOptions->getIncomingType());
2393 $mailOptions->updateOptions();
2394 }
2395 }
2396
2397 private function getCDataWithoutTags() : string
2398 {
2399 return $this->stripTags($this->cdata);
2400 }
2401
2402 private function stripTags(string $string) : string
2403 {
2404 return strip_tags($string);
2405 }
2406}
$filename
Definition: buildRTE.php:89
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_PASSWD_PLAIN
const IL_PASSWD_CRYPTED
const IL_FAIL_ON_CONFLICT
const IL_USER_MAPPING_ID
const IL_IMPORT_FAILURE
const IL_UPDATE_ON_CONFLICT
const IL_EXTRACT_ROLES
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($a_obj_id)
Get singleton instance.
@classDescription Date and time handling
static _getActiveServerList()
Get active server list.
Class ilMailOptions this class handles user mails.
static _getUsedHTMLTags($a_module="")
Returns an array of all allowed HTML tags for text editing.
Class ilObjCourse.
Class ilObjRole.
static _lookupLogin($a_user_id)
lookup login
static _checkExternalAuthAccount($a_auth, $a_account, $tryFallback=true)
check whether external account and authentication method matches with a user
static getUserIdByLogin($a_login)
static _uploadPersonalPicture($tmp_file, $obj_id)
Create a personal picture image file from a temporary image file.
static _lookupExternalAccount($a_user_id)
lookup external account for login and authmethod
static _lookupId($a_user_str)
Lookup id by login.
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
Recommended content manager (business logic)
static getActiveIdpList()
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
static _lookupActivatedStyle($a_skin, $a_style)
lookup if a style is activated
special template class to simplify handling of ITX/PEAR
Class for TimeZone exceptions.
static _getInstance($a_tz='')
get instance by timezone
Class ilUserDefinedData.
static _getInstance()
Get instance.
Class for user related exception handling in ILIAS.
$action
The Action attribute determines what to do for the current User element.
getUserCount()
get count of User elements
isFieldRequired($fieldname)
determine if a field $fieldname is to a required field (global setting)
getCollectedRoles()
get collected roles
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
$userCount
The count of user elements in the XML file.
$personalPicture
Cached personal picture of the actual user This is used because the ilObjUser object has no field for...
logWarning($aLogin, $aMessage)
Writes a warning log message to the protocol.
$parentRolesCache
Cached parent roles.
extractRolesEndTag($a_xml_parser, $a_name)
handler for end of element when in extract roles mode.
logFailure($aLogin, $aMessage)
Writes a failure log message to the protocol.
$disableSkin
Indicates if the skins are enabled.
setUserMappingMode($value)
write access to user mapping mode
logSuccess($aLogin, $userid, $action)
Writes a success log message to the protocol.
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class @access private
startParsing()
start the parser
assignToRoleWithParents($a_user_obj, $a_role_id)
Assigns a user to a role and to all parent roles.
$conflict_rule
Conflict handling rule.
saveTempImage($image_data, $filename)
Saves binary image data to a temporary image file and returns the name of the image file on success.
importEndTag($a_xml_parser, $a_name)
handler for end of element when in import user mode.
verifyBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
$protocol
The variable holds the protocol of the import.
isSuccess()
Returns true, if the import was successful.
$currActive
The active state of the current user.
importBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element in user import mode
$updateLookAndSkin
boolean to determine if look and skin should be updated
$localRoleCache
Cached local roles.
verifyEndTag($a_xml_parser, $a_name)
handler for end of element when in verify mode.
getParentRoleIds($a_role_id)
Get array of parent role ids from cache.
setRoleAssignment($a_assign)
set import to local role assignemt
getProtocolAsHTML($a_log_title)
Returns the protocol as a HTML table.
__construct($a_xml_file='', $a_mode=IL_USER_IMPORT, $a_conflict_rule=IL_FAIL_ON_CONFLICT)
Constructor.
$error_level
This variable is used to report the error level of the validation process or the importing process.
$currPassword
The password of the current user.
$currPasswordType
The password type of the current user.
assignToRole($a_user_obj, $a_role_id)
Assigns a user to a role.
getUserMappingMode()
read access to user mapping mode
sendAccountMail()
send account mail
isSendMail()
read access to property send mail
getErrorLevel()
Returns the error level.
checkProfileIncomplete($user_obj)
Check if profile is incomplete Will set the usr_data field profile_incomplete if any required field i...
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
buildTag($type, $name, $attr="")
generate a tag with given name and attributes
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
getRoleObject($a_role_id)
Returns the parent object of the role folder object which contains the specified role.
getProtocol()
Returns the protocol.
readRequiredFields()
read required fields
getUserMapping()
returns a map user_id <=> login
$logins
This variable is used to collect each login that we encounter in the import data.
getCourseMembersObjectForRole($a_role_id)
Returns the parent object of the role folder object which contains the specified role.
extractRolesBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element in extract roles mode
detachFromRole($a_user_obj, $a_role_id)
Detachs a user from a role.
$hideSkin
Indicates if the skins are hidden.
setSendMail($value)
write access to property send mail
$userStyles
User assigned styles.
setFolderId($a_folder_id)
assign users to this folder (normally the usr_folder) But if called from local admin => the ref_id of...
static isProfileIncomplete($a_user, $a_include_udf=true, $a_personal_data_only=true)
Check if all required personal data fields are set.
User settings configuration (what preferences can be visible/changed/...)
static isPrefExportable($key)
returns wether a key from db is exportable or not
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static __extractId($ilias_id, $inst_id)
extract ref id from role title, e.g.
const USER_FOLDER_ID
Definition: constants.php:31
const SYSTEM_USER_ID
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: constants.php:24
const IL_INST_ID
Definition: constants.php:38
const ANONYMOUS_USER_ID
Definition: constants.php:25
$login
Definition: cron.php:13
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
if($format !==null) $name
Definition: metadata.php:230
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:17
$type
$messages
Definition: xapiexit.php:5
$message
Definition: xapiexit.php:14