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