emptyexample.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/imports/emptyexample.php
  19. * \ingroup import
  20. * \brief Show example of import file
  21. */
  22. // This file is a wrapper, so empty header
  23. function llxHeader()
  24. {
  25. print '<html><title>Build an import example file</title><body>';
  26. }
  27. // This file is a wrapper, so empty footer
  28. function llxFooter()
  29. {
  30. print '</body></html>';
  31. }
  32. require '../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/imports/class/import.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/modules/import/modules_import.php';
  36. $datatoimport=GETPOST('datatoimport');
  37. $format=GETPOST('format');
  38. // Load translation files required by the page
  39. $langs->load("exports");
  40. // Check exportkey
  41. if (empty($datatoimport))
  42. {
  43. $user->getrights();
  44. llxHeader();
  45. print '<div class="error">Bad value for datatoimport.</div>';
  46. llxFooter();
  47. exit;
  48. }
  49. $filename=$langs->trans("ExampleOfImportFile").'_'.$datatoimport.'.'.$format;
  50. $objimport=new Import($db);
  51. $objimport->load_arrays($user,$datatoimport);
  52. // Load arrays from descriptor module
  53. $entity=$objimport->array_import_entities[0][$code];
  54. $entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity;
  55. $entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity;
  56. $fieldstarget=$objimport->array_import_fields[0];
  57. $valuestarget=$objimport->array_import_examplevalues[0];
  58. $attachment = true;
  59. if (isset($_GET["attachment"])) $attachment=$_GET["attachment"];
  60. //$attachment = false;
  61. $contenttype=dol_mimetype($format);
  62. if (isset($_GET["contenttype"])) $contenttype=$_GET["contenttype"];
  63. //$contenttype='text/plain';
  64. $outputencoding='UTF-8';
  65. if ($contenttype) header('Content-Type: '.$contenttype.($outputencoding?'; charset='.$outputencoding:''));
  66. if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
  67. // List of targets fields
  68. $headerlinefields=array();
  69. $contentlinevalues=array();
  70. $i = 0;
  71. foreach($fieldstarget as $code=>$label)
  72. {
  73. $withoutstar=preg_replace('/\*/','',$fieldstarget[$code]);
  74. $headerlinefields[]=$langs->transnoentities($withoutstar).($withoutstar != $fieldstarget[$code]?'*':'').' ('.$code.')';
  75. $contentlinevalues[]=$valuestarget[$code];
  76. }
  77. //var_dump($headerlinefields);
  78. //var_dump($contentlinevalues);
  79. print $objimport->build_example_file($format,$headerlinefields,$contentlinevalues,$datatoimport);