From 9587403e0abc8d78b5f605823489b73d1897573b Mon Sep 17 00:00:00 2001 From: Eric Seigne Date: Tue, 14 Jan 2025 22:16:34 +0100 Subject: [PATCH 1/5] add a hook on vat rate --- htdocs/core/class/html.form.class.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 29de7398bac..ede456909d5 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6906,11 +6906,28 @@ class Form public function load_tva($htmlname = 'tauxtva', $selectedrate = '', $societe_vendeuse = null, $societe_acheteuse = null, $idprod = 0, $info_bits = 0, $type = '', $options_only = false, $mode = 0, $type_vat = 0) { // phpcs:enable - global $langs, $mysoc; + global $langs, $mysoc, $hookmanager; $langs->load('errors'); $return = ''; + // Bypass the default method + $hookmanager->initHooks(array('commonobject')); + $info_bits == 1 ? $is_npr = 1 : $is_npr = 0; + $parameters = array( + 'seller' => $societe_vendeuse, + 'buyer' => $societe_acheteuse, + 'idprod' => $idprod, + 'is_npr' => $is_npr, + 'type' => $type, + 'options_only' => $options_only, + 'mode' => $mode, + 'type_vat' => $type_vat + ); + $reshook = $hookmanager->executeHooks('load_tva', $parameters); + if ($reshook > 0) { + return $hookmanager->resPrint; + } // Define defaultnpr, defaultttx and defaultcode $defaultnpr = ($info_bits & 0x01); From 01be602fb19ec73984056593b008354526c7b057 Mon Sep 17 00:00:00 2001 From: Quentin VIAL--GOUTEYRON Date: Wed, 15 Jan 2025 08:42:14 +0100 Subject: [PATCH 2/5] FIX Issue 32460 db prefix module builder --- .../modules/mailings/modules_mailings.php | 22 +++++++++---------- htdocs/modulebuilder/template/admin/setup.php | 2 +- .../template/class/api_mymodule.class.php | 8 +++---- .../template/class/myobject.class.php | 8 +++---- .../mailing_mymodule_selector1.modules.php | 4 ++-- .../core/modules/modMyModule.class.php | 18 +++++++-------- .../mymodule/mod_myobject_standard.php | 4 ++-- .../modulebuilder/template/mymoduleindex.php | 6 ++--- .../modulebuilder/template/myobject_list.php | 10 ++++----- .../template/scripts/mymodule.php | 2 +- 10 files changed, 42 insertions(+), 42 deletions(-) diff --git a/htdocs/core/modules/mailings/modules_mailings.php b/htdocs/core/modules/mailings/modules_mailings.php index e45bd655ef3..9605cbe9019 100644 --- a/htdocs/core/modules/mailings/modules_mailings.php +++ b/htdocs/core/modules/mailings/modules_mailings.php @@ -169,14 +169,14 @@ class MailingTargets // This can't be abstract as it is used for some method { // phpcs:enable // Mise a jour nombre de destinataire dans table des mailings - $sql = "SELECT COUNT(*) nb FROM ".MAIN_DB_PREFIX."mailing_cibles"; + $sql = "SELECT COUNT(*) nb FROM ".$this->db->prefix()."mailing_cibles"; $sql .= " WHERE fk_mailing = ".((int) $mailing_id); $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); $nb = $obj->nb; - $sql = "UPDATE ".MAIN_DB_PREFIX."mailing"; + $sql = "UPDATE ".$this->db->prefix()."mailing"; $sql .= " SET nbemail = ".((int) $nb)." WHERE rowid = ".((int) $mailing_id); if (!$this->db->query($sql)) { dol_syslog($this->db->error()); @@ -208,7 +208,7 @@ class MailingTargets // This can't be abstract as it is used for some method $num = count($cibles); foreach ($cibles as $targetarray) { if (!empty($targetarray['email'])) { // avoid empty email address - $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles"; + $sql = "INSERT INTO ".$this->db->prefix()."mailing_cibles"; $sql .= " (fk_mailing,"; $sql .= " fk_contact,"; $sql .= " lastname, firstname, email, other, source_url, source_id,"; @@ -244,27 +244,27 @@ class MailingTargets // This can't be abstract as it is used for some method /* //Update the status to show thirdparty mail that don't want to be contacted anymore' - $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles"; + $sql = "UPDATE ".$this->db->prefix()."mailing_cibles"; $sql .= " SET statut=3"; - $sql .= " WHERE fk_mailing = ".((int) $mailing_id)." AND email in (SELECT email FROM ".MAIN_DB_PREFIX."societe where fk_stcomm=-1)"; + $sql .= " WHERE fk_mailing = ".((int) $mailing_id)." AND email in (SELECT email FROM ".$this->db->prefix()."societe where fk_stcomm=-1)"; $sql .= " AND source_type='thirdparty'"; dol_syslog(__METHOD__.": mailing update status to display thirdparty mail that do not want to be contacted"); $result=$this->db->query($sql); //Update the status to show contact mail that don't want to be contacted anymore' - $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles"; + $sql = "UPDATE ".$this->db->prefix()."mailing_cibles"; $sql .= " SET statut=3"; - $sql .= " WHERE fk_mailing = ".((int) $mailing_id)." AND source_type='contact' AND (email in (SELECT sc.email FROM ".MAIN_DB_PREFIX."socpeople AS sc "; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe s ON s.rowid=sc.fk_soc WHERE s.fk_stcomm=-1 OR no_email=1))"; + $sql .= " WHERE fk_mailing = ".((int) $mailing_id)." AND source_type='contact' AND (email in (SELECT sc.email FROM ".$this->db->prefix()."socpeople AS sc "; + $sql .= " INNER JOIN ".$this->db->prefix()."societe s ON s.rowid=sc.fk_soc WHERE s.fk_stcomm=-1 OR no_email=1))"; dol_syslog(__METHOD__.": mailing update status to display contact mail that do not want to be contacted",LOG_DEBUG); $result=$this->db->query($sql); */ if (empty($this->evenunsubscribe)) { - $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles as mc"; + $sql = "UPDATE ".$this->db->prefix()."mailing_cibles as mc"; $sql .= " SET mc.statut = 3"; $sql .= " WHERE mc.fk_mailing = ".((int) $mailing_id); - $sql .= " AND EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = mc.email and mu.entity = ".((int) $conf->entity).")"; + $sql .= " AND EXISTS (SELECT rowid FROM ".$this->db->prefix()."mailing_unsubscribe as mu WHERE mu.email = mc.email and mu.entity = ".((int) $conf->entity).")"; dol_syslog(__METHOD__.":mailing update status to display emails that do not want to be contacted anymore", LOG_DEBUG); $result = $this->db->query($sql); @@ -291,7 +291,7 @@ class MailingTargets // This can't be abstract as it is used for some method public function clear_target($mailing_id) { // phpcs:enable - $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles"; + $sql = "DELETE FROM ".$this->db->prefix()."mailing_cibles"; $sql .= " WHERE fk_mailing = ".((int) $mailing_id); if (!$this->db->query($sql)) { diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php index d7d87fe8f1e..306a28aa5b9 100644 --- a/htdocs/modulebuilder/template/admin/setup.php +++ b/htdocs/modulebuilder/template/admin/setup.php @@ -478,7 +478,7 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { // Load array def with activated templates $def = array(); $sql = "SELECT nom"; - $sql .= " FROM ".MAIN_DB_PREFIX."document_model"; + $sql .= " FROM ".$db->prefix()."document_model"; $sql .= " WHERE type = '".$db->escape($type)."'"; $sql .= " AND entity = ".$conf->entity; $resql = $db->query($sql); diff --git a/htdocs/modulebuilder/template/class/api_mymodule.class.php b/htdocs/modulebuilder/template/class/api_mymodule.class.php index 14b89da504c..e67def67c0c 100644 --- a/htdocs/modulebuilder/template/class/api_mymodule.class.php +++ b/htdocs/modulebuilder/template/class/api_mymodule.class.php @@ -136,8 +136,8 @@ class MyModuleApi extends DolibarrApi } $sql = "SELECT t.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX.$tmpobject->table_element." AS t"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element."_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields + $sql .= " FROM ".$this->db->prefix().$tmpobject->table_element." AS t"; + $sql .= " LEFT JOIN ".$this->db->prefix().$tmpobject->table_element."_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields $sql .= " WHERE 1 = 1"; if ($tmpobject->ismultientitymanaged) { $sql .= ' AND t.entity IN ('.getEntity($tmpobject->element).')'; @@ -148,9 +148,9 @@ class MyModuleApi extends DolibarrApi // Search on sale representative if ($search_sale && $search_sale != '-1') { if ($search_sale == -2) { - $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)"; + $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".$this->db->prefix()."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)"; } elseif ($search_sale > 0) { - $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).")"; + $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".$this->db->prefix()."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).")"; } } if ($sqlfilters) { diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index f9251809d17..7c43d256d17 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -587,7 +587,7 @@ class MyObject extends CommonObject if (!empty($num)) { // Validate - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET "; if (!empty($this->fields['ref'])) { $sql .= " ref = '".$this->db->escape($num)."',"; @@ -625,14 +625,14 @@ class MyObject extends CommonObject // Rename directory if dir was a temporary ref 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 = 'myobject/".$this->db->escape($this->newref)."'"; + $sql = 'UPDATE '.$this->db->prefix()."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'myobject/".$this->db->escape($this->newref)."'"; $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'myobject/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; $resql = $this->db->query($sql); if (!$resql) { $error++; $this->error = $this->db->lasterror(); } - $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'myobject/".$this->db->escape($this->newref)."'"; + $sql = 'UPDATE '.$this->db->prefix()."ecm_files set filepath = 'myobject/".$this->db->escape($this->newref)."'"; $sql .= " WHERE filepath = 'myobject/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; $resql = $this->db->query($sql); if (!$resql) { @@ -1026,7 +1026,7 @@ class MyObject extends CommonObject if (!empty($this->fields['fk_user_valid'])) { $sql .= ", fk_user_valid"; } - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; $sql .= " WHERE t.rowid = ".((int) $id); $result = $this->db->query($sql); diff --git a/htdocs/modulebuilder/template/core/modules/mailings/mailing_mymodule_selector1.modules.php b/htdocs/modulebuilder/template/core/modules/mailings/mailing_mymodule_selector1.modules.php index a14f339306b..b55fa3e6fe3 100644 --- a/htdocs/modulebuilder/template/core/modules/mailings/mailing_mymodule_selector1.modules.php +++ b/htdocs/modulebuilder/template/core/modules/mailings/mailing_mymodule_selector1.modules.php @@ -111,7 +111,7 @@ class mailing_mailing_mymodule_selector1 extends MailingTargets $j = 0; $sql = "SELECT rowid as id, firstname, lastname, email"; - $sql .= " FROM ".MAIN_DB_PREFIX."myobject"; + $sql .= " FROM ".$this->db->prefix()."myobject"; $sql .= " WHERE email IS NOT NULL AND email <> ''"; if (GETPOSTISSET('filter') && GETPOST('filter', 'alphanohtml') != 'none') { $sql .= " AND status = '".$this->db->escape(GETPOST('filter', 'alphanohtml'))."'"; @@ -195,7 +195,7 @@ class mailing_mailing_mymodule_selector1 extends MailingTargets public function getNbOfRecipients($sql = '') { $sql = "SELECT COUNT(DISTINCT(email)) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."myobject as p"; + $sql .= " FROM ".$this->db->prefix()."myobject as p"; $sql .= " WHERE email IS NOT NULL AND email <> ''"; $a = parent::getNbOfRecipients($sql); diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index 9a0e0829972..2a894544b8e 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -228,7 +228,7 @@ class modMyModule extends DolibarrModules // Label of tables 'tablib' => array("Table1", "Table2", "Table3"), // Request to select fields - 'tabsql' => array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table1 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table2 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table3 as f'), + 'tabsql' => array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.$this->db->prefix().'table1 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.$this->db->prefix().'table2 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.$this->db->prefix().'table3 as f'), // Sort order 'tabsqlsort' => array("label ASC", "label ASC", "label ASC"), // List of fields (result of select to show dictionary) @@ -411,8 +411,8 @@ class modMyModule extends DolibarrModules //$this->export_examplevalues_array[$r] = array('t.field' => 'Example'); //$this->export_help_array[$r] = array('t.field' => 'FieldDescHelp'); $this->export_sql_start[$r]='SELECT DISTINCT '; - $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'mymodule_myobject as t'; - //$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'mymodule_myobject_line as tl ON tl.fk_myobject = t.rowid'; + $this->export_sql_end[$r] =' FROM '.$this->db->prefix().'mymodule_myobject as t'; + //$this->export_sql_end[$r] .=' LEFT JOIN '.$this->db->prefix().'mymodule_myobject_line as tl ON tl.fk_myobject = t.rowid'; $this->export_sql_end[$r] .=' WHERE 1 = 1'; $this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('myobject').')'; $r++; */ @@ -426,7 +426,7 @@ class modMyModule extends DolibarrModules $this->import_code[$r] = $this->rights_class.'_'.$r; $this->import_label[$r] = 'MyObjectLines'; // Translation key (used only if key ExportDataset_xxx_z not found) $this->import_icon[$r] = $this->picto; - $this->import_tables_array[$r] = array('t' => MAIN_DB_PREFIX.'mymodule_myobject', 'extra' => MAIN_DB_PREFIX.'mymodule_myobject_extrafields'); + $this->import_tables_array[$r] = array('t' => $this->db->prefix().'mymodule_myobject', 'extra' => $this->db->prefix().'mymodule_myobject_extrafields'); $this->import_tables_creator_array[$r] = array('t' => 'fk_user_author'); // Fields to store import user id $import_sample = array(); $keyforclass = 'MyObject'; $keyforclassfile='/mymodule/class/myobject.class.php'; $keyforelement='myobject@mymodule'; @@ -434,7 +434,7 @@ class modMyModule extends DolibarrModules $import_extrafield_sample = array(); $keyforselect='myobject'; $keyforaliasextra='extra'; $keyforelement='myobject@mymodule'; include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php'; - $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'mymodule_myobject'); + $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.$this->db->prefix().'mymodule_myobject'); $this->import_regex_array[$r] = array(); $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample); $this->import_updatekeys_array[$r] = array('t.ref' => 'Ref'); @@ -512,10 +512,10 @@ class modMyModule extends DolibarrModules } $sql = array_merge($sql, array( - "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'standard_".strtolower($myTmpObjectKey)."' AND type = '".$this->db->escape(strtolower($myTmpObjectKey))."' AND entity = ".((int) $conf->entity), - "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('standard_".strtolower($myTmpObjectKey)."', '".$this->db->escape(strtolower($myTmpObjectKey))."', ".((int) $conf->entity).")", - "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'generic_".strtolower($myTmpObjectKey)."_odt' AND type = '".$this->db->escape(strtolower($myTmpObjectKey))."' AND entity = ".((int) $conf->entity), - "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('generic_".strtolower($myTmpObjectKey)."_odt', '".$this->db->escape(strtolower($myTmpObjectKey))."', ".((int) $conf->entity).")" + "DELETE FROM ".$this->db->prefix()."document_model WHERE nom = 'standard_".strtolower($myTmpObjectKey)."' AND type = '".$this->db->escape(strtolower($myTmpObjectKey))."' AND entity = ".((int) $conf->entity), + "INSERT INTO ".$this->db->prefix()."document_model (nom, type, entity) VALUES('standard_".strtolower($myTmpObjectKey)."', '".$this->db->escape(strtolower($myTmpObjectKey))."', ".((int) $conf->entity).")", + "DELETE FROM ".$this->db->prefix()."document_model WHERE nom = 'generic_".strtolower($myTmpObjectKey)."_odt' AND type = '".$this->db->escape(strtolower($myTmpObjectKey))."' AND entity = ".((int) $conf->entity), + "INSERT INTO ".$this->db->prefix()."document_model (nom, type, entity) VALUES('generic_".strtolower($myTmpObjectKey)."_odt', '".$this->db->escape(strtolower($myTmpObjectKey))."', ".((int) $conf->entity).")" )); } } diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php index 4d2329d8a2f..98d9b5fbffe 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php @@ -93,7 +93,7 @@ class mod_myobject_standard extends ModeleNumRefMyObject $posindice = strlen($this->prefix) + 6; $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; - $sql .= " FROM ".MAIN_DB_PREFIX."mymodule_myobject"; + $sql .= " FROM ".$db->prefix()."mymodule_myobject"; $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; if ($object->ismultientitymanaged == 1) { $sql .= " AND entity = ".$conf->entity; @@ -131,7 +131,7 @@ class mod_myobject_standard extends ModeleNumRefMyObject // first we get the max value $posindice = strlen($this->prefix) + 6; $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; - $sql .= " FROM ".MAIN_DB_PREFIX."mymodule_myobject"; + $sql .= " FROM ".$db->prefix()."mymodule_myobject"; $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; if ($object->ismultientitymanaged == 1) { $sql .= " AND entity = ".$conf->entity; diff --git a/htdocs/modulebuilder/template/mymoduleindex.php b/htdocs/modulebuilder/template/mymoduleindex.php index 8ac978ddfa6..892231a8f01 100644 --- a/htdocs/modulebuilder/template/mymoduleindex.php +++ b/htdocs/modulebuilder/template/mymoduleindex.php @@ -132,8 +132,8 @@ if (isModEnabled('mymodule') && $user->hasRight('mymodule', 'read')) { $sql = "SELECT c.rowid, c.ref, c.ref_client, c.total_ht, c.tva as total_tva, c.total_ttc, s.rowid as socid, s.nom as name, s.client, s.canvas"; $sql.= ", s.code_client"; - $sql.= " FROM ".MAIN_DB_PREFIX."commande as c"; - $sql.= ", ".MAIN_DB_PREFIX."societe as s"; + $sql.= " FROM ".$db->prefix()."commande as c"; + $sql.= ", ".$db->prefix()."societe as s"; $sql.= " WHERE c.fk_soc = s.rowid"; $sql.= " AND c.fk_statut = 0"; $sql.= " AND c.entity IN (".getEntity('commande').")"; @@ -204,7 +204,7 @@ print '
'; // Last modified myobject if (isModEnabled('mymodule') && $user->hasRight('mymodule', 'read')) { $sql = "SELECT s.rowid, s.ref, s.label, s.date_creation, s.tms"; - $sql.= " FROM ".MAIN_DB_PREFIX."mymodule_myobject as s"; + $sql.= " FROM ".$db->prefix()."mymodule_myobject as s"; $sql.= " WHERE s.entity IN (".getEntity($myobjectstatic->element).")"; //if ($socid) $sql.= " AND s.rowid = $socid"; $sql .= " ORDER BY s.tms DESC"; diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 864ad8adf9d..85bf290801a 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -317,10 +317,10 @@ $sql = preg_replace('/,\s*$/', '', $sql); $sqlfields = $sql; // $sql fields to remove for count total -$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t"; -//$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."anothertable as rc ON rc.parent = t.rowid"; +$sql .= " FROM ".$db->prefix().$object->table_element." as t"; +//$sql .= " LEFT JOIN ".$db->prefix()."anothertable as rc ON rc.parent = t.rowid"; if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; + $sql .= " LEFT JOIN ".$db->prefix().$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; } // Add table from hooks $parameters = array(); @@ -378,9 +378,9 @@ if (!$user->hasRight('societe', 'client', 'voir')) { // Search on sale representative if ($search_sale && $search_sale != '-1') { if ($search_sale == -2) { - $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)"; + $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".$db->prefix()."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)"; } elseif ($search_sale > 0) { - $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).")"; + $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".$db->prefix()."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).")"; } } // Search on socid diff --git a/htdocs/modulebuilder/template/scripts/mymodule.php b/htdocs/modulebuilder/template/scripts/mymodule.php index 24978ec7f15..8b19deb0a5e 100644 --- a/htdocs/modulebuilder/template/scripts/mymodule.php +++ b/htdocs/modulebuilder/template/scripts/mymodule.php @@ -184,7 +184,7 @@ else print "Object with id ".$myobject->id." deleted\n"; // An example of a direct SQL read without using the fetch method /* $sql = "SELECT field1, field2"; -$sql.= " FROM ".MAIN_DB_PREFIX."myobject"; +$sql.= " FROM ".$db->prefix()."myobject"; $sql.= " WHERE field3 = 'xxx'"; $sql.= " ORDER BY field1 ASC"; From acf1430bedf51eba495fbc4ed53e5616b661af07 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 Jan 2025 14:18:22 +0100 Subject: [PATCH 3/5] Update html.form.class.php --- htdocs/core/class/html.form.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index ede456909d5..adbc77946c2 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6927,8 +6927,10 @@ class Form $reshook = $hookmanager->executeHooks('load_tva', $parameters); if ($reshook > 0) { return $hookmanager->resPrint; + } elseif ($reshook === 0) { + $return .= $hookmanager->resPrint; } - + // Define defaultnpr, defaultttx and defaultcode $defaultnpr = ($info_bits & 0x01); $defaultnpr = (preg_match('/\*/', $selectedrate) ? 1 : $defaultnpr); From fffa47723fc13897629c3e1d0920fc82ecb2f360 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 15 Jan 2025 14:37:24 +0100 Subject: [PATCH 4/5] Qual: Fix ci (pre-commit) Exclude/fix shellcheck notices --- .github/workflows/pre-commit.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 81ecb17f1cd..ccd276f8a97 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -62,8 +62,9 @@ jobs: - name: Extract PHP version id: extract-php-version run: | + # shellcheck disable=SC2016 PHP_VERSION=$(sed -n 's/.*\$arrayphpmaxversionwarning\s*=\s*array\s*(\s*\([0-9]\+\)\s*,\s*\([0-9]\+\).*/\1.\2/p' htdocs/install/check.php) - echo "PHP_VERSION=$PHP_VERSION" >> $GITHUB_ENV + echo "PHP_VERSION=$PHP_VERSION" >> "$GITHUB_ENV" - name: Setup PHPCS uses: shivammathur/setup-php@v2 From ac35daf08fbcde6bf1d8beb492e204b6bbec0503 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 15 Jan 2025 14:54:33 +0100 Subject: [PATCH 5/5] Qual: Fix whitespace --- htdocs/core/class/html.form.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 66008eb07db..e784c59863e 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -23,7 +23,7 @@ * Copyright (C) 2018 Josep Lluis Amador * Copyright (C) 2023 Joachim Kueter * Copyright (C) 2023 Nick Fragoulis - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 William Mead * * This program is free software; you can redistribute it and/or modify @@ -6930,7 +6930,7 @@ class Form } elseif ($reshook === 0) { $return .= $hookmanager->resPrint; } - + // Define defaultnpr, defaultttx and defaultcode $defaultnpr = ($info_bits & 0x01); $defaultnpr = (preg_match('/\*/', $selectedrate) ? 1 : $defaultnpr);