ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  var $approve_date_set = false;
52  var $time_limit_set = false;
53  var $time_limit_owner_set = false;
54 
58  var $updateLookAndSkin = false;
60  var $roles;
65  var $action;
74  var $protocol;
84  var $logins;
85 
94 
95 
102 
165 
174 
183 
190 
198 
207 
213 
222 
226  var $skin;
227 
231  var $style;
232 
237 
242 
247 
253  var $user_id;
254 
259  private $userObj;
260 
267 
271  private static $account_mail_cache = array();
272 
282  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  {
305 
306  foreach($skins as $skin)
307  {
308  foreach($skin->getStyles() as $style)
309  {
310  include_once("./Services/Style/System/classes/class.ilSystemStyleSettings.php");
311  if (!ilSystemStyleSettings::_lookupActivatedStyle($skin->getId(),$style->getId()))
312  {
313  continue;
314  }
315  $this->userStyles [] = $skin->getId().":".$style->getId();
316  }
317  }
318  }
319 
320  $settings = $ilias->getAllSettings();
321  if ($settings["usr_settings_hide_skin_style"] == 1)
322  {
323  $this->hideSkin = TRUE;
324  }
325  else
326  {
327  $this->hideSkin = FALSE;
328  }
329  if ($settings["usr_settings_disable_skin_style"] == 1)
330  {
331  $this->disableSkin = TRUE;
332  }
333  else
334  {
335  $this->disableSkin = FALSE;
336  }
337 
338  include_once("Services/Mail/classes/class.ilAccountMail.php");
339  $this->acc_mail = new ilAccountMail();
340  $this->acc_mail->useLangVariablesAsFallback(true);
341 
342  parent::__construct($a_xml_file);
343  }
344 
350  function setFolderId($a_folder_id)
351  {
352  $this->folder_id = $a_folder_id;
353  }
354 
355  function getFolderId()
356  {
357  return $this->folder_id;
358  }
359 
365  function setHandlers($a_xml_parser)
366  {
367  xml_set_object($a_xml_parser,$this);
368  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
369  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
370  }
371 
375  function startParsing()
376  {
377  parent::startParsing();
378  }
379 
385  function setRoleAssignment($a_assign)
386  {
387  $this->role_assign = $a_assign;
388  }
389 
397  function buildTag ($type, $name, $attr="")
398  {
399  $tag = "<";
400 
401  if ($type == "end")
402  $tag.= "/";
403 
404  $tag.= $name;
405 
406  if (is_array($attr))
407  {
408  while (list($k,$v) = each($attr))
409  $tag.= " ".$k."=\"$v\"";
410  }
411 
412  $tag.= ">";
413 
414  return $tag;
415  }
416 
420  function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
421  {
422  switch ($this->mode)
423  {
424  case IL_EXTRACT_ROLES :
425  $this->extractRolesBeginTag($a_xml_parser, $a_name, $a_attribs);
426  break;
427  case IL_USER_IMPORT :
428  $this->importBeginTag($a_xml_parser, $a_name, $a_attribs);
429  break;
430  case IL_VERIFY :
431  $this->verifyBeginTag($a_xml_parser, $a_name, $a_attribs);
432  break;
433  }
434 
435  $this->cdata = "";
436  }
437 
441  function extractRolesBeginTag($a_xml_parser, $a_name, $a_attribs)
442  {
443  switch($a_name)
444  {
445  case "Role":
446  // detect numeric, ilias id (then extract role id) or alphanumeric
447  $this->current_role_id = $a_attribs["Id"];
448  if ($internal_id = ilUtil::__extractId($this->current_role_id, IL_INST_ID))
449  {
450  $this->current_role_id = $internal_id;
451  }
452  $this->current_role_type = $a_attribs["Type"];
453 
454  break;
455  }
456  }
460  function importBeginTag($a_xml_parser, $a_name, $a_attribs)
461  {
462  global $ilias,$lng;
463 
464  switch($a_name)
465  {
466  case "Role":
467  $this->current_role_id = $a_attribs["Id"];
468  if ($internal_id = ilUtil::__extractId($this->current_role_id, IL_INST_ID))
469  {
470  $this->current_role_id = $internal_id;
471  }
472  $this->current_role_type = $a_attribs["Type"];
473  $this->current_role_action = (is_null($a_attribs["Action"])) ? "Assign" : $a_attribs["Action"];
474  break;
475 
476  case "PersonalPicture":
477  $this->personalPicture = array(
478  "encoding" => $a_attribs["encoding"],
479  "imagetype" => $a_attribs["imagetype"],
480  "content" => ""
481  );
482  break;
483 
484  case "Look":
485  $this->skin = $a_attribs["Skin"];
486  $this->style = $a_attribs["Style"];
487  break;
488 
489  case "User":
490  $this->acc_mail->reset();
491  $this->prefs = array();
492  $this->currentPrefKey = null;
493  $this->auth_mode_set = false;
494  $this->approve_date_set = false;
495  $this->time_limit_set = false;
496  $this->time_limit_owner_set = false;
497  $this->updateLookAndSkin = false;
498  $this->skin = "";
499  $this->style = "";
500  $this->personalPicture = null;
501  $this->userCount++;
502  $this->userObj = new ilObjUser();
503 
504  // user defined fields
505  $this->udf_data = array();
506 
507  // if we have an object id, store it
508  $this->user_id = -1;
509  if (!is_null($a_attribs["Id"]) && $this->getUserMappingMode() == IL_USER_MAPPING_ID)
510  {
511  if (is_numeric($a_attribs["Id"]))
512  {
513  $this->user_id = $a_attribs["Id"];
514  }
515  elseif ($id = ilUtil::__extractId ($a_attribs["Id"], IL_INST_ID))
516  {
517  $this->user_id = $id;
518  }
519  }
520 
521  $this->userObj->setPref("skin",
522  $ilias->ini->readVariable("layout","skin"));
523  $this->userObj->setPref("style",
524  $ilias->ini->readVariable("layout","style"));
525 
526  $this->userObj->setLanguage($a_attribs["Language"]);
527  $this->userObj->setImportId($a_attribs["Id"]);
528  $this->action = (is_null($a_attribs["Action"])) ? "Insert" : $a_attribs["Action"];
529  $this->currPassword = null;
530  $this->currPasswordType = null;
531  $this->currActive = null;
532  $this->multi_values = array();
533  break;
534 
535  case 'Password':
536  $this->currPasswordType = $a_attribs['Type'];
537  break;
538  case "AuthMode":
539  if (array_key_exists("type", $a_attribs))
540  {
541  switch ($a_attribs["type"])
542  {
543  case "default":
544  case "local":
545  case "ldap":
546 
547  if(strcmp('ldap', $a_attribs['type']) === 0)
548  {
549  // no server id provided => use default server
550  include_once './Services/LDAP/classes/class.ilLDAPServer.php';
552  if(count($list) == 1)
553  {
554  $this->auth_mode_set = true;
555  $ldap_id = current($list);
556  $this->userObj->setAuthMode('ldap_'.$ldap_id);
557  }
558  }
559  break;
560 
561  case "radius":
562  case "shibboleth":
563  case "script":
564  case "cas":
565  case "soap":
566  case "openid":
567  // begin-patch auth_plugin
568  default:
569  $this->auth_mode_set = true;
570  $this->userObj->setAuthMode($a_attribs["type"]);
571  break;
572  /*
573  $this->logFailure($this->userObj->getLogin(),
574  sprintf($lng->txt("usrimport_xml_element_inapplicable"),"AuthMode",$a_attribs["type"]));
575  break;
576  *
577  */
578  }
579  }
580  else
581  {
582  $this->logFailure($this->userObj->getLogin(),
583  sprintf($lng->txt("usrimport_xml_element_inapplicable"),"AuthMode",$a_attribs["type"]));
584  }
585  break;
586 
587  case 'UserDefinedField':
588  $this->tmp_udf_id = $a_attribs['Id'];
589  $this->tmp_udf_name = $a_attribs['Name'];
590  break;
591 
592  case 'AccountInfo':
593  $this->current_messenger_type = strtolower($a_attribs["Type"]);
594  break;
595  case 'GMapInfo':
596  $this->userObj->setLatitude($a_attribs["latitude"]);
597  $this->userObj->setLongitude($a_attribs["longitude"]);
598  $this->userObj->setLocationZoom($a_attribs["zoom"]);
599  break;
600  case 'Pref':
601  $this->currentPrefKey = $a_attribs["key"];
602  break;
603  }
604  }
608  function verifyBeginTag($a_xml_parser, $a_name, $a_attribs)
609  {
610  global $lng;
611 
612  switch($a_name)
613  {
614  case "Role":
615  if (is_null($a_attribs['Id'])
616  || $a_attribs['Id'] == "")
617  {
618  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_missing"),"Role","Id"));
619  }
620  $this->current_role_id = $a_attribs["Id"];
621  $this->current_role_type = $a_attribs["Type"];
622  if ($this->current_role_type != 'Global'
623  && $this->current_role_type != 'Local')
624  {
625  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_missing"),"Role","Type"));
626  }
627  $this->current_role_action = (is_null($a_attribs["Action"])) ? "Assign" : $a_attribs["Action"];
628  if ($this->current_role_action != "Assign"
629  && $this->current_role_action != "AssignWithParents"
630  && $this->current_role_action != "Detach")
631  {
632  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"Role","Action",$a_attribs["Action"]));
633  }
634  if ($this->action == "Insert"
635  && $this->current_role_action == "Detach")
636  {
637  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_inapplicable"),"Role","Action",$this->current_role_action,$this->action));
638  }
639  if ($this->action == "Delete")
640  {
641  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_inapplicable"),"Role","Delete"));
642  }
643  break;
644 
645  case "User":
646  $this->userCount++;
647  $this->userObj = new ilObjUser();
648  $this->userObj->setLanguage($a_attribs["Language"]);
649  $this->userObj->setImportId($a_attribs["Id"]);
650  $this->currentPrefKey = null;
651  // if we have an object id, store it
652  $this->user_id = -1;
653 
654  if (!is_null($a_attribs["Id"]) && $this->getUserMappingMode() == IL_USER_MAPPING_ID)
655  {
656  if (is_numeric($a_attribs["Id"]))
657  {
658  $this->user_id = $a_attribs["Id"];
659  }
660  elseif ($id = ilUtil::__extractId ($a_attribs["Id"], IL_INST_ID))
661  {
662  $this->user_id = $id;
663  }
664  }
665 
666  $this->action = (is_null($a_attribs["Action"])) ? "Insert" : $a_attribs["Action"];
667  if ($this->action != "Insert"
668  && $this->action != "Update"
669  && $this->action != "Delete")
670  {
671  $this->logFailure($this->userObj->getImportId(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"User","Action",$a_attribs["Action"]));
672  }
673  $this->currPassword = null;
674  $this->currPasswordType = null;
675  break;
676 
677  case 'Password':
678  $this->currPasswordType = $a_attribs['Type'];
679  break;
680  case "AuthMode":
681  if (array_key_exists("type", $a_attribs))
682  {
683  switch($a_attribs["type"])
684  {
685  case "default":
686  case "local":
687  case "ldap":
688 
689  if(strcmp('ldap', $a_attribs['type']) === 0)
690  {
691  // no server id provided
692  include_once './Services/LDAP/classes/class.ilLDAPServer.php';
694  if(count($list) != 1)
695  {
696  $this->logFailure(
697  $this->userObj->getImportId(),
698  sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"AuthMode","type",$a_attribs['type']));
699  }
700  }
701  break;
702 
703  case "radius":
704  case "shibboleth":
705  case "script":
706  case "cas":
707  case "soap":
708  case "openid":
709  // begin-patch auth_plugin
710  default:
711  $this->userObj->setAuthMode($a_attribs["type"]);
712  break;
713  /*
714  default:
715  $this->logFailure($this->userObj->getImportId(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"AuthMode","type",$a_attribs["type"]));
716  break;
717  *
718  */
719  }
720  }
721  else
722  {
723  $this->logFailure($this->userObj->getImportId(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"AuthMode","type",""));
724  }
725  break;
726  case 'Pref':
727  $this->currentPrefKey = $a_attribs["key"];
728  break;
729 
730  }
731  }
732 
736  function handlerEndTag($a_xml_parser, $a_name)
737  {
738  switch ($this->mode)
739  {
740  case IL_EXTRACT_ROLES :
741  $this->extractRolesEndTag($a_xml_parser, $a_name);
742  break;
743  case IL_USER_IMPORT :
744  $this->importEndTag($a_xml_parser, $a_name);
745  break;
746  case IL_VERIFY :
747  $this->verifyEndTag($a_xml_parser, $a_name);
748  break;
749  }
750  }
751 
755  function extractRolesEndTag($a_xml_parser, $a_name)
756  {
757  switch($a_name)
758  {
759  case "Role":
760  $this->roles[$this->current_role_id]["name"] = $this->cdata;
761  $this->roles[$this->current_role_id]["type"] =
762  $this->current_role_type;
763  break;
764  }
765  }
766 
770  function getRoleObject($a_role_id)
771  {
772  if (array_key_exists($a_role_id, $this->localRoleCache))
773  {
774  return $this->localRoleCache[$a_role_id];
775  }
776  else
777  {
778  $role_obj = new ilObjRole($a_role_id, false);
779  $role_obj->read();
780  $this->localRoleCache[$a_role_id] = $role_obj;
781  return $role_obj;
782  }
783 
784  }
788  function getCourseMembersObjectForRole($a_role_id)
789  {
790  global $rbacreview, $rbacadmin, $tree;
791 
792  if (array_key_exists($a_role_id.'_courseMembersObject', $this->localRoleCache))
793  {
794  return $this->localRoleCache[$a_role_id.'_courseMembersObject'];
795  }
796  else
797  {
798  require_once("Modules/Course/classes/class.ilObjCourse.php");
799  require_once("Modules/Course/classes/class.ilCourseParticipants.php");
800  $course_refs = $rbacreview->getFoldersAssignedToRole($a_role_id, true);
801  $course_ref = $course_refs[0];
802  $course_obj = new ilObjCourse($course_ref, true);
803  $crsmembers_obj = ilCourseParticipants::_getInstanceByObjId($course_obj->getId());
804  $this->localRoleCache[$a_role_id.'_courseMembersObject'] = $crsmembers_obj;
805  return $crsmembers_obj;
806  }
807 
808  }
809 
813  function assignToRole($a_user_obj, $a_role_id)
814  {
815  require_once "./Services/AccessControl/classes/class.ilObjRole.php";
816  include_once('./Services/Object/classes/class.ilObject.php');
817  #require_once "Modules/Course/classes/class.ilObjCourse.php";
818  #require_once "Modules/Course/classes/class.ilCourseParticipants.php";
819 
820  global $rbacreview, $rbacadmin, $tree;
821 
822  // Do nothing, if the user is already assigned to the role.
823  // Specifically, we do not want to put a course object or
824  // group object on the personal desktop again, if a user
825  // has removed it from the personal desktop.
826  if ($rbacreview->isAssigned($a_user_obj->getId(), $a_role_id))
827  {
828  return;
829  }
830 
831  // If it is a course role, use the ilCourseMember object to assign
832  // the user to the role
833 
834  $rbacadmin->assignUser($a_role_id, $a_user_obj->getId(), true);
835  $obj_id = $rbacreview->getObjectOfRole($a_role_id);
836  switch($type = ilObject::_lookupType($obj_id))
837  {
838  case 'grp':
839  case 'crs':
840  $ref_ids = ilObject::_getAllReferences($obj_id);
841  $ref_id = current((array) $ref_ids);
842  if($ref_id)
843  {
844  ilObjUser::_addDesktopItem($a_user_obj->getId(),$ref_id,$type);
845  }
846  break;
847  default:
848  break;
849  }
850  }
855  function getParentRoleIds($a_role_id)
856  {
857  global $rbacreview;
858 
859  if (! array_key_exists($a_role_id, $this->parentRolesCache))
860  {
861  $parent_role_ids = array();
862 
863  $role_obj = $this->getRoleObject($a_role_id);
864  $short_role_title = substr($role_obj->getTitle(),0,12);
865  $folders = $rbacreview->getFoldersAssignedToRole($a_role_id, true);
866  if (count($folders) > 0)
867  {
868  $all_parent_role_ids = $rbacreview->getParentRoleIds($folders[0]);
869  foreach ($all_parent_role_ids as $parent_role_id => $parent_role_data)
870  {
871  if ($parent_role_id != $a_role_id)
872  {
873  switch (substr($parent_role_data['title'],0,12))
874  {
875  case 'il_crs_admin' :
876  case 'il_grp_admin' :
877  if ($short_role_title == 'il_crs_admin' || $short_role_title == 'il_grp_admin')
878  {
879  $parent_role_ids[] = $parent_role_id;
880  }
881  break;
882  case 'il_crs_tutor' :
883  case 'il_grp_tutor' :
884  if ($short_role_title == 'il_crs_tutor' || $short_role_title == 'il_grp_tutor')
885  {
886  $parent_role_ids[] = $parent_role_id;
887  }
888  break;
889  case 'il_crs_membe' :
890  case 'il_grp_membe' :
891  if ($short_role_title == 'il_crs_membe' || $short_role_title == 'il_grp_membe')
892  {
893  $parent_role_ids[] = $parent_role_id;
894  }
895  break;
896  default :
897  break;
898  }
899  }
900  }
901  }
902  $this->parentRolesCache[$a_role_id] = $parent_role_ids;
903  }
904  return $this->parentRolesCache[$a_role_id];
905  }
909  function assignToRoleWithParents($a_user_obj, $a_role_id)
910  {
911  $this->assignToRole($a_user_obj, $a_role_id);
912 
913  $parent_role_ids = $this->getParentRoleIds($a_role_id);
914  foreach ($parent_role_ids as $parent_role_id)
915  {
916  $this->assignToRole($a_user_obj, $parent_role_id);
917  }
918  }
922  function detachFromRole($a_user_obj, $a_role_id)
923  {
924  global $rbacreview, $rbacadmin, $tree;
925 
926  $rbacadmin->deassignUser($a_role_id, $a_user_obj->getId());
927 
928  if (substr(ilObject::_lookupTitle($a_role_id),0,6) == 'il_crs' or
929  substr(ilObject::_lookupTitle($a_role_id),0,6) == 'il_grp')
930  {
931  $obj = $rbacreview->getObjectOfRole($a_role_id);
932  $ref = ilObject::_getAllReferences($obj);
933  $ref_id = end($ref);
934  ilObjUser::_dropDesktopItem($a_user_obj->getId(), $ref_id, ilObject::_lookupType($obj));
935  }
936 }
937 
941  function importEndTag($a_xml_parser, $a_name)
942  {
943  global $ilias, $rbacadmin, $rbacreview, $ilUser, $lng, $ilSetting;
944 
945  switch($a_name)
946  {
947  case "Role":
948  $this->roles[$this->current_role_id]["name"] = $this->cdata;
949  $this->roles[$this->current_role_id]["type"] = $this->current_role_type;
950  $this->roles[$this->current_role_id]["action"] = $this->current_role_action;
951  break;
952 
953  case "PersonalPicture":
954  switch ($this->personalPicture["encoding"])
955  {
956  case "Base64":
957  $this->personalPicture["content"] = base64_decode($this->cdata);
958  break;
959  case "UUEncode":
960  $this->personalPicture["content"] = convert_uudecode($this->cdata);
961  break;
962  }
963  break;
964 
965  case "User":
966  $this->userObj->setFullname();
967  // Fetch the user_id from the database, if we didn't have it in xml file
968  // fetch as well, if we are trying to insert -> recognize duplicates!
969  if ($this->user_id == -1 || $this->action=="Insert")
970  $user_id = ilObjUser::getUserIdByLogin($this->userObj->getLogin());
971  else
972  $user_id = $this->user_id;
973 
974  //echo $user_id.":".$this->userObj->getLogin();
975 
976  // Handle conflicts
977  switch ($this->conflict_rule)
978  {
979  case IL_FAIL_ON_CONFLICT :
980  // do not change action
981  break;
982  case IL_UPDATE_ON_CONFLICT :
983  switch ($this->action)
984  {
985  case "Insert" :
986  if ($user_id)
987  {
988  $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_replaced"),"Insert","Update"));
989  $this->action = "Update";
990  }
991  break;
992  case "Update" :
993  if (! $user_id)
994  {
995  $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_replaced"),"Update","Insert"));
996  $this->action = "Insert";
997  }
998  break;
999  case "Delete" :
1000  if (! $user_id)
1001  {
1002  $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_ignored"),"Delete"));
1003  $this->action = "Ignore";
1004  }
1005  break;
1006  }
1007  break;
1008  case IL_IGNORE_ON_CONFLICT :
1009  switch ($this->action)
1010  {
1011  case "Insert" :
1012  if ($user_id)
1013  {
1014  $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_ignored"),"Insert"));
1015  $this->action = "Ignore";
1016  }
1017  break;
1018  case "Update" :
1019  if (! $user_id)
1020  {
1021  $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_ignored"),"Update"));
1022  $this->action = "Ignore";
1023  }
1024  break;
1025  case "Delete" :
1026  if (! $user_id)
1027  {
1028  $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_ignored"),"Delete"));
1029  $this->action = "Ignore";
1030  }
1031  break;
1032  }
1033  break;
1034  }
1035 
1036  // check external account conflict (if external account is already used)
1037  // note: we cannot apply conflict rules in the same manner as to logins here
1038  // so we ignore records with already existing external accounts.
1039  //echo $this->userObj->getAuthMode().'h';
1040  $am = ($this->userObj->getAuthMode() == "default" || $this->userObj->getAuthMode() == "")
1041  ? ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode'))
1042  : $this->userObj->getAuthMode();
1043  $loginForExternalAccount = ($this->userObj->getExternalAccount() == "")
1044  ? ""
1045  : ilObjUser::_checkExternalAuthAccount($am, $this->userObj->getExternalAccount());
1046  switch ($this->action)
1047  {
1048  case "Insert" :
1049  if ($loginForExternalAccount != "")
1050  {
1051  $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_no_insert_ext_account_exists")." (".$this->userObj->getExternalAccount().")");
1052  $this->action = "Ignore";
1053  }
1054  break;
1055 
1056  case "Update" :
1057  // this variable describes the ILIAS login which belongs to the given external account!!!
1058  // it is NOT nescessarily the ILIAS login of the current user record !!
1059  // so if we found an ILIAS login according to the authentication method
1060  // check if the ILIAS login belongs to the current user record, otherwise somebody else is using it!
1061  if ($loginForExternalAccount != "")
1062  {
1063  // check if we changed the value!
1064  $externalAccountHasChanged = $this->userObj->getExternalAccount() != ilObjUser::_lookupExternalAccount($this->user_id);
1065  // if it has changed and the external login
1066  if ($externalAccountHasChanged && trim($loginForExternalAccount) != trim($this->userObj->getLogin()))
1067  {
1068  $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_no_update_ext_account_exists")." (".$this->userObj->getExternalAccount().")");
1069  $this->action = "Ignore";
1070  }
1071  }
1072  break;
1073  }
1074 
1075  if(sizeof($this->multi_values))
1076  {
1077  if(isset($this->multi_values["GeneralInterest"]))
1078  {
1079  $this->userObj->setGeneralInterests($this->multi_values["GeneralInterest"]);
1080  }
1081  if(isset($this->multi_values["OfferingHelp"]))
1082  {
1083  $this->userObj->setOfferingHelp($this->multi_values["OfferingHelp"]);
1084  }
1085  if(isset($this->multi_values["LookingForHelp"]))
1086  {
1087  $this->userObj->setLookingForHelp($this->multi_values["LookingForHelp"]);
1088  }
1089  }
1090 
1091  // Perform the action
1092  switch ($this->action)
1093  {
1094  case "Insert" :
1095  if ($user_id)
1096  {
1097  $this->logFailure($this->userObj->getLogin(),$lng->txt("usrimport_cant_insert"));
1098  }
1099  else
1100  {
1101 
1102  if(!strlen($this->currPassword) == 0)
1103  {
1104  switch(strtoupper($this->currPasswordType))
1105  {
1106  case "BCRYPT":
1107  $this->userObj->setPasswd($this->currPassword, IL_PASSWD_CRYPTED);
1108  $this->userObj->setPasswordEncodingType('bcryptphp');
1109  $this->userObj->setPasswordSalt(null);
1110  break;
1111 
1112  case "PLAIN":
1113  $this->userObj->setPasswd($this->currPassword, IL_PASSWD_PLAIN);
1114  $this->acc_mail->setUserPassword($this->currPassword);
1115  break;
1116 
1117  default:
1118  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"Type","Password",$this->currPasswordType));
1119  break;
1120 
1121  }
1122  }
1123  else
1124  {
1125  // this does the trick for empty passwords
1126  // since a MD5 string has always 32 characters,
1127  // no hashed password combination will ever equal to
1128  // an empty string
1129  $this->userObj->setPasswd("", IL_PASSWD_CRYPTED);
1130 
1131  }
1132 
1133  $this->userObj->setTitle($this->userObj->getFullname());
1134  $this->userObj->setDescription($this->userObj->getEmail());
1135 
1136  if(!$this->time_limit_owner_set)
1137  {
1138  $this->userObj->setTimeLimitOwner($this->getFolderId());
1139  }
1140 
1141  // default time limit settings
1142  if(!$this->time_limit_set)
1143  {
1144  $this->userObj->setTimeLimitUnlimited(1);
1145  $this->userObj->setTimeLimitMessage(0);
1146 
1147  if (! $this->approve_date_set)
1148  {
1149  $this->userObj->setApproveDate(date("Y-m-d H:i:s"));
1150  }
1151  }
1152 
1153 
1154  $this->userObj->setActive($this->currActive == 'true' || is_null($this->currActive));
1155 
1156  // Finally before saving new user.
1157  // Check if profile is incomplete
1158 
1159  // #8759
1160  if(count($this->udf_data))
1161  {
1162  $this->userObj->setUserDefinedData($this->udf_data);
1163  }
1164 
1165  $this->userObj->setProfileIncomplete($this->checkProfileIncomplete($this->userObj));
1166  $this->userObj->create();
1167 
1168  //insert user data in table user_data
1169  $this->userObj->saveAsNew(false);
1170 
1171  // Set default prefs
1172  $this->userObj->setPref('hits_per_page',$ilSetting->get('hits_per_page',30));
1173  //$this->userObj->setPref('show_users_online',$ilSetting->get('show_users_online','y'));
1174 
1175  if (count ($this->prefs))
1176  {
1177  foreach ($this->prefs as $key => $value)
1178  {
1179  if ($key != "mail_incoming_type" &&
1180  $key != "mail_signature" &&
1181  $key != "mail_linebreak"
1182  )
1183  {
1184  $this->userObj->setPref($key, $value);
1185  }
1186  }
1187  }
1188 
1189  if(!is_array($this->prefs) || array_search('chat_osc_accept_msg', $this->prefs) === false)
1190  {
1191  $this->userObj->setPref('chat_osc_accept_msg', $ilSetting->get('chat_osc_accept_msg', 'n'));
1192  }
1193  if(!is_array($this->prefs) || array_search('bs_allow_to_contact_me', $this->prefs) === false)
1194  {
1195  $this->userObj->setPref('bs_allow_to_contact_me', $ilSetting->get('bs_allow_to_contact_me', 'n'));
1196  }
1197 
1198  $this->userObj->writePrefs();
1199 
1200  // update mail preferences, to be extended
1201  $this->updateMailPreferences($this->userObj->getId());
1202 
1203  if (is_array($this->personalPicture))
1204  {
1205  if (strlen($this->personalPicture["content"]))
1206  {
1207  $extension = "jpg";
1208  if (preg_match("/.*(png|jpg|gif|jpeg)$/", $this->personalPicture["imagetype"], $matches))
1209  {
1210  $extension = $matches[1];
1211  }
1212  $tmp_name = $this->saveTempImage($this->personalPicture["content"], ".$extension");
1213  if (strlen($tmp_name))
1214  {
1215  ilObjUser::_uploadPersonalPicture($tmp_name, $this->userObj->getId());
1216  unlink($tmp_name);
1217  }
1218  }
1219  }
1220 
1221  //set role entries
1222  foreach($this->roles as $role_id => $role)
1223  {
1224  if ($this->role_assign[$role_id])
1225  {
1226  $this->assignToRole($this->userObj, $this->role_assign[$role_id]);
1227  }
1228  }
1229 
1230  if(count($this->udf_data))
1231  {
1232  include_once './Services/User/classes/class.ilUserDefinedData.php';
1233  $udd = new ilUserDefinedData($this->userObj->getId());
1234  foreach($this->udf_data as $field => $value)
1235  {
1236  $udd->set("f_".$field,$value);
1237  }
1238  $udd->update();
1239  }
1240 
1241  $this->sendAccountMail();
1242  $this->logSuccess($this->userObj->getLogin(),$this->userObj->getId(), "Insert");
1243  // reset account mail object
1244  $this->acc_mail->reset();
1245  }
1246  break;
1247 
1248  case "Update" :
1249  if (! $user_id)
1250  {
1251  $this->logFailure($this->userObj->getLogin(),$lng->txt("usrimport_cant_update"));
1252  }
1253  else
1254  {
1255  $updateUser = new ilObjUser($user_id);
1256  $updateUser->read();
1257  $updateUser->readPrefs();
1258  if ($this->currPassword != null)
1259  {
1260  switch(strtoupper($this->currPasswordType))
1261  {
1262  case "BCRYPT":
1263  $updateUser->setPasswd($this->currPassword, IL_PASSWD_CRYPTED);
1264  $updateUser->setPasswordEncodingType('bcryptphp');
1265  $updateUser->setPasswordSalt(null);
1266  break;
1267 
1268  case "PLAIN":
1269  $updateUser->setPasswd($this->currPassword, IL_PASSWD_PLAIN);
1270  $this->acc_mail->setUserPassword($this->currPassword);
1271  break;
1272 
1273  default:
1274  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"Type","Password",$this->currPasswordType));
1275  break;
1276  }
1277  }
1278  if (! is_null($this->userObj->getFirstname())) $updateUser->setFirstname($this->userObj->getFirstname());
1279  if (! is_null($this->userObj->getLastname())) $updateUser->setLastname($this->userObj->getLastname());
1280  if (! is_null($this->userObj->getUTitle())) $updateUser->setUTitle($this->userObj->getUTitle());
1281  if (! is_null($this->userObj->getGender())) $updateUser->setGender($this->userObj->getGender());
1282  if (! is_null($this->userObj->getEmail())) $updateUser->setEmail($this->userObj->getEmail());
1283  if (! is_null($this->userObj->getBirthday())) $updateUser->setBirthday($this->userObj->getBirthday());
1284  if (! is_null($this->userObj->getInstitution())) $updateUser->setInstitution($this->userObj->getInstitution());
1285  if (! is_null($this->userObj->getStreet())) $updateUser->setStreet($this->userObj->getStreet());
1286  if (! is_null($this->userObj->getCity())) $updateUser->setCity($this->userObj->getCity());
1287  if (! is_null($this->userObj->getZipCode())) $updateUser->setZipCode($this->userObj->getZipCode());
1288  if (! is_null($this->userObj->getCountry())) $updateUser->setCountry($this->userObj->getCountry());
1289  if (! is_null($this->userObj->getSelectedCountry())) $updateUser->setSelectedCountry($this->userObj->getSelectedCountry());
1290  if (! is_null($this->userObj->getPhoneOffice())) $updateUser->setPhoneOffice($this->userObj->getPhoneOffice());
1291  if (! is_null($this->userObj->getPhoneHome())) $updateUser->setPhoneHome($this->userObj->getPhoneHome());
1292  if (! is_null($this->userObj->getPhoneMobile())) $updateUser->setPhoneMobile($this->userObj->getPhoneMobile());
1293  if (! is_null($this->userObj->getFax())) $updateUser->setFax($this->userObj->getFax());
1294  if (! is_null($this->userObj->getHobby())) $updateUser->setHobby($this->userObj->getHobby());
1295  if (! is_null($this->userObj->getGeneralInterests())) $updateUser->setGeneralInterests($this->userObj->getGeneralInterests());
1296  if (! is_null($this->userObj->getOfferingHelp())) $updateUser->setOfferingHelp($this->userObj->getOfferingHelp());
1297  if (! is_null($this->userObj->getLookingForHelp())) $updateUser->setLookingForHelp($this->userObj->getLookingForHelp());
1298  if (! is_null($this->userObj->getComment())) $updateUser->setComment($this->userObj->getComment());
1299  if (! is_null($this->userObj->getDepartment())) $updateUser->setDepartment($this->userObj->getDepartment());
1300  if (! is_null($this->userObj->getMatriculation())) $updateUser->setMatriculation($this->userObj->getMatriculation());
1301  if (! is_null($this->currActive)) $updateUser->setActive($this->currActive == "true", is_object($ilUser) ? $ilUser->getId() : 0);
1302  if (! is_null($this->userObj->getClientIP())) $updateUser->setClientIP($this->userObj->getClientIP());
1303  if (! is_null($this->userObj->getTimeLimitUnlimited())) $updateUser->setTimeLimitUnlimited($this->userObj->getTimeLimitUnlimited());
1304  if (! is_null($this->userObj->getTimeLimitFrom())) $updateUser->setTimeLimitFrom($this->userObj->getTimeLimitFrom());
1305  if (! is_null($this->userObj->getTimeLimitUntil())) $updateUser->setTimeLimitUntil($this->userObj->getTimeLimitUntil());
1306  if (! is_null($this->userObj->getTimeLimitMessage())) $updateUser->setTimeLimitMessage($this->userObj->getTimeLimitMessage());
1307  if (! is_null($this->userObj->getApproveDate())) $updateUser->setApproveDate($this->userObj->getApproveDate());
1308  if (! is_null($this->userObj->getAgreeDate())) $updateUser->setAgreeDate($this->userObj->getAgreeDate());
1309  if (! is_null($this->userObj->getLanguage())) $updateUser->setLanguage($this->userObj->getLanguage());
1310  if (! is_null($this->userObj->getExternalAccount())) $updateUser->setExternalAccount($this->userObj->getExternalAccount());
1311 
1312  // Fixed: if auth_mode is not set, it was always overwritten with auth_default
1313  #if (! is_null($this->userObj->getAuthMode())) $updateUser->setAuthMode($this->userObj->getAuthMode());
1314  if($this->auth_mode_set)
1315  $updateUser->setAuthMode($this->userObj->getAuthMode());
1316 
1317  // Special handlin since it defaults to 7 (USER_FOLDER_ID)
1318  if($this->time_limit_owner_set)
1319  {
1320  $updateUser->setTimeLimitOwner($this->userObj->getTimeLimitOwner());
1321  }
1322 
1323 
1324  if (count ($this->prefs))
1325  {
1326  foreach ($this->prefs as $key => $value)
1327  {
1328  if ($key != "mail_incoming_type" &&
1329  $key != "mail_signature" &&
1330  $key != "mail_linebreak"
1331  ){
1332  $updateUser->setPref($key, $value);
1333  }
1334  }
1335  }
1336 
1337  // save user preferences (skin and style)
1338  if ($this->updateLookAndSkin)
1339  {
1340  $updateUser->setPref("skin", $this->userObj->getPref("skin"));
1341  $updateUser->setPref("style", $this->userObj->getPref("style"));
1342  }
1343 
1344 
1345  $updateUser->writePrefs();
1346 
1347  // update mail preferences, to be extended
1348  $this->updateMailPreferences($updateUser->getId());
1349 
1350  // #8759
1351  if(count($this->udf_data))
1352  {
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  {
1364  include_once './Services/User/classes/class.ilUserDefinedData.php';
1365  $udd = new ilUserDefinedData($updateUser->getId());
1366  foreach($this->udf_data as $field => $value)
1367  {
1368  $udd->set("f_".$field,$value);
1369  }
1370  $udd->update();
1371  }
1372 
1373  // update login
1374  if (!is_null($this->userObj->getLogin()) && $this->user_id != -1)
1375  {
1376  try
1377  {
1378  $updateUser->updateLogin($this->userObj->getLogin());
1379  }
1380  catch (ilUserException $e)
1381  {
1382  }
1383  }
1384 
1385 
1386  // if language has changed
1387 
1388  if (is_array($this->personalPicture))
1389  {
1390  if (strlen($this->personalPicture["content"]))
1391  {
1392  $extension = "jpg";
1393  if (preg_match("/.*(png|jpg|gif|jpeg)$/", $this->personalPicture["imagetype"], $matches))
1394  {
1395  $extension = $matches[1];
1396  }
1397  $tmp_name = $this->saveTempImage($this->personalPicture["content"], ".$extension");
1398  if (strlen($tmp_name))
1399  {
1400  ilObjUser::_uploadPersonalPicture($tmp_name, $this->userObj->getId());
1401  unlink($tmp_name);
1402  }
1403  }
1404  }
1405 
1406 
1407  //update role entries
1408  //-------------------
1409  foreach ($this->roles as $role_id => $role)
1410  {
1411  if ($this->role_assign[$role_id])
1412  {
1413  switch ($role["action"])
1414  {
1415  case "Assign" :
1416  $this->assignToRole($updateUser, $this->role_assign[$role_id]);
1417  break;
1418  case "AssignWithParents" :
1419  $this->assignToRoleWithParents($updateUser, $this->role_assign[$role_id]);
1420  break;
1421  case "Detach" :
1422  $this->detachFromRole($updateUser, $this->role_assign[$role_id]);
1423  break;
1424  }
1425  }
1426  }
1427  $this->logSuccess($updateUser->getLogin(), $user_id, "Update");
1428  }
1429  break;
1430  case "Delete" :
1431  if (! $user_id)
1432  {
1433  $this->logFailure($this->userObj->getLogin(),$lng->txt("usrimport_cant_delete"));
1434  }
1435  else
1436  {
1437  $deleteUser = new ilObjUser($user_id);
1438  $deleteUser->delete();
1439 
1440  $this->logSuccess($this->userObj->getLogin(),$user_id, "Delete");
1441  }
1442  break;
1443  }
1444 
1445  // init role array for next user
1446  $this->roles = array();
1447  break;
1448 
1449  case "Login":
1450  $this->userObj->setLogin($this->cdata);
1451  break;
1452 
1453  case "Password":
1454  $this->currPassword = $this->cdata;
1455  break;
1456 
1457  case "Firstname":
1458  $this->userObj->setFirstname($this->cdata);
1459  break;
1460 
1461  case "Lastname":
1462  $this->userObj->setLastname($this->cdata);
1463  break;
1464 
1465  case "Title":
1466  $this->userObj->setUTitle($this->cdata);
1467  break;
1468 
1469  case "Gender":
1470  $this->userObj->setGender($this->cdata);
1471  break;
1472 
1473  case "Email":
1474  $this->userObj->setEmail($this->cdata);
1475  break;
1476 
1477  case "Birthday":
1478  $timestamp = strtotime($this->cdata);
1479  if ($timestamp !== false)
1480  {
1481  $this->userObj->setBirthday($this->cdata);
1482  }
1483  break;
1484  case "Institution":
1485  $this->userObj->setInstitution($this->cdata);
1486  break;
1487 
1488  case "Street":
1489  $this->userObj->setStreet($this->cdata);
1490  break;
1491 
1492  case "City":
1493  $this->userObj->setCity($this->cdata);
1494  break;
1495 
1496  case "PostalCode":
1497  $this->userObj->setZipCode($this->cdata);
1498  break;
1499 
1500  case "Country":
1501  $this->userObj->setCountry($this->cdata);
1502  break;
1503 
1504  case "SelCountry":
1505  $this->userObj->setSelectedCountry($this->cdata);
1506  break;
1507 
1508  case "PhoneOffice":
1509  $this->userObj->setPhoneOffice($this->cdata);
1510  break;
1511 
1512  case "PhoneHome":
1513  $this->userObj->setPhoneHome($this->cdata);
1514  break;
1515 
1516  case "PhoneMobile":
1517  $this->userObj->setPhoneMobile($this->cdata);
1518  break;
1519 
1520  case "Fax":
1521  $this->userObj->setFax($this->cdata);
1522  break;
1523 
1524  case "Hobby":
1525  $this->userObj->setHobby($this->cdata);
1526  break;
1527 
1528  case "GeneralInterest":
1529  case "OfferingHelp":
1530  case "LookingForHelp":
1531  $this->multi_values[$a_name][] = $this->cdata;
1532  break;
1533 
1534  case "Comment":
1535  $this->userObj->setComment($this->cdata);
1536  break;
1537 
1538  case "Department":
1539  $this->userObj->setDepartment($this->cdata);
1540  break;
1541 
1542  case "Matriculation":
1543  $this->userObj->setMatriculation($this->cdata);
1544  break;
1545 
1546  case "Active":
1547  $this->currActive = $this->cdata;
1548  break;
1549 
1550  case "ClientIP":
1551  $this->userObj->setClientIP($this->cdata);
1552  break;
1553 
1554  case "TimeLimitOwner":
1555  $this->time_limit_owner_set = true;
1556  $this->userObj->setTimeLimitOwner($this->cdata);
1557  break;
1558 
1559  case "TimeLimitUnlimited":
1560  $this->time_limit_set = true;
1561  $this->userObj->setTimeLimitUnlimited($this->cdata);
1562  break;
1563 
1564  case "TimeLimitFrom":
1565  if (is_numeric($this->cdata))
1566  {
1567  // Treat cdata as a unix timestamp
1568  $this->userObj->setTimeLimitFrom($this->cdata);
1569  }
1570  else
1571  {
1572  // Try to convert cdata into unix timestamp, or ignore it
1573  $timestamp = strtotime($this->cdata);
1574  if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00")
1575  {
1576  $this->userObj->setTimeLimitFrom($timestamp);
1577  }
1578  elseif ($this->cdata == "0000-00-00 00:00:00")
1579  {
1580  $this->userObj->setTimeLimitFrom(null);
1581  }
1582 
1583  }
1584  break;
1585 
1586  case "TimeLimitUntil":
1587  if (is_numeric($this->cdata))
1588  {
1589  // Treat cdata as a unix timestamp
1590  $this->userObj->setTimeLimitUntil($this->cdata);
1591  }
1592  else
1593  {
1594  // Try to convert cdata into unix timestamp, or ignore it
1595  $timestamp = strtotime($this->cdata);
1596  if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00")
1597  {
1598  $this->userObj->setTimeLimitUntil($timestamp);
1599  }
1600  elseif ($this->cdata == "0000-00-00 00:00:00")
1601  {
1602  $this->userObj->setTimeLimitUntil(null);
1603  }
1604  }
1605  break;
1606 
1607  case "TimeLimitMessage":
1608  $this->userObj->setTimeLimitMessage($this->cdata);
1609  break;
1610 
1611  case "ApproveDate":
1612  $this->approve_date_set = true;
1613  if (is_numeric($this->cdata))
1614  {
1615  // Treat cdata as a unix timestamp
1616  $tmp_date = new ilDateTime($this->cdata,IL_CAL_UNIX);
1617  $this->userObj->setApproveDate($tmp_date->get(IL_CAL_DATETIME));
1618  }
1619  else
1620  {
1621  // Try to convert cdata into unix timestamp, or ignore it
1622  $timestamp = strtotime($this->cdata);
1623  if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00")
1624  {
1625  $tmp_date = new ilDateTime($timestamp,IL_CAL_UNIX);
1626  $this->userObj->setApproveDate($tmp_date->get(IL_CAL_DATETIME));
1627  }
1628  elseif ($this->cdata == "0000-00-00 00:00:00")
1629  {
1630  $this->userObj->setApproveDate(null);
1631  }
1632  }
1633  break;
1634 
1635  case "AgreeDate":
1636  if (is_numeric($this->cdata))
1637  {
1638  // Treat cdata as a unix timestamp
1639  $tmp_date = new ilDateTime($this->cdata,IL_CAL_UNIX);
1640  $this->userObj->setAgreeDate($tmp_date->get(IL_CAL_DATETIME));
1641  }
1642  else
1643  {
1644  // Try to convert cdata into unix timestamp, or ignore it
1645  $timestamp = strtotime($this->cdata);
1646  if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00")
1647  {
1648  $tmp_date = new ilDateTime($timestamp,IL_CAL_UNIX);
1649  $this->userObj->setAgreeDate($tmp_date->get(IL_CAL_DATETIME));
1650  }
1651  elseif ($this->cdata == "0000-00-00 00:00:00")
1652  {
1653  $this->userObj->setAgreeDate(null);
1654  }
1655  }
1656  break;
1657 
1658  case "ExternalAccount":
1659  $this->userObj->setExternalAccount($this->cdata);
1660  break;
1661 
1662  case "Look":
1663  $this->updateLookAndSkin = false;
1664  if (!$this->hideSkin)
1665  {
1666  // TODO: what to do with disabled skins? is it possible to change the skin via import?
1667  if ((strlen($this->skin) > 0) && (strlen($this->style) > 0))
1668  {
1669  if (is_array($this->userStyles))
1670  {
1671  if (in_array($this->skin . ":" . $this->style, $this->userStyles))
1672  {
1673  $this->userObj->setPref("skin", $this->skin);
1674  $this->userObj->setPref("style", $this->style);
1675  $this->updateLookAndSkin = true;
1676  }
1677  }
1678  }
1679  }
1680  break;
1681 
1682  case 'UserDefinedField':
1683  include_once './Services/User/classes/class.ilUserDefinedFields.php';
1685  if($field_id = $udf->fetchFieldIdFromImportId($this->tmp_udf_id))
1686  {
1687  $this->udf_data[$field_id] = $this->cdata;
1688  }
1689  elseif($field_id = $udf->fetchFieldIdFromName($this->tmp_udf_name))
1690  {
1691  $this->udf_data[$field_id] = $this->cdata;
1692  }
1693  break;
1694  case 'AccountInfo':
1695  if($this->current_messenger_type =="external")
1696  {
1697  $this->userObj->setExternalAccount($this->cdata);
1698  }
1699  break;
1700  case 'Pref':
1701  if ($this->currentPrefKey != null && strlen(trim($this->cdata)) > 0
1702  && ilUserXMLWriter::isPrefExportable($this->currentPrefKey))
1703  $this->prefs[$this->currentPrefKey] = trim($this->cdata);
1704  $this->currentPrefKey = null;
1705  break;
1706  }
1707  }
1708 
1713  function saveTempImage($image_data, $filename)
1714  {
1715  $tempname = ilUtil::ilTempnam() . $filename;
1716  $fh = fopen($tempname, "wb");
1717  if ($fh == false)
1718  {
1719  return "";
1720  }
1721  $imagefile = fwrite($fh, $image_data);
1722  fclose($fh);
1723  return $tempname;
1724  }
1725 
1729  function verifyEndTag($a_xml_parser, $a_name)
1730  {
1731  global $lng,$ilAccess,$ilSetting,$ilObjDataCache;
1732 
1733  switch($a_name)
1734  {
1735  case "Role":
1736  $this->roles[$this->current_role_id]["name"] = $this->cdata;
1737  $this->roles[$this->current_role_id]["type"] = $this->current_role_type;
1738  $this->roles[$this->current_role_id]["action"] = $this->current_role_action;
1739  break;
1740 
1741  case "User":
1742  $this->userObj->setFullname();
1743  if ($this->user_id != -1 && ($this->action == "Update" || $this->action == "Delete"))
1744  $user_exists = !is_null(ilObjUser::_lookupLogin($this->user_id));
1745  else
1746  $user_exists = ilObjUser::getUserIdByLogin($this->userObj->getLogin()) != 0;
1747 
1748  if (is_null($this->userObj->getLogin()))
1749  {
1750  $this->logFailure("---",sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Login", "Insert"));
1751  }
1752 
1753  switch ($this->action)
1754  {
1755  case "Insert" :
1756  if ($user_exists and $this->conflict_rule == IL_FAIL_ON_CONFLICT)
1757  {
1758  $this->logWarning($this->userObj->getLogin(),$lng->txt("usrimport_cant_insert"));
1759  }
1760  if (is_null($this->userObj->getGender()) && $this->isFieldRequired("gender"))
1761  {
1762  $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Gender", "Insert"));
1763  }
1764  if (is_null($this->userObj->getFirstname()))
1765  {
1766  $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Firstname", "Insert"));
1767  }
1768  if (is_null($this->userObj->getLastname()))
1769  {
1770  $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Lastname", "Insert"));
1771  }
1772  if (count($this->roles) == 0)
1773  {
1774  $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Role", "Insert"));
1775  }
1776  else
1777  {
1778  $has_global_role = false;
1779  foreach ($this->roles as $role)
1780  {
1781  if ($role['type'] == 'Global')
1782  {
1783  $has_global_role = true;
1784  break;
1785  }
1786  }
1787  if (! $has_global_role)
1788  {
1789  $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_global_role_for_action_required"),"Insert"));
1790  }
1791  }
1792  break;
1793  case "Update" :
1794  if(!$user_exists)
1795  {
1796  $this->logWarning($this->userObj->getLogin(),$lng->txt("usrimport_cant_update"));
1797  }
1798  elseif($this->user_id != -1 && !is_null($this->userObj->getLogin()))
1799  // check if someone owns the new login name!
1800  {
1801  $someonesId = ilObjUser::_lookupId($this->userObj->getLogin());
1802 
1803  if (is_numeric($someonesId ) && $someonesId != $this->user_id) {
1804  $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_login_is_not_unique"));
1805  }
1806  }
1807  break;
1808  case "Delete" :
1809  if(!$user_exists)
1810  {
1811  $this->logWarning($this->userObj->getLogin(),$lng->txt("usrimport_cant_delete"));
1812  }
1813  break;
1814  }
1815 
1816  // init role array for next user
1817  $this->roles = array();
1818  break;
1819 
1820  case "Login":
1821  if (array_key_exists($this->cdata, $this->logins))
1822  {
1823  $this->logWarning($this->cdata, $lng->txt("usrimport_login_is_not_unique"));
1824  }
1825  else
1826  {
1827  $this->logins[$this->cdata] = $this->cdata;
1828  }
1829  $this->userObj->setLogin($this->cdata);
1830  break;
1831 
1832  case "Password":
1833  switch ($this->currPasswordType)
1834  {
1835  case "BCRYPT":
1836  $this->userObj->setPasswd($this->cdata, IL_PASSWD_CRYPTED);
1837  $this->userObj->setPasswordEncodingType('bcryptphp');
1838  $this->userObj->setPasswordSalt(null);
1839  break;
1840 
1841  case "PLAIN":
1842  $this->userObj->setPasswd($this->cdata, IL_PASSWD_PLAIN);
1843  $this->acc_mail->setUserPassword($this->currPassword);
1844  break;
1845 
1846  default :
1847  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"Type","Password",$this->currPasswordType));
1848  break;
1849  }
1850  break;
1851 
1852  case "Firstname":
1853  $this->userObj->setFirstname($this->cdata);
1854  break;
1855 
1856  case "Lastname":
1857  $this->userObj->setLastname($this->cdata);
1858  break;
1859 
1860  case "Title":
1861  $this->userObj->setUTitle($this->cdata);
1862  break;
1863 
1864  case "Gender":
1865  if ($this->cdata != "m"
1866  && $this->cdata != "f")
1867  {
1868  $this->logFailure(
1869  $this->userObj->getLogin(),
1870  sprintf($lng->txt("usrimport_xml_element_content_illegal"),"Gender",$this->cdata)
1871  );
1872  }
1873  $this->userObj->setGender($this->cdata);
1874  break;
1875 
1876  case "Email":
1877  $this->userObj->setEmail($this->cdata);
1878  break;
1879 
1880  case "Institution":
1881  $this->userObj->setInstitution($this->cdata);
1882  break;
1883 
1884  case "Street":
1885  $this->userObj->setStreet($this->cdata);
1886  break;
1887 
1888  case "City":
1889  $this->userObj->setCity($this->cdata);
1890  break;
1891 
1892  case "PostalCode":
1893  $this->userObj->setZipCode($this->cdata);
1894  break;
1895 
1896  case "Country":
1897  $this->userObj->setCountry($this->cdata);
1898  break;
1899 
1900  case "SelCountry":
1901  $this->userObj->setSelectedCountry($this->cdata);
1902  break;
1903 
1904  case "PhoneOffice":
1905  $this->userObj->setPhoneOffice($this->cdata);
1906  break;
1907 
1908  case "PhoneHome":
1909  $this->userObj->setPhoneHome($this->cdata);
1910  break;
1911 
1912  case "PhoneMobile":
1913  $this->userObj->setPhoneMobile($this->cdata);
1914  break;
1915 
1916  case "Fax":
1917  $this->userObj->setFax($this->cdata);
1918  break;
1919 
1920  case "Hobby":
1921  $this->userObj->setHobby($this->cdata);
1922  break;
1923 
1924  case "GeneralInterest":
1925  case "OfferingHelp":
1926  case "LookingForHelp":
1927  $this->multi_values[$a_name][] = $this->cdata;
1928  break;
1929 
1930  case "Comment":
1931  $this->userObj->setComment($this->cdata);
1932  break;
1933 
1934  case "Department":
1935  $this->userObj->setDepartment($this->cdata);
1936  break;
1937 
1938  case "Matriculation":
1939  $this->userObj->setMatriculation($this->cdata);
1940  break;
1941 
1942  case "ExternalAccount":
1943 //echo "-".$this->userObj->getAuthMode()."-".$this->userObj->getLogin()."-";
1944  $am = ($this->userObj->getAuthMode() == "default" || $this->userObj->getAuthMode() == "")
1945  ? ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode'))
1946  : $this->userObj->getAuthMode();
1947  $loginForExternalAccount = (trim($this->cdata) == "")
1948  ? ""
1949  : ilObjUser::_checkExternalAuthAccount($am, trim($this->cdata));
1950  switch ($this->action)
1951  {
1952  case "Insert" :
1953  if ($loginForExternalAccount != "")
1954  {
1955  $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_no_insert_ext_account_exists")." (".$this->cdata.")");
1956  }
1957  break;
1958 
1959  case "Update" :
1960  if ($loginForExternalAccount != "")
1961  {
1962  $externalAccountHasChanged = trim($this->cdata) != ilObjUser::_lookupExternalAccount($this->user_id);
1963  if ($externalAccountHasChanged && trim($loginForExternalAccount) != trim($this->userObj->getLogin()))
1964  {
1965  $this->logWarning($this->userObj->getLogin(),
1966  $lng->txt("usrimport_no_update_ext_account_exists")." (".$this->cdata." for ".$loginForExternalAccount.")");
1967  }
1968  }
1969  break;
1970 
1971  }
1972  if ($externalAccountHasChanged)
1973  $this->userObj->setExternalAccount(trim($this->cdata));
1974  break;
1975 
1976  case "Active":
1977  if ($this->cdata != "true"
1978  && $this->cdata != "false")
1979  {
1980  $this->logFailure($this->userObj->getLogin(),
1981  sprintf($lng->txt("usrimport_xml_element_content_illegal"),"Active",$this->cdata));
1982  }
1983  $this->currActive = $this->cdata;
1984  break;
1985  case "TimeLimitOwner":
1986  if (!preg_match("/\d+/", $this->cdata))
1987  {
1988  $this->logFailure($this->userObj->getLogin(),
1989  sprintf($lng->txt("usrimport_xml_element_content_illegal"),"TimeLimitOwner",$this->cdata));
1990  }
1991  elseif(!$ilAccess->checkAccess('cat_administrate_users','',$this->cdata))
1992  {
1993  $this->logFailure($this->userObj->getLogin(),
1994  sprintf($lng->txt("usrimport_xml_element_content_illegal"),"TimeLimitOwner",$this->cdata));
1995  }
1996  elseif($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($this->cdata)) != 'cat' && !(int) $this->cdata == USER_FOLDER_ID)
1997  {
1998  $this->logFailure($this->userObj->getLogin(),
1999  sprintf($lng->txt("usrimport_xml_element_content_illegal"),"TimeLimitOwner",$this->cdata));
2000 
2001  }
2002  $this->userObj->setTimeLimitOwner($this->cdata);
2003  break;
2004  case "TimeLimitUnlimited":
2005  switch (strtolower($this->cdata))
2006  {
2007  case "true":
2008  case "1":
2009  $this->userObj->setTimeLimitUnlimited(1);
2010  break;
2011  case "false":
2012  case "0":
2013  $this->userObj->setTimeLimitUnlimited(0);
2014  break;
2015  default:
2016  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"),"TimeLimitUnlimited",$this->cdata));
2017  break;
2018  }
2019  break;
2020  case "TimeLimitFrom":
2021  // Accept datetime or Unix timestamp
2022  if (strtotime($this->cdata) === false && ! is_numeric($this->cdata))
2023  {
2024  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"),"TimeLimitFrom",$this->cdata));
2025  }
2026  $this->userObj->setTimeLimitFrom($this->cdata);
2027  break;
2028  case "TimeLimitUntil":
2029  // Accept datetime or Unix timestamp
2030  if (strtotime($this->cdata) === false && ! is_numeric($this->cdata))
2031  {
2032  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"),"TimeLimitUntil",$this->cdata));
2033  }
2034  $this->userObj->setTimeLimitUntil($this->cdata);
2035  break;
2036  case "TimeLimitMessage":
2037  switch (strtolower($this->cdata))
2038  {
2039  case "1":
2040  $this->userObj->setTimeLimitMessage(1);
2041  break;
2042  case "0":
2043  $this->userObj->setTimeLimitMessage(0);
2044  break;
2045  default:
2046  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"),"TimeLimitMessage",$this->cdata));
2047  break;
2048  }
2049  break;
2050  case "ApproveDate":
2051  // Accept datetime or Unix timestamp
2052  if (strtotime($this->cdata) === false && ! is_numeric($this->cdata) && !$this->cdata == "0000-00-00 00:00:00")
2053  {
2054  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"),"ApproveDate",$this->cdata));
2055  }
2056  break;
2057  case "AgreeDate":
2058  // Accept datetime or Unix timestamp
2059  if (strtotime($this->cdata) === false && ! is_numeric($this->cdata) && !$this->cdata == "0000-00-00 00:00:00")
2060  {
2061  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"),"AgreeDate",$this->cdata));
2062  }
2063  break;
2064  case "Pref":
2065  if ($this->currentPrefKey != null)
2066  $this->verifyPref($this->currentPrefKey, $this->cdata);
2067  $this->currentPrefKey == null;
2068  }
2069  }
2070 
2074  function handlerCharacterData($a_xml_parser, $a_data)
2075  {
2076  // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
2077  // TODO: Mit Alex klären, ob das noch benötigt wird $a_data = preg_replace("/\n/","",$a_data);
2078  // TODO: Mit Alex klären, ob das noch benötigt wird $a_data = preg_replace("/\t+/","",$a_data);
2079  if($a_data != "\n") $a_data = preg_replace("/\t+/"," ",$a_data);
2080 
2081  if(strlen($a_data) > 0)
2082  {
2083  $this->cdata .= $a_data;
2084  }
2085  }
2086 
2091  {
2092  return $this->roles;
2093  }
2097  function getUserCount()
2098  {
2099  return $this->userCount;
2100  }
2101 
2108  function logWarning($aLogin, $aMessage)
2109  {
2110  if (! array_key_exists($aLogin, $this->protocol))
2111  {
2112  $this->protocol[$aLogin] = array();
2113  }
2114  if ($aMessage)
2115  {
2116  $this->protocol[$aLogin][] = $aMessage;
2117  }
2118  if ($this->error_level == IL_IMPORT_SUCCESS)
2119  {
2120  $this->error_level = IL_IMPORT_WARNING;
2121  }
2122  }
2129  function logFailure($aLogin, $aMessage)
2130  {
2131  if (! array_key_exists($aLogin, $this->protocol))
2132  {
2133  $this->protocol[$aLogin] = array();
2134  }
2135  if ($aMessage)
2136  {
2137  $this->protocol[$aLogin][] = $aMessage;
2138  }
2139  $this->error_level = IL_IMPORT_FAILURE;
2140  }
2141 
2149  function logSuccess($aLogin, $userid, $action)
2150  {
2151  $this->user_mapping[$userid] = array("login" => $aLogin, "action" => $action, "message" => "successful");
2152  }
2153 
2154 
2163  function getProtocol()
2164  {
2165  return $this->protocol;
2166  }
2170  function getProtocolAsHTML($a_log_title)
2171  {
2172  global $lng;
2173 
2174  $block = new ilTemplate("tpl.usr_import_log_block.html", true, true, "Services/User");
2175  $block->setVariable("TXT_LOG_TITLE", $a_log_title);
2176  $block->setVariable("TXT_MESSAGE_ID", $lng->txt("login"));
2177  $block->setVariable("TXT_MESSAGE_TEXT", $lng->txt("message"));
2178  foreach ($this->getProtocol() as $login => $messages)
2179  {
2180  $block->setCurrentBlock("log_row");
2181  $reason = "";
2182  foreach ($messages as $message)
2183  {
2184  if ($reason == "")
2185  {
2186  $reason = $message;
2187  }
2188  else
2189  {
2190  $reason = $reason."<br>".$message;
2191  }
2192  }
2193  $block->setVariable("MESSAGE_ID", $login);
2194  $block->setVariable("MESSAGE_TEXT", $reason);
2195  $block->parseCurrentBlock();
2196  }
2197  return $block->get();
2198  }
2199 
2203  function isSuccess()
2204  {
2205  return $this->error_level == IL_IMPORT_SUCCESS;
2206  }
2207 
2212  function getErrorLevel()
2213  {
2214  return $this->error_level;
2215  }
2216 
2222  function getUserMapping() {
2223  return $this->user_mapping;
2224  }
2225 
2229  function sendAccountMail()
2230  {
2231  if($_POST["send_mail"] != "" ||
2232  ($this->isSendMail() && $this->userObj->getEmail() != ""))
2233  {
2234  $this->acc_mail->setUser($this->userObj);
2235 
2236  $amail = $this->readAccountMailFromCache($this->userObj->getLanguage());
2237  if($amail["att_file"])
2238  {
2239  include_once "Services/User/classes/class.ilFSStorageUserFolder.php";
2241  $fs->create();
2242  $path = $fs->getAbsolutePath() . "/";
2243 
2244  $this->acc_mail->addAttachment($path . "/" . $amail["lang"], $amail["att_file"]);
2245  }
2246  $this->acc_mail->send();
2247  }
2248  }
2249 
2254  private function readAccountMailFromCache($lang_key)
2255  {
2256  if(!isset(self::$account_mail_cache[$lang_key]))
2257  {
2258  $default_lang_key = $GLOBALS["lng"]->getDefaultLanguage();
2259 
2260  // try individual account mail in user administration
2261  include_once './Services/User/classes/class.ilObjUserFolder.php';
2262 
2263  $amail = ilObjUserFolder::_lookupNewAccountMail($lang_key);
2264 
2265  if (trim($amail["body"]) != "" && trim($amail["subject"]) != "")
2266  {
2267  self::$account_mail_cache[$lang_key] = $amail;
2268  }
2269  else
2270  {
2271  $lang_key = $default_lang_key;
2272  }
2273 
2274  if(!isset(self::$account_mail_cache[$default_lang_key]))
2275  {
2276  $amail = ilObjUserFolder::_lookupNewAccountMail($default_lang_key);
2277  self::$account_mail_cache[$default_lang_key] = $amail;
2278  }
2279  }
2280  return self::$account_mail_cache[$lang_key];
2281  }
2282 
2288  function setSendMail ($value) {
2289  $this->send_mail = $value ? true: false;
2290  }
2291 
2297  function isSendMail () {
2298  return $this->send_mail;
2299  }
2300 
2306  function setUserMappingMode($value)
2307  {
2308  if ($value == IL_USER_MAPPING_ID || $value == IL_USER_MAPPING_LOGIN)
2309  $this->mapping_mode = $value;
2310  else die ("wrong argument using methode setUserMappingMethod in ".__FILE__);
2311  }
2312 
2319  {
2320  return $this->mapping_mode;
2321  }
2322 
2329  private function readRequiredFields()
2330  {
2331  global $ilSetting;
2332 
2333  if(is_array($this->required_fields))
2334  {
2335  return $this->required_fields;
2336  }
2337  foreach($ilSetting->getAll() as $field => $value)
2338  {
2339  if(substr($field,0,8) == 'require_' and $value == 1)
2340  {
2341  $value = substr($field,8);
2342  $this->required_fields[$value] = $value;
2343  }
2344  }
2345  return $this->required_fields ? $this->required_fields : array();
2346  }
2347 
2356  private function checkProfileIncomplete($user_obj)
2357  {
2358  include_once "Services/User/classes/class.ilUserProfile.php";
2359  return ilUserProfile::isProfileIncomplete($user_obj);
2360  }
2361 
2368  protected function isFieldRequired ($fieldname)
2369  {
2370  $requiredFields = $this->readRequiredFields();
2371  $fieldname = strtolower(trim($fieldname));
2372  return array_key_exists($fieldname, $requiredFields);
2373  }
2374 
2375  private function verifyPref ($key, $value) {
2376  switch ($key) {
2377  case 'mail_linebreak':
2378  case 'hits_per_page':
2379  if (!is_numeric($value) || $value < 0)
2380  $this->logFailure("---", "Wrong value '$value': Positiv numeric value expected for preference $key.");
2381  break;
2382  case 'language':
2383  case 'skin':
2384  case 'style':
2385  case 'ilPageEditor_HTMLMode':
2386  case 'ilPageEditor_JavaScript':
2387  case 'ilPageEditor_MediaMode':
2388  case 'tst_javascript':
2389  case 'tst_lastquestiontype':
2390  case 'tst_multiline_answers':
2391  case 'tst_use_previous_answers':
2392  case 'graphicalAnswerSetting':
2393  case 'priv_feed_pass':
2394  $this->logFailure("---", "Preference $key is not supported.");
2395  break;
2396  case 'public_city':
2397  case 'public_country':
2398  case 'public_department':
2399  case 'public_email':
2400  case 'public_fax':
2401  case 'public_hobby':
2402  case 'public_institution':
2403  case 'public_matriculation':
2404  case 'public_phone':
2405  case 'public_phone_home':
2406  case 'public_phone_mobile':
2407  case 'public_phone_office':
2408  case 'public_street':
2409  case 'public_upload':
2410  case 'public_zip':
2411  case 'public_interests_general':
2412  case 'public_interests_help_offered':
2413  case 'public_interests_help_looking':
2414  case 'send_info_mails':
2415  case 'hide_own_online_status':
2416  if (!in_array($value, array('y', 'n')))
2417  $this->logFailure("---", "Wrong value '$value': Value 'y' or 'n' expected for preference $key.");
2418  break;
2419  case 'bs_allow_to_contact_me':
2420  if(!in_array($value, array('y', 'n')))
2421  {
2422  $this->logFailure("---", "Wrong value '$value': Value 'y' or 'n' expected for preference $key.");
2423  }
2424  break;
2425  case 'chat_osc_accept_msg':
2426  if(!in_array($value, array('y', 'n')))
2427  {
2428  $this->logFailure("---", "Wrong value '$value': Value 'y' or 'n' expected for preference $key.");
2429  }
2430  break;
2431  case 'public_profile':
2432  if (!in_array($value, array('y', 'n', 'g')))
2433  $this->logFailure("---", "Wrong value '$value': Value 'y', 'g' or 'n' expected for preference $key.");
2434  break;
2435  case 'show_users_online':
2436  if (!in_array($value, array('y', 'n', 'associated')))
2437  $this->logFailure("---", "Wrong value '$value': Value 'y' or 'n' or 'associated' expected for preference $key.");
2438  break;
2439  case 'mail_incoming_type':
2440  if (!in_array((int) $value, array("0","1","2")))
2441  $this->logFailure("---", "Wrong value '$value': Value \"0\" (LOCAL),\"1\" (EMAIL) or \"2\" (BOTH) expected for preference $key.");
2442  break;
2443  case 'weekstart':
2444  if (!in_array($value, array ("0","1")))
2445  $this->logFailure("---", "Wrong value '$value': Value \"0\" (Sunday) or \"1\" (Monday) expected for preference $key.");
2446  break;
2447 
2448  case 'mail_signature':
2449  break;
2450  case 'user_tz':
2451  include_once('Services/Calendar/classes/class.ilTimeZone.php');
2452  try {
2453  $tz = ilTimeZone::_getInstance($value);
2454  return true;
2455  } catch (ilTimeZoneException $tze) {
2456  $this->logFailure("---", "Wrong value '$value': Invalid timezone $value detected for preference $key.");
2457  }
2458  break;
2459  default:
2461  $this->logFailure("---", "Preference $key is not supported.");
2462  break;
2463  }
2464  }
2465 
2466  private function updateMailPreferences ($usr_id) {
2467  if (array_key_exists("mail_incoming_type", $this->prefs) ||
2468  array_key_exists("mail_signature", $this->prefs) ||
2469  array_key_exists("mail_linebreak", $this->prefs)
2470  )
2471  {
2472  include_once("Services/Mail/classes/class.ilMailOptions.php");
2473  $mailOptions = new ilMailOptions($usr_id);
2474  $mailOptions->updateOptions(
2475  array_key_exists("mail_signature", $this->prefs) ? $this->prefs["mail_signature"] : $mailOptions->getSignature(),
2476  array_key_exists("mail_linebreak", $this->prefs) ? $this->prefs["mail_linebreak"] : $mailOptions->getLinebreak(),
2477  array_key_exists("mail_incoming_type", $this->prefs) ? $this->prefs["mail_incoming_type"] : $mailOptions->getIncomingType(),
2478  $mailOptions->getCronjobNotification()
2479  );
2480  }
2481  }
2482 
2483 }
2484 ?>
$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 UserMail this class handles user mails.
static _lookupExternalAccount($a_user_id)
lookup external account for login and authmethod
$path
Definition: aliased.php:25
setRoleAssignment($a_assign)
set import to local role assignemt
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.
const IL_USER_IMPORT
$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.
"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.
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
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
$ref_id
Definition: sahs_server.php:39
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.
static _checkExternalAuthAccount($a_auth, $a_account)
check whether external account and authentication method matches with a user
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 __extractId($ilias_id, $inst_id)
extract ref id from role title, e.g.
$_POST["username"]
$userCount
The count of user elements in the XML file.
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