diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php
index 6e917010b51..9669d8c0ff3 100644
--- a/htdocs/comm/mailing/cibles.php
+++ b/htdocs/comm/mailing/cibles.php
@@ -91,8 +91,7 @@ if ($action == 'add')
{
require_once $file;
- // We fill $filtersarray. Using this variable is now deprecated.
- // Kept for backward compatibility.
+ // We fill $filtersarray. Using this variable is now deprecated. Kept for backward compatibility.
$filtersarray=array();
if (isset($_POST["filter"])) $filtersarray[0]=$_POST["filter"];
@@ -157,11 +156,13 @@ if ($action == 'delete')
}
}
-if ($_POST["button_removefilter"])
+// Purge search criteria
+if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
{
$search_lastname='';
$search_firstname='';
$search_email='';
+ $search_other='';
$search_dest_status='';
}
@@ -304,12 +305,10 @@ if ($object->fetch($id) >= 0)
if ($qualified)
{
$var = !$var;
- //print '
';
-// print '';
if ($allowaddtarget)
{
- print '
';
- //print '';
print '';
if ($allowaddtarget)
{
@@ -361,10 +355,8 @@ if ($object->fetch($id) >= 0)
if ($filter) print $filter;
else print $langs->trans("None");
}
- //print '
';
print '';
- //print '';
print '';
if ($allowaddtarget)
{
@@ -376,19 +368,14 @@ if ($object->fetch($id) >= 0)
//print $langs->trans("MailNoChangePossible");
print " ";
}
- //print '
';
print '';
if ($allowaddtarget) print '';
else print '';
-
- //print " \n";
-// print ''."\n";
}
}
} // End foreach dir
- //print '';
print '';
print ' ';
diff --git a/htdocs/core/modules/mailings/contacts1.modules.php b/htdocs/core/modules/mailings/contacts1.modules.php
index 0e4966a5ada..51cca978ca6 100644
--- a/htdocs/core/modules/mailings/contacts1.modules.php
+++ b/htdocs/core/modules/mailings/contacts1.modules.php
@@ -28,8 +28,7 @@ include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
/**
- * \class mailing_contacts1
- * \brief Class to offer a selector of emailing targets with Rule 'Poire'.
+ * Class to offer a selector of emailing targets from contacts
*/
class mailing_contacts1 extends MailingTargets
{
@@ -39,7 +38,7 @@ class mailing_contacts1 extends MailingTargets
var $require_module=array("societe"); // Module mailing actif si modules require_module actifs
var $require_admin=0; // Module mailing actif pour user admin ou non
var $picto='contact';
-
+
var $db;
@@ -101,8 +100,7 @@ class mailing_contacts1 extends MailingTargets
$sql.= " AND c.no_email = 0";
$sql.= " AND c.statut = 1";
- // La requete doit retourner un champ "nb" pour etre comprise
- // par parent::getNbOfRecipients
+ // The request must return a field called "nb" to be understandable by parent::getNbOfRecipients
return parent::getNbOfRecipients($sql);
}
@@ -118,10 +116,86 @@ class mailing_contacts1 extends MailingTargets
$langs->load("companies");
$langs->load("commercial");
$langs->load("suppliers");
+ $langs->load("categories");
$s='';
- $s.='';
+
+ // 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('societe').")";
+ /*$sql.= " AND sp.email != ''"; // Note that null != '' is false
+ $sql.= " AND sp.no_email = 0";
+ $sql.= " AND sp.statut = 1";*/
+ $sql.= " AND (sp.poste IS NOT NULL AND sp.poste != '')";
+ $sql.= " GROUP BY sp.poste";
+ $sql.= " ORDER BY sp.poste";
+ $resql = $this->db->query($sql);
+
+ $s.=$langs->trans("PostOrFunction").': ';
+ $s.='';
+ $s.=' ';
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+ $s.=''.dol_escape_htmltag($obj->poste).' ('.$obj->nb.') ';
+ $i++;
+ }
+ }
+ else dol_print_error($this->db);
+ $s.=' ';
+
+ $s.=' ';
+
+ // Filter on contact category
+ $s .= $langs->trans("ContactCategoriesShort").': ';
+ $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.statut = 1"; // Note that null != '' is false
+ //$sql.= " AND sp.no_email = 0";
+ //$sql.= " AND sp.email != ''";
+ //$sql.= " AND sp.entity IN (".getEntity('societe').")";
+ $sql.= " AND cs.fk_categorie = c.rowid";
+ $sql.= " AND cs.fk_socpeople = sp.rowid";
+ $sql.= " GROUP BY c.label";
+ $sql.= " ORDER BY c.label";
+ $resql = $this->db->query($sql);
+
+ $s.='';
+ $s.=' ';
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+ if ($num)
+ {
+ $i = 0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+ $s.=''.$obj->label.' ('.$obj->nb.') ';
+ $i++;
+ }
+ }
+ else
+ {
+ $s.=''.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").' ';
+ }
+ }
+ else dol_print_error($this->db);
+ $s.=' ';
+
+ $s.=' ';
+
// Add prospect of a particular level
+ $s.=$langs->trans("NatureOfThirdParty").': ';
+ $s.='';
$sql = "SELECT code, label";
$sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
$sql.= " WHERE active > 0";
@@ -132,7 +206,7 @@ class mailing_contacts1 extends MailingTargets
$num = $this->db->num_rows($resql);
if ($num) $s.=' ';
else $s.=''.$langs->trans("ContactsAllShort").' ';
- $s.=''.$langs->trans("ThirdPartyProspects").' ';
+ $s.=''.$langs->trans("ThirdPartyProspects").' ';
$i = 0;
while ($i < $num)
@@ -144,10 +218,96 @@ class mailing_contacts1 extends MailingTargets
$i++;
}
}
+ else dol_print_error($this->db);
$s.=''.$langs->trans("ThirdPartyCustomers").' ';
//$s.=''.$langs->trans("ThirdPartyCustomersWithIdProf12",$langs->trans("ProfId1"),$langs->trans("ProfId2")).' ';
$s.=''.$langs->trans("ThirdPartySuppliers").' ';
$s.=' ';
+
+ $s.= ' ';
+
+ // Filter on thirdparty category
+ $s .= $langs->trans("CustomersProspectsCategoriesShort").': ';
+ $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.statut = 1"; // Note that null != '' is false
+ //$sql.= " AND sp.no_email = 0";
+ //$sql.= " AND sp.email != ''";
+ //$sql.= " AND sp.entity IN (".getEntity('societe').")";
+ $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";
+ $resql = $this->db->query($sql);
+
+ $s.='';
+ $s.=' ';
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+ if ($num)
+ {
+ $i = 0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+ $s.=''.$obj->label.' ('.$obj->nb.') ';
+ $i++;
+ }
+ }
+ else
+ {
+ $s.=''.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").' ';
+ }
+ }
+ else dol_print_error($this->db);
+ $s.=' ';
+
+ $s.= ' ';
+
+ // Filter on thirdparty category
+ $s .= $langs->trans("SuppliersCategoriesShort").': ';
+ $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.statut = 1"; // Note that null != '' is false
+ //$sql.= " AND sp.no_email = 0";
+ //$sql.= " AND sp.email != ''";
+ //$sql.= " AND sp.entity IN (".getEntity('societe').")";
+ $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";
+ $resql = $this->db->query($sql);
+
+ $s.='';
+ $s.=' ';
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+ if ($num)
+ {
+ $i = 0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+ $s.=''.$obj->label.' ('.$obj->nb.') ';
+ $i++;
+ }
+ }
+ else
+ {
+ $s.=''.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").' ';
+ }
+ }
+ else dol_print_error($this->db);
+ $s.=' ';
+
return $s;
}
@@ -168,13 +328,19 @@ class mailing_contacts1 extends MailingTargets
* Ajoute destinataires dans table des cibles
*
* @param int $mailing_id Id of emailing
- * @param array $filtersarray Requete sql de selection des destinataires
+ * @param array $filtersarray Optional filter data (deprecated)
* @return int <0 si erreur, nb ajout si ok
*/
function add_to_target($mailing_id,$filtersarray=array())
{
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');
+
$cibles = array();
// List prospects levels
@@ -197,27 +363,43 @@ class mailing_contacts1 extends MailingTargets
}
else dol_print_error($this->db);
- // La requete doit retourner: id, email, fk_contact, name, firstname, other
- $sql = "SELECT c.rowid as id, c.email as email, c.rowid as fk_contact,";
- $sql.= " c.lastname, c.firstname, c.civility as civility_id,";
+ // 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 c";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = c.fk_soc";
- $sql.= " WHERE c.entity IN (".getEntity('societe').")";
- $sql.= " AND c.email <> ''";
- $sql.= " AND c.no_email = 0";
- $sql.= " AND c.statut = 1";
- $sql.= " AND c.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
- foreach($filtersarray as $key)
+ $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = sp.fk_soc";
+ if ($filter_category <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c";
+ if ($filter_category <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_contact as cs";
+ if ($filter_category_customer <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c2";
+ if ($filter_category_customer <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as c2s";
+ if ($filter_category_supplier <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c3";
+ if ($filter_category_supplier <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_fournisseur as c3s";
+ $sql.= " WHERE sp.entity IN (".getEntity('societe').")";
+ $sql.= " AND sp.email <> ''";
+ $sql.= " AND sp.no_email = 0";
+ $sql.= " AND sp.statut = 1";
+ $sql.= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
+ // Filter on category
+ if ($filter_category <> 'all') $sql.= " AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid";
+ if ($filter_category <> 'all') $sql.= " AND c.label = '".$this->db->escape($filter_category)."'";
+ if ($filter_category_customer <> 'all') $sql.= " AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc";
+ if ($filter_category_customer <> 'all') $sql.= " AND c2.label = '".$this->db->escape($filter_category_customer)."'";
+ if ($filter_category_supplier <> 'all') $sql.= " AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc";
+ if ($filter_category_supplier <> 'all') $sql.= " AND c3.label = '".$this->db->escape($filter_category_supplier)."'";
+ // Filter on nature
+ $key = $filter;
{
- if ($key == 'prospects') $sql.= " AND s.client=2";
//print "xx".$key;
+ if ($key == 'prospects') $sql.= " AND s.client=2";
foreach($prospectlevel as $codelevel=>$valuelevel) if ($key == 'prospectslevel'.$codelevel) $sql.= " AND s.fk_prospectlevel='".$codelevel."'";
if ($key == 'customers') $sql.= " AND s.client=1";
if ($key == 'suppliers') $sql.= " AND s.fournisseur=1";
}
- $sql.= " ORDER BY c.email";
- //print "x".$sql;
+ // Filter on job position
+ $key = $filter_jobposition;
+ if (! empty($key) && $key != 'all') $sql.= " AND sp.poste ='".$this->db->escape($key)."'";
+ $sql.= " ORDER BY sp.email";
+ //print "wwwwwwx".$sql;
// Stocke destinataires dans cibles
$result=$this->db->query($sql);
@@ -242,8 +424,9 @@ class mailing_contacts1 extends MailingTargets
'firstname' => $obj->firstname,
'other' =>
($langs->transnoentities("ThirdParty").'='.$obj->companyname).';'.
- ($langs->transnoentities("UserTitle").'='.($obj->civility_id?$langs->transnoentities("Civility".$obj->civility_id):'')),
- 'source_url' => $this->url($obj->id),
+ ($langs->transnoentities("UserTitle").'='.($obj->civility_id?$langs->transnoentities("Civility".$obj->civility_id):'')).';'.
+ ($langs->transnoentities("JobPosition").'='.$obj->jobposition),
+ 'source_url' => $this->url($obj->id),
'source_id' => $obj->id,
'source_type' => 'contact'
);
diff --git a/htdocs/core/modules/mailings/contacts2.modules.php b/htdocs/core/modules/mailings/contacts2.modules.php
deleted file mode 100644
index a9c05434cd3..00000000000
--- a/htdocs/core/modules/mailings/contacts2.modules.php
+++ /dev/null
@@ -1,222 +0,0 @@
-
- * Copyright (C) 2013 Regis Houssin
- *
- * 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
- * along with this program. If not, see .
- * or see http://www.gnu.org/
- */
-
-/**
- * \file htdocs/core/modules/mailings/contacts2.modules.php
- * \ingroup mailing
- * \brief Provides a list of recipients for mailing module
- */
-
-include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
-
-
-/**
- * \class mailing_contacts2
- * \brief Class to manage a list of personalised recipients for mailing feature
- */
-class mailing_contacts2 extends MailingTargets
-{
- var $name='ContactsByFunction';
- // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
- var $desc='Add contacts by function';
- var $require_admin=0;
-
- var $require_module=array();
- var $picto='contact';
- var $db;
-
-
- /**
- * Constructor
- *
- * @param DoliDB $db Database handler
- */
- function __construct($db)
- {
- $this->db=$db;
- }
-
-
- /**
- * Renvoie url lien vers fiche de la source du destinataire du mailing
- *
- * @param int $id ID
- * @return string Url lien
- */
- function url($id)
- {
- return ''.img_object('',"contact").' ';
- }
-
- /**
- * This is the main function that returns the array of emails
- *
- * @param int $mailing_id Id of mailing. No need to use it.
- * @param array $filtersarray Function
- * @return int <0 if error, number of emails added if ok
- */
- function add_to_target($mailing_id,$filtersarray=array())
- {
- global $conf,$langs;
-
- $target = array();
-
- // La requete doit retourner: id, email, fk_contact, name, firstname, other
- $sql = "SELECT sp.rowid as id, sp.email as email, sp.rowid as fk_contact,";
- $sql.= " sp.lastname, sp.firstname as firstname, sp.civility as civility_id,";
- $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";
- $sql.= " WHERE sp.entity IN (".getEntity('societe').")";
- $sql.= " AND sp.email <> ''"; // Note that null != '' is false
- $sql.= " AND sp.no_email = 0";
- $sql.= " AND sp.statut = 1";
- //$sql.= " AND sp.poste != ''";
- $sql.= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
- if ($filtersarray[0]<>'all') $sql.= " AND sp.poste ='".$this->db->escape($filtersarray[0])."'";
- $sql.= " ORDER BY sp.lastname, sp.firstname";
- $resql = $this->db->query($sql);
- if ($resql)
- {
- $num = $this->db->num_rows($resql);
- $i = 0;
- while ($i < $num)
- {
- $obj= $this->db->fetch_object($resql);
- $target[] = array(
- 'email' => $obj->email,
- 'fk_contact' => $obj->fk_contact,
- 'lastname' => $obj->lastname,
- 'firstname' => $obj->firstname,
- 'other' =>
- ($langs->transnoentities("ThirdParty").'='.$obj->companyname).';'.
- ($langs->transnoentities("UserTitle").'='.($obj->civility_id?$langs->transnoentities("Civility".$obj->civility_id):'')),
- 'source_url' => $this->url($obj->id),
- 'source_id' => $obj->id,
- 'source_type' => 'contact'
- );
- $i++;
- }
- }
-
- return parent::add_to_target($mailing_id, $target);
- }
-
-
- /**
- * 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 array Array with SQL requests
- */
- function getSqlArrayForStats()
- {
- global $conf;
-
- $statssql=array();
- /*for ($i=0; $i<5; $i++) {
- $statssql[$i] = "SELECT sp.poste as label";
- $statssql[$i].= ", count(distinct(sp.email)) as nb";
- $statssql[$i].= " FROM ".MAIN_DB_PREFIX."socpeople as sp,";
- $statssql[$i].= " ".MAIN_DB_PREFIX."societe as s";
- $statssql[$i].= " WHERE s.rowid = sp.fk_soc";
- $statssql[$i].= " AND sp.email != ''"; // Note that null != '' is false
- $statssql[$i].= " AND (sp.poste IS NOT NULL AND sp.poste != '')";
- $statssql[$i].= " AND sp.entity IN (".getEntity('societe').")";
- $statssql[$i].= " GROUP BY label";
- $statssql[$i].= " ORDER BY nb DESC";
- $statssql[$i].= " LIMIT $i,1";
- }*/
-
- return $statssql;
- }
-
-
- /**
- * Return here number of distinct emails returned by your selector.
- *
- * @param string $sql Requete sql de comptage
- * @return int
- */
- function getNbOfRecipients($sql='')
- {
- global $conf;
-
- // We must report here number of contacts when absolutely no filter selected (so all contacts).
- // Number with a filter are show in the combo list for each filter.
- // If we want a filter "a position is defined", we must add it into formFilter
- $sql = "SELECT count(distinct(sp.email)) as nb";
- $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = sp.fk_soc";
- $sql.= " WHERE sp.entity IN (".getEntity('societe').")";
- $sql.= " AND sp.email != ''"; // Note that null != '' is false
- $sql.= " AND sp.no_email = 0";
- $sql.= " AND sp.statut = 1";
- //$sql.= " AND sp.poste != ''";
- // La requete doit retourner un champ "nb" pour etre comprise
- // par parent::getNbOfRecipients
- return parent::getNbOfRecipients($sql);
- }
-
- /**
- * This is to add a form filter to provide variant of selector
- * If used, the HTML select must be called "filter"
- *
- * @return string A html select zone
- */
- function formFilter()
- {
- global $conf, $langs;
-
- $langs->load("companies");
-
- $sql = "SELECT sp.poste, count(distinct(sp.email)) AS nb";
- $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
- $sql.= " WHERE sp.entity IN (".getEntity('societe').")";
- $sql.= " AND sp.email != ''"; // Note that null != '' is false
- $sql.= " AND sp.no_email = 0";
- $sql.= " AND sp.statut = 1";
- $sql.= " AND (sp.poste IS NOT NULL AND sp.poste != '')";
- $sql.= " GROUP BY sp.poste";
- $sql.= " ORDER BY sp.poste";
-
- $resql = $this->db->query($sql);
-
- $s='';
- $s.='';
- $s.=' ';
- if ($resql)
- {
- $num = $this->db->num_rows($resql);
- $i = 0;
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- $s.=''.$obj->poste.' ('.$obj->nb.') ';
- $i++;
- }
- }
- $s.=' ';
- return $s;
- }
-
-}
-
diff --git a/htdocs/core/modules/mailings/contacts3.modules.php b/htdocs/core/modules/mailings/contacts3.modules.php
deleted file mode 100644
index c16f6869668..00000000000
--- a/htdocs/core/modules/mailings/contacts3.modules.php
+++ /dev/null
@@ -1,250 +0,0 @@
-
- * Copyright (C) 2013 Laurent Destailleur
- *
- * 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
- * along with this program. If not, see .
- * or see http://www.gnu.org/
- */
-
-/**
- * \file htdocs/core/modules/mailings/contacts3.modules.php
- * \ingroup mailing
- * \brief Provides a list of recipients for mailing module
- */
-
-include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
-
-
-/**
- * Class to manage a list of personalised recipients for mailing feature
- */
-class mailing_contacts3 extends MailingTargets
-{
- var $name='ContactsByCompanyCategory';
- // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
- var $desc='Add contacts by company category';
- var $require_admin=0;
-
- var $require_module=array();
- var $picto='contact';
- var $db;
-
-
- /**
- * Constructor
- *
- * @param DoliDB $db Database handler
- */
- function __construct($db)
- {
- $this->db=$db;
- }
-
- /**
- * Renvoie url lien vers fiche de la source du destinataire du mailing
- *
- * @param int $id ID
- * @return string Url lien
- */
- function url($id)
- {
- return ''.img_object('',"contact").' ';
- }
-
- /**
- * This is the main function that returns the array of emails
- *
- * @param int $mailing_id Id of mailing. No need to use it.
- * @param array $filtersarray Category
- * @return int <0 if error, number of emails added if ok
- */
- function add_to_target($mailing_id,$filtersarray=array())
- {
- global $conf,$langs;
-
- $target = array();
-
- // La requete doit retourner: id, email, fk_contact, name, firstname, other
- $sql = "SELECT sp.rowid as id, sp.email as email, sp.rowid as fk_contact,";
- $sql.= " sp.lastname, sp.firstname, sp.civility as civility_id,";
- $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";
- if ($filtersarray[0] <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c";
- if ($filtersarray[0] <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs";
- $sql.= " WHERE sp.email <> ''"; // Note that null != '' is false
- $sql.= " AND sp.no_email = 0";
- $sql.= " AND sp.statut = 1";
- $sql.= " AND sp.entity IN (".getEntity('societe').")";
- $sql.= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
- if ($filtersarray[0] <> 'all') $sql.= " AND cs.fk_categorie = c.rowid";
- if ($filtersarray[0] <> 'all') $sql.= " AND cs.fk_soc = sp.fk_soc";
- if ($filtersarray[0] <> 'all') $sql.= " AND c.label = '".$this->db->escape($filtersarray[0])."'";
- $sql.= " ORDER BY sp.lastname, sp.firstname";
-
- $resql = $this->db->query($sql);
- if ($resql)
- {
- $num = $this->db->num_rows($resql);
- $i = 0;
-
- while ($i < $num)
- {
- $obj= $this->db->fetch_object($resql);
- $target[] = array(
- 'email' => $obj->email,
- 'fk_contact' => $obj->fk_contact,
- 'lastname' => $obj->lastname,
- 'firstname' => $obj->firstname,
- 'other' =>
- ($langs->transnoentities("ThirdParty").'='.$obj->companyname).';'.
- ($langs->transnoentities("UserTitle").'='.($obj->civility_id?$langs->transnoentities("Civility".$obj->civility_id):'')),
- 'source_url' => $this->url($obj->id),
- 'source_id' => $obj->id,
- 'source_type' => 'contact'
- );
- $i++;
- }
- }
-
- return parent::add_to_target($mailing_id, $target);
- }
-
-
- /**
- * 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 array Array with SQL requests
- */
- function getSqlArrayForStats()
- {
- global $conf, $langs;
-
- $statssql=array();
- /*for ($i=0; $i<5; $i++) {
- $statssql[$i] = "SELECT c.label, count(sp.rowid) AS nb";
- $statssql[$i].= " FROM ".MAIN_DB_PREFIX."socpeople as sp,";
- $statssql[$i].= " ".MAIN_DB_PREFIX."societe as s,";
- $statssql[$i].= " ".MAIN_DB_PREFIX."categorie as c,";
- $statssql[$i].= " ".MAIN_DB_PREFIX."categorie_societe as cs";
- $statssql[$i].= " WHERE s.rowid = sp.fk_soc";
- $statssql[$i].= " AND sp.email != ''"; // Note that null != '' is false
- $statssql[$i].= " AND sp.entity IN (".getEntity('societe').")";
- $statssql[$i].= " AND cs.fk_categorie = c.rowid";
- $statssql[$i].= " AND cs.fk_soc = sp.fk_soc";
- $statssql[$i].= " GROUP BY c.label";
- $statssql[$i].= " ORDER BY nb DESC";
- $statssql[$i].= " LIMIT $i,1";
- }*/
-
- return $statssql;
- }
-
-
- /**
- * Return here number of distinct emails returned by your selector.
- *
- * @param string $sql Requete sql de comptage
- * @return int Number of recipients
- */
- function getNbOfRecipients($sql='')
- {
- global $conf;
-
- // We must report here number of contacts when absolutely no filter selected (so all contacts).
- // Number with a filter are show in the combo list for each filter.
- // If we want a filter "is inside at least one category", we must add it into formFilter
- $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('societe').")";
- $sql.= " AND c.email != ''"; // Note that null != '' is false
- $sql.= " AND c.no_email = 0";
- $sql.= " AND c.statut = 1";
- /*
- $sql = "SELECT count(distinct(sp.email)) as nb";
- $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp,";
- $sql.= " ".MAIN_DB_PREFIX."societe as s,";
- $sql.= " ".MAIN_DB_PREFIX."categorie as c,";
- $sql.= " ".MAIN_DB_PREFIX."categorie_societe as cs";
- $sql.= " WHERE s.rowid = sp.fk_soc";
- $sql.= " AND sp.entity IN (".getEntity('societe').")";
- $sql.= " AND sp.email != ''"; // Note that null != '' is false
- $sql.= " AND cs.fk_categorie = c.rowid";
- $sql.= " AND cs.fk_soc = sp.fk_soc";
- */
- // La requete doit retourner un champ "nb" pour etre comprise
- // par parent::getNbOfRecipients
- return parent::getNbOfRecipients($sql);
- }
-
- /**
- * This is to add a form filter to provide variant of selector
- * If used, the HTML select must be called "filter".
- *
- * @return string A html select zone
- */
- function formFilter()
- {
- global $conf, $langs;
-
- $langs->load("companies");
-
- $sql = "SELECT c.label, count(distinct(sp.email)) AS nb";
- $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp,";
- $sql.= " ".MAIN_DB_PREFIX."categorie as c,";
- $sql.= " ".MAIN_DB_PREFIX."categorie_societe as cs";
- $sql.= " WHERE sp.email != ''"; // Note that null != '' is false
- $sql.= " AND sp.no_email = 0";
- $sql.= " AND sp.statut = 1";
- $sql.= " AND sp.entity IN (".getEntity('societe').")";
- $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";
-
- $resql = $this->db->query($sql);
-
- $s='';
- $s.='';
- $s.=' ';
- if ($resql)
- {
- $num = $this->db->num_rows($resql);
- if ($num)
- {
- $i = 0;
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- $s.=''.$obj->label.' ('.$obj->nb.') ';
- $i++;
- }
- }
- else
- {
- $s.=''.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").' ';
- }
- }
- else dol_print_error($this->db);
- $s.=' ';
-
- return $s;
- }
-
-}
-
diff --git a/htdocs/core/modules/mailings/contacts4.modules.php b/htdocs/core/modules/mailings/contacts4.modules.php
deleted file mode 100644
index f4c67874bfb..00000000000
--- a/htdocs/core/modules/mailings/contacts4.modules.php
+++ /dev/null
@@ -1,252 +0,0 @@
-
- * Copyright (C) 2013 Florian HENRY
- *
- * 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
- * along with this program. If not, see .
- * or see http://www.gnu.org/
- */
-
-/**
- * \file htdocs/core/modules/mailings/contacts4.modules.php
- * \ingroup mailing
- * \brief Provides a list of recipients for mailing module
- */
-
-include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
-
-
-/**
- * Class to manage a list of personalised recipients for mailing feature
- */
-class mailing_contacts4 extends MailingTargets
-{
- var $name='ContactsByCategory';
- // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
- var $desc='Add contacts by category';
- var $require_admin=0;
-
- var $require_module=array();
- var $picto='contact';
- var $db;
-
-
- /**
- * Constructor
- *
- * @param DoliDB $db Database handler
- */
- function __construct($db)
- {
- $this->db=$db;
- }
-
- /**
- * Renvoie url lien vers fiche de la source du destinataire du mailing
- *
- * @param int $id ID
- * @return string Url lien
- */
- function url($id)
- {
- return ''.img_object('',"contact").' ';
- }
-
- /**
- * This is the main function that returns the array of emails
- *
- * @param int $mailing_id Id of mailing. No need to use it.
- * @param array $filtersarray Category
- * @return int <0 if error, number of emails added if ok
- */
- function add_to_target($mailing_id,$filtersarray=array())
- {
- global $conf,$langs;
-
- $target = array();
-
- // La requete doit retourner: id, email, fk_contact, name, firstname, other
- $sql = "SELECT sp.rowid as id, sp.email as email, sp.rowid as fk_contact,";
- $sql.= " sp.lastname, sp.firstname, sp.civility as civility_id,";
- $sql.= " s.nom as companyname";
- $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
- if ($filtersarray[0] <> 'all')$sql.= " INNER JOIN ".MAIN_DB_PREFIX."categorie_contact as cs ON cs.fk_socpeople=sp.rowid";
- if ($filtersarray[0] <> 'all') $sql.= " INNER JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = sp.fk_soc";
- $sql.= " WHERE sp.email != ''"; // Note that null != '' is false
- $sql.= " AND sp.no_email = 0";
- $sql.= " AND sp.statut = 1";
- $sql.= " AND sp.entity IN (".getEntity('societe').")";
- if ($filtersarray[0] <> 'all') $sql.= " AND c.label = '".$this->db->escape($filtersarray[0])."'";
- $sql.= " ORDER BY sp.lastname, sp.firstname";
-
- dol_syslog(get_class($this).':: add_to_target',LOG_DEBUG);
- $resql = $this->db->query($sql);
- if ($resql)
- {
- $num = $this->db->num_rows($resql);
- $i = 0;
-
- while ($i < $num)
- {
- $obj= $this->db->fetch_object($resql);
- $target[] = array(
- 'email' => $obj->email,
- 'fk_contact' => $obj->fk_contact,
- 'lastname' => $obj->lastname,
- 'firstname' => $obj->firstname,
- 'other' =>
- ($langs->transnoentities("ThirdParty").'='.$obj->companyname).';'.
- ($langs->transnoentities("UserTitle").'='.($obj->civility_id?$langs->transnoentities("Civility".$obj->civility_id):'')),
- 'source_url' => $this->url($obj->id),
- 'source_id' => $obj->id,
- 'source_type' => 'contact'
- );
- $i++;
- }
- }else {
- $this->error=$this->db->lasterrno();
- return -1;
- }
-
- return parent::add_to_target($mailing_id, $target);
- }
-
-
- /**
- * 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 array Array with SQL requests
- */
- function getSqlArrayForStats()
- {
- global $conf, $langs;
-
- $statssql=array();
- /*for ($i=0; $i<5; $i++) {
- $statssql[$i] = "SELECT c.label, count(sp.rowid) AS nb";
- $statssql[$i].= " FROM ".MAIN_DB_PREFIX."socpeople as sp,";
- $statssql[$i].= " ".MAIN_DB_PREFIX."societe as s,";
- $statssql[$i].= " ".MAIN_DB_PREFIX."categorie as c,";
- $statssql[$i].= " ".MAIN_DB_PREFIX."categorie_societe as cs";
- $statssql[$i].= " WHERE s.rowid = sp.fk_soc";
- $statssql[$i].= " AND sp.email != ''"; // Note that null != '' is false
- $statssql[$i].= " AND sp.entity IN (".getEntity('societe').")";
- $statssql[$i].= " AND cs.fk_categorie = c.rowid";
- $statssql[$i].= " AND cs.fk_soc = sp.fk_soc";
- $statssql[$i].= " GROUP BY c.label";
- $statssql[$i].= " ORDER BY nb DESC";
- $statssql[$i].= " LIMIT $i,1";
- }*/
-
- return $statssql;
- }
-
-
- /**
- * Return here number of distinct emails returned by your selector.
- *
- * @param string $sql Requete sql de comptage
- * @return int Number of recipients
- */
- function getNbOfRecipients($sql='')
- {
- global $conf;
-
- // We must report here number of contacts when absolutely no filter selected (so all contacts).
- // Number with a filter are show in the combo list for each filter.
- // If we want a filter "is inside at least one category", we must add it into formFilter
- $sql = "SELECT count(distinct(c.email)) as nb";
- $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
- $sql.= " WHERE c.entity IN (".getEntity('societe').")";
- $sql.= " AND c.email != ''"; // Note that null != '' is false
- $sql.= " AND c.no_email = 0";
- $sql.= " AND c.statut = 1";
- /*
- $sql = "SELECT count(distinct(sp.email)) as nb";
- $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp,";
- $sql.= " ".MAIN_DB_PREFIX."societe as s,";
- $sql.= " ".MAIN_DB_PREFIX."categorie as c,";
- $sql.= " ".MAIN_DB_PREFIX."categorie_societe as cs";
- $sql.= " WHERE s.rowid = sp.fk_soc";
- $sql.= " AND sp.entity IN (".getEntity('societe').")";
- $sql.= " AND sp.email != ''"; // Note that null != '' is false
- $sql.= " AND cs.fk_categorie = c.rowid";
- $sql.= " AND cs.fk_soc = sp.fk_soc";
- */
- // La requete doit retourner un champ "nb" pour etre comprise
- // par parent::getNbOfRecipients
- return parent::getNbOfRecipients($sql);
- }
-
- /**
- * This is to add a form filter to provide variant of selector
- * If used, the HTML select must be called "filter".
- *
- * @return string A html select zone
- */
- function formFilter()
- {
- global $conf, $langs;
-
- $langs->load("companies");
-
- $sql = "SELECT c.label, count(distinct(sp.email)) AS nb";
- $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
- $sql.= " INNER JOIN ".MAIN_DB_PREFIX."categorie_contact as cs ON cs.fk_socpeople=sp.rowid";
- $sql.= " INNER JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";
- $sql.= " WHERE sp.email != ''"; // Note that null != '' is false
- $sql.= " AND sp.no_email = 0";
- $sql.= " AND sp.statut = 1";
- $sql.= " AND sp.entity IN (".getEntity('societe').")";
- $sql.= " GROUP BY c.label";
- $sql.= " ORDER BY c.label";
-
- $resql = $this->db->query($sql);
-
- dol_syslog(get_class($this).':: formFilter',LOG_DEBUG);
- if ($resql) {
- $s='';
- $s.='';
- $s.=' ';
-
- $num = $this->db->num_rows($resql);
- if ($num)
- {
- $i = 0;
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- $s.=''.$obj->label.' ('.$obj->nb.') ';
- $i++;
- }
- }
- else
- {
- $s.=''.$langs->trans("NoContactWithCategoryFound").' ';
- }
- $s.=' ';
- return $s;
- }
- else {
- $this->error=$this->db->lasterrno();
- return -1;
- }
-
- }
-
-}
-
diff --git a/htdocs/core/modules/mailings/fraise.modules.php b/htdocs/core/modules/mailings/fraise.modules.php
index 05d9e525652..e0226017ede 100644
--- a/htdocs/core/modules/mailings/fraise.modules.php
+++ b/htdocs/core/modules/mailings/fraise.modules.php
@@ -34,7 +34,7 @@ class mailing_fraise extends MailingTargets
{
var $name='FundationMembers'; // Identifiant du module mailing
// This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
- var $desc='Foundation members with emails (by status)';
+ var $desc='Foundation members with emails';
// Set to 1 if selector is available for admin users only
var $require_admin=0;
@@ -108,10 +108,14 @@ class mailing_fraise extends MailingTargets
{
global $conf, $langs;
$langs->load("members");
+ $langs->load("categories");
+ $langs->load("companies");
$form=new Form($this->db);
$s='';
+
+ // Status
$s.=$langs->trans("Status").': ';
$s.='';
$s.=' ';
@@ -121,7 +125,7 @@ class mailing_fraise extends MailingTargets
$s.=''.$langs->trans("MemberStatusResiliatedShort").' ';
$s.=' ';
$s.=$langs->trans("Type").': ';
- $s.='';
+ $s.='';
$sql = "SELECT rowid, libelle, statut";
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type";
$sql.= " WHERE entity = ".$conf->entity;
@@ -150,6 +154,47 @@ class mailing_fraise extends MailingTargets
}
$s.=' ';
+
+ $s.=' ';
+
+ $s.=$langs->trans("Category").': ';
+ $s.='';
+
+ // Show categories
+ $sql = "SELECT rowid, label, type, visible";
+ $sql.= " FROM ".MAIN_DB_PREFIX."categorie";
+ $sql.= " WHERE type = 3"; // We keep only categories for members
+ // $sql.= " AND visible > 0"; // We ignore the property visible because member's categories does not use this property (only products categories use it).
+ $sql.= " AND entity = ".$conf->entity;
+ $sql.= " ORDER BY label";
+
+ //print $sql;
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+
+ $s.=' ';
+ if (! $num) $s.=''.$langs->trans("NoCategoriesDefined").' ';
+
+ $i = 0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ $s.=''.dol_trunc($obj->label,38,'middle');
+ $s.=' ';
+ $i++;
+ }
+ }
+ else
+ {
+ dol_print_error($this->db);
+ }
+
+ $s.=' ';
+
+
$s.=' ';
$s.=$langs->trans("DateEndSubscription").': ';
$s.=$langs->trans("After").' > '.$form->select_date(-1,'subscriptionafter',0,0,1,'fraise',1,0,1,0);
@@ -200,18 +245,29 @@ class mailing_fraise extends MailingTargets
$sql = "SELECT a.rowid as id, a.email as email, null as fk_contact, ";
$sql.= " a.lastname, a.firstname,";
$sql.= " a.datefin, a.civility as civility_id, a.login, a.societe"; // Other fields
- $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as ta";
+ $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
+ if ($_POST['filter_category'])
+ {
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_member as cm ON cm.fk_member = a.rowid";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON c.rowid = cm.fk_categorie";
+ }
+ $sql.= " , ".MAIN_DB_PREFIX."adherent_type as ta";
$sql.= " WHERE a.email <> ''"; // Note that null != '' is false
$sql.= " AND a.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
+ // Filter on status
if (isset($_POST["filter"]) && $_POST["filter"] == '-1') $sql.= " AND a.statut=-1";
if (isset($_POST["filter"]) && $_POST["filter"] == '1a') $sql.= " AND a.statut=1 AND a.datefin >= '".$this->db->idate($now)."'";
if (isset($_POST["filter"]) && $_POST["filter"] == '1b') $sql.= " AND a.statut=1 AND (a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."')";
if (isset($_POST["filter"]) && $_POST["filter"] == '0') $sql.= " AND a.statut=0";
+ // Filter on date
if ($dateendsubscriptionafter > 0) $sql.=" AND datefin > '".$this->db->idate($dateendsubscriptionafter)."'";
if ($dateendsubscriptionbefore > 0) $sql.=" AND datefin < '".$this->db->idate($dateendsubscriptionbefore)."'";
$sql.= " AND a.fk_adherent_type = ta.rowid";
- if ($_POST['filtertype']) $sql.= " AND ta.rowid='".$_POST['filtertype']."'";
- $sql.= " ORDER BY a.email";
+ // Filter on type
+ if ($_POST['filter_type']) $sql.= " AND ta.rowid='".$_POST['filter_type']."'";
+ // Filter on category
+ if ($_POST['filter_category']) $sql.= " AND c.rowid='".$_POST['filter_category']."'";
+ $sql.= " ORDER BY a.email";
//print $sql;
// Add targets into table
diff --git a/htdocs/core/modules/mailings/framboise.modules.php b/htdocs/core/modules/mailings/framboise.modules.php
deleted file mode 100644
index 82f7e51e0ef..00000000000
--- a/htdocs/core/modules/mailings/framboise.modules.php
+++ /dev/null
@@ -1,234 +0,0 @@
-
- * Copyright (C) 2005-2009 Regis Houssin
- *
- * This file is an example to follow to add your own email selector inside
- * the Dolibarr email tool.
- * Follow instructions given in README file to know what to change to build
- * your own emailing list selector.
- * Code that need to be changed in this file are marked by "CHANGE THIS" tag.
- */
-
-/**
- * \file htdocs/core/modules/mailings/framboise.modules.php
- * \ingroup mailing
- * \brief Example file to provide a list of recipients for mailing module
- */
-
-include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
-
-
-/**
- * Class to manage a list of personalised recipients for mailing feature
- */
-class mailing_framboise extends MailingTargets
-{
- var $name='MembersCategories';
- // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
- var $desc="Foundation members with emails (by categories)";
- // Set to 1 if selector is available for admin users only
- var $require_admin=0;
-
- var $require_module=array("adherent","categorie");
- var $picto='user';
- var $db;
-
-
- /**
- * Constructor
- *
- * @param DoliDB $db Database handler
- */
- function __construct($db)
- {
- $this->db=$db;
- }
-
-
- /**
- * This is the main function that returns the array of emails.
- *
- * @param int $mailing_id Id of mailing. No need to use it.
- * @param array $filtersarray If you used the formFilter function. Empty otherwise.
- * @return int <0 if error, number of emails added if ok
- */
- function add_to_target($mailing_id,$filtersarray=array())
- {
- global $conf, $langs;
- $langs->load("members");
- $langs->load("companies");
-
- $cibles = array();
-
- // Select the members from category
- $sql = "SELECT a.rowid as id, a.email as email, a.lastname, null as fk_contact, a.firstname,";
- $sql.= " a.datefin, a.civility as civility_id, a.login, a.societe,"; // Other fields
- if ($_POST['filter']) $sql.= " c.label";
- else $sql.=" null as label";
- $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
- if ($_POST['filter'])
- {
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_member as cm ON cm.fk_member = a.rowid";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON c.rowid = cm.fk_categorie";
- }
- $sql.= " WHERE a.email != ''";
- $sql.= " AND a.entity = ".$conf->entity;
- if ($_POST['filter']) $sql.= " AND c.rowid='".$_POST['filter']."'";
- $sql.= " ORDER BY a.email";
-
- // Stocke destinataires dans cibles
- $result=$this->db->query($sql);
- 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 = '';
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($result);
- if ($old <> $obj->email)
- {
- $cibles[$j] = array(
- 'email' => $obj->email,
- 'fk_contact' => $obj->fk_contact,
- 'lastname' => $obj->lastname,
- 'firstname' => $obj->firstname,
- 'other' =>
- ($langs->transnoentities("Login").'='.$obj->login).';'.
- ($langs->transnoentities("UserTitle").'='.($obj->civility_id?$langs->transnoentities("Civility".$obj->civility_id):'')).';'.
- ($langs->transnoentities("DateEnd").'='.dol_print_date($this->db->jdate($obj->datefin),'day')).';'.
- ($langs->transnoentities("Company").'='.$obj->societe).';'.
- ($obj->label?$langs->transnoentities("Category").'='.$obj->label:''),
- 'source_url' => $this->url($obj->id),
- 'source_id' => $obj->id,
- 'source_type' => 'member'
- );
- $old = $obj->email;
- $j++;
- }
-
- $i++;
- }
- }
- else
- {
- dol_syslog($this->db->error());
- $this->error=$this->db->error();
- return -1;
- }
-
- return parent::add_to_target($mailing_id, $cibles);
- }
-
-
- /**
- * 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 array Array with SQL requests
- */
- function getSqlArrayForStats()
- {
- // CHANGE THIS: Optionnal
-
- //var $statssql=array();
- //$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL";
- return array();
- }
-
-
- /**
- * 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.
- *
- * @param string $sql Requete sql de comptage
- * @return int Nb of recipients
- */
- function getNbOfRecipients($sql='')
- {
- global $conf;
-
- $sql = "SELECT count(distinct(a.email)) as nb";
- $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
- $sql.= " WHERE a.email != ''";
- $sql.= " AND a.entity = ".$conf->entity;
-
- // La requete doit retourner un champ "nb" pour etre comprise
- // par parent::getNbOfRecipients
- return parent::getNbOfRecipients($sql);
- }
-
- /**
- * This is to add a form filter to provide variant of selector
- * If used, the HTML select must be called "filter"
- *
- * @return string A html select zone
- */
- function formFilter()
- {
- global $conf, $langs;
-
- $langs->load("companies");
- $langs->load("categories");
-
- $s='';
- $s.='';
-
- // Show categories
- $sql = "SELECT rowid, label, type, visible";
- $sql.= " FROM ".MAIN_DB_PREFIX."categorie";
- $sql.= " WHERE type = 3"; // We keep only categories for members
- // $sql.= " AND visible > 0"; // We ignore the property visible because member's categories does not use this property (only products categories use it).
- $sql.= " AND entity = ".$conf->entity;
- $sql.= " ORDER BY label";
-
- //print $sql;
- $resql = $this->db->query($sql);
- if ($resql)
- {
- $num = $this->db->num_rows($resql);
-
- $s.=' ';
- if (! $num) $s.=''.$langs->trans("NoCategoriesDefined").' ';
-
- $i = 0;
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
-
- $s.=''.dol_trunc($obj->label,38,'middle');
- $s.=' ';
- $i++;
- }
- }
- else
- {
- dol_print_error($this->db);
- }
-
- $s.=' ';
- return $s;
-
- }
-
-
- /**
- * Can include an URL link on each record provided by selector shown on target page.
- *
- * @param int $id Id of member
- * @return string Url link
- */
- function url($id)
- {
- return ''.img_object('',"user").' ';
- }
-
-}
-
diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php
index 2c032ffa7c0..80162f24b5c 100644
--- a/htdocs/install/upgrade2.php
+++ b/htdocs/install/upgrade2.php
@@ -4023,6 +4023,10 @@ function migrate_delete_old_files($db,$langs,$conf)
DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria_frontoffice.php',
DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy_backoffice.php',
DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy_frontoffice.php',
+ DOL_DOCUMENT_ROOT.'/core/modules/mailings/contacts2.modules.php',
+ DOL_DOCUMENT_ROOT.'/core/modules/mailings/contacts3.modules.php',
+ DOL_DOCUMENT_ROOT.'/core/modules/mailings/contacts4.modules.php',
+ DOL_DOCUMENT_ROOT.'/core/modules/mailings/framboise.modules.php',
DOL_DOCUMENT_ROOT.'/core/modules/mailings/dolibarr_services_expired.modules.php',
DOL_DOCUMENT_ROOT.'/core/modules/mailings/peche.modules.php',
DOL_DOCUMENT_ROOT.'/core/modules/mailings/poire.modules.php',
@@ -4036,6 +4040,7 @@ function migrate_delete_old_files($db,$langs,$conf)
DOL_DOCUMENT_ROOT.'/product/class/api_product.class.php',
DOL_DOCUMENT_ROOT.'/societe/class/api_contact.class.php',
DOL_DOCUMENT_ROOT.'/societe/class/api_thirdparty.class.php'
+
);
foreach ($filetodeletearray as $filetodelete)
diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang
index bd7d7983191..a7e7c67ae9c 100644
--- a/htdocs/langs/en_US/companies.lang
+++ b/htdocs/langs/en_US/companies.lang
@@ -50,6 +50,7 @@ Lastname=Last name
Firstname=First name
PostOrFunction=Job position
UserTitle=Title
+NatureOfThirdParty=Nature of Third party
Address=Address
State=State/Province
StateShort=State