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