} // Set up the import form. $mform = new grade_import_form(null, array('includeseparator' => true, 'verbosescales' => true)); // If the csv file hasn't been imported yet then look for a form submission or // show the initial submission form. if (!$iid) { // If the import form has been submitted. if ($formdata = $mform->get_data()) { // Large files are likely to take their time and memory. Let PHP know // that we'll take longer, and that the process should be recycled soon // to free up memory. core_php_time_limit::raise(); raise_memory_limit(MEMORY_EXTRA); // Use current (non-conflicting) time stamp. $importcode = get_new_importcode(); $text = $mform->get_file_content('userfile'); $iid = csv_import_reader::get_new_iid('grade'); $csvimport = new csv_import_reader($iid, 'grade'); $csvimport->load_csv_content($text, $formdata->encoding, $separator); // --- get header (field names) --- $header = $csvimport->get_columns(); // Print a preview of the data. $numlines = 0; // 0 lines previewed so far. echo $OUTPUT->heading(get_string('importpreview', 'grades')); foreach ($header as $i => $h) { $h = trim($h); // Remove whitespace. $h = clean_param($h, PARAM_RAW); // Clean the header. $header[$i] = $h;