if ((!isset($rowcols['profile_field_company']) || empty($rowcols['profile_field_company'])) && !company_user::is_company_user() && $companyid == 0) { $errormsg['profile_field_company'] = get_string('profile_field_company_not_set', 'block_iomad_company_admin'); } if (isset($rowcols['profile_field_company']) && !company_user::can_see_company($rowcols['profile_field_company'])) { $errormsg['profile_field_company'] = get_string('invalid_company', 'block_iomad_company_admin'); } if ($companyid > 0 && isset($rowcols['profile_field_company']) && !empty($rowcols['profile_field_company']) && $rowcols['profile_field_company'] != $companyshortname) { $errormsg['profile_field_company'] = get_string('profile_field_company_not_empty_does_not_match_selected', 'block_iomad_company_admin'); } if ((!isset($rowcols['username']) || empty($rowcols['username'])) && isset($rowcols['email']) && !empty($rowcols['email'])) { // No username given, try to find an existing user via the email address. if ($perfexistinguser = $DB->get_record('user', array('email' => $rowcols['email']))) { $rowcols['username'] = $perfexistinguser->username; } else { // No existing user matches, generate a new username. $rowcols['username'] = company_user::generate_username($rowcols['email']); } } $usernameexist = $DB->record_exists('user', array('username' => $rowcols['username'])); $emailexist = $DB->record_exists('user', array('email' => $rowcols['email'])); $cleanusername = clean_param($rowcols['username'], PARAM_USERNAME); $validusername = strcmp($rowcols['username'], $cleanusername); $validemail = validate_email($rowcols['email']); if ($validusername != 0 || !$validemail) { if ($validusername != 0) { $errormsg['username'] = get_string('invalidusernameupload'); } if (!$validemail) { $errormsg['email'] = get_string('invalidemail'); } }