dolibarr/htdocs/imports/emptyexample.php

89 lines
2.9 KiB
PHP
Raw Normal View History

2009-09-07 23:14:21 +02:00
<?php
/* Copyright (C) 2009-2010 Laurent Destailleur <eldy@users.sourceforge.net>
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 2 of the License, or
* (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
2011-08-01 01:45:11 +02:00
* along with this program. If not, see <http://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
*/
2011-09-20 17:48:06 +02:00
// This file is a wrapper, so empty header
function llxHeader() { print '<html><title>Build an import example file</title><body>'; }
2011-09-20 17:48:06 +02:00
// This file is a wrapper, so empty footer
function llxFooter() { print '</body></html>'; }
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
2012-06-17 17:44:38 +02:00
$datatoimport=GETPOST('datatoimport');
$format=GETPOST('format');
2009-09-12 04:07:25 +02:00
$langs->load("exports");
2009-09-08 01:49:16 +02:00
// Check exportkey
if (empty($datatoimport))
2009-09-07 23:14:21 +02:00
{
2009-09-08 01:49:16 +02:00
$user->getrights();
2009-09-07 23:14:21 +02:00
2009-09-08 01:49:16 +02:00
llxHeader();
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
}
2009-09-08 01:49:16 +02:00
$filename=$langs->trans("ExampleOfImportFile").'_'.$datatoimport.'.'.$format;
2009-09-07 23:14:21 +02:00
2009-09-08 01:49:16 +02:00
$objimport=new Import($db);
$objimport->load_arrays($user,$datatoimport);
// Load arrays from descriptor module
$entity=$objimport->array_import_entities[0][$code];
$entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity;
$entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity;
$fieldstarget=$objimport->array_import_fields[0];
$valuestarget=$objimport->array_import_examplevalues[0];
$attachment = true;
if (isset($_GET["attachment"])) $attachment=$_GET["attachment"];
//$attachment = false;
$contenttype=dol_mimetype($format);
if (isset($_GET["contenttype"])) $contenttype=$_GET["contenttype"];
//$contenttype='text/plain';
$outputencoding='UTF-8';
if ($contenttype) header('Content-Type: '.$contenttype.($outputencoding?'; charset='.$outputencoding:''));
if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
// List of targets fields
$headerlinefields=array();
$contentlinevalues=array();
$i = 0;
foreach($fieldstarget as $code=>$label)
2009-09-07 23:14:21 +02:00
{
2009-09-08 01:49:16 +02:00
$headerlinefields[]=$fieldstarget[$code].' ('.$code.')';
$contentlinevalues[]=$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
2012-06-17 17:44:38 +02:00
print $objimport->build_example_file($format,$headerlinefields,$contentlinevalues,$datatoimport);
2009-09-07 23:14:21 +02:00
?>