2004-10-20 23:15:17 +02:00
< ? php
2019-03-01 18:28:51 +01:00
/* Copyright ( c ) 2002 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( c ) 2002 - 2003 Jean - Louis Bergamo < jlb @ j1b . org >
* Copyright ( c ) 2004 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
* Copyright ( C ) 2005 - 2017 Regis Houssin < regis . houssin @ inodbox . com >
* Copyright ( C ) 2005 Lionel Cousteix < etm_ltd @ tiscali . co . uk >
* Copyright ( C ) 2011 Herve Prot < herve . prot @ symeos . com >
2019-03-21 15:18:05 +01:00
* Copyright ( C ) 2013 - 2019 Philippe Grand < philippe . grand @ atoo - net . com >
2019-03-01 18:28:51 +01:00
* Copyright ( C ) 2013 - 2015 Alexandre Spangaro < aspangaro @ open - dsi . fr >
* Copyright ( C ) 2015 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2018 charlene Benke < charlie @ patas - monkey . com >
2021-11-22 12:01:20 +01:00
* Copyright ( C ) 2018 - 2021 Nicolas ZABOURI < info @ inovea - conseil . com >
2024-03-02 16:38:35 +01:00
* Copyright ( C ) 2019 - 2024 Frédéric France < frederic . france @ free . fr >
2019-09-11 23:45:02 +02:00
* Copyright ( C ) 2019 Abbes Bahfir < dolipar @ dolipar . org >
2024-01-29 14:05:25 +01:00
* Copyright ( C ) 2024 MDW < mdeweerd @ users . noreply . github . com >
2006-11-20 03:10:47 +01:00
*
2002-04-30 12:51:35 +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
2002-04-30 12:51:35 +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 />.
2002-04-30 12:51:35 +02:00
*/
2005-03-15 18:17:58 +01:00
/**
2010-07-21 14:35:56 +02:00
* \file htdocs / user / class / user . class . php
2012-01-11 01:06:56 +01:00
* \brief File of class to manage users
2012-03-27 09:59:28 +02:00
* \ingroup core
2008-07-19 18:53:56 +02:00
*/
2004-08-07 20:47:54 +02:00
2023-03-13 12:48:25 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/security.lib.php' ;
2019-11-13 19:35:39 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php' ;
2023-04-27 23:48:21 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonpeople.class.php' ;
2007-11-05 23:37:41 +01:00
2023-03-13 12:48:25 +01:00
2005-03-15 18:17:58 +01:00
/**
2012-04-01 20:31:39 +02:00
* Class to manage Dolibarr users
2008-07-19 18:53:56 +02:00
*/
2007-11-05 23:37:41 +01:00
class User extends CommonObject
2003-08-11 20:56:42 +02:00
{
2023-04-27 23:48:21 +02:00
use CommonPeople ;
2018-08-23 18:52:47 +02:00
/**
* @ var string ID to identify managed object
*/
2019-11-13 19:35:39 +01:00
public $element = 'user' ;
2018-08-31 22:34:02 +02:00
2018-08-22 19:56:24 +02:00
/**
* @ var string Name of table without prefix where object is stored
*/
2019-11-13 19:35:39 +01:00
public $table_element = 'user' ;
2018-08-31 22:34:02 +02:00
2018-10-06 12:04:17 +02:00
/**
2020-12-05 23:53:55 +01:00
* @ var string Field with ID of parent key if this field has a parent
2018-10-06 12:04:17 +02:00
*/
2019-11-13 19:35:39 +01:00
public $fk_element = 'fk_user' ;
2018-10-06 12:04:17 +02:00
2018-10-06 12:18:03 +02:00
/**
* 0 = No test on entity , 1 = Test with field entity , 2 = Test with link by societe
* @ var int
*/
public $ismultientitymanaged = 1 ;
2004-08-07 20:47:54 +02:00
2023-05-24 00:24:14 +02:00
/**
* @ var int Does object support extrafields ? 0 = No , 1 = Yes
*/
public $isextrafieldmanaged = 1 ;
2020-11-05 08:55:04 +01:00
/**
* @ var string picto
*/
2020-04-24 23:56:57 +02:00
public $picto = 'user' ;
2019-11-13 19:35:39 +01:00
public $id = 0 ;
2023-07-27 17:45:40 +02:00
2023-12-15 22:54:40 +01:00
/**
* @ var User old copy of User
*/
public $oldcopy ;
2023-07-27 17:45:40 +02:00
/**
* @ var int
* @ deprecated
* @ see $status
*/
2017-12-18 11:55:34 +01:00
public $statut ;
2023-07-27 17:45:40 +02:00
2023-08-09 16:02:27 +02:00
public $status ;
2023-10-02 21:49:08 +02:00
/**
* @ var string Open ID
*/
public $openid ;
2016-12-20 21:11:50 +01:00
public $ldap_sid ;
public $search_sid ;
public $employee ;
2020-12-05 11:30:18 +01:00
public $civility_code ;
2020-11-10 21:43:45 +01:00
2023-01-18 22:20:25 +01:00
/**
* @ var string fullname
*/
public $fullname ;
2020-11-10 21:43:45 +01:00
/**
* @ var string gender
*/
2016-12-20 21:11:50 +01:00
public $gender ;
2022-05-17 01:21:33 +02:00
2017-10-06 12:08:01 +02:00
public $birth ;
2020-11-05 08:55:04 +01:00
/**
* @ var string email
*/
2016-12-20 21:11:50 +01:00
public $email ;
2018-10-12 11:29:47 +02:00
2023-12-05 00:44:31 +01:00
/**
* @ var string email
*/
public $email_oauth2 ;
2020-11-05 08:55:04 +01:00
/**
* @ var string personal email
*/
2019-03-16 08:53:06 +01:00
public $personal_email ;
2019-09-12 18:04:24 +02:00
2020-09-07 10:18:17 +02:00
/**
2023-01-31 00:42:23 +01:00
* @ var array array of socialnetwo18dprks
2020-09-07 10:18:17 +02:00
*/
public $socialnetworks ;
2019-09-12 18:04:24 +02:00
2020-11-05 19:00:45 +01:00
/**
* @ var string job position
*/
public $job ;
/**
* @ var string user signature
*/
2016-12-20 21:11:50 +01:00
public $signature ;
2018-10-06 12:01:00 +02:00
2020-11-05 19:00:45 +01:00
/**
* @ var string office phone
*/
2016-12-20 21:11:50 +01:00
public $office_phone ;
2020-11-05 19:00:45 +01:00
/**
* @ var string office fax
*/
2016-12-20 21:11:50 +01:00
public $office_fax ;
2020-11-05 19:00:45 +01:00
/**
* @ var string phone mobile
*/
2016-12-20 21:11:50 +01:00
public $user_mobile ;
2020-11-05 19:00:45 +01:00
/**
* @ var string personal phone mobile
*/
2020-09-07 10:18:17 +02:00
public $personal_mobile ;
2020-11-05 19:00:45 +01:00
/**
* @ var int 1 if admin 0 if standard user
*/
2016-12-20 21:11:50 +01:00
public $admin ;
2020-11-05 19:00:45 +01:00
/**
* @ var string user login
*/
2016-12-20 21:11:50 +01:00
public $login ;
2020-11-05 19:00:45 +01:00
/**
* @ var string user apikey
*/
2017-11-10 18:14:29 +01:00
public $api_key ;
2018-08-31 18:27:16 +02:00
/**
* @ var int Entity
*/
2016-12-20 21:11:50 +01:00
public $entity ;
2007-11-13 21:17:52 +01:00
2020-11-05 08:55:04 +01:00
/**
* @ var string Clear password in memory
*/
2016-12-20 21:11:50 +01:00
public $pass ;
2020-11-05 08:55:04 +01:00
2023-07-27 17:45:40 +02:00
/**
2024-01-11 10:07:06 +01:00
* @ var string Encrypted password in memory
2023-07-27 17:45:40 +02:00
*/
public $pass_crypted ;
2020-11-05 08:55:04 +01:00
/**
* @ var string Clear password in database ( defined if DATABASE_PWD_ENCRYPTED = 0 )
*/
2016-12-20 21:11:50 +01:00
public $pass_indatabase ;
2020-11-05 08:55:04 +01:00
/**
* @ var string Encrypted password in database ( always defined )
*/
2016-12-20 21:11:50 +01:00
public $pass_indatabase_crypted ;
2007-11-13 21:17:52 +01:00
2019-03-21 15:18:05 +01:00
/**
2020-11-06 16:28:26 +01:00
* @ var string Temporary password
*/
public $pass_temp ;
2019-03-21 20:15:19 +01:00
2019-03-21 15:18:05 +01:00
/**
2020-09-07 10:18:17 +02:00
* Date creation record ( datec )
*
* @ var integer
*/
public $datec ;
2012-05-23 13:09:36 +02:00
2015-04-23 23:21:06 +02:00
/**
2020-09-07 10:18:17 +02:00
* Date modification record ( tms )
*
* @ var integer
2015-04-23 23:21:06 +02:00
*/
2020-09-07 10:18:17 +02:00
public $datem ;
2012-05-23 13:09:36 +02:00
2015-04-23 23:21:06 +02:00
/**
2020-11-05 19:00:45 +01:00
* @ var int If this is defined , it is an external user
2015-04-23 23:21:06 +02:00
*/
2016-12-20 21:11:50 +01:00
public $socid ;
2018-10-12 12:23:45 +02:00
/**
2020-11-05 19:00:45 +01:00
* @ var int If this is defined , it is a user created from a contact
*/
2020-06-25 12:17:47 +02:00
public $contact_id ;
2016-12-20 21:11:50 +01:00
2018-10-12 12:23:45 +02:00
/**
2020-09-07 10:18:17 +02:00
* @ var int ID
*/
2016-12-20 21:11:50 +01:00
public $fk_member ;
2018-08-31 17:55:31 +02:00
/**
2020-11-05 09:40:37 +01:00
* @ var int User ID of supervisor
2018-08-31 17:55:31 +02:00
*/
2016-12-20 21:11:50 +01:00
public $fk_user ;
2020-11-05 09:40:37 +01:00
2020-11-05 19:00:45 +01:00
/**
* @ var int User ID of expense validator
*/
2019-03-16 08:53:06 +01:00
public $fk_user_expense_validator ;
2016-12-20 21:11:50 +01:00
2020-11-05 19:00:45 +01:00
/**
* @ var int User ID of holidays validator
*/
2020-09-07 10:18:17 +02:00
public $fk_user_holiday_validator ;
2016-12-20 21:11:50 +01:00
2020-11-05 19:00:45 +01:00
/**
* @ string clicktodial url
*/
2016-12-20 21:11:50 +01:00
public $clicktodial_url ;
2020-11-05 19:00:45 +01:00
/**
* @ var string clicktodial login
*/
2016-12-20 21:11:50 +01:00
public $clicktodial_login ;
2020-11-05 19:00:45 +01:00
/**
* @ var string clicktodial password
*/
2016-12-20 21:11:50 +01:00
public $clicktodial_password ;
2020-11-05 19:00:45 +01:00
/**
* @ var string clicktodial poste
*/
2016-12-20 21:11:50 +01:00
public $clicktodial_poste ;
2023-04-15 03:16:53 +02:00
/**
2024-01-22 18:08:49 +01:00
* @ var int 0 by default , 1 if click to dial data were already loaded for this user
2023-04-15 03:16:53 +02:00
*/
public $clicktodial_loaded ;
2016-12-20 21:11:50 +01:00
public $datelastlogin ;
public $datepreviouslogin ;
2023-01-16 11:48:34 +01:00
public $flagdelsessionsbefore ;
2022-04-28 17:34:04 +02:00
public $iplastlogin ;
public $ippreviouslogin ;
2020-06-25 12:17:47 +02:00
public $datestartvalidity ;
2020-09-21 18:44:20 +02:00
public $dateendvalidity ;
2020-11-05 19:00:45 +01:00
/**
* @ var string photo filename
*/
2016-12-20 21:11:50 +01:00
public $photo ;
2024-01-22 18:08:49 +01:00
/**
2024-01-22 18:10:02 +01:00
* @ var string default language
2024-01-22 18:08:49 +01:00
*/
2016-12-20 21:11:50 +01:00
public $lang ;
2020-11-05 19:00:45 +01:00
/**
* @ var stdClass Class of permissions user -> rights -> permx
*/
public $rights ;
/**
* @ var int All permissions are loaded
*/
public $all_permissions_are_loaded ;
2017-06-06 07:57:03 +02:00
2020-11-05 19:00:45 +01:00
/**
2022-05-08 15:18:34 +02:00
* @ var int Number of rights granted to the user . Value loaded after a getrights () .
2020-11-05 19:00:45 +01:00
*/
public $nb_rights ;
2021-06-05 01:17:16 +02:00
/**
* @ var array To store list of groups of user ( used by API / info for example )
*/
public $user_group_list ;
2020-11-05 19:00:45 +01:00
/**
* @ var array Cache array of already loaded permissions
*/
private $_tab_loaded = array ();
2017-06-06 07:57:03 +02:00
2020-11-05 19:00:45 +01:00
/**
* @ var stdClass To store personal config
*/
public $conf ;
2022-09-01 10:54:20 +02:00
public $default_values ; // To store default values for user. Loaded by loadDefaultValues().
2024-01-11 10:01:34 +01:00
public $lastsearch_values_tmp ; // To store current search criteria for user
public $lastsearch_values ; // To store last saved search criteria for user
2017-06-06 07:57:03 +02:00
2024-03-15 23:14:21 +01:00
/**
2024-03-23 21:46:12 +01:00
* @ var array < int , User >| array < int , array { rowid : int , id : int , fk_user : int , fk_soc : int , firstname : string , lastname : string , login : string , statut : int , entity : string , email : string , gender : int , admin : string , photo : string , fullpath : string , fullname : string , level : int } > Array of User ( filled from fetchAll ) or Array with hierarchy of user information ( filled with get_full_tree ()
2024-03-15 23:14:21 +01:00
*/
public $users = array ();
2019-11-13 19:35:39 +01:00
public $parentof ; // To store an array of all parents for all ids.
2024-01-11 10:01:34 +01:00
private $cache_childids ; // Cache array of already loaded children
2017-06-06 07:57:03 +02:00
2019-11-13 19:35:39 +01:00
public $accountancy_code ; // Accountancy code in prevision of the complete accountancy module
2017-03-13 15:00:44 +01:00
2019-11-13 19:35:39 +01:00
public $thm ; // Average cost of employee - Used for valuation of time spent
public $tjm ; // Average cost of employee
2017-03-13 15:00:44 +01:00
2019-11-13 19:35:39 +01:00
public $salary ; // Monthly salary - Denormalized value from llx_user_employment
public $salaryextra ; // Monthly salary extra - Denormalized value from llx_user_employment
public $weeklyhours ; // Weekly hours - Denormalized value from llx_user_employment
2008-07-19 18:53:56 +02:00
2020-11-05 19:00:45 +01:00
/**
* @ var string Define background color for user in agenda
*/
public $color ;
2017-03-13 15:00:44 +01:00
2019-11-13 19:35:39 +01:00
public $dateemployment ; // Define date of employment by company
public $dateemploymentend ; // Define date of employment end by company
2008-07-19 18:53:56 +02:00
2017-06-15 11:08:53 +02:00
public $default_c_exp_tax_cat ;
2022-03-02 11:20:07 +01:00
/**
* @ var string ref for employee
*/
public $ref_employee ;
/**
* @ var string national registration number
*/
public $national_registration_number ;
2017-06-15 11:08:53 +02:00
public $default_range ;
2018-07-02 09:34:34 +02:00
2020-11-10 21:43:45 +01:00
/**
*@ var int id of warehouse
*/
2019-02-15 05:20:33 +01:00
public $fk_warehouse ;
2018-07-02 09:34:34 +02:00
2023-07-27 17:45:40 +02:00
/**
* @ var int egroupware id
*/
public $egroupware_id ;
2022-04-07 23:44:57 +02:00
2018-08-31 22:34:02 +02:00
public $fields = array (
2024-03-08 21:34:18 +01:00
'rowid' => array ( 'type' => 'integer' , 'label' => 'TechnicalID' , 'enabled' => 1 , 'visible' => - 2 , 'notnull' => 1 , 'index' => 1 , 'position' => 1 , 'comment' => 'Id' ),
'lastname' => array ( 'type' => 'varchar(50)' , 'label' => 'Lastname' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'showoncombobox' => 1 , 'index' => 1 , 'position' => 20 , 'searchall' => 1 ),
'firstname' => array ( 'type' => 'varchar(50)' , 'label' => 'Firstname' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'showoncombobox' => 1 , 'index' => 1 , 'position' => 10 , 'searchall' => 1 ),
'ref_employee' => array ( 'type' => 'varchar(50)' , 'label' => 'RefEmployee' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'showoncombobox' => 1 , 'index' => 1 , 'position' => 30 , 'searchall' => 1 ),
'national_registration_number' => array ( 'type' => 'varchar(50)' , 'label' => 'NationalRegistrationNumber' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'showoncombobox' => 1 , 'index' => 1 , 'position' => 40 , 'searchall' => 1 )
2020-09-07 10:18:17 +02:00
);
2017-03-13 15:00:44 +01:00
2019-10-31 23:29:17 +01:00
const STATUS_DISABLED = 0 ;
const STATUS_ENABLED = 1 ;
2008-07-19 18:53:56 +02:00
/**
2018-08-31 22:34:02 +02:00
* Constructor of the class
2011-09-04 20:41:19 +02:00
*
2024-01-13 15:50:02 +01:00
* @ param DoliDB $db Database handler
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function __construct ( $db )
2008-07-19 18:53:56 +02:00
{
2012-01-13 18:24:25 +01:00
$this -> db = $db ;
2008-07-19 18:53:56 +02:00
2015-10-23 15:24:47 +02:00
// User preference
2009-01-09 22:22:58 +01:00
$this -> clicktodial_loaded = 0 ;
2008-07-19 18:53:56 +02:00
2015-10-23 15:24:47 +02:00
// For cache usage
2008-07-19 18:53:56 +02:00
$this -> all_permissions_are_loaded = 0 ;
2016-06-04 13:25:39 +02:00
$this -> nb_rights = 0 ;
2016-03-17 09:22:12 +01:00
// Force some default values
2015-10-23 15:24:47 +02:00
$this -> admin = 0 ;
$this -> employee = 1 ;
2016-03-17 09:22:12 +01:00
2019-02-25 20:35:59 +01:00
$this -> conf = new stdClass ();
$this -> rights = new stdClass ();
$this -> rights -> user = new stdClass ();
$this -> rights -> user -> user = new stdClass ();
$this -> rights -> user -> self = new stdClass ();
2021-10-22 10:49:47 +02:00
$this -> rights -> user -> user_advance = new stdClass ();
$this -> rights -> user -> self_advance = new stdClass ();
$this -> rights -> user -> group_advance = new stdClass ();
2008-07-19 18:53:56 +02:00
}
2007-04-13 18:11:44 +02:00
/**
2017-10-28 16:00:07 +02:00
* Load a user from database with its id or ref ( login ) .
* This function does not load permissions , only user properties . Use getrights () for this just after the fetch .
2011-08-21 01:56:03 +02:00
*
2016-12-07 19:16:33 +01:00
* @ param int $id If defined , id to used for search
* @ param string $login If defined , login to used for search
* @ param string $sid If defined , sid to used for search
2017-04-14 12:52:32 +02:00
* @ param int $loadpersonalconf 1 = also load personal conf of user ( in $user -> conf -> xxx ), 0 = do not load personal conf .
2015-10-22 14:05:16 +02:00
* @ param int $entity If a value is >= 0 , we force the search on a specific entity . If - 1 , means search depens on default setup .
2023-11-20 23:59:09 +01:00
* @ param string $email If defined , email to used for search
2022-07-18 11:51:28 +02:00
* @ param int $fk_socpeople If defined , id of contact for search
2023-12-05 00:44:31 +01:00
* @ param int $use_email_oauth2 1 = Use also email_oauth2 to fetch on email
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 if KO , 0 not found , > 0 if OK
2008-07-19 18:53:56 +02:00
*/
2023-12-05 00:44:31 +01:00
public function fetch ( $id = 0 , $login = '' , $sid = '' , $loadpersonalconf = 0 , $entity = - 1 , $email = '' , $fk_socpeople = 0 , $use_email_oauth2 = 0 )
2007-04-13 18:11:44 +02:00
{
2016-03-29 21:07:53 +02:00
global $conf , $user ;
2007-01-05 10:25:52 +01:00
2011-06-29 12:23:32 +02:00
// Clean parameters
2019-12-18 15:20:36 +01:00
$login = trim ( $login );
2008-07-19 18:53:56 +02:00
2011-06-29 12:23:32 +02:00
// Get user
2023-12-05 00:44:31 +01:00
$sql = " SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.job, " ;
$sql .= " u.email, u.email_oauth2, u.personal_email, " ;
2019-12-18 15:20:36 +01:00
$sql .= " u.socialnetworks, " ;
$sql .= " u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile, " ;
$sql .= " u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id, " ;
2022-09-03 11:07:47 +02:00
$sql .= " u.admin, u.login, u.note_private, u.note_public, " ;
2019-12-18 15:20:36 +01:00
$sql .= " u.pass, u.pass_crypted, u.pass_temp, u.api_key, " ;
$sql .= " u.fk_soc, u.fk_socpeople, u.fk_member, u.fk_user, u.ldap_sid, u.fk_user_expense_validator, u.fk_user_holiday_validator, " ;
2023-01-03 10:27:54 +01:00
$sql .= " u.statut as status, u.lang, u.entity, " ;
2019-12-18 15:20:36 +01:00
$sql .= " u.datec as datec, " ;
$sql .= " u.tms as datem, " ;
$sql .= " u.datelastlogin as datel, " ;
$sql .= " u.datepreviouslogin as datep, " ;
2023-01-16 11:48:34 +01:00
$sql .= " u.flagdelsessionsbefore, " ;
2022-04-28 22:28:32 +02:00
$sql .= " u.iplastlogin, " ;
$sql .= " u.ippreviouslogin, " ;
2020-11-29 21:01:57 +01:00
$sql .= " u.datelastpassvalidation, " ;
2020-06-25 12:17:47 +02:00
$sql .= " u.datestartvalidity, " ;
$sql .= " u.dateendvalidity, " ;
2019-12-18 15:20:36 +01:00
$sql .= " u.photo as photo, " ;
$sql .= " u.openid as openid, " ;
$sql .= " u.accountancy_code, " ;
$sql .= " u.thm, " ;
$sql .= " u.tjm, " ;
$sql .= " u.salary, " ;
$sql .= " u.salaryextra, " ;
$sql .= " u.weeklyhours, " ;
$sql .= " u.color, " ;
$sql .= " u.dateemployment, u.dateemploymentend, " ;
$sql .= " u.fk_warehouse, " ;
2020-03-06 14:38:06 +01:00
$sql .= " u.ref_ext, " ;
2019-12-18 15:20:36 +01:00
$sql .= " u.default_range, u.default_c_exp_tax_cat, " ; // Expense report default mode
2022-03-02 11:20:07 +01:00
$sql .= " u.national_registration_number, " ;
$sql .= " u.ref_employee, " ;
2019-12-18 15:20:36 +01:00
$sql .= " c.code as country_code, c.label as country, " ;
$sql .= " d.code_departement as state_code, d.nom as state " ;
2022-01-21 16:57:57 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " user as u " ;
$sql .= " LEFT JOIN " . $this -> db -> prefix () . " c_country as c ON u.fk_country = c.rowid " ;
$sql .= " LEFT JOIN " . $this -> db -> prefix () . " c_departements as d ON u.fk_state = d.rowid " ;
2011-08-20 18:59:14 +02:00
2020-11-05 08:55:04 +01:00
if ( $entity < 0 ) {
2023-11-27 12:08:48 +01:00
if (( ! isModEnabled ( 'multicompany' ) || ! getDolGlobalString ( 'MULTICOMPANY_TRANSVERSE_MODE' )) && ( ! empty ( $user -> entity ))) {
2021-07-05 11:33:32 +02:00
$sql .= " WHERE u.entity IN (0, " . (( int ) $conf -> entity ) . " ) " ;
2020-05-21 15:05:19 +02:00
} else {
2019-12-18 15:20:36 +01:00
$sql .= " WHERE u.entity IS NOT NULL " ; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database
2017-10-07 13:09:31 +02:00
}
2020-11-05 14:42:37 +01:00
} else {
// The fetch was forced on an entity
2023-11-27 12:08:48 +01:00
if ( isModEnabled ( 'multicompany' ) && getDolGlobalString ( 'MULTICOMPANY_TRANSVERSE_MODE' )) {
2019-12-18 15:20:36 +01:00
$sql .= " WHERE u.entity IS NOT NULL " ; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database
2020-11-05 08:55:04 +01:00
} else {
2021-07-05 11:33:32 +02:00
$sql .= " WHERE u.entity IN (0, " . (( int ) (( $entity != '' && $entity >= 0 ) ? $entity : $conf -> entity )) . " ) " ; // search in entity provided in parameter
2020-11-05 08:55:04 +01:00
}
2011-08-20 00:15:22 +02:00
}
2016-03-17 09:22:12 +01:00
2021-09-13 09:44:54 +02:00
if ( $sid ) {
// permet une recherche du user par son SID ActiveDirectory ou Samba
$sql .= " AND (u.ldap_sid = ' " . $this -> db -> escape ( $sid ) . " ' OR u.login = ' " . $this -> db -> escape ( $login ) . " ') " ;
2020-11-05 08:55:04 +01:00
} elseif ( $login ) {
2019-12-18 15:20:36 +01:00
$sql .= " AND u.login = ' " . $this -> db -> escape ( $login ) . " ' " ;
2020-11-05 08:55:04 +01:00
} elseif ( $email ) {
2023-12-05 00:44:31 +01:00
$sql .= " AND (u.email = ' " . $this -> db -> escape ( $email ) . " ' " ;
if ( $use_email_oauth2 ) {
$sql .= " OR u.email_oauth2 = ' " . $this -> db -> escape ( $email ) . " ' " ;
}
$sql .= " ) " ;
2022-07-18 11:51:28 +02:00
} elseif ( $fk_socpeople > 0 ) {
$sql .= " AND u.fk_socpeople = " . (( int ) $fk_socpeople );
2020-05-21 15:05:19 +02:00
} else {
2021-03-14 11:48:39 +01:00
$sql .= " AND u.rowid = " . (( int ) $id );
2007-04-13 18:11:44 +02:00
}
2019-12-18 15:20:36 +01:00
$sql .= " ORDER BY u.entity ASC " ; // Avoid random result when there is 2 login in 2 different entities
2017-09-11 00:02:52 +02:00
2021-09-13 09:44:54 +02:00
if ( $sid ) {
// permet une recherche du user par son SID ActiveDirectory ou Samba
$sql .= ' ' . $this -> db -> plimit ( 1 );
}
2023-12-05 00:44:31 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$num = $this -> db -> num_rows ( $resql );
if ( $num > 1 ) {
$this -> error = " USERDUPLICATEFOUND " ;
dol_syslog ( get_class ( $this ) . " ::fetch more than 1 user found " , LOG_WARNING );
$this -> db -> free ( $resql );
return 0 ;
}
$obj = $this -> db -> fetch_object ( $resql );
2020-10-29 00:34:41 +01:00
if ( $obj ) {
2019-11-13 19:35:39 +01:00
$this -> id = $obj -> rowid ;
$this -> ref = $obj -> rowid ;
2011-09-04 20:41:19 +02:00
2020-11-05 19:00:45 +01:00
$this -> ref_ext = $obj -> ref_ext ;
2011-01-15 10:31:09 +01:00
2020-11-05 19:00:45 +01:00
$this -> ldap_sid = $obj -> ldap_sid ;
2020-12-05 11:30:18 +01:00
$this -> civility_code = $obj -> civility_code ;
2020-11-05 19:00:45 +01:00
$this -> lastname = $obj -> lastname ;
2019-11-13 19:35:39 +01:00
$this -> firstname = $obj -> firstname ;
2022-03-02 11:20:07 +01:00
$this -> ref_employee = $obj -> ref_employee ;
$this -> national_registration_number = $obj -> national_registration_number ;
2016-03-17 09:22:12 +01:00
2020-11-05 19:00:45 +01:00
$this -> employee = $obj -> employee ;
2008-07-19 18:53:56 +02:00
2019-11-13 19:35:39 +01:00
$this -> login = $obj -> login ;
2015-05-30 02:17:05 +02:00
$this -> gender = $obj -> gender ;
2017-10-06 12:08:01 +02:00
$this -> birth = $this -> db -> jdate ( $obj -> birth );
2007-04-13 18:11:44 +02:00
$this -> pass_indatabase = $obj -> pass ;
2007-04-23 00:55:32 +02:00
$this -> pass_indatabase_crypted = $obj -> pass_crypted ;
2019-11-13 19:35:39 +01:00
$this -> pass = $obj -> pass ;
2012-10-05 12:40:19 +02:00
$this -> pass_temp = $obj -> pass_temp ;
2023-03-13 12:48:25 +01:00
$this -> api_key = dolDecrypt ( $obj -> api_key );
2015-11-18 06:34:08 +01:00
2017-10-07 13:09:31 +02:00
$this -> address = $obj -> address ;
$this -> zip = $obj -> zip ;
$this -> town = $obj -> town ;
2015-11-18 06:34:08 +01:00
2019-02-25 20:35:59 +01:00
$this -> country_id = $obj -> country_id ;
2019-11-13 19:35:39 +01:00
$this -> country_code = $obj -> country_id ? $obj -> country_code : '' ;
2019-02-25 20:35:59 +01:00
//$this->country = $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):'';
2015-11-18 06:34:08 +01:00
2017-10-07 13:09:31 +02:00
$this -> state_id = $obj -> state_id ;
$this -> state_code = $obj -> state_code ;
2019-11-13 19:35:39 +01:00
$this -> state = ( $obj -> state != '-' ? $obj -> state : '' );
2015-11-18 06:34:08 +01:00
2012-10-05 12:40:19 +02:00
$this -> office_phone = $obj -> office_phone ;
2019-03-16 08:53:06 +01:00
$this -> office_fax = $obj -> office_fax ;
$this -> user_mobile = $obj -> user_mobile ;
2020-09-07 10:18:17 +02:00
$this -> personal_mobile = $obj -> personal_mobile ;
2019-12-18 15:20:36 +01:00
$this -> email = $obj -> email ;
2023-12-05 00:44:31 +01:00
$this -> email_oauth2 = $obj -> email_oauth2 ;
2019-09-12 18:32:47 +02:00
$this -> personal_email = $obj -> personal_email ;
2022-09-21 03:23:03 +02:00
$this -> socialnetworks = ( $obj -> socialnetworks ? ( array ) json_decode ( $obj -> socialnetworks , true ) : array ());
2019-12-18 15:20:36 +01:00
$this -> job = $obj -> job ;
$this -> signature = $obj -> signature ;
2012-10-05 12:40:19 +02:00
$this -> admin = $obj -> admin ;
2019-12-18 15:20:36 +01:00
$this -> note_public = $obj -> note_public ;
$this -> note_private = $obj -> note_private ;
2022-01-23 19:20:13 +01:00
$this -> note = $obj -> note_private ; // deprecated
2023-01-03 10:27:54 +01:00
$this -> statut = $obj -> status ; // deprecated
$this -> status = $obj -> status ;
2012-10-05 12:40:19 +02:00
$this -> photo = $obj -> photo ;
$this -> openid = $obj -> openid ;
$this -> lang = $obj -> lang ;
$this -> entity = $obj -> entity ;
2019-02-25 20:35:59 +01:00
$this -> accountancy_code = $obj -> accountancy_code ;
2014-03-16 20:37:43 +01:00
$this -> thm = $obj -> thm ;
2014-09-13 17:41:26 +02:00
$this -> tjm = $obj -> tjm ;
2019-11-13 19:35:39 +01:00
$this -> salary = $obj -> salary ;
2019-02-27 14:21:15 +01:00
$this -> salaryextra = $obj -> salaryextra ;
2019-02-25 20:35:59 +01:00
$this -> weeklyhours = $obj -> weeklyhours ;
2019-02-27 14:21:15 +01:00
$this -> color = $obj -> color ;
2019-02-25 20:35:59 +01:00
$this -> dateemployment = $this -> db -> jdate ( $obj -> dateemployment );
2018-05-12 17:59:43 +02:00
$this -> dateemploymentend = $this -> db -> jdate ( $obj -> dateemploymentend );
2012-10-05 12:40:19 +02:00
$this -> datec = $this -> db -> jdate ( $obj -> datec );
$this -> datem = $this -> db -> jdate ( $obj -> datem );
2019-11-13 19:35:39 +01:00
$this -> datelastlogin = $this -> db -> jdate ( $obj -> datel );
$this -> datepreviouslogin = $this -> db -> jdate ( $obj -> datep );
2023-01-16 11:48:34 +01:00
$this -> flagdelsessionsbefore = $this -> db -> jdate ( $obj -> flagdelsessionsbefore , 'gmt' );
2022-04-28 22:28:32 +02:00
$this -> iplastlogin = $obj -> iplastlogin ;
$this -> ippreviouslogin = $obj -> ippreviouslogin ;
2020-06-25 12:17:47 +02:00
$this -> datestartvalidity = $this -> db -> jdate ( $obj -> datestartvalidity );
$this -> dateendvalidity = $this -> db -> jdate ( $obj -> dateendvalidity );
2008-07-19 18:53:56 +02:00
2015-04-18 18:11:01 +02:00
$this -> socid = $obj -> fk_soc ;
2020-06-25 12:17:47 +02:00
$this -> contact_id = $obj -> fk_socpeople ;
2007-10-02 15:54:34 +02:00
$this -> fk_member = $obj -> fk_member ;
2019-11-13 19:35:39 +01:00
$this -> fk_user = $obj -> fk_user ;
2020-09-07 10:18:17 +02:00
$this -> fk_user_expense_validator = $obj -> fk_user_expense_validator ;
$this -> fk_user_holiday_validator = $obj -> fk_user_holiday_validator ;
2017-09-11 00:02:52 +02:00
2019-02-25 20:35:59 +01:00
$this -> default_range = $obj -> default_range ;
$this -> default_c_exp_tax_cat = $obj -> default_c_exp_tax_cat ;
2019-02-27 14:21:15 +01:00
$this -> fk_warehouse = $obj -> fk_warehouse ;
2013-06-16 21:31:21 +02:00
2017-06-25 17:09:08 +02:00
// Protection when module multicompany was set, admin was set to first entity and then, the module was disabled,
// in such case, this admin user must be admin for ALL entities.
2022-08-28 14:40:36 +02:00
if ( ! isModEnabled ( 'multicompany' ) && $this -> admin && $this -> entity == 1 ) {
2020-10-29 00:34:41 +01:00
$this -> entity = 0 ;
}
2016-03-17 09:22:12 +01:00
2020-10-23 20:08:35 +02:00
// Retrieve all extrafield
2013-05-10 12:03:27 +02:00
// fetch optionals attributes and labels
2018-02-20 19:38:18 +01:00
$this -> fetch_optionals ();
2007-04-13 18:11:44 +02:00
2023-12-05 00:44:31 +01:00
$this -> db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = " USERNOTFOUND " ;
2011-09-24 01:46:14 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch user not found " , LOG_DEBUG );
2007-04-13 18:11:44 +02:00
2023-12-05 00:44:31 +01:00
$this -> db -> free ( $resql );
2007-10-02 20:16:29 +02:00
return 0 ;
2008-07-19 18:53:56 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror ();
2007-04-13 18:11:44 +02:00
return - 1 ;
}
2008-07-19 18:53:56 +02:00
2014-10-16 06:20:54 +02:00
// To get back the global configuration unique to the user
2020-10-29 00:34:41 +01:00
if ( $loadpersonalconf ) {
2023-10-30 14:23:27 +01:00
$result = $this -> loadPersonalConf ();
2017-06-06 07:57:03 +02:00
2018-12-15 18:11:40 +01:00
$result = $this -> loadDefaultValues ();
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror ();
2018-12-15 18:11:40 +01:00
return - 3 ;
}
}
return 1 ;
}
2023-10-30 14:23:27 +01:00
/**
* Load const values from database table user_param and set it into user -> conf -> XXX
*
2023-11-09 15:50:42 +01:00
* @ return int >= 0 if OK , < 0 if KO
2023-10-30 14:23:27 +01:00
*/
public function loadPersonalConf ()
{
global $conf ;
// Load user->conf for user
$sql = " SELECT param, value FROM " . $this -> db -> prefix () . " user_param " ;
$sql .= " WHERE fk_user = " . (( int ) $this -> id );
$sql .= " AND entity = " . (( int ) $conf -> entity );
//dol_syslog(get_class($this).'::fetch load personalized conf', LOG_DEBUG);
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num ) {
$obj = $this -> db -> fetch_object ( $resql );
$p = ( ! empty ( $obj -> param ) ? $obj -> param : '' );
if ( ! empty ( $p )) {
$this -> conf -> $p = $obj -> value ;
}
$i ++ ;
}
$this -> db -> free ( $resql );
2023-11-09 15:50:42 +01:00
return $num ;
2023-10-30 14:23:27 +01:00
} else {
$this -> error = $this -> db -> lasterror ();
2023-11-09 15:50:42 +01:00
2023-10-30 14:23:27 +01:00
return - 2 ;
}
}
2018-12-15 18:11:40 +01:00
/**
2021-03-20 21:36:42 +01:00
* Load default values from database table into property -> default_values
2018-12-15 18:11:40 +01:00
*
* @ return int > 0 if OK , < 0 if KO
*/
2019-02-25 20:35:59 +01:00
public function loadDefaultValues ()
2018-12-15 18:11:40 +01:00
{
global $conf ;
2023-10-30 14:23:27 +01:00
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'MAIN_ENABLE_DEFAULT_VALUES' )) {
2021-03-01 20:36:42 +01:00
// Load user->default_values for user. TODO Save this in memcached ?
require_once DOL_DOCUMENT_ROOT . '/core/class/defaultvalues.class.php' ;
2018-12-15 18:11:40 +01:00
2021-03-01 20:36:42 +01:00
$defaultValues = new DefaultValues ( $this -> db );
2024-03-05 03:51:36 +01:00
$result = $defaultValues -> fetchAll ( '' , '' , 0 , 0 , '(t.user_id:in:0,' . $this -> id . ') AND (entity:in:' . ( isset ( $this -> entity ) ? $this -> entity : $conf -> entity ) . ',' . $conf -> entity . ')' ); // User 0 (all) + me (if defined)
//$result = $defaultValues->fetchAll('', '', 0, 0, array('t.user_id'=>array(0, $this->id), 'entity'=>array((isset($this->entity) ? $this->entity : $conf->entity), $conf->entity))); // User 0 (all) + me (if defined)
2021-03-01 20:36:42 +01:00
2021-03-02 14:44:31 +01:00
if ( ! is_array ( $result ) && $result < 0 ) {
2021-03-01 21:00:32 +01:00
setEventMessages ( $defaultValues -> error , $defaultValues -> errors , 'errors' );
2021-03-01 20:36:42 +01:00
dol_print_error ( $this -> db );
return - 1 ;
2021-03-02 15:34:43 +01:00
} elseif ( count ( $result ) > 0 ) {
2021-03-01 21:00:32 +01:00
foreach ( $result as $defval ) {
2021-03-01 20:36:42 +01:00
if ( ! empty ( $defval -> page ) && ! empty ( $defval -> type ) && ! empty ( $defval -> param )) {
$pagewithoutquerystring = $defval -> page ;
$pagequeries = '' ;
$reg = array ();
if ( preg_match ( '/^([^\?]+)\?(.*)$/' , $pagewithoutquerystring , $reg )) { // There is query param
$pagewithoutquerystring = $reg [ 1 ];
$pagequeries = $reg [ 2 ];
}
$this -> default_values [ $pagewithoutquerystring ][ $defval -> type ][ $pagequeries ? $pagequeries : '_noquery_' ][ $defval -> param ] = $defval -> value ;
2017-10-07 13:09:31 +02:00
}
}
2018-12-15 18:11:40 +01:00
}
2019-11-13 19:35:39 +01:00
if ( ! empty ( $this -> default_values )) {
2020-10-29 00:34:41 +01:00
foreach ( $this -> default_values as $a => $b ) {
foreach ( $b as $c => $d ) {
2018-12-15 18:11:40 +01:00
krsort ( $this -> default_values [ $a ][ $c ]);
2017-10-07 13:09:31 +02:00
}
}
2017-04-14 12:52:32 +02:00
}
2018-12-15 18:11:40 +01:00
}
2021-03-01 20:36:42 +01:00
return 1 ;
2007-04-13 18:11:44 +02:00
}
2008-07-19 18:53:56 +02:00
2021-08-24 14:47:50 +02:00
/**
* Return if a user has a permission .
* You can use it like this : if ( $user -> hasRight ( 'module' , 'level11' )) .
* It replaces old syntax : if ( $user -> rights -> module -> level1 )
*
2024-01-29 14:05:25 +01:00
* @ param string $module Module of permission to check
2021-09-19 00:50:23 +02:00
* @ param string $permlevel1 Permission level1 ( Example : 'read' , 'write' , 'delete' )
2021-08-24 14:47:50 +02:00
* @ param string $permlevel2 Permission level2
2021-08-24 15:28:59 +02:00
* @ return int 1 if user has permission , 0 if not .
2021-08-24 14:47:50 +02:00
* @ see clearrights (), delrights (), getrights (), hasRight ()
*/
public function hasRight ( $module , $permlevel1 , $permlevel2 = '' )
{
2021-09-19 00:50:23 +02:00
// For compatibility with bad naming permissions on module
$moduletomoduletouse = array (
2023-01-31 16:05:19 +01:00
'compta' => 'comptabilite' ,
2021-09-19 00:50:23 +02:00
'contract' => 'contrat' ,
2022-09-08 12:29:46 +02:00
'member' => 'adherent' ,
2021-09-19 00:50:23 +02:00
'mo' => 'mrp' ,
'order' => 'commande' ,
2022-09-08 12:29:33 +02:00
'produit' => 'product' ,
2021-09-19 00:50:23 +02:00
'project' => 'projet' ,
2022-09-07 16:39:19 +02:00
'propale' => 'propal' ,
2021-09-19 00:50:23 +02:00
'shipping' => 'expedition' ,
'task' => 'task@projet' ,
'fichinter' => 'ficheinter' ,
2021-12-19 03:54:04 +01:00
'inventory' => 'stock' ,
2021-09-19 00:50:23 +02:00
'invoice' => 'facture' ,
'invoice_supplier' => 'fournisseur' ,
2022-09-24 09:13:19 +02:00
'order_supplier' => 'fournisseur' ,
2021-10-05 12:42:42 +02:00
'knowledgerecord' => 'knowledgerecord@knowledgemanagement' ,
'skill@hrm' => 'all@hrm' , // skill / job / position objects rights are for the moment grouped into right level "all"
'job@hrm' => 'all@hrm' , // skill / job / position objects rights are for the moment grouped into right level "all"
2022-05-13 10:46:02 +02:00
'position@hrm' => 'all@hrm' , // skill / job / position objects rights are for the moment grouped into right level "all"
2023-03-17 11:42:06 +01:00
'facturerec' => 'facture' ,
'margins' => 'margin' ,
2021-09-19 00:50:23 +02:00
);
2022-06-09 13:15:40 +02:00
2021-09-19 00:50:23 +02:00
if ( ! empty ( $moduletomoduletouse [ $module ])) {
$module = $moduletomoduletouse [ $module ];
}
2022-06-09 13:15:40 +02:00
$moduleRightsMapping = array (
2024-02-09 15:58:49 +01:00
'product' => 'produit' ,
2023-01-31 16:05:19 +01:00
'margin' => 'margins' ,
'comptabilite' => 'compta'
2022-06-09 13:15:40 +02:00
);
2022-06-09 13:20:59 +02:00
2022-06-09 13:15:40 +02:00
$rightsPath = $module ;
if ( ! empty ( $moduleRightsMapping [ $rightsPath ])) {
$rightsPath = $moduleRightsMapping [ $rightsPath ];
}
2024-02-09 15:58:49 +01:00
// If module is abc@module, we check permission user->hasRight(module, abc, permlevel1)
2022-06-09 13:15:40 +02:00
$tmp = explode ( '@' , $rightsPath , 2 );
2022-08-31 22:14:20 +02:00
if ( ! empty ( $tmp [ 1 ])) {
2022-09-21 01:30:40 +02:00
if ( strpos ( $module , '@' ) !== false ) {
$module = $tmp [ 1 ];
}
2024-02-16 23:56:07 +01:00
if ( $tmp [ 0 ] != $tmp [ 1 ]) {
// If $module = 'myobject@mymodule'
$rightsPath = $tmp [ 1 ];
$permlevel2 = $permlevel1 ;
$permlevel1 = $tmp [ 0 ];
} else {
// If $module = 'abc@abc'
$rightsPath = $tmp [ 1 ];
}
2021-09-19 00:50:23 +02:00
}
2022-09-08 12:29:33 +02:00
// In $conf->modules, we have 'accounting', 'product', 'facture', ...
// In $user->rights, we have 'accounting', 'produit', 'facture', ...
2022-09-08 16:38:39 +02:00
//var_dump($this->rights->$rightsPath);
//var_dump($conf->modules);
2024-02-17 00:10:41 +01:00
//var_dump($module.' '.isModEnabled($module).' '.$rightsPath.' '.$permlevel1.' '.$permlevel2);
2022-09-09 13:58:54 +02:00
if ( ! isModEnabled ( $module )) {
2021-09-19 00:50:23 +02:00
return 0 ;
}
2024-01-09 14:24:21 +01:00
// Special case for external user
if ( ! empty ( $this -> socid )) {
if ( $module = 'societe' && $permlevel1 = 'client' && $permlevel2 == 'voir' ) {
return 0 ; // An external user never has the permission ->societe->client->voir to see all thirdparties (always restricted to himself)
}
}
2021-09-19 00:50:23 +02:00
// For compatibility with bad naming permissions on permlevel1
if ( $permlevel1 == 'propale' ) {
$permlevel1 = 'propal' ;
}
if ( $permlevel1 == 'member' ) {
$permlevel1 = 'adherent' ;
}
if ( $permlevel1 == 'recruitmentcandidature' ) {
$permlevel1 = 'recruitmentjobposition' ;
}
2022-09-08 12:29:33 +02:00
2022-06-09 13:15:40 +02:00
//var_dump($this->rights);
2023-01-31 16:05:19 +01:00
//var_dump($rightsPath.' '.$permlevel1.' '.$permlevel2);
2022-06-09 13:15:40 +02:00
if ( empty ( $rightsPath ) || empty ( $this -> rights ) || empty ( $this -> rights -> $rightsPath ) || empty ( $permlevel1 )) {
2021-08-24 14:47:50 +02:00
return 0 ;
}
if ( $permlevel2 ) {
2022-06-09 13:15:40 +02:00
if ( ! empty ( $this -> rights -> $rightsPath -> $permlevel1 )) {
if ( ! empty ( $this -> rights -> $rightsPath -> $permlevel1 -> $permlevel2 )) {
return $this -> rights -> $rightsPath -> $permlevel1 -> $permlevel2 ;
2021-09-19 00:50:23 +02:00
}
// For backward compatibility with old permissions called "lire", "creer", "create", "supprimer"
// instead of "read", "write", "delete"
2022-06-09 13:15:40 +02:00
if ( $permlevel2 == 'read' && ! empty ( $this -> rights -> $rightsPath -> $permlevel1 -> lire )) {
2022-07-29 13:04:04 +02:00
return $this -> rights -> $rightsPath -> $permlevel1 -> lire ;
2021-09-19 00:50:23 +02:00
}
2022-06-09 13:15:40 +02:00
if ( $permlevel2 == 'write' && ! empty ( $this -> rights -> $rightsPath -> $permlevel1 -> creer )) {
2022-08-02 11:53:33 +02:00
return $this -> rights -> $rightsPath -> $permlevel1 -> creer ;
2021-09-19 00:50:23 +02:00
}
2022-06-09 13:15:40 +02:00
if ( $permlevel2 == 'write' && ! empty ( $this -> rights -> $rightsPath -> $permlevel1 -> create )) {
2022-07-29 13:04:04 +02:00
return $this -> rights -> $rightsPath -> $permlevel1 -> create ;
2021-09-19 00:50:23 +02:00
}
2022-06-09 13:15:40 +02:00
if ( $permlevel2 == 'delete' && ! empty ( $this -> rights -> $rightsPath -> $permlevel1 -> supprimer )) {
2022-07-29 13:04:04 +02:00
return $this -> rights -> $rightsPath -> $permlevel1 -> supprimer ;
2021-09-19 00:50:23 +02:00
}
2021-08-24 14:47:50 +02:00
}
} else {
2022-06-09 13:15:40 +02:00
if ( ! empty ( $this -> rights -> $rightsPath -> $permlevel1 )) {
return $this -> rights -> $rightsPath -> $permlevel1 ;
2021-08-24 14:47:50 +02:00
}
2021-09-19 00:50:23 +02:00
// For backward compatibility with old permissions called "lire", "creer", "create", "supprimer"
// instead of "read", "write", "delete"
2022-06-09 13:15:40 +02:00
if ( $permlevel1 == 'read' && ! empty ( $this -> rights -> $rightsPath -> lire )) {
return $this -> rights -> $rightsPath -> lire ;
2021-09-19 00:50:23 +02:00
}
2022-06-09 13:15:40 +02:00
if ( $permlevel1 == 'write' && ! empty ( $this -> rights -> $rightsPath -> creer )) {
2022-08-02 11:53:33 +02:00
return $this -> rights -> $rightsPath -> creer ;
2021-09-19 00:50:23 +02:00
}
2022-06-09 13:15:40 +02:00
if ( $permlevel1 == 'write' && ! empty ( $this -> rights -> $rightsPath -> create )) {
return $this -> rights -> $rightsPath -> create ;
2021-09-19 00:50:23 +02:00
}
2022-06-09 13:15:40 +02:00
if ( $permlevel1 == 'delete' && ! empty ( $this -> rights -> $rightsPath -> supprimer )) {
return $this -> rights -> $rightsPath -> supprimer ;
2021-09-19 00:50:23 +02:00
}
2021-08-24 14:47:50 +02:00
}
return 0 ;
}
2008-07-19 18:53:56 +02:00
/**
2014-10-16 06:20:54 +02:00
* Add a right to the user
2011-09-04 20:41:19 +02:00
*
2018-07-02 09:34:34 +02:00
* @ param int $rid Id of permission to add or 0 to add several permissions
2019-06-20 02:43:56 +02:00
* @ param string $allmodule Add all permissions of module $allmodule or 'allmodules' to include all modules .
* @ param string $allperms Add all permissions of module $allmodule , subperms $allperms only or '' to include all permissions .
2012-09-27 11:54:51 +02:00
* @ param int $entity Entity to use
2017-10-07 13:09:31 +02:00
* @ param int $notrigger 1 = Does not execute triggers , 0 = Execute triggers
2012-09-27 11:54:51 +02:00
* @ return int > 0 if OK , < 0 if KO
2021-08-24 14:47:50 +02:00
* @ see clearrights (), delrights (), getrights (), hasRight ()
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function addrights ( $rid , $allmodule = '' , $allperms = '' , $entity = 0 , $notrigger = 0 )
2008-07-19 18:53:56 +02:00
{
2017-02-28 11:48:46 +01:00
global $conf , $user , $langs ;
2009-05-07 01:30:49 +02:00
2021-12-09 11:07:38 +01:00
$entity = ( empty ( $entity ) ? $conf -> entity : $entity );
dol_syslog ( get_class ( $this ) . " ::addrights $rid , $allmodule , $allperms , $entity , $notrigger for user id= " . $this -> id );
2012-09-27 11:54:51 +02:00
2023-04-13 18:30:06 +02:00
if ( empty ( $this -> id )) {
$this -> error = 'Try to call addrights on an object user with an empty id' ;
return - 1 ;
}
2019-11-13 19:35:39 +01:00
$error = 0 ;
$whereforadd = '' ;
2008-07-19 18:53:56 +02:00
$this -> db -> begin ();
2020-10-29 00:34:41 +01:00
if ( ! empty ( $rid )) {
2020-11-07 19:39:51 +01:00
$module = $perms = $subperms = '' ;
2021-12-09 11:07:38 +01:00
// If we ask to add a given permission, we first load properties of this permission (module, perms and subperms).
2008-07-19 18:53:56 +02:00
$sql = " SELECT module, perms, subperms " ;
2022-01-21 16:57:57 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " rights_def " ;
2020-11-07 19:39:51 +01:00
$sql .= " WHERE id = " . (( int ) $rid );
$sql .= " AND entity = " . (( int ) $entity );
2008-07-19 18:53:56 +02:00
2019-11-13 19:35:39 +01:00
$result = $this -> db -> query ( $sql );
2008-07-19 18:53:56 +02:00
if ( $result ) {
$obj = $this -> db -> fetch_object ( $result );
2020-11-07 19:39:51 +01:00
if ( $obj ) {
$module = $obj -> module ;
$perms = $obj -> perms ;
$subperms = $obj -> subperms ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-02-28 11:48:46 +01:00
$error ++ ;
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-07-19 18:53:56 +02:00
}
2021-12-09 11:07:38 +01:00
// Define the where for the permission to add
2020-11-07 19:39:51 +01:00
$whereforadd = " id= " . (( int ) $rid );
2021-12-09 11:07:38 +01:00
// Add also inherited permissions
2020-10-29 00:34:41 +01:00
if ( ! empty ( $subperms )) {
2020-11-07 19:39:51 +01:00
$whereforadd .= " OR (module=' " . $this -> db -> escape ( $module ) . " ' AND perms=' " . $this -> db -> escape ( $perms ) . " ' AND (subperms='lire' OR subperms='read')) " ;
2020-10-29 00:34:41 +01:00
} elseif ( ! empty ( $perms )) {
2020-11-07 19:39:51 +01:00
$whereforadd .= " OR (module=' " . $this -> db -> escape ( $module ) . " ' AND (perms='lire' OR perms='read') AND subperms IS NULL) " ;
2020-10-29 00:34:41 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2024-01-11 10:01:34 +01:00
// A list of permission was requested (not a single specific permission)
// based on the name of a module of permissions
// Used in the where clause to determine the list of permissions to add.
2020-10-29 00:34:41 +01:00
if ( ! empty ( $allmodule )) {
if ( $allmodule == 'allmodules' ) {
2019-11-13 19:35:39 +01:00
$whereforadd = 'allmodules' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$whereforadd = " module=' " . $this -> db -> escape ( $allmodule ) . " ' " ;
2020-10-29 00:34:41 +01:00
if ( ! empty ( $allperms )) {
$whereforadd .= " AND perms=' " . $this -> db -> escape ( $allperms ) . " ' " ;
}
2018-07-03 21:46:20 +02:00
}
2017-10-22 13:05:47 +02:00
}
2008-07-19 18:53:56 +02:00
}
2021-04-05 13:52:19 +02:00
// Add automatically other permission using the criteria whereforadd
2023-03-26 01:45:59 +01:00
// $whereforadd can be a SQL filter or the string 'allmodules'
2020-10-29 00:34:41 +01:00
if ( ! empty ( $whereforadd )) {
2008-07-19 18:53:56 +02:00
//print "$module-$perms-$subperms";
$sql = " SELECT id " ;
2022-01-21 16:57:57 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " rights_def " ;
2021-08-23 19:33:24 +02:00
$sql .= " WHERE entity = " . (( int ) $entity );
2019-11-13 19:35:39 +01:00
if ( ! empty ( $whereforadd ) && $whereforadd != 'allmodules' ) {
2021-12-09 11:12:40 +01:00
$sql .= " AND ( " . $whereforadd . " ) " ; // Note: parenthesis are important because whereforadd can contains OR. Also note that $whereforadd is already sanitized
2018-07-03 21:46:20 +02:00
}
2008-07-19 18:53:56 +02:00
2023-03-26 01:45:59 +01:00
$sqldelete = " DELETE FROM " . $this -> db -> prefix () . " user_rights " ;
$sqldelete .= " WHERE fk_user = " . (( int ) $this -> id ) . " AND fk_id IN ( " ;
$sqldelete .= $sql ;
$sqldelete .= " ) AND entity = " . (( int ) $entity );
if ( ! $this -> db -> query ( $sqldelete )) {
$error ++ ;
}
2022-05-08 15:18:34 +02:00
2023-03-26 01:45:59 +01:00
if ( ! $error ) {
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num ) {
$obj = $this -> db -> fetch_object ( $resql );
if ( $obj ) {
$nid = $obj -> id ;
$sql = " INSERT INTO " . $this -> db -> prefix () . " user_rights (entity, fk_user, fk_id) VALUES ( " . (( int ) $entity ) . " , " . (( int ) $this -> id ) . " , " . (( int ) $nid ) . " ) " ;
if ( ! $this -> db -> query ( $sql )) {
$error ++ ;
}
2022-05-08 15:18:34 +02:00
}
2008-07-19 18:53:56 +02:00
2023-03-26 01:45:59 +01:00
$i ++ ;
}
} else {
$error ++ ;
dol_print_error ( $this -> db );
2008-07-19 18:53:56 +02:00
}
}
}
2020-10-29 00:34:41 +01:00
if ( ! $error && ! $notrigger ) {
2017-12-08 12:38:22 +01:00
$langs -> load ( " other " );
2024-03-08 21:34:18 +01:00
$this -> context = array ( 'audit' => $langs -> trans ( " PermissionsAdd " ) . ( $rid ? ' (id=' . $rid . ')' : '' ));
2017-03-13 15:00:44 +01:00
2017-10-07 13:09:31 +02:00
// Call trigger
2019-11-13 19:35:39 +01:00
$result = $this -> call_trigger ( 'USER_MODIFY' , $user );
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2017-10-07 13:09:31 +02:00
// End call triggers
2017-02-28 11:48:46 +01:00
}
2017-03-13 15:00:44 +01:00
2017-02-28 11:48:46 +01:00
if ( $error ) {
2008-07-19 18:53:56 +02:00
$this -> db -> rollback ();
2017-02-28 11:48:46 +01:00
return - $error ;
2020-05-21 15:05:19 +02:00
} else {
2008-07-19 18:53:56 +02:00
$this -> db -> commit ();
return 1 ;
}
}
2004-08-07 20:47:54 +02:00
2006-11-26 20:19:46 +01:00
/**
2014-10-16 06:20:54 +02:00
* Remove a right to the user
2011-09-04 20:41:19 +02:00
*
2011-09-20 19:34:15 +02:00
* @ param int $rid Id du droit a retirer
* @ param string $allmodule Retirer tous les droits du module allmodule
* @ param string $allperms Retirer tous les droits du module allmodule , perms allperms
2017-02-28 20:55:14 +01:00
* @ param int $entity Entity to use
2017-10-07 13:09:31 +02:00
* @ param int $notrigger 1 = Does not execute triggers , 0 = Execute triggers
2012-01-11 01:06:56 +01:00
* @ return int > 0 if OK , < 0 if OK
2021-08-24 14:47:50 +02:00
* @ see clearrights (), addrights (), getrights (), hasRight ()
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function delrights ( $rid , $allmodule = '' , $allperms = '' , $entity = 0 , $notrigger = 0 )
2008-07-19 18:53:56 +02:00
{
2017-02-28 11:48:46 +01:00
global $conf , $user , $langs ;
2009-05-07 01:30:49 +02:00
2019-11-13 19:35:39 +01:00
$error = 0 ;
$wherefordel = '' ;
$entity = ( ! empty ( $entity ) ? $entity : $conf -> entity );
2008-07-19 18:53:56 +02:00
$this -> db -> begin ();
2019-11-13 19:35:39 +01:00
if ( ! empty ( $rid )) {
2020-11-07 19:39:51 +01:00
$module = $perms = $subperms = '' ;
2024-01-11 10:01:34 +01:00
// When the request is to delete a specific permissions, this gets the
// les charactis for the module, permissions and sub-permission of this permission.
2008-07-19 18:53:56 +02:00
$sql = " SELECT module, perms, subperms " ;
2022-01-21 16:57:57 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " rights_def " ;
2019-11-13 19:35:39 +01:00
$sql .= " WHERE id = ' " . $this -> db -> escape ( $rid ) . " ' " ;
2021-08-23 19:33:24 +02:00
$sql .= " AND entity = " . (( int ) $entity );
2008-07-19 18:53:56 +02:00
2019-11-13 19:35:39 +01:00
$result = $this -> db -> query ( $sql );
2008-07-19 18:53:56 +02:00
if ( $result ) {
$obj = $this -> db -> fetch_object ( $result );
2020-11-07 19:39:51 +01:00
if ( $obj ) {
$module = $obj -> module ;
$perms = $obj -> perms ;
$subperms = $obj -> subperms ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-02-28 11:48:46 +01:00
$error ++ ;
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-07-19 18:53:56 +02:00
}
2024-01-11 10:01:34 +01:00
// Where clause for the list of permissions to delete
2020-11-07 19:39:51 +01:00
$wherefordel = " id= " . (( int ) $rid );
2008-07-19 18:53:56 +02:00
// Suppression des droits induits
2020-10-29 00:34:41 +01:00
if ( $subperms == 'lire' || $subperms == 'read' ) {
2020-11-07 19:39:51 +01:00
$wherefordel .= " OR (module=' " . $this -> db -> escape ( $module ) . " ' AND perms=' " . $this -> db -> escape ( $perms ) . " ' AND subperms IS NOT NULL) " ;
2020-10-29 00:34:41 +01:00
}
if ( $perms == 'lire' || $perms == 'read' ) {
2020-11-07 19:39:51 +01:00
$wherefordel .= " OR (module=' " . $this -> db -> escape ( $module ) . " ') " ;
2020-10-29 00:34:41 +01:00
}
2019-02-25 20:35:59 +01:00
} else {
2024-01-11 10:01:34 +01:00
// The deletion of the permissions concerns the name of a module or
// list of permissions.
// Used in the Where clause to determine the list of permission to delete
2020-10-29 18:37:52 +01:00
if ( ! empty ( $allmodule )) {
if ( $allmodule == 'allmodules' ) {
2019-11-13 19:35:39 +01:00
$wherefordel = 'allmodules' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$wherefordel = " module=' " . $this -> db -> escape ( $allmodule ) . " ' " ;
2020-10-29 18:37:52 +01:00
if ( ! empty ( $allperms )) {
$wherefordel .= " AND perms=' " . $this -> db -> escape ( $allperms ) . " ' " ;
}
2018-07-03 21:46:20 +02:00
}
}
2008-07-19 18:53:56 +02:00
}
// Suppression des droits selon critere defini dans wherefordel
2020-10-29 00:34:41 +01:00
if ( ! empty ( $wherefordel )) {
2008-07-19 18:53:56 +02:00
//print "$module-$perms-$subperms";
$sql = " SELECT id " ;
2022-01-21 16:57:57 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " rights_def " ;
2021-08-23 19:33:24 +02:00
$sql .= " WHERE entity = " . (( int ) $entity );
2019-11-13 19:35:39 +01:00
if ( ! empty ( $wherefordel ) && $wherefordel != 'allmodules' ) {
2021-12-09 11:12:40 +01:00
$sql .= " AND ( " . $wherefordel . " ) " ; // Note: parenthesis are important because wherefordel can contains OR. Also note that $wherefordel is already sanitized
2018-07-03 21:46:20 +02:00
}
2008-07-19 18:53:56 +02:00
2020-09-23 13:18:09 +02:00
// avoid admin can remove his own important rights
2020-10-29 00:34:41 +01:00
if ( $this -> admin == 1 ) {
2020-10-07 15:01:28 +02:00
$sql .= " AND id NOT IN (251, 252, 253, 254, 255, 256) " ; // other users rights
$sql .= " AND id NOT IN (341, 342, 343, 344) " ; // own rights
$sql .= " AND id NOT IN (351, 352, 353, 354) " ; // groups rights
$sql .= " AND id NOT IN (358) " ; // user export
2020-09-23 13:18:09 +02:00
}
2023-03-26 01:45:59 +01:00
$sqldelete = " DELETE FROM " . $this -> db -> prefix () . " user_rights " ;
$sqldelete .= " WHERE fk_user = " . (( int ) $this -> id ) . " AND fk_id IN ( " ;
$sqldelete .= $sql ;
$sqldelete .= " ) " ;
$sqldelete .= " AND entity = " . (( int ) $entity );
2008-07-19 18:53:56 +02:00
2023-03-26 01:45:59 +01:00
$resql = $this -> db -> query ( $sqldelete );
if ( ! $resql ) {
2017-02-28 11:48:46 +01:00
$error ++ ;
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-07-19 18:53:56 +02:00
}
}
2020-10-29 00:34:41 +01:00
if ( ! $error && ! $notrigger ) {
2017-12-08 12:38:22 +01:00
$langs -> load ( " other " );
2024-03-08 21:34:18 +01:00
$this -> context = array ( 'audit' => $langs -> trans ( " PermissionsDelete " ) . ( $rid ? ' (id=' . $rid . ')' : '' ));
2017-03-13 15:00:44 +01:00
2017-10-07 13:09:31 +02:00
// Call trigger
2019-11-13 19:35:39 +01:00
$result = $this -> call_trigger ( 'USER_MODIFY' , $user );
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2017-10-07 13:09:31 +02:00
// End call triggers
2017-02-28 11:48:46 +01:00
}
2017-03-13 15:00:44 +01:00
2017-02-28 11:48:46 +01:00
if ( $error ) {
2008-07-19 18:53:56 +02:00
$this -> db -> rollback ();
2017-02-28 11:48:46 +01:00
return - $error ;
2020-05-21 15:05:19 +02:00
} else {
2008-07-19 18:53:56 +02:00
$this -> db -> commit ();
return 1 ;
}
}
/**
2011-09-20 19:34:15 +02:00
* Clear all permissions array of user
*
* @ return void
2021-08-24 14:47:50 +02:00
* @ see getrights (), hasRight ()
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function clearrights ()
2008-07-19 18:53:56 +02:00
{
2011-09-24 01:46:14 +02:00
dol_syslog ( get_class ( $this ) . " ::clearrights reset user->rights " );
2024-02-11 11:11:58 +01:00
$this -> rights = new stdClass ();
2019-11-13 19:35:39 +01:00
$this -> nb_rights = 0 ;
$this -> all_permissions_are_loaded = 0 ;
$this -> _tab_loaded = array ();
2006-11-26 20:19:46 +01:00
}
2007-02-28 04:13:34 +01:00
/**
2024-02-26 19:08:00 +01:00
* Load permissions granted to a user -> id into object user -> rights
2011-09-04 20:41:19 +02:00
*
2018-07-02 09:34:34 +02:00
* @ param string $moduletag Limit permission for a particular module ( '' by default means load all permissions )
* @ param int $forcereload Force reload of permissions even if they were already loaded ( ignore cache )
2011-09-20 19:34:15 +02:00
* @ return void
2021-08-24 14:47:50 +02:00
* @ see clearrights (), delrights (), addrights (), hasRight ()
2009-09-10 23:47:22 +02:00
*/
2019-02-25 20:35:59 +01:00
public function getrights ( $moduletag = '' , $forcereload = 0 )
2007-02-28 04:13:34 +01:00
{
2009-04-27 22:37:50 +02:00
global $conf ;
2009-05-07 01:30:49 +02:00
2024-03-13 15:34:29 +01:00
$alreadyloaded = false ;
2020-10-29 00:34:41 +01:00
if ( empty ( $forcereload )) {
if ( $moduletag && isset ( $this -> _tab_loaded [ $moduletag ]) && $this -> _tab_loaded [ $moduletag ]) {
2018-07-02 09:34:34 +02:00
// Rights for this module are already loaded, so we leave
2024-03-13 15:34:29 +01:00
$alreadyloaded = true ;
2018-07-02 09:34:34 +02:00
}
2007-02-28 04:13:34 +01:00
2020-10-29 00:34:41 +01:00
if ( ! empty ( $this -> all_permissions_are_loaded )) {
2018-07-02 09:34:34 +02:00
// We already loaded all rights for this user, so we leave
2024-03-13 15:34:29 +01:00
$alreadyloaded = true ;
2018-07-02 09:34:34 +02:00
}
2007-02-28 04:13:34 +01:00
}
2008-07-19 18:53:56 +02:00
2022-05-08 15:18:34 +02:00
// For avoid error
if ( ! isset ( $this -> rights ) || ! is_object ( $this -> rights )) {
$this -> rights = new stdClass (); // For avoid error
}
if ( ! isset ( $this -> rights -> user ) || ! is_object ( $this -> rights -> user )) {
$this -> rights -> user = new stdClass (); // For avoid error
}
2019-06-18 20:15:04 +02:00
// Get permission of users + Get permissions of groups
2008-07-19 18:53:56 +02:00
2024-03-13 15:34:29 +01:00
if ( ! $alreadyloaded ) {
// First user permissions
$sql = " SELECT DISTINCT r.module, r.perms, r.subperms " ;
$sql .= " FROM " . $this -> db -> prefix () . " user_rights as ur, " ;
$sql .= " " . $this -> db -> prefix () . " rights_def as r " ;
$sql .= " WHERE r.id = ur.fk_id " ;
if ( getDolGlobalString ( 'MULTICOMPANY_BACKWARD_COMPATIBILITY' )) {
// on old version, we use entity defined into table r only
$sql .= " AND r.entity IN (0, " . ( isModEnabled ( 'multicompany' ) && getDolGlobalString ( 'MULTICOMPANY_TRANSVERSE_MODE' ) ? " 1, " : " " ) . $conf -> entity . " ) " ;
} else {
// On table r=rights_def, the unique key is (id, entity) because id is hard coded into module descriptor and insert during module activation.
// So we must include the filter on entity on both table r. and ur.
$sql .= " AND r.entity = " . (( int ) $conf -> entity ) . " AND ur.entity = " . (( int ) $conf -> entity );
}
$sql .= " AND ur.fk_user= " . (( int ) $this -> id );
$sql .= " AND r.perms IS NOT NULL " ;
if ( ! getDolGlobalString ( 'MAIN_USE_ADVANCED_PERMS' )) {
$sql .= " AND r.perms NOT LIKE '%_advance' " ; // Hide advanced perms if option is not enabled
}
if ( $moduletag ) {
$sql .= " AND r.module = ' " . $this -> db -> escape ( $moduletag ) . " ' " ;
}
2007-10-24 01:28:13 +02:00
2024-03-13 15:34:29 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num ) {
$obj = $this -> db -> fetch_object ( $resql );
if ( $obj ) {
$module = $obj -> module ;
$perms = $obj -> perms ;
$subperms = $obj -> subperms ;
if ( ! empty ( $perms )) {
if ( ! empty ( $module )) {
if ( ! isset ( $this -> rights -> $module ) || ! is_object ( $this -> rights -> $module )) {
$this -> rights -> $module = new stdClass ();
2020-11-07 19:39:51 +01:00
}
2024-03-13 15:34:29 +01:00
if ( ! empty ( $subperms )) {
if ( ! isset ( $this -> rights -> $module -> $perms ) || ! is_object ( $this -> rights -> $module -> $perms )) {
$this -> rights -> $module -> $perms = new stdClass ();
}
if ( empty ( $this -> rights -> $module -> $perms -> $subperms )) {
$this -> nb_rights ++ ;
}
$this -> rights -> $module -> $perms -> $subperms = 1 ;
} else {
if ( empty ( $this -> rights -> $module -> $perms )) {
$this -> nb_rights ++ ;
}
$this -> rights -> $module -> $perms = 1 ;
2020-11-07 19:39:51 +01:00
}
2020-10-29 00:34:41 +01:00
}
2017-12-15 15:15:14 +01:00
}
2007-02-28 04:13:34 +01:00
}
2024-03-13 15:34:29 +01:00
$i ++ ;
2007-02-28 04:13:34 +01:00
}
2024-03-13 15:34:29 +01:00
$this -> db -> free ( $resql );
2007-02-28 04:13:34 +01:00
}
2024-03-13 15:34:29 +01:00
// Now permissions of groups
$sql = " SELECT DISTINCT r.module, r.perms, r.subperms " ;
$sql .= " FROM " . $this -> db -> prefix () . " usergroup_rights as gr, " ;
$sql .= " " . $this -> db -> prefix () . " usergroup_user as gu, " ;
$sql .= " " . $this -> db -> prefix () . " rights_def as r " ;
$sql .= " WHERE r.id = gr.fk_id " ;
// A very strange business rules. Must be same than into user->getrights() user/perms.php and user/group/perms.php
if ( getDolGlobalString ( 'MULTICOMPANY_BACKWARD_COMPATIBILITY' )) {
if ( isModEnabled ( 'multicompany' ) && getDolGlobalString ( 'MULTICOMPANY_TRANSVERSE_MODE' )) {
$sql .= " AND gu.entity IN (0, " . $conf -> entity . " ) " ;
} else {
$sql .= " AND r.entity = " . (( int ) $conf -> entity );
}
2017-07-31 06:01:05 +02:00
} else {
2024-03-13 15:34:29 +01:00
$sql .= " AND gr.entity = " . (( int ) $conf -> entity ); // Only groups created in current entity
// The entity on the table usergroup_user should be useless and should never be used because it is already into gr and r.
// but when using MULTICOMPANY_TRANSVERSE_MODE, we may insert record that make rubbish result due to duplicate record of
// other entities, so we are forced to add a filter here
$sql .= " AND gu.entity IN (0, " . $conf -> entity . " ) " ;
$sql .= " AND r.entity = " . (( int ) $conf -> entity ); // Only permission of modules enabled in current entity
}
// End of strange business rule
$sql .= " AND gr.fk_usergroup = gu.fk_usergroup " ;
$sql .= " AND gu.fk_user = " . (( int ) $this -> id );
$sql .= " AND r.perms IS NOT NULL " ;
if ( $moduletag ) {
$sql .= " AND r.module = ' " . $this -> db -> escape ( $moduletag ) . " ' " ;
2017-07-31 06:01:05 +02:00
}
2007-02-28 04:13:34 +01:00
2024-03-13 15:34:29 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num ) {
$obj = $this -> db -> fetch_object ( $resql );
if ( $obj ) {
$module = $obj -> module ;
$perms = $obj -> perms ;
$subperms = $obj -> subperms ;
if ( ! empty ( $perms )) {
if ( ! empty ( $module )) {
if ( ! isset ( $this -> rights -> $module ) || ! is_object ( $this -> rights -> $module )) {
$this -> rights -> $module = new stdClass ();
2020-11-07 19:39:51 +01:00
}
2024-03-13 15:34:29 +01:00
if ( ! empty ( $subperms )) {
if ( ! isset ( $this -> rights -> $module -> $perms ) || ! is_object ( $this -> rights -> $module -> $perms )) {
$this -> rights -> $module -> $perms = new stdClass ();
}
if ( empty ( $this -> rights -> $module -> $perms -> $subperms )) {
$this -> nb_rights ++ ;
}
$this -> rights -> $module -> $perms -> $subperms = 1 ;
} else {
if ( empty ( $this -> rights -> $module -> $perms )) {
$this -> nb_rights ++ ;
}
// if we have already define a subperm like this $this->rights->$module->level1->level2 with llx_user_rights, we don't want override level1 because the level2 can be not define on user group
if ( ! isset ( $this -> rights -> $module -> $perms ) || ! is_object ( $this -> rights -> $module -> $perms )) {
$this -> rights -> $module -> $perms = 1 ;
}
2020-11-07 19:39:51 +01:00
}
}
2020-10-29 00:34:41 +01:00
}
2007-02-28 04:13:34 +01:00
}
2024-03-13 15:34:29 +01:00
$i ++ ;
2007-02-28 04:13:34 +01:00
}
2024-03-13 15:34:29 +01:00
$this -> db -> free ( $resql );
2007-02-28 04:13:34 +01:00
}
2012-04-28 17:59:08 +02:00
2024-03-13 15:34:29 +01:00
// Force permission on user for admin
if ( ! empty ( $this -> admin )) {
if ( empty ( $this -> rights -> user -> user )) {
$this -> rights -> user -> user = new stdClass ();
2022-05-08 15:18:34 +02:00
}
2024-03-13 15:34:29 +01:00
$listofpermtotest = array ( 'lire' , 'creer' , 'password' , 'supprimer' , 'export' );
2022-05-08 15:18:34 +02:00
foreach ( $listofpermtotest as $permtotest ) {
2024-03-13 15:34:29 +01:00
if ( empty ( $this -> rights -> user -> user -> $permtotest )) {
$this -> rights -> user -> user -> $permtotest = 1 ;
2022-05-08 15:18:34 +02:00
$this -> nb_rights ++ ;
}
}
2024-03-13 15:34:29 +01:00
if ( empty ( $this -> rights -> user -> self )) {
$this -> rights -> user -> self = new stdClass ();
2022-05-08 15:18:34 +02:00
}
2024-03-13 15:34:29 +01:00
$listofpermtotest = array ( 'creer' , 'password' );
2022-05-08 15:18:34 +02:00
foreach ( $listofpermtotest as $permtotest ) {
2024-03-13 15:34:29 +01:00
if ( empty ( $this -> rights -> user -> self -> $permtotest )) {
$this -> rights -> user -> self -> $permtotest = 1 ;
2022-05-08 15:18:34 +02:00
$this -> nb_rights ++ ;
}
}
2024-03-13 15:34:29 +01:00
// Add test on advanced permissions
if ( getDolGlobalString ( 'MAIN_USE_ADVANCED_PERMS' )) {
if ( empty ( $this -> rights -> user -> user_advance )) {
$this -> rights -> user -> user_advance = new stdClass ();
}
$listofpermtotest = array ( 'readperms' , 'write' );
foreach ( $listofpermtotest as $permtotest ) {
if ( empty ( $this -> rights -> user -> user_advance -> $permtotest )) {
$this -> rights -> user -> user_advance -> $permtotest = 1 ;
$this -> nb_rights ++ ;
}
}
if ( empty ( $this -> rights -> user -> self_advance )) {
$this -> rights -> user -> self_advance = new stdClass ();
}
$listofpermtotest = array ( 'readperms' , 'writeperms' );
foreach ( $listofpermtotest as $permtotest ) {
if ( empty ( $this -> rights -> user -> self_advance -> $permtotest )) {
$this -> rights -> user -> self_advance -> $permtotest = 1 ;
$this -> nb_rights ++ ;
}
}
if ( empty ( $this -> rights -> user -> group_advance )) {
$this -> rights -> user -> group_advance = new stdClass ();
}
$listofpermtotest = array ( 'read' , 'readperms' , 'write' , 'delete' );
foreach ( $listofpermtotest as $permtotest ) {
if ( empty ( $this -> rights -> user ) || empty ( $this -> rights -> user -> group_advance -> $permtotest )) {
$this -> rights -> user -> group_advance -> $permtotest = 1 ;
$this -> nb_rights ++ ;
}
2022-05-08 15:18:34 +02:00
}
}
}
2024-03-13 15:34:29 +01:00
// For backward compatibility
if ( isset ( $this -> rights -> propale ) && ! isset ( $this -> rights -> propal )) {
$this -> rights -> propal = $this -> rights -> propale ;
}
if ( isset ( $this -> rights -> propal ) && ! isset ( $this -> rights -> propale )) {
$this -> rights -> propale = $this -> rights -> propal ;
}
2007-02-28 04:13:34 +01:00
2024-03-13 15:34:29 +01:00
if ( ! $moduletag ) {
// If the module was not define, then everything is loaded.
// Therefore, we can consider that the permissions are cached
// because they were all loaded for this user instance.
$this -> all_permissions_are_loaded = 1 ;
} else {
// If the module is defined, we flag it as loaded into cache
$this -> _tab_loaded [ $moduletag ] = 1 ;
}
2007-02-28 04:13:34 +01:00
}
}
2003-08-11 20:56:42 +02:00
2008-07-19 18:53:56 +02:00
/**
2011-09-20 19:34:15 +02:00
* Change status of a user
2011-09-04 20:41:19 +02:00
*
2019-11-02 11:36:48 +01:00
* @ param int $status Status to set
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 if KO , 0 if nothing is done , > 0 if OK
2008-07-19 18:53:56 +02:00
*/
2019-11-02 11:36:48 +01:00
public function setstatus ( $status )
2008-01-29 21:34:58 +01:00
{
2019-11-13 19:35:39 +01:00
global $conf , $langs , $user ;
2008-07-19 18:53:56 +02:00
2019-11-13 19:35:39 +01:00
$error = 0 ;
2008-07-19 18:53:56 +02:00
2008-03-20 22:22:35 +01:00
// Check parameters
2023-01-03 11:32:33 +01:00
if ( isset ( $this -> statut )) {
if ( $this -> statut == $status ) {
return 0 ;
}
} elseif ( isset ( $this -> status ) && $this -> status == $status ) {
2020-10-29 00:34:41 +01:00
return 0 ;
}
2008-07-19 18:53:56 +02:00
2008-01-29 21:34:58 +01:00
$this -> db -> begin ();
2008-07-19 18:53:56 +02:00
2019-11-02 11:36:48 +01:00
// Save in database
2022-01-21 16:57:57 +01:00
$sql = " UPDATE " . $this -> db -> prefix () . " user " ;
2021-03-30 03:37:54 +02:00
$sql .= " SET statut = " . (( int ) $status );
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2008-01-29 21:34:58 +01:00
$result = $this -> db -> query ( $sql );
2008-07-19 18:53:56 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::setstatus " , LOG_DEBUG );
2020-10-29 00:34:41 +01:00
if ( $result ) {
2023-10-10 12:22:22 +02:00
if ( $status == 0 ) {
$this -> context [ 'actionmsg' ] = 'User ' . $this -> login . ' disabled' ;
} else {
$this -> context [ 'actionmsg' ] = 'User ' . $this -> login . ' enabled' ;
}
2017-10-07 13:09:31 +02:00
// Call trigger
2019-11-13 19:35:39 +01:00
$result = $this -> call_trigger ( 'USER_ENABLEDISABLE' , $user );
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2017-10-07 13:09:31 +02:00
// End call triggers
2008-01-29 21:34:58 +01:00
}
2008-07-19 18:53:56 +02:00
2020-10-29 00:34:41 +01:00
if ( $error ) {
2008-01-29 21:34:58 +01:00
$this -> db -> rollback ();
return - $error ;
2020-05-21 15:05:19 +02:00
} else {
2021-03-30 03:37:54 +02:00
$this -> status = $status ;
$this -> statut = $status ;
2008-01-29 21:34:58 +01:00
$this -> db -> commit ();
return 1 ;
}
}
2008-07-19 18:53:56 +02:00
2016-02-13 10:27:12 +01:00
/**
* Sets object to supplied categories .
*
* Deletes object from existing categories not supplied .
* Adds it to non existing supplied categories .
* Existing categories are left untouch .
*
2022-12-31 14:01:03 +01:00
* @ param int [] | int $categories Category or categories IDs
2023-12-01 19:51:32 +01:00
* @ return int Return integer < 0 if KO , > 0 if OK
2016-02-13 10:27:12 +01:00
*/
public function setCategories ( $categories )
{
2019-12-05 14:06:03 +01:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2020-12-23 23:32:50 +01:00
return parent :: setCategoriesCommon ( $categories , Categorie :: TYPE_USER );
2016-02-13 10:27:12 +01:00
}
2008-07-19 18:53:56 +02:00
/**
2018-12-22 17:34:27 +01:00
* Delete the user
2011-09-04 20:41:19 +02:00
*
2018-12-22 17:34:27 +01:00
* @ param User $user User than delete
2023-12-01 19:51:32 +01:00
* @ return int Return integer < 0 if KO , > 0 if OK
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function delete ( User $user )
2008-07-19 18:53:56 +02:00
{
2019-11-13 19:35:39 +01:00
global $conf , $langs ;
2008-07-19 18:53:56 +02:00
2019-11-13 19:35:39 +01:00
$error = 0 ;
2012-01-07 15:01:30 +01:00
2008-07-19 18:53:56 +02:00
$this -> db -> begin ();
2010-05-05 19:36:20 +02:00
$this -> fetch ( $this -> id );
2008-07-19 18:53:56 +02:00
2014-06-13 02:28:30 +02:00
dol_syslog ( get_class ( $this ) . " ::delete " , LOG_DEBUG );
2014-10-16 06:20:54 +02:00
// Remove rights
2022-01-21 16:57:57 +01:00
$sql = " DELETE FROM " . $this -> db -> prefix () . " user_rights WHERE fk_user = " . (( int ) $this -> id );
2014-06-13 02:28:30 +02:00
2020-10-29 00:34:41 +01:00
if ( ! $error && ! $this -> db -> query ( $sql )) {
2012-12-02 13:51:33 +01:00
$error ++ ;
2017-10-07 13:09:31 +02:00
$this -> error = $this -> db -> lasterror ();
2010-11-10 11:53:39 +01:00
}
2010-11-15 20:08:35 +01:00
2010-11-10 11:53:39 +01:00
// Remove group
2022-01-21 16:57:57 +01:00
$sql = " DELETE FROM " . $this -> db -> prefix () . " usergroup_user WHERE fk_user = " . (( int ) $this -> id );
2020-10-29 00:34:41 +01:00
if ( ! $error && ! $this -> db -> query ( $sql )) {
2012-12-05 11:18:45 +01:00
$error ++ ;
2017-10-07 13:09:31 +02:00
$this -> error = $this -> db -> lasterror ();
2008-07-19 18:53:56 +02:00
}
2020-09-16 11:48:06 +02:00
// Remove params
2022-01-21 16:57:57 +01:00
$sql = " DELETE FROM " . $this -> db -> prefix () . " user_param WHERE fk_user = " . (( int ) $this -> id );
2020-10-29 00:34:41 +01:00
if ( ! $error && ! $this -> db -> query ( $sql )) {
2012-12-05 11:18:45 +01:00
$error ++ ;
2017-10-07 13:09:31 +02:00
$this -> error = $this -> db -> lasterror ();
2008-07-19 18:53:56 +02:00
}
2014-10-16 06:20:54 +02:00
// If contact, remove link
2020-10-29 00:34:41 +01:00
if ( $this -> contact_id > 0 ) {
2022-01-21 16:57:57 +01:00
$sql = " UPDATE " . $this -> db -> prefix () . " socpeople SET fk_user_creat = null WHERE rowid = " . (( int ) $this -> contact_id );
2020-10-29 00:34:41 +01:00
if ( ! $error && ! $this -> db -> query ( $sql )) {
2012-12-02 13:51:33 +01:00
$error ++ ;
2017-10-07 13:09:31 +02:00
$this -> error = $this -> db -> lasterror ();
2008-07-19 18:53:56 +02:00
}
}
2012-12-08 19:23:13 +01:00
// Remove extrafields
2020-10-29 00:34:41 +01:00
if ( ! $error ) {
2020-09-07 10:18:17 +02:00
$result = $this -> deleteExtraFields ();
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
2020-09-07 10:18:17 +02:00
$error ++ ;
dol_syslog ( get_class ( $this ) . " ::delete error -4 " . $this -> error , LOG_ERR );
}
2017-10-07 13:09:31 +02:00
}
2012-12-02 13:51:33 +01:00
// Remove user
2020-10-29 00:34:41 +01:00
if ( ! $error ) {
2022-01-21 16:57:57 +01:00
$sql = " DELETE FROM " . $this -> db -> prefix () . " user WHERE rowid = " . (( int ) $this -> id );
2020-10-29 00:34:41 +01:00
dol_syslog ( get_class ( $this ) . " ::delete " , LOG_DEBUG );
if ( ! $this -> db -> query ( $sql )) {
$error ++ ;
$this -> error = $this -> db -> lasterror ();
}
2017-10-07 13:09:31 +02:00
}
2012-12-02 13:51:33 +01:00
2020-10-29 00:34:41 +01:00
if ( ! $error ) {
2017-10-07 13:09:31 +02:00
// Call trigger
2019-11-13 19:35:39 +01:00
$result = $this -> call_trigger ( 'USER_DELETE' , $user );
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
2017-10-07 13:09:31 +02:00
$error ++ ;
$this -> db -> rollback ();
return - 1 ;
}
// End call triggers
2014-07-05 08:59:41 +02:00
2008-07-19 18:53:56 +02:00
$this -> db -> commit ();
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2008-07-19 18:53:56 +02:00
$this -> db -> rollback ();
return - 1 ;
}
}
/**
2010-11-15 20:08:35 +01:00
* Create a user into database
2011-09-04 20:41:19 +02:00
*
2024-01-11 10:01:34 +01:00
* @ param User $user Object user doing creation
2015-08-20 15:18:36 +02:00
* @ param int $notrigger 1 = do not execute triggers , 0 otherwise
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 if KO , id of created user if OK
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function create ( $user , $notrigger = 0 )
2007-09-09 22:10:20 +02:00
{
2019-11-13 19:35:39 +01:00
global $conf , $langs ;
2012-03-11 21:45:17 +01:00
global $mysoc ;
2008-07-19 18:53:56 +02:00
2009-05-07 01:30:49 +02:00
// Clean parameters
2020-10-28 20:57:36 +01:00
$this -> setUpperOrLowerCase ();
2019-12-12 17:29:11 +01:00
2022-07-16 15:20:45 +02:00
$this -> civility_code = trim (( string ) $this -> civility_code );
$this -> login = trim (( string ) $this -> login );
2020-10-29 00:34:41 +01:00
if ( ! isset ( $this -> entity )) {
$this -> entity = $conf -> entity ; // If not defined, we use default value
}
2008-07-19 18:53:56 +02:00
2019-11-13 19:35:39 +01:00
dol_syslog ( get_class ( $this ) . " ::create login= " . $this -> login . " , user= " . ( is_object ( $user ) ? $user -> id : '' ), LOG_DEBUG );
2008-07-19 18:53:56 +02:00
2022-01-25 16:01:50 +01:00
$badCharUnauthorizedIntoLoginName = getDolGlobalString ( 'MAIN_LOGIN_BADCHARUNAUTHORIZED' , ',@<>"\'' );
2022-01-04 12:05:06 +01:00
2010-01-08 18:33:30 +01:00
// Check parameters
2024-01-12 20:40:34 +01:00
if ( getDolGlobalString ( 'USER_MAIL_REQUIRED' ) && ! isValidEmail ( $this -> email )) {
2010-01-08 18:33:30 +01:00
$langs -> load ( " errors " );
2019-01-27 11:55:16 +01:00
$this -> error = $langs -> trans ( " ErrorBadEMail " , $this -> email );
2010-01-08 18:33:30 +01:00
return - 1 ;
}
2020-10-28 20:57:36 +01:00
if ( empty ( $this -> login )) {
2015-08-20 15:18:36 +02:00
$langs -> load ( " errors " );
2019-01-27 11:55:16 +01:00
$this -> error = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Login " ));
2015-08-20 15:18:36 +02:00
return - 1 ;
2022-01-25 16:01:50 +01:00
} elseif ( preg_match ( '/[' . preg_quote ( $badCharUnauthorizedIntoLoginName , '/' ) . ']/' , $this -> login )) {
2021-07-21 00:35:08 +02:00
$langs -> load ( " errors " );
2022-11-30 17:37:29 +01:00
$this -> error = $langs -> trans ( " ErrorBadCharIntoLoginName " , $langs -> transnoentitiesnoconv ( " Login " ));
2021-07-21 00:35:08 +02:00
return - 1 ;
2015-08-20 15:18:36 +02:00
}
2010-01-08 18:33:30 +01:00
2011-11-30 11:27:48 +01:00
$this -> datec = dol_now ();
2010-05-05 19:27:12 +02:00
2019-11-13 19:35:39 +01:00
$error = 0 ;
2007-09-09 22:10:20 +02:00
$this -> db -> begin ();
2008-07-19 18:53:56 +02:00
2021-06-13 19:05:48 +02:00
// Check if login already exists in same entity or into entity 0.
if ( $this -> login ) {
2022-01-21 16:57:57 +01:00
$sqltochecklogin = " SELECT COUNT(*) as nb FROM " . $this -> db -> prefix () . " user WHERE entity IN ( " . $this -> db -> sanitize (( int ) $this -> entity ) . " , 0) AND login = ' " . $this -> db -> escape ( $this -> login ) . " ' " ;
2021-06-13 19:05:48 +02:00
$resqltochecklogin = $this -> db -> query ( $sqltochecklogin );
if ( $resqltochecklogin ) {
$objtochecklogin = $this -> db -> fetch_object ( $resqltochecklogin );
if ( $objtochecklogin && $objtochecklogin -> nb > 0 ) {
$langs -> load ( " errors " );
$this -> error = $langs -> trans ( " ErrorLoginAlreadyExists " , $this -> login );
dol_syslog ( get_class ( $this ) . " ::create " . $this -> error , LOG_DEBUG );
$this -> db -> rollback ();
return - 6 ;
}
$this -> db -> free ( $resqltochecklogin );
}
}
2022-02-07 14:25:20 +01:00
if ( ! empty ( $this -> email )) {
2022-01-21 16:57:57 +01:00
$sqltochecklogin = " SELECT COUNT(*) as nb FROM " . $this -> db -> prefix () . " user WHERE entity IN ( " . $this -> db -> sanitize (( int ) $this -> entity ) . " , 0) AND email = ' " . $this -> db -> escape ( $this -> email ) . " ' " ;
2021-06-13 19:05:48 +02:00
$resqltochecklogin = $this -> db -> query ( $sqltochecklogin );
if ( $resqltochecklogin ) {
$objtochecklogin = $this -> db -> fetch_object ( $resqltochecklogin );
if ( $objtochecklogin && $objtochecklogin -> nb > 0 ) {
$langs -> load ( " errors " );
$this -> error = $langs -> trans ( " ErrorEmailAlreadyExists " , $this -> email );
dol_syslog ( get_class ( $this ) . " ::create " . $this -> error , LOG_DEBUG );
$this -> db -> rollback ();
return - 6 ;
}
$this -> db -> free ( $resqltochecklogin );
}
}
// Insert into database
2022-01-21 16:57:57 +01:00
$sql = " INSERT INTO " . $this -> db -> prefix () . " user (datec, login, ldap_sid, entity) " ;
2021-08-28 03:09:18 +02:00
$sql .= " VALUES(' " . $this -> db -> idate ( $this -> datec ) . " ', ' " . $this -> db -> escape ( $this -> login ) . " ', ' " . $this -> db -> escape ( $this -> ldap_sid ) . " ', " . (( int ) $this -> entity ) . " ) " ;
2021-06-13 19:05:48 +02:00
$result = $this -> db -> query ( $sql );
2017-03-13 15:00:44 +01:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::create " , LOG_DEBUG );
2021-06-13 19:05:48 +02:00
if ( $result ) {
2022-01-21 16:57:57 +01:00
$this -> id = $this -> db -> last_insert_id ( $this -> db -> prefix () . " user " );
2008-08-30 01:49:53 +02:00
2021-06-13 19:05:48 +02:00
// Set default rights
if ( $this -> set_default_rights () < 0 ) {
$this -> error = 'ErrorFailedToSetDefaultRightOfUser' ;
2007-12-19 11:24:18 +01:00
$this -> db -> rollback ();
2021-06-13 19:05:48 +02:00
return - 5 ;
}
2020-05-28 19:10:06 +02:00
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'MAIN_DEFAULT_WAREHOUSE_USER' ) && getDolGlobalString ( 'STOCK_USERSTOCK_AUTOCREATE' )) {
2021-06-13 19:05:48 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php' ;
$langs -> load ( " stocks " );
2023-08-06 01:14:36 +02:00
2021-06-13 19:05:48 +02:00
$entrepot = new Entrepot ( $this -> db );
$entrepot -> label = $langs -> trans ( " PersonalStock " , $this -> getFullName ( $langs ));
$entrepot -> libelle = $entrepot -> label ; // For backward compatibility
$entrepot -> description = $langs -> trans ( " ThisWarehouseIsPersonalStock " , $this -> getFullName ( $langs ));
$entrepot -> statut = 1 ;
$entrepot -> country_id = $mysoc -> country_id ;
2023-08-06 01:14:36 +02:00
2021-06-13 19:05:48 +02:00
$warehouseid = $entrepot -> create ( $user );
$this -> fk_warehouse = $warehouseid ;
}
2017-03-13 15:00:44 +01:00
2021-06-13 19:05:48 +02:00
// Update minor fields
$result = $this -> update ( $user , 1 , 1 );
if ( $result < 0 ) {
$this -> db -> rollback ();
return - 4 ;
}
2008-08-30 01:49:53 +02:00
2021-06-13 19:05:48 +02:00
if ( ! $notrigger ) {
// Call trigger
$result = $this -> call_trigger ( 'USER_CREATE' , $user );
if ( $result < 0 ) {
$error ++ ;
2006-12-05 23:55:50 +01:00
}
2021-06-13 19:05:48 +02:00
// End call triggers
}
if ( ! $error ) {
$this -> db -> commit ();
return $this -> id ;
} else {
//$this->error=$interface->error;
dol_syslog ( get_class ( $this ) . " ::create " . $this -> error , LOG_ERR );
$this -> db -> rollback ();
return - 3 ;
2006-12-05 23:55:50 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror ();
2006-12-05 23:55:50 +01:00
$this -> db -> rollback ();
2021-06-13 19:05:48 +02:00
return - 2 ;
2006-12-05 23:55:50 +01:00
}
}
2004-08-07 20:47:54 +02:00
2005-09-26 21:37:20 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2007-09-09 22:10:20 +02:00
/**
2011-09-20 19:34:15 +02:00
* Create a user from a contact object . User will be internal but if contact is linked to a third party , user will be external
2011-09-04 20:41:19 +02:00
*
2011-09-20 19:34:15 +02:00
* @ param Contact $contact Object for source contact
* @ param string $login Login to force
* @ param string $password Password to force
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 if error , if OK returns id of created user
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function create_from_contact ( $contact , $login = '' , $password = '' )
2007-09-09 22:10:20 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-11-13 19:35:39 +01:00
global $conf , $user , $langs ;
2008-07-19 18:53:56 +02:00
2019-11-13 19:35:39 +01:00
$error = 0 ;
2012-01-07 15:01:30 +01:00
2015-11-18 06:34:08 +01:00
// Define parameters
2019-02-25 20:35:59 +01:00
$this -> admin = 0 ;
2020-12-05 11:30:18 +01:00
$this -> civility_code = $contact -> civility_code ;
2019-02-25 20:35:59 +01:00
$this -> lastname = $contact -> lastname ;
$this -> firstname = $contact -> firstname ;
2023-08-23 16:26:00 +02:00
//$this->gender = $contact->gender; // contact ha sno gender
2019-02-25 20:35:59 +01:00
$this -> email = $contact -> email ;
2019-10-01 19:59:49 +02:00
$this -> socialnetworks = $contact -> socialnetworks ;
2019-02-25 20:35:59 +01:00
$this -> office_phone = $contact -> phone_pro ;
$this -> office_fax = $contact -> fax ;
$this -> user_mobile = $contact -> phone_mobile ;
$this -> address = $contact -> address ;
$this -> zip = $contact -> zip ;
$this -> town = $contact -> town ;
2021-02-17 15:26:56 +01:00
$this -> setUpperOrLowerCase ();
2019-02-25 20:35:59 +01:00
$this -> state_id = $contact -> state_id ;
$this -> country_id = $contact -> country_id ;
$this -> employee = 0 ;
2017-03-13 15:00:44 +01:00
2020-11-04 13:33:52 +01:00
if ( empty ( $login )) {
include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
$login = dol_buildlogin ( $contact -> lastname , $contact -> firstname );
}
2008-12-17 19:34:47 +01:00
$this -> login = $login ;
2008-07-19 18:53:56 +02:00
$this -> db -> begin ();
2019-10-07 14:16:47 +02:00
// Create user and set $this->id. Trigger is disabled because executed later.
2019-12-18 15:20:36 +01:00
$result = $this -> create ( $user , 1 );
2020-10-29 00:34:41 +01:00
if ( $result > 0 ) {
2022-01-21 16:57:57 +01:00
$sql = " UPDATE " . $this -> db -> prefix () . " user " ;
2021-06-09 15:36:47 +02:00
$sql .= " SET fk_socpeople= " . (( int ) $contact -> id );
2021-01-19 09:24:15 +01:00
$sql .= " , civility=' " . $this -> db -> escape ( $contact -> civility_code ) . " ' " ;
2021-01-19 10:56:46 +01:00
if ( $contact -> socid > 0 ) {
2021-06-09 15:36:47 +02:00
$sql .= " , fk_soc= " . (( int ) $contact -> socid );
2020-10-29 00:34:41 +01:00
}
2021-01-19 10:56:46 +01:00
$sql .= " WHERE rowid= " . (( int ) $this -> id );
2021-01-18 17:06:06 +01:00
2019-12-18 15:20:36 +01:00
$resql = $this -> db -> query ( $sql );
2008-07-19 18:53:56 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::create_from_contact " , LOG_DEBUG );
2020-10-29 00:34:41 +01:00
if ( $resql ) {
2019-12-18 15:20:36 +01:00
$this -> context [ 'createfromcontact' ] = 'createfromcontact' ;
2015-07-19 15:24:54 +02:00
2017-10-07 13:09:31 +02:00
// Call trigger
2019-12-18 15:20:36 +01:00
$result = $this -> call_trigger ( 'USER_CREATE' , $user );
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
2023-12-04 13:53:48 +01:00
$error ++ ;
$this -> db -> rollback ();
return - 1 ;
2020-10-29 00:34:41 +01:00
}
2017-10-07 13:09:31 +02:00
// End call triggers
2014-07-05 08:59:41 +02:00
2008-07-19 18:53:56 +02:00
$this -> db -> commit ();
return $this -> id ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> error ();
2008-07-19 18:53:56 +02:00
$this -> db -> rollback ();
return - 1 ;
}
2020-05-21 15:05:19 +02:00
} else {
2008-07-19 18:53:56 +02:00
// $this->error deja positionne
2011-09-24 01:46:14 +02:00
dol_syslog ( get_class ( $this ) . " ::create_from_contact - 0 " );
2008-07-19 18:53:56 +02:00
$this -> db -> rollback ();
return $result ;
}
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2008-07-19 18:53:56 +02:00
/**
2020-10-14 14:02:07 +02:00
* Create a user into database from a member object .
* If $member -> fk_soc is set , it will be an external user .
2011-09-04 20:41:19 +02:00
*
2020-11-04 13:33:52 +01:00
* @ param Adherent $member Object member source
* @ param string $login Login to force
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 if KO , if OK , return id of created account
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function create_from_member ( $member , $login = '' )
2008-07-19 18:53:56 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-11-13 19:35:39 +01:00
global $conf , $user , $langs ;
2008-07-19 18:53:56 +02:00
2020-01-28 21:23:05 +01:00
// Set properties on new user
2009-01-14 15:59:28 +01:00
$this -> admin = 0 ;
2020-12-05 11:30:18 +01:00
$this -> civility_code = $member -> civility_id ;
2013-03-23 17:40:18 +01:00
$this -> lastname = $member -> lastname ;
$this -> firstname = $member -> firstname ;
2021-02-17 16:39:03 +01:00
$this -> gender = $member -> gender ;
2013-03-23 17:40:18 +01:00
$this -> email = $member -> email ;
$this -> fk_member = $member -> id ;
2013-03-30 14:27:13 +01:00
$this -> address = $member -> address ;
$this -> zip = $member -> zip ;
$this -> town = $member -> town ;
2021-02-17 15:26:56 +01:00
$this -> setUpperOrLowerCase ();
2013-03-30 14:27:13 +01:00
$this -> state_id = $member -> state_id ;
$this -> country_id = $member -> country_id ;
2020-01-28 21:23:05 +01:00
$this -> socialnetworks = $member -> socialnetworks ;
2007-04-27 00:01:10 +02:00
2020-01-28 21:23:05 +01:00
$this -> pass = $member -> pass ;
$this -> pass_crypted = $member -> pass_indatabase_crypted ;
2007-04-27 00:01:10 +02:00
2020-11-04 13:33:52 +01:00
if ( empty ( $login )) {
include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
$login = dol_buildlogin ( $member -> lastname , $member -> firstname );
}
2009-01-14 15:59:28 +01:00
$this -> login = $login ;
2007-04-27 00:01:10 +02:00
2008-07-19 18:53:56 +02:00
$this -> db -> begin ();
2007-04-27 00:01:10 +02:00
2014-01-23 09:19:15 +01:00
// Create and set $this->id
2019-11-13 19:35:39 +01:00
$result = $this -> create ( $user );
2020-10-29 00:34:41 +01:00
if ( $result > 0 ) {
2020-02-02 19:34:09 +01:00
if ( ! empty ( $this -> pass )) { // If a clear password was received (this situation should not happen anymore now), we use it to save it into database
2020-01-28 21:23:05 +01:00
$newpass = $this -> setPassword ( $user , $this -> pass );
2023-09-13 06:44:54 +02:00
if ( is_int ( $newpass ) && $newpass < 0 ) {
2020-10-29 00:34:41 +01:00
$result = - 2 ;
}
2024-01-11 10:07:06 +01:00
} elseif ( ! empty ( $this -> pass_crypted )) { // If an encrypted password is already known, we save it directly into database because the previous create did not save it.
2022-01-21 16:57:57 +01:00
$sql = " UPDATE " . $this -> db -> prefix () . " user " ;
2020-01-28 21:23:05 +01:00
$sql .= " SET pass_crypted = ' " . $this -> db -> escape ( $this -> pass_crypted ) . " ' " ;
2021-03-14 12:20:23 +01:00
$sql .= " WHERE rowid= " . (( int ) $this -> id );
2020-01-28 21:23:05 +01:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( ! $resql ) {
2020-01-28 21:23:05 +01:00
$result = - 1 ;
}
}
2014-02-17 11:48:57 +01:00
2023-01-12 14:40:00 +01:00
if ( $result > 0 && $member -> socid ) { // If member is linked to a thirdparty
2022-01-21 16:57:57 +01:00
$sql = " UPDATE " . $this -> db -> prefix () . " user " ;
2023-01-12 14:40:00 +01:00
$sql .= " SET fk_soc= " . (( int ) $member -> socid );
2021-03-14 12:20:23 +01:00
$sql .= " WHERE rowid= " . (( int ) $this -> id );
2013-02-11 20:45:36 +01:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::create_from_member " , LOG_DEBUG );
2019-11-13 19:35:39 +01:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $resql ) {
2013-01-12 15:16:38 +01:00
$this -> db -> commit ();
return $this -> id ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror ();
2013-02-11 20:45:36 +01:00
2013-01-12 15:16:38 +01:00
$this -> db -> rollback ();
return - 1 ;
}
2008-07-19 18:53:56 +02:00
}
}
2014-01-23 09:19:15 +01:00
2020-10-29 00:34:41 +01:00
if ( $result > 0 ) {
2014-01-23 09:19:15 +01:00
$this -> db -> commit ();
return $this -> id ;
2020-05-21 15:05:19 +02:00
} else {
2008-07-19 18:53:56 +02:00
// $this->error deja positionne
$this -> db -> rollback ();
2014-01-23 09:19:15 +01:00
return - 2 ;
2008-07-19 18:53:56 +02:00
}
}
2007-04-27 00:01:10 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2007-04-27 00:01:10 +02:00
/**
2014-10-16 06:20:54 +02:00
* Assign rights by default
2011-09-04 20:41:19 +02:00
*
2024-01-11 10:01:34 +01:00
* @ return integer erreur < 0 , si ok renvoi le nbre de droits par default positions
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function set_default_rights ()
2008-07-19 18:53:56 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2009-04-27 22:37:50 +02:00
global $conf ;
2009-05-07 01:30:49 +02:00
2020-11-01 20:54:36 +01:00
$rd = array ();
$num = 0 ;
2022-01-21 16:57:57 +01:00
$sql = " SELECT id FROM " . $this -> db -> prefix () . " rights_def " ;
2019-11-13 19:35:39 +01:00
$sql .= " WHERE bydefault = 1 " ;
2021-08-23 19:33:24 +02:00
$sql .= " AND entity = " . (( int ) $conf -> entity );
2008-07-19 18:53:56 +02:00
2019-11-13 19:35:39 +01:00
$resql = $this -> db -> query ( $sql );
2020-11-01 20:54:36 +01:00
if ( $resql ) {
2010-08-14 04:44:07 +02:00
$num = $this -> db -> num_rows ( $resql );
2008-07-19 18:53:56 +02:00
$i = 0 ;
2020-11-01 20:54:36 +01:00
while ( $i < $num ) {
2010-08-14 04:44:07 +02:00
$row = $this -> db -> fetch_row ( $resql );
2008-07-19 18:53:56 +02:00
$rd [ $i ] = $row [ 0 ];
$i ++ ;
}
2010-08-14 04:44:07 +02:00
$this -> db -> free ( $resql );
2008-07-19 18:53:56 +02:00
}
$i = 0 ;
2020-11-01 20:54:36 +01:00
while ( $i < $num ) {
2022-01-21 16:57:57 +01:00
$sql = " DELETE FROM " . $this -> db -> prefix () . " user_rights WHERE fk_user = $this->id AND fk_id= $rd[$i] " ;
2019-11-13 19:35:39 +01:00
$result = $this -> db -> query ( $sql );
2008-07-19 18:53:56 +02:00
2022-01-21 16:57:57 +01:00
$sql = " INSERT INTO " . $this -> db -> prefix () . " user_rights (fk_user, fk_id) VALUES ( $this->id , $rd[$i] ) " ;
2019-11-13 19:35:39 +01:00
$result = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( ! $result ) {
return - 1 ;
}
2008-07-19 18:53:56 +02:00
$i ++ ;
}
return $i ;
}
/**
2013-02-11 20:45:36 +01:00
* Update a user into database ( and also password if this -> pass is defined )
2011-09-04 20:41:19 +02:00
*
2021-06-13 19:05:48 +02:00
* @ param User $user User making update
* @ param int $notrigger 1 = do not execute triggers , 0 by default
2011-09-20 19:34:15 +02:00
* @ param int $nosyncmember 0 = Synchronize linked member ( standard info ), 1 = Do not synchronize linked member
* @ param int $nosyncmemberpass 0 = Synchronize linked member ( password ), 1 = Do not synchronize linked member
2017-12-19 16:16:31 +01:00
* @ param int $nosynccontact 0 = Synchronize linked contact , 1 = Do not synchronize linked contact
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 if KO , >= 0 if OK
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function update ( $user , $notrigger = 0 , $nosyncmember = 0 , $nosyncmemberpass = 0 , $nosynccontact = 0 )
2008-07-19 18:53:56 +02:00
{
2017-02-28 11:20:33 +01:00
global $conf , $langs ;
2008-07-19 18:53:56 +02:00
2019-11-13 19:35:39 +01:00
$nbrowsaffected = 0 ;
$error = 0 ;
2007-09-09 22:10:20 +02:00
2011-09-24 01:46:14 +02:00
dol_syslog ( get_class ( $this ) . " ::update notrigger= " . $notrigger . " , nosyncmember= " . $nosyncmember . " , nosyncmemberpass= " . $nosyncmemberpass );
2008-07-19 18:53:56 +02:00
2009-05-07 01:30:49 +02:00
// Clean parameters
2022-07-16 15:20:45 +02:00
$this -> civility_code = trim (( string ) $this -> civility_code );
$this -> lastname = trim (( string ) $this -> lastname );
$this -> firstname = trim (( string ) $this -> firstname );
$this -> ref_employee = trim (( string ) $this -> ref_employee );
$this -> national_registration_number = trim (( string ) $this -> national_registration_number );
$this -> employee = ( $this -> employee > 0 ? $this -> employee : 0 );
$this -> login = trim (( string ) $this -> login );
$this -> gender = trim (( string ) $this -> gender );
2023-01-27 14:06:31 +01:00
2022-07-16 15:20:45 +02:00
$this -> pass = trim (( string ) $this -> pass );
$this -> api_key = trim (( string ) $this -> api_key );
2023-01-27 14:06:31 +01:00
$this -> datestartvalidity = empty ( $this -> datestartvalidity ) ? '' : $this -> datestartvalidity ;
$this -> dateendvalidity = empty ( $this -> dateendvalidity ) ? '' : $this -> dateendvalidity ;
2022-07-16 15:20:45 +02:00
$this -> address = trim (( string ) $this -> address );
$this -> zip = trim (( string ) $this -> zip );
$this -> town = trim (( string ) $this -> town );
$this -> state_id = ( $this -> state_id > 0 ? $this -> state_id : 0 );
$this -> country_id = ( $this -> country_id > 0 ? $this -> country_id : 0 );
$this -> office_phone = trim (( string ) $this -> office_phone );
$this -> office_fax = trim (( string ) $this -> office_fax );
$this -> user_mobile = trim (( string ) $this -> user_mobile );
$this -> personal_mobile = trim (( string ) $this -> personal_mobile );
$this -> email = trim (( string ) $this -> email );
$this -> personal_email = trim (( string ) $this -> personal_email );
$this -> job = trim (( string ) $this -> job );
$this -> signature = trim (( string ) $this -> signature );
$this -> note_public = trim (( string ) $this -> note_public );
$this -> note_private = trim (( string ) $this -> note_private );
$this -> openid = trim (( string ) $this -> openid );
$this -> admin = ( $this -> admin > 0 ? $this -> admin : 0 );
$this -> accountancy_code = trim (( string ) $this -> accountancy_code );
$this -> color = trim (( string ) $this -> color );
$this -> dateemployment = empty ( $this -> dateemployment ) ? '' : $this -> dateemployment ;
$this -> dateemploymentend = empty ( $this -> dateemploymentend ) ? '' : $this -> dateemploymentend ;
2023-01-27 14:06:31 +01:00
2022-07-16 15:20:45 +02:00
$this -> birth = empty ( $this -> birth ) ? '' : $this -> birth ;
$this -> fk_warehouse = ( int ) $this -> fk_warehouse ;
2017-09-11 00:02:52 +02:00
2022-07-28 15:13:13 +02:00
$this -> setUpperOrLowerCase ();
2010-01-08 18:33:30 +01:00
// Check parameters
2022-01-25 16:03:30 +01:00
$badCharUnauthorizedIntoLoginName = getDolGlobalString ( 'MAIN_LOGIN_BADCHARUNAUTHORIZED' , ',@<>"\'' );
2022-01-04 12:05:06 +01:00
2024-01-12 20:40:34 +01:00
if ( getDolGlobalString ( 'USER_MAIL_REQUIRED' ) && ! isValidEmail ( $this -> email )) {
2010-01-08 18:33:30 +01:00
$langs -> load ( " errors " );
2019-01-27 11:55:16 +01:00
$this -> error = $langs -> trans ( " ErrorBadEMail " , $this -> email );
2010-01-08 18:33:30 +01:00
return - 1 ;
}
2020-10-29 00:34:41 +01:00
if ( empty ( $this -> login )) {
2015-08-20 15:18:36 +02:00
$langs -> load ( " errors " );
2020-09-21 16:31:51 +02:00
$this -> error = $langs -> trans ( " ErrorFieldRequired " , 'Login' );
2015-08-20 15:18:36 +02:00
return - 1 ;
2022-01-25 16:03:30 +01:00
} elseif ( preg_match ( '/[' . preg_quote ( $badCharUnauthorizedIntoLoginName , '/' ) . ']/' , $this -> login )) {
2021-07-21 00:35:08 +02:00
$langs -> load ( " errors " );
2022-11-30 17:37:29 +01:00
$this -> error = $langs -> trans ( " ErrorBadCharIntoLoginName " , $langs -> transnoentitiesnoconv ( " Login " ));
2021-07-21 00:35:08 +02:00
return - 1 ;
2015-08-20 15:18:36 +02:00
}
2016-03-17 09:22:12 +01:00
2008-07-19 18:53:56 +02:00
$this -> db -> begin ();
2021-06-13 16:15:05 +02:00
// Check if login already exists in same entity or into entity 0.
2021-06-13 19:05:48 +02:00
if ( ! empty ( $this -> oldcopy ) && $this -> oldcopy -> login != $this -> login ) {
2022-01-21 16:57:57 +01:00
$sqltochecklogin = " SELECT COUNT(*) as nb FROM " . $this -> db -> prefix () . " user WHERE entity IN ( " . $this -> db -> sanitize (( int ) $this -> entity ) . " , 0) AND login = ' " . $this -> db -> escape ( $this -> login ) . " ' " ;
2021-06-13 16:15:05 +02:00
$resqltochecklogin = $this -> db -> query ( $sqltochecklogin );
if ( $resqltochecklogin ) {
$objtochecklogin = $this -> db -> fetch_object ( $resqltochecklogin );
if ( $objtochecklogin && $objtochecklogin -> nb > 0 ) {
$langs -> load ( " errors " );
$this -> error = $langs -> trans ( " ErrorLoginAlreadyExists " , $this -> login );
2021-06-13 19:05:48 +02:00
dol_syslog ( get_class ( $this ) . " ::create " . $this -> error , LOG_DEBUG );
$this -> db -> rollback ();
2021-06-13 16:15:05 +02:00
return - 1 ;
}
}
}
2022-02-07 14:25:20 +01:00
if ( ! empty ( $this -> oldcopy ) && ! empty ( $this -> email ) && $this -> oldcopy -> email != $this -> email ) {
2022-01-21 16:57:57 +01:00
$sqltochecklogin = " SELECT COUNT(*) as nb FROM " . $this -> db -> prefix () . " user WHERE entity IN ( " . $this -> db -> sanitize (( int ) $this -> entity ) . " , 0) AND email = ' " . $this -> db -> escape ( $this -> email ) . " ' " ;
2021-06-13 16:15:05 +02:00
$resqltochecklogin = $this -> db -> query ( $sqltochecklogin );
if ( $resqltochecklogin ) {
$objtochecklogin = $this -> db -> fetch_object ( $resqltochecklogin );
if ( $objtochecklogin && $objtochecklogin -> nb > 0 ) {
$langs -> load ( " errors " );
$this -> error = $langs -> trans ( " ErrorEmailAlreadyExists " , $this -> email );
2021-06-13 19:05:48 +02:00
dol_syslog ( get_class ( $this ) . " ::create " . $this -> error , LOG_DEBUG );
$this -> db -> rollback ();
2021-06-13 16:15:05 +02:00
return - 1 ;
}
}
}
2024-01-11 10:01:34 +01:00
// Update data
2022-01-21 16:57:57 +01:00
$sql = " UPDATE " . $this -> db -> prefix () . " user SET " ;
2020-12-05 11:30:18 +01:00
$sql .= " civility = ' " . $this -> db -> escape ( $this -> civility_code ) . " ' " ;
$sql .= " , lastname = ' " . $this -> db -> escape ( $this -> lastname ) . " ' " ;
2019-12-18 15:20:36 +01:00
$sql .= " , firstname = ' " . $this -> db -> escape ( $this -> firstname ) . " ' " ;
2022-03-02 11:20:07 +01:00
$sql .= " , ref_employee = ' " . $this -> db -> escape ( $this -> ref_employee ) . " ' " ;
$sql .= " , national_registration_number = ' " . $this -> db -> escape ( $this -> national_registration_number ) . " ' " ;
2019-12-18 15:20:36 +01:00
$sql .= " , employee = " . ( int ) $this -> employee ;
$sql .= " , login = ' " . $this -> db -> escape ( $this -> login ) . " ' " ;
2023-03-13 12:48:25 +01:00
$sql .= " , api_key = " . ( $this -> api_key ? " ' " . $this -> db -> escape ( dolEncrypt ( $this -> api_key , '' , '' , 'dolibarr' )) . " ' " : " null " );
2019-12-18 15:20:36 +01:00
$sql .= " , gender = " . ( $this -> gender != - 1 ? " ' " . $this -> db -> escape ( $this -> gender ) . " ' " : " null " ); // 'man' or 'woman'
2022-04-06 14:09:44 +02:00
$sql .= " , birth= " . ( strval ( $this -> birth ) != '' ? " ' " . $this -> db -> idate ( $this -> birth , 'tzserver' ) . " ' " : 'null' );
2020-10-29 00:34:41 +01:00
if ( ! empty ( $user -> admin )) {
$sql .= " , admin = " . ( int ) $this -> admin ; // admin flag can be set/unset only by an admin user
}
2019-12-18 15:20:36 +01:00
$sql .= " , address = ' " . $this -> db -> escape ( $this -> address ) . " ' " ;
$sql .= " , zip = ' " . $this -> db -> escape ( $this -> zip ) . " ' " ;
$sql .= " , town = ' " . $this -> db -> escape ( $this -> town ) . " ' " ;
$sql .= " , fk_state = " . (( ! empty ( $this -> state_id ) && $this -> state_id > 0 ) ? " ' " . $this -> db -> escape ( $this -> state_id ) . " ' " : " null " );
$sql .= " , fk_country = " . (( ! empty ( $this -> country_id ) && $this -> country_id > 0 ) ? " ' " . $this -> db -> escape ( $this -> country_id ) . " ' " : " null " );
$sql .= " , office_phone = ' " . $this -> db -> escape ( $this -> office_phone ) . " ' " ;
$sql .= " , office_fax = ' " . $this -> db -> escape ( $this -> office_fax ) . " ' " ;
$sql .= " , user_mobile = ' " . $this -> db -> escape ( $this -> user_mobile ) . " ' " ;
2020-09-07 10:18:17 +02:00
$sql .= " , personal_mobile = ' " . $this -> db -> escape ( $this -> personal_mobile ) . " ' " ;
2019-12-18 15:20:36 +01:00
$sql .= " , email = ' " . $this -> db -> escape ( $this -> email ) . " ' " ;
2020-09-07 10:18:17 +02:00
$sql .= " , personal_email = ' " . $this -> db -> escape ( $this -> personal_email ) . " ' " ;
$sql .= " , socialnetworks = ' " . $this -> db -> escape ( json_encode ( $this -> socialnetworks )) . " ' " ;
2019-12-18 15:20:36 +01:00
$sql .= " , job = ' " . $this -> db -> escape ( $this -> job ) . " ' " ;
$sql .= " , signature = ' " . $this -> db -> escape ( $this -> signature ) . " ' " ;
$sql .= " , accountancy_code = ' " . $this -> db -> escape ( $this -> accountancy_code ) . " ' " ;
$sql .= " , color = ' " . $this -> db -> escape ( $this -> color ) . " ' " ;
$sql .= " , dateemployment= " . ( strval ( $this -> dateemployment ) != '' ? " ' " . $this -> db -> idate ( $this -> dateemployment ) . " ' " : 'null' );
$sql .= " , dateemploymentend= " . ( strval ( $this -> dateemploymentend ) != '' ? " ' " . $this -> db -> idate ( $this -> dateemploymentend ) . " ' " : 'null' );
2020-09-21 18:44:20 +02:00
$sql .= " , datestartvalidity= " . ( strval ( $this -> datestartvalidity ) != '' ? " ' " . $this -> db -> idate ( $this -> datestartvalidity ) . " ' " : 'null' );
$sql .= " , dateendvalidity= " . ( strval ( $this -> dateendvalidity ) != '' ? " ' " . $this -> db -> idate ( $this -> dateendvalidity ) . " ' " : 'null' );
2022-09-03 11:07:47 +02:00
$sql .= " , note_private = ' " . $this -> db -> escape ( $this -> note_private ) . " ' " ;
2019-12-18 15:20:36 +01:00
$sql .= " , note_public = ' " . $this -> db -> escape ( $this -> note_public ) . " ' " ;
$sql .= " , photo = " . ( $this -> photo ? " ' " . $this -> db -> escape ( $this -> photo ) . " ' " : " null " );
$sql .= " , openid = " . ( $this -> openid ? " ' " . $this -> db -> escape ( $this -> openid ) . " ' " : " null " );
$sql .= " , fk_user = " . ( $this -> fk_user > 0 ? " ' " . $this -> db -> escape ( $this -> fk_user ) . " ' " : " null " );
2020-09-07 10:18:17 +02:00
$sql .= " , fk_user_expense_validator = " . ( $this -> fk_user_expense_validator > 0 ? " ' " . $this -> db -> escape ( $this -> fk_user_expense_validator ) . " ' " : " null " );
$sql .= " , fk_user_holiday_validator = " . ( $this -> fk_user_holiday_validator > 0 ? " ' " . $this -> db -> escape ( $this -> fk_user_holiday_validator ) . " ' " : " null " );
2020-10-29 00:34:41 +01:00
if ( isset ( $this -> thm ) || $this -> thm != '' ) {
$sql .= " , thm= " . ( $this -> thm != '' ? " ' " . $this -> db -> escape ( $this -> thm ) . " ' " : " null " );
}
if ( isset ( $this -> tjm ) || $this -> tjm != '' ) {
$sql .= " , tjm= " . ( $this -> tjm != '' ? " ' " . $this -> db -> escape ( $this -> tjm ) . " ' " : " null " );
}
if ( isset ( $this -> salary ) || $this -> salary != '' ) {
$sql .= " , salary= " . ( $this -> salary != '' ? " ' " . $this -> db -> escape ( $this -> salary ) . " ' " : " null " );
}
if ( isset ( $this -> salaryextra ) || $this -> salaryextra != '' ) {
$sql .= " , salaryextra= " . ( $this -> salaryextra != '' ? " ' " . $this -> db -> escape ( $this -> salaryextra ) . " ' " : " null " );
}
2019-12-18 15:20:36 +01:00
$sql .= " , weeklyhours= " . ( $this -> weeklyhours != '' ? " ' " . $this -> db -> escape ( $this -> weeklyhours ) . " ' " : " null " );
2021-11-09 18:36:04 +01:00
if ( ! empty ( $user -> admin ) && empty ( $user -> entity ) && $user -> id != $this -> id ) {
$sql .= " , entity = " . (( int ) $this -> entity ); // entity flag can be set/unset only by an another superadmin user
}
2019-12-18 15:20:36 +01:00
$sql .= " , default_range = " . ( $this -> default_range > 0 ? $this -> default_range : 'null' );
$sql .= " , default_c_exp_tax_cat = " . ( $this -> default_c_exp_tax_cat > 0 ? $this -> default_c_exp_tax_cat : 'null' );
2020-11-11 09:26:13 +01:00
$sql .= " , fk_warehouse = " . ( $this -> fk_warehouse > 0 ? $this -> fk_warehouse : " null " );
2020-08-07 14:22:43 +02:00
$sql .= " , lang = " . ( $this -> lang ? " ' " . $this -> db -> escape ( $this -> lang ) . " ' " : " null " );
2021-08-23 19:33:24 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2017-03-13 15:00:44 +01:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::update " , LOG_DEBUG );
2008-07-19 18:53:56 +02:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $resql ) {
2019-12-18 15:20:36 +01:00
$nbrowsaffected += $this -> db -> affected_rows ( $resql );
2008-08-30 01:49:53 +02:00
2009-07-27 02:08:49 +02:00
// Update password
2020-10-29 00:34:41 +01:00
if ( ! empty ( $this -> pass )) {
2023-01-16 10:57:31 +01:00
if ( $this -> pass != $this -> pass_indatabase && ! dol_verifyHash ( $this -> pass , $this -> pass_indatabase_crypted )) {
2024-01-11 10:07:06 +01:00
// If a new value for password is set and different than the one encrypted into database
2023-01-16 10:57:31 +01:00
$result = $this -> setPassword ( $user , $this -> pass , 0 , $notrigger , $nosyncmemberpass , 0 , 1 );
2023-09-13 06:44:54 +02:00
if ( is_int ( $result ) && $result < 0 ) {
2022-01-21 15:26:54 +01:00
return - 5 ;
2020-10-29 00:34:41 +01:00
}
2008-07-19 18:53:56 +02:00
}
}
2008-08-30 01:49:53 +02:00
2009-05-07 01:30:49 +02:00
// If user is linked to a member, remove old link to this member
2020-10-29 00:34:41 +01:00
if ( $this -> fk_member > 0 ) {
2016-06-25 18:48:50 +02:00
dol_syslog ( get_class ( $this ) . " ::update remove link with member. We will recreate it later " , LOG_DEBUG );
2022-01-21 16:57:57 +01:00
$sql = " UPDATE " . $this -> db -> prefix () . " user SET fk_member = NULL where fk_member = " . (( int ) $this -> fk_member );
2009-05-07 01:30:49 +02:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( ! $resql ) {
2023-12-04 13:53:48 +01:00
$this -> error = $this -> db -> error ();
$this -> db -> rollback ();
return - 5 ;
2020-10-29 00:34:41 +01:00
}
2009-05-07 01:30:49 +02:00
}
// Set link to user
2016-06-25 18:48:50 +02:00
dol_syslog ( get_class ( $this ) . " ::update set link with member " , LOG_DEBUG );
2022-01-21 16:57:57 +01:00
$sql = " UPDATE " . $this -> db -> prefix () . " user SET fk_member = " . ( $this -> fk_member > 0 ? (( int ) $this -> fk_member ) : 'null' ) . " where rowid = " . (( int ) $this -> id );
2009-05-07 01:30:49 +02:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( ! $resql ) {
2023-12-04 13:53:48 +01:00
$this -> error = $this -> db -> error ();
$this -> db -> rollback ();
return - 5 ;
2020-10-29 00:34:41 +01:00
}
2009-05-07 01:30:49 +02:00
2020-10-29 00:34:41 +01:00
if ( $nbrowsaffected ) { // If something has changed in data
if ( $this -> fk_member > 0 && ! $nosyncmember ) {
2017-10-07 13:09:31 +02:00
dol_syslog ( get_class ( $this ) . " ::update user is linked with a member. We try to update member too. " , LOG_DEBUG );
2017-03-13 15:00:44 +01:00
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php' ;
2008-08-30 01:49:53 +02:00
2017-12-19 16:16:31 +01:00
// This user is linked with a member, so we also update member information
2007-10-21 22:40:24 +02:00
// if this is an update.
2019-12-18 15:20:36 +01:00
$adh = new Adherent ( $this -> db );
$result = $adh -> fetch ( $this -> fk_member );
2008-08-30 01:49:53 +02:00
2020-10-29 00:34:41 +01:00
if ( $result > 0 ) {
2020-12-05 11:30:18 +01:00
$adh -> civility_code = $this -> civility_code ;
2019-12-18 15:20:36 +01:00
$adh -> firstname = $this -> firstname ;
$adh -> lastname = $this -> lastname ;
$adh -> login = $this -> login ;
$adh -> gender = $this -> gender ;
$adh -> birth = $this -> birth ;
2017-03-13 15:00:44 +01:00
2019-12-18 15:20:36 +01:00
$adh -> pass = $this -> pass ;
2017-03-13 15:00:44 +01:00
2019-12-18 15:20:36 +01:00
$adh -> address = $this -> address ;
$adh -> town = $this -> town ;
$adh -> zip = $this -> zip ;
$adh -> state_id = $this -> state_id ;
$adh -> country_id = $this -> country_id ;
2018-08-31 22:34:02 +02:00
2019-12-18 15:20:36 +01:00
$adh -> email = $this -> email ;
2018-10-12 11:29:47 +02:00
2019-12-18 15:20:36 +01:00
$adh -> socialnetworks = $this -> socialnetworks ;
2018-10-12 11:29:47 +02:00
2019-12-18 15:20:36 +01:00
$adh -> phone = $this -> office_phone ;
$adh -> phone_mobile = $this -> user_mobile ;
2008-07-19 18:53:56 +02:00
2022-08-07 10:14:05 +02:00
$adh -> default_lang = $this -> lang ;
2019-12-18 15:20:36 +01:00
$adh -> user_id = $this -> id ;
$adh -> user_login = $this -> login ;
2009-05-07 01:30:49 +02:00
2019-12-18 15:20:36 +01:00
$result = $adh -> update ( $user , 0 , 1 , 0 );
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
2019-12-18 15:20:36 +01:00
$this -> error = $adh -> error ;
$this -> errors = $adh -> errors ;
2016-06-25 18:48:50 +02:00
dol_syslog ( get_class ( $this ) . " ::update error after calling adh->update to sync it with user: " . $this -> error , LOG_ERR );
2007-09-09 22:10:20 +02:00
$error ++ ;
}
2020-10-29 00:34:41 +01:00
} elseif ( $result < 0 ) {
2019-12-18 15:20:36 +01:00
$this -> error = $adh -> error ;
$this -> errors = $adh -> errors ;
2007-09-07 20:25:53 +02:00
$error ++ ;
}
}
2017-12-19 16:16:31 +01:00
2020-10-29 00:34:41 +01:00
if ( $this -> contact_id > 0 && ! $nosynccontact ) {
2017-12-19 16:16:31 +01:00
dol_syslog ( get_class ( $this ) . " ::update user is linked with a contact. We try to update contact too. " , LOG_DEBUG );
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
2020-06-25 12:17:47 +02:00
// This user is linked with a contact, so we also update contact information if this is an update.
2019-12-18 15:20:36 +01:00
$tmpobj = new Contact ( $this -> db );
$result = $tmpobj -> fetch ( $this -> contact_id );
2017-12-19 16:16:31 +01:00
2020-10-29 00:34:41 +01:00
if ( $result >= 0 ) {
2020-12-05 11:30:18 +01:00
$tmpobj -> civility_code = $this -> civility_code ;
2019-12-18 15:20:36 +01:00
$tmpobj -> firstname = $this -> firstname ;
$tmpobj -> lastname = $this -> lastname ;
$tmpobj -> login = $this -> login ;
$tmpobj -> gender = $this -> gender ;
$tmpobj -> birth = $this -> birth ;
2017-12-19 16:16:31 +01:00
//$tmpobj->pass=$this->pass;
2019-12-18 15:20:36 +01:00
$tmpobj -> email = $this -> email ;
2018-10-12 11:29:47 +02:00
2019-12-18 15:20:36 +01:00
$tmpobj -> socialnetworks = $this -> socialnetworks ;
2018-10-12 11:29:47 +02:00
2019-12-18 15:20:36 +01:00
$tmpobj -> phone_pro = $this -> office_phone ;
$tmpobj -> phone_mobile = $this -> user_mobile ;
$tmpobj -> fax = $this -> office_fax ;
2017-12-19 16:16:31 +01:00
2022-08-07 10:14:05 +02:00
$tmpobj -> default_lang = $this -> lang ;
2019-12-18 15:20:36 +01:00
$tmpobj -> address = $this -> address ;
$tmpobj -> town = $this -> town ;
$tmpobj -> zip = $this -> zip ;
$tmpobj -> state_id = $this -> state_id ;
$tmpobj -> country_id = $this -> country_id ;
2017-12-19 16:16:31 +01:00
2019-12-18 15:20:36 +01:00
$tmpobj -> user_id = $this -> id ;
$tmpobj -> user_login = $this -> login ;
2017-12-19 16:16:31 +01:00
2019-12-18 15:20:36 +01:00
$result = $tmpobj -> update ( $tmpobj -> id , $user , 0 , 'update' , 1 );
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
2019-12-18 15:20:36 +01:00
$this -> error = $tmpobj -> error ;
$this -> errors = $tmpobj -> errors ;
2017-12-19 16:16:31 +01:00
dol_syslog ( get_class ( $this ) . " ::update error after calling adh->update to sync it with user: " . $this -> error , LOG_ERR );
$error ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-12-18 15:20:36 +01:00
$this -> error = $tmpobj -> error ;
$this -> errors = $tmpobj -> errors ;
2017-12-19 16:16:31 +01:00
$error ++ ;
}
}
2011-09-03 18:44:34 +02:00
}
2011-09-04 20:41:19 +02:00
2019-12-18 15:20:36 +01:00
$action = 'update' ;
2014-11-15 19:04:21 +01:00
2018-04-10 12:03:01 +02:00
// Actions on extra fields
2020-10-29 00:34:41 +01:00
if ( ! $error ) {
2019-12-18 15:20:36 +01:00
$result = $this -> insertExtraFields ();
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
2017-02-28 11:20:33 +01:00
$error ++ ;
2012-12-02 11:03:23 +01:00
}
}
2012-11-30 15:55:59 +01:00
2020-10-29 00:34:41 +01:00
if ( ! $error && ! $notrigger ) {
2017-10-07 13:09:31 +02:00
// Call trigger
2019-12-18 15:20:36 +01:00
$result = $this -> call_trigger ( 'USER_MODIFY' , $user );
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2017-10-07 13:09:31 +02:00
// End call triggers
2008-07-19 18:53:56 +02:00
}
2007-09-07 20:25:53 +02:00
2020-10-29 00:34:41 +01:00
if ( ! $error ) {
2007-09-07 20:25:53 +02:00
$this -> db -> commit ();
2011-09-03 18:37:12 +02:00
return $nbrowsaffected ;
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
dol_syslog ( get_class ( $this ) . " ::update error= " . $this -> error , LOG_ERR );
2007-09-07 20:25:53 +02:00
$this -> db -> rollback ();
2011-09-03 18:37:12 +02:00
return - 1 ;
2007-09-07 20:25:53 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror ();
2011-09-03 18:37:12 +02:00
$this -> db -> rollback ();
return - 2 ;
2008-07-19 18:53:56 +02:00
}
2008-02-24 18:01:48 +01:00
}
2004-08-07 20:47:54 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2007-09-08 11:44:26 +02:00
/**
2024-01-11 10:01:34 +01:00
* Update the user ' s last login date in the database .
* Function called when a new connection is made by the user
2011-09-04 20:41:19 +02:00
*
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 si echec , >= 0 si ok
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function update_last_login_date ()
2008-07-19 18:53:56 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-11-13 19:35:39 +01:00
$now = dol_now ();
2008-07-19 18:53:56 +02:00
2022-04-28 17:34:04 +02:00
$userremoteip = getUserRemoteIP ();
2022-01-21 16:57:57 +01:00
$sql = " UPDATE " . $this -> db -> prefix () . " user SET " ;
2019-11-13 19:35:39 +01:00
$sql .= " datepreviouslogin = datelastlogin, " ;
2022-04-28 17:34:04 +02:00
$sql .= " ippreviouslogin = iplastlogin, " ;
2019-11-13 19:35:39 +01:00
$sql .= " datelastlogin = ' " . $this -> db -> idate ( $now ) . " ', " ;
2022-04-28 17:34:04 +02:00
$sql .= " iplastlogin = ' " . $this -> db -> escape ( $userremoteip ) . " ', " ;
2024-01-11 10:01:34 +01:00
$sql .= " tms = tms " ; // The last update date must change because the last login date is updated
2021-08-23 19:33:24 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2009-01-30 23:18:07 +01:00
2011-09-24 01:46:14 +02:00
dol_syslog ( get_class ( $this ) . " ::update_last_login_date user->id= " . $this -> id . " " . $sql , LOG_DEBUG );
2008-07-19 18:53:56 +02:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $resql ) {
2019-11-13 19:35:39 +01:00
$this -> datepreviouslogin = $this -> datelastlogin ;
$this -> datelastlogin = $now ;
2022-04-28 17:34:04 +02:00
$this -> ippreviouslogin = $this -> iplastlogin ;
$this -> iplastlogin = $userremoteip ;
2008-07-19 18:53:56 +02:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror () . ' sql=' . $sql ;
2008-07-19 18:53:56 +02:00
return - 1 ;
}
}
2006-11-20 03:10:47 +01:00
2006-04-24 23:28:24 +02:00
/**
2011-01-29 18:41:26 +01:00
* Change password of a user
2011-09-04 20:41:19 +02:00
*
2020-05-06 15:15:12 +02:00
* @ param User $user Object user of user requesting the change ( not the user for who we change the password ) . May be unknown .
2021-04-17 03:11:58 +02:00
* @ param string $password New password , in clear text or already encrypted ( to generate if not provided )
* @ param int $changelater 0 = Default , 1 = Save password into pass_temp to change password only after clicking on confirm email
2011-09-20 19:34:15 +02:00
* @ param int $notrigger 1 = Does not launch triggers
* @ param int $nosyncmember Do not synchronize linked member
2024-01-11 10:07:06 +01:00
* @ param int $passwordalreadycrypted 0 = Value is cleartext password , 1 = Value is encrypted value .
2023-01-12 14:40:00 +01:00
* @ param int $flagdelsessionsbefore 1 = Save also the current date to ask to invalidate all other session before this date .
2024-01-15 22:48:38 +01:00
* @ return int | string If OK return clear password , 0 if no change ( warning , you may retrieve 1 instead of 0 even if password was same ), < 0 if error
2008-07-19 18:53:56 +02:00
*/
2023-01-12 14:40:00 +01:00
public function setPassword ( $user , $password = '' , $changelater = 0 , $notrigger = 0 , $nosyncmember = 0 , $passwordalreadycrypted = 0 , $flagdelsessionsbefore = 1 )
2008-07-19 18:53:56 +02:00
{
global $conf , $langs ;
2019-11-13 19:35:39 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php' ;
2011-09-20 19:19:46 +02:00
2019-11-13 19:35:39 +01:00
$error = 0 ;
2006-11-20 03:10:47 +01:00
2019-01-27 11:55:16 +01:00
dol_syslog ( get_class ( $this ) . " ::setPassword user= " . $user -> id . " password= " . preg_replace ( '/./i' , '*' , $password ) . " changelater= " . $changelater . " notrigger= " . $notrigger . " nosyncmember= " . $nosyncmember , LOG_DEBUG );
2006-11-20 03:10:47 +01:00
2011-09-24 01:46:14 +02:00
// If new password not provided, we generate one
2020-10-29 00:34:41 +01:00
if ( ! $password ) {
2019-11-13 19:35:39 +01:00
$password = getRandomPassword ( false );
2008-07-19 18:53:56 +02:00
}
2022-01-03 12:26:57 +01:00
// Check and encrypt the password
2021-04-17 03:11:58 +02:00
if ( empty ( $passwordalreadycrypted )) {
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'USER_PASSWORD_GENERATED' )) {
2022-01-03 12:26:57 +01:00
// Add a check on rules for password syntax using the setup of the password generator
$modGeneratePassClass = 'modGeneratePass' . ucfirst ( $conf -> global -> USER_PASSWORD_GENERATED );
2022-01-03 16:09:08 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/security/generate/' . $modGeneratePassClass . '.class.php' ;
2022-01-03 12:26:57 +01:00
if ( class_exists ( $modGeneratePassClass )) {
$modGeneratePass = new $modGeneratePassClass ( $this -> db , $conf , $langs , $user );
2022-01-03 16:09:08 +01:00
// To check an input user password, we disable the cleaning on ambiguous characters (this is used only for auto-generated password)
$modGeneratePass -> WithoutAmbi = 0 ;
2022-01-03 12:26:57 +01:00
2022-01-03 16:09:08 +01:00
// Call to validatePassword($password) to check pass match rules
$testpassword = $modGeneratePass -> validatePassword ( $password );
if ( ! $testpassword ) {
$this -> error = $modGeneratePass -> error ;
return - 1 ;
2022-01-03 12:26:57 +01:00
}
2022-01-03 16:09:08 +01:00
}
2022-01-03 12:26:57 +01:00
}
2022-01-21 15:26:54 +01:00
2022-01-03 12:26:57 +01:00
// Now, we encrypt the new password
2021-04-17 03:11:58 +02:00
$password_crypted = dol_hash ( $password );
}
2006-11-25 22:39:58 +01:00
2021-04-17 03:11:58 +02:00
// Update password
2020-10-29 00:34:41 +01:00
if ( ! $changelater ) {
if ( ! is_object ( $this -> oldcopy )) {
$this -> oldcopy = clone $this ;
}
2011-11-02 18:05:45 +01:00
2017-10-07 13:09:31 +02:00
$this -> db -> begin ();
2014-07-05 08:59:41 +02:00
2022-01-21 16:57:57 +01:00
$sql = " UPDATE " . $this -> db -> prefix () . " user " ;
2019-11-13 19:35:39 +01:00
$sql .= " SET pass_crypted = ' " . $this -> db -> escape ( $password_crypted ) . " ', " ;
$sql .= " pass_temp = null " ;
2023-01-14 21:21:48 +01:00
if ( ! empty ( $flagdelsessionsbefore )) {
2023-01-12 14:40:00 +01:00
$sql .= " , flagdelsessionsbefore = ' " . $this -> db -> idate ( dol_now () - 5 , 'gmt' ) . " ' " ;
}
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'DATABASE_PWD_ENCRYPTED' )) {
2019-11-13 19:35:39 +01:00
$sql .= " , pass = null " ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$sql .= " , pass = ' " . $this -> db -> escape ( $password ) . " ' " ;
2007-06-02 03:53:54 +02:00
}
2021-08-23 19:33:24 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2007-06-02 03:53:54 +02:00
2014-07-02 21:29:07 +02:00
dol_syslog ( get_class ( $this ) . " ::setPassword " , LOG_DEBUG );
2008-07-19 18:53:56 +02:00
$result = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $result ) {
if ( $this -> db -> affected_rows ( $result )) {
2019-11-13 19:35:39 +01:00
$this -> pass = $password ;
$this -> pass_indatabase = $password ;
$this -> pass_indatabase_crypted = $password_crypted ;
2007-06-02 03:53:54 +02:00
2020-10-29 00:34:41 +01:00
if ( $this -> fk_member && ! $nosyncmember ) {
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php' ;
2008-07-19 18:53:56 +02:00
2024-01-11 10:01:34 +01:00
// This user is linked with a member, so we also update members information
2007-10-22 01:04:06 +02:00
// if this is an update.
2019-11-13 19:35:39 +01:00
$adh = new Adherent ( $this -> db );
$result = $adh -> fetch ( $this -> fk_member );
2008-07-19 18:53:56 +02:00
2020-10-29 00:34:41 +01:00
if ( $result >= 0 ) {
2024-01-11 10:01:34 +01:00
$result = $adh -> setPassword ( $user , $this -> pass , ( ! getDolGlobalString ( 'DATABASE_PWD_ENCRYPTED' ) ? 0 : 1 ), 1 ); // The encryption is not managed in the 'adherent' module
2023-09-13 06:44:54 +02:00
if ( is_int ( $result ) && $result < 0 ) {
2019-11-13 19:35:39 +01:00
$this -> error = $adh -> error ;
2019-01-27 11:55:16 +01:00
dol_syslog ( get_class ( $this ) . " ::setPassword " . $this -> error , LOG_ERR );
2007-10-22 01:04:06 +02:00
$error ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $adh -> error ;
2007-10-22 01:04:06 +02:00
$error ++ ;
}
}
2011-01-12 03:43:48 +01:00
2019-01-27 11:55:16 +01:00
dol_syslog ( get_class ( $this ) . " ::setPassword notrigger= " . $notrigger . " error= " . $error , LOG_DEBUG );
2007-10-22 01:04:06 +02:00
2020-10-29 00:34:41 +01:00
if ( ! $error && ! $notrigger ) {
2017-10-07 13:09:31 +02:00
// Call trigger
2019-11-13 19:35:39 +01:00
$result = $this -> call_trigger ( 'USER_NEW_PASSWORD' , $user );
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
2023-12-04 13:53:48 +01:00
$error ++ ;
$this -> db -> rollback ();
return - 1 ;
2020-10-29 00:34:41 +01:00
}
2017-10-07 13:09:31 +02:00
// End call triggers
2007-08-31 09:43:23 +02:00
}
2014-07-05 08:59:41 +02:00
2014-07-03 14:01:01 +02:00
$this -> db -> commit ();
2008-07-19 18:53:56 +02:00
return $this -> pass ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
2008-07-19 18:53:56 +02:00
return 0 ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-07-19 18:53:56 +02:00
return - 1 ;
}
2020-05-21 15:05:19 +02:00
} else {
2021-04-17 03:11:58 +02:00
// We store password in password temporary field.
// After receiving confirmation link, we will erase and store it in pass_crypted
2022-01-21 16:57:57 +01:00
$sql = " UPDATE " . $this -> db -> prefix () . " user " ;
2019-11-13 19:35:39 +01:00
$sql .= " SET pass_temp = ' " . $this -> db -> escape ( $password ) . " ' " ;
2021-08-23 19:33:24 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2007-09-01 00:06:14 +02:00
2019-11-13 19:35:39 +01:00
dol_syslog ( get_class ( $this ) . " ::setPassword " , LOG_DEBUG ); // No log
2008-07-19 18:53:56 +02:00
$result = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $result ) {
2008-07-19 18:53:56 +02:00
return $password ;
2020-05-21 15:05:19 +02:00
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-07-19 18:53:56 +02:00
return - 3 ;
}
2007-04-23 00:55:32 +02:00
}
2008-07-19 18:53:56 +02:00
}
2002-12-18 19:02:06 +01:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2007-06-02 03:53:54 +02:00
/**
2023-05-23 01:35:30 +02:00
* Send a new password ( or instructions to reset it ) by email
2011-09-04 20:41:19 +02:00
*
2023-02-19 02:41:53 +01:00
* @ param User $user Object user that send the email ( not the user we send to ) @ todo object $user is not used !
2015-05-12 23:47:28 +02:00
* @ param string $password New password
2019-12-11 19:11:13 +01:00
* @ param int $changelater 0 = Send clear passwod into email , 1 = Change password only after clicking on confirm email . @ todo Add method 2 = Send link to reset password
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 si erreur , > 0 si ok
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function send_password ( $user , $password = '' , $changelater = 0 )
2008-07-19 18:53:56 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2021-04-17 03:32:05 +02:00
global $conf , $langs , $mysoc ;
2011-12-05 19:41:38 +01:00
global $dolibarr_main_url_root ;
2012-01-07 15:01:30 +01:00
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
2005-02-04 12:08:01 +01:00
2019-11-13 19:35:39 +01:00
$msgishtml = 0 ;
2006-11-20 03:10:47 +01:00
2007-06-02 03:53:54 +02:00
// Define $msg
2008-07-19 18:53:56 +02:00
$mesg = '' ;
2008-08-30 01:49:53 +02:00
2019-11-13 19:35:39 +01:00
$outputlangs = new Translate ( " " , $conf );
2019-05-19 02:06:37 +02:00
2008-08-30 01:49:53 +02:00
if ( isset ( $this -> conf -> MAIN_LANG_DEFAULT )
2021-07-05 11:33:32 +02:00
&& $this -> conf -> MAIN_LANG_DEFAULT != 'auto' ) { // If user has defined its own language (rare because in most cases, auto is used)
2023-12-04 13:53:48 +01:00
$outputlangs -> getDefaultLang ( $this -> conf -> MAIN_LANG_DEFAULT );
2008-08-30 01:49:53 +02:00
}
2020-05-06 15:03:57 +02:00
if ( $this -> conf -> MAIN_LANG_DEFAULT ) {
2020-09-07 10:18:17 +02:00
$outputlangs -> setDefaultLang ( $this -> conf -> MAIN_LANG_DEFAULT );
} else { // If user has not defined its own language, we used current language
2019-11-13 19:35:39 +01:00
$outputlangs = $langs ;
2008-08-30 01:49:53 +02:00
}
2009-01-09 22:22:58 +01:00
2020-09-07 10:18:17 +02:00
// Load translation files required by the page
2018-09-18 17:37:08 +02:00
$outputlangs -> loadLangs ( array ( " main " , " errors " , " users " , " other " ));
2013-08-25 06:53:59 +02:00
2023-09-29 16:27:07 +02:00
$appli = getDolGlobalString ( 'MAIN_APPLICATION_TITLE' , constant ( 'DOL_APPLICATION_TITLE' ));
2017-03-13 15:00:44 +01:00
2023-09-29 16:27:07 +02:00
$subject = '[' . $appli . '] ' . $outputlangs -> transnoentitiesnoconv ( " SubjectNewPassword " , $appli );
2013-08-25 06:53:59 +02:00
2012-12-12 14:46:13 +01:00
// Define $urlwithroot
2019-11-13 19:35:39 +01:00
$urlwithouturlroot = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( $dolibarr_main_url_root ));
$urlwithroot = $urlwithouturlroot . DOL_URL_ROOT ; // This is to use external domain name found into config file
2012-09-26 12:06:08 +02:00
2020-10-29 00:34:41 +01:00
if ( ! $changelater ) {
2016-11-08 23:03:58 +01:00
$url = $urlwithroot . '/' ;
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'URL_REDIRECTION_AFTER_CHANGEPASSWORD' )) {
2024-01-05 04:18:53 +01:00
$url = getDolGlobalString ( 'URL_REDIRECTION_AFTER_CHANGEPASSWORD' );
2023-05-23 01:35:30 +02:00
}
dol_syslog ( get_class ( $this ) . " ::send_password changelater is off, url= " . $url );
2019-11-13 19:35:39 +01:00
$mesg .= $outputlangs -> transnoentitiesnoconv ( " RequestToResetPasswordReceived " ) . " . \n " ;
$mesg .= $outputlangs -> transnoentitiesnoconv ( " NewKeyIs " ) . " : \n \n " ;
$mesg .= $outputlangs -> transnoentitiesnoconv ( " Login " ) . " = " . $this -> login . " \n " ;
$mesg .= $outputlangs -> transnoentitiesnoconv ( " Password " ) . " = " . $password . " \n \n " ;
$mesg .= " \n " ;
2017-03-13 15:00:44 +01:00
2019-11-13 19:35:39 +01:00
$mesg .= $outputlangs -> transnoentitiesnoconv ( " ClickHereToGoTo " , $appli ) . ': ' . $url . " \n \n " ;
$mesg .= " -- \n " ;
2020-05-06 15:15:12 +02:00
$mesg .= $user -> getFullName ( $outputlangs ); // Username that send the email (not the user for who we want to reset password)
2020-05-21 15:05:19 +02:00
} else {
2023-05-03 12:01:36 +02:00
//print $password.'-'.$this->id.'-'.$conf->file->instance_unique_id;
2021-04-17 03:11:58 +02:00
$url = $urlwithroot . '/user/passwordforgotten.php?action=validatenewpassword' ;
2023-05-03 12:01:36 +02:00
$url .= '&username=' . urlencode ( $this -> login ) . " &passworduidhash= " . urlencode ( dol_hash ( $password . '-' . $this -> id . '-' . $conf -> file -> instance_unique_id ));
2023-04-18 10:46:24 +02:00
if ( isModEnabled ( 'multicompany' )) {
2023-02-18 16:24:56 +01:00
$url .= '&entity=' . ( ! empty ( $this -> entity ) ? $this -> entity : 1 );
2023-02-18 16:08:19 +01:00
}
2021-04-17 03:11:58 +02:00
2023-05-23 01:35:30 +02:00
dol_syslog ( get_class ( $this ) . " ::send_password changelater is on, url= " . $url );
2021-04-17 03:11:58 +02:00
$msgishtml = 1 ;
$mesg .= $outputlangs -> transnoentitiesnoconv ( " RequestToResetPasswordReceived " ) . " <br> \n " ;
$mesg .= $outputlangs -> transnoentitiesnoconv ( " NewKeyWillBe " ) . " :<br> \n <br> \n " ;
$mesg .= '<strong>' . $outputlangs -> transnoentitiesnoconv ( " Login " ) . " </strong> = " . $this -> login . " <br> \n " ;
$mesg .= '<strong>' . $outputlangs -> transnoentitiesnoconv ( " Password " ) . " </strong> = " . $password . " <br> \n <br> \n " ;
$mesg .= " <br> \n " ;
$mesg .= $outputlangs -> transnoentitiesnoconv ( " YouMustClickToChange " ) . " :<br> \n " ;
$mesg .= '<a href="' . $url . '" rel="noopener">' . $outputlangs -> transnoentitiesnoconv ( " ConfirmPasswordChange " ) . '</a>' . " <br> \n <br> \n " ;
$mesg .= $outputlangs -> transnoentitiesnoconv ( " ForgetIfNothing " ) . " <br> \n <br> \n " ;
2007-06-02 03:53:54 +02:00
}
2016-11-08 23:03:58 +01:00
2020-05-06 15:03:57 +02:00
$trackid = 'use' . $this -> id ;
2023-05-23 01:35:30 +02:00
$sendcontext = 'password' ;
2020-05-06 14:48:02 +02:00
2020-09-07 10:18:17 +02:00
$mailfile = new CMailFile (
$subject ,
2017-10-07 13:09:31 +02:00
$this -> email ,
2018-01-24 15:43:55 +01:00
$conf -> global -> MAIN_MAIL_EMAIL_FROM ,
2017-10-07 13:09:31 +02:00
$mesg ,
array (),
array (),
array (),
'' ,
'' ,
0 ,
2020-09-07 10:18:17 +02:00
$msgishtml ,
'' ,
'' ,
2023-05-23 01:35:30 +02:00
$trackid ,
'' ,
$sendcontext
2023-12-04 13:53:48 +01:00
);
2005-07-02 00:09:12 +02:00
2020-10-29 00:34:41 +01:00
if ( $mailfile -> sendfile ()) {
2008-07-19 18:53:56 +02:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2011-09-24 01:46:14 +02:00
$langs -> trans ( " errors " );
2019-11-13 19:35:39 +01:00
$this -> error = $langs -> trans ( " ErrorFailedToSendPassword " ) . ' ' . $mailfile -> error ;
2008-07-19 18:53:56 +02:00
return - 1 ;
}
}
/**
2011-09-04 20:41:19 +02:00
* Renvoie la derniere erreur fonctionnelle de manipulation de l ' objet
*
* @ return string chaine erreur
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function error ()
2008-07-19 18:53:56 +02:00
{
return $this -> error ;
}
2005-02-26 19:34:14 +01:00
2006-11-20 03:10:47 +01:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2008-07-19 18:53:56 +02:00
/**
2019-11-14 18:40:30 +01:00
* Read clicktodial information for user
2011-09-04 20:41:19 +02:00
*
2023-12-01 19:51:32 +01:00
* @ return int Return integer < 0 if KO , > 0 if OK
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function fetch_clicktodial ()
2008-07-19 18:53:56 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2013-03-31 16:44:24 +02:00
$sql = " SELECT url, login, pass, poste " ;
2022-01-21 16:57:57 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " user_clicktodial as u " ;
2021-08-23 19:33:24 +02:00
$sql .= " WHERE u.fk_user = " . (( int ) $this -> id );
2006-11-20 03:10:47 +01:00
2009-01-09 22:22:58 +01:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $resql ) {
if ( $this -> db -> num_rows ( $resql )) {
2009-01-09 22:22:58 +01:00
$obj = $this -> db -> fetch_object ( $resql );
2005-01-14 15:18:45 +01:00
2013-03-31 16:44:24 +02:00
$this -> clicktodial_url = $obj -> url ;
2009-01-09 22:22:58 +01:00
$this -> clicktodial_login = $obj -> login ;
$this -> clicktodial_password = $obj -> pass ;
$this -> clicktodial_poste = $obj -> poste ;
}
2005-01-14 15:18:45 +01:00
2019-11-13 19:35:39 +01:00
$this -> clicktodial_loaded = 1 ; // Data loaded (found or not)
2009-01-14 15:59:28 +01:00
2009-01-09 22:22:58 +01:00
$this -> db -> free ( $resql );
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> error ();
2009-01-09 22:22:58 +01:00
return - 1 ;
2008-07-19 18:53:56 +02:00
}
2005-01-14 15:18:45 +01:00
}
2005-02-26 19:34:14 +01:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2008-07-19 18:53:56 +02:00
/**
2011-09-20 19:34:15 +02:00
* Update clicktodial info
*
2023-12-01 19:51:32 +01:00
* @ return int Return integer < 0 if KO , > 0 if OK
2020-09-07 10:18:17 +02:00
*/
public function update_clicktodial ()
{
// phpcs:enable
2011-09-24 01:46:14 +02:00
$this -> db -> begin ();
2006-11-20 03:10:47 +01:00
2022-01-21 16:57:57 +01:00
$sql = " DELETE FROM " . $this -> db -> prefix () . " user_clicktodial " ;
2021-08-23 19:33:24 +02:00
$sql .= " WHERE fk_user = " . (( int ) $this -> id );
2002-12-18 19:02:06 +01:00
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::update_clicktodial' , LOG_DEBUG );
2008-07-19 18:53:56 +02:00
$result = $this -> db -> query ( $sql );
2005-01-14 15:18:45 +01:00
2022-01-21 16:57:57 +01:00
$sql = " INSERT INTO " . $this -> db -> prefix () . " user_clicktodial " ;
2013-03-31 16:44:24 +02:00
$sql .= " (fk_user,url,login,pass,poste) " ;
2008-07-19 18:53:56 +02:00
$sql .= " VALUES ( " . $this -> id ;
2019-11-13 19:35:39 +01:00
$sql .= " , ' " . $this -> db -> escape ( $this -> clicktodial_url ) . " ' " ;
$sql .= " , ' " . $this -> db -> escape ( $this -> clicktodial_login ) . " ' " ;
$sql .= " , ' " . $this -> db -> escape ( $this -> clicktodial_password ) . " ' " ;
$sql .= " , ' " . $this -> db -> escape ( $this -> clicktodial_poste ) . " ') " ;
2006-11-20 03:10:47 +01:00
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::update_clicktodial' , LOG_DEBUG );
2008-07-19 18:53:56 +02:00
$result = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $result ) {
2011-09-24 01:46:14 +02:00
$this -> db -> commit ();
2013-03-31 16:44:24 +02:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2011-09-24 01:46:14 +02:00
$this -> db -> rollback ();
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror ();
2011-09-24 01:46:14 +02:00
return - 1 ;
2008-07-19 18:53:56 +02:00
}
2020-09-07 10:18:17 +02:00
}
2005-01-27 16:56:32 +01:00
2005-02-26 19:34:14 +01:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2008-07-19 18:53:56 +02:00
/**
2011-09-20 19:34:15 +02:00
* Add user into a group
2011-09-04 20:41:19 +02:00
*
2021-03-22 13:31:06 +01:00
* @ param int $group Id of group
2011-09-20 19:34:15 +02:00
* @ param int $entity Entity
* @ param int $notrigger Disable triggers
2023-12-01 19:51:32 +01:00
* @ return int Return integer < 0 if KO , > 0 if OK
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function SetInGroup ( $group , $entity , $notrigger = 0 )
2008-07-19 18:53:56 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2011-06-07 17:45:01 +02:00
global $conf , $langs , $user ;
2011-06-29 12:23:32 +02:00
2019-11-13 19:35:39 +01:00
$error = 0 ;
2011-05-28 02:16:12 +02:00
$this -> db -> begin ();
2005-01-27 16:56:32 +01:00
2022-01-21 16:57:57 +01:00
$sql = " DELETE FROM " . $this -> db -> prefix () . " usergroup_user " ;
2021-08-23 19:33:24 +02:00
$sql .= " WHERE fk_user = " . (( int ) $this -> id );
2021-03-22 13:31:06 +01:00
$sql .= " AND fk_usergroup = " . (( int ) $group );
2021-08-23 19:33:24 +02:00
$sql .= " AND entity = " . (( int ) $entity );
2006-11-20 03:10:47 +01:00
2008-07-19 18:53:56 +02:00
$result = $this -> db -> query ( $sql );
2005-01-27 16:56:32 +01:00
2022-01-21 16:57:57 +01:00
$sql = " INSERT INTO " . $this -> db -> prefix () . " usergroup_user (entity, fk_user, fk_usergroup) " ;
2021-08-23 19:33:24 +02:00
$sql .= " VALUES ( " . (( int ) $entity ) . " , " . (( int ) $this -> id ) . " , " . (( int ) $group ) . " ) " ;
2006-11-20 03:10:47 +01:00
2008-07-19 18:53:56 +02:00
$result = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $result ) {
if ( ! $error && ! $notrigger ) {
2024-03-08 21:34:18 +01:00
$this -> context = array ( 'audit' => $langs -> trans ( " UserSetInGroup " ), 'newgroupid' => $group );
2017-03-13 15:00:44 +01:00
2017-10-07 13:09:31 +02:00
// Call trigger
2019-11-13 19:35:39 +01:00
$result = $this -> call_trigger ( 'USER_MODIFY' , $user );
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2017-10-07 13:09:31 +02:00
// End call triggers
2011-06-07 17:45:01 +02:00
}
2011-06-29 12:23:32 +02:00
2020-10-29 00:34:41 +01:00
if ( ! $error ) {
2011-06-07 17:45:01 +02:00
$this -> db -> commit ();
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2011-09-24 01:46:14 +02:00
dol_syslog ( get_class ( $this ) . " ::SetInGroup " . $this -> error , LOG_ERR );
2011-06-07 17:45:01 +02:00
$this -> db -> rollback ();
return - 2 ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror ();
2011-06-07 17:45:01 +02:00
$this -> db -> rollback ();
return - 1 ;
}
2008-07-19 18:53:56 +02:00
}
2005-01-27 16:56:32 +01:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2006-08-07 04:20:57 +02:00
/**
2011-09-20 19:34:15 +02:00
* Remove a user from a group
2011-09-04 20:41:19 +02:00
*
2021-03-22 13:31:06 +01:00
* @ param int $group Id of group
2011-09-24 01:46:14 +02:00
* @ param int $entity Entity
* @ param int $notrigger Disable triggers
2023-12-01 19:51:32 +01:00
* @ return int Return integer < 0 if KO , > 0 if OK
2006-08-07 04:20:57 +02:00
*/
2019-02-25 20:35:59 +01:00
public function RemoveFromGroup ( $group , $entity , $notrigger = 0 )
2008-07-19 18:53:56 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-11-13 19:35:39 +01:00
global $conf , $langs , $user ;
2011-06-29 12:23:32 +02:00
2019-11-13 19:35:39 +01:00
$error = 0 ;
2005-01-27 16:56:32 +01:00
2011-09-24 01:46:14 +02:00
$this -> db -> begin ();
2011-05-28 02:16:12 +02:00
2022-01-21 16:57:57 +01:00
$sql = " DELETE FROM " . $this -> db -> prefix () . " usergroup_user " ;
2021-08-23 19:33:24 +02:00
$sql .= " WHERE fk_user = " . (( int ) $this -> id );
2021-03-22 13:31:06 +01:00
$sql .= " AND fk_usergroup = " . (( int ) $group );
2023-01-14 02:40:44 +01:00
if ( empty ( $entity )) {
$sql .= " AND entity IN (0, 1) " ; // group may be in entity 0 (so $entity=0) and link with user into entity 1.
} else {
$sql .= " AND entity = " . (( int ) $entity );
}
2006-11-20 03:10:47 +01:00
2008-07-19 18:53:56 +02:00
$result = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $result ) {
if ( ! $error && ! $notrigger ) {
2024-03-08 21:34:18 +01:00
$this -> context = array ( 'audit' => $langs -> trans ( " UserRemovedFromGroup " ), 'oldgroupid' => $group );
2017-03-13 15:00:44 +01:00
2017-10-07 13:09:31 +02:00
// Call trigger
2019-11-13 19:35:39 +01:00
$result = $this -> call_trigger ( 'USER_MODIFY' , $user );
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2017-10-07 13:09:31 +02:00
// End call triggers
2011-06-07 17:45:01 +02:00
}
2011-05-28 02:16:12 +02:00
2020-10-29 00:34:41 +01:00
if ( ! $error ) {
2011-06-07 17:45:01 +02:00
$this -> db -> commit ();
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2011-09-24 01:46:14 +02:00
dol_syslog ( get_class ( $this ) . " ::RemoveFromGroup " . $this -> error , LOG_ERR );
2011-06-07 17:45:01 +02:00
$this -> db -> rollback ();
return - 2 ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror ();
2011-06-07 17:45:01 +02:00
$this -> db -> rollback ();
return - 1 ;
}
2008-07-19 18:53:56 +02:00
}
2006-08-07 04:20:57 +02:00
2015-05-30 19:50:07 +02:00
2023-01-27 14:06:31 +01:00
/**
* Return a link with photo
* Use this -> id , this -> photo
*
2023-01-27 14:27:51 +01:00
* @ return int 0 = Valid , > 0 if not valid
2023-01-27 14:06:31 +01:00
*/
2023-01-27 14:27:51 +01:00
public function isNotIntoValidityDateRange ()
2023-01-27 14:06:31 +01:00
{
include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
$now = dol_now ();
2023-01-27 14:27:51 +01:00
//dol_syslog("isNotIntoValidityDateRange ".$this->datestartvalidity);
2023-01-27 14:06:31 +01:00
// Check date start validity
if ( $this -> datestartvalidity && $this -> datestartvalidity > dol_get_last_hour ( $now )) {
2023-01-27 14:27:51 +01:00
return 1 ;
2023-01-27 14:06:31 +01:00
}
// Check date end validity
if ( $this -> dateendvalidity && $this -> dateendvalidity < dol_get_first_hour ( $now )) {
2023-01-27 14:27:51 +01:00
return 1 ;
2023-01-27 14:06:31 +01:00
}
2023-01-27 14:27:51 +01:00
return 0 ;
2023-01-27 14:06:31 +01:00
}
2015-05-30 19:50:07 +02:00
/**
2015-05-31 01:06:51 +02:00
* Return a link with photo
* Use this -> id , this -> photo
2015-05-30 19:50:07 +02:00
*
2015-05-31 01:06:51 +02:00
* @ param int $width Width of image
* @ param int $height Height of image
2015-05-31 17:31:15 +02:00
* @ param string $cssclass Force a css class
2017-10-07 13:09:31 +02:00
* @ param string $imagesize 'mini' , 'small' or '' ( original )
2015-05-31 01:06:51 +02:00
* @ return string String with URL link
2024-01-23 15:56:31 +01:00
* @ see getImagePublicURLOfObject ()
2015-05-30 19:50:07 +02:00
*/
2019-02-25 20:35:59 +01:00
public function getPhotoUrl ( $width , $height , $cssclass = '' , $imagesize = '' )
2015-05-30 19:50:07 +02:00
{
2019-11-13 19:35:39 +01:00
$result = '<a href="' . DOL_URL_ROOT . '/user/card.php?id=' . $this -> id . '">' ;
$result .= Form :: showphoto ( 'userphoto' , $this , $width , $height , 0 , $cssclass , $imagesize );
$result .= '</a>' ;
2015-05-30 19:50:07 +02:00
2017-10-07 13:09:31 +02:00
return $result ;
2015-05-30 19:50:07 +02:00
}
2023-01-30 23:24:23 +01:00
/**
2023-05-05 13:16:29 +02:00
* Return array of data to show into tooltips
2023-01-30 23:24:23 +01:00
*
2024-01-23 15:56:31 +01:00
* @ param array $params Array with options , infologin
2023-01-30 23:24:23 +01:00
* @ since v18
* @ return array
*/
public function getTooltipContentArray ( $params )
{
global $conf , $langs , $menumanager ;
2023-11-17 02:10:45 +01:00
global $dolibarr_main_demo ;
2023-01-30 23:24:23 +01:00
$infologin = $params [ 'infologin' ] ? ? 0 ;
$option = $params [ 'option' ] ? ? '' ;
2024-01-11 10:01:34 +01:00
$data = [];
2023-01-30 23:24:23 +01:00
if ( ! empty ( $this -> photo )) {
$photo = '<div class="photointooltip floatright">' ;
$photo .= Form :: showphoto ( 'userphoto' , $this , 0 , 60 , 0 , 'photoref photowithmargin photologintooltip' , 'small' , 0 , 1 ); // Force height to 60 so we total height of tooltip can be calculated and collision can be managed
$photo .= '</div>' ;
2024-01-11 10:01:34 +01:00
$data [ 'photo' ] = $photo ;
2023-01-30 23:24:23 +01:00
//$label .= '<div style="clear: both;"></div>';
}
// Info Login
2024-01-11 10:01:34 +01:00
$data [ 'opendiv' ] = '<div class="centpercent divtooltip">' ;
$data [ 'picto' ] = img_picto ( '' , $this -> picto ) . ' <u class="paddingrightonly">' . $langs -> trans ( " User " ) . '</u> ' . $this -> getLibStatut ( 4 );
$data [ 'name' ] = '<br><b>' . $langs -> trans ( 'Name' ) . ':</b> ' . dol_string_nohtmltag ( $this -> getFullName ( $langs , '' ));
2023-01-30 23:24:23 +01:00
if ( ! empty ( $this -> login )) {
2024-01-11 10:01:34 +01:00
$data [ 'login' ] = '<br><b>' . $langs -> trans ( 'Login' ) . ':</b> ' . dol_string_nohtmltag ( $this -> login );
2023-01-30 23:24:23 +01:00
}
if ( ! empty ( $this -> job )) {
2024-01-11 10:01:34 +01:00
$data [ 'job' ] = '<br><b>' . $langs -> trans ( " Job " ) . ':</b> ' . dol_string_nohtmltag ( $this -> job );
2023-01-30 23:24:23 +01:00
}
2024-01-11 10:01:34 +01:00
$data [ 'email' ] = '<br><b>' . $langs -> trans ( " Email " ) . ':</b> ' . dol_string_nohtmltag ( $this -> email );
2023-01-30 23:24:23 +01:00
if ( ! empty ( $this -> office_phone ) || ! empty ( $this -> office_fax ) || ! empty ( $this -> fax )) {
$phonelist = array ();
if ( $this -> office_phone ) {
$phonelist [] = dol_print_phone ( $this -> office_phone , $this -> country_code , $this -> id , 0 , '' , ' ' , 'phone' );
}
if ( $this -> office_fax ) {
$phonelist [] = dol_print_phone ( $this -> office_fax , $this -> country_code , $this -> id , 0 , '' , ' ' , 'fax' );
}
if ( $this -> user_mobile ) {
$phonelist [] = dol_print_phone ( $this -> user_mobile , $this -> country_code , $this -> id , 0 , '' , ' ' , 'mobile' );
}
2024-01-11 10:01:34 +01:00
$data [ 'phones' ] = '<br><b>' . $langs -> trans ( 'Phone' ) . ':</b> ' . implode ( ' ' , $phonelist );
2023-01-30 23:24:23 +01:00
}
if ( ! empty ( $this -> admin )) {
2024-01-11 10:01:34 +01:00
$data [ 'administrator' ] = '<br><b>' . $langs -> trans ( " Administrator " ) . '</b>: ' . yn ( $this -> admin );
2023-01-30 23:24:23 +01:00
}
if ( ! empty ( $this -> accountancy_code ) || $option == 'accountancy' ) {
2023-11-06 17:30:21 +01:00
$langs -> load ( " companies " );
2024-01-11 10:01:34 +01:00
$data [ 'accountancycode' ] = '<br><b>' . $langs -> trans ( " AccountancyCode " ) . '</b>: ' . $this -> accountancy_code ;
2023-01-30 23:24:23 +01:00
}
$company = '' ;
if ( ! empty ( $this -> socid )) { // Add thirdparty for external users
$thirdpartystatic = new Societe ( $this -> db );
$thirdpartystatic -> fetch ( $this -> socid );
2023-11-17 02:10:45 +01:00
$companyimg = '' ;
if ( empty ( $params [ 'hidethirdpartylogo' ])) {
$companyimg = ' ' . $thirdpartystatic -> getNomUrl ( 2 , (( $option == 'nolink' ) ? 'nolink' : '' )); // picto only of company
2023-01-30 23:24:23 +01:00
}
2023-11-17 02:10:45 +01:00
$company = ' (' . $langs -> trans ( " Company " ) . ': ' . ( $companyimg ? $companyimg : img_picto ( '' , 'company' )) . ' ' . dol_string_nohtmltag ( $thirdpartystatic -> name ) . ')' ;
2023-01-30 23:24:23 +01:00
}
$type = ( $this -> socid ? $langs -> trans ( " ExternalUser " ) . $company : $langs -> trans ( " InternalUser " ));
2024-01-11 10:01:34 +01:00
$data [ 'type' ] = '<br><b>' . $langs -> trans ( " Type " ) . ':</b> ' . $type ;
$data [ 'closediv' ] = '</div>' ;
2023-04-27 15:55:21 +02:00
2023-01-30 23:24:23 +01:00
if ( $infologin > 0 ) {
2024-01-11 10:01:34 +01:00
$data [ 'newlinelogin' ] = '<br>' ;
$data [ 'session' ] = '<br><u>' . $langs -> trans ( " Session " ) . '</u>' ;
$data [ 'ip' ] = '<br><b>' . $langs -> trans ( " IPAddress " ) . '</b>: ' . dol_string_nohtmltag ( getUserRemoteIP ());
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'MAIN_MODULE_MULTICOMPANY' )) {
2024-01-11 10:01:34 +01:00
$data [ 'multicompany' ] = '<br><b>' . $langs -> trans ( " ConnectedOnMultiCompany " ) . ':</b> ' . $conf -> entity . ' (User entity ' . $this -> entity . ')' ;
2023-01-30 23:24:23 +01:00
}
2024-01-11 10:01:34 +01:00
$data [ 'authentication' ] = '<br><b>' . $langs -> trans ( " AuthenticationMode " ) . ':</b> ' . dol_string_nohtmltag ( $_SESSION [ " dol_authmode " ] . ( empty ( $dolibarr_main_demo ) ? '' : ' (demo)' ));
$data [ 'connectedsince' ] = '<br><b>' . $langs -> trans ( " ConnectedSince " ) . ':</b> ' . dol_print_date ( $this -> datelastlogin , " dayhour " , 'tzuser' );
$data [ 'previousconnexion' ] = '<br><b>' . $langs -> trans ( " PreviousConnexion " ) . ':</b> ' . dol_print_date ( $this -> datepreviouslogin , " dayhour " , 'tzuser' );
$data [ 'currenttheme' ] = '<br><b>' . $langs -> trans ( " CurrentTheme " ) . ':</b> ' . dol_string_nohtmltag ( $conf -> theme );
$data [ 'currentmenumanager' ] = '<br><b>' . $langs -> trans ( " CurrentMenuManager " ) . ':</b> ' . dol_string_nohtmltag ( $menumanager -> name );
2023-01-30 23:24:23 +01:00
$s = picto_from_langcode ( $langs -> getDefaultLang ());
2024-01-11 10:01:34 +01:00
$data [ 'currentuserlang' ] = '<br><b>' . $langs -> trans ( " CurrentUserLanguage " ) . ':</b> ' . dol_string_nohtmltag (( $s ? $s . ' ' : '' ) . $langs -> getDefaultLang ());
$data [ 'browser' ] = '<br><b>' . $langs -> trans ( " Browser " ) . ':</b> ' . dol_string_nohtmltag ( $conf -> browser -> name . ( $conf -> browser -> version ? ' ' . $conf -> browser -> version : '' ) . ' (' . $_SERVER [ 'HTTP_USER_AGENT' ] . ')' );
$data [ 'layout' ] = '<br><b>' . $langs -> trans ( " Layout " ) . ':</b> ' . dol_string_nohtmltag ( $conf -> browser -> layout );
$data [ 'screen' ] = '<br><b>' . $langs -> trans ( " Screen " ) . ':</b> ' . dol_string_nohtmltag ( $_SESSION [ 'dol_screenwidth' ] . ' x ' . $_SESSION [ 'dol_screenheight' ]);
2023-01-30 23:24:23 +01:00
if ( $conf -> browser -> layout == 'phone' ) {
2024-01-11 10:01:34 +01:00
$data [ 'phone' ] = '<br><b>' . $langs -> trans ( " Phone " ) . ':</b> ' . $langs -> trans ( " Yes " );
2023-01-30 23:24:23 +01:00
}
if ( ! empty ( $_SESSION [ " disablemodules " ])) {
Qual: Apply automatic phan fixes (deprecations, unneeded imports) (#28154)
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
* Qual: Apply automatic phan fixes (deprecations, unneeded imports)
# Qual: Apply automatic phan fixes (deprecations, unneeded imports)
This applies automatic fixes by phan for deprecated functions, unneeded imports).
2024-02-13 21:46:12 +01:00
$data [ 'disabledmodules' ] = '<br><b>' . $langs -> trans ( " DisabledModules " ) . ':</b> <br>' . dol_string_nohtmltag ( implode ( ', ' , explode ( ',' , $_SESSION [ " disablemodules " ])));
2023-01-30 23:24:23 +01:00
}
}
2024-01-11 10:01:34 +01:00
return $data ;
2023-01-30 23:24:23 +01:00
}
2006-08-07 04:20:57 +02:00
/**
2024-01-11 10:01:34 +01:00
* Return a HTML link to the user card ( with optionally the picto )
2013-02-23 15:26:39 +01:00
* Use this -> id , this -> lastname , this -> firstname
2011-09-04 20:41:19 +02:00
*
2017-10-03 16:00:52 +02:00
* @ param int $withpictoimg Include picto in link ( 0 = No picto , 1 = Include picto into link , 2 = Only picto , - 1 = Include photo into link , - 2 = Only picto photo , - 3 = Only photo very small )
2021-05-03 12:01:26 +02:00
* @ param string $option On what the link point to ( 'leave' , 'accountancy' , 'nolink' , )
2018-03-29 11:34:01 +02:00
* @ param integer $infologin 0 = Add default info tooltip , 1 = Add complete info tooltip , - 1 = No info tooltip
2017-10-07 13:09:31 +02:00
* @ param integer $notooltip 1 = Disable tooltip on picto and name
* @ param int $maxlen Max length of visible user name
* @ param int $hidethirdpartylogo Hide logo of thirdparty if user is external user
2018-12-23 01:28:36 +01:00
* @ param string $mode '' = Show firstname and lastname , 'firstname' = Show only firstname , 'firstelselast' = Show firstname or lastname if not defined , 'login' = Show login
2017-10-07 13:09:31 +02:00
* @ param string $morecss Add more css on link
* @ param int $save_lastsearch_value - 1 = Auto , 0 = No save of lastsearch_values when clicking , 1 = Save lastsearch_values whenclicking
2017-10-03 16:00:52 +02:00
* @ return string String with URL
2006-08-07 04:20:57 +02:00
*/
2019-02-25 20:35:59 +01:00
public function getNomUrl ( $withpictoimg = 0 , $option = '' , $infologin = 0 , $notooltip = 0 , $maxlen = 24 , $hidethirdpartylogo = 0 , $mode = '' , $morecss = '' , $save_lastsearch_value = - 1 )
2006-08-07 04:20:57 +02:00
{
2018-07-05 11:52:41 +02:00
global $langs , $conf , $db , $hookmanager , $user ;
2017-03-23 10:59:13 +01:00
global $dolibarr_main_authentication , $dolibarr_main_demo ;
2015-01-25 01:20:58 +01:00
2022-09-06 15:37:00 +02:00
if ( ! $user -> hasRight ( 'user' , 'user' , 'read' ) && $user -> id != $this -> id ) {
2020-10-29 00:34:41 +01:00
$option = 'nolink' ;
}
2018-07-05 11:52:41 +02:00
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'MAIN_OPTIMIZEFORTEXTBROWSER' ) && $withpictoimg ) {
2020-10-29 00:34:41 +01:00
$withpictoimg = 0 ;
}
2016-03-17 09:22:12 +01:00
2023-02-06 23:00:42 +01:00
$result = '' ;
$params = [
'id' => $this -> id ,
'objecttype' => $this -> element ,
'infologin' => $infologin ,
'option' => $option ,
2024-02-18 15:25:46 +01:00
'hidethirdpartylogo' => $hidethirdpartylogo ,
2023-02-06 23:00:42 +01:00
];
$classfortooltip = 'classfortooltip' ;
$dataparams = '' ;
if ( getDolGlobalInt ( 'MAIN_ENABLE_AJAX_TOOLTIP' )) {
$classfortooltip = 'classforajaxtooltip' ;
2023-04-03 19:51:40 +02:00
$dataparams = ' data-params="' . dol_escape_htmltag ( json_encode ( $params )) . '"' ;
$label = '' ;
} else {
$label = implode ( $this -> getTooltipContentArray ( $params ));
2021-05-03 12:01:26 +02:00
}
2023-04-03 19:51:40 +02:00
2023-02-06 23:00:42 +01:00
$companylink = '' ;
2020-10-29 00:34:41 +01:00
if ( ! empty ( $this -> socid )) { // Add thirdparty for external users
2023-02-06 23:00:42 +01:00
$thirdpartystatic = new Societe ( $this -> db );
2018-03-29 11:34:01 +02:00
$thirdpartystatic -> fetch ( $this -> socid );
2020-10-29 00:34:41 +01:00
if ( empty ( $hidethirdpartylogo )) {
$companylink = ' ' . $thirdpartystatic -> getNomUrl ( 2 , (( $option == 'nolink' ) ? 'nolink' : '' )); // picto only of company
}
}
2023-02-06 23:00:42 +01:00
2020-10-29 00:34:41 +01:00
if ( $infologin < 0 ) {
$label = '' ;
2019-12-18 15:20:36 +01:00
}
2017-03-23 10:59:13 +01:00
2017-10-06 00:26:24 +02:00
$url = DOL_URL_ROOT . '/user/card.php?id=' . $this -> id ;
2020-10-29 00:34:41 +01:00
if ( $option == 'leave' ) {
$url = DOL_URL_ROOT . '/holiday/list.php?id=' . $this -> id ;
}
2017-03-23 10:59:13 +01:00
2020-10-29 00:34:41 +01:00
if ( $option != 'nolink' ) {
2017-10-03 16:00:52 +02:00
// Add param to save lastsearch_values or not
2019-11-13 19:35:39 +01:00
$add_save_lastsearch_values = ( $save_lastsearch_value == 1 ? 1 : 0 );
2023-09-10 17:41:22 +02:00
if ( $save_lastsearch_value == - 1 && isset ( $_SERVER [ " PHP_SELF " ]) && preg_match ( '/list\.php/' , $_SERVER [ " PHP_SELF " ])) {
2020-10-29 00:34:41 +01:00
$add_save_lastsearch_values = 1 ;
}
if ( $add_save_lastsearch_values ) {
$url .= '&save_lastsearch_values=1' ;
}
2017-10-03 16:00:52 +02:00
}
2017-03-23 10:59:13 +01:00
2019-11-13 19:35:39 +01:00
$linkstart = '<a href="' . $url . '"' ;
$linkclose = " " ;
2020-10-29 00:34:41 +01:00
if ( empty ( $notooltip )) {
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'MAIN_OPTIMIZEFORTEXTBROWSER' )) {
2017-03-23 10:59:13 +01:00
$langs -> load ( " users " );
2019-11-13 19:35:39 +01:00
$label = $langs -> trans ( " ShowUser " );
$linkclose .= ' alt="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
2017-03-23 10:59:13 +01:00
}
2023-04-03 19:51:40 +02:00
$linkclose .= ( $label ? ' title="' . dol_escape_htmltag ( $label , 1 ) . '"' : ' title="tocomplete"' );
2023-02-04 21:22:30 +01:00
$linkclose .= $dataparams . ' class="' . $classfortooltip . ( $morecss ? ' ' . $morecss : '' ) . '"' ;
2023-04-03 19:51:40 +02:00
} else {
$linkclose = ( $morecss ? ' class="' . $morecss . '"' : '' );
2017-03-23 10:59:13 +01:00
}
2016-07-16 18:05:58 +02:00
2019-11-13 19:35:39 +01:00
$linkstart .= $linkclose . '>' ;
$linkend = '</a>' ;
2006-08-07 04:20:57 +02:00
2017-10-07 13:09:31 +02:00
//if ($withpictoimg == -1) $result.='<div class="nowrap">';
2019-11-13 19:35:39 +01:00
$result .= (( $option == 'nolink' ) ? '' : $linkstart );
2020-10-29 00:34:41 +01:00
if ( $withpictoimg ) {
$paddafterimage = '' ;
2022-09-01 15:38:31 +02:00
if ( abs (( int ) $withpictoimg ) == 1 ) {
2020-10-29 00:34:41 +01:00
$paddafterimage = 'style="margin-' . ( $langs -> trans ( " DIRECTION " ) == 'rtl' ? 'left' : 'right' ) . ': 3px;"' ;
}
2017-10-07 13:09:31 +02:00
// Only picto
2020-10-29 00:34:41 +01:00
if ( $withpictoimg > 0 ) {
2023-10-17 12:36:12 +02:00
$picto = '<!-- picto user --><span class="nopadding userimg' . ( $morecss ? ' ' . $morecss : '' ) . '"><div class="valignmiddle userphoto inline-block center marginrightonlyshort"' . ( $paddafterimage ? ' ' . $paddafterimage : '' ) . '>' . img_object ( '' , 'user' , 'class=""' , 0 , 0 , $notooltip ? 0 : 1 ) . '</div></span>' ;
2021-03-01 20:37:16 +01:00
} else {
// Picto must be a photo
2020-10-29 00:34:41 +01:00
$picto = '<!-- picto photo user --><span class="nopadding userimg' . ( $morecss ? ' ' . $morecss : '' ) . '"' . ( $paddafterimage ? ' ' . $paddafterimage : '' ) . '>' . Form :: showphoto ( 'userphoto' , $this , 0 , 0 , 0 , 'userphoto' . ( $withpictoimg == - 3 ? 'small' : '' ), 'mini' , 0 , 1 ) . '</span>' ;
}
2019-11-13 19:35:39 +01:00
$result .= $picto ;
2015-10-24 13:52:35 +02:00
}
2020-10-29 00:34:41 +01:00
if ( $withpictoimg > - 2 && $withpictoimg != 2 ) {
2023-11-27 12:08:48 +01:00
if ( ! getDolGlobalString ( 'MAIN_OPTIMIZEFORTEXTBROWSER' )) {
2023-07-27 17:45:40 +02:00
$result .= '<span class="nopadding usertext' . (( ! isset ( $this -> status ) || $this -> status ) ? '' : ' strikefordisabled' ) . ( $morecss ? ' ' . $morecss : '' ) . '">' ;
2020-10-29 00:34:41 +01:00
}
if ( $mode == 'login' ) {
2021-01-25 22:46:09 +01:00
$result .= dol_string_nohtmltag ( dol_trunc ( $this -> login , $maxlen ));
2020-10-29 00:34:41 +01:00
} else {
2021-01-25 22:46:09 +01:00
$result .= dol_string_nohtmltag ( $this -> getFullName ( $langs , '' , ( $mode == 'firstelselast' ? 3 : ( $mode == 'firstname' ? 2 : - 1 )), $maxlen ));
2020-10-29 00:34:41 +01:00
}
2023-11-27 12:08:48 +01:00
if ( ! getDolGlobalString ( 'MAIN_OPTIMIZEFORTEXTBROWSER' )) {
2020-10-29 00:34:41 +01:00
$result .= '</span>' ;
}
2006-08-07 04:20:57 +02:00
}
2019-11-13 19:35:39 +01:00
$result .= (( $option == 'nolink' ) ? '' : $linkend );
2015-10-24 19:45:41 +02:00
//if ($withpictoimg == -1) $result.='</div>';
2017-06-06 07:57:03 +02:00
2019-11-13 19:35:39 +01:00
$result .= $companylink ;
2017-06-06 07:57:03 +02:00
2018-03-15 20:46:55 +01:00
global $action ;
$hookmanager -> initHooks ( array ( 'userdao' ));
2024-03-08 21:34:18 +01:00
$parameters = array ( 'id' => $this -> id , 'getnomurl' => & $result );
2019-11-13 19:35:39 +01:00
$reshook = $hookmanager -> executeHooks ( 'getNomUrl' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
2020-10-29 00:34:41 +01:00
if ( $reshook > 0 ) {
$result = $hookmanager -> resPrint ;
} else {
$result .= $hookmanager -> resPrint ;
}
2018-03-15 20:46:55 +01:00
2006-08-07 04:20:57 +02:00
return $result ;
2006-09-01 01:44:34 +02:00
}
2006-11-20 03:10:47 +01:00
2006-09-01 01:44:34 +02:00
/**
2024-01-11 10:01:34 +01:00
* Return clickable link of login ( optionally with picto )
2011-09-04 20:41:19 +02:00
*
2021-10-05 13:34:25 +02:00
* @ param int $withpictoimg Include picto into link ( 1 = picto , - 1 = photo )
2021-05-18 18:18:00 +02:00
* @ param string $option On what the link point to ( 'leave' , 'accountancy' , 'nolink' , )
* @ param integer $notooltip 1 = Disable tooltip on picto and name
* @ param string $morecss Add more css on link
* @ return string String with URL
2006-09-01 01:44:34 +02:00
*/
2021-05-18 18:18:00 +02:00
public function getLoginUrl ( $withpictoimg = 0 , $option = '' , $notooltip = 0 , $morecss = '' )
2006-09-01 01:44:34 +02:00
{
2018-07-05 11:52:41 +02:00
global $langs , $user ;
2006-11-20 03:10:47 +01:00
2019-11-13 19:35:39 +01:00
$result = '' ;
2006-11-20 03:10:47 +01:00
2017-11-02 15:03:09 +01:00
$linkstart = '<a href="' . DOL_URL_ROOT . '/user/card.php?id=' . $this -> id . '">' ;
2019-11-13 19:35:39 +01:00
$linkend = '</a>' ;
2006-09-01 01:44:34 +02:00
2019-11-28 16:16:55 +01:00
//Check user's rights to see an other user
2023-10-15 18:41:39 +02:00
if (( ! $user -> hasRight ( 'user' , 'user' , 'lire' ) && $this -> id != $user -> id )) {
2020-10-29 00:34:41 +01:00
$option = 'nolink' ;
}
2018-08-13 17:26:32 +02:00
2020-10-29 00:34:41 +01:00
if ( $option == 'xxx' ) {
2017-11-02 15:03:09 +01:00
$linkstart = '<a href="' . DOL_URL_ROOT . '/user/card.php?id=' . $this -> id . '">' ;
2024-03-13 00:32:56 +01:00
$linkend = '</a>' ; // @phan-suppress-current-line PhanPluginRedundantAssignment
2006-09-01 01:44:34 +02:00
}
2018-08-13 17:26:32 +02:00
2020-10-29 00:34:41 +01:00
if ( $option == 'nolink' ) {
2018-07-05 11:52:41 +02:00
$linkstart = '' ;
2019-11-13 19:35:39 +01:00
$linkend = '' ;
2018-07-05 11:52:41 +02:00
}
2006-09-01 01:44:34 +02:00
2019-11-13 19:35:39 +01:00
$result .= $linkstart ;
2021-05-18 18:18:00 +02:00
if ( $withpictoimg ) {
$paddafterimage = '' ;
if ( abs ( $withpictoimg ) == 1 ) {
$paddafterimage = 'style="margin-' . ( $langs -> trans ( " DIRECTION " ) == 'rtl' ? 'left' : 'right' ) . ': 3px;"' ;
}
// Only picto
if ( $withpictoimg > 0 ) {
$picto = '<!-- picto user --><span class="nopadding userimg' . ( $morecss ? ' ' . $morecss : '' ) . '">' . img_object ( '' , 'user' , $paddafterimage . ' ' . ( $notooltip ? '' : 'class="paddingright classfortooltip"' ), 0 , 0 , $notooltip ? 0 : 1 ) . '</span>' ;
} else {
// Picto must be a photo
$picto = '<!-- picto photo user --><span class="nopadding userimg' . ( $morecss ? ' ' . $morecss : '' ) . '"' . ( $paddafterimage ? ' ' . $paddafterimage : '' ) . '>' . Form :: showphoto ( 'userphoto' , $this , 0 , 0 , 0 , 'userphoto' . ( $withpictoimg == - 3 ? 'small' : '' ), 'mini' , 0 , 1 ) . '</span>' ;
}
$result .= $picto ;
2020-10-29 00:34:41 +01:00
}
2019-11-13 19:35:39 +01:00
$result .= $this -> login ;
$result .= $linkend ;
2021-05-18 18:18:00 +02:00
2006-09-01 01:44:34 +02:00
return $result ;
2006-09-02 03:17:50 +02:00
}
2006-11-20 03:10:47 +01:00
2006-09-02 03:17:50 +02:00
/**
2020-09-15 14:45:51 +02:00
* Return the label of the status of user ( active , inactive )
2011-09-04 20:41:19 +02:00
*
2020-09-15 14:45:51 +02:00
* @ param int $mode 0 = long label , 1 = short label , 2 = Picto + short label , 3 = Picto , 4 = Picto + long label , 5 = Short label + Picto , 6 = Long label + Picto
2011-09-20 19:34:15 +02:00
* @ return string Label of status
2006-09-02 03:17:50 +02:00
*/
2019-02-25 20:35:59 +01:00
public function getLibStatut ( $mode = 0 )
2006-09-02 03:17:50 +02:00
{
2022-06-08 20:07:16 +02:00
return $this -> LibStatut ( isset ( $this -> statut ) ? ( int ) $this -> statut : ( int ) $this -> status , $mode );
2006-09-02 03:17:50 +02:00
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
2020-09-15 14:45:51 +02:00
* Return the label of a status of user ( active , inactive )
2020-09-07 10:18:17 +02:00
*
* @ param int $status Id status
2019-10-31 23:29:17 +01:00
* @ param int $mode 0 = long label , 1 = short label , 2 = Picto + short label , 3 = Picto , 4 = Picto + long label , 5 = Short label + Picto , 6 = Long label + Picto
2020-09-07 10:18:17 +02:00
* @ return string Label of status
*/
public function LibStatut ( $status , $mode = 0 )
{
// phpcs:enable
2006-09-02 03:17:50 +02:00
global $langs ;
2020-10-29 00:34:41 +01:00
if ( empty ( $this -> labelStatus ) || empty ( $this -> labelStatusShort )) {
2019-10-31 23:29:17 +01:00
global $langs ;
//$langs->load("mymodule");
2021-10-16 19:37:57 +02:00
$this -> labelStatus [ self :: STATUS_ENABLED ] = $langs -> transnoentitiesnoconv ( 'Enabled' );
$this -> labelStatus [ self :: STATUS_DISABLED ] = $langs -> transnoentitiesnoconv ( 'Disabled' );
$this -> labelStatusShort [ self :: STATUS_ENABLED ] = $langs -> transnoentitiesnoconv ( 'Enabled' );
$this -> labelStatusShort [ self :: STATUS_DISABLED ] = $langs -> transnoentitiesnoconv ( 'Disabled' );
2006-09-02 03:17:50 +02:00
}
2019-10-31 23:29:17 +01:00
$statusType = 'status5' ;
2020-10-29 00:34:41 +01:00
if ( $status == self :: STATUS_ENABLED ) {
$statusType = 'status4' ;
}
2019-10-31 23:29:17 +01:00
2023-08-12 17:03:16 +02:00
$label = $this -> labelStatus [ $status ];
$labelshort = $this -> labelStatusShort [ $status ];
$now = dol_now ();
if ( ! empty ( $this -> datestartvalidity ) && $now < $this -> datestartvalidity ) {
$statusType = 'status3' ;
$label .= ' (' . $langs -> trans ( " UserNotYetValid " ) . ')' ;
}
if ( ! empty ( $this -> dateendvalidity ) && $now > ( $this -> dateendvalidity + 24 * 3600 - 1 )) {
$statusType = 'status2' ;
$label .= ' (' . $langs -> trans ( " UserExpired " ) . ')' ;
}
return dolGetStatus ( $label , $labelshort , '' , $statusType , $mode );
2006-11-20 03:10:47 +01:00
}
2006-11-19 17:02:53 +01:00
2022-05-18 16:55:03 +02:00
/**
2024-01-11 10:01:34 +01:00
* Return clicable link of object ( optionally with picto )
2022-05-18 16:55:03 +02:00
*
* @ param string $option Where point the link ( 0 => main card , 1 , 2 => shipment , 'nolink' => No link )
2023-01-18 22:27:52 +01:00
* @ param array $arraydata Array of data
2022-05-18 16:55:03 +02:00
* @ return string HTML Code for Kanban thumb .
*/
2023-01-18 22:27:52 +01:00
public function getKanbanView ( $option = '' , $arraydata = null )
2022-05-18 16:55:03 +02:00
{
2023-06-22 20:53:09 +02:00
global $langs ;
2023-03-07 22:04:40 +01:00
$selected = ( empty ( $arraydata [ 'selected' ]) ? 0 : $arraydata [ 'selected' ]);
2022-05-18 16:55:03 +02:00
$return = '<div class="box-flex-item box-flex-grow-zero">' ;
$return .= '<div class="info-box info-box-sm">' ;
$return .= '<span class="info-box-icon bg-infobox-action">' ;
2022-06-14 11:47:56 +02:00
$label = '' ;
if ( ! empty ( $this -> photo )) {
//$label .= '<div class="photointooltip floatright">';
$label .= Form :: showphoto ( 'userphoto' , $this , 0 , 60 , 0 , 'photokanban photoref photowithmargin photologintooltip' , 'small' , 0 , 1 ); // Force height to 60 so we total height of tooltip can be calculated and collision can be managed
//$label .= '</div>';
//$label .= '<div style="clear: both;"></div>';
$return .= $label ;
} else {
$return .= img_picto ( '' , $this -> picto );
}
2022-05-18 16:55:03 +02:00
//$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
$return .= '</span>' ;
$return .= '<div class="info-box-content">' ;
2023-06-22 20:53:09 +02:00
$return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . ( method_exists ( $this , 'getNomUrl' ) ? $this -> getNomUrl ( 0 , '' , 0 , 0 , 24 , 0 , '' , 'valignmiddle' ) : $this -> ref );
if ( isModEnabled ( 'multicompany' ) && $this -> admin && ! $this -> entity ) {
2023-09-12 15:58:42 +02:00
$return .= img_picto ( $langs -> trans ( " SuperAdministratorDesc " ), 'redstar' , 'class="valignmiddle paddingright paddingleft"' );
2023-06-22 20:53:09 +02:00
} elseif ( $this -> admin ) {
2023-09-12 15:58:42 +02:00
$return .= img_picto ( $langs -> trans ( " AdministratorDesc " ), 'star' , 'class="valignmiddle paddingright paddingleft"' );
2023-06-22 20:53:09 +02:00
}
$return .= '</span>' ;
2023-10-17 15:43:56 +02:00
if ( $selected >= 0 ) {
$return .= '<input id="cb' . $this -> id . '" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="' . $this -> id . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
}
2022-05-18 16:55:03 +02:00
if ( property_exists ( $this , 'label' )) {
$return .= '<br><span class="info-box-label opacitymedium">' . $this -> label . '</span>' ;
2022-06-14 11:47:56 +02:00
}
if ( $this -> email ) {
$return .= '<br><span class="info-box-label opacitymedium small">' . img_picto ( '' , 'email' ) . ' ' . $this -> email . '</span>' ;
2022-05-18 16:55:03 +02:00
}
if ( method_exists ( $this , 'getLibStatut' )) {
2023-12-19 11:51:48 +01:00
$return .= '<br><div class="info-box-status">' . $this -> getLibStatut ( 3 ) . '</div>' ;
2022-05-18 16:55:03 +02:00
}
$return .= '</div>' ;
$return .= '</div>' ;
$return .= '</div>' ;
return $return ;
}
2019-05-10 16:12:16 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2019-05-10 16:37:03 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2009-08-11 14:51:33 +02:00
/**
2011-05-01 12:48:43 +02:00
* Retourne chaine DN complete dans l 'annuaire LDAP pour l' objet
2011-09-04 20:41:19 +02:00
*
2014-06-20 13:07:15 +02:00
* @ param array $info Info array loaded by _load_ldap_info
2011-09-20 19:34:15 +02:00
* @ param int $mode 0 = Return full DN ( uid = qqq , ou = xxx , dc = aaa , dc = bbb )
2017-10-04 11:22:41 +02:00
* 1 = Return parent ( ou = xxx , dc = aaa , dc = bbb )
* 2 = Return key only ( RDN ) ( uid = qqq )
2011-09-20 19:34:15 +02:00
* @ return string DN
2008-07-19 18:53:56 +02:00
*/
2019-05-10 11:47:44 +02:00
public function _load_ldap_dn ( $info , $mode = 0 )
2006-11-20 02:13:13 +01:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2006-11-21 23:51:05 +01:00
global $conf ;
2019-11-13 19:35:39 +01:00
$dn = '' ;
2020-10-29 00:34:41 +01:00
if ( $mode == 0 ) {
2023-10-15 18:41:39 +02:00
$dn = getDolGlobalString ( 'LDAP_KEY_USERS' ) . " = " . $info [ getDolGlobalString ( 'LDAP_KEY_USERS' )] . " , " . getDolGlobalString ( 'LDAP_USER_DN' );
2020-10-29 00:34:41 +01:00
} elseif ( $mode == 1 ) {
2024-01-05 04:18:53 +01:00
$dn = getDolGlobalString ( 'LDAP_USER_DN' );
2020-10-29 00:34:41 +01:00
} elseif ( $mode == 2 ) {
2023-10-15 18:41:39 +02:00
$dn = getDolGlobalString ( 'LDAP_KEY_USERS' ) . " = " . $info [ getDolGlobalString ( 'LDAP_KEY_USERS' )];
2020-10-29 00:34:41 +01:00
}
2006-11-21 23:51:05 +01:00
return $dn ;
2006-11-20 02:13:13 +01:00
}
2019-05-10 16:12:16 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2019-05-10 16:37:03 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2009-08-11 22:16:58 +02:00
/**
2011-05-01 12:48:43 +02:00
* Initialize the info array ( array of LDAP values ) that will be used to call LDAP functions
2011-09-04 20:41:19 +02:00
*
2024-01-11 10:01:34 +01:00
* @ return array Table with attribute information
2008-07-19 18:53:56 +02:00
*/
2019-05-10 11:47:44 +02:00
public function _load_ldap_info ()
2006-11-20 02:13:13 +01:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-11-13 19:35:39 +01:00
global $conf , $langs ;
2006-11-20 03:10:47 +01:00
2019-11-13 19:35:39 +01:00
$info = array ();
2020-11-11 07:31:10 +01:00
$socialnetworks = getArrayOfSocialNetworks ();
2019-11-13 19:35:39 +01:00
$keymodified = false ;
2006-11-21 23:51:05 +01:00
2007-04-13 02:35:13 +02:00
// Object classes
2023-12-13 15:20:53 +01:00
$info [ " objectclass " ] = explode ( ',' , getDolGlobalString ( 'LDAP_USER_OBJECT_CLASS' ));
2008-07-19 18:53:56 +02:00
2019-11-13 19:35:39 +01:00
$this -> fullname = $this -> getFullName ( $langs );
2010-07-18 12:39:07 +02:00
2017-09-30 11:51:22 +02:00
// Possible LDAP KEY (constname => varname)
$ldapkey = array (
'LDAP_FIELD_FULLNAME' => 'fullname' ,
'LDAP_FIELD_NAME' => 'lastname' ,
2017-10-02 08:43:53 +02:00
'LDAP_FIELD_FIRSTNAME' => 'firstname' ,
2017-09-30 11:51:22 +02:00
'LDAP_FIELD_LOGIN' => 'login' ,
2024-03-08 21:34:18 +01:00
'LDAP_FIELD_LOGIN_SAMBA' => 'login' ,
2017-10-02 08:43:53 +02:00
'LDAP_FIELD_PHONE' => 'office_phone' ,
'LDAP_FIELD_MOBILE' => 'user_mobile' ,
2018-10-12 11:29:47 +02:00
'LDAP_FIELD_FAX' => 'office_fax' ,
2017-09-30 11:51:22 +02:00
'LDAP_FIELD_MAIL' => 'email' ,
2018-10-12 11:29:47 +02:00
'LDAP_FIELD_SID' => 'ldap_sid' ,
2017-09-30 11:51:22 +02:00
);
2006-11-20 03:10:47 +01:00
// Champs
2020-10-29 00:34:41 +01:00
foreach ( $ldapkey as $constname => $varname ) {
2023-08-05 15:44:28 +02:00
if ( ! empty ( $this -> $varname ) && getDolGlobalString ( $constname )) {
$info [ getDolGlobalString ( $constname )] = $this -> $varname ;
2017-09-30 11:51:22 +02:00
// Check if it is the LDAP key and if its value has been changed
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'LDAP_KEY_USERS' ) && $conf -> global -> LDAP_KEY_USERS == getDolGlobalString ( $constname )) {
2020-10-29 00:34:41 +01:00
if ( ! empty ( $this -> oldcopy ) && $this -> $varname != $this -> oldcopy -> $varname ) {
$keymodified = true ; // For check if LDAP key has been modified
}
2017-09-30 11:51:22 +02:00
}
}
}
2020-11-11 07:31:10 +01:00
foreach ( $socialnetworks as $key => $value ) {
2023-08-05 15:44:28 +02:00
if ( ! empty ( $this -> socialnetworks [ $value [ 'label' ]]) && getDolGlobalString ( 'LDAP_FIELD_' . strtoupper ( $value [ 'label' ]))) {
$info [ getDolGlobalString ( 'LDAP_FIELD_' . strtoupper ( $value [ 'label' ]))] = $this -> socialnetworks [ $value [ 'label' ]];
2020-11-11 07:31:10 +01:00
}
}
2023-11-27 12:08:48 +01:00
if ( $this -> address && getDolGlobalString ( 'LDAP_FIELD_ADDRESS' )) {
2023-10-15 18:41:39 +02:00
$info [ getDolGlobalString ( 'LDAP_FIELD_ADDRESS' )] = $this -> address ;
2020-10-29 00:34:41 +01:00
}
2023-11-27 12:08:48 +01:00
if ( $this -> zip && getDolGlobalString ( 'LDAP_FIELD_ZIP' )) {
2023-10-15 18:41:39 +02:00
$info [ getDolGlobalString ( 'LDAP_FIELD_ZIP' )] = $this -> zip ;
2020-10-29 00:34:41 +01:00
}
2023-11-27 12:08:48 +01:00
if ( $this -> town && getDolGlobalString ( 'LDAP_FIELD_TOWN' )) {
2023-10-15 18:41:39 +02:00
$info [ getDolGlobalString ( 'LDAP_FIELD_TOWN' )] = $this -> town ;
2020-10-29 00:34:41 +01:00
}
2023-11-27 12:08:48 +01:00
if ( $this -> note_public && getDolGlobalString ( 'LDAP_FIELD_DESCRIPTION' )) {
2023-10-15 18:41:39 +02:00
$info [ getDolGlobalString ( 'LDAP_FIELD_DESCRIPTION' )] = dol_string_nohtmltag ( $this -> note_public , 2 );
2020-10-29 00:34:41 +01:00
}
if ( $this -> socid > 0 ) {
2006-11-20 02:13:13 +01:00
$soc = new Societe ( $this -> db );
2017-09-30 11:51:22 +02:00
$soc -> fetch ( $this -> socid );
2006-11-20 03:10:47 +01:00
2023-10-15 18:41:39 +02:00
$info [ getDolGlobalString ( 'LDAP_FIELD_COMPANY' )] = $soc -> name ;
2020-10-29 00:34:41 +01:00
if ( $soc -> client == 1 ) {
$info [ " businessCategory " ] = " Customers " ;
}
if ( $soc -> client == 2 ) {
$info [ " businessCategory " ] = " Prospects " ;
}
if ( $soc -> fournisseur == 1 ) {
$info [ " businessCategory " ] = " Suppliers " ;
}
2006-11-20 02:13:13 +01:00
}
2017-09-30 11:51:22 +02:00
// When password is modified
2020-10-29 00:34:41 +01:00
if ( ! empty ( $this -> pass )) {
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'LDAP_FIELD_PASSWORD' )) {
2024-01-12 17:18:52 +01:00
$info [ getDolGlobalString ( 'LDAP_FIELD_PASSWORD' )] = $this -> pass ; // this->pass = unencrypted password
2020-10-29 00:34:41 +01:00
}
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'LDAP_FIELD_PASSWORD_CRYPTED' )) {
2023-10-15 18:41:39 +02:00
$info [ getDolGlobalString ( 'LDAP_FIELD_PASSWORD_CRYPTED' )] = dol_hash ( $this -> pass , 'openldap' ); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2020-10-29 00:34:41 +01:00
}
2023-12-13 15:20:53 +01:00
} elseif ( getDolGlobalString ( 'LDAP_SERVER_PROTOCOLVERSION' ) !== '3' ) {
2021-03-01 20:37:16 +01:00
// Set LDAP password if possible
// If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'DATABASE_PWD_ENCRYPTED' )) {
2017-09-30 11:51:22 +02:00
// Just for the default MD5 !
2023-11-27 12:08:48 +01:00
if ( ! getDolGlobalString ( 'MAIN_SECURITY_HASH_ALGO' )) {
if ( $this -> pass_indatabase_crypted && getDolGlobalString ( 'LDAP_FIELD_PASSWORD_CRYPTED' )) {
2023-10-15 18:41:39 +02:00
$info [ getDolGlobalString ( 'LDAP_FIELD_PASSWORD_CRYPTED' )] = dolGetLdapPasswordHash ( $this -> pass_indatabase_crypted , 'md5frommd5' ); // Create OpenLDAP MD5 password from Dolibarr MD5 password
2017-09-30 11:51:22 +02:00
}
}
2021-03-01 20:37:16 +01:00
} elseif ( ! empty ( $this -> pass_indatabase )) {
// Use $this->pass_indatabase value if exists
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'LDAP_FIELD_PASSWORD' )) {
2024-01-12 17:18:52 +01:00
$info [ getDolGlobalString ( 'LDAP_FIELD_PASSWORD' )] = $this -> pass_indatabase ; // $this->pass_indatabase = unencrypted password
2020-10-29 00:34:41 +01:00
}
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'LDAP_FIELD_PASSWORD_CRYPTED' )) {
2023-10-15 18:41:39 +02:00
$info [ getDolGlobalString ( 'LDAP_FIELD_PASSWORD_CRYPTED' )] = dol_hash ( $this -> pass_indatabase , 'openldap' ); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2020-10-29 00:34:41 +01:00
}
2017-09-24 19:18:41 +02:00
}
}
2006-11-20 03:10:47 +01:00
2023-07-27 17:45:40 +02:00
if ( getDolGlobalString ( 'LDAP_SERVER_TYPE' ) == 'egroupware' ) {
2006-11-20 02:13:13 +01:00
$info [ " objectclass " ][ 4 ] = " phpgwContact " ; // compatibilite egroupware
2006-11-20 03:10:47 +01:00
2006-11-20 02:13:13 +01:00
$info [ 'uidnumber' ] = $this -> id ;
2006-11-20 03:10:47 +01:00
2019-11-13 19:35:39 +01:00
$info [ 'phpgwTz' ] = 0 ;
2006-11-20 02:13:13 +01:00
$info [ 'phpgwMailType' ] = 'INTERNET' ;
$info [ 'phpgwMailHomeType' ] = 'INTERNET' ;
2006-11-20 03:10:47 +01:00
2006-11-20 02:13:13 +01:00
$info [ " phpgwContactTypeId " ] = 'n' ;
$info [ " phpgwContactCatId " ] = 0 ;
$info [ " phpgwContactAccess " ] = " public " ;
2006-11-20 03:10:47 +01:00
2020-10-29 00:34:41 +01:00
if ( dol_strlen ( $this -> egroupware_id ) == 0 ) {
2006-11-20 02:13:13 +01:00
$this -> egroupware_id = 1 ;
}
2006-11-20 03:10:47 +01:00
2006-11-20 02:13:13 +01:00
$info [ " phpgwContactOwner " ] = $this -> egroupware_id ;
2006-11-20 03:10:47 +01:00
2020-10-29 00:34:41 +01:00
if ( $this -> email ) {
$info [ " rfc822Mailbox " ] = $this -> email ;
}
2023-08-05 14:59:31 +02:00
if ( $this -> user_mobile ) {
$info [ " phpgwCellTelephoneNumber " ] = $this -> user_mobile ;
2020-10-29 00:34:41 +01:00
}
2006-11-20 02:13:13 +01:00
}
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'LDAP_FIELD_USERID' )) {
2023-10-15 18:41:39 +02:00
$info [ getDolGlobalString ( 'LDAP_FIELD_USERID' )] = $this -> id ;
2020-10-29 00:34:41 +01:00
}
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'LDAP_FIELD_GROUPID' )) {
2020-09-07 10:18:17 +02:00
$usergroup = new UserGroup ( $this -> db );
$groupslist = $usergroup -> listGroupsForUser ( $this -> id );
2023-10-15 18:41:39 +02:00
$info [ getDolGlobalString ( 'LDAP_FIELD_GROUPID' )] = '65534' ;
2020-09-07 10:18:17 +02:00
if ( ! empty ( $groupslist )) {
foreach ( $groupslist as $groupforuser ) {
2023-10-15 18:41:39 +02:00
$info [ getDolGlobalString ( 'LDAP_FIELD_GROUPID' )] = $groupforuser -> id ; //Select first group in list
2020-09-07 10:18:17 +02:00
break ;
}
}
}
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'LDAP_FIELD_HOMEDIRECTORY' ) && getDolGlobalString ( 'LDAP_FIELD_HOMEDIRECTORYPREFIX' )) {
2023-10-15 18:41:39 +02:00
$info [ getDolGlobalString ( 'LDAP_FIELD_HOMEDIRECTORY' )] = " { $conf -> global -> LDAP_FIELD_HOMEDIRECTORYPREFIX } / $this->login " ;
2020-10-29 00:34:41 +01:00
}
2019-09-11 23:45:02 +02:00
2020-09-07 10:18:17 +02:00
return $info ;
}
2008-07-19 18:53:56 +02:00
2006-11-20 03:10:47 +01:00
2006-11-19 17:41:17 +01:00
/**
2011-09-24 01:46:14 +02:00
* Initialise an instance with random values .
* Used to build previews or test instances .
* id must be 0 if object instance is a specimen .
*
2020-10-29 00:34:41 +01:00
* @ return int
2006-11-19 17:41:17 +01:00
*/
2019-02-25 20:35:59 +01:00
public function initAsSpecimen ()
2006-11-19 17:41:17 +01:00
{
2019-12-18 15:20:36 +01:00
global $user , $langs ;
2006-11-19 17:41:17 +01:00
2019-12-18 15:20:36 +01:00
$now = dol_now ();
2013-06-16 21:31:21 +02:00
2024-01-11 10:01:34 +01:00
// Initialise parameters
2019-12-18 15:20:36 +01:00
$this -> id = 0 ;
2006-11-19 17:41:17 +01:00
$this -> ref = 'SPECIMEN' ;
2019-12-18 15:20:36 +01:00
$this -> specimen = 1 ;
$this -> lastname = 'DOLIBARR' ;
$this -> firstname = 'SPECIMEN' ;
$this -> gender = 'man' ;
$this -> note_public = 'This is a note public' ;
$this -> note_private = 'This is a note private' ;
$this -> email = 'email@specimen.com' ;
2020-09-07 10:18:17 +02:00
$this -> personal_email = 'personalemail@specimen.com' ;
2019-09-12 18:12:28 +02:00
$this -> socialnetworks = array (
'skype' => 'skypepseudo' ,
'twitter' => 'twitterpseudo' ,
'facebook' => 'facebookpseudo' ,
'linkedin' => 'linkedinpseudo' ,
);
2019-12-18 15:20:36 +01:00
$this -> office_phone = '0999999999' ;
$this -> office_fax = '0999999998' ;
$this -> user_mobile = '0999999997' ;
2020-09-07 10:18:17 +02:00
$this -> personal_mobile = '0999999996' ;
2019-12-18 15:20:36 +01:00
$this -> admin = 0 ;
$this -> login = 'dolibspec' ;
2022-01-24 12:43:42 +01:00
$this -> pass = 'dolibSpec+@123' ;
2013-04-01 14:49:33 +02:00
//$this->pass_indatabase='dolibspec'; Set after a fetch
//$this->pass_indatabase_crypted='e80ca5a88c892b0aaaf7e154853bccab'; Set after a fetch
2019-12-18 15:20:36 +01:00
$this -> datec = $now ;
$this -> datem = $now ;
2006-11-19 17:41:17 +01:00
2019-12-18 15:20:36 +01:00
$this -> datelastlogin = $now ;
2022-04-28 17:34:04 +02:00
$this -> iplastlogin = '127.0.0.1' ;
2019-12-18 15:20:36 +01:00
$this -> datepreviouslogin = $now ;
2022-04-28 17:34:04 +02:00
$this -> ippreviouslogin = '127.0.0.1' ;
2023-01-03 11:32:33 +01:00
$this -> statut = 1 ; // deprecated
$this -> status = 1 ;
2006-11-19 17:41:17 +01:00
2013-04-01 14:49:33 +02:00
$this -> entity = 1 ;
2024-03-02 16:38:35 +01:00
2020-10-29 00:34:41 +01:00
return 1 ;
2006-11-20 03:10:47 +01:00
}
2006-12-03 20:29:41 +01:00
2008-07-19 18:53:56 +02:00
/**
2011-09-20 19:34:15 +02:00
* Load info of user object
2011-09-04 20:41:19 +02:00
*
2011-09-20 19:34:15 +02:00
* @ param int $id Id of user to load
* @ return void
2008-07-19 18:53:56 +02:00
*/
2019-02-25 20:35:59 +01:00
public function info ( $id )
2008-07-19 18:53:56 +02:00
{
2010-01-13 19:51:19 +01:00
$sql = " SELECT u.rowid, u.login as ref, u.datec, " ;
2019-11-13 19:35:39 +01:00
$sql .= " u.tms as date_modification, u.entity " ;
2022-01-21 16:57:57 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " user as u " ;
2021-03-14 11:48:39 +01:00
$sql .= " WHERE u.rowid = " . (( int ) $id );
2008-07-19 18:53:56 +02:00
2019-11-13 19:35:39 +01:00
$result = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $result ) {
if ( $this -> db -> num_rows ( $result )) {
2008-07-19 18:53:56 +02:00
$obj = $this -> db -> fetch_object ( $result );
$this -> id = $obj -> rowid ;
2019-11-13 19:35:39 +01:00
$this -> ref = ( ! $obj -> ref ) ? $obj -> rowid : $obj -> ref ;
2019-02-25 20:35:59 +01:00
$this -> date_creation = $this -> db -> jdate ( $obj -> datec );
2010-01-13 19:51:19 +01:00
$this -> date_modification = $this -> db -> jdate ( $obj -> date_modification );
2019-02-25 20:35:59 +01:00
$this -> entity = $obj -> entity ;
2008-07-19 18:53:56 +02:00
}
$this -> db -> free ( $result );
2020-05-21 15:05:19 +02:00
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-07-19 18:53:56 +02:00
}
}
2007-09-01 00:06:14 +02:00
2010-02-21 22:21:12 +01:00
/**
2011-05-01 12:48:43 +02:00
* Return number of mass Emailing received by this contacts with its email
2011-09-04 20:41:19 +02:00
*
2011-05-01 12:48:43 +02:00
* @ return int Number of EMailings
2010-02-21 22:21:12 +01:00
*/
2019-02-25 20:35:59 +01:00
public function getNbOfEMailings ()
2010-02-21 22:21:12 +01:00
{
$sql = " SELECT count(mc.email) as nb " ;
2022-01-21 16:57:57 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " mailing_cibles as mc " ;
2019-11-13 19:35:39 +01:00
$sql .= " WHERE mc.email = ' " . $this -> db -> escape ( $this -> email ) . " ' " ;
2024-01-11 10:01:34 +01:00
$sql .= " AND mc.statut NOT IN (-1,0) " ; // -1 error, 0 not sent, 1 sent with success
2018-06-06 18:18:50 +02:00
2019-11-13 19:35:39 +01:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $resql ) {
2010-02-21 22:21:12 +01:00
$obj = $this -> db -> fetch_object ( $resql );
2019-11-13 19:35:39 +01:00
$nb = $obj -> nb ;
2010-02-21 22:21:12 +01:00
$this -> db -> free ( $resql );
return $nb ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> error ();
2010-02-21 22:21:12 +01:00
return - 1 ;
}
}
2010-06-17 18:53:26 +02:00
2010-06-07 07:11:45 +02:00
/**
2011-09-20 19:34:15 +02:00
* Return number of existing users
2011-09-04 20:41:19 +02:00
*
2015-10-05 10:04:34 +02:00
* @ param string $limitTo Limit to '' or 'active'
* @ param string $option 'superadmin' = return for entity 0 only
* @ param int $admin Filter on admin tag
2011-09-20 19:34:15 +02:00
* @ return int Number of users
2010-06-07 07:11:45 +02:00
*/
2019-02-25 20:35:59 +01:00
public function getNbOfUsers ( $limitTo , $option = '' , $admin = - 1 )
2010-06-07 07:11:45 +02:00
{
global $conf ;
2010-06-17 18:53:26 +02:00
2010-06-07 07:11:45 +02:00
$sql = " SELECT count(rowid) as nb " ;
2022-01-21 16:57:57 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " user " ;
2020-10-29 00:34:41 +01:00
if ( $option == 'superadmin' ) {
2019-11-13 19:35:39 +01:00
$sql .= " WHERE entity = 0 " ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$sql .= " WHERE entity IN ( " . getEntity ( 'user' , 0 ) . " ) " ;
2020-11-10 21:46:51 +01:00
if ( $limitTo == 'active' ) {
$sql .= " AND statut = 1 " ;
}
2020-11-10 21:43:45 +01:00
}
if ( $admin >= 0 ) {
$sql .= " AND admin = " . ( int ) $admin ;
2011-05-16 21:56:43 +02:00
}
2010-06-17 18:53:26 +02:00
2019-11-13 19:35:39 +01:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $resql ) {
2010-06-07 07:11:45 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2020-11-10 21:43:45 +01:00
$nb = ( int ) $obj -> nb ;
2010-06-07 07:11:45 +02:00
$this -> db -> free ( $resql );
return $nb ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror ();
2010-06-07 07:11:45 +02:00
return - 1 ;
}
}
2010-02-21 22:21:12 +01:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2013-01-30 16:50:28 +01:00
/**
2013-04-04 13:58:33 +02:00
* Update user using data from the LDAP
*
2019-04-04 18:33:12 +02:00
* @ param Object $ldapuser Ladp User
2023-12-01 19:51:32 +01:00
* @ return int Return integer < 0 if KO , > 0 if OK
2013-01-30 16:50:28 +01:00
*/
2019-02-25 20:35:59 +01:00
public function update_ldap2dolibarr ( & $ldapuser )
2013-02-11 20:45:36 +01:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2013-04-04 13:58:33 +02:00
// TODO: Voir pourquoi le update met à jour avec toutes les valeurs vide (global $user écrase ?)
2013-01-30 16:50:28 +01:00
global $user , $conf ;
2020-11-11 07:31:10 +01:00
$socialnetworks = getArrayOfSocialNetworks ();
2022-12-30 18:43:43 +01:00
$tmpvar = getDolGlobalString ( 'LDAP_FIELD_FIRSTNAME' );
$this -> firstname = $ldapuser -> $tmpvar ;
$tmpvar = getDolGlobalString ( 'LDAP_FIELD_NAME' );
$this -> lastname = $ldapuser -> $tmpvar ;
$tmpvar = getDolGlobalString ( 'LDAP_FIELD_LOGIN' );
$this -> login = $ldapuser -> $tmpvar ;
$tmpvar = getDolGlobalString ( 'LDAP_FIELD_PASSWORD' );
$this -> pass = $ldapuser -> $tmpvar ;
$tmpvar = getDolGlobalString ( 'LDAP_FIELD_PASSWORD_CRYPTED' );
$this -> pass_indatabase_crypted = $ldapuser -> $tmpvar ;
$tmpvar = getDolGlobalString ( 'LDAP_FIELD_PHONE' );
$this -> office_phone = $ldapuser -> $tmpvar ;
$tmpvar = getDolGlobalString ( 'LDAP_FIELD_MOBILE' );
$this -> user_mobile = $ldapuser -> $tmpvar ;
$tmpvar = getDolGlobalString ( 'LDAP_FIELD_FAX' );
$this -> office_fax = $ldapuser -> $tmpvar ;
$tmpvar = getDolGlobalString ( 'LDAP_FIELD_MAIL' );
$this -> email = $ldapuser -> $tmpvar ;
2020-11-11 07:31:10 +01:00
foreach ( $socialnetworks as $key => $value ) {
2022-12-30 18:43:43 +01:00
$tmpvar = getDolGlobalString ( 'LDAP_FIELD_' . strtoupper ( $value [ 'label' ]));
$this -> socialnetworks [ $value [ 'label' ]] = $ldapuser -> $tmpvar ;
2020-11-11 07:31:10 +01:00
}
2022-12-30 18:43:43 +01:00
$tmpvar = getDolGlobalString ( 'LDAP_FIELD_SID' );
$this -> ldap_sid = $ldapuser -> $tmpvar ;
2019-11-13 19:35:39 +01:00
2022-12-30 18:43:43 +01:00
$tmpvar = getDolGlobalString ( 'LDAP_FIELD_TITLE' );
$this -> job = $ldapuser -> $tmpvar ;
$tmpvar = getDolGlobalString ( 'LDAP_FIELD_DESCRIPTION' );
$this -> note_public = $ldapuser -> $tmpvar ;
2013-02-11 20:45:36 +01:00
2013-01-30 16:50:28 +01:00
$result = $this -> update ( $user );
2013-02-11 20:45:36 +01:00
2013-01-30 16:50:28 +01:00
dol_syslog ( get_class ( $this ) . " ::update_ldap2dolibarr result= " . $result , LOG_DEBUG );
2013-02-11 20:45:36 +01:00
2013-01-30 16:50:28 +01:00
return $result ;
}
2013-02-11 20:45:36 +01:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2013-03-30 14:27:13 +01:00
/**
2024-01-11 10:01:34 +01:00
* Return and array with all instantiated first level children users of current user
2013-03-30 14:27:13 +01:00
*
2024-03-15 23:14:21 +01:00
* @ return User [] | int <- 1 , - 1 >
2019-04-04 18:33:12 +02:00
* @ see getAllChildIds ()
2013-03-30 14:27:13 +01:00
*/
2019-02-25 20:35:59 +01:00
public function get_children ()
2013-03-30 14:27:13 +01:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2022-01-21 16:57:57 +01:00
$sql = " SELECT rowid FROM " . $this -> db -> prefix () . " user " ;
2021-08-23 19:33:24 +02:00
$sql .= " WHERE fk_user = " . (( int ) $this -> id );
2013-03-30 14:27:13 +01:00
2021-08-27 22:42:04 +02:00
dol_syslog ( get_class ( $this ) . " ::get_children " , LOG_DEBUG );
2019-11-13 19:35:39 +01:00
$res = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $res ) {
2019-11-13 19:35:39 +01:00
$users = array ();
2020-10-29 00:34:41 +01:00
while ( $rec = $this -> db -> fetch_array ( $res )) {
2013-03-30 14:27:13 +01:00
$user = new User ( $this -> db );
$user -> fetch ( $rec [ 'rowid' ]);
$users [] = $user ;
}
return $users ;
2020-05-21 15:05:19 +02:00
} else {
2013-03-30 14:27:13 +01:00
dol_print_error ( $this -> db );
return - 1 ;
}
}
/**
2019-02-25 20:35:59 +01:00
* Load this -> parentof that is array ( id_son => id_parent , ... )
2013-03-30 14:27:13 +01:00
*
2024-03-15 23:14:21 +01:00
* @ return int <- 1 , 1 > Return integer < 0 if KO , > 0 if OK
2013-03-30 14:27:13 +01:00
*/
2018-09-02 09:57:19 +02:00
private function loadParentOf ()
2013-03-30 14:27:13 +01:00
{
global $conf ;
2019-11-13 19:35:39 +01:00
$this -> parentof = array ();
2013-03-30 14:27:13 +01:00
// Load array[child]=parent
$sql = " SELECT fk_user as id_parent, rowid as id_son " ;
2022-01-21 16:57:57 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " user " ;
2019-11-13 19:35:39 +01:00
$sql .= " WHERE fk_user <> 0 " ;
$sql .= " AND entity IN ( " . getEntity ( 'user' ) . " ) " ;
2013-03-30 14:27:13 +01:00
2018-09-02 09:57:19 +02:00
dol_syslog ( get_class ( $this ) . " ::loadParentOf " , LOG_DEBUG );
2013-03-30 14:27:13 +01:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $resql ) {
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2019-11-13 19:35:39 +01:00
$this -> parentof [ $obj -> id_son ] = $obj -> id_parent ;
2013-03-30 14:27:13 +01:00
}
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2013-03-30 14:27:13 +01:00
dol_print_error ( $this -> db );
return - 1 ;
}
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2013-03-30 14:27:13 +01:00
/**
2019-11-02 15:20:35 +01:00
* Build the hierarchy / tree of users into an array .
2014-10-30 11:16:45 +01:00
* Set and return this -> users that is an array sorted according to tree with arrays of :
* id = id user
* lastname
* firstname
2024-01-11 10:01:34 +01:00
* fullname = Name with full path to user
* fullpath = Full path composed of the ids : " _grandparentid_parentid_id "
2013-03-30 14:27:13 +01:00
*
2014-08-11 10:50:08 +02:00
* @ param int $deleteafterid Removed all users including the leaf $deleteafterid ( and all its child ) in user tree .
2024-01-11 10:01:34 +01:00
* @ param string $filter SQL filter on users . This parameter must not come from user input .
2024-03-23 21:46:12 +01:00
* @ return int <- 1 , - 1 >| array < int , array { rowid : int , id : int , fk_user : int , fk_soc : int , firstname : string , lastname : string , login : string , statut : int , entity : string , email : string , gender : int , admin : string , photo : string , fullpath : string , fullname : string , level : int } > Array of user information ( also : $this -> users ) . Note : $this -> parentof is also set .
2013-03-30 14:27:13 +01:00
*/
2020-09-07 10:18:17 +02:00
public function get_full_tree ( $deleteafterid = 0 , $filter = '' )
{
// phpcs:enable
2018-03-23 10:42:36 +01:00
global $conf , $user ;
global $hookmanager ;
// Actions hooked (by external module)
$hookmanager -> initHooks ( array ( 'userdao' ));
2014-05-30 12:55:00 +02:00
2013-03-30 14:27:13 +01:00
$this -> users = array ();
// Init this->parentof that is array(id_son=>id_parent, ...)
2018-09-02 09:57:19 +02:00
$this -> loadParentOf ();
2014-09-13 17:41:26 +02:00
2013-03-30 14:27:13 +01:00
// Init $this->users array
2019-11-13 19:35:39 +01:00
$sql = " SELECT DISTINCT u.rowid, u.firstname, u.lastname, u.fk_user, u.fk_soc, u.login, u.email, u.gender, u.admin, u.statut, u.photo, u.entity " ; // Distinct reduce pb with old tables with duplicates
2022-01-21 16:57:57 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " user as u " ;
2018-03-23 10:42:36 +01:00
// Add fields from hooks
2019-11-13 19:35:39 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printUserListWhere' , $parameters ); // Note that $action and $object may have been modified by hook
2018-03-23 10:52:10 +01:00
if ( $reshook > 0 ) {
2019-11-13 19:35:39 +01:00
$sql .= $hookmanager -> resPrint ;
2018-03-06 19:22:59 +01:00
} else {
2019-11-13 19:35:39 +01:00
$sql .= " WHERE u.entity IN ( " . getEntity ( 'user' ) . " ) " ;
2014-05-30 12:43:07 +02:00
}
2020-10-29 00:34:41 +01:00
if ( $filter ) {
$sql .= " AND " . $filter ;
}
2015-06-20 20:35:57 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::get_full_tree get user list " , LOG_DEBUG );
2013-03-30 14:27:13 +01:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $resql ) {
2019-11-13 19:35:39 +01:00
$i = 0 ;
2020-10-29 00:34:41 +01:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2013-03-30 14:27:13 +01:00
$this -> users [ $obj -> rowid ][ 'rowid' ] = $obj -> rowid ;
$this -> users [ $obj -> rowid ][ 'id' ] = $obj -> rowid ;
$this -> users [ $obj -> rowid ][ 'fk_user' ] = $obj -> fk_user ;
2015-06-16 15:08:20 +02:00
$this -> users [ $obj -> rowid ][ 'fk_soc' ] = $obj -> fk_soc ;
2013-03-30 14:27:13 +01:00
$this -> users [ $obj -> rowid ][ 'firstname' ] = $obj -> firstname ;
$this -> users [ $obj -> rowid ][ 'lastname' ] = $obj -> lastname ;
2013-02-20 21:16:31 +01:00
$this -> users [ $obj -> rowid ][ 'login' ] = $obj -> login ;
$this -> users [ $obj -> rowid ][ 'statut' ] = $obj -> statut ;
2014-05-30 12:55:00 +02:00
$this -> users [ $obj -> rowid ][ 'entity' ] = $obj -> entity ;
2015-06-16 15:08:20 +02:00
$this -> users [ $obj -> rowid ][ 'email' ] = $obj -> email ;
$this -> users [ $obj -> rowid ][ 'gender' ] = $obj -> gender ;
2015-10-05 23:53:49 +02:00
$this -> users [ $obj -> rowid ][ 'admin' ] = $obj -> admin ;
2015-10-25 19:31:13 +01:00
$this -> users [ $obj -> rowid ][ 'photo' ] = $obj -> photo ;
2013-03-30 14:27:13 +01:00
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2013-03-30 14:27:13 +01:00
dol_print_error ( $this -> db );
return - 1 ;
}
2024-03-15 23:14:21 +01:00
// We add the fullpath property to each element of the first level (no parent exists)
2013-03-30 14:27:13 +01:00
dol_syslog ( get_class ( $this ) . " ::get_full_tree call to build_path_from_id_user " , LOG_DEBUG );
2020-10-29 00:34:41 +01:00
foreach ( $this -> users as $key => $val ) {
2019-11-13 19:35:39 +01:00
$result = $this -> build_path_from_id_user ( $key , 0 ); // Process a branch from the root user key (this user has no parent)
2020-10-29 00:34:41 +01:00
if ( $result < 0 ) {
2019-11-13 19:35:39 +01:00
$this -> error = 'ErrorLoopInHierarchy' ;
2017-10-07 13:09:31 +02:00
return - 1 ;
2017-02-21 23:52:13 +01:00
}
2013-03-30 14:27:13 +01:00
}
2014-08-11 10:50:08 +02:00
// Exclude leaf including $deleteafterid from tree
2020-10-29 00:34:41 +01:00
if ( $deleteafterid ) {
2014-08-11 10:50:08 +02:00
//print "Look to discard user ".$deleteafterid."\n";
2019-11-13 19:35:39 +01:00
$keyfilter1 = '^' . $deleteafterid . '$' ;
$keyfilter2 = '_' . $deleteafterid . '$' ;
$keyfilter3 = '^' . $deleteafterid . '_' ;
$keyfilter4 = '_' . $deleteafterid . '_' ;
2024-03-15 23:14:21 +01:00
foreach ( array_keys ( $this -> users ) as $key ) {
2024-03-19 22:37:24 +01:00
$fullpath = ( string ) $this -> users [ $key ][ 'fullpath' ];
2024-03-15 23:14:21 +01:00
if ( preg_match ( '/' . $keyfilter1 . '/' , $fullpath ) || preg_match ( '/' . $keyfilter2 . '/' , $fullpath )
|| preg_match ( '/' . $keyfilter3 . '/' , $fullpath ) || preg_match ( '/' . $keyfilter4 . '/' , $fullpath )) {
2023-12-04 13:53:48 +01:00
unset ( $this -> users [ $key ]);
2021-07-06 19:02:03 +02:00
}
2013-03-30 14:27:13 +01:00
}
}
dol_syslog ( get_class ( $this ) . " ::get_full_tree dol_sort_array " , LOG_DEBUG );
2019-11-13 19:35:39 +01:00
$this -> users = dol_sort_array ( $this -> users , 'fullname' , 'asc' , true , false );
2013-03-30 14:27:13 +01:00
2014-07-05 08:59:41 +02:00
//var_dump($this->users);
2013-03-30 14:27:13 +01:00
return $this -> users ;
}
2014-10-30 11:15:13 +01:00
/**
2024-01-11 10:01:34 +01:00
* Return list of all child user ids in hierarchy ( all sublevels ) .
2017-01-26 23:40:16 +01:00
* Note : Calling this function also reset full list of users into $this -> users .
2014-10-30 11:15:13 +01:00
*
2017-01-26 23:36:58 +01:00
* @ param int $addcurrentuser 1 = Add also current user id to the list .
2017-01-26 23:40:16 +01:00
* @ return array Array of user id lower than user ( all levels under user ) . This overwrite this -> users .
2019-04-08 16:04:15 +02:00
* @ see get_children ()
2014-10-30 11:15:13 +01:00
*/
2020-09-07 10:18:17 +02:00
public function getAllChildIds ( $addcurrentuser = 0 )
{
2019-11-13 19:35:39 +01:00
$childids = array ();
2017-10-07 13:09:31 +02:00
2020-10-29 00:34:41 +01:00
if ( isset ( $this -> cache_childids [ $this -> id ])) {
2017-10-07 13:09:31 +02:00
$childids = $this -> cache_childids [ $this -> id ];
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
// Init this->users
$this -> get_full_tree ();
2019-11-13 19:35:39 +01:00
$idtoscan = $this -> id ;
2017-10-07 13:09:31 +02:00
dol_syslog ( " Build childid for id = " . $idtoscan );
2020-10-29 00:34:41 +01:00
foreach ( $this -> users as $id => $val ) {
2017-10-07 13:09:31 +02:00
//var_dump($val['fullpath']);
2020-10-29 00:34:41 +01:00
if ( preg_match ( '/_' . $idtoscan . '_/' , $val [ 'fullpath' ])) {
$childids [ $val [ 'id' ]] = $val [ 'id' ];
}
2017-10-07 13:09:31 +02:00
}
}
2017-01-26 18:08:00 +01:00
$this -> cache_childids [ $this -> id ] = $childids ;
2017-03-13 15:00:44 +01:00
2020-10-29 00:34:41 +01:00
if ( $addcurrentuser ) {
$childids [ $this -> id ] = $this -> id ;
}
2017-03-13 15:00:44 +01:00
2014-10-30 11:15:13 +01:00
return $childids ;
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2013-03-30 14:27:13 +01:00
/**
2024-01-11 10:01:34 +01:00
* For user id_user and its children available in this -> users , define property fullpath and fullname .
2016-03-14 21:22:49 +01:00
* Function called by get_full_tree () .
2013-03-30 14:27:13 +01:00
*
* @ param int $id_user id_user entry to update
2017-02-21 23:52:13 +01:00
* @ param int $protection Deep counter to avoid infinite loop ( no more required , a protection is added with array useridfound )
2024-03-15 23:14:21 +01:00
* @ return int <- 1 , 1 > Return integer < 0 if KO ( infinite loop ), >= 0 if OK
2013-03-30 14:27:13 +01:00
*/
2020-09-07 10:18:17 +02:00
public function build_path_from_id_user ( $id_user , $protection = 0 )
{
// phpcs:enable
2020-08-17 17:40:08 +02:00
//dol_syslog(get_class($this)."::build_path_from_id_user id_user=".$id_user." protection=".$protection, LOG_DEBUG);
2013-03-30 14:27:13 +01:00
2020-10-29 00:34:41 +01:00
if ( ! empty ( $this -> users [ $id_user ][ 'fullpath' ])) {
2013-03-30 14:27:13 +01:00
// Already defined
dol_syslog ( get_class ( $this ) . " ::build_path_from_id_user fullpath and fullname already defined " , LOG_WARNING );
2017-02-21 23:52:13 +01:00
return 0 ;
2013-03-30 14:27:13 +01:00
}
// Define fullpath and fullname
$this -> users [ $id_user ][ 'fullpath' ] = '_' . $id_user ;
2014-08-07 20:11:39 +02:00
$this -> users [ $id_user ][ 'fullname' ] = $this -> users [ $id_user ][ 'lastname' ];
2023-12-04 13:53:48 +01:00
$i = 0 ;
$cursor_user = $id_user ;
2013-03-30 14:27:13 +01:00
2019-11-13 19:35:39 +01:00
$useridfound = array ( $id_user );
2021-07-05 13:44:05 +02:00
while ( ! empty ( $this -> parentof [ $cursor_user ]) && ! empty ( $this -> users [ $this -> parentof [ $cursor_user ]])) {
2020-10-29 00:34:41 +01:00
if ( in_array ( $this -> parentof [ $cursor_user ], $useridfound )) {
2017-02-21 23:52:13 +01:00
dol_syslog ( " The hierarchy of user has a recursive loop " , LOG_WARNING );
2019-11-13 19:35:39 +01:00
return - 1 ; // Should not happen. Protection against looping hierarchy
2017-02-21 23:52:13 +01:00
}
2019-11-13 19:35:39 +01:00
$useridfound [] = $this -> parentof [ $cursor_user ];
2017-10-07 13:09:31 +02:00
$this -> users [ $id_user ][ 'fullpath' ] = '_' . $this -> parentof [ $cursor_user ] . $this -> users [ $id_user ][ 'fullpath' ];
2014-08-07 20:11:39 +02:00
$this -> users [ $id_user ][ 'fullname' ] = $this -> users [ $this -> parentof [ $cursor_user ]][ 'lastname' ] . ' >> ' . $this -> users [ $id_user ][ 'fullname' ];
2023-12-04 13:53:48 +01:00
$i ++ ;
$cursor_user = $this -> parentof [ $cursor_user ];
2013-03-30 14:27:13 +01:00
}
// We count number of _ to have level
2019-11-13 19:35:39 +01:00
$this -> users [ $id_user ][ 'level' ] = dol_strlen ( preg_replace ( '/[^_]/i' , '' , $this -> users [ $id_user ][ 'fullpath' ]));
2013-03-30 14:27:13 +01:00
2017-02-21 23:52:13 +01:00
return 1 ;
2013-03-30 14:27:13 +01:00
}
2015-04-18 18:11:01 +02:00
/**
* Function used to replace a thirdparty id with another one .
*
2022-12-28 13:27:13 +01:00
* @ param DoliDB $dbs Database handler , because function is static we name it $dbs not $db to avoid breaking coding test
* @ param int $origin_id Old thirdparty id
* @ param int $dest_id New thirdparty id
* @ return bool
2015-04-18 18:11:01 +02:00
*/
2022-12-28 13:27:13 +01:00
public static function replaceThirdparty ( DoliDB $dbs , $origin_id , $dest_id )
2015-04-18 18:11:01 +02:00
{
$tables = array (
2018-09-16 13:49:22 +02:00
'user' ,
2015-04-18 18:11:01 +02:00
);
2022-12-28 13:27:13 +01:00
return CommonObject :: commonReplaceThirdparty ( $dbs , $origin_id , $dest_id , $tables );
2015-04-18 18:11:01 +02:00
}
2016-03-17 09:22:12 +01:00
2015-12-05 19:31:32 +01:00
/**
2019-04-25 01:50:48 +02:00
* Load metrics this -> nb for dashboard
2017-10-07 13:09:31 +02:00
*
2023-12-01 19:51:32 +01:00
* @ return int Return integer < 0 if KO , > 0 if OK
2017-10-07 13:09:31 +02:00
*/
2024-01-18 18:55:53 +01:00
public function loadStateBoard ()
2017-10-07 13:09:31 +02:00
{
2021-09-09 16:06:16 +02:00
global $conf ;
2017-10-07 13:09:31 +02:00
2019-11-13 19:35:39 +01:00
$this -> nb = array ();
2017-10-07 13:09:31 +02:00
2021-09-09 09:21:30 +02:00
$sql = " SELECT COUNT(DISTINCT u.rowid) as nb " ;
2022-01-21 16:57:57 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " user as u " ;
2023-11-27 12:08:48 +01:00
if ( isModEnabled ( 'multicompany' ) && getDolGlobalString ( 'MULTICOMPANY_TRANSVERSE_MODE' )) {
2022-01-21 16:57:57 +01:00
$sql .= " , " . $this -> db -> prefix () . " usergroup_user as ug " ;
2021-09-09 16:06:16 +02:00
$sql .= " WHERE ug.entity IN ( " . getEntity ( 'usergroup' ) . " ) " ;
$sql .= " AND ug.fk_user = u.rowid " ;
2021-09-08 10:25:27 +02:00
} else {
2021-09-09 16:06:16 +02:00
$sql .= " WHERE u.entity IN ( " . getEntity ( 'user' ) . " ) " ;
2021-09-08 10:25:27 +02:00
}
$sql .= " AND u.statut > 0 " ;
2017-10-07 13:09:31 +02:00
//$sql.= " AND employee != 0";
2019-11-13 19:35:39 +01:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $resql ) {
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2019-11-13 19:35:39 +01:00
$this -> nb [ " users " ] = $obj -> nb ;
2017-10-07 13:09:31 +02:00
}
$this -> db -> free ( $resql );
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> error ();
2017-10-07 13:09:31 +02:00
return - 1 ;
}
}
2016-03-17 09:22:12 +01:00
2017-03-02 15:13:42 +01:00
/**
* Create a document onto disk according to template module .
*
* @ param string $modele Force model to use ( '' to not force )
* @ param Translate $outputlangs Object langs to use for output
* @ param int $hidedetails Hide details of lines
* @ param int $hidedesc Hide description
* @ param int $hideref Hide ref
2024-01-11 10:01:34 +01:00
* @ param null | array $moreparams Array to provide more information
2017-03-02 15:13:42 +01:00
* @ return int 0 if KO , 1 if OK
*/
2019-01-27 15:20:16 +01:00
public function generateDocument ( $modele , $outputlangs , $hidedetails = 0 , $hidedesc = 0 , $hideref = 0 , $moreparams = null )
2017-03-02 15:13:42 +01:00
{
2018-09-16 13:49:22 +02:00
global $conf , $user , $langs ;
2017-03-02 15:13:42 +01:00
$langs -> load ( " user " );
2024-01-11 10:01:34 +01:00
// Set the '$modele' to the name of the document template (model) to use
2020-10-29 00:34:41 +01:00
if ( ! dol_strlen ( $modele )) {
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'USER_ADDON_PDF' )) {
2024-01-05 04:18:53 +01:00
$modele = getDolGlobalString ( 'USER_ADDON_PDF' );
2020-05-21 15:05:19 +02:00
} else {
2017-03-02 15:13:42 +01:00
$modele = 'bluesky' ;
}
}
$modelpath = " core/modules/user/doc/ " ;
2018-06-15 09:47:28 +02:00
return $this -> commonGenerateDocument ( $modelpath , $modele , $outputlangs , $hidedetails , $hidedesc , $hideref , $moreparams );
2017-03-02 15:13:42 +01:00
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2018-03-21 11:48:30 +01:00
/**
2018-03-21 23:03:22 +01:00
* Return property of user from its id
2018-03-21 11:48:30 +01:00
*
* @ param int $rowid id of contact
2023-07-16 14:54:08 +02:00
* @ param string $mode 'email' , 'mobile' , or 'name'
2018-03-21 23:03:22 +01:00
* @ return string Email of user with format : " Full name <email> "
2018-03-21 11:48:30 +01:00
*/
2019-02-25 20:35:59 +01:00
public function user_get_property ( $rowid , $mode )
2018-03-21 11:48:30 +01:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-11-13 19:35:39 +01:00
$user_property = '' ;
2018-03-21 11:48:30 +01:00
2020-10-29 00:34:41 +01:00
if ( empty ( $rowid )) {
return '' ;
}
2018-03-21 11:48:30 +01:00
$sql = " SELECT rowid, email, user_mobile, civility, lastname, firstname " ;
2022-01-21 16:57:57 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " user " ;
2020-09-20 03:36:02 +02:00
$sql .= " WHERE rowid = " . (( int ) $rowid );
2018-03-21 11:48:30 +01:00
2019-11-13 19:35:39 +01:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $resql ) {
2018-03-21 11:48:30 +01:00
$nump = $this -> db -> num_rows ( $resql );
2020-10-29 00:34:41 +01:00
if ( $nump ) {
2018-03-21 11:48:30 +01:00
$obj = $this -> db -> fetch_object ( $resql );
2020-10-29 00:34:41 +01:00
if ( $mode == 'email' ) {
$user_property = dolGetFirstLastname ( $obj -> firstname , $obj -> lastname ) . " < " . $obj -> email . " > " ;
} elseif ( $mode == 'mobile' ) {
$user_property = $obj -> user_mobile ;
2023-07-16 14:54:08 +02:00
} elseif ( $mode == 'name' ) {
$user_property = dolGetFirstLastname ( $obj -> firstname , $obj -> lastname );
2020-10-29 00:34:41 +01:00
}
2018-03-21 11:48:30 +01:00
}
return $user_property ;
2020-05-21 15:05:19 +02:00
} else {
2018-03-21 11:48:30 +01:00
dol_print_error ( $this -> db );
}
2023-05-01 17:21:00 +02:00
return '' ;
2018-03-21 11:48:30 +01:00
}
2023-01-07 04:05:59 +01:00
/**
* Return string with full Url to virtual card
*
2023-01-07 12:36:53 +01:00
* @ param string $mode Mode for link
2023-03-13 16:28:58 +01:00
* @ param string $typeofurl 'external' or 'internal'
2023-01-07 12:36:53 +01:00
* @ return string Url string link
2023-01-07 04:05:59 +01:00
*/
2023-03-13 16:28:58 +01:00
public function getOnlineVirtualCardUrl ( $mode = '' , $typeofurl = 'external' )
2023-01-07 04:05:59 +01:00
{
2023-05-03 12:01:36 +02:00
global $dolibarr_main_url_root ;
2023-01-07 04:05:59 +01:00
global $conf ;
2023-05-03 12:01:36 +02:00
$encodedsecurekey = dol_hash ( $conf -> file -> instance_unique_id . 'uservirtualcard' . $this -> id . '-' . $this -> login , 'md5' );
2023-01-07 04:05:59 +01:00
if ( isModEnabled ( 'multicompany' )) {
$entity_qr = '&entity=' . (( int ) $conf -> entity );
} else {
$entity_qr = '' ;
}
// Define $urlwithroot
$urlwithouturlroot = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( $dolibarr_main_url_root ));
$urlwithroot = $urlwithouturlroot . DOL_URL_ROOT ; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
2023-03-13 16:28:58 +01:00
if ( $typeofurl == 'internal' ) {
$urlwithroot = DOL_URL_ROOT ;
}
2023-01-07 12:36:53 +01:00
return $urlwithroot . '/public/users/view.php?id=' . $this -> id . '&securekey=' . $encodedsecurekey . $entity_qr . ( $mode ? '&mode=' . urlencode ( $mode ) : '' );
2023-01-07 04:05:59 +01:00
}
2018-03-21 11:48:30 +01:00
/**
2018-03-21 23:03:22 +01:00
* Load all objects into $this -> users
2018-03-21 11:48:30 +01:00
*
2018-11-27 16:39:08 +01:00
* @ param string $sortorder sort order
* @ param string $sortfield sort field
* @ param int $limit limit page
* @ param int $offset page
2024-03-05 03:51:36 +01:00
* @ param string $filter Filter as an Universal Search string .
* Example : '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:' a % ')'
* @ param string $filtermode No more used
2019-04-24 08:17:10 +02:00
* @ param bool $entityfilter Activate entity filter
2023-12-01 19:51:32 +01:00
* @ return int Return integer < 0 if KO , > 0 if OK
2018-03-21 11:48:30 +01:00
*/
2024-03-05 03:51:36 +01:00
public function fetchAll ( $sortorder = '' , $sortfield = '' , $limit = 0 , $offset = 0 , $filter = '' , $filtermode = 'AND' , $entityfilter = false )
2020-09-07 10:18:17 +02:00
{
global $conf , $user ;
2018-03-21 11:48:30 +01:00
2019-11-13 19:35:39 +01:00
$sql = " SELECT t.rowid " ;
2022-01-21 16:57:57 +01:00
$sql .= ' FROM ' . $this -> db -> prefix () . $this -> table_element . ' as t ' ;
2019-04-24 08:17:10 +02:00
2020-10-29 00:34:41 +01:00
if ( $entityfilter ) {
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'MULTICOMPANY_TRANSVERSE_MODE' )) {
2019-11-13 19:35:39 +01:00
if ( ! empty ( $user -> admin ) && empty ( $user -> entity ) && $conf -> entity == 1 ) {
$sql .= " WHERE t.entity IS NOT NULL " ; // Show all users
2019-04-24 08:17:10 +02:00
} else {
2022-01-21 16:57:57 +01:00
$sql .= " , " . $this -> db -> prefix () . " usergroup_user as ug " ;
2019-11-13 19:35:39 +01:00
$sql .= " WHERE ((ug.fk_user = t.rowid " ;
2022-10-28 16:31:01 +02:00
$sql .= " AND ug.entity IN ( " . getEntity ( 'usergroup' ) . " )) " ;
2019-11-13 19:35:39 +01:00
$sql .= " OR t.entity = 0) " ; // Show always superadmin
2019-04-24 08:17:10 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$sql .= " WHERE t.entity IN ( " . getEntity ( 'user' ) . " ) " ;
2019-04-24 08:17:10 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2021-05-05 11:49:11 +02:00
$sql .= " WHERE 1 = 1 " ;
2019-04-24 08:17:10 +02:00
}
2018-03-21 11:48:30 +01:00
2018-11-27 16:39:08 +01:00
// Manage filter
2024-03-05 03:51:36 +01:00
$errormessage = '' ;
$sql .= forgeSQLFromUniversalSearchCriteria ( $filter , $errormessage );
if ( $errormessage ) {
$this -> errors [] = $errormessage ;
2024-03-08 21:34:18 +01:00
dol_syslog ( __METHOD__ . ' ' . implode ( ',' , $this -> errors ), LOG_ERR );
2024-03-05 03:51:36 +01:00
return - 1 ;
2018-11-27 16:39:08 +01:00
}
2024-03-05 03:51:36 +01:00
2019-11-13 19:35:39 +01:00
$sql .= $this -> db -> order ( $sortfield , $sortorder );
2020-10-29 00:34:41 +01:00
if ( $limit ) {
$sql .= $this -> db -> plimit ( $limit + 1 , $offset );
}
2018-03-21 11:48:30 +01:00
2020-02-17 12:34:00 +01:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
2018-03-21 11:48:30 +01:00
2019-11-13 19:35:39 +01:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( $resql ) {
2019-11-13 19:35:39 +01:00
$this -> users = array ();
2018-03-21 11:48:30 +01:00
$num = $this -> db -> num_rows ( $resql );
2020-10-29 00:34:41 +01:00
if ( $num ) {
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2018-03-21 11:48:30 +01:00
$line = new self ( $this -> db );
$result = $line -> fetch ( $obj -> rowid );
2019-11-13 19:35:39 +01:00
if ( $result > 0 && ! empty ( $line -> id )) {
2018-03-21 11:48:30 +01:00
$this -> users [ $obj -> rowid ] = clone $line ;
}
}
$this -> db -> free ( $resql );
}
return $num ;
2020-05-21 15:05:19 +02:00
} else {
2020-09-08 21:27:28 +02:00
$this -> errors [] = $this -> db -> lasterror ();
return - 1 ;
}
2020-08-21 08:18:26 +02:00
}
/**
* Cache the SQL results of the function " findUserIdByEmail( $email ) "
2020-08-25 12:20:48 +02:00
*
2020-08-25 12:16:44 +02:00
* NOTE : findUserIdByEmailCache [ ... ] === - 1 means not found in database
2020-08-25 12:20:48 +02:00
*
2020-08-21 08:18:26 +02:00
* @ var array
*/
private $findUserIdByEmailCache ;
/**
2020-08-25 12:16:44 +02:00
* Find a user by the given e - mail and return it ' s user id when found
*
* NOTE :
* Use AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR
* to disable exact e - mail search
2020-08-21 08:18:26 +02:00
*
2020-08-25 12:16:44 +02:00
* @ param string $email The full e - mail ( or a part of a e - mail )
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 = user was not found , > 0 = The id of the user
2020-08-21 08:18:26 +02:00
*/
public function findUserIdByEmail ( $email )
{
2022-04-30 20:41:18 +02:00
if ( isset ( $this -> findUserIdByEmailCache [ $email ])) {
2020-08-21 08:18:26 +02:00
return $this -> findUserIdByEmailCache [ $email ];
}
2020-08-25 12:16:44 +02:00
$this -> findUserIdByEmailCache [ $email ] = - 1 ;
2020-08-21 08:18:26 +02:00
$sql = 'SELECT rowid' ;
2022-01-21 16:57:57 +01:00
$sql .= ' FROM ' . $this -> db -> prefix () . 'user' ;
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR' )) {
2024-02-16 01:19:53 +01:00
$sql .= " WHERE email LIKE '% " . $this -> db -> escape ( $this -> db -> escapeforlike ( $email )) . " %' " ;
2020-10-29 00:34:41 +01:00
} else {
2021-08-28 03:09:18 +02:00
$sql .= " WHERE email = ' " . $this -> db -> escape ( $email ) . " ' " ;
2020-08-25 12:16:44 +02:00
}
$sql .= ' LIMIT 1' ;
2020-08-21 08:18:26 +02:00
$resql = $this -> db -> query ( $sql );
2020-10-29 00:34:41 +01:00
if ( ! $resql ) {
2020-08-25 12:16:44 +02:00
return - 1 ;
2020-08-21 08:18:26 +02:00
}
$obj = $this -> db -> fetch_object ( $resql );
2020-10-29 00:34:41 +01:00
if ( ! $obj ) {
2020-08-25 12:16:44 +02:00
return - 1 ;
2018-03-21 11:48:30 +01:00
}
2020-08-21 08:18:26 +02:00
2020-08-25 12:16:44 +02:00
$this -> findUserIdByEmailCache [ $email ] = ( int ) $obj -> rowid ;
2020-08-21 08:18:26 +02:00
2020-08-25 12:16:44 +02:00
return $this -> findUserIdByEmailCache [ $email ];
2020-08-21 08:18:26 +02:00
}
2002-04-30 12:51:35 +02:00
}