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