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

BookCalAvailabilitiesDocumentController   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 96
rs 10
c 0
b 0
f 0
wmc 14

1 Method

Rating   Name   Duplication   Size   Complexity  
F index() 0 93 14
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_document.php
38
 *   \ingroup    bookcal
39
 *   \brief      Tab for documents linked to Availabilities
40
 */
41
42
// Load Dolibarr environment
43
require BASE_PATH . '/main.inc.php';
44
require_once BASE_PATH . '/../Dolibarr/Lib/Company.php';
45
require_once BASE_PATH . '/../Dolibarr/Lib/Files.php';
46
require_once BASE_PATH . '/../Dolibarr/Lib/Images.php';
47
require_once BASE_PATH . '/../Dolibarr/Modules/BookCal/Lib/BookCalAvailabilities.php';
48
49
class BookCalAvailabilitiesDocumentController extends DolibarrController
50
{
51
52
    public function index(bool $executeActions = true): bool
53
    {
54
        global $conf;
55
        global $db;
56
        global $user;
57
        global $hookmanager;
58
        global $user;
59
        global $menumanager;
60
        global $langs;
61
62
63
// Load translation files required by the page
64
        $langs->loadLangs(["agenda", "companies", "other", "mails"]);
65
66
67
        $action = GETPOST('action', 'aZ09');
68
        $confirm = GETPOST('confirm');
69
        $id = (GETPOSTINT('socid') ? GETPOSTINT('socid') : GETPOSTINT('id'));
70
        $ref = GETPOST('ref', 'alpha');
71
72
// Get parameters
73
        $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
74
        $sortfield = GETPOST('sortfield', 'aZ09comma');
75
        $sortorder = GETPOST('sortorder', 'aZ09comma');
76
        $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
77
        if (empty($page) || $page == -1) {
78
            $page = 0;
79
        }     // If $page is not defined, or '' or -1
80
        $offset = $limit * $page;
81
        $pageprev = $page - 1;
82
        $pagenext = $page + 1;
83
        if (!$sortorder) {
84
            $sortorder = "ASC";
85
        }
86
        if (!$sortfield) {
87
            $sortfield = "name";
88
        }
89
//if (! $sortfield) $sortfield="position_name";
90
91
// Initialize technical objects
92
        $object = new Availabilities($db);
93
        $extrafields = new ExtraFields($db);
94
        $diroutputmassaction = $conf->bookcal->dir_output . '/temp/massgeneration/' . $user->id;
95
        $hookmanager->initHooks(['availabilitiesdocument', 'globalcard']); // Note that conf->hooks_modules contains array
96
// Fetch optionals attributes and labels
97
        $extrafields->fetch_name_optionals_label($object->table_element);
98
99
// Load object
100
        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
101
102
        if ($id > 0 || !empty($ref)) {
103
            $upload_dir = $conf->bookcal->multidir_output[$object->entity ? $object->entity : $conf->entity] . "/availabilities/" . get_exdir(0, 0, 0, 1, $object);
104
        }
105
106
// There is several ways to check permission.
107
// Set $enablepermissioncheck to 1 to enable a minimum low level of checks
108
        $enablepermissioncheck = 0;
109
        if ($enablepermissioncheck) {
110
            $permissiontoread = $user->hasRight('bookcal', 'availabilities', 'read');
111
            $permissiontoadd = $user->hasRight('bookcal', 'availabilities', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
112
        } else {
113
            $permissiontoread = 1;
114
            $permissiontoadd = 1;
115
        }
116
117
// Security check (enable the most restrictive one)
118
//if ($user->socid > 0) accessforbidden();
119
//if ($user->socid > 0) $socid = $user->socid;
120
//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
121
//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
122
        if (!isModEnabled('bookcal')) {
123
            accessforbidden();
124
        }
125
        if (!$permissiontoread) {
126
            accessforbidden();
127
        }
128
129
130
        /*
131
         * Actions
132
         */
133
134
        include DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
135
136
137
        /*
138
         * View
139
         */
140
        require_once realpath(BASE_PATH . '/../Dolibarr/Modules/BookCal/Views/availabilities_document.php');
141
142
        $db->close();
143
144
        return true;
145
    }
146
}
147