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