Issues (2811)

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

1
<?php
2
3
/* Copyright (C) 2003-2007  Rodolphe Quiedeville        <[email protected]>
4
 * Copyright (C) 2004-2015  Laurent Destailleur         <[email protected]>
5
 * Copyright (C) 2005       Marc Barilley / Ocebo       <[email protected]>
6
 * Copyright (C) 2005-2009  Regis Houssin               <[email protected]>
7
 * Copyright (C) 2005       Simon TOSSER                <[email protected]>
8
 * Copyright (C) 2011-2012  Juanjo Menent               <[email protected]>
9
 * Copyright (C) 2013       Cédric Salvador             <[email protected]>
10
 * Copyright (C) 2015-2023  Alexandre Spangaro          <[email protected]>
11
 * Copyright (C) 2021       Gauthier VERDOL             <[email protected]>
12
 * Copyright (C) 2024		MDW							<[email protected]>
13
 * Copyright (C) 2024       Rafael San José             <[email protected]>
14
 *
15
 * This program is free software; you can redistribute it and/or modify
16
 * it under the terms of the GNU General Public License as published by
17
 * the Free Software Foundation; either version 3 of the License, or
18
 * (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27
 * or see https://www.gnu.org/
28
 */
29
30
use Dolibarr\Code\Core\Classes\ExtraFields;
31
use Dolibarr\Code\Core\Classes\Form;
32
use Dolibarr\Code\Core\Classes\FormProjets;
33
use Dolibarr\Code\Projet\Classes\Project;
34
use Dolibarr\Code\Salaries\Classes\Salary;
35
use Dolibarr\Code\User\Classes\User;
36
use Dolibarr\Lib\ViewMain;
37
38
/**
39
 *       \file       htdocs/salaries/document.php
40
 *       \ingroup    salaries
41
 *       \brief      Page of linked files onto salaries
42
 */
43
44
// Load Dolibarr environment
45
require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php';
46
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php';
47
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/salaries.lib.php';
48
if (isModEnabled('project')) {
49
    }
50
51
// Load translation files required by the page
52
$langs->loadLangs(array("compta", "bills", "users", "salaries", "hrm"));
53
54
$id = GETPOSTINT('id');
55
$ref = GETPOST('ref', 'alpha');
56
$action = GETPOST('action', 'aZ09');
57
$confirm = GETPOST('confirm', 'alpha');
58
59
$label = GETPOST('label', 'alphanohtml');
60
$projectid = (GETPOSTINT('projectid') ? GETPOSTINT('projectid') : GETPOSTINT('fk_project'));
61
62
// Get parameters
63
$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
64
$sortfield = GETPOST('sortfield', 'aZ09comma');
65
$sortorder = GETPOST('sortorder', 'aZ09comma');
66
$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
67
if (empty($page) || $page == -1) {
68
    $page = 0;
69
}     // If $page is not defined, or '' or -1
70
$offset = $limit * $page;
71
$pageprev = $page - 1;
72
$pagenext = $page + 1;
73
if (!$sortorder) {
74
    $sortorder = "ASC";
75
}
76
if (!$sortfield) {
77
    $sortfield = "name";
78
}
79
80
$object = new Salary($db);
81
$extrafields = new ExtraFields($db);
82
83
$childids = $user->getAllChildIds(1);
84
85
// fetch optionals attributes and labels
86
$extrafields->fetch_name_optionals_label($object->table_element);
87
88
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
89
$hookmanager->initHooks(array('salarydoc', 'globalcard'));
90
91
if ($id > 0 || !empty($ref)) {
92
    $object->fetch($id, $ref);
93
94
    // Check current user can read this salary
95
    $canread = 0;
96
    if ($user->hasRight('salaries', 'readall')) {
97
        $canread = 1;
98
    }
99
    if ($user->hasRight('salaries', 'read') && $object->fk_user > 0 && in_array($object->fk_user, $childids)) {
100
        $canread = 1;
101
    }
102
103
    if (!$canread) {
104
        accessforbidden();
105
    }
106
}
107
108
$upload_dir = $conf->salaries->dir_output . '/' . dol_sanitizeFileName($object->id);
109
$modulepart = 'salaries';
110
111
// Security check
112
$socid = GETPOSTINT('socid');
113
if ($user->socid) {
114
    $socid = $user->socid;
115
}
116
restrictedArea($user, 'salaries', $object->id, 'salary', '');
117
118
$permissiontoread = $user->hasRight('salaries', 'read');
119
$permissiontoadd = $user->hasRight('salaries', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
120
$permissiontodelete = $user->hasRight('salaries', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_UNPAID);
121
122
/*
123
 * Actions
124
 */
125
126
include DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
127
128
// Link to a project
129
if ($action == 'classin' && $permissiontoadd) {
130
    $object->fetch($id);
131
    $object->setProject($projectid);
132
}
133
134
// set label
135
if ($action == 'setlabel' && $permissiontoadd) {
136
    $object->fetch($id);
137
    $object->label = $label;
0 ignored issues
show
Documentation Bug introduced by
It seems like $label can also be of type array or array or array. However, the property $label is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
138
    $object->update($user);
139
}
140
141
/*
142
 * View
143
 */
144
145
$form = new Form($db);
146
if (isModEnabled('project')) {
147
    $formproject = new FormProjets($db);
148
}
149
150
$title = $langs->trans('Salary') . " - " . $langs->trans('Documents');
151
$help_url = "";
152
ViewMain::llxHeader("", $title, $help_url);
153
154
if ($object->id) {
155
    $object->fetch_thirdparty();
156
157
    $head = salaries_prepare_head($object);
158
159
    print dol_get_fiche_head($head, 'documents', $langs->trans("SalaryPayment"), -1, 'salary');
160
161
    // Build file list
162
    $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
163
    $totalsize = 0;
164
    foreach ($filearray as $key => $file) {
165
        $totalsize += $file['size'];
166
    }
167
168
    $linkback = '<a href="' . constant('BASE_URL') . '/salaries/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
169
170
    $morehtmlref = '<div class="refidno">';
171
172
    $userstatic = new User($db);
173
    $userstatic->fetch($object->fk_user);
174
175
    // Label
176
    if ($action != 'editlabel') {
177
        $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $permissiontoadd, 'string', '', 0, 1);
178
        $morehtmlref .= $object->label;
179
    } else {
180
        $morehtmlref .= $langs->trans('Label') . ' :&nbsp;';
181
        $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
182
        $morehtmlref .= '<input type="hidden" name="action" value="setlabel">';
183
        $morehtmlref .= '<input type="hidden" name="token" value="' . newToken() . '">';
184
        $morehtmlref .= '<input type="text" name="label" value="' . $object->label . '"/>';
185
        $morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
186
        $morehtmlref .= '</form>';
187
    }
188
189
    $morehtmlref .= '<br>' . $langs->trans('Employee') . ' : ' . $userstatic->getNomUrl(-1);
190
191
    $usercancreate = $permissiontoadd;
192
193
    // Project
194
    if (isModEnabled('project')) {
195
        $langs->load("projects");
196
        $morehtmlref .= '<br>';
197
        if ($usercancreate) {
198
            $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
199
            if ($action != 'classify') {
200
                $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
201
            }
202
            $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, -1, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
203
        } else {
204
            if (!empty($object->fk_project)) {
205
                $proj = new Project($db);
206
                $proj->fetch($object->fk_project);
207
                $morehtmlref .= $proj->getNomUrl(1);
208
                if ($proj->title) {
209
                    $morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
210
                }
211
            }
212
        }
213
    }
214
215
    $morehtmlref .= '</div>';
216
217
    dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
218
219
    print '<div class="fichecenter">';
220
    print '<div class="underbanner clearboth"></div>';
221
222
    print '<table class="border tableforfield centpercent">';
223
224
    print "<tr>";
225
    print '<td class="titlefield">' . $langs->trans("DateStartPeriod") . '</td><td>';
226
    print dol_print_date($object->datesp, 'day');
227
    print '</td></tr>';
228
229
    print "<tr>";
230
    print '<td>' . $langs->trans("DateEndPeriod") . '</td><td>';
231
    print dol_print_date($object->dateep, 'day');
232
    print '</td></tr>';
233
234
    print '<tr><td>' . $langs->trans("Amount") . '</td><td><span class="amount">' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency) . '</span></td></tr>';
235
236
    print '<tr><td class="titlefield">' . $langs->trans("NbOfAttachedFiles") . '</td><td>' . count($filearray) . '</td></tr>';
237
238
    print '<tr><td>' . $langs->trans("TotalSizeOfAttachedFiles") . '</td><td>' . dol_print_size($totalsize, 1, 1) . '</td></tr>';
239
240
    print '</table>';
241
242
    print '</div>';
243
244
    print dol_get_fiche_end();
245
246
    $modulepart = 'salaries';
247
    // $permissiontoadd = $permissiontoadd;
248
    $param = '&id=' . $object->id;
249
    include DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
250
} else {
251
    print $langs->trans("ErrorUnknown");
252
}
253
254
// End of page
255
ViewMain::llxFooter();
256
$db->close();
257