$previewdata = array(); while ($numlines <= $formdata->previewrows) { $lines = $csvimport->next(); if ($lines) { $previewdata[] = $lines; } $numlines++; } $table->data = $previewdata; echo html_writer::table($table); } else { // Display the standard upload file form. groups_print_course_menu($course, 'index.php?id=' . $id); echo html_writer::start_tag('div', array('class' => 'clearer')); echo html_writer::end_tag('div'); $mform->display(); echo $OUTPUT->footer(); die; } } // Data has already been submitted so we can use the $iid to retrieve it. $csvimport = new csv_import_reader($iid, 'grade'); $header = $csvimport->get_columns(); // we create a form to handle mapping data from the file to the database. $mform2 = new grade_import_mapping_form(null, array('gradeitems' => $gradeitems, 'header' => $header)); $mform2->set_data(array('iid' => $iid, 'id' => $id, 'importcode' => $importcode, 'verbosescales' => $verbosescales)); // Here, if we have data, we process the fields and enter the information into the database. if ($formdata = $mform2->get_data()) { foreach ($header as $i => $h) { $h = trim($h); // Remove whitespace.