vcard.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
  6. * Copyright (C) 2020-2021 Frédéric France <frederic.france@netlogic.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/adherents/vcard.php
  23. * \ingroup societe
  24. * \brief Vcard tab of a member
  25. */
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/vcard.class.php';
  30. $id = GETPOST('id', 'int');
  31. $ref = GETPOST('ref', 'alphanohtml');
  32. $object = new adherent($db);
  33. // Fetch object
  34. if ($id > 0 || !empty($ref)) {
  35. // Load member
  36. $result = $object->fetch($id, $ref);
  37. // Define variables to know what current user can do on users
  38. $canadduser = ($user->admin || $user->rights->user->user->creer);
  39. // Define variables to know what current user can do on properties of user linked to edited member
  40. if ($object->user_id) {
  41. // $User is the user who edits, $object->user_id is the id of the related user in the edited member
  42. $caneditfielduser = ((($user->id == $object->user_id) && $user->rights->user->self->creer)
  43. || (($user->id != $object->user_id) && $user->rights->user->user->creer));
  44. $caneditpassworduser = ((($user->id == $object->user_id) && $user->rights->user->self->password)
  45. || (($user->id != $object->user_id) && $user->rights->user->user->password));
  46. }
  47. }
  48. // Define variables to determine what the current user can do on the members
  49. $canaddmember = $user->hasRight('adherent', 'creer');
  50. // Define variables to determine what the current user can do on the properties of a member
  51. if ($id) {
  52. $caneditfieldmember = $user->hasRight('adherent', 'creer');
  53. }
  54. // Security check
  55. $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
  56. /*
  57. * Actions
  58. */
  59. // None
  60. /*
  61. * View
  62. */
  63. $company = new Societe($db);
  64. if ($object->socid) {
  65. $result = $company->fetch($object->socid);
  66. }
  67. // We create VCard
  68. $v = new vCard();
  69. $v->setProdId('Dolibarr '.DOL_VERSION);
  70. $v->setUid('DOLIBARR-ADHERENTID-'.$object->id);
  71. $v->setName($object->lastname, $object->firstname, "", $object->civility, "");
  72. $v->setFormattedName($object->getFullName($langs, 1));
  73. $v->setPhoneNumber($object->phone_pro, "TYPE=WORK;VOICE");
  74. //$v->setPhoneNumber($object->phone_perso,"TYPE=HOME;VOICE");
  75. $v->setPhoneNumber($object->phone_mobile, "TYPE=CELL;VOICE");
  76. $v->setPhoneNumber($object->fax, "TYPE=WORK;FAX");
  77. $country = $object->country_code ? $object->country : '';
  78. $v->setAddress("", "", $object->address, $object->town, $object->state, $object->zip, $country, "TYPE=WORK;POSTAL");
  79. $v->setLabel("", "", $object->address, $object->town, $object->state, $object->zip, $country, "TYPE=WORK");
  80. $v->setEmail($object->email);
  81. $v->setNote($object->note_public);
  82. $v->setTitle($object->poste);
  83. // Data from linked company
  84. if ($company->id) {
  85. $v->setURL($company->url, "TYPE=WORK");
  86. if (!$object->phone_pro) {
  87. $v->setPhoneNumber($company->phone, "TYPE=WORK;VOICE");
  88. }
  89. if (!$object->fax) {
  90. $v->setPhoneNumber($company->fax, "TYPE=WORK;FAX");
  91. }
  92. if (!$object->zip) {
  93. $v->setAddress("", "", $company->address, $company->town, $company->state, $company->zip, $company->country, "TYPE=WORK;POSTAL");
  94. }
  95. // when company e-mail is empty, use only adherent e-mail
  96. if (empty(trim($company->email))) {
  97. // was set before, don't set twice
  98. } elseif (empty(trim($object->email))) {
  99. // when adherent e-mail is empty, use only company e-mail
  100. $v->setEmail($company->email);
  101. } elseif (strtolower(end(explode("@", $object->email))) == strtolower(end(explode("@", $company->email)))) {
  102. // when e-mail domain of adherent and company are the same, use adherent e-mail at first (and company e-mail at second)
  103. $v->setEmail($object->email);
  104. // support by Microsoft Outlook (2019 and possible earlier)
  105. $v->setEmail($company->email, 'INTERNET');
  106. } else {
  107. // when e-mail of adherent and company complete different use company e-mail at first (and adherent e-mail at second)
  108. $v->setEmail($company->email);
  109. // support by Microsoft Outlook (2019 and possible earlier)
  110. $v->setEmail($object->email, 'INTERNET');
  111. }
  112. // Si adherent lie a un tiers non de type "particulier"
  113. if ($company->typent_code != 'TE_PRIVATE') {
  114. $v->setOrg($company->name);
  115. }
  116. }
  117. // Personal informations
  118. $v->setPhoneNumber($object->phone_perso, "TYPE=HOME;VOICE");
  119. if ($object->birth) {
  120. $v->setBirthday($object->birth);
  121. }
  122. $db->close();
  123. // Renvoi la VCard au navigateur
  124. $output = $v->getVCard();
  125. $filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf"
  126. $filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
  127. //$filename = dol_sanitizeFileName($filename);
  128. header("Content-Disposition: attachment; filename=\"".$filename."\"");
  129. header("Content-Length: ".dol_strlen($output));
  130. header("Connection: close");
  131. header("Content-Type: text/x-vcard; name=\"".$filename."\"");
  132. print $output;