dolibarr  16.0.5
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 
24 if (!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 
35 function llxHeader()
36 {
37  print '<html><title>Build an import example file</title><body>';
38 }
39 
46 function llxFooter()
47 {
48  print '</body></html>';
49 }
50 
51 require '../main.inc.php';
52 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
53 require_once DOL_DOCUMENT_ROOT.'/imports/class/import.class.php';
54 require_once DOL_DOCUMENT_ROOT.'/core/modules/import/modules_import.php';
55 
56 $datatoimport = GETPOST('datatoimport');
57 $format = GETPOST('format');
58 
59 // Load translation files required by the page
60 $langs->load("exports");
61 
62 // Check exportkey
63 if (empty($datatoimport)) {
64  $user->getrights();
65 
66  llxHeader();
67  print '<div class="error">Bad value for datatoimport.</div>';
68  llxFooter();
69  exit;
70 }
71 
72 
73 $filename = $langs->trans("ExampleOfImportFile").'_'.$datatoimport.'.'.$format;
74 
75 $objimport = new Import($db);
76 $objimport->load_arrays($user, $datatoimport);
77 // Load arrays from descriptor module
78 $fieldstarget = $objimport->array_import_fields[0];
79 $valuestarget = $objimport->array_import_examplevalues[0];
80 
81 $attachment = true;
82 if (isset($_GET["attachment"])) {
83  $attachment = $_GET["attachment"];
84 }
85 //$attachment = false;
86 $contenttype = dol_mimetype($format);
87 if (isset($_GET["contenttype"])) {
88  $contenttype = $_GET["contenttype"];
89 }
90 //$contenttype='text/plain';
91 $outputencoding = 'UTF-8';
92 
93 if ($contenttype) {
94  header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
95 }
96 if ($attachment) {
97  header('Content-Disposition: attachment; filename="'.$filename.'"');
98 }
99 
100 
101 // List of targets fields
102 $headerlinefields = array(); // Array of fields (label to show)
103 $contentlinevalues = array(); // Array of example values
104 $i = 0;
105 foreach ($fieldstarget as $code => $label) {
106  $withoutstar = preg_replace('/\*/', '', $fieldstarget[$code]);
107  $headerlinefields[] = $langs->transnoentities($withoutstar).($withoutstar != $fieldstarget[$code] ? '*' : '').' ('.$code.')';
108  $contentlinevalues[] = (isset($valuestarget[$code]) ? $valuestarget[$code] : '');
109 }
110 //var_dump($headerlinefields);
111 //var_dump($contentlinevalues);
112 
113 print $objimport->build_example_file($format, $headerlinefields, $contentlinevalues, $datatoimport);
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
Import
Class to manage imports.
Definition: import.class.php:30
dol_mimetype
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
Definition: functions.lib.php:9741
llxFooter
llxFooter()
This file is a wrapper, so empty footer.
Definition: emptyexample.php:46
llxHeader
if(!defined('NOTOKENRENEWAL')) llxHeader()
This file is a wrapper, so empty header.
Definition: emptyexample.php:35