dolibarr  13.0.2
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 {
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 = "Gestion des utilisateurs (requis)";
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(5, 4); // 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  );
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] = 'Consulter les autres utilisateurs';
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] = 'Consulter les permissions des autres utilisateurs';
101  $this->rights[$r][2] = 'r';
102  $this->rights[$r][3] = 0;
103  $this->rights[$r][4] = 'user_advance';
104  $this->rights[$r][5] = 'readperms';
105 
106  $r++;
107  $this->rights[$r][0] = 253;
108  $this->rights[$r][1] = 'Creer/modifier utilisateurs internes et externes';
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] = 'Creer/modifier utilisateurs externes seulement';
117  $this->rights[$r][2] = 'w';
118  $this->rights[$r][3] = 0;
119  $this->rights[$r][4] = 'user_advance';
120  $this->rights[$r][5] = 'write';
121 
122  $r++;
123  $this->rights[$r][0] = 255;
124  $this->rights[$r][1] = 'Modifier le mot de passe des autres utilisateurs';
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] = 'Supprimer ou desactiver les autres utilisateurs';
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] = 'Consulter ses propres 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] = 'Creer/modifier ses propres infos utilisateur';
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] = 'Modifier son propre mot de passe';
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] = 'Modifier ses propres 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] = 'Consulter les groupes';
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] = 'Consulter les permissions des groupes';
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] = 'Creer/modifier les groupes et leurs 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] = 'Supprimer ou desactiver les groupes';
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] = 'Exporter les utilisateurs';
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'=>"Note", 'u.signature'=>'Signature',
228  'u.fk_user'=>'HierarchicalResponsible', 'u.thm'=>'THM', 'u.tjm'=>'TJM', 'u.weeklyhours'=>'WeeklyHours',
229  'u.dateemployment'=>'DateEmployment', '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", 'u.fk_member'=>"MemberId"
234  );
235  $this->export_TypeFields_array[$r] = array(
236  'u.rowid'=>'Numeric', 'u.login'=>"Text", 'u.lastname'=>"Text", 'u.firstname'=>"Text", 'u.employee'=>'Boolean', 'u.job'=>'Text',
237  'u.accountancy_code'=>'Text',
238  'u.address'=>"Text", 'u.zip'=>"Text", 'u.town'=>"Text",
239  'u.office_phone'=>'Text', 'u.user_mobile'=>'Text', 'u.office_fax'=>'Text',
240  'u.email'=>'Text', 'u.datec'=>"Date", 'u.tms'=>"Date", 'u.admin'=>"Boolean", 'u.statut'=>'Status', 'u.note'=>"Text", 'u.datelastlogin'=>'Date',
241  'u.fk_user'=>"List:user:login",
242  'u.birth'=>'Date',
243  'u.datepreviouslogin'=>'Date', 'u.fk_soc'=>"List:societe:nom:rowid", 'u.fk_member'=>"List:adherent:firstname"
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'=>"user", 'u.signature'=>'user',
251  'u.fk_user'=>'user', 'u.thm'=>'user', 'u.tjm'=>'user', 'u.weeklyhours'=>'user',
252  'u.dateemployment'=>'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  );
258  $keyforselect = 'user'; $keyforelement = 'user'; $keyforaliasextra = 'extra';
259  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
260  if (empty($conf->adherent->enabled))
261  {
262  unset($this->export_fields_array[$r]['u.fk_member']);
263  unset($this->export_entities_array[$r]['u.fk_member']);
264  }
265  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
266  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'user as u';
267  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user_extrafields as extra ON u.rowid = extra.fk_object';
268  $this->export_sql_end[$r] .= ' WHERE u.entity IN ('.getEntity('user').')';
269 
270  // Imports
271  $r = 0;
272 
273  // Import list of users attributes
274  $r++;
275  $this->import_code[$r] = $this->rights_class.'_'.$r;
276  $this->import_label[$r] = 'ImportDataset_user_1';
277  $this->import_icon[$r] = 'user';
278  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
279  $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)
280  $this->import_fields_array[$r] = array(
281  'u.login'=>"Login*", 'u.lastname'=>"Name*", 'u.firstname'=>"Firstname", 'u.employee'=>"Employee*", 'u.job'=>"PostOrFunction", 'u.gender'=>"Gender",
282  'u.accountancy_code'=>"UserAccountancyCode",
283  'u.pass_crypted'=>"Password", 'u.admin'=>"Administrator", 'u.fk_soc'=>"Company*", 'u.address'=>"Address", 'u.zip'=>"Zip", 'u.town'=>"Town",
284  'u.fk_state'=>"StateId", 'u.fk_country'=>"CountryCode",
285  'u.office_phone'=>"Phone", 'u.user_mobile'=>"Mobile", 'u.office_fax'=>"Fax",
286  'u.email'=>"Email", 'u.note'=>"Note", 'u.signature'=>'Signature',
287  'u.fk_user'=>'HierarchicalResponsible', 'u.thm'=>'THM', 'u.tjm'=>'TJM', 'u.weeklyhours'=>'WeeklyHours',
288  'u.dateemployment'=>'DateEmployment', 'u.salary'=>'Salary', 'u.color'=>'Color', 'u.api_key'=>'ApiKey',
289  'u.birth'=>'DateOfBirth',
290  'u.datec'=>"DateCreation",
291  'u.statut'=>'Status'
292  );
293  // Add extra fields
294  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'user' AND entity IN (0,".$conf->entity.")";
295  $resql = $this->db->query($sql);
296  if ($resql) // This can fail when class is used on old database (during migration for example)
297  {
298  while ($obj = $this->db->fetch_object($resql))
299  {
300  $fieldname = 'extra.'.$obj->name;
301  $fieldlabel = ucfirst($obj->label);
302  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
303  }
304  }
305  // End add extra fields
306  $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)
307  $this->import_convertvalue_array[$r] = array(
308  'u.fk_state'=>array('rule'=>'fetchidfromcodeid', 'classfile'=>'/core/class/cstate.class.php', 'class'=>'Cstate', 'method'=>'fetch', 'dict'=>'DictionaryState'),
309  'u.fk_country'=>array('rule'=>'fetchidfromcodeid', 'classfile'=>'/core/class/ccountry.class.php', 'class'=>'Ccountry', 'method'=>'fetch', 'dict'=>'DictionaryCountry'),
310  'u.salary'=>array('rule'=>'numeric')
311  );
312  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
313  $this->import_regex_array[$r] = array(
314  'u.employee'=>'^[0|1]',
315  '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])?$',
316  'u.dateemployment'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
317  'u.birth'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'
318  );
319  $this->import_examplevalues_array[$r] = array(
320  'u.lastname'=>"Doe", 'u.firstname'=>'John', 'u.login'=>'jdoe', 'u.employee'=>'0 or 1', 'u.job'=>'CTO', 'u.gender'=>'0 or 1',
321  'u.pass_crypted'=>'Encrypted password',
322  'u.fk_soc'=>'0 (internal user) or company name (external user)', 'u.datec'=>dol_print_date(dol_now(), '%Y-%m-%d'), 'u.address'=>"61 jump street",
323  'u.zip'=>"123456", 'u.town'=>"Big town", 'u.fk_country'=>'US, FR, DE...', 'u.office_phone'=>"0101010101", 'u.office_fax'=>"0101010102",
324  'u.email'=>"test@mycompany.com", 'u.salary'=>"10000", 'u.note'=>"This is an example of note for record", 'u.datec'=>"2015-01-01 or 2015-01-01 12:30:00",
325  'u.statut'=>"0 (closed) or 1 (active)",
326  );
327  $this->import_updatekeys_array[$r] = array('u.lastname'=>'Lastname', 'u.firstname'=>'Firstname', 'u.login'=>'Login');
328  }
329 
330 
339  public function init($options = '')
340  {
341  global $conf;
342 
343  // Permissions
344  $this->remove($options);
345 
346  $sql = array();
347 
348  return $this->_init($sql, $options);
349  }
350 }
Class DolibarrModules.
init($options= '')
Function called when module is enabled.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
dol_now($mode= 'auto')
Return date for now.
Class to describe and enable module User.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
__construct($db)
Constructor.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
_init($array_sql, $options= '')
Enables a module.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232