Issues (2811)

public/htdocs/commande/contact.php (1 issue)

Labels
Severity
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-2022  Philippe Grand              <[email protected]>
7
 * Copyright (C) 2021 		Frédéric France		        <[email protected]>
8
 * Copyright (C) 2024       Rafael San José             <[email protected]>
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23
24
use Dolibarr\Code\Commande\Classes\Commande;
25
use Dolibarr\Code\Contact\Classes\Contact;
26
use Dolibarr\Code\Core\Classes\Form;
27
use Dolibarr\Code\Core\Classes\FormCompany;
28
use Dolibarr\Code\Core\Classes\FormOther;
29
use Dolibarr\Code\Projet\Classes\Project;
30
use Dolibarr\Code\User\Classes\User;
31
use Dolibarr\Lib\ViewMain;
32
33
/**
34
 *     \file       htdocs/commande/contact.php
35
 *     \ingroup    order
36
 *     \brief      Onglet de gestion des contacts de commande
37
 */
38
39
// Load Dolibarr environment
40
require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php';
41
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/order.lib.php';
42
43
// Load translation files required by the page
44
$langs->loadLangs(array('orders', 'sendings', 'companies', 'bills'));
45
46
$id = GETPOSTINT('id');
47
$ref = GETPOST('ref', 'alpha');
48
$action = GETPOST('action', 'aZ09');
49
50
// Security check
51
if ($user->socid) {
52
    $socid = $user->socid;
53
}
54
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
55
$hookmanager->initHooks(array('ordercontact', 'globalcard'));
56
57
$result = restrictedArea($user, 'commande', $id, '');
58
$hookmanager->initHooks(array('ordercontactcard', 'globalcard'));
59
60
$usercancreate = $user->hasRight("commande", "creer");
61
62
$object = new Commande($db);
63
64
/*
65
 * Actions
66
 */
67
68
$parameters = array('id' => $id);
69
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
70
if ($reshook < 0) {
71
    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
72
}
73
74
if (empty($reshook)) {
75
    // Add new contact
76
    if ($action == 'addcontact' && $user->hasRight('commande', 'creer')) {
77
        $result = $object->fetch($id);
78
79
        if ($result > 0 && $id > 0) {
80
            $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
81
            $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
82
            $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
83
        }
84
85
        if ($result >= 0) {
86
            header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
87
            exit;
88
        } else {
89
            if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
90
                $langs->load("errors");
91
                setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
92
            } else {
93
                setEventMessages($object->error, $object->errors, 'errors');
94
            }
95
        }
96
    } elseif ($action == 'swapstatut' && $user->hasRight('commande', 'creer')) {
97
        // Toggle the status of a contact
98
        if ($object->fetch($id)) {
99
            $result = $object->swapContactStatus(GETPOSTINT('ligne'));
100
        } else {
101
            dol_print_error($db);
102
        }
103
    } elseif ($action == 'deletecontact' && $user->hasRight('commande', 'creer')) {
104
        // Delete contact
105
        $object->fetch($id);
106
        $result = $object->delete_contact(GETPOSTINT("lineid"));
107
108
        if ($result >= 0) {
109
            header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
110
            exit;
111
        } else {
112
            setEventMessages($object->error, $object->errors, 'errors');
113
        }
114
    }
115
}
116
117
/*
118
 * View
119
 */
120
$form = new Form($db);
121
$formcompany = new FormCompany($db);
122
$formother = new FormOther($db);
123
$contactstatic = new Contact($db);
124
$userstatic = new User($db);
125
126
127
/* *************************************************************************** */
128
/*                                                                             */
129
/* Card view and edit mode                                                       */
130
/*                                                                             */
131
/* *************************************************************************** */
132
133
if ($id > 0 || !empty($ref)) {
134
    if ($object->fetch($id, $ref) > 0) {
135
        $object->fetch_thirdparty();
136
137
        $title = $object->ref . " - " . $langs->trans('ContactsAddresses');
138
        $help_url = 'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
139
        ViewMain::llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-order page-card_contact');
140
141
        $head = commande_prepare_head($object);
142
        print dol_get_fiche_head($head, 'contact', $langs->trans("CustomerOrder"), -1, 'order');
143
144
        // Order card
145
146
        $linkback = '<a href="' . constant('BASE_URL') . 'commande/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
147
148
        $morehtmlref = '<div class="refidno">';
149
        // Ref customer
150
        $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
151
        $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
152
        // Thirdparty
153
        $morehtmlref .= '<br>' . $object->thirdparty->getNomUrl(1);
0 ignored issues
show
The method getNomUrl() does not exist on null. ( Ignorable by Annotation )

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

153
        $morehtmlref .= '<br>' . $object->thirdparty->/** @scrutinizer ignore-call */ getNomUrl(1);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
154
        // Project
155
        if (isModEnabled('project')) {
156
            $langs->load("projects");
157
            $morehtmlref .= '<br>';
158
            if (0) {
159
                $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
160
                if ($action != 'classify') {
161
                    $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
162
                }
163
                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
164
            } else {
165
                if (!empty($object->fk_project)) {
166
                    $proj = new Project($db);
167
                    $proj->fetch($object->fk_project);
168
                    $morehtmlref .= $proj->getNomUrl(1);
169
                    if ($proj->title) {
170
                        $morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
171
                    }
172
                }
173
            }
174
        }
175
        $morehtmlref .= '</div>';
176
177
        dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
178
179
        print dol_get_fiche_end();
180
181
        print '<br>';
182
183
        // Contacts lines (modules that overwrite templates must declare this into descriptor)
184
        $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
185
        foreach ($dirtpls as $reldir) {
186
            $res = @include dol_buildpath($reldir . '/contacts.tpl.php');
187
            if ($res) {
188
                break;
189
            }
190
        }
191
    } else {
192
        // Contact not found
193
        print "ErrorRecordNotFound";
194
    }
195
}
196
197
198
// End of page
199
ViewMain::llxFooter();
200
$db->close();
201