Qual: Fix 'SqlInjection' notices (#39223)

# Qual: Fix 'SqlInjection' notices

Batch of 25 files with changes to fix 'SqlInjection' Notices
This commit is contained in:
MDW 2026-07-20 02:51:42 +02:00 committed by GitHub
parent 1df0531b43
commit b51b38ef64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 89 additions and 87 deletions

View file

@ -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";

View file

@ -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);

View file

@ -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";

View file

@ -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 .= ")";

View file

@ -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);

View file

@ -2,6 +2,7 @@
/* Copyright (C) 2026 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2026 Nick Fragoulis
* Copyright (C) 2026 Jose Martinez <jose.martinez@pichinov.com>
* Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
*
* 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) {

View file

@ -2,6 +2,7 @@
/* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
*
* 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;

View file

@ -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++;

View file

@ -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++;

View file

@ -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++;

View file

@ -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);

View file

@ -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);

View file

@ -3,7 +3,7 @@
* Copyright (C) 2013-2014 Cedric GROSS <c.gross@kreiz-it.fr>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
*
* 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)) {

View file

@ -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);
}

View file

@ -3,7 +3,7 @@
* Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 Christophe Battarel <christophe@altairis.fr>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
* 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').",";

View file

@ -378,7 +378,7 @@ print '<td width="40%" class="center">'.$langs->trans("NbOfReceptions").'</td></
$sql = "SELECT count(*) as nb, date_format(date_reception,'%Y') as dm";
$sql.= " FROM ".MAIN_DB_PREFIX."reception";
$sql.= " WHERE fk_statut > 0";
$sql.= " AND entity = ".$conf->entity;
$sql.= " AND entity = ".((int) $conf->entity);
$sql.= " GROUP BY dm DESC";
$resql=$db->query($sql);

View file

@ -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++;

View file

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2013-2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2023-2024 William Mead <william.mead@manchenumerique.fr>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
*
* 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)) {

View file

@ -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);
}

View file

@ -8,7 +8,7 @@
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2019 Abbes Bahfir <dolipar@dolipar.org>
* Copyright (C) 2023-2026 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2025 Charlene Benke <charlene@patas-monkey.com>
*
* 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++;

View file

@ -4,7 +4,7 @@
* Copyright (C) 2005-2024 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
* Copyright (C) 2019-2026 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2025-2026 MDW <mdeweerd@users.noreply.github.com>
*
* 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);

View file

@ -5,7 +5,7 @@
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2019-2026 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
*
* 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, '');

View file

@ -3,6 +3,7 @@
* Copyright (C) 2005-2024 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
*
* 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);

View file

@ -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");

View file

@ -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);