Fix: Select target on supplier category

This commit is contained in:
Laurent Destailleur 2011-11-30 11:55:33 +01:00
parent cb971eeb9a
commit a47a16f281

View File

@ -40,7 +40,7 @@ class mailing_thirdparties extends MailingTargets
/** /**
* Constructor * Constructor
* *
* @param DoliDB $DB Database handler * @param DoliDB $db Database handler
*/ */
function mailing_thirdparties($db) function mailing_thirdparties($db)
{ {
@ -49,10 +49,11 @@ class mailing_thirdparties extends MailingTargets
/** /**
* \brief This is the main function that returns the array of emails * This is the main function that returns the array of emails
* \param mailing_id Id of mailing. No need to use it. *
* \param filterarray If you used the formFilter function. Empty otherwise. * @param int $mailing_id Id of mailing. No need to use it.
* \return int <0 if error, number of emails added if ok * @param array $filterarray 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()) function add_to_target($mailing_id,$filtersarray=array())
{ {
@ -60,23 +61,35 @@ class mailing_thirdparties extends MailingTargets
$cibles = array(); $cibles = array();
// CHANGE THIS
// Select the third parties from category // Select the third parties from category
$sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname,"; if (empty($_POST['filter']))
if ($_POST['filter']) $sql.= " c.label";
else $sql.=" null as label";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
if ($_POST['filter'])
{ {
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON cs.fk_societe = s.rowid"; $sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, null as label";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON c.rowid = cs.fk_categorie"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= " WHERE s.email != ''";
$sql.= " AND s.entity = ".$conf->entity;
} }
$sql.= " WHERE s.email != ''"; else
$sql.= " AND s.entity = ".$conf->entity; {
if ($_POST['filter']) $sql.= " AND c.rowid='".$_POST['filter']."'"; $sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label";
$sql.= " ORDER BY s.email"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."categorie_societe as cs, ".MAIN_DB_PREFIX."categorie as c";
$sql.= " WHERE s.email != ''";
$sql.= " AND s.entity = ".$conf->entity;
$sql.= " AND cs.fk_societe = s.rowid";
$sql.= " AND c.rowid = cs.fk_categorie";
$sql.= " AND c.rowid='".$this->db->escape($_POST['filter'])."'";
$sql.= " UNION ";
$sql.= "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."categorie_fournisseur as cs, ".MAIN_DB_PREFIX."categorie as c";
$sql.= " WHERE s.email != ''";
$sql.= " AND s.entity = ".$conf->entity;
$sql.= " AND cs.fk_societe = s.rowid";
$sql.= " AND c.rowid = cs.fk_categorie";
$sql.= " AND c.rowid='".$this->db->escape($_POST['filter'])."'";
}
$sql.= " ORDER BY email";
// Stocke destinataires dans cibles // Stock recipients emails into targets table
$result=$this->db->query($sql); $result=$this->db->query($sql);
if ($result) if ($result)
{ {