dolibarr 18.0.6
vcard.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2023 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) 2021-2022 Anthony Berton <anthony.berton@bb2a.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
31require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/vcard.class.php';
33
34$id = GETPOST('id', 'int');
35
36// Security check
37$socid = 0;
38if ($user->socid > 0) {
39 $socid = $user->socid;
40}
41$feature2 = 'user';
42$result = restrictedArea($user, 'user', $id, 'user', $feature2);
43
44$object = new User($db);
45$result = $object->fetch($id);
46if ($result <= 0) {
47 dol_print_error($object->error);
48 exit;
49}
50
51// Data from linked company
52$company = new Societe($db);
53if ($object->socid > 0) {
54 $result = $company->fetch($object->socid);
55}
56
57
58/*
59 * View
60 */
61
62// We create VCard
63$v = new vCard();
64$output = $v->buildVCardString($object, $company, $langs);
65
66$filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf"
67$filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
68//$filename = dol_sanitizeFileName($filename);
69
70top_httphead('text/x-vcard; name="'.$filename.'"');
71
72header("Content-Disposition: attachment; filename=\"".$filename."\"");
73header("Content-Length: ".dol_strlen($output));
74header("Connection: close");
75
76print $output;
77
78$db->close();
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
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.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
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.