ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
50{
51 public $approve_date_set = false;
52 public $time_limit_set = false;
53 public $time_limit_owner_set = false;
54
58 public $updateLookAndSkin = false;
59 public $folder_id;
60 public $roles;
65 public $action;
74 public $protocol;
84 public $logins;
85
94
95
102
165
174
183
189 public $user_mapping = [];
190
198
207
213
222
226 public $skin;
227
231 public $style;
232
237
241 public $hideSkin;
242
247
253 public $user_id;
254
259 private $userObj;
260
267
277 public function __construct($a_xml_file = '', $a_mode = IL_USER_IMPORT, $a_conflict_rule = IL_FAIL_ON_CONFLICT)
278 {
279 global $DIC;
280
281 $global_settings = $DIC->settings();
282
283 $this->roles = array();
284 $this->mode = $a_mode;
285 $this->conflict_rule = $a_conflict_rule;
286 $this->error_level = IL_IMPORT_SUCCESS;
287 $this->protocol = array();
288 $this->logins = array();
289 $this->userCount = 0;
290 $this->localRoleCache = array();
291 $this->parentRolesCache = array();
292 $this->send_mail = false;
293 $this->mapping_mode = IL_USER_MAPPING_LOGIN;
294
295 // get all active style instead of only assigned ones -> cannot transfer all to another otherwise
296 $this->userStyles = array();
297 include_once './Services/Style/System/classes/class.ilStyleDefinition.php';
298 $skins = ilStyleDefinition::getAllSkins();
299
300 if (is_array($skins)) {
301 foreach ($skins as $skin) {
302 foreach ($skin->getStyles() as $style) {
303 include_once("./Services/Style/System/classes/class.ilSystemStyleSettings.php");
305 continue;
306 }
307 $this->userStyles [] = $skin->getId() . ":" . $style->getId();
308 }
309 }
310 }
311
312 $settings = $global_settings->getAll();
313 if ($settings["usr_settings_hide_skin_style"] == 1) {
314 $this->hideSkin = true;
315 } else {
316 $this->hideSkin = false;
317 }
318 if ($settings["usr_settings_disable_skin_style"] == 1) {
319 $this->disableSkin = true;
320 } else {
321 $this->disableSkin = false;
322 }
323
324 include_once("Services/Mail/classes/class.ilAccountMail.php");
325 $this->acc_mail = new ilAccountMail();
326 $this->acc_mail->setAttachConfiguredFiles(true);
327 $this->acc_mail->useLangVariablesAsFallback(true);
328
329 parent::__construct($a_xml_file);
330 }
331
337 public function setFolderId($a_folder_id)
338 {
339 $this->folder_id = $a_folder_id;
340 }
341
342 public function getFolderId()
343 {
344 return $this->folder_id;
345 }
346
352 public function setHandlers($a_xml_parser)
353 {
354 xml_set_object($a_xml_parser, $this);
355 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
356 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
357 }
358
362 public function startParsing()
363 {
364 parent::startParsing();
365 }
366
372 public function setRoleAssignment($a_assign)
373 {
374 $this->role_assign = $a_assign;
375 }
376
384 public function buildTag($type, $name, $attr = "")
385 {
386 $tag = "<";
387
388 if ($type == "end") {
389 $tag .= "/";
390 }
391
392 $tag .= $name;
393
394 if (is_array($attr)) {
395 foreach ($attr as $k => $v) {
396 $tag .= " " . $k . "=\"$v\"";
397 }
398 }
399
400 $tag .= ">";
401
402 return $tag;
403 }
404
408 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
409 {
410 switch ($this->mode) {
411 case IL_EXTRACT_ROLES:
412 $this->extractRolesBeginTag($a_xml_parser, $a_name, $a_attribs);
413 break;
414 case IL_USER_IMPORT:
415 $this->importBeginTag($a_xml_parser, $a_name, $a_attribs);
416 break;
417 case IL_VERIFY:
418 $this->verifyBeginTag($a_xml_parser, $a_name, $a_attribs);
419 break;
420 }
421
422 $this->cdata = "";
423 }
424
428 public function extractRolesBeginTag($a_xml_parser, $a_name, $a_attribs)
429 {
430 switch ($a_name) {
431 case "Role":
432 // detect numeric, ilias id (then extract role id) or alphanumeric
433 $this->current_role_id = $a_attribs["Id"];
434 if ($internal_id = ilUtil::__extractId($this->current_role_id, IL_INST_ID)) {
435 $this->current_role_id = $internal_id;
436 }
437 $this->current_role_type = $a_attribs["Type"];
438
439 break;
440 }
441 }
445 public function importBeginTag($a_xml_parser, $a_name, $a_attribs)
446 {
447 global $DIC;
448
449 $ilias = $DIC['ilias'];
450 $lng = $DIC['lng'];
451
452 switch ($a_name) {
453 case "Role":
454 $this->current_role_id = $a_attribs["Id"];
455 if ($internal_id = ilUtil::__extractId($this->current_role_id, IL_INST_ID)) {
456 $this->current_role_id = $internal_id;
457 }
458 $this->current_role_type = $a_attribs["Type"];
459 $this->current_role_action = (is_null($a_attribs["Action"])) ? "Assign" : $a_attribs["Action"];
460 break;
461
462 case "PersonalPicture":
463 $this->personalPicture = array(
464 "encoding" => $a_attribs["encoding"],
465 "imagetype" => $a_attribs["imagetype"],
466 "content" => ""
467 );
468 break;
469
470 case "Look":
471 $this->skin = $a_attribs["Skin"];
472 $this->style = $a_attribs["Style"];
473 break;
474
475 case "User":
476 $this->acc_mail->reset();
477 $this->prefs = array();
478 $this->currentPrefKey = null;
479 $this->auth_mode_set = false;
480 $this->approve_date_set = false;
481 $this->time_limit_set = false;
482 $this->time_limit_owner_set = false;
483 $this->updateLookAndSkin = false;
484 $this->skin = "";
485 $this->style = "";
486 $this->personalPicture = null;
487 $this->userCount++;
488 $this->userObj = new ilObjUser();
489
490 // user defined fields
491 $this->udf_data = array();
492
493 // if we have an object id, store it
494 $this->user_id = -1;
495 if (!is_null($a_attribs["Id"]) && $this->getUserMappingMode() == IL_USER_MAPPING_ID) {
496 if (is_numeric($a_attribs["Id"])) {
497 $this->user_id = $a_attribs["Id"];
498 } elseif ($id = ilUtil::__extractId($a_attribs["Id"], IL_INST_ID)) {
499 $this->user_id = $id;
500 }
501 }
502
503 $this->userObj->setPref(
504 "skin",
505 $ilias->ini->readVariable("layout", "skin")
506 );
507 $this->userObj->setPref(
508 "style",
509 $ilias->ini->readVariable("layout", "style")
510 );
511
512 $this->userObj->setLanguage($a_attribs["Language"]);
513 $this->userObj->setImportId($a_attribs["Id"]);
514 $this->action = (is_null($a_attribs["Action"])) ? "Insert" : $a_attribs["Action"];
515 $this->currPassword = null;
516 $this->currPasswordType = null;
517 $this->currActive = null;
518 $this->multi_values = array();
519 break;
520
521 case 'Password':
522 $this->currPasswordType = $a_attribs['Type'];
523 break;
524 case "AuthMode":
525 if (array_key_exists("type", $a_attribs)) {
526 switch ($a_attribs["type"]) {
527 case "saml":
528 case "ldap":
529 if (strcmp('saml', $a_attribs['type']) === 0) {
531 if (count($list) === 1) {
532 $this->auth_mode_set = true;
533 $idp = current($list);
534 $this->userObj->setAuthMode('saml_' . $idp->getIdpId());
535 }
536 break;
537 }
538 if (strcmp('ldap', $a_attribs['type']) === 0) {
539 // no server id provided => use default server
540 include_once './Services/LDAP/classes/class.ilLDAPServer.php';
542 if (count($list) == 1) {
543 $this->auth_mode_set = true;
544 $ldap_id = current($list);
545 $this->userObj->setAuthMode('ldap_' . $ldap_id);
546 }
547 }
548 break;
549
550 case "default":
551 case "local":
552 case "radius":
553 case "shibboleth":
554 case "script":
555 case "cas":
556 case "soap":
557 case "openid":
558 // begin-patch auth_plugin
559 default:
560 $this->auth_mode_set = true;
561 $this->userObj->setAuthMode($a_attribs["type"]);
562 break;
563 /*
564 $this->logFailure($this->userObj->getLogin(),
565 sprintf($lng->txt("usrimport_xml_element_inapplicable"),"AuthMode",$a_attribs["type"]));
566 break;
567 *
568 */
569 }
570 } else {
571 $this->logFailure(
572 $this->userObj->getLogin(),
573 sprintf($lng->txt("usrimport_xml_element_inapplicable"), "AuthMode", $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", $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->current_role_action, $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", $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", $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", $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 default:
704 $this->logFailure($this->userObj->getImportId(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"AuthMode","type",$a_attribs["type"]));
705 break;
706 *
707 */
708 }
709 } else {
710 $this->logFailure($this->userObj->getImportId(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "AuthMode", "type", ""));
711 }
712 break;
713 case 'Pref':
714 $this->currentPrefKey = $a_attribs["key"];
715 break;
716
717 }
718 }
719
723 public function handlerEndTag($a_xml_parser, $a_name)
724 {
725 switch ($this->mode) {
726 case IL_EXTRACT_ROLES:
727 $this->extractRolesEndTag($a_xml_parser, $a_name);
728 break;
729 case IL_USER_IMPORT:
730 $this->importEndTag($a_xml_parser, $a_name);
731 break;
732 case IL_VERIFY:
733 $this->verifyEndTag($a_xml_parser, $a_name);
734 break;
735 }
736 }
737
741 public function extractRolesEndTag($a_xml_parser, $a_name)
742 {
743 switch ($a_name) {
744 case "Role":
745 $this->roles[$this->current_role_id]["name"] = $this->cdata;
746 $this->roles[$this->current_role_id]["type"] =
747 $this->current_role_type;
748 break;
749 }
750 }
751
755 public function getRoleObject($a_role_id)
756 {
757 if (array_key_exists($a_role_id, $this->localRoleCache)) {
758 return $this->localRoleCache[$a_role_id];
759 } else {
760 $role_obj = new ilObjRole($a_role_id, false);
761 $role_obj->read();
762 $this->localRoleCache[$a_role_id] = $role_obj;
763 return $role_obj;
764 }
765 }
769 public function getCourseMembersObjectForRole($a_role_id)
770 {
771 global $DIC;
772
773 $rbacreview = $DIC['rbacreview'];
774 $rbacadmin = $DIC['rbacadmin'];
775 $tree = $DIC['tree'];
776
777 if (array_key_exists($a_role_id . '_courseMembersObject', $this->localRoleCache)) {
778 return $this->localRoleCache[$a_role_id . '_courseMembersObject'];
779 } else {
780 require_once("Modules/Course/classes/class.ilObjCourse.php");
781 require_once("Modules/Course/classes/class.ilCourseParticipants.php");
782 $course_refs = $rbacreview->getFoldersAssignedToRole($a_role_id, true);
783 $course_ref = $course_refs[0];
784 $course_obj = new ilObjCourse($course_ref, true);
785 $crsmembers_obj = ilCourseParticipants::_getInstanceByObjId($course_obj->getId());
786 $this->localRoleCache[$a_role_id . '_courseMembersObject'] = $crsmembers_obj;
787 return $crsmembers_obj;
788 }
789 }
790
794 public function assignToRole($a_user_obj, $a_role_id)
795 {
796 require_once "./Services/AccessControl/classes/class.ilObjRole.php";
797 include_once('./Services/Object/classes/class.ilObject.php');
798 #require_once "Modules/Course/classes/class.ilObjCourse.php";
799 #require_once "Modules/Course/classes/class.ilCourseParticipants.php";
800
801 global $DIC;
802
803 $rbacreview = $DIC['rbacreview'];
804 $rbacadmin = $DIC['rbacadmin'];
805 $tree = $DIC['tree'];
806
807 // Do nothing, if the user is already assigned to the role.
808 // Specifically, we do not want to put a course object or
809 // group object on the personal desktop again, if a user
810 // has removed it from the personal desktop.
811 if ($rbacreview->isAssigned($a_user_obj->getId(), $a_role_id)) {
812 return;
813 }
814
815 // If it is a course role, use the ilCourseMember object to assign
816 // the user to the role
817
818 $rbacadmin->assignUser($a_role_id, $a_user_obj->getId(), true);
819 $obj_id = $rbacreview->getObjectOfRole($a_role_id);
820 switch ($type = ilObject::_lookupType($obj_id)) {
821 case 'grp':
822 case 'crs':
823 $ref_ids = ilObject::_getAllReferences($obj_id);
824 $ref_id = current((array) $ref_ids);
825 if ($ref_id) {
826 ilObjUser::_addDesktopItem($a_user_obj->getId(), $ref_id, $type);
827 }
828 break;
829 default:
830 break;
831 }
832 }
837 public function getParentRoleIds($a_role_id)
838 {
839 global $DIC;
840
841 $rbacreview = $DIC['rbacreview'];
842
843 if (!array_key_exists($a_role_id, $this->parentRolesCache)) {
844 $parent_role_ids = array();
845
846 $role_obj = $this->getRoleObject($a_role_id);
847 $short_role_title = substr($role_obj->getTitle(), 0, 12);
848 $folders = $rbacreview->getFoldersAssignedToRole($a_role_id, true);
849 if (count($folders) > 0) {
850 $all_parent_role_ids = $rbacreview->getParentRoleIds($folders[0]);
851 foreach ($all_parent_role_ids as $parent_role_id => $parent_role_data) {
852 if ($parent_role_id != $a_role_id) {
853 switch (substr($parent_role_data['title'], 0, 12)) {
854 case 'il_crs_admin':
855 case 'il_grp_admin':
856 if ($short_role_title == 'il_crs_admin' || $short_role_title == 'il_grp_admin') {
857 $parent_role_ids[] = $parent_role_id;
858 }
859 break;
860 case 'il_crs_tutor':
861 case 'il_grp_tutor':
862 if ($short_role_title == 'il_crs_tutor' || $short_role_title == 'il_grp_tutor') {
863 $parent_role_ids[] = $parent_role_id;
864 }
865 break;
866 case 'il_crs_membe':
867 case 'il_grp_membe':
868 if ($short_role_title == 'il_crs_membe' || $short_role_title == 'il_grp_membe') {
869 $parent_role_ids[] = $parent_role_id;
870 }
871 break;
872 default:
873 break;
874 }
875 }
876 }
877 }
878 $this->parentRolesCache[$a_role_id] = $parent_role_ids;
879 }
880 return $this->parentRolesCache[$a_role_id];
881 }
885 public function assignToRoleWithParents($a_user_obj, $a_role_id)
886 {
887 $this->assignToRole($a_user_obj, $a_role_id);
888
889 $parent_role_ids = $this->getParentRoleIds($a_role_id);
890 foreach ($parent_role_ids as $parent_role_id) {
891 $this->assignToRole($a_user_obj, $parent_role_id);
892 }
893 }
897 public function detachFromRole($a_user_obj, $a_role_id)
898 {
899 global $DIC;
900
901 $rbacreview = $DIC['rbacreview'];
902 $rbacadmin = $DIC['rbacadmin'];
903 $tree = $DIC['tree'];
904
905 $rbacadmin->deassignUser($a_role_id, $a_user_obj->getId());
906
907 if (substr(ilObject::_lookupTitle($a_role_id), 0, 6) == 'il_crs' or
908 substr(ilObject::_lookupTitle($a_role_id), 0, 6) == 'il_grp') {
909 $obj = $rbacreview->getObjectOfRole($a_role_id);
910 $ref = ilObject::_getAllReferences($obj);
911 $ref_id = end($ref);
912 ilObjUser::_dropDesktopItem($a_user_obj->getId(), $ref_id, ilObject::_lookupType($obj));
913 }
914 }
915
919 public function importEndTag($a_xml_parser, $a_name)
920 {
921 global $DIC;
922
923 $ilias = $DIC['ilias'];
924 $rbacadmin = $DIC['rbacadmin'];
925 $rbacreview = $DIC['rbacreview'];
926 $ilUser = $DIC['ilUser'];
927 $lng = $DIC['lng'];
928 $ilSetting = $DIC['ilSetting'];
929
930 switch ($a_name) {
931 case "Role":
932 $this->roles[$this->current_role_id]["name"] = $this->cdata;
933 $this->roles[$this->current_role_id]["type"] = $this->current_role_type;
934 $this->roles[$this->current_role_id]["action"] = $this->current_role_action;
935 break;
936
937 case "PersonalPicture":
938 switch ($this->personalPicture["encoding"]) {
939 case "Base64":
940 $this->personalPicture["content"] = base64_decode($this->cdata);
941 break;
942 case "UUEncode":
943 $this->personalPicture["content"] = convert_uudecode($this->cdata);
944 break;
945 }
946 break;
947
948 case "User":
949 $this->userObj->setFullname();
950 // Fetch the user_id from the database, if we didn't have it in xml file
951 // fetch as well, if we are trying to insert -> recognize duplicates!
952 if ($this->user_id == -1 || $this->action == "Insert") {
953 $user_id = ilObjUser::getUserIdByLogin($this->userObj->getLogin());
954 } else {
956 }
957
958 //echo $user_id.":".$this->userObj->getLogin();
959
960 // Handle conflicts
961 switch ($this->conflict_rule) {
963 // do not change action
964 break;
966 switch ($this->action) {
967 case "Insert":
968 if ($user_id) {
969 $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_replaced"), "Insert", "Update"));
970 $this->action = "Update";
971 }
972 break;
973 case "Update":
974 if (!$user_id) {
975 $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_replaced"), "Update", "Insert"));
976 $this->action = "Insert";
977 }
978 break;
979 case "Delete":
980 if (!$user_id) {
981 $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_ignored"), "Delete"));
982 $this->action = "Ignore";
983 }
984 break;
985 }
986 break;
988 switch ($this->action) {
989 case "Insert":
990 if ($user_id) {
991 $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_ignored"), "Insert"));
992 $this->action = "Ignore";
993 }
994 break;
995 case "Update":
996 if (!$user_id) {
997 $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_ignored"), "Update"));
998 $this->action = "Ignore";
999 }
1000 break;
1001 case "Delete":
1002 if (!$user_id) {
1003 $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_ignored"), "Delete"));
1004 $this->action = "Ignore";
1005 }
1006 break;
1007 }
1008 break;
1009 }
1010
1011 // check external account conflict (if external account is already used)
1012 // note: we cannot apply conflict rules in the same manner as to logins here
1013 // so we ignore records with already existing external accounts.
1014 //echo $this->userObj->getAuthMode().'h';
1015 $am = ($this->userObj->getAuthMode() == "default" || $this->userObj->getAuthMode() == "")
1016 ? ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode'))
1017 : $this->userObj->getAuthMode();
1018 $loginForExternalAccount = ($this->userObj->getExternalAccount() == "")
1019 ? ""
1020 : ilObjUser::_checkExternalAuthAccount($am, $this->userObj->getExternalAccount());
1021 switch ($this->action) {
1022 case "Insert":
1023 if ($loginForExternalAccount != "") {
1024 $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_no_insert_ext_account_exists") . " (" . $this->userObj->getExternalAccount() . ")");
1025 $this->action = "Ignore";
1026 }
1027 break;
1028
1029 case "Update":
1030 // this variable describes the ILIAS login which belongs to the given external account!!!
1031 // it is NOT nescessarily the ILIAS login of the current user record !!
1032 // so if we found an ILIAS login according to the authentication method
1033 // check if the ILIAS login belongs to the current user record, otherwise somebody else is using it!
1034 if ($loginForExternalAccount != "") {
1035 // check if we changed the value!
1036 $externalAccountHasChanged = $this->userObj->getExternalAccount() != ilObjUser::_lookupExternalAccount($this->user_id);
1037 // if it has changed and the external login
1038 if ($externalAccountHasChanged && trim($loginForExternalAccount) != trim($this->userObj->getLogin())) {
1039 $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_no_update_ext_account_exists") . " (" . $this->userObj->getExternalAccount() . ")");
1040 $this->action = "Ignore";
1041 }
1042 }
1043 break;
1044 }
1045
1046 if (sizeof($this->multi_values)) {
1047 if (isset($this->multi_values["GeneralInterest"])) {
1048 $this->userObj->setGeneralInterests($this->multi_values["GeneralInterest"]);
1049 }
1050 if (isset($this->multi_values["OfferingHelp"])) {
1051 $this->userObj->setOfferingHelp($this->multi_values["OfferingHelp"]);
1052 }
1053 if (isset($this->multi_values["LookingForHelp"])) {
1054 $this->userObj->setLookingForHelp($this->multi_values["LookingForHelp"]);
1055 }
1056 }
1057
1058 // Perform the action
1059 switch ($this->action) {
1060 case "Insert":
1061 if ($user_id) {
1062 $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_cant_insert"));
1063 } else {
1064 if (!strlen($this->currPassword) == 0) {
1065 switch (strtoupper($this->currPasswordType)) {
1066 case "BCRYPT":
1067 $this->userObj->setPasswd($this->currPassword, IL_PASSWD_CRYPTED);
1068 $this->userObj->setPasswordEncodingType('bcryptphp');
1069 $this->userObj->setPasswordSalt(null);
1070 break;
1071
1072 case "PLAIN":
1073 $this->userObj->setPasswd($this->currPassword, IL_PASSWD_PLAIN);
1074 $this->acc_mail->setUserPassword($this->currPassword);
1075 break;
1076
1077 default:
1078 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "Type", "Password", $this->currPasswordType));
1079 break;
1080
1081 }
1082 } else {
1083 // this does the trick for empty passwords
1084 // since a MD5 string has always 32 characters,
1085 // no hashed password combination will ever equal to
1086 // an empty string
1087 $this->userObj->setPasswd("", IL_PASSWD_CRYPTED);
1088 }
1089
1090 $this->userObj->setTitle($this->userObj->getFullname());
1091 $this->userObj->setDescription($this->userObj->getEmail());
1092
1093 if (!$this->time_limit_owner_set) {
1094 $this->userObj->setTimeLimitOwner($this->getFolderId());
1095 }
1096
1097 // default time limit settings
1098 if (!$this->time_limit_set) {
1099 $this->userObj->setTimeLimitUnlimited(1);
1100 $this->userObj->setTimeLimitMessage(0);
1101
1102 if (!$this->approve_date_set) {
1103 $this->userObj->setApproveDate(date("Y-m-d H:i:s"));
1104 }
1105 }
1106
1107
1108 $this->userObj->setActive($this->currActive == 'true' || is_null($this->currActive));
1109
1110 // Finally before saving new user.
1111 // Check if profile is incomplete
1112
1113 // #8759
1114 if (count($this->udf_data)) {
1115 $this->userObj->setUserDefinedData($this->udf_data);
1116 }
1117
1118 $this->userObj->setProfileIncomplete($this->checkProfileIncomplete($this->userObj));
1119 $this->userObj->create();
1120
1121 //insert user data in table user_data
1122 $this->userObj->saveAsNew(false);
1123
1124 // Set default prefs
1125 $this->userObj->setPref('hits_per_page', $ilSetting->get('hits_per_page', 30));
1126 //$this->userObj->setPref('show_users_online',$ilSetting->get('show_users_online','y'));
1127
1128 if (count($this->prefs)) {
1129 foreach ($this->prefs as $key => $value) {
1130 if ($key != "mail_incoming_type" &&
1131 $key != "mail_signature" &&
1132 $key != "mail_linebreak"
1133 ) {
1134 $this->userObj->setPref($key, $value);
1135 }
1136 }
1137 }
1138
1139 if (!is_array($this->prefs) || array_search('chat_osc_accept_msg', $this->prefs) === false) {
1140 $this->userObj->setPref('chat_osc_accept_msg', $ilSetting->get('chat_osc_accept_msg', 'n'));
1141 }
1142 if (!is_array($this->prefs) || array_search('bs_allow_to_contact_me', $this->prefs) === false) {
1143 $this->userObj->setPref('bs_allow_to_contact_me', $ilSetting->get('bs_allow_to_contact_me', 'n'));
1144 }
1145
1146 $this->userObj->writePrefs();
1147
1148 // update mail preferences, to be extended
1149 $this->updateMailPreferences($this->userObj->getId());
1150
1151 if (is_array($this->personalPicture)) {
1152 if (strlen($this->personalPicture["content"])) {
1153 $extension = "jpg";
1154 if (preg_match("/.*(png|jpg|gif|jpeg)$/", $this->personalPicture["imagetype"], $matches)) {
1155 $extension = $matches[1];
1156 }
1157 $tmp_name = $this->saveTempImage($this->personalPicture["content"], ".$extension");
1158 if (strlen($tmp_name)) {
1159 ilObjUser::_uploadPersonalPicture($tmp_name, $this->userObj->getId());
1160 unlink($tmp_name);
1161 }
1162 }
1163 }
1164
1165 //set role entries
1166 foreach ($this->roles as $role_id => $role) {
1167 if ($this->role_assign[$role_id]) {
1168 $this->assignToRole($this->userObj, $this->role_assign[$role_id]);
1169 }
1170 }
1171
1172 if (count($this->udf_data)) {
1173 include_once './Services/User/classes/class.ilUserDefinedData.php';
1174 $udd = new ilUserDefinedData($this->userObj->getId());
1175 foreach ($this->udf_data as $field => $value) {
1176 $udd->set("f_" . $field, $value);
1177 }
1178 $udd->update();
1179 }
1180
1181 $this->sendAccountMail();
1182 $this->logSuccess($this->userObj->getLogin(), $this->userObj->getId(), "Insert");
1183 // reset account mail object
1184 $this->acc_mail->reset();
1185 }
1186 break;
1187
1188 case "Update":
1189 if (!$user_id) {
1190 $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_cant_update"));
1191 } else {
1192 $updateUser = new ilObjUser($user_id);
1193 $updateUser->read();
1194 $updateUser->readPrefs();
1195 if ($this->currPassword != null) {
1196 switch (strtoupper($this->currPasswordType)) {
1197 case "BCRYPT":
1198 $updateUser->setPasswd($this->currPassword, IL_PASSWD_CRYPTED);
1199 $updateUser->setPasswordEncodingType('bcryptphp');
1200 $updateUser->setPasswordSalt(null);
1201 break;
1202
1203 case "PLAIN":
1204 $updateUser->setPasswd($this->currPassword, IL_PASSWD_PLAIN);
1205 $this->acc_mail->setUserPassword($this->currPassword);
1206 break;
1207
1208 default:
1209 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "Type", "Password", $this->currPasswordType));
1210 break;
1211 }
1212 }
1213 if (!is_null($this->userObj->getFirstname())) {
1214 $updateUser->setFirstname($this->userObj->getFirstname());
1215 }
1216 if (!is_null($this->userObj->getLastname())) {
1217 $updateUser->setLastname($this->userObj->getLastname());
1218 }
1219 if (!is_null($this->userObj->getUTitle())) {
1220 $updateUser->setUTitle($this->userObj->getUTitle());
1221 }
1222 if (!is_null($this->userObj->getGender())) {
1223 $updateUser->setGender($this->userObj->getGender());
1224 }
1225 if (!is_null($this->userObj->getEmail())) {
1226 $updateUser->setEmail($this->userObj->getEmail());
1227 }
1228 if (!is_null($this->userObj->getSecondEmail())) {
1229 $updateUser->setSecondEmail($this->userObj->getSecondEmail());
1230 }
1231 if (!is_null($this->userObj->getBirthday())) {
1232 $updateUser->setBirthday($this->userObj->getBirthday());
1233 }
1234 if (!is_null($this->userObj->getInstitution())) {
1235 $updateUser->setInstitution($this->userObj->getInstitution());
1236 }
1237 if (!is_null($this->userObj->getStreet())) {
1238 $updateUser->setStreet($this->userObj->getStreet());
1239 }
1240 if (!is_null($this->userObj->getCity())) {
1241 $updateUser->setCity($this->userObj->getCity());
1242 }
1243 if (!is_null($this->userObj->getZipCode())) {
1244 $updateUser->setZipCode($this->userObj->getZipCode());
1245 }
1246 if (!is_null($this->userObj->getCountry())) {
1247 $updateUser->setCountry($this->userObj->getCountry());
1248 }
1249 if (!is_null($this->userObj->getSelectedCountry())) {
1250 $updateUser->setSelectedCountry($this->userObj->getSelectedCountry());
1251 }
1252 if (!is_null($this->userObj->getPhoneOffice())) {
1253 $updateUser->setPhoneOffice($this->userObj->getPhoneOffice());
1254 }
1255 if (!is_null($this->userObj->getPhoneHome())) {
1256 $updateUser->setPhoneHome($this->userObj->getPhoneHome());
1257 }
1258 if (!is_null($this->userObj->getPhoneMobile())) {
1259 $updateUser->setPhoneMobile($this->userObj->getPhoneMobile());
1260 }
1261 if (!is_null($this->userObj->getFax())) {
1262 $updateUser->setFax($this->userObj->getFax());
1263 }
1264 if (!is_null($this->userObj->getHobby())) {
1265 $updateUser->setHobby($this->userObj->getHobby());
1266 }
1267 if (!is_null($this->userObj->getGeneralInterests())) {
1268 $updateUser->setGeneralInterests($this->userObj->getGeneralInterests());
1269 }
1270 if (!is_null($this->userObj->getOfferingHelp())) {
1271 $updateUser->setOfferingHelp($this->userObj->getOfferingHelp());
1272 }
1273 if (!is_null($this->userObj->getLookingForHelp())) {
1274 $updateUser->setLookingForHelp($this->userObj->getLookingForHelp());
1275 }
1276 if (!is_null($this->userObj->getComment())) {
1277 $updateUser->setComment($this->userObj->getComment());
1278 }
1279 if (!is_null($this->userObj->getDepartment())) {
1280 $updateUser->setDepartment($this->userObj->getDepartment());
1281 }
1282 if (!is_null($this->userObj->getMatriculation())) {
1283 $updateUser->setMatriculation($this->userObj->getMatriculation());
1284 }
1285 if (!is_null($this->currActive)) {
1286 $updateUser->setActive($this->currActive == "true", is_object($ilUser) ? $ilUser->getId() : 0);
1287 }
1288 if (!is_null($this->userObj->getClientIP())) {
1289 $updateUser->setClientIP($this->userObj->getClientIP());
1290 }
1291 if (!is_null($this->userObj->getTimeLimitUnlimited())) {
1292 $updateUser->setTimeLimitUnlimited($this->userObj->getTimeLimitUnlimited());
1293 }
1294 if (!is_null($this->userObj->getTimeLimitFrom())) {
1295 $updateUser->setTimeLimitFrom($this->userObj->getTimeLimitFrom());
1296 }
1297 if (!is_null($this->userObj->getTimeLimitUntil())) {
1298 $updateUser->setTimeLimitUntil($this->userObj->getTimeLimitUntil());
1299 }
1300 if (!is_null($this->userObj->getTimeLimitMessage())) {
1301 $updateUser->setTimeLimitMessage($this->userObj->getTimeLimitMessage());
1302 }
1303 if (!is_null($this->userObj->getApproveDate())) {
1304 $updateUser->setApproveDate($this->userObj->getApproveDate());
1305 }
1306 if (!is_null($this->userObj->getAgreeDate())) {
1307 $updateUser->setAgreeDate($this->userObj->getAgreeDate());
1308 }
1309 if (!is_null($this->userObj->getLanguage())) {
1310 $updateUser->setLanguage($this->userObj->getLanguage());
1311 }
1312 if (!is_null($this->userObj->getExternalAccount())) {
1313 $updateUser->setExternalAccount($this->userObj->getExternalAccount());
1314 }
1315
1316 // Fixed: if auth_mode is not set, it was always overwritten with auth_default
1317 #if (! is_null($this->userObj->getAuthMode())) $updateUser->setAuthMode($this->userObj->getAuthMode());
1318 if ($this->auth_mode_set) {
1319 $updateUser->setAuthMode($this->userObj->getAuthMode());
1320 }
1321
1322 // Special handlin since it defaults to 7 (USER_FOLDER_ID)
1323 if ($this->time_limit_owner_set) {
1324 $updateUser->setTimeLimitOwner($this->userObj->getTimeLimitOwner());
1325 }
1326
1327
1328 if (count($this->prefs)) {
1329 foreach ($this->prefs as $key => $value) {
1330 if ($key != "mail_incoming_type" &&
1331 $key != "mail_signature" &&
1332 $key != "mail_linebreak"
1333 ) {
1334 $updateUser->setPref($key, $value);
1335 }
1336 }
1337 }
1338
1339 // save user preferences (skin and style)
1340 if ($this->updateLookAndSkin) {
1341 $updateUser->setPref("skin", $this->userObj->getPref("skin"));
1342 $updateUser->setPref("style", $this->userObj->getPref("style"));
1343 }
1344
1345
1346 $updateUser->writePrefs();
1347
1348 // update mail preferences, to be extended
1349 $this->updateMailPreferences($updateUser->getId());
1350
1351 // #8759
1352 if (count($this->udf_data)) {
1353 $updateUser->setUserDefinedData($this->udf_data);
1354 }
1355
1356 $updateUser->setProfileIncomplete($this->checkProfileIncomplete($updateUser));
1357 $updateUser->setFullname();
1358 $updateUser->setTitle($updateUser->getFullname());
1359 $updateUser->setDescription($updateUser->getEmail());
1360 $updateUser->update();
1361
1362 if (count($this->udf_data)) {
1363 include_once './Services/User/classes/class.ilUserDefinedData.php';
1364 $udd = new ilUserDefinedData($updateUser->getId());
1365 foreach ($this->udf_data as $field => $value) {
1366 $udd->set("f_" . $field, $value);
1367 }
1368 $udd->update();
1369 }
1370
1371 // update login
1372 if (!is_null($this->userObj->getLogin()) && $this->user_id != -1) {
1373 try {
1374 $updateUser->updateLogin($this->userObj->getLogin());
1375 } catch (ilUserException $e) {
1376 }
1377 }
1378
1379
1380 // if language has changed
1381
1382 if (is_array($this->personalPicture)) {
1383 if (strlen($this->personalPicture["content"])) {
1384 $extension = "jpg";
1385 if (preg_match("/.*(png|jpg|gif|jpeg)$/", $this->personalPicture["imagetype"], $matches)) {
1386 $extension = $matches[1];
1387 }
1388 $tmp_name = $this->saveTempImage($this->personalPicture["content"], ".$extension");
1389 if (strlen($tmp_name)) {
1390 ilObjUser::_uploadPersonalPicture($tmp_name, $updateUser->getId());
1391 unlink($tmp_name);
1392 }
1393 }
1394 }
1395
1396
1397 //update role entries
1398 //-------------------
1399 foreach ($this->roles as $role_id => $role) {
1400 if ($this->role_assign[$role_id]) {
1401 switch ($role["action"]) {
1402 case "Assign":
1403 $this->assignToRole($updateUser, $this->role_assign[$role_id]);
1404 break;
1405 case "AssignWithParents":
1406 $this->assignToRoleWithParents($updateUser, $this->role_assign[$role_id]);
1407 break;
1408 case "Detach":
1409 $this->detachFromRole($updateUser, $this->role_assign[$role_id]);
1410 break;
1411 }
1412 }
1413 }
1414 $this->logSuccess($updateUser->getLogin(), $user_id, "Update");
1415 }
1416 break;
1417 case "Delete":
1418 if (!$user_id) {
1419 $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_cant_delete"));
1420 } else {
1421 $deleteUser = new ilObjUser($user_id);
1422 $deleteUser->delete();
1423
1424 $this->logSuccess($this->userObj->getLogin(), $user_id, "Delete");
1425 }
1426 break;
1427 }
1428
1429 // init role array for next user
1430 $this->roles = array();
1431 break;
1432
1433 case "Login":
1434 $this->userObj->setLogin($this->cdata);
1435 break;
1436
1437 case "Password":
1438 $this->currPassword = $this->cdata;
1439 break;
1440
1441 case "Firstname":
1442 $this->userObj->setFirstname($this->cdata);
1443 break;
1444
1445 case "Lastname":
1446 $this->userObj->setLastname($this->cdata);
1447 break;
1448
1449 case "Title":
1450 $this->userObj->setUTitle($this->cdata);
1451 break;
1452
1453 case "Gender":
1454 $this->userObj->setGender($this->cdata);
1455 break;
1456
1457 case "Email":
1458 $this->userObj->setEmail($this->cdata);
1459 break;
1460 case "SecondEmail":
1461 $this->userObj->setSecondEmail($this->cdata);
1462 break;
1463 case "Birthday":
1464 $timestamp = strtotime($this->cdata);
1465 if ($timestamp !== false) {
1466 $this->userObj->setBirthday($this->cdata);
1467 }
1468 break;
1469 case "Institution":
1470 $this->userObj->setInstitution($this->cdata);
1471 break;
1472
1473 case "Street":
1474 $this->userObj->setStreet($this->cdata);
1475 break;
1476
1477 case "City":
1478 $this->userObj->setCity($this->cdata);
1479 break;
1480
1481 case "PostalCode":
1482 $this->userObj->setZipCode($this->cdata);
1483 break;
1484
1485 case "Country":
1486 $this->userObj->setCountry($this->cdata);
1487 break;
1488
1489 case "SelCountry":
1490 $this->userObj->setSelectedCountry($this->cdata);
1491 break;
1492
1493 case "PhoneOffice":
1494 $this->userObj->setPhoneOffice($this->cdata);
1495 break;
1496
1497 case "PhoneHome":
1498 $this->userObj->setPhoneHome($this->cdata);
1499 break;
1500
1501 case "PhoneMobile":
1502 $this->userObj->setPhoneMobile($this->cdata);
1503 break;
1504
1505 case "Fax":
1506 $this->userObj->setFax($this->cdata);
1507 break;
1508
1509 case "Hobby":
1510 $this->userObj->setHobby($this->cdata);
1511 break;
1512
1513 case "GeneralInterest":
1514 case "OfferingHelp":
1515 case "LookingForHelp":
1516 $this->multi_values[$a_name][] = $this->cdata;
1517 break;
1518
1519 case "Comment":
1520 $this->userObj->setComment($this->cdata);
1521 break;
1522
1523 case "Department":
1524 $this->userObj->setDepartment($this->cdata);
1525 break;
1526
1527 case "Matriculation":
1528 $this->userObj->setMatriculation($this->cdata);
1529 break;
1530
1531 case "Active":
1532 $this->currActive = $this->cdata;
1533 break;
1534
1535 case "ClientIP":
1536 $this->userObj->setClientIP($this->cdata);
1537 break;
1538
1539 case "TimeLimitOwner":
1540 $this->time_limit_owner_set = true;
1541 $this->userObj->setTimeLimitOwner($this->cdata);
1542 break;
1543
1544 case "TimeLimitUnlimited":
1545 $this->time_limit_set = true;
1546 $this->userObj->setTimeLimitUnlimited($this->cdata);
1547 break;
1548
1549 case "TimeLimitFrom":
1550 if (is_numeric($this->cdata)) {
1551 // Treat cdata as a unix timestamp
1552 $this->userObj->setTimeLimitFrom($this->cdata);
1553 } else {
1554 // Try to convert cdata into unix timestamp, or ignore it
1555 $timestamp = strtotime($this->cdata);
1556 if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00") {
1557 $this->userObj->setTimeLimitFrom($timestamp);
1558 } elseif ($this->cdata == "0000-00-00 00:00:00") {
1559 $this->userObj->setTimeLimitFrom(null);
1560 }
1561 }
1562 break;
1563
1564 case "TimeLimitUntil":
1565 if (is_numeric($this->cdata)) {
1566 // Treat cdata as a unix timestamp
1567 $this->userObj->setTimeLimitUntil($this->cdata);
1568 } else {
1569 // Try to convert cdata into unix timestamp, or ignore it
1570 $timestamp = strtotime($this->cdata);
1571 if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00") {
1572 $this->userObj->setTimeLimitUntil($timestamp);
1573 } elseif ($this->cdata == "0000-00-00 00:00:00") {
1574 $this->userObj->setTimeLimitUntil(null);
1575 }
1576 }
1577 break;
1578
1579 case "TimeLimitMessage":
1580 $this->userObj->setTimeLimitMessage($this->cdata);
1581 break;
1582
1583 case "ApproveDate":
1584 $this->approve_date_set = true;
1585 if (is_numeric($this->cdata)) {
1586 // Treat cdata as a unix timestamp
1587 $tmp_date = new ilDateTime($this->cdata, IL_CAL_UNIX);
1588 $this->userObj->setApproveDate($tmp_date->get(IL_CAL_DATETIME));
1589 } else {
1590 // Try to convert cdata into unix timestamp, or ignore it
1591 $timestamp = strtotime($this->cdata);
1592 if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00") {
1593 $tmp_date = new ilDateTime($timestamp, IL_CAL_UNIX);
1594 $this->userObj->setApproveDate($tmp_date->get(IL_CAL_DATETIME));
1595 } elseif ($this->cdata == "0000-00-00 00:00:00") {
1596 $this->userObj->setApproveDate(null);
1597 }
1598 }
1599 break;
1600
1601 case "AgreeDate":
1602 if (is_numeric($this->cdata)) {
1603 // Treat cdata as a unix timestamp
1604 $tmp_date = new ilDateTime($this->cdata, IL_CAL_UNIX);
1605 $this->userObj->setAgreeDate($tmp_date->get(IL_CAL_DATETIME));
1606 } else {
1607 // Try to convert cdata into unix timestamp, or ignore it
1608 $timestamp = strtotime($this->cdata);
1609 if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00") {
1610 $tmp_date = new ilDateTime($timestamp, IL_CAL_UNIX);
1611 $this->userObj->setAgreeDate($tmp_date->get(IL_CAL_DATETIME));
1612 } elseif ($this->cdata == "0000-00-00 00:00:00") {
1613 $this->userObj->setAgreeDate(null);
1614 }
1615 }
1616 break;
1617
1618 case "ExternalAccount":
1619 $this->userObj->setExternalAccount($this->cdata);
1620 break;
1621
1622 case "Look":
1623 $this->updateLookAndSkin = false;
1624 if (!$this->hideSkin) {
1625 // TODO: what to do with disabled skins? is it possible to change the skin via import?
1626 if ((strlen($this->skin) > 0) && (strlen($this->style) > 0)) {
1627 if (is_array($this->userStyles)) {
1628 if (in_array($this->skin . ":" . $this->style, $this->userStyles)) {
1629 $this->userObj->setPref("skin", $this->skin);
1630 $this->userObj->setPref("style", $this->style);
1631 $this->updateLookAndSkin = true;
1632 }
1633 }
1634 }
1635 }
1636 break;
1637
1638 case 'UserDefinedField':
1639 include_once './Services/User/classes/class.ilUserDefinedFields.php';
1641 if ($field_id = $udf->fetchFieldIdFromImportId($this->tmp_udf_id)) {
1642 $this->udf_data[$field_id] = $this->cdata;
1643 } elseif ($field_id = $udf->fetchFieldIdFromName($this->tmp_udf_name)) {
1644 $this->udf_data[$field_id] = $this->cdata;
1645 }
1646 break;
1647 case 'AccountInfo':
1648 if ($this->current_messenger_type == "external") {
1649 $this->userObj->setExternalAccount($this->cdata);
1650 }
1651 break;
1652 case 'Pref':
1653 if ($this->currentPrefKey != null && strlen(trim($this->cdata)) > 0
1654 && ilUserXMLWriter::isPrefExportable($this->currentPrefKey)) {
1655 $this->prefs[$this->currentPrefKey] = trim($this->cdata);
1656 }
1657 $this->currentPrefKey = null;
1658 break;
1659 }
1660 }
1661
1666 public function saveTempImage($image_data, $filename)
1667 {
1668 $tempname = ilUtil::ilTempnam() . $filename;
1669 $fh = fopen($tempname, "wb");
1670 if ($fh == false) {
1671 return "";
1672 }
1673 $imagefile = fwrite($fh, $image_data);
1674 fclose($fh);
1675 return $tempname;
1676 }
1677
1681 public function verifyEndTag($a_xml_parser, $a_name)
1682 {
1683 global $DIC;
1684
1685 $lng = $DIC['lng'];
1686 $ilAccess = $DIC['ilAccess'];
1687 $ilSetting = $DIC['ilSetting'];
1688 $ilObjDataCache = $DIC['ilObjDataCache'];
1689
1690 switch ($a_name) {
1691 case "Role":
1692 $this->roles[$this->current_role_id]["name"] = $this->cdata;
1693 $this->roles[$this->current_role_id]["type"] = $this->current_role_type;
1694 $this->roles[$this->current_role_id]["action"] = $this->current_role_action;
1695 break;
1696
1697 case "User":
1698 $this->userObj->setFullname();
1699 if ($this->user_id != -1 && ($this->action == "Update" || $this->action == "Delete")) {
1700 $user_exists = !is_null(ilObjUser::_lookupLogin($this->user_id));
1701 } else {
1702 $user_exists = ilObjUser::getUserIdByLogin($this->userObj->getLogin()) != 0;
1703 }
1704
1705 if (is_null($this->userObj->getLogin())) {
1706 $this->logFailure("---", sprintf($lng->txt("usrimport_xml_element_for_action_required"), "Login", "Insert"));
1707 }
1708
1709 switch ($this->action) {
1710 case "Insert":
1711 if ($user_exists and $this->conflict_rule == IL_FAIL_ON_CONFLICT) {
1712 $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_cant_insert"));
1713 }
1714 if (is_null($this->userObj->getGender()) && $this->isFieldRequired("gender")) {
1715 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_for_action_required"), "Gender", "Insert"));
1716 }
1717 if (is_null($this->userObj->getFirstname())) {
1718 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_for_action_required"), "Firstname", "Insert"));
1719 }
1720 if (is_null($this->userObj->getLastname())) {
1721 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_for_action_required"), "Lastname", "Insert"));
1722 }
1723 if (count($this->roles) == 0) {
1724 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_for_action_required"), "Role", "Insert"));
1725 } else {
1726 $has_global_role = false;
1727 foreach ($this->roles as $role) {
1728 if ($role['type'] == 'Global') {
1729 $has_global_role = true;
1730 break;
1731 }
1732 }
1733 if (!$has_global_role) {
1734 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_global_role_for_action_required"), "Insert"));
1735 }
1736 }
1737 break;
1738 case "Update":
1739 if (!$user_exists) {
1740 $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_cant_update"));
1741 } elseif ($this->user_id != -1 && !is_null($this->userObj->getLogin())) {
1742 // check if someone owns the new login name!
1743 $someonesId = ilObjUser::_lookupId($this->userObj->getLogin());
1744
1745 if (is_numeric($someonesId) && $someonesId != $this->user_id) {
1746 $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_login_is_not_unique"));
1747 }
1748 }
1749 break;
1750 case "Delete":
1751 if (!$user_exists) {
1752 $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_cant_delete"));
1753 }
1754 break;
1755 }
1756
1757 // init role array for next user
1758 $this->roles = array();
1759 break;
1760
1761 case "Login":
1762 if (array_key_exists($this->cdata, $this->logins)) {
1763 $this->logWarning($this->cdata, $lng->txt("usrimport_login_is_not_unique"));
1764 } else {
1765 $this->logins[$this->cdata] = $this->cdata;
1766 }
1767 $this->userObj->setLogin($this->cdata);
1768 break;
1769
1770 case "Password":
1771 switch ($this->currPasswordType) {
1772 case "BCRYPT":
1773 $this->userObj->setPasswd($this->cdata, IL_PASSWD_CRYPTED);
1774 $this->userObj->setPasswordEncodingType('bcryptphp');
1775 $this->userObj->setPasswordSalt(null);
1776 break;
1777
1778 case "PLAIN":
1779 $this->userObj->setPasswd($this->cdata, IL_PASSWD_PLAIN);
1780 $this->acc_mail->setUserPassword($this->currPassword);
1781 break;
1782
1783 default:
1784 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"), "Type", "Password", $this->currPasswordType));
1785 break;
1786 }
1787 break;
1788
1789 case "Firstname":
1790 $this->userObj->setFirstname($this->cdata);
1791 break;
1792
1793 case "Lastname":
1794 $this->userObj->setLastname($this->cdata);
1795 break;
1796
1797 case "Title":
1798 $this->userObj->setUTitle($this->cdata);
1799 break;
1800
1801 case "Gender":
1802 if (!in_array(strtolower($this->cdata), ['n', 'm', 'f'])) {
1803 $this->logFailure(
1804 $this->userObj->getLogin(),
1805 sprintf($lng->txt("usrimport_xml_element_content_illegal"), "Gender", $this->cdata)
1806 );
1807 }
1808 $this->userObj->setGender($this->cdata);
1809 break;
1810
1811 case "Email":
1812 $this->userObj->setEmail($this->cdata);
1813 break;
1814 case "SecondEmail":
1815 $this->userObj->setSecondEmail($this->cdata);
1816 break;
1817 case "Institution":
1818 $this->userObj->setInstitution($this->cdata);
1819 break;
1820
1821 case "Street":
1822 $this->userObj->setStreet($this->cdata);
1823 break;
1824
1825 case "City":
1826 $this->userObj->setCity($this->cdata);
1827 break;
1828
1829 case "PostalCode":
1830 $this->userObj->setZipCode($this->cdata);
1831 break;
1832
1833 case "Country":
1834 $this->userObj->setCountry($this->cdata);
1835 break;
1836
1837 case "SelCountry":
1838 $this->userObj->setSelectedCountry($this->cdata);
1839 break;
1840
1841 case "PhoneOffice":
1842 $this->userObj->setPhoneOffice($this->cdata);
1843 break;
1844
1845 case "PhoneHome":
1846 $this->userObj->setPhoneHome($this->cdata);
1847 break;
1848
1849 case "PhoneMobile":
1850 $this->userObj->setPhoneMobile($this->cdata);
1851 break;
1852
1853 case "Fax":
1854 $this->userObj->setFax($this->cdata);
1855 break;
1856
1857 case "Hobby":
1858 $this->userObj->setHobby($this->cdata);
1859 break;
1860
1861 case "GeneralInterest":
1862 case "OfferingHelp":
1863 case "LookingForHelp":
1864 $this->multi_values[$a_name][] = $this->cdata;
1865 break;
1866
1867 case "Comment":
1868 $this->userObj->setComment($this->cdata);
1869 break;
1870
1871 case "Department":
1872 $this->userObj->setDepartment($this->cdata);
1873 break;
1874
1875 case "Matriculation":
1876 $this->userObj->setMatriculation($this->cdata);
1877 break;
1878
1879 case "ExternalAccount":
1880//echo "-".$this->userObj->getAuthMode()."-".$this->userObj->getLogin()."-";
1881 $am = ($this->userObj->getAuthMode() == "default" || $this->userObj->getAuthMode() == "")
1882 ? ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode'))
1883 : $this->userObj->getAuthMode();
1884 $loginForExternalAccount = (trim($this->cdata) == "")
1885 ? ""
1886 : ilObjUser::_checkExternalAuthAccount($am, trim($this->cdata));
1887 switch ($this->action) {
1888 case "Insert":
1889 if ($loginForExternalAccount != "") {
1890 $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_no_insert_ext_account_exists") . " (" . $this->cdata . ")");
1891 }
1892 break;
1893
1894 case "Update":
1895 if ($loginForExternalAccount != "") {
1896 $externalAccountHasChanged = trim($this->cdata) != ilObjUser::_lookupExternalAccount($this->user_id);
1897 if ($externalAccountHasChanged && trim($loginForExternalAccount) != trim($this->userObj->getLogin())) {
1898 $this->logWarning(
1899 $this->userObj->getLogin(),
1900 $lng->txt("usrimport_no_update_ext_account_exists") . " (" . $this->cdata . " for " . $loginForExternalAccount . ")"
1901 );
1902 }
1903 }
1904 break;
1905
1906 }
1907 if ($externalAccountHasChanged) {
1908 $this->userObj->setExternalAccount(trim($this->cdata));
1909 }
1910 break;
1911
1912 case "Active":
1913 if ($this->cdata != "true"
1914 && $this->cdata != "false") {
1915 $this->logFailure(
1916 $this->userObj->getLogin(),
1917 sprintf($lng->txt("usrimport_xml_element_content_illegal"), "Active", $this->cdata)
1918 );
1919 }
1920 $this->currActive = $this->cdata;
1921 break;
1922 case "TimeLimitOwner":
1923 if (!preg_match("/\d+/", $this->cdata)) {
1924 $this->logFailure(
1925 $this->userObj->getLogin(),
1926 sprintf($lng->txt("usrimport_xml_element_content_illegal"), "TimeLimitOwner", $this->cdata)
1927 );
1928 } elseif (!$ilAccess->checkAccess('cat_administrate_users', '', $this->cdata)) {
1929 $this->logFailure(
1930 $this->userObj->getLogin(),
1931 sprintf($lng->txt("usrimport_xml_element_content_illegal"), "TimeLimitOwner", $this->cdata)
1932 );
1933 } elseif ($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($this->cdata)) != 'cat' && !(int) $this->cdata == USER_FOLDER_ID) {
1934 $this->logFailure(
1935 $this->userObj->getLogin(),
1936 sprintf($lng->txt("usrimport_xml_element_content_illegal"), "TimeLimitOwner", $this->cdata)
1937 );
1938 }
1939 $this->userObj->setTimeLimitOwner($this->cdata);
1940 break;
1941 case "TimeLimitUnlimited":
1942 switch (strtolower($this->cdata)) {
1943 case "true":
1944 case "1":
1945 $this->userObj->setTimeLimitUnlimited(1);
1946 break;
1947 case "false":
1948 case "0":
1949 $this->userObj->setTimeLimitUnlimited(0);
1950 break;
1951 default:
1952 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"), "TimeLimitUnlimited", $this->cdata));
1953 break;
1954 }
1955 break;
1956 case "TimeLimitFrom":
1957 // Accept datetime or Unix timestamp
1958 if (strtotime($this->cdata) === false && !is_numeric($this->cdata)) {
1959 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"), "TimeLimitFrom", $this->cdata));
1960 }
1961 $this->userObj->setTimeLimitFrom($this->cdata);
1962 break;
1963 case "TimeLimitUntil":
1964 // Accept datetime or Unix timestamp
1965 if (strtotime($this->cdata) === false && !is_numeric($this->cdata)) {
1966 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"), "TimeLimitUntil", $this->cdata));
1967 }
1968 $this->userObj->setTimeLimitUntil($this->cdata);
1969 break;
1970 case "TimeLimitMessage":
1971 switch (strtolower($this->cdata)) {
1972 case "1":
1973 $this->userObj->setTimeLimitMessage(1);
1974 break;
1975 case "0":
1976 $this->userObj->setTimeLimitMessage(0);
1977 break;
1978 default:
1979 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"), "TimeLimitMessage", $this->cdata));
1980 break;
1981 }
1982 break;
1983 case "ApproveDate":
1984 // Accept datetime or Unix timestamp
1985 if (strtotime($this->cdata) === false && !is_numeric($this->cdata) && !$this->cdata == "0000-00-00 00:00:00") {
1986 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"), "ApproveDate", $this->cdata));
1987 }
1988 break;
1989 case "AgreeDate":
1990 // Accept datetime or Unix timestamp
1991 if (strtotime($this->cdata) === false && !is_numeric($this->cdata) && !$this->cdata == "0000-00-00 00:00:00") {
1992 $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"), "AgreeDate", $this->cdata));
1993 }
1994 break;
1995 case "Pref":
1996 if ($this->currentPrefKey != null) {
1997 $this->verifyPref($this->currentPrefKey, $this->cdata);
1998 }
1999 $this->currentPrefKey == null;
2000 }
2001 }
2002
2006 public function handlerCharacterData($a_xml_parser, $a_data)
2007 {
2008 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
2009 // TODO: Mit Alex klären, ob das noch benötigt wird $a_data = preg_replace("/\n/","",$a_data);
2010 // TODO: Mit Alex klären, ob das noch benötigt wird $a_data = preg_replace("/\t+/","",$a_data);
2011 if ($a_data != "\n") {
2012 $a_data = preg_replace("/\t+/", " ", $a_data);
2013 }
2014
2015 if (strlen($a_data) > 0) {
2016 $this->cdata .= $a_data;
2017 }
2018 }
2019
2023 public function getCollectedRoles()
2024 {
2025 return $this->roles;
2026 }
2030 public function getUserCount()
2031 {
2032 return $this->userCount;
2033 }
2034
2041 public function logWarning($aLogin, $aMessage)
2042 {
2043 if (!array_key_exists($aLogin, $this->protocol)) {
2044 $this->protocol[$aLogin] = array();
2045 }
2046 if ($aMessage) {
2047 $this->protocol[$aLogin][] = $aMessage;
2048 }
2049 if ($this->error_level == IL_IMPORT_SUCCESS) {
2050 $this->error_level = IL_IMPORT_WARNING;
2051 }
2052 }
2059 public function logFailure($aLogin, $aMessage)
2060 {
2061 if (!array_key_exists($aLogin, $this->protocol)) {
2062 $this->protocol[$aLogin] = array();
2063 }
2064 if ($aMessage) {
2065 $this->protocol[$aLogin][] = $aMessage;
2066 }
2067 $this->error_level = IL_IMPORT_FAILURE;
2068 }
2069
2077 public function logSuccess($aLogin, $userid, $action)
2078 {
2079 $this->user_mapping[$userid] = array("login" => $aLogin, "action" => $action, "message" => "successful");
2080 }
2081
2082
2091 public function getProtocol()
2092 {
2093 return $this->protocol;
2094 }
2098 public function getProtocolAsHTML($a_log_title)
2099 {
2100 global $DIC;
2101
2102 $lng = $DIC['lng'];
2103
2104 $block = new ilTemplate("tpl.usr_import_log_block.html", true, true, "Services/User");
2105 $block->setVariable("TXT_LOG_TITLE", $a_log_title);
2106 $block->setVariable("TXT_MESSAGE_ID", $lng->txt("login"));
2107 $block->setVariable("TXT_MESSAGE_TEXT", $lng->txt("message"));
2108 foreach ($this->getProtocol() as $login => $messages) {
2109 $block->setCurrentBlock("log_row");
2110 $reason = "";
2111 foreach ($messages as $message) {
2112 if ($reason == "") {
2113 $reason = $message;
2114 } else {
2115 $reason = $reason . "<br>" . $message;
2116 }
2117 }
2118 $block->setVariable("MESSAGE_ID", $login);
2119 $block->setVariable("MESSAGE_TEXT", $reason);
2120 $block->parseCurrentBlock();
2121 }
2122 return $block->get();
2123 }
2124
2128 public function isSuccess()
2129 {
2130 return $this->error_level == IL_IMPORT_SUCCESS;
2131 }
2132
2137 public function getErrorLevel()
2138 {
2139 return $this->error_level;
2140 }
2141
2147 public function getUserMapping()
2148 {
2149 return $this->user_mapping;
2150 }
2151
2155 public function sendAccountMail()
2156 {
2157 if ($_POST["send_mail"] != "" ||
2158 ($this->isSendMail() && $this->userObj->getEmail() != "")) {
2159 $this->acc_mail->setUser($this->userObj);
2160 $this->acc_mail->send();
2161 }
2162 }
2163
2169 public function setSendMail($value)
2170 {
2171 $this->send_mail = $value ? true: false;
2172 }
2173
2179 public function isSendMail()
2180 {
2181 return $this->send_mail;
2182 }
2183
2189 public function setUserMappingMode($value)
2190 {
2191 if ($value == IL_USER_MAPPING_ID || $value == IL_USER_MAPPING_LOGIN) {
2192 $this->mapping_mode = $value;
2193 } else {
2194 die("wrong argument using methode setUserMappingMethod in " . __FILE__);
2195 }
2196 }
2197
2203 public function getUserMappingMode()
2204 {
2205 return $this->mapping_mode;
2206 }
2207
2214 private function readRequiredFields()
2215 {
2216 global $DIC;
2217
2218 $ilSetting = $DIC['ilSetting'];
2219
2220 if (is_array($this->required_fields)) {
2221 return $this->required_fields;
2222 }
2223 foreach ($ilSetting->getAll() as $field => $value) {
2224 if (substr($field, 0, 8) == 'require_' and $value == 1) {
2225 $value = substr($field, 8);
2226 $this->required_fields[$value] = $value;
2227 }
2228 }
2229 return $this->required_fields ? $this->required_fields : array();
2230 }
2231
2240 private function checkProfileIncomplete($user_obj)
2241 {
2242 include_once "Services/User/classes/class.ilUserProfile.php";
2243 return ilUserProfile::isProfileIncomplete($user_obj);
2244 }
2245
2252 protected function isFieldRequired($fieldname)
2253 {
2254 $requiredFields = $this->readRequiredFields();
2255 $fieldname = strtolower(trim($fieldname));
2256 return array_key_exists($fieldname, $requiredFields);
2257 }
2258
2259 private function verifyPref($key, $value)
2260 {
2261 switch ($key) {
2262 case 'mail_linebreak':
2263 case 'hits_per_page':
2264 if (!is_numeric($value) || $value < 0) {
2265 $this->logFailure("---", "Wrong value '$value': Positiv numeric value expected for preference $key.");
2266 }
2267 break;
2268 case 'language':
2269 case 'skin':
2270 case 'style':
2271 case 'ilPageEditor_HTMLMode':
2272 case 'ilPageEditor_JavaScript':
2273 case 'ilPageEditor_MediaMode':
2274 case 'tst_javascript':
2275 case 'tst_lastquestiontype':
2276 case 'tst_multiline_answers':
2277 case 'tst_use_previous_answers':
2278 case 'graphicalAnswerSetting':
2279 case 'priv_feed_pass':
2280 $this->logFailure("---", "Preference $key is not supported.");
2281 break;
2282 case 'public_city':
2283 case 'public_country':
2284 case 'public_department':
2285 case 'public_email':
2286 case 'public_second_email':
2287 case 'public_fax':
2288 case 'public_hobby':
2289 case 'public_institution':
2290 case 'public_matriculation':
2291 case 'public_phone':
2292 case 'public_phone_home':
2293 case 'public_phone_mobile':
2294 case 'public_phone_office':
2295 case 'public_street':
2296 case 'public_upload':
2297 case 'public_zip':
2298 case 'public_interests_general':
2299 case 'public_interests_help_offered':
2300 case 'public_interests_help_looking':
2301 case 'send_info_mails':
2302 case 'hide_own_online_status':
2303 if (!in_array($value, array('y', 'n'))) {
2304 $this->logFailure("---", "Wrong value '$value': Value 'y' or 'n' expected for preference $key.");
2305 }
2306 break;
2307 case 'bs_allow_to_contact_me':
2308 if (!in_array($value, array('y', 'n'))) {
2309 $this->logFailure("---", "Wrong value '$value': Value 'y' or 'n' expected for preference $key.");
2310 }
2311 break;
2312 case 'chat_osc_accept_msg':
2313 if (!in_array($value, array('y', 'n'))) {
2314 $this->logFailure("---", "Wrong value '$value': Value 'y' or 'n' expected for preference $key.");
2315 }
2316 break;
2317 case 'public_profile':
2318 if (!in_array($value, array('y', 'n', 'g'))) {
2319 $this->logFailure("---", "Wrong value '$value': Value 'y', 'g' or 'n' expected for preference $key.");
2320 }
2321 break;
2322 case 'show_users_online':
2323 if (!in_array($value, array('y', 'n', 'associated'))) {
2324 $this->logFailure("---", "Wrong value '$value': Value 'y' or 'n' or 'associated' expected for preference $key.");
2325 }
2326 break;
2327 case 'mail_incoming_type':
2328 if (!in_array((int) $value, array("0","1","2"))) {
2329 $this->logFailure("---", "Wrong value '$value': Value \"0\" (LOCAL),\"1\" (EMAIL) or \"2\" (BOTH) expected for preference $key.");
2330 }
2331 break;
2332 case 'weekstart':
2333 if (!in_array($value, array("0","1"))) {
2334 $this->logFailure("---", "Wrong value '$value': Value \"0\" (Sunday) or \"1\" (Monday) expected for preference $key.");
2335 }
2336 break;
2337
2338 case 'mail_signature':
2339 break;
2340 case 'user_tz':
2341 include_once('Services/Calendar/classes/class.ilTimeZone.php');
2342 try {
2343 $tz = ilTimeZone::_getInstance($value);
2344 return true;
2345 } catch (ilTimeZoneException $tze) {
2346 $this->logFailure("---", "Wrong value '$value': Invalid timezone $value detected for preference $key.");
2347 }
2348 break;
2349 default:
2351 $this->logFailure("---", "Preference $key is not supported.");
2352 }
2353 break;
2354 }
2355 }
2356
2357 private function updateMailPreferences($usr_id)
2358 {
2359 if (array_key_exists("mail_incoming_type", $this->prefs) ||
2360 array_key_exists("mail_signature", $this->prefs) ||
2361 array_key_exists("mail_linebreak", $this->prefs)
2362 ) {
2363 include_once("Services/Mail/classes/class.ilMailOptions.php");
2364 $mailOptions = new ilMailOptions($usr_id);
2365
2366 $mailOptions->setLinebreak(array_key_exists("mail_linebreak", $this->prefs) ? $this->prefs["mail_linebreak"] : $mailOptions->getLinebreak());
2367 $mailOptions->setSignature(array_key_exists("mail_signature", $this->prefs) ? $this->prefs["mail_signature"] : $mailOptions->getSignature());
2368 $mailOptions->setIncomingType(array_key_exists("mail_incoming_type", $this->prefs) ? $this->prefs["mail_incoming_type"] : $mailOptions->getIncomingType());
2369 $mailOptions->updateOptions();
2370 }
2371 }
2372}
$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 USER_FOLDER_ID
Class ilObjUserFolder.
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.
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 _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
drop an item from user's personal desktop
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 _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par="")
add an item to user's personal desktop
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
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.
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.
if(empty($userids)) $userid
$login
Definition: cron.php:13
$key
Definition: croninfo.php:18
$messages
Definition: en.php:5
if(!array_key_exists('StateId', $_REQUEST)) $id
if(function_exists( 'posix_getuid') &&posix_getuid()===0) if(!array_key_exists('t', $options)) $tag
Definition: cron.php:35
catch(Exception $e) $message
global $ilSetting
Definition: privfeed.php:17
$type
$idp
Definition: prp.php:13
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18