dolibarr  18.0.6
modUser.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
28 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29 
33 class modUser extends DolibarrModules
34 {
40  public function __construct($db)
41  {
42  global $conf;
43 
44  $this->db = $db;
45  $this->numero = 0;
46 
47  $this->family = "hr"; // Family for module (or "base" if core module)
48  $this->module_position = '05';
49  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
50  $this->name = preg_replace('/^mod/i', '', get_class($this));
51  $this->description = "Management of users and groups of users (mandatory)";
52 
53  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
54  $this->version = 'dolibarr';
55 
56  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
57  $this->picto = 'group';
58 
59  // Data directories to create when module is enabled
60  $this->dirs = array("/users/temp");
61 
62  // Config pages
63  $this->config_page_url = array("user.php");
64 
65  // Dependencies
66  $this->hidden = false; // A condition to hide module
67  $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
68  $this->requiredby = array(); // List of module ids to disable if this one is disabled
69  $this->conflictwith = array(); // List of module class names as string this module is in conflict with
70  $this->phpmin = array(7, 0); // Minimum version of PHP required by module
71  $this->langfiles = array("main", "users", "companies", "members", "salaries", "hrm");
72  $this->always_enabled = true; // Can't be disabled
73 
74  // Constants
75  $this->const = array();
76 
77  // Boxes
78  $this->boxes = array(
79  0=>array('file'=>'box_lastlogin.php', 'enabledbydefaulton'=>'Home'),
80  1=>array('file'=>'box_birthdays.php', 'enabledbydefaulton'=>'Home'),
81  2=>array('file'=>'box_dolibarr_state_board.php', 'enabledbydefaulton'=>'Home')
82  );
83 
84  // Permissions
85  $this->rights = array();
86  $this->rights_class = 'user';
87  $this->rights_admin_allowed = 1; // Admin is always granted of permission (even when module is disabled)
88  $r = 0;
89 
90  $r++;
91  $this->rights[$r][0] = 251;
92  $this->rights[$r][1] = 'Read information of other users, groups and permissions';
93  $this->rights[$r][2] = 'r';
94  $this->rights[$r][3] = 0;
95  $this->rights[$r][4] = 'user';
96  $this->rights[$r][5] = 'lire';
97 
98  $r++;
99  $this->rights[$r][0] = 252;
100  $this->rights[$r][1] = 'Read permissions of other users';
101  $this->rights[$r][2] = 'r';
102  $this->rights[$r][3] = 0;
103  $this->rights[$r][4] = 'user_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
104  $this->rights[$r][5] = 'readperms';
105 
106  $r++;
107  $this->rights[$r][0] = 253;
108  $this->rights[$r][1] = 'Create/modify internal and external users, groups and permissions';
109  $this->rights[$r][2] = 'w';
110  $this->rights[$r][3] = 0;
111  $this->rights[$r][4] = 'user';
112  $this->rights[$r][5] = 'creer';
113 
114  $r++;
115  $this->rights[$r][0] = 254;
116  $this->rights[$r][1] = 'Create/modify external users only';
117  $this->rights[$r][2] = 'w';
118  $this->rights[$r][3] = 0;
119  $this->rights[$r][4] = 'user_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
120  $this->rights[$r][5] = 'write';
121 
122  $r++;
123  $this->rights[$r][0] = 255;
124  $this->rights[$r][1] = 'Modify the password of other users';
125  $this->rights[$r][2] = 'w';
126  $this->rights[$r][3] = 0;
127  $this->rights[$r][4] = 'user';
128  $this->rights[$r][5] = 'password';
129 
130  $r++;
131  $this->rights[$r][0] = 256;
132  $this->rights[$r][1] = 'Delete or disable other users';
133  $this->rights[$r][2] = 'd';
134  $this->rights[$r][3] = 0;
135  $this->rights[$r][4] = 'user';
136  $this->rights[$r][5] = 'supprimer';
137 
138  $r++;
139  $this->rights[$r][0] = 341;
140  $this->rights[$r][1] = 'Read its own permissions';
141  $this->rights[$r][2] = 'r';
142  $this->rights[$r][3] = 0;
143  $this->rights[$r][4] = 'self_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
144  $this->rights[$r][5] = 'readperms';
145 
146  $r++;
147  $this->rights[$r][0] = 342;
148  $this->rights[$r][1] = 'Create/modify of its own user';
149  $this->rights[$r][2] = 'w';
150  $this->rights[$r][3] = 0;
151  $this->rights[$r][4] = 'self';
152  $this->rights[$r][5] = 'creer';
153 
154  $r++;
155  $this->rights[$r][0] = 343;
156  $this->rights[$r][1] = 'Modify its own password';
157  $this->rights[$r][2] = 'w';
158  $this->rights[$r][3] = 0;
159  $this->rights[$r][4] = 'self';
160  $this->rights[$r][5] = 'password';
161 
162  $r++;
163  $this->rights[$r][0] = 344;
164  $this->rights[$r][1] = 'Modify its own permissions';
165  $this->rights[$r][2] = 'w';
166  $this->rights[$r][3] = 0;
167  $this->rights[$r][4] = 'self_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
168  $this->rights[$r][5] = 'writeperms';
169 
170  $r++;
171  $this->rights[$r][0] = 351;
172  $this->rights[$r][1] = 'Read groups';
173  $this->rights[$r][2] = 'r';
174  $this->rights[$r][3] = 0;
175  $this->rights[$r][4] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
176  $this->rights[$r][5] = 'read';
177 
178  $r++;
179  $this->rights[$r][0] = 352;
180  $this->rights[$r][1] = 'Read permissions of groups';
181  $this->rights[$r][2] = 'r';
182  $this->rights[$r][3] = 0;
183  $this->rights[$r][4] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
184  $this->rights[$r][5] = 'readperms';
185 
186  $r++;
187  $this->rights[$r][0] = 353;
188  $this->rights[$r][1] = 'Create/modify groups and permissions';
189  $this->rights[$r][2] = 'w';
190  $this->rights[$r][3] = 0;
191  $this->rights[$r][4] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
192  $this->rights[$r][5] = 'write';
193 
194  $r++;
195  $this->rights[$r][0] = 354;
196  $this->rights[$r][1] = 'Delete groups';
197  $this->rights[$r][2] = 'd';
198  $this->rights[$r][3] = 0;
199  $this->rights[$r][4] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
200  $this->rights[$r][5] = 'delete';
201 
202  $r++;
203  $this->rights[$r][0] = 358;
204  $this->rights[$r][1] = 'Export all users';
205  $this->rights[$r][2] = 'r';
206  $this->rights[$r][3] = 0;
207  $this->rights[$r][4] = 'user';
208  $this->rights[$r][5] = 'export';
209 
210 
211  // Menus
212  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
213 
214 
215  // Exports
216  $r = 0;
217 
218  $r++;
219  $this->export_code[$r] = $this->rights_class.'_'.$r;
220  $this->export_label[$r] = 'List of users and attributes';
221  $this->export_permission[$r] = array(array("user", "user", "export"));
222  $this->export_fields_array[$r] = array(
223  'u.rowid'=>"Id", 'u.login'=>"Login", 'u.lastname'=>"Lastname", 'u.firstname'=>"Firstname", 'u.employee'=>"Employee", 'u.job'=>"PostOrFunction", 'u.gender'=>"Gender",
224  'u.accountancy_code'=>"UserAccountancyCode",
225  'u.address'=>"Address", 'u.zip'=>"Zip", 'u.town'=>"Town",
226  'u.office_phone'=>'Phone', 'u.user_mobile'=>"Mobile", 'u.office_fax'=>'Fax',
227  'u.email'=>"Email", 'u.note_public'=>"NotePublic", 'u.note_private'=>"NotePrivate", 'u.signature'=>'Signature',
228  'u.fk_user'=>'HierarchicalResponsible', 'u.thm'=>'THM', 'u.tjm'=>'TJM', 'u.weeklyhours'=>'WeeklyHours',
229  'u.dateemployment'=>'DateEmploymentStart', 'u.dateemploymentend'=>'DateEmploymentEnd', 'u.salary'=>'Salary', 'u.color'=>'Color', 'u.api_key'=>'ApiKey',
230  'u.birth'=>'DateOfBirth',
231  'u.datec'=>"DateCreation", 'u.tms'=>"DateLastModification",
232  'u.admin'=>"Administrator", 'u.statut'=>'Status', 'u.datelastlogin'=>'LastConnexion', 'u.datepreviouslogin'=>'PreviousConnexion',
233  'u.fk_socpeople'=>"IdContact", 'u.fk_soc'=>"IdCompany",
234  'u.fk_member'=>"MemberId",
235  "a.firstname"=>"MemberFirstname",
236  "a.lastname"=>"MemberLastname",
237  'g.nom'=>"Group"
238  );
239  $this->export_TypeFields_array[$r] = array(
240  'u.rowid'=>'Numeric', 'u.login'=>"Text", 'u.lastname'=>"Text", 'u.firstname'=>"Text", 'u.employee'=>'Boolean', 'u.job'=>'Text',
241  'u.accountancy_code'=>'Text',
242  'u.address'=>"Text", 'u.zip'=>"Text", 'u.town'=>"Text",
243  'u.office_phone'=>'Text', 'u.user_mobile'=>'Text', 'u.office_fax'=>'Text',
244  'u.email'=>'Text', 'u.datec'=>"Date", 'u.tms'=>"Date", 'u.admin'=>"Boolean", 'u.statut'=>'Status', 'u.note_public'=>"Text", 'u.note_private'=>"Text", 'u.signature'=>"Text", 'u.datelastlogin'=>'Date',
245  'u.fk_user'=>"FormSelect:select_dolusers",
246  'u.birth'=>'Date',
247  'u.datepreviouslogin'=>'Date',
248  'u.fk_socpeople'=>'FormSelect:selectcontacts',
249  'u.fk_soc'=>"FormSelect:select_company",
250  'u.tjm'=>"Numeric", 'u.thm'=>"Numeric", 'u.fk_member'=>"Numeric",
251  'u.weeklyhours'=>"Numeric",
252  'u.dateemployment'=>"Date", 'u.dateemploymentend'=>"Date", 'u.salary'=>"Numeric",
253  'u.color'=>'Text', 'u.api_key'=>'Text',
254  'a.firstname'=>'Text',
255  'a.lastname'=>'Text',
256  'g.nom'=>"Text"
257  );
258  $this->export_entities_array[$r] = array(
259  'u.rowid'=>"user", 'u.login'=>"user", 'u.lastname'=>"user", 'u.firstname'=>"user", 'u.employee'=>'user', 'u.job'=>'user', 'u.gender'=>'user',
260  'u.accountancy_code'=>'user',
261  'u.address'=>"user", 'u.zip'=>"user", 'u.town'=>"user",
262  'u.office_phone'=>'user', 'u.user_mobile'=>'user', 'u.office_fax'=>'user',
263  'u.email'=>'user', 'u.note_public'=>"user", 'u.note_private'=>"user", 'u.signature'=>'user',
264  'u.fk_user'=>'user', 'u.thm'=>'user', 'u.tjm'=>'user', 'u.weeklyhours'=>'user',
265  'u.dateemployment'=>'user', 'u.dateemploymentend'=>'user', 'u.salary'=>'user', 'u.color'=>'user', 'u.api_key'=>'user',
266  'u.birth'=>'user',
267  'u.datec'=>"user", 'u.tms'=>"user",
268  'u.admin'=>"user", 'u.statut'=>'user', 'u.datelastlogin'=>'user', 'u.datepreviouslogin'=>'user',
269  'u.fk_socpeople'=>"contact", 'u.fk_soc'=>"company", 'u.fk_member'=>"member",
270  'a.firstname'=>"member", 'a.lastname'=>"member",
271  'g.nom'=>"Group"
272  );
273  $keyforselect = 'user';
274  $keyforelement = 'user';
275  $keyforaliasextra = 'extra';
276  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
277  if (!isModEnabled('adherent')) {
278  unset($this->export_fields_array[$r]['u.fk_member']);
279  unset($this->export_entities_array[$r]['u.fk_member']);
280  }
281  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
282  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'user as u';
283  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user_extrafields as extra ON u.rowid = extra.fk_object';
284  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'usergroup_user as ug ON u.rowid = ug.fk_user';
285  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'usergroup as g ON ug.fk_usergroup = g.rowid';
286  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'adherent as a ON u.fk_member = a.rowid';
287  $this->export_sql_end[$r] .= ' WHERE u.entity IN ('.getEntity('user').')';
288 
289  // Imports
290  $r = 0;
291 
292  // Import list of users attributes
293  $r++;
294  $this->import_code[$r] = $this->rights_class.'_'.$r;
295  $this->import_label[$r] = 'ImportDataset_user_1';
296  $this->import_icon[$r] = 'user';
297  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
298  $this->import_tables_array[$r] = array('u'=>MAIN_DB_PREFIX.'user', 'extra'=>MAIN_DB_PREFIX.'user_extrafields'); // List of tables to insert into (insert done in same order)
299  $this->import_fields_array[$r] = array(
300  'u.login'=>"Login*", 'u.lastname'=>"Name*", 'u.firstname'=>"Firstname", 'u.employee'=>"Employee*", 'u.job'=>"PostOrFunction", 'u.gender'=>"Gender",
301  'u.accountancy_code'=>"UserAccountancyCode",
302  'u.pass_crypted'=>"Password", 'u.admin'=>"Administrator", 'u.fk_soc'=>"Company*", 'u.address'=>"Address", 'u.zip'=>"Zip", 'u.town'=>"Town",
303  'u.fk_state'=>"StateId", 'u.fk_country'=>"CountryCode",
304  'u.office_phone'=>"Phone", 'u.user_mobile'=>"Mobile", 'u.office_fax'=>"Fax",
305  'u.email'=>"Email", 'u.note_public'=>"NotePublic", 'u.note_private'=>"NotePrivate", 'u.signature'=>'Signature',
306  'u.fk_user'=>'HierarchicalResponsible', 'u.thm'=>'THM', 'u.tjm'=>'TJM', 'u.weeklyhours'=>'WeeklyHours',
307  'u.dateemployment'=>'DateEmploymentStart', 'u.dateemploymentend'=>'DateEmploymentEnd', 'u.salary'=>'Salary', 'u.color'=>'Color', 'u.api_key'=>'ApiKey',
308  'u.birth'=>'DateOfBirth',
309  'u.datec'=>"DateCreation",
310  'u.statut'=>'Status'
311  );
312  // Add extra fields
313  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'user' AND entity IN (0,".$conf->entity.")";
314  $resql = $this->db->query($sql);
315  if ($resql) { // This can fail when class is used on old database (during migration for example)
316  while ($obj = $this->db->fetch_object($resql)) {
317  $fieldname = 'extra.'.$obj->name;
318  $fieldlabel = ucfirst($obj->label);
319  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
320  }
321  }
322  // End add extra fields
323  $this->import_fieldshidden_array[$r] = array('u.fk_user_creat'=>'user->id', 'extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'user'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
324  $this->import_convertvalue_array[$r] = array(
325  'u.fk_state'=>array('rule'=>'fetchidfromcodeid', 'classfile'=>'/core/class/cstate.class.php', 'class'=>'Cstate', 'method'=>'fetch', 'dict'=>'DictionaryState'),
326  'u.fk_country'=>array('rule'=>'fetchidfromcodeid', 'classfile'=>'/core/class/ccountry.class.php', 'class'=>'Ccountry', 'method'=>'fetch', 'dict'=>'DictionaryCountry'),
327  'u.salary'=>array('rule'=>'numeric')
328  );
329  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
330  $this->import_regex_array[$r] = array(
331  'u.employee'=>'^[0|1]',
332  'u.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])?$',
333  'u.dateemployment'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
334  'u.birth'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'
335  );
336  $this->import_examplevalues_array[$r] = array(
337  'u.lastname'=>"Doe", 'u.firstname'=>'John', 'u.login'=>'jdoe', 'u.employee'=>'0 or 1', 'u.job'=>'CTO', 'u.gender'=>'man or woman',
338  'u.pass_crypted'=>'Encrypted password',
339  'u.fk_soc'=>'0 (internal user) or company name (external user)', 'u.address'=>"61 jump street",
340  'u.zip'=>"123456", 'u.town'=>"Big town", 'u.fk_country'=>'US, FR, DE...', 'u.office_phone'=>"0101010101", 'u.office_fax'=>"0101010102",
341  'u.email'=>"test@mycompany.com", 'u.salary'=>"10000", 'u.note_public'=>"This is an example of public note for record", 'u.note_private'=>"This is an example of private note for record", 'u.datec'=>"2015-01-01 or 2015-01-01 12:30:00",
342  'u.statut'=>"0 (closed) or 1 (active)",
343  );
344  $this->import_updatekeys_array[$r] = array('u.lastname'=>'Lastname', 'u.firstname'=>'Firstname', 'u.login'=>'Login');
345  }
346 
347 
356  public function init($options = '')
357  {
358  global $conf;
359 
360  // Permissions
361  $this->remove($options);
362 
363  $sql = array();
364 
365  return $this->_init($sql, $options);
366  }
367 }
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Class to describe and enable module User.
__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.
isModEnabled($module)
Is Dolibarr module enabled.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:123