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) 2020-2021 Frédéric France <[email protected]> |
||
8 | * Copyright (C) 2024 MDW <[email protected]> |
||
9 | * Copyright (C) 2024 Rafael San José <[email protected]> |
||
10 | * |
||
11 | * This program is free software; you can redistribute it and/or modify |
||
12 | * it under the terms of the GNU General Public License as published by |
||
13 | * the Free Software Foundation; either version 3 of the License, or |
||
14 | * (at your option) any later version. |
||
15 | * |
||
16 | * This program is distributed in the hope that it will be useful, |
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
19 | * GNU General Public License for more details. |
||
20 | * |
||
21 | * You should have received a copy of the GNU General Public License |
||
22 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
23 | */ |
||
24 | |||
25 | use Dolibarr\Code\Adherents\Classes\Adherent; |
||
26 | use Dolibarr\Code\Core\Classes\vCard; |
||
27 | use Dolibarr\Code\Societe\Classes\Societe; |
||
28 | use Dolibarr\Lib\ViewMain; |
||
29 | |||
30 | /** |
||
31 | * \file htdocs/adherents/vcard.php |
||
32 | * \ingroup societe |
||
33 | * \brief Vcard tab of a member |
||
34 | */ |
||
35 | |||
36 | // Load Dolibarr environment |
||
37 | require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php'; |
||
38 | |||
39 | $id = GETPOSTINT('id'); |
||
40 | $ref = GETPOST('ref', 'alphanohtml'); |
||
41 | |||
42 | $object = new Adherent($db); |
||
43 | |||
44 | // Fetch object |
||
45 | if ($id > 0 || !empty($ref)) { |
||
46 | // Load member |
||
47 | $result = $object->fetch($id, $ref); |
||
48 | |||
49 | // Define variables to know what current user can do on users |
||
50 | $canadduser = ($user->admin || $user->hasRight('user', 'user', 'creer')); |
||
51 | // Define variables to know what current user can do on properties of user linked to edited member |
||
52 | if ($object->user_id) { |
||
53 | // $User is the user who edits, $object->user_id is the id of the related user in the edited member |
||
54 | $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'creer')) |
||
55 | || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'creer'))); |
||
56 | $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'password')) |
||
57 | || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'password'))); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | // Define variables to determine what the current user can do on the members |
||
62 | $canaddmember = $user->hasRight('adherent', 'creer'); |
||
63 | // Define variables to determine what the current user can do on the properties of a member |
||
64 | if ($id) { |
||
65 | $caneditfieldmember = $user->hasRight('adherent', 'creer'); |
||
66 | } |
||
67 | |||
68 | // Security check |
||
69 | $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0); |
||
70 | |||
71 | |||
72 | /* |
||
73 | * Actions |
||
74 | */ |
||
75 | |||
76 | // None |
||
77 | |||
78 | /* |
||
79 | * View |
||
80 | */ |
||
81 | |||
82 | $company = new Societe($db); |
||
83 | if ($object->socid) { |
||
84 | $result = $company->fetch($object->socid); |
||
85 | } |
||
86 | |||
87 | |||
88 | |||
89 | // We create VCard |
||
90 | $v = new vCard(); |
||
91 | $v->setProdId('Dolibarr ' . DOL_VERSION); |
||
92 | |||
93 | $v->setUid('DOLIBARR-ADHERENTID-' . $object->id); |
||
94 | $v->setName($object->lastname, $object->firstname, "", $object->civility, ""); |
||
95 | $v->setFormattedName($object->getFullName($langs, 1)); |
||
96 | |||
97 | $v->setPhoneNumber($object->phone_pro, "TYPE=WORK;VOICE"); |
||
98 | //$v->setPhoneNumber($object->phone_perso,"TYPE=HOME;VOICE"); |
||
99 | $v->setPhoneNumber($object->phone_mobile, "TYPE=CELL;VOICE"); |
||
100 | $v->setPhoneNumber($object->fax, "TYPE=WORK;FAX"); |
||
101 | |||
102 | $country = $object->country_code ? $object->country : ''; |
||
103 | |||
104 | $v->setAddress("", "", $object->address, $object->town, $object->state, $object->zip, $country, "TYPE=WORK;POSTAL"); |
||
105 | // @phan-suppress-next-line PhanDeprecatedFunction (setLabel is the old method, new is setAddress) |
||
106 | $v->setLabel("", "", $object->address, $object->town, $object->state, $object->zip, $country, "TYPE=WORK"); |
||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||
107 | |||
108 | $v->setEmail($object->email); |
||
109 | $v->setNote($object->note_public); |
||
110 | $v->setTitle($object->poste); |
||
111 | |||
112 | // Data from linked company |
||
113 | if ($company->id) { |
||
114 | $v->setURL($company->url, "TYPE=WORK"); |
||
115 | if (!$object->phone_pro) { |
||
116 | $v->setPhoneNumber($company->phone, "TYPE=WORK;VOICE"); |
||
117 | } |
||
118 | if (!$object->fax) { |
||
119 | $v->setPhoneNumber($company->fax, "TYPE=WORK;FAX"); |
||
120 | } |
||
121 | if (!$object->zip) { |
||
122 | $v->setAddress("", "", $company->address, $company->town, $company->state, $company->zip, $company->country, "TYPE=WORK;POSTAL"); |
||
123 | } |
||
124 | // when company e-mail is empty, use only adherent e-mail |
||
125 | if (empty(trim($company->email))) { |
||
126 | // was set before, don't set twice |
||
127 | } elseif (empty(trim($object->email))) { |
||
128 | // when adherent e-mail is empty, use only company e-mail |
||
129 | $v->setEmail($company->email); |
||
130 | } else { |
||
131 | $tmpobject = explode("@", trim($object->email)); |
||
132 | $tmpcompany = explode("@", trim($company->email)); |
||
133 | |||
134 | if (strtolower(end($tmpobject)) == strtolower(end($tmpcompany))) { |
||
135 | // when e-mail domain of adherent and company are the same, use adherent e-mail at first (and company e-mail at second) |
||
136 | $v->setEmail($object->email); |
||
137 | |||
138 | // support by Microsoft Outlook (2019 and possible earlier) |
||
139 | $v->setEmail($company->email, 'INTERNET'); |
||
140 | } else { |
||
141 | // when e-mail of adherent and company complete different use company e-mail at first (and adherent e-mail at second) |
||
142 | $v->setEmail($company->email); |
||
143 | |||
144 | // support by Microsoft Outlook (2019 and possible earlier) |
||
145 | $v->setEmail($object->email, 'INTERNET'); |
||
146 | } |
||
147 | } |
||
148 | |||
149 | // Si adherent lie a un tiers non de type "particulier" |
||
150 | if ($company->typent_code != 'TE_PRIVATE') { |
||
151 | $v->setOrg($company->name); |
||
152 | } |
||
153 | } |
||
154 | |||
155 | // Personal information |
||
156 | $v->setPhoneNumber($object->phone_perso, "TYPE=HOME;VOICE"); |
||
157 | if ($object->birth) { |
||
158 | $v->setBirthday($object->birth); |
||
159 | } |
||
160 | |||
161 | $db->close(); |
||
162 | |||
163 | |||
164 | // Renvoi la VCard au navigateur |
||
165 | |||
166 | $output = $v->getVCard(); |
||
167 | |||
168 | $filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf" |
||
169 | $filenameurlencoded = dol_sanitizeFileName(urlencode($filename)); |
||
170 | //$filename = dol_sanitizeFileName($filename); |
||
171 | |||
172 | |||
173 | header("Content-Disposition: attachment; filename=\"" . $filename . "\""); |
||
174 | header("Content-Length: " . dol_strlen($output)); |
||
175 | header("Connection: close"); |
||
176 | header("Content-Type: text/x-vcard; name=\"" . $filename . "\""); |
||
177 | |||
178 | print $output; |
||
179 |