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