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