vcard.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/contact/vcard.php
  21. * \ingroup societe
  22. * \brief Onglet vcard d'un contact
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/vcard.class.php';
  28. $contact = new Contact($db);
  29. $id = GETPOST('id', 'int');
  30. // Security check
  31. $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
  32. $result=$contact->fetch($id);
  33. if ($result <= 0)
  34. {
  35. dol_print_error($contact->error);
  36. exit;
  37. }
  38. $physicalperson=1;
  39. $company = new Societe($db);
  40. if ($contact->socid)
  41. {
  42. $result=$company->fetch($contact->socid);
  43. }
  44. // We create VCard
  45. $v = new vCard();
  46. $v->setProdId('Dolibarr '.DOL_VERSION);
  47. $v->setUid('DOLIBARR-CONTACTID-'.$contact->id);
  48. $v->setName($contact->lastname, $contact->firstname, "", "", "");
  49. $v->setFormattedName($contact->getFullName($langs));
  50. // By default, all informations are for work (except phone_perso and phone_mobile)
  51. $v->setPhoneNumber($contact->phone_pro, "PREF;WORK;VOICE");
  52. $v->setPhoneNumber($contact->phone_mobile, "CELL;VOICE");
  53. $v->setPhoneNumber($contact->fax, "WORK;FAX");
  54. $v->setAddress("", "", $contact->address, $contact->town, "", $contact->zip, ($contact->country_code?$contact->country:''), "WORK;POSTAL");
  55. $v->setLabel("", "", $contact->address, $contact->town, "", $contact->zip, ($contact->country_code?$contact->country:''), "WORK");
  56. $v->setEmail($contact->email,'internet,pref');
  57. $v->setNote($contact->note);
  58. $v->setTitle($contact->poste);
  59. // Data from linked company
  60. if ($company->id)
  61. {
  62. $v->setURL($company->url, "WORK");
  63. if (! $contact->phone_pro) $v->setPhoneNumber($company->phone, "WORK;VOICE");
  64. if (! $contact->fax) $v->setPhoneNumber($company->fax, "WORK;FAX");
  65. if (! $contact->zip) $v->setAddress("", "", $company->address, $company->town, "", $company->zip, $company->country, "WORK;POSTAL");
  66. if ($company->email != $contact->email) $v->setEmail($company->email,'internet');
  67. // Si contact lie a un tiers non de type "particulier"
  68. if ($contact->typent_code != 'TE_PRIVATE') $v->setOrg($company->name);
  69. }
  70. // Personal informations
  71. $v->setPhoneNumber($contact->phone_perso, "HOME;VOICE");
  72. if ($contact->birthday) $v->setBirthday($contact->birthday);
  73. $db->close();
  74. // Renvoi la VCard au navigateur
  75. $output = $v->getVCard();
  76. $filename =trim(urldecode($v->getFileName())); // "Nom prenom.vcf"
  77. $filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
  78. //$filename = dol_sanitizeFileName($filename);
  79. header("Content-Disposition: attachment; filename=\"".$filename."\"");
  80. header("Content-Length: ".dol_strlen($output));
  81. header("Connection: close");
  82. header("Content-Type: text/x-vcard; name=\"".$filename."\"");
  83. print $output;