dolibarr/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php

478 lines
14 KiB
PHP
Raw Permalink Normal View History

2016-04-01 10:52:19 +02:00
<?php
/* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
2025-01-06 18:20:18 +01:00
* Copyright (C) 2019-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
2017-12-01 15:39:18 +01:00
*
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2017-12-01 15:39:18 +01:00
*/
2016-04-01 10:52:19 +02:00
/**
* \file comm/mailing/class/html.formadvtargetemailing.class.php
2016-05-06 21:28:06 +02:00
* \ingroup mailing
* \brief File for the class with functions for the building of HTML components for advtargetemailing
2016-04-01 10:52:19 +02:00
*/
/**
* Class to manage building of HTML components
*/
2016-04-04 15:28:25 +02:00
class FormAdvTargetEmailing extends Form
{
2018-08-22 10:51:55 +02:00
/**
* @var DoliDB Database handler.
*/
public $db;
2018-08-29 15:37:35 +02:00
2018-08-17 22:29:21 +02:00
/**
* @var string Error code (or message)
*/
public $error = '';
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
/**
* Constructor
*
* @param DoliDB $db handler
*/
public function __construct($db)
{
global $langs;
2016-04-01 17:09:03 +02:00
$this->db = $db;
}
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
/**
* Affiche un champs select contenant une liste
*
* @param string[] $selected_array à preselectionner
2016-04-01 10:52:19 +02:00
* @param string $htmlname select field
* @return string select field
*/
public function multiselectProspectionStatus($selected_array = array(), $htmlname = 'cust_prospect_status')
{
2016-04-01 10:52:19 +02:00
global $conf, $langs;
2017-12-01 15:39:18 +01:00
$options_array = array();
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
$sql = "SELECT code, label";
$sql .= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
2016-04-01 10:52:19 +02:00
$sql .= " WHERE active > 0";
$sql .= " ORDER BY sortorder";
2020-02-17 13:59:44 +01:00
2019-02-10 10:45:49 +01:00
$resql = $this->db->query($sql);
2016-04-01 10:52:19 +02:00
if ($resql) {
2019-02-10 10:45:49 +01:00
$num = $this->db->num_rows($resql);
2016-04-01 10:52:19 +02:00
$i = 0;
while ($i < $num) {
2019-02-10 10:45:49 +01:00
$obj = $this->db->fetch_object($resql);
2016-04-01 17:09:03 +02:00
2019-02-10 10:45:49 +01:00
$level = $langs->trans($obj->code);
2021-02-23 18:59:19 +01:00
if ($level == $obj->code) {
2019-02-10 10:45:49 +01:00
$level = $langs->trans($obj->label);
2021-02-23 18:59:19 +01:00
}
2017-12-01 15:39:18 +01:00
$options_array[$obj->code] = $level;
2016-04-01 17:09:03 +02:00
$i++;
2016-04-01 10:52:19 +02:00
}
} else {
2017-12-01 15:39:18 +01:00
dol_print_error($this->db);
2016-04-01 10:52:19 +02:00
}
2017-12-01 15:39:18 +01:00
return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
}
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
/**
* Return combo list of activated countries, into language of user
*
2021-02-23 18:59:19 +01:00
* @param string $htmlname of html select object
* @param string[] $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
*
* @param string $htmlname of html select object
* @param string[] $selected_array or Code or Label of preselected country
2021-02-23 18:59:19 +01:00
* @return string HTML string with select
2016-04-01 10:52:19 +02:00
*/
public function multiselectCountry($htmlname = 'country_id', $selected_array = array())
{
2016-04-01 10:52:19 +02:00
global $conf, $langs;
2016-04-01 17:09:03 +02:00
2016-05-08 11:33:46 +02:00
$langs->load("dict");
$maxlength = 0;
2017-07-11 14:47:37 +02:00
2016-04-01 10:52:19 +02:00
$out = '';
2016-05-08 11:33:46 +02:00
$countryArray = array();
$label = array();
2016-04-01 17:09:03 +02:00
2016-05-08 11:33:46 +02:00
$options_array = array();
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
$sql = "SELECT rowid, code as code_iso, label";
$sql .= " FROM ".MAIN_DB_PREFIX."c_country";
2016-04-01 10:52:19 +02:00
$sql .= " WHERE active = 1 AND code<>''";
$sql .= " ORDER BY code ASC";
2016-04-01 17:09:03 +02:00
2016-05-08 11:33:46 +02:00
$resql = $this->db->query($sql);
2016-04-01 10:52:19 +02:00
if ($resql) {
2016-05-08 11:33:46 +02:00
$num = $this->db->num_rows($resql);
2016-04-01 10:52:19 +02:00
$i = 0;
if ($num) {
$foundselected = false;
2016-04-01 17:09:03 +02:00
2016-05-08 11:33:46 +02:00
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
2016-04-01 10:52:19 +02:00
$countryArray [$i] ['rowid'] = $obj->rowid;
$countryArray [$i] ['code_iso'] = $obj->code_iso;
$countryArray [$i] ['label'] = ($obj->code_iso && $langs->transnoentitiesnoconv("Country".$obj->code_iso) != "Country".$obj->code_iso ? $langs->transnoentitiesnoconv("Country".$obj->code_iso) : ($obj->label != '-' ? $obj->label : ''));
2016-05-08 11:33:46 +02:00
$label[$i] = $countryArray[$i]['label'];
$i++;
2016-04-01 10:52:19 +02:00
}
2016-04-01 17:09:03 +02:00
2022-06-03 14:14:53 +02:00
$array1_sort_order = SORT_ASC;
array_multisort($label, $array1_sort_order, $countryArray);
2016-04-01 17:09:03 +02:00
2016-05-08 11:33:46 +02:00
foreach ($countryArray as $row) {
$label = dol_trunc($row['label'], $maxlength, 'middle');
2021-02-23 18:59:19 +01:00
if ($row['code_iso']) {
$label .= ' ('.$row['code_iso'].')';
2021-02-23 18:59:19 +01:00
}
2016-04-01 17:09:03 +02:00
2016-05-08 11:33:46 +02:00
$options_array[$row['rowid']] = $label;
2016-04-01 10:52:19 +02:00
}
}
} else {
2016-05-08 11:33:46 +02:00
dol_print_error($this->db);
2016-04-01 10:52:19 +02:00
}
2016-04-01 17:09:03 +02:00
2016-05-08 11:33:46 +02:00
return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
}
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
/**
* Return select list for categories (to use in form search selectors)
*
2016-04-04 15:28:25 +02:00
* @param string $htmlname control name
* @param string[] $selected_array array of data
2016-04-04 15:28:25 +02:00
* @param User $user User action
2016-04-01 10:52:19 +02:00
* @return string combo list code
*/
public function multiselectselectSalesRepresentatives($htmlname, $selected_array, $user)
{
2016-04-01 10:52:19 +02:00
global $conf;
2016-04-01 17:09:03 +02:00
$options_array = array();
2016-04-01 17:09:03 +02:00
$sql_usr = '';
2016-04-01 10:52:19 +02:00
$sql_usr .= "SELECT DISTINCT u2.rowid, u2.lastname as name, u2.firstname, u2.login";
$sql_usr .= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql_usr .= " WHERE u2.entity IN (0,".$conf->entity.")";
2024-01-09 13:08:22 +01:00
$sql_usr .= " AND u2.rowid = sc.fk_user";
2023-11-27 11:39:32 +01:00
if (getDolGlobalString('USER_HIDE_INACTIVE_IN_COMBOBOX')) {
2024-01-09 13:08:22 +01:00
$sql_usr .= " AND u2.statut <> 0";
2021-02-23 18:59:19 +01:00
}
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 15:58:49 +01:00
if (getDolGlobalString('USER_HIDE_NONEMPLOYEE_IN_COMBOBOX')) {
2023-08-30 17:08:57 +02:00
$sql_usr .= " AND u2.employee<>0 ";
}
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 15:58:49 +01:00
if (getDolGlobalString('USER_HIDE_EXTERNAL_IN_COMBOBOX')) {
$sql_usr .= " AND u2.fk_soc IS NULL ";
}
2016-04-01 10:52:19 +02:00
$sql_usr .= " ORDER BY name ASC";
// print $sql_usr;exit;
2016-04-01 17:09:03 +02:00
$resql_usr = $this->db->query($sql_usr);
2016-04-01 10:52:19 +02:00
if ($resql_usr) {
while ($obj_usr = $this->db->fetch_object($resql_usr)) {
$label = $obj_usr->firstname." ".$obj_usr->name." (".$obj_usr->login.')';
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
$options_array [$obj_usr->rowid] = $label;
}
$this->db->free($resql_usr);
2016-04-01 10:52:19 +02:00
} else {
dol_print_error($this->db);
2016-04-01 10:52:19 +02:00
}
2016-04-01 17:09:03 +02:00
return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
}
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
/**
* Return select list for categories (to use in form search selectors)
*
* @param string $htmlname of combo list (example: 'search_sale')
* @param string[] $selected_array selected array
2016-04-01 10:52:19 +02:00
* @return string combo list code
*/
public function multiselectselectLanguage($htmlname = '', $selected_array = array())
{
global $conf, $langs;
2016-04-01 17:09:03 +02:00
$options_array = array();
2016-04-01 17:09:03 +02:00
$langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 12);
2016-04-01 17:09:03 +02:00
2021-02-23 18:59:19 +01:00
foreach ($langs_available as $key => $value) {
2016-04-01 10:52:19 +02:00
$label = $value;
2016-05-08 11:33:46 +02:00
$options_array[$key] = $label;
2016-04-01 10:52:19 +02:00
}
asort($options_array);
2016-05-08 11:33:46 +02:00
return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
}
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
/**
2024-03-23 15:03:00 +01:00
* Return multiselect list of entities for extrafield type sellist
2016-04-01 10:52:19 +02:00
*
2016-04-04 15:28:25 +02:00
* @param string $htmlname control name
2024-03-23 15:18:44 +01:00
* @param array<string,string> $sqlqueryparam array
* @param string[] $selected_array array
2016-04-01 17:09:03 +02:00
*
* @return string HTML combo
2016-04-01 10:52:19 +02:00
*/
2019-02-27 20:45:07 +01:00
public function advMultiselectarraySelllist($htmlname, $sqlqueryparam = array(), $selected_array = array())
2017-12-01 15:39:18 +01:00
{
$options_array = array();
2016-04-01 17:09:03 +02:00
2021-02-23 18:59:19 +01:00
if (is_array($sqlqueryparam)) {
$param_list = array_keys($sqlqueryparam);
2024-03-24 05:44:36 +01:00
$InfoFieldList = explode(":", $param_list[0], 4);
2016-04-01 17:09:03 +02:00
2024-03-24 05:44:36 +01:00
// 0 1 : Table name
// 1 2 : Name of field that contains the label
// 2 3 : Key fields name (if differ of rowid)
// 3 4 : Where clause filter on column or table extrafield, syntax field='value' or extra.field=value
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
$keyList = 'rowid';
if (count($InfoFieldList) >= 3) {
2021-08-27 22:42:04 +02:00
if (strpos($InfoFieldList[3], 'extra.') !== false) {
$keyList = 'main.'.$InfoFieldList[2].' as rowid';
2016-04-01 10:52:19 +02:00
} else {
2021-08-27 22:42:04 +02:00
$keyList = $InfoFieldList[2].' as rowid';
2016-04-01 10:52:19 +02:00
}
}
2016-04-01 17:09:03 +02:00
2024-03-24 05:44:36 +01:00
$sql = "SELECT ".$this->db->sanitize($keyList).", ".$this->db->sanitize($InfoFieldList[1]);
$sql .= " FROM ".$this->db->sanitize(MAIN_DB_PREFIX.$InfoFieldList[0]);
2021-08-27 22:42:04 +02:00
if (!empty($InfoFieldList[3])) {
2024-03-24 05:44:36 +01:00
$errorstr = '';
2016-04-01 10:52:19 +02:00
// We have to join on extrafield table
2021-08-27 22:42:04 +02:00
if (strpos($InfoFieldList[3], 'extra') !== false) {
2024-03-24 05:44:36 +01:00
$sql .= ' as main, '.$this->db->sanitize(MAIN_DB_PREFIX.$InfoFieldList[0]).'_extrafields as extra';
$sql .= " WHERE extra.fk_object = main.".$this->db->sanitize(empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2]);
2024-03-24 05:44:36 +01:00
$sql .= " AND ".forgeSQLFromUniversalSearchCriteria($InfoFieldList[3], $errorstr, 1);
2016-04-01 10:52:19 +02:00
} else {
2024-03-24 05:44:36 +01:00
$sql .= " WHERE ".forgeSQLFromUniversalSearchCriteria($InfoFieldList[3], $errorstr, 1);
2016-04-01 10:52:19 +02:00
}
}
if (!empty($InfoFieldList[1])) {
$sql .= $this->db->order($InfoFieldList[1]);
2016-04-01 10:52:19 +02:00
}
// $sql.= ' WHERE entity = '.$conf->entity;
2016-04-01 17:09:03 +02:00
2016-05-08 11:33:46 +02:00
$resql = $this->db->query($sql);
2016-04-01 10:52:19 +02:00
if ($resql) {
2016-05-08 11:33:46 +02:00
$num = $this->db->num_rows($resql);
2016-04-01 10:52:19 +02:00
$i = 0;
if ($num) {
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
2024-03-24 05:44:36 +01:00
$fieldtoread = $InfoFieldList[1];
$labeltoshow = dol_trunc($obj->$fieldtoread, 90);
$options_array[$obj->rowid] = $labeltoshow;
$i++;
2016-04-01 10:52:19 +02:00
}
}
$this->db->free($resql);
2016-04-01 10:52:19 +02:00
}
}
2016-04-01 17:09:03 +02:00
2016-05-08 11:33:46 +02:00
return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
2016-04-01 10:52:19 +02:00
}
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
/**
* Return combo list with people title
*
2016-05-08 11:33:46 +02:00
* @param string $htmlname Name of HTML select combo field
* @param string[] $selected_array Array
2016-05-08 11:33:46 +02:00
* @return string HTML combo
2016-04-01 10:52:19 +02:00
*/
2019-02-27 20:45:07 +01:00
public function multiselectCivility($htmlname = 'civilite_id', $selected_array = array())
2016-04-01 10:52:19 +02:00
{
global $conf, $langs, $user;
2016-04-01 10:52:19 +02:00
$langs->load("dict");
2016-04-01 17:09:03 +02:00
$options_array = array();
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
$sql = "SELECT rowid, code, label as civilite, active FROM ".MAIN_DB_PREFIX."c_civility";
$sql .= " WHERE active = 1";
2016-04-01 17:09:03 +02:00
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
2021-02-23 18:59:19 +01:00
if ($resql) {
2016-04-01 10:52:19 +02:00
$num = $this->db->num_rows($resql);
$i = 0;
2021-02-23 18:59:19 +01:00
if ($num) {
while ($i < $num) {
2016-04-01 10:52:19 +02:00
$obj = $this->db->fetch_object($resql);
2022-01-18 13:44:52 +01:00
// If a translation exists, we use it, else we use the default label
$label = ($langs->trans("Civility".$obj->code) != "Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->civilite != '-' ? $obj->civilite : ''));
2016-04-01 17:09:03 +02:00
$options_array[$obj->code] = $label;
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
$i++;
}
}
2020-05-21 15:05:19 +02:00
} else {
2016-04-01 10:52:19 +02:00
dol_print_error($this->db);
}
2016-04-01 17:09:03 +02:00
return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
2016-04-01 10:52:19 +02:00
}
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
/**
* Return multiselect list of entities.
*
* @param string $htmlname select
* @param array<string,mixed> $options_array to manage
* @param string[] $selected_array to manage
2016-04-01 10:52:19 +02:00
* @param int $showempty show empty
2016-04-01 17:09:03 +02:00
* @return string HTML combo
2016-04-01 10:52:19 +02:00
*/
public function advMultiselectarray($htmlname, $options_array = array(), $selected_array = array(), $showempty = 0)
{
2016-04-01 10:52:19 +02:00
global $conf, $langs;
2016-04-01 17:09:03 +02:00
$form = new Form($this->db);
foreach ($options_array as $okey => $val) {
if ((string) $okey == '') {
continue;
}
$valarray = explode('|', $val);
$val = $valarray[0];
if ($val) {
$options_array[$okey] = $langs->trans($val);
} else {
$options_array[$okey] = $val;
}
}
$return = $form->multiselectarray($htmlname, $options_array, $selected_array, 0, 0, '', 0, 295);
2016-04-01 10:52:19 +02:00
return $return;
}
2016-04-01 17:09:03 +02:00
/**
2018-06-24 17:55:03 +02:00
* Return a combo list to select emailing target selector
2016-04-01 17:09:03 +02:00
*
2018-06-24 17:55:03 +02:00
* @param string $htmlname control name
* @param integer $selected default selected
2018-06-24 17:55:03 +02:00
* @param integer $showempty empty lines
* @param string $type_element Type element. Example: 'mailing'
* @param string $morecss More CSS
2018-06-24 17:55:03 +02:00
* @return string HTML combo
2016-04-01 17:09:03 +02:00
*/
public function selectAdvtargetemailingTemplate($htmlname = 'template_id', $selected = 0, $showempty = 0, $type_element = 'mailing', $morecss = '')
{
2016-04-01 10:52:19 +02:00
$out = '';
2016-04-01 17:09:03 +02:00
2024-10-24 01:12:58 +02:00
$sql = "SELECT c.rowid, c.name, c.fk_element as elementid";
$sql .= " FROM ".MAIN_DB_PREFIX."mailing_advtarget as c";
2021-04-30 10:57:21 +02:00
$sql .= " WHERE type_element = '".$this->db->escape($type_element)."'";
2016-04-01 10:52:19 +02:00
$sql .= " ORDER BY c.name";
2016-04-01 17:09:03 +02:00
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
2016-04-01 10:52:19 +02:00
if ($resql) {
$out .= '<select id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">';
2021-02-23 18:59:19 +01:00
if ($showempty) {
2016-04-01 10:52:19 +02:00
$out .= '<option value=""></option>';
2021-02-23 18:59:19 +01:00
}
$num = $this->db->num_rows($resql);
2016-04-01 10:52:19 +02:00
$i = 0;
if ($num) {
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
2016-04-01 10:52:19 +02:00
$label = $obj->name;
if (empty($label)) {
2024-10-24 01:12:58 +02:00
$label = (string) $obj->elementid;
2016-04-01 10:52:19 +02:00
}
2016-04-01 17:09:03 +02:00
2016-04-01 10:52:19 +02:00
if ($selected > 0 && $selected == $obj->rowid) {
$out .= '<option value="'.$obj->rowid.'" selected="selected">'.$label.'</option>';
2016-04-01 10:52:19 +02:00
} else {
$out .= '<option value="'.$obj->rowid.'">'.$label.'</option>';
2016-04-01 10:52:19 +02:00
}
$i++;
2016-04-01 10:52:19 +02:00
}
}
$out .= '</select>';
} else {
dol_print_error($this->db);
2016-04-01 10:52:19 +02:00
}
2024-10-24 01:12:58 +02:00
$this->db->free($resql);
2024-10-24 01:12:58 +02:00
2016-04-01 10:52:19 +02:00
return $out;
}
2018-08-15 14:28:34 +02:00
}