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

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