dolibarr 24.0.0-beta
commonpeople.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2023-2025 Frédéric France <frederic.france@free.fr>
3 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
57trait CommonPeople
58{
62 public $address;
63
67 public $zip;
68
72 public $town;
73
77 public $state_id;
81 public $state_code;
82
86 public $state;
87
91 public $email;
92
96 public $url;
97
98
108 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
109 {
110 //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
111 $lastname = $this->lastname;
112 $firstname = $this->firstname;
113 if (empty($lastname)) {
114 // societe is deprecated - @suppress-next-line PhanUndeclaredProperty
115 $lastname = (isset($this->lastname) ? $this->lastname : (isset($this->name) ? $this->name : (property_exists($this, 'nom') && isset($this->nom) ? $this->nom : (property_exists($this, 'societe') && isset($this->societe) ? $this->societe : (property_exists($this, 'company') && isset($this->company) ? $this->company : ''))))); // @phpstan-ignore-line
116 }
117
118 $ret = '';
119 if (!empty($option) && !empty($this->civility_code)) {
120 if ($langs->transnoentitiesnoconv("Civility".$this->civility_code) != "Civility".$this->civility_code) {
121 $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_code).' ';
122 } else {
123 $ret .= $this->civility_code.' ';
124 }
125 }
126
127 $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
128
129 return dol_string_nohtmltag(dol_trunc($ret, $maxlen));
130 }
131
141 public function getAnonymisableFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
142 {
143 if (getDolGlobalInt('MAIN_ANONYMIZE_USER_FULLNAME') == 1) {
144 return '***';
145 }
146 return $this->getFullName($langs, $option, $nameorder, $maxlen);
147 }
148
154 public function getCivilityLabel()
155 {
156 global $langs;
157
158 $code = (!empty($this->civility_code) ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite : '')));
159 if (empty($code)) {
160 return '';
161 }
162
163 $langs->load("dict");
164 return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
165 }
166
167
168
176 public function getBannerAddress($htmlkey, $object)
177 {
178 global $conf, $langs, $form, $extralanguages;
179
180 $countriesusingstate = array('AU', 'US', 'IN', 'GB', 'ES', 'UK', 'TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS
181
182 $contactid = 0;
183 $thirdpartyid = 0;
184 $elementforaltlanguage = $this->element;
185 if ($this->element === 'societe' && $this instanceof Societe) {
186 $thirdpartyid = $this->id;
187 }
188 if ($this->element === 'contact' && $this instanceof Contact) {
189 $contactid = $this->id;
190 $thirdpartyid = empty($this->fk_soc) ? 0 : $this->fk_soc;
191 }
192 if ($this->element == 'member' && $this instanceof Adherent) {
193 $contactid = $this->id;
194 $thirdpartyid = empty($this->socid) ? 0 : $this->socid;
195 }
196 if ($this->element === 'user' && $this instanceof User) {
197 $contactid = $this->contact_id;
198 $thirdpartyid = empty($object->fk_soc) ? 0 : $object->fk_soc;
199 }
200 if ($this->element == 'recruitmentcandidature' && $this instanceof RecruitmentCandidature) {
201 $thirdpartyid = 0;
202 }
203
204 $out = '';
205
206 $outdone = 0;
207 $coords = $this->getFullAddress(1, ', ', getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT'));
208 if ($coords) {
209 if (!empty($conf->use_javascript_ajax)) {
210 // Add picto with tooltip on map
211 $namecoords = '';
212 if ($this->element == 'contact' && getDolGlobalString('MAIN_SHOW_COMPANY_NAME_IN_BANNER_ADDRESS')) {
213 $namecoords .= $object->name.'<br>';
214 }
215 $namecoords .= $this->getFullName($langs, 1).'<br>'.$coords;
216 // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile
217 $out .= '<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\', \''.dol_escape_js('<span class="opacitymedium">'.$langs->trans("HelpCopyToClipboard").'</span>').'\', \''.dol_escape_js($langs->trans("Copy").' / '.$langs->trans("Paste")).'\');">';
218 $out .= img_picto($langs->trans("Address"), 'map-marker-alt');
219 $out .= '</a> ';
220 }
221 $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
222 if ($address) {
223 $out .= $address;
224 $outdone++;
225 }
226 $outdone++;
227
228 // List of extra languages
229 $arrayoflangcode = array();
230 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
231 $arrayoflangcode[] = getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE');
232 }
233
234 if (/* is_array($arrayoflangcode) && */count($arrayoflangcode)) {
235 if (!is_object($extralanguages)) {
236 include_once DOL_DOCUMENT_ROOT.'/core/class/extralanguages.class.php';
237 $extralanguages = new ExtraLanguages($this->db);
238 }
239 $extralanguages->fetch_name_extralanguages($elementforaltlanguage);
240
241 if (!empty($extralanguages->attributes[$elementforaltlanguage]['address']) || !empty($extralanguages->attributes[$elementforaltlanguage]['town'])) {
242 $out .= "<!-- alternatelanguage for '".$elementforaltlanguage."' set to fields '".implode(',', $extralanguages->attributes[$elementforaltlanguage])."' -->\n";
243 $this->fetchValuesForExtraLanguages();
244 if (!is_object($form)) {
245 $form = new Form($this->db);
246 }
247 $htmltext = '';
248 // If there is extra languages
249 foreach ($arrayoflangcode as $extralangcode) {
250 $s = picto_from_langcode($extralangcode, 'class="pictoforlang paddingright"');
251 // This also call dol_format_address()
252 $coords = $this->getFullAddress(1, ', ', $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT, $extralangcode);
253 $htmltext .= $s.dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
254 }
255 $out .= $form->textwithpicto('', $htmltext, -1, 'language', 'opacitymedium paddingleft');
256 }
257 }
258 }
259
260 // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress
261 if (!in_array($this->country_code, $countriesusingstate) && !getDolGlobalString('MAIN_FORCE_STATE_INTO_ADDRESS')
262 && !getDolGlobalString('SOCIETE_DISABLE_STATE') && $this->state) {
263 if (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 && $this->region) {
264 $out .= ($outdone ? ' - ' : '').$this->region.' - '.$this->state;
265 } else {
266 $out .= ($outdone ? ' - ' : '').$this->state;
267 }
268 $outdone++;
269 }
270
271 if ($outdone) {
272 $out = '<div class="address inline-block">'.$out.'</div>';
273 }
274
275 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)) {
276 $out .= ($outdone ? '<br>' : '');
277 }
278
279 // Phones
280 $outphonedone = 0;
281 if (!empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone
282 // $out .= ($outphonedone ? ' ' : '');
283 $out .= dol_print_phone($this->phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePro"));
284 $outdone++;
285 $outphonedone++;
286 }
287 if (!empty($this->phone_pro)) {
288 $out .= ($outphonedone ? ' ' : '');
289 $out .= dol_print_phone($this->phone_pro, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePro"));
290 $outdone++;
291 $outphonedone++;
292 }
293 if (!empty($this->phone_mobile)) {
294 $out .= ($outphonedone ? ' ' : '');
295 $out .= dol_print_phone($this->phone_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'mobile', $langs->trans("PhoneMobile"));
296 $outdone++;
297 $outphonedone++;
298 }
299 if (!empty($this->phone_perso)) {
300 $out .= ($outphonedone ? ' ' : '');
301 $out .= dol_print_phone($this->phone_perso, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePerso"));
302 $outdone++;
303 $outphonedone++;
304 }
305 if (!empty($this->office_phone)) {
306 $out .= ($outphonedone ? ' ' : '');
307 $out .= dol_print_phone($this->office_phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePro"));
308 $outdone++;
309 $outphonedone++;
310 }
311 if (!empty($this->user_mobile)) {
312 $out .= ($outphonedone ? ' ' : '');
313 $out .= dol_print_phone($this->user_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'mobile', $langs->trans("PhoneMobile"));
314 $outdone++;
315 $outphonedone++;
316 }
317 if (!empty($this->fax)) {
318 $out .= ($outphonedone ? ' ' : '');
319 $out .= dol_print_phone($this->fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', '&nbsp;', 'fax', $langs->trans("Fax"));
320 $outdone++;
321 $outphonedone++;
322 }
323 if (!empty($this->office_fax)) {
324 $out .= ($outphonedone ? ' ' : '');
325 $out .= dol_print_phone($this->office_fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', '&nbsp;', 'fax', $langs->trans("Fax"));
326 $outdone++;
327 $outphonedone++;
328 }
329
330 if ($out) {
331 $out .= '<div style="clear: both;"></div>';
332 }
333 $outdone = 0;
334 if (!empty($this->email)) {
335 $out .= dol_print_email($this->email, $this->id, $object->id, 1, 0, 1, 1);
336 $outdone++;
337 }
338 if (!empty($this->url)) {
339 //$out.=dol_print_url($this->url,'_goout',0,1);//steve changed to blank
340 if (!empty($this->email)) {
341 $out .= ' ';
342 }
343 $out .= dol_print_url($this->url, '_blank', 0, 1);
344 $outdone++;
345 }
346
347 if (isModEnabled('socialnetworks')) {
348 $outsocialnetwork = '';
349
350 if (!empty($this->socialnetworks) && is_array($this->socialnetworks) && count($this->socialnetworks) > 0) {
351 $socialnetworksdict = getArrayOfSocialNetworks();
352 foreach ($this->socialnetworks as $key => $value) {
353 if ($value) {
354 $outsocialnetwork .= dol_print_socialnetworks($value, $this->id, $object->id, $key, $socialnetworksdict);
355 }
356 $outdone++;
357 }
358 }
359
360 if ($outsocialnetwork) {
361 $out .= '<div style="clear: both;">'.$outsocialnetwork.'</div>';
362 }
363 }
364
365 if ($out) {
366 return '<!-- BEGIN part to show address block -->'."\n".$out.'<!-- END Part to show address block -->'."\n";
367 } else {
368 return '';
369 }
370 }
371
377 public function setUpperOrLowerCase()
378 {
379 if (getDolGlobalString('MAIN_TE_PRIVATE_FIRST_AND_LASTNAME_TO_UPPER')) {
380 $this->lastname = dol_ucwords(dol_strtolower($this->lastname));
381 $this->firstname = dol_ucwords(dol_strtolower($this->firstname));
382 if (empty($this->typent_code) || $this->typent_code != "TE_PRIVATE") {
383 $this->name = dol_ucwords(dol_strtolower($this->name));
384 }
385 if (!empty($this->firstname)) {
386 $this->lastname = dol_strtoupper($this->lastname);
387 }
388 if (property_exists($this, 'name_alias')) {
389 $this->name_alias = isset($this->name_alias) ? dol_ucwords(dol_strtolower($this->name_alias)) : '';
390 }
391 }
392 if (getDolGlobalString('MAIN_FIRST_TO_UPPER')) {
393 $this->lastname = dol_ucwords(dol_strtolower($this->lastname));
394 $this->firstname = dol_ucwords(dol_strtolower($this->firstname));
395 $this->name = dol_ucwords(dol_strtolower($this->name));
396 if (property_exists($this, 'name_alias')) {
397 $this->name_alias = isset($this->name_alias) ? dol_ucwords(dol_strtolower($this->name_alias)) : '';
398 }
399 }
400 if (getDolGlobalString('MAIN_ALL_TO_UPPER')) {
401 $this->lastname = dol_strtoupper($this->lastname);
402 $this->name = dol_strtoupper($this->name);
403 if (property_exists($this, 'name_alias')) {
404 $this->name_alias = dol_strtoupper($this->name_alias);
405 }
406 }
407 if (getDolGlobalString('MAIN_ALL_TOWN_TO_UPPER')) {
408 $this->address = dol_strtoupper($this->address ?? '');
409 $this->town = dol_strtoupper($this->town ?? '');
410 }
411 if (!empty($this->email)) {
412 $this->email = dol_strtolower($this->email);
413 }
414 if (isset($this->personal_email)) {
415 $this->personal_email = dol_strtolower($this->personal_email);
416 }
417 }
418
419
420 // Methods used by this Trait that must be implemented in the parent class.
421 // Note: this helps static type checking
422
432 abstract public function getFullAddress($withcountry = 0, $sep = "\n", $withregion = 0, $extralangcode = '');
433
434
442 abstract public function fetchValuesForExtraLanguages();
443}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage members of a foundation.
Class to manage contact/addresses.
Class for RecruitmentCandidature.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
getBannerAddress($htmlkey, $object)
Return full address for banner.
getCivilityLabel()
Return civility label of object.
getAnonymisableFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname) or anonymous string.
getFullAddress($withcountry=0, $sep="\n", $withregion=0, $extralangcode='')
Return full address of contact.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
div refaddress div address
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133