if (!empty($grade_item->itemmodule)) { $displaystring = get_string('modulename', $grade_item->itemmodule) . get_string('labelsep', 'langconfig') . $grade_item->get_name(); } else { $displaystring = $grade_item->get_name(); } $gradeitems[$grade_item->id] = $displaystring; } } } // 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;
$PAGE->set_pagelayout('admin'); if (!($course = $DB->get_record('course', array('id' => $id)))) { print_error('nocourseid'); } require_login($course); $context = get_context_instance(CONTEXT_COURSE, $id); require_capability('moodle/grade:import', $context); require_capability('gradeimport/xml:view', $context); // print header $strgrades = get_string('grades', 'grades'); $actionstr = get_string('pluginname', 'gradeimport_xml'); if (!empty($CFG->gradepublishing)) { $CFG->gradepublishing = has_capability('gradeimport/xml:publish', $context); } $mform = new grade_import_form(); if ($data = $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. @set_time_limit(0); raise_memory_limit(MEMORY_EXTRA); if ($text = $mform->get_file_content('userfile')) { print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades')); $error = ''; $importcode = import_xml_grades($text, $course, $error); if ($importcode) { grade_import_commit($id, $importcode, $data->feedback, true); echo $OUTPUT->footer(); die; } else { echo $OUTPUT->notification($error);