dolibarr  13.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 = "Assets module";
62  // Used only if file README.md and README-LL.md not found.
63  $this->descriptionlong = "Assets 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 = 'accounting';
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(5, 4); // 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 
107 
108  if (!isset($conf->asset) || !isset($conf->asset->enabled))
109  {
110  $conf->asset = new stdClass();
111  $conf->asset->enabled = 0;
112  }
113 
114 
115  // Array to add new pages in new tabs
116  $this->tabs = array();
117  // Example:
118  // $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
119  // $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.
120  // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
121  //
122  // Where objecttype can be
123  // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
124  // 'contact' to add a tab in contact view
125  // 'contract' to add a tab in contract view
126  // 'group' to add a tab in group view
127  // 'intervention' to add a tab in intervention view
128  // 'invoice' to add a tab in customer invoice view
129  // 'invoice_supplier' to add a tab in supplier invoice view
130  // 'member' to add a tab in fundation member view
131  // 'opensurveypoll' to add a tab in opensurvey poll view
132  // 'order' to add a tab in customer order view
133  // 'order_supplier' to add a tab in supplier order view
134  // 'payment' to add a tab in payment view
135  // 'payment_supplier' to add a tab in supplier payment view
136  // 'product' to add a tab in product view
137  // 'propal' to add a tab in propal view
138  // 'project' to add a tab in project view
139  // 'stock' to add a tab in stock view
140  // 'thirdparty' to add a tab in third party view
141  // 'user' to add a tab in user view
142 
143 
144  // Dictionaries
145  $this->dictionaries = array();
146 
147 
148  // Boxes/Widgets
149  // Add here list of php file(s) stored in asset/core/boxes that contains class to show a widget.
150  $this->boxes = array(
151  //0=>array('file'=>'assetswidget1.php@asset','note'=>'Widget provided by Assets','enabledbydefaulton'=>'Home'),
152  //1=>array('file'=>'assetswidget2.php@asset','note'=>'Widget provided by Assets'),
153  //2=>array('file'=>'assetswidget3.php@asset','note'=>'Widget provided by Assets')
154  );
155 
156 
157  // Cronjobs (List of cron jobs entries to add when module is enabled)
158  // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
159  //$this->cronjobs = array(
160  // 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)
161  //);
162  // 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),
163  // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>true)
164  // );
165 
166 
167  // Permissions
168  $this->rights = array(); // Permission array used by this module
169  $this->rights_class = 'asset';
170  $r = 0;
171 
172  $r++;
173  $this->rights[$r][0] = 51001; // Permission id (must not be already used)
174  $this->rights[$r][1] = 'Read assets'; // Permission label
175  $this->rights[$r][2] = 'r';
176  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
177  $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
178  $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
179 
180  $r++;
181  $this->rights[$r][0] = 51002; // Permission id (must not be already used)
182  $this->rights[$r][1] = 'Create/Update assets'; // Permission label
183  $this->rights[$r][2] = 'w';
184  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
185  $this->rights[$r][4] = 'write'; // 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] = 51003; // Permission id (must not be already used)
190  $this->rights[$r][1] = 'Delete assets'; // Permission label
191  $this->rights[$r][2] = 'd';
192  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
193  $this->rights[$r][4] = 'delete'; // 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] = 51005; // Permission id (must not be already used)
198  $this->rights[$r][1] = 'Setup types of asset'; // Permission label
199  $this->rights[$r][2] = 'w';
200  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
201  $this->rights[$r][4] = 'setup_advance'; // 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  // Menus
205  //-------
206  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
207  }
208 
217  public function init($options = '')
218  {
219  // Permissions
220  $this->remove($options);
221 
222  $sql = array();
223 
224  return $this->_init($sql, $options);
225  }
226 }
Class DolibarrModules.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</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:750
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:108
Description and activation class for module FixedAssets.
$conf db
API class for accounts.
Definition: inc.php:54
__construct($db)
Constructor.
_init($array_sql, $options= '')
Enables a module.