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