From b51b38ef643241bd76472a516be8cb0185193a5d Mon Sep 17 00:00:00 2001 From: MDW Date: Mon, 20 Jul 2026 02:51:42 +0200 Subject: [PATCH] Qual: Fix 'SqlInjection' notices (#39223) # Qual: Fix 'SqlInjection' notices Batch of 25 files with changes to fix 'SqlInjection' Notices --- .../class/accountancycategory.class.php | 22 ++++++++--------- .../class/accountingjournal.class.php | 2 +- .../accountancy/journal/treasuryjournal.php | 6 ++--- htdocs/adherents/class/subscription.class.php | 2 +- htdocs/admin/barcode.php | 8 +++---- htdocs/ai/tools/reports.class.php | 18 +++++++------- htdocs/bookmarks/class/bookmark.class.php | 9 +++---- htdocs/hrm/class/evaluation.class.php | 4 ++-- htdocs/hrm/class/job.class.php | 4 ++-- htdocs/hrm/class/skilldet.class.php | 4 ++-- .../class/opensurveysondage.class.php | 2 +- .../product/actions_card_product.class.php | 2 +- htdocs/product/class/productbatch.class.php | 12 +++++----- htdocs/projet/class/projectstats.class.php | 2 +- .../class/receptionlinebatch.class.php | 24 +++++++++---------- htdocs/reception/stats/index.php | 2 +- .../class/recruitmentcandidature.class.php | 4 ++-- htdocs/resource/class/dolresource.class.php | 10 ++++---- htdocs/salaries/class/salariesstats.class.php | 2 +- htdocs/user/class/usergroup.class.php | 8 +++---- htdocs/user/group/list.php | 4 ++-- htdocs/user/hierarchy.php | 12 +++++----- htdocs/user/home.php | 3 ++- .../variants/class/ProductAttribute.class.php | 8 +++---- .../webservices/server_productorservice.php | 2 +- 25 files changed, 89 insertions(+), 87 deletions(-) diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php index 1e5048ca286..30c33394ec5 100644 --- a/htdocs/accountancy/class/accountancycategory.class.php +++ b/htdocs/accountancy/class/accountancycategory.class.php @@ -444,7 +444,7 @@ class AccountancyCategory // extends CommonObject $sql .= " FROM ".$this->db->prefix()."accounting_account as t"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON t.fk_pcg_version = asy.pcg_version AND asy.rowid = ".((int) $pcgver); $sql .= " WHERE t.fk_accounting_category = ".((int) $id); - $sql .= " AND t.entity = ".$conf->entity; + $sql .= " AND t.entity = ".((int) $conf->entity); $this->lines_display = array(); @@ -483,7 +483,7 @@ class AccountancyCategory // extends CommonObject $sql .= " WHERE (aa.fk_accounting_category <> ".((int) $id)." OR aa.fk_accounting_category IS NULL)"; $sql .= " AND asy.rowid = ".((int) getDolGlobalInt('CHARTOFACCOUNTS')); $sql .= " AND aa.active = 1"; - $sql .= " AND aa.entity = ".$conf->entity; + $sql .= " AND aa.entity = ".((int) $conf->entity); $sql .= " GROUP BY aa.account_number, aa.label"; $sql .= " ORDER BY aa.account_number, aa.label"; @@ -529,7 +529,7 @@ class AccountancyCategory // extends CommonObject $sql .= " INNER JOIN ".$this->db->prefix()."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = ".((int) getDolGlobalInt('CHARTOFACCOUNTS')); $sql .= " AND aa.active = 1"; - $sql .= " AND aa.entity = ".$conf->entity; + $sql .= " AND aa.entity = ".((int) $conf->entity); $sql .= " ORDER BY LENGTH(aa.account_number) DESC;"; // LENGTH is ok with mysql and postgresql $this->db->begin(); @@ -734,10 +734,10 @@ class AccountancyCategory // extends CommonObject $sql .= " WHERE t.fk_accounting_category IN (SELECT c.rowid"; $sql .= " FROM ".$this->db->prefix().$this->table_element." as c"; $sql .= " WHERE c.active = 1"; - $sql .= " AND c.entity = ".$conf->entity; + $sql .= " AND c.entity = ".((int) $conf->entity); $sql .= " AND (c.fk_country = ".((int) $mysoc->country_id)." OR c.fk_country = 0)"; $sql .= " AND cat.rowid = t.fk_accounting_category"; - $sql .= " AND t.entity = ".$conf->entity; + $sql .= " AND t.entity = ".((int) $conf->entity); if ($catid > 0) { $sql .= " AND cat.rowid = ".((int) $catid); } @@ -796,7 +796,7 @@ class AccountancyCategory // extends CommonObject $sql .= " FROM ".$this->db->prefix().$this->table_element." as c"; $sql .= " WHERE c.active = " . (int) $active; $sql .= " AND c.fk_report=".((int) $id_report); - $sql .= " AND c.entity = ".$conf->entity; + $sql .= " AND c.entity = ".((int) $conf->entity); if ($categorytype >= 0) { $sql .= " AND c.category_type = 1"; } @@ -868,7 +868,7 @@ class AccountancyCategory // extends CommonObject $sql = "SELECT t.rowid, t.account_number, t.label as account_label"; $sql .= " FROM ".$this->db->prefix()."accounting_account as t"; $sql .= " WHERE t.fk_accounting_category = ".((int) $cat_id); - $sql .= " AND t.entity = ".$conf->entity; + $sql .= " AND t.entity = ".((int) $conf->entity); $sql .= " AND t.active = 1"; $sql .= " AND t.fk_pcg_version = '".$this->db->escape($pcgvercode)."'"; $sql .= " ORDER BY t.account_number"; @@ -876,7 +876,7 @@ class AccountancyCategory // extends CommonObject $sql = "SELECT t.rowid, t.account_number, t.label as account_label"; $sql .= " FROM ".$this->db->prefix()."accounting_account as t"; $sql .= " WHERE ".$sanitizedpredefinedgroupwhere; - $sql .= " AND t.entity = ".$conf->entity; + $sql .= " AND t.entity = ".((int) $conf->entity); $sql .= ' AND t.active = 1'; $sql .= " AND t.fk_pcg_version = '".$this->db->escape($pcgvercode)."'"; $sql .= " ORDER BY t.account_number"; @@ -989,7 +989,7 @@ class AccountancyCategory // extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."accounting_category_account as aca"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = aca.fk_accounting_account"; $sql .= " WHERE aca.fk_accounting_category = ".((int) $this->id); - $sql .= " AND aa.entity = ".$conf->entity; + $sql .= " AND aa.entity = ".((int) $conf->entity); $sql .= " ORDER BY aa.account_number ASC"; dol_syslog(get_class($this)."::getAccountsForCategory", LOG_DEBUG); @@ -1033,7 +1033,7 @@ class AccountancyCategory // extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."accounting_category_account as aca"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."c_accounting_category as ac ON ac.rowid = aca.fk_accounting_category"; $sql .= " WHERE aca.fk_accounting_account = ".((int) $fkAccountingAccount); - $sql .= " AND ac.entity = ".$conf->entity; + $sql .= " AND ac.entity = ".((int) $conf->entity); $sql .= " ORDER BY ac.position ASC"; dol_syslog(get_class($this)."::getCategoriesForAccount", LOG_DEBUG); @@ -1109,7 +1109,7 @@ class AccountancyCategory // extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."accounting_category_account"; $sql .= " WHERE fk_accounting_category = ".((int) $this->id); $sql .= " )"; - $sql .= " AND aa.entity = ".$conf->entity; + $sql .= " AND aa.entity = ".((int) $conf->entity); $sql .= " AND aa.active = 1"; $sql .= " AND aa.fk_pcg_version = '".$this->db->escape($pcgvercode)."'"; $sql .= " ORDER BY aa.account_number ASC"; diff --git a/htdocs/accountancy/class/accountingjournal.class.php b/htdocs/accountancy/class/accountingjournal.class.php index 22cd31bf0a7..25aeae90dd2 100644 --- a/htdocs/accountancy/class/accountingjournal.class.php +++ b/htdocs/accountancy/class/accountingjournal.class.php @@ -169,7 +169,7 @@ class AccountingJournal extends CommonObject $sql .= " rowid = ".((int) $rowid); } elseif ($journal_code) { $sql .= " code = '".$this->db->escape($journal_code)."'"; - $sql .= " AND entity = ".$conf->entity; + $sql .= " AND entity = ".((int) $conf->entity); } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); diff --git a/htdocs/accountancy/journal/treasuryjournal.php b/htdocs/accountancy/journal/treasuryjournal.php index dbef0b6fca4..232ab2960ce 100644 --- a/htdocs/accountancy/journal/treasuryjournal.php +++ b/htdocs/accountancy/journal/treasuryjournal.php @@ -626,7 +626,7 @@ if ($resql) { } else { $sql .= " LEFT JOIN ".$db->prefix()."accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=cs.rowid"; } - $sql .= " WHERE cs.entity = ".$conf->entity; // We don't share object for accountancy, we use source object sharing + $sql .= " WHERE cs.entity = ".((int) $conf->entity); // We don't share object for accountancy, we use source object sharing // Not already in bookkeeping if ($in_bookkeeping == 'notyet') { $sql .= " AND ab.rowid IS NULL"; @@ -694,7 +694,7 @@ if ($resql) { $sql .= " LEFT JOIN ".$db->prefix()."accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=t.rowid"; } $sql .= " WHERE bu.fk_bank IN (".$db->sanitize(implode(',', $ids)).")"; - // $sql .= " AND t.entity = " . $conf->entity; // TODO when entity is managed in tva + // $sql .= " AND t.entity = " . ((int) $conf->entity); // TODO when entity is managed in tva // Not already in bookkeeping if ($in_bookkeeping == 'notyet') { $sql .= " AND ab.rowid IS NULL"; @@ -827,7 +827,7 @@ if ($resql) { } else { $sql .= " LEFT JOIN ".$db->prefix()."accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=l.rowid"; } - $sql .= " WHERE l.entity = ".$conf->entity; // We don't share object for accountancy, we use source object sharing + $sql .= " WHERE l.entity = ".((int) $conf->entity); // We don't share object for accountancy, we use source object sharing // Not already in bookkeeping if ($in_bookkeeping == 'notyet') { $sql .= " AND ab.rowid IS NULL"; diff --git a/htdocs/adherents/class/subscription.class.php b/htdocs/adherents/class/subscription.class.php index 9d6485c3921..75a7a63abb5 100644 --- a/htdocs/adherents/class/subscription.class.php +++ b/htdocs/adherents/class/subscription.class.php @@ -206,7 +206,7 @@ class Subscription extends CommonObject $sql .= " '".$this->db->escape($this->note_public ? $this->note_public : $this->note)."',"; $sql .= " '".$this->db->escape($this->note_private)."',"; $sql .= " ".(empty($this->ref_ext) ? "null" : "'".$this->db->escape($this->ref_ext)."'").","; - $sql .= " ".((int) ($this->user_creation_id > 0 ? $this->user_creation_id : $user->id)); + $sql .= " ".((int) ($this->user_creation_id > 0 ? $this->user_creation_id : ((int) $user->id))); $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null"); $sql .= ")"; diff --git a/htdocs/admin/barcode.php b/htdocs/admin/barcode.php index 0845e3901b6..c836c2f3a83 100644 --- a/htdocs/admin/barcode.php +++ b/htdocs/admin/barcode.php @@ -84,7 +84,7 @@ if ($action == 'setcoder') { $sqlp = "UPDATE ".MAIN_DB_PREFIX."c_barcode_type"; $sqlp .= " SET coder = '".$db->escape($coder)."'"; $sqlp .= " WHERE rowid = ".((int) $code_id); - $sqlp .= " AND entity = ".$conf->entity; + $sqlp .= " AND entity = ".((int) $conf->entity); $resql = $db->query($sqlp); if (!$resql) { @@ -106,7 +106,7 @@ if ($action == 'setcoder') { } elseif ($action == 'updateengine') { $sql = "SELECT rowid, coder"; $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; - $sql .= " WHERE entity = ".$conf->entity; + $sql .= " WHERE entity = ".((int) $conf->entity); $sql .= " ORDER BY code"; $resql = $db->query($sql); @@ -124,7 +124,7 @@ if ($action == 'setcoder') { $sqlp = "UPDATE ".MAIN_DB_PREFIX."c_barcode_type"; $sqlp .= " SET coder = '".$db->escape($coder)."'"; $sqlp .= " WHERE rowid = ".((int) $code_id); - $sqlp .= " AND entity = ".$conf->entity; + $sqlp .= " AND entity = ".((int) $conf->entity); $upsql = $db->query($sqlp); if (!$upsql) { @@ -413,7 +413,7 @@ if (getDolGlobalString('BARCODE_USE_ON_PRODUCT') || getDolGlobalString('BARCODE_ $sql = "SELECT rowid, code as encoding, libelle as label, coder, example"; $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; - $sql .= " WHERE entity = ".$conf->entity; + $sql .= " WHERE entity = ".((int) $conf->entity); $sql .= " ORDER BY code"; dol_syslog("admin/barcode.php", LOG_DEBUG); diff --git a/htdocs/ai/tools/reports.class.php b/htdocs/ai/tools/reports.class.php index 6510c86cabb..75e93e44436 100644 --- a/htdocs/ai/tools/reports.class.php +++ b/htdocs/ai/tools/reports.class.php @@ -2,6 +2,7 @@ /* Copyright (C) 2026 Laurent Destailleur * Copyright (C) 2026 Nick Fragoulis * Copyright (C) 2026 Jose Martinez + * Copyright (C) 2026 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 @@ -37,7 +38,6 @@ require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; */ class ToolReports extends McpTool { - /** * Constructor * @@ -213,10 +213,10 @@ class ToolReports extends McpTool } if (!empty($args['thirdparty_name'])) { - $name = $this->db->escape($args['thirdparty_name']); + $sqlName = $this->db->escape($args['thirdparty_name']); $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "societe - WHERE nom LIKE '%" . $name . "%' + WHERE nom LIKE '%" . $sqlName . "%' AND entity IN (" . getEntity('societe') . ") LIMIT 1"; @@ -388,11 +388,11 @@ class ToolReports extends McpTool return [[$langs->transnoentitiesnoconv("Error") => $langs->transnoentitiesnoconv("ErrorThirdPartyNotFound")]]; } - $queries = []; + $sqlQueries = []; // Invoices if ($type == 'all' || $type == 'invoices') { - $queries[] = "SELECT 'Invoice' as source_type, rowid, ref, total_ttc as amount, datef as date_entry, fk_statut + $sqlQueries[] = "SELECT 'Invoice' as source_type, rowid, ref, total_ttc as amount, datef as date_entry, fk_statut FROM " . MAIN_DB_PREFIX . "facture WHERE fk_soc = " . (int) $socid . " AND entity IN (" . getEntity('facture') . ") AND fk_statut IN (1, 2)"; @@ -400,7 +400,7 @@ class ToolReports extends McpTool // Orders if ($type == 'all' || $type == 'orders') { - $queries[] = "SELECT 'Order' as source_type, rowid, ref, total_ttc as amount, date_commande as date_entry, fk_statut + $sqlQueries[] = "SELECT 'Order' as source_type, rowid, ref, total_ttc as amount, date_commande as date_entry, fk_statut FROM " . MAIN_DB_PREFIX . "commande WHERE fk_soc = " . (int) $socid . " AND entity IN (" . getEntity('commande') . ") AND fk_statut > 0"; @@ -408,18 +408,18 @@ class ToolReports extends McpTool // Proposals if ($type == 'all' || $type == 'proposals') { - $queries[] = "SELECT 'Proposal' as source_type, rowid, ref, total_ttc as amount, datep as date_entry, fk_statut + $sqlQueries[] = "SELECT 'Proposal' as source_type, rowid, ref, total_ttc as amount, datep as date_entry, fk_statut FROM " . MAIN_DB_PREFIX . "propal WHERE fk_soc = " . (int) $socid . " AND entity IN (" . getEntity('propal') . ") AND fk_statut > 0"; } - if (empty($queries)) { + if (empty($sqlQueries)) { return [[$langs->transnoentitiesnoconv("Error") => "Invalid transaction type"]]; } $sql = "SELECT * FROM ("; - $sql .= implode(" UNION ", $queries); + $sql .= implode(" UNION ", $sqlQueries); $sql .= ") as combined_transactions "; $whereParts = []; if ($dateStart > 0) { diff --git a/htdocs/bookmarks/class/bookmark.class.php b/htdocs/bookmarks/class/bookmark.class.php index f109e67531a..a14dca9f0c8 100644 --- a/htdocs/bookmarks/class/bookmark.class.php +++ b/htdocs/bookmarks/class/bookmark.class.php @@ -2,6 +2,7 @@ /* Copyright (C) 2005 Laurent Destailleur * Copyright (C) 2015 Marcos García * Copyright (C) 2024 Frédéric France + * Copyright (C) 2026 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 @@ -118,7 +119,7 @@ class Bookmark extends CommonObject $sql .= " title, position, favicon"; $sql .= " FROM ".MAIN_DB_PREFIX."bookmark"; $sql .= " WHERE rowid = ".((int) $id); - $sql .= " AND entity = ".$conf->entity; + $sql .= " AND entity = ".((int) $conf->entity); dol_syslog("Bookmark::fetch", LOG_DEBUG); $resql = $this->db->query($sql); @@ -168,7 +169,7 @@ class Bookmark extends CommonObject $sql .= ",title,favicon,position"; $sql .= ",entity"; $sql .= ") VALUES ("; - $sql .= ($this->fk_user > 0 ? $this->fk_user : "0").","; + $sql .= ($this->fk_user > 0 ? ((int) $this->fk_user) : "0").","; $sql .= " '".$this->db->idate($now)."',"; $sql .= " '".$this->db->escape($this->url)."', '".$this->db->escape($this->target)."',"; $sql .= " '".$this->db->escape($this->title)."', '".$this->db->escape($this->favicon)."', ".(int) $this->position; @@ -212,7 +213,7 @@ class Bookmark extends CommonObject } $sql = "UPDATE ".MAIN_DB_PREFIX."bookmark"; - $sql .= " SET fk_user = ".($this->fk_user > 0 ? $this->fk_user : "0"); + $sql .= " SET fk_user = ".($this->fk_user > 0 ? ((int) $this->fk_user) : "0"); $sql .= " ,dateb = '".$this->db->idate($this->datec)."'"; $sql .= " ,url = '".$this->db->escape($this->url)."'"; $sql .= " ,target = '".$this->db->escape($this->target)."'"; @@ -343,7 +344,7 @@ class Bookmark extends CommonObject global $action, $hookmanager; $hookmanager->initHooks(array('mybookmarkdao')); - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); + $parameters = array('id' => $this->id, 'getnomurl' => &$result); $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if ($reshook > 0) { $result = $hookmanager->resPrint; diff --git a/htdocs/hrm/class/evaluation.class.php b/htdocs/hrm/class/evaluation.class.php index 25f340af80d..086f71e8b04 100644 --- a/htdocs/hrm/class/evaluation.class.php +++ b/htdocs/hrm/class/evaluation.class.php @@ -584,14 +584,14 @@ class Evaluation extends CommonObject if (preg_match('/^[\(]?PROV/i', $this->ref)) { // Now we rename also files into index $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'evaluation/".$this->db->escape($this->newref)."'"; - $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity); $resql = $this->db->query($sql); if (!$resql) { $error++; $this->error = $this->db->lasterror(); } $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'evaluation/".$this->db->escape($this->newref)."'"; - $sql .= " WHERE filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $sql .= " WHERE filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity); $resql = $this->db->query($sql); if (!$resql) { $error++; diff --git a/htdocs/hrm/class/job.class.php b/htdocs/hrm/class/job.class.php index 1f05a96fcf8..bc4f32f4382 100644 --- a/htdocs/hrm/class/job.class.php +++ b/htdocs/hrm/class/job.class.php @@ -522,14 +522,14 @@ class Job extends CommonObject if (preg_match('/^[\(]?PROV/i', $this->ref)) { // Now we rename also files into index $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'job/".$this->db->escape($this->newref)."'"; - $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'job/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'job/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity); $resql = $this->db->query($sql); if (!$resql) { $error++; $this->error = $this->db->lasterror(); } $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'job/".$this->db->escape($this->newref)."'"; - $sql .= " WHERE filepath = 'job/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $sql .= " WHERE filepath = 'job/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity); $resql = $this->db->query($sql); if (!$resql) { $error++; diff --git a/htdocs/hrm/class/skilldet.class.php b/htdocs/hrm/class/skilldet.class.php index 724930cae0b..d92f792bab7 100644 --- a/htdocs/hrm/class/skilldet.class.php +++ b/htdocs/hrm/class/skilldet.class.php @@ -546,14 +546,14 @@ class Skilldet extends CommonObjectLine if (preg_match('/^[\(]?PROV/i', $this->ref)) { // Now we rename also files into index $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'skilldet/".$this->db->escape($this->newref)."'"; - $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skilldet/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skilldet/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity); $resql = $this->db->query($sql); if (!$resql) { $error++; $this->error = $this->db->lasterror(); } $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skilldet/".$this->db->escape($this->newref)."'"; - $sql .= " WHERE filepath = 'skilldet/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $sql .= " WHERE filepath = 'skilldet/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity); $resql = $this->db->query($sql); if (!$resql) { $error++; diff --git a/htdocs/opensurvey/class/opensurveysondage.class.php b/htdocs/opensurvey/class/opensurveysondage.class.php index 700644cf601..3ecd91171d1 100644 --- a/htdocs/opensurvey/class/opensurveysondage.class.php +++ b/htdocs/opensurvey/class/opensurveysondage.class.php @@ -347,7 +347,7 @@ class Opensurveysondage extends CommonObject $sql .= " t.sujet,"; $sql .= " t.tms"; $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_sondage as t"; - $sql .= " WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey)."'"; + $sql .= " WHERE t.id_sondage = '".$this->db->escape($id ? ((int) $id) : $numsurvey)."'"; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); diff --git a/htdocs/product/canvas/product/actions_card_product.class.php b/htdocs/product/canvas/product/actions_card_product.class.php index e1fe19900f4..a6836c47d12 100644 --- a/htdocs/product/canvas/product/actions_card_product.class.php +++ b/htdocs/product/canvas/product/actions_card_product.class.php @@ -313,7 +313,7 @@ class ActionsCardProduct $sql = "SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang"; $sql .= " FROM ".MAIN_DB_PREFIX."c_field_list"; $sql .= " WHERE element = '".$this->db->escape($this->fieldListName)."'"; - $sql .= " AND entity = ".$conf->entity; + $sql .= " AND entity = ".((int) $conf->entity); $sql .= " ORDER BY rang ASC"; $resql = $this->db->query($sql); diff --git a/htdocs/product/class/productbatch.class.php b/htdocs/product/class/productbatch.class.php index 4377550d1bb..e57861a1189 100644 --- a/htdocs/product/class/productbatch.class.php +++ b/htdocs/product/class/productbatch.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2013-2014 Cedric GROSS * Copyright (C) 2024-2025 Frédéric France * Copyright (C) 2024 Ferran Marcet - * Copyright (C) 2024-2025 MDW + * Copyright (C) 2024-2026 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 @@ -130,11 +130,11 @@ class Productbatch extends CommonObject $sql .= "qty,"; $sql .= "import_key"; $sql .= ") VALUES ("; - $sql .= " ".(!isset($this->fk_product_stock) ? 'NULL' : $this->fk_product_stock).","; + $sql .= " ".(!isset($this->fk_product_stock) ? 'NULL' : ((int) $this->fk_product_stock)).","; $sql .= " ".(!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'".$this->db->idate($this->sellby)."'").","; // no more used $sql .= " ".(!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'".$this->db->idate($this->eatby)."'").","; // no more used $sql .= " ".(!isset($this->batch) ? 'NULL' : "'".$this->db->escape($this->batch)."'").","; - $sql .= " ".(!isset($this->qty) ? 'NULL' : $this->qty).","; + $sql .= " ".(!isset($this->qty) ? 'NULL' : ((float) $this->qty)).","; $sql .= " ".(!isset($this->import_key) ? 'NULL' : "'".$this->db->escape($this->import_key)."'"); $sql .= ")"; @@ -235,11 +235,11 @@ class Productbatch extends CommonObject // Update request $sql = "UPDATE ".$this->db->prefix().self::$_table_element." SET"; - $sql .= " fk_product_stock=".(isset($this->fk_product_stock) ? $this->fk_product_stock : "null").","; + $sql .= " fk_product_stock=".(isset($this->fk_product_stock) ? ((int) $this->fk_product_stock) : "null").","; $sql .= " sellby=".(dol_strlen($this->sellby) != 0 ? "'".$this->db->idate($this->sellby)."'" : 'null').","; $sql .= " eatby=".(dol_strlen($this->eatby) != 0 ? "'".$this->db->idate($this->eatby)."'" : 'null').","; $sql .= " batch=".(isset($this->batch) ? "'".$this->db->escape($this->batch)."'" : "null").","; - $sql .= " qty=".(isset($this->qty) ? $this->qty : "null").","; + $sql .= " qty=".(isset($this->qty) ? ((float) $this->qty) : "null").","; $sql .= " import_key=".(isset($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null"); $sql .= " WHERE rowid=".((int) $this->id); @@ -429,7 +429,7 @@ class Productbatch extends CommonObject $sql .= ", ".$this->db->prefix()."product_stock as ps"; $sql .= " WHERE t.fk_product_stock = ps.rowid AND ps.fk_entrepot = ".((int) $fk_warehouse); if ($fk_product > 0) { - $sql .= " AND ps.fk_product = ".((int) $fk_product); + $sql .= " AND ps.fk_product = ".((int) $fk_product); } } if (!empty($eatby)) { diff --git a/htdocs/projet/class/projectstats.class.php b/htdocs/projet/class/projectstats.class.php index 49df84b32f9..f212b095d50 100644 --- a/htdocs/projet/class/projectstats.class.php +++ b/htdocs/projet/class/projectstats.class.php @@ -77,7 +77,7 @@ class ProjectStats extends Stats $this->from = MAIN_DB_PREFIX.$this->project->table_element; $this->field = 'opp_amount'; - $this->where = " entity = ".$conf->entity; + $this->where = " entity = ".((int) $conf->entity); if ($this->socid > 0) { $this->where .= " AND fk_soc = ".((int) $this->socid); } diff --git a/htdocs/reception/class/receptionlinebatch.class.php b/htdocs/reception/class/receptionlinebatch.class.php index 4e5b1ad0217..3babc6f5e72 100644 --- a/htdocs/reception/class/receptionlinebatch.class.php +++ b/htdocs/reception/class/receptionlinebatch.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2014 Juanjo Menent * Copyright (C) 2024-2025 Frédéric France * Copyright (C) 2024 Christophe Battarel - * Copyright (C) 2024-2025 MDW + * Copyright (C) 2024-2026 MDW * Copyright (C) 2025 Nick Fragoulis * * This program is free software; you can redistribute it and/or modify @@ -403,10 +403,10 @@ class ReceptionLineBatch extends CommonObjectLine $sql .= ", description"; $sql .= ", rang"; $sql .= ") VALUES ("; - $sql .= $this->fk_reception; - $sql .= ", ".(empty($this->fk_entrepot) ? 'NULL' : $this->fk_entrepot); - $sql .= ", ".(empty($this->fk_elementdet) ? 'NULL' : $this->fk_elementdet); - $sql .= ", ".(empty($this->fk_product) ? 'NULL' : $this->fk_product); + $sql .= ((int) $this->fk_reception); + $sql .= ", ".(empty($this->fk_entrepot) ? 'NULL' : ((int) $this->fk_entrepot)); + $sql .= ", ".(empty($this->fk_elementdet) ? 'NULL' : ((int) $this->fk_elementdet)); + $sql .= ", ".(empty($this->fk_product) ? 'NULL' : ((int) $this->fk_product)); $sql .= ", '".(empty($this->element_type) ? 'order' : $this->db->escape($this->element_type))."'"; $sql .= ", ".price2num($this->qty, 'MS'); $sql .= ", ".((int) $this->fk_unit); @@ -579,15 +579,15 @@ class ReceptionLineBatch extends CommonObjectLine // Update request $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; - $sql .= " fk_element=".(isset($this->fk_element) ? $this->fk_element : "null").","; - $sql .= " fk_product=".(isset($this->fk_product) ? $this->fk_product : "null").","; - $sql .= " fk_elementdet=".(isset($this->fk_elementdet) ? $this->fk_elementdet : "null").","; - $sql .= " qty=".(isset($this->qty) ? $this->qty : "null").","; - $sql .= " fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot : "null").","; - $sql .= " fk_user=".(isset($this->fk_user) ? $this->fk_user : "null").","; + $sql .= " fk_element=".(isset($this->fk_element) ? ((int) $this->fk_element) : "null").","; + $sql .= " fk_product=".(isset($this->fk_product) ? ((int) $this->fk_product) : "null").","; + $sql .= " fk_elementdet=".(isset($this->fk_elementdet) ? ((int) $this->fk_elementdet) : "null").","; + $sql .= " qty=".(isset($this->qty) ? ((float) $this->qty) : "null").","; + $sql .= " fk_entrepot=".(isset($this->fk_entrepot) ? ((int) $this->fk_entrepot) : "null").","; + $sql .= " fk_user=".(isset($this->fk_user) ? ((int) $this->fk_user) : "null").","; $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; $sql .= " comment=".(isset($this->comment) ? "'".$this->db->escape($this->comment)."'" : "null").","; - $sql .= " status=".(isset($this->status) ? $this->status : "null").","; + $sql .= " status=".(isset($this->status) ? ((int) $this->status) : "null").","; $sql .= " tms=".(dol_strlen((string) $this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; $sql .= " batch=".(isset($this->batch) ? "'".$this->db->escape($this->batch)."'" : "null").","; $sql .= " eatby=".(dol_strlen((string) $this->eatby) != 0 ? "'".$this->db->idate((int) $this->eatby)."'" : 'null').","; diff --git a/htdocs/reception/stats/index.php b/htdocs/reception/stats/index.php index fdda34045a8..4b9b598efcc 100644 --- a/htdocs/reception/stats/index.php +++ b/htdocs/reception/stats/index.php @@ -378,7 +378,7 @@ print ''.$langs->trans("NbOfReceptions").' 0"; -$sql.= " AND entity = ".$conf->entity; +$sql.= " AND entity = ".((int) $conf->entity); $sql.= " GROUP BY dm DESC"; $resql=$db->query($sql); diff --git a/htdocs/recruitment/class/recruitmentcandidature.class.php b/htdocs/recruitment/class/recruitmentcandidature.class.php index d02cb0eb417..4e6e8cfeee8 100644 --- a/htdocs/recruitment/class/recruitmentcandidature.class.php +++ b/htdocs/recruitment/class/recruitmentcandidature.class.php @@ -589,14 +589,14 @@ class RecruitmentCandidature extends CommonObject if (preg_match('/^[\(]?PROV/i', $this->ref)) { // Now we rename also files into index $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'recruitmentcandidature/".$this->db->escape($this->newref)."'"; - $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'recruitmentcandidature/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'recruitmentcandidature/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity); $resql = $this->db->query($sql); if (!$resql) { $error++; $this->error = $this->db->lasterror(); } $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'recruitmentcandidature/".$this->db->escape($this->newref)."'"; - $sql .= " WHERE filepath = 'recruitmentcandidature/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $sql .= " WHERE filepath = 'recruitmentcandidature/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity); $resql = $this->db->query($sql); if (!$resql) { $error++; diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index e4aa17edf77..96ab3534e7b 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2023-2024 William Mead - * Copyright (C) 2024-2025 MDW + * Copyright (C) 2024-2026 MDW * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -202,7 +202,7 @@ class Dolresource extends CommonObject $sql .= "datec, "; $sql .= "fk_user_author "; $sql .= ") VALUES ("; - $sql .= (int) (empty($this->entity) ? $conf->entity : $this->entity) . ", "; + $sql .= (int) (empty($this->entity) ? ((int) $conf->entity) : ((int) $this->entity)) . ", "; foreach ($new_resource_values as $value) { $sql .= " " . (!empty($value) ? "'" . $this->db->escape($value) . "'" : 'NULL') . ","; } @@ -288,7 +288,7 @@ class Dolresource extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource"; if ($id) { - $sql .= " WHERE t.rowid = ".($id); + $sql .= " WHERE t.rowid = ".((int) $id); } else { $sql .= " WHERE t.ref = '".$this->db->escape($ref)."'"; } @@ -482,7 +482,7 @@ class Dolresource extends CommonObject $sql .= " t.fk_user_create,"; $sql .= " t.tms as date_modification"; $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as t"; - $sql .= " WHERE t.rowid = ".($id); + $sql .= " WHERE t.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); @@ -536,7 +536,7 @@ class Dolresource extends CommonObject $this->db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; - $sql .= " WHERE rowid = ".($rowid); + $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(get_class($this), LOG_DEBUG); if ($this->db->query($sql)) { diff --git a/htdocs/salaries/class/salariesstats.class.php b/htdocs/salaries/class/salariesstats.class.php index 7952ef45acd..58179e74751 100644 --- a/htdocs/salaries/class/salariesstats.class.php +++ b/htdocs/salaries/class/salariesstats.class.php @@ -67,7 +67,7 @@ class SalariesStats extends Stats $this->from = MAIN_DB_PREFIX.$object->table_element; $this->field = 'amount'; - $this->where = " entity = ".$conf->entity; + $this->where = " entity = ".((int) $conf->entity); if ($this->socid > 0) { $this->where .= " AND fk_soc = ".((int) $this->socid); } diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index 42f64a88728..ce362488226 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -8,7 +8,7 @@ * Copyright (C) 2018 Nicolas ZABOURI * Copyright (C) 2019 Abbes Bahfir * Copyright (C) 2023-2026 Frédéric France - * Copyright (C) 2024-2025 MDW + * Copyright (C) 2024-2026 MDW * Copyright (C) 2025 Charlene Benke * * This program is free software; you can redistribute it and/or modify @@ -222,7 +222,7 @@ class UserGroup extends CommonObject if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) { $sql .= " AND g.entity IS NOT NULL"; } else { - $sql .= " AND g.entity IN (0,".$conf->entity.")"; + $sql .= " AND g.entity IN (0,".((int) $conf->entity).")"; } $sql .= " ORDER BY g.nom"; @@ -282,7 +282,7 @@ class UserGroup extends CommonObject if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) { $sql .= " AND u.entity IS NOT NULL"; } else { - $sql .= " AND u.entity IN (0,".$conf->entity.")"; + $sql .= " AND u.entity IN (0,".((int) $conf->entity).")"; } if (!empty($excludefilter)) { $sql .= ' AND ('.$excludefilter.')'; @@ -549,7 +549,7 @@ class UserGroup extends CommonObject } $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights"; - $sql .= " WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid); + $sql .= " WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid); $sql .= " AND entity = ".((int) $entity); if (!$this->db->query($sql)) { $error++; diff --git a/htdocs/user/group/list.php b/htdocs/user/group/list.php index a200929065c..68fa0ded39d 100644 --- a/htdocs/user/group/list.php +++ b/htdocs/user/group/list.php @@ -4,7 +4,7 @@ * Copyright (C) 2005-2024 Regis Houssin * Copyright (C) 2011 Herve Prot * Copyright (C) 2019-2026 Frédéric France - * Copyright (C) 2025 MDW + * Copyright (C) 2025-2026 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 @@ -191,7 +191,7 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_rights as ugr ON ugr.fk_usergrou if (isModEnabled('multicompany') && $conf->entity == 1 && (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') || ($user->admin && !$user->entity))) { $sql .= " WHERE g.entity IS NOT NULL"; } else { - $sql .= " WHERE g.entity IN (0,".$conf->entity.")"; + $sql .= " WHERE g.entity IN (0,".((int) $conf->entity).")"; } if (!empty($search_group)) { natural_search(array("g.nom", "g.note"), $search_group); diff --git a/htdocs/user/hierarchy.php b/htdocs/user/hierarchy.php index 8b1e7e6bf43..c57aedad27f 100644 --- a/htdocs/user/hierarchy.php +++ b/htdocs/user/hierarchy.php @@ -5,7 +5,7 @@ * Copyright (C) 2007 Patrick Raguin * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2019-2026 Frédéric France - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2026 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 @@ -114,16 +114,16 @@ $arrayofcss = array('/public/includes/jquery/plugins/jquerytreeview/jquery.treev llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', 'bodyforlist mod-user page-hierarchy'); -$filters = []; +$sql_filters_arr = []; if (($search_status != '' && $search_status >= 0)) { - $filters[] = "(statut:=:".((int) $search_status).")"; + $sql_filters_arr[] = "(statut:=:".((int) $search_status).")"; } if ($search_employee == 1) { - $filters[] = "(employee:=:1)"; + $sql_filters_arr[] = "(employee:=:1)"; } $sqlfilter = ''; -if (!empty($filters)) { - $sqlfilter = implode(' AND ', $filters); +if (!empty($sql_filters_arr)) { + $sqlfilter = implode(' AND ', $sql_filters_arr); } // Load hierarchy of users $user_arbo_all = $userstatic->get_full_tree(0, ''); diff --git a/htdocs/user/home.php b/htdocs/user/home.php index ca88da0bdad..64dfd72b087 100644 --- a/htdocs/user/home.php +++ b/htdocs/user/home.php @@ -3,6 +3,7 @@ * Copyright (C) 2005-2024 Regis Houssin * Copyright (C) 2019 Nicolas ZABOURI * Copyright (C) 2024-2026 Frédéric France + * Copyright (C) 2026 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 @@ -246,7 +247,7 @@ if ($permissiontoreadgroup) { if (isModEnabled('multicompany') && $conf->entity == 1 && (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') || ($user->admin && !$user->entity))) { $sql .= " WHERE g.entity IS NOT NULL"; } else { - $sql .= " WHERE g.entity IN (0, ".$conf->entity.")"; + $sql .= " WHERE g.entity IN (0, ".((int) $conf->entity).")"; } $sql .= $db->order("g.datec", "DESC"); $sql .= $db->plimit($max); diff --git a/htdocs/variants/class/ProductAttribute.class.php b/htdocs/variants/class/ProductAttribute.class.php index 3376e034416..22da2cf1c0a 100644 --- a/htdocs/variants/class/ProductAttribute.class.php +++ b/htdocs/variants/class/ProductAttribute.class.php @@ -529,10 +529,10 @@ class ProductAttribute extends CommonObject /** * Load array lines * - * @param string $filters Filter on other fields + * @param string $sql_filters Filter on other fields * @return int Return integer <0 if KO, >0 if OK */ - public function fetch_lines($filters = '') + public function fetch_lines($sql_filters = '') { // phpcs:enable global $langs; @@ -559,8 +559,8 @@ class ProductAttribute extends CommonObject $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $this->db->sanitize($this->table_element) . " AS t ON t.rowid = td." . $this->db->sanitize($this->fk_element); $sql .= " WHERE t.rowid = " . ((int) $this->id); $sql .= " AND t.entity IN (" . getEntity('product') . ")"; - if ($filters) { - $sql .= $filters; + if ($sql_filters) { + $sql .= $sql_filters; } $sql .= $this->db->order("td.position", "asc"); diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php index 8a1d803f972..f99b76eab3e 100644 --- a/htdocs/webservices/server_productorservice.php +++ b/htdocs/webservices/server_productorservice.php @@ -934,7 +934,7 @@ function getListOfProductsOrServices($authentication, $filterproduct) if (!$error) { $sql = "SELECT rowid, ref, ref_ext"; $sql .= " FROM ".MAIN_DB_PREFIX."product"; - $sql .= " WHERE entity=".$conf->entity; + $sql .= " WHERE entity=".((int) $conf->entity); foreach ($filterproduct as $key => $val) { if ($key == 'type' && $val >= 0) { $sql .= " AND fk_product_type = ".((int) $val);