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