emptyexample.php 3.0 KB

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