dolibarr  17.0.2
modAsset.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
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 
27 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
28 
29 
34 {
40  public function __construct($db)
41  {
42  global $langs, $conf;
43 
44  $this->db = $db;
45 
46  // Id for module (must be unique).
47  // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
48  $this->numero = 51000; // TODO Go on page https://wiki.dolibarr.org/index.php/List_of_modules_id to reserve id number for your module
49 
50  // Family can be 'crm','financial','hr','projects','products','ecm','technic','interface','other'
51  // It is used to group modules by family in module setup page
52  $this->family = "financial";
53  // Module position in the family on 2 digits ('01', '10', '20', ...)
54  $this->module_position = '70';
55  // Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
56  //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
57 
58  // Module label (no space allowed), used if translation string 'ModuleAssetsName' not found (MyModue is name of module).
59  $this->name = preg_replace('/^mod/i', '', get_class($this));
60  // Module description, used if translation string 'ModuleAssetsDesc' not found (MyModue is name of module).
61  $this->description = "Asset module";
62  // Used only if file README.md and README-LL.md not found.
63  $this->descriptionlong = "Asset module to manage assets module and depreciation charge on Dolibarr";
64 
65  // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
66  $this->version = 'development';
67  // Key used in llx_const table to save module status enabled/disabled (where ASSETS is value of property name of module in uppercase)
68  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
69  // Name of image file used for this module.
70  // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
71  // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
72  $this->picto = 'asset';
73 
74  // Defined all module parts (triggers, login, substitutions, menus, css, etc...)
75  // for default path (eg: /asset/core/xxxxx) (0=disable, 1=enable)
76  // for specific path of parts (eg: /asset/core/modules/barcode)
77  // for specific css file (eg: /asset/css/assets.css.php)
78  $this->module_parts = array();
79 
80  // Data directories to create when module is enabled.
81  // Example: this->dirs = array("/asset/temp","/asset/subdir");
82  $this->dirs = array("/asset/temp");
83 
84  // Config pages. Put here list of php page, stored into asset/admin directory, to use to setup module.
85  $this->config_page_url = array("setup.php@asset");
86 
87  // Dependencies
88  $this->hidden = false; // A condition to hide module
89  $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
90  $this->requiredby = array(); // List of module ids to disable if this one is disabled
91  $this->conflictwith = array(); // List of module class names as string this module is in conflict with
92  $this->langfiles = array("assets");
93  $this->phpmin = array(7, 0); // Minimum version of PHP required by module
94  $this->need_dolibarr_version = array(7, 0); // Minimum version of Dolibarr required by module
95  $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
96  $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
97  //$this->automatic_activation = array('FR'=>'AssetsWasAutomaticallyActivatedBecauseOfYourCountryChoice');
98  //$this->always_enabled = true; // If true, can't be disabled
99 
100  // Constants
101  // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
102  // Example: $this->const=array(0=>array('ASSETS_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
103  // 1=>array('ASSETS_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
104  // );
105  $this->const = array();
106  $this->const[1] = array(
107  "ASSET_DEPRECIATION_DURATION_PER_YEAR",
108  "chaine",
109  "365",
110  "Duration per year to calculate depreciation. In some case, can be 360 days",
111  0,
112  'current',
113  1
114  );
115 
116 
117  if (!isset($conf->asset) || !isset($conf->asset->enabled)) {
118  $conf->asset = new stdClass();
119  $conf->asset->enabled = 0;
120  }
121 
122 
123  // Array to add new pages in new tabs
124  $this->tabs = array();
125  // Example:
126  // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@assets:$user->rights->assets->read:/asset/mynewtab1.php?id=__ID__'); // To add a new tab identified by code tabname1
127  // $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@assets:$user->rights->othermodule->read:/asset/mynewtab2.php?id=__ID__', // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key.
128  // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
129  //
130  // Where objecttype can be
131  // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
132  // 'contact' to add a tab in contact view
133  // 'contract' to add a tab in contract view
134  // 'group' to add a tab in group view
135  // 'intervention' to add a tab in intervention view
136  // 'invoice' to add a tab in customer invoice view
137  // 'invoice_supplier' to add a tab in supplier invoice view
138  // 'member' to add a tab in fundation member view
139  // 'opensurveypoll' to add a tab in opensurvey poll view
140  // 'order' to add a tab in sales order view
141  // 'order_supplier' to add a tab in supplier order view
142  // 'payment' to add a tab in payment view
143  // 'payment_supplier' to add a tab in supplier payment view
144  // 'product' to add a tab in product view
145  // 'propal' to add a tab in propal view
146  // 'project' to add a tab in project view
147  // 'stock' to add a tab in stock view
148  // 'thirdparty' to add a tab in third party view
149  // 'user' to add a tab in user view
150 
151 
152  // Dictionaries
153  $this->dictionaries = array();
154 
155 
156  // Boxes/Widgets
157  // Add here list of php file(s) stored in asset/core/boxes that contains class to show a widget.
158  $this->boxes = array(
159  //0=>array('file'=>'assetswidget1.php@asset','note'=>'Widget provided by Assets','enabledbydefaulton'=>'Home'),
160  //1=>array('file'=>'assetswidget2.php@asset','note'=>'Widget provided by Assets'),
161  //2=>array('file'=>'assetswidget3.php@asset','note'=>'Widget provided by Assets')
162  );
163 
164 
165  // Cronjobs (List of cron jobs entries to add when module is enabled)
166  // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
167  //$this->cronjobs = array(
168  // 0=>array('label'=>'MyJob label', 'jobtype'=>'method', 'class'=>'/asset/class/asset.class.php', 'objectname'=>'Asset', 'method'=>'doScheduledJob', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>true)
169  //);
170  // Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>true),
171  // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>true)
172  // );
173 
174 
175  // Permissions
176  $this->rights = array(); // Permission array used by this module
177  $this->rights_class = 'asset';
178  $r = 0;
179 
180  $r++;
181  $this->rights[$r][0] = 51001; // Permission id (must not be already used)
182  $this->rights[$r][1] = 'Read assets'; // Permission label
183  $this->rights[$r][2] = 'r';
184  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
185  $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
186  $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
187 
188  $r++;
189  $this->rights[$r][0] = 51002; // Permission id (must not be already used)
190  $this->rights[$r][1] = 'Create/Update assets'; // Permission label
191  $this->rights[$r][2] = 'w';
192  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
193  $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
194  $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
195 
196  $r++;
197  $this->rights[$r][0] = 51003; // Permission id (must not be already used)
198  $this->rights[$r][1] = 'Delete assets'; // Permission label
199  $this->rights[$r][2] = 'd';
200  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
201  $this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
202  $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
203 
204  $r++;
205  $this->rights[$r][0] = 51004; // Permission id (must not be already used)
206  $this->rights[$r][1] = 'Read asset models'; // Permission label
207  $this->rights[$r][2] = 'r';
208  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
209  $this->rights[$r][4] = 'model_advance'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
210  $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
211 
212  $r++;
213  $this->rights[$r][0] = 51005; // Permission id (must not be already used)
214  $this->rights[$r][1] = 'Create/Update asset models'; // Permission label
215  $this->rights[$r][2] = 'w';
216  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
217  $this->rights[$r][4] = 'model_advance'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
218  $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
219 
220  $r++;
221  $this->rights[$r][0] = 51006; // Permission id (must not be already used)
222  $this->rights[$r][1] = 'Delete asset models'; // Permission label
223  $this->rights[$r][2] = 'd';
224  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
225  $this->rights[$r][4] = 'model_advance'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
226  $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
227 
228  // Menus
229  //-------
230  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
231  }
232 
241  public function init($options = '')
242  {
243  $result = $this->_load_tables('/install/mysql/', 'asset');
244  if ($result < 0) {
245  return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default')
246  }
247 
248  // Permissions
249  $this->remove($options);
250 
251  $sql = array();
252 
253  return $this->_init($sql, $options);
254  }
255 }
db
$conf db
API class for accounts.
Definition: inc.php:41
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
DolibarrModules\_load_tables
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Definition: DolibarrModules.class.php:1084
name
$conf db name
Definition: repair.php:122
modAsset\init
init($options='')
Function called when module is enabled.
Definition: modAsset.class.php:241
DolibarrModules\_init
_init($array_sql, $options='')
Enables a module.
Definition: DolibarrModules.class.php:397
modAsset\__construct
__construct($db)
Constructor.
Definition: modAsset.class.php:40
modAsset
Description and activation class for module FixedAssets.
Definition: modAsset.class.php:33
DolibarrModules
Class DolibarrModules.
Definition: DolibarrModules.class.php:37