dolibarr  13.0.2
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 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/vcard.class.php';
31 
32 $contact = new Contact($db);
33 
34 
35 $id = GETPOST('id', 'int');
36 
37 // Security check
38 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
39 
40 
41 $result = $contact->fetch($id);
42 if ($result <= 0)
43 {
44  dol_print_error($contact->error);
45  exit;
46 }
47 
48 $physicalperson = 1;
49 
50 $company = new Societe($db);
51 if ($contact->socid)
52 {
53  $result = $company->fetch($contact->socid);
54 }
55 
56 // We create VCard
57 $v = new vCard();
58 $v->setProdId('Dolibarr '.DOL_VERSION);
59 
60 $v->setUid('DOLIBARR-CONTACTID-'.$contact->id);
61 $v->setName($contact->lastname, $contact->firstname, "", $contact->civility, "");
62 $v->setFormattedName($contact->getFullName($langs, 1));
63 
64 $v->setPhoneNumber($contact->phone_pro, "TYPE=WORK;VOICE");
65 //$v->setPhoneNumber($contact->phone_perso,"TYPE=HOME;VOICE");
66 $v->setPhoneNumber($contact->phone_mobile, "TYPE=CELL;VOICE");
67 $v->setPhoneNumber($contact->fax, "TYPE=WORK;FAX");
68 
69 $country = $contact->country_code ? $contact->country : '';
70 
71 $v->setAddress("", "", $contact->address, $contact->town, $contact->state, $contact->zip, $country, "TYPE=WORK;POSTAL");
72 $v->setLabel("", "", $contact->address, $contact->town, $contact->state, $contact->zip, $country, "TYPE=WORK");
73 
74 $v->setEmail($contact->email);
75 $v->setNote($contact->note);
76 $v->setTitle($contact->poste);
77 
78 // Data from linked company
79 if ($company->id)
80 {
81  $v->setURL($company->url, "TYPE=WORK");
82  if (!$contact->phone_pro) $v->setPhoneNumber($company->phone, "TYPE=WORK;VOICE");
83  if (!$contact->fax) $v->setPhoneNumber($company->fax, "TYPE=WORK;FAX");
84  if (!$contact->zip) $v->setAddress("", "", $company->address, $company->town, $company->state, $company->zip, $company->country, "TYPE=WORK;POSTAL");
85 
86  // when company e-mail is empty, use only contact e-mail
87  if (empty(trim($company->email)))
88  {
89  // was set before, don't set twice
90  }
91  // when contact e-mail is empty, use only company e-mail
92  elseif (empty(trim($contact->email)))
93  {
94  $v->setEmail($company->email);
95  }
96  // when e-mail domain of contact and company are the same, use contact e-mail at first (and company e-mail at second)
97  elseif (strtolower(end(explode("@", $contact->email))) == strtolower(end(explode("@", $company->email))))
98  {
99  $v->setEmail($contact->email);
100 
101  // support by Microsoft Outlook (2019 and possible earlier)
102  $v->setEmail($company->email, 'INTERNET');
103  }
104  // when e-mail of contact and company complete different use company e-mail at first (and contact e-mail at second)
105  else {
106  $v->setEmail($company->email);
107 
108  // support by Microsoft Outlook (2019 and possible earlier)
109  $v->setEmail($contact->email, 'INTERNET');
110  }
111 
112  // Si contact lie a un tiers non de type "particulier"
113  if ($contact->typent_code != 'TE_PRIVATE') $v->setOrg($company->name);
114 }
115 
116 // Personal informations
117 $v->setPhoneNumber($contact->phone_perso, "TYPE=HOME;VOICE");
118 if ($contact->birthday) $v->setBirthday($contact->birthday);
119 
120 $db->close();
121 
122 
123 // Renvoi la VCard au navigateur
124 
125 $output = $v->getVCard();
126 
127 $filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf"
128 $filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
129 //$filename = dol_sanitizeFileName($filename);
130 
131 
132 header("Content-Disposition: attachment; filename=\"".$filename."\"");
133 header("Content-Length: ".dol_strlen($output));
134 header("Connection: close");
135 header("Content-Type: text/x-vcard; name=\"".$filename."\"");
136 
137 print $output;
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage contact/addresses.
Class to buld vCard files.
Definition: vcard.class.php:86
Class to manage third parties objects (customers, suppliers, prospects...)
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...