dolibarr 23.0.3
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
132
138 public function getCivilityLabel()
139 {
140 global $langs;
141
142 $code = (!empty($this->civility_code) ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite : '')));
143 if (empty($code)) {
144 return '';
145 }
146
147 $langs->load("dict");
148 return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
149 }
150
151
152
160 public function getBannerAddress($htmlkey, $object)
161 {
162 global $conf, $langs, $form, $extralanguages;
163
164 $countriesusingstate = array('AU', 'US', 'IN', 'GB', 'ES', 'UK', 'TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS
165
166 $contactid = 0;
167 $thirdpartyid = 0;
168 $elementforaltlanguage = $this->element;
169 if ($this->element === 'societe' && $this instanceof Societe) {
170 $thirdpartyid = $this->id;
171 }
172 if ($this->element === 'contact' && $this instanceof Contact) {
173 $contactid = $this->id;
174 $thirdpartyid = empty($this->fk_soc) ? 0 : $this->fk_soc;
175 }
176 if ($this->element == 'member' && $this instanceof Adherent) {
177 $contactid = $this->id;
178 $thirdpartyid = empty($this->socid) ? 0 : $this->socid;
179 }
180 if ($this->element === 'user' && $this instanceof User) {
181 $contactid = $this->contact_id;
182 $thirdpartyid = empty($object->fk_soc) ? 0 : $object->fk_soc;
183 }
184 if ($this->element == 'recruitmentcandidature' && $this instanceof RecruitmentCandidature) {
185 $thirdpartyid = 0;
186 }
187
188 $out = '';
189
190 $outdone = 0;
191 $coords = $this->getFullAddress(1, ', ', getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT'));
192 if ($coords) {
193 if (!empty($conf->use_javascript_ajax)) {
194 // Add picto with tooltip on map
195 $namecoords = '';
196 if ($this->element == 'contact' && getDolGlobalString('MAIN_SHOW_COMPANY_NAME_IN_BANNER_ADDRESS')) {
197 $namecoords .= $object->name.'<br>';
198 }
199 $namecoords .= $this->getFullName($langs, 1).'<br>'.$coords;
200 // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile
201 $out .= '<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">';
202 $out .= img_picto($langs->trans("Address"), 'map-marker-alt');
203 $out .= '</a> ';
204 }
205 $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
206 if ($address) {
207 $out .= $address;
208 $outdone++;
209 }
210 $outdone++;
211
212 // List of extra languages
213 $arrayoflangcode = array();
214 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
215 $arrayoflangcode[] = getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE');
216 }
217
218 if (/* is_array($arrayoflangcode) && */count($arrayoflangcode)) {
219 if (!is_object($extralanguages)) {
220 include_once DOL_DOCUMENT_ROOT.'/core/class/extralanguages.class.php';
221 $extralanguages = new ExtraLanguages($this->db);
222 }
223 $extralanguages->fetch_name_extralanguages($elementforaltlanguage);
224
225 if (!empty($extralanguages->attributes[$elementforaltlanguage]['address']) || !empty($extralanguages->attributes[$elementforaltlanguage]['town'])) {
226 $out .= "<!-- alternatelanguage for '".$elementforaltlanguage."' set to fields '".implode(',', $extralanguages->attributes[$elementforaltlanguage])."' -->\n";
227 $this->fetchValuesForExtraLanguages();
228 if (!is_object($form)) {
229 $form = new Form($this->db);
230 }
231 $htmltext = '';
232 // If there is extra languages
233 foreach ($arrayoflangcode as $extralangcode) {
234 $s = picto_from_langcode($extralangcode, 'class="pictoforlang paddingright"');
235 // This also call dol_format_address()
236 $coords = $this->getFullAddress(1, ', ', $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT, $extralangcode);
237 $htmltext .= $s.dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
238 }
239 $out .= $form->textwithpicto('', $htmltext, -1, 'language', 'opacitymedium paddingleft');
240 }
241 }
242 }
243
244 // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress
245 if (!in_array($this->country_code, $countriesusingstate) && !getDolGlobalString('MAIN_FORCE_STATE_INTO_ADDRESS')
246 && !getDolGlobalString('SOCIETE_DISABLE_STATE') && $this->state) {
247 if (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 && $this->region) {
248 $out .= ($outdone ? ' - ' : '').$this->region.' - '.$this->state;
249 } else {
250 $out .= ($outdone ? ' - ' : '').$this->state;
251 }
252 $outdone++;
253 }
254
255 if ($outdone) {
256 $out = '<div class="address inline-block">'.$out.'</div>';
257 }
258
259 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)) {
260 $out .= ($outdone ? '<br>' : '');
261 }
262
263 // Phones
264 $outphonedone = 0;
265 if (!empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone
266 // $out .= ($outphonedone ? ' ' : '');
267 $out .= dol_print_phone($this->phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePro"));
268 $outdone++;
269 $outphonedone++;
270 }
271 if (!empty($this->phone_pro)) {
272 $out .= ($outphonedone ? ' ' : '');
273 $out .= dol_print_phone($this->phone_pro, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePro"));
274 $outdone++;
275 $outphonedone++;
276 }
277 if (!empty($this->phone_mobile)) {
278 $out .= ($outphonedone ? ' ' : '');
279 $out .= dol_print_phone($this->phone_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'mobile', $langs->trans("PhoneMobile"));
280 $outdone++;
281 $outphonedone++;
282 }
283 if (!empty($this->phone_perso)) {
284 $out .= ($outphonedone ? ' ' : '');
285 $out .= dol_print_phone($this->phone_perso, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePerso"));
286 $outdone++;
287 $outphonedone++;
288 }
289 if (!empty($this->office_phone)) {
290 $out .= ($outphonedone ? ' ' : '');
291 $out .= dol_print_phone($this->office_phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePro"));
292 $outdone++;
293 $outphonedone++;
294 }
295 if (!empty($this->user_mobile)) {
296 $out .= ($outphonedone ? ' ' : '');
297 $out .= dol_print_phone($this->user_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'mobile', $langs->trans("PhoneMobile"));
298 $outdone++;
299 $outphonedone++;
300 }
301 if (!empty($this->fax)) {
302 $out .= ($outphonedone ? ' ' : '');
303 $out .= dol_print_phone($this->fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', '&nbsp;', 'fax', $langs->trans("Fax"));
304 $outdone++;
305 $outphonedone++;
306 }
307 if (!empty($this->office_fax)) {
308 $out .= ($outphonedone ? ' ' : '');
309 $out .= dol_print_phone($this->office_fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', '&nbsp;', 'fax', $langs->trans("Fax"));
310 $outdone++;
311 $outphonedone++;
312 }
313
314 if ($out) {
315 $out .= '<div style="clear: both;"></div>';
316 }
317 $outdone = 0;
318 if (!empty($this->email)) {
319 $out .= dol_print_email($this->email, $this->id, $object->id, 1, 0, 1, 1);
320 $outdone++;
321 }
322 if (!empty($this->url)) {
323 //$out.=dol_print_url($this->url,'_goout',0,1);//steve changed to blank
324 if (!empty($this->email)) {
325 $out .= ' ';
326 }
327 $out .= dol_print_url($this->url, '_blank', 0, 1);
328 $outdone++;
329 }
330
331 if (isModEnabled('socialnetworks')) {
332 $outsocialnetwork = '';
333
334 if (!empty($this->socialnetworks) && is_array($this->socialnetworks) && count($this->socialnetworks) > 0) {
335 $socialnetworksdict = getArrayOfSocialNetworks();
336 foreach ($this->socialnetworks as $key => $value) {
337 if ($value) {
338 $outsocialnetwork .= dol_print_socialnetworks($value, $this->id, $object->id, $key, $socialnetworksdict);
339 }
340 $outdone++;
341 }
342 }
343
344 if ($outsocialnetwork) {
345 $out .= '<div style="clear: both;">'.$outsocialnetwork.'</div>';
346 }
347 }
348
349 if ($out) {
350 return '<!-- BEGIN part to show address block -->'."\n".$out.'<!-- END Part to show address block -->'."\n";
351 } else {
352 return '';
353 }
354 }
355
361 public function setUpperOrLowerCase()
362 {
363 if (getDolGlobalString('MAIN_TE_PRIVATE_FIRST_AND_LASTNAME_TO_UPPER')) {
364 $this->lastname = dol_ucwords(dol_strtolower($this->lastname));
365 $this->firstname = dol_ucwords(dol_strtolower($this->firstname));
366 if (empty($this->typent_code) || $this->typent_code != "TE_PRIVATE") {
367 $this->name = dol_ucwords(dol_strtolower($this->name));
368 }
369 if (!empty($this->firstname)) {
370 $this->lastname = dol_strtoupper($this->lastname);
371 }
372 if (property_exists($this, 'name_alias')) {
373 $this->name_alias = isset($this->name_alias) ? dol_ucwords(dol_strtolower($this->name_alias)) : '';
374 }
375 }
376 if (getDolGlobalString('MAIN_FIRST_TO_UPPER')) {
377 $this->lastname = dol_ucwords(dol_strtolower($this->lastname));
378 $this->firstname = dol_ucwords(dol_strtolower($this->firstname));
379 $this->name = dol_ucwords(dol_strtolower($this->name));
380 if (property_exists($this, 'name_alias')) {
381 $this->name_alias = isset($this->name_alias) ? dol_ucwords(dol_strtolower($this->name_alias)) : '';
382 }
383 }
384 if (getDolGlobalString('MAIN_ALL_TO_UPPER')) {
385 $this->lastname = dol_strtoupper($this->lastname);
386 $this->name = dol_strtoupper($this->name);
387 if (property_exists($this, 'name_alias')) {
388 $this->name_alias = dol_strtoupper($this->name_alias);
389 }
390 }
391 if (getDolGlobalString('MAIN_ALL_TOWN_TO_UPPER')) {
392 $this->address = dol_strtoupper($this->address ?? '');
393 $this->town = dol_strtoupper($this->town ?? '');
394 }
395 if (!empty($this->email)) {
396 $this->email = dol_strtolower($this->email);
397 }
398 if (isset($this->personal_email)) {
399 $this->personal_email = dol_strtolower($this->personal_email);
400 }
401 }
402
403
404 // Methods used by this Trait that must be implemented in the parent class.
405 // Note: this helps static type checking
406
416 abstract public function getFullAddress($withcountry = 0, $sep = "\n", $withregion = 0, $extralangcode = '');
417
418
426 abstract public function fetchValuesForExtraLanguages();
427}
$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.
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)
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:128