dolibarr  16.0.5
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) 2020-2021 Frédéric France <frederic.france@netlogic.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 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/vcard.class.php';
32 
33 $id = GETPOST('id', 'int');
34 $ref = GETPOST('ref', 'alphanohtml');
35 
36 $object = new adherent($db);
37 
38 // Fetch object
39 if ($id > 0 || !empty($ref)) {
40  // Load member
41  $result = $object->fetch($id, $ref);
42 
43  // Define variables to know what current user can do on users
44  $canadduser = ($user->admin || $user->rights->user->user->creer);
45  // Define variables to know what current user can do on properties of user linked to edited member
46  if ($object->user_id) {
47  // $User is the user who edits, $object->user_id is the id of the related user in the edited member
48  $caneditfielduser = ((($user->id == $object->user_id) && $user->rights->user->self->creer)
49  || (($user->id != $object->user_id) && $user->rights->user->user->creer));
50  $caneditpassworduser = ((($user->id == $object->user_id) && $user->rights->user->self->password)
51  || (($user->id != $object->user_id) && $user->rights->user->user->password));
52  }
53 }
54 
55 // Define variables to determine what the current user can do on the members
56 $canaddmember = $user->rights->adherent->creer;
57 // Define variables to determine what the current user can do on the properties of a member
58 if ($id) {
59  $caneditfieldmember = $user->rights->adherent->creer;
60 }
61 
62 // Security check
63 $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
64 
65 
66 /*
67  * Actions
68  */
69 
70 // None
71 
72 
73 /*
74  * View
75  */
76 
77 $company = new Societe($db);
78 if ($object->socid) {
79  $result = $company->fetch($object->socid);
80 }
81 
82 
83 
84 // We create VCard
85 $v = new vCard();
86 $v->setProdId('Dolibarr '.DOL_VERSION);
87 
88 $v->setUid('DOLIBARR-ADHERENTID-'.$object->id);
89 $v->setName($object->lastname, $object->firstname, "", $object->civility, "");
90 $v->setFormattedName($object->getFullName($langs, 1));
91 
92 $v->setPhoneNumber($object->phone_pro, "TYPE=WORK;VOICE");
93 //$v->setPhoneNumber($object->phone_perso,"TYPE=HOME;VOICE");
94 $v->setPhoneNumber($object->phone_mobile, "TYPE=CELL;VOICE");
95 $v->setPhoneNumber($object->fax, "TYPE=WORK;FAX");
96 
97 $country = $object->country_code ? $object->country : '';
98 
99 $v->setAddress("", "", $object->address, $object->town, $object->state, $object->zip, $country, "TYPE=WORK;POSTAL");
100 $v->setLabel("", "", $object->address, $object->town, $object->state, $object->zip, $country, "TYPE=WORK");
101 
102 $v->setEmail($object->email);
103 $v->setNote($object->note_public);
104 $v->setTitle($object->poste);
105 
106 // Data from linked company
107 if ($company->id) {
108  $v->setURL($company->url, "TYPE=WORK");
109  if (!$object->phone_pro) {
110  $v->setPhoneNumber($company->phone, "TYPE=WORK;VOICE");
111  }
112  if (!$object->fax) {
113  $v->setPhoneNumber($company->fax, "TYPE=WORK;FAX");
114  }
115  if (!$object->zip) {
116  $v->setAddress("", "", $company->address, $company->town, $company->state, $company->zip, $company->country, "TYPE=WORK;POSTAL");
117  }
118  // when company e-mail is empty, use only adherent e-mail
119  if (empty(trim($company->email))) {
120  // was set before, don't set twice
121  } elseif (empty(trim($object->email))) {
122  // when adherent e-mail is empty, use only company e-mail
123  $v->setEmail($company->email);
124  } elseif (strtolower(end(explode("@", $object->email))) == strtolower(end(explode("@", $company->email)))) {
125  // when e-mail domain of adherent and company are the same, use adherent e-mail at first (and company e-mail at second)
126  $v->setEmail($object->email);
127 
128  // support by Microsoft Outlook (2019 and possible earlier)
129  $v->setEmail($company->email, 'INTERNET');
130  } else {
131  // when e-mail of adherent and company complete different use company e-mail at first (and adherent e-mail at second)
132  $v->setEmail($company->email);
133 
134  // support by Microsoft Outlook (2019 and possible earlier)
135  $v->setEmail($object->email, 'INTERNET');
136  }
137 
138  // Si adherent lie a un tiers non de type "particulier"
139  if ($company->typent_code != 'TE_PRIVATE') {
140  $v->setOrg($company->name);
141  }
142 }
143 
144 // Personal informations
145 $v->setPhoneNumber($object->phone_perso, "TYPE=HOME;VOICE");
146 if ($object->birth) {
147  $v->setBirthday($object->birth);
148 }
149 
150 $db->close();
151 
152 
153 // Renvoi la VCard au navigateur
154 
155 $output = $v->getVCard();
156 
157 $filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf"
158 $filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
159 //$filename = dol_sanitizeFileName($filename);
160 
161 
162 header("Content-Disposition: attachment; filename=\"".$filename."\"");
163 header("Content-Length: ".dol_strlen($output));
164 header("Connection: close");
165 header("Content-Type: text/x-vcard; name=\"".$filename."\"");
166 
167 print $output;
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
vCard
Class to buld vCard files.
Definition: vcard.class.php:88
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747