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.'/user/class/user.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 $user2 = new user($db);
33 
34 
35 $id = GETPOST('id', 'int');
36 
37 // Security check
38 $socid = 0;
39 if ($user->socid > 0) $socid = $user->socid;
40 $feature2 = 'user';
41 $result = restrictedArea($user, 'user', $id, 'user', $feature2);
42 
43 
44 $result = $user2->fetch($id);
45 if ($result <= 0)
46 {
47  dol_print_error($user2->error);
48  exit;
49 }
50 
51 $physicalperson = 1;
52 
53 $company = new Societe($db);
54 if ($user2->socid)
55 {
56  $result = $company->fetch($user2->socid);
57 }
58 
59 // We create VCard
60 $v = new vCard();
61 $v->setProdId('Dolibarr '.DOL_VERSION);
62 
63 $v->setUid('DOLIBARR-USERID-'.$user2->id);
64 $v->setName($user2->lastname, $user2->firstname, "", $user2->civility_code, "");
65 $v->setFormattedName($user2->getFullName($langs, 1));
66 
67 $v->setPhoneNumber($user2->phone_pro, "TYPE=WORK;VOICE");
68 //$v->setPhoneNumber($user2->phone_perso,"TYPE=HOME;VOICE");
69 $v->setPhoneNumber($user2->phone_mobile, "TYPE=CELL;VOICE");
70 $v->setPhoneNumber($user2->fax, "TYPE=WORK;FAX");
71 
72 $country = $user2->country_code ? $user2->country : '';
73 
74 $v->setAddress("", "", $user2->address, $user2->town, $user2->state, $user2->zip, $country, "TYPE=WORK;POSTAL");
75 $v->setLabel("", "", $user2->address, $user2->town, $user2->state, $user2->zip, $country, "TYPE=WORK");
76 
77 $v->setEmail($user2->email);
78 $v->setNote($user2->note);
79 $v->setTitle($user2->poste);
80 
81 // Data from linked company
82 if ($company->id)
83 {
84  $v->setURL($company->url, "TYPE=WORK");
85  if (!$user2->phone_pro) $v->setPhoneNumber($company->phone, "TYPE=WORK;VOICE");
86  if (!$user2->fax) $v->setPhoneNumber($company->fax, "TYPE=WORK;FAX");
87  if (!$user2->zip) $v->setAddress("", "", $company->address, $company->town, $company->state, $company->zip, $company->country, "TYPE=WORK;POSTAL");
88 
89  // when company e-mail is empty, use only user e-mail
90  if (empty(trim($company->email)))
91  {
92  // was set before, don't set twice
93  }
94  // when user e-mail is empty, use only company e-mail
95  elseif (empty(trim($user2->email)))
96  {
97  $v->setEmail($company->email);
98  }
99  // when e-mail domain of user and company are the same, use user e-mail at first (and company e-mail at second)
100  elseif (strtolower(end(explode("@", $user2->email))) == strtolower(end(explode("@", $company->email))))
101  {
102  $v->setEmail($user2->email);
103 
104  // support by Microsoft Outlook (2019 and possible earlier)
105  $v->setEmail($company->email, 'INTERNET');
106  }
107  // when e-mail of user and company complete different use company e-mail at first (and user e-mail at second)
108  else {
109  $v->setEmail($company->email);
110 
111  // support by Microsoft Outlook (2019 and possible earlier)
112  $v->setEmail($user2->email, 'INTERNET');
113  }
114 
115  // Si user lie a un tiers non de type "particulier"
116  if ($user2->typent_code != 'TE_PRIVATE') $v->setOrg($company->name);
117 }
118 
119 // Personal informations
120 $v->setPhoneNumber($user2->phone_perso, "TYPE=HOME;VOICE");
121 if ($user2->birth) $v->setBirthday($user2->birth);
122 
123 $db->close();
124 
125 // Renvoi la VCard au navigateur
126 
127 $output = $v->getVCard();
128 
129 $filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf"
130 $filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
131 //$filename = dol_sanitizeFileName($filename);
132 
133 
134 header("Content-Disposition: attachment; filename=\"".$filename."\"");
135 header("Content-Length: ".dol_strlen($output));
136 header("Connection: close");
137 header("Content-Type: text/x-vcard; name=\"".$filename."\"");
138 
139 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 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.
$conf db user
Definition: repair.php:109
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...