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