dolibarr 19.0.3
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 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
29{
33 public $address;
34
38 public $zip;
39
43 public $town;
44
48 public $state_id; // The state/department
49 public $state_code;
50 public $state;
51
55 public $email;
56
60 public $url;
61
62
72 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
73 {
74 //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
75 $lastname = $this->lastname;
76 $firstname = $this->firstname;
77 if (empty($lastname)) {
78 $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 : '')))));
79 }
80
81 $ret = '';
82 if (!empty($option) && !empty($this->civility_code)) {
83 if ($langs->transnoentitiesnoconv("Civility".$this->civility_code) != "Civility".$this->civility_code) {
84 $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_code).' ';
85 } else {
86 $ret .= $this->civility_code.' ';
87 }
88 }
89
90 $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
91
92 return dol_string_nohtmltag(dol_trunc($ret, $maxlen));
93 }
94
102 public function getBannerAddress($htmlkey, $object)
103 {
104 global $conf, $langs, $form, $extralanguages;
105
106 $countriesusingstate = array('AU', 'US', 'IN', 'GB', 'ES', 'UK', 'TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS
107
108 $contactid = 0;
109 $thirdpartyid = 0;
110 $elementforaltlanguage = $this->element;
111 if ($this->element == 'societe') {
113 $thirdpartyid = $this->id;
114 }
115 if ($this->element == 'contact') {
117 $contactid = $this->id;
118 $thirdpartyid = empty($this->fk_soc) ? 0 : $this->fk_soc;
119 }
120 if ($this->element == 'user') {
122 $contactid = $this->contact_id;
123 $thirdpartyid = empty($object->fk_soc) ? 0 : $object->fk_soc;
124 }
125
126 $out = '';
127
128 $outdone = 0;
129 $coords = $this->getFullAddress(1, ', ', getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT'));
130 if ($coords) {
131 if (!empty($conf->use_javascript_ajax)) {
132 // Add picto with tooltip on map
133 $namecoords = '';
134 if ($this->element == 'contact' && getDolGlobalString('MAIN_SHOW_COMPANY_NAME_IN_BANNER_ADDRESS')) {
135 $namecoords .= $object->name.'<br>';
136 }
137 $namecoords .= $this->getFullName($langs, 1).'<br>'.$coords;
138 // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile
139 $out .= '<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">';
140 $out .= img_picto($langs->trans("Address"), 'map-marker-alt');
141 $out .= '</a> ';
142 }
143 $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
144 if ($address) {
145 $out .= $address;
146 $outdone++;
147 }
148 $outdone++;
149
150 // List of extra languages
151 $arrayoflangcode = array();
152 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
153 $arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
154 }
155
156 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
157 if (!is_object($extralanguages)) {
158 include_once DOL_DOCUMENT_ROOT.'/core/class/extralanguages.class.php';
159 $extralanguages = new ExtraLanguages($this->db);
160 }
161 $extralanguages->fetch_name_extralanguages($elementforaltlanguage);
162
163 if (!empty($extralanguages->attributes[$elementforaltlanguage]['address']) || !empty($extralanguages->attributes[$elementforaltlanguage]['town'])) {
164 $out .= "<!-- alternatelanguage for '".$elementforaltlanguage."' set to fields '".join(',', $extralanguages->attributes[$elementforaltlanguage])."' -->\n";
165 $this->fetchValuesForExtraLanguages();
166 if (!is_object($form)) {
167 $form = new Form($this->db);
168 }
169 $htmltext = '';
170 // If there is extra languages
171 foreach ($arrayoflangcode as $extralangcode) {
172 $s = picto_from_langcode($extralangcode, 'class="pictoforlang paddingright"');
173 // This also call dol_format_address()
174 $coords = $this->getFullAddress(1, ', ', $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT, $extralangcode);
175 $htmltext .= $s.dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
176 }
177 $out .= $form->textwithpicto('', $htmltext, -1, 'language', 'opacitymedium paddingleft');
178 }
179 }
180 }
181
182 // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress
183 if (!in_array($this->country_code, $countriesusingstate) && !getDolGlobalString('MAIN_FORCE_STATE_INTO_ADDRESS')
184 && !getDolGlobalString('SOCIETE_DISABLE_STATE') && $this->state) {
185 if (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 && $this->region) {
186 $out .= ($outdone ? ' - ' : '').$this->region.' - '.$this->state;
187 } else {
188 $out .= ($outdone ? ' - ' : '').$this->state;
189 }
190 $outdone++;
191 }
192
193 if ($outdone) {
194 $out = '<div class="address inline-block">'.$out.'</div>';
195 }
196
197 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)) {
198 $out .= ($outdone ? '<br>' : '');
199 }
200 if (!empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone
201 $out .= dol_print_phone($this->phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePro"));
202 $outdone++;
203 }
204 if (!empty($this->phone_pro)) {
205 $out .= dol_print_phone($this->phone_pro, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePro"));
206 $outdone++;
207 }
208 if (!empty($this->phone_mobile)) {
209 $out .= dol_print_phone($this->phone_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'mobile', $langs->trans("PhoneMobile"));
210 $outdone++;
211 }
212 if (!empty($this->phone_perso)) {
213 $out .= dol_print_phone($this->phone_perso, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePerso"));
214 $outdone++;
215 }
216 if (!empty($this->office_phone)) {
217 $out .= dol_print_phone($this->office_phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePro"));
218 $outdone++;
219 }
220 if (!empty($this->user_mobile)) {
221 $out .= dol_print_phone($this->user_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'mobile', $langs->trans("PhoneMobile"));
222 $outdone++;
223 }
224 if (!empty($this->fax)) {
225 $out .= dol_print_phone($this->fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', '&nbsp;', 'fax', $langs->trans("Fax"));
226 $outdone++;
227 }
228 if (!empty($this->office_fax)) {
229 $out .= dol_print_phone($this->office_fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', '&nbsp;', 'fax', $langs->trans("Fax"));
230 $outdone++;
231 }
232
233 if ($out) {
234 $out .= '<div style="clear: both;"></div>';
235 }
236 $outdone = 0;
237 if (!empty($this->email)) {
238 $out .= dol_print_email($this->email, $this->id, $object->id, 1, 0, 0, 1);
239 $outdone++;
240 }
241 if (!empty($this->url)) {
242 //$out.=dol_print_url($this->url,'_goout',0,1);//steve changed to blank
243 if (!empty($this->email)) {
244 $out .= ' ';
245 }
246 $out .= dol_print_url($this->url, '_blank', 0, 1);
247 $outdone++;
248 }
249
250 if (isModEnabled('socialnetworks')) {
251 $outsocialnetwork = '';
252
253 if (!empty($this->socialnetworks) && is_array($this->socialnetworks) && count($this->socialnetworks) > 0) {
254 $socialnetworksdict = getArrayOfSocialNetworks();
255 foreach ($this->socialnetworks as $key => $value) {
256 if ($value) {
257 $outsocialnetwork .= dol_print_socialnetworks($value, $this->id, $object->id, $key, $socialnetworksdict);
258 }
259 $outdone++;
260 }
261 }
262
263 if ($outsocialnetwork) {
264 $out .= '<div style="clear: both;">'.$outsocialnetwork.'</div>';
265 }
266 }
267
268 if ($out) {
269 return '<!-- BEGIN part to show address block -->'."\n".$out.'<!-- END Part to show address block -->'."\n";
270 } else {
271 return '';
272 }
273 }
274
280 public function setUpperOrLowerCase()
281 {
282 if (getDolGlobalString('MAIN_FIRST_TO_UPPER')) {
283 $this->lastname = dol_ucwords(dol_strtolower($this->lastname));
284 $this->firstname = dol_ucwords(dol_strtolower($this->firstname));
285 $this->name = dol_ucwords(dol_strtolower($this->name));
286 if (property_exists($this, 'name_alias')) {
287 $this->name_alias = isset($this->name_alias) ? dol_ucwords(dol_strtolower($this->name_alias)) : '';
288 }
289 }
290 if (getDolGlobalString('MAIN_ALL_TO_UPPER')) {
291 $this->lastname = dol_strtoupper($this->lastname);
292 $this->name = dol_strtoupper($this->name);
293 if (property_exists($this, 'name_alias')) {
294 $this->name_alias = dol_strtoupper($this->name_alias);
295 }
296 }
297 if (getDolGlobalString('MAIN_ALL_TOWN_TO_UPPER')) {
298 $this->address = dol_strtoupper($this->address);
299 $this->town = dol_strtoupper($this->town);
300 }
301 if (isset($this->email)) {
302 $this->email = dol_strtolower($this->email);
303 }
304 if (isset($this->personal_email)) {
305 $this->personal_email = dol_strtolower($this->personal_email);
306 }
307 }
308}
trait CommonPeople
Superclass for thirdparties, contacts, members or users.
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 dolibarr global constant string value.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:124