dolibarr 23.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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26if (!defined('NOTOKENRENEWAL')) {
27 define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
28}
29
30
53function llxHeader($head = '', $title = '', $help_url = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $morequerystring = '', $morecssonbody = '', $replacemainareaby = '', $disablenofollow = 0, $disablenoindex = 0) // @phan-suppress-current-line PhanRedefineFunction
54{
55 print '<html><title>Build an import example file</title><body>';
56}
57
68function llxFooter($comment = '', $zone = 'private', $disabledoutputofmessages = 0) // @phan-suppress-current-line PhanRedefineFunction
69{
70 print '</body></html>';
71}
72
73// Load Dolibarr environment
74require '../main.inc.php';
75require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
76require_once DOL_DOCUMENT_ROOT.'/imports/class/import.class.php';
77require_once DOL_DOCUMENT_ROOT.'/core/modules/import/modules_import.php';
78
87$datatoimport = GETPOST('datatoimport');
88$format = GETPOST('format');
89
90// Load translation files required by the page
91$langs->load("exports");
92
93// Check exportkey
94if (empty($datatoimport)) {
95 $user->loadRights();
96
97 llxHeader();
98 print '<div class="error">Bad value for datatoimport.</div>';
99 llxFooter();
100 exit;
101}
102
103
104$filename = $langs->transnoentitiesnoconv("ExampleOfImportFile").'_'.$datatoimport.'.'.$format;
105
106$objimport = new Import($db);
107$objimport->load_arrays($user, $datatoimport);
108// Load arrays from descriptor module
109$fieldstarget = $objimport->array_import_fields[0];
110$valuestarget = $objimport->array_import_examplevalues[0];
111
112$attachment = true;
113if (GETPOSTISSET("attachment")) {
114 $attachment = GETPOST("attachment");
115}
116//$attachment = false;
117$contenttype = dol_mimetype($format);
118if (GETPOSTISSET("contenttype")) {
119 $contenttype = GETPOST("contenttype");
120}
121//$contenttype='text/plain';
122$outputencoding = 'UTF-8';
123
124if ($contenttype) {
125 header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
126}
127if ($attachment) {
128 header('Content-Disposition: attachment; filename="'.$filename.'"');
129}
130
131
132// List of targets fields
133$headerlinefields = array(); // Array of fields (label to show)
134$contentlinevalues = array(); // Array of example values
135$i = 0;
136foreach ($fieldstarget as $code => $label) {
137 $withoutstar = preg_replace('/\*/', '', $fieldstarget[$code]);
138 $headerlinefields[] = $langs->transnoentities($withoutstar).($withoutstar != $fieldstarget[$code] ? '*' : '').' ('.$code.')';
139 $contentlinevalues[] = (isset($valuestarget[$code]) ? $valuestarget[$code] : '');
140}
141//var_dump($headerlinefields);
142//var_dump($contentlinevalues);
143
144print $objimport->build_example_file($format, $headerlinefields, $contentlinevalues, $datatoimport);
Class to manage imports.
if(!defined( 'NOTOKENRENEWAL')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
This file is a wrapper, so empty header.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
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.