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

BookCalBookingListController   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 48
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 15

1 Method

Rating   Name   Duplication   Size   Complexity  
F index() 0 81 15
1
<?php
2
3
/* Copyright (C) 2002-2005  Rodolphe Quiedeville    <[email protected]>
4
 * Copyright (C) 2004       Eric Seigne				<[email protected]>
5
 * Copyright (C) 2004-2016  Laurent Destailleur		<[email protected]>
6
 * Copyright (C) 2005-2012  Regis Houssin			<[email protected]>
7
 * Copyright (C) 2010-2014  Juanjo Menent			<[email protected]>
8
 * Copyright (C) 2017       Ferran Marcet			<[email protected]>
9
 * Copyright (C) 2023-2024  Frédéric France         <[email protected]>
10
 * Copyright (C) 2024       Rafael San José         <[email protected]>
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 3 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24
 */
25
26
namespace DoliModules\BookCal\Controller;
27
28
global $conf;
29
global $db;
30
global $user;
31
global $hookmanager;
32
global $user;
33
global $menumanager;
34
global $langs;
35
global $mysoc;
36
37
use DoliCore\Base\DolibarrController;
38
39
/**
40
 *  \file       htdocs/bookcal/booking_list.php
41
 *  \ingroup    bookcal
42
 *  \brief      Management of direct debit order or credit transfer of invoices
43
 */
44
45
// Load Dolibarr environment
46
use DoliModules\BookCal\Model\Calendar;
47
48
require BASE_PATH . '/main.inc.php';
49
50
require_once BASE_PATH . '/../Dolibarr/Lib/Date.php';
51
require_once BASE_PATH . '/../Dolibarr/Lib/Company.php';
52
require_once BASE_PATH . '/../Dolibarr/Modules/BookCal/Lib/BookCalCalendar.php';
53
54
// load module libraries
55
require_once __DIR__ . '/class/calendar.class.php';
56
57
class BookCalBookingListController extends DolibarrController
58
{
59
60
    public function index(bool $executeActions = true): bool
61
    {
62
        global $conf;
63
        global $db;
64
        global $user;
65
        global $hookmanager;
66
        global $user;
67
        global $menumanager;
68
        global $langs;
69
70
71
// Load translation files required by the page
72
        $langs->loadLangs(["agenda", "other"]);
73
74
        $id = (GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('facid')); // For backward compatibility
75
        $ref = GETPOST('ref', 'alpha');
76
        $socid = GETPOSTINT('socid');
77
        $action = GETPOST('action', 'aZ09');
78
        $type = GETPOST('type', 'aZ09');
79
80
        $fieldid = (!empty($ref) ? 'ref' : 'rowid');
81
        if ($user->socid) {
82
            $socid = $user->socid;
83
        }
84
85
        $moreparam = '';
86
87
        $object = new Calendar($db);
88
89
// Load object
90
        if ($id > 0 || !empty($ref)) {
91
            $ret = $object->fetch($id, $ref);
92
            $isdraft = (($object->status == Calendar::STATUS_DRAFT) ? 1 : 0);
93
            if ($ret > 0) {
94
                $object->fetch_thirdparty();
95
            }
96
        }
97
98
// There is several ways to check permission.
99
// Set $enablepermissioncheck to 1 to enable a minimum low level of checks
100
        $enablepermissioncheck = 0;
101
        if ($enablepermissioncheck) {
102
            $permissiontoread = $user->hasRight('bookcal', 'calendar', 'read');
103
            $permissiontoadd = $user->hasRight('bookcal', 'calendar', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
104
            $permissiontodelete = $user->hasRight('bookcal', 'calendar', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
105
            $permissionnote = $user->hasRight('bookcal', 'calendar', 'write'); // Used by the include of actions_setnotes.inc.php
106
            $permissiondellink = $user->hasRight('bookcal', 'calendar', 'write'); // Used by the include of actions_dellink.inc.php
107
        } else {
108
            $permissiontoread = 1;
109
            $permissiontoadd = 1; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
110
            $permissiontodelete = 1;
111
            $permissionnote = 1;
112
            $permissiondellink = 1;
113
        }
114
115
        if (!isModEnabled("bookcal")) {
116
            accessforbidden();
117
        }
118
        if (!$permissiontoread) {
119
            accessforbidden();
120
        }
121
122
        /*
123
         * Actions
124
         */
125
126
        $parameters = '';
127
        $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
128
        if ($reshook < 0) {
129
            setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
130
        }
131
132
133
        /*
134
         * View
135
         */
136
        require_once realpath(BASE_PATH . '/../Dolibarr/Modules/BookCal/Views/booking_list.php');
137
138
        $db->close();
139
140
        return true;
141
    }
142
}
143