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