From 69f82e5cb635733a3d5e4ab8f68f504d2bdfa160 Mon Sep 17 00:00:00 2001 From: HENRY Florian Date: Tue, 15 Jul 2025 15:40:25 +0200 Subject: [PATCH] fix: advanced target emailling missing case (#34715) * fix: advanced target emailling missing case * fix: travis for simple quote SQL --------- Co-authored-by: Laurent Destailleur --- .../mailing/class/advtargetemailing.class.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/htdocs/comm/mailing/class/advtargetemailing.class.php b/htdocs/comm/mailing/class/advtargetemailing.class.php index 0fd4ea09ccd..a7eef05e6a5 100644 --- a/htdocs/comm/mailing/class/advtargetemailing.class.php +++ b/htdocs/comm/mailing/class/advtargetemailing.class.php @@ -641,6 +641,27 @@ class AdvanceTargetingMailing extends CommonObject if ($arrayquery['options_'.$key] > 0) { $sqlwhere[] = " (te.".$key." = ".((int) $arrayquery["options_".$key]).")"; } + } elseif ($extrafields->attributes[$elementtype]['type'][$key] == 'chkbxlst' + && is_array($arrayquery['options_'.$key])) { + if (count($arrayquery['options_'.$key])) { + $i2 = 0; + $field = "te.".$key; + $sqlwhereselllist=""; + foreach ($arrayquery['options_'.$key] as $data) { + $data = trim($data); + if ($data) { + $sqlwhereselllist .= ($i2 > 0 ? " OR (" : "(").$field." LIKE '".$this->db->escape($data).",%'"; + $sqlwhereselllist .= " OR ".$field." = '".$this->db->escape($data)."'"; + $sqlwhereselllist .= " OR ".$field." LIKE '%,".$this->db->escape($data)."'"; + $sqlwhereselllist .= " OR ".$field." LIKE '%,".$this->db->escape($data).",%'"; + $sqlwhereselllist .= ")"; + $i2++; // a criteria for 1 more field was added to string (we can add several criteria for the same field as it is a multiselect search criteria) + } + } + if (!empty($sqlwhereselllist)) { + $sqlwhere[] = "( ".$sqlwhereselllist." )"; + } + } } else { if (is_array($arrayquery['options_'.$key])) { $sqlwhere[] = " (te.".$key." IN (".$this->db->sanitize("'".implode("','", $arrayquery["options_".$key])."'", 1)."))"; @@ -784,6 +805,31 @@ class AdvanceTargetingMailing extends CommonObject $sqlwhere[] = " (te.".$key." = ".((int) $arrayquery["options_".$key."_cnct"]).")"; } } + } elseif ($extrafields->attributes[$elementtype]['type'][$key] == 'link') { + if ($arrayquery['options_'.$key."_cnct"] > 0) { + $sqlwhere[]= " (te.".$key." = ".((int) $arrayquery["options_".$key."_cnct"]).")"; + } + } elseif ($extrafields->attributes[$elementtype]['type'][$key] == 'chkbxlst' + && is_array($arrayquery['options_'.$key.'_cnct'])) { + if (count($arrayquery['options_'.$key.'_cnct'])) { + $i2 = 0; + $field = "te.".$key; + $sqlwhereselllist=""; + foreach ($arrayquery['options_'.$key.'_cnct'] as $data) { + $data = trim($data); + if ($data) { + $sqlwhereselllist .= ($i2 > 0 ? " OR (" : "(").$field." LIKE '".$this->db->escape($data).",%'"; + $sqlwhereselllist .= " OR ".$field." = '".$this->db->escape($data)."'"; + $sqlwhereselllist .= " OR ".$field." LIKE '%,".$this->db->escape($data)."'"; + $sqlwhereselllist .= " OR ".$field." LIKE '%,".$this->db->escape($data).",%'"; + $sqlwhereselllist .= ")"; + $i2++; // a criteria for 1 more field was added to string (we can add several criteria for the same field as it is a multiselect search criteria) + } + } + if (!empty($sqlwhereselllist)) { + $sqlwhere[] = "( ".$sqlwhereselllist." )"; + } + } } else { if (is_array($arrayquery['options_'.$key.'_cnct'])) { $sqlwhere[] = " (te.".$key." IN (".$this->db->sanitize("'".implode("','", $arrayquery["options_".$key."_cnct"])."'", 1)."))"; @@ -888,6 +934,31 @@ class AdvanceTargetingMailing extends CommonObject if ($arrayquery['options_'.$key] != '') { $sqlwhere[] = " (tse.".$key." = ".((int) $arrayquery["options_".$key]).")"; } + } elseif ($extrafields->attributes[$elementtype]['type'][$key] == 'link') { + if ($arrayquery['options_'.$key] > 0) { + $sqlwhere[]= " (te.".$key." = ".((int) $arrayquery["options_".$key]).")"; + } + } elseif ($extrafields->attributes[$elementtype]['type'][$key] == 'chkbxlst' + && is_array($arrayquery['options_'.$key])) { + if (count($arrayquery['options_'.$key])) { + $i2 = 0; + $field = "tse.".$key; + $sqlwhereselllist=""; + foreach ($arrayquery['options_'.$key] as $data) { + $data = trim($data); + if ($data) { + $sqlwhereselllist .= ($i2 > 0 ? " OR (" : "(").$field." LIKE '".$this->db->escape($data).",%'"; + $sqlwhereselllist .= " OR ".$field." = '".$this->db->escape($data)."'"; + $sqlwhereselllist .= " OR ".$field." LIKE '%,".$this->db->escape($data)."'"; + $sqlwhereselllist .= " OR ".$field." LIKE '%,".$this->db->escape($data).",%'"; + $sqlwhereselllist .= ")"; + $i2++; // a criteria for 1 more field was added to string (we can add several criteria for the same field as it is a multiselect search criteria) + } + } + if (!empty($sqlwhereselllist)) { + $sqlwhere[] = "( ".$sqlwhereselllist." )"; + } + } } else { if (is_array($arrayquery['options_'.$key])) { $sqlwhere[] = " (tse.".$key." IN (".$this->db->sanitize("'".implode("','", $arrayquery["options_".$key])."'", 1)."))";