From 1fa7013313dcebe6845d1fbe91ad90bf9b5acbb7 Mon Sep 17 00:00:00 2001 From: brad Date: Fri, 22 Mar 2024 15:11:52 +1100 Subject: [PATCH 1/2] FIX Add state/province filter to email adv select --- htdocs/comm/mailing/advtargetemailing.php | 2 +- htdocs/core/tpl/advtarget.tpl.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/mailing/advtargetemailing.php b/htdocs/comm/mailing/advtargetemailing.php index e00986437477a..e135b8ab378ab 100644 --- a/htdocs/comm/mailing/advtargetemailing.php +++ b/htdocs/comm/mailing/advtargetemailing.php @@ -1,4 +1,4 @@ - * Copyright (C) 2016 Laurent Destailleur * diff --git a/htdocs/core/tpl/advtarget.tpl.php b/htdocs/core/tpl/advtarget.tpl.php index 42aba1b10ba8b..efd80c5141d5a 100644 --- a/htdocs/core/tpl/advtarget.tpl.php +++ b/htdocs/core/tpl/advtarget.tpl.php @@ -1,4 +1,4 @@ - * Copyright (C) 2024 Frédéric France */ From d351005cb1a893b102feaa360d7b5ac43d847297 Mon Sep 17 00:00:00 2001 From: brad Date: Fri, 22 Mar 2024 15:19:18 +1100 Subject: [PATCH 2/2] FIX Add state/province filter to email adv select --- htdocs/comm/mailing/advtargetemailing.php | 2 +- .../mailing/class/advtargetemailing.class.php | 9 +++ .../html.formadvtargetemailing.class.php | 62 +++++++++++++++++++ htdocs/core/tpl/advtarget.tpl.php | 16 ++++- 4 files changed, 85 insertions(+), 4 deletions(-) diff --git a/htdocs/comm/mailing/advtargetemailing.php b/htdocs/comm/mailing/advtargetemailing.php index e00986437477a..e135b8ab378ab 100644 --- a/htdocs/comm/mailing/advtargetemailing.php +++ b/htdocs/comm/mailing/advtargetemailing.php @@ -1,4 +1,4 @@ - * Copyright (C) 2016 Laurent Destailleur * diff --git a/htdocs/comm/mailing/class/advtargetemailing.class.php b/htdocs/comm/mailing/class/advtargetemailing.class.php index e97f3d6df66ea..28bdb0b02d8e1 100644 --- a/htdocs/comm/mailing/class/advtargetemailing.class.php +++ b/htdocs/comm/mailing/class/advtargetemailing.class.php @@ -584,6 +584,9 @@ public function query_thirdparty($arrayquery) if (!empty($arrayquery['cust_saleman']) && count($arrayquery['cust_saleman']) > 0) { $sqlwhere[] = " (saleman.fk_user IN (".$this->db->sanitize(implode(',', $arrayquery['cust_saleman']))."))"; } + if (!empty($arrayquery['cust_state']) && count($arrayquery['cust_state']) > 0) { + $sqlwhere[] = " (t.fk_departement IN (".$this->db->sanitize(implode(',', $arrayquery['cust_state']))."))"; + } if (!empty($arrayquery['cust_country']) && count($arrayquery['cust_country']) > 0) { $sqlwhere[] = " (t.fk_pays IN (".$this->db->sanitize(implode(',', $arrayquery['cust_country']))."))"; } @@ -825,6 +828,12 @@ public function query_contact($arrayquery, $withThirdpartyFilter = 0) if (!empty($arrayquery['cust_saleman']) && count($arrayquery['cust_saleman']) > 0) { $sqlwhere[] = " (saleman.fk_user IN (".$this->db->sanitize(implode(',', $arrayquery['cust_saleman']))."))"; } + //if (!empty($arrayquery['cust_state'])) { + // $sqlwhere[] = $this->transformToSQL('tsd.nom', $arrayquery['cust_state']); + //} + if (!empty($arrayquery['cust_state']) && count($arrayquery['cust_state']) > 0) { + $sqlwhere[] = " (t.fk_departement IN (".$this->db->sanitize(implode(',', $arrayquery['cust_state']))."))"; + } if (!empty($arrayquery['cust_country']) && count($arrayquery['cust_country']) > 0) { $sqlwhere[] = " (ts.fk_pays IN (".$this->db->sanitize(implode(',', $arrayquery['cust_country']))."))"; } diff --git a/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php b/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php index 70f7c9ba9752c..5ec9be92dbc07 100644 --- a/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php +++ b/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php @@ -87,6 +87,68 @@ public function multiselectProspectionStatus($selected_array = array(), $htmlnam return $this->advMultiselectarray($htmlname, $options_array, $selected_array); } + /** + * Return combo list of activated countries, into language of user + * + * @param string $htmlname of html select object + * @param array $selected_array or Code or Label of preselected country + * @return string HTML string with select + */ + public function multiselectState($htmlname = 'state_id', $selected_array = array()) + { + global $conf, $langs; + + $langs->load("dict"); + $maxlength = 0; + + $out = ''; + $countryArray = array(); + $label = array(); + + $options_array = array(); + + $sql = "SELECT d.rowid as rowid, d.code_departement as code_iso, d.nom as department, r.nom as region"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_departements d"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_regions r on d.fk_region=r.code_region"; + $sql .= " WHERE d.active = 1 AND d.code_departement<>''"; + //$sql .= " ORDER BY r.nom ASC, d.nom ASC"; + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + $i = 0; + if ($num) { + $foundselected = false; + + while ($i < $num) { + $obj = $this->db->fetch_object($resql); + $stateArray [$i] ['rowid'] = $obj->rowid; + $stateArray [$i] ['code_iso'] = $obj->code_iso; + $stateArray [$i] ['label'] = $obj->region.'/'.$obj->department; + //($obj->code_iso && $langs->transnoentitiesnoconv("Country".$obj->code_iso) != "Country".$obj->code_iso ? $langs->transnoentitiesnoconv("Country".$obj->code_iso) : ($obj->label != '-' ? $obj->label : '')); + $label[$i] = $stateArray[$i]['label']; + $i++; + } + + $array1_sort_order = SORT_ASC; + array_multisort($label, $array1_sort_order, $stateArray); + + foreach ($stateArray as $row) { + $label = dol_trunc($row['label'], $maxlength, 'middle'); + if ($row['code_iso']) { + $label .= ' ('.$row['code_iso'].')'; + } + + $options_array[$row['rowid']] = $label; + } + } + } else { + dol_print_error($this->db); + } + + return $this->advMultiselectarray($htmlname, $options_array, $selected_array); + } + /** * Return combo list of activated countries, into language of user * diff --git a/htdocs/core/tpl/advtarget.tpl.php b/htdocs/core/tpl/advtarget.tpl.php index 42aba1b10ba8b..0741286c1c827 100644 --- a/htdocs/core/tpl/advtarget.tpl.php +++ b/htdocs/core/tpl/advtarget.tpl.php @@ -1,4 +1,4 @@ - * Copyright (C) 2024 Frédéric France */ @@ -110,9 +110,9 @@ print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); $cust_code_str = (string) $array_query['cust_code']; } else { - $cust_code_str = "null"; + $cust_code_str = null; } -print ''."\n"; +print ''."\n"; print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help'); print ''."\n"; @@ -143,6 +143,16 @@ print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help'); print ''."\n"; +// State Client +print ''.$langs->trans('State'); +if (!empty($array_query['cust_state'])) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); +} +print ''."\n"; +print $formadvtargetemaling->multiselectState('cust_state', $array_query['cust_state']); +print ''."\n"; +print ''."\n"; + // Customer Country print ''.$langs->trans("Country"); if (!empty($array_query['cust_country'])) {