public static function _createRandomUserAccount($keyarray) { global $ilDB, $ilUser, $ilSetting, $rbacadmin; if ($_SESSION['create_user_account'] != NULL) { $obj_user = new ilObjUser($_SESSION['create_user_account']); return $obj_user; } else { $userLogin = array(); $res = $ilDB->query('SELECT sequence FROM object_data_seq'); $row = $ilDB->fetchAssoc($res); $temp_user_id = (int) $row['sequence'] + 1; $userLogin['login'] = '******' . $temp_user_id; $userLogin['passwd'] = ilUtil::generatePasswords(1); require_once 'Services/User/classes/class.ilObjUser.php'; include_once "Services/Mail/classes/class.ilAccountMail.php"; $obj_user = new ilObjUser(); $obj_user->setId($temp_user_id); $obj_user->setLogin($userLogin['login']); $obj_user->setPasswd((string) $userLogin['passwd'][0], IL_PASSWD_PLAIN); $_SESSION['tmp_user_account']['login'] = $userLogin['login']; $_SESSION['tmp_user_account']['passwd'] = $userLogin['passwd']; $obj_user->setFirstname($keyarray['first_name']); $obj_user->setLastname($keyarray['last_name']); $obj_user->setEmail($keyarray['payer_email']); # $obj_user->setEmail('*****@*****.**'); $obj_user->setGender('f'); $obj_user->setLanguage($ilSetting->get("language")); $obj_user->setActive(true); $obj_user->setTimeLimitUnlimited(true); $obj_user->setTitle($obj_user->getFullname()); $obj_user->setDescription($obj_user->getEmail()); $obj_user->setTimeLimitOwner(7); $obj_user->setTimeLimitUnlimited(1); $obj_user->setTimeLimitMessage(0); $obj_user->setApproveDate(date("Y-m-d H:i:s")); // Set default prefs $obj_user->setPref('hits_per_page', $ilSetting->get('hits_per_page', 30)); $obj_user->setPref('show_users_online', $ilSetting->get('show_users_online', 'y')); $obj_user->writePrefs(); // at the first login the user must complete profile $obj_user->setProfileIncomplete(true); $obj_user->create(); $obj_user->saveAsNew(); $user_role = ilObject::_exists(4, false); if (!$user_role) { include_once "./Services/AccessControl/classes/class.ilObjRole.php"; $reg_allowed = ilObjRole::_lookupRegisterAllowed(); $user_role = $reg_allowed[0]['id']; } else { $user_role = 4; } $rbacadmin->assignUser((int) $user_role, $obj_user->getId(), true); include_once "Services/Mail/classes/class.ilMimeMail.php"; global $ilias, $lng; $settings = $ilias->getAllSettings(); $mmail = new ilMimeMail(); $mmail->autoCheck(false); $mmail->From($settings["admin_email"]); $mmail->To($obj_user->getEmail()); // mail subject $subject = $lng->txt("reg_mail_subject"); // mail body $body = $lng->txt("reg_mail_body_salutation") . " " . $obj_user->getFullname() . ",\n\n" . $lng->txt("reg_mail_body_text1") . "\n\n" . $lng->txt("reg_mail_body_text2") . "\n" . ILIAS_HTTP_PATH . "/login.php?client_id=" . $ilias->client_id . "\n"; $body .= $lng->txt("login") . ": " . $obj_user->getLogin() . "\n"; $body .= $lng->txt("passwd") . ": " . $userLogin['passwd'][0] . "\n"; $body .= "\n"; $body .= $lng->txt("reg_mail_body_text3") . "\n\r"; $body .= $obj_user->getProfileAsString($lng); $mmail->Subject($subject); $mmail->Body($body); $mmail->Send(); $_SESSION['create_user_account'] = $obj_user->getId(); return $obj_user; } }
/** * Add standard fields to form */ function addStandardFieldsToForm($a_form, $a_user = NULL, array $custom_fields = NULL) { global $ilSetting, $lng, $rbacreview, $ilias; // custom registration settings if (self::$mode == self::MODE_REGISTRATION) { include_once 'Services/Registration/classes/class.ilRegistrationSettings.php'; $registration_settings = new ilRegistrationSettings(); self::$user_field["username"]["group"] = "login_data"; self::$user_field["password"]["group"] = "login_data"; self::$user_field["language"]["default"] = $lng->lang_key; // different position for role $roles = self::$user_field["roles"]; unset(self::$user_field["roles"]); self::$user_field["roles"] = $roles; self::$user_field["roles"]["group"] = "settings"; } $fields = $this->getStandardFields(); $current_group = ""; $custom_fields_done = false; foreach ($fields as $f => $p) { // next group? -> diplay subheader if ($p["group"] != $current_group && ilUserProfile::userSettingVisible($f)) { if (is_array($custom_fields) && !$custom_fields_done) { // should be appended to "other" or at least before "settings" if ($current_group == "other" || $p["group"] == "settings") { // add "other" subheader if ($current_group != "other") { $sh = new ilFormSectionHeaderGUI(); $sh->setTitle($lng->txt("other")); $a_form->addItem($sh); } foreach ($custom_fields as $custom_field) { $a_form->addItem($custom_field); } $custom_fields_done = true; } } $sh = new ilFormSectionHeaderGUI(); $sh->setTitle($lng->txt($p["group"])); $a_form->addItem($sh); $current_group = $p["group"]; } $m = ""; if (isset($p["method"])) { $m = $p["method"]; } $lv = isset($p["lang_var"]) && $p["lang_var"] != "" ? $p["lang_var"] : $f; switch ($p["input"]) { case "login": if ((int) $ilSetting->get('allow_change_loginname') || self::$mode == self::MODE_REGISTRATION) { $val = new ilTextInputGUI($lng->txt('username'), 'username'); if ($a_user) { $val->setValue($a_user->getLogin()); } $val->setMaxLength(32); $val->setSize(40); $val->setRequired(true); } else { // user account name $val = new ilNonEditableValueGUI($lng->txt("username"), 'ne_un'); if ($a_user) { $val->setValue($a_user->getLogin()); } } $a_form->addItem($val); break; case "text": if (ilUserProfile::userSettingVisible($f)) { $ti = new ilTextInputGUI($lng->txt($lv), "usr_" . $f); if ($a_user) { $ti->setValue($a_user->{$m}()); } $ti->setMaxLength($p["maxlength"]); $ti->setSize($p["size"]); $ti->setRequired($ilSetting->get("require_" . $f)); if (!$ti->getRequired() || $ti->getValue()) { $ti->setDisabled($ilSetting->get("usr_settings_disable_" . $f)); } $a_form->addItem($ti); } break; case "sel_country": if (ilUserProfile::userSettingVisible($f)) { include_once "./Services/Form/classes/class.ilCountrySelectInputGUI.php"; $ci = new ilCountrySelectInputGUI($lng->txt($lv), "usr_" . $f); if ($a_user) { $ci->setValue($a_user->{$m}()); } $ci->setRequired($ilSetting->get("require_" . $f)); if (!$ci->getRequired() || $ci->getValue()) { $ci->setDisabled($ilSetting->get("usr_settings_disable_" . $f)); } $a_form->addItem($ci); } break; case "birthday": if (ilUserProfile::userSettingVisible($f)) { $bi = new ilBirthdayInputGUI($lng->txt($lv), "usr_" . $f); include_once "./Services/Calendar/classes/class.ilDateTime.php"; $date = null; if ($a_user && strlen($a_user->{$m}())) { $date = new ilDateTime($a_user->{$m}(), IL_CAL_DATE); $bi->setDate($date); } $bi->setShowEmpty(true); $bi->setStartYear(1900); $bi->setRequired($ilSetting->get("require_" . $f)); if (!$bi->getRequired() || $date) { $bi->setDisabled($ilSetting->get("usr_settings_disable_" . $f)); } $a_form->addItem($bi); } break; case "radio": if (ilUserProfile::userSettingVisible($f)) { $rg = new ilRadioGroupInputGUI($lng->txt($lv), "usr_" . $f); if ($a_user) { $rg->setValue($a_user->{$m}()); } foreach ($p["values"] as $k => $v) { $op = new ilRadioOption($lng->txt($v), $k); $rg->addOption($op); } $rg->setRequired($ilSetting->get("require_" . $f)); if (!$rg->getRequired() || $rg->getValue()) { $rg->setDisabled($ilSetting->get("usr_settings_disable_" . $f)); } $a_form->addItem($rg); } break; case "picture": if (ilUserProfile::userSettingVisible("upload") && $a_user) { $ii = new ilImageFileInputGUI($lng->txt("personal_picture"), "userfile"); $ii->setDisabled($ilSetting->get("usr_settings_disable_upload")); $upload = $a_form->getFileUpload("userfile"); if ($upload["name"]) { $ii->setPending($upload["name"]); } else { $im = ilObjUser::_getPersonalPicturePath($a_user->getId(), "small", true, true); if ($im != "") { $ii->setImage($im); $ii->setAlt($lng->txt("personal_picture")); } } // ilinc link as info if (ilUserProfile::userSettingVisible("upload") and $ilSetting->get("ilinc_active")) { include_once './Modules/ILinc/classes/class.ilObjiLincUser.php'; $ilinc_user = new ilObjiLincUser($a_user); if ($ilinc_user->id) { include_once './Modules/ILinc/classes/class.ilnetucateXMLAPI.php'; $ilincAPI = new ilnetucateXMLAPI(); $ilincAPI->uploadPicture($ilinc_user); $response = $ilincAPI->sendRequest("uploadPicture"); // return URL to user's personal page $url = trim($response->data['url']['cdata']); $desc = $lng->txt("ilinc_upload_pic_text") . " " . '<a href="' . $url . '">' . $lng->txt("ilinc_upload_pic_linktext") . '</a>'; $ii->setInfo($desc); } } $a_form->addItem($ii); } break; case "roles": if (self::$mode == self::MODE_DESKTOP) { if (ilUserProfile::userSettingVisible("roles")) { $global_roles = $rbacreview->getGlobalRoles(); foreach ($global_roles as $role_id) { if (in_array($role_id, $rbacreview->assignedRoles($a_user->getId()))) { $roleObj = $ilias->obj_factory->getInstanceByObjId($role_id); $role_names .= $roleObj->getTitle() . ", "; unset($roleObj); } } $dr = new ilNonEditableValueGUI($lng->txt("default_roles"), "ne_dr"); $dr->setValue(substr($role_names, 0, -2)); $a_form->addItem($dr); } } else { if (self::$mode == self::MODE_REGISTRATION) { if ($registration_settings->roleSelectionEnabled()) { include_once "./Services/AccessControl/classes/class.ilObjRole.php"; $options = array(); foreach (ilObjRole::_lookupRegisterAllowed() as $role) { $options[$role["id"]] = $role["title"]; } // registration form validation will take care of missing field / value if ($options) { if (sizeof($options) > 1) { $ta = new ilSelectInputGUI($lng->txt('default_role'), "usr_" . $f); $ta->setOptions($options); $ta->setRequired($ilSetting->get("require_" . $f)); if (!$ta->getRequired()) { $ta->setDisabled($ilSetting->get("usr_settings_disable_" . $f)); } } else { $ta = new ilHiddenInputGUI("usr_" . $f); $ta->setValue(array_shift(array_keys($options))); } $a_form->addItem($ta); } } } } break; case "email": if (ilUserProfile::userSettingVisible($f)) { $em = new ilEMailInputGUI($lng->txt($lv), "usr_" . $f); if ($a_user) { $em->setValue($a_user->{$m}()); } $em->setRequired($ilSetting->get("require_" . $f)); if (!$em->getRequired() || $em->getValue()) { $em->setDisabled($ilSetting->get("usr_settings_disable_" . $f)); } if (self::MODE_REGISTRATION == self::$mode) { $em->setRetype(true); } $a_form->addItem($em); } break; case "textarea": if (ilUserProfile::userSettingVisible($f)) { $ta = new ilTextAreaInputGUI($lng->txt($lv), "usr_" . $f); if ($a_user) { $ta->setValue($a_user->{$m}()); } $ta->setRows($p["rows"]); $ta->setCols($p["cols"]); $ta->setRequired($ilSetting->get("require_" . $f)); if (!$ta->getRequired() || $ta->getValue()) { $ta->setDisabled($ilSetting->get("usr_settings_disable_" . $f)); } $a_form->addItem($ta); } break; case "messenger": if (ilUserProfile::userSettingVisible("instant_messengers")) { $im_arr = $p["types"]; foreach ($im_arr as $im_name) { $im = new ilTextInputGUI($lng->txt("im_" . $im_name), "usr_im_" . $im_name); if ($a_user) { $im->setValue($a_user->getInstantMessengerId($im_name)); } $im->setMaxLength($p["maxlength"]); $im->setSize($p["size"]); $im->setRequired($ilSetting->get("require_" . "instant_messengers")); if (!$im->getRequired() || $im->getValue()) { $im->setDisabled($ilSetting->get("usr_settings_disable_" . "instant_messengers")); } $a_form->addItem($im); } } break; case "password": if (self::$mode == self::MODE_REGISTRATION) { if (!$registration_settings->passwordGenerationEnabled()) { $ta = new ilPasswordInputGUI($lng->txt($lv), "usr_" . $f); $ta->setRequired(true); // $ta->setDisabled($ilSetting->get("usr_settings_disable_".$f)); } else { $ta = new ilNonEditableValueGUI($lng->txt($lv)); $ta->setValue($lng->txt("reg_passwd_via_mail")); } $a_form->addItem($ta); } break; case "language": if (ilUserProfile::userSettingVisible($f)) { $ta = new ilSelectInputGUI($lng->txt($lv), "usr_" . $f); if ($a_user) { $ta->setValue($a_user->{$m}()); } $options = array(); $lng->loadLanguageModule("meta"); foreach ($lng->getInstalledLanguages() as $lang_key) { $options[$lang_key] = $lng->txt("meta_l_" . $lang_key); } asort($options); // #9728 $ta->setOptions($options); $ta->setRequired($ilSetting->get("require_" . $f)); if (!$ta->getRequired() || $ta->getValue()) { $ta->setDisabled($ilSetting->get("usr_settings_disable_" . $f)); } $a_form->addItem($ta); } break; case "multitext": if (ilUserProfile::userSettingVisible($f)) { $ti = new ilTextInputGUI($lng->txt($lv), "usr_" . $f); $ti->setMulti(true); if ($a_user) { $ti->setValue($a_user->{$m}()); } $ti->setMaxLength($p["maxlength"]); $ti->setSize($p["size"]); $ti->setRequired($ilSetting->get("require_" . $f)); if (!$ti->getRequired() || $ti->getValue()) { $ti->setDisabled($ilSetting->get("usr_settings_disable_" . $f)); } if ($this->ajax_href) { // add field to ajax call $ti->setDataSource($this->ajax_href . "&f=" . $f); } $a_form->addItem($ti); } break; } } // append custom fields as "other" if (is_array($custom_fields) && !$custom_fields_done) { // add "other" subheader if ($current_group != "other") { $sh = new ilFormSectionHeaderGUI(); $sh->setTitle($lng->txt("other")); $a_form->addItem($sh); } foreach ($custom_fields as $custom_field) { $a_form->addItem($custom_field); } } }
/** * display settings menu * * @access public */ function authSettingsObject() { global $rbacsystem, $ilSetting; if (!$rbacsystem->checkAccess("visible,read", $this->object->getRefId())) { $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE); } $this->tabs_gui->setTabActive('authentication_settings'); $this->setSubTabs('authSettings'); $this->tabs_gui->setSubTabActive("auth_settings"); $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.auth_general.html", "Services/Authentication"); $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this)); $this->tpl->setVariable("TXT_AUTH_TITLE", $this->lng->txt("auth_select")); $this->tpl->setVariable("TXT_AUTH_MODE", $this->lng->txt("auth_mode")); $this->tpl->setVariable("TXT_AUTH_DEFAULT", $this->lng->txt("default")); $this->tpl->setVariable("TXT_AUTH_ACTIVE", $this->lng->txt("active")); $this->tpl->setVariable("TXT_AUTH_NUM_USERS", $this->lng->txt("num_users")); $this->tpl->setVariable("TXT_LOCAL", $this->lng->txt("auth_local")); $this->tpl->setVariable("TXT_LDAP", $this->lng->txt("auth_ldap")); $this->tpl->setVariable("TXT_SHIB", $this->lng->txt("auth_shib")); $this->tpl->setVariable("TXT_CAS", $this->lng->txt("auth_cas")); $this->tpl->setVariable("TXT_RADIUS", $this->lng->txt("auth_radius")); $this->tpl->setVariable("TXT_SCRIPT", $this->lng->txt("auth_script")); $this->tpl->setVariable("TXT_APACHE", $this->lng->txt("auth_apache")); $auth_cnt = ilObjUser::_getNumberOfUsersPerAuthMode(); $auth_modes = ilAuthUtils::_getAllAuthModes(); foreach ($auth_modes as $mode => $mode_name) { //echo "-".$ilSetting->get('auth_mode')."-".$mode."-"; if ($ilSetting->get('auth_mode') == $mode) { $this->tpl->setVariable("NUM_" . strtoupper($mode_name), (int) $auth_cnt[$mode_name] + $auth_cnt["default"] . " (" . $this->lng->txt("auth_per_default") . ": " . $auth_cnt["default"] . ")"); } else { $this->tpl->setVariable("NUM_" . strtoupper($mode_name), (int) $auth_cnt[$mode_name]); } } $this->tpl->setVariable("TXT_CONFIGURE", $this->lng->txt("auth_configure")); $this->tpl->setVariable("TXT_AUTH_REMARK", $this->lng->txt("auth_remark_non_local_auth")); $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save")); $this->tpl->setVariable("CMD_SUBMIT", "setAuthMode"); // local vars $checked = "checked=\"checked\""; $disabled = "disabled=\"disabled\""; $style_disabled = "_disabled"; // icon handlers $icon_ok = "<img src=\"" . ilUtil::getImagePath("icon_ok.svg") . "\" alt=\"" . $this->lng->txt("enabled") . "\" title=\"" . $this->lng->txt("enabled") . "\" border=\"0\" vspace=\"0\"/>"; $icon_not_ok = "<img src=\"" . ilUtil::getImagePath("icon_not_ok.svg") . "\" alt=\"" . $this->lng->txt("disabled") . "\" title=\"" . $this->lng->txt("disabled") . "\" border=\"0\" vspace=\"0\"/>"; $this->tpl->setVariable("AUTH_LOCAL_ACTIVE", $icon_ok); include_once 'Services/LDAP/classes/class.ilLDAPServer.php'; $this->tpl->setVariable('AUTH_LDAP_ACTIVE', count(ilLDAPServer::_getActiveServerList()) ? $icon_ok : $icon_not_ok); #$this->tpl->setVariable("AUTH_LDAP_ACTIVE", $this->ilias->getSetting('ldap_active') ? $icon_ok : $icon_not_ok); $this->tpl->setVariable("AUTH_RADIUS_ACTIVE", $this->ilias->getSetting('radius_active') ? $icon_ok : $icon_not_ok); $this->tpl->setVariable("AUTH_SHIB_ACTIVE", $this->ilias->getSetting('shib_active') ? $icon_ok : $icon_not_ok); $this->tpl->setVariable("AUTH_SCRIPT_ACTIVE", $this->ilias->getSetting('script_active') ? $icon_ok : $icon_not_ok); $this->tpl->setVariable("AUTH_CAS_ACTIVE", $this->ilias->getSetting('cas_active') ? $icon_ok : $icon_not_ok); $this->tpl->setVariable("AUTH_APACHE_ACTIVE", $this->ilias->getSetting('apache_active') ? $icon_ok : $icon_not_ok); // alter style and disable buttons depending on current selection switch ($this->ilias->getSetting('auth_mode')) { case AUTH_LOCAL: // default $this->tpl->setVariable("CHK_LOCAL", $checked); break; case AUTH_LDAP: // LDAP $this->tpl->setVariable("CHK_LDAP", $checked); break; case AUTH_SHIBBOLETH: // SHIB $this->tpl->setVariable("CHK_SHIB", $checked); break; case AUTH_RADIUS: // RADIUS $this->tpl->setVariable("CHK_RADIUS", $checked); break; case AUTH_CAS: // CAS $this->tpl->setVariable("CHK_CAS", $checked); break; case AUTH_SCRIPT: // script $this->tpl->setVariable("CHK_SCRIPT", $checked); break; case AUTH_APACHE: // apache $this->tpl->setVariable("CHK_APACHE", $checked); break; } // auth mode determinitation if ($this->initAuthModeDetermination()) { $this->tpl->setVariable('TABLE_AUTH_DETERMINATION', $this->form->getHTML()); } // roles table $this->tpl->setVariable("FORMACTION_ROLES", $this->ctrl->getFormAction($this)); $this->tpl->setVariable("TXT_AUTH_ROLES", $this->lng->txt("auth_active_roles")); $this->tpl->setVariable("TXT_ROLE", $this->lng->txt("obj_role")); $this->tpl->setVariable("TXT_ROLE_AUTH_MODE", $this->lng->txt("auth_role_auth_mode")); $this->tpl->setVariable("CMD_SUBMIT_ROLES", "updateAuthRoles"); include_once "./Services/AccessControl/classes/class.ilObjRole.php"; $reg_roles = ilObjRole::_lookupRegisterAllowed(); // auth mode selection include_once './Services/Authentication/classes/class.ilAuthUtils.php'; $active_auth_modes = ilAuthUtils::_getActiveAuthModes(); foreach ($reg_roles as $role) { foreach ($active_auth_modes as $auth_name => $auth_key) { // do not list auth modes with external login screen // even not default, because it can easily be set to // a non-working auth mode if ($auth_name == "default" || $auth_name == "cas" || $auth_name == "shibboleth" || $auth_name == 'ldap' || $auth_name == 'apache' || $auth_name == "ecs" || $auth_name == "openid") { continue; } $this->tpl->setCurrentBlock("auth_mode_selection"); if ($auth_name == 'default') { $name = $this->lng->txt('auth_' . $auth_name) . " (" . $this->lng->txt('auth_' . ilAuthUtils::_getAuthModeName($auth_key)) . ")"; } else { $name = $this->lng->txt('auth_' . $auth_name); } $this->tpl->setVariable("AUTH_MODE_NAME", $name); $this->tpl->setVariable("AUTH_MODE", $auth_name); if ($role['auth_mode'] == $auth_name) { $this->tpl->setVariable("SELECTED_AUTH_MODE", "selected=\"selected\""); } $this->tpl->parseCurrentBlock(); } // END auth_mode selection $this->tpl->setCurrentBlock("roles"); $this->tpl->setVariable("ROLE", $role['title']); $this->tpl->setVariable("ROLE_ID", $role['id']); $this->tpl->parseCurrentBlock(); } }
function __prepareAccessLimitationRoleList() { global $lng; $this->__initRoleAccessLimitations(); include_once './Services/AccessControl/classes/class.ilObjRole.php'; $all = array(); foreach (ilObjRole::_lookupRegisterAllowed() as $role) { switch ($this->access_limitations_obj->getMode($role['id'])) { case 'absolute': $txt_access_value = $lng->txt('reg_access_limitation_limited_until'); $txt_access_value .= " " . ilDatePresentation::formatDate(new ilDateTime($this->access_limitations_obj->getAbsolute($role['id'], IL_CAL_UNIX))); break; case 'relative': $years = $this->access_limitations_obj->getRelative($role['id'], 'y'); $months = $this->access_limitations_obj->getRelative($role['id'], 'm'); $days = $this->access_limitations_obj->getRelative($role['id'], 'd'); $txt_access_value = $lng->txt('reg_access_limitation_limited_time') . " "; if ($years) { $txt_access_value .= $years . " "; $txt_access_value .= $years == 1 ? $lng->txt('year') : $lng->txt('years'); if ($months) { if ($days) { $txt_access_value .= ", "; } else { $txt_access_value .= " " . $lng->txt('and') . " "; } } elseif ($days) { $txt_access_value .= " " . $lng->txt('and') . " "; } } if ($months) { $txt_access_value .= $months . " "; $txt_access_value .= $months == 1 ? $lng->txt('month') : $lng->txt('months'); if ($days) { $txt_access_value .= " " . $lng->txt('and') . " "; } } if ($days) { $txt_access_value .= $days . " "; $txt_access_value .= $days == 1 ? $lng->txt('day') : $lng->txt('days'); } break; default: $txt_access_value = $lng->txt('reg_access_limitation_none'); break; } $all[] = $role['title'] . ' (' . $txt_access_value . ')'; } return $all; }