Passed
Push — EXTRACT_CLASSES ( ae6b5c...83d77a )
by Rafael
60:14 queued 23:58
created

WebPortalMember::getBannerAddressForWebPortal()   F

Complexity

Conditions 41
Paths > 20000

Size

Total Lines 121
Code Lines 79

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 41
eloc 79
nc 1781760
nop 1
dl 0
loc 121
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/* Copyright (C) 2023-2024  Laurent Destailleur         <[email protected]>
4
 * Copyright (C) 2023-2024	Lionel Vessiller		    <[email protected]>
5
 * Copyright (C) 2024		MDW							<[email protected]>
6
 * Copyright (C) 2024       Frédéric France             <[email protected]>
7
 * Copyright (C) 2024       Rafael San José             <[email protected]>
8
 *
9
 * This program is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21
 */
22
23
namespace Dolibarr\Code\WebPortal\Classes;
24
25
use Dolibarr\Code\Adherents\Classes\Adherent;
26
27
/**
28
 * \file        htdocs/webportal/class/webportalmember.class.php
29
 * \ingroup     webportal
30
 * \brief       This file is a CRUD class file for WebPortalMember (Create/Read/Update/Delete)
31
 */
32
33
/**
34
 * Class for WebPortalMember
35
 */
36
class WebPortalMember extends Adherent
37
{
38
    /**
39
     * @var string ID of module.
40
     */
41
    public $module = 'webportal';
42
43
    /**
44
     * Status list (short label)
45
     */
46
    const ARRAY_STATUS_LABEL = array(
47
        Adherent::STATUS_DRAFT => 'Draft',
48
        Adherent::STATUS_VALIDATED => 'Validated',
49
        Adherent::STATUS_RESILIATED => 'MemberStatusResiliatedShort',
50
        Adherent::STATUS_EXCLUDED => 'MemberStatusExcludedShort',
51
    );
52
53
    /**
54
     * MorPhy list : Moral or Physical
55
     */
56
    const MORPHY_LIST = array(
57
        'phy' => 'Physical',
58
        'mor' => 'Moral',
59
    );
60
61
    /**
62
     * Gender list
63
     */
64
    const GENDER_LIST = array(
65
        'man' => 'Genderman',
66
        'woman' => 'Genderwoman',
67
        'other' => 'Genderother',
68
    );
69
70
    /**
71
     * @var Adherent Member for static methods
72
     */
73
    protected $member_static = null;
74
75
    /**
76
     *  'type' field format:
77
     *    'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',
78
     *    'select' (list of values are in 'options'),
79
     *    'varchar(x)',
80
     *    'text', 'html',
81
     *    'double(24,8)', 'price',
82
     *    'date', 'datetime',
83
     *    'checkbox', 'radio',
84
     *    'mail', 'phone', 'url', 'password'
85
     *        Note: Filter must be a Dolibarr Universal Filter syntax string. Example: "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.status:!=:0) or (t.nature:is:NULL)"
86
     *  'label' the translation key.
87
     *  'picto' is code of a picto to show before value in forms
88
     *  'enabled' is a condition when the field must be managed (Example: 1 or 'getDolGlobalInt('MY_SETUP_PARAM') or 'isModEnabled("multicurrency")' ...)
89
     *  'position' is the sort order of field.
90
     *  'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
91
     *  'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
92
     *  'noteditable' says if field is not editable (1 or 0)
93
     *  'alwayseditable' says if field can be modified also when status is not draft ('1' or '0')
94
     *  'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
95
     *  'index' if we want an index in database.
96
     *  'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommended to name the field fk_...).
97
     *  'searchall' is 1 if we want to search in this field when making a search from the quick search button.
98
     *  'isameasure' must be set to 1 or 2 if field can be used for measure. Field type must be summable like integer or double(24,8). Use 1 in most cases, or 2 if you don't want to see the column total into list (for example for percentage)
99
     *  'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200'
100
     *  'help' and 'helplist' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
101
     *  'showoncombobox' if value of the field must be visible into the label of the combobox that list record
102
     *  'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
103
     *  'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar'
104
     *  'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
105
     *  'comment' is not used. You can store here any text of your choice. It is not used by application.
106
     *    'validate' is 1 if need to validate with $this->validateField()
107
     *  'copytoclipboard' is 1 or 2 to allow to add a picto to copy value into clipboard (1=picto after label, 2=picto after value)
108
     *  'showonheader' is 1 to show on the top of the card (header section)
109
     *
110
     *  Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
111
     */
112
113
    // BEGIN MODULEBUILDER PROPERTIES
114
    /**
115
     * @var array<string,array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string}>  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string,array{type:...ring>,comment?:string}> at position 16 could not be parsed: Expected '}' at position 16, but found 'int'.
Loading history...
116
     */
117
    public $fields = array(
118
        'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 10,),
119
        'ref' => array('type' => 'varchar(30)', 'label' => 'Ref', 'default' => '1', 'enabled' => 1, 'visible' => 5, 'notnull' => 1, 'position' => 12, 'index' => 1, 'showonheader' => 1,),
120
        'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 15, 'index' => 1,),
121
122
        'lastname' => array('type' => 'varchar(50)', 'label' => 'Lastname', 'enabled' => 1, 'visible' => 4, 'position' => 30, 'showonheader' => 1,),
123
        'firstname' => array('type' => 'varchar(50)', 'label' => 'Firstname', 'enabled' => 1, 'visible' => 4, 'position' => 35, 'showonheader' => 1,),
124
        'gender' => array('type' => 'varchar(10)', 'label' => 'Gender', 'enabled' => 1, 'visible' => 4, 'position' => 50, 'arrayofkeyval' => self::GENDER_LIST, 'showonheader' => 1,),
125
        'company' => array('type' => 'varchar(128)', 'label' => 'Societe', 'enabled' => 1, 'visible' => 4, 'position' => 65, 'showonheader' => 1,),
126
        'address' => array('type' => 'text', 'label' => 'Address', 'enabled' => 1, 'visible' => 4, 'position' => 75, 'showonheader' => 1,),
127
        'zip' => array('type' => 'varchar(10)', 'label' => 'Zip', 'enabled' => 1, 'visible' => 4, 'position' => 80, 'showonheader' => 1,),
128
        'town' => array('type' => 'varchar(50)', 'label' => 'Town', 'enabled' => 1, 'visible' => 4, 'position' => 85, 'showonheader' => 1,),
129
        'state_id' => array('type' => 'integer', 'label' => 'State id', 'enabled' => '!getDolGlobalString("MEMBER_DISABLE_STATE")', 'visible' => -5, 'position' => 90, 'showonheader' => 1,),
130
        'country_id' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => 4, 'position' => 95, 'showonheader' => 1,),
131
        'phone' => array('type' => 'varchar(30)', 'label' => 'Phone', 'enabled' => 1, 'visible' => 4, 'position' => 115, 'showonheader' => 1,),
132
        'phone_perso' => array('type' => 'varchar(30)', 'label' => 'Phone perso', 'enabled' => 1, 'visible' => 4, 'position' => 120, 'showonheader' => 1,),
133
        'phone_mobile' => array('type' => 'varchar(30)', 'label' => 'Phone mobile', 'enabled' => 1, 'visible' => 4, 'position' => 125, 'showonheader' => 1,),
134
        'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'enabled' => 1, 'visible' => 4, 'position' => 200, 'showonheader' => 1, 'picto' => 'email'),
135
        'url' => array('type' => 'varchar(255)', 'label' => 'Url', 'enabled' => 1, 'visible' => 4, 'position' => 210, 'showonheader' => 1,),
136
137
        'login' => array('type' => 'varchar(50)', 'label' => 'Login', 'enabled' => 1, 'visible' => 4, 'position' => 240,),
138
        'typeid' => array('type' => 'integer:AdherentType:adherents/class/adherent_type.class.php', 'label' => 'MemberType', 'enabled' => 1, 'visible' => 4, 'notnull' => 1, 'position' => 255),
139
        'morphy' => array('type' => 'varchar(3)', 'label' => 'MemberNature', 'enabled' => 1, 'visible' => 4, 'notnull' => 1, 'position' => 260, 'arrayofkeyval' => self::MORPHY_LIST,),
140
        'civility_id' => array('type' => 'sellist:c_civility:label:rowid::active=1', 'label' => 'Civility', 'enabled' => 1, 'visible' => 4, 'position' => 270,),
141
        'birth' => array('type' => 'date', 'label' => 'DateOfBirth', 'enabled' => 1, 'visible' => 4, 'position' => 290,),
142
        'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 1, 'visible' => 5, 'position' => 300,),
143
144
        'datefin' => array('type' => 'date', 'label' => 'SubscriptionEndDate', 'enabled' => 1, 'visible' => 5, 'position' => 400,),
145
146
        'status' => array('type' => 'smallint(6)', 'label' => 'Status', 'enabled' => 1, 'visible' => 5, 'notnull' => 1, 'position' => 500, 'arrayofkeyval' => self::ARRAY_STATUS_LABEL, 'showonheader' => 1,),
147
    );
148
    public $rowid;
149
    //public $ref;
150
    //public $lastname;
151
    //public $firstname;
152
    //public $gender;
153
    //public $address;
154
    //public $zip;
155
    //public $town;
156
    //public $state_id;
157
    //public $country;
158
    //public $phone;
159
    //public $phone_perso;
160
    //public $phone_mobile;
161
    //public $email;
162
    //public $url;
163
    //public $socialnetworks;
164
    //public $login;
165
    public $fk_adherent_type;
166
    //public $morphy;
167
    //public $societe;
168
    //public $civility_id;
169
    //public $datefin;
170
    //public $birth;
171
    //public $fk_soc;
172
    //public $status;
173
    // END MODULEBUILDER PROPERTIES
174
175
    /**
176
     * Get member for static method
177
     *
178
     * @return  Adherent
179
     */
180
    protected function getMemberStatic()
181
    {
182
        if (!$this->member_static) {
183
            $this->member_static = new Adherent($this->db);
184
        }
185
186
        return $this->member_static;
187
    }
188
189
    /**
190
     * Constructor
191
     *
192
     * @param   DoliDb  $db     Database handler
0 ignored issues
show
Bug introduced by
The type Dolibarr\Code\WebPortal\Classes\DoliDb was not found. Did you mean DoliDb? If so, make sure to prefix the type with \.
Loading history...
193
     */
194
    public function __construct(DoliDB $db)
0 ignored issues
show
Bug introduced by
The type Dolibarr\Code\WebPortal\Classes\DoliDB was not found. Did you mean DoliDB? If so, make sure to prefix the type with \.
Loading history...
195
    {
196
        global $langs;
197
198
        $this->db = $db;
199
200
        $this->isextrafieldmanaged = 0;
201
202
        $this->getMemberStatic();
203
204
        // Translate some data of arrayofkeyval
205
        if (is_object($langs)) {
206
            foreach ($this->fields as $key => $val) {
207
                if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
208
                    foreach ($val['arrayofkeyval'] as $key2 => $val2) {
209
                        $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
210
                    }
211
                }
212
            }
213
        }
214
    }
215
216
    /**
217
     * getTooltipContentArray
218
     *
219
     * @param   array   $params     Params to construct tooltip data
220
     * @return  array
221
     * @since v18
222
     */
223
    public function getTooltipContentArray($params)
224
    {
225
        global $langs;
226
227
        $datas = [];
228
229
        if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
230
            return ['optimize' => $langs->trans("WebPortalMember")];
231
        }
232
        $datas['picto'] = img_picto('', $this->picto) . ' <u>' . $langs->trans("WebPortalMember") . '</u>';
233
        if (isset($this->status)) {
234
            $datas['picto'] .= ' ' . $this->getLibStatut(5);
235
        }
236
        $datas['ref'] .= '<br><b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
237
238
        return $datas;
239
    }
240
241
    /**
242
     *  Return clicable name (with picto eventually)
243
     *
244
     * @param   int     $withpictoimg           0=No picto, 1=Include picto into link, 2=Only picto, -1=Include photo into link, -2=Only picto photo, -3=Only photo very small)
245
     * @param   int     $maxlen                 Length max label
246
     * @param   string  $option                 Page for link ('card', 'category', 'subscription', ...)
247
     * @param   string  $mode                   ''=Show firstname+lastname as label (using default order), 'firstname'=Show only firstname, 'lastname'=Show only lastname, 'login'=Show login, 'ref'=Show ref
248
     * @param   string  $morecss                Add more css on link
249
     * @param   int     $save_lastsearch_value  -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
250
     * @param   int     $notooltip              1=Disable tooltip
251
     * @param   int     $addlinktonotes         1=Add link to notes
252
     * @return  string  String with Url
253
     */
254
    public function getNomUrl($withpictoimg = 0, $maxlen = 0, $option = 'card', $mode = '', $morecss = '', $save_lastsearch_value = -1, $notooltip = 0, $addlinktonotes = 0)
255
    {
256
        global $langs, $hookmanager;
257
258
        if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpictoimg) {
259
            $withpictoimg = 0;
260
        }
261
262
        $option = 'nolink';
263
264
        $result = '';
265
        $linkstart = '';
266
        $linkend = '';
267
        $classfortooltip = 'classfortooltip';
268
        $dataparams = '';
269
        $params = [
270
            'id' => $this->id,
271
            'objecttype' => $this->element,
272
            'option' => $option,
273
            'nofetch' => 1,
274
        ];
275
        if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
276
            $classfortooltip = 'classforajaxtooltip';
277
            $dataparams = ' data-params="' . dol_escape_htmltag(json_encode($params)) . '"';
278
            $label = '';
279
        } else {
280
            $label = implode($this->getTooltipContentArray($params));
281
        }
282
283
        $url = '';
284
        //$url = DOL_URL_ROOT.'/adherents/card.php?rowid='.((int) $this->id);
285
        //if ($option == 'subscription') {
286
        //    $url = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.((int) $this->id);
287
        //}
288
289
        //if ($option != 'nolink') {
290
        //    // Add param to save lastsearch_values or not
291
        //    $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
292
        //    if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
293
        //        $add_save_lastsearch_values = 1;
294
        //    }
295
        //    if ($add_save_lastsearch_values) {
296
        //        $url .= '&save_lastsearch_values=1';
297
        //    }
298
        //}
299
300
        $linkstart .= '<a href="' . $url . '"';
301
        $linkclose = "";
302
        if (empty($notooltip)) {
303
            if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
304
                $langs->load("users");
305
                $label = $langs->trans("ShowUser");
306
                $linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"';
307
            }
308
            $linkclose .= ($label ? ' title="' . dol_escape_htmltag($label, 1) . '"' : ' title="tocomplete"');
309
            $linkclose .= $dataparams . ' class="' . $classfortooltip . ($morecss ? ' ' . $morecss : '') . '"';
310
        }
311
312
        $linkstart .= $linkclose . '>';
313
        $linkend = '</a>';
314
315
        if ($option === 'nolink') {
316
            $linkstart = '';
317
            $linkend = '';
318
        }
319
320
        $result .= $linkstart;
321
        if ($withpictoimg) {
322
            $result .= '<div class="inline-block nopadding valignmiddle">';
323
        }
324
        if ($withpictoimg) {
325
            $paddafterimage = '';
326
            if (abs($withpictoimg) == 1 || abs($withpictoimg) == 4) {
327
                $morecss .= ' paddingrightonly';
328
            }
329
            // Only picto
330
            if ($withpictoimg > 0) {
331
                $picto = '<span class="nopadding' . ($morecss ? ' userimg' . $morecss : '') . '">' . img_object('', 'user', $paddafterimage . ' ' . ($notooltip ? '' : $dataparams), 0, 0, $notooltip ? 0 : 1) . '</span>';
332
            } else {
333
                // Picto must be a photo
334
                $picto = '<span class="nopadding' . ($morecss ? ' userimg' . $morecss : '') . '"' . ($paddafterimage ? ' ' . $paddafterimage : '') . '>';
335
                $picto .= Form::showphoto('memberphoto', $this, 0, 0, 0, 'userphoto' . (($withpictoimg == -3 || $withpictoimg == -4) ? 'small' : ''), 'mini', 0, 1);
336
                $picto .= '</span>';
337
            }
338
            $result .= $picto;
339
        }
340
        if (($withpictoimg > -2 && $withpictoimg != 2) || $withpictoimg == -4) {
341
            if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
342
                $result .= '<span class="nopadding valignmiddle' . ((!isset($this->statut) || $this->statut) ? '' : ' strikefordisabled') .
343
                    ($morecss ? ' usertext' . $morecss : '') . '">';
344
            }
345
            if ($mode == 'login') {
346
                $result .= dol_trunc($this->login, $maxlen);
347
            } elseif ($mode == 'ref') {
348
                $result .= $this->ref;
349
            } else {
350
                $result .= $this->getFullName($langs, '', ($mode == 'firstname' ? 2 : ($mode == 'lastname' ? 4 : -1)), $maxlen);
351
            }
352
            if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
353
                $result .= '</span>';
354
            }
355
        }
356
        if ($withpictoimg) {
357
            $result .= '</div>';
358
        }
359
        $result .= $linkend;
360
361
        //if ($addlinktonotes) {
362
        //    if ($this->note_private) {
363
        //        $notetoshow = $langs->trans("ViewPrivateNote").':<br>'.dol_string_nohtmltag($this->note_private, 1);
364
        //        $result .= ' <span class="note inline-block">';
365
        //        $result .= '<a href="'.DOL_URL_ROOT.'/adherents/note.php?id='.$this->id.'" class="classfortooltip" title="'.dol_escape_htmltag($notetoshow).'">';
366
        //        $result .= img_picto('', 'note');
367
        //        $result .= '</a>';
368
        //        $result .= '</span>';
369
        //    }
370
        //}
371
        global $action;
372
        $hookmanager->initHooks(array($this->element . 'dao'));
373
        $parameters = array('id' => $this->id, 'getnomurl' => &$result);
374
        $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
375
        if ($reshook > 0) {
376
            $result = $hookmanager->resPrint;
377
        } else {
378
            $result .= $hookmanager->resPrint;
379
        }
380
        return $result;
381
    }
382
383
    /**
384
     * Retourne le libelle du statut d'un adherent (brouillon, valide, resilie, exclu)
385
     *
386
     * @param   int     $mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
387
     * @return  string  Label
388
     */
389
    public function getLibStatut($mode = 0)
390
    {
391
        return $this->LibStatut($this->status, $this->need_subscription, $this->datefin, $mode);
392
    }
393
394
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
395
396
    /**
397
     * Renvoi le libelle d'un statut donne
398
     *
399
     * @param   int     $status                 Id status
400
     * @param   int     $need_subscription      1 if member type need subscription, 0 otherwise
401
     * @param   int     $date_end_subscription  Date fin adhesion
402
     * @param   int     $mode                   0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
403
     * @return  string  Label
404
     */
405
    public function LibStatut($status, $need_subscription, $date_end_subscription, $mode = 0)
406
    {
407
		// phpcs:enable
408
        return $this->getMemberStatic()->LibStatut($status, $need_subscription, $date_end_subscription, $mode);
409
    }
410
411
    /**
412
     * Return full address for banner
413
     *
414
     * @param   string  $htmlkey    HTML id to make banner content unique
415
     * @return  string  Full address string
416
     */
417
    public function getBannerAddressForWebPortal($htmlkey)
418
    {
419
        global $conf, $langs, $form, $extralanguages;
420
421
        $countriesusingstate = array('AU', 'US', 'IN', 'GB', 'ES', 'UK', 'TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS
422
423
        $contactid = 0;
424
        $thirdpartyid = 0;
425
        $elementforaltlanguage = $this->element;
426
427
        $out = '';
428
429
        $outdone = 0;
430
        $coords = $this->getFullAddress(1, ', ', getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT'));
431
        if ($coords) {
432
            $address = dol_print_address($coords, 'address_' . $htmlkey . '_' . $this->id, $this->element, $this->id, 1, ', ');
433
            if ($address) {
434
                $out .= $address;
435
                $outdone++;
436
            }
437
            $outdone++;
438
439
            // List of extra languages
440
            $arrayoflangcode = array();
441
            if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
442
                $arrayoflangcode[] = getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE');
443
            }
444
445
            if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
446
                if (!is_object($extralanguages)) {
447
                    include_once DOL_DOCUMENT_ROOT . '/core/class/extralanguages.class.php';
448
                    $extralanguages = new ExtraLanguages($this->db);
449
                }
450
                $extralanguages->fetch_name_extralanguages($elementforaltlanguage);
451
452
                if (!empty($extralanguages->attributes[$elementforaltlanguage]['address']) || !empty($extralanguages->attributes[$elementforaltlanguage]['town'])) {
453
                    $out .= "<!-- alternatelanguage for '" . $elementforaltlanguage . "' set to fields '" . implode(',', $extralanguages->attributes[$elementforaltlanguage]) . "' -->\n";
454
                    $this->fetchValuesForExtraLanguages();
455
                    if (!is_object($form)) {
456
                        $form = new Form($this->db);
457
                    }
458
                    $htmltext = '';
459
                    // If there is extra languages
460
                    foreach ($arrayoflangcode as $extralangcode) {
461
                        $s = picto_from_langcode($extralangcode, 'class="pictoforlang paddingright"');
462
                        // This also call dol_format_address()
463
                        $coords = $this->getFullAddress(1, ', ', $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT, $extralangcode);
464
                        $htmltext .= $s . dol_print_address($coords, 'address_' . $htmlkey . '_' . $this->id, $this->element, $this->id, 1, ', ');
465
                    }
466
                    $out .= $form->textwithpicto('', $htmltext, -1, 'language', 'opacitymedium paddingleft');
467
                }
468
            }
469
        }
470
471
        // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress
472
        if (
473
            !in_array($this->country_code, $countriesusingstate) && !getDolGlobalString('MAIN_FORCE_STATE_INTO_ADDRESS')
474
            && !getDolGlobalString('SOCIETE_DISABLE_STATE') && $this->state
475
        ) {
476
            if (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 && $this->region) {
477
                $out .= ($outdone ? ' - ' : '') . $this->region . ' - ' . $this->state;
478
            } else {
479
                $out .= ($outdone ? ' - ' : '') . $this->state;
480
            }
481
            $outdone++;
482
        }
483
484
        if ($outdone) {
485
            $out = '<div class="address inline-block">' . $out . '</div>';
486
        }
487
488
        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)) {
489
            $out .= ($outdone ? '<br>' : '');
490
        }
491
        if (!empty($this->phone) && empty($this->phone_pro)) {        // For objects that store pro phone into ->phone
492
            $out .= dol_print_phone($this->phone, $this->country_code, $contactid, $thirdpartyid, '', '&nbsp;', 'phone', $langs->trans("PhonePro"));
493
            $outdone++;
494
        }
495
        if (!empty($this->phone_pro)) {
496
            $out .= dol_print_phone($this->phone_pro, $this->country_code, $contactid, $thirdpartyid, '', '&nbsp;', 'phone', $langs->trans("PhonePro"));
497
            $outdone++;
498
        }
499
        if (!empty($this->phone_mobile)) {
500
            $out .= dol_print_phone($this->phone_mobile, $this->country_code, $contactid, $thirdpartyid, '', '&nbsp;', 'mobile', $langs->trans("PhoneMobile"));
501
            $outdone++;
502
        }
503
        if (!empty($this->phone_perso)) {
504
            $out .= dol_print_phone($this->phone_perso, $this->country_code, $contactid, $thirdpartyid, '', '&nbsp;', 'phone', $langs->trans("PhonePerso"));
505
            $outdone++;
506
        }
507
        if (!empty($this->office_phone)) {
508
            $out .= dol_print_phone($this->office_phone, $this->country_code, $contactid, $thirdpartyid, '', '&nbsp;', 'phone', $langs->trans("PhonePro"));
509
            $outdone++;
510
        }
511
        if (!empty($this->user_mobile)) {
512
            $out .= dol_print_phone($this->user_mobile, $this->country_code, $contactid, $thirdpartyid, '', '&nbsp;', 'mobile', $langs->trans("PhoneMobile"));
513
            $outdone++;
514
        }
515
        if (!empty($this->fax)) {
516
            $out .= dol_print_phone($this->fax, $this->country_code, $contactid, $thirdpartyid, '', '&nbsp;', 'fax', $langs->trans("Fax"));
517
            $outdone++;
518
        }
519
        if (!empty($this->office_fax)) {
520
            $out .= dol_print_phone($this->office_fax, $this->country_code, $contactid, $thirdpartyid, '', '&nbsp;', 'fax', $langs->trans("Fax"));
521
            $outdone++;
522
        }
523
524
        if ($out) {
525
            $out .= '<div style="clear: both;"></div>';
526
        }
527
        $outdone = 0;
528
        if (!empty($this->email)) {
529
            $out .= dol_print_email($this->email, $this->id, $this->id, '', 0, 0, 1);
530
            $outdone++;
531
        }
532
        if (!empty($this->url)) {
533
            $out .= dol_print_url($this->url, '_blank', 0, 1);
534
            $outdone++;
535
        }
536
537
        return $out;
538
    }
539
}
540