dolibarr  7.0.0-beta
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@capnetworks.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->special = 0;
59  $this->picto='group';
60 
61  // Data directories to create when module is enabled
62  $this->dirs = array("/users/temp");
63 
64  // Config pages
65  $this->config_page_url = array("user.php");
66 
67  // Dependancies
68  $this->depends = array();
69  $this->requiredby = array();
70  $this->langfiles = array("main","users","companies","members",'salaries');
71  $this->always_enabled = true; // Can't be disabled
72 
73  // Constants
74  $this->const = array();
75 
76  // Boxes
77  $this->boxes = array(
78  0=>array('file'=>'box_lastlogin.php','enabledbydefaulton'=>'Home'),
79  );
80 
81  // Permissions
82  $this->rights = array();
83  $this->rights_class = 'user';
84  $this->rights_admin_allowed = 1; // Admin is always granted of permission (even when module is disabled)
85  $r=0;
86 
87  $r++;
88  $this->rights[$r][0] = 251;
89  $this->rights[$r][1] = 'Consulter les autres utilisateurs';
90  $this->rights[$r][2] = 'r';
91  $this->rights[$r][3] = 0;
92  $this->rights[$r][4] = 'user';
93  $this->rights[$r][5] = 'lire';
94 
95  $r++;
96  $this->rights[$r][0] = 252;
97  $this->rights[$r][1] = 'Consulter les permissions des autres utilisateurs';
98  $this->rights[$r][2] = 'r';
99  $this->rights[$r][3] = 0;
100  $this->rights[$r][4] = 'user_advance';
101  $this->rights[$r][5] = 'readperms';
102 
103  $r++;
104  $this->rights[$r][0] = 253;
105  $this->rights[$r][1] = 'Creer/modifier utilisateurs internes et externes';
106  $this->rights[$r][2] = 'w';
107  $this->rights[$r][3] = 0;
108  $this->rights[$r][4] = 'user';
109  $this->rights[$r][5] = 'creer';
110 
111  $r++;
112  $this->rights[$r][0] = 254;
113  $this->rights[$r][1] = 'Creer/modifier utilisateurs externes seulement';
114  $this->rights[$r][2] = 'w';
115  $this->rights[$r][3] = 0;
116  $this->rights[$r][4] = 'user_advance';
117  $this->rights[$r][5] = 'write';
118 
119  $r++;
120  $this->rights[$r][0] = 255;
121  $this->rights[$r][1] = 'Modifier le mot de passe des autres utilisateurs';
122  $this->rights[$r][2] = 'w';
123  $this->rights[$r][3] = 0;
124  $this->rights[$r][4] = 'user';
125  $this->rights[$r][5] = 'password';
126 
127  $r++;
128  $this->rights[$r][0] = 256;
129  $this->rights[$r][1] = 'Supprimer ou desactiver les autres utilisateurs';
130  $this->rights[$r][2] = 'd';
131  $this->rights[$r][3] = 0;
132  $this->rights[$r][4] = 'user';
133  $this->rights[$r][5] = 'supprimer';
134 
135  $r++;
136  $this->rights[$r][0] = 341;
137  $this->rights[$r][1] = 'Consulter ses propres permissions';
138  $this->rights[$r][2] = 'r';
139  $this->rights[$r][3] = 0;
140  $this->rights[$r][4] = 'self_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
141  $this->rights[$r][5] = 'readperms';
142 
143  $r++;
144  $this->rights[$r][0] = 342;
145  $this->rights[$r][1] = 'Creer/modifier ses propres infos utilisateur';
146  $this->rights[$r][2] = 'w';
147  $this->rights[$r][3] = 0;
148  $this->rights[$r][4] = 'self';
149  $this->rights[$r][5] = 'creer';
150 
151  $r++;
152  $this->rights[$r][0] = 343;
153  $this->rights[$r][1] = 'Modifier son propre mot de passe';
154  $this->rights[$r][2] = 'w';
155  $this->rights[$r][3] = 0;
156  $this->rights[$r][4] = 'self';
157  $this->rights[$r][5] = 'password';
158 
159  $r++;
160  $this->rights[$r][0] = 344;
161  $this->rights[$r][1] = 'Modifier ses propres permissions';
162  $this->rights[$r][2] = 'w';
163  $this->rights[$r][3] = 0;
164  $this->rights[$r][4] = 'self_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
165  $this->rights[$r][5] = 'writeperms';
166 
167  $r++;
168  $this->rights[$r][0] = 351;
169  $this->rights[$r][1] = 'Consulter les groupes';
170  $this->rights[$r][2] = 'r';
171  $this->rights[$r][3] = 0;
172  $this->rights[$r][4] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
173  $this->rights[$r][5] = 'read';
174 
175  $r++;
176  $this->rights[$r][0] = 352;
177  $this->rights[$r][1] = 'Consulter les permissions des groupes';
178  $this->rights[$r][2] = 'r';
179  $this->rights[$r][3] = 0;
180  $this->rights[$r][4] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
181  $this->rights[$r][5] = 'readperms';
182 
183  $r++;
184  $this->rights[$r][0] = 353;
185  $this->rights[$r][1] = 'Creer/modifier les groupes et leurs permissions';
186  $this->rights[$r][2] = 'w';
187  $this->rights[$r][3] = 0;
188  $this->rights[$r][4] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
189  $this->rights[$r][5] = 'write';
190 
191  $r++;
192  $this->rights[$r][0] = 354;
193  $this->rights[$r][1] = 'Supprimer ou desactiver les groupes';
194  $this->rights[$r][2] = 'd';
195  $this->rights[$r][3] = 0;
196  $this->rights[$r][4] = 'group_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
197  $this->rights[$r][5] = 'delete';
198 
199  $r++;
200  $this->rights[$r][0] = 358;
201  $this->rights[$r][1] = 'Exporter les utilisateurs';
202  $this->rights[$r][2] = 'r';
203  $this->rights[$r][3] = 0;
204  $this->rights[$r][4] = 'user';
205  $this->rights[$r][5] = 'export';
206 
207 
208  // Menus
209  //-------
210 
211  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
212 
213 
214  // Exports
215  //--------
216  $r=0;
217 
218  $r++;
219  $this->export_code[$r]=$this->rights_class.'_'.$r;
220  $this->export_label[$r]='Liste des utilisateurs Dolibarr et attributs';
221  $this->export_permission[$r]=array(array("user","user","export"));
222  $this->export_fields_array[$r]=array('u.rowid'=>"Id",'u.login'=>"Login",'u.lastname'=>"Lastname",'u.firstname'=>"Firstname",'u.accountancy_code'=>"UserAccountancyCode",'u.office_phone'=>'Phone','u.office_fax'=>'Fax','u.email'=>'EMail','u.datec'=>"DateCreation",'u.tms'=>"DateLastModification",'u.admin'=>"Administrator",'u.statut'=>'Status','u.note'=>"Note",'u.datelastlogin'=>'LastConnexion','u.datepreviouslogin'=>'PreviousConnexion','u.fk_socpeople'=>"IdContact",'u.fk_soc'=>"IdCompany",'u.fk_member'=>"MemberId");
223  $this->export_TypeFields_array[$r]=array('u.login'=>"Text",'u.lastname'=>"Text",'u.firstname'=>"Text",'u.accountancy_code'=>'Text','u.office_phone'=>'Text','u.office_fax'=>'Text','u.email'=>'Text','u.datec'=>"Date",'u.tms'=>"Date",'u.admin'=>"Boolean",'u.statut'=>'Status','u.note'=>"Text",'u.datelastlogin'=>'Date','u.datepreviouslogin'=>'Date','u.fk_soc'=>"List:societe:nom:rowid",'u.fk_member'=>"List:adherent:firstname");
224  $this->export_entities_array[$r]=array('u.rowid'=>"user",'u.login'=>"user",'u.lastname'=>"user",'u.firstname'=>"user",'u.accountancy_code'=>'user','u.office_phone'=>'user','u.office_fax'=>'user','u.email'=>'user','u.datec'=>"user",'u.tms'=>"user",'u.admin'=>"user",'u.statut'=>'user','u.note'=>"user",'u.datelastlogin'=>'user','u.datepreviouslogin'=>'user','u.fk_socpeople'=>"contact",'u.fk_soc'=>"company",'u.fk_member'=>"member");
225  if (empty($conf->adherent->enabled))
226  {
227  unset($this->export_fields_array[$r]['u.fk_member']);
228  unset($this->export_entities_array[$r]['u.fk_member']);
229  }
230  $this->export_sql_start[$r]='SELECT DISTINCT ';
231  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'user as u';
232  $this->export_sql_end[$r] .=' WHERE u.entity IN ('.getEntity('user').')';
233 
234  // Imports
235  //--------
236  $r=0;
237 
238  // Import list of users attributes
239  $r++;
240  $this->import_code[$r]=$this->rights_class.'_'.$r;
241  $this->import_label[$r]='ImportDataset_user_1';
242  $this->import_icon[$r]='user';
243  $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
244  $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)
245  $this->import_fields_array[$r]=array('u.lastname'=>"Name*",'u.firstname'=>"Firstname",'u.employee'=>"Employee*",'u.job'=>"Job",'u.gender'=>"Gender",'u.login'=>"Login*",'u.pass_crypted'=>"Password",'u.admin'=>"Administrator",'u.fk_soc'=>"Company*",'u.address'=>"Address",'u.zip'=>"Zip",'u.town'=>"Town",'u.fk_state'=>"StateId",'u.fk_country'=>"CountryCode",'u.office_phone'=>"Phone",'u.user_mobile'=>"Mobile",'u.office_fax'=>"Fax",'u.email'=>"Email",'u.note'=>"Note",'u.signature'=>'Signature','u.fk_user'=>'Supervisor','u.thm'=>'THM','u.tjm'=>'TJM','u.dateemployment'=>'DateEmployment','u.salary'=>'Salary','u.color'=>'Color','u.api_key'=>'ApiKey','u.datec'=>"DateCreation");
246  // Add extra fields
247  $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'user' AND entity = ".$conf->entity;
248  $resql=$this->db->query($sql);
249  if ($resql) // This can fail when class is used on old database (during migration for example)
250  {
251  while ($obj=$this->db->fetch_object($resql))
252  {
253  $fieldname='extra.'.$obj->name;
254  $fieldlabel=ucfirst($obj->label);
255  $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
256  }
257  }
258  // End add extra fields
259  $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)
260  $this->import_convertvalue_array[$r]=array(
261  'u.fk_state'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cstate.class.php','class'=>'Cstate','method'=>'fetch','dict'=>'DictionaryState'),
262  'u.fk_country'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'),
263  'u.salary'=>array('rule'=>'numeric')
264  );
265  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
266  $this->import_regex_array[$r]=array('u.employee'=>'^[0|1]','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])?$');
267  $this->import_examplevalues_array[$r]=array('u.lastname'=>"Doe",'u.firstname'=>'John','u.login'=>'jdoe','u.employee'=>'0 or 1','u.status'=>"0 (closed) or 1 (active)",'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",'u.zip'=>"123456",'u.town'=>"Big town",'u.fk_country'=>'US, FR, DE...','u.office_phone'=>"0101010101",'u.office_fax'=>"0101010102",'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");
268  $this->import_updatekeys_array[$r]=array('u.lastname'=>'Lastname','u.firstname'=>'Firstname','u.login'=>'Login');
269 
270  }
271 
272 
281  function init($options='')
282  {
283  global $conf;
284 
285  // Permissions
286  $this->remove($options);
287 
288  $sql = array();
289 
290  return $this->_init($sql,$options);
291  }
292 }
Class DolibarrModules.
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="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< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></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:554
Class to describe and enable module User.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
dol_now($mode='gmt')
Return date for now.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
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.
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:1013