Passed
Push — main ( 9a81fe...875825 )
by Rafael
41:55
created

BookCalAvailabilitiesNoteController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 44
dl 0
loc 87
rs 10
c 0
b 0
f 0
wmc 9

1 Method

Rating   Name   Duplication   Size   Complexity  
B index() 0 84 9
1
<?php
2
3
/* Copyright (C) 2007-2017  Laurent Destailleur     <[email protected]>
4
 * Copyright (C) 2022       Alice Adminson          <[email protected]>
5
 * Copyright (C) 2024       Rafael San José         <[email protected]>
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
namespace DoliModules\BookCal\Controller;
22
23
global $conf;
24
global $db;
25
global $user;
26
global $hookmanager;
27
global $user;
28
global $menumanager;
29
global $langs;
30
global $mysoc;
31
32
use DoliCore\Base\DolibarrController;
33
use DoliCore\Lib\ExtraFields;
34
use DoliModules\BookCal\Model\Availabilities;
35
36
/**
37
 *   \file       htdocs/bookcal/availabilities_note.php
38
 *   \ingroup    bookcal
39
 *   \brief      Tab for notes on Availabilities
40
 */
41
42
// Load Dolibarr environment
43
require BASE_PATH . '/main.inc.php';
44
require_once BASE_PATH . '/../Dolibarr/Modules/BookCal/Lib/BookCalAvailabilities.php';
45
46
class BookCalAvailabilitiesNoteController extends DolibarrController
47
{
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
59
60
// Load translation files required by the page
61
        $langs->loadLangs(["agenda", "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 Availabilities($db);
72
        $extrafields = new ExtraFields($db);
73
        $diroutputmassaction = $conf->bookcal->dir_output . '/temp/massgeneration/' . $user->id;
74
        $hookmanager->initHooks(['availabilitiesnote', 'globalcard']); // Note that conf->hooks_modules contains array
75
// Fetch optionals attributes and labels
76
        $extrafields->fetch_name_optionals_label($object->table_element);
77
78
// Load object
79
        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
80
        if ($id > 0 || !empty($ref)) {
81
            $upload_dir = $conf->bookcal->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity] . "/" . $object->id;
82
        }
83
84
85
// There is several ways to check permission.
86
// Set $enablepermissioncheck to 1 to enable a minimum low level of checks
87
        $enablepermissioncheck = 0;
88
        if ($enablepermissioncheck) {
89
            $permissiontoread = $user->hasRight('bookcal', 'availabilities', 'read');
90
            $permissiontoadd = $user->hasRight('bookcal', 'availabilities', 'write');
91
            $permissionnote = $user->hasRight('bookcal', 'availabilities', 'write'); // Used by the include of actions_setnotes.inc.php
92
        } else {
93
            $permissiontoread = 1;
94
            $permissiontoadd = 1;
95
            $permissionnote = 1;
96
        }
97
98
// Security check (enable the most restrictive one)
99
//if ($user->socid > 0) accessforbidden();
100
//if ($user->socid > 0) $socid = $user->socid;
101
//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
102
//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
103
        if (!isModEnabled('bookcal')) {
104
            accessforbidden();
105
        }
106
        if (!$permissiontoread) {
107
            accessforbidden();
108
        }
109
110
111
        /*
112
         * Actions
113
         */
114
115
        $parameters = [];
116
        $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
117
        if ($reshook < 0) {
118
            setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
119
        }
120
        if (empty($reshook)) {
121
            include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not include_once
122
        }
123
124
125
        /*
126
         * View
127
         */
128
        require_once realpath(BASE_PATH . '/../Dolibarr/Modules/BookCal/Views/availabilities_note.php');
129
130
        $db->close();
131
132
        return true;
133
    }
134
}
135