1 | <?php |
||||
2 | |||||
3 | /* Copyright (C) 2004 Rodolphe Quiedeville <[email protected]> |
||||
4 | * Copyright (C) 2004-2010 Laurent Destailleur <[email protected]> |
||||
5 | * Copyright (C) 2005-2012 Regis Houssin <[email protected]> |
||||
6 | * Copyright (C) 2020 Tobias Sekan <[email protected]> |
||||
7 | * Copyright (C) 2024 MDW <[email protected]> |
||||
8 | * Copyright (C) 2024 Rafael San José <[email protected]> |
||||
9 | * |
||||
10 | * This program is free software; you can redistribute it and/or modify |
||||
11 | * it under the terms of the GNU General Public License as published by |
||||
12 | * the Free Software Foundation; either version 3 of the License, or |
||||
13 | * (at your option) any later version. |
||||
14 | * |
||||
15 | * This program is distributed in the hope that it will be useful, |
||||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
18 | * GNU General Public License for more details. |
||||
19 | * |
||||
20 | * You should have received a copy of the GNU General Public License |
||||
21 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||||
22 | */ |
||||
23 | |||||
24 | use Dolibarr\Code\Contact\Classes\Contact; |
||||
25 | use Dolibarr\Code\Core\Classes\vCard; |
||||
26 | use Dolibarr\Code\Societe\Classes\Societe; |
||||
27 | use Dolibarr\Lib\ViewMain; |
||||
28 | |||||
29 | /** |
||||
30 | * \file htdocs/contact/vcard.php |
||||
31 | * \ingroup societe |
||||
32 | * \brief Onglet vcard d'un contact |
||||
33 | */ |
||||
34 | |||||
35 | // Load Dolibarr environment |
||||
36 | require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php'; |
||||
37 | |||||
38 | $contact = new Contact($db); |
||||
39 | |||||
40 | |||||
41 | $id = GETPOSTINT('id'); |
||||
42 | |||||
43 | // Security check |
||||
44 | $result = restrictedArea($user, 'contact', $id, 'socpeople&societe'); |
||||
45 | |||||
46 | |||||
47 | $result = $contact->fetch($id); |
||||
48 | if ($result <= 0) { |
||||
49 | dol_print_error($db, $contact->error); |
||||
50 | exit; |
||||
51 | } |
||||
52 | |||||
53 | |||||
54 | $company = new Societe($db); |
||||
55 | if ($contact->socid) { |
||||
56 | $result = $company->fetch($contact->socid); |
||||
57 | } |
||||
58 | |||||
59 | // We create VCard |
||||
60 | $v = new vCard(); |
||||
61 | $v->setProdId('Dolibarr ' . DOL_VERSION); |
||||
62 | |||||
63 | $v->setUid('DOLIBARR-CONTACTID-' . $contact->id); |
||||
64 | $v->setName($contact->lastname, $contact->firstname, "", $contact->civility, ""); |
||||
65 | $v->setFormattedName($contact->getFullName($langs, 1)); |
||||
66 | |||||
67 | $v->setPhoneNumber($contact->phone_pro, "TYPE=WORK;VOICE"); |
||||
68 | //$v->setPhoneNumber($contact->phone_perso,"TYPE=HOME;VOICE"); |
||||
69 | $v->setPhoneNumber($contact->phone_mobile, "TYPE=CELL;VOICE"); |
||||
70 | $v->setPhoneNumber($contact->fax, "TYPE=WORK;FAX"); |
||||
71 | |||||
72 | $country = $contact->country_code ? $contact->country : ''; |
||||
73 | |||||
74 | $v->setAddress("", "", $contact->address, $contact->town, $contact->state, $contact->zip, $country, "TYPE=WORK;POSTAL"); |
||||
75 | // @phan-suppress-next-line PhanDeprecatedFunction setLabel applies the old method, setAddress is the new method. |
||||
76 | $v->setLabel("", "", $contact->address, $contact->town, $contact->state, $contact->zip, $country, "TYPE=WORK"); |
||||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||||
77 | |||||
78 | $v->setEmail($contact->email); |
||||
79 | $v->setNote($contact->note); |
||||
0 ignored issues
–
show
The property
Dolibarr\Core\Base\CommonObject::$note has been deprecated: Use $note_private instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This property has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead. ![]() |
|||||
80 | $v->setTitle($contact->poste); |
||||
81 | |||||
82 | // Data from linked company |
||||
83 | if ($company->id) { |
||||
84 | $v->setURL($company->url, "TYPE=WORK"); |
||||
85 | if (!$contact->phone_pro) { |
||||
86 | $v->setPhoneNumber($company->phone, "TYPE=WORK;VOICE"); |
||||
87 | } |
||||
88 | if (!$contact->fax) { |
||||
89 | $v->setPhoneNumber($company->fax, "TYPE=WORK;FAX"); |
||||
90 | } |
||||
91 | if (!$contact->zip) { |
||||
92 | $v->setAddress("", "", $company->address, $company->town, $company->state, $company->zip, $company->country, "TYPE=WORK;POSTAL"); |
||||
93 | } |
||||
94 | |||||
95 | // when company e-mail is empty, use only contact e-mail |
||||
96 | if (empty(trim($company->email))) { |
||||
97 | // was set before, don't set twice |
||||
98 | } elseif (empty(trim($contact->email))) { |
||||
99 | // when contact e-mail is empty, use only company e-mail |
||||
100 | $v->setEmail($company->email); |
||||
101 | } else { |
||||
102 | $tmpcontact = explode("@", trim($contact->email)); |
||||
103 | $tmpcompany = explode("@", trim($company->email)); |
||||
104 | |||||
105 | if (strtolower(end($tmpcontact)) == strtolower(end($tmpcompany))) { |
||||
106 | // when e-mail domain of contact and company are the same, use contact e-mail at first (and company e-mail at second) |
||||
107 | $v->setEmail($contact->email); |
||||
108 | |||||
109 | // support by Microsoft Outlook (2019 and possible earlier) |
||||
110 | $v->setEmail($company->email, 'INTERNET'); |
||||
111 | } else { |
||||
112 | // when e-mail of contact and company complete different use company e-mail at first (and contact e-mail at second) |
||||
113 | $v->setEmail($company->email); |
||||
114 | |||||
115 | // support by Microsoft Outlook (2019 and possible earlier) |
||||
116 | $v->setEmail($contact->email, 'INTERNET'); |
||||
117 | } |
||||
118 | } |
||||
119 | |||||
120 | // Si contact lie a un tiers non de type "particulier" |
||||
121 | if ($company->typent_code != 'TE_PRIVATE') { |
||||
122 | $v->setOrg($company->name); |
||||
123 | } |
||||
124 | } |
||||
125 | |||||
126 | // Personal information |
||||
127 | $v->setPhoneNumber($contact->phone_perso, "TYPE=HOME;VOICE"); |
||||
128 | if ($contact->birthday) { |
||||
129 | $v->setBirthday($contact->birthday); |
||||
130 | } |
||||
131 | |||||
132 | $db->close(); |
||||
133 | |||||
134 | |||||
135 | // Renvoi la VCard au navigateur |
||||
136 | |||||
137 | $output = $v->getVCard(); |
||||
138 | |||||
139 | $filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf" |
||||
140 | $filenameurlencoded = dol_sanitizeFileName(urlencode($filename)); |
||||
141 | //$filename = dol_sanitizeFileName($filename); |
||||
142 | |||||
143 | |||||
144 | header("Content-Disposition: attachment; filename=\"" . $filename . "\""); |
||||
145 | header("Content-Length: " . dol_strlen($output)); |
||||
146 | header("Connection: close"); |
||||
147 | header("Content-Type: text/x-vcard; name=\"" . $filename . "\""); |
||||
148 | |||||
149 | print $output; |
||||
150 |