dolibarr 19.0.3
emptyexample.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2009-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24if (!defined('NOTOKENRENEWAL')) {
25 define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
26}
27
28
35function llxHeader()
36{
37 print '<html><title>Build an import example file</title><body>';
38}
39
46function llxFooter()
47{
48 print '</body></html>';
49}
50
51// Load Dolibarr environment
52require '../main.inc.php';
53require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
54require_once DOL_DOCUMENT_ROOT.'/imports/class/import.class.php';
55require_once DOL_DOCUMENT_ROOT.'/core/modules/import/modules_import.php';
56
57$datatoimport = GETPOST('datatoimport');
58$format = GETPOST('format');
59
60// Load translation files required by the page
61$langs->load("exports");
62
63// Check exportkey
64if (empty($datatoimport)) {
65 $user->getrights();
66
67 llxHeader();
68 print '<div class="error">Bad value for datatoimport.</div>';
69 llxFooter();
70 exit;
71}
72
73
74$filename = $langs->trans("ExampleOfImportFile").'_'.$datatoimport.'.'.$format;
75
76$objimport = new Import($db);
77$objimport->load_arrays($user, $datatoimport);
78// Load arrays from descriptor module
79$fieldstarget = $objimport->array_import_fields[0];
80$valuestarget = $objimport->array_import_examplevalues[0];
81
82$attachment = true;
83if (isset($_GET["attachment"])) {
84 $attachment = $_GET["attachment"];
85}
86//$attachment = false;
87$contenttype = dol_mimetype($format);
88if (isset($_GET["contenttype"])) {
89 $contenttype = $_GET["contenttype"];
90}
91//$contenttype='text/plain';
92$outputencoding = 'UTF-8';
93
94if ($contenttype) {
95 header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
96}
97if ($attachment) {
98 header('Content-Disposition: attachment; filename="'.$filename.'"');
99}
100
101
102// List of targets fields
103$headerlinefields = array(); // Array of fields (label to show)
104$contentlinevalues = array(); // Array of example values
105$i = 0;
106foreach ($fieldstarget as $code => $label) {
107 $withoutstar = preg_replace('/\*/', '', $fieldstarget[$code]);
108 $headerlinefields[] = $langs->transnoentities($withoutstar).($withoutstar != $fieldstarget[$code] ? '*' : '').' ('.$code.')';
109 $contentlinevalues[] = (isset($valuestarget[$code]) ? $valuestarget[$code] : '');
110}
111//var_dump($headerlinefields);
112//var_dump($contentlinevalues);
113
114print $objimport->build_example_file($format, $headerlinefields, $contentlinevalues, $datatoimport);
Class to manage imports.
if(!defined( 'NOTOKENRENEWAL')) llxHeader()
This file is a wrapper, so empty header.
llxFooter()
This file is a wrapper, so empty footer.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.