vcard.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2023 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
  6. * Copyright (C) 2021-2022 Anthony Berton <anthony.berton@bb2a.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/user/vcard.php
  23. * \ingroup user
  24. * \brief Page to return a user vcard
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/vcard.class.php';
  31. $id = GETPOST('id', 'int');
  32. // Security check
  33. $socid = 0;
  34. if ($user->socid > 0) {
  35. $socid = $user->socid;
  36. }
  37. $feature2 = 'user';
  38. $result = restrictedArea($user, 'user', $id, 'user', $feature2);
  39. $object = new User($db);
  40. $result = $object->fetch($id);
  41. if ($result <= 0) {
  42. dol_print_error($object->error);
  43. exit;
  44. }
  45. // Data from linked company
  46. $company = new Societe($db);
  47. if ($object->socid > 0) {
  48. $result = $company->fetch($object->socid);
  49. }
  50. /*
  51. * View
  52. */
  53. // We create VCard
  54. $v = new vCard();
  55. $output = $v->buildVCardString($object, $company, $langs);
  56. $filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf"
  57. $filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
  58. //$filename = dol_sanitizeFileName($filename);
  59. top_httphead('text/x-vcard; name="'.$filename.'"');
  60. header("Content-Disposition: attachment; filename=\"".$filename."\"");
  61. header("Content-Length: ".dol_strlen($output));
  62. header("Connection: close");
  63. print $output;
  64. $db->close();