Skip to content

Commit

Permalink
Merge pull request #29018 from bradley-jarvis/fix-add-state-province-…
Browse files Browse the repository at this point in the history
…filter-field

NEW add state province filter field
  • Loading branch information
eldy committed Mar 23, 2024
2 parents 5c31471 + e34d4ec commit f050f79
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
9 changes: 9 additions & 0 deletions htdocs/comm/mailing/class/advtargetemailing.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']))."))";
}
Expand Down Expand Up @@ -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']))."))";
}
Expand Down
61 changes: 61 additions & 0 deletions htdocs/comm/mailing/class/html.formadvtargetemailing.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,67 @@ 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 = '';
$stateArray = array();
$label = array();

$options_array = array();

$sql = "SELECT d.rowid as rowid, d.code_departement as code, 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<>'' AND r.code_region<>''";
//$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'] = $obj->code;
$stateArray [$i] ['label'] = $obj->region.'/'.$obj->department;
$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']) {
$label .= ' ('.$row['code'].')';
}

$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
*
Expand Down
14 changes: 12 additions & 2 deletions htdocs/core/tpl/advtarget.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '</td><td><input type="text" name="cust_code" value="'.$cust_code_str.'"/></td><td>'."\n";
print '</td><td><input type="text" name="cust_code"'.($cust_code_str!=null?' value="'.$cust_code_str:'').'"/></td><td>'."\n";
print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help');
print '</td></tr>'."\n";

Expand Down Expand Up @@ -143,6 +143,16 @@
print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help');
print '</td></tr>'."\n";

// State Client
print '<tr><td>'.$langs->trans('State');
if (!empty($array_query['cust_state'])) {
print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing');
}
print '</td><td>'."\n";
print $formadvtargetemaling->multiselectState('cust_state', $array_query['cust_state']);
print '</td><td>'."\n";
print '</td></tr>'."\n";

// Customer Country
print '<tr><td>'.$langs->trans("Country");
if (!empty($array_query['cust_country'])) {
Expand Down

0 comments on commit f050f79

Please sign in to comment.