/** * Display Sample * * @param $model PluginDatainjectionModel object **/ function showSample(PluginDatainjectionModel $model) { $headers = PluginDatainjectionMapping::getMappingsSortedByRank($model->fields['id']); $sample = '"' . implode('"' . $this->getDelimiter() . '"', $headers) . "\"\n"; header('Content-disposition: attachment; filename="' . str_replace(' ', '_', $model->getName()) . '.csv"'); header('Content-Type: text/comma-separated-values'); header('Content-Transfer-Encoding: UTF-8'); header('Content-Length: ' . mb_strlen($sample, 'UTF-8')); header('Pragma: no-cache'); header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); header('Expires: 0'); echo $sample; }
static function exportErrorsInCSV() { $error_lines = json_decode(PluginDatainjectionSession::getParam('error_lines'), true); self::stripslashes_array($error_lines); if (!empty($error_lines)) { $model = unserialize(PluginDatainjectionSession::getParam('currentmodel')); $file = PLUGIN_DATAINJECTION_UPLOAD_DIR . PluginDatainjectionSession::getParam('file_name'); $mappings = $model->getMappings(); $tmpfile = fopen($file, 'w'); //If headers present if ($model->getBackend()->isHeaderPresent()) { $headers = PluginDatainjectionMapping::getMappingsSortedByRank($model->fields['id']); fputcsv($tmpfile, $headers, $model->getBackend()->getDelimiter()); } //Write lines foreach ($error_lines as $line) { fputcsv($tmpfile, $line, $model->getBackend()->getDelimiter()); } fclose($tmpfile); $name = "Error-" . PluginDatainjectionSession::getParam('file_name'); $name = str_replace(' ', '', $name); header('Content-disposition: attachment; filename=' . $name); header('Content-Type: application/octet-stream'); header('Content-Transfer-Encoding: fichier'); header('Content-Length: ' . filesize($file)); header('Pragma: no-cache'); header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); header('Expires: 0'); readfile($file); unlink($file); } }