dolibarr 21.0.0-alpha
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-2024 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
29include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
30
35{
41 public function __construct($db)
42 {
43 global $conf;
44
45 $this->db = $db;
46 $this->numero = 0;
47
48 $this->family = "hr"; // Family for module (or "base" if core module)
49 $this->module_position = '05';
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 $this->description = "Management of users and groups of users (mandatory)";
53
54 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
55 $this->version = 'dolibarr';
56
57 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
58 $this->picto = 'group';
59
60 // Data directories to create when module is enabled
61 $this->dirs = array("/users/temp");
62
63 // Config pages
64 $this->config_page_url = array("user.php");
65
66 // Dependencies
67 $this->hidden = false; // A condition to hide module
68 $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
69 $this->requiredby = array(); // List of module ids to disable if this one is disabled
70 $this->conflictwith = array(); // List of module class names as string this module is in conflict with
71 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
72 $this->langfiles = array("main", "users", "companies", "members", "salaries", "hrm");
73 $this->always_enabled = true; // Can't be disabled
74
75 // Constants
76 $this->const = array();
77
78 // Boxes
79 $this->boxes = array(
80 0=>array('file'=>'box_lastlogin.php', 'enabledbydefaulton'=>'Home'),
81 1=>array('file'=>'box_birthdays.php', 'enabledbydefaulton'=>'Home'),
82 2=>array('file'=>'box_dolibarr_state_board.php', 'enabledbydefaulton'=>'Home')
83 );
84
85 // Permissions
86 $this->rights = array();
87 $this->rights_class = 'user';
88 $this->rights_admin_allowed = 1; // Admin is always granted of permission (even when module is disabled)
89 $r = 0;
90
91 $r++;
92 $this->rights[$r][self::KEY_ID] = 251;
93 $this->rights[$r][self::KEY_LABEL] = 'Read information of other users, groups and permissions';
94 $this->rights[$r][self::KEY_DEFAULT] = 0;
95 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'user';
96 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'lire';
97
98 $r++;
99 $this->rights[$r][self::KEY_ID] = 252;
100 $this->rights[$r][self::KEY_LABEL] = 'Read permissions of other users';
101 $this->rights[$r][self::KEY_DEFAULT] = 0;
102 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'user_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
103 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'readperms';
104
105 $r++;
106 $this->rights[$r][self::KEY_ID] = 253;
107 $this->rights[$r][self::KEY_LABEL] = 'Create/modify internal and external users, groups and permissions';
108 $this->rights[$r][self::KEY_DEFAULT] = 0;
109 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'user';
110 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'creer';
111
112 $r++;
113 $this->rights[$r][self::KEY_ID] = 254;
114 $this->rights[$r][self::KEY_LABEL] = 'Create/modify external users only';
115 $this->rights[$r][self::KEY_DEFAULT] = 0;
116 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'user_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
117 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'write';
118
119 $r++;
120 $this->rights[$r][self::KEY_ID] = 255;
121 $this->rights[$r][self::KEY_LABEL] = 'Modify the password of other users';
122 $this->rights[$r][self::KEY_DEFAULT] = 0;
123 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'user';
124 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'password';
125
126 $r++;
127 $this->rights[$r][self::KEY_ID] = 256;
128 $this->rights[$r][self::KEY_LABEL] = 'Delete or disable other users';
129 $this->rights[$r][self::KEY_DEFAULT] = 0;
130 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'user';
131 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'supprimer';
132
133 $r++;
134 $this->rights[$r][self::KEY_ID] = 341;
135 $this->rights[$r][self::KEY_LABEL] = 'Read its own permissions';
136 $this->rights[$r][self::KEY_DEFAULT] = 0;
137 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'self_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
138 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'readperms';
139
140 $r++;
141 $this->rights[$r][self::KEY_ID] = 342;
142 $this->rights[$r][self::KEY_LABEL] = 'Create/modify of its own user';
143 $this->rights[$r][self::KEY_DEFAULT] = 0;
144 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'self';
145 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'creer';
146
147 $r++;
148 $this->rights[$r][self::KEY_ID] = 343;
149 $this->rights[$r][self::KEY_LABEL] = 'Modify its own password';
150 $this->rights[$r][self::KEY_DEFAULT] = 0;
151 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'self';
152 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'password';
153
154 $r++;
155 $this->rights[$r][self::KEY_ID] = 344;
156 $this->rights[$r][self::KEY_LABEL] = 'Modify its own permissions';
157 $this->rights[$r][self::KEY_DEFAULT] = 0;
158 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'self_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
159 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'writeperms';
160
161 $r++;
162 $this->rights[$r][self::KEY_ID] = 351;
163 $this->rights[$r][self::KEY_LABEL] = 'Read groups';
164 $this->rights[$r][self::KEY_DEFAULT] = 0;
165 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
166 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'read';
167
168 $r++;
169 $this->rights[$r][self::KEY_ID] = 352;
170 $this->rights[$r][self::KEY_LABEL] = 'Read permissions of groups';
171 $this->rights[$r][self::KEY_DEFAULT] = 0;
172 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
173 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'readperms';
174
175 $r++;
176 $this->rights[$r][self::KEY_ID] = 353;
177 $this->rights[$r][self::KEY_LABEL] = 'Create/modify groups and permissions';
178 $this->rights[$r][self::KEY_DEFAULT] = 0;
179 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
180 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'write';
181
182 $r++;
183 $this->rights[$r][self::KEY_ID] = 354;
184 $this->rights[$r][self::KEY_LABEL] = 'Delete groups';
185 $this->rights[$r][self::KEY_DEFAULT] = 0;
186 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
187 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'delete';
188
189 $r++;
190 $this->rights[$r][self::KEY_ID] = 358;
191 $this->rights[$r][self::KEY_LABEL] = 'Export all users';
192 $this->rights[$r][self::KEY_DEFAULT] = 0;
193 $this->rights[$r][self::KEY_FIRST_LEVEL] = 'user';
194 $this->rights[$r][self::KEY_SECOND_LEVEL] = 'export';
195
196
197 // Menus
198 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
199
200
201 // Exports
202 $r = 0;
203
204 $r++;
205 $this->export_code[$r] = $this->rights_class.'_'.$r;
206 $this->export_label[$r] = 'List of users and attributes';
207 $this->export_permission[$r] = array(array("user", "user", "export"));
208 $this->export_fields_array[$r] = array(
209 'u.rowid'=>"Id", 'u.login'=>"Login", 'u.lastname'=>"Lastname", 'u.firstname'=>"Firstname", 'u.employee'=>"Employee", 'u.job'=>"PostOrFunction", 'u.gender'=>"Gender",
210 'u.accountancy_code'=>"UserAccountancyCode",
211 'u.address'=>"Address", 'u.zip'=>"Zip", 'u.town'=>"Town",
212 'u.office_phone'=>'Phone', 'u.user_mobile'=>"Mobile", 'u.office_fax'=>'Fax',
213 'u.email'=>"Email", 'u.note_public'=>"NotePublic", 'u.note_private'=>"NotePrivate", 'u.signature'=>'Signature',
214 'u.fk_user'=>'HierarchicalResponsible', 'u.thm'=>'THM', 'u.tjm'=>'TJM', 'u.weeklyhours'=>'WeeklyHours',
215 'u.dateemployment'=>'DateEmploymentStart', 'u.dateemploymentend'=>'DateEmploymentEnd', 'u.salary'=>'Salary', 'u.color'=>'Color', 'u.api_key'=>'ApiKey',
216 'u.birth'=>'DateOfBirth',
217 'u.datec'=>"DateCreation", 'u.tms'=>"DateLastModification",
218 'u.admin'=>"Administrator", 'u.statut'=>'Status', 'u.datelastlogin'=>'LastConnexion', 'u.datepreviouslogin'=>'PreviousConnexion',
219 'u.fk_socpeople'=>"IdContact", 'u.fk_soc'=>"IdCompany",
220 'u.fk_member'=>"MemberId",
221 "a.firstname"=>"MemberFirstname",
222 "a.lastname"=>"MemberLastname",
223 'g.nom'=>"Group"
224 );
225 $this->export_TypeFields_array[$r] = array(
226 'u.rowid'=>'Numeric', 'u.login'=>"Text", 'u.lastname'=>"Text", 'u.firstname'=>"Text", 'u.employee'=>'Boolean', 'u.job'=>'Text',
227 'u.accountancy_code'=>'Text',
228 'u.address'=>"Text", 'u.zip'=>"Text", 'u.town'=>"Text",
229 'u.office_phone'=>'Text', 'u.user_mobile'=>'Text', 'u.office_fax'=>'Text',
230 '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',
231 'u.fk_user'=>"FormSelect:select_dolusers",
232 'u.birth'=>'Date',
233 'u.datepreviouslogin'=>'Date',
234 'u.fk_socpeople'=>'FormSelect:selectcontacts',
235 'u.fk_soc'=>"FormSelect:select_company",
236 'u.tjm'=>"Numeric", 'u.thm'=>"Numeric", 'u.fk_member'=>"Numeric",
237 'u.weeklyhours'=>"Numeric",
238 'u.dateemployment'=>"Date", 'u.dateemploymentend'=>"Date", 'u.salary'=>"Numeric",
239 'u.color'=>'Text', 'u.api_key'=>'Text',
240 'a.firstname'=>'Text',
241 'a.lastname'=>'Text',
242 'g.nom'=>"Text"
243 );
244 $this->export_entities_array[$r] = array(
245 'u.rowid'=>"user", 'u.login'=>"user", 'u.lastname'=>"user", 'u.firstname'=>"user", 'u.employee'=>'user', 'u.job'=>'user', 'u.gender'=>'user',
246 'u.accountancy_code'=>'user',
247 'u.address'=>"user", 'u.zip'=>"user", 'u.town'=>"user",
248 'u.office_phone'=>'user', 'u.user_mobile'=>'user', 'u.office_fax'=>'user',
249 'u.email'=>'user', 'u.note_public'=>"user", 'u.note_private'=>"user", 'u.signature'=>'user',
250 'u.fk_user'=>'user', 'u.thm'=>'user', 'u.tjm'=>'user', 'u.weeklyhours'=>'user',
251 'u.dateemployment'=>'user', 'u.dateemploymentend'=>'user', 'u.salary'=>'user', 'u.color'=>'user', 'u.api_key'=>'user',
252 'u.birth'=>'user',
253 'u.datec'=>"user", 'u.tms'=>"user",
254 'u.admin'=>"user", 'u.statut'=>'user', 'u.datelastlogin'=>'user', 'u.datepreviouslogin'=>'user',
255 'u.fk_socpeople'=>"contact", 'u.fk_soc'=>"company", 'u.fk_member'=>"member",
256 'a.firstname'=>"member", 'a.lastname'=>"member",
257 'g.nom'=>"Group"
258 );
259 $keyforselect = 'user';
260 $keyforelement = 'user';
261 $keyforaliasextra = 'extra';
262 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
263 if (!isModEnabled('member')) {
264 unset($this->export_fields_array[$r]['u.fk_member']);
265 unset($this->export_entities_array[$r]['u.fk_member']);
266 }
267 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
268 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'user as u';
269 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user_extrafields as extra ON u.rowid = extra.fk_object';
270 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'usergroup_user as ug ON u.rowid = ug.fk_user';
271 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'usergroup as g ON ug.fk_usergroup = g.rowid';
272 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'adherent as a ON u.fk_member = a.rowid';
273 $this->export_sql_end[$r] .= ' WHERE u.entity IN ('.getEntity('user').')';
274
275
276 $r++;
277 $this->export_code[$r] = $this->rights_class.'_'.$r;
278 $this->export_label[$r] = 'List of security events';
279 $this->export_permission[$r] = array(array("user")); // Only admin
280 $this->export_fields_array[$r] = array(
281 'e.rowid'=>"Id", 'e.type'=>"Type",
282 'e.dateevent'=>"Date",
283 'e.description'=>'Description',
284 'e.ip'=>'IPAddress', 'e.user_agent'=>'UserAgent',
285 'e.authentication_method' => 'AuthenticationMode',
286 'e.fk_user'=>"UserID", 'u.login'=>"Login",
287 );
288 $this->export_TypeFields_array[$r] = array(
289 'e.rowid'=>'Numeric', 'e.type'=>"Text",
290 'e.dateevent'=>"Date",
291 'e.description'=>'Text',
292 'e.ip'=>'Text', 'e.user_agent'=>'Text',
293 'e.authentication_method' => 'Text',
294 'e.fk_user'=>"Numeric", 'u.login'=>"Text",
295 );
296 $this->export_entities_array[$r] = array(
297 'e.rowid'=>'securityevent', 'e.type'=>"securityevent",
298 'e.dateevent'=>"securityevent",
299 'e.description'=>'securityevent',
300 'e.ip'=>'securityevent', 'e.user_agent'=>'securityevent',
301 'e.authentication_method' => 'securityevent',
302 'e.fk_user'=>"user", 'u.login'=>"user",
303 );
304 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
305 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'events as e';
306 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON e.fk_user = u.rowid';
307 $this->export_sql_end[$r] .= ' WHERE e.entity IN ('.getEntity('event').')';
308
309
310 // Imports
311 $r = 0;
312
313 // Import list of users attributes
314 $r++;
315 $this->import_code[$r] = $this->rights_class.'_'.$r;
316 $this->import_label[$r] = 'ImportDataset_user_1';
317 $this->import_icon[$r] = 'user';
318 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
319 $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)
320 $this->import_fields_array[$r] = array(
321 'u.login'=>"Login*", 'u.lastname'=>"Name*", 'u.firstname'=>"Firstname", 'u.employee'=>"Employee*", 'u.job'=>"PostOrFunction", 'u.gender'=>"Gender",
322 'u.accountancy_code'=>"UserAccountancyCode",
323 'u.pass_crypted'=>"Password", 'u.admin'=>"Administrator", 'u.fk_soc'=>"Company*", 'u.address'=>"Address", 'u.zip'=>"Zip", 'u.town'=>"Town",
324 'u.fk_state'=>"StateId", 'u.fk_country'=>"CountryCode",
325 'u.office_phone'=>"Phone", 'u.user_mobile'=>"Mobile", 'u.office_fax'=>"Fax",
326 'u.email'=>"Email", 'u.note_public'=>"NotePublic", 'u.note_private'=>"NotePrivate", 'u.signature'=>'Signature',
327 'u.fk_user'=>'HierarchicalResponsible', 'u.thm'=>'THM', 'u.tjm'=>'TJM', 'u.weeklyhours'=>'WeeklyHours',
328 'u.dateemployment'=>'DateEmploymentStart', 'u.dateemploymentend'=>'DateEmploymentEnd', 'u.salary'=>'Salary', 'u.color'=>'Color', 'u.api_key'=>'ApiKey',
329 'u.birth'=>'DateOfBirth',
330 'u.datec'=>"DateCreation",
331 'u.statut'=>'Status'
332 );
333 // Add extra fields
334 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'user' AND entity IN (0,".$conf->entity.")";
335 $resql = $this->db->query($sql);
336 if ($resql) { // This can fail when class is used on old database (during migration for example)
337 while ($obj = $this->db->fetch_object($resql)) {
338 $fieldname = 'extra.'.$obj->name;
339 $fieldlabel = ucfirst($obj->label);
340 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
341 }
342 }
343 // End add extra fields
344 $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)
345 $this->import_convertvalue_array[$r] = array(
346 'u.fk_state'=>array('rule'=>'fetchidfromcodeid', 'classfile'=>'/core/class/cstate.class.php', 'class'=>'Cstate', 'method'=>'fetch', 'dict'=>'DictionaryState'),
347 'u.fk_country'=>array('rule'=>'fetchidfromcodeid', 'classfile'=>'/core/class/ccountry.class.php', 'class'=>'Ccountry', 'method'=>'fetch', 'dict'=>'DictionaryCountry'),
348 'u.salary'=>array('rule'=>'numeric')
349 );
350 //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
351 $this->import_regex_array[$r] = array(
352 'u.employee'=>'^[0|1]',
353 '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])?$',
354 'u.dateemployment'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
355 'u.birth'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'
356 );
357 $this->import_examplevalues_array[$r] = array(
358 'u.lastname'=>"Doe", 'u.firstname'=>'John', 'u.login'=>'jdoe', 'u.employee'=>'0 or 1', 'u.job'=>'CTO', 'u.gender'=>'man or woman',
359 'u.pass_crypted'=>'Encrypted password',
360 'u.fk_soc'=>'0 (internal user) or company name (external user)', 'u.address'=>"61 jump street",
361 'u.zip'=>"123456", 'u.town'=>"Big town", 'u.fk_country'=>'US, FR, DE...', 'u.office_phone'=>"0101010101", 'u.office_fax'=>"0101010102",
362 '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",
363 'u.statut'=>"0 (closed) or 1 (active)",
364 );
365 $this->import_updatekeys_array[$r] = array('u.lastname'=>'Lastname', 'u.firstname'=>'Firstname', 'u.login'=>'Login');
366 }
367
368
377 public function init($options = '')
378 {
379 global $conf;
380
381 // Permissions
382 $this->remove($options);
383
384 $sql = array();
385
386 return $this->_init($sql, $options);
387 }
388}
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.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after 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:142