Issues (2811)

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

Labels
Severity
1
<?php
2
3
/* Copyright (C) 2003-2007  Rodolphe Quiedeville        <[email protected]>
4
 * Copyright (C) 2004-2016  Laurent Destailleur         <[email protected]>
5
 * Copyright (C) 2005       Marc Barilley / Ocebo       <[email protected]>
6
 * Copyright (C) 2005-2012  Regis Houssin               <[email protected]>
7
 * Copyright (C) 2013       Cédric Salvador             <[email protected]>
8
 * Copyright (C) 2017       Ferran Marcet       	    <[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\Commande\Classes\Commande;
26
use Dolibarr\Code\Core\Classes\Form;
27
use Dolibarr\Code\Projet\Classes\Project;
28
use Dolibarr\Lib\ViewMain;
29
30
/**
31
 *  \file       htdocs/commande/document.php
32
 *  \ingroup    order
33
 *  \brief      Management page of documents attached to an order
34
 */
35
36
// Load Dolibarr environment
37
require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php';
38
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/order.lib.php';
39
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php';
40
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/images.lib.php';
41
42
// Load translation files required by the page
43
$langs->loadLangs(array('companies', 'other', 'bills', 'orders'));
44
45
$action = GETPOST('action', 'aZ09');
46
$confirm = GETPOST('confirm');
47
$id = GETPOSTINT('id');
48
$ref = GETPOST('ref');
49
50
// Get parameters
51
$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
52
$sortfield = GETPOST('sortfield', 'aZ09comma');
53
$sortorder = GETPOST('sortorder', 'aZ09comma');
54
$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
55
if (empty($page) || $page == -1) {
56
    $page = 0;
57
}     // If $page is not defined, or '' or -1
58
$offset = $limit * $page;
59
$pageprev = $page - 1;
60
$pagenext = $page + 1;
61
62
if (getDolGlobalString('MAIN_DOC_SORT_FIELD')) {
63
    $sortfield = getDolGlobalString('MAIN_DOC_SORT_FIELD');
64
}
65
if (getDolGlobalString('MAIN_DOC_SORT_ORDER')) {
66
    $sortorder = getDolGlobalString('MAIN_DOC_SORT_ORDER');
67
}
68
69
if (!$sortorder) {
70
    $sortorder = "ASC";
71
}
72
if (!$sortfield) {
73
    $sortfield = "name";
74
}
75
76
$object = new Commande($db);
77
78
$usercancreate = $user->hasRight("commande", "creer");
79
$permissiontoadd = $usercancreate;
80
81
// Security check
82
if ($user->socid) {
83
    $socid = $user->socid;
84
}
85
86
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
87
$hookmanager->initHooks(array('orderdocument', 'globalcard'));
88
89
$result = restrictedArea($user, 'commande', $id, '');
90
91
92
/*
93
 * Actions
94
 */
95
96
if ($object->fetch($id)) {
97
    $object->fetch_thirdparty();
98
    $upload_dir = $conf->commande->multidir_output[$object->entity] . "/" . dol_sanitizeFileName($object->ref);
99
}
100
101
include DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
102
103
104
/*
105
 * View
106
 */
107
$title = $object->ref . " - " . $langs->trans('Documents');
108
$help_url = 'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
109
ViewMain::llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-order page-card_documents');
110
111
$form = new Form($db);
112
113
if ($id > 0 || !empty($ref)) {
114
    if ($object->fetch($id, $ref)) {
115
        $object->fetch_thirdparty();
116
117
        $upload_dir = $conf->commande->multidir_output[$object->entity] . '/' . dol_sanitizeFileName($object->ref);
118
119
        $head = commande_prepare_head($object);
120
        print dol_get_fiche_head($head, 'documents', $langs->trans('CustomerOrder'), -1, 'order');
121
122
        // Build file list
123
        $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
124
        $totalsize = 0;
125
        foreach ($filearray as $key => $file) {
126
            $totalsize += $file['size'];
127
        }
128
129
        // Order card
130
131
        $linkback = '<a href="' . constant('BASE_URL') . 'commande/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
132
133
134
        $morehtmlref = '<div class="refidno">';
135
        // Ref customer
136
        $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
137
        $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
138
        // Thirdparty
139
        $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

139
        $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...
140
        // Project
141
        if (isModEnabled('project')) {
142
            $langs->load("projects");
143
            $morehtmlref .= '<br>';
144
            if (0) {
145
                $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
146
                if ($action != 'classify') {
147
                    $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
148
                }
149
                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
150
            } else {
151
                if (!empty($object->fk_project)) {
152
                    $proj = new Project($db);
153
                    $proj->fetch($object->fk_project);
154
                    $morehtmlref .= $proj->getNomUrl(1);
155
                    if ($proj->title) {
156
                        $morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
157
                    }
158
                }
159
            }
160
        }
161
        $morehtmlref .= '</div>';
162
163
        // Order card
164
165
        $linkback = '<a href="' . constant('BASE_URL') . 'commande/list.php' . (!empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
166
167
        dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
168
169
        print '<div class="fichecenter">';
170
        print '<div class="underbanner clearboth"></div>';
171
172
        print '<table class="border tableforfield centpercent">';
173
174
        print '<tr><td class="titlefield">' . $langs->trans("NbOfAttachedFiles") . '</td><td colspan="3">' . count($filearray) . '</td></tr>';
175
        print '<tr><td>' . $langs->trans("TotalSizeOfAttachedFiles") . '</td><td colspan="3">' . dol_print_size($totalsize, 1, 1) . '</td></tr>';
176
177
        print "</table>\n";
178
179
        print "</div>\n";
180
181
        print dol_get_fiche_end();
182
183
        $modulepart = 'commande';
184
        $permissiontoadd = $user->hasRight('commande', 'creer');
185
        $permtoedit = $user->hasRight('commande', 'creer');
186
        $param = '&id=' . $object->id . '&entity=' . (empty($object->entity) ? $conf->entity : $object->entity);
187
        include DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
188
    } else {
189
        dol_print_error($db);
190
    }
191
} else {
192
    header('Location: index.php');
193
    exit;
194
}
195
196
197
// End of page
198
ViewMain::llxFooter();
199
$db->close();
200