|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* Copyright (C) 2017 Laurent Destailleur <[email protected]> |
|
4
|
|
|
* Copyright (C) ---Put here your own copyright and developer email--- |
|
5
|
|
|
* |
|
6
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU General Public License as published by |
|
8
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU General Public License |
|
17
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace DoliModules\Bom\Controller; |
|
21
|
|
|
|
|
22
|
|
|
global $conf; |
|
23
|
|
|
global $db; |
|
24
|
|
|
global $user; |
|
25
|
|
|
global $hookmanager; |
|
26
|
|
|
global $user; |
|
27
|
|
|
global $menumanager; |
|
28
|
|
|
global $langs; |
|
29
|
|
|
global $mysoc; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* \file htdocs/bom/bom_agenda.php |
|
33
|
|
|
* \ingroup bom |
|
34
|
|
|
* \brief Page of BOM events |
|
35
|
|
|
*/ |
|
36
|
|
|
|
|
37
|
|
|
// Load Dolibarr environment |
|
38
|
|
|
use DoliCore\Base\DolibarrController; |
|
39
|
|
|
use DoliCore\Lib\ExtraFields; |
|
40
|
|
|
use DoliModules\Bom\Model\Bom; |
|
41
|
|
|
|
|
42
|
|
|
require BASE_PATH . '/main.inc.php'; |
|
43
|
|
|
require_once BASE_PATH . '/../Dolibarr/Lib/Company.php'; |
|
44
|
|
|
require_once BASE_PATH . '/../Dolibarr/Lib/Functions2.php'; |
|
45
|
|
|
require_once BASE_PATH . '/../Dolibarr/Modules/Bom/Lib/Bom.php'; |
|
46
|
|
|
|
|
47
|
|
|
class BomAgendaController extends DolibarrController |
|
48
|
|
|
{ |
|
49
|
|
|
public function index(bool $executeActions = true): bool |
|
50
|
|
|
{ |
|
51
|
|
|
global $conf; |
|
52
|
|
|
global $db; |
|
53
|
|
|
global $user; |
|
54
|
|
|
global $hookmanager; |
|
55
|
|
|
global $user; |
|
56
|
|
|
global $menumanager; |
|
57
|
|
|
global $langs; |
|
58
|
|
|
global $mysoc; |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
// Load translation files required by the page |
|
62
|
|
|
$langs->loadLangs(['mrp', 'other']); |
|
63
|
|
|
|
|
64
|
|
|
// Get parameters |
|
65
|
|
|
$id = GETPOSTINT('id'); |
|
66
|
|
|
$socid = GETPOSTINT('socid'); |
|
67
|
|
|
$ref = GETPOST('ref', 'alpha'); |
|
68
|
|
|
|
|
69
|
|
|
$action = GETPOST('action', 'aZ09'); |
|
70
|
|
|
$cancel = GETPOST('cancel', 'aZ09'); |
|
71
|
|
|
$backtopage = GETPOST('backtopage', 'alpha'); |
|
72
|
|
|
|
|
73
|
|
|
if (GETPOST('actioncode', 'array')) { |
|
74
|
|
|
$actioncode = GETPOST('actioncode', 'array', 3); |
|
75
|
|
|
if (!count($actioncode)) { |
|
76
|
|
|
$actioncode = '0'; |
|
77
|
|
|
} |
|
78
|
|
|
} else { |
|
79
|
|
|
$actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT')); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$search_rowid = GETPOST('search_rowid'); |
|
83
|
|
|
$search_agenda_label = GETPOST('search_agenda_label'); |
|
84
|
|
|
|
|
85
|
|
|
// Load variables for pagination |
|
86
|
|
|
$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; |
|
87
|
|
|
$sortfield = GETPOST('sortfield', 'aZ09comma'); |
|
88
|
|
|
$sortorder = GETPOST('sortorder', 'aZ09comma'); |
|
89
|
|
|
$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); |
|
90
|
|
|
if (empty($page) || $page == -1) { |
|
91
|
|
|
$page = 0; |
|
92
|
|
|
} // If $page is not defined, or '' or -1 |
|
93
|
|
|
$offset = $limit * $page; |
|
94
|
|
|
$pageprev = $page - 1; |
|
95
|
|
|
$pagenext = $page + 1; |
|
96
|
|
|
if (!$sortfield) { |
|
97
|
|
|
$sortfield = 'a.datep,a.id'; |
|
98
|
|
|
} |
|
99
|
|
|
if (!$sortorder) { |
|
100
|
|
|
$sortorder = 'DESC'; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
// Initialize technical objects |
|
104
|
|
|
$object = new Bom($db); |
|
105
|
|
|
$extrafields = new ExtraFields($db); |
|
106
|
|
|
$diroutputmassaction = $conf->bom->dir_output . '/temp/massgeneration/' . $user->id; |
|
107
|
|
|
$hookmanager->initHooks(['bomagenda', 'globalcard']); // Note that conf->hooks_modules contains array |
|
108
|
|
|
|
|
109
|
|
|
// Fetch optionals attributes and labels |
|
110
|
|
|
$extrafields->fetch_name_optionals_label($object->table_element); |
|
111
|
|
|
|
|
112
|
|
|
// Load object |
|
113
|
|
|
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals |
|
114
|
|
|
if ($id > 0 || !empty($ref)) { |
|
115
|
|
|
$upload_dir = (!empty($conf->bom->multidir_output[$object->entity]) ? $conf->bom->multidir_output[$object->entity] : $conf->bom->dir_output) . "/" . $object->id; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
// Security check - Protection if external user |
|
119
|
|
|
//if ($user->socid > 0) accessforbidden(); |
|
120
|
|
|
//if ($user->socid > 0) $socid = $user->socid; |
|
121
|
|
|
$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); |
|
122
|
|
|
restrictedArea($user, 'bom', $object->id, $object->table_element, '', '', 'rowid', $isdraft); |
|
123
|
|
|
|
|
124
|
|
|
/* |
|
125
|
|
|
* Actions |
|
126
|
|
|
*/ |
|
127
|
|
|
|
|
128
|
|
|
$parameters = ['id' => $socid]; |
|
129
|
|
|
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
|
130
|
|
|
if ($reshook < 0) { |
|
131
|
|
|
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
if (empty($reshook)) { |
|
135
|
|
|
// Cancel |
|
136
|
|
|
if (GETPOST('cancel', 'alpha') && !empty($backtopage)) { |
|
137
|
|
|
header("Location: " . $backtopage); |
|
138
|
|
|
exit; |
|
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
// Purge search criteria |
|
142
|
|
|
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers |
|
143
|
|
|
$actioncode = ''; |
|
144
|
|
|
$search_agenda_label = ''; |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/* |
|
149
|
|
|
* View |
|
150
|
|
|
*/ |
|
151
|
|
|
require_once realpath(BASE_PATH . '/../Dolibarr/Modules/Bom/Views/bom_agenda.php'); |
|
152
|
|
|
|
|
153
|
|
|
$db->close(); |
|
154
|
|
|
|
|
155
|
|
|
return true; |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: