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