|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* Copyright (C) 2013-2014 Jean-François Ferry <[email protected]> |
|
4
|
|
|
* Copyright (C) 2015 Laurent Destailleur <[email protected]> |
|
5
|
|
|
* Copyright (C) 2024 MDW <[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
|
|
|
* Module to manage resources into Dolibarr ERP/CRM |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace Dolibarr\Modules; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* \defgroup resource Module resource |
|
27
|
|
|
* \brief Resource module descriptor. |
|
28
|
|
|
* \file core/modules/modResource.class.php |
|
29
|
|
|
* \ingroup resource |
|
30
|
|
|
* \brief Description and activation file for the module Resource |
|
31
|
|
|
*/ |
|
32
|
|
|
|
|
33
|
|
|
use Dolibarr\Core\Base\DolibarrModules; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Description and activation class for module Resource |
|
37
|
|
|
*/ |
|
38
|
|
|
class Resource extends DolibarrModules |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* Constructor. Define names, constants, directories, boxes, permissions |
|
42
|
|
|
* |
|
43
|
|
|
* @param DoliDB $db Database handler |
|
|
|
|
|
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct($db) |
|
46
|
|
|
{ |
|
47
|
|
|
global $langs, $conf; // $langs may be used by the tpl files. |
|
48
|
|
|
|
|
49
|
|
|
$this->db = $db; |
|
50
|
|
|
|
|
51
|
|
|
// Id for module (must be unique). |
|
52
|
|
|
// Use a free id here |
|
53
|
|
|
// (See in Home -> System information -> Dolibarr for list of used modules id). |
|
54
|
|
|
$this->numero = 63000; |
|
55
|
|
|
|
|
56
|
|
|
// Key text used to identify module (for permissions, menus, etc...) |
|
57
|
|
|
$this->rights_class = 'resource'; |
|
58
|
|
|
|
|
59
|
|
|
// Family can be 'crm','financial','hr','projects','products','ecm','technic','other' |
|
60
|
|
|
// It is used to group modules in module setup page |
|
61
|
|
|
$this->family = "projects"; |
|
62
|
|
|
$this->module_position = '20'; |
|
63
|
|
|
// Module label (no space allowed) |
|
64
|
|
|
// used if translation string 'ModuleXXXName' not found |
|
65
|
|
|
// (where XXX is value of numeric property 'numero' of module) |
|
66
|
|
|
$this->name = preg_replace('/^mod/i', '', get_only_class($this)); |
|
67
|
|
|
// Module description |
|
68
|
|
|
// used if translation string 'ModuleXXXDesc' not found |
|
69
|
|
|
// (where XXX is value of numeric property 'numero' of module) |
|
70
|
|
|
$this->description = "Manage resources (printers, cars, room, ...) you can then share into events"; |
|
71
|
|
|
// Possible values for version are: 'development', 'experimental' or version |
|
72
|
|
|
$this->version = 'dolibarr'; |
|
73
|
|
|
// Key used in llx_const table to save module status enabled/disabled |
|
74
|
|
|
// (where MYMODULE is value of property name of module in uppercase) |
|
75
|
|
|
$this->const_name = 'MAIN_MODULE_' . static::getNameOf($this->name); // strtoupper($this->name); |
|
76
|
|
|
// Name of image file used for this module. |
|
77
|
|
|
// If file is in theme/yourtheme/img directory under name object_pictovalue.png |
|
78
|
|
|
// use this->picto='pictovalue' |
|
79
|
|
|
// If file is in module/img directory under name object_pictovalue.png |
|
80
|
|
|
// use this->picto='pictovalue@module' |
|
81
|
|
|
$this->picto = 'resource'; // mypicto@resource |
|
82
|
|
|
// Defined all module parts (triggers, login, substitutions, menus, css, etc...) |
|
83
|
|
|
// for default path (eg: /resource/core/xxxxx) (0=disable, 1=enable) |
|
84
|
|
|
// for specific path of parts (eg: /resource/core/modules/barcode) |
|
85
|
|
|
// for specific css file (eg: /resource/css/resource.css.php) |
|
86
|
|
|
$this->module_parts = array(); |
|
87
|
|
|
|
|
88
|
|
|
// Data directories to create when module is enabled. |
|
89
|
|
|
// Example: this->dirs = array("/resource/temp"); |
|
90
|
|
|
//$this->dirs = array("/resource"); |
|
91
|
|
|
|
|
92
|
|
|
// Config pages. Put here list of php pages |
|
93
|
|
|
// stored into resource/admin directory, used to setup module. |
|
94
|
|
|
$this->config_page_url = array("resource.php"); |
|
95
|
|
|
|
|
96
|
|
|
// Dependencies |
|
97
|
|
|
// List of modules id that must be enabled if this module is enabled |
|
98
|
|
|
$this->depends = array(); |
|
99
|
|
|
// List of modules id to disable if this one is disabled |
|
100
|
|
|
$this->requiredby = array(''); |
|
101
|
|
|
// Minimum version of PHP required by module |
|
102
|
|
|
$this->phpmin = array(7, 0); |
|
103
|
|
|
|
|
104
|
|
|
$this->langfiles = array("resource"); // langfiles@resource |
|
105
|
|
|
// Constants |
|
106
|
|
|
// List of particular constants to add when module is enabled |
|
107
|
|
|
// (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive) |
|
108
|
|
|
// Example: |
|
109
|
|
|
$this->const = array(); |
|
110
|
|
|
|
|
111
|
|
|
// Array to add new pages in new tabs |
|
112
|
|
|
// Example: |
|
113
|
|
|
$this->tabs = array( |
|
114
|
|
|
// // To add a new tab identified by code tabname1 |
|
115
|
|
|
// 'objecttype:+tabname1:Title1:langfile@resource:$user->rights->resource->read:/resource/mynewtab1.php?id=__ID__', |
|
116
|
|
|
// // To add another new tab identified by code tabname2 |
|
117
|
|
|
// 'objecttype:+tabname2:Title2:langfile@resource:$user->rights->othermodule->read:/resource/mynewtab2.php?id=__ID__', |
|
118
|
|
|
// // To remove an existing tab identified by code tabname |
|
119
|
|
|
// 'objecttype:-tabname' |
|
120
|
|
|
); |
|
121
|
|
|
// where objecttype can be |
|
122
|
|
|
// 'thirdparty' to add a tab in third party view |
|
123
|
|
|
// 'intervention' to add a tab in intervention view |
|
124
|
|
|
// 'order_supplier' to add a tab in supplier order view |
|
125
|
|
|
// 'invoice_supplier' to add a tab in supplier invoice view |
|
126
|
|
|
// 'invoice' to add a tab in customer invoice view |
|
127
|
|
|
// 'order' to add a tab in sales order view |
|
128
|
|
|
// 'product' to add a tab in product view |
|
129
|
|
|
// 'stock' to add a tab in stock view |
|
130
|
|
|
// 'propal' to add a tab in propal view |
|
131
|
|
|
// 'member' to add a tab in foundation member view |
|
132
|
|
|
// 'contract' to add a tab in contract view |
|
133
|
|
|
// 'user' to add a tab in user view |
|
134
|
|
|
// 'group' to add a tab in group view |
|
135
|
|
|
// 'contact' to add a tab in contact view |
|
136
|
|
|
// 'categories_x' to add a tab in category view |
|
137
|
|
|
// (reresource 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member) |
|
138
|
|
|
|
|
139
|
|
|
// Boxes |
|
140
|
|
|
// Add here list of php file(s) stored in core/boxes that contains class to show a box. |
|
141
|
|
|
$this->boxes = array(); // Boxes list |
|
142
|
|
|
$r = 0; |
|
143
|
|
|
// Example: |
|
144
|
|
|
|
|
145
|
|
|
//$this->boxes[$r][1] = "MyBox@resource"; |
|
146
|
|
|
//$r ++; |
|
147
|
|
|
/* |
|
148
|
|
|
$this->boxes[$r][1] = "myboxb.php"; |
|
149
|
|
|
$r++; |
|
150
|
|
|
*/ |
|
151
|
|
|
|
|
152
|
|
|
// Permissions |
|
153
|
|
|
$this->rights = array(); // Permission array used by this module |
|
154
|
|
|
$r = 0; |
|
155
|
|
|
|
|
156
|
|
|
$this->rights[$r][0] = 63001; |
|
157
|
|
|
$this->rights[$r][1] = 'Read resources'; |
|
158
|
|
|
$this->rights[$r][3] = 0; |
|
159
|
|
|
$this->rights[$r][4] = 'read'; |
|
160
|
|
|
$r++; |
|
161
|
|
|
|
|
162
|
|
|
$this->rights[$r][0] = 63002; |
|
163
|
|
|
$this->rights[$r][1] = 'Create/Modify resources'; |
|
164
|
|
|
$this->rights[$r][3] = 0; |
|
165
|
|
|
$this->rights[$r][4] = 'write'; |
|
166
|
|
|
$r++; |
|
167
|
|
|
|
|
168
|
|
|
$this->rights[$r][0] = 63003; |
|
169
|
|
|
$this->rights[$r][1] = 'Delete resources'; |
|
170
|
|
|
$this->rights[$r][3] = 0; |
|
171
|
|
|
$this->rights[$r][4] = 'delete'; |
|
172
|
|
|
$r++; |
|
173
|
|
|
|
|
174
|
|
|
$this->rights[$r][0] = 63004; |
|
175
|
|
|
$this->rights[$r][1] = 'Link resources to agenda events'; |
|
176
|
|
|
$this->rights[$r][3] = 0; |
|
177
|
|
|
$this->rights[$r][4] = 'link'; |
|
178
|
|
|
$r++; |
|
179
|
|
|
|
|
180
|
|
|
|
|
181
|
|
|
// Menus |
|
182
|
|
|
//------- |
|
183
|
|
|
$this->menu = 1; // This module add menu entries. They are coded into menu manager. |
|
184
|
|
|
|
|
185
|
|
|
|
|
186
|
|
|
// Main menu entries |
|
187
|
|
|
$this->menu = array(); // List of menus to add |
|
188
|
|
|
$r = 0; |
|
189
|
|
|
|
|
190
|
|
|
// Menus declaration |
|
191
|
|
|
$this->menu[$r] = array( |
|
192
|
|
|
'fk_menu' => 'fk_mainmenu=agenda', |
|
193
|
|
|
'type' => 'left', |
|
194
|
|
|
'titre' => 'MenuResourceIndex', |
|
195
|
|
|
'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth em92"'), |
|
196
|
|
|
'mainmenu' => 'agenda', |
|
197
|
|
|
'leftmenu' => 'resource', |
|
198
|
|
|
'url' => '/resource/list.php', |
|
199
|
|
|
'langs' => 'resource', |
|
200
|
|
|
'position' => 100, |
|
201
|
|
|
'enabled' => '1', |
|
202
|
|
|
'perms' => '$user->rights->resource->read', |
|
203
|
|
|
'user' => 0 |
|
204
|
|
|
); |
|
205
|
|
|
$r++; |
|
206
|
|
|
|
|
207
|
|
|
$this->menu[$r++] = array( |
|
208
|
|
|
'fk_menu' => 'fk_mainmenu=agenda,fk_leftmenu=resource', //On utilise les ancres définis dans le menu parent déclaré au dessus |
|
209
|
|
|
'type' => 'left', // Toujours un menu gauche |
|
210
|
|
|
'titre' => 'MenuResourceAdd', |
|
211
|
|
|
'mainmenu' => 'agenda', |
|
212
|
|
|
'leftmenu' => 'resource_add', |
|
213
|
|
|
'url' => '/resource/card.php?action=create', |
|
214
|
|
|
'langs' => 'resource', |
|
215
|
|
|
'position' => 101, |
|
216
|
|
|
'enabled' => '1', |
|
217
|
|
|
'perms' => '$user->rights->resource->write', |
|
218
|
|
|
'target' => '', |
|
219
|
|
|
'user' => 0 |
|
220
|
|
|
); |
|
221
|
|
|
|
|
222
|
|
|
$this->menu[$r++] = array( |
|
223
|
|
|
'fk_menu' => 'fk_mainmenu=agenda,fk_leftmenu=resource', //On utilise les ancres définis dans le menu parent déclaré au dessus |
|
224
|
|
|
'type' => 'left', // Toujours un menu gauche |
|
225
|
|
|
'titre' => 'List', |
|
226
|
|
|
'mainmenu' => 'agenda', |
|
227
|
|
|
'leftmenu' => 'resource_list', |
|
228
|
|
|
'url' => '/resource/list.php', |
|
229
|
|
|
'langs' => 'resource', |
|
230
|
|
|
'position' => 102, |
|
231
|
|
|
'enabled' => '1', |
|
232
|
|
|
'perms' => '$user->rights->resource->read', |
|
233
|
|
|
'target' => '', |
|
234
|
|
|
'user' => 0 |
|
235
|
|
|
); |
|
236
|
|
|
|
|
237
|
|
|
|
|
238
|
|
|
// Exports |
|
239
|
|
|
//-------- |
|
240
|
|
|
$r = 0; |
|
241
|
|
|
|
|
242
|
|
|
$r++; |
|
243
|
|
|
$this->export_code[$r] = $this->rights_class . '_' . $r; |
|
244
|
|
|
$this->export_label[$r] = "ResourceSingular"; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
245
|
|
|
$this->export_permission[$r] = array(array("resource", "read")); |
|
246
|
|
|
|
|
247
|
|
|
$this->export_fields_array[$r] = array('r.rowid' => 'IdResource', 'r.ref' => 'ResourceFormLabel_ref', 'c.rowid' => 'ResourceTypeID', 'c.code' => 'ResourceTypeCode', 'c.label' => 'ResourceTypeLabel', 'r.description' => 'ResourceFormLabel_description', 'r.note_private' => "NotePrivate", 'r.note_public' => "NotePublic", 'r.asset_number' => 'AssetNumber', 'r.datec' => "DateCreation", 'r.tms' => "DateLastModification"); |
|
248
|
|
|
$this->export_TypeFields_array[$r] = array('r.rowid' => 'List:resource:ref', 'r.ref' => 'Text', 'r.asset_number' => 'Text', 'r.description' => 'Text', 'c.rowid' => 'List:c_type_resource:label', 'c.code' => 'Text', 'c.label' => 'Text', 'r.datec' => 'Date', 'r.tms' => 'Date', 'r.note_private' => 'Text', 'r.note_public' => 'Text'); |
|
249
|
|
|
$this->export_entities_array[$r] = array('r.rowid' => 'resource', 'r.ref' => 'resource', 'c.rowid' => 'resource', 'c.code' => 'resource', 'c.label' => 'resource', 'r.description' => 'resource', 'r.note_private' => "resource", 'r.resource' => "resource", 'r.asset_number' => 'resource', 'r.datec' => "resource", 'r.tms' => "resource"); |
|
250
|
|
|
|
|
251
|
|
|
$keyforselect = 'resource'; |
|
252
|
|
|
$keyforelement = 'resource'; |
|
253
|
|
|
$keyforaliasextra = 'extra'; |
|
254
|
|
|
|
|
255
|
|
|
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php'; |
|
256
|
|
|
|
|
257
|
|
|
$this->export_dependencies_array[$r] = array('resource' => array('r.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them. |
|
258
|
|
|
$this->export_sql_start[$r] = 'SELECT DISTINCT '; |
|
259
|
|
|
$this->export_sql_end[$r] = ' FROM ' . MAIN_DB_PREFIX . 'resource as r'; |
|
260
|
|
|
$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_type_resource as c ON c.code = r.fk_code_type_resource'; |
|
261
|
|
|
$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'resource_extrafields as extra ON extra.fk_object = r.rowid'; |
|
262
|
|
|
$this->export_sql_end[$r] .= ' WHERE r.entity IN (' . getEntity('resource') . ')'; |
|
263
|
|
|
|
|
264
|
|
|
|
|
265
|
|
|
// Imports |
|
266
|
|
|
//-------- |
|
267
|
|
|
$r = 0; |
|
268
|
|
|
|
|
269
|
|
|
// Import list of third parties and attributes |
|
270
|
|
|
$r++; |
|
271
|
|
|
$this->import_code[$r] = $this->rights_class . '_' . $r; |
|
272
|
|
|
$this->import_label[$r] = 'ImportDataset_resource_1'; |
|
273
|
|
|
$this->import_icon[$r] = 'resource'; |
|
274
|
|
|
$this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon |
|
275
|
|
|
$this->import_tables_array[$r] = array('r' => MAIN_DB_PREFIX . 'resource', 'extra' => MAIN_DB_PREFIX . 'resource_extrafields'); // List of tables to insert into (insert done in same order) |
|
276
|
|
|
$this->import_fields_array[$r] = array('r.ref' => "ResourceFormLabel_ref*", 'r.fk_code_type_resource' => 'ResourceTypeCode', 'r.description' => 'ResourceFormLabel_description', 'r.note_private' => "NotePrivate", 'r.note_public' => "NotePublic", 'r.asset_number' => 'AssetNumber', 'r.datec' => 'DateCreation'); |
|
277
|
|
|
// Add extra fields |
|
278
|
|
|
$sql = "SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . "extrafields WHERE type <> 'separate' AND elementtype = 'resource' AND entity IN (0," . $conf->entity . ")"; |
|
279
|
|
|
$resql = $this->db->query($sql); |
|
280
|
|
|
if ($resql) { // This can fail when class is used on old database (during migration for example) |
|
281
|
|
|
while ($obj = $this->db->fetch_object($resql)) { |
|
282
|
|
|
$fieldname = 'extra.' . $obj->name; |
|
283
|
|
|
$fieldlabel = ucfirst($obj->label); |
|
284
|
|
|
$this->import_fields_array[$r][$fieldname] = $fieldlabel . ($obj->fieldrequired ? '*' : ''); |
|
285
|
|
|
} |
|
286
|
|
|
} |
|
287
|
|
|
// End add extra fields |
|
288
|
|
|
$this->import_fieldshidden_array[$r] = array('r.fk_user_author' => 'user->id', 'extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'resource'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) |
|
289
|
|
|
$this->import_convertvalue_array[$r] = array( |
|
290
|
|
|
'r.fk_code_type_resource' => array('rule' => 'fetchidfromcodeorlabel', 'classfile' => '/core/class/ctyperesource.class.php', 'class' => 'Ctyperesource', 'method' => 'fetch', 'dict' => 'DictionaryResourceType'), |
|
291
|
|
|
); |
|
292
|
|
|
//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t'); |
|
293
|
|
|
$this->import_regex_array[$r] = array('s.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$'); |
|
294
|
|
|
$this->import_examplevalues_array[$r] = array('r.ref' => "REF1", 'r.fk_code_type_resource' => "Code from dictionary resource type", 'r.datec' => "2017-01-01 or 2017-01-01 12:30:00"); |
|
295
|
|
|
$this->import_updatekeys_array[$r] = array('r.rf' => 'ResourceFormLabel_ref'); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* Function called when module is enabled. |
|
300
|
|
|
* The init function add constants, boxes, permissions and menus |
|
301
|
|
|
* (defined in constructor) into Dolibarr database. |
|
302
|
|
|
* It also creates data directories |
|
303
|
|
|
* |
|
304
|
|
|
* @param string $options Options when enabling module ('', 'noboxes') |
|
305
|
|
|
* @return int 1 if OK, 0 if KO |
|
306
|
|
|
*/ |
|
307
|
|
|
public function init($options = '') |
|
308
|
|
|
{ |
|
309
|
|
|
$sql = array(); |
|
310
|
|
|
|
|
311
|
|
|
return $this->_init($sql, $options); |
|
312
|
|
|
} |
|
313
|
|
|
} |
|
314
|
|
|
|