MDL-18247 Merged from MOODLE_19_STABLE

This commit is contained in:
nicolasconnault 2009-02-17 07:25:24 +00:00
parent 1bd66f3914
commit 233ae5a323

View file

@ -32,6 +32,8 @@ $id = required_param('id', PARAM_INT); // course id
$separator = optional_param('separator', '', PARAM_ALPHA); $separator = optional_param('separator', '', PARAM_ALPHA);
$verbosescales = optional_param('verbosescales', 1, PARAM_BOOL); $verbosescales = optional_param('verbosescales', 1, PARAM_BOOL);
define('GRADE_CSV_LINE_LENGTH', 4096);
if (!$course = $DB->get_record('course', array('id'=>$id))) { if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid'); print_error('nocourseid');
} }
@ -84,7 +86,7 @@ if ($id) {
if ($importcode = optional_param('importcode', '', PARAM_FILE)) { if ($importcode = optional_param('importcode', '', PARAM_FILE)) {
$filename = $CFG->dataroot.'/temp/gradeimport/cvs/'.$USER->id.'/'.$importcode; $filename = $CFG->dataroot.'/temp/gradeimport/cvs/'.$USER->id.'/'.$importcode;
$fp = fopen($filename, "r"); $fp = fopen($filename, "r");
$header = split($csv_delimiter, fgets($fp,1024), PARAM_RAW); $header = split($csv_delimiter, fgets($fp,GRADE_CSV_LINE_LENGTH), PARAM_RAW);
} }
$mform2 = new grade_import_mapping_form(null, array('gradeitems'=>$gradeitems, 'header'=>$header)); $mform2 = new grade_import_mapping_form(null, array('gradeitems'=>$gradeitems, 'header'=>$header));
@ -123,7 +125,7 @@ if ($formdata = $mform->get_data()) {
$fp = fopen($filename, "r"); $fp = fopen($filename, "r");
// --- get header (field names) --- // --- get header (field names) ---
$header = split($csv_delimiter, fgets($fp,1024), PARAM_RAW); $header = split($csv_delimiter, fgets($fp,GRADE_CSV_LINE_LENGTH), PARAM_RAW);
// print some preview // print some preview
$numlines = 0; // 0 preview lines displayed $numlines = 0; // 0 preview lines displayed
@ -137,7 +139,7 @@ if ($formdata = $mform->get_data()) {
} }
echo '</tr>'; echo '</tr>';
while (!feof ($fp) && $numlines <= $formdata->previewrows) { while (!feof ($fp) && $numlines <= $formdata->previewrows) {
$lines = split($csv_delimiter, fgets($fp,1024)); $lines = split($csv_delimiter, fgets($fp,GRADE_CSV_LINE_LENGTH));
echo '<tr>'; echo '<tr>';
foreach ($lines as $line) { foreach ($lines as $line) {
echo '<td>'.$line.'</td>';; echo '<td>'.$line.'</td>';;
@ -166,7 +168,7 @@ if ($formdata = $mform->get_data()) {
if ($fp = fopen($filename, "r")) { if ($fp = fopen($filename, "r")) {
// --- get header (field names) --- // --- get header (field names) ---
$header = split($csv_delimiter, clean_param(fgets($fp,1024), PARAM_RAW)); $header = split($csv_delimiter, clean_param(fgets($fp,GRADE_CSV_LINE_LENGTH), PARAM_RAW));
foreach ($header as $i => $h) { foreach ($header as $i => $h) {
$h = trim($h); $header[$i] = $h; // remove whitespace $h = trim($h); $header[$i] = $h; // remove whitespace
@ -214,14 +216,14 @@ if ($formdata = $mform->get_data()) {
if ($fp = fopen($filename, "r")) { if ($fp = fopen($filename, "r")) {
// read the first line makes sure this doesn't get read again // read the first line makes sure this doesn't get read again
$header = split($csv_delimiter, fgets($fp,1024)); $header = split($csv_delimiter, fgets($fp,GRADE_CSV_LINE_LENGTH));
$newgradeitems = array(); // temporary array to keep track of what new headers are processed $newgradeitems = array(); // temporary array to keep track of what new headers are processed
$status = true; $status = true;
while (!feof ($fp)) { while (!feof ($fp)) {
// add something // add something
$line = split($csv_delimiter, fgets($fp,1024)); $line = split($csv_delimiter, fgets($fp,GRADE_CSV_LINE_LENGTH));
if(count($line) <= 1){ if(count($line) <= 1){
// there is no data on this line, move on // there is no data on this line, move on