From 8fb24d2b435852865c72a2b2f508e6dea5d7da87 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 13 Nov 2013 17:25:48 -0800 Subject: [PATCH] MDL-42547 tool_uploaduser: trim values before uploading users --- admin/tool/uploaduser/index.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/admin/tool/uploaduser/index.php b/admin/tool/uploaduser/index.php index ae0bd0ad6ba..c366d033eaf 100644 --- a/admin/tool/uploaduser/index.php +++ b/admin/tool/uploaduser/index.php @@ -231,10 +231,10 @@ if ($formdata = $mform2->is_cancelled()) { $user->$key['text'] = $value; $user->$key['format'] = FORMAT_MOODLE; } else { - $user->$key = $value; + $user->$key = trim($value); } } else { - $user->$key = $value; + $user->$key = trim($value); } if (in_array($key, $upt->columns)) { @@ -870,6 +870,7 @@ if ($formdata = $mform2->is_cancelled()) { if ($rid) { // find duration $timeend = 0; + if (!empty($user->{'enrolperiod'.$i})) { $duration = (int)$user->{'enrolperiod'.$i} * 60*60*24; // convert days to seconds if ($duration > 0) { // sanity check @@ -1001,7 +1002,7 @@ while ($linenum <= $previewrows and $fields = $cir->next()) { $rowcols = array(); $rowcols['line'] = $linenum; foreach($fields as $key => $field) { - $rowcols[$filecolumns[$key]] = s($field); + $rowcols[$filecolumns[$key]] = s(trim($field)); } $rowcols['status'] = array(); @@ -1027,7 +1028,7 @@ while ($linenum <= $previewrows and $fields = $cir->next()) { } if (isset($rowcols['city'])) { - $rowcols['city'] = trim($rowcols['city']); + $rowcols['city'] = $rowcols['city']; if (empty($rowcols['city'])) { $rowcols['status'][] = get_string('fieldrequired', 'error', 'city'); }