modHRM.class.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. /**
  19. * \defgroup HRM Module hrm
  20. * \brief Module for Human Resource Management (HRM)
  21. *
  22. * \file htdocs/core/modules/modHRM.class.php
  23. * \ingroup HRM
  24. * \brief Description and activation file for the module HRM
  25. */
  26. include_once DOL_DOCUMENT_ROOT."/core/modules/DolibarrModules.class.php";
  27. /**
  28. * Description and activation class for module HRM
  29. */
  30. class modHRM extends DolibarrModules
  31. {
  32. /**
  33. * Constructor. Define names, constants, directories, boxes, permissions
  34. *
  35. * @param DoliDB $db Database handler
  36. */
  37. public function __construct($db)
  38. {
  39. global $langs, $conf;
  40. $this->db = $db;
  41. // Id for module (must be unique).
  42. // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
  43. $this->numero = 4000;
  44. // Key text used to identify module (for permissions, menus, etc...)
  45. $this->rights_class = 'hrm';
  46. // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
  47. // It is used to group modules in module setup page
  48. $this->family = "hr";
  49. $this->module_position = '50';
  50. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  51. $this->name = preg_replace('/^mod/i', '', get_class($this));
  52. // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
  53. $this->description = "HRM";
  54. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  55. $this->version = 'dolibarr';
  56. // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
  57. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  58. // Name of image file used for this module.
  59. // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
  60. // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
  61. $this->picto = 'hrm';
  62. // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
  63. $this->module_parts = array(
  64. // Set this to 1 if module has its own trigger directory (core/triggers)
  65. 'triggers' => 0,
  66. // Set this to 1 if module has its own login method file (core/login)
  67. 'login' => 0,
  68. // Set this to 1 if module has its own substitution function file (core/substitutions)
  69. 'substitutions' => 0,
  70. // Set this to 1 if module has its own menus handler directory (core/menus)
  71. 'menus' => 0,
  72. // Set this to 1 if module overwrite template dir (core/tpl)
  73. 'tpl' => 0,
  74. // Set this to 1 if module has its own barcode directory (core/modules/barcode)
  75. 'barcode' => 0,
  76. // Set this to 1 if module has its own models directory (core/modules/xxx)
  77. 'models' => 1,
  78. // Set this to 1 if module has its own printing directory (core/modules/printing)
  79. 'printing' => 0,
  80. // Set this to 1 if module has its own theme directory (theme)
  81. 'theme' => 0,
  82. // Set this to relative path of css file if module has its own css file
  83. 'css' => array(),
  84. // Set this to relative path of js file if module must load a js on all pages
  85. 'js' => array(),
  86. // Set this to 1 if features of module are opened to external users
  87. 'moduleforexternal' => 0,
  88. );
  89. // Data directories to create when module is enabled.
  90. // Example: this->dirs = array("/hrm/temp","/hrm/subdir");
  91. $this->dirs = array("/hrm/temp");
  92. // Config pages. Put here list of php page, stored into hrm/admin directory, to use to setup module.
  93. $this->config_page_url = array("hrm.php");
  94. // Dependencies
  95. $this->hidden = false; // A condition to hide module
  96. $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
  97. $this->requiredby = array(); // List of module ids to disable if this one is disabled
  98. $this->conflictwith = array(); // List of module class names as string this module is in conflict with
  99. $this->phpmin = array(7, 0); // Minimum version of PHP required by module
  100. $this->need_dolibarr_version = array(11, 0); // Minimum version of Dolibarr required by module
  101. $this->langfiles = array("hrm");
  102. // Constants
  103. // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',0),
  104. // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) );
  105. $this->const = array(); // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 0 or 'allentities')
  106. $r = 0;
  107. if (!isset($conf->hrm) || !isset($conf->hrm->enabled)) {
  108. $conf->hrm = new stdClass();
  109. $conf->hrm->enabled = 0;
  110. }
  111. // Array to add new pages in new tabs
  112. $this->tabs = array();
  113. $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
  114. //$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
  115. // Example:
  116. // $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
  117. // $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.
  118. // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
  119. //
  120. // Where objecttype can be
  121. // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
  122. // 'contact' to add a tab in contact view
  123. // 'contract' to add a tab in contract view
  124. // 'group' to add a tab in group view
  125. // 'intervention' to add a tab in intervention view
  126. // 'invoice' to add a tab in customer invoice view
  127. // 'invoice_supplier' to add a tab in supplier invoice view
  128. // 'member' to add a tab in fundation member view
  129. // 'opensurveypoll' to add a tab in opensurvey poll view
  130. // 'order' to add a tab in sales order view
  131. // 'order_supplier' to add a tab in supplier order view
  132. // 'payment' to add a tab in payment view
  133. // 'payment_supplier' to add a tab in supplier payment view
  134. // 'product' to add a tab in product view
  135. // 'propal' to add a tab in propal view
  136. // 'project' to add a tab in project view
  137. // 'stock' to add a tab in stock view
  138. // 'thirdparty' to add a tab in third party view
  139. // 'user' to add a tab in user view
  140. // Dictionaries
  141. $this->dictionaries = array();
  142. // Boxes/Widgets
  143. // Add here list of php file(s) stored in hrm/core/boxes that contains a class to show a widget.
  144. $this->boxes = array(
  145. // 0 => array(
  146. // 'file' => 'hrmwidget1.php@hrm',
  147. // 'note' => 'Widget provided by HrmTest',
  148. // 'enabledbydefaulton' => 'Home',
  149. // ),
  150. // ...
  151. );
  152. // Cronjobs (List of cron jobs entries to add when module is enabled)
  153. // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
  154. $this->cronjobs = array(
  155. // 0 => array(
  156. // 'label' => 'MyJob label',
  157. // 'jobtype' => 'method',
  158. // 'class' => '/hrm/class/poste.class.php',
  159. // 'objectname' => 'Poste',
  160. // 'method' => 'doScheduledJob',
  161. // 'parameters' => '',
  162. // 'comment' => 'Comment',
  163. // 'frequency' => 2,
  164. // 'unitfrequency' => 3600,
  165. // 'status' => 0,
  166. // 'test' => '$conf->hrm->enabled',
  167. // 'priority' => 50,
  168. // ),
  169. );
  170. // Permissions
  171. $this->rights = array(); // Permission array used by this module
  172. $r = 0;
  173. // Skill / Job / Position
  174. $this->rights[$r][0] = 4001; // Permission id (must not be already used)
  175. $this->rights[$r][1] = 'Read skill/job/position'; // Permission label
  176. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  177. $this->rights[$r][4] = 'all';
  178. $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->hrm->all->read)
  179. $r++;
  180. $this->rights[$r][0] = 4002; // Permission id (must not be already used)
  181. $this->rights[$r][1] = 'Create/modify skill/job/position'; // Permission label
  182. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  183. $this->rights[$r][4] = 'all';
  184. $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->hrm->all->write)
  185. $r++;
  186. $this->rights[$r][0] = 4003; // Permission id (must not be already used)
  187. $this->rights[$r][1] = 'Delete skill/job/position'; // Permission label
  188. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  189. $this->rights[$r][4] = 'all';
  190. $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->rights->hrm->all->delete)
  191. $r++;
  192. // Evaluation
  193. $this->rights[$r][0] = 4021; // Permission id (must not be already used)
  194. $this->rights[$r][1] = 'Read evaluations'; // Permission label
  195. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  196. $this->rights[$r][4] = 'evaluation';
  197. $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->hrm->evaluation->read)
  198. $r++;
  199. $this->rights[$r][0] = 4022; // Permission id (must not be already used)
  200. $this->rights[$r][1] = 'Create/modify your evaluation'; // Permission label
  201. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  202. $this->rights[$r][4] = 'evaluation';
  203. $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->hrm->evaluation->write)
  204. $r++;
  205. $this->rights[$r][0] = 4023; // Permission id (must not be already used)
  206. $this->rights[$r][1] = 'Validate evaluation'; // Permission label
  207. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  208. $this->rights[$r][4] = 'evaluation_advance';
  209. $this->rights[$r][5] = 'validate'; // In php code, permission will be checked by test if ($user->rights->hrm->evaluation->validate)
  210. $r++;
  211. $this->rights[$r][0] = 4025; // Permission id (must not be already used)
  212. $this->rights[$r][1] = 'Delete evaluations'; // Permission label
  213. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  214. $this->rights[$r][4] = 'evaluation';
  215. $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->rights->hrm->evaluation->delete)
  216. $r++;
  217. // Comparison
  218. $this->rights[$r][0] = 4028; // Permission id (must not be already used)
  219. $this->rights[$r][1] = 'See comparison menu'; // Permission label
  220. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  221. $this->rights[$r][4] = 'compare_advance';
  222. $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->hrm->compare_advance->read)
  223. $r++;
  224. // Evaluation
  225. $this->rights[$r][0] = 4029; // Permission id (must not be already used)
  226. $this->rights[$r][1] = 'Read all evaluations'; // Permission label
  227. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  228. $this->rights[$r][4] = 'evaluation';
  229. $this->rights[$r][5] = 'readall'; // In php code, permission will be checked by test if ($user->rights->hrm->evaluation->read)
  230. $r++;
  231. // Read employee
  232. $this->rights[$r][0] = 4031; // Permission id (must not be already used)
  233. $this->rights[$r][1] = 'Read personal/HR information'; // Permission label
  234. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  235. $this->rights[$r][4] = 'read_personal_information';
  236. $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->hrm->read_personal_information->read)
  237. $r++;
  238. // Write employee
  239. $this->rights[$r][0] = 4032; // Permission id (must not be already used)
  240. $this->rights[$r][1] = 'Write personal/HR information'; // Permission label
  241. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  242. $this->rights[$r][4] = 'write_personal_information';
  243. $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->hrm->write_personal_information->write)
  244. $r++;
  245. }
  246. /**
  247. * Function called when module is enabled.
  248. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  249. * It also creates data directories
  250. *
  251. * @param string $options Options when enabling module ('', 'newboxdefonly', 'noboxes')
  252. * @return int 1 if OK, 0 if KO
  253. */
  254. public function init($options = '')
  255. {
  256. // Permissions
  257. $this->remove($options);
  258. $result = $this->_load_tables('/install/mysql/', 'hrm');
  259. if ($result < 0) {
  260. 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')
  261. }
  262. $sql = array();
  263. return $this->_init($sql, $options);
  264. }
  265. }