|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* Copyright (C) 2023 Frédéric France <[email protected]> |
|
4
|
|
|
* Copyright (C) 2024 MDW <[email protected]> |
|
5
|
|
|
* Copyright (C) 2024 Rafael San José <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU General Public License as published by |
|
9
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License |
|
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* \file htdocs/core/class/commonpeople.class.php |
|
23
|
|
|
* \ingroup core |
|
24
|
|
|
* \brief File of the superclass of object classes that support people |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
namespace DoliCore\Model; |
|
29
|
|
|
|
|
30
|
|
|
use Contact; |
|
31
|
|
|
use ExtraLanguages; |
|
32
|
|
|
use Form; |
|
33
|
|
|
use Societe; |
|
34
|
|
|
use Translate; |
|
35
|
|
|
use User; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Support class for thirdparties, contacts, members, users or resources |
|
39
|
|
|
*/ |
|
40
|
|
|
trait CommonPeople |
|
41
|
|
|
{ |
|
42
|
|
|
/** |
|
43
|
|
|
* @var string Address |
|
44
|
|
|
*/ |
|
45
|
|
|
public $address; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var string zip code |
|
49
|
|
|
*/ |
|
50
|
|
|
public $zip; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var string town |
|
54
|
|
|
*/ |
|
55
|
|
|
public $town; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var int $state_id |
|
59
|
|
|
*/ |
|
60
|
|
|
public $state_id; // The state/department |
|
61
|
|
|
public $state_code; |
|
62
|
|
|
public $state; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var string email |
|
66
|
|
|
*/ |
|
67
|
|
|
public $email; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var string url |
|
71
|
|
|
*/ |
|
72
|
|
|
public $url; |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Return full name (civility+' '+name+' '+lastname) |
|
77
|
|
|
* |
|
78
|
|
|
* @param Translate $langs Language object for translation of civility (used only if option is 1) |
|
79
|
|
|
* @param int $option 0=No option, 1=Add civility |
|
80
|
|
|
* @param int $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname, 3=Firstname if |
|
81
|
|
|
* defined else lastname, 4=Lastname, 5=Lastname if defined else firstname |
|
82
|
|
|
* @param int $maxlen Maximum length |
|
83
|
|
|
* |
|
84
|
|
|
* @return string String with full name |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0) |
|
87
|
|
|
{ |
|
88
|
|
|
//print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n"; |
|
89
|
|
|
$lastname = $this->lastname; |
|
90
|
|
|
$firstname = $this->firstname; |
|
91
|
|
|
if (empty($lastname)) { |
|
92
|
|
|
$lastname = (isset($this->lastname) ? $this->lastname : (isset($this->name) ? $this->name : (isset($this->nom) ? $this->nom : (isset($this->societe) ? $this->societe : (isset($this->company) ? $this->company : ''))))); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$ret = ''; |
|
96
|
|
|
if (!empty($option) && !empty($this->civility_code)) { |
|
97
|
|
|
if ($langs->transnoentitiesnoconv("Civility" . $this->civility_code) != "Civility" . $this->civility_code) { |
|
98
|
|
|
$ret .= $langs->transnoentitiesnoconv("Civility" . $this->civility_code) . ' '; |
|
99
|
|
|
} else { |
|
100
|
|
|
$ret .= $this->civility_code . ' '; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$ret .= dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
105
|
|
|
|
|
106
|
|
|
return dol_string_nohtmltag(dol_trunc($ret, $maxlen)); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Return full address for banner |
|
111
|
|
|
* |
|
112
|
|
|
* @param string $htmlkey HTML id to make banner content unique |
|
113
|
|
|
* @param Object $object Object (thirdparty, thirdparty of contact for contact, null for a member) |
|
114
|
|
|
* |
|
115
|
|
|
* @return string Full address string |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getBannerAddress($htmlkey, $object) |
|
118
|
|
|
{ |
|
119
|
|
|
global $conf, $langs, $form, $extralanguages; |
|
120
|
|
|
|
|
121
|
|
|
$countriesusingstate = ['AU', 'US', 'IN', 'GB', 'ES', 'UK', 'TR']; // See also option MAIN_FORCE_STATE_INTO_ADDRESS |
|
122
|
|
|
|
|
123
|
|
|
$contactid = 0; |
|
124
|
|
|
$thirdpartyid = 0; |
|
125
|
|
|
$elementforaltlanguage = $this->element; |
|
126
|
|
|
if ($this->element == 'societe') { |
|
127
|
|
|
/** @var Societe $this */ |
|
128
|
|
|
$thirdpartyid = $this->id; |
|
129
|
|
|
} |
|
130
|
|
|
if ($this->element == 'contact') { |
|
131
|
|
|
/** @var Contact $this */ |
|
132
|
|
|
$contactid = $this->id; |
|
133
|
|
|
$thirdpartyid = empty($this->fk_soc) ? 0 : $this->fk_soc; |
|
134
|
|
|
} |
|
135
|
|
|
if ($this->element == 'user') { |
|
136
|
|
|
/** @var User $this */ |
|
137
|
|
|
$contactid = $this->contact_id; |
|
138
|
|
|
$thirdpartyid = empty($object->fk_soc) ? 0 : $object->fk_soc; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
$out = ''; |
|
142
|
|
|
|
|
143
|
|
|
$outdone = 0; |
|
144
|
|
|
$coords = $this->getFullAddress(1, ', ', getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT')); |
|
|
|
|
|
|
145
|
|
|
if ($coords) { |
|
146
|
|
|
if (!empty($conf->use_javascript_ajax)) { |
|
147
|
|
|
// Add picto with tooltip on map |
|
148
|
|
|
$namecoords = ''; |
|
149
|
|
|
if ($this->element == 'contact' && getDolGlobalString('MAIN_SHOW_COMPANY_NAME_IN_BANNER_ADDRESS')) { |
|
150
|
|
|
$namecoords .= $object->name . '<br>'; |
|
151
|
|
|
} |
|
152
|
|
|
$namecoords .= $this->getFullName($langs, 1) . '<br>' . $coords; |
|
153
|
|
|
// hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile |
|
154
|
|
|
$out .= '<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\'' . dol_escape_js($namecoords) . '\',\'' . dol_escape_js($langs->trans("HelpCopyToClipboard")) . '\');">'; |
|
155
|
|
|
$out .= img_picto($langs->trans("Address"), 'map-marker-alt'); |
|
156
|
|
|
$out .= '</a> '; |
|
157
|
|
|
} |
|
158
|
|
|
$address = dol_print_address($coords, 'address_' . $htmlkey . '_' . $this->id, $this->element, $this->id, 1, ', '); |
|
159
|
|
|
if ($address) { |
|
160
|
|
|
$out .= $address; |
|
161
|
|
|
$outdone++; |
|
162
|
|
|
} |
|
163
|
|
|
$outdone++; |
|
164
|
|
|
|
|
165
|
|
|
// List of extra languages |
|
166
|
|
|
$arrayoflangcode = []; |
|
167
|
|
|
if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) { |
|
168
|
|
|
$arrayoflangcode[] = getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
if (is_array($arrayoflangcode) && count($arrayoflangcode)) { |
|
172
|
|
|
if (!is_object($extralanguages)) { |
|
173
|
|
|
include_once DOL_DOCUMENT_ROOT . '/core/class/extralanguages.class.php'; |
|
174
|
|
|
$extralanguages = new ExtraLanguages($this->db); |
|
175
|
|
|
} |
|
176
|
|
|
$extralanguages->fetch_name_extralanguages($elementforaltlanguage); |
|
177
|
|
|
|
|
178
|
|
|
if (!empty($extralanguages->attributes[$elementforaltlanguage]['address']) || !empty($extralanguages->attributes[$elementforaltlanguage]['town'])) { |
|
179
|
|
|
$out .= "<!-- alternatelanguage for '" . $elementforaltlanguage . "' set to fields '" . implode(',', $extralanguages->attributes[$elementforaltlanguage]) . "' -->\n"; |
|
180
|
|
|
$this->fetchValuesForExtraLanguages(); |
|
|
|
|
|
|
181
|
|
|
if (!is_object($form)) { |
|
182
|
|
|
$form = new Form($this->db); |
|
183
|
|
|
} |
|
184
|
|
|
$htmltext = ''; |
|
185
|
|
|
// If there is extra languages |
|
186
|
|
|
foreach ($arrayoflangcode as $extralangcode) { |
|
187
|
|
|
$s = picto_from_langcode($extralangcode, 'class="pictoforlang paddingright"'); |
|
188
|
|
|
// This also call dol_format_address() |
|
189
|
|
|
$coords = $this->getFullAddress(1, ', ', $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT, $extralangcode); |
|
190
|
|
|
$htmltext .= $s . dol_print_address($coords, 'address_' . $htmlkey . '_' . $this->id, $this->element, $this->id, 1, ', '); |
|
191
|
|
|
} |
|
192
|
|
|
$out .= $form->textwithpicto('', $htmltext, -1, 'language', 'opacitymedium paddingleft'); |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
// If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress |
|
198
|
|
|
if ( |
|
199
|
|
|
!in_array($this->country_code, $countriesusingstate) && !getDolGlobalString('MAIN_FORCE_STATE_INTO_ADDRESS') |
|
200
|
|
|
&& !getDolGlobalString('SOCIETE_DISABLE_STATE') && $this->state |
|
201
|
|
|
) { |
|
202
|
|
|
if (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 && $this->region) { |
|
203
|
|
|
$out .= ($outdone ? ' - ' : '') . $this->region . ' - ' . $this->state; |
|
204
|
|
|
} else { |
|
205
|
|
|
$out .= ($outdone ? ' - ' : '') . $this->state; |
|
206
|
|
|
} |
|
207
|
|
|
$outdone++; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
if ($outdone) { |
|
211
|
|
|
$out = '<div class="address inline-block">' . $out . '</div>'; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
if (!empty($this->phone) || !empty($this->phone_pro) || !empty($this->phone_mobile) || !empty($this->phone_perso) || !empty($this->fax) || !empty($this->office_phone) || !empty($this->user_mobile) || !empty($this->office_fax)) { |
|
215
|
|
|
$out .= ($outdone ? '<br>' : ''); |
|
216
|
|
|
} |
|
217
|
|
|
if (!empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone |
|
218
|
|
|
$out .= dol_print_phone($this->phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); |
|
219
|
|
|
$outdone++; |
|
220
|
|
|
} |
|
221
|
|
|
if (!empty($this->phone_pro)) { |
|
222
|
|
|
$out .= dol_print_phone($this->phone_pro, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); |
|
223
|
|
|
$outdone++; |
|
224
|
|
|
} |
|
225
|
|
|
if (!empty($this->phone_mobile)) { |
|
226
|
|
|
$out .= dol_print_phone($this->phone_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'mobile', $langs->trans("PhoneMobile")); |
|
227
|
|
|
$outdone++; |
|
228
|
|
|
} |
|
229
|
|
|
if (!empty($this->phone_perso)) { |
|
230
|
|
|
$out .= dol_print_phone($this->phone_perso, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePerso")); |
|
231
|
|
|
$outdone++; |
|
232
|
|
|
} |
|
233
|
|
|
if (!empty($this->office_phone)) { |
|
234
|
|
|
$out .= dol_print_phone($this->office_phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); |
|
235
|
|
|
$outdone++; |
|
236
|
|
|
} |
|
237
|
|
|
if (!empty($this->user_mobile)) { |
|
238
|
|
|
$out .= dol_print_phone($this->user_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'mobile', $langs->trans("PhoneMobile")); |
|
239
|
|
|
$outdone++; |
|
240
|
|
|
} |
|
241
|
|
|
if (!empty($this->fax)) { |
|
242
|
|
|
$out .= dol_print_phone($this->fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', ' ', 'fax', $langs->trans("Fax")); |
|
243
|
|
|
$outdone++; |
|
244
|
|
|
} |
|
245
|
|
|
if (!empty($this->office_fax)) { |
|
246
|
|
|
$out .= dol_print_phone($this->office_fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', ' ', 'fax', $langs->trans("Fax")); |
|
247
|
|
|
$outdone++; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
if ($out) { |
|
251
|
|
|
$out .= '<div style="clear: both;"></div>'; |
|
252
|
|
|
} |
|
253
|
|
|
$outdone = 0; |
|
254
|
|
|
if (!empty($this->email)) { |
|
255
|
|
|
$out .= dol_print_email($this->email, $this->id, $object->id, 1, 0, 0, 1); |
|
256
|
|
|
$outdone++; |
|
257
|
|
|
} |
|
258
|
|
|
if (!empty($this->url)) { |
|
259
|
|
|
//$out.=dol_print_url($this->url,'_goout',0,1);//steve changed to blank |
|
260
|
|
|
if (!empty($this->email)) { |
|
261
|
|
|
$out .= ' '; |
|
262
|
|
|
} |
|
263
|
|
|
$out .= dol_print_url($this->url, '_blank', 0, 1); |
|
264
|
|
|
$outdone++; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
if (isModEnabled('socialnetworks')) { |
|
268
|
|
|
$outsocialnetwork = ''; |
|
269
|
|
|
|
|
270
|
|
|
if (!empty($this->socialnetworks) && is_array($this->socialnetworks) && count($this->socialnetworks) > 0) { |
|
271
|
|
|
$socialnetworksdict = getArrayOfSocialNetworks(); |
|
272
|
|
|
foreach ($this->socialnetworks as $key => $value) { |
|
273
|
|
|
if ($value) { |
|
274
|
|
|
$outsocialnetwork .= dol_print_socialnetworks($value, $this->id, $object->id, $key, $socialnetworksdict); |
|
275
|
|
|
} |
|
276
|
|
|
$outdone++; |
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
if ($outsocialnetwork) { |
|
281
|
|
|
$out .= '<div style="clear: both;">' . $outsocialnetwork . '</div>'; |
|
282
|
|
|
} |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
if ($out) { |
|
286
|
|
|
return '<!-- BEGIN part to show address block -->' . "\n" . $out . '<!-- END Part to show address block -->' . "\n"; |
|
287
|
|
|
} else { |
|
288
|
|
|
return ''; |
|
289
|
|
|
} |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* Set to upper or ucwords/lower if needed |
|
294
|
|
|
* |
|
295
|
|
|
* @return void |
|
296
|
|
|
*/ |
|
297
|
|
|
public function setUpperOrLowerCase() |
|
298
|
|
|
{ |
|
299
|
|
|
if (getDolGlobalString('MAIN_FIRST_TO_UPPER')) { |
|
300
|
|
|
$this->lastname = dol_ucwords(dol_strtolower($this->lastname)); |
|
301
|
|
|
$this->firstname = dol_ucwords(dol_strtolower($this->firstname)); |
|
302
|
|
|
$this->name = dol_ucwords(dol_strtolower($this->name)); |
|
303
|
|
|
if (property_exists($this, 'name_alias')) { |
|
304
|
|
|
$this->name_alias = isset($this->name_alias) ? dol_ucwords(dol_strtolower($this->name_alias)) : ''; |
|
305
|
|
|
} |
|
306
|
|
|
} |
|
307
|
|
|
if (getDolGlobalString('MAIN_ALL_TO_UPPER')) { |
|
308
|
|
|
$this->lastname = dol_strtoupper($this->lastname); |
|
309
|
|
|
$this->name = dol_strtoupper($this->name); |
|
310
|
|
|
if (property_exists($this, 'name_alias')) { |
|
311
|
|
|
$this->name_alias = dol_strtoupper($this->name_alias); |
|
312
|
|
|
} |
|
313
|
|
|
} |
|
314
|
|
|
if (getDolGlobalString('MAIN_ALL_TOWN_TO_UPPER')) { |
|
315
|
|
|
$this->address = dol_strtoupper($this->address); |
|
316
|
|
|
$this->town = dol_strtoupper($this->town); |
|
317
|
|
|
} |
|
318
|
|
|
if (isset($this->email)) { |
|
319
|
|
|
$this->email = dol_strtolower($this->email); |
|
320
|
|
|
} |
|
321
|
|
|
if (isset($this->personal_email)) { |
|
322
|
|
|
$this->personal_email = dol_strtolower($this->personal_email); |
|
323
|
|
|
} |
|
324
|
|
|
} |
|
325
|
|
|
} |
|
326
|
|
|
|