Passed
Push — main ( 7eb3b3...9a81fe )
by Rafael
42:16
created

BomNoteController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 35
c 1
b 0
f 0
dl 0
loc 78
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B index() 0 76 7
1
<?php
2
3
/* Copyright (C) 2007-2017  Laurent Destailleur     <[email protected]>
4
 * Copyright (C) 2019       Frédéric France         <[email protected]>
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_note.php
33
 *    \ingroup    bom
34
 *    \brief      Card with notes on BillOfMaterials
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 DOL_DOCUMENT_ROOT . '/bom/class/bom.class.php';
44
require_once BASE_PATH . '/../Dolibarr/Modules/Bom/Lib/Bom.php';
45
46
class BomNoteController extends DolibarrController
47
{
48
    public function index(bool $executeActions = true): bool
49
    {
50
        global $conf;
51
        global $db;
52
        global $user;
53
        global $hookmanager;
54
        global $user;
55
        global $menumanager;
56
        global $langs;
57
        global $mysoc;
58
59
60
// Load translation files required by the page
61
        $langs->loadLangs(["mrp", "companies"]);
62
63
// Get parameters
64
        $id = GETPOSTINT('id');
65
        $ref = GETPOST('ref', 'alpha');
66
        $action = GETPOST('action', 'aZ09');
67
        $cancel = GETPOST('cancel', 'aZ09');
68
        $backtopage = GETPOST('backtopage', 'alpha');
69
70
// Initialize technical objects
71
        $object = new Bom($db);
72
        $extrafields = new ExtraFields($db);
73
74
// Initialize technical objects for hooks
75
        $hookmanager->initHooks(['bomnote', 'globalcard']); // Note that conf->hooks_modules contains array
76
77
// Massactions
78
        $diroutputmassaction = $conf->bom->dir_output . '/temp/massgeneration/' . $user->id;
79
80
// Fetch optionals attributes and labels
81
        $extrafields->fetch_name_optionals_label($object->table_element);
82
83
// Security check - Protection if external user
84
//if ($user->socid > 0) accessforbidden();
85
//if ($user->socid > 0) $socid = $user->socid;
86
//$result = restrictedArea($user, 'bom', $id);
87
88
// Load object
89
        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
90
        if ($id > 0 || !empty($ref)) {
91
            $upload_dir = (!empty($conf->bom->multidir_output[$object->entity]) ? $conf->bom->multidir_output[$object->entity] : $conf->bom->dir_output) . "/" . $object->id;
92
        }
93
94
        $permissionnote = $user->hasRight('bom', 'write'); // Used by the include of actions_setnotes.inc.php
95
96
// Security check - Protection if external user
97
//if ($user->socid > 0) accessforbidden();
98
//if ($user->socid > 0) $socid = $user->socid;
99
        $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
100
        restrictedArea($user, 'bom', $object->id, $object->table_element, '', '', 'rowid', $isdraft);
101
102
103
        /*
104
         * Actions
105
         */
106
107
        $parameters = [];
108
        $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
109
        if ($reshook < 0) {
110
            setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
111
        }
112
        if (empty($reshook)) {
113
            include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not include_once
114
        }
115
116
117
        /*
118
         * View
119
         */
120
        require_once realpath(BASE_PATH . '/../Dolibarr/Modules/Bom/Views/bom_note.php');
121
122
        $db->close();
123
        return true;
124
    }
125
}
126