$strduplicateusername = get_string('duplicateusername', 'error');
$struserauthunsupported = get_string('userauthunsupported', 'error');
-
+$stremailduplicate = get_string('useremailduplicate', 'error');;
$errorstr = get_string('error');
$PRF_FIELDS = array();
-if ($prof_fields = $fields = get_records_select('user_info_field')) {
+if ($prof_fields = get_records('user_info_field')) {
foreach ($prof_fields as $prof_field) {
$PRF_FIELDS[] = 'profile_field_'.$prof_field->shortname;
}
$optype = $formdata->uutype;
- $createpasswords = (!empty($formdata->uupasswordnew) and $optype != UU_UPDATE);
- $updatepasswords = (!empty($formdata->uupasswordold) and $optype != UU_ADDNEW and $optype != UU_ADDINC);
- $allowrenames = (!empty($formdata->uuallowrenames) and $optype != UU_ADDNEW and $optype != UU_ADDINC);
- $allowdeletes = (!empty($formdata->uuallowdeletes) and $optype != UU_ADDNEW and $optype != UU_ADDINC);
- $updatetype = isset($formdata->uuupdatetype) ? $formdata->uuupdatetype : 0;
- $bulk = $formdata->uubulk;
+ $createpasswords = (!empty($formdata->uupasswordnew) and $optype != UU_UPDATE);
+ $updatepasswords = (!empty($formdata->uupasswordold) and $optype != UU_ADDNEW and $optype != UU_ADDINC);
+ $allowrenames = (!empty($formdata->uuallowrenames) and $optype != UU_ADDNEW and $optype != UU_ADDINC);
+ $allowdeletes = (!empty($formdata->uuallowdeletes) and $optype != UU_ADDNEW and $optype != UU_ADDINC);
+ $updatetype = isset($formdata->uuupdatetype) ? $formdata->uuupdatetype : 0;
+ $bulk = $formdata->uubulk;
+ $noemailduplicates = $formdata->uunoemailduplicates;
// verification moved to two places: after upload and into form2
$usersnew = 0;
continue;
}
- if ($olduser = get_record('user', 'username', addslashes($oldusername), 'mnethostid', $user->mnethostid)) {
+ if ($olduser = get_record('user', 'username', addslashes($oldusername), 'mnethostid', addslashes($user->mnethostid))) {
$upt->track('id', $olduser->id, 'normal', false);
if (has_capability('moodle/site:doanything', $systemcontext, $olduser->id)) {
$upt->track('status', $strusernotrenamedadmin, 'error');
continue;
}
if ($existinguser->$column !== $user->$column) {
+ if ($column == 'email') {
+ if (record_exists('user', 'email', addslashes($user->email))) {
+ if ($noemailduplicates) {
+ $upt->track('email', $stremailduplicate, 'error');
+ $upt->track('status', $strusernotupdated, 'error');
+ $userserrors++;
+ continue 2;
+ } else {
+ $upt->track('email', $stremailduplicate, 'warning');
+ }
+ }
+ }
if ($column != 'password' and in_array($column, $upt->columns)) {
$upt->track($column, '', 'normal', false); // clear previous
$upt->track($column, $existinguser->$column.'-->'.$user->$column, 'info');
}
}
+ if (record_exists('user', 'email', addslashes($user->email))) {
+ if ($noemailduplicates) {
+ $upt->track('email', $stremailduplicate, 'error');
+ $upt->track('status', $strusernotaddederror, 'error');
+ $userserrors++;
+ continue;
+ } else {
+ $upt->track('email', $stremailduplicate, 'warning');
+ }
+ }
+
if ($user->id = insert_record('user', addslashes_recursive($user))) {
$info = ': ' . $user->username .' (ID = ' . $user->id . ')';
$upt->track('status', $struseradded);
$shortname = $user->{'course'.$i};
if (!array_key_exists($shortname, $ccache)) {
- if (!$course = get_record('course', 'shortname', $shortname, '', '', '', '', 'id, shortname, defaultrole')) {
+ if (!$course = get_record('course', 'shortname', addslashes($shortname), '', '', '', '', 'id, shortname, defaultrole')) {
$upt->track('enrolments', get_string('unknowncourse', 'error', $shortname), 'error');
continue;
}
$username = $matches[1][0].($matches[2][0]+1);
}
- if (record_exists('user', 'username', addslashes($username), 'mnethostid', $mnethostid)) {
+ if (record_exists('user', 'username', addslashes($username), 'mnethostid', addslashes($mnethostid))) {
return increment_username($username, $mnethostid);
} else {
return $username;
$choices = array(0 => get_string('infilefield', 'auth'), 1 => get_string('createpasswordifneeded', 'auth'));
$mform->addElement('select', 'uupasswordnew', get_string('uupasswordnew', 'admin'), $choices);
+ $mform->setDefault('uupasswordnew', 0);
$mform->disabledIf('uupasswordnew', 'uutype', 'eq', UU_UPDATE);
$choices = array(0 => get_string('nochanges', 'admin'),
2 => get_string('uuupdateall', 'admin'),
3 => get_string('uuupdatemissing', 'admin'));
$mform->addElement('select', 'uuupdatetype', get_string('uuupdatetype', 'admin'), $choices);
+ $mform->setDefault('uuupdatetype', 0);
$mform->disabledIf('uuupdatetype', 'uutype', 'eq', UU_ADDNEW);
$mform->disabledIf('uuupdatetype', 'uutype', 'eq', UU_ADDINC);
$choices = array(0 => get_string('nochanges', 'admin'), 1 => get_string('update'));
$mform->addElement('select', 'uupasswordold', get_string('uupasswordold', 'admin'), $choices);
+ $mform->setDefault('uupasswordold', 0);
$mform->disabledIf('uupasswordold', 'uutype', 'eq', UU_ADDNEW);
$mform->disabledIf('uupasswordold', 'uutype', 'eq', UU_ADDINC);
$mform->disabledIf('uupasswordold', 'uuupdatetype', 'eq', 0);
$mform->disabledIf('uupasswordold', 'uuupdatetype', 'eq', 3);
$mform->addElement('selectyesno', 'uuallowrenames', get_string('allowrenames', 'admin'));
+ $mform->setDefault('uuallowrenames', 0);
$mform->disabledIf('uuallowrenames', 'uutype', 'eq', UU_ADDNEW);
$mform->disabledIf('uuallowrenames', 'uutype', 'eq', UU_ADDINC);
$mform->addElement('selectyesno', 'uuallowdeletes', get_string('allowdeletes', 'admin'));
+ $mform->setDefault('uuallowdeletes', 0);
$mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_ADDNEW);
$mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_ADDINC);
+ $mform->addElement('selectyesno', 'uunoemailduplicates', get_string('uunoemailduplicates', 'admin'));
+ $mform->setDefault('uunoemailduplicates', 0);
+
$choices = array(0 => get_string('no'),
1 => get_string('uubulknew', 'admin'),
2 => get_string('uubulkupdated', 'admin'),
3 => get_string('uubulkall', 'admin'));
$mform->addElement('select', 'uubulk', get_string('uubulk', 'admin'), $choices);
+ $mform->setDefault('uubulk', 0);
// roles selection
$showroles = false;