Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 124... Línea 124...
124
        fseek($fp, 0);
124
        fseek($fp, 0);
125
        // Create an array to store the imported data for error checking.
125
        // Create an array to store the imported data for error checking.
126
        $columns = array();
126
        $columns = array();
127
        // str_getcsv doesn't iterate through the csv data properly. It has
127
        // str_getcsv doesn't iterate through the csv data properly. It has
128
        // problems with line returns.
128
        // problems with line returns.
129
        while ($fgetdata = fgetcsv($fp, 0, $csv_delimiter, $enclosure)) {
129
        while ($fgetdata = fgetcsv($fp, 0, $csv_delimiter, $enclosure, '\\')) {
130
            // Check to see if we have an empty line.
130
            // Check to see if we have an empty line.
131
            if (count($fgetdata) == 1) {
131
            if (count($fgetdata) == 1) {
132
                if ($fgetdata[0] !== null) {
132
                if ($fgetdata[0] !== null) {
133
                    // The element has data. Add it to the array.
133
                    // The element has data. Add it to the array.
134
                    $columns[] = $fgetdata;
134
                    $columns[] = $fgetdata;
Línea 202... Línea 202...
202
        $filename = $CFG->tempdir.'/csvimport/'.$this->_type.'/'.$USER->id.'/'.$this->_iid;
202
        $filename = $CFG->tempdir.'/csvimport/'.$this->_type.'/'.$USER->id.'/'.$this->_iid;
203
        if (!file_exists($filename)) {
203
        if (!file_exists($filename)) {
204
            return false;
204
            return false;
205
        }
205
        }
206
        $fp = fopen($filename, "r");
206
        $fp = fopen($filename, "r");
207
        $line = fgetcsv($fp);
207
        $line = fgetcsv($fp, escape: '\\');
208
        fclose($fp);
208
        fclose($fp);
209
        if ($line === false) {
209
        if ($line === false) {
210
            return false;
210
            return false;
211
        }
211
        }
212
        $this->_columns = $line;
212
        $this->_columns = $line;
Línea 232... Línea 232...
232
        }
232
        }
233
        if (!$this->_fp = fopen($filename, "r")) {
233
        if (!$this->_fp = fopen($filename, "r")) {
234
            return false;
234
            return false;
235
        }
235
        }
236
        //skip header
236
        //skip header
237
        return (fgetcsv($this->_fp) !== false);
237
        return (fgetcsv($this->_fp, escape: '\\') !== false);
238
    }
238
    }
Línea 239... Línea 239...
239
 
239
 
240
    /**
240
    /**
241
     * Get next line
241
     * Get next line
Línea 244... Línea 244...
244
     */
244
     */
245
    public function next() {
245
    public function next() {
246
        if (empty($this->_fp) or feof($this->_fp)) {
246
        if (empty($this->_fp) or feof($this->_fp)) {
247
            return false;
247
            return false;
248
        }
248
        }
249
        if ($ser = fgetcsv($this->_fp)) {
249
        if ($ser = fgetcsv($this->_fp, escape: '\\')) {
250
            return $ser;
250
            return $ser;
251
        } else {
251
        } else {
252
            return false;
252
            return false;
253
        }
253
        }
254
    }
254
    }
Línea 447... Línea 447...
447
            if ($this->bom) {
447
            if ($this->bom) {
448
                fputs($this->fp, core_text::UTF8_BOM);
448
                fputs($this->fp, core_text::UTF8_BOM);
449
            }
449
            }
450
        }
450
        }
451
        $delimiter = csv_import_reader::get_delimiter($this->delimiter);
451
        $delimiter = csv_import_reader::get_delimiter($this->delimiter);
452
        fputcsv($this->fp, $row, $delimiter, $this->csvenclosure);
452
        fputcsv($this->fp, $row, $delimiter, $this->csvenclosure, '\\');
453
    }
453
    }
Línea 454... Línea 454...
454
 
454
 
455
    /**
455
    /**
456
     * Echos or returns a csv data line by line for displaying.
456
     * Echos or returns a csv data line by line for displaying.