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