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