2005-08-23 13:13:03 +02:00
< ? php
2006-03-31 23:36:50 +02:00
/* Copyright ( C ) 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2009-04-10 02:29:23 +02:00
* Copyright ( C ) 2005 - 2009 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2005-08-23 13:13:03 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2005-08-23 13:13:03 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2005-08-23 13:13:03 +02:00
*/
/**
2009-07-30 00:52:08 +02:00
* \defgroup user Module user management
2008-12-05 00:06:45 +01:00
* \brief Module pour gerer les utilisateurs
2011-10-24 14:11:49 +02:00
* \file htdocs / core / modules / modUser . class . php
2008-12-05 00:06:45 +01:00
* \ingroup user
2021-03-20 13:55:43 +01:00
* \brief Description and activation file for the module users
2008-10-01 21:10:17 +02:00
*/
2005-08-23 13:13:03 +02:00
2020-01-18 16:17:07 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php' ;
2005-08-23 13:13:03 +02:00
/**
2015-09-07 15:55:26 +02:00
* Class to describe and enable module User
2008-10-01 21:10:17 +02:00
*/
2005-08-23 13:13:03 +02:00
class modUser extends DolibarrModules
{
2008-10-01 21:10:17 +02:00
/**
2011-09-26 16:22:35 +02:00
* Constructor . Define names , constants , directories , boxes , permissions
*
2012-01-04 21:23:50 +01:00
* @ param DoliDB $db Database handler
2008-10-01 21:10:17 +02:00
*/
2019-02-25 20:35:59 +01:00
public function __construct ( $db )
2008-10-01 21:10:17 +02:00
{
2009-04-28 11:41:30 +02:00
global $conf ;
2009-05-04 13:40:00 +02:00
2012-01-04 21:23:50 +01:00
$this -> db = $db ;
2008-10-01 21:10:17 +02:00
$this -> numero = 0 ;
2020-01-18 16:17:07 +01:00
$this -> family = " hr " ; // Family for module (or "base" if core module)
2019-06-21 13:25:40 +02:00
$this -> module_position = '05' ;
2008-10-01 21:10:17 +02:00
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
2019-01-27 11:55:16 +01:00
$this -> name = preg_replace ( '/^mod/i' , '' , get_class ( $this ));
2021-10-28 14:28:04 +02:00
$this -> description = " Management of users and groups of users (mandatory) " ;
2008-10-01 21:10:17 +02:00
2008-12-15 23:25:59 +01:00
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
$this -> version = 'dolibarr' ;
2009-04-10 02:29:23 +02:00
2008-10-06 09:39:52 +02:00
$this -> const_name = 'MAIN_MODULE_' . strtoupper ( $this -> name );
2020-01-18 16:17:07 +01:00
$this -> picto = 'group' ;
2008-10-01 21:10:17 +02:00
2009-04-28 23:18:28 +02:00
// Data directories to create when module is enabled
2010-02-11 09:32:49 +01:00
$this -> dirs = array ( " /users/temp " );
2008-10-01 21:10:17 +02:00
// Config pages
2010-03-31 08:23:28 +02:00
$this -> config_page_url = array ( " user.php " );
2008-10-01 21:10:17 +02:00
2018-07-10 22:32:55 +02:00
// Dependencies
2020-01-18 16:17:07 +01:00
$this -> hidden = false ; // A condition to hide module
$this -> depends = array (); // List of module class names as string that must be enabled if this module is enabled
$this -> requiredby = array (); // List of module ids to disable if this one is disabled
$this -> conflictwith = array (); // List of module class names as string this module is in conflict with
2022-09-27 20:48:47 +02:00
$this -> phpmin = array ( 7 , 0 ); // Minimum version of PHP required by module
2020-01-18 16:17:07 +01:00
$this -> langfiles = array ( " main " , " users " , " companies " , " members " , " salaries " , " hrm " );
$this -> always_enabled = true ; // Can't be disabled
2008-10-01 21:10:17 +02:00
2009-05-04 13:40:00 +02:00
// Constants
2008-10-01 21:10:17 +02:00
$this -> const = array ();
2009-05-04 13:40:00 +02:00
// Boxes
2017-02-21 11:57:52 +01:00
$this -> boxes = array (
2020-10-31 14:32:18 +01:00
0 => array ( 'file' => 'box_lastlogin.php' , 'enabledbydefaulton' => 'Home' ),
2020-12-01 14:50:12 +01:00
1 => array ( 'file' => 'box_birthdays.php' , 'enabledbydefaulton' => 'Home' ),
2 => array ( 'file' => 'box_dolibarr_state_board.php' , 'enabledbydefaulton' => 'Home' )
2017-02-21 11:57:52 +01:00
);
2008-10-01 21:10:17 +02:00
// Permissions
$this -> rights = array ();
$this -> rights_class = 'user' ;
2020-01-18 16:17:07 +01:00
$this -> rights_admin_allowed = 1 ; // Admin is always granted of permission (even when module is disabled)
$r = 0 ;
2008-10-01 21:10:17 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 251 ;
2021-10-28 14:28:04 +02:00
$this -> rights [ $r ][ 1 ] = 'Read information of other users, groups and permissions' ;
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 2 ] = 'r' ;
2010-09-19 12:55:35 +02:00
$this -> rights [ $r ][ 3 ] = 0 ;
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 4 ] = 'user' ;
$this -> rights [ $r ][ 5 ] = 'lire' ;
2010-11-07 18:45:51 +01:00
2008-10-01 21:10:17 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 252 ;
2021-10-21 22:31:51 +02:00
$this -> rights [ $r ][ 1 ] = 'Read permissions of other users' ;
2010-10-28 21:31:11 +02:00
$this -> rights [ $r ][ 2 ] = 'r' ;
$this -> rights [ $r ][ 3 ] = 0 ;
2021-10-28 14:28:04 +02:00
$this -> rights [ $r ][ 4 ] = 'user_advance' ; // Visible if option MAIN_USE_ADVANCED_PERMS is on
2010-10-28 21:31:11 +02:00
$this -> rights [ $r ][ 5 ] = 'readperms' ;
2010-11-07 18:45:51 +01:00
2010-10-28 21:31:11 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 253 ;
2021-10-28 14:28:04 +02:00
$this -> rights [ $r ][ 1 ] = 'Create/modify internal and external users, groups and permissions' ;
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 2 ] = 'w' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'user' ;
$this -> rights [ $r ][ 5 ] = 'creer' ;
2011-02-02 21:41:54 +01:00
2008-10-01 21:10:17 +02:00
$r ++ ;
2010-10-28 21:31:11 +02:00
$this -> rights [ $r ][ 0 ] = 254 ;
2021-10-21 22:31:51 +02:00
$this -> rights [ $r ][ 1 ] = 'Create/modify external users only' ;
2010-11-08 18:21:52 +01:00
$this -> rights [ $r ][ 2 ] = 'w' ;
$this -> rights [ $r ][ 3 ] = 0 ;
2021-10-28 14:28:04 +02:00
$this -> rights [ $r ][ 4 ] = 'user_advance' ; // Visible if option MAIN_USE_ADVANCED_PERMS is on
2010-11-08 18:21:52 +01:00
$this -> rights [ $r ][ 5 ] = 'write' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 255 ;
2021-10-21 22:31:51 +02:00
$this -> rights [ $r ][ 1 ] = 'Modify the password of other users' ;
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 2 ] = 'w' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'user' ;
$this -> rights [ $r ][ 5 ] = 'password' ;
$r ++ ;
2010-11-08 18:21:52 +01:00
$this -> rights [ $r ][ 0 ] = 256 ;
2021-10-21 22:31:51 +02:00
$this -> rights [ $r ][ 1 ] = 'Delete or disable other users' ;
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 2 ] = 'd' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'user' ;
$this -> rights [ $r ][ 5 ] = 'supprimer' ;
2010-11-07 18:45:51 +01:00
2008-10-01 21:10:17 +02:00
$r ++ ;
2010-11-08 18:21:52 +01:00
$this -> rights [ $r ][ 0 ] = 341 ;
2021-10-21 22:31:51 +02:00
$this -> rights [ $r ][ 1 ] = 'Read its own permissions' ;
2010-10-29 07:38:33 +02:00
$this -> rights [ $r ][ 2 ] = 'r' ;
2016-06-04 12:16:30 +02:00
$this -> rights [ $r ][ 3 ] = 0 ;
2020-01-18 16:17:07 +01:00
$this -> rights [ $r ][ 4 ] = 'self_advance' ; // Visible if option MAIN_USE_ADVANCED_PERMS is on
2010-10-29 07:38:33 +02:00
$this -> rights [ $r ][ 5 ] = 'readperms' ;
2010-11-07 18:45:51 +01:00
2010-10-29 07:38:33 +02:00
$r ++ ;
2010-11-08 18:21:52 +01:00
$this -> rights [ $r ][ 0 ] = 342 ;
2021-10-21 22:31:51 +02:00
$this -> rights [ $r ][ 1 ] = 'Create/modify of its own user' ;
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 2 ] = 'w' ;
2016-06-04 12:16:30 +02:00
$this -> rights [ $r ][ 3 ] = 0 ;
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 4 ] = 'self' ;
$this -> rights [ $r ][ 5 ] = 'creer' ;
$r ++ ;
2010-11-08 18:21:52 +01:00
$this -> rights [ $r ][ 0 ] = 343 ;
2021-10-21 22:31:51 +02:00
$this -> rights [ $r ][ 1 ] = 'Modify its own password' ;
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 2 ] = 'w' ;
2016-06-04 12:16:30 +02:00
$this -> rights [ $r ][ 3 ] = 0 ;
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 4 ] = 'self' ;
$this -> rights [ $r ][ 5 ] = 'password' ;
2010-11-07 18:45:51 +01:00
2008-10-01 21:10:17 +02:00
$r ++ ;
2010-11-08 18:21:52 +01:00
$this -> rights [ $r ][ 0 ] = 344 ;
2021-10-21 22:31:51 +02:00
$this -> rights [ $r ][ 1 ] = 'Modify its own permissions' ;
2010-10-28 21:31:11 +02:00
$this -> rights [ $r ][ 2 ] = 'w' ;
2016-06-04 12:16:30 +02:00
$this -> rights [ $r ][ 3 ] = 0 ;
2020-01-18 16:17:07 +01:00
$this -> rights [ $r ][ 4 ] = 'self_advance' ; // Visible if option MAIN_USE_ADVANCED_PERMS is on
2010-10-28 21:31:11 +02:00
$this -> rights [ $r ][ 5 ] = 'writeperms' ;
2010-11-07 18:45:51 +01:00
2010-10-28 21:31:11 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 351 ;
2021-10-28 14:28:04 +02:00
$this -> rights [ $r ][ 1 ] = 'Read groups' ;
2010-10-28 21:31:11 +02:00
$this -> rights [ $r ][ 2 ] = 'r' ;
$this -> rights [ $r ][ 3 ] = 0 ;
2020-01-18 16:17:07 +01:00
$this -> rights [ $r ][ 4 ] = 'group_advance' ; // Visible if option MAIN_USE_ADVANCED_PERMS is on
2010-10-28 21:31:11 +02:00
$this -> rights [ $r ][ 5 ] = 'read' ;
2010-11-07 18:45:51 +01:00
2010-10-28 21:31:11 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 352 ;
2021-10-28 14:28:04 +02:00
$this -> rights [ $r ][ 1 ] = 'Read permissions of groups' ;
2010-10-28 21:31:11 +02:00
$this -> rights [ $r ][ 2 ] = 'r' ;
$this -> rights [ $r ][ 3 ] = 0 ;
2020-01-18 16:17:07 +01:00
$this -> rights [ $r ][ 4 ] = 'group_advance' ; // Visible if option MAIN_USE_ADVANCED_PERMS is on
2010-10-28 21:31:11 +02:00
$this -> rights [ $r ][ 5 ] = 'readperms' ;
2010-11-07 18:45:51 +01:00
2010-10-28 21:31:11 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 353 ;
2021-10-28 14:28:04 +02:00
$this -> rights [ $r ][ 1 ] = 'Create/modify groups and permissions' ;
2010-10-28 21:31:11 +02:00
$this -> rights [ $r ][ 2 ] = 'w' ;
$this -> rights [ $r ][ 3 ] = 0 ;
2020-01-18 16:17:07 +01:00
$this -> rights [ $r ][ 4 ] = 'group_advance' ; // Visible if option MAIN_USE_ADVANCED_PERMS is on
2010-10-28 21:31:11 +02:00
$this -> rights [ $r ][ 5 ] = 'write' ;
2010-11-07 18:45:51 +01:00
2010-10-28 21:31:11 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 354 ;
2021-10-28 14:28:04 +02:00
$this -> rights [ $r ][ 1 ] = 'Delete groups' ;
2010-10-28 21:31:11 +02:00
$this -> rights [ $r ][ 2 ] = 'd' ;
$this -> rights [ $r ][ 3 ] = 0 ;
2020-01-18 16:17:07 +01:00
$this -> rights [ $r ][ 4 ] = 'group_advance' ; // Visible if option MAIN_USE_ADVANCED_PERMS is on
2010-10-28 21:31:11 +02:00
$this -> rights [ $r ][ 5 ] = 'delete' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 358 ;
2021-10-21 22:31:51 +02:00
$this -> rights [ $r ][ 1 ] = 'Export all users' ;
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 2 ] = 'r' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'user' ;
$this -> rights [ $r ][ 5 ] = 'export' ;
2017-12-08 16:15:41 +01:00
2020-10-31 14:32:18 +01:00
// Menus
$this -> menu = 1 ; // This module add menu entries. They are coded into menu manager.
2017-12-08 16:15:41 +01:00
2008-10-01 21:10:17 +02:00
// Exports
2020-01-18 16:17:07 +01:00
$r = 0 ;
2008-10-01 21:10:17 +02:00
$r ++ ;
2020-01-18 16:17:07 +01:00
$this -> export_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> export_label [ $r ] = 'List of users and attributes' ;
$this -> export_permission [ $r ] = array ( array ( " user " , " user " , " export " ));
$this -> export_fields_array [ $r ] = array (
2020-10-31 14:32:18 +01:00
'u.rowid' => " Id " , 'u.login' => " Login " , 'u.lastname' => " Lastname " , 'u.firstname' => " Firstname " , 'u.employee' => " Employee " , 'u.job' => " PostOrFunction " , 'u.gender' => " Gender " ,
'u.accountancy_code' => " UserAccountancyCode " ,
'u.address' => " Address " , 'u.zip' => " Zip " , 'u.town' => " Town " ,
'u.office_phone' => 'Phone' , 'u.user_mobile' => " Mobile " , 'u.office_fax' => 'Fax' ,
2022-09-06 04:48:26 +02:00
'u.email' => " Email " , 'u.note_public' => " NotePublic " , 'u.note_private' => " NotePrivate " , 'u.signature' => 'Signature' ,
2020-10-31 14:32:18 +01:00
'u.fk_user' => 'HierarchicalResponsible' , 'u.thm' => 'THM' , 'u.tjm' => 'TJM' , 'u.weeklyhours' => 'WeeklyHours' ,
2022-05-17 00:50:59 +02:00
'u.dateemployment' => 'DateEmploymentStart' , 'u.dateemploymentend' => 'DateEmploymentEnd' , 'u.salary' => 'Salary' , 'u.color' => 'Color' , 'u.api_key' => 'ApiKey' ,
2020-10-31 14:32:18 +01:00
'u.birth' => 'DateOfBirth' ,
'u.datec' => " DateCreation " , 'u.tms' => " DateLastModification " ,
2020-01-18 16:17:07 +01:00
'u.admin' => " Administrator " , 'u.statut' => 'Status' , 'u.datelastlogin' => 'LastConnexion' , 'u.datepreviouslogin' => 'PreviousConnexion' ,
2022-05-17 00:50:59 +02:00
'u.fk_socpeople' => " IdContact " , 'u.fk_soc' => " IdCompany " ,
'u.fk_member' => " MemberId " ,
" a.firstname " => " MemberFirstname " ,
" a.lastname " => " MemberLastname " ,
2021-04-14 09:44:01 +02:00
'g.nom' => " Group "
2018-05-27 15:04:12 +02:00
);
2020-01-18 16:17:07 +01:00
$this -> export_TypeFields_array [ $r ] = array (
'u.rowid' => 'Numeric' , 'u.login' => " Text " , 'u.lastname' => " Text " , 'u.firstname' => " Text " , 'u.employee' => 'Boolean' , 'u.job' => 'Text' ,
2020-10-31 14:32:18 +01:00
'u.accountancy_code' => 'Text' ,
'u.address' => " Text " , 'u.zip' => " Text " , 'u.town' => " Text " ,
'u.office_phone' => 'Text' , 'u.user_mobile' => 'Text' , 'u.office_fax' => 'Text' ,
2022-09-06 04:48:26 +02:00
'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' ,
2022-05-17 00:50:59 +02:00
'u.fk_user' => " FormSelect:select_dolusers " ,
2021-04-14 09:49:18 +02:00
'u.birth' => 'Date' ,
2022-05-17 00:50:59 +02:00
'u.datepreviouslogin' => 'Date' ,
'u.fk_socpeople' => 'FormSelect:selectcontacts' ,
'u.fk_soc' => " FormSelect:select_company " ,
'u.tjm' => " Numeric " , 'u.thm' => " Numeric " , 'u.fk_member' => " Numeric " ,
'u.weeklyhours' => " Numeric " ,
'u.dateemployment' => " Date " , 'u.dateemploymentend' => " Date " , 'u.salary' => " Numeric " ,
'u.color' => 'Text' , 'u.api_key' => 'Text' ,
'a.firstname' => 'Text' ,
'a.lastname' => 'Text' ,
2021-04-14 09:44:01 +02:00
'g.nom' => " Text "
2018-05-27 15:04:12 +02:00
);
2020-01-18 16:17:07 +01:00
$this -> export_entities_array [ $r ] = array (
'u.rowid' => " user " , 'u.login' => " user " , 'u.lastname' => " user " , 'u.firstname' => " user " , 'u.employee' => 'user' , 'u.job' => 'user' , 'u.gender' => 'user' ,
2021-04-14 09:49:18 +02:00
'u.accountancy_code' => 'user' ,
'u.address' => " user " , 'u.zip' => " user " , 'u.town' => " user " ,
'u.office_phone' => 'user' , 'u.user_mobile' => 'user' , 'u.office_fax' => 'user' ,
2022-09-06 04:48:26 +02:00
'u.email' => 'user' , 'u.note_public' => " user " , 'u.note_private' => " user " , 'u.signature' => 'user' ,
2021-04-14 09:49:18 +02:00
'u.fk_user' => 'user' , 'u.thm' => 'user' , 'u.tjm' => 'user' , 'u.weeklyhours' => 'user' ,
2022-05-17 00:50:59 +02:00
'u.dateemployment' => 'user' , 'u.dateemploymentend' => 'user' , 'u.salary' => 'user' , 'u.color' => 'user' , 'u.api_key' => 'user' ,
2021-04-14 09:49:18 +02:00
'u.birth' => 'user' ,
'u.datec' => " user " , 'u.tms' => " user " ,
'u.admin' => " user " , 'u.statut' => 'user' , 'u.datelastlogin' => 'user' , 'u.datepreviouslogin' => 'user' ,
'u.fk_socpeople' => " contact " , 'u.fk_soc' => " company " , 'u.fk_member' => " member " ,
2022-05-17 00:50:59 +02:00
'a.firstname' => " member " , 'a.lastname' => " member " ,
2021-04-14 09:44:01 +02:00
'g.nom' => " Group "
2018-05-27 15:04:12 +02:00
);
2021-03-01 20:37:16 +01:00
$keyforselect = 'user' ;
$keyforelement = 'user' ;
$keyforaliasextra = 'extra' ;
2020-11-12 14:11:59 +01:00
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> adherent -> enabled )) {
2020-12-01 02:41:19 +01:00
unset ( $this -> export_fields_array [ $r ][ 'u.fk_member' ]);
unset ( $this -> export_entities_array [ $r ][ 'u.fk_member' ]);
}
2020-01-18 16:17:07 +01:00
$this -> export_sql_start [ $r ] = 'SELECT DISTINCT ' ;
$this -> export_sql_end [ $r ] = ' FROM ' . MAIN_DB_PREFIX . 'user as u' ;
2020-11-12 14:11:59 +01:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'user_extrafields as extra ON u.rowid = extra.fk_object' ;
2021-04-14 09:44:01 +02:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'usergroup_user as ug ON u.rowid = ug.fk_user' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'usergroup as g ON ug.fk_usergroup = g.rowid' ;
2022-05-17 00:50:59 +02:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'adherent as a ON u.fk_member = a.rowid' ;
2020-01-18 16:17:07 +01:00
$this -> export_sql_end [ $r ] .= ' WHERE u.entity IN (' . getEntity ( 'user' ) . ')' ;
2017-12-08 16:15:41 +01:00
2017-04-17 04:22:53 +02:00
// Imports
2020-01-18 16:17:07 +01:00
$r = 0 ;
2017-04-17 04:22:53 +02:00
// Import list of users attributes
$r ++ ;
2020-01-18 16:17:07 +01:00
$this -> import_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> import_label [ $r ] = 'ImportDataset_user_1' ;
$this -> import_icon [ $r ] = 'user' ;
$this -> import_entities_array [ $r ] = array (); // We define here only fields that use another icon that the one defined into import_icon
$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)
$this -> import_fields_array [ $r ] = array (
2020-10-31 14:32:18 +01:00
'u.login' => " Login* " , 'u.lastname' => " Name* " , 'u.firstname' => " Firstname " , 'u.employee' => " Employee* " , 'u.job' => " PostOrFunction " , 'u.gender' => " Gender " ,
'u.accountancy_code' => " UserAccountancyCode " ,
2020-01-18 16:17:07 +01:00
'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 " ,
2020-10-31 14:32:18 +01:00
'u.office_phone' => " Phone " , 'u.user_mobile' => " Mobile " , 'u.office_fax' => " Fax " ,
2022-09-06 04:48:26 +02:00
'u.email' => " Email " , 'u.note_public' => " NotePublic " , 'u.note_private' => " NotePrivate " , 'u.signature' => 'Signature' ,
2020-10-31 14:32:18 +01:00
'u.fk_user' => 'HierarchicalResponsible' , 'u.thm' => 'THM' , 'u.tjm' => 'TJM' , 'u.weeklyhours' => 'WeeklyHours' ,
2022-05-17 00:50:59 +02:00
'u.dateemployment' => 'DateEmploymentStart' , 'u.dateemploymentend' => 'DateEmploymentEnd' , 'u.salary' => 'Salary' , 'u.color' => 'Color' , 'u.api_key' => 'ApiKey' ,
2020-10-31 14:32:18 +01:00
'u.birth' => 'DateOfBirth' ,
'u.datec' => " DateCreation " ,
'u.statut' => 'Status'
2018-05-27 15:04:12 +02:00
);
2017-04-17 04:22:53 +02:00
// Add extra fields
2021-10-31 14:33:44 +01:00
$sql = " SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . " extrafields WHERE type <> 'separate' AND elementtype = 'user' AND entity IN (0, " . $conf -> entity . " ) " ;
2020-01-18 16:17:07 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) { // This can fail when class is used on old database (during migration for example)
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2020-10-31 14:32:18 +01:00
$fieldname = 'extra.' . $obj -> name ;
$fieldlabel = ucfirst ( $obj -> label );
$this -> import_fields_array [ $r ][ $fieldname ] = $fieldlabel . ( $obj -> fieldrequired ? '*' : '' );
}
2017-04-17 04:22:53 +02:00
}
// End add extra fields
2020-01-18 16:17:07 +01:00
$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)
$this -> import_convertvalue_array [ $r ] = array (
'u.fk_state' => array ( 'rule' => 'fetchidfromcodeid' , 'classfile' => '/core/class/cstate.class.php' , 'class' => 'Cstate' , 'method' => 'fetch' , 'dict' => 'DictionaryState' ),
2020-10-31 14:32:18 +01:00
'u.fk_country' => array ( 'rule' => 'fetchidfromcodeid' , 'classfile' => '/core/class/ccountry.class.php' , 'class' => 'Ccountry' , 'method' => 'fetch' , 'dict' => 'DictionaryCountry' ),
'u.salary' => array ( 'rule' => 'numeric' )
2017-04-17 04:22:53 +02:00
);
//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
2020-01-18 16:17:07 +01:00
$this -> import_regex_array [ $r ] = array (
2018-05-27 15:04:12 +02:00
'u.employee' => '^[0|1]' ,
2019-01-31 15:51:02 +01:00
'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])?$' ,
2020-10-31 14:32:18 +01:00
'u.dateemployment' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$' ,
'u.birth' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'
2018-05-27 15:04:12 +02:00
);
2020-01-18 16:17:07 +01:00
$this -> import_examplevalues_array [ $r ] = array (
2021-08-26 11:53:57 +02:00
'u.lastname' => " Doe " , 'u.firstname' => 'John' , 'u.login' => 'jdoe' , 'u.employee' => '0 or 1' , 'u.job' => 'CTO' , 'u.gender' => 'man or woman' ,
2020-02-11 19:32:27 +01:00
'u.pass_crypted' => 'Encrypted password' ,
2023-01-03 13:47:34 +01:00
'u.fk_soc' => '0 (internal user) or company name (external user)' , 'u.address' => " 61 jump street " ,
2020-01-18 16:17:07 +01:00
'u.zip' => " 123456 " , 'u.town' => " Big town " , 'u.fk_country' => 'US, FR, DE...' , 'u.office_phone' => " 0101010101 " , 'u.office_fax' => " 0101010102 " ,
2022-09-06 04:48:26 +02:00
'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 " ,
2020-10-31 14:32:18 +01:00
'u.statut' => " 0 (closed) or 1 (active) " ,
2018-05-27 15:04:12 +02:00
);
2020-01-18 16:17:07 +01:00
$this -> import_updatekeys_array [ $r ] = array ( 'u.lastname' => 'Lastname' , 'u.firstname' => 'Firstname' , 'u.login' => 'Login' );
2008-10-01 21:10:17 +02:00
}
2020-10-31 14:32:18 +01:00
/**
2012-01-04 21:23:50 +01:00
* Function called when module is enabled .
* The init function add constants , boxes , permissions and menus ( defined in constructor ) into Dolibarr database .
* It also creates data directories
*
2020-10-31 14:32:18 +01:00
* @ param string $options Options when enabling module ( '' , 'noboxes' )
2012-01-04 21:23:50 +01:00
* @ return int 1 if OK , 0 if KO
2020-10-31 14:32:18 +01:00
*/
public function init ( $options = '' )
{
2008-10-01 21:10:17 +02:00
global $conf ;
// Permissions
2012-03-03 17:37:45 +01:00
$this -> remove ( $options );
2008-10-01 21:10:17 +02:00
$sql = array ();
2019-01-27 11:55:16 +01:00
return $this -> _init ( $sql , $options );
2020-10-31 14:32:18 +01:00
}
2005-08-23 13:13:03 +02:00
}