dolibarr  7.0.0-beta
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@capnetworks.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/vcard.class.php';
30 
31 $contact = new Contact($db);
32 
33 
34 $id = GETPOST('id', 'int');
35 
36 // Security check
37 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
38 
39 
40 $result=$contact->fetch($id);
41 if ($result <= 0)
42 {
43  dol_print_error($contact->error);
44  exit;
45 }
46 
47 $physicalperson=1;
48 
49 $company = new Societe($db);
50 if ($contact->socid)
51 {
52  $result=$company->fetch($contact->socid);
53 }
54 
55 // We create VCard
56 $v = new vCard();
57 $v->setProdId('Dolibarr '.DOL_VERSION);
58 
59 $v->setUid('DOLIBARR-CONTACTID-'.$contact->id);
60 $v->setName($contact->lastname, $contact->firstname, "", "", "");
61 $v->setFormattedName($contact->getFullName($langs));
62 
63 // By default, all informations are for work (except phone_perso and phone_mobile)
64 $v->setPhoneNumber($contact->phone_pro, "PREF;WORK;VOICE");
65 $v->setPhoneNumber($contact->phone_mobile, "CELL;VOICE");
66 $v->setPhoneNumber($contact->fax, "WORK;FAX");
67 
68 $v->setAddress("", "", $contact->address, $contact->town, "", $contact->zip, ($contact->country_code?$contact->country:''), "WORK;POSTAL");
69 $v->setLabel("", "", $contact->address, $contact->town, "", $contact->zip, ($contact->country_code?$contact->country:''), "WORK");
70 $v->setEmail($contact->email,'internet,pref');
71 $v->setNote($contact->note);
72 
73 $v->setTitle($contact->poste);
74 
75 // Data from linked company
76 if ($company->id)
77 {
78  $v->setURL($company->url, "WORK");
79  if (! $contact->phone_pro) $v->setPhoneNumber($company->phone, "WORK;VOICE");
80  if (! $contact->fax) $v->setPhoneNumber($company->fax, "WORK;FAX");
81  if (! $contact->zip) $v->setAddress("", "", $company->address, $company->town, "", $company->zip, $company->country, "WORK;POSTAL");
82  if ($company->email != $contact->email) $v->setEmail($company->email,'internet');
83  // Si contact lie a un tiers non de type "particulier"
84  if ($contact->typent_code != 'TE_PRIVATE') $v->setOrg($company->name);
85 }
86 
87 // Personal informations
88 $v->setPhoneNumber($contact->phone_perso, "HOME;VOICE");
89 if ($contact->birthday) $v->setBirthday($contact->birthday);
90 
91 $db->close();
92 
93 
94 // Renvoi la VCard au navigateur
95 
96 $output = $v->getVCard();
97 
98 $filename =trim(urldecode($v->getFileName())); // "Nom prenom.vcf"
99 $filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
100 //$filename = dol_sanitizeFileName($filename);
101 
102 
103 header("Content-Disposition: attachment; filename=\"".$filename."\"");
104 header("Content-Length: ".dol_strlen($output));
105 header("Connection: close");
106 header("Content-Type: text/x-vcard; name=\"".$filename."\"");
107 
108 print $output;
Class to manage contact/addresses.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Class to buld vCard files.
Definition: vcard.class.php:85
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage third parties objects (customers, suppliers, prospects...)
print
Draft customers invoices.
Definition: index.php:91
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.