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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/vcard.class.php';
32
33$contact = new Contact($db);
34
35
36$id = GETPOST('id', 'int');
37
38// Security check
39$result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
40
41
42$result = $contact->fetch($id);
43if ($result <= 0) {
44 dol_print_error($db, $contact->error);
45 exit;
46}
47
48
49$company = new Societe($db);
50if ($contact->socid) {
51 $result = $company->fetch($contact->socid);
52}
53
54// We create VCard
55$v = new vCard();
56$v->setProdId('Dolibarr '.DOL_VERSION);
57
58$v->setUid('DOLIBARR-CONTACTID-'.$contact->id);
59$v->setName($contact->lastname, $contact->firstname, "", $contact->civility, "");
60$v->setFormattedName($contact->getFullName($langs, 1));
61
62$v->setPhoneNumber($contact->phone_pro, "TYPE=WORK;VOICE");
63//$v->setPhoneNumber($contact->phone_perso,"TYPE=HOME;VOICE");
64$v->setPhoneNumber($contact->phone_mobile, "TYPE=CELL;VOICE");
65$v->setPhoneNumber($contact->fax, "TYPE=WORK;FAX");
66
67$country = $contact->country_code ? $contact->country : '';
68
69$v->setAddress("", "", $contact->address, $contact->town, $contact->state, $contact->zip, $country, "TYPE=WORK;POSTAL");
70$v->setLabel("", "", $contact->address, $contact->town, $contact->state, $contact->zip, $country, "TYPE=WORK");
71
72$v->setEmail($contact->email);
73$v->setNote($contact->note);
74$v->setTitle($contact->poste);
75
76// Data from linked company
77if ($company->id) {
78 $v->setURL($company->url, "TYPE=WORK");
79 if (!$contact->phone_pro) {
80 $v->setPhoneNumber($company->phone, "TYPE=WORK;VOICE");
81 }
82 if (!$contact->fax) {
83 $v->setPhoneNumber($company->fax, "TYPE=WORK;FAX");
84 }
85 if (!$contact->zip) {
86 $v->setAddress("", "", $company->address, $company->town, $company->state, $company->zip, $company->country, "TYPE=WORK;POSTAL");
87 }
88
89 // when company e-mail is empty, use only contact e-mail
90 if (empty(trim($company->email))) {
91 // was set before, don't set twice
92 } elseif (empty(trim($contact->email))) {
93 // when contact e-mail is empty, use only company e-mail
94 $v->setEmail($company->email);
95 } else {
96 $tmpcontact = explode("@", trim($contact->email));
97 $tmpcompany = explode("@", trim($company->email));
98
99 if (strtolower(end($tmpcontact)) == strtolower(end($tmpcompany))) {
100 // when e-mail domain of contact and company are the same, use contact e-mail at first (and company e-mail at second)
101 $v->setEmail($contact->email);
102
103 // support by Microsoft Outlook (2019 and possible earlier)
104 $v->setEmail($company->email, 'INTERNET');
105 } else {
106 // when e-mail of contact and company complete different use company e-mail at first (and contact e-mail at second)
107 $v->setEmail($company->email);
108
109 // support by Microsoft Outlook (2019 and possible earlier)
110 $v->setEmail($contact->email, 'INTERNET');
111 }
112 }
113
114 // Si contact lie a un tiers non de type "particulier"
115 if ($company->typent_code != 'TE_PRIVATE') {
116 $v->setOrg($company->name);
117 }
118}
119
120// Personal informations
121$v->setPhoneNumber($contact->phone_perso, "TYPE=HOME;VOICE");
122if ($contact->birthday) {
123 $v->setBirthday($contact->birthday);
124}
125
126$db->close();
127
128
129// Renvoi la VCard au navigateur
130
131$output = $v->getVCard();
132
133$filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf"
134$filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
135//$filename = dol_sanitizeFileName($filename);
136
137
138header("Content-Disposition: attachment; filename=\"".$filename."\"");
139header("Content-Length: ".dol_strlen($output));
140header("Connection: close");
141header("Content-Type: text/x-vcard; name=\"".$filename."\"");
142
143print $output;
Class to manage third parties objects (customers, suppliers, prospects...)
Class to buld vCard files.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
Contact()
Old copy.
Definition index.php:572