dolibarr 21.0.0-beta
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-2024 Frédéric France <frederic.france@free.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
43$id = GETPOSTINT('id');
44$ref = GETPOST('ref', 'alphanohtml');
45
46$object = new Adherent($db);
47
48// Fetch object
49if ($id > 0 || !empty($ref)) {
50 // Load member
51 $result = $object->fetch($id, $ref);
52
53 // Define variables to know what current user can do on users
54 $canadduser = ($user->admin || $user->hasRight('user', 'user', 'creer'));
55 // Define variables to know what the current user can do on properties of user linked to edited member
56 if ($object->user_id) {
57 // $User is the user who edits, $object->user_id is the id of the related user in the edited member
58 $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'creer'))
59 || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'creer')));
60 $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'password'))
61 || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'password')));
62 }
63}
64
65// Define variables to determine what the current user can do on the members
66$canaddmember = $user->hasRight('adherent', 'creer');
67// Define variables to determine what the current user can do on the properties of a member
68if ($id) {
69 $caneditfieldmember = $user->hasRight('adherent', 'creer');
70}
71
72// Security check
73$result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
74
75
76/*
77 * Actions
78 */
79
80// None
81
82
83/*
84 * View
85 */
86
87$company = new Societe($db);
88if ($object->socid) {
89 $result = $company->fetch($object->socid);
90}
91
92
93
94// We create VCard
95$v = new vCard();
96$v->setProdId('Dolibarr '.DOL_VERSION);
97
98$v->setUid('DOLIBARR-ADHERENTID-'.$object->id);
99$v->setName($object->lastname, $object->firstname, "", $object->civility, "");
100$v->setFormattedName($object->getFullName($langs, 1));
101
102$v->setPhoneNumber($object->phone_pro, "TYPE=WORK;VOICE");
103//$v->setPhoneNumber($object->phone_perso,"TYPE=HOME;VOICE");
104$v->setPhoneNumber($object->phone_mobile, "TYPE=CELL;VOICE");
105$v->setPhoneNumber($object->fax, "TYPE=WORK;FAX");
106
107$country = $object->country_code ? $object->country : '';
108
109$v->setAddress("", "", $object->address, $object->town, $object->state, $object->zip, $country, "TYPE=WORK;POSTAL");
110// @phan-suppress-next-line PhanDeprecatedFunction (setLabel is the old method, new is setAddress)
111$v->setLabel("", "", $object->address, $object->town, $object->state, $object->zip, $country, "TYPE=WORK");
112
113$v->setEmail($object->email);
114$v->setNote($object->note_public);
115$v->setTitle($object->poste);
116
117// Data from linked company
118if ($company->id) {
119 $v->setURL($company->url, "TYPE=WORK");
120 if (!$object->phone_pro) {
121 $v->setPhoneNumber($company->phone, "TYPE=WORK;VOICE");
122 }
123 if (!$object->fax) {
124 $v->setPhoneNumber($company->fax, "TYPE=WORK;FAX");
125 }
126 if (!$object->zip) {
127 $v->setAddress("", "", $company->address, $company->town, $company->state, $company->zip, $company->country, "TYPE=WORK;POSTAL");
128 }
129 // when company e-mail is empty, use only adherent e-mail
130 if (empty(trim($company->email))) {
131 // was set before, don't set twice
132 } elseif (empty(trim($object->email))) {
133 // when adherent e-mail is empty, use only company e-mail
134 $v->setEmail($company->email);
135 } else {
136 $tmpobject = explode("@", trim($object->email));
137 $tmpcompany = explode("@", trim($company->email));
138
139 if (strtolower(end($tmpobject)) == strtolower(end($tmpcompany))) {
140 // when e-mail domain of adherent and company are the same, use adherent e-mail at first (and company e-mail at second)
141 $v->setEmail($object->email);
142
143 // support by Microsoft Outlook (2019 and possible earlier)
144 $v->setEmail($company->email, 'INTERNET');
145 } else {
146 // when e-mail of adherent and company complete different use company e-mail at first (and adherent e-mail at second)
147 $v->setEmail($company->email);
148
149 // support by Microsoft Outlook (2019 and possible earlier)
150 $v->setEmail($object->email, 'INTERNET');
151 }
152 }
153
154 // Si adherent lie a un tiers non de type "particulier"
155 if ($company->typent_code != 'TE_PRIVATE') {
156 $v->setOrg($company->name);
157 }
158}
159
160// Personal information
161$v->setPhoneNumber($object->phone_perso, "TYPE=HOME;VOICE");
162if ($object->birth) {
163 $v->setBirthday($object->birth);
164}
165
166$db->close();
167
168
169// Renvoi la VCard au navigateur
170
171$output = $v->getVCard();
172
173$filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf"
174$filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
175//$filename = dol_sanitizeFileName($filename);
176
177
178header("Content-Disposition: attachment; filename=\"".$filename."\"");
179header("Content-Length: ".dol_strlen($output));
180header("Connection: close");
181header("Content-Type: text/x-vcard; name=\"".$filename."\"");
182
183print $output;
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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.