dolibarr  7.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  *
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  // Where to store the module in setup page
73  // (0=common,1=interface,2=others,3=very specific)
74  $this->special = 2;
75  // Name of image file used for this module.
76  // If file is in theme/yourtheme/img directory under name object_pictovalue.png
77  // use this->picto='pictovalue'
78  // If file is in module/img directory under name object_pictovalue.png
79  // use this->picto='pictovalue@module'
80  $this->picto = 'resource'; // mypicto@resource
81  // Defined all module parts (triggers, login, substitutions, menus, css, etc...)
82  // for default path (eg: /resource/core/xxxxx) (0=disable, 1=enable)
83  // for specific path of parts (eg: /resource/core/modules/barcode)
84  // for specific css file (eg: /resource/css/resource.css.php)
85  $this->module_parts = array(
86  // Set this to 1 if module has its own trigger directory
87  //'triggers' => 1,
88  // Set this to 1 if module has its own login method directory
89  //'login' => 0,
90  // Set this to 1 if module has its own substitution function file
91  //'substitutions' => 0,
92  // Set this to 1 if module has its own menus handler directory
93  //'menus' => 0,
94  // Set this to 1 if module has its own barcode directory
95  //'barcode' => 0,
96  // Set this to 1 if module has its own models directory
97  //'models' => 0,
98  // Set this to relative path of css if module has its own css file
99  //'css' => '/resource/css/resource.css.php',
100  // Set here all hooks context managed by module
101  // 'hooks' => array('actioncard','actioncommdao','resource_card','element_resource')
102  // Set here all workflow context managed by module
103  //'workflow' => array('order' => array('WORKFLOW_ORDER_AUTOCREATE_INVOICE'))
104  );
105 
106  // Data directories to create when module is enabled.
107  // Example: this->dirs = array("/resource/temp");
108  //$this->dirs = array("/resource");
109 
110  // Config pages. Put here list of php pages
111  // stored into resource/admin directory, used to setup module.
112  $this->config_page_url = array("resource.php");
113 
114  // Dependencies
115  // List of modules id that must be enabled if this module is enabled
116  $this->depends = array();
117  // List of modules id to disable if this one is disabled
118  $this->requiredby = array('modPlace');
119  // Minimum version of PHP required by module
120  $this->phpmin = array(5, 3);
121 
122  $this->langfiles = array("resource"); // langfiles@resource
123  // Constants
124  // List of particular constants to add when module is enabled
125  // (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
126  // Example:
127  $this->const = array();
128 
129  // Array to add new pages in new tabs
130  // Example:
131  $this->tabs = array(
132  // // To add a new tab identified by code tabname1
133  // 'objecttype:+tabname1:Title1:langfile@resource:$user->rights->resource->read:/resource/mynewtab1.php?id=__ID__',
134  // // To add another new tab identified by code tabname2
135  // 'objecttype:+tabname2:Title2:langfile@resource:$user->rights->othermodule->read:/resource/mynewtab2.php?id=__ID__',
136  // // To remove an existing tab identified by code tabname
137  // 'objecttype:-tabname'
138  );
139  // where objecttype can be
140  // 'thirdparty' to add a tab in third party view
141  // 'intervention' to add a tab in intervention view
142  // 'order_supplier' to add a tab in supplier order view
143  // 'invoice_supplier' to add a tab in supplier invoice view
144  // 'invoice' to add a tab in customer invoice view
145  // 'order' to add a tab in customer order view
146  // 'product' to add a tab in product view
147  // 'stock' to add a tab in stock view
148  // 'propal' to add a tab in propal view
149  // 'member' to add a tab in fundation member view
150  // 'contract' to add a tab in contract view
151  // 'user' to add a tab in user view
152  // 'group' to add a tab in group view
153  // 'contact' to add a tab in contact view
154  // 'categories_x' to add a tab in category view
155  // (reresource 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
156 
157  // Boxes
158  // Add here list of php file(s) stored in core/boxes that contains class to show a box.
159  $this->boxes = array(); // Boxes list
160  $r = 0;
161  // Example:
162 
163  //$this->boxes[$r][1] = "MyBox@resource";
164  //$r ++;
165  /*
166  $this->boxes[$r][1] = "myboxb.php";
167  $r++;
168  */
169 
170  // Permissions
171  $this->rights = array(); // Permission array used by this module
172  $r = 0;
173 
174  $this->rights[$r][0] = 63001;
175  $this->rights[$r][1] = 'Read resources';
176  $this->rights[$r][3] = 0;
177  $this->rights[$r][4] = 'read';
178  $r++;
179 
180  $this->rights[$r][0] = 63002;
181  $this->rights[$r][1] = 'Create/Modify resources';
182  $this->rights[$r][3] = 0;
183  $this->rights[$r][4] = 'write';
184  $r++;
185 
186  $this->rights[$r][0] = 63003;
187  $this->rights[$r][1] = 'Delete resources';
188  $this->rights[$r][3] = 0;
189  $this->rights[$r][4] = 'delete';
190  $r++;
191 
192  $this->rights[$r][0] = 63004;
193  $this->rights[$r][1] = 'Link resources to agenda events';
194  $this->rights[$r][3] = 0;
195  $this->rights[$r][4] = 'link';
196  $r++;
197 
198 
199  // Menus
200  //-------
201  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
202 
203 
204  // Main menu entries
205  $this->menu = array(); // List of menus to add
206  $r = 0;
207 
208  // Menus declaration
209  $this->menu[$r]=array(
210  'fk_menu'=>'fk_mainmenu=tools',
211  'type'=>'left',
212  'titre'=> 'MenuResourceIndex',
213  'mainmenu'=>'tools',
214  'leftmenu'=> 'resource',
215  'url'=> '/resource/list.php',
216  'langs'=> 'resource',
217  'position'=> 100,
218  'enabled'=> '1',
219  'perms'=> '$user->rights->resource->read',
220  'user'=> 0
221  );
222  $r++;
223 
224  $this->menu[$r++]=array(
225  'fk_menu'=>'fk_mainmenu=tools,fk_leftmenu=resource', //On utilise les ancres définis dans le menu parent déclaré au dessus
226  'type'=> 'left', // Toujours un menu gauche
227  'titre'=> 'MenuResourceAdd',
228  'mainmenu'=> 'tools',
229  'leftmenu'=> 'resource_add',
230  'url'=> '/resource/card.php?action=create',
231  'langs'=> 'resource',
232  'position'=> 101,
233  'enabled'=> '1',
234  'perms'=> '$user->rights->resource->read',
235  'target'=> '',
236  'user'=> 0
237  );
238 
239  $this->menu[$r++]=array(
240  'fk_menu'=>'fk_mainmenu=tools,fk_leftmenu=resource', //On utilise les ancres définis dans le menu parent déclaré au dessus
241  'type'=> 'left', // Toujours un menu gauche
242  'titre'=> 'List',
243  'mainmenu'=> 'tools',
244  'leftmenu'=> 'resource_list',
245  'url'=> '/resource/list.php',
246  'langs'=> 'resource',
247  'position'=> 102,
248  'enabled'=> '1',
249  'perms'=> '$user->rights->resource->read',
250  'target'=> '',
251  'user'=> 0
252  );
253 
254 
255  // Exports
256  //--------
257  $r=0;
258 
259  $r++;
260  $this->export_code[$r]=$this->rights_class.'_'.$r;
261  $this->export_label[$r]="ResourceSingular"; // Translation key (used only if key ExportDataset_xxx_z not found)
262  $this->export_permission[$r]=array(array("resource","read"));
263  $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");
264  $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');
265  $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");
266  $keyforselect='resource'; $keyforelement='resource'; $keyforaliasextra='extra';
267  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
268 
269  $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.
270  $this->export_sql_start[$r]='SELECT DISTINCT ';
271  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'resource as r ';
272  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_resource as c ON c.rowid=r.fk_code_type_resource';
273  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'resource_extrafields as extra ON extra.fk_object = c.rowid';
274  $this->export_sql_end[$r] .=' AND r.entity IN ('.getEntity('resource').')';
275 
276 
277  // Imports
278  //--------
279  $r=0;
280 
281  // Import list of third parties and attributes
282  $r++;
283  $this->import_code[$r]=$this->rights_class.'_'.$r;
284  $this->import_label[$r]='ImportDataset_resource_1';
285  $this->import_icon[$r]='resource';
286  $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
287  $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)
288  $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');
289  // Add extra fields
290  $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'resource' AND entity = ".$conf->entity;
291  $resql=$this->db->query($sql);
292  if ($resql) // This can fail when class is used on old database (during migration for example)
293  {
294  while ($obj=$this->db->fetch_object($resql))
295  {
296  $fieldname='extra.'.$obj->name;
297  $fieldlabel=ucfirst($obj->label);
298  $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
299  }
300  }
301  // End add extra fields
302  $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)
303  $this->import_convertvalue_array[$r]=array(
304  'r.fk_code_type_resource'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/core/class/ctyperesource.class.php','class'=>'Ctyperesource','method'=>'fetch','dict'=>'DictionaryResourceType'),
305  );
306  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
307  $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])?$');
308  $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");
309  $this->import_updatekeys_array[$r]=array('r.rf'=>'ResourceFormLabel_ref');
310 
311  }
312 
322  public function init($options = '')
323  {
324  $sql = array();
325 
326  $result = $this->loadTables();
327 
328  return $this->_init($sql, $options);
329  }
330 
339  private function loadTables()
340  {
341  return $this->_load_tables('/resource/sql/');
342  }
343 }
Class DolibarrModules.
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="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< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:554
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.
Description and activation class for module Resource.
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:104
__construct($db)
Constructor.
_init($array_sql, $options='')
Enables a module.
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:1013
_load_tables($reldir)
Create tables and keys required by module.