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