1 | <?php |
||
2 | |||
3 | /* Copyright (C) 2005-2015 Laurent Destailleur <[email protected]> |
||
4 | * Copyright (C) 2015 Charlie BENKE <[email protected]> |
||
5 | * Copyright (C) 2017-2023 Alexandre Spangaro <[email protected]> |
||
6 | * Copyright (C) 2021 Gauthier VERDOL <[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 | use Dolibarr\Code\Core\Classes\ExtraFields; |
||
24 | use Dolibarr\Code\Core\Classes\Form; |
||
25 | use Dolibarr\Code\Core\Classes\FormProjets; |
||
26 | use Dolibarr\Code\Projet\Classes\Project; |
||
27 | use Dolibarr\Code\Salaries\Classes\Salary; |
||
28 | use Dolibarr\Code\User\Classes\User; |
||
29 | use Dolibarr\Lib\ViewMain; |
||
30 | |||
31 | /** |
||
32 | * \file htdocs/salaries/info.php |
||
33 | * \ingroup salaries |
||
34 | * \brief Page with info about salaries contribution |
||
35 | */ |
||
36 | |||
37 | // Load Dolibarr environment |
||
38 | require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php'; |
||
39 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/salaries.lib.php'; |
||
40 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/functions2.lib.php'; |
||
41 | if (isModEnabled('project')) { |
||
42 | } |
||
43 | |||
44 | // Load translation files required by the page |
||
45 | $langs->loadLangs(array("compta", "bills", "users", "salaries", "hrm")); |
||
46 | |||
47 | $id = GETPOSTINT('id'); |
||
48 | $ref = GETPOST('ref', 'alpha'); |
||
49 | $action = GETPOST('action', 'aZ09'); |
||
50 | |||
51 | $label = GETPOST('label', 'alphanohtml'); |
||
52 | $projectid = (GETPOSTINT('projectid') ? GETPOSTINT('projectid') : GETPOSTINT('fk_project')); |
||
53 | |||
54 | // Security check |
||
55 | $socid = GETPOSTINT('socid'); |
||
56 | if ($user->socid) { |
||
57 | $socid = $user->socid; |
||
58 | } |
||
59 | |||
60 | $object = new Salary($db); |
||
61 | $extrafields = new ExtraFields($db); |
||
62 | |||
63 | $childids = $user->getAllChildIds(1); |
||
64 | |||
65 | // fetch optionals attributes and labels |
||
66 | $extrafields->fetch_name_optionals_label($object->table_element); |
||
67 | |||
68 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
||
69 | $hookmanager->initHooks(array('salaryinfo', 'globalcard')); |
||
70 | |||
71 | $object = new Salary($db); |
||
72 | if ($id > 0 || !empty($ref)) { |
||
73 | $object->fetch($id, $ref); |
||
74 | |||
75 | // Check current user can read this salary |
||
76 | $canread = 0; |
||
77 | if ($user->hasRight('salaries', 'readall')) { |
||
78 | $canread = 1; |
||
79 | } |
||
80 | if ($user->hasRight('salaries', 'read') && $object->fk_user > 0 && in_array($object->fk_user, $childids)) { |
||
81 | $canread = 1; |
||
82 | } |
||
83 | if (!$canread) { |
||
84 | accessforbidden(); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | restrictedArea($user, 'salaries', $object->id, 'salary', ''); |
||
89 | |||
90 | $permissiontoread = $user->hasRight('salaries', 'read'); |
||
91 | $permissiontoadd = $user->hasRight('salaries', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php |
||
92 | $permissiontodelete = $user->hasRight('salaries', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_UNPAID); |
||
93 | |||
94 | |||
95 | /* |
||
96 | * Actions |
||
97 | */ |
||
98 | |||
99 | // Link to a project |
||
100 | if ($action == 'classin' && $permissiontoadd) { |
||
101 | $object->fetch($id); |
||
102 | $object->setProject($projectid); |
||
103 | } |
||
104 | |||
105 | // set label |
||
106 | if ($action == 'setlabel' && $permissiontoadd) { |
||
107 | $object->fetch($id); |
||
108 | $object->label = $label; |
||
0 ignored issues
–
show
|
|||
109 | $object->update($user); |
||
110 | } |
||
111 | |||
112 | /* |
||
113 | * View |
||
114 | */ |
||
115 | |||
116 | $form = new Form($db); |
||
117 | if (isModEnabled('project')) { |
||
118 | $formproject = new FormProjets($db); |
||
119 | } |
||
120 | |||
121 | $title = $langs->trans('Salary') . " - " . $langs->trans('Info'); |
||
122 | $help_url = ""; |
||
123 | ViewMain::llxHeader("", $title, $help_url); |
||
124 | |||
125 | $object->fetch($id); |
||
126 | $object->info($id); |
||
127 | |||
128 | $head = salaries_prepare_head($object); |
||
129 | |||
130 | print dol_get_fiche_head($head, 'info', $langs->trans("SalaryPayment"), -1, 'salary'); |
||
131 | |||
132 | $linkback = '<a href="' . constant('BASE_URL') . '/salaries/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>'; |
||
133 | |||
134 | $morehtmlref = '<div class="refidno">'; |
||
135 | |||
136 | $userstatic = new User($db); |
||
137 | $userstatic->fetch($object->fk_user); |
||
138 | |||
139 | |||
140 | // Label |
||
141 | if ($action != 'editlabel') { |
||
142 | $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $permissiontoadd, 'string', '', 0, 1); |
||
143 | $morehtmlref .= $object->label; |
||
144 | } else { |
||
145 | $morehtmlref .= $langs->trans('Label') . ' : '; |
||
146 | $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">'; |
||
147 | $morehtmlref .= '<input type="hidden" name="action" value="setlabel">'; |
||
148 | $morehtmlref .= '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
149 | $morehtmlref .= '<input type="text" name="label" value="' . $object->label . '"/>'; |
||
150 | $morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">'; |
||
151 | $morehtmlref .= '</form>'; |
||
152 | } |
||
153 | |||
154 | $morehtmlref .= '<br>' . $langs->trans('Employee') . ' : ' . $userstatic->getNomUrl(-1); |
||
155 | |||
156 | $usercancreate = $permissiontoadd; |
||
157 | |||
158 | // Project |
||
159 | if (isModEnabled('project')) { |
||
160 | $langs->load("projects"); |
||
161 | $morehtmlref .= '<br>'; |
||
162 | if ($usercancreate) { |
||
163 | $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); |
||
164 | if ($action != 'classify') { |
||
165 | $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> '; |
||
166 | } |
||
167 | $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, -1, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300'); |
||
168 | } else { |
||
169 | if (!empty($object->fk_project)) { |
||
170 | $proj = new Project($db); |
||
171 | $proj->fetch($object->fk_project); |
||
172 | $morehtmlref .= $proj->getNomUrl(1); |
||
173 | if ($proj->title) { |
||
174 | $morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>'; |
||
175 | } |
||
176 | } |
||
177 | } |
||
178 | } |
||
179 | |||
180 | $morehtmlref .= '</div>'; |
||
181 | |||
182 | dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', ''); |
||
183 | |||
184 | print '<div class="fichecenter">'; |
||
185 | print '<div class="underbanner clearboth"></div>'; |
||
186 | |||
187 | print '<br>'; |
||
188 | |||
189 | print '<table class="centpercent"><tr><td>'; |
||
190 | dol_print_object_info($object); |
||
191 | print '</td></tr></table>'; |
||
192 | |||
193 | print '</div>'; |
||
194 | |||
195 | print dol_get_fiche_end(); |
||
196 | |||
197 | // End of page |
||
198 | ViewMain::llxFooter(); |
||
199 | $db->close(); |
||
200 |
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 theid
property of an instance of theAccount
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.