mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +02:00
Merge branch 'w16_MDL-17344_m21_uploadprof' of git://github.com/skodak/moodle
This commit is contained in:
commit
e62ea95dfc
1 changed files with 32 additions and 14 deletions
|
@ -157,14 +157,14 @@ class uu_progress_tracker {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validation callback function - verified the column line of csv file.
|
* Validation callback function - verified the column line of csv file.
|
||||||
* Converts column names to lowercase too.
|
* Converts standard column names to lowercase.
|
||||||
* @param csv_import_reader $cir
|
* @param csv_import_reader $cir
|
||||||
* @param array standard user fields
|
* @param array $stdfields standard user fields
|
||||||
* @param array custom profile fields
|
* @param array $profilefields custom profile fields
|
||||||
* @param moodle_url $returnurl return url in case of any error
|
* @param moodle_url $returnurl return url in case of any error
|
||||||
* @return array list of fields
|
* @return array list of fields
|
||||||
*/
|
*/
|
||||||
function uu_validate_user_upload_columns(csv_import_reader $cir, $stdfields, $frofilefields, moodle_url $returnurl) {
|
function uu_validate_user_upload_columns(csv_import_reader $cir, $stdfields, $profilefields, moodle_url $returnurl) {
|
||||||
$columns = $cir->get_columns();
|
$columns = $cir->get_columns();
|
||||||
|
|
||||||
if (empty($columns)) {
|
if (empty($columns)) {
|
||||||
|
@ -178,22 +178,40 @@ function uu_validate_user_upload_columns(csv_import_reader $cir, $stdfields, $fr
|
||||||
print_error('csvfewcolumns', 'error', $returnurl);
|
print_error('csvfewcolumns', 'error', $returnurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$textlib = textlib_get_instance(); // profile fields may contain unicode chars
|
||||||
|
|
||||||
// test columns
|
// test columns
|
||||||
$processed = array();
|
$processed = array();
|
||||||
foreach ($columns as $key=>$unused) {
|
foreach ($columns as $key=>$unused) {
|
||||||
$field = strtolower($columns[$key]); // no unicode expected here, ignore case
|
$field = $columns[$key];
|
||||||
if (!in_array($field, $stdfields) && !in_array($field, $frofilefields) &&// if not a standard field and not an enrolment field, then we have an error
|
$lcfield = $textlib->strtolower($field);
|
||||||
!preg_match('/^course\d+$/', $field) && !preg_match('/^group\d+$/', $field) &&
|
if (in_array($field, $stdfields) or in_array($lcfield, $stdfields)) {
|
||||||
!preg_match('/^type\d+$/', $field) && !preg_match('/^role\d+$/', $field) &&
|
// standard fields are only lowercase
|
||||||
!preg_match('/^enrolperiod\d+$/', $field)) {
|
$newfield = $lcfield;
|
||||||
print_error('invalidfieldname', 'error', $returnurl, $field);
|
|
||||||
}
|
} else if (in_array($field, $profilefields)) {
|
||||||
if (in_array($field, $processed)) {
|
// exact profile field name match - these are case sensitive
|
||||||
|
$newfield = $field;
|
||||||
|
|
||||||
|
} else if (in_array($lcfield, $profilefields)) {
|
||||||
|
// hack: somebody wrote uppercase in csv file, but the system knows only lowercase profile field
|
||||||
|
$newfield = $lcfield;
|
||||||
|
|
||||||
|
} else if (preg_match('/^(course|group|type|role|enrolperiod)\d+$/', $lcfield)) {
|
||||||
|
// special fields for enrolments
|
||||||
|
$newfield = $lcfield;
|
||||||
|
|
||||||
|
} else {
|
||||||
$cir->close();
|
$cir->close();
|
||||||
$cir->cleanup();
|
$cir->cleanup();
|
||||||
print_error('duplicatefieldname', 'error', $returnurl, $field);
|
print_error('invalidfieldname', 'error', $returnurl, $field);
|
||||||
}
|
}
|
||||||
$processed[$key] = $field;
|
if (in_array($newfield, $processed)) {
|
||||||
|
$cir->close();
|
||||||
|
$cir->cleanup();
|
||||||
|
print_error('duplicatefieldname', 'error', $returnurl, $newfield);
|
||||||
|
}
|
||||||
|
$processed[$key] = $newfield;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $processed;
|
return $processed;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue