dolibarr  9.0.0
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 <http://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  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 = '10';
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');
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  );
82 
83  // Permissions
84  $this->rights = array();
85  $this->rights_class = 'user';
86  $this->rights_admin_allowed = 1; // Admin is always granted of permission (even when module is disabled)
87  $r=0;
88 
89  $r++;
90  $this->rights[$r][0] = 251;
91  $this->rights[$r][1] = 'Consulter les autres utilisateurs';
92  $this->rights[$r][2] = 'r';
93  $this->rights[$r][3] = 0;
94  $this->rights[$r][4] = 'user';
95  $this->rights[$r][5] = 'lire';
96 
97  $r++;
98  $this->rights[$r][0] = 252;
99  $this->rights[$r][1] = 'Consulter les permissions des autres utilisateurs';
100  $this->rights[$r][2] = 'r';
101  $this->rights[$r][3] = 0;
102  $this->rights[$r][4] = 'user_advance';
103  $this->rights[$r][5] = 'readperms';
104 
105  $r++;
106  $this->rights[$r][0] = 253;
107  $this->rights[$r][1] = 'Creer/modifier utilisateurs internes et externes';
108  $this->rights[$r][2] = 'w';
109  $this->rights[$r][3] = 0;
110  $this->rights[$r][4] = 'user';
111  $this->rights[$r][5] = 'creer';
112 
113  $r++;
114  $this->rights[$r][0] = 254;
115  $this->rights[$r][1] = 'Creer/modifier utilisateurs externes seulement';
116  $this->rights[$r][2] = 'w';
117  $this->rights[$r][3] = 0;
118  $this->rights[$r][4] = 'user_advance';
119  $this->rights[$r][5] = 'write';
120 
121  $r++;
122  $this->rights[$r][0] = 255;
123  $this->rights[$r][1] = 'Modifier le mot de passe des autres utilisateurs';
124  $this->rights[$r][2] = 'w';
125  $this->rights[$r][3] = 0;
126  $this->rights[$r][4] = 'user';
127  $this->rights[$r][5] = 'password';
128 
129  $r++;
130  $this->rights[$r][0] = 256;
131  $this->rights[$r][1] = 'Supprimer ou desactiver les autres utilisateurs';
132  $this->rights[$r][2] = 'd';
133  $this->rights[$r][3] = 0;
134  $this->rights[$r][4] = 'user';
135  $this->rights[$r][5] = 'supprimer';
136 
137  $r++;
138  $this->rights[$r][0] = 341;
139  $this->rights[$r][1] = 'Consulter ses propres permissions';
140  $this->rights[$r][2] = 'r';
141  $this->rights[$r][3] = 0;
142  $this->rights[$r][4] = 'self_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
143  $this->rights[$r][5] = 'readperms';
144 
145  $r++;
146  $this->rights[$r][0] = 342;
147  $this->rights[$r][1] = 'Creer/modifier ses propres infos utilisateur';
148  $this->rights[$r][2] = 'w';
149  $this->rights[$r][3] = 0;
150  $this->rights[$r][4] = 'self';
151  $this->rights[$r][5] = 'creer';
152 
153  $r++;
154  $this->rights[$r][0] = 343;
155  $this->rights[$r][1] = 'Modifier son propre mot de passe';
156  $this->rights[$r][2] = 'w';
157  $this->rights[$r][3] = 0;
158  $this->rights[$r][4] = 'self';
159  $this->rights[$r][5] = 'password';
160 
161  $r++;
162  $this->rights[$r][0] = 344;
163  $this->rights[$r][1] = 'Modifier ses propres permissions';
164  $this->rights[$r][2] = 'w';
165  $this->rights[$r][3] = 0;
166  $this->rights[$r][4] = 'self_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
167  $this->rights[$r][5] = 'writeperms';
168 
169  $r++;
170  $this->rights[$r][0] = 351;
171  $this->rights[$r][1] = 'Consulter les groupes';
172  $this->rights[$r][2] = 'r';
173  $this->rights[$r][3] = 0;
174  $this->rights[$r][4] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
175  $this->rights[$r][5] = 'read';
176 
177  $r++;
178  $this->rights[$r][0] = 352;
179  $this->rights[$r][1] = 'Consulter les permissions des groupes';
180  $this->rights[$r][2] = 'r';
181  $this->rights[$r][3] = 0;
182  $this->rights[$r][4] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
183  $this->rights[$r][5] = 'readperms';
184 
185  $r++;
186  $this->rights[$r][0] = 353;
187  $this->rights[$r][1] = 'Creer/modifier les groupes et leurs permissions';
188  $this->rights[$r][2] = 'w';
189  $this->rights[$r][3] = 0;
190  $this->rights[$r][4] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
191  $this->rights[$r][5] = 'write';
192 
193  $r++;
194  $this->rights[$r][0] = 354;
195  $this->rights[$r][1] = 'Supprimer ou desactiver les groupes';
196  $this->rights[$r][2] = 'd';
197  $this->rights[$r][3] = 0;
198  $this->rights[$r][4] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
199  $this->rights[$r][5] = 'delete';
200 
201  $r++;
202  $this->rights[$r][0] = 358;
203  $this->rights[$r][1] = 'Exporter les utilisateurs';
204  $this->rights[$r][2] = 'r';
205  $this->rights[$r][3] = 0;
206  $this->rights[$r][4] = 'user';
207  $this->rights[$r][5] = 'export';
208 
209 
210  // Menus
211  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
212 
213 
214  // Exports
215  $r=0;
216 
217  $r++;
218  $this->export_code[$r]=$this->rights_class.'_'.$r;
219  $this->export_label[$r]='List of users and attributes';
220  $this->export_permission[$r]=array(array("user","user","export"));
221  $this->export_fields_array[$r]=array(
222  'u.rowid'=>"Id",'u.login'=>"Login",'u.lastname'=>"Lastname",'u.firstname'=>"Firstname",'u.employee'=>"Employee",'u.job'=>"PostOrFunction",'u.gender'=>"Gender",
223  'u.accountancy_code'=>"UserAccountancyCode",
224  'u.address'=>"Address",'u.zip'=>"Zip",'u.town'=>"Town",
225  'u.office_phone'=>'Phone','u.user_mobile'=>"Mobile",'u.office_fax'=>'Fax',
226  'u.email'=>"Email",'u.note'=>"Note",'u.signature'=>'Signature',
227  'u.fk_user'=>'Supervisor','u.thm'=>'THM','u.tjm'=>'TJM','u.weeklyhours'=>'WeeklyHours',
228  'u.dateemployment'=>'DateEmployment','u.salary'=>'Salary','u.color'=>'Color','u.api_key'=>'ApiKey',
229  'u.birth'=>'BirthdayDate',
230  'u.datec'=>"DateCreation",'u.tms'=>"DateLastModification",
231  'u.admin'=>"Administrator",'u.statut'=>'Status','u.datelastlogin'=>'LastConnexion','u.datepreviouslogin'=>'PreviousConnexion',
232  'u.fk_socpeople'=>"IdContact",'u.fk_soc'=>"IdCompany",'u.fk_member'=>"MemberId"
233  );
234  $this->export_TypeFields_array[$r]=array(
235  'u.login'=>"Text",'u.lastname'=>"Text",'u.firstname'=>"Text",'u.employee'=>'Boolean','u.job'=>'Text',
236  'u.accountancy_code'=>'Text',
237  'u.address'=>"Text",'u.zip'=>"Text",'u.town'=>"Text",
238  'u.office_phone'=>'Text','u.user_mobile'=>'Text','u.office_fax'=>'Text',
239  'u.email'=>'Text','u.datec'=>"Date",'u.tms'=>"Date",'u.admin'=>"Boolean",'u.statut'=>'Status','u.note'=>"Text",'u.datelastlogin'=>'Date',
240  'u.fk_user'=>"List:user:login",
241  'u.birth'=>'Date',
242  'u.datepreviouslogin'=>'Date','u.fk_soc'=>"List:societe:nom:rowid",'u.fk_member'=>"List:adherent:firstname"
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'=>"user",'u.signature'=>'user',
250  'u.fk_user'=>'user','u.thm'=>'user','u.tjm'=>'user','u.weeklyhours'=>'user',
251  'u.dateemployment'=>'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  );
257  if (empty($conf->adherent->enabled))
258  {
259  unset($this->export_fields_array[$r]['u.fk_member']);
260  unset($this->export_entities_array[$r]['u.fk_member']);
261  }
262  $this->export_sql_start[$r]='SELECT DISTINCT ';
263  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'user as u';
264  $this->export_sql_end[$r] .=' WHERE u.entity IN ('.getEntity('user').')';
265 
266  // Imports
267  $r=0;
268 
269  // Import list of users attributes
270  $r++;
271  $this->import_code[$r]=$this->rights_class.'_'.$r;
272  $this->import_label[$r]='ImportDataset_user_1';
273  $this->import_icon[$r]='user';
274  $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
275  $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)
276  $this->import_fields_array[$r]=array(
277  'u.login'=>"Login*",'u.lastname'=>"Name*",'u.firstname'=>"Firstname",'u.employee'=>"Employee*",'u.job'=>"PostOrFunction",'u.gender'=>"Gender",
278  'u.accountancy_code'=>"UserAccountancyCode",
279  'u.pass_crypted'=>"Password",'u.admin'=>"Administrator",'u.fk_soc'=>"Company*",'u.address'=>"Address",'u.zip'=>"Zip",'u.town'=>"Town",
280  'u.fk_state'=>"StateId",'u.fk_country'=>"CountryCode",
281  'u.office_phone'=>"Phone",'u.user_mobile'=>"Mobile",'u.office_fax'=>"Fax",
282  'u.email'=>"Email",'u.note'=>"Note",'u.signature'=>'Signature',
283  'u.fk_user'=>'Supervisor','u.thm'=>'THM','u.tjm'=>'TJM','u.weeklyhours'=>'WeeklyHours',
284  'u.dateemployment'=>'DateEmployment','u.salary'=>'Salary','u.color'=>'Color','u.api_key'=>'ApiKey',
285  'u.birth'=>'BirthdayDate',
286  'u.datec'=>"DateCreation",
287  'u.statut'=>'Status'
288  );
289  // Add extra fields
290  $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'user' AND entity IN (0,".$conf->entity.")";
291  $resql=$this->db->query($sql);
292  if ($resql) // This can fail when class is used on old database (during migration for example)
293  {
294  while ($obj=$this->db->fetch_object($resql))
295  {
296  $fieldname='extra.'.$obj->name;
297  $fieldlabel=ucfirst($obj->label);
298  $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
299  }
300  }
301  // End add extra fields
302  $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)
303  $this->import_convertvalue_array[$r]=array(
304  'u.fk_state'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cstate.class.php','class'=>'Cstate','method'=>'fetch','dict'=>'DictionaryState'),
305  'u.fk_country'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'),
306  'u.salary'=>array('rule'=>'numeric')
307  );
308  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
309  $this->import_regex_array[$r]=array(
310  'u.employee'=>'^[0|1]',
311  '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])?$',
312  'u.dateemployment'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
313  'u.birth'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'
314  );
315  $this->import_examplevalues_array[$r]=array(
316  'u.lastname'=>"Doe",'u.firstname'=>'John','u.login'=>'jdoe','u.employee'=>'0 or 1',
317  '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",
318  'u.zip'=>"123456",'u.town'=>"Big town",'u.fk_country'=>'US, FR, DE...','u.office_phone'=>"0101010101",'u.office_fax'=>"0101010102",
319  '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",
320  'u.statut'=>"0 (closed) or 1 (active)",
321  );
322  $this->import_updatekeys_array[$r]=array('u.lastname'=>'Lastname','u.firstname'=>'Firstname','u.login'=>'Login');
323  }
324 
325 
334  function init($options='')
335  {
336  global $conf;
337 
338  // Permissions
339  $this->remove($options);
340 
341  $sql = array();
342 
343  return $this->_init($sql,$options);
344  }
345 }
Class DolibarrModules.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
Class to describe and enable module User.
init($options='')
Function called when module is enabled.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
__construct($db)
Constructor.
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
_init($array_sql, $options='')
Enables a module.