From 05e6c8ce11e7fc82e09ada4b13bb16098cf9771b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 18 Oct 2025 19:09:52 +0200 Subject: [PATCH 1/9] Fix phpstan (#35828) * clean phpstan baseline * clean baseline * clean baseline * clean baseline * clean baseline --- dev/build/phpstan/phpstan-baseline.neon | 78 ------------------- .../tpl/depreciation_options_view.tpl.php | 1 + htdocs/compta/tva/clients.php | 1 + .../tpl/extrafields_list_print_fields.tpl.php | 3 + .../tpl/extrafields_list_search_sql.tpl.php | 2 + htdocs/core/tpl/filemanager.tpl.php | 11 ++- .../core/tpl/objectlinked_lineimport.tpl.php | 14 ++-- 7 files changed, 23 insertions(+), 87 deletions(-) diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index 7c91286d1ca..c23f77e134e 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -1410,12 +1410,6 @@ parameters: count: 1 path: ../../../htdocs/asset/tpl/depreciation_options_edit.tpl.php - - - message: '#^Variable \$db might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../htdocs/asset/tpl/depreciation_options_view.tpl.php - - message: '#^Variable \$parameters might not be defined\.$#' identifier: variable.undefined @@ -4032,12 +4026,6 @@ parameters: count: 1 path: ../../../htdocs/compta/tva/clients.php - - - message: '#^Variable \$description might not be defined\.$#' - identifier: variable.undefined - count: 8 - path: ../../../htdocs/compta/tva/clients.php - - message: '#^Strict comparison using \=\=\= between true and true will always evaluate to true\.$#' identifier: identical.alwaysTrue @@ -8658,42 +8646,18 @@ parameters: count: 1 path: ../../../htdocs/core/tpl/extrafields_list_array_fields.tpl.php - - - message: '#^Variable \$db might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../htdocs/core/tpl/extrafields_list_print_fields.tpl.php - - message: '#^Variable \$i might not be defined\.$#' identifier: variable.undefined count: 1 path: ../../../htdocs/core/tpl/extrafields_list_print_fields.tpl.php - - - message: '#^Variable \$obj might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../htdocs/core/tpl/extrafields_list_print_fields.tpl.php - - message: '#^Variable \$totalarray might not be defined\.$#' identifier: variable.undefined count: 2 path: ../../../htdocs/core/tpl/extrafields_list_print_fields.tpl.php - - - message: '#^Variable \$db might not be defined\.$#' - identifier: variable.undefined - count: 8 - path: ../../../htdocs/core/tpl/extrafields_list_search_sql.tpl.php - - - - message: '#^Variable \$sql might not be defined\.$#' - identifier: variable.undefined - count: 7 - path: ../../../htdocs/core/tpl/extrafields_list_search_sql.tpl.php - - message: '#^Variable \$param might not be defined\.$#' identifier: variable.undefined @@ -8712,36 +8676,6 @@ parameters: count: 1 path: ../../../htdocs/core/tpl/filemanager.tpl.php - - - message: '#^Variable \$action might not be defined\.$#' - identifier: variable.undefined - count: 6 - path: ../../../htdocs/core/tpl/filemanager.tpl.php - - - - message: '#^Variable \$ecmdir might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../htdocs/core/tpl/filemanager.tpl.php - - - - message: '#^Variable \$filepathnoext might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../htdocs/core/tpl/filemanager.tpl.php - - - - message: '#^Variable \$module in empty\(\) always exists and is not falsy\.$#' - identifier: empty.variable - count: 1 - path: ../../../htdocs/core/tpl/filemanager.tpl.php - - - - message: '#^Variable \$pageid might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../htdocs/core/tpl/filemanager.tpl.php - - message: '#^Variable \$websitekey might not be defined\.$#' identifier: variable.undefined @@ -8814,18 +8748,6 @@ parameters: count: 2 path: ../../../htdocs/core/tpl/objectline_view.tpl.php - - - message: '#^Variable \$langs might not be defined\.$#' - identifier: variable.undefined - count: 4 - path: ../../../htdocs/core/tpl/objectlinked_lineimport.tpl.php - - - - message: '#^Variable \$object might not be defined\.$#' - identifier: variable.undefined - count: 3 - path: ../../../htdocs/core/tpl/objectlinked_lineimport.tpl.php - - message: '#^Variable \$langs might not be defined\.$#' identifier: variable.undefined diff --git a/htdocs/asset/tpl/depreciation_options_view.tpl.php b/htdocs/asset/tpl/depreciation_options_view.tpl.php index 6994eeb1f50..59353160a24 100644 --- a/htdocs/asset/tpl/depreciation_options_view.tpl.php +++ b/htdocs/asset/tpl/depreciation_options_view.tpl.php @@ -27,6 +27,7 @@ */ /** + * @var DoliDB $db * @var Form $form * @var HookManager $hookmanager * @var AssetDepreciationOptions $assetdepreciationoptions diff --git a/htdocs/compta/tva/clients.php b/htdocs/compta/tva/clients.php index 4229cec5b6e..dcd9189c1f3 100644 --- a/htdocs/compta/tva/clients.php +++ b/htdocs/compta/tva/clients.php @@ -155,6 +155,7 @@ $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '. $builddate = dol_now(); +$description = ''; if (getDolGlobalString('TAX_MODE_SELL_PRODUCT') == 'invoice') { $description = $langs->trans("RulesVATDueProducts"); } diff --git a/htdocs/core/tpl/extrafields_list_print_fields.tpl.php b/htdocs/core/tpl/extrafields_list_print_fields.tpl.php index 4328520dfc5..440cb592b34 100644 --- a/htdocs/core/tpl/extrafields_list_print_fields.tpl.php +++ b/htdocs/core/tpl/extrafields_list_print_fields.tpl.php @@ -20,6 +20,8 @@ /** * @var Conf $conf * @var CommonObject $object + * @var stdClass $obj + * @var DoliDB $db * @var ExtraFields $extrafields * * @var string $extrafieldsobjectkey @@ -27,6 +29,7 @@ ' @phan-var-force CommonObject $object +@phan-var-force stdClass $obj '; // Protection to avoid direct call of template diff --git a/htdocs/core/tpl/extrafields_list_search_sql.tpl.php b/htdocs/core/tpl/extrafields_list_search_sql.tpl.php index fb50e5fcd79..30fee094541 100644 --- a/htdocs/core/tpl/extrafields_list_search_sql.tpl.php +++ b/htdocs/core/tpl/extrafields_list_search_sql.tpl.php @@ -24,7 +24,9 @@ /** * @var Conf $conf * @var CommonObject $object + * @var DoliDB $db * @var ExtraFields $extrafields + * @var string $sql */ // Protection to avoid direct call of template diff --git a/htdocs/core/tpl/filemanager.tpl.php b/htdocs/core/tpl/filemanager.tpl.php index 8ae866f2194..dad6e61aa56 100644 --- a/htdocs/core/tpl/filemanager.tpl.php +++ b/htdocs/core/tpl/filemanager.tpl.php @@ -23,13 +23,19 @@ /** * @var Conf $conf * @var DoliDB $db + * @var EcmDirectory $ecmdir * @var Form $form * @var HookManager $hookmanager * @var Translate $langs * @var User $user * @var Website $website * - * @var string $module + * @var string $action + * @var ?string $module + * @var int $section + * @var string $filepathnoext + * @var string $pageid + * @var int $formalreadyopen */ // Protection to avoid direct call of template if (empty($conf) || !is_object($conf)) { @@ -42,6 +48,7 @@ if (empty($conf) || !is_object($conf)) { @phan-var-force string $filepathnoext @phan-var-force string $pageid @phan-var-force EcmDirectory $ecmdir +@phan-var-force ?string $module @phan-var-force int $section '; @@ -56,7 +63,7 @@ require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; $langs->load("ecm"); -if (empty($module)) { +if (!isset($module)) { $module = 'ecm'; } diff --git a/htdocs/core/tpl/objectlinked_lineimport.tpl.php b/htdocs/core/tpl/objectlinked_lineimport.tpl.php index c6ac5664b3c..720b8cba1f7 100644 --- a/htdocs/core/tpl/objectlinked_lineimport.tpl.php +++ b/htdocs/core/tpl/objectlinked_lineimport.tpl.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011-2013 Regis Houssin * Copyright (C) 2025 MDW * * This program is free software; you can redistribute it and/or modify @@ -15,6 +15,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +/** + * @var Conf $conf + * @var CommonObject $object + * @var Translate $langs + */ // Protection to avoid direct call of template if (empty($conf) || !is_object($conf)) { @@ -24,7 +29,7 @@ if (empty($conf) || !is_object($conf)) { $objectUrl = $object->getNomUrl(0, '', '0', 1); if ($object->element == 'propal') { - $objectUrl = DOL_URL_ROOT.'/comm/propal/card.php?id='.$object->id; + $objectUrl = dolBuildUrl(DOL_URL_ROOT.'/comm/propal/card.php', ['id' => $object->id]); } ?> @@ -94,12 +99,7 @@ $(document).ready(function(){ { $.jnotify("trans('ErrorNoUrl'); ?>", "error", true); } - }); - - - - }); From 66683105f17da75f0604176aaa35b834f129a757 Mon Sep 17 00:00:00 2001 From: MDW Date: Sat, 18 Oct 2025 19:10:43 +0200 Subject: [PATCH 2/9] Qual: Fix phan notices (#35827) # Qual: Fix phan notices Some type hints updates + correction to get week from date (action/pertype.php) + check that value is not null (pdf_* classes). --- dev/tools/phan/baseline.txt | 13 +++--- htdocs/comm/action/pertype.php | 6 +-- htdocs/compta/facture/class/facture.class.php | 2 +- htdocs/core/actions_addupdatedelete.inc.php | 6 +-- htdocs/core/lib/pdf.lib.php | 4 +- .../modules/cheque/doc/pdf_blochet.class.php | 4 +- .../commande/doc/pdf_eratosthene.modules.php | 5 ++- .../facture/doc/pdf_octopus.modules.php | 43 ++++++++++--------- .../facture/doc/pdf_sponge.modules.php | 43 ++++++++++--------- .../modules/propale/doc/pdf_azur.modules.php | 5 ++- .../modules/propale/doc/pdf_cyan.modules.php | 5 ++- 11 files changed, 69 insertions(+), 67 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index 84f617721b4..9a5a0557e9f 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -11,20 +11,20 @@ return [ // # Issue statistics: // PhanUndeclaredProperty : 420+ occurrences // PhanTypeMismatchProperty : 100+ occurrences - // PhanTypeMismatchArgument : 70+ occurrences + // PhanTypeMismatchArgument : 65+ occurrences // PhanUndeclaredGlobalVariable : 60+ occurrences // PhanTypeMismatchArgumentNullable : 40+ occurrences // PhanTypeInvalidDimOffset : 15+ occurrences - // PhanTypeMismatchDimFetch : 15+ occurrences + // PhanTypeMismatchDimFetch : 10+ occurrences // PhanUndeclaredMethod : 8 occurrences // PhanPossiblyUndeclaredGlobalVariable : 6 occurrences // PhanTypeArraySuspiciousNull : 6 occurrences // PhanTypeComparisonFromArray : 6 occurrences // PhanTypeExpectedObjectPropAccess : 5 occurrences - // PhanTypeMismatchArgumentProbablyReal : 5 occurrences // PhanPluginDuplicateArrayKey : 4 occurrences // PhanParamTooMany : 3 occurrences // PhanPluginUndeclaredVariableIsset : 3 occurrences + // PhanTypeMismatchArgumentProbablyReal : 2 occurrences // PhanPossiblyUndeclaredVariable : 1 occurrence // PhanTypeExpectedObjectPropAccessButGotNull : 1 occurrence // PhanTypeMismatchReturn : 1 occurrence @@ -34,7 +34,7 @@ return [ 'htdocs/bookcal/class/calendar.class.php' => ['PhanUndeclaredMethod', 'PhanUndeclaredProperty'], 'htdocs/categories/viewcat.php' => ['PhanUndeclaredProperty'], 'htdocs/comm/action/index.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty'], - 'htdocs/comm/action/pertype.php' => ['PhanTypeComparisonFromArray', 'PhanTypeExpectedObjectPropAccess', 'PhanTypeMismatchDimFetch'], + 'htdocs/comm/action/pertype.php' => ['PhanTypeComparisonFromArray', 'PhanTypeExpectedObjectPropAccess'], 'htdocs/comm/action/peruser.php' => ['PhanTypeComparisonFromArray', 'PhanTypeMismatchArgument'], 'htdocs/comm/card.php' => ['PhanTypeMismatchArgument'], 'htdocs/comm/mailing/index.php' => ['PhanUndeclaredProperty'], @@ -53,7 +53,6 @@ return [ 'htdocs/compta/clients.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/compta/facture/card-rec.php' => ['PhanTypeMismatchArgument'], 'htdocs/compta/facture/card.php' => ['PhanUndeclaredProperty'], - 'htdocs/compta/facture/class/api_invoices.class.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'htdocs/compta/facture/class/facture-rec.class.php' => ['PhanUndeclaredProperty'], 'htdocs/compta/facture/class/facture.class.php' => ['PhanUndeclaredProperty'], 'htdocs/compta/localtax/card.php' => ['PhanUndeclaredGlobalVariable'], @@ -72,7 +71,7 @@ return [ 'htdocs/compta/tva/index.php' => ['PhanTypeMismatchArgument'], 'htdocs/compta/tva/quadri_detail.php' => ['PhanTypeArraySuspiciousNull', 'PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgument'], 'htdocs/contrat/card.php' => ['PhanUndeclaredGlobalVariable'], - 'htdocs/core/actions_addupdatedelete.inc.php' => ['PhanTypeMismatchDimFetch', 'PhanUndeclaredProperty'], + 'htdocs/core/actions_addupdatedelete.inc.php' => ['PhanUndeclaredProperty'], 'htdocs/core/actions_massactions.inc.php' => ['PhanUndeclaredProperty'], 'htdocs/core/actions_sendmails.inc.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/core/ajax/ajaxdirtree.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty', 'PhanUndeclaredGlobalVariable'], @@ -105,7 +104,6 @@ return [ 'htdocs/core/menus/standard/auguria.lib.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/asset/mod_asset_advanced.php' => ['PhanUndeclaredProperty'], 'htdocs/core/modules/bom/mod_bom_advanced.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], - 'htdocs/core/modules/cheque/doc/pdf_blochet.class.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'htdocs/core/modules/cheque/modules_chequereceipts.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/commande/doc/pdf_einstein.modules.php' => ['PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'], 'htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'], @@ -228,7 +226,6 @@ return [ 'htdocs/projet/tasks/tpl/linkedobjectblock.tpl.php' => ['PhanUndeclaredProperty'], 'htdocs/public/members/new.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/public/payment/newpayment.php' => ['PhanUndeclaredProperty'], - 'htdocs/public/payment/paymentok.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'htdocs/public/project/suggestbooth.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/public/project/suggestconference.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/public/project/viewandvote.php' => ['PhanUndeclaredGlobalVariable'], diff --git a/htdocs/comm/action/pertype.php b/htdocs/comm/action/pertype.php index ca277618baf..f0733642668 100644 --- a/htdocs/comm/action/pertype.php +++ b/htdocs/comm/action/pertype.php @@ -6,7 +6,7 @@ * Copyright (C) 2011 Juanjo Menent * Copyright (C) 2014 Cedric GROSS * Copyright (C) 2019-2025 Frédéric France - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * * 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 @@ -254,11 +254,11 @@ $nowday = $nowarray['mday']; // Define list of all external calendars (global setup) $listofextcals = array(); -$prev = dol_get_first_day($year, $month); $first_day = 1; $first_month = 1; $first_year = $year; +$prev = dol_get_first_day_week($day, $month, $year); $week = $prev['week']; $day = (int) $day; @@ -339,7 +339,6 @@ $param .= "&maxprint=".urlencode((string) ($maxprint)); $paramnoactionodate = $param; -$prev = dol_get_first_day($year, 1); $prev_year = $year - 1; $prev_month = $month; $prev_day = $day; @@ -347,6 +346,7 @@ $first_day = 1; $first_month = 1; $first_year = $year; +$prev = dol_get_first_day_week(1, 1, $year); $week = $prev['week']; $day = (int) $day; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index b2c060944f8..2a7d806ce5c 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1533,7 +1533,7 @@ class Facture extends CommonInvoice /** * Load an object from a contract and create a new invoice into database * - * @param Facture $object Object source + * @param Contrat $object Object source * @param User $user Object user * @param int[] $lines Ids of lines to use for invoice. If empty, all lines will be used. * @return int Return integer <0 if KO, 0 if nothing done, 1 if OK diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index 60cefeee7e8..6da5d8cb271 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -1,6 +1,6 @@ - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024-2025 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -153,7 +153,7 @@ if ($action == 'add' && !empty($permissiontoadd)) { $value = ((GETPOST($key) == '1' || GETPOST($key) == 'on') ? 1 : 0); } elseif ($object->fields[$key]['type'] == 'reference') { $tmparraykey = array_keys($object->param_list); - $value = $tmparraykey[GETPOST($key)].','.GETPOST($key.'2'); + $value = $tmparraykey[(int) GETPOST($key)].','.GETPOST($key.'2'); } elseif (preg_match('/^chkbxlst:(.*)/', $object->fields[$key]['type']) || $object->fields[$key]['type'] == 'checkbox') { $value = ''; $values_arr = GETPOST($key, 'array'); @@ -315,7 +315,7 @@ if ($action == 'update' && !empty($permissiontoadd)) { } elseif ($object->fields[$key]['type'] == 'boolean') { $value = ((GETPOST($key, 'aZ09') == 'on' || GETPOST($key, 'aZ09') == '1') ? 1 : 0); } elseif ($object->fields[$key]['type'] == 'reference') { - $value = array_keys($object->param_list)[GETPOST($key)].','.GETPOST($key.'2'); + $value = array_keys($object->param_list)[(int) GETPOST($key)].','.GETPOST($key.'2'); } elseif (preg_match('/^chkbxlst:/', $object->fields[$key]['type']) || $object->fields[$key]['type'] == 'checkbox') { $value = ''; $values_arr = GETPOST($key, 'array'); diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index dacc6b1d443..4116bbaa7d5 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1035,9 +1035,9 @@ function pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber = 0, * @param float $marge_basse Margin bottom we use for the autobreak * @param float $marge_gauche Margin left (no more used) * @param float $page_hauteur Page height - * @param CommonObject $object Object shown in PDF + * @param ?CommonObject $object Object shown in PDF * @param int<0,3> $showdetails Show company address details into footer (0=Nothing, 1=Show address, 2=Show managers, 3=Both) - * @param int $hidefreetext 1=Hide free text, 0=Show free text + * @param int<0,1> $hidefreetext 1=Hide free text, 0=Show free text * @param float $page_largeur Page width * @param string $watermark Watermark text to print on page * @return int Return height of bottom margin including footer text diff --git a/htdocs/core/modules/cheque/doc/pdf_blochet.class.php b/htdocs/core/modules/cheque/doc/pdf_blochet.class.php index 5d1f6fe5b6d..9122f2fc442 100644 --- a/htdocs/core/modules/cheque/doc/pdf_blochet.class.php +++ b/htdocs/core/modules/cheque/doc/pdf_blochet.class.php @@ -208,7 +208,7 @@ class BordereauChequeBlochet extends ModeleChequeReceipts $this->Body($pdf, $pagenb, $pages, $outputlangs); - // Pied de page + // Page footer $this->_pagefoot($pdf, null, $outputlangs); if (method_exists($pdf, 'AliasNbPages')) { $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod @@ -427,7 +427,7 @@ class BordereauChequeBlochet extends ModeleChequeReceipts * Show footer of page. Need this->emetteur object * * @param TCPDF $pdf PDF - * @param CommonObject $object Object to show + * @param ?CommonObject $object Object to show * @param Translate $outputlangs Object lang for output * @param int<0,1> $hidefreetext 1=Hide free text * @return int diff --git a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php index 7400d0bbd20..5b39cfc0204 100644 --- a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php @@ -228,8 +228,9 @@ class pdf_eratosthene extends ModelePDFCommandes $realpath = null; foreach ($pdir as $midir) { if (!$arephoto) { - if ($conf->entity != $objphoto->entity) { - $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities + $entity = $objphoto->entity; + if ($entity !== null && $conf->entity != $entity) { + $dir = $conf->product->multidir_output[$entity].'/'.$midir; //Check repertories of current entities } else { $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product } diff --git a/htdocs/core/modules/facture/doc/pdf_octopus.modules.php b/htdocs/core/modules/facture/doc/pdf_octopus.modules.php index a60b833f2be..c5d45278269 100644 --- a/htdocs/core/modules/facture/doc/pdf_octopus.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_octopus.modules.php @@ -329,8 +329,9 @@ class pdf_octopus extends ModelePDFFactures $realpath = false; foreach ($pdir as $midir) { if (!$arephoto) { - if ($conf->entity != $objphoto->entity) { - $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities + $entity = $objphoto->entity; + if ($entity !== null && $conf->entity != $entity) { + $dir = $conf->product->multidir_output[$entity].'/'.$midir; //Check repertories of current entities } else { $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product } @@ -1480,13 +1481,13 @@ class pdf_octopus extends ModelePDFFactures if ($object->status > Facture::STATUS_DRAFT && getDolGlobalInt('PDF_INVOICE_SHOW_BALANCE_SUMMARY')) { // All customer previous invoices $sql = "SELECT f.rowid, f.datef, f.total_ttc"; - $sql.= " FROM " . MAIN_DB_PREFIX . "facture as f"; - $sql.= " WHERE f.fk_soc = " . ((int) $object->socid); - $sql.= " AND f.entity IN (" . getEntity('invoice') . ")"; - $sql.= " AND f.datef <= '" . $this->db->idate($object->date) . "'"; - $sql.= " AND f.rowid < " . ((int) $object->id); - $sql.= " AND f.fk_statut > 0"; - $sql.= " ORDER BY f.datef ASC"; + $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f"; + $sql .= " WHERE f.fk_soc = " . ((int) $object->socid); + $sql .= " AND f.entity IN (" . getEntity('invoice') . ")"; + $sql .= " AND f.datef <= '" . $this->db->idate($object->date) . "'"; + $sql .= " AND f.rowid < " . ((int) $object->id); + $sql .= " AND f.fk_statut > 0"; + $sql .= " ORDER BY f.datef ASC"; $old_balance = 0; $invoices = array(); @@ -1501,12 +1502,12 @@ class pdf_octopus extends ModelePDFFactures // All payments before current date $sql_payments = "SELECT p.datep, pf.fk_facture, pf.amount"; - $sql_payments.= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf"; - $sql_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement"; - $sql_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture"; - $sql_payments.= " WHERE f.fk_soc = " . ((int) $object->socid); - $sql_payments.= " AND p.datep < '" . $this->db->idate($object->date) . "'"; - $sql_payments.= " ORDER BY p.datep ASC"; + $sql_payments .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf"; + $sql_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement"; + $sql_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture"; + $sql_payments .= " WHERE f.fk_soc = " . ((int) $object->socid); + $sql_payments .= " AND p.datep < '" . $this->db->idate($object->date) . "'"; + $sql_payments .= " ORDER BY p.datep ASC"; $total_payments = 0; $resql_payments = $this->db->query($sql_payments); @@ -1519,11 +1520,11 @@ class pdf_octopus extends ModelePDFFactures // Payments made on current invoice date (including current invoice) $sql_current_date_payments = "SELECT p.datep, pf.fk_facture, pf.amount"; - $sql_current_date_payments.= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf"; - $sql_current_date_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement"; - $sql_current_date_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture"; - $sql_current_date_payments.= " WHERE f.fk_soc = " . ((int) $object->socid); - $sql_current_date_payments.= " AND DATE(p.datep) = DATE('" . $this->db->idate($object->date) . "')"; + $sql_current_date_payments .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf"; + $sql_current_date_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement"; + $sql_current_date_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture"; + $sql_current_date_payments .= " WHERE f.fk_soc = " . ((int) $object->socid); + $sql_current_date_payments .= " AND DATE(p.datep) = DATE('" . $this->db->idate($object->date) . "')"; $current_date_payments = 0; $resql_current_date = $this->db->query($sql_current_date_payments); @@ -1547,7 +1548,7 @@ class pdf_octopus extends ModelePDFFactures $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0, 'L', true); $pdf->SetFont('', '', $default_font_size - 2); - $pdf->SetXY($posxval+8, $posy); + $pdf->SetXY($posxval + 8, $posy); $titre = $outputlangs->transnoentities("NewBalance").' : '.price($new_balance); $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0, 'L', true); diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index 9f143a5805b..1eebedadea0 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -264,8 +264,9 @@ class pdf_sponge extends ModelePDFFactures $realpath = false; foreach ($pdir as $midir) { if (!$arephoto) { - if ($conf->entity != $objphoto->entity) { - $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities + $entity = $objphoto->entity; + if ($entity !== null && $conf->entity != $entity) { + $dir = $conf->product->multidir_output[$entity].'/'.$midir; //Check repertories of current entities } else { $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product } @@ -1399,13 +1400,13 @@ class pdf_sponge extends ModelePDFFactures if ($object->status > Facture::STATUS_DRAFT && getDolGlobalInt('PDF_INVOICE_SHOW_BALANCE_SUMMARY')) { // All customer previous invoices $sql = "SELECT f.rowid, f.datef, f.total_ttc"; - $sql.= " FROM " . MAIN_DB_PREFIX . "facture as f"; - $sql.= " WHERE f.fk_soc = " . ((int) $object->socid); - $sql.= " AND f.entity IN (" . getEntity('invoice') . ")"; - $sql.= " AND f.datef <= '" . $this->db->idate($object->date) . "'"; - $sql.= " AND f.rowid < " . ((int) $object->id); - $sql.= " AND f.fk_statut > 0"; - $sql.= " ORDER BY f.datef ASC"; + $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f"; + $sql .= " WHERE f.fk_soc = " . ((int) $object->socid); + $sql .= " AND f.entity IN (" . getEntity('invoice') . ")"; + $sql .= " AND f.datef <= '" . $this->db->idate($object->date) . "'"; + $sql .= " AND f.rowid < " . ((int) $object->id); + $sql .= " AND f.fk_statut > 0"; + $sql .= " ORDER BY f.datef ASC"; $old_balance = 0; $invoices = array(); @@ -1420,12 +1421,12 @@ class pdf_sponge extends ModelePDFFactures // All payments before current date $sql_payments = "SELECT p.datep, pf.fk_facture, pf.amount"; - $sql_payments.= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf"; - $sql_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement"; - $sql_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture"; - $sql_payments.= " WHERE f.fk_soc = " . ((int) $object->socid); - $sql_payments.= " AND p.datep < '" . $this->db->idate($object->date) . "'"; - $sql_payments.= " ORDER BY p.datep ASC"; + $sql_payments .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf"; + $sql_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement"; + $sql_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture"; + $sql_payments .= " WHERE f.fk_soc = " . ((int) $object->socid); + $sql_payments .= " AND p.datep < '" . $this->db->idate($object->date) . "'"; + $sql_payments .= " ORDER BY p.datep ASC"; $total_payments = 0; $resql_payments = $this->db->query($sql_payments); @@ -1438,11 +1439,11 @@ class pdf_sponge extends ModelePDFFactures // Payments made on current invoice date (including current invoice) $sql_current_date_payments = "SELECT p.datep, pf.fk_facture, pf.amount"; - $sql_current_date_payments.= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf"; - $sql_current_date_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement"; - $sql_current_date_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture"; - $sql_current_date_payments.= " WHERE f.fk_soc = " . ((int) $object->socid); - $sql_current_date_payments.= " AND DATE(p.datep) = DATE('" . $this->db->idate($object->date) . "')"; + $sql_current_date_payments .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf"; + $sql_current_date_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement"; + $sql_current_date_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture"; + $sql_current_date_payments .= " WHERE f.fk_soc = " . ((int) $object->socid); + $sql_current_date_payments .= " AND DATE(p.datep) = DATE('" . $this->db->idate($object->date) . "')"; $current_date_payments = 0; $resql_current_date = $this->db->query($sql_current_date_payments); @@ -1466,7 +1467,7 @@ class pdf_sponge extends ModelePDFFactures $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0, 'L', true); $pdf->SetFont('', '', $default_font_size - 2); - $pdf->SetXY($posxval+8, $posy); + $pdf->SetXY($posxval + 8, $posy); $titre = $outputlangs->transnoentities("NewBalance").' : '.price($new_balance); $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0, 'L', true); diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index 3ec4f84b215..bb8cbd76641 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -243,8 +243,9 @@ class pdf_azur extends ModelePDFPropales $realpath = ''; foreach ($pdir as $midir) { if (!$arephoto) { - if ($conf->entity != $objphoto->entity) { - $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities + $entity = $objphoto->entity; + if ($entity !== null && $conf->entity != $entity) { + $dir = $conf->product->multidir_output[$entity].'/'.$midir; //Check repertories of current entities } else { $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product } diff --git a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php index f768c5e2e40..5f0266602df 100644 --- a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php @@ -220,8 +220,9 @@ class pdf_cyan extends ModelePDFPropales $arephoto = false; foreach ($pdir as $midir) { if (!$arephoto) { - if ($conf->entity != $objphoto->entity) { - $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities + $entity = $objphoto->entity; + if ($entity !== null && $conf->entity != $entity) { + $dir = $conf->product->multidir_output[$entity].'/'.$midir; //Check repertories of current entities } else { $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product } From 4bc77ebcda60da0f1081da4328c9c68ad7140fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 19 Oct 2025 01:56:26 +0200 Subject: [PATCH 3/9] clean phpstan baseline (#35836) * clean phpstan baseline * clean phpstan baseline --- dev/build/phpstan/phpstan-baseline.neon | 30 ------------------------- htdocs/core/website.inc.php | 7 ++++++ 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index c23f77e134e..d980edeaf18 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -7410,12 +7410,6 @@ parameters: count: 1 path: ../../../htdocs/core/modules/cheque/doc/pdf_blochet.class.php - - - message: '#^Parameter \#2 \$object of method BordereauChequeBlochet\:\:_pagefoot\(\) expects CommonObject, null given\.$#' - identifier: argument.type - count: 1 - path: ../../../htdocs/core/modules/cheque/doc/pdf_blochet.class.php - - message: '#^Property Commande\:\:\$availability \(string\) in isset\(\) is not nullable\.$#' identifier: isset.property @@ -8796,30 +8790,6 @@ parameters: count: 1 path: ../../../htdocs/core/website.inc.php - - - message: '#^Variable \$conf might not be defined\.$#' - identifier: variable.undefined - count: 3 - path: ../../../htdocs/core/website.inc.php - - - - message: '#^Variable \$db might not be defined\.$#' - identifier: variable.undefined - count: 7 - path: ../../../htdocs/core/website.inc.php - - - - message: '#^Variable \$hookmanager might not be defined\.$#' - identifier: variable.undefined - count: 2 - path: ../../../htdocs/core/website.inc.php - - - - message: '#^Variable \$websitekey might not be defined\.$#' - identifier: variable.undefined - count: 2 - path: ../../../htdocs/core/website.inc.php - - message: '#^Loose comparison using \=\= between 1 and 0 will always evaluate to false\.$#' identifier: equal.alwaysFalse diff --git a/htdocs/core/website.inc.php b/htdocs/core/website.inc.php index 3fdee498d18..a0e9eec4ba2 100644 --- a/htdocs/core/website.inc.php +++ b/htdocs/core/website.inc.php @@ -24,6 +24,13 @@ * It is run only when a web page is called. * The global variable $websitekey must be defined. */ +/** + * @var Conf $conf + * @var DoliDB $db + * @var HookManager $hookmanager + * + * @var string $websitekey + */ // Load website class include_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php'; From ed4b7ce58df26acd1d091d7b5398c868e80633a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 19 Oct 2025 01:58:11 +0200 Subject: [PATCH 4/9] clean phpstan baseline (#35838) * clean phpstan baseline * clean phpstan baseline * clean phpstan baseline * fix --- dev/build/phpstan/phpstan-baseline.neon | 36 ------- htdocs/societe/class/societe.class.php | 121 ++++++++++++------------ 2 files changed, 60 insertions(+), 97 deletions(-) diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index d980edeaf18..0f9bcb5cb86 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -15576,24 +15576,6 @@ parameters: count: 1 path: ../../../htdocs/societe/class/companybankaccount.class.php - - - message: '#^Call to function method_exists\(\) with \$this\(Societe\) and ''getLibStatut'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/societe/class/societe.class.php - - - - message: '#^Call to function method_exists\(\) with \$this\(Societe\) and ''getNomUrl'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/societe/class/societe.class.php - - - - message: '#^Call to function property_exists\(\) with \$this\(Societe\) and ''code_client'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/societe/class/societe.class.php - - message: '#^Loose comparison using \!\= between ''email''\|''mobile'' and ''poste'' will always evaluate to true\.$#' identifier: notEqual.alwaysTrue @@ -15606,24 +15588,12 @@ parameters: count: 1 path: ../../../htdocs/societe/class/societe.class.php - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 6 - path: ../../../htdocs/societe/class/societe.class.php - - message: '#^Property Contact\:\:\$roles \(array\\|null\) does not accept non\-empty\-list\\.$#' identifier: assign.propertyType count: 1 path: ../../../htdocs/societe/class/societe.class.php - - - message: '#^Property Societe\:\:\$bank_account \(Account\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/societe/class/societe.class.php - - message: '#^Property Societe\:\:\$client \(int\) in isset\(\) is not nullable\.$#' identifier: isset.property @@ -15642,12 +15612,6 @@ parameters: count: 1 path: ../../../htdocs/societe/class/societe.class.php - - - message: '#^Property Societe\:\:\$stcomm_id \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/societe/class/societe.class.php - - message: '#^Property Societe\:\:\$typent_id \(int\) in isset\(\) is not nullable\.$#' identifier: isset.property diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 5fc9009f80a..5c4fae945d3 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -545,14 +545,17 @@ class Societe extends CommonObject * @var int Type thirdparty */ public $typent_id = 0; + /** * @var string */ public $typent_code; + /** * @var int */ public $effectif; + /** * @var int */ @@ -722,7 +725,7 @@ class Societe extends CommonObject /** * Status prospect id - * @var int + * @var ?int */ public $stcomm_id; @@ -891,7 +894,7 @@ class Societe extends CommonObject /** - * @var Account|string Default BAN account + * @var null|Account|string Default BAN account */ public $bank_account; @@ -1108,7 +1111,7 @@ class Societe extends CommonObject $ret = $this->update($this->id, $user, 0, 1, 1, 'add'); // update accountancy for this entity - if (!$error && getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { + if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { $this->db->query("DELETE FROM ".MAIN_DB_PREFIX."societe_perentity WHERE fk_soc = ".((int) $this->id)." AND entity = ".((int) $conf->entity)); $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_perentity ("; @@ -1208,19 +1211,19 @@ class Societe extends CommonObject require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; $contact = new Contact($this->db); - $contact->name = $this->name_bis; - $contact->firstname = $this->firstname; - $contact->civility_id = $this->civility_id; - $contact->socid = $this->id; // fk_soc - $contact->statut = 1; // deprecated - $contact->status = 1; - $contact->priv = 0; - $contact->country_id = $this->country_id; - $contact->state_id = $this->state_id; - $contact->address = $this->address; - $contact->email = $this->email; - $contact->zip = $this->zip; - $contact->town = $this->town; + $contact->name = $this->name_bis; + $contact->firstname = $this->firstname; + $contact->civility_id = $this->civility_id; + $contact->socid = $this->id; // fk_soc + $contact->statut = 1; // deprecated + $contact->status = 1; + $contact->priv = 0; + $contact->country_id = $this->country_id; + $contact->state_id = $this->state_id; + $contact->address = $this->address; + $contact->email = $this->email; + $contact->zip = $this->zip; + $contact->town = $this->town; $this->setUpperOrLowerCase(); $contact->phone_pro = $this->phone; if (getDolGlobalString('CONTACTS_DEFAULT_ROLES')) { @@ -1489,13 +1492,13 @@ class Societe extends CommonObject $this->email = trim((string) $this->email); $this->url = $this->url ? clean_url($this->url, 0) : ''; $this->note_private = (empty($this->note_private) ? '' : trim($this->note_private)); - $this->note_public = (empty($this->note_public) ? '' : trim($this->note_public)); - $this->idprof1 = trim((string) $this->idprof1); - $this->idprof2 = trim((string) $this->idprof2); - $this->idprof3 = trim((string) $this->idprof3); - $this->idprof4 = trim((string) $this->idprof4); - $this->idprof5 = (!empty($this->idprof5) ? trim($this->idprof5) : ''); - $this->idprof6 = (!empty($this->idprof6) ? trim($this->idprof6) : ''); + $this->note_public = (empty($this->note_public) ? '' : trim($this->note_public)); + $this->idprof1 = trim((string) $this->idprof1); + $this->idprof2 = trim((string) $this->idprof2); + $this->idprof3 = trim((string) $this->idprof3); + $this->idprof4 = trim((string) $this->idprof4); + $this->idprof5 = (!empty($this->idprof5) ? trim($this->idprof5) : ''); + $this->idprof6 = (!empty($this->idprof6) ? trim($this->idprof6) : ''); $this->prefix_comm = trim((string) $this->prefix_comm); $this->outstanding_limit = price2num($this->outstanding_limit); $this->order_min_amount = price2num($this->order_min_amount); @@ -1769,7 +1772,7 @@ class Societe extends CommonObject $nbrowsaffected = $this->db->affected_rows($resql); - if (!$error && $nbrowsaffected) { + if ($nbrowsaffected) { // Update information on linked member if it is an update if (!$nosyncmember && isModEnabled('member')) { require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; @@ -2415,7 +2418,7 @@ class Societe extends CommonObject $this->db->begin(); // User is mandatory for trigger call - if (!$error && $call_trigger) { + if ($call_trigger) { // Call trigger $result = $this->call_trigger('COMPANY_DELETE', $fuser); if ($result < 0) { @@ -2972,15 +2975,13 @@ class Societe extends CommonObject if ($this->id > 0 && $commid > 0) { $this->db->begin(); - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux"; - $sql .= " WHERE fk_soc = ".((int) $this->id)." AND fk_user = ".((int) $commid); + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux"; + $sql .= " WHERE fk_soc = ".((int) $this->id)." AND fk_user = ".((int) $commid); - $resql = $this->db->query($sql); - if (!$resql) { - dol_syslog(get_class($this)."::add_commercial Error ".$this->db->lasterror()); - $error++; - } + $resql = $this->db->query($sql); + if (!$resql) { + dol_syslog(get_class($this)."::add_commercial Error ".$this->db->lasterror()); + $error++; } if (!$error) { @@ -5084,7 +5085,7 @@ class Societe extends CommonObject */ public function getLibProspCommStatut($mode = 0, $label = '') { - return $this->LibProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto); + return $this->LibProspCommStatut((int) $this->stcomm_id, $mode, $label, $this->stcomm_picto); } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -5652,43 +5653,41 @@ class Societe extends CommonObject { $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']); - $return = '
'; - $return .= '
'; - $return .= ''; + $out = '
'; + $out .= '
'; + $out .= ''; if (!empty($this->logo) && class_exists('Form')) { - $return .= Form::showphoto('societe', $this, 0, 40, 0, 'photokanban', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip. + $out .= Form::showphoto('societe', $this, 0, 40, 0, 'photokanban', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip. } else { - $return .= img_picto('', $this->picto); + $out .= img_picto('', $this->picto); } - $return .= ''; - $return .= '
'; - $return .= '
'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref); - $return .= '
'; + $out .= ''; + $out .= '
'; + $out .= '
' . $this->getNomUrl(1); + $out .= '
'; if (!empty($this->phone)) { - $return .= '
'; + $out .= '
'; // @phan-suppress-next-line PhanPluginSuspiciousParamPosition - $return .= dol_print_phone($this->phone, $this->country_code, 0, $this->id, 'tel', 'hidenum', 'phone', $this->phone, 0, 'paddingleft paddingright'); - $return .= '
'; + $out .= dol_print_phone($this->phone, $this->country_code, 0, $this->id, 'tel', 'hidenum', 'phone', $this->phone, 0, 'paddingleft paddingright'); + $out .= '
'; } if (!empty($this->email)) { - $return .= '
'; - $return .= dol_print_email($this->email, 0, $this->id, 'thirdparty', -1, 1, 2, 'paddingleft paddingright'); - $return .= '
'; + $out .= '
'; + $out .= dol_print_email($this->email, 0, $this->id, 'thirdparty', -1, 1, 2, 'paddingleft paddingright'); + $out .= '
'; } if ($selected >= 0) { - $return .= ''; + $out .= ''; } - if (property_exists($this, 'code_client')) { - $return .= '
'.$this->code_client.''; + if (!empty($this->code_client)) { + $out .= '
'.$this->code_client.''; } - if (method_exists($this, 'getLibStatut')) { - $return .= '
'.$this->getLibStatut(3).'
'; - } - $return .= '
'; // end info-box-content - $return .= '
'; - $return .= '
'; + $out .= '
' . $this->getLibStatut(3) . '
'; + $out .= '
'; // end info-box-content + $out .= '
'; + $out .= '
'; - return $return; + return $out; } /** @@ -5791,7 +5790,7 @@ class Societe extends CommonObject dol_syslog("mergeCompany merge thirdparty id=".$soc_origin_id." (will be deleted) into the thirdparty id=".$this->id); - if (!$error && $soc_origin->fetch($soc_origin_id) < 1) { + if ($soc_origin->fetch($soc_origin_id) < 1) { $this->error = $langs->trans('ErrorRecordNotFound'); $error++; } @@ -5935,7 +5934,7 @@ class Societe extends CommonObject require_once DOL_DOCUMENT_ROOT.$object_file; - if (!$error && !$object_name::replaceThirdparty($this->db, $soc_origin->id, $this->id)) { + if (!$object_name::replaceThirdparty($this->db, $soc_origin->id, $this->id)) { $error++; $this->error = $this->db->lasterror(); break; From 8f7931eb4971669dd34bab805a10ccd98a7c7b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 19 Oct 2025 03:34:09 +0200 Subject: [PATCH 5/9] clean phpstan baseline (#35837) * clean phpstan baseline * clean phpstan baseline --------- Co-authored-by: Laurent Destailleur --- dev/build/phpstan/phpstan-baseline.neon | 32 +++++++++---------- htdocs/cron/card.php | 41 +++++++++++-------------- 2 files changed, 34 insertions(+), 39 deletions(-) diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index 0f9bcb5cb86..fdb05436336 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -8791,28 +8791,28 @@ parameters: path: ../../../htdocs/core/website.inc.php - - message: '#^Loose comparison using \=\= between 1 and 0 will always evaluate to false\.$#' - identifier: equal.alwaysFalse - count: 1 - path: ../../../htdocs/cron/card.php + message: '#^Variable \$conf might not be defined\.$#' + identifier: variable.undefined + count: 3 + path: ../../../htdocs/core/website.inc.php - - message: '#^Negated boolean expression is always false\.$#' - identifier: booleanNot.alwaysFalse + message: '#^Variable \$db might not be defined\.$#' + identifier: variable.undefined + count: 7 + path: ../../../htdocs/core/website.inc.php + + - + message: '#^Variable \$hookmanager might not be defined\.$#' + identifier: variable.undefined count: 2 - path: ../../../htdocs/cron/card.php + path: ../../../htdocs/core/website.inc.php - - message: '#^Result of && is always false\.$#' - identifier: booleanAnd.alwaysFalse + message: '#^Variable \$websitekey might not be defined\.$#' + identifier: variable.undefined count: 2 - path: ../../../htdocs/cron/card.php - - - - message: '#^Right side of && is always true\.$#' - identifier: booleanAnd.rightAlwaysTrue - count: 5 - path: ../../../htdocs/cron/card.php + path: ../../../htdocs/core/website.inc.php - message: '#^Variable \$mc might not be defined\.$#' diff --git a/htdocs/cron/card.php b/htdocs/cron/card.php index 094513580f4..a11bb87c8f4 100644 --- a/htdocs/cron/card.php +++ b/htdocs/cron/card.php @@ -56,14 +56,14 @@ $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); $securitykey = GETPOST('securitykey', 'alpha'); -if (!$user->hasRight('cron', 'create')) { - accessforbidden(); -} - $permissiontoadd = $user->hasRight('cron', 'create'); $permissiontoexecute = $user->hasRight('cron', 'execute'); $permissiontodelete = $user->hasRight('cron', 'delete'); +if (!$permissiontoadd) { + accessforbidden(); +} +// after this test $permissiontoadd is always true and never can't be false /* * Actions @@ -131,7 +131,7 @@ if ($action == 'confirm_execute' && $confirm == "yes" && $permissiontoexecute) { } -if ($action == 'add' && $permissiontoadd) { +if ($action == 'add'/* && $permissiontoadd */) { $object->jobtype = GETPOST('jobtype'); $object->label = GETPOST('label'); $object->command = GETPOST('command'); @@ -167,7 +167,7 @@ if ($action == 'add' && $permissiontoadd) { } // Save parameters -if ($action == 'update' && $permissiontoadd) { +if ($action == 'update'/* && $permissiontoadd */) { $object->id = $id; $object->jobtype = GETPOST('jobtype'); $object->label = GETPOST('label'); @@ -201,7 +201,7 @@ if ($action == 'update' && $permissiontoadd) { } } -if ($action == 'activate' && $permissiontoadd) { +if ($action == 'activate'/* && $permissiontoadd */) { $object->status = 1; // Add cron task @@ -217,7 +217,7 @@ if ($action == 'activate' && $permissiontoadd) { } } -if ($action == 'inactive' && $permissiontoadd) { +if ($action == 'inactive'/* && $permissiontoadd */) { $object->status = 0; $object->processing = 0; @@ -235,7 +235,8 @@ if ($action == 'inactive' && $permissiontoadd) { } // Action clone object -if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) { +if ($action == 'confirm_clone' && $confirm == 'yes'/* && $permissiontoadd */) { + // @phpstan-ignore-next-line if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) { // @phan-suppress-current-line PhanPluginBothLiteralsBinaryOp setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); } else { @@ -799,11 +800,7 @@ if (($action == "create") || ($action == "edit")) { print "\n\n".'
'."\n"; - if (!$user->hasRight('cron', 'create')) { - print ''.$langs->trans("Edit").''; - } else { - print ''.$langs->trans("Edit").''; - } + print ''.$langs->trans("Edit").''; if ((!$user->hasRight('cron', 'execute'))) { print ''.$langs->trans("CronExecute").''; @@ -813,18 +810,16 @@ if (($action == "create") || ($action == "edit")) { print ''.$langs->trans("CronExecute").''; } - if (!$user->hasRight('cron', 'create')) { - print ''.$langs->trans("CronStatusActiveBtn").'/'.$langs->trans("CronStatusInactiveBtn").''; - } else { - print ''.$langs->trans("ToClone").''; - if (empty($object->status)) { - print ''.$langs->trans("CronStatusActiveBtn").''; - } else { - print ''.$langs->trans("CronStatusInactiveBtn").''; - } + print ''.$langs->trans("ToClone").''; + + if (empty($object->status)) { + print ''.$langs->trans("CronStatusActiveBtn").''; + } else { + print ''.$langs->trans("CronStatusInactiveBtn").''; } + if (!$user->hasRight('cron', 'delete')) { print ''.$langs->trans("Delete").''; } else { From 9193aa889a295511e930cf783f6a766703a394be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 19 Oct 2025 03:34:22 +0200 Subject: [PATCH 6/9] clean phpstan baseline (#35839) --- dev/build/phpstan/phpstan-baseline.neon | 12 ------------ htdocs/societe/tpl/linesalesrepresentative.tpl.php | 4 +++- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index fdb05436336..3a4156b5d6b 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -15750,18 +15750,6 @@ parameters: count: 1 path: ../../../htdocs/societe/price.php - - - message: '#^Variable \$db might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../htdocs/societe/tpl/linesalesrepresentative.tpl.php - - - - message: '#^Variable \$object might not be defined\.$#' - identifier: variable.undefined - count: 4 - path: ../../../htdocs/societe/tpl/linesalesrepresentative.tpl.php - - message: '#^Variable \$contextpage in empty\(\) always exists and is not falsy\.$#' identifier: empty.variable diff --git a/htdocs/societe/tpl/linesalesrepresentative.tpl.php b/htdocs/societe/tpl/linesalesrepresentative.tpl.php index 1da3c51d555..7871596ad85 100644 --- a/htdocs/societe/tpl/linesalesrepresentative.tpl.php +++ b/htdocs/societe/tpl/linesalesrepresentative.tpl.php @@ -18,9 +18,11 @@ */ /** * @var Conf $conf + * @var DoliDB $db * @var Form $form * @var Translate $langs * @var User $user + * @var Societe $object * * @var string $action */ @@ -39,7 +41,7 @@ print $langs->trans('SalesRepresentatives'); print ''; if ($action != 'editsalesrepresentatives' && $user->hasRight('societe', 'creer')) { print ''; - print 'id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; + print ' 'editsalesrepresentatives', 'socid' => $object->id], true) . '">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; print ''; } print ''; From 8a84fad171e9cba76e623068c5d6ab3a88c69c95 Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 19 Oct 2025 03:35:04 +0200 Subject: [PATCH 7/9] Qual: Fix misuse of Mo->error (#35841) # Qual: Fix misuse of Mo->error Phan identified that ++ was performed on Mo->error which is a string. This fixes that by using a local $error variable (as in another function). --- dev/tools/phan/baseline.txt | 1 - htdocs/mrp/class/mo.class.php | 31 +++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index 9a5a0557e9f..bbc33c25795 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -194,7 +194,6 @@ return [ 'htdocs/loan/document.php' => ['PhanUndeclaredProperty'], 'htdocs/loan/note.php' => ['PhanUndeclaredProperty'], 'htdocs/loan/payment/payment.php' => ['PhanUndeclaredProperty'], - 'htdocs/mrp/class/mo.class.php' => ['PhanTypeMismatchProperty'], 'htdocs/mrp/tpl/linkedobjectblock.tpl.php' => ['PhanUndeclaredProperty'], 'htdocs/multicurrency/class/api_multicurrencies.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/multicurrency/class/multicurrency.class.php' => ['PhanTypeExpectedObjectPropAccess'], diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index 057edb279d0..bb775265cbb 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -795,14 +795,14 @@ class Mo extends CommonObject /** - * Recurse through BOM only adding products to list to consume/produce - * - * @param User $user User that modifies - * @param string $role MoLine Role that products are added as - * @param BOM $bom BOM to parse lines from - * @param float $quantity Quantity modifier for sub products/BOM - * @return int Return integer <0 if KO, >0 if OK - */ + * Recurse through BOM only adding products to list to consume/produce + * + * @param User $user User that modifies + * @param string $role MoLine Role that products are added as + * @param BOM $bom BOM to parse lines from + * @param float $quantity Quantity modifier for sub products/BOM + * @return int Return integer <0 if KO, >0 if OK + */ public function processBOM(User $user, $role, $bom, $quantity) { $error = 0; @@ -850,7 +850,9 @@ class Mo extends CommonObject } } } - if ($error) break; + if ($error) { + break; + } } return $error; } @@ -968,6 +970,7 @@ class Mo extends CommonObject $arrayoflines = $this->fetchLinesLinked('consumed', $idline); // Get lines consumed under the one to delete $result = 0; + $error = 0; $this->db->begin(); @@ -997,7 +1000,7 @@ class Mo extends CommonObject $idstockmove = $stockmove->livraison($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $movement->batch, 0, $codemovementCancel); } if ($idstockmove < 0) { - $this->error++; + $error++; setEventMessages($stockmove->error, $stockmove->errors, 'errors'); } else { $result = $moline->delete($user, $notrigger); @@ -1020,7 +1023,7 @@ class Mo extends CommonObject $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel); } if ($idstockmove < 0) { - $this->error++; + $error++; setEventMessages($stockmove->error, $stockmove->errors, 'errors'); } else { $moline = new MoLine($this->db); @@ -1028,13 +1031,13 @@ class Mo extends CommonObject $resdel = $moline->delete($user, $notrigger); if ($resdel < 0) { - $this->error++; + $error++; setEventMessages($moline->error, $moline->errors, 'errors'); } } } - if (empty($this->error)) { + if ($error == 0) { $result = $this->deleteLineCommon($user, $idline, $notrigger); } } @@ -1043,7 +1046,7 @@ class Mo extends CommonObject $result = $this->deleteLineCommon($user, $idline, $notrigger); } - if (!empty($this->error) || $result <= 0) { + if ($error != 0 || $result <= 0) { $this->db->rollback(); } else { $this->db->commit(); From db4d73ed50507be378fd10a8f72aa32aab7c177c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 19 Oct 2025 03:35:21 +0200 Subject: [PATCH 8/9] clean baseline phpstan (#35840) --- htdocs/takepos/css/pos.css.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/takepos/css/pos.css.php b/htdocs/takepos/css/pos.css.php index 4ad53abfb55..ea0b48835aa 100644 --- a/htdocs/takepos/css/pos.css.php +++ b/htdocs/takepos/css/pos.css.php @@ -52,6 +52,9 @@ define('ISLOADEDBYSTEELSHEET', '1'); session_cache_limiter('public'); require_once __DIR__.'/../../main.inc.php'; // __DIR__ allow this script to be included in custom themes +/** + * @var Conf $conf + */ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; // Define css type From 1e329f2325d61ec619ddcc04c9314d1bee5e4e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 19 Oct 2025 17:09:54 +0200 Subject: [PATCH 9/9] clean code (#35843) * clean code * clean code * clean code * clean code * clean code * clean code * clean code * clean code * clean code * clean code --- dev/build/phpstan/phpstan-baseline.neon | 36 ----- htdocs/adherents/list.php | 145 ++++++++++-------- .../tpl/extrafields_list_search_param.tpl.php | 38 ++++- htdocs/cron/list.php | 24 +-- 4 files changed, 128 insertions(+), 115 deletions(-) diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index 3a4156b5d6b..80b94b047d1 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -8790,30 +8790,6 @@ parameters: count: 1 path: ../../../htdocs/core/website.inc.php - - - message: '#^Variable \$conf might not be defined\.$#' - identifier: variable.undefined - count: 3 - path: ../../../htdocs/core/website.inc.php - - - - message: '#^Variable \$db might not be defined\.$#' - identifier: variable.undefined - count: 7 - path: ../../../htdocs/core/website.inc.php - - - - message: '#^Variable \$hookmanager might not be defined\.$#' - identifier: variable.undefined - count: 2 - path: ../../../htdocs/core/website.inc.php - - - - message: '#^Variable \$websitekey might not be defined\.$#' - identifier: variable.undefined - count: 2 - path: ../../../htdocs/core/website.inc.php - - message: '#^Variable \$mc might not be defined\.$#' identifier: variable.undefined @@ -8832,12 +8808,6 @@ parameters: count: 1 path: ../../../htdocs/cron/class/cronjob.class.php - - - message: '#^Ternary operator condition is always true\.$#' - identifier: ternary.alwaysTrue - count: 10 - path: ../../../htdocs/cron/list.php - - message: '#^Variable \$contextpage in empty\(\) always exists and is not falsy\.$#' identifier: empty.variable @@ -15984,12 +15954,6 @@ parameters: count: 5 path: ../../../htdocs/takepos/ajax/ajax.php - - - message: '#^Variable \$conf might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../htdocs/takepos/css/pos.css.php - - message: '#^Right side of && is always true\.$#' identifier: booleanAnd.rightAlwaysTrue diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index eea353f37c0..13d2e42d872 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -50,51 +50,50 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; // Load translation files required by the page $langs->loadLangs(array("members", "companies", "categories")); - // Get parameters -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'aZ09'); $massaction = GETPOST('massaction', 'alpha'); $show_files = GETPOSTINT('show_files'); -$confirm = GETPOST('confirm', 'alpha'); -$cancel = GETPOST('cancel', 'alpha'); -$toselect = GETPOST('toselect', 'array:int'); +$confirm = GETPOST('confirm', 'alpha'); +$cancel = GETPOST('cancel', 'alpha'); +$toselect = GETPOST('toselect', 'array:int'); $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'memberslist'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); -$optioncss = GETPOST('optioncss', 'aZ'); -$mode = GETPOST('mode', 'alpha'); +$optioncss = GETPOST('optioncss', 'aZ'); +$mode = GETPOST('mode', 'alpha'); $groupby = GETPOST('groupby', 'aZ09'); // Example: $groupby = 'p.fk_opp_status' or $groupby = 'p.fk_statut' // Search fields -$search = GETPOST("search", 'alpha'); +$search = GETPOST("search", 'alpha'); $search_id = GETPOST('search_id', 'int'); -$search_ref = GETPOST("search_ref", 'alpha'); -$search_lastname = GETPOST("search_lastname", 'alpha'); -$search_firstname = GETPOST("search_firstname", 'alpha'); -$search_gender = GETPOST("search_gender", 'alpha'); -$search_civility = GETPOST("search_civility", 'alpha'); -$search_company = GETPOST('search_company', 'alphanohtml'); -$search_login = GETPOST("search_login", 'alpha'); -$search_address = GETPOST("search_address", 'alpha'); -$search_zip = GETPOST("search_zip", 'alpha'); -$search_town = GETPOST("search_town", 'alpha'); -$search_state = GETPOST("search_state", 'alpha'); // county / departement / federal state -$search_country = GETPOST("search_country", 'alpha'); -$search_phone = GETPOST("search_phone", 'alpha'); +$search_ref = GETPOST("search_ref", 'alpha'); +$search_lastname = GETPOST("search_lastname", 'alpha'); +$search_firstname = GETPOST("search_firstname", 'alpha'); +$search_gender = GETPOST("search_gender", 'alpha'); +$search_civility = GETPOST("search_civility", 'alpha'); +$search_company = GETPOST('search_company', 'alphanohtml'); +$search_login = GETPOST("search_login", 'alpha'); +$search_address = GETPOST("search_address", 'alpha'); +$search_zip = GETPOST("search_zip", 'alpha'); +$search_town = GETPOST("search_town", 'alpha'); +$search_state = GETPOST("search_state", 'alpha'); // county / departement / federal state +$search_country = GETPOST("search_country", 'alpha'); +$search_phone = GETPOST("search_phone", 'alpha'); $search_phone_perso = GETPOST("search_phone_perso", 'alpha'); $search_phone_mobile = GETPOST("search_phone_mobile", 'alpha'); -$search_type = GETPOST("search_type", 'alpha'); -$search_email = GETPOST("search_email", 'alpha'); -$search_categ = GETPOST("search_categ", 'intcomma'); -$search_morphy = GETPOST("search_morphy", 'alpha'); -$search_import_key = trim(GETPOST("search_import_key", 'alpha')); +$search_type = GETPOST("search_type", 'alpha'); +$search_email = GETPOST("search_email", 'alpha'); +$search_categ = GETPOST("search_categ", 'intcomma'); +$search_morphy = GETPOST("search_morphy", 'alpha'); +$search_import_key = trim(GETPOST("search_import_key", 'alpha')); $socid = GETPOSTINT('socid'); if (GETPOSTINT('catid') && empty($search_categ)) { $search_categ = GETPOSTINT('catid'); } -$search_filter = GETPOST("search_filter", 'alpha'); -$search_status = GETPOST("search_status", 'intcomma'); // status +$search_filter = GETPOST("search_filter", 'alpha'); +$search_status = GETPOST("search_status", 'intcomma'); // status $search_datec_start = dol_mktime(0, 0, 0, GETPOSTINT('search_datec_start_month'), GETPOSTINT('search_datec_start_day'), GETPOSTINT('search_datec_start_year')); $search_datec_end = dol_mktime(23, 59, 59, GETPOSTINT('search_datec_end_month'), GETPOSTINT('search_datec_end_day'), GETPOSTINT('search_datec_end_year')); $search_datem_start = dol_mktime(0, 0, 0, GETPOSTINT('search_datem_start_month'), GETPOSTINT('search_datem_start_day'), GETPOSTINT('search_datem_start_year')); @@ -645,98 +644,116 @@ if ($search_type > 0) { } // $parameters -$param = ''; +$query = []; if (!empty($mode)) { - $param .= '&mode='.urlencode($mode); + $query += ['mode' => $mode]; } if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { - $param .= '&contextpage='.urlencode($contextpage); + $query += ['contextpage' => $contextpage]; } if ($limit > 0 && $limit != $conf->liste_limit) { - $param .= '&limit='.((int) $limit); + $query += ['limit' => $limit]; } if ($optioncss != '') { - $param .= '&optioncss='.urlencode($optioncss); + $query += ['optioncss' => $optioncss]; } if ($groupby != '') { - $param .= '&groupby='.urlencode($groupby); + $query += ['groupby' => $groupby]; } if ($search_all != "") { - $param .= "&search_all=".urlencode($search_all); + $query += ['search_all' => $search_all]; } if ($search_ref) { - $param .= "&search_ref=".urlencode($search_ref); + $query += ['search_ref' => $search_ref]; } if ($search_civility) { - $param .= "&search_civility=".urlencode($search_civility); + $query += ['search_civility' => $search_civility]; } if ($search_firstname) { - $param .= "&search_firstname=".urlencode($search_firstname); + $query += ['search_firstname' => $search_firstname]; } if ($search_lastname) { - $param .= "&search_lastname=".urlencode($search_lastname); + $query += ['search_lastname' => $search_lastname]; } if ($search_gender) { - $param .= "&search_gender=".urlencode($search_gender); + $query += ['search_gender' => $search_gender]; +} +if ($search_morphy != '' && $search_morphy != '-1') { + $query += ['search_morphy' => $search_morphy]; } if ($search_login) { - $param .= "&search_login=".urlencode($search_login); + $query += ['search_login' => $search_login]; } if ($search_email) { - $param .= "&search_email=".urlencode($search_email); + $query += ['search_email' => $search_email]; } if ($search_categ > 0 || $search_categ == -2) { - $param .= "&search_categ=".urlencode((string) ($search_categ)); + $query += ['search_categ' => $search_categ]; } if ($search_company) { - $param .= "&search_company=".urlencode($search_company); + $query += ['search_company' => $search_company]; } if ($search_address != '') { - $param .= "&search_address=".urlencode($search_address); + $query += ['search_address' => $search_address]; } if ($search_town != '') { - $param .= "&search_town=".urlencode($search_town); + $query += ['search_town' => $search_town]; } if ($search_zip != '') { - $param .= "&search_zip=".urlencode($search_zip); + $query += ['search_zip' => $search_zip]; } if ($search_state != '') { - $param .= "&search_state=".urlencode($search_state); + $query += ['search_state' => $search_state]; } if ($search_country != '') { - $param .= "&search_country=".urlencode($search_country); + $query += ['search_country' => $search_country]; } if ($search_phone != '') { - $param .= "&search_phone=".urlencode($search_phone); + $query += ['search_phone' => $search_phone]; } if ($search_phone_perso != '') { - $param .= "&search_phone_perso=".urlencode($search_phone_perso); + $query += ['search_phone_perso' => $search_phone_perso]; } if ($search_phone_mobile != '') { - $param .= "&search_phone_mobile=".urlencode($search_phone_mobile); + $query += ['search_phone_mobile' => $search_phone_mobile]; } if ($search_filter && $search_filter != '-1') { - $param .= "&search_filter=".urlencode($search_filter); + $query += ['search_filter' => $search_filter]; } if ($search_status != "" && $search_status != -3) { - $param .= "&search_status=".urlencode($search_status); + $query += ['search_status' => $search_status]; } if ($search_import_key != '') { - $param .= '&search_import_key='.urlencode($search_import_key); + $query += ['search_import_key' => $search_import_key]; } if ($search_type > 0) { - $param .= "&search_type=".urlencode($search_type); + $query += ['search_type' => $search_type]; } if ($search_datec_start) { - $param .= '&search_datec_start_day='.dol_print_date($search_datec_start, '%d').'&search_datec_start_month='.dol_print_date($search_datec_start, '%m').'&search_datec_start_year='.dol_print_date($search_datec_start, '%Y'); + $query += [ + 'search_datec_start_day' => dol_print_date($search_datec_start, '%d'), + 'search_datec_start_month' => dol_print_date($search_datec_start, '%m'), + 'search_datec_start_year' => dol_print_date($search_datec_start, '%Y'), + ]; } if ($search_datem_end) { - $param .= '&search_datem_end_day='.dol_print_date($search_datem_end, '%d').'&search_datem_end_month='.dol_print_date($search_datem_end, '%m').'&search_datem_end_year='.dol_print_date($search_datem_end, '%Y'); + $query += [ + 'search_datem_end_day' => dol_print_date($search_datem_end, '%d'), + 'search_datem_end_month' => dol_print_date($search_datem_end, '%m'), + 'search_datem_end_year' => dol_print_date($search_datem_end, '%Y'), + ]; } -// Add $param from extra fields +// Add $query from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; +// Add $query from hooks +$parameters = array('query' => &$query); +$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + +// build $param +$param = http_build_query($query); + // List of mass actions available $arrayofmassactions = array( //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), @@ -776,12 +793,14 @@ print ''; print ''; print ''; - $newcardbutton = ''; -$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition')); -$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition')); +$queryforbutton = $query; +$queryforbutton['mode'] = 'common'; +$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', dolBuildUrl($_SERVER["PHP_SELF"], $queryforbutton), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition')); +$queryforbutton['mode'] = 'kanban'; +$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', dolBuildUrl($_SERVER["PHP_SELF"], $queryforbutton), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition')); $newcardbutton .= dolGetButtonTitleSeparator(); -$newcardbutton .= dolGetButtonTitle($langs->trans('NewMember'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/adherents/card.php?action=create', '', $user->hasRight('adherent', 'creer')); +$newcardbutton .= dolGetButtonTitle($langs->trans('NewMember'), '', 'fa fa-plus-circle', dolBuildUrl(DOL_URL_ROOT.'/adherents/card.php', ['action' => 'create']), '', $user->hasRight('adherent', 'creer')); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1); diff --git a/htdocs/core/tpl/extrafields_list_search_param.tpl.php b/htdocs/core/tpl/extrafields_list_search_param.tpl.php index 94a67d6102a..4aa69e2c46c 100644 --- a/htdocs/core/tpl/extrafields_list_search_param.tpl.php +++ b/htdocs/core/tpl/extrafields_list_search_param.tpl.php @@ -26,17 +26,28 @@ * @var CommonObject $object * @var ExtraFields $extrafields * - * @var array $search_array_options - * @var string $search_options_pattern - * @var string $param - * @var string $extrafieldsobjectkey + * @var array $search_array_options + * @var string $search_options_pattern + * @var null|string $param + * @var null|array{string:mixed} $query + * @var string $extrafieldsobjectkey */ +' +@phan-var-force null|array{string:mixed} $query +'; + // Protection to avoid direct call of template if (empty($conf) || !is_object($conf)) { print "Error, template page can't be called as URL"; exit(1); } +if (!isset($query)) { + $query = []; +} +if (!isset($param)) { + $param = ''; +} // Loop to complete $param for extrafields if (!empty($search_array_options) && is_array($search_array_options)) { // $extrafieldsobject is the $object->table_element like 'societe', 'socpeople', ... @@ -46,7 +57,6 @@ if (!empty($search_array_options) && is_array($search_array_options)) { // $extr if (empty($extrafieldsobjectkey) && is_object($object)) { $extrafieldsobjectkey = $object->table_element; } - foreach ($search_array_options as $key => $val) { $tmpkey = preg_replace('/'.$search_options_pattern.'/', '', $key); // date range from list filters is stored as array('start' => , 'end' => ) @@ -57,6 +67,13 @@ if (!empty($search_array_options) && is_array($search_array_options)) { // $extr $param .= '&'.$search_options_pattern.$tmpkey.'_startday='.dol_print_date($val['start'], '%d'); $param .= '&'.$search_options_pattern.$tmpkey.'_starthour='.dol_print_date($val['start'], '%H'); $param .= '&'.$search_options_pattern.$tmpkey.'_startmin='.dol_print_date($val['start'], '%M'); + $query += [ + $search_options_pattern.$tmpkey.'_startyear' => dol_print_date($val['start'], '%Y'), + $search_options_pattern.$tmpkey.'_startmonth' => dol_print_date($val['start'], '%m'), + $search_options_pattern.$tmpkey.'_startday' => dol_print_date($val['start'], '%d'), + $search_options_pattern.$tmpkey.'_starthour' => dol_print_date($val['start'], '%H'), + $search_options_pattern.$tmpkey.'_startmin' => dol_print_date($val['start'], '%M'), + ]; } elseif (is_array($val) && array_key_exists('end', $val)) { // end date $param .= '&'.$search_options_pattern.$tmpkey.'_endyear='.dol_print_date($val['end'], '%Y'); @@ -64,24 +81,35 @@ if (!empty($search_array_options) && is_array($search_array_options)) { // $extr $param .= '&'.$search_options_pattern.$tmpkey.'_endday='.dol_print_date($val['end'], '%d'); $param .= '&'.$search_options_pattern.$tmpkey.'_endhour='.dol_print_date($val['end'], '%H'); $param .= '&'.$search_options_pattern.$tmpkey.'_endmin='.dol_print_date($val['end'], '%M'); + $query += [ + $search_options_pattern.$tmpkey.'_endyear' => dol_print_date($val['end'], '%Y'), + $search_options_pattern.$tmpkey.'_endmonth' => dol_print_date($val['end'], '%m'), + $search_options_pattern.$tmpkey.'_endday'=> dol_print_date($val['end'], '%d'), + $search_options_pattern.$tmpkey.'_endhour'=> dol_print_date($val['end'], '%H'), + $search_options_pattern.$tmpkey.'_endmin'=> dol_print_date($val['end'], '%M'), + ]; $val = ''; } elseif ($val !== '' && $val !== null && $val !== []) { if (is_array($val)) { foreach ($val as $val2) { $param .= '&'.$search_options_pattern.$tmpkey.'[]='.urlencode($val2); + $query += [$search_options_pattern.$tmpkey.'[]' => $val2]; } } else { // test if we have checkbox type, we add the _multiselect needed into param $tmpkey = preg_replace('/'.$search_options_pattern.'/', '', $key); if (in_array($extrafields->attributes[$extrafieldsobjectkey]['type'][$tmpkey], array('checkbox', 'chkbxlst'))) { $param .= '&'.$search_options_pattern.$tmpkey.'_multiselect='.urlencode($val); + $query += [$search_options_pattern.$tmpkey.'_multiselect' => $val]; } // test if we have boolean type, we add the _booleand needed into param if (in_array($extrafields->attributes[$extrafieldsobjectkey]['type'][$tmpkey], array('boolean'))) { $param .= '&'.$search_options_pattern.$tmpkey.'_boolean='.urlencode($val); + $query += [$search_options_pattern.$tmpkey.'_boolean' => $val]; } $param .= '&'.$search_options_pattern.$tmpkey.'='.urlencode($val); + $query += [$search_options_pattern.$tmpkey => $val]; } } } diff --git a/htdocs/cron/list.php b/htdocs/cron/list.php index 24093fadb07..09388f48b49 100644 --- a/htdocs/cron/list.php +++ b/htdocs/cron/list.php @@ -136,16 +136,18 @@ foreach ($object->fields as $key => $val) { $object->fields = dol_sort_array($object->fields, 'position'); $arrayfields = dol_sort_array($arrayfields, 'position'); -// Security -if (!$user->hasRight('cron', 'read')) { - accessforbidden(); -} $permissiontoread = $user->hasRight('cron', 'read'); $permissiontoadd = $user->hasRight('cron', 'create') ? $user->hasRight('cron', 'create') : $user->hasRight('cron', 'write'); $permissiontodelete = $user->hasRight('cron', 'delete'); $permissiontoexecute = $user->hasRight('cron', 'execute'); +// Security +if (!$permissiontoread) { + accessforbidden(); +} +// after this test $permissiontoread is always true and never can't be false + $error = 0; //var_dump($arrayfields); @@ -251,7 +253,7 @@ if (empty($reshook)) { // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; - header("Location: ".DOL_URL_ROOT.'/cron/list.php?'.$param.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '')); // Make a redirect to avoid to run twice the job when using back + header("Location: ".DOL_URL_ROOT.'/cron/list.php?'.$param.'&sortfield='.$sortfield.'&sortorder='.$sortorder); // Make a redirect to avoid to run twice the job when using back exit; } } @@ -867,13 +869,13 @@ if ($num > 0) { // Action print ''; - $backtopage = urlencode($_SERVER["PHP_SELF"].'?'.$param.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '')); + $backtopage = urlencode($_SERVER["PHP_SELF"].'?'.$param.'&sortfield='.$sortfield.'&sortorder='.$sortorder); if ($user->hasRight('cron', 'create')) { - print 'trans('Edit'))."\">".img_picto($langs->trans('Edit'), 'edit')."  "; } if ($user->hasRight('cron', 'delete')) { - print ''.img_picto($langs->trans('CronDelete'), 'delete', '', 0, 0, 0, '', 'marginleftonly').'   '; } else { print ''.img_picto($langs->trans('NotEnoughPermissions'), 'delete', '', 0, 0, 0, '', 'marginleftonly').'   '; @@ -881,9 +883,9 @@ if ($num > 0) { if ($user->hasRight('cron', 'execute')) { if (!empty($obj->status)) { print '".img_picto($langs->trans('CronExecute'), "play", '', 0, 0, 0, '', 'marginleftonly').''; } else { print ''.img_picto($langs->trans('JobDisabled'), "playdisabled", '', 0, 0, 0, '', 'marginleftonly').'';