diff --git a/htdocs/blockedlog/class/blockedlog.class.php b/htdocs/blockedlog/class/blockedlog.class.php
index b559ee84096..1c9b9282bd7 100644
--- a/htdocs/blockedlog/class/blockedlog.class.php
+++ b/htdocs/blockedlog/class/blockedlog.class.php
@@ -201,7 +201,7 @@ class BlockedLog
/*
// Salary
- if (!empty($conf->salary->enabled)) {
+ if (isModEnabled('salary')) {
$this->trackedevents['PAYMENT_SALARY_CREATE']='BlockedLogSalaryPaymentCreate';
$this->trackedevents['PAYMENT_SALARY_MODIFY']='BlockedLogSalaryPaymentCreate';
$this->trackedevents['PAYMENT_SALARY_DELETE']='BlockedLogSalaryPaymentCreate';
diff --git a/htdocs/bookcal/availabilities_agenda.php b/htdocs/bookcal/availabilities_agenda.php
index 4de8cdae284..30a5cb249c3 100644
--- a/htdocs/bookcal/availabilities_agenda.php
+++ b/htdocs/bookcal/availabilities_agenda.php
@@ -146,7 +146,7 @@ if ($object->id > 0) {
$help_url = 'EN:Module_Agenda_En|DE:Modul_Terminplanung';
llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-bookcal page-card_availabilities_agenda');
- if (!empty($conf->notification->enabled)) {
+ if (isModEnabled('notification')) {
$langs->load("mails");
}
$head = availabilitiesPrepareHead($object);
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 6e35b9debe2..369b7844172 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -1421,7 +1421,7 @@ class Commande extends CommonOrder
$this->origin_id = $object->id;
// Multicurrency (test on $this->multicurrency_tx because we should take the default rate only if not using origin rate)
- if (!empty($conf->multicurrency->enabled)) {
+ if (isModEnabled('multicurrency')) {
if (!empty($object->multicurrency_code)) {
$this->multicurrency_code = $object->multicurrency_code;
}
diff --git a/htdocs/compta/paiement/document.php b/htdocs/compta/paiement/document.php
index cc3dc586540..a3164e50093 100644
--- a/htdocs/compta/paiement/document.php
+++ b/htdocs/compta/paiement/document.php
@@ -35,7 +35,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
-if (!empty($conf->project->enabled)) {
+if (isModEnabled('project')) {
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
}
@@ -127,7 +127,7 @@ if ($object->id > 0) {
$allow_delete = 1;
// Bank account
- if (!empty($conf->banque->enabled)) {
+ if (isModEnabled('bank')) {
if ($object->fk_account) {
$bankline = new AccountLine($db);
$bankline->fetch($object->bank_line);
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 6121f90d23c..4b8b075d0cd 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -1749,7 +1749,7 @@ abstract class CommonObject
} elseif (strpos($obj->element, 'supplier') !== false && $obj->element != 'supplier_proposal') {
$modulename = 'fournisseur';
}
- if (!empty($conf->{$modulename}->enabled)) {
+ if (isModEnabled($modulename)) {
$libelle_element = $langs->trans('ContactDefault_'.$obj->element);
$tmpelement = $obj->element;
$transkey = "TypeContact_".$tmpelement."_".$source."_".$obj->code;
diff --git a/htdocs/core/class/infobox.class.php b/htdocs/core/class/infobox.class.php
index 19ebf3e77ac..76e090d884e 100644
--- a/htdocs/core/class/infobox.class.php
+++ b/htdocs/core/class/infobox.class.php
@@ -180,7 +180,7 @@ class InfoBox
$tmpenabled = 0; // $tmpenabled is used for the '|' test (OR)
foreach ($arrayelem as $module) {
$tmpmodule = preg_replace('/@[^@]+/', '', $module);
- if (!empty($conf->$tmpmodule->enabled)) {
+ if (isModEnabled($tmpmodule)) {
$tmpenabled = 1;
}
//print $boxname.'-'.$module.'-module enabled='.(empty($conf->$tmpmodule->enabled)?0:1).'
';
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index f0c1d6c19aa..c9a5e42935d 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -4520,7 +4520,7 @@ function dolGetCountryCodeFromIp($ip)
$countrycode = '';
- if (!empty($conf->geoipmaxmind->enabled)) {
+ if (isModEnabled('geoipmaxmind')) {
$datafile = getDolGlobalString('GEOIPMAXMIND_COUNTRY_DATAFILE');
//$ip='24.24.24.24';
//$datafile='/usr/share/GeoIP/GeoIP.dat'; Note that this must be downloaded datafile (not same than datafile provided with ubuntu packages)
@@ -4546,7 +4546,7 @@ function dol_user_country()
//$ret=$user->xxx;
$ret = '';
- if (!empty($conf->geoipmaxmind->enabled)) {
+ if (isModEnabled('geoipmaxmind')) {
$ip = getUserRemoteIP();
$datafile = getDolGlobalString('GEOIPMAXMIND_COUNTRY_DATAFILE');
//$ip='24.24.24.24';
diff --git a/htdocs/core/lib/sendings.lib.php b/htdocs/core/lib/sendings.lib.php
index 38148b222a0..bfd96475cc8 100644
--- a/htdocs/core/lib/sendings.lib.php
+++ b/htdocs/core/lib/sendings.lib.php
@@ -285,7 +285,7 @@ function show_list_sending_receive($origin, $origin_id, $filter = '')
print '
'.$langs->trans("Warehouse").' | ';
}
/*TODO Add link to expeditiondet_batch
- if (!empty($conf->productbatch->enabled))
+ if (isModEnabled('productbatch'))
{
print '';
print ' | ';
@@ -411,7 +411,7 @@ function show_list_sending_receive($origin, $origin_id, $filter = '')
// Batch number management
/*TODO Add link to expeditiondet_batch
- if (!empty($conf->productbatch->enabled))
+ if (isModEnabled('productbatch'))
{
//var_dump($objp->edrowid);
$lines[$i]->detail_batch
diff --git a/htdocs/core/modules/modProductBatch.class.php b/htdocs/core/modules/modProductBatch.class.php
index 5a7e283ccf5..b0c6a41ea8b 100644
--- a/htdocs/core/modules/modProductBatch.class.php
+++ b/htdocs/core/modules/modProductBatch.class.php
@@ -136,7 +136,7 @@ class modProductBatch extends DolibarrModules
$sql = array();
- if (!empty($conf->cashdesk->enabled)) {
+ if (isModEnabled('cashdesk')) {
if (!getDolGlobalString('CASHDESK_NO_DECREASE_STOCK')) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
$res = dolibarr_set_const($db, "CASHDESK_NO_DECREASE_STOCK", 1, 'chaine', 0, '', $conf->entity);
diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php
index 2bef662a479..1044bfbb05e 100644
--- a/htdocs/fourn/card.php
+++ b/htdocs/fourn/card.php
@@ -45,7 +45,7 @@ if (isModEnabled('member')) {
if (isModEnabled('category')) {
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
}
-if (!empty($conf->accounting->enabled)) {
+if (isModEnabled('accounting')) {
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
}
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index 6aaea69b048..994e8fb7ca0 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -1993,7 +1993,7 @@ if ($action == 'create') {
'morecss' => 'minwidth300'
)
);
- if (!empty($conf->notification->enabled)) {
+ if (isModEnabled('notification')) {
require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
$notify = new Notify($db);
$text .= '
';
@@ -2005,7 +2005,7 @@ if ($action == 'create') {
// Confirmation de l'envoi de la commande
if ($action == 'commande') {
$date_com = dol_mktime(GETPOST('rehour'), GETPOST('remin'), GETPOST('resec'), GETPOST("remonth"), GETPOST("reday"), GETPOST("reyear"));
- if (!empty($conf->notification->enabled)) {
+ if (isModEnabled('notification')) {
require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
$notify = new Notify($db);
$text .= '
';
diff --git a/htdocs/product/price.php b/htdocs/product/price.php
index b9a2d280f73..a5958a553a5 100644
--- a/htdocs/product/price.php
+++ b/htdocs/product/price.php
@@ -1473,7 +1473,7 @@ if (($action == 'edit_price' || $action == 'edit_level_price') && $object->getRi
print '';
// Only show price mode and expression selector if module is enabled
- if (!empty($conf->dynamicprices->enabled)) {
+ if (isModEnabled('dynamicprices')) {
// Price mode selector
print ''."\n";
print '| '.$langs->trans("PriceMode").' | ';
@@ -2345,7 +2345,7 @@ if ((!getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || $action == 'showlog_defau
if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
print ' | '.$langs->trans("INCT").' | ';
}
- if (!empty($conf->dynamicprices->enabled)) {
+ if (isModEnabled('dynamicprices')) {
print ''.$langs->trans("PriceExpressionSelected").' | ';
}
print ''.$langs->trans("MinPrice").' '.$langs->trans("HT").' | ';
@@ -2460,7 +2460,7 @@ if ((!getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || $action == 'showlog_defau
print $resultarray[2];
print '';
}
- if (!empty($conf->dynamicprices->enabled)) { //Only if module is enabled
+ if (isModEnabled('dynamicprices')) { // Only if module is enabled
print ' | ';
}
}
diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php
index 68b727a055d..2f2b735e97b 100644
--- a/htdocs/theme/eldy/style.css.php
+++ b/htdocs/theme/eldy/style.css.php
@@ -338,7 +338,7 @@ if (getDolGlobalString('MAIN_USE_TOP_MENU_QUICKADD_DROPDOWN')) {
if (getDolGlobalString('MAIN_USE_TOP_MENU_SEARCH_DROPDOWN')) {
$maxwidthloginblock += 55;
}
-if (!empty($conf->bookmark->enabled)) {
+if (isModEnabled('bookmark')) {
$maxwidthloginblock += 55;
}
diff --git a/htdocs/user/group/card.php b/htdocs/user/group/card.php
index 2abd7183b86..f9a800fd495 100644
--- a/htdocs/user/group/card.php
+++ b/htdocs/user/group/card.php
@@ -322,7 +322,7 @@ if ($action == 'create') {
print '';
// Name (already in dol_banner, we keep it to have the GlobalGroup picto, but we should move it in dol_banner)
- if (!empty($conf->mutlicompany->enabled)) {
+ if (isModEnabled('multicompany')) {
print '| '.$langs->trans("Name").' | ';
print ''.dol_escape_htmltag($object->name);
if (empty($object->entity)) {
diff --git a/htdocs/user/group/ldap.php b/htdocs/user/group/ldap.php
index 93c5cb91cb7..68472c3e639 100644
--- a/htdocs/user/group/ldap.php
+++ b/htdocs/user/group/ldap.php
@@ -111,7 +111,7 @@ print '';
print '';
// Name (already in dol_banner, we keep it to have the GlobalGroup picto, but we should move it in dol_banner)
-if (!empty($conf->mutlicompany->enabled)) {
+if (isModEnabled('multicompany')) {
print '| '.$langs->trans("Name").' | ';
print ''.$object->name;
if (!$object->entity) {
diff --git a/htdocs/user/group/perms.php b/htdocs/user/group/perms.php
index cba79dd5d9d..7ae14e9b794 100644
--- a/htdocs/user/group/perms.php
+++ b/htdocs/user/group/perms.php
@@ -221,7 +221,7 @@ if ($object->id > 0) {
print '';
// Name (already in dol_banner, we keep it to have the GlobalGroup picto, but we should move it in dol_banner)
- if (!empty($conf->mutlicompany->enabled)) {
+ if (isModEnabled('multicompany')) {
print '| '.$langs->trans("Name").' | ';
print ''.dol_escape_htmltag($object->name);
if (empty($object->entity)) {
diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php
index 90f96f900b5..a4b7696cf03 100644
--- a/htdocs/webservices/server_productorservice.php
+++ b/htdocs/webservices/server_productorservice.php
@@ -1,7 +1,7 @@
* Copyright (C) 2012 JF FERRY
- * Copyright (C) 2020-2024 Frédéric France
+ * Copyright (C) 2020-2024 Frédéric France
*
* 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
@@ -613,7 +613,7 @@ function createProductOrService($authentication, $product)
if (!$error) {
// Update stock if stock count is provided and differs from database after creation or update
- if (isset($product['stock_real']) && $product['stock_real'] != '' && !empty($conf->global->stock->enabled)) {
+ if (isset($product['stock_real']) && $product['stock_real'] != '' && isModEnabled('stock')) {
include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
$savstockreal = $newobject->stock_reel;
@@ -766,7 +766,7 @@ function updateProductOrService($authentication, $product)
$error++;
} else {
// Update stock if stock count is provided and differs from database after creation or update
- if (isset($product['stock_real']) && $product['stock_real'] != '' && !empty($conf->global->stock->enabled)) {
+ if (isset($product['stock_real']) && $product['stock_real'] != '' && isModEnabled('stock')) {
include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
$savstockreal = $newobject->stock_reel;
diff --git a/test/phpunit/CodingPhpTest.php b/test/phpunit/CodingPhpTest.php
index 3a69b982468..ea0a885e00a 100644
--- a/test/phpunit/CodingPhpTest.php
+++ b/test/phpunit/CodingPhpTest.php
@@ -137,6 +137,17 @@ class CodingPhpTest extends CommonClassTest
$this->verifyIsModuleEnabledOk($filecontent, $report_filepath);
+ // Check we do not use the syntax conf->global->enabled->...
+ $ok = true;
+ $matches = array();
+ preg_match_all('/->global->(.*)->enabled/', $filecontent, $matches, PREG_SET_ORDER);
+ foreach ($matches as $key => $val) {
+ $ok = false;
+ break;
+ }
+ //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
+ $this->assertTrue($ok, 'Found a ->global->...->enabled instead of isModEnabled("...") in file '.$file['relativename']);
+
if (preg_match('/\.class\.php/', $file['relativename'])
|| preg_match('/boxes\/box_/', $file['relativename'])
|| preg_match('/modules\/.*\/doc\/(doc|pdf)_/', $file['relativename'])
| | |