Issues (2811)

public/htdocs/societe/societecontact.php (2 issues)

1
<?php
2
3
/* Copyright (C) 2005       Patrick Rouillon            <[email protected]>
4
 * Copyright (C) 2005-2011	Laurent Destailleur         <[email protected]>
5
 * Copyright (C) 2005-2012	Regis Houssin               <[email protected]>
6
 * Copyright (C) 2011-2015	Philippe Grand              <[email protected]>
7
 * Copyright (C) 2014       Charles-Fr Benke	        <[email protected]>
8
 * Copyright (C) 2015       Marcos García               <[email protected]>
9
 * Copyright (C) 2024       Rafael San José             <[email protected]>
10
 *
11
 * This program is free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23
 */
24
25
use Dolibarr\Code\Adherents\Classes\Adherent;
26
use Dolibarr\Code\Adherents\Classes\AdherentType;
27
use Dolibarr\Code\Contact\Classes\Contact;
28
use Dolibarr\Code\Core\Classes\Form;
29
use Dolibarr\Code\Core\Classes\FormCompany;
30
use Dolibarr\Code\Core\Classes\FormOther;
31
use Dolibarr\Code\Societe\Classes\Societe;
32
use Dolibarr\Code\User\Classes\User;
33
use Dolibarr\Lib\ViewMain;
34
35
/**
36
 *     \file        htdocs/societe/societecontact.php
37
 *     \ingroup     societe
38
 *     \brief       Tab to manage differently contact.
39
 *                  Used when the unstable option MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES is on.
40
 */
41
42
// Load Dolibarr environment
43
require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php';
44
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/company.lib.php';
45
46
// Load translation files required by the page
47
$langs->loadLangs(array('companies', 'orders'));
48
49
// Get parameters
50
$id = GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('socid');
51
$ref = GETPOST('ref', 'alpha');
52
$action = GETPOST('action', 'aZ09');
53
$massaction = GETPOST('massaction', 'alpha');
54
55
$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
56
$sortfield = GETPOST('sortfield', 'aZ09comma');
57
$sortorder = GETPOST('sortorder', 'aZ09comma');
58
$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
59
if (!$sortorder) {
60
    $sortorder = "ASC";
61
}
62
if (!$sortfield) {
63
    $sortfield = "s.nom";
64
}
65
if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) {
66
    $page = 0;
67
}
68
$offset = $limit * $page;
69
$pageprev = $page - 1;
70
$pagenext = $page + 1;
71
72
// Security check
73
if ($user->socid) {
74
    $socid = $user->socid;
75
}
76
$result = restrictedArea($user, 'societe', $id, '');
77
78
// Initialize objects
79
$object = new Societe($db);
80
81
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
82
$hookmanager->initHooks(array('contactthirdparty', 'globalcard'));
83
84
/*
85
 * Actions
86
 */
87
88
if ($action == 'addcontact' && $user->hasRight('societe', 'creer')) {
89
    $result = $object->fetch($id);
90
91
    if ($result > 0 && $id > 0) {
92
        $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
93
        $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
94
        $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
95
    }
96
97
    if ($result >= 0) {
98
        header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
99
        exit;
100
    } else {
101
        if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
102
            $langs->load("errors");
103
            $mesg = '<div class="error">' . $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType") . '</div>';
104
        } else {
105
            $mesg = '<div class="error">' . $object->error . '</div>';
106
        }
107
    }
108
} elseif ($action == 'swapstatut' && $user->hasRight('societe', 'creer')) {
109
    // bascule du statut d'un contact
110
    if ($object->fetch($id)) {
111
        $result = $object->swapContactStatus(GETPOSTINT('ligne'));
112
    } else {
113
        dol_print_error($db);
114
    }
115
} elseif ($action == 'deletecontact' && $user->hasRight('societe', 'creer')) {
116
    // Efface un contact
117
    $object->fetch($id);
118
    $result = $object->delete_contact(GETPOSTINT("lineid"));
119
120
    if ($result >= 0) {
121
        header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
122
        exit;
123
    } else {
124
        dol_print_error($db);
125
    }
126
}
127
128
129
/*
130
 * View
131
 */
132
133
$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
134
ViewMain::llxHeader('', $langs->trans("ThirdParty"), $help_url);
135
136
$form = new Form($db);
137
$formcompany = new FormCompany($db);
138
$formother = new FormOther($db);
139
$contactstatic = new Contact($db);
140
$userstatic = new User($db);
141
142
// View and edit
143
144
if ($id > 0 || !empty($ref)) {
145
    if ($object->fetch($id, $ref) > 0) {
146
        $head = societe_prepare_head($object);
147
        print dol_get_fiche_head($head, 'contactext', $langs->trans("ThirdParty"), -1, 'company');
148
149
        print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '">';
150
        print '<input type="hidden" name="token" value="' . newToken() . '">';
151
152
        $linkback = '<a href="' . constant('BASE_URL') . '/societe/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
153
154
        dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
155
156
        print '<div class="fichecenter">';
157
158
        print '<div class="underbanner clearboth"></div>';
159
        print '<table class="border centpercent">';
160
161
        // Prospect/Customer
162
        /*print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
163
        print $object->getLibCustProspStatut();
164
        print '</td></tr>';
165
166
        // Supplier
167
        print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
168
        print yn($object->fournisseur);
169
        print '</td></tr>';*/
170
171
        if (getDolGlobalString('SOCIETE_USEPREFIX')) {  // Old not used prefix field
172
            print '<tr><td>' . $langs->trans('Prefix') . '</td><td colspan="3">' . $object->prefix_comm . '</td></tr>';
173
        }
174
175
        if ($object->client) {
176
            print '<tr><td class="titlefield">';
177
            print $langs->trans('CustomerCode') . '</td><td colspan="3">';
178
            print $object->code_client;
179
            $tmpcheck = $object->check_codeclient();
180
            if ($tmpcheck != 0 && $tmpcheck != -5) {
181
                print ' <span class="error">(' . $langs->trans("WrongCustomerCode") . ')</span>';
182
            }
183
            print '</td></tr>';
184
        }
185
186
        if ($object->fournisseur) {
187
            print '<tr><td class="titlefield">';
188
            print $langs->trans('SupplierCode') . '</td><td colspan="3">';
189
            print $object->code_fournisseur;
190
            $tmpcheck = $object->check_codefournisseur();
191
            if ($tmpcheck != 0 && $tmpcheck != -5) {
192
                print ' <span class="error">(' . $langs->trans("WrongSupplierCode") . ')</span>';
193
            }
194
            print '</td></tr>';
195
        }
196
        print '</table>';
197
198
        print '</div>';
199
200
        print '</form>';
201
        print '<br>';
202
203
        // Contacts lines (modules that overwrite templates must declare this into descriptor)
204
        $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
205
        foreach ($dirtpls as $reldir) {
206
            $res = @include dol_buildpath($reldir . '/contacts.tpl.php');
207
            if ($res) {
208
                break;
209
            }
210
        }
211
212
        // additional list with adherents of company
213
        if (isModEnabled('member') && $user->hasRight('adherent', 'lire')) {
214
            $membertypestatic = new AdherentType($db);
215
            $memberstatic = new Adherent($db);
216
217
            $langs->load("members");
218
            $sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, d.fk_soc,";
219
            $sql .= " d.datefin,";
220
            $sql .= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,";
221
            $sql .= " t.libelle as type_label, t.subscription";
222
            $sql .= " FROM " . MAIN_DB_PREFIX . "adherent as d";
223
            $sql .= ", " . MAIN_DB_PREFIX . "adherent_type as t";
224
            $sql .= " WHERE d.fk_soc = " . ((int)$id);
225
            $sql .= " AND d.fk_adherent_type = t.rowid";
226
227
            dol_syslog("get list sql=" . $sql);
228
            $resql = $db->query($sql);
229
            if ($resql) {
230
                $num = $db->num_rows($resql);
231
232
                if ($num > 0) {
233
                    $param = '';
234
235
                    $titre = $langs->trans("MembersListOfTiers");
236
                    print '<br>';
237
238
                    print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, 0, '');
239
240
                    print "<table class=\"noborder\" width=\"100%\">";
241
                    print '<tr class="liste_titre">';
242
                    print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", $param, "", "", $sortfield, $sortorder);
243
                    print_liste_field_titre("NameSlashCompany", $_SERVER["PHP_SELF"], "d.lastname", $param, "", "", $sortfield, $sortorder);
244
                    print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "d.login", $param, "", "", $sortfield, $sortorder);
245
                    print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "t.libelle", $param, "", "", $sortfield, $sortorder);
246
                    print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "d.morphy", $param, "", "", $sortfield, $sortorder);
247
                    print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "d.email", $param, "", "", $sortfield, $sortorder);
248
                    print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.statut,d.datefin", $param, "", "", $sortfield, $sortorder);
249
                    print_liste_field_titre("EndSubscription", $_SERVER["PHP_SELF"], "d.datefin", $param, "", '', $sortfield, $sortorder, 'center ');
250
                    print "</tr>\n";
251
252
                    $i = 0;
253
                    while ($i < $num && $i < $conf->liste_limit) {
254
                        $objp = $db->fetch_object($resql);
255
256
                        $datefin = $db->jdate($objp->datefin);
257
                        $memberstatic->id = $objp->rowid;
258
                        $memberstatic->ref = $objp->rowid;
259
                        $memberstatic->lastname = $objp->lastname;
260
                        $memberstatic->firstname = $objp->firstname;
261
                        $memberstatic->statut = $objp->statut;
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$statut has been deprecated: Use $status instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

261
                        /** @scrutinizer ignore-deprecated */ $memberstatic->statut = $objp->statut;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
262
                        $memberstatic->datefin = $db->jdate($objp->datefin);
263
264
                        $companyname = $objp->company;
265
266
                        print '<tr class="oddeven">';
267
268
                        // Ref
269
                        print "<td>";
270
                        print $memberstatic->getNomUrl(1);
271
                        print "</td>\n";
272
273
                        // Lastname
274
                        print "<td><a href=\"card.php?rowid=$objp->rowid\">";
275
                        print((!empty($objp->lastname) || !empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : '');
276
                        print(((!empty($objp->lastname) || !empty($objp->firstname)) && !empty($companyname)) ? ' / ' : '');
277
                        print(!empty($companyname) ? dol_trunc($companyname, 32) : '');
278
                        print "</a></td>\n";
279
280
                        // Login
281
                        print "<td>" . $objp->login . "</td>\n";
282
283
                        // Type
284
                        $membertypestatic->id = $objp->type_id;
285
                        $membertypestatic->libelle = $objp->type_label; // deprecated
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Code\Adherents\...\AdherentType::$libelle has been deprecated: Use label ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

285
                        /** @scrutinizer ignore-deprecated */ $membertypestatic->libelle = $objp->type_label; // deprecated

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
286
                        $membertypestatic->label = $objp->type_label;
287
288
                        print '<td class="nowrap">';
289
                        print $membertypestatic->getNomUrl(1, 32);
290
                        print '</td>';
291
292
                        // Moral/Physique
293
                        print "<td>" . $memberstatic->getmorphylib($objp->morphy) . "</td>\n";
294
295
                        // EMail
296
                        print "<td>" . dol_print_email($objp->email, 0, 0, 1) . "</td>\n";
297
298
                        // Statut
299
                        print '<td class="nowrap">';
300
                        print $memberstatic->LibStatut($objp->statut, $objp->subscription, $datefin, 2);
301
                        print "</td>";
302
303
                        // End of subscription date
304
                        if ($datefin) {
305
                            print '<td class="center nowrap">';
306
                            print dol_print_date($datefin, 'day');
307
                            if ($memberstatic->hasDelay()) {
308
                                print " " . img_warning($langs->trans("SubscriptionLate"));
309
                            }
310
                            print '</td>';
311
                        } else {
312
                            print '<td class="left nowrap">';
313
                            if (!empty($objp->subscription)) {
314
                                print $langs->trans("SubscriptionNotReceived");
315
                                if ($objp->statut > 0) {
316
                                    print " " . img_warning();
317
                                }
318
                            } else {
319
                                print '&nbsp;';
320
                            }
321
                            print '</td>';
322
                        }
323
324
                        print "</tr>\n";
325
                        $i++;
326
                    }
327
                    print "</table>\n";
328
                }
329
            }
330
        }
331
    } else {
332
        // Contrat non trouve
333
        print "ErrorRecordNotFound";
334
    }
335
}
336
337
// End of page
338
ViewMain::llxFooter();
339
$db->close();
340