dolibarr  9.0.0
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 <http://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(5, 4);
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 customer 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=tools',
189  'type'=>'left',
190  'titre'=> 'MenuResourceIndex',
191  'mainmenu'=>'tools',
192  'leftmenu'=> 'resource',
193  'url'=> '/resource/list.php',
194  'langs'=> 'resource',
195  'position'=> 100,
196  'enabled'=> '1',
197  'perms'=> '$user->rights->resource->read',
198  'user'=> 0
199  );
200  $r++;
201 
202  $this->menu[$r++]=array(
203  'fk_menu'=>'fk_mainmenu=tools,fk_leftmenu=resource', //On utilise les ancres définis dans le menu parent déclaré au dessus
204  'type'=> 'left', // Toujours un menu gauche
205  'titre'=> 'MenuResourceAdd',
206  'mainmenu'=> 'tools',
207  'leftmenu'=> 'resource_add',
208  'url'=> '/resource/card.php?action=create',
209  'langs'=> 'resource',
210  'position'=> 101,
211  'enabled'=> '1',
212  'perms'=> '$user->rights->resource->write',
213  'target'=> '',
214  'user'=> 0
215  );
216 
217  $this->menu[$r++]=array(
218  'fk_menu'=>'fk_mainmenu=tools,fk_leftmenu=resource', //On utilise les ancres définis dans le menu parent déclaré au dessus
219  'type'=> 'left', // Toujours un menu gauche
220  'titre'=> 'List',
221  'mainmenu'=> 'tools',
222  'leftmenu'=> 'resource_list',
223  'url'=> '/resource/list.php',
224  'langs'=> 'resource',
225  'position'=> 102,
226  'enabled'=> '1',
227  'perms'=> '$user->rights->resource->read',
228  'target'=> '',
229  'user'=> 0
230  );
231 
232 
233  // Exports
234  //--------
235  $r=0;
236 
237  $r++;
238  $this->export_code[$r]=$this->rights_class.'_'.$r;
239  $this->export_label[$r]="ResourceSingular"; // Translation key (used only if key ExportDataset_xxx_z not found)
240  $this->export_permission[$r]=array(array("resource","read"));
241  $this->export_fields_array[$r]=array('r.rowid'=>'IdResource','r.ref'=>'ResourceFormLabel_ref','c.code'=>'ResourceTypeCode','c.label'=>'ResourceType','r.description'=>'ResourceFormLabel_description','r.note_private'=>"NotePrivate",'r.note_public'=>"NotePublic",'r.asset_number'=>'AssetNumber','r.datec'=>"DateCreation",'r.tms'=>"DateLastModification");
242  $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');
243  $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");
244  $keyforselect='resource'; $keyforelement='resource'; $keyforaliasextra='extra';
245  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
246 
247  $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.
248  $this->export_sql_start[$r]='SELECT DISTINCT ';
249  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'resource as r ';
250  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_resource as c ON c.rowid=r.fk_code_type_resource';
251  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'resource_extrafields as extra ON extra.fk_object = c.rowid';
252  $this->export_sql_end[$r] .=' AND r.entity IN ('.getEntity('resource').')';
253 
254 
255  // Imports
256  //--------
257  $r=0;
258 
259  // Import list of third parties and attributes
260  $r++;
261  $this->import_code[$r]=$this->rights_class.'_'.$r;
262  $this->import_label[$r]='ImportDataset_resource_1';
263  $this->import_icon[$r]='resource';
264  $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
265  $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)
266  $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');
267  // Add extra fields
268  $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'resource' AND entity IN (0,".$conf->entity.")";
269  $resql=$this->db->query($sql);
270  if ($resql) // This can fail when class is used on old database (during migration for example)
271  {
272  while ($obj=$this->db->fetch_object($resql))
273  {
274  $fieldname='extra.'.$obj->name;
275  $fieldlabel=ucfirst($obj->label);
276  $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
277  }
278  }
279  // End add extra fields
280  $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)
281  $this->import_convertvalue_array[$r]=array(
282  'r.fk_code_type_resource'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/core/class/ctyperesource.class.php','class'=>'Ctyperesource','method'=>'fetch','dict'=>'DictionaryResourceType'),
283  );
284  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
285  $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])?$');
286  $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");
287  $this->import_updatekeys_array[$r]=array('r.rf'=>'ResourceFormLabel_ref');
288  }
289 
299  public function init($options = '')
300  {
301  $sql = array();
302 
303  $result = $this->loadTables();
304 
305  return $this->_init($sql, $options);
306  }
307 
316  private function loadTables()
317  {
318  return $this->_load_tables('/resource/sql/');
319  }
320 }
Class DolibarrModules.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
loadTables()
Create tables, keys and data required by module Files llx_table1.sql, llx_table1.key.sql llx_data.sql with create table, create keys and create data commands must be stored in directory /resource/sql/ This function is called by this->init.
init($options='')
Function called when module is enabled.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
Description and activation class for module Resource.
__construct($db)
Constructor.
_init($array_sql, $options='')
Enables a module.
_load_tables($reldir)
Create tables and keys required by module.