dolibarr 21.0.0-alpha
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 = GETPOSTINT('id');
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($db, $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
62if (GETPOST('mode') == 'virtualcard') {
63 // Clean the data to show according to options
64 if (getDolUserInt('USER_PUBLIC_HIDE_PHOTO', 0, $object)) {
65 $object->photo = '';
66 }
67 if (getDolUserInt('USER_PUBLIC_HIDE_EMAIL', 0, $object)) {
68 $object->email = '';
69 }
70 if (getDolUserInt('USER_PUBLIC_HIDE_URL', 0, $object)) {
71 $object->url = '';
72 }
73 if (getDolUserInt('USER_PUBLIC_HIDE_OFFICE_PHONE', 0, $object)) {
74 $object->office_phone = '';
75 }
76 if (getDolUserInt('USER_PUBLIC_HIDE_OFFICE_FAX', 0, $object)) {
77 $object->office_fax = '';
78 }
79 if (getDolUserInt('USER_PUBLIC_HIDE_USER_MOBILE', 0, $object)) {
80 $object->user_mobile = '';
81 }
82 if (!getDolUserInt('USER_PUBLIC_SHOW_BIRTH', 0, $object)) {
83 $object->birth = '';
84 }
85 if (!getDolUserInt('USER_PUBLIC_SHOW_ADDRESS', 0, $object)) {
86 $object->country_code = '';
87 $object->zip = '';
88 $object->address = '';
89 }
90 if (getDolUserInt('USER_PUBLIC_HIDE_SOCIALNETWORKS', 0, $object)) {
91 $object->socialnetworks = array();
92 }
93
94 // Business section
95 if (getDolUserInt('USER_PUBLIC_HIDE_COMPANY', 0, $object) || getDolUserInt('USER_PUBLIC_HIDE_SOCIALNETWORKS_BUSINESS', 0, $object)) {
96 $company->socialnetworks = array();
97 }
98}
99
100// We create VCard
101$v = new vCard();
102$output = $v->buildVCardString($object, $company, $langs);
103
104$filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf"
105$filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
106//$filename = dol_sanitizeFileName($filename);
107
108top_httphead('text/x-vcard; name="'.$filename.'"');
109
110header("Content-Disposition: attachment; filename=\"".$filename."\"");
111header("Content-Length: ".dol_strlen($output));
112header("Connection: close");
113
114print $output;
115
116$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Class to build vCard files.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.