dolibarr 24.0.0-beta
modResource.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2014 Jean-François Ferry <jfefe@aternatik.fr>
3 * Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
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
30include_once DOL_DOCUMENT_ROOT."/core/modules/DolibarrModules.class.php";
31
32
37{
43 public function __construct($db)
44 {
45 global $langs, $conf; // $langs may be used by the tpl files.
46
47 $this->db = $db;
48
49 // Id for module (must be unique).
50 // Use a free id here
51 // (See in Home -> System information -> Dolibarr for list of used modules id).
52 $this->numero = 63000;
53
54 // Key text used to identify module (for permissions, menus, etc...)
55 $this->rights_class = 'resource';
56
57 // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
58 // It is used to group modules in module setup page
59 $this->family = "projects";
60 $this->module_position = '20';
61 // Module label (no space allowed)
62 // used if translation string 'ModuleXXXName' not found
63 // (where XXX is value of numeric property 'numero' of module)
64 $this->name = preg_replace('/^mod/i', '', get_class($this));
65 // Module description
66 // used if translation string 'ModuleXXXDesc' not found
67 // (where XXX is value of numeric property 'numero' of module)
68 $this->description = "Manage resources (printers, cars, room, ...) you can then share into events";
69 // Possible values for version are: 'development', 'experimental' or version
70 $this->version = 'dolibarr';
71 // Key used in llx_const table to save module status enabled/disabled
72 // (where MYMODULE is value of property name of module in uppercase)
73 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
74 // Name of image file used for this module.
75 // If file is in theme/yourtheme/img directory under name object_pictovalue.png
76 // use this->picto='pictovalue'
77 // If file is in module/img directory under name object_pictovalue.png
78 // use this->picto='pictovalue@module'
79 $this->picto = 'resource'; // mypicto@resource
80 // Defined all module parts (triggers, login, substitutions, menus, css, etc...)
81 // for default path (eg: /resource/core/xxxxx) (0=disable, 1=enable)
82 // for specific path of parts (eg: /resource/core/modules/barcode)
83 // for specific css file (eg: /resource/css/resource.css.php)
84 $this->module_parts = array();
85
86 // Data directories to create when module is enabled.
87 // Example: this->dirs = array("/resource/temp");
88 //$this->dirs = array("/resource");
89
90 // Config pages. Put here list of php pages
91 // stored into resource/admin directory, used to setup module.
92 $this->config_page_url = array("resource.php");
93
94 // Dependencies
95 // List of modules id that must be enabled if this module is enabled
96 $this->depends = array();
97 // List of modules id to disable if this one is disabled
98 $this->requiredby = array('');
99 // Minimum version of PHP required by module
100 $this->phpmin = array(7, 0);
101
102 $this->langfiles = array("resource"); // langfiles@resource
103 // Constants
104 // List of particular constants to add when module is enabled
105 // (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
106 // Example:
107 $this->const = array();
108
109 // Array to add new pages in new tabs
110 // Example:
111 $this->tabs = array(
112 // // To add a new tab identified by code tabname1
113 // 'objecttype:+tabname1:Title1:langfile@resource:$user->rights->resource->read:/resource/mynewtab1.php?id=__ID__',
114 // // To add another new tab identified by code tabname2
115 // 'objecttype:+tabname2:Title2:langfile@resource:$user->rights->othermodule->read:/resource/mynewtab2.php?id=__ID__',
116 // // To remove an existing tab identified by code tabname
117 // 'objecttype:-tabname'
118 );
119 // where objecttype can be
120 // 'thirdparty' to add a tab in third party view
121 // 'intervention' to add a tab in intervention view
122 // 'order_supplier' to add a tab in supplier order view
123 // 'invoice_supplier' to add a tab in supplier invoice view
124 // 'invoice' to add a tab in customer invoice view
125 // 'order' to add a tab in sales order view
126 // 'product' to add a tab in product view
127 // 'stock' to add a tab in stock view
128 // 'propal' to add a tab in propal view
129 // 'member' to add a tab in foundation member view
130 // 'contract' to add a tab in contract view
131 // 'user' to add a tab in user view
132 // 'group' to add a tab in group view
133 // 'contact' to add a tab in contact view
134 // 'categories_x' to add a tab in category view
135 // (reresource 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
136
137 // Boxes
138 // Add here list of php file(s) stored in core/boxes that contains class to show a box.
139 $this->boxes = array(); // Boxes list
140 $r = 0;
141 // Example:
142
143 //$this->boxes[$r][1] = "MyBox@resource";
144 //$r ++;
145 /*
146 $this->boxes[$r][1] = "myboxb.php";
147 $r++;
148 */
149
150 // Permissions
151 $this->rights = array(); // Permission array used by this module
152 $r = 0;
153
154 $this->rights[$r][0] = 63001;
155 $this->rights[$r][1] = 'Read resources';
156 $this->rights[$r][3] = 0;
157 $this->rights[$r][4] = 'read';
158 $r++;
159
160 $this->rights[$r][0] = 63002;
161 $this->rights[$r][1] = 'Create/Modify resources';
162 $this->rights[$r][3] = 0;
163 $this->rights[$r][4] = 'write';
164 $r++;
165
166 $this->rights[$r][0] = 63003;
167 $this->rights[$r][1] = 'Delete resources';
168 $this->rights[$r][3] = 0;
169 $this->rights[$r][4] = 'delete';
170 $r++;
171
172 $this->rights[$r][0] = 63004;
173 $this->rights[$r][1] = 'Link resources to agenda events';
174 $this->rights[$r][3] = 0;
175 $this->rights[$r][4] = 'link';
176 $r++;
177
178
179 // Menus
180 //-------
181 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
182
183
184 // Main menu entries
185 $this->menu = array(); // List of menus to add
186 $r = 0;
187
188 // Menus declaration
189 $this->menu[$r] = array(
190 'fk_menu' => 'fk_mainmenu=agenda',
191 'type' => 'left',
192 'titre' => 'MenuResourceIndex',
193 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth em92"'),
194 'mainmenu' => 'agenda',
195 'leftmenu' => 'resource',
196 'url' => '/resource/list.php',
197 'langs' => 'resource',
198 'position' => 100,
199 'enabled' => '1',
200 'perms' => '$user->hasRight("resource", "read")',
201 'user' => 0
202 );
203 $r++;
204
205 $this->menu[$r++] = array(
206 'fk_menu' => 'fk_mainmenu=agenda,fk_leftmenu=resource', // Uses anchors defined in the parent menu declared above
207 'type' => 'left', // Toujours un menu gauche
208 'titre' => 'MenuResourceAdd',
209 'mainmenu' => 'agenda',
210 'leftmenu' => 'resource_add',
211 'url' => '/resource/card.php?action=create',
212 'langs' => 'resource',
213 'position' => 101,
214 'enabled' => '1',
215 'perms' => '$user->hasRight("resource", "write")',
216 'target' => '',
217 'user' => 0
218 );
219
220 $this->menu[$r++] = array(
221 'fk_menu' => 'fk_mainmenu=agenda,fk_leftmenu=resource', // Uses anchors defined in the parent menu declared above
222 'type' => 'left', // Toujours un menu gauche
223 'titre' => 'List',
224 'mainmenu' => 'agenda',
225 'leftmenu' => 'resource_list',
226 'url' => '/resource/list.php',
227 'langs' => 'resource',
228 'position' => 102,
229 'enabled' => '1',
230 'perms' => '$user->hasRight("resource", "read")',
231 'target' => '',
232 'user' => 0
233 );
234
235
236 // Exports
237 //--------
238 $r = 0;
239
240 $r++;
241 $this->export_code[$r] = $this->rights_class.'_'.$r;
242 $this->export_label[$r] = "ResourceSingular"; // Translation key (used only if key ExportDataset_xxx_z not found)
243 $this->export_permission[$r] = array(array("resource", "read"));
244
245 $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");
246 $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');
247 $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");
248
249 $keyforselect = 'resource';
250 $keyforelement = 'resource';
251 $keyforaliasextra = 'extra';
252
253 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
254
255 $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.
256 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
257 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'resource as r';
258 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_resource as c ON c.code = r.fk_code_type_resource';
259 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'resource_extrafields as extra ON extra.fk_object = r.rowid';
260 $this->export_sql_end[$r] .= ' WHERE r.entity IN ('.getEntity('resource').')';
261
262
263
264 // Imports
265 //--------
266 $r = 0;
267
268 // Import list of third parties and attributes
269 $r++;
270 $this->import_code[$r] = $this->rights_class.'_'.$r;
271 $this->import_label[$r] = 'ImportDataset_resource_1';
272 $this->import_icon[$r] = 'resource';
273 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
274 $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)
275 $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');
276 // Add extra fields
277 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'resource' AND entity IN (0,".$conf->entity.")";
278 $resql = $this->db->query($sql);
279 if ($resql) { // This can fail when class is used on old database (during migration for example)
280 while ($obj = $this->db->fetch_object($resql)) {
281 $fieldname = 'extra.'.$obj->name;
282 $fieldlabel = ucfirst($obj->label);
283 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
284 }
285 }
286 // End add extra fields
287 $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)
288 $this->import_convertvalue_array[$r] = array(
289 'r.fk_code_type_resource' => array('rule' => 'fetchidfromcodeorlabel', 'classfile' => '/core/class/ctyperesource.class.php', 'class' => 'Ctyperesource', 'method' => 'fetch', 'dict' => 'DictionaryResourceType'),
290 );
291 //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
292 $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])?$');
293 $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");
294 $this->import_updatekeys_array[$r] = array('r.rf' => 'ResourceFormLabel_ref');
295 }
296
306 public function init($options = '')
307 {
308 $sql = array();
309
310 return $this->_init($sql, $options);
311 }
312}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Description and activation class for module Resource.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133