dolibarr  18.0.6
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 
52 
62  public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
63  {
64  //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
65  $lastname = $this->lastname;
66  $firstname = $this->firstname;
67  if (empty($lastname)) {
68  $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 : '')))));
69  }
70 
71  $ret = '';
72  if (!empty($option) && !empty($this->civility_code)) {
73  if ($langs->transnoentitiesnoconv("Civility".$this->civility_code) != "Civility".$this->civility_code) {
74  $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_code).' ';
75  } else {
76  $ret .= $this->civility_code.' ';
77  }
78  }
79 
80  $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
81 
82  return dol_string_nohtmltag(dol_trunc($ret, $maxlen));
83  }
84 
92  public function getBannerAddress($htmlkey, $object)
93  {
94  global $conf, $langs, $form, $extralanguages;
95 
96  $countriesusingstate = array('AU', 'US', 'IN', 'GB', 'ES', 'UK', 'TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS
97 
98  $contactid = 0;
99  $thirdpartyid = 0;
100  $elementforaltlanguage = $this->element;
101  if ($this->element == 'societe') {
103  $thirdpartyid = $this->id;
104  }
105  if ($this->element == 'contact') {
107  $contactid = $this->id;
108  $thirdpartyid = empty($this->fk_soc) ? 0 : $this->fk_soc;
109  }
110  if ($this->element == 'user') {
112  $contactid = $this->contact_id;
113  $thirdpartyid = empty($object->fk_soc) ? 0 : $object->fk_soc;
114  }
115 
116  $out = '';
117 
118  $outdone = 0;
119  $coords = $this->getFullAddress(1, ', ', getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT'));
120  if ($coords) {
121  if (!empty($conf->use_javascript_ajax)) {
122  // Add picto with tooltip on map
123  $namecoords = '';
124  if ($this->element == 'contact' && !empty($conf->global->MAIN_SHOW_COMPANY_NAME_IN_BANNER_ADDRESS)) {
125  $namecoords .= $object->name.'<br>';
126  }
127  $namecoords .= $this->getFullName($langs, 1).'<br>'.$coords;
128  // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile
129  $out .= '<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">';
130  $out .= img_picto($langs->trans("Address"), 'map-marker-alt');
131  $out .= '</a> ';
132  }
133  $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
134  if ($address) {
135  $out .= $address;
136  $outdone++;
137  }
138  $outdone++;
139 
140  // List of extra languages
141  $arrayoflangcode = array();
142  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE)) {
143  $arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
144  }
145 
146  if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
147  if (!is_object($extralanguages)) {
148  include_once DOL_DOCUMENT_ROOT.'/core/class/extralanguages.class.php';
149  $extralanguages = new ExtraLanguages($this->db);
150  }
151  $extralanguages->fetch_name_extralanguages($elementforaltlanguage);
152 
153  if (!empty($extralanguages->attributes[$elementforaltlanguage]['address']) || !empty($extralanguages->attributes[$elementforaltlanguage]['town'])) {
154  $out .= "<!-- alternatelanguage for '".$elementforaltlanguage."' set to fields '".join(',', $extralanguages->attributes[$elementforaltlanguage])."' -->\n";
155  $this->fetchValuesForExtraLanguages();
156  if (!is_object($form)) {
157  $form = new Form($this->db);
158  }
159  $htmltext = '';
160  // If there is extra languages
161  foreach ($arrayoflangcode as $extralangcode) {
162  $s = picto_from_langcode($extralangcode, 'class="pictoforlang paddingright"');
163  // This also call dol_format_address()
164  $coords = $this->getFullAddress(1, ', ', $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT, $extralangcode);
165  $htmltext .= $s.dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
166  }
167  $out .= $form->textwithpicto('', $htmltext, -1, 'language', 'opacitymedium paddingleft');
168  }
169  }
170  }
171 
172  // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress
173  if (!in_array($this->country_code, $countriesusingstate) && empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS)
174  && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) {
175  if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) {
176  $out .= ($outdone ? ' - ' : '').$this->region.' - '.$this->state;
177  } else {
178  $out .= ($outdone ? ' - ' : '').$this->state;
179  }
180  $outdone++;
181  }
182 
183  if ($outdone) {
184  $out = '<div class="address inline-block">'.$out.'</div>';
185  }
186 
187  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)) {
188  $out .= ($outdone ? '<br>' : '');
189  }
190  if (!empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone
191  $out .= dol_print_phone($this->phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePro"));
192  $outdone++;
193  }
194  if (!empty($this->phone_pro)) {
195  $out .= dol_print_phone($this->phone_pro, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePro"));
196  $outdone++;
197  }
198  if (!empty($this->phone_mobile)) {
199  $out .= dol_print_phone($this->phone_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'mobile', $langs->trans("PhoneMobile"));
200  $outdone++;
201  }
202  if (!empty($this->phone_perso)) {
203  $out .= dol_print_phone($this->phone_perso, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePerso"));
204  $outdone++;
205  }
206  if (!empty($this->office_phone)) {
207  $out .= dol_print_phone($this->office_phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePro"));
208  $outdone++;
209  }
210  if (!empty($this->user_mobile)) {
211  $out .= dol_print_phone($this->user_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'mobile', $langs->trans("PhoneMobile"));
212  $outdone++;
213  }
214  if (!empty($this->fax)) {
215  $out .= dol_print_phone($this->fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', '&nbsp;', 'fax', $langs->trans("Fax"));
216  $outdone++;
217  }
218  if (!empty($this->office_fax)) {
219  $out .= dol_print_phone($this->office_fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', '&nbsp;', 'fax', $langs->trans("Fax"));
220  $outdone++;
221  }
222 
223  if ($out) {
224  $out .= '<div style="clear: both;"></div>';
225  }
226  $outdone = 0;
227  if (!empty($this->email)) {
228  $out .= dol_print_email($this->email, $this->id, $object->id, 'AC_EMAIL', 0, 0, 1);
229  $outdone++;
230  }
231  if (!empty($this->url)) {
232  //$out.=dol_print_url($this->url,'_goout',0,1);//steve changed to blank
233  $out .= dol_print_url($this->url, '_blank', 0, 1);
234  $outdone++;
235  }
236 
237  if (isModEnabled('socialnetworks')) {
238  $outsocialnetwork = '';
239 
240  if (!empty($this->socialnetworks) && is_array($this->socialnetworks) && count($this->socialnetworks) > 0) {
241  $socialnetworksdict = getArrayOfSocialNetworks();
242  foreach ($this->socialnetworks as $key => $value) {
243  if ($value) {
244  $outsocialnetwork .= dol_print_socialnetworks($value, $this->id, $object->id, $key, $socialnetworksdict);
245  }
246  $outdone++;
247  }
248  }
249 
250  if ($outsocialnetwork) {
251  $out .= '<div style="clear: both;">'.$outsocialnetwork.'</div>';
252  }
253  }
254 
255  if ($out) {
256  return '<!-- BEGIN part to show address block -->'."\n".$out.'<!-- END Part to show address block -->'."\n";
257  } else {
258  return '';
259  }
260  }
261 
267  public function setUpperOrLowerCase()
268  {
269  global $conf;
270 
271  if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) {
272  $this->lastname = dol_ucwords(dol_strtolower($this->lastname));
273  $this->firstname = dol_ucwords(dol_strtolower($this->firstname));
274  $this->name = dol_ucwords(dol_strtolower($this->name));
275  $this->name_alias = isset($this->name_alias)?dol_ucwords(dol_strtolower($this->name_alias)):'';
276  }
277  if (!empty($conf->global->MAIN_ALL_TO_UPPER)) {
278  $this->lastname = dol_strtoupper($this->lastname);
279  $this->name = dol_strtoupper($this->name);
280  $this->name_alias = dol_strtoupper($this->name_alias);
281  }
282  if (!empty($conf->global->MAIN_ALL_TOWN_TO_UPPER)) {
283  $this->address = dol_strtoupper($this->address);
284  $this->town = dol_strtoupper($this->town);
285  }
286  if (isset($this->email)) {
287  $this->email = dol_strtolower($this->email);
288  }
289  if (isset($this->personal_email)) {
290  $this->personal_email = dol_strtolower($this->personal_email);
291  }
292  }
293 }
trait CommonPeople
Superclass for thirdparties, contacts, members or users.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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 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.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:123