vcard.php 5.8 KB

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