dolibarr 21.0.0-alpha
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
74$datatoimport = GETPOST('datatoimport');
75$format = GETPOST('format');
76
77// Load translation files required by the page
78$langs->load("exports");
79
80// Check exportkey
81if (empty($datatoimport)) {
82 $user->loadRights();
83
84 llxHeader();
85 print '<div class="error">Bad value for datatoimport.</div>';
86 llxFooter();
87 exit;
88}
89
90
91$filename = $langs->transnoentitiesnoconv("ExampleOfImportFile").'_'.$datatoimport.'.'.$format;
92
93$objimport = new Import($db);
94$objimport->load_arrays($user, $datatoimport);
95// Load arrays from descriptor module
96$fieldstarget = $objimport->array_import_fields[0];
97$valuestarget = $objimport->array_import_examplevalues[0];
98
99$attachment = true;
100if (GETPOSTISSET("attachment")) {
101 $attachment = GETPOST("attachment");
102}
103//$attachment = false;
104$contenttype = dol_mimetype($format);
105if (GETPOSTISSET("contenttype")) {
106 $contenttype = GETPOST("contenttype");
107}
108//$contenttype='text/plain';
109$outputencoding = 'UTF-8';
110
111if ($contenttype) {
112 header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
113}
114if ($attachment) {
115 header('Content-Disposition: attachment; filename="'.$filename.'"');
116}
117
118
119// List of targets fields
120$headerlinefields = array(); // Array of fields (label to show)
121$contentlinevalues = array(); // Array of example values
122$i = 0;
123foreach ($fieldstarget as $code => $label) {
124 $withoutstar = preg_replace('/\*/', '', $fieldstarget[$code]);
125 $headerlinefields[] = $langs->transnoentities($withoutstar).($withoutstar != $fieldstarget[$code] ? '*' : '').' ('.$code.')';
126 $contentlinevalues[] = (isset($valuestarget[$code]) ? $valuestarget[$code] : '');
127}
128//var_dump($headerlinefields);
129//var_dump($contentlinevalues);
130
131print $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.