Look: Ajout picto sur statut mailing
Amlioration de la modularit des modules de selction cibles d'un mailing pour rendre plus facile ajout de ses propres mailing-list.
This commit is contained in:
parent
922f3afbcb
commit
7de56b341a
@ -237,7 +237,9 @@ if ($mil->fetch($_GET["id"]) == 0)
|
||||
print '<td align="center">'.($obj->getNbOfRecipients()).'</td>';
|
||||
|
||||
print '<td align="center">';
|
||||
print $obj->formFilter();
|
||||
$filter=$obj->formFilter();
|
||||
if ($filter) print $filter;
|
||||
else print $langs->trans("None");
|
||||
print '</td>';
|
||||
|
||||
print '<td align="center">';
|
||||
|
||||
@ -307,8 +307,8 @@ else
|
||||
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">'.$mil->id.'</td></tr>';
|
||||
print '<tr><td width="25%">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$mil->titre.'</td></tr>';
|
||||
print '<tr><td width="25%">'.$langs->trans("MailFrom").'</td><td colspan="3">'.htmlentities($mil->email_from).'</td></tr>';
|
||||
print '<tr><td width="25%">'.$langs->trans("Status").'</td><td colspan="3">'.$mil->getLibStatut(4).'</td></tr>';
|
||||
print '<tr><td width="25%">'.$langs->trans("TotalNbOfDistinctRecipients").'</td><td colspan="3">'.($mil->nbemail?$mil->nbemail:'<font class="error">'.$langs->trans("NoTargetYet").'</font>').'</td></tr>';
|
||||
print '<tr><td width="25%">'.$langs->trans("Status").'</td><td colspan="3">'.$mil->statuts[$mil->statut].'</td></tr>';
|
||||
|
||||
$uc = new User($db, $mil->user_creat);
|
||||
$uc->fetch();
|
||||
|
||||
@ -81,6 +81,7 @@ while (($file = readdir($handle))!==false)
|
||||
if (eregi("(.*)\.(.*)\.(.*)",$file,$reg))
|
||||
{
|
||||
$modulename=$reg[1];
|
||||
if ($modulename == 'example') continue;
|
||||
|
||||
// Chargement de la classe
|
||||
$file = $dir."/".$modulename.".modules.php";
|
||||
@ -104,7 +105,7 @@ while (($file = readdir($handle))!==false)
|
||||
{
|
||||
$var = !$var;
|
||||
|
||||
foreach ($mailmodule->statssql as $sql)
|
||||
foreach ($mailmodule->getSqlArrayForStats() as $sql)
|
||||
{
|
||||
print '<tr '.$bc[$var].'>';
|
||||
|
||||
@ -157,7 +158,7 @@ if ($result)
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td colspan="2">'.$langs->trans("LastMailings",10).'</td>';
|
||||
print '<td align="center">'.$langs->trans("NbOfEMails").'</td>';
|
||||
print '<td align="center">'.$langs->trans("Status").'</td></tr>';
|
||||
print '<td align="right">'.$langs->trans("Status").'</td></tr>';
|
||||
|
||||
$num = $db->num_rows($result);
|
||||
if ($num > 0)
|
||||
@ -174,8 +175,8 @@ if ($result)
|
||||
print '<td><a href="fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowEMail"),"email").' '.$obj->rowid.'</a></td>';
|
||||
print '<td>'.$obj->titre.'</td>';
|
||||
print '<td align="center">'.($obj->nbemail?$obj->nbemail:"0").'</td>';
|
||||
$mail=new Mailing($db);
|
||||
print '<td align="center">'.$mail->statuts[$obj->statut].'</td>';
|
||||
$mailstatic=new Mailing($db);
|
||||
print '<td align="right">'.$mailstatic->LibStatut($obj->statut,5).'</td>';
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
|
||||
@ -281,7 +281,68 @@ class Mailing
|
||||
$this->db->query($sql);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Retourne le libellé du statut d'un mailing (brouillon, validée, ...)
|
||||
* \param mode 0=libellé long, 1=libellé court, 2=Picto + Libellé court, 3=Picto, 4=Picto + Libellé long
|
||||
* \return string Libelle
|
||||
*/
|
||||
function getLibStatut($mode=0)
|
||||
{
|
||||
return $this->LibStatut($this->statut,$mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Renvoi le libellé d'un statut donné
|
||||
* \param statut Id statut
|
||||
* \param mode 0=libellé long, 1=libellé court, 2=Picto + Libellé court, 3=Picto, 4=Picto + Libellé long, 5=Libellé court + Picto
|
||||
* \return string Libellé du statut
|
||||
*/
|
||||
function LibStatut($statut,$mode=0)
|
||||
{
|
||||
global $langs;
|
||||
$langs->load('mails');
|
||||
|
||||
if ($mode == 0)
|
||||
{
|
||||
return $this->statuts[$statut];
|
||||
}
|
||||
if ($mode == 1)
|
||||
{
|
||||
return $this->statuts[$statut];
|
||||
}
|
||||
if ($mode == 2)
|
||||
{
|
||||
if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$this->statuts[$statut];
|
||||
if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1').' '.$this->statuts[$statut];
|
||||
if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$this->statuts[$statut];
|
||||
if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$this->statuts[$statut];
|
||||
}
|
||||
if ($mode == 3)
|
||||
{
|
||||
if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0');
|
||||
if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1');
|
||||
if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3');
|
||||
if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6');
|
||||
}
|
||||
if ($mode == 4)
|
||||
{
|
||||
if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$this->statuts[$statut];
|
||||
if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1').' '.$this->statuts[$statut];
|
||||
if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$this->statuts[$statut];
|
||||
if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$this->statuts[$statut];
|
||||
}
|
||||
if ($mode == 5)
|
||||
{
|
||||
if ($statut == 0) return $this->statuts[$statut].' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
|
||||
if ($statut == 1) return $this->statuts[$statut].' '.img_picto($langs->trans($this->statuts[$statut]),'statut1');
|
||||
if ($statut == 2) return $this->statuts[$statut].' '.img_picto($langs->trans($this->statuts[$statut]),'statut3');
|
||||
if ($statut == 3) return $this->statuts[$statut].' '.img_picto($langs->trans($this->statuts[$statut]),'statut6');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
47
htdocs/includes/modules/mailings/README
Normal file
47
htdocs/includes/modules/mailings/README
Normal file
@ -0,0 +1,47 @@
|
||||
|
||||
If you want to add your own emails selector/import module. This is steps to follow
|
||||
to add you own email predefined selector:
|
||||
|
||||
|
||||
***** STEP 1 *****
|
||||
|
||||
Copy file
|
||||
htdocs/includes/mailings/example.modules.php
|
||||
into
|
||||
htdocs/includes/mailings/myselector.modules.php
|
||||
|
||||
You can choose value of your choice instead of "myselector" in name
|
||||
of new file.
|
||||
|
||||
|
||||
***** STEP 2 *****
|
||||
|
||||
Edit this file myselector.modules.php and change following text:
|
||||
|
||||
"class mailing_example" into "class mailing_myselector"
|
||||
"var $name='example';" into var $name='myselector';
|
||||
"var $desc='...';" into var $desc='A text to describe selector';
|
||||
"function mailing_example" into "function mailing_myselector"
|
||||
|
||||
Then add code inside the "add_to_target" function. What you must do is simply
|
||||
fill the $target PHP array with one record for each email your selector must return.
|
||||
|
||||
You can choose the way you get data: From a file, a database. You are free,
|
||||
the only requirement is that the $target array is filled by records that are
|
||||
themselves array of: ('email', 'name', 'firstname').
|
||||
|
||||
This is for example how you can fill the $target array:
|
||||
|
||||
// ----- Your code start here -----
|
||||
$target[0]=array('email'=>'email_0','name'=>'name_0','firstname'=>'firstname_0');
|
||||
...
|
||||
$target[n]=array('email'=>'email_n','name'=>'name_n','firstname'=>'firstname_n');
|
||||
// ----- Your code end here -----
|
||||
|
||||
|
||||
|
||||
***** STEP 3 *****
|
||||
|
||||
Once this file has been edited, you can go to the Dolibarr emailing feature,
|
||||
you will see a new line selector in the "target" editor of an emailing.
|
||||
|
||||
122
htdocs/includes/modules/mailings/example.modules.php
Normal file
122
htdocs/includes/modules/mailings/example.modules.php
Normal file
@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/* Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/includes/modules/mailings/modules_mailings.php';
|
||||
|
||||
|
||||
// CHANGE THIS: Class name must be called mailing_xxx with xxx=name of your selector
|
||||
class mailing_example extends MailingTargets
|
||||
{
|
||||
// CHANGE THIS: Put here a name not already used
|
||||
var $name='example';
|
||||
// CHANGE THIS: Put here a description of your selector module
|
||||
var $desc='Put here a description';
|
||||
// CHANGE THIS: Set to 1 if selector is available for admin users only
|
||||
var $require_admin=0;
|
||||
|
||||
var $require_module=array();
|
||||
var $picto='';
|
||||
var $db;
|
||||
|
||||
|
||||
// CHANGE THIS: Constructor name must be called mailing_xxx with xxx=name of your selector
|
||||
function mailing_example($DB)
|
||||
{
|
||||
$this->db=$DB;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief 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.
|
||||
* \return int <0 if error, number of emails added if ok
|
||||
*/
|
||||
function add_to_target($mailing_id,$filtersarray=array())
|
||||
{
|
||||
$target = array();
|
||||
|
||||
// CHANGE THIS
|
||||
// ----- Your code start here -----
|
||||
|
||||
// You must fill the $target array with record like this
|
||||
// $target[0]=array('email'=>'email_0','name'=>'name_0','firstname'=>'firstname_0');
|
||||
// ...
|
||||
// $target[n]=array('email'=>'email_n','name'=>'name_n','firstname'=>'firstname_n');
|
||||
|
||||
// Example: $target[0]=array('email'=>'myemail@mydomain.com','name'=>'Doe','firstname'=>'John');
|
||||
|
||||
// ----- Your code end here -----
|
||||
|
||||
return parent::add_to_target($mailing_id, $target);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief 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
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* \brief 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.
|
||||
* \return int
|
||||
*/
|
||||
function getNbOfRecipients()
|
||||
{
|
||||
// CHANGE THIS: Optionnal
|
||||
|
||||
// Example: return parent::getNbOfRecipients("SELECT count(*) as nb from dolibarr_table");
|
||||
// Example: return 500;
|
||||
return '?';
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief 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()
|
||||
{
|
||||
// CHANGE THIS: Optionnal
|
||||
|
||||
$s='';
|
||||
return $s;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Can include an URL link on each record provided by selector
|
||||
* shown on target page.
|
||||
* \return string Url link
|
||||
*/
|
||||
function url($id)
|
||||
{
|
||||
// CHANGE THIS: Optionnal
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@ -59,30 +59,44 @@ class mailing_fraise extends MailingTargets
|
||||
var $picto='user';
|
||||
|
||||
var $db;
|
||||
var $statssql=array();
|
||||
|
||||
|
||||
function mailing_fraise($DB)
|
||||
{
|
||||
global $langs;
|
||||
$langs->load("members");
|
||||
|
||||
$this->db=$DB;
|
||||
|
||||
// Liste des tableaux des stats espace mailing
|
||||
$this->statssql[0]="SELECT '".addslashes($langs->trans("FundationMembers"))."' as label, count(*) as nb FROM ".MAIN_DB_PREFIX."adherent where statut = 1";
|
||||
}
|
||||
|
||||
|
||||
function getSqlArrayForStats()
|
||||
{
|
||||
global $langs;
|
||||
$langs->load("members");
|
||||
|
||||
$statssql=array();
|
||||
$statssql[0]="SELECT '".addslashes($langs->trans("FundationMembers"))."' as label, count(*) as nb FROM ".MAIN_DB_PREFIX."adherent where statut = 1";
|
||||
|
||||
return $statssql;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* \brief 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.
|
||||
* \return int
|
||||
*/
|
||||
function getNbOfRecipients()
|
||||
{
|
||||
// La requete doit retourner: nb
|
||||
$sql = "SELECT count(distinct(a.email)) as nb";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
|
||||
$sql .= " WHERE a.email IS NOT NULL";
|
||||
|
||||
// La requete doit retourner un champ "nb" pour etre comprise
|
||||
// par parent::getNbOfRecipients
|
||||
return parent::getNbOfRecipients($sql);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Affiche formulaire de filtre qui apparait dans page de selection
|
||||
* des destinataires de mailings
|
||||
@ -121,6 +135,8 @@ class mailing_fraise extends MailingTargets
|
||||
*/
|
||||
function add_to_target($mailing_id,$filtersarray=array())
|
||||
{
|
||||
$cibles = array();
|
||||
|
||||
// La requete doit retourner: id, email, fk_contact, name, firstname
|
||||
$sql = "SELECT a.rowid as id, a.email as email, null as fk_contact, a.nom as name, a.prenom as firstname";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
|
||||
@ -133,8 +149,45 @@ class mailing_fraise extends MailingTargets
|
||||
}
|
||||
$sql.= " ORDER BY a.email";
|
||||
|
||||
return parent::add_to_target($mailing_id, $sql);
|
||||
}
|
||||
// Stocke destinataires dans cibles
|
||||
$result=$this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $this->db->num_rows($result);
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
|
||||
dolibarr_syslog("fraisemodules.php: mailing $num cibles trouvées");
|
||||
|
||||
$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,
|
||||
'name' => $obj->name,
|
||||
'firstname' => $obj->firstname,
|
||||
'url' => $this->url($obj->id)
|
||||
);
|
||||
$old = $obj->email;
|
||||
$j++;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog($this->db->error());
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return parent::add_to_target($mailing_id, $cibles);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -132,41 +132,8 @@ class MailingTargets
|
||||
* \param sql Requete sql de selection des destinataires
|
||||
* \return int < 0 si erreur, nb ajout si ok
|
||||
*/
|
||||
function add_to_target($mailing_id, $sql)
|
||||
function add_to_target($mailing_id, $cibles)
|
||||
{
|
||||
$cibles = array();
|
||||
|
||||
// Stocke destinataires dans cibles
|
||||
$result=$this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $this->db->num_rows($result);
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
|
||||
dolibarr_syslog("mailing-prepare: mailing $num cibles trouvées");
|
||||
|
||||
$old = '';
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($result);
|
||||
if ($old <> $obj->email)
|
||||
{
|
||||
$cibles[$j] = array($obj->email,$obj->fk_contact,$obj->name,$obj->firstname,$this->url($obj->id));
|
||||
$old = $obj->email;
|
||||
$j++;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog($this->db->error());
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// Insère destinataires de cibles dans table
|
||||
@ -176,14 +143,14 @@ class MailingTargets
|
||||
{
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles";
|
||||
$sql .= " (fk_mailing, ";
|
||||
if ($cibles[$i][1]) $sql .= "fk_contact, ";
|
||||
if ($cibles[$i]['fk_contact']) $sql .= "fk_contact, ";
|
||||
$sql .= "nom, prenom, email, url)";
|
||||
$sql .= " VALUES (".$mailing_id.",";
|
||||
if ($cibles[$i][1]) $sql .= $cibles[$i][1] .",";
|
||||
$sql .= "'".addslashes($cibles[$i][2])."',";
|
||||
$sql .= "'".addslashes($cibles[$i][3])."',";
|
||||
$sql .= "'".addslashes($cibles[$i][0])."',";
|
||||
$sql .= "'".addslashes($cibles[$i][4])."')";
|
||||
if ($cibles[$i]['fk_contact']) $sql .= $cibles[$i]['fk_contact'] .",";
|
||||
$sql .= "'".addslashes($cibles[$i]['name'])."',";
|
||||
$sql .= "'".addslashes($cibles[$i]['firstname'])."',";
|
||||
$sql .= "'".addslashes($cibles[$i]['email'])."',";
|
||||
$sql .= "'".addslashes($cibles[$i]['url'])."')";
|
||||
|
||||
$result=$this->db->query($sql);
|
||||
if ($result)
|
||||
|
||||
@ -53,40 +53,52 @@ include_once DOL_DOCUMENT_ROOT.'/includes/modules/mailings/modules_mailings.php'
|
||||
class mailing_poire extends MailingTargets
|
||||
{
|
||||
var $name='ContactCompanies'; // Identifiant du module mailing
|
||||
var $desc='Contacts avec emails des sociétés'; // Libellé utilisé si aucune traduction pour MailingModuleDescXXX ou XXX=name trouvée
|
||||
var $desc='Contacts des sociétés'; // Libellé utilisé si aucune traduction pour MailingModuleDescXXX ou XXX=name trouvée
|
||||
var $require_module=array("commercial"); // 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;
|
||||
var $statssql=array();
|
||||
|
||||
|
||||
function mailing_poire($DB)
|
||||
{
|
||||
$this->db=$DB;
|
||||
}
|
||||
|
||||
|
||||
function getSqlArrayForStats()
|
||||
{
|
||||
global $langs;
|
||||
$langs->load("commercial");
|
||||
|
||||
$this->db=$DB;
|
||||
$statssql=array();
|
||||
$statssql[0]="SELECT '".$langs->trans("NbOfCompaniesContacts")."' as label, count(distinct(c.email)) as nb FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."societe as s WHERE s.idp = c.fk_soc AND s.client = 1 AND c.email != ''";
|
||||
|
||||
return $statssql;
|
||||
}
|
||||
|
||||
// Liste des tableaux des stats espace mailing
|
||||
//$this->statssql[0]="SELECT '".$langs->trans("Customers")."' as label, count(*) as nb FROM ".MAIN_DB_PREFIX."societe WHERE client = 1";
|
||||
$this->statssql[0]="SELECT '".$langs->trans("NbOfCompaniesContacts")."' as label, count(distinct(c.email)) as nb FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."societe as s WHERE s.idp = c.fk_soc AND s.client = 1 AND c.email != ''";
|
||||
}
|
||||
|
||||
/*
|
||||
* \brief 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.
|
||||
* \return int
|
||||
*/
|
||||
function getNbOfRecipients()
|
||||
{
|
||||
// La requete doit retourner: nb
|
||||
$sql = "SELECT count(distinct(c.email)) as nb";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql .= " WHERE s.idp = c.fk_soc";
|
||||
$sql .= " AND s.client = 1";
|
||||
$sql .= " AND c.email != ''";
|
||||
|
||||
// La requete doit retourner un champ "nb" pour etre comprise
|
||||
// par parent::getNbOfRecipients
|
||||
return parent::getNbOfRecipients($sql);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Affiche formulaire de filtre qui apparait dans page de selection
|
||||
* des destinataires de mailings
|
||||
@ -102,9 +114,10 @@ class mailing_poire extends MailingTargets
|
||||
$s='';
|
||||
$s.='<select name="filter" class="flat">';
|
||||
$s.='<option value="all">'.$langs->trans("ContactsAllShort").'</option>';
|
||||
$s.='<option value="prospects">'.$langs->trans("Prospects").'</option>';
|
||||
$s.='<option value="customers">'.$langs->trans("Customers").'</option>';
|
||||
$s.='<option value="suppliers">'.$langs->trans("Suppliers").'</option>';
|
||||
$s.='<option value="prospects">'.$langs->trans("ThirdPartyProspects").'</option>';
|
||||
$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>';
|
||||
return $s;
|
||||
}
|
||||
@ -124,10 +137,12 @@ class mailing_poire extends MailingTargets
|
||||
* \brief Ajoute destinataires dans table des cibles
|
||||
* \param mailing_id Id du mailing concerné
|
||||
* \param filterarray Requete sql de selection des destinataires
|
||||
* \return int < 0 si erreur, nb ajout si ok
|
||||
* \return int <0 si erreur, nb ajout si ok
|
||||
*/
|
||||
function add_to_target($mailing_id,$filtersarray=array())
|
||||
{
|
||||
$cibles = array();
|
||||
|
||||
// La requete doit retourner: id, email, fk_contact, name, firstname
|
||||
$sql = "SELECT c.idp as id, c.email as email, c.idp as fk_contact, c.name as name, c.firstname as firstname";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
|
||||
@ -142,7 +157,45 @@ class mailing_poire extends MailingTargets
|
||||
}
|
||||
$sql .= " ORDER BY c.email";
|
||||
|
||||
return parent::add_to_target($mailing_id, $sql);
|
||||
|
||||
// Stocke destinataires dans cibles
|
||||
$result=$this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $this->db->num_rows($result);
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
|
||||
dolibarr_syslog("poire.modules.php: mailing $num cibles trouvées");
|
||||
|
||||
$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,
|
||||
'name' => $obj->name,
|
||||
'firstname' => $obj->firstname,
|
||||
'url' => $this->url($obj->id)
|
||||
);
|
||||
$old = $obj->email;
|
||||
$j++;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog($this->db->error());
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return parent::add_to_target($mailing_id, $cibles);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -58,30 +58,42 @@ class mailing_pomme extends MailingTargets
|
||||
var $picto='user';
|
||||
|
||||
var $db;
|
||||
var $statssql=array();
|
||||
|
||||
|
||||
function mailing_pomme($DB)
|
||||
{
|
||||
$this->db=$DB;
|
||||
}
|
||||
|
||||
|
||||
function getSqlArrayForStats()
|
||||
{
|
||||
global $langs;
|
||||
$langs->load("users");
|
||||
|
||||
$this->db=$DB;
|
||||
|
||||
// Liste des tableaux des stats espace mailing
|
||||
$statssql=array();
|
||||
$sql = "SELECT '".$langs->trans("DolibarrUsers")."' as label, count(distinct(email)) as nb FROM ".MAIN_DB_PREFIX."user as u";
|
||||
$sql.= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test
|
||||
$this->statssql[0]=$sql;
|
||||
|
||||
}
|
||||
$statssql[0]=$sql;
|
||||
|
||||
return $statssql;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* \brief 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.
|
||||
* \return int
|
||||
*/
|
||||
function getNbOfRecipients()
|
||||
{
|
||||
// La requete doit retourner: nb
|
||||
$sql = "SELECT count(distinct(u.email)) as nb";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
|
||||
$sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test
|
||||
|
||||
// La requete doit retourner un champ "nb" pour etre comprise
|
||||
// par parent::getNbOfRecipients
|
||||
return parent::getNbOfRecipients($sql);
|
||||
}
|
||||
|
||||
@ -104,13 +116,52 @@ class mailing_pomme extends MailingTargets
|
||||
*/
|
||||
function add_to_target($mailing_id,$filtersarray=array())
|
||||
{
|
||||
$cibles = array();
|
||||
|
||||
// La requete doit retourner: id, email, fk_contact, name, firstname
|
||||
$sql = "SELECT u.rowid as id, u.email as email, null as fk_contact, u.name as name, u.firstname as firstname";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
|
||||
$sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test
|
||||
$sql .= " ORDER BY u.email";
|
||||
|
||||
return parent::add_to_target($mailing_id, $sql);
|
||||
// Stocke destinataires dans cibles
|
||||
$result=$this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $this->db->num_rows($result);
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
|
||||
dolibarr_syslog("pomme.modules.php: mailing $num cibles trouvées");
|
||||
|
||||
$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,
|
||||
'name' => $obj->name,
|
||||
'firstname' => $obj->firstname,
|
||||
'url' => $this->url($obj->id)
|
||||
);
|
||||
$old = $obj->email;
|
||||
$j++;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog($this->db->error());
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return parent::add_to_target($mailing_id, $cibles);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user