/** * Get profile fields (DEPRECATED, use ilUserProfile() instead) * * @return array of fieldnames */ static function &getProfileFields() { include_once "./Services/User/classes/class.ilUserProfile.php"; $up = new ilUserProfile(); $up->skipField("username"); $up->skipField("roles"); $up->skipGroup("preferences"); $fds = $up->getStandardFields(); foreach ($fds as $k => $f) { $profile_fields[] = $k; } return $profile_fields; }
/** * Init personal form */ function initPersonalDataForm() { global $ilSetting, $lng, $ilUser, $styleDefinition, $rbacreview; include_once "Services/Form/classes/class.ilPropertyFormGUI.php"; $this->form = new ilPropertyFormGUI(); $this->form->setFormAction($this->ctrl->getFormAction($this)); // user defined fields $user_defined_data = $ilUser->getUserDefinedData(); foreach ($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition) { if ($definition['field_type'] == UDF_TYPE_TEXT) { $this->input["udf_" . $definition['field_id']] = new ilTextInputGUI($definition['field_name'], "udf_" . $definition['field_id']); $this->input["udf_" . $definition['field_id']]->setMaxLength(255); $this->input["udf_" . $definition['field_id']]->setSize(40); } else { if ($definition['field_type'] == UDF_TYPE_WYSIWYG) { $this->input["udf_" . $definition['field_id']] = new ilTextAreaInputGUI($definition['field_name'], "udf_" . $definition['field_id']); $this->input["udf_" . $definition['field_id']]->setUseRte(true); } else { $options = $this->user_defined_fields->fieldValuesToSelectArray($definition['field_values']); $this->input["udf_" . $definition['field_id']] = new ilSelectInputGUI($definition['field_name'], "udf_" . $definition['field_id']); $this->input["udf_" . $definition['field_id']]->setOptions($options); } } $value = $user_defined_data["f_" . $field_id]; $this->input["udf_" . $definition['field_id']]->setValue($value); if ($definition['required']) { $this->input["udf_" . $definition['field_id']]->setRequired(true); } if (!$definition['changeable'] && (!$definition['required'] || $value)) { $this->input["udf_" . $definition['field_id']]->setDisabled(true); } // add "please select" if no current value if ($definition['field_type'] == UDF_TYPE_SELECT && !$value) { $options = array("" => $lng->txt("please_select")) + $options; $this->input["udf_" . $definition['field_id']]->setOptions($options); } } // standard fields include_once "./Services/User/classes/class.ilUserProfile.php"; $up = new ilUserProfile(); $up->skipField("password"); $up->skipGroup("settings"); $up->skipGroup("preferences"); $up->setAjaxCallback($this->ctrl->getLinkTargetByClass('ilPublicUserProfileGUI', 'doProfileAutoComplete', '', true)); // standard fields $up->addStandardFieldsToForm($this->form, $ilUser, $this->input); $this->addLocationToForm($this->form, $ilUser); $this->form->addCommandButton("savePersonalData", $lng->txt("save")); }
/** * Import record * * @param * @return */ function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version) { global $ilSetting, $ilUser; //echo $a_entity; //var_dump($a_rec); switch ($a_entity) { case "personal_data": // only users themselves import their profiles! // thus we can map the import id of the dataset to the current user $a_mapping->addMapping("Services/User", "usr", $a_rec["Id"], $ilUser->getId()); break; case "usr_profile": $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["Id"]); if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr") { if (!isset($this->users[$usr_id])) { $this->users[$usr_id] = new ilObjUser($usr_id); } $user = $this->users[$usr_id]; include_once "./Services/User/classes/class.ilUserProfile.php"; $prof = new ilUserProfile(); $prof->skipField("username"); $prof->skipField("password"); $prof->skipField("roles"); $prof->skipGroup("settings"); $fields = $prof->getStandardFields(); foreach ($fields as $k => $f) { $up_k = $this->convertToLeadingUpper($k); // only change fields, when it is possible in profile if (ilUserProfile::userSettingVisible($k) && !$ilSetting->get("usr_settings_disable_" . $k) && $f["method"] != "" && isset($a_rec[$up_k])) { $set_method = "set" . substr($f["method"], 3); $user->{$set_method}($a_rec[$up_k]); // echo "<br>-setting-".$set_method."-".$a_rec[$up_k]."-"; } } $user->update(); // personal picture $pic_dir = $this->getImportDirectory() . "/" . str_replace("..", "", $a_rec["Picture"]); if ($pic_dir != "" && is_dir($pic_dir)) { $upload_file = $pic_dir . "/upload_" . $a_rec["Id"] . "pic"; if (is_file($upload_file)) { ilObjUser::_uploadPersonalPicture($upload_file, $user->getId()); } } } break; case "usr_setting": $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["UserId"]); if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr") { if (!isset($this->users[$usr_id])) { $this->users[$usr_id] = new ilObjUser($usr_id); } $user = $this->users[$usr_id]; $user->writePref($a_rec["Keyword"], $a_rec["Value"]); } break; case "usr_multi": $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["UserId"]); if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr") { $this->multi[$usr_id][$a_rec["FieldId"]][] = $a_rec["Value"]; } break; } }
protected function getSelectableUserColumns($a_in_course = false, $a_in_group = false) { global $lng, $ilSetting; $cols = $privacy_fields = array(); include_once "./Services/User/classes/class.ilUserProfile.php"; $up = new ilUserProfile(); $up->skipGroup("preferences"); $up->skipGroup("settings"); $up->skipGroup("interests"); $ufs = $up->getStandardFields(); // default fields $cols["login"] = array("txt" => $lng->txt("login"), "default" => true); if (!$this->anonymized) { $cols["firstname"] = array("txt" => $lng->txt("firstname"), "default" => true); $cols["lastname"] = array("txt" => $lng->txt("lastname"), "default" => true); } // show only if extended data was activated in lp settings include_once 'Services/Tracking/classes/class.ilObjUserTracking.php'; $tracking = new ilObjUserTracking(); if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS)) { $cols["first_access"] = array("txt" => $lng->txt("trac_first_access"), "default" => true); $cols["last_access"] = array("txt" => $lng->txt("trac_last_access"), "default" => true); } if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_READ_COUNT)) { $cols["read_count"] = array("txt" => $lng->txt("trac_read_count"), "default" => true); } if ($tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS)) { $cols["spent_seconds"] = array("txt" => $lng->txt("trac_spent_seconds"), "default" => true); } if ($this->isPercentageAvailable($this->obj_id)) { $cols["percentage"] = array("txt" => $lng->txt("trac_percentage"), "default" => true); } // do not show status if learning progress is deactivated $olp = ilObjectLP::getInstance($this->obj_id); if ($olp->isActive()) { $cols["status"] = array("txt" => $lng->txt("trac_status"), "default" => true); $cols['status_changed'] = array('txt' => $lng->txt('trac_status_changed'), 'default' => false); } if ($this->type != "lm") { $cols["mark"] = array("txt" => $lng->txt("trac_mark"), "default" => true); } $cols["u_comment"] = array("txt" => $lng->txt("trac_comment"), "default" => false); $cols["create_date"] = array("txt" => $lng->txt("create_date"), "default" => false); $cols["language"] = array("txt" => $lng->txt("language"), "default" => false); // add user data only if object is [part of] course if (!$this->anonymized && ($a_in_course || $a_in_group)) { // only show if export permission is granted include_once 'Services/PrivacySecurity/classes/class.ilPrivacySettings.php'; if (ilPrivacySettings::_getInstance()->checkExportAccess($this->ref_id)) { // other user profile fields foreach ($ufs as $f => $fd) { if (!isset($cols[$f]) && $f != "username" && !$fd["lists_hide"]) { if ($a_in_course && !($fd["course_export_fix_value"] || $ilSetting->get("usr_settings_course_export_" . $f))) { continue; } if ($a_in_group && !($fd["group_export_fix_value"] || $ilSetting->get("usr_settings_group_export_" . $f))) { continue; } $cols[$f] = array("txt" => $lng->txt($f), "default" => false); $privacy_fields[] = $f; } } // additional defined user data fields include_once './Services/User/classes/class.ilUserDefinedFields.php'; $user_defined_fields = ilUserDefinedFields::_getInstance(); if ($a_in_course) { $user_defined_fields = $user_defined_fields->getCourseExportableFields(); } else { $user_defined_fields = $user_defined_fields->getGroupExportableFields(); } foreach ($user_defined_fields as $definition) { if ($definition["field_type"] != UDF_TYPE_WYSIWYG) { $f = "udf_" . $definition["field_id"]; $cols[$f] = array("txt" => $definition["field_name"], "default" => false); $privacy_fields[] = $f; } } } } return array($cols, $privacy_fields); }
protected function __createUser($a_role) { global $ilSetting, $rbacadmin; $this->userObj = new ilObjUser(); include_once "./Services/User/classes/class.ilUserProfile.php"; $up = new ilUserProfile(); $up->setMode(ilUserProfile::MODE_REGISTRATION); $map = array(); $up->skipGroup("preferences"); $up->skipGroup("settings"); $up->skipGroup("instant_messengers"); $up->skipField("password"); $up->skipField("birthday"); $up->skipField("upload"); foreach ($up->getStandardFields() as $k => $v) { if ($v["method"]) { $method = "set" . substr($v["method"], 3); if (method_exists($this->userObj, $method)) { if ($k != "username") { $k = "usr_" . $k; } $field_obj = $this->form->getItemByPostVar($k); if ($field_obj) { $this->userObj->{$method}($this->form->getInput($k)); } } } } $this->userObj->setFullName(); $birthday_obj = $this->form->getItemByPostVar("usr_birthday"); if ($birthday_obj) { $birthday = $this->form->getInput("usr_birthday"); $birthday = $birthday["date"]; // when birthday was not set, array will not be substituted with string by ilBirthdayInputGui if (!is_array($birthday)) { $this->userObj->setBirthday($birthday); } } // messenger $map = array("icq", "yahoo", "msn", "aim", "skype", "jabber", "voip"); foreach ($map as $client) { $field = "usr_im_" . $client; $field_obj = $this->form->getItemByPostVar($field); if ($field_obj) { $this->userObj->setInstantMessengerId($client, $this->form->getInput($field)); } } $this->userObj->setTitle($this->userObj->getFullname()); $this->userObj->setDescription($this->userObj->getEmail()); if ($this->registration_settings->passwordGenerationEnabled()) { $password = ilUtil::generatePasswords(1); $password = $password[0]; } else { $password = $this->form->getInput("usr_password"); } $this->userObj->setPasswd($password); // Set user defined data include_once './Services/User/classes/class.ilUserDefinedFields.php'; $user_defined_fields =& ilUserDefinedFields::_getInstance(); $defs = $user_defined_fields->getRegistrationDefinitions(); $udf = array(); foreach ($_POST as $k => $v) { if (substr($k, 0, 4) == "udf_") { $f = substr($k, 4); $udf[$f] = $v; } } $this->userObj->setUserDefinedData($udf); $this->userObj->setTimeLimitOwner(7); $this->code_was_used = false; if ($this->code_enabled) { // #10853 - could be optional $code = $this->form->getInput('usr_registration_code'); if ($code) { // set code to used include_once './Services/Registration/classes/class.ilRegistrationCode.php'; ilRegistrationCode::useCode($code); $this->code_was_used = true; } } // something went wrong with the form validation if (!$a_role) { global $ilias; $ilias->raiseError("Invalid role selection in registration" . ", IP: " . $_SERVER["REMOTE_ADDR"], $ilias->error_obj->FATAL); } if ($this->registration_settings->getAccessLimitation()) { include_once 'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php'; $access_limitations_obj = new ilRegistrationRoleAccessLimitations(); $access_limit_mode = $access_limitations_obj->getMode($a_role); if ($access_limit_mode == 'absolute') { $access_limit = $access_limitations_obj->getAbsolute($a_role); $this->userObj->setTimeLimitUnlimited(0); $this->userObj->setTimeLimitUntil($access_limit); } elseif ($access_limit_mode == 'relative') { $rel_d = (int) $access_limitations_obj->getRelative($a_role, 'd'); $rel_m = (int) $access_limitations_obj->getRelative($a_role, 'm'); $rel_y = (int) $access_limitations_obj->getRelative($a_role, 'y'); $access_limit = $rel_d * 86400 + $rel_m * 2592000 + $rel_y * 31536000 + time(); $this->userObj->setTimeLimitUnlimited(0); $this->userObj->setTimeLimitUntil($access_limit); } else { $this->userObj->setTimeLimitUnlimited(1); $this->userObj->setTimeLimitUntil(time()); } } else { $this->userObj->setTimeLimitUnlimited(1); $this->userObj->setTimeLimitUntil(time()); } $this->userObj->setTimeLimitFrom(time()); $this->userObj->create(); if ($this->registration_settings->getRegistrationType() == IL_REG_DIRECT || $this->registration_settings->getRegistrationType() == IL_REG_CODES || $this->code_was_used) { $this->userObj->setActive(1, 0); } else { if ($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION) { $this->userObj->setActive(0, 0); } else { $this->userObj->setActive(0, 0); } } $this->userObj->updateOwner(); // set a timestamp for last_password_change // this ts is needed by the ACCOUNT_SECURITY_MODE_CUSTOMIZED // in ilSecuritySettings $this->userObj->setLastPasswordChangeTS(time()); //insert user data in table user_data $this->userObj->saveAsNew(); // store acceptance of user agreement $this->userObj->writeAccepted(); // setup user preferences $this->userObj->setLanguage($this->form->getInput('usr_language')); $hits_per_page = $ilSetting->get("hits_per_page"); if ($hits_per_page < 10) { $hits_per_page = 10; } $this->userObj->setPref("hits_per_page", $hits_per_page); $show_online = $ilSetting->get("show_users_online"); if ($show_online == "") { $show_online = "y"; } $this->userObj->setPref("show_users_online", $show_online); $this->userObj->writePrefs(); $rbacadmin->assignUser((int) $a_role, $this->userObj->getId(), true); return $password; }
/** * Get selectable columns * * @param * @return */ function getSelectableColumns() { global $lng; include_once "./Services/User/classes/class.ilUserProfile.php"; $up = new ilUserProfile(); $up->skipGroup("preferences"); $up->skipGroup("interests"); $up->skipGroup("settings"); // default fields $cols = array(); // first and last name cannot be hidden $cols["firstname"] = array("txt" => $lng->txt("firstname"), "default" => true); $cols["lastname"] = array("txt" => $lng->txt("lastname"), "default" => true); if ($this->getMode() == self::MODE_USER_FOLDER) { $ufs = $up->getStandardFields(); $cols["access_until"] = array("txt" => $lng->txt("access_until"), "default" => true); $cols["last_login"] = array("txt" => $lng->txt("last_login"), "default" => true); // #13967 $cols["create_date"] = array("txt" => $lng->txt("create_date")); $cols["approve_date"] = array("txt" => $lng->txt("approve_date")); $cols["agree_date"] = array("txt" => $lng->txt("agree_date")); } else { $ufs = $up->getLocalUserAdministrationFields(); } // email should be the 1st "optional" field (can be hidden) if (isset($ufs["email"])) { $cols["email"] = array("txt" => $lng->txt("email"), "default" => true); } // other user profile fields foreach ($ufs as $f => $fd) { if (!isset($cols[$f]) && !$fd["lists_hide"]) { $cols[$f] = array("txt" => $lng->txt($f), "default" => false); } } // fields that are always shown unset($cols["username"]); return $cols; }
protected function __createUser($a_role) { /** * @var $ilSetting ilSetting * @var $rbacadmin ilRbacAdmin * @var $lng ilLanguage */ global $ilSetting, $rbacadmin, $lng; // something went wrong with the form validation if (!$a_role) { global $ilias; $ilias->raiseError("Invalid role selection in registration" . ", IP: " . $_SERVER["REMOTE_ADDR"], $ilias->error_obj->FATAL); } $this->userObj = new ilObjUser(); include_once "./Services/User/classes/class.ilUserProfile.php"; $up = new ilUserProfile(); $up->setMode(ilUserProfile::MODE_REGISTRATION); $map = array(); $up->skipGroup("preferences"); $up->skipGroup("settings"); $up->skipGroup("instant_messengers"); $up->skipField("password"); $up->skipField("birthday"); $up->skipField("upload"); foreach ($up->getStandardFields() as $k => $v) { if ($v["method"]) { $method = "set" . substr($v["method"], 3); if (method_exists($this->userObj, $method)) { if ($k != "username") { $k = "usr_" . $k; } $field_obj = $this->form->getItemByPostVar($k); if ($field_obj) { $this->userObj->{$method}($this->form->getInput($k)); } } } } $this->userObj->setFullName(); $birthday_obj = $this->form->getItemByPostVar("usr_birthday"); if ($birthday_obj) { $birthday = $this->form->getInput("usr_birthday"); $birthday = $birthday["date"]; // when birthday was not set, array will not be substituted with string by ilBirthdayInputGui if (!is_array($birthday)) { $this->userObj->setBirthday($birthday); } } // messenger $map = array("icq", "yahoo", "msn", "aim", "skype", "jabber", "voip"); foreach ($map as $client) { $field = "usr_im_" . $client; $field_obj = $this->form->getItemByPostVar($field); if ($field_obj) { $this->userObj->setInstantMessengerId($client, $this->form->getInput($field)); } } $this->userObj->setTitle($this->userObj->getFullname()); $this->userObj->setDescription($this->userObj->getEmail()); if ($this->registration_settings->passwordGenerationEnabled()) { $password = ilUtil::generatePasswords(1); $password = $password[0]; } else { $password = $this->form->getInput("usr_password"); } $this->userObj->setPasswd($password); // Set user defined data include_once './Services/User/classes/class.ilUserDefinedFields.php'; $user_defined_fields =& ilUserDefinedFields::_getInstance(); $defs = $user_defined_fields->getRegistrationDefinitions(); $udf = array(); foreach ($_POST as $k => $v) { if (substr($k, 0, 4) == "udf_") { $f = substr($k, 4); $udf[$f] = $v; } } $this->userObj->setUserDefinedData($udf); $this->userObj->setTimeLimitOwner(7); $access_limit = null; $this->code_was_used = false; if ($this->code_enabled) { $code_local_roles = $code_has_access_limit = null; // #10853 - could be optional $code = $this->form->getInput('usr_registration_code'); if ($code) { include_once './Services/Registration/classes/class.ilRegistrationCode.php'; // set code to used ilRegistrationCode::useCode($code); $this->code_was_used = true; // handle code attached local role(s) and access limitation $code_data = ilRegistrationCode::getCodeData($code); if ($code_data["role_local"]) { // need user id before we can assign role(s) $code_local_roles = explode(";", $code_data["role_local"]); } if ($code_data["alimit"]) { // see below $code_has_access_limit = true; switch ($code_data["alimit"]) { case "absolute": $abs = date_parse($code_data["alimitdt"]); $access_limit = mktime(23, 59, 59, $abs['month'], $abs['day'], $abs['year']); break; case "relative": $rel = unserialize($code_data["alimitdt"]); $access_limit = $rel["d"] * 86400 + $rel["m"] * 2592000 + $rel["y"] * 31536000 + time(); break; } } } } // code access limitation will override any other access limitation setting if (!($this->code_was_used && $code_has_access_limit) && $this->registration_settings->getAccessLimitation()) { include_once 'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php'; $access_limitations_obj = new ilRegistrationRoleAccessLimitations(); switch ($access_limitations_obj->getMode($a_role)) { case 'absolute': $access_limit = $access_limitations_obj->getAbsolute($a_role); break; case 'relative': $rel_d = (int) $access_limitations_obj->getRelative($a_role, 'd'); $rel_m = (int) $access_limitations_obj->getRelative($a_role, 'm'); $rel_y = (int) $access_limitations_obj->getRelative($a_role, 'y'); $access_limit = $rel_d * 86400 + $rel_m * 2592000 + $rel_y * 31536000 + time(); break; } } if ($access_limit) { $this->userObj->setTimeLimitUnlimited(0); $this->userObj->setTimeLimitUntil($access_limit); } else { $this->userObj->setTimeLimitUnlimited(1); $this->userObj->setTimeLimitUntil(time()); } $this->userObj->setTimeLimitFrom(time()); $this->userObj->create(); if ($this->registration_settings->getRegistrationType() == IL_REG_DIRECT || $this->registration_settings->getRegistrationType() == IL_REG_CODES || $this->code_was_used) { $this->userObj->setActive(1, 0); } else { if ($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION) { $this->userObj->setActive(0, 0); } else { $this->userObj->setActive(0, 0); } } $this->userObj->updateOwner(); // set a timestamp for last_password_change // this ts is needed by ilSecuritySettings $this->userObj->setLastPasswordChangeTS(time()); $this->userObj->setIsSelfRegistered(true); //insert user data in table user_data $this->userObj->saveAsNew(); try { require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceSignableDocumentFactory.php'; ilTermsOfServiceHelper::trackAcceptance($this->userObj, ilTermsOfServiceSignableDocumentFactory::getByLanguageObject($lng)); } catch (ilTermsOfServiceNoSignableDocumentFoundException $e) { } // setup user preferences $this->userObj->setLanguage($this->form->getInput('usr_language')); $hits_per_page = $ilSetting->get("hits_per_page"); if ($hits_per_page < 10) { $hits_per_page = 10; } $this->userObj->setPref("hits_per_page", $hits_per_page); $show_online = $ilSetting->get("show_users_online"); if ($show_online == "") { $show_online = "y"; } $this->userObj->setPref("show_users_online", $show_online); $this->userObj->writePrefs(); $rbacadmin->assignUser((int) $a_role, $this->userObj->getId()); // local roles from code if ($this->code_was_used && is_array($code_local_roles)) { foreach (array_unique($code_local_roles) as $local_role_obj_id) { // is given role (still) valid? if (ilObject::_lookupType($local_role_obj_id) == "role") { $rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId()); } } } return $password; }
/** * Read info about exportable fields * * @access private * */ private function read() { include_once './Services/User/classes/class.ilUserProfile.php'; $profile = new ilUserProfile(); $profile->skipGroup('settings'); foreach ($profile->getStandardFields() as $key => $data) { if ($this->getType() == 'crs') { if (!$data['course_export_hide']) { if (isset($data['course_export_fix_value']) and $data['course_export_fix_value']) { $this->possible_fields[$key] = $data['course_export_fix_value']; } else { $this->possible_fields[$key] = 0; } } } elseif ($this->getType() == 'grp') { if (!$data['group_export_hide']) { if (isset($data['group_export_fix_value']) and $data['group_export_fix_value']) { $this->possible_fields[$key] = $data['group_export_fix_value']; } else { $this->possible_fields[$key] = 0; } } } } $settings_all = $this->settings->getAll(); $field_part_limit = 5; switch ($this->getType()) { case 'crs': $field_prefix = 'usr_settings_course_export_'; $field_part_limit = 5; break; case 'grp': $field_prefix = 'usr_settings_group_export_'; $field_part_limit = 5; break; } foreach ($settings_all as $key => $value) { if (stristr($key, $field_prefix) and $value) { // added limit for mantis 11096 $field_parts = explode('_', $key, $field_part_limit); $field = $field_parts[count($field_parts) - 1]; if (array_key_exists($field, $this->possible_fields)) { $this->possible_fields[$field] = 1; } } } return true; }