From 05cee784896f76d7a0098bf1a879bbf163378d6e Mon Sep 17 00:00:00 2001 From: MichPound Date: Thu, 17 Jun 2021 12:03:37 +0100 Subject: [PATCH] TW17177714, added in check for incorrect delimiters --- lang/en/block_badgeawarder.php | 3 ++- processor.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lang/en/block_badgeawarder.php b/lang/en/block_badgeawarder.php index 2e57929..ca4a726 100644 --- a/lang/en/block_badgeawarder.php +++ b/lang/en/block_badgeawarder.php @@ -41,9 +41,10 @@ $string['selectcountry'] = 'Select Default Country'; $string['csv'] = 'The badge CSV file'; $string['csvdelimiter'] = 'CSV delimiter'; +$string['csvdelimitererror'] = 'Incorrect field delimiter detected.'; $string['csvfileerror'] = 'There was an error in your CSV upload file'; $string['csvformaterror'] = '
The CSV manager failed to find all required fields, The BadgeAwarder requires -the fields firstname, lastname, badge, email on the first row.
If you receive this message either one of these fields were missing or you have not chosen the correct field delimiter.'; +the fields firstname, lastname, badge, email on the first row.
If you receive this message one of these fields were missing.'; $string['csvline'] = 'CSV line'; $string['defaultuploadtype'] = 'Default upload type'; $string['defaultdelimiter'] = 'Default delimiter'; diff --git a/processor.php b/processor.php index e3ebf61..5ec4d36 100644 --- a/processor.php +++ b/processor.php @@ -600,6 +600,20 @@ public function reset() { protected function validate() { global $COURSE; foreach ($this->filecolumns as $requiredcolumn) { + + foreach ($this->columns as $test) { + // Checks that the columns do not still contain delimiters. + // If they still contain delimiters this means the wrong delimiter was used. + $delimiters = array(',', ';', ':', '\t'); + foreach ($delimiters as $delimiter) { + if (strpos($test, $delimiter)){ + $returnlink = new moodle_url('/course/view.php', array('id' => $COURSE->id)); + throw new moodle_exception('csvloaderror', 'error', + $returnlink, get_string('csvdelimitererror', 'block_badgeawarder'), ''); + } + } + } + if (!in_array($requiredcolumn, $this->columns)) { $returnlink = new moodle_url('/course/view.php', array('id' => $COURSE->id)); throw new moodle_exception('csvloaderror', 'error',