ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
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  case "radius":
558  case "shibboleth":
559  case "script":
560  case "cas":
561  case "soap":
562  case "openid":
563  // begin-patch auth_plugin
564  default:
565  $this->auth_mode_set = true;
566  $this->userObj->setAuthMode($a_attribs["type"]);
567  break;
568  /*
569  $this->logFailure($this->userObj->getLogin(),
570  sprintf($lng->txt("usrimport_xml_element_inapplicable"),"AuthMode",$a_attribs["type"]));
571  break;
572  *
573  */
574  }
575  }
576  else
577  {
578  $this->logFailure($this->userObj->getLogin(),
579  sprintf($lng->txt("usrimport_xml_element_inapplicable"),"AuthMode",$a_attribs["type"]));
580  }
581  break;
582 
583  case 'UserDefinedField':
584  $this->tmp_udf_id = $a_attribs['Id'];
585  $this->tmp_udf_name = $a_attribs['Name'];
586  break;
587 
588  case 'AccountInfo':
589  $this->current_messenger_type = strtolower($a_attribs["Type"]);
590  break;
591  case 'GMapInfo':
592  $this->userObj->setLatitude($a_attribs["latitude"]);
593  $this->userObj->setLongitude($a_attribs["longitude"]);
594  $this->userObj->setLocationZoom($a_attribs["zoom"]);
595  break;
596  case 'Pref':
597  $this->currentPrefKey = $a_attribs["key"];
598  break;
599  }
600  }
604  function verifyBeginTag($a_xml_parser, $a_name, $a_attribs)
605  {
606  global $lng;
607 
608  switch($a_name)
609  {
610  case "Role":
611  if (is_null($a_attribs['Id'])
612  || $a_attribs['Id'] == "")
613  {
614  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_missing"),"Role","Id"));
615  }
616  $this->current_role_id = $a_attribs["Id"];
617  $this->current_role_type = $a_attribs["Type"];
618  if ($this->current_role_type != 'Global'
619  && $this->current_role_type != 'Local')
620  {
621  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_missing"),"Role","Type"));
622  }
623  $this->current_role_action = (is_null($a_attribs["Action"])) ? "Assign" : $a_attribs["Action"];
624  if ($this->current_role_action != "Assign"
625  && $this->current_role_action != "AssignWithParents"
626  && $this->current_role_action != "Detach")
627  {
628  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"Role","Action",$a_attribs["Action"]));
629  }
630  if ($this->action == "Insert"
631  && $this->current_role_action == "Detach")
632  {
633  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_inapplicable"),"Role","Action",$this->current_role_action,$this->action));
634  }
635  if ($this->action == "Delete")
636  {
637  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_inapplicable"),"Role","Delete"));
638  }
639  break;
640 
641  case "User":
642  $this->userCount++;
643  $this->userObj = new ilObjUser();
644  $this->userObj->setLanguage($a_attribs["Language"]);
645  $this->userObj->setImportId($a_attribs["Id"]);
646  $this->currentPrefKey = null;
647  // if we have an object id, store it
648  $this->user_id = -1;
649 
650  if (!is_null($a_attribs["Id"]) && $this->getUserMappingMode() == IL_USER_MAPPING_ID)
651  {
652  if (is_numeric($a_attribs["Id"]))
653  {
654  $this->user_id = $a_attribs["Id"];
655  }
656  elseif ($id = ilUtil::__extractId ($a_attribs["Id"], IL_INST_ID))
657  {
658  $this->user_id = $id;
659  }
660  }
661 
662  $this->action = (is_null($a_attribs["Action"])) ? "Insert" : $a_attribs["Action"];
663  if ($this->action != "Insert"
664  && $this->action != "Update"
665  && $this->action != "Delete")
666  {
667  $this->logFailure($this->userObj->getImportId(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"User","Action",$a_attribs["Action"]));
668  }
669  $this->currPassword = null;
670  $this->currPasswordType = null;
671  $this->currPasswordSalt = null;
672  break;
673 
674  case 'Password':
675  $this->currPasswordType = $a_attribs['Type'];
676  $this->currPasswordSalt = $a_attribs['Salt'];
677  break;
678  case "AuthMode":
679  if (array_key_exists("type", $a_attribs))
680  {
681  switch ($a_attribs["type"])
682  {
683  case "default":
684  case "local":
685  case "ldap":
686  case "radius":
687  case "shibboleth":
688  case "script":
689  case "cas":
690  case "soap":
691  case "openid":
692  // begin-patch auth_plugin
693  default:
694  $this->userObj->setAuthMode($a_attribs["type"]);
695  break;
696  /*
697  default:
698  $this->logFailure($this->userObj->getImportId(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"AuthMode","type",$a_attribs["type"]));
699  break;
700  *
701  */
702  }
703  }
704  else
705  {
706  $this->logFailure($this->userObj->getImportId(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"AuthMode","type",""));
707  }
708  break;
709  case 'Pref':
710  $this->currentPrefKey = $a_attribs["key"];
711  break;
712 
713  }
714  }
715 
719  function handlerEndTag($a_xml_parser, $a_name)
720  {
721  switch ($this->mode)
722  {
723  case IL_EXTRACT_ROLES :
724  $this->extractRolesEndTag($a_xml_parser, $a_name);
725  break;
726  case IL_USER_IMPORT :
727  $this->importEndTag($a_xml_parser, $a_name);
728  break;
729  case IL_VERIFY :
730  $this->verifyEndTag($a_xml_parser, $a_name);
731  break;
732  }
733  }
734 
738  function extractRolesEndTag($a_xml_parser, $a_name)
739  {
740  switch($a_name)
741  {
742  case "Role":
743  $this->roles[$this->current_role_id]["name"] = $this->cdata;
744  $this->roles[$this->current_role_id]["type"] =
745  $this->current_role_type;
746  break;
747  }
748  }
749 
753  function getRoleObject($a_role_id)
754  {
755  if (array_key_exists($a_role_id, $this->localRoleCache))
756  {
757  return $this->localRoleCache[$a_role_id];
758  }
759  else
760  {
761  $role_obj = new ilObjRole($a_role_id, false);
762  $role_obj->read();
763  $this->localRoleCache[$a_role_id] = $role_obj;
764  return $role_obj;
765  }
766 
767  }
771  function getCourseMembersObjectForRole($a_role_id)
772  {
773  global $rbacreview, $rbacadmin, $tree;
774 
775  if (array_key_exists($a_role_id.'_courseMembersObject', $this->localRoleCache))
776  {
777  return $this->localRoleCache[$a_role_id.'_courseMembersObject'];
778  }
779  else
780  {
781  require_once("Modules/Course/classes/class.ilObjCourse.php");
782  require_once("Modules/Course/classes/class.ilCourseParticipants.php");
783  $course_refs = $rbacreview->getFoldersAssignedToRole($a_role_id, true);
784  $course_ref = $course_refs[0];
785  $course_obj = new ilObjCourse($course_ref, true);
786  $crsmembers_obj = ilCourseParticipants::_getInstanceByObjId($course_obj->getId());
787  $this->localRoleCache[$a_role_id.'_courseMembersObject'] = $crsmembers_obj;
788  return $crsmembers_obj;
789  }
790 
791  }
792 
796  function assignToRole($a_user_obj, $a_role_id)
797  {
798  require_once "./Services/AccessControl/classes/class.ilObjRole.php";
799  include_once('./Services/Object/classes/class.ilObject.php');
800  #require_once "Modules/Course/classes/class.ilObjCourse.php";
801  #require_once "Modules/Course/classes/class.ilCourseParticipants.php";
802 
803  global $rbacreview, $rbacadmin, $tree;
804 
805  // Do nothing, if the user is already assigned to the role.
806  // Specifically, we do not want to put a course object or
807  // group object on the personal desktop again, if a user
808  // has removed it from the personal desktop.
809  if ($rbacreview->isAssigned($a_user_obj->getId(), $a_role_id))
810  {
811  return;
812  }
813 
814  // If it is a course role, use the ilCourseMember object to assign
815  // the user to the role
816 
817  $rbacadmin->assignUser($a_role_id, $a_user_obj->getId(), true);
818  $obj_id = $rbacreview->getObjectOfRole($a_role_id);
819  switch($type = ilObject::_lookupType($obj_id))
820  {
821  case 'grp':
822  case 'crs':
823  $ref_ids = ilObject::_getAllReferences($obj_id);
824  $ref_id = current((array) $ref_ids);
825  if($ref_id)
826  {
827  ilObjUser::_addDesktopItem($a_user_obj->getId(),$ref_id,$type);
828  }
829  break;
830  default:
831  break;
832  }
833  }
838  function getParentRoleIds($a_role_id)
839  {
840  global $rbacreview;
841 
842  if (! array_key_exists($a_role_id, $this->parentRolesCache))
843  {
844  $parent_role_ids = array();
845 
846  $role_obj = $this->getRoleObject($a_role_id);
847  $short_role_title = substr($role_obj->getTitle(),0,12);
848  $folders = $rbacreview->getFoldersAssignedToRole($a_role_id, true);
849  if (count($folders) > 0)
850  {
851  $all_parent_role_ids = $rbacreview->getParentRoleIds($folders[0]);
852  foreach ($all_parent_role_ids as $parent_role_id => $parent_role_data)
853  {
854  if ($parent_role_id != $a_role_id)
855  {
856  switch (substr($parent_role_data['title'],0,12))
857  {
858  case 'il_crs_admin' :
859  case 'il_grp_admin' :
860  if ($short_role_title == 'il_crs_admin' || $short_role_title == 'il_grp_admin')
861  {
862  $parent_role_ids[] = $parent_role_id;
863  }
864  break;
865  case 'il_crs_tutor' :
866  case 'il_grp_tutor' :
867  if ($short_role_title == 'il_crs_tutor' || $short_role_title == 'il_grp_tutor')
868  {
869  $parent_role_ids[] = $parent_role_id;
870  }
871  break;
872  case 'il_crs_membe' :
873  case 'il_grp_membe' :
874  if ($short_role_title == 'il_crs_membe' || $short_role_title == 'il_grp_membe')
875  {
876  $parent_role_ids[] = $parent_role_id;
877  }
878  break;
879  default :
880  break;
881  }
882  }
883  }
884  }
885  $this->parentRolesCache[$a_role_id] = $parent_role_ids;
886  }
887  return $this->parentRolesCache[$a_role_id];
888  }
892  function assignToRoleWithParents($a_user_obj, $a_role_id)
893  {
894  $this->assignToRole($a_user_obj, $a_role_id);
895 
896  $parent_role_ids = $this->getParentRoleIds($a_role_id);
897  foreach ($parent_role_ids as $parent_role_id)
898  {
899  $this->assignToRole($a_user_obj, $parent_role_id);
900  }
901  }
905  function detachFromRole($a_user_obj, $a_role_id)
906  {
907  global $rbacreview, $rbacadmin, $tree;
908 
909  $rbacadmin->deassignUser($a_role_id, $a_user_obj->getId());
910 
911  if (substr(ilObject::_lookupTitle($a_role_id),0,6) == 'il_crs' or
912  substr(ilObject::_lookupTitle($a_role_id),0,6) == 'il_grp')
913  {
914  $obj = $rbacreview->getObjectOfRole($a_role_id);
915  $ref = ilObject::_getAllReferences($obj);
916  $ref_id = end($ref);
917  ilObjUser::_dropDesktopItem($a_user_obj->getId(), $ref_id, ilObject::_lookupType($obj));
918  }
919 }
920 
924  function importEndTag($a_xml_parser, $a_name)
925  {
926  global $ilias, $rbacadmin, $rbacreview, $ilUser, $lng, $ilSetting;
927 
928  switch($a_name)
929  {
930  case "Role":
931  $this->roles[$this->current_role_id]["name"] = $this->cdata;
932  $this->roles[$this->current_role_id]["type"] = $this->current_role_type;
933  $this->roles[$this->current_role_id]["action"] = $this->current_role_action;
934  break;
935 
936  case "PersonalPicture":
937  switch ($this->personalPicture["encoding"])
938  {
939  case "Base64":
940  $this->personalPicture["content"] = base64_decode($this->cdata);
941  break;
942  case "UUEncode":
943  // this only works with PHP >= 5
944  if (version_compare(PHP_VERSION,'5','>='))
945  {
946  $this->personalPicture["content"] = convert_uudecode($this->cdata);
947  }
948  break;
949  }
950  break;
951 
952  case "User":
953  $this->userObj->setFullname();
954  // Fetch the user_id from the database, if we didn't have it in xml file
955  // fetch as well, if we are trying to insert -> recognize duplicates!
956  if ($this->user_id == -1 || $this->action=="Insert")
957  $user_id = ilObjUser::getUserIdByLogin($this->userObj->getLogin());
958  else
959  $user_id = $this->user_id;
960 
961  //echo $user_id.":".$this->userObj->getLogin();
962 
963  // Handle conflicts
964  switch ($this->conflict_rule)
965  {
966  case IL_FAIL_ON_CONFLICT :
967  // do not change action
968  break;
969  case IL_UPDATE_ON_CONFLICT :
970  switch ($this->action)
971  {
972  case "Insert" :
973  if ($user_id)
974  {
975  $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_replaced"),"Insert","Update"));
976  $this->action = "Update";
977  }
978  break;
979  case "Update" :
980  if (! $user_id)
981  {
982  $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_replaced"),"Update","Insert"));
983  $this->action = "Insert";
984  }
985  break;
986  case "Delete" :
987  if (! $user_id)
988  {
989  $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_ignored"),"Delete"));
990  $this->action = "Ignore";
991  }
992  break;
993  }
994  break;
995  case IL_IGNORE_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_ignored"),"Insert"));
1002  $this->action = "Ignore";
1003  }
1004  break;
1005  case "Update" :
1006  if (! $user_id)
1007  {
1008  $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_ignored"),"Update"));
1009  $this->action = "Ignore";
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  }
1022 
1023  // check external account conflict (if external account is already used)
1024  // note: we cannot apply conflict rules in the same manner as to logins here
1025  // so we ignore records with already existing external accounts.
1026  //echo $this->userObj->getAuthMode().'h';
1027  $am = ($this->userObj->getAuthMode() == "default" || $this->userObj->getAuthMode() == "")
1028  ? ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode'))
1029  : $this->userObj->getAuthMode();
1030  $loginForExternalAccount = ($this->userObj->getExternalAccount() == "")
1031  ? ""
1032  : ilObjUser::_checkExternalAuthAccount($am, $this->userObj->getExternalAccount());
1033  switch ($this->action)
1034  {
1035  case "Insert" :
1036  if ($loginForExternalAccount != "")
1037  {
1038  $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_no_insert_ext_account_exists")." (".$this->userObj->getExternalAccount().")");
1039  $this->action = "Ignore";
1040  }
1041  break;
1042 
1043  case "Update" :
1044  // this variable describes the ILIAS login which belongs to the given external account!!!
1045  // it is NOT nescessarily the ILIAS login of the current user record !!
1046  // so if we found an ILIAS login according to the authentication method
1047  // check if the ILIAS login belongs to the current user record, otherwise somebody else is using it!
1048  if ($loginForExternalAccount != "")
1049  {
1050  // check if we changed the value!
1051  $externalAccountHasChanged = $this->userObj->getExternalAccount() != ilObjUser::_lookupExternalAccount($this->user_id);
1052  // if it has changed and the external login
1053  if ($externalAccountHasChanged && trim($loginForExternalAccount) != trim($this->userObj->getLogin()))
1054  {
1055  $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_no_update_ext_account_exists")." (".$this->userObj->getExternalAccount().")");
1056  $this->action = "Ignore";
1057  }
1058  }
1059  break;
1060  }
1061 
1062  if(sizeof($this->multi_values))
1063  {
1064  if(isset($this->multi_values["GeneralInterest"]))
1065  {
1066  $this->userObj->setGeneralInterests($this->multi_values["GeneralInterest"]);
1067  }
1068  if(isset($this->multi_values["OfferingHelp"]))
1069  {
1070  $this->userObj->setOfferingHelp($this->multi_values["OfferingHelp"]);
1071  }
1072  if(isset($this->multi_values["LookingForHelp"]))
1073  {
1074  $this->userObj->setLookingForHelp($this->multi_values["LookingForHelp"]);
1075  }
1076  }
1077 
1078  // Perform the action
1079  switch ($this->action)
1080  {
1081  case "Insert" :
1082  if ($user_id)
1083  {
1084  $this->logFailure($this->userObj->getLogin(),$lng->txt("usrimport_cant_insert"));
1085  }
1086  else
1087  {
1088 
1089  if(!strlen($this->currPassword) == 0)
1090  {
1091  switch($this->currPasswordType)
1092  {
1093  case "BCRYPT":
1094  if(!strlen($this->currPasswordSalt))
1095  {
1096  $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_xml_pw_bcrypt_missing_salt"));
1097  }
1098  $this->userObj->setPasswd($this->currPassword, IL_PASSWD_CRYPTED);
1099  $this->userObj->setPasswordEncodingType('bcrypt');
1100  $this->userObj->setPasswordSalt($this->currPasswordSalt);
1101  break;
1102 
1103  case "PLAIN":
1104  $this->userObj->setPasswd($this->currPassword, IL_PASSWD_PLAIN);
1105  $this->acc_mail->setUserPassword($this->currPassword);
1106  break;
1107 
1108  }
1109  }
1110  else
1111  {
1112  // this does the trick for empty passwords
1113  // since a MD5 string has always 32 characters,
1114  // no hashed password combination will ever equal to
1115  // an empty string
1116  $this->userObj->setPasswd("", IL_PASSWD_CRYPTED);
1117 
1118  }
1119 
1120  $this->userObj->setTitle($this->userObj->getFullname());
1121  $this->userObj->setDescription($this->userObj->getEmail());
1122 
1123  if(!$this->time_limit_owner_set)
1124  {
1125  $this->userObj->setTimeLimitOwner($this->getFolderId());
1126  }
1127 
1128  // default time limit settings
1129  if(!$this->time_limit_set)
1130  {
1131  $this->userObj->setTimeLimitUnlimited(1);
1132  $this->userObj->setTimeLimitMessage(0);
1133 
1134  if (! $this->approve_date_set)
1135  {
1136  $this->userObj->setApproveDate(date("Y-m-d H:i:s"));
1137  }
1138  }
1139 
1140 
1141  $this->userObj->setActive($this->currActive == 'true' || is_null($this->currActive));
1142 
1143  // Finally before saving new user.
1144  // Check if profile is incomplete
1145 
1146  // #8759
1147  if(count($this->udf_data))
1148  {
1149  $this->userObj->setUserDefinedData($this->udf_data);
1150  }
1151 
1152  $this->userObj->setProfileIncomplete($this->checkProfileIncomplete($this->userObj));
1153  $this->userObj->create();
1154 
1155  //insert user data in table user_data
1156  $this->userObj->saveAsNew(false);
1157 
1158  // Set default prefs
1159  $this->userObj->setPref('hits_per_page',$ilSetting->get('hits_per_page',30));
1160  $this->userObj->setPref('show_users_online',$ilSetting->get('show_users_online','y'));
1161 
1162  if (count ($this->prefs))
1163  {
1164  foreach ($this->prefs as $key => $value)
1165  {
1166  if ($key != "mail_incoming_type" &&
1167  $key != "mail_signature" &&
1168  $key != "mail_linebreak"
1169  )
1170  {
1171  $this->userObj->setPref($key, $value);
1172  }
1173  }
1174  }
1175 
1176  $this->userObj->writePrefs();
1177 
1178  // update mail preferences, to be extended
1179  $this->updateMailPreferences($this->userObj->getId());
1180 
1181  if (is_array($this->personalPicture))
1182  {
1183  if (strlen($this->personalPicture["content"]))
1184  {
1185  $extension = "jpg";
1186  if (preg_match("/.*(png|jpg|gif|jpeg)$/", $this->personalPicture["imagetype"], $matches))
1187  {
1188  $extension = $matches[1];
1189  }
1190  $tmp_name = $this->saveTempImage($this->personalPicture["content"], ".$extension");
1191  if (strlen($tmp_name))
1192  {
1193  ilObjUser::_uploadPersonalPicture($tmp_name, $this->userObj->getId());
1194  unlink($tmp_name);
1195  }
1196  }
1197  }
1198 
1199  //set role entries
1200  foreach($this->roles as $role_id => $role)
1201  {
1202  if ($this->role_assign[$role_id])
1203  {
1204  $this->assignToRole($this->userObj, $this->role_assign[$role_id]);
1205  }
1206  }
1207 
1208  if(count($this->udf_data))
1209  {
1210  include_once './Services/User/classes/class.ilUserDefinedData.php';
1211  $udd = new ilUserDefinedData($this->userObj->getId());
1212  foreach($this->udf_data as $field => $value)
1213  {
1214  $udd->set("f_".$field,$value);
1215  }
1216  $udd->update();
1217  }
1218 
1219  $this->sendAccountMail();
1220  $this->logSuccess($this->userObj->getLogin(),$this->userObj->getId(), "Insert");
1221  // reset account mail object
1222  $this->acc_mail->reset();
1223  }
1224  break;
1225 
1226  case "Update" :
1227  if (! $user_id)
1228  {
1229  $this->logFailure($this->userObj->getLogin(),$lng->txt("usrimport_cant_update"));
1230  }
1231  else
1232  {
1233  $updateUser = new ilObjUser($user_id);
1234  $updateUser->read();
1235  $updateUser->readPrefs();
1236  if ($this->currPassword != null)
1237  {
1238  switch ($this->currPasswordType)
1239  {
1240  case "BCRYPT":
1241  if(!strlen($this->currPasswordSalt))
1242  {
1243  $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_xml_pw_bcrypt_missing_salt"));
1244  }
1245  $updateUser->setPasswd($this->currPassword, IL_PASSWD_CRYPTED);
1246  $updateUser->setPasswordEncodingType('bcrypt');
1247  $updateUser->setPasswordSalt($this->currPasswordSalt);
1248  break;
1249 
1250  case "PLAIN":
1251  $updateUser->setPasswd($this->currPassword, IL_PASSWD_PLAIN);
1252  $this->acc_mail->setUserPassword($this->currPassword);
1253  break;
1254  }
1255  }
1256  if (! is_null($this->userObj->getFirstname())) $updateUser->setFirstname($this->userObj->getFirstname());
1257  if (! is_null($this->userObj->getLastname())) $updateUser->setLastname($this->userObj->getLastname());
1258  if (! is_null($this->userObj->getUTitle())) $updateUser->setUTitle($this->userObj->getUTitle());
1259  if (! is_null($this->userObj->getGender())) $updateUser->setGender($this->userObj->getGender());
1260  if (! is_null($this->userObj->getEmail())) $updateUser->setEmail($this->userObj->getEmail());
1261  if (! is_null($this->userObj->getBirthday())) $updateUser->setBirthday($this->userObj->getBirthday());
1262  if (! is_null($this->userObj->getInstitution())) $updateUser->setInstitution($this->userObj->getInstitution());
1263  if (! is_null($this->userObj->getStreet())) $updateUser->setStreet($this->userObj->getStreet());
1264  if (! is_null($this->userObj->getCity())) $updateUser->setCity($this->userObj->getCity());
1265  if (! is_null($this->userObj->getZipCode())) $updateUser->setZipCode($this->userObj->getZipCode());
1266  if (! is_null($this->userObj->getCountry())) $updateUser->setCountry($this->userObj->getCountry());
1267  if (! is_null($this->userObj->getPhoneOffice())) $updateUser->setPhoneOffice($this->userObj->getPhoneOffice());
1268  if (! is_null($this->userObj->getPhoneHome())) $updateUser->setPhoneHome($this->userObj->getPhoneHome());
1269  if (! is_null($this->userObj->getPhoneMobile())) $updateUser->setPhoneMobile($this->userObj->getPhoneMobile());
1270  if (! is_null($this->userObj->getFax())) $updateUser->setFax($this->userObj->getFax());
1271  if (! is_null($this->userObj->getHobby())) $updateUser->setHobby($this->userObj->getHobby());
1272  if (! is_null($this->userObj->getGeneralInterests())) $updateUser->setGeneralInterests($this->userObj->getGeneralInterests());
1273  if (! is_null($this->userObj->getOfferingHelp())) $updateUser->setOfferingHelp($this->userObj->getOfferingHelp());
1274  if (! is_null($this->userObj->getLookingForHelp())) $updateUser->setLookingForHelp($this->userObj->getLookingForHelp());
1275  if (! is_null($this->userObj->getComment())) $updateUser->setComment($this->userObj->getComment());
1276  if (! is_null($this->userObj->getDepartment())) $updateUser->setDepartment($this->userObj->getDepartment());
1277  if (! is_null($this->userObj->getMatriculation())) $updateUser->setMatriculation($this->userObj->getMatriculation());
1278  if (! is_null($this->currActive)) $updateUser->setActive($this->currActive == "true", is_object($ilUser) ? $ilUser->getId() : 0);
1279  if (! is_null($this->userObj->getClientIP())) $updateUser->setClientIP($this->userObj->getClientIP());
1280  if (! is_null($this->userObj->getTimeLimitUnlimited())) $updateUser->setTimeLimitUnlimited($this->userObj->getTimeLimitUnlimited());
1281  if (! is_null($this->userObj->getTimeLimitFrom())) $updateUser->setTimeLimitFrom($this->userObj->getTimeLimitFrom());
1282  if (! is_null($this->userObj->getTimeLimitUntil())) $updateUser->setTimeLimitUntil($this->userObj->getTimeLimitUntil());
1283  if (! is_null($this->userObj->getTimeLimitMessage())) $updateUser->setTimeLimitMessage($this->userObj->getTimeLimitMessage());
1284  if (! is_null($this->userObj->getApproveDate())) $updateUser->setApproveDate($this->userObj->getApproveDate());
1285  if (! is_null($this->userObj->getAgreeDate())) $updateUser->setAgreeDate($this->userObj->getAgreeDate());
1286  if (! is_null($this->userObj->getLanguage())) $updateUser->setLanguage($this->userObj->getLanguage());
1287  if (! is_null($this->userObj->getExternalAccount())) $updateUser->setExternalAccount($this->userObj->getExternalAccount());
1288 
1289  // Fixed: if auth_mode is not set, it was always overwritten with auth_default
1290  #if (! is_null($this->userObj->getAuthMode())) $updateUser->setAuthMode($this->userObj->getAuthMode());
1291  if($this->auth_mode_set)
1292  $updateUser->setAuthMode($this->userObj->getAuthMode());
1293 
1294  if (! is_null($this->userObj->getInstantMessengerId("aim"))) $updateUser->setInstantMessengerId("aim", $this->userObj->getInstantMessengerId("aim"));
1295  if (! is_null($this->userObj->getInstantMessengerId("msn"))) $updateUser->setInstantMessengerId("msn", $this->userObj->getInstantMessengerId("msn"));
1296  if (! is_null($this->userObj->getInstantMessengerId("icq"))) $updateUser->setInstantMessengerId("icq", $this->userObj->getInstantMessengerId("icq"));
1297  if (! is_null($this->userObj->getInstantMessengerId("yahoo"))) $updateUser->setInstantMessengerId("yahoo", $this->userObj->getInstantMessengerId("yahoo"));
1298  if (! is_null($this->userObj->getInstantMessengerId("skype"))) $updateUser->setInstantMessengerId("skype", $this->userObj->getInstantMessengerId("skype"));
1299  if (! is_null($this->userObj->getInstantMessengerId("jabber"))) $updateUser->setInstantMessengerId("jabber", $this->userObj->getInstantMessengerId("jabber"));
1300  if (! is_null($this->userObj->getInstantMessengerId("voip"))) $updateUser->setInstantMessengerId("voip", $this->userObj->getInstantMessengerId("voip"));
1301 
1302  // Special handlin since it defaults to 7 (USER_FOLDER_ID)
1303  if($this->time_limit_owner_set)
1304  {
1305  $updateUser->setTimeLimitOwner($this->userObj->getTimeLimitOwner());
1306  }
1307 
1308 
1309  if (count ($this->prefs))
1310  {
1311  foreach ($this->prefs as $key => $value)
1312  {
1313  if ($key != "mail_incoming_type" &&
1314  $key != "mail_signature" &&
1315  $key != "mail_linebreak"
1316  ){
1317  $updateUser->setPref($key, $value);
1318  }
1319  }
1320  }
1321 
1322  // save user preferences (skin and style)
1323  if ($this->updateLookAndSkin)
1324  {
1325  $updateUser->setPref("skin", $this->userObj->getPref("skin"));
1326  $updateUser->setPref("style", $this->userObj->getPref("style"));
1327  }
1328 
1329 
1330  $updateUser->writePrefs();
1331 
1332  // update mail preferences, to be extended
1333  $this->updateMailPreferences($updateUser->getId());
1334 
1335  // #8759
1336  if(count($this->udf_data))
1337  {
1338  $updateUser->setUserDefinedData($this->udf_data);
1339  }
1340 
1341  $updateUser->setProfileIncomplete($this->checkProfileIncomplete($updateUser));
1342 
1343  $updateUser->setTitle($updateUser->getFullname());
1344  $updateUser->setDescription($updateUser->getEmail());
1345  $updateUser->update();
1346 
1347  if(count($this->udf_data))
1348  {
1349  include_once './Services/User/classes/class.ilUserDefinedData.php';
1350  $udd = new ilUserDefinedData($updateUser->getId());
1351  foreach($this->udf_data as $field => $value)
1352  {
1353  $udd->set("f_".$field,$value);
1354  }
1355  $udd->update();
1356  }
1357 
1358  // update login
1359  if (!is_null($this->userObj->getLogin()) && $this->user_id != -1)
1360  {
1361  try
1362  {
1363  $updateUser->updateLogin($this->userObj->getLogin());
1364  }
1365  catch (ilUserException $e)
1366  {
1367  }
1368  }
1369 
1370 
1371  // if language has changed
1372 
1373  if (is_array($this->personalPicture))
1374  {
1375  if (strlen($this->personalPicture["content"]))
1376  {
1377  $extension = "jpg";
1378  if (preg_match("/.*(png|jpg|gif|jpeg)$/", $this->personalPicture["imagetype"], $matches))
1379  {
1380  $extension = $matches[1];
1381  }
1382  $tmp_name = $this->saveTempImage($this->personalPicture["content"], ".$extension");
1383  if (strlen($tmp_name))
1384  {
1385  ilObjUser::_uploadPersonalPicture($tmp_name, $this->userObj->getId());
1386  unlink($tmp_name);
1387  }
1388  }
1389  }
1390 
1391 
1392  //update role entries
1393  //-------------------
1394  foreach ($this->roles as $role_id => $role)
1395  {
1396  if ($this->role_assign[$role_id])
1397  {
1398  switch ($role["action"])
1399  {
1400  case "Assign" :
1401  $this->assignToRole($updateUser, $this->role_assign[$role_id]);
1402  break;
1403  case "AssignWithParents" :
1404  $this->assignToRoleWithParents($updateUser, $this->role_assign[$role_id]);
1405  break;
1406  case "Detach" :
1407  $this->detachFromRole($updateUser, $this->role_assign[$role_id]);
1408  break;
1409  }
1410  }
1411  }
1412  $this->logSuccess($updateUser->getLogin(), $user_id, "Update");
1413  }
1414  break;
1415  case "Delete" :
1416  if (! $user_id)
1417  {
1418  $this->logFailure($this->userObj->getLogin(),$lng->txt("usrimport_cant_delete"));
1419  }
1420  else
1421  {
1422  $deleteUser = new ilObjUser($user_id);
1423  $deleteUser->delete();
1424 
1425  $this->logSuccess($this->userObj->getLogin(),$user_id, "Delete");
1426  }
1427  break;
1428  }
1429 
1430  // init role array for next user
1431  $this->roles = array();
1432  break;
1433 
1434  case "Login":
1435  $this->userObj->setLogin($this->cdata);
1436  break;
1437 
1438  case "Password":
1439  $this->currPassword = $this->cdata;
1440  break;
1441 
1442  case "Firstname":
1443  $this->userObj->setFirstname($this->cdata);
1444  break;
1445 
1446  case "Lastname":
1447  $this->userObj->setLastname($this->cdata);
1448  break;
1449 
1450  case "Title":
1451  $this->userObj->setUTitle($this->cdata);
1452  break;
1453 
1454  case "Gender":
1455  $this->userObj->setGender($this->cdata);
1456  break;
1457 
1458  case "Email":
1459  $this->userObj->setEmail($this->cdata);
1460  break;
1461 
1462  case "Birthday":
1463  $timestamp = strtotime($this->cdata);
1464  if ($timestamp !== false)
1465  {
1466  $this->userObj->setBirthday($this->cdata);
1467  }
1468  break;
1469  case "Institution":
1470  $this->userObj->setInstitution($this->cdata);
1471  break;
1472 
1473  case "Street":
1474  $this->userObj->setStreet($this->cdata);
1475  break;
1476 
1477  case "City":
1478  $this->userObj->setCity($this->cdata);
1479  break;
1480 
1481  case "PostalCode":
1482  $this->userObj->setZipCode($this->cdata);
1483  break;
1484 
1485  case "Country":
1486  $this->userObj->setCountry($this->cdata);
1487  break;
1488 
1489  case "PhoneOffice":
1490  $this->userObj->setPhoneOffice($this->cdata);
1491  break;
1492 
1493  case "PhoneHome":
1494  $this->userObj->setPhoneHome($this->cdata);
1495  break;
1496 
1497  case "PhoneMobile":
1498  $this->userObj->setPhoneMobile($this->cdata);
1499  break;
1500 
1501  case "Fax":
1502  $this->userObj->setFax($this->cdata);
1503  break;
1504 
1505  case "Hobby":
1506  $this->userObj->setHobby($this->cdata);
1507  break;
1508 
1509  case "GeneralInterest":
1510  case "OfferingHelp":
1511  case "LookingForHelp":
1512  $this->multi_values[$a_name][] = $this->cdata;
1513  break;
1514 
1515  case "Comment":
1516  $this->userObj->setComment($this->cdata);
1517  break;
1518 
1519  case "Department":
1520  $this->userObj->setDepartment($this->cdata);
1521  break;
1522 
1523  case "Matriculation":
1524  $this->userObj->setMatriculation($this->cdata);
1525  break;
1526 
1527  case "Active":
1528  $this->currActive = $this->cdata;
1529  break;
1530 
1531  case "ClientIP":
1532  $this->userObj->setClientIP($this->cdata);
1533  break;
1534 
1535  case "TimeLimitOwner":
1536  $this->time_limit_owner_set = true;
1537  $this->userObj->setTimeLimitOwner($this->cdata);
1538  break;
1539 
1540  case "TimeLimitUnlimited":
1541  $this->time_limit_set = true;
1542  $this->userObj->setTimeLimitUnlimited($this->cdata);
1543  break;
1544 
1545  case "TimeLimitFrom":
1546  if (is_numeric($this->cdata))
1547  {
1548  // Treat cdata as a unix timestamp
1549  $this->userObj->setTimeLimitFrom($this->cdata);
1550  }
1551  else
1552  {
1553  // Try to convert cdata into unix timestamp, or ignore it
1554  $timestamp = strtotime($this->cdata);
1555  if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00")
1556  {
1557  $this->userObj->setTimeLimitFrom($timestamp);
1558  }
1559  elseif ($this->cdata == "0000-00-00 00:00:00")
1560  {
1561  $this->userObj->setTimeLimitFrom(null);
1562  }
1563 
1564  }
1565  break;
1566 
1567  case "TimeLimitUntil":
1568  if (is_numeric($this->cdata))
1569  {
1570  // Treat cdata as a unix timestamp
1571  $this->userObj->setTimeLimitUntil($this->cdata);
1572  }
1573  else
1574  {
1575  // Try to convert cdata into unix timestamp, or ignore it
1576  $timestamp = strtotime($this->cdata);
1577  if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00")
1578  {
1579  $this->userObj->setTimeLimitUntil($timestamp);
1580  }
1581  elseif ($this->cdata == "0000-00-00 00:00:00")
1582  {
1583  $this->userObj->setTimeLimitUntil(null);
1584  }
1585  }
1586  break;
1587 
1588  case "TimeLimitMessage":
1589  $this->userObj->setTimeLimitMessage($this->cdata);
1590  break;
1591 
1592  case "ApproveDate":
1593  $this->approve_date_set = true;
1594  if (is_numeric($this->cdata))
1595  {
1596  // Treat cdata as a unix timestamp
1597  $tmp_date = new ilDateTime($this->cdata,IL_CAL_UNIX);
1598  $this->userObj->setApproveDate($tmp_date->get(IL_CAL_DATETIME));
1599  }
1600  else
1601  {
1602  // Try to convert cdata into unix timestamp, or ignore it
1603  $timestamp = strtotime($this->cdata);
1604  if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00")
1605  {
1606  $tmp_date = new ilDateTime($timestamp,IL_CAL_UNIX);
1607  $this->userObj->setApproveDate($tmp_date->get(IL_CAL_DATETIME));
1608  }
1609  elseif ($this->cdata == "0000-00-00 00:00:00")
1610  {
1611  $this->userObj->setApproveDate(null);
1612  }
1613  }
1614  break;
1615 
1616  case "AgreeDate":
1617  if (is_numeric($this->cdata))
1618  {
1619  // Treat cdata as a unix timestamp
1620  $tmp_date = new ilDateTime($this->cdata,IL_CAL_UNIX);
1621  $this->userObj->setAgreeDate($tmp_date->get(IL_CAL_DATETIME));
1622  }
1623  else
1624  {
1625  // Try to convert cdata into unix timestamp, or ignore it
1626  $timestamp = strtotime($this->cdata);
1627  if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00")
1628  {
1629  $tmp_date = new ilDateTime($timestamp,IL_CAL_UNIX);
1630  $this->userObj->setAgreeDate($tmp_date->get(IL_CAL_DATETIME));
1631  }
1632  elseif ($this->cdata == "0000-00-00 00:00:00")
1633  {
1634  $this->userObj->setAgreeDate(null);
1635  }
1636  }
1637  break;
1638 
1639  case "ExternalAccount":
1640  $this->userObj->setExternalAccount($this->cdata);
1641  break;
1642 
1643  case "Look":
1644  $this->updateLookAndSkin = false;
1645  if (!$this->hideSkin)
1646  {
1647  // TODO: what to do with disabled skins? is it possible to change the skin via import?
1648  if ((strlen($this->skin) > 0) && (strlen($this->style) > 0))
1649  {
1650  if (is_array($this->userStyles))
1651  {
1652  if (in_array($this->skin . ":" . $this->style, $this->userStyles))
1653  {
1654  $this->userObj->setPref("skin", $this->skin);
1655  $this->userObj->setPref("style", $this->style);
1656  $this->updateLookAndSkin = true;
1657  }
1658  }
1659  }
1660  }
1661  break;
1662 
1663  case 'UserDefinedField':
1664  include_once './Services/User/classes/class.ilUserDefinedFields.php';
1666  if($field_id = $udf->fetchFieldIdFromImportId($this->tmp_udf_id))
1667  {
1668  $this->udf_data[$field_id] = $this->cdata;
1669  }
1670  elseif($field_id = $udf->fetchFieldIdFromName($this->tmp_udf_name))
1671  {
1672  $this->udf_data[$field_id] = $this->cdata;
1673  }
1674  break;
1675  case 'AccountInfo':
1676  if ($this->current_messenger_type =="delicious")
1677  {
1678  $this->userObj->setDelicious($this->cdata);
1679  }
1680  elseif ($this->current_messenger_type =="external")
1681  {
1682  $this->userObj->setExternalAccount($this->cdata);
1683  }
1684  else
1685  {
1686  $this->userObj->setInstantMessengerId($this->current_messenger_type, $this->cdata);
1687  }
1688  break;
1689  case 'Pref':
1690  if ($this->currentPrefKey != null && strlen(trim($this->cdata)) > 0
1691  && ilUserXMLWriter::isPrefExportable($this->currentPrefKey))
1692  $this->prefs[$this->currentPrefKey] = trim($this->cdata);
1693  $this->currentPrefKey = null;
1694  break;
1695  }
1696  }
1697 
1702  function saveTempImage($image_data, $filename)
1703  {
1704  $tempname = ilUtil::ilTempnam() . $filename;
1705  $fh = fopen($tempname, "wb");
1706  if ($fh == false)
1707  {
1708  return "";
1709  }
1710  $imagefile = fwrite($fh, $image_data);
1711  fclose($fh);
1712  return $tempname;
1713  }
1714 
1718  function verifyEndTag($a_xml_parser, $a_name)
1719  {
1720  global $lng,$ilAccess,$ilSetting,$ilObjDataCache;
1721 
1722  switch($a_name)
1723  {
1724  case "Role":
1725  $this->roles[$this->current_role_id]["name"] = $this->cdata;
1726  $this->roles[$this->current_role_id]["type"] = $this->current_role_type;
1727  $this->roles[$this->current_role_id]["action"] = $this->current_role_action;
1728  break;
1729 
1730  case "User":
1731  $this->userObj->setFullname();
1732  if ($this->user_id != -1 && ($this->action == "Update" || $this->action == "Delete"))
1733  $user_exists = !is_null(ilObjUser::_lookupLogin($this->user_id));
1734  else
1735  $user_exists = ilObjUser::getUserIdByLogin($this->userObj->getLogin()) != 0;
1736 
1737  if (is_null($this->userObj->getLogin()))
1738  {
1739  $this->logFailure("---",sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Login", "Insert"));
1740  }
1741 
1742  switch ($this->action)
1743  {
1744  case "Insert" :
1745  if ($user_exists and $this->conflict_rule == IL_FAIL_ON_CONFLICT)
1746  {
1747  $this->logWarning($this->userObj->getLogin(),$lng->txt("usrimport_cant_insert"));
1748  }
1749  if (is_null($this->userObj->getGender()) && $this->isFieldRequired("gender"))
1750  {
1751  $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Gender", "Insert"));
1752  }
1753  if (is_null($this->userObj->getFirstname()))
1754  {
1755  $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Firstname", "Insert"));
1756  }
1757  if (is_null($this->userObj->getLastname()))
1758  {
1759  $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Lastname", "Insert"));
1760  }
1761  if (count($this->roles) == 0)
1762  {
1763  $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Role", "Insert"));
1764  }
1765  else
1766  {
1767  $has_global_role = false;
1768  foreach ($this->roles as $role)
1769  {
1770  if ($role['type'] == 'Global')
1771  {
1772  $has_global_role = true;
1773  break;
1774  }
1775  }
1776  if (! $has_global_role)
1777  {
1778  $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_global_role_for_action_required"),"Insert"));
1779  }
1780  }
1781  break;
1782  case "Update" :
1783  if(!$user_exists)
1784  {
1785  $this->logWarning($this->userObj->getLogin(),$lng->txt("usrimport_cant_update"));
1786  }
1787  elseif($this->user_id != -1 && !is_null($this->userObj->getLogin()))
1788  // check if someone owns the new login name!
1789  {
1790  $someonesId = ilObjUser::_lookupId($this->userObj->getLogin());
1791 
1792  if (is_numeric($someonesId ) && $someonesId != $this->user_id) {
1793  $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_login_is_not_unique"));
1794  }
1795  }
1796  break;
1797  case "Delete" :
1798  if(!$user_exists)
1799  {
1800  $this->logWarning($this->userObj->getLogin(),$lng->txt("usrimport_cant_delete"));
1801  }
1802  break;
1803  }
1804 
1805  // init role array for next user
1806  $this->roles = array();
1807  break;
1808 
1809  case "Login":
1810  if (array_key_exists($this->cdata, $this->logins))
1811  {
1812  $this->logWarning($this->cdata, $lng->txt("usrimport_login_is_not_unique"));
1813  }
1814  else
1815  {
1816  $this->logins[$this->cdata] = $this->cdata;
1817  }
1818  $this->userObj->setLogin($this->cdata);
1819  break;
1820 
1821  case "Password":
1822  switch ($this->currPasswordType)
1823  {
1824  case "BCRYPT":
1825  if(!strlen($this->currPasswordSalt))
1826  {
1827  $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_xml_pw_bcrypt_missing_salt"));
1828  }
1829  $this->userObj->setPasswd($this->cdata, IL_PASSWD_CRYPTED);
1830  $this->userObj->setPasswordEncodingType('bcrypt');
1831  $this->userObj->setPasswordSalt($this->currPasswordSalt);
1832  break;
1833 
1834  case "PLAIN":
1835  $this->userObj->setPasswd($this->cdata, IL_PASSWD_PLAIN);
1836  $this->acc_mail->setUserPassword($this->currPassword);
1837  break;
1838 
1839  default :
1840  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"Type","Password",$this->currPasswordType));
1841  break;
1842  }
1843  break;
1844 
1845  case "Firstname":
1846  $this->userObj->setFirstname($this->cdata);
1847  break;
1848 
1849  case "Lastname":
1850  $this->userObj->setLastname($this->cdata);
1851  break;
1852 
1853  case "Title":
1854  $this->userObj->setUTitle($this->cdata);
1855  break;
1856 
1857  case "Gender":
1858  if ($this->cdata != "m"
1859  && $this->cdata != "f")
1860  {
1861  $this->logFailure(
1862  $this->userObj->getLogin(),
1863  sprintf($lng->txt("usrimport_xml_element_content_illegal"),"Gender",$this->cdata)
1864  );
1865  }
1866  $this->userObj->setGender($this->cdata);
1867  break;
1868 
1869  case "Email":
1870  $this->userObj->setEmail($this->cdata);
1871  break;
1872 
1873  case "Institution":
1874  $this->userObj->setInstitution($this->cdata);
1875  break;
1876 
1877  case "Street":
1878  $this->userObj->setStreet($this->cdata);
1879  break;
1880 
1881  case "City":
1882  $this->userObj->setCity($this->cdata);
1883  break;
1884 
1885  case "PostalCode":
1886  $this->userObj->setZipCode($this->cdata);
1887  break;
1888 
1889  case "Country":
1890  $this->userObj->setCountry($this->cdata);
1891  break;
1892 
1893  case "PhoneOffice":
1894  $this->userObj->setPhoneOffice($this->cdata);
1895  break;
1896 
1897  case "PhoneHome":
1898  $this->userObj->setPhoneHome($this->cdata);
1899  break;
1900 
1901  case "PhoneMobile":
1902  $this->userObj->setPhoneMobile($this->cdata);
1903  break;
1904 
1905  case "Fax":
1906  $this->userObj->setFax($this->cdata);
1907  break;
1908 
1909  case "Hobby":
1910  $this->userObj->setHobby($this->cdata);
1911  break;
1912 
1913  case "GeneralInterest":
1914  case "OfferingHelp":
1915  case "LookingForHelp":
1916  $this->multi_values[$a_name][] = $this->cdata;
1917  break;
1918 
1919  case "Comment":
1920  $this->userObj->setComment($this->cdata);
1921  break;
1922 
1923  case "Department":
1924  $this->userObj->setDepartment($this->cdata);
1925  break;
1926 
1927  case "Matriculation":
1928  $this->userObj->setMatriculation($this->cdata);
1929  break;
1930 
1931  case "ExternalAccount":
1932 //echo "-".$this->userObj->getAuthMode()."-".$this->userObj->getLogin()."-";
1933  $am = ($this->userObj->getAuthMode() == "default" || $this->userObj->getAuthMode() == "")
1934  ? ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode'))
1935  : $this->userObj->getAuthMode();
1936  $loginForExternalAccount = (trim($this->cdata) == "")
1937  ? ""
1938  : ilObjUser::_checkExternalAuthAccount($am, trim($this->cdata));
1939  switch ($this->action)
1940  {
1941  case "Insert" :
1942  if ($loginForExternalAccount != "")
1943  {
1944  $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_no_insert_ext_account_exists")." (".$this->cdata.")");
1945  }
1946  break;
1947 
1948  case "Update" :
1949  if ($loginForExternalAccount != "")
1950  {
1951  $externalAccountHasChanged = trim($this->cdata) != ilObjUser::_lookupExternalAccount($this->user_id);
1952  if ($externalAccountHasChanged && trim($loginForExternalAccount) != trim($this->userObj->getLogin()))
1953  {
1954  $this->logWarning($this->userObj->getLogin(),
1955  $lng->txt("usrimport_no_update_ext_account_exists")." (".$this->cdata." for ".$loginForExternalAccount.")");
1956  }
1957  }
1958  break;
1959 
1960  }
1961  if ($externalAccountHasChanged)
1962  $this->userObj->setExternalAccount(trim($this->cdata));
1963  break;
1964 
1965  case "Active":
1966  if ($this->cdata != "true"
1967  && $this->cdata != "false")
1968  {
1969  $this->logFailure($this->userObj->getLogin(),
1970  sprintf($lng->txt("usrimport_xml_element_content_illegal"),"Active",$this->cdata));
1971  }
1972  $this->currActive = $this->cdata;
1973  break;
1974  case "TimeLimitOwner":
1975  if (!preg_match("/\d+/", $this->cdata))
1976  {
1977  $this->logFailure($this->userObj->getLogin(),
1978  sprintf($lng->txt("usrimport_xml_element_content_illegal"),"TimeLimitOwner",$this->cdata));
1979  }
1980  elseif(!$ilAccess->checkAccess('cat_administrate_users','',$this->cdata))
1981  {
1982  $this->logFailure($this->userObj->getLogin(),
1983  sprintf($lng->txt("usrimport_xml_element_content_illegal"),"TimeLimitOwner",$this->cdata));
1984  }
1985  elseif($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($this->cdata)) != 'cat' && !(int) $this->cdata == USER_FOLDER_ID)
1986  {
1987  $this->logFailure($this->userObj->getLogin(),
1988  sprintf($lng->txt("usrimport_xml_element_content_illegal"),"TimeLimitOwner",$this->cdata));
1989 
1990  }
1991  $this->userObj->setTimeLimitOwner($this->cdata);
1992  break;
1993  case "TimeLimitUnlimited":
1994  switch (strtolower($this->cdata))
1995  {
1996  case "true":
1997  case "1":
1998  $this->userObj->setTimeLimitUnlimited(1);
1999  break;
2000  case "false":
2001  case "0":
2002  $this->userObj->setTimeLimitUnlimited(0);
2003  break;
2004  default:
2005  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"),"TimeLimitUnlimited",$this->cdata));
2006  break;
2007  }
2008  break;
2009  case "TimeLimitFrom":
2010  // Accept datetime or Unix timestamp
2011  if (strtotime($this->cdata) === false && ! is_numeric($this->cdata))
2012  {
2013  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"),"TimeLimitFrom",$this->cdata));
2014  }
2015  $this->userObj->setTimeLimitFrom($this->cdata);
2016  break;
2017  case "TimeLimitUntil":
2018  // Accept datetime or Unix timestamp
2019  if (strtotime($this->cdata) === false && ! is_numeric($this->cdata))
2020  {
2021  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"),"TimeLimitUntil",$this->cdata));
2022  }
2023  $this->userObj->setTimeLimitUntil($this->cdata);
2024  break;
2025  case "TimeLimitMessage":
2026  switch (strtolower($this->cdata))
2027  {
2028  case "1":
2029  $this->userObj->setTimeLimitMessage(1);
2030  break;
2031  case "0":
2032  $this->userObj->setTimeLimitMessage(0);
2033  break;
2034  default:
2035  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"),"TimeLimitMessage",$this->cdata));
2036  break;
2037  }
2038  break;
2039  case "ApproveDate":
2040  // Accept datetime or Unix timestamp
2041  if (strtotime($this->cdata) === false && ! is_numeric($this->cdata) && !$this->cdata == "0000-00-00 00:00:00")
2042  {
2043  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"),"ApproveDate",$this->cdata));
2044  }
2045  break;
2046  case "AgreeDate":
2047  // Accept datetime or Unix timestamp
2048  if (strtotime($this->cdata) === false && ! is_numeric($this->cdata) && !$this->cdata == "0000-00-00 00:00:00")
2049  {
2050  $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_content_illegal"),"AgreeDate",$this->cdata));
2051  }
2052  break;
2053  case "Pref":
2054  if ($this->currentPrefKey != null)
2055  $this->verifyPref($this->currentPrefKey, $this->cdata);
2056  $this->currentPrefKey == null;
2057  }
2058  }
2059 
2063  function handlerCharacterData($a_xml_parser, $a_data)
2064  {
2065  // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
2066  // TODO: Mit Alex klären, ob das noch benötigt wird $a_data = preg_replace("/\n/","",$a_data);
2067  // TODO: Mit Alex klären, ob das noch benötigt wird $a_data = preg_replace("/\t+/","",$a_data);
2068  if($a_data != "\n") $a_data = preg_replace("/\t+/"," ",$a_data);
2069 
2070  if(strlen($a_data) > 0)
2071  {
2072  $this->cdata .= $a_data;
2073  }
2074  }
2075 
2080  {
2081  return $this->roles;
2082  }
2086  function getUserCount()
2087  {
2088  return $this->userCount;
2089  }
2090 
2097  function logWarning($aLogin, $aMessage)
2098  {
2099  if (! array_key_exists($aLogin, $this->protocol))
2100  {
2101  $this->protocol[$aLogin] = array();
2102  }
2103  if ($aMessage)
2104  {
2105  $this->protocol[$aLogin][] = $aMessage;
2106  }
2107  if ($this->error_level == IL_IMPORT_SUCCESS)
2108  {
2109  $this->error_level = IL_IMPORT_WARNING;
2110  }
2111  }
2118  function logFailure($aLogin, $aMessage)
2119  {
2120  if (! array_key_exists($aLogin, $this->protocol))
2121  {
2122  $this->protocol[$aLogin] = array();
2123  }
2124  if ($aMessage)
2125  {
2126  $this->protocol[$aLogin][] = $aMessage;
2127  }
2128  $this->error_level = IL_IMPORT_FAILURE;
2129  }
2130 
2138  function logSuccess($aLogin, $userid, $action)
2139  {
2140  $this->user_mapping[$userid] = array("login" => $aLogin, "action" => $action, "message" => "successful");
2141  }
2142 
2143 
2152  function getProtocol()
2153  {
2154  return $this->protocol;
2155  }
2159  function getProtocolAsHTML($a_log_title)
2160  {
2161  global $lng;
2162 
2163  $block = new ilTemplate("tpl.usr_import_log_block.html", true, true, "Services/User");
2164  $block->setVariable("TXT_LOG_TITLE", $a_log_title);
2165  $block->setVariable("TXT_MESSAGE_ID", $lng->txt("login"));
2166  $block->setVariable("TXT_MESSAGE_TEXT", $lng->txt("message"));
2167  foreach ($this->getProtocol() as $login => $messages)
2168  {
2169  $block->setCurrentBlock("log_row");
2170  $reason = "";
2171  foreach ($messages as $message)
2172  {
2173  if ($reason == "")
2174  {
2175  $reason = $message;
2176  }
2177  else
2178  {
2179  $reason = $reason."<br>".$message;
2180  }
2181  }
2182  $block->setVariable("MESSAGE_ID", $login);
2183  $block->setVariable("MESSAGE_TEXT", $reason);
2184  $block->parseCurrentBlock();
2185  }
2186  return $block->get();
2187  }
2188 
2192  function isSuccess()
2193  {
2194  return $this->error_level == IL_IMPORT_SUCCESS;
2195  }
2196 
2201  function getErrorLevel()
2202  {
2203  return $this->error_level;
2204  }
2205 
2211  function getUserMapping() {
2212  return $this->user_mapping;
2213  }
2214 
2218  function sendAccountMail()
2219  {
2220  if($_POST["send_mail"] != "" ||
2221  ($this->isSendMail() && $this->userObj->getEmail() != ""))
2222  {
2223  $this->acc_mail->setUser($this->userObj);
2224 
2225  $amail = $this->readAccountMailFromCache($this->userObj->getLanguage());
2226  if($amail["att_file"])
2227  {
2228  include_once "Services/User/classes/class.ilFSStorageUserFolder.php";
2230  $fs->create();
2231  $path = $fs->getAbsolutePath() . "/";
2232 
2233  $this->acc_mail->addAttachment($path . "/" . $amail["lang"], $amail["att_file"]);
2234  }
2235  $this->acc_mail->send();
2236  }
2237  }
2238 
2243  private function readAccountMailFromCache($lang_key)
2244  {
2245  if(!isset(self::$account_mail_cache[$lang_key]))
2246  {
2247  $default_lang_key = $GLOBALS["lng"]->getDefaultLanguage();
2248 
2249  // try individual account mail in user administration
2250  include_once './Services/User/classes/class.ilObjUserFolder.php';
2251 
2252  $amail = ilObjUserFolder::_lookupNewAccountMail($lang_key);
2253 
2254  if (trim($amail["body"]) != "" && trim($amail["subject"]) != "")
2255  {
2256  self::$account_mail_cache[$lang_key] = $amail;
2257  }
2258  else
2259  {
2260  $lang_key = $default_lang_key;
2261  }
2262 
2263  if(!isset(self::$account_mail_cache[$default_lang_key]))
2264  {
2265  $amail = ilObjUserFolder::_lookupNewAccountMail($default_lang_key);
2266  self::$account_mail_cache[$default_lang_key] = $amail;
2267  }
2268  }
2269  return self::$account_mail_cache[$lang_key];
2270  }
2271 
2277  function setSendMail ($value) {
2278  $this->send_mail = $value ? true: false;
2279  }
2280 
2286  function isSendMail () {
2287  return $this->send_mail;
2288  }
2289 
2295  function setUserMappingMode($value)
2296  {
2297  if ($value == IL_USER_MAPPING_ID || $value == IL_USER_MAPPING_LOGIN)
2298  $this->mapping_mode = $value;
2299  else die ("wrong argument using methode setUserMappingMethod in ".__FILE__);
2300  }
2301 
2308  {
2309  return $this->mapping_mode;
2310  }
2311 
2318  private function readRequiredFields()
2319  {
2320  global $ilSetting;
2321 
2322  if(is_array($this->required_fields))
2323  {
2324  return $this->required_fields;
2325  }
2326  foreach($ilSetting->getAll() as $field => $value)
2327  {
2328  if(substr($field,0,8) == 'require_' and $value == 1)
2329  {
2330  $value = substr($field,8);
2331  $this->required_fields[$value] = $value;
2332  }
2333  }
2334  return $this->required_fields ? $this->required_fields : array();
2335  }
2336 
2345  private function checkProfileIncomplete($user_obj)
2346  {
2347  include_once "Services/User/classes/class.ilUserProfile.php";
2348  return ilUserProfile::isProfileIncomplete($user_obj);
2349  }
2350 
2357  protected function isFieldRequired ($fieldname)
2358  {
2359  $requiredFields = $this->readRequiredFields();
2360  $fieldname = strtolower(trim($fieldname));
2361  return array_key_exists($fieldname, $requiredFields);
2362  }
2363 
2364  private function verifyPref ($key, $value) {
2365  switch ($key) {
2366  case 'mail_linebreak':
2367  case 'hits_per_page':
2368  if (!is_numeric($value) || $value < 0)
2369  $this->logFailure("---", "Wrong value '$value': Positiv numeric value expected for preference $key.");
2370  break;
2371  case 'language':
2372  case 'skin':
2373  case 'style':
2374  case 'ilPageEditor_HTMLMode':
2375  case 'ilPageEditor_JavaScript':
2376  case 'ilPageEditor_MediaMode':
2377  case 'tst_javascript':
2378  case 'tst_lastquestiontype':
2379  case 'tst_multiline_answers':
2380  case 'tst_use_previous_answers':
2381  case 'graphicalAnswerSetting':
2382  case 'priv_feed_pass':
2383  $this->logFailure("---", "Preference $key is not supported.");
2384  break;
2385  case 'public_city':
2386  case 'public_country':
2387  case 'public_department':
2388  case 'public_email':
2389  case 'public_fax':
2390  case 'public_hobby':
2391  case 'public_institution':
2392  case 'public_matriculation':
2393  case 'public_phone':
2394  case 'public_phone_home':
2395  case 'public_phone_mobile':
2396  case 'public_phone_office':
2397  case 'public_street':
2398  case 'public_upload':
2399  case 'public_zip':
2400  case 'public_interests_general':
2401  case 'public_interests_help_offered':
2402  case 'public_interests_help_looking':
2403  case 'send_info_mails':
2404  case 'hide_own_online_status':
2405  if (!in_array($value, array('y', 'n')))
2406  $this->logFailure("---", "Wrong value '$value': Value 'y' or 'n' expected for preference $key.");
2407  break;
2408  case 'public_profile':
2409  if (!in_array($value, array('y', 'n', 'g')))
2410  $this->logFailure("---", "Wrong value '$value': Value 'y', 'g' or 'n' expected for preference $key.");
2411  break;
2412  case 'show_users_online':
2413  if (!in_array($value, array('y', 'n', 'associated')))
2414  $this->logFailure("---", "Wrong value '$value': Value 'y' or 'n' or 'associated' expected for preference $key.");
2415  break;
2416  case 'mail_incoming_type':
2417  if (!in_array((int) $value, array("0","1","2")))
2418  $this->logFailure("---", "Wrong value '$value': Value \"0\" (LOCAL),\"1\" (EMAIL) or \"2\" (BOTH) expected for preference $key.");
2419  break;
2420  case 'weekstart':
2421  if (!in_array($value, array ("0","1")))
2422  $this->logFailure("---", "Wrong value '$value': Value \"0\" (Sunday) or \"1\" (Monday) expected for preference $key.");
2423  break;
2424 
2425  case 'mail_signature':
2426  break;
2427  case 'user_tz':
2428  include_once('Services/Calendar/classes/class.ilTimeZone.php');
2429  try {
2430  $tz = ilTimeZone::_getInstance($value);
2431  return true;
2432  } catch (ilTimeZoneException $tze) {
2433  $this->logFailure("---", "Wrong value '$value': Invalid timezone $value detected for preference $key.");
2434  }
2435  break;
2436  default:
2438  $this->logFailure("---", "Preference $key is not supported.");
2439  break;
2440  }
2441  }
2442 
2443  private function updateMailPreferences ($usr_id) {
2444  if (array_key_exists("mail_incoming_type", $this->prefs) ||
2445  array_key_exists("mail_signature", $this->prefs) ||
2446  array_key_exists("mail_linebreak", $this->prefs)
2447  )
2448  {
2449  include_once("Services/Mail/classes/class.ilMailOptions.php");
2450  $mailOptions = new ilMailOptions($usr_id);
2451  $mailOptions->updateOptions(
2452  array_key_exists("mail_signature", $this->prefs) ? $this->prefs["mail_signature"] : $mailOptions->getSignature(),
2453  array_key_exists("mail_linebreak", $this->prefs) ? $this->prefs["mail_linebreak"] : $mailOptions->getLinebreak(),
2454  array_key_exists("mail_incoming_type", $this->prefs) ? $this->prefs["mail_incoming_type"] : $mailOptions->getIncomingType(),
2455  $mailOptions->getCronjobNotification()
2456  );
2457  }
2458  }
2459 
2460 }
2461 ?>
$hideSkin
Indicates if the skins are hidden.
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.
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...
$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.
$GLOBALS['ct_recipient']
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
_lookupLogin($a_user_id)
lookup login
$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.
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
static ilTempnam()
Create a temporary file in an ILIAS writable directory.
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.
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