2017-03-09 14:16:45 +00:00
< ? php
2026-07-16 12:06:54 +00:00
/* Copyright ( C ) 2017 - 2025 Laurent Destailleur < eldy @ users . sourcefore . net >
* Copyright ( C ) 2026 Regis Houssin < regis . houssin @ inodbox . com >
2026-07-18 14:17:03 +00:00
* Copyright ( C ) 2026 MDW < mdeweerd @ users . noreply . github . com >
2017-03-09 14:16:45 +00: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
* the Free Software Foundation ; either version 3 of the License , or
* ( 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 19:55:30 +00:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2017-03-09 14:16:45 +00:00
*/
/**
2017-03-27 20:44:50 +00:00
* \defgroup blockedlog Module BlockedLog
2017-03-09 14:16:45 +00:00
* \brief Add a log into a block chain for some actions .
2017-03-27 20:44:50 +00:00
* \file htdocs / core / modules / modBlockedLog . class . php
* \ingroup blockedlog
2021-03-20 12:55:43 +00:00
* \brief Description and activation file for the module BlockedLog
2017-03-09 14:16:45 +00:00
*/
2020-04-10 08:59:32 +00:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php' ;
2025-12-02 19:29:20 +00:00
include_once DOL_DOCUMENT_ROOT . '/blockedlog/lib/blockedlog.lib.php' ;
2026-02-24 16:35:35 +00:00
include_once DOL_DOCUMENT_ROOT . '/blockedlog/versionmod.inc.php' ;
2025-12-02 19:29:20 +00:00
2017-03-09 14:16:45 +00:00
/**
2017-03-29 19:36:50 +00:00
* Class to describe a BlockedLog module
2017-03-09 14:16:45 +00:00
*/
2017-03-27 20:44:50 +00:00
class modBlockedLog extends DolibarrModules
2017-03-09 14:16:45 +00:00
{
2020-10-31 13:32:18 +00:00
/**
* Constructor . Define names , constants , directories , boxes , permissions
*
* @ param DoliDB $db Database handler
*/
public function __construct ( $db )
{
2025-06-23 12:04:36 +00:00
global $mysoc ;
2020-10-31 13:32:18 +00:00
$this -> db = $db ;
$this -> numero = 3200 ;
// Key text used to identify module (for permissions, menus, etc...)
$this -> rights_class = 'blockedlog' ;
// Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
// It is used to group modules in module setup page
$this -> family = " base " ;
// Module position in the family on 2 digits ('01', '10', '20', ...)
2021-02-05 15:14:42 +00:00
$this -> module_position = '76' ;
2020-10-31 13:32:18 +00:00
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
$this -> name = preg_replace ( '/^mod/i' , '' , get_class ( $this ));
2025-06-23 12:04:36 +00:00
$this -> description = " Enable a log on some business events into an unalterable log. This module may be mandatory for some countries. " ;
2025-12-02 19:29:20 +00:00
2020-10-31 13:32:18 +00:00
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
2026-02-19 21:29:20 +00:00
$this -> version = constant ( 'DOLCERT_VERSION' );
2026-02-22 23:11:16 +00:00
$this -> version_if_core = 1 ;
2020-10-31 13:32:18 +00:00
// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
$this -> const_name = 'MAIN_MODULE_' . strtoupper ( $this -> name );
// Name of image file used for this module.
2025-10-10 12:45:07 +00:00
$this -> picto = 'blockedlog' ;
2020-10-31 13:32:18 +00:00
// Data directories to create when module is enabled
$this -> dirs = array ();
// Config pages
//-------------
2026-02-09 17:28:53 +00:00
$this -> config_page_url = array ( 'registration.php?origin=setupmodule&withtab=1@blockedlog' );
2020-10-31 13:32:18 +00:00
2024-01-13 18:48:20 +00:00
// Dependencies
2020-10-31 13:32:18 +00:00
//-------------
$this -> hidden = false ; // A condition to disable module
2026-02-24 16:35:35 +00:00
$this -> depends = array ( 'always' => 'modFacture' ); // List of modules id that must be enabled if this module is enabled
2020-10-31 13:32:18 +00:00
$this -> requiredby = array (); // List of modules id to disable if this one is disabled
$this -> conflictwith = array (); // List of modules id this module is in conflict with
$this -> langfiles = array ( 'blockedlog' );
2025-10-10 08:16:33 +00:00
$this -> warnings_activation = array ();
$this -> warnings_activation_ext = array ();
2026-02-24 16:35:35 +00:00
$this -> warnings_unactivation = array ( 'FR' => 'BlockedLogAreRequiredByYourCountryLegislation' );
2020-10-31 13:32:18 +00:00
// Currently, activation is not automatic because only companies (in France) making invoices to non business customers must
// enable this module.
2025-01-05 17:34:01 +00:00
/* if ( getDolGlobalString ( 'BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY' )) {
2025-10-10 08:16:33 +00:00
$tmp = explode ( ',' , getDolGlobalString ( 'BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY' ));
2021-02-23 21:03:23 +00:00
$this -> automatic_activation = array ();
2025-10-10 08:16:33 +00:00
foreach ( $tmp as $countrycodekey )
2021-02-23 21:03:23 +00:00
{
2025-10-10 08:16:33 +00:00
$this -> automatic_activation [ $countrycodekey ] = 'BlockedLogActivatedBecauseRequiredByYourCountryLegislation' ;
2021-02-23 21:03:23 +00:00
}
} */
2020-10-31 13:32:18 +00:00
//var_dump($this->automatic_activation);
2024-10-25 18:13:14 +00:00
$this -> always_enabled = ( isModEnabled ( 'blockedlog' )
2023-11-27 10:39:32 +00:00
&& getDolGlobalString ( 'BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY' )
2023-12-13 14:20:53 +00:00
&& in_array (( empty ( $mysoc -> country_code ) ? '' : $mysoc -> country_code ), explode ( ',' , getDolGlobalString ( 'BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY' )))
2020-10-31 13:32:18 +00:00
&& $this -> alreadyUsed ());
// Constants
//-----------
$this -> const = array (
2026-02-24 16:35:35 +00:00
1 => array ( 'BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY' , 'chaine' , 'FR' , 'This is list of country code where the module may be mandatory' , 0 , 'current' , 0 )
2020-10-31 13:32:18 +00:00
);
// New pages on tabs
// -----------------
$this -> tabs = array ();
// Boxes
//------
$this -> boxes = array ();
// Permissions
// -----------------
$this -> rights = array (); // Permission array used by this module
2021-04-05 11:52:19 +00:00
$r = 1 ;
2020-10-31 13:32:18 +00:00
$this -> rights [ $r ][ 0 ] = $this -> numero + $r ; // Permission id (must not be already used)
$this -> rights [ $r ][ 1 ] = 'Read archived events and fingerprints' ; // Permission label
$this -> rights [ $r ][ 3 ] = 0 ; // Permission by default for new user (0/1)
$this -> rights [ $r ][ 4 ] = 'read' ; // In php code, permission will be checked by test if ($user->rights->mymodule->level1->level2)
$this -> rights [ $r ][ 5 ] = '' ;
// Main menu entries
// -----------------
$r = 0 ;
$this -> menu [ $r ] = array (
2026-02-24 16:35:35 +00:00
'fk_menu' => 'fk_mainmenu=tools' , // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'mainmenu' => 'tools' ,
'leftmenu' => 'blockedlogbrowser' ,
'type' => 'left' , // This is a Left menu entry
'titre' => 'BrowseBlockedLog' ,
2021-02-07 21:18:34 +00:00
'prefix' => img_picto ( '' , $this -> picto , 'class="paddingright pictofixedwidth"' ),
2026-02-24 16:35:35 +00:00
'url' => '/blockedlog/admin/blockedlog_list.php?mainmenu=tools&leftmenu=blockedlogbrowser' ,
'langs' => 'blockedlog' , // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position' => 200 ,
'enabled' => 'isModEnabled("blockedlog")' , // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
'perms' => '$user->hasRight("blockedlog", "read")' , // Use 'perms'=>'$user->hasRight("mymodule","level1","level2")' if you want your menu with a permission rules
'target' => '' ,
'user' => 2 , // 0=Menu for internal users, 1=external users, 2=both
2021-02-07 21:18:34 +00:00
);
2020-10-31 13:32:18 +00:00
$r ++ ;
}
/**
* Check if module was already used before unactivation linked to warnings_unactivation property
*
* @ return boolean True if already used , otherwise False
*/
public function alreadyUsed ()
{
2025-10-28 12:07:19 +00:00
require_once DOL_DOCUMENT_ROOT . '/blockedlog/lib/blockedlog.lib.php' ;
2026-01-01 11:26:35 +00:00
return isBlockedLogUsed ();
2020-10-31 13:32:18 +00:00
}
/**
* Function called when module is enabled .
* The init function add constants , boxes , permissions and menus ( defined in constructor ) into Dolibarr database .
* It also creates data directories .
*
2025-01-15 09:25:47 +00:00
* @ param string $options Options when enabling module ( '' , 'noboxes' , 'acceptredirect' , 'forceinit' )
2020-10-31 13:32:18 +00:00
* @ return int 1 if OK , 0 if KO
*/
public function init ( $options = '' )
{
2026-06-16 15:06:46 +00:00
global $conf , $langs , $mysoc , $user ;
2020-10-31 13:32:18 +00:00
$sql = array ();
2026-06-16 15:06:46 +00:00
2026-06-19 21:50:44 +00:00
// Detect minimal version of PHP
if ( version_compare ( PHP_VERSION , '7.0.0' ) < 0 ) {
$errmsg = 'Error: You are using a too low version of PHP' ;
dol_syslog ( $errmsg , LOG_ERR );
$this -> error = $errmsg ;
return 0 ;
}
2026-06-16 15:06:46 +00:00
// Clear cache
unset ( $_SESSION [ 'obfuscationkey_' . (( int ) $conf -> entity )]);
unset ( $conf -> cache [ 'obfuscationkey_' . (( int ) $conf -> entity )]);
2020-10-31 13:32:18 +00:00
2026-01-08 20:45:10 +00:00
require_once DOL_DOCUMENT_ROOT . '/blockedlog/class/blockedlog.class.php' ;
$b = new BlockedLog ( $this -> db );
2025-01-15 09:25:47 +00:00
// any value of $options except 'acceptredirect' will bypass this redirection
2026-06-16 15:06:46 +00:00
if ( isALNEQualifiedVersion ( 1 , 1 ) && $options == 'acceptredirect' ) { // Redirect done for all french companies, even if not assujeti.
2026-01-27 00:15:30 +00:00
// We first switch on registration page
2026-02-09 17:28:53 +00:00
header ( " Location: " . DOL_URL_ROOT . '/blockedlog/admin/registration.php?origin=initmodule&withtab=0' );
2026-01-27 00:15:30 +00:00
exit ;
}
2026-01-08 20:45:10 +00:00
2026-06-20 06:07:21 +00:00
// Check the context of running company is defined
if ( empty ( $mysoc -> country_code )) {
$errmsg = 'Error: The context of the running company is not defined' ;
dol_syslog ( $errmsg , LOG_ERR );
$this -> error = $errmsg ;
return 0 ;
}
2025-12-02 19:29:20 +00:00
// Check that the HTTPS is forced
2026-01-08 20:45:10 +00:00
$s = $b -> canBeEnabled ();
if ( $s ) { // Activation not allowed
$this -> error = $s ;
2025-12-02 19:29:20 +00:00
return 0 ;
}
2026-06-21 17:16:53 +00:00
// If we are here, it means the registration has been done, we can activate the module (this means creating a HMAC key).
$this -> db -> begin ();
2026-06-18 11:22:36 +00:00
$error = 0 ;
2026-06-15 19:18:28 +00:00
// Generate and save the HMAC key if it does not exists yet
2026-06-21 17:16:53 +00:00
$hmac_encoded_secret_key = $b -> getEncodedHMACSecretKey ();
2026-06-15 19:18:28 +00:00
2025-11-12 16:25:40 +00:00
if ( empty ( $hmac_encoded_secret_key )) {
2026-06-16 15:06:46 +00:00
// No HMAC key yet, we generate one.
2026-06-15 19:18:28 +00:00
$randomsecret = bin2hex ( random_bytes ( 32 )); // 64 char hex - 256 bits
2026-06-06 14:17:23 +00:00
2026-06-15 21:00:35 +00:00
$hmac_secret_key = 'BLOCKEDLOGHMAC' . $randomsecret ; // Example: 'BLOCKEDLOGHMACY3Ewx37RXbSd8gL9JV8p7Wqw7qvq2K2A'
//$hmac_secret_key = 'BLOCKEDLOGHMACY3Ewx37RXbSd8gL9JV8p7Wqw7qvq2K2A';
2025-11-12 16:25:40 +00:00
2026-06-16 15:06:46 +00:00
$obfuscationkey = '' ;
if ( isALNERunningVersion ( 1 ) && $mysoc -> country_code == 'FR' ) {
try {
$obfuscationkey = $b -> getObfuscationKey (); // Get the obfuscation key from memory or remote server. If not found, we retrieve it.
//$obfuscationkey = ''; // Uncomment this to test if obfuscation key can't be retrieved.
} catch ( Exception $e ) {
$error ++ ;
setEventMessages ( $e -> getMessage (), null , 'errors' );
$obfuscationkey = '' ;
}
if ( empty ( $obfuscationkey )) {
$error ++ ;
2026-06-17 15:39:31 +00:00
$url_for_ping = getDolGlobalString ( 'MAIN_URL_FOR_PING' , " https://ping.dolibarr.org/ " );
setEventMessages ( $langs -> trans ( 'FailedToGetRemoteObfuscationKeyReTryLater' , $url_for_ping ), null , 'errors' );
2026-06-16 15:06:46 +00:00
}
if ( ! $error ) {
2026-06-21 17:16:53 +00:00
// Save HMAC key to obfuscate it with the $obfuscationkey
2026-06-16 15:06:46 +00:00
//$result = dolibarr_set_const($this->db, 'BLOCKEDLOG_HMAC_KEY', $hmac_secret_key, 'chaine', 0, 'The secret key for HMAC used for blockedlog record', 0); // Will encrypt the value using dolCrypt and store it.
$result = $b -> saveHMACSecretKey ( $hmac_secret_key , 'dolobfuscationv1-' . $mysoc -> idprof1 , $obfuscationkey ); // gitleaks:allow
if ( $result < 0 ) {
$error ++ ;
setEventMessages ( $b -> error , $b -> errors , 'errors' );
}
}
} else {
2026-06-18 11:22:36 +00:00
$result = $b -> saveHMACSecretKey ( $hmac_secret_key , 'dolcrypt' ); // gitleaks:allow
2026-06-16 15:06:46 +00:00
if ( $result < 0 ) {
$error ++ ;
setEventMessages ( $b -> error , $b -> errors , 'errors' );
}
}
2025-11-12 16:25:40 +00:00
} else {
2026-06-21 17:16:53 +00:00
// This case should not happen. If using a certified version, the module can't be disabled and reinitialized, so
// we should not reach this code. In case it happens in future (or if using F5 just after enabling module), we reach this protection
// that check everything is still ok and report a warning if not.
// Here we have the obfuscated value of BLOCKEDLOG_HMAC_KEY in $hmac_encoded_secret_key. We need to unobfuscate it.
$hmac_secret_key = '' ;
try {
$hmac_secret_key = $b -> getClearHMACSecretKey ( $hmac_encoded_secret_key ); // Note: On network trouble, an Exception is thrown to the caller
} catch ( Exception $e ) {
$firsterrormessage = $e -> getMessage ();
// Another chance to get HMAC when saved with old obfuscation method (dolcrypt) - Migration will be done at next writing.
$hmac_encoded_secret_key_alt = $b -> getEncodedHMACSecretKey ( 1 , 1 );
if ( ! empty ( $hmac_encoded_secret_key_alt )) {
try {
$hmac_secret_key_alt = $b -> getClearHMACSecretKey ( $hmac_encoded_secret_key_alt ); // Note: On network trouble, an Exception is thrown to the caller
if ( preg_match ( '/^BLOCKEDLOGHMAC/' , ( string ) $hmac_secret_key_alt )) {
$hmac_secret_key = $hmac_secret_key_alt ;
$firsterrormessage = '' ;
}
} catch ( Exception $e ) {
if ( empty ( $firsterrormessage )) {
$firsterrormessage = $e -> getMessage ();
}
}
} else {
if ( empty ( $firsterrormessage )) {
$firsterrormessage = $e -> getMessage ();
}
}
if ( $firsterrormessage ) { // If error
$error ++ ;
2026-06-21 17:31:16 +00:00
$this -> error = 'modBlockLog init Error: ' . $firsterrormessage . '. ' ;
2026-06-21 17:16:53 +00:00
}
}
if ( ! preg_match ( '/^BLOCKEDLOGHMAC/' , $hmac_secret_key )) {
$error ++ ;
2026-06-21 17:31:16 +00:00
$this -> error .= 'modBlockedLog init Error: Failed to decode the crypted value of the parameter BLOCKEDLOG_HMAC_KEY ' . $hmac_encoded_secret_key . ' using the remote obfuscation key. The value was found in llx_const table but decoding with obfuscation key failed. May be the remote server to get the obfuscation key to decode it was offline.' ;
$this -> error .= ' If you don\'t use the Unalterable Log module, you can also remove the BLOCKEDLOG_HMAC_KEY entry from llx_const table. If you use the Unalterable Log, this is not possible because this will invalidate all past record.' ;
2026-06-21 17:16:53 +00:00
}
/*
2026-06-16 15:06:46 +00:00
if ( preg_match ( '/^dolobfuscationv1/' , $hmac_encoded_secret_key )) {
// New method
$obfuscationkey = '' ;
try {
2026-06-20 14:30:50 +00:00
dol_syslog ( " mysoc->profid1 = " . $mysoc -> idprof1 );
2026-06-16 15:06:46 +00:00
$obfuscationkey = $b -> getObfuscationKey (); // Get the obfuscation key from memory or remote server. If not found, we retrieve it.
//$obfuscationkey = ''; // Uncomment this to test if obfuscation key can't be retrieved.
} catch ( Exception $e ) {
$error ++ ;
$this -> error = $e -> getMessage ();
$obfuscationkey = '' ;
}
if ( empty ( $obfuscationkey )) {
$error ++ ;
2026-06-17 15:39:31 +00:00
$url_for_ping = getDolGlobalString ( 'MAIN_URL_FOR_PING' , " https://ping.dolibarr.org/ " );
$this -> error = $langs -> trans ( 'FailedToGetRemoteObfuscationKeyReTryLater' , $url_for_ping );
2026-06-16 15:06:46 +00:00
}
$hmac_secret_key = dolDecrypt ( $hmac_encoded_secret_key , $obfuscationkey );
if ( ! preg_match ( '/^BLOCKEDLOGHMAC/' , $hmac_secret_key )) {
2026-06-18 11:22:36 +00:00
$error ++ ;
2026-06-20 06:07:21 +00:00
$this -> error = 'modBlockedLog init Error: Failed to decode the crypted value of the parameter BLOCKEDLOG_HMAC_KEY ' . $hmac_encoded_secret_key . ' using the remote obfuscation key. The value was found in llx_const table but decoding with ' . $obfuscationkey . ' failed. May be the remote server to get the obfucation key to decode it was offline.' ;
2026-06-16 15:06:46 +00:00
$this -> error .= 'If you don\'t use the Unalterable Log module, you can also remove the BLOCKEDLOG_HMAC_KEY entry from llx_const table. If you use the Unalterable Log, this is not possible because this will invalidate all past record.' ;
}
} else {
// Old method for backward compatibility
2026-06-18 11:22:36 +00:00
// Note: The migration of the way to store the HMAC key from old method to the new one will be done automatically at next recording by buildFinalSignatureHash()
2026-06-16 15:06:46 +00:00
$hmac_secret_key = dolDecrypt ( $hmac_encoded_secret_key );
if ( ! preg_match ( '/^BLOCKEDLOGHMAC/' , $hmac_secret_key )) {
2026-06-18 11:22:36 +00:00
$error ++ ;
2026-06-20 06:07:21 +00:00
$this -> error = 'modBlockedLog init Error: Failed to decode the crypted value of the parameter BLOCKEDLOG_HMAC_KEY ' . $hmac_encoded_secret_key . ' using the $dolibarr_main_crypt_key. The value was found in llx_const table but decoding failed. May be the database data were restored onto another environment and the coding/decoding key $dolibarr_main_dolcrypt_key was not restored with the same value in conf.php file.' ;
2026-06-16 15:06:46 +00:00
$this -> error .= 'Restore the value of $dolibarr_main_crypt_key that was used for encryption in database and restart the migration.' ;
$this -> error .= 'If you don\'t use the Unalterable Log module, you can also remove the BLOCKEDLOG_HMAC_KEY entry from llx_const table. If you use the Unalterable Log, this is not possible because this will invalidate all past record.' ;
}
2025-11-12 16:25:40 +00:00
}
2026-06-21 17:16:53 +00:00
*/
2025-11-12 16:25:40 +00:00
}
2026-06-18 11:22:36 +00:00
if ( $error ) {
$this -> db -> rollback ();
return 0 ;
} else {
$this -> db -> commit ();
}
2025-11-12 16:25:40 +00:00
2025-01-15 09:25:47 +00:00
// We add an entry to show we enable the module
2020-10-31 13:32:18 +00:00
2021-08-23 08:20:22 +00:00
$object = new stdClass ();
2024-10-25 18:13:14 +00:00
$object -> id = 0 ;
2020-10-31 13:32:18 +00:00
$object -> element = 'module' ;
$object -> ref = 'systemevent' ;
$object -> entity = $conf -> entity ;
$object -> date = dol_now ();
2026-06-18 15:28:14 +00:00
$object -> label = 'Module enabled' ;
2020-10-31 13:32:18 +00:00
2025-11-12 16:25:40 +00:00
// Add first entry in unalterable Log to track that module was activated
2024-10-25 18:13:14 +00:00
$action = 'MODULE_SET' ;
2025-01-15 09:25:47 +00:00
$result = $b -> setObjectData ( $object , $action , 0 , $user , 0 );
2024-10-25 18:13:14 +00:00
2021-02-23 21:03:23 +00:00
if ( $result < 0 ) {
2020-10-31 13:32:18 +00:00
$this -> error = $b -> error ;
2022-11-14 19:51:52 +00:00
$this -> errors = $b -> errors ;
2020-10-31 13:32:18 +00:00
return 0 ;
}
2025-01-15 09:25:47 +00:00
$this -> db -> begin ();
2020-10-31 13:32:18 +00:00
$res = $b -> create ( $user );
if ( $res <= 0 ) {
2025-01-15 09:25:47 +00:00
$this -> db -> rollback ();
2020-10-31 13:32:18 +00:00
$this -> error = $b -> error ;
$this -> errors = $b -> errors ;
return $res ;
}
2025-01-15 09:25:47 +00:00
$resinit = $this -> _init ( $sql , $options );
if ( $resinit <= 0 ) {
$this -> db -> rollback ();
return $resinit ;
}
$this -> db -> commit ();
return 1 ;
2020-10-31 13:32:18 +00:00
}
/**
* Function called when module is disabled .
* The remove function removes tabs , constants , boxes , permissions and menus from Dolibarr database .
* Data directories are not deleted
*
2026-02-17 15:59:07 +00:00
* @ param string $options Options when enabling module ( '' , 'noboxes' , 'forcedisable' )
2026-06-06 14:17:23 +00:00
* @ return int 1 if OK , 0 if KO to cancel all actions
2020-10-31 13:32:18 +00:00
*/
public function remove ( $options = '' )
{
2025-11-10 23:59:51 +00:00
global $conf , $user ;
2020-10-31 13:32:18 +00:00
$sql = array ();
// If already used, we add an entry to show we enable module
require_once DOL_DOCUMENT_ROOT . '/blockedlog/class/blockedlog.class.php' ;
2026-06-18 15:28:14 +00:00
$b = new BlockedLog ( $this -> db );
2020-10-31 13:32:18 +00:00
2026-02-17 15:59:07 +00:00
dol_syslog ( " modBlockedLog::remove option= " . $options , LOG_DEBUG );
2020-10-31 13:32:18 +00:00
$object = new stdClass ();
$object -> id = 1 ;
$object -> element = 'module' ;
$object -> ref = 'systemevent' ;
$object -> entity = $conf -> entity ;
$object -> date = dol_now ();
2025-11-14 10:47:05 +00:00
$object -> label = 'Module disabled' ;
2020-10-31 13:32:18 +00:00
2026-06-18 15:28:14 +00:00
// Add entry in unalterable Log to track that module was activated
$action = 'MODULE_RESET' ;
$result = $b -> setObjectData ( $object , $action , 0 , $user , 0 );
2021-02-23 21:03:23 +00:00
if ( $result < 0 ) {
2020-10-31 13:32:18 +00:00
$this -> error = $b -> error ;
2022-11-14 19:51:52 +00:00
$this -> errors = $b -> errors ;
2020-10-31 13:32:18 +00:00
return 0 ;
}
2021-02-23 21:03:23 +00:00
if ( $b -> alreadyUsed ( 1 )) {
2025-11-12 18:37:19 +00:00
// Unalterable log was already used.
2026-02-17 15:59:07 +00:00
if ( $options != 'forcedisable' && ! $b -> canBeDisabled ()) {
2025-11-12 18:37:19 +00:00
// Case we refuse to disable it
global $langs ;
$this -> error = $langs -> trans ( 'DisablingBlockedLogIsNotallowedOnceUsedExceptOnFullreset' , $langs -> transnoentitiesnoconv ( 'BlockedLog' ));
return 0 ;
} else {
// Case we disable it with a log
$res = $b -> create ( $user , '0000000000' ); // If already used for something else than SET or UNSET, we log with error
}
2020-10-31 13:32:18 +00:00
} else {
$res = $b -> create ( $user );
}
if ( $res <= 0 ) {
$this -> error = $b -> error ;
$this -> errors = $b -> errors ;
return $res ;
}
return $this -> _remove ( $sql , $options );
}
2025-12-02 19:29:20 +00:00
/**
* Overwrite the common getDesc () method
*
* @ param int < 0 , 1 > $foruseinpopupdesc If 1 , we return a short description for use into popup window
* @ return string Translated module description
*/
public function getDesc ( $foruseinpopupdesc = 0 )
{
2026-02-09 02:21:18 +00:00
global $langs , $mysoc ;
2025-12-02 19:29:20 +00:00
$langs -> load ( " admin " );
// If module description translation exists
$s = $langs -> transnoentitiesnoconv ( " Module " . $this -> numero . " Desc " );
if ( $foruseinpopupdesc ) {
$langs -> load ( " blockedlog " );
2026-02-09 02:21:18 +00:00
$s .= '<br>' ;
// Special message for France
if ( $mysoc -> country_code == 'FR' ) {
$islne = isALNEQualifiedVersion ( 1 , 1 );
2026-06-08 10:54:46 +00:00
$versionbadge = '<span class="badge-text badge-secondary">' . getBlockedLogVersionToShow ();
/*
if ( $mysoc -> country_code == 'FR' && ! constant ( 'CERTIF_LNE' )) {
// Can add an edditional mention
$versionbadge .= ' - ' . $langs -> trans ( " NeedAThirdPartyStatement " );
}
*/
$versionbadge .= '</span>' ;
2026-02-09 02:21:18 +00:00
if ( $islne ) {
2026-02-12 20:43:54 +00:00
if ( preg_match ( '/\-/' , DOL_VERSION )) {
// This is an alpha or beta version
2026-02-16 04:48:39 +00:00
$s .= info_admin ( $langs -> trans ( " LNECandidateVersionForCertificationFR " , $versionbadge ), 0 , 0 , 'info' );
2026-02-12 20:43:54 +00:00
} else {
2026-02-16 04:48:39 +00:00
$s .= info_admin ( $langs -> trans ( " LNECertifiedVersionFR " , $versionbadge ), 0 , 0 , 'info' );
2026-02-12 20:43:54 +00:00
}
2026-02-09 02:21:18 +00:00
} else {
2026-02-16 04:48:39 +00:00
$s .= info_admin ( $langs -> trans ( " NotCertifiedVersionFR " , $versionbadge ), 0 , 0 , 'warning' );
2026-02-09 02:21:18 +00:00
}
}
// Add warning to advice users to make regularly archives
if ( in_array ( $mysoc -> country_code , array ( 'FR' ))) {
2025-12-02 19:29:20 +00:00
$s .= info_admin ( $langs -> trans ( " UnalterableLogTool1FR " ), 0 , 0 , 'warning' );
}
}
return $s ;
}
2017-03-09 14:16:45 +00:00
}