dolibarr/htdocs/imports/emptyexample.php

145 lines
5.4 KiB
PHP
Raw Permalink Normal View History

2009-09-07 23:14:21 +02:00
<?php
/* Copyright (C) 2009-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
2025-02-03 13:37:43 +01:00
* Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
2009-09-07 23:14:21 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
2009-09-07 23:14:21 +02:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2009-09-07 23:14:21 +02:00
*/
/**
2009-09-08 01:49:16 +02:00
* \file htdocs/imports/emptyexample.php
2009-09-07 23:14:21 +02:00
* \ingroup import
2009-09-08 01:49:16 +02:00
* \brief Show example of import file
2009-09-07 23:14:21 +02:00
*/
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
}
2020-05-30 02:27:10 +02:00
/**
* This file is a wrapper, so empty header
*
* Note: also called by functions.lib:recordNotFound
*
* @param string $head Optional head lines
* @param string $title HTML title
* @param string $help_url Url links to help page
* Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage|DE:GermanPage
* For other external page: http://server/url
* @param string $target Target to use on links
* @param int $disablejs More content into html header
* @param int $disablehead More content into html header
2024-10-27 00:34:44 +02:00
* @param string[]|string $arrayofjs Array of complementary js files
* @param string[]|string $arrayofcss Array of complementary css files
* @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails)
* @param string $morecssonbody More CSS on body tag. For example 'classforhorizontalscrolloftabs'.
* @param string $replacemainareaby Replace call to main_area() by a print of this string
* @param int $disablenofollow Disable the "nofollow" on meta robot header
* @param int $disablenoindex Disable the "noindex" on meta robot header
* @return void
*/
function llxHeader($head = '', $title = '', $help_url = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $morequerystring = '', $morecssonbody = '', $replacemainareaby = '', $disablenofollow = 0, $disablenoindex = 0) // @phan-suppress-current-line PhanRedefineFunction
2018-08-15 17:34:35 +02:00
{
print '<html><title>Build an import example file</title><body>';
2018-08-15 17:34:35 +02:00
}
/**
* This file is a wrapper, so empty footer
*
* Note: also called by functions.lib:recordNotFound
*
* @param string $comment A text to add as HTML comment into HTML generated page
* @param string $zone 'private' (for private pages) or 'public' (for public pages)
* @param int $disabledoutputofmessages Clear all messages stored into session without displaying them
* @return void
*/
function llxFooter($comment = '', $zone = 'private', $disabledoutputofmessages = 0) // @phan-suppress-current-line PhanRedefineFunction
2018-08-15 17:34:35 +02:00
{
print '</body></html>';
2018-08-15 17:34:35 +02:00
}
2022-09-07 20:08:59 +02:00
// Load Dolibarr environment
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/imports/class/import.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/import/modules_import.php';
2009-09-07 23:14:21 +02:00
add baseline exclude for phpstan (#31632) * add baseline exclude for phpstan * update * update * update * update * update * merge * restore one filter * delete old errors * fix * fix * fix * $moreforfilter can t be empty * fix * enable check * refresh baseline * add phpdoc * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2024-11-04 23:53:20 +01:00
/**
* @var Conf $conf
* @var DoliDB $db
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
$datatoimport = GETPOST('datatoimport');
$format = GETPOST('format');
2012-06-17 17:44:38 +02:00
2018-05-26 21:11:25 +02:00
// Load translation files required by the page
2009-09-12 04:07:25 +02:00
$langs->load("exports");
2009-09-08 01:49:16 +02:00
// Check exportkey
if (empty($datatoimport)) {
$user->loadRights();
2009-09-07 23:14:21 +02:00
llxHeader();
2009-09-08 01:49:16 +02:00
print '<div class="error">Bad value for datatoimport.</div>';
llxFooter();
2009-09-08 01:49:16 +02:00
exit;
2009-09-07 23:14:21 +02:00
}
$filename = $langs->transnoentitiesnoconv("ExampleOfImportFile").'_'.$datatoimport.'.'.$format;
2009-09-07 23:14:21 +02:00
$objimport = new Import($db);
$objimport->load_arrays($user, $datatoimport);
2009-09-08 01:49:16 +02:00
// Load arrays from descriptor module
$fieldstarget = $objimport->array_import_fields[0];
$valuestarget = $objimport->array_import_examplevalues[0];
2009-09-08 01:49:16 +02:00
$attachment = true;
2024-03-28 20:19:28 +01:00
if (GETPOSTISSET("attachment")) {
$attachment = GETPOST("attachment");
}
2009-09-08 01:49:16 +02:00
//$attachment = false;
$contenttype = dol_mimetype($format);
2024-03-28 20:19:28 +01:00
if (GETPOSTISSET("contenttype")) {
$contenttype = GETPOST("contenttype");
}
2009-09-08 01:49:16 +02:00
//$contenttype='text/plain';
$outputencoding = 'UTF-8';
2009-09-08 01:49:16 +02:00
if ($contenttype) {
header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
}
if ($attachment) {
header('Content-Disposition: attachment; filename="'.$filename.'"');
}
2009-09-08 01:49:16 +02:00
// List of targets fields
2021-07-31 16:22:50 +02:00
$headerlinefields = array(); // Array of fields (label to show)
$contentlinevalues = array(); // Array of example values
2009-09-08 01:49:16 +02:00
$i = 0;
foreach ($fieldstarget as $code => $label) {
$withoutstar = preg_replace('/\*/', '', $fieldstarget[$code]);
$headerlinefields[] = $langs->transnoentities($withoutstar).($withoutstar != $fieldstarget[$code] ? '*' : '').' ('.$code.')';
2021-07-31 16:22:50 +02:00
$contentlinevalues[] = (isset($valuestarget[$code]) ? $valuestarget[$code] : '');
2009-09-07 23:14:21 +02:00
}
2009-09-08 01:49:16 +02:00
//var_dump($headerlinefields);
//var_dump($contentlinevalues);
2009-09-07 23:14:21 +02:00
print $objimport->build_example_file($format, $headerlinefields, $contentlinevalues, $datatoimport);