dolibarr  19.0.0-dev
modHRM.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2015-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  * or see https://www.gnu.org/
17  */
18 
27 include_once DOL_DOCUMENT_ROOT."/core/modules/DolibarrModules.class.php";
28 
29 
33 class modHRM extends DolibarrModules
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 = 4000;
49  // Key text used to identify module (for permissions, menus, etc...)
50  $this->rights_class = 'hrm';
51 
52  // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
53  // It is used to group modules in module setup page
54  $this->family = "hr";
55  $this->module_position = '50';
56  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
57  $this->name = preg_replace('/^mod/i', '', get_class($this));
58  // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
59  $this->description = "HRM";
60  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
61  $this->version = 'dolibarr';
62  // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
63  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
64  // Name of image file used for this module.
65  // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
66  // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
67  $this->picto = 'hrm';
68 
69  // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
70  $this->module_parts = array(
71  // Set this to 1 if module has its own trigger directory (core/triggers)
72  'triggers' => 0,
73  // Set this to 1 if module has its own login method file (core/login)
74  'login' => 0,
75  // Set this to 1 if module has its own substitution function file (core/substitutions)
76  'substitutions' => 0,
77  // Set this to 1 if module has its own menus handler directory (core/menus)
78  'menus' => 0,
79  // Set this to 1 if module overwrite template dir (core/tpl)
80  'tpl' => 0,
81  // Set this to 1 if module has its own barcode directory (core/modules/barcode)
82  'barcode' => 0,
83  // Set this to 1 if module has its own models directory (core/modules/xxx)
84  'models' => 1,
85  // Set this to 1 if module has its own printing directory (core/modules/printing)
86  'printing' => 0,
87  // Set this to 1 if module has its own theme directory (theme)
88  'theme' => 0,
89  // Set this to relative path of css file if module has its own css file
90  'css' => array(),
91  // Set this to relative path of js file if module must load a js on all pages
92  'js' => array(),
93 
94  // Set this to 1 if features of module are opened to external users
95  'moduleforexternal' => 0,
96  );
97 
98  // Data directories to create when module is enabled.
99  // Example: this->dirs = array("/hrm/temp","/hrm/subdir");
100  $this->dirs = array("/hrm/temp");
101 
102  // Config pages. Put here list of php page, stored into hrm/admin directory, to use to setup module.
103  $this->config_page_url = array("hrm.php");
104 
105  // Dependencies
106  $this->hidden = false; // A condition to hide module
107  $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
108  $this->requiredby = array(); // List of module ids to disable if this one is disabled
109  $this->conflictwith = array(); // List of module class names as string this module is in conflict with
110  $this->phpmin = array(7, 0); // Minimum version of PHP required by module
111  $this->need_dolibarr_version = array(11, 0); // Minimum version of Dolibarr required by module
112  $this->langfiles = array("hrm");
113 
114  // Constants
115  // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',0),
116  // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) );
117  // 2=>array('MAIN_MODULE_MYMODULE_NEEDSMARTY','chaine',1,'Constant to say module need smarty',0)
118  $this->const = array(); // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 0 or 'allentities')
119  $r = 0;
120 
121 
122  if (!isset($conf->hrm) || !isset($conf->hrm->enabled)) {
123  $conf->hrm = new stdClass();
124  $conf->hrm->enabled = 0;
125  }
126 
127  // Array to add new pages in new tabs
128  $this->tabs = array();
129  $this->tabs[] = array('data'=>'user:+skill_tab:Skills:hrm:1:/hrm/skill_tab.php?id=__ID__&objecttype=user'); // To add a new tab identified by code tabname1
130  //$this->tabs[] = array('data'=>'job:+tabname1:Poste:mylangfile@hrm:1:/hrm/poste_list.php?fk_job=__ID__'); // To add a new tab identified by code tabname1
131  // Example:
132  // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@hrm:$user->rights->hrm->read:/hrm/mynewtab1.php?id=__ID__'); // To add a new tab identified by code tabname1
133  // $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@hrm:$user->rights->othermodule->read:/hrm/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.
134  // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
135  //
136  // Where objecttype can be
137  // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
138  // 'contact' to add a tab in contact view
139  // 'contract' to add a tab in contract view
140  // 'group' to add a tab in group view
141  // 'intervention' to add a tab in intervention view
142  // 'invoice' to add a tab in customer invoice view
143  // 'invoice_supplier' to add a tab in supplier invoice view
144  // 'member' to add a tab in fundation member view
145  // 'opensurveypoll' to add a tab in opensurvey poll view
146  // 'order' to add a tab in sales order view
147  // 'order_supplier' to add a tab in supplier order view
148  // 'payment' to add a tab in payment view
149  // 'payment_supplier' to add a tab in supplier payment view
150  // 'product' to add a tab in product view
151  // 'propal' to add a tab in propal view
152  // 'project' to add a tab in project view
153  // 'stock' to add a tab in stock view
154  // 'thirdparty' to add a tab in third party view
155  // 'user' to add a tab in user view
156 
157 
158  // Dictionaries
159  $this->dictionaries = array();
160 
161  // Boxes/Widgets
162  // Add here list of php file(s) stored in hrm/core/boxes that contains a class to show a widget.
163  $this->boxes = array(
164  // 0 => array(
165  // 'file' => 'hrmwidget1.php@hrm',
166  // 'note' => 'Widget provided by HrmTest',
167  // 'enabledbydefaulton' => 'Home',
168  // ),
169  // ...
170  );
171 
172  // Cronjobs (List of cron jobs entries to add when module is enabled)
173  // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
174  $this->cronjobs = array(
175  // 0 => array(
176  // 'label' => 'MyJob label',
177  // 'jobtype' => 'method',
178  // 'class' => '/hrm/class/poste.class.php',
179  // 'objectname' => 'Poste',
180  // 'method' => 'doScheduledJob',
181  // 'parameters' => '',
182  // 'comment' => 'Comment',
183  // 'frequency' => 2,
184  // 'unitfrequency' => 3600,
185  // 'status' => 0,
186  // 'test' => '$conf->hrm->enabled',
187  // 'priority' => 50,
188  // ),
189  );
190 
191 
192  // Permissions
193  $this->rights = array(); // Permission array used by this module
194  $r = 0;
195 
196  // Skill / Job / Position
197  $this->rights[$r][0] = 4001; // Permission id (must not be already used)
198  $this->rights[$r][1] = 'Read skill/job/position'; // Permission label
199  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
200  $this->rights[$r][4] = 'all';
201  $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->hrm->all->read)
202  $r++;
203 
204  $this->rights[$r][0] = 4002; // Permission id (must not be already used)
205  $this->rights[$r][1] = 'Create/modify skill/job/position'; // Permission label
206  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
207  $this->rights[$r][4] = 'all';
208  $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->hrm->all->write)
209  $r++;
210 
211  $this->rights[$r][0] = 4003; // Permission id (must not be already used)
212  $this->rights[$r][1] = 'Delete skill/job/position'; // Permission label
213  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
214  $this->rights[$r][4] = 'all';
215  $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->rights->hrm->all->delete)
216  $r++;
217 
218  // Evaluation
219  $this->rights[$r][0] = 4021; // Permission id (must not be already used)
220  $this->rights[$r][1] = 'Read evaluations'; // Permission label
221  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
222  $this->rights[$r][4] = 'evaluation';
223  $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->hrm->evaluation->read)
224  $r++;
225 
226  $this->rights[$r][0] = 4022; // Permission id (must not be already used)
227  $this->rights[$r][1] = 'Create/modify your evaluation'; // Permission label
228  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
229  $this->rights[$r][4] = 'evaluation';
230  $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->hrm->evaluation->write)
231  $r++;
232 
233  $this->rights[$r][0] = 4023; // Permission id (must not be already used)
234  $this->rights[$r][1] = 'Validate evaluation'; // Permission label
235  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
236  $this->rights[$r][4] = 'evaluation_advance';
237  $this->rights[$r][5] = 'validate'; // In php code, permission will be checked by test if ($user->rights->hrm->evaluation->validate)
238  $r++;
239 
240  $this->rights[$r][0] = 4025; // Permission id (must not be already used)
241  $this->rights[$r][1] = 'Delete evaluations'; // Permission label
242  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
243  $this->rights[$r][4] = 'evaluation';
244  $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->rights->hrm->evaluation->delete)
245  $r++;
246 
247  // Comparison
248  $this->rights[$r][0] = 4028; // Permission id (must not be already used)
249  $this->rights[$r][1] = 'See comparison menu'; // Permission label
250  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
251  $this->rights[$r][4] = 'compare_advance';
252  $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->hrm->compare_advance->read)
253  $r++;
254 
255  // Evaluation
256  $this->rights[$r][0] = 4029; // Permission id (must not be already used)
257  $this->rights[$r][1] = 'Read all evaluations'; // Permission label
258  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
259  $this->rights[$r][4] = 'evaluation';
260  $this->rights[$r][5] = 'readall'; // In php code, permission will be checked by test if ($user->rights->hrm->evaluation->read)
261  $r++;
262 
263  // Read employee
264  $this->rights[$r][0] = 4031; // Permission id (must not be already used)
265  $this->rights[$r][1] = 'Read personal/HR information'; // Permission label
266  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
267  $this->rights[$r][4] = 'read_personal_information';
268  $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->hrm->read_personal_information->read)
269  $r++;
270 
271  // Write employee
272  $this->rights[$r][0] = 4032; // Permission id (must not be already used)
273  $this->rights[$r][1] = 'Write personal/HR information'; // Permission label
274  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
275  $this->rights[$r][4] = 'write_personal_information';
276  $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->hrm->write_personal_information->write)
277  $r++;
278  }
279 
288  public function init($options = '')
289  {
290  // Permissions
291  $this->remove($options);
292 
293  $result = $this->_load_tables('/install/mysql/', 'hrm');
294  if ($result < 0) {
295  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')
296  }
297 
298  $sql = array();
299 
300  return $this->_init($sql, $options);
301  }
302 }
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Description and activation class for module HRM.
__construct($db)
Constructor.
init($options='')
Function called when module is enabled.
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:123