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