|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* Copyright (C) 2005-2022 Laurent Destailleur <[email protected]> |
|
4
|
|
|
* Copyright (C) 2024 Rafael San José <[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\BookMarks\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
|
|
|
use DoliCore\Base\DolibarrController; |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* \file htdocs/bookmarks/list.php |
|
36
|
|
|
* \ingroup bookmark |
|
37
|
|
|
* \brief Page to display list of bookmarks |
|
38
|
|
|
*/ |
|
39
|
|
|
|
|
40
|
|
|
// Load Dolibarr environment |
|
41
|
|
|
use DoliCore\Form\Form; |
|
42
|
|
|
use DoliCore\Lib\ExtraFields; |
|
43
|
|
|
use DoliCore\Model\Bookmark; |
|
44
|
|
|
|
|
45
|
|
|
require BASE_PATH . '/main.inc.php'; |
|
46
|
|
|
|
|
47
|
|
|
class BookMarksListController 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(['bookmarks', 'admin']); |
|
63
|
|
|
|
|
64
|
|
|
// Get Parameters |
|
65
|
|
|
$action = GETPOST('action', 'aZ09'); |
|
66
|
|
|
$massaction = GETPOST('massaction', 'alpha'); |
|
67
|
|
|
$show_files = GETPOSTINT('show_files'); |
|
68
|
|
|
$confirm = GETPOST('confirm', 'alpha'); |
|
69
|
|
|
$cancel = GETPOST('cancel', 'alpha'); |
|
70
|
|
|
$toselect = GETPOST('toselect', 'array'); |
|
71
|
|
|
$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'bookmarklist'; // To manage different context of search |
|
72
|
|
|
$backtopage = GETPOST('backtopage', 'alpha'); |
|
73
|
|
|
$optioncss = GETPOST('optioncss', 'alpha'); |
|
74
|
|
|
$mode = GETPOST('mode', 'aZ'); |
|
75
|
|
|
|
|
76
|
|
|
$id = GETPOSTINT("id"); |
|
77
|
|
|
$search_title = GETPOST('search_title', 'alpha'); |
|
78
|
|
|
|
|
79
|
|
|
// Load variable for pagination |
|
80
|
|
|
$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; |
|
81
|
|
|
$sortfield = GETPOST('sortfield', 'aZ09comma'); |
|
82
|
|
|
$sortorder = GETPOST('sortorder', 'aZ09comma'); |
|
83
|
|
|
$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); |
|
84
|
|
|
if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { |
|
85
|
|
|
// If $page is not defined, or '' or -1 or if we click on clear filters |
|
86
|
|
|
$page = 0; |
|
87
|
|
|
} |
|
88
|
|
|
$offset = $limit * $page; |
|
89
|
|
|
$pageprev = $page - 1; |
|
90
|
|
|
$pagenext = $page + 1; |
|
91
|
|
|
if (!$sortfield) { |
|
92
|
|
|
$sortfield = 'b.position'; |
|
93
|
|
|
} |
|
94
|
|
|
if (!$sortorder) { |
|
95
|
|
|
$sortorder = 'ASC'; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
// Initialize Objects |
|
99
|
|
|
$object = new Bookmark($db); |
|
100
|
|
|
$extrafields = new ExtraFields($db); |
|
101
|
|
|
$arrayfields = []; |
|
102
|
|
|
$hookmanager->initHooks(['bookmarklist']); // Note that conf->hooks_modules contains array |
|
103
|
|
|
|
|
104
|
|
|
if ($id > 0) { |
|
105
|
|
|
$object->fetch($id); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$object->fields = dol_sort_array($object->fields, 'position'); |
|
109
|
|
|
$arrayfields = dol_sort_array($arrayfields, 'position'); |
|
110
|
|
|
|
|
111
|
|
|
// Security check |
|
112
|
|
|
restrictedArea($user, 'bookmark', $object); |
|
113
|
|
|
|
|
114
|
|
|
// Permissions |
|
115
|
|
|
$permissiontoread = $user->hasRight('bookmark', 'lire'); |
|
116
|
|
|
$permissiontoadd = $user->hasRight('bookmark', 'creer'); |
|
117
|
|
|
$permissiontodelete = ($user->hasRight('bookmark', 'supprimer') || ($permissiontoadd && $object->fk_user == $user->id)); |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
/* |
|
121
|
|
|
* Actions |
|
122
|
|
|
*/ |
|
123
|
|
|
|
|
124
|
|
|
if (GETPOST('cancel', 'alpha')) { |
|
125
|
|
|
$action = 'list'; |
|
126
|
|
|
$massaction = ''; |
|
127
|
|
|
} |
|
128
|
|
|
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { |
|
129
|
|
|
$massaction = ''; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
$parameters = []; |
|
133
|
|
|
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
|
134
|
|
|
if ($reshook < 0) { |
|
135
|
|
|
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
if (empty($reshook)) { |
|
139
|
|
|
// Selection of new fields |
|
140
|
|
|
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php'; |
|
141
|
|
|
|
|
142
|
|
|
if ( |
|
143
|
|
|
GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') |
|
144
|
|
|
|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha') |
|
145
|
|
|
) { |
|
146
|
|
|
$massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
// Mass actions |
|
150
|
|
|
$objectclass = 'Bookmark'; |
|
151
|
|
|
$objectlabel = 'Bookmark'; |
|
152
|
|
|
$uploaddir = $conf->bookmark->dir_output; |
|
153
|
|
|
include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php'; |
|
154
|
|
|
|
|
155
|
|
|
if ($action == 'delete' && $permissiontodelete) { |
|
156
|
|
|
$object->fetch($id); |
|
157
|
|
|
$res = $object->delete($user); |
|
158
|
|
|
if ($res > 0) { |
|
159
|
|
|
header("Location: " . $_SERVER['PHP_SELF']); |
|
160
|
|
|
exit; |
|
|
|
|
|
|
161
|
|
|
} else { |
|
162
|
|
|
setEventMessages($object->error, $object->errors, 'errors'); |
|
163
|
|
|
$action = ''; |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
|
|
169
|
|
|
/* |
|
170
|
|
|
* View |
|
171
|
|
|
*/ |
|
172
|
|
|
require_once realpath(BASE_PATH . '/../Dolibarr/Modules/BookMarks/Views/list.php'); |
|
173
|
|
|
|
|
174
|
|
|
$db->close(); |
|
175
|
|
|
|
|
176
|
|
|
return true; |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: