From 5c3d4326f479c7bff185703fe659380c6ba323bd Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 17 Nov 2024 12:32:01 +0100 Subject: [PATCH] NEW: vcard (vcf) download for third party (#31957) # NEW: vcard (vcf) download for third party (#31957) This adds a download link to fetch a vcard for a Third party. --- htdocs/societe/card.php | 6 ++- htdocs/societe/vcard.php | 102 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 htdocs/societe/vcard.php diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index e4a3c6c47d5ec..4c0502d84415b 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -2921,7 +2921,11 @@ function init_check_no_email(input) { $linkback = ''.$langs->trans("BackToList").''; - dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom'); + $morehtmlref = ''; + $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"'); + $morehtmlref .= ''; + + dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom', $morehtmlref); // Call Hook tabContentViewThirdparty $parameters = array(); diff --git a/htdocs/societe/vcard.php b/htdocs/societe/vcard.php new file mode 100644 index 0000000000000..f12bbcd830616 --- /dev/null +++ b/htdocs/societe/vcard.php @@ -0,0 +1,102 @@ + + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2020 Tobias Sekan + * Copyright (C) 2024 MDW + * Copyright (C) 2024 Frédéric France + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/societe/vcard.php + * \ingroup societe + * \brief Third party vcard download + */ + +// Load Dolibarr environment +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/vcard.class.php'; + +/** + * @var Conf $conf + * @var DoliDB $db + * @var HookManager $hookmanager + * @var Translate $langs + * @var User $user + */ + +$company = new Societe($db); + + +$socid = GETPOSTINT('socid'); + +// Security check +$result = restrictedArea($user, 'societe', $socid, '&societe'); + + +$result = $company->fetch($socid); +if ($result <= 0) { + dol_print_error($db, $company->error); + exit; +} + + +// Compute VCard +$v = new vCard(); +$v->setProdId('Dolibarr '.DOL_VERSION); + +$v->setUid('DOLIBARR-THIRDPARTYID-'.$societe->id); + + +// Data from company +$v->setURL($company->url, "TYPE=WORK"); +$v->setPhoneNumber($company->phone, "TYPE=WORK;VOICE"); +$v->setPhoneNumber($company->fax, "TYPE=WORK;FAX"); +$v->setAddress("", "", $company->address, $company->town, $company->state, $company->zip, $company->country, "TYPE=WORK;POSTAL"); +if (!empty(trim($company->email))) { + $v->setEmail($company->email); +} + +// If the company is not a private person +if ($company->typent_code != 'TE_PRIVATE') { + $v->setOrg($company->name); + $v->filename = $company->name.'.vcf'; + $v->setFormattedName($company->name.(!empty($company->name_alias) ? ' ('.$company->name_alias.')' : '')); +} else { + $v->setName($company->lastname, $company->firstname, "", $company->civility, ""); + // TODO: Reuse getFullName() from commonsocpeople. + $v->setFormattedName(dolGetFirstLastname($company->firstname, $company->lastname)); +} + +$db->close(); + + +// Send the vCard to the web client + +$output = $v->getVCard(); + +$filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf" +$filenameurlencoded = dol_sanitizeFileName(urlencode($filename)); +//$filename = dol_sanitizeFileName($filename); + + +header("Content-Disposition: attachment; filename=\"".$filename."\""); +header("Content-Length: ".dol_strlen($output)); +header("Connection: close"); +header("Content-Type: text/x-vcard; name=\"".$filename."\""); + +print $output;