dolibarr 23.0.3
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) 2024 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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.'/societe/class/societe.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/vcard.class.php';
33
42$company = new Societe($db);
43
44
45$socid = GETPOSTINT('id');
46
47// Security check
48$result = restrictedArea($user, 'societe', $socid, '&societe');
49
50
51$result = $company->fetch($socid);
52if ($result <= 0) {
53 dol_print_error($db, $company->error);
54 exit;
55}
56
57
58// Compute VCard
59$v = new vCard();
60$v->setProdId('Dolibarr '.DOL_VERSION);
61
62$v->setUid('DOLIBARR-THIRDPARTYID-'.$company->id);
63
64
65// Data from company
66if (!empty($company->url)) {
67 $v->setURL($company->url, "TYPE=WORK");
68}
69if (!empty($company->phone)) {
70 $v->setPhoneNumber($company->phone, "TYPE=WORK;VOICE");
71}
72if (!empty($company->phone_mobile)) {
73 $v->setPhoneNumber($company->phone_mobile, "TYPE=CELL;VOICE");
74}
75if (!empty($company->fax)) {
76 $v->setPhoneNumber($company->fax, "TYPE=WORK;FAX");
77}
78$v->setAddress("", "", $company->address, $company->town, $company->state, $company->zip, $company->country, "TYPE=WORK;POSTAL");
79if (!empty(trim($company->email))) {
80 $v->setEmail($company->email);
81}
82
83// If the company is not a private person
84if ($company->typent_code != 'TE_PRIVATE') {
85 $v->setOrg($company->name);
86 $v->filename = $company->name.'.vcf';
87
88 $v->setFormattedName($company->name.(!empty($company->name_alias) ? ' ('.$company->name_alias.')' : ''));
89} else {
90 $civility = (string) $company->civility_code;
91 if (!empty($civility)) {
92 $transKey = "Civility".$civility;
93 $trans = $langs->transnoentitiesnoconv($transKey);
94 if ($trans !== $transKey) {
95 $civility = $trans;
96 }
97 }
98 $v->setName($company->lastname, $company->firstname, "", $civility, "");
99 $v->setFormattedName($company->getFullName($langs));
100}
101
102
103$db->close();
104
105
106// Send the vCard to the web client
107
108$output = $v->getVCard();
109
110$filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf"
111$filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
112//$filename = dol_sanitizeFileName($filename);
113
114
115header("Content-Disposition: attachment; filename=\"".$filename."\"");
116header("Content-Length: ".dol_strlen($output));
117header("Connection: close");
118header("Content-Type: text/x-vcard; name=\"".$filename."\"");
119
120print $output;
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_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.