dolibarr/htdocs/core/modules/mailings/contacts1.modules.php

491 lines
17 KiB
PHP
Raw Permalink Normal View History

<?php
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
2018-10-27 14:43:12 +02:00
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
2025-01-05 18:12:36 +01:00
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
*
* 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/>.
* or see https://www.gnu.org/
*/
/**
* \file htdocs/core/modules/mailings/contacts1.modules.php
* \ingroup mailing
* \brief File of class to offer a selector of emailing targets with Rule 'Poire'.
*/
include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
/**
2017-08-25 21:12:22 +02:00
* Class to offer a selector of emailing targets from contacts
*/
class mailing_contacts1 extends MailingTargets
{
public $name = 'ContactCompanies'; // Identifiant du module mailing
2017-01-29 14:53:05 +01:00
// This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
public $desc = 'Contacts of thirdparties (prospects, customers, suppliers...)';
public $require_module = array("societe"); // Module mailing actif si modules require_module actifs
public $require_admin = 0; // Module mailing actif pour user admin ou non
2019-10-30 09:58:19 +01:00
/**
* @var string condition to enable module
*/
2022-11-29 01:23:46 +01:00
public $enabled = 'isModEnabled("societe")';
2019-10-30 09:48:34 +01:00
/**
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
*/
public $picto = 'contact';
2017-08-25 21:12:22 +02:00
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
$this->db = $db;
}
/**
2011-11-13 11:45:25 +01:00
* On the main mailing area, there is a box with statistics.
* If you want to add a line in this report you must provide an
* array of SQL request that returns two field:
* One called "label", One called "nb".
*
* @return string[] Array with SQL requests
2011-11-13 11:45:25 +01:00
*/
public function getSqlArrayForStats()
{
2024-01-11 14:37:32 +01:00
global $langs;
$langs->load("commercial");
$statssql = array();
2020-09-19 22:41:05 +02:00
$statssql[0] = "SELECT '".$this->db->escape($langs->trans("NbOfCompaniesContacts"))."' as label,";
$statssql[0] .= " count(distinct(c.email)) as nb";
$statssql[0] .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
$statssql[0] .= " WHERE c.entity IN (".getEntity('contact').")";
2021-10-23 22:27:29 +02:00
$statssql[0] .= " AND c.email <> ''"; // Note that null != '' is false
$statssql[0] .= " AND c.statut = 1";
return $statssql;
}
/**
2012-01-10 10:23:57 +01:00
* Return here number of distinct emails returned by your selector.
* For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500.
*
2022-05-29 09:58:36 +02:00
* @param string $sql Requete sql de comptage
* @return int|string Nb of recipient, or <0 if error, or '' if NA
*/
public function getNbOfRecipients($sql = '')
{
2023-11-30 17:45:41 +01:00
global $conf;
$sql = "SELECT count(distinct(c.email)) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = c.fk_soc";
$sql .= " WHERE c.entity IN (".getEntity('contact').")";
2021-10-23 22:27:29 +02:00
$sql .= " AND c.email <> ''"; // Note that null != '' is false
2023-04-08 17:16:22 +02:00
if (empty($this->evenunsubscribe)) {
$sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = c.email and mu.entity = ".((int) $conf->entity).")";
}
// exclude unsubscribed users
$sql .= " AND c.statut = 1";
2017-08-25 21:12:22 +02:00
// The request must return a field called "nb" to be understandable by parent::getNbOfRecipients
return parent::getNbOfRecipients($sql);
}
/**
2012-01-10 10:23:57 +01:00
* Affiche formulaire de filtre qui apparait dans page de selection des destinataires de mailings
*
* @return string Retourne zone select
*/
public function formFilter()
{
global $conf,$langs;
2018-09-12 15:09:12 +02:00
// Load translation files required by the page
$langs->loadLangs(array("commercial", "companies", "suppliers", "categories"));
$s = '';
2017-08-25 21:12:22 +02:00
// Add filter on job position
$sql = "SELECT sp.poste, count(distinct(sp.email)) AS nb";
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
$sql .= " WHERE sp.entity IN (".getEntity('contact').")";
2021-10-23 22:27:29 +02:00
$sql .= " AND sp.email <> ''"; // Note that null != '' is false
$sql .= " AND sp.statut = 1";
2021-10-23 22:27:29 +02:00
$sql .= " AND (sp.poste IS NOT NULL AND sp.poste <> '')";
$sql .= " GROUP BY sp.poste";
$sql .= " ORDER BY sp.poste";
2017-08-25 21:12:22 +02:00
$resql = $this->db->query($sql);
2023-02-10 23:11:47 +01:00
$s .= '<select id="filter_jobposition_contact" name="filter_jobposition" class="flat maxwidth200" placeholder="'.dol_escape_htmltag($langs->trans("PostOrFunction")).'">';
2022-01-31 12:02:48 +01:00
$s .= '<option value="-1">'.$langs->trans("PostOrFunction").'</option>';
2021-02-23 22:03:23 +01:00
if ($resql) {
2017-08-25 21:12:22 +02:00
$num = $this->db->num_rows($resql);
$i = 0;
2021-07-31 17:20:48 +02:00
if ($num > 0) {
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$s .= '<option value="'.dol_escape_htmltag($obj->poste).'">'.dol_escape_htmltag($obj->poste).' ('.$obj->nb.')</option>';
$i++;
}
} else {
$s .= '<option disabled="disabled" value="">'.$langs->trans("None").'</option>';
2017-08-25 21:12:22 +02:00
}
2021-02-23 22:03:23 +01:00
} else {
dol_print_error($this->db);
2017-08-25 21:12:22 +02:00
}
$s .= '</select>';
2022-01-31 12:02:48 +01:00
$s .= ajax_combobox("filter_jobposition_contact");
$s .= ' ';
2017-08-25 21:12:22 +02:00
// Filter on contact category
$sql = "SELECT c.label, count(distinct(sp.email)) AS nb";
$sql .= " FROM ";
$sql .= " ".MAIN_DB_PREFIX."socpeople as sp,";
$sql .= " ".MAIN_DB_PREFIX."categorie as c,";
$sql .= " ".MAIN_DB_PREFIX."categorie_contact as cs";
$sql .= " WHERE sp.entity IN (".getEntity('contact').")";
2021-10-23 22:27:29 +02:00
$sql .= " AND sp.email <> ''"; // Note that null != '' is false
$sql .= " AND sp.statut = 1";
$sql .= " AND cs.fk_categorie = c.rowid";
$sql .= " AND cs.fk_socpeople = sp.rowid";
$sql .= " GROUP BY c.label";
$sql .= " ORDER BY c.label";
2017-08-25 21:12:22 +02:00
$resql = $this->db->query($sql);
2023-02-10 23:11:47 +01:00
$s .= '<select id="filter_category_contact" name="filter_category" class="flat maxwidth200">';
2022-01-31 12:02:48 +01:00
$s .= '<option value="-1">'.$langs->trans("ContactCategoriesShort").'</option>';
2021-02-23 22:03:23 +01:00
if ($resql) {
2017-08-25 21:12:22 +02:00
$num = $this->db->num_rows($resql);
2021-02-23 22:03:23 +01:00
if ($num) {
2017-08-25 21:12:22 +02:00
$i = 0;
2021-02-23 22:03:23 +01:00
while ($i < $num) {
2017-08-25 21:12:22 +02:00
$obj = $this->db->fetch_object($resql);
$s .= '<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>';
2017-08-25 21:12:22 +02:00
$i++;
}
2020-05-21 15:05:19 +02:00
} else {
$s .= '<option value="-1" disabled="disabled">'.$langs->trans("NoContactWithCategoryFound").'</option>';
2017-08-25 21:12:22 +02:00
}
2021-02-23 22:03:23 +01:00
} else {
dol_print_error($this->db);
2017-08-25 21:12:22 +02:00
}
$s .= '</select>';
2022-01-31 12:02:48 +01:00
$s .= ajax_combobox("filter_category_contact");
$s .= '<br>';
2017-08-25 21:12:22 +02:00
// Add prospect of a particular level
2023-02-10 23:11:47 +01:00
$s .= '<select id="filter_contact" name="filter" class="flat maxwidth200">';
$sql = "SELECT code, label";
$sql .= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
$sql .= " WHERE active > 0";
$sql .= " ORDER BY label";
$resql = $this->db->query($sql);
2021-02-23 22:03:23 +01:00
if ($resql) {
$num = $this->db->num_rows($resql);
2021-02-23 22:03:23 +01:00
if ($num) {
2022-01-31 12:02:48 +01:00
$s .= '<option value="-1">'.$langs->trans("NatureOfThirdParty").'</option>';
2021-02-23 22:03:23 +01:00
} else {
2022-01-31 12:02:48 +01:00
$s .= '<option value="-1">'.$langs->trans("ContactsAllShort").'</option>';
2021-02-23 22:03:23 +01:00
}
$s .= '<option value="prospects">'.$langs->trans("ThirdPartyProspects").'</option>';
$i = 0;
2021-02-23 22:03:23 +01:00
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$level = $langs->trans($obj->code);
2021-02-23 22:03:23 +01:00
if ($level == $obj->code) {
$level = $langs->trans($obj->label);
}
$labeltoshow = $langs->trans("ThirdPartyProspects").' <span class="opacitymedium">('.$langs->trans("ProspectLevelShort").'='.$level.')</span>';
$s .= '<option value="prospectslevel'.$obj->code.'" data-html="'.dol_escape_htmltag($labeltoshow).'">'.$labeltoshow.'</option>';
$i++;
}
2021-02-23 22:03:23 +01:00
} else {
dol_print_error($this->db);
}
$s .= '<option value="customers">'.$langs->trans("ThirdPartyCustomers").'</option>';
//$s.='<option value="customersidprof">'.$langs->trans("ThirdPartyCustomersWithIdProf12",$langs->trans("ProfId1"),$langs->trans("ProfId2")).'</option>';
$s .= '<option value="suppliers">'.$langs->trans("ThirdPartySuppliers").'</option>';
$s .= '</select>';
2022-01-31 12:02:48 +01:00
$s .= ajax_combobox("filter_contact");
2017-08-25 21:12:22 +02:00
$s .= ' ';
2017-08-25 21:12:22 +02:00
// Filter on thirdparty category
$sql = "SELECT c.label, count(distinct(sp.email)) AS nb";
$sql .= " FROM ";
$sql .= " ".MAIN_DB_PREFIX."socpeople as sp,";
$sql .= " ".MAIN_DB_PREFIX."categorie as c,";
$sql .= " ".MAIN_DB_PREFIX."categorie_societe as cs";
$sql .= " WHERE sp.entity IN (".getEntity('contact').")";
2021-10-23 22:27:29 +02:00
$sql .= " AND sp.email <> ''"; // Note that null != '' is false
$sql .= " AND sp.statut = 1";
$sql .= " AND cs.fk_categorie = c.rowid";
$sql .= " AND cs.fk_soc = sp.fk_soc";
$sql .= " GROUP BY c.label";
$sql .= " ORDER BY c.label";
2017-08-25 21:12:22 +02:00
$resql = $this->db->query($sql);
2022-01-31 12:02:48 +01:00
$s .= '<select id="filter_category_customer_contact" name="filter_category_customer" class="flat maxwidth200">';
$s .= '<option value="-1">'.$langs->trans("CustomersProspectsCategoriesShort").'</option>';
2021-02-23 22:03:23 +01:00
if ($resql) {
2017-08-25 21:12:22 +02:00
$num = $this->db->num_rows($resql);
2021-02-23 22:03:23 +01:00
if ($num) {
2017-08-25 21:12:22 +02:00
$i = 0;
2021-02-23 22:03:23 +01:00
while ($i < $num) {
2017-08-25 21:12:22 +02:00
$obj = $this->db->fetch_object($resql);
$s .= '<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>';
2017-08-25 21:12:22 +02:00
$i++;
}
2020-05-21 15:05:19 +02:00
} else {
$s .= '<option value="-1" disabled="disabled">'.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").'</option>';
2017-08-25 21:12:22 +02:00
}
2021-02-23 22:03:23 +01:00
} else {
dol_print_error($this->db);
2017-08-25 21:12:22 +02:00
}
$s .= '</select>';
2022-01-31 12:02:48 +01:00
$s .= ajax_combobox("filter_category_customer_contact");
2017-08-25 21:12:22 +02:00
$s .= ' ';
2017-08-25 21:12:22 +02:00
// Filter on thirdparty category
$sql = "SELECT c.label, count(distinct(sp.email)) AS nb";
$sql .= " FROM ";
$sql .= " ".MAIN_DB_PREFIX."socpeople as sp,";
$sql .= " ".MAIN_DB_PREFIX."categorie as c,";
$sql .= " ".MAIN_DB_PREFIX."categorie_fournisseur as cs";
$sql .= " WHERE sp.entity IN (".getEntity('contact').")";
2021-10-23 22:27:29 +02:00
$sql .= " AND sp.email <> ''"; // Note that null != '' is false
$sql .= " AND sp.statut = 1";
$sql .= " AND cs.fk_categorie = c.rowid";
$sql .= " AND cs.fk_soc = sp.fk_soc";
$sql .= " GROUP BY c.label";
$sql .= " ORDER BY c.label";
2017-08-25 21:12:22 +02:00
$resql = $this->db->query($sql);
2022-01-31 12:02:48 +01:00
$s .= '<select id="filter_category_supplier_contact" name="filter_category_supplier" class="flat maxwidth200">';
$s .= '<option value="-1">'.$langs->trans("SuppliersCategoriesShort").'</option>';
2021-02-23 22:03:23 +01:00
if ($resql) {
2017-08-25 21:12:22 +02:00
$num = $this->db->num_rows($resql);
2021-02-23 22:03:23 +01:00
if ($num) {
2017-08-25 21:12:22 +02:00
$i = 0;
2021-02-23 22:03:23 +01:00
while ($i < $num) {
2017-08-25 21:12:22 +02:00
$obj = $this->db->fetch_object($resql);
$s .= '<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>';
2017-08-25 21:12:22 +02:00
$i++;
}
2020-05-21 15:05:19 +02:00
} else {
$s .= '<option value="-1" disabled="disabled">'.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").'</option>';
2017-08-25 21:12:22 +02:00
}
2021-02-23 22:03:23 +01:00
} else {
dol_print_error($this->db);
2017-08-25 21:12:22 +02:00
}
$s .= '</select>';
2017-08-25 21:12:22 +02:00
2022-01-31 12:02:48 +01:00
$s .= ajax_combobox("filter_category_supplier_contact");
2022-04-22 14:49:22 +02:00
// Choose language
if (getDolGlobalInt('MAIN_MULTILANGS')) {
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
$formadmin = new FormAdmin($this->db);
2023-04-24 01:32:47 +02:00
$s .= img_picto($langs->trans("DefaultLang"), 'language', 'class="pictofixedwidth"');
2025-01-05 18:12:36 +01:00
$s .= $formadmin->select_language(GETPOST('filter_lang', 'aZ09'), 'filter_lang', 0, array(), $langs->trans("DefaultLang"), 0, 0, '', 0, 0, 0, array(), 1);
}
2022-04-22 14:49:22 +02:00
return $s;
}
/**
* Provide the URL to the car of the source information of the recipient for the mailing
2012-01-10 10:23:57 +01:00
*
* @param int $id ID
* @return string URL link
*/
public function url($id)
{
return '<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$id.'">'.img_object('', "contact").'</a>';
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
2023-04-08 17:16:22 +02:00
* Add some recipients into target table
2012-01-10 10:23:57 +01:00
*
2018-09-06 21:27:18 +02:00
* @param int $mailing_id Id of emailing
2023-12-06 15:46:39 +01:00
* @return int Return integer <0 si erreur, nb ajout si ok
*/
public function add_to_target($mailing_id)
{
// phpcs:enable
global $conf, $langs;
$filter = GETPOST('filter', 'alpha');
$filter_jobposition = GETPOST('filter_jobposition', 'alpha');
$filter_category = GETPOST('filter_category', 'alpha');
$filter_category_customer = GETPOST('filter_category_customer', 'alpha');
$filter_category_supplier = GETPOST('filter_category_supplier', 'alpha');
2022-04-22 14:49:22 +02:00
$filter_lang = GETPOST('filter_lang', 'alpha');
2017-08-25 21:12:22 +02:00
$cibles = array();
// List prospects levels
$prospectlevel = array();
$sql = "SELECT code, label";
$sql .= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
$sql .= " WHERE active > 0";
$sql .= " ORDER BY label";
$resql = $this->db->query($sql);
2021-02-23 22:03:23 +01:00
if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
2021-02-23 22:03:23 +01:00
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$prospectlevel[$obj->code] = $obj->label;
$i++;
}
2021-02-23 22:03:23 +01:00
} else {
dol_print_error($this->db);
}
2017-08-25 21:12:22 +02:00
// Request must return: id, email, fk_contact, lastname, firstname, other
$sql = "SELECT sp.rowid as id, sp.email as email, sp.rowid as fk_contact, sp.lastname, sp.firstname, sp.civility as civility_id, sp.poste as jobposition,";
$sql .= " s.nom as companyname";
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = sp.fk_soc";
2022-01-31 12:02:48 +01:00
if ($filter_category != 'all' && $filter_category != '-1') {
2021-02-23 22:03:23 +01:00
$sql .= ", ".MAIN_DB_PREFIX."categorie as c";
$sql .= ", ".MAIN_DB_PREFIX."categorie_contact as cs";
}
2022-01-31 12:02:48 +01:00
if ($filter_category_customer != 'all' && $filter_category_customer != '-1') {
2021-02-23 22:03:23 +01:00
$sql .= ", ".MAIN_DB_PREFIX."categorie as c2";
$sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c2s";
}
2022-01-31 12:02:48 +01:00
if ($filter_category_supplier != 'all' && $filter_category_supplier != '-1') {
2021-02-23 22:03:23 +01:00
$sql .= ", ".MAIN_DB_PREFIX."categorie as c3";
$sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as c3s";
}
$sql .= " WHERE sp.entity IN (".getEntity('contact').")";
$sql .= " AND sp.email <> ''";
2022-11-29 01:23:46 +01:00
2023-04-08 17:16:22 +02:00
if (empty($this->evenunsubscribe)) {
$sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = sp.email and mu.entity = ".((int) $conf->entity).")";
}
// Exclude unsubscribed email addresses
$sql .= " AND sp.statut = 1";
2021-08-23 18:56:46 +02:00
$sql .= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")";
2022-04-29 19:31:05 +02:00
2017-08-25 21:12:22 +02:00
// Filter on category
2022-01-31 12:02:48 +01:00
if ($filter_category != 'all' && $filter_category != '-1') {
2021-02-23 22:03:23 +01:00
$sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid";
$sql .= " AND c.label = '".$this->db->escape($filter_category)."'";
}
2022-01-31 12:02:48 +01:00
if ($filter_category_customer != 'all' && $filter_category_customer != '-1') {
2021-02-23 22:03:23 +01:00
$sql .= " AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc";
$sql .= " AND c2.label = '".$this->db->escape($filter_category_customer)."'";
}
2022-01-31 12:02:48 +01:00
if ($filter_category_supplier != 'all' && $filter_category_supplier != '-1') {
2021-02-23 22:03:23 +01:00
$sql .= " AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc";
$sql .= " AND c3.label = '".$this->db->escape($filter_category_supplier)."'";
}
2022-04-29 19:31:05 +02:00
2022-04-29 17:57:55 +02:00
// Filter on language
if (!empty($filter_lang) && $filter_lang != '-1') {
2022-11-29 01:23:46 +01:00
$sql .= " AND sp.default_lang LIKE '".$this->db->escape($filter_lang)."%'";
2022-04-29 17:57:55 +02:00
}
2022-04-29 19:31:05 +02:00
2022-04-29 17:57:55 +02:00
// Filter on nature
2017-08-25 21:12:22 +02:00
$key = $filter;
2022-01-31 12:02:48 +01:00
//print "xx".$key;
2021-02-23 22:03:23 +01:00
if ($key == 'prospects') {
$sql .= " AND s.client = 2";
2021-02-23 22:03:23 +01:00
}
foreach ($prospectlevel as $codelevel => $valuelevel) {
if ($key == 'prospectslevel'.$codelevel) {
2022-01-31 12:02:48 +01:00
$sql .= " AND s.fk_prospectlevel = '".$this->db->escape($codelevel)."'";
2021-02-23 22:03:23 +01:00
}
}
2021-02-23 22:03:23 +01:00
if ($key == 'customers') {
$sql .= " AND s.client = 1";
2021-02-23 22:03:23 +01:00
}
if ($key == 'suppliers') {
$sql .= " AND s.fournisseur = 1";
}
2022-01-31 12:02:48 +01:00
2017-08-25 21:12:22 +02:00
// Filter on job position
$key = $filter_jobposition;
2022-01-31 12:02:48 +01:00
if (!empty($key) && $key != 'all' && $key != '-1') {
$sql .= " AND sp.poste = '".$this->db->escape($key)."'";
2021-02-23 22:03:23 +01:00
}
2022-01-31 12:02:48 +01:00
$sql .= " ORDER BY sp.email";
//print "wwwwwwx".$sql;
// Store recipients in target tables
$result = $this->db->query($sql);
2021-02-23 22:03:23 +01:00
if ($result) {
$num = $this->db->num_rows($result);
$i = 0;
$j = 0;
dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
$old = '';
2021-02-23 22:03:23 +01:00
while ($i < $num) {
$obj = $this->db->fetch_object($result);
2023-12-27 12:12:20 +01:00
if ($old != $obj->email) {
$cibles[$j] = array(
2021-02-23 22:03:23 +01:00
'email' => $obj->email,
'fk_contact' => (int) $obj->fk_contact,
2021-02-23 22:03:23 +01:00
'lastname' => $obj->lastname,
'firstname' => $obj->firstname,
'other' =>
($langs->transnoentities("ThirdParty").'='.$obj->companyname).';'.
($langs->transnoentities("UserTitle").'='.($obj->civility_id ? $langs->transnoentities("Civility".$obj->civility_id) : '')).';'.
2023-02-11 12:28:23 +01:00
($langs->transnoentities("PostOrFunction").'='.$obj->jobposition),
2021-02-23 22:03:23 +01:00
'source_url' => $this->url($obj->id),
'source_id' => (int) $obj->id,
2021-02-23 22:03:23 +01:00
'source_type' => 'contact'
);
$old = $obj->email;
$j++;
}
$i++;
}
2020-05-21 15:05:19 +02:00
} else {
dol_syslog($this->db->error());
$this->error = $this->db->error();
return -1;
}
2023-12-04 12:07:31 +01:00
return parent::addTargetsToDatabase($mailing_id, $cibles);
}
}