--- /tmp/dsg/dolibarr/htdocs/core/modules/mailings/github_advthirdparties.modules.php
+++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_advthirdparties.modules.php
@@ -25,22 +25,22 @@
*/
class mailing_advthirdparties extends MailingTargets
{
- public $name = 'ThirdPartyAdvancedTargeting';
+ public $name = 'ThirdPartyAdvancedTargeting';
// This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
- public $desc = "Third parties";
- public $require_admin = 0;
-
- public $require_module = array("none"); // This module should not be displayed as Selector in mailling
-
- /**
- * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
- */
- public $picto = 'company';
-
- /**
- * @var DoliDB Database handler.
- */
- public $db;
+ public $desc = "Third parties";
+ public $require_admin = 0;
+
+ public $require_module = array("none"); // This module should not be displayed as Selector in mailling
+
+ /**
+ * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
+ */
+ public $picto = 'company';
+
+ /**
+ * @var DoliDB Database handler.
+ */
+ public $db;
/**
@@ -54,7 +54,7 @@
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* This is the main function that returns the array of emails
*
@@ -66,7 +66,7 @@
*/
public function add_to_target_spec($mailing_id, $socid, $type_of_target, $contactid)
{
- // phpcs:enable
+ // phpcs:enable
global $conf, $langs;
dol_syslog(get_class($this)."::add_to_target_spec socid=".var_export($socid, true).' contactid='.var_export($contactid, true));
@@ -83,41 +83,43 @@
$sql .= " AND s.rowid IN (".implode(',', $socid).")";
$sql .= " ORDER BY email";
- // Stock recipients emails into targets table
- $result = $this->db->query($sql);
- if ($result)
- {
- $num = $this->db->num_rows($result);
- $i = 0;
-
- dol_syslog(get_class($this)."::add_to_target_spec mailing ".$num." targets found", LOG_DEBUG);
-
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($result);
-
- if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
- if (!array_key_exists($obj->email, $cibles)) {
- $cibles[$obj->email] = array(
- 'email' => $obj->email,
- 'fk_contact' => $obj->fk_contact,
- 'name' => $obj->name,
- 'firstname' => $obj->firstname,
- 'other' => '',
- 'source_url' => $this->url($obj->id, 'thirdparty'),
- 'source_id' => $obj->id,
- 'source_type' => 'thirdparty'
- );
- }
- }
-
- $i++;
- }
- } else {
- dol_syslog($this->db->error());
- $this->error = $this->db->error();
- return -1;
- }
+ // Stock recipients emails into targets table
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ $num = $this->db->num_rows($result);
+ $i = 0;
+
+ dol_syslog(get_class($this)."::add_to_target_spec mailing ".$num." targets found", LOG_DEBUG);
+
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($result);
+
+ if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
+ if (!array_key_exists($obj->email, $cibles)) {
+ $cibles[$obj->email] = array(
+ 'email' => $obj->email,
+ 'fk_contact' => $obj->fk_contact,
+ 'name' => $obj->name,
+ 'firstname' => $obj->firstname,
+ 'other' => '',
+ 'source_url' => $this->url($obj->id, 'thirdparty'),
+ 'source_id' => $obj->id,
+ 'source_type' => 'thirdparty'
+ );
+ }
+ }
+
+ $i++;
+ }
+ }
+ else
+ {
+ dol_syslog($this->db->error());
+ $this->error = $this->db->error();
+ return -1;
+ }
}
}
@@ -136,41 +138,43 @@
}
$sql .= " ORDER BY email";
- // Stock recipients emails into targets table
- $result = $this->db->query($sql);
- if ($result)
- {
- $num = $this->db->num_rows($result);
- $i = 0;
-
- dol_syslog(get_class($this)."::add_to_target_spec mailing ".$num." targets found");
-
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($result);
-
- if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
- if (!array_key_exists($obj->email, $cibles)) {
- $cibles[$obj->email] = array(
- 'email' => $obj->email,
- 'fk_contact' =>$obj->id,
- 'lastname' => $obj->lastname,
- 'firstname' => $obj->firstname,
- 'other' => '',
- 'source_url' => $this->url($obj->id, 'contact'),
- 'source_id' => $obj->id,
- 'source_type' => 'contact'
- );
- }
- }
-
- $i++;
- }
- } else {
- dol_syslog($this->db->error());
- $this->error = $this->db->error();
- return -1;
- }
+ // Stock recipients emails into targets table
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ $num = $this->db->num_rows($result);
+ $i = 0;
+
+ dol_syslog(get_class($this)."::add_to_target_spec mailing ".$num." targets found");
+
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($result);
+
+ if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
+ if (!array_key_exists($obj->email, $cibles)) {
+ $cibles[$obj->email] = array(
+ 'email' => $obj->email,
+ 'fk_contact' =>$obj->id,
+ 'lastname' => $obj->lastname,
+ 'firstname' => $obj->firstname,
+ 'other' => '',
+ 'source_url' => $this->url($obj->id, 'contact'),
+ 'source_id' => $obj->id,
+ 'source_type' => 'contact'
+ );
+ }
+ }
+
+ $i++;
+ }
+ }
+ else
+ {
+ dol_syslog($this->db->error());
+ $this->error = $this->db->error();
+ return -1;
+ }
}
}
@@ -268,7 +272,9 @@
$s .= '';
$i++;
}
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
}
--- /tmp/dsg/dolibarr/htdocs/core/modules/mailings/github_contacts1.modules.php
+++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_contacts1.modules.php
@@ -44,23 +44,23 @@
public $picto = 'contact';
/**
- * @var DoliDB Database handler.
- */
- public $db;
-
-
- /**
- * Constructor
- *
- * @param DoliDB $db Database handler
- */
- public function __construct($db)
- {
- $this->db = $db;
- }
-
-
- /**
+ * @var DoliDB Database handler.
+ */
+ public $db;
+
+
+ /**
+ * Constructor
+ *
+ * @param DoliDB $db Database handler
+ */
+ public function __construct($db)
+ {
+ $this->db = $db;
+ }
+
+
+ /**
* 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:
@@ -68,14 +68,14 @@
*
* @return string[] Array with SQL requests
*/
- public function getSqlArrayForStats()
- {
+ public function getSqlArrayForStats()
+ {
global $conf, $langs;
$langs->load("commercial");
$statssql = array();
- $statssql[0] = "SELECT '".$this->db->escape($langs->trans("NbOfCompaniesContacts"))."' as label,";
+ $statssql[0] = "SELECT '".$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('socpeople').")";
@@ -84,7 +84,7 @@
$statssql[0] .= " AND c.statut = 1";
return $statssql;
- }
+ }
/**
@@ -95,13 +95,13 @@
* @param string $sql Requete sql de comptage
* @return int
*/
- public function getNbOfRecipients($sql = '')
- {
+ public function getNbOfRecipients($sql = '')
+ {
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 .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = c.fk_soc";
$sql .= " WHERE c.entity IN (".getEntity('socpeople').")";
$sql .= " AND c.email != ''"; // Note that null != '' is false
$sql .= " AND c.no_email = 0";
@@ -111,7 +111,7 @@
// The request must return a field called "nb" to be understandable by parent::getNbOfRecipients
return parent::getNbOfRecipients($sql);
- }
+ }
/**
@@ -119,12 +119,12 @@
*
* @return string Retourne zone select
*/
- public function formFilter()
- {
+ public function formFilter()
+ {
global $langs;
// Load translation files required by the page
- $langs->loadLangs(array("commercial", "companies", "suppliers", "categories"));
+ $langs->loadLangs(array("commercial", "companies", "suppliers", "categories"));
$s = '';
@@ -153,7 +153,8 @@
$s .= '';
$i++;
}
- } else dol_print_error($this->db);
+ }
+ else dol_print_error($this->db);
$s .= '';
$s .= ' ';
@@ -189,10 +190,13 @@
$s .= '';
$i++;
}
- } else {
+ }
+ else
+ {
$s .= '';
}
- } else dol_print_error($this->db);
+ }
+ else dol_print_error($this->db);
$s .= '';
$s .= '
';
@@ -221,7 +225,8 @@
$s .= '';
$i++;
}
- } else dol_print_error($this->db);
+ }
+ else dol_print_error($this->db);
$s .= '';
//$s.='';
$s .= '';
@@ -260,10 +265,13 @@
$s .= '';
$i++;
}
- } else {
+ }
+ else
+ {
$s .= '';
}
- } else dol_print_error($this->db);
+ }
+ else dol_print_error($this->db);
$s .= '';
$s .= ' ';
@@ -299,38 +307,41 @@
$s .= '';
$i++;
}
- } else {
+ }
+ else
+ {
$s .= '';
}
- } else dol_print_error($this->db);
+ }
+ else dol_print_error($this->db);
$s .= '';
return $s;
- }
+ }
/**
* Renvoie url lien vers fiche de la source du destinataire du mailing
*
- * @param int $id ID
+ * @param int $id ID
* @return string Url lien
*/
- public function url($id)
- {
- return ''.img_object('', "contact").'';
- }
-
-
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ public function url($id)
+ {
+ return ''.img_object('', "contact").'';
+ }
+
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Ajoute destinataires dans table des cibles
*
* @param int $mailing_id Id of emailing
* @return int <0 si erreur, nb ajout si ok
*/
- public function add_to_target($mailing_id)
- {
- // phpcs:enable
+ public function add_to_target($mailing_id)
+ {
+ // phpcs:enable
global $conf, $langs;
$filter = GETPOST('filter', 'alpha');
@@ -358,20 +369,21 @@
$prospectlevel[$obj->code] = $obj->label;
$i++;
}
- } else dol_print_error($this->db);
+ }
+ else dol_print_error($this->db);
// 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";
- 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('socpeople').")";
+ $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('socpeople').")";
$sql .= " AND sp.email <> ''";
$sql .= " AND sp.no_email = 0";
$sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = sp.email) = 0";
@@ -380,17 +392,17 @@
$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 <> '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_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
+ if ($filter_category_supplier <> 'all') $sql .= " AND c3.label = '".$this->db->escape($filter_category_supplier)."'";
+ // Filter on nature
$key = $filter;
{
//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='".$this->db->escape($codelevel)."'";
+ 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";
}
@@ -417,17 +429,17 @@
if ($old <> $obj->email)
{
$cibles[$j] = 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) : '')).';'.
- ($langs->transnoentities("JobPosition").'='.$obj->jobposition),
+ '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) : '')).';'.
+ ($langs->transnoentities("JobPosition").'='.$obj->jobposition),
'source_url' => $this->url($obj->id),
- 'source_id' => $obj->id,
- 'source_type' => 'contact'
+ 'source_id' => $obj->id,
+ 'source_type' => 'contact'
);
$old = $obj->email;
$j++;
@@ -435,12 +447,14 @@
$i++;
}
- } else {
+ }
+ else
+ {
dol_syslog($this->db->error());
$this->error = $this->db->error();
return -1;
}
return parent::addTargetsToDatabase($mailing_id, $cibles);
- }
+ }
}
--- /tmp/dsg/dolibarr/htdocs/core/modules/mailings/github_example.modules.php
+++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_example.modules.php
@@ -25,70 +25,70 @@
*/
class mailing_example extends MailingTargets
{
- // CHANGE THIS: Put here a name not already used
- public $name = 'example';
- // CHANGE THIS: Put here a description of your selector module.
- // This label is used if no translation is found for key MailingModuleDescXXX where XXX=name is found
- public $desc = 'Put here a description';
- // CHANGE THIS: Set to 1 if selector is available for admin users only
- public $require_admin = 0;
- // CHANGE THIS: Add a tooltip language key to add a tooltip help icon after the email target selector
- public $tooltip = 'MyTooltipLangKey';
+ // CHANGE THIS: Put here a name not already used
+ public $name = 'example';
+ // CHANGE THIS: Put here a description of your selector module.
+ // This label is used if no translation is found for key MailingModuleDescXXX where XXX=name is found
+ public $desc = 'Put here a description';
+ // CHANGE THIS: Set to 1 if selector is available for admin users only
+ public $require_admin = 0;
+ // CHANGE THIS: Add a tooltip language key to add a tooltip help icon after the email target selector
+ public $tooltip = 'MyTooltipLangKey';
- public $require_module = array();
+ public $require_module = array();
- /**
- * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
- */
- public $picto = '';
+ /**
+ * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
+ */
+ public $picto = '';
- /**
- * @var DoliDB Database handler.
- */
- public $db;
+ /**
+ * @var DoliDB Database handler.
+ */
+ public $db;
- // CHANGE THIS: Constructor name must be called mailing_xxx with xxx=name of your selector
+ // CHANGE THIS: Constructor name must be called mailing_xxx with xxx=name of your selector
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
- public function __construct($db)
- {
- $this->db = $db;
- }
+ public function __construct($db)
+ {
+ $this->db = $db;
+ }
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
- /**
- * This is the main function that returns the array of emails
- *
- * @param int $mailing_id Id of mailing. No need to use it.
- * @return int <0 if error, number of emails added if ok
- */
- public function add_to_target($mailing_id)
- {
- // phpcs:enable
- $target = array();
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * This is the main function that returns the array of emails
+ *
+ * @param int $mailing_id Id of mailing. No need to use it.
+ * @return int <0 if error, number of emails added if ok
+ */
+ public function add_to_target($mailing_id)
+ {
+ // phpcs:enable
+ $target = array();
- // CHANGE THIS
- // ----- Your code start here -----
+ // 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', 'other'=>'other_0');
+ // You must fill the $target array with record like this
+ // $target[0]=array('email'=>'email_0','name'=>'name_0','firstname'=>'firstname_0', 'other'=>'other_0');
// ...
- // $target[n]=array('email'=>'email_n','name'=>'name_n','firstname'=>'firstname_n', 'other'=>'other_n');
+ // $target[n]=array('email'=>'email_n','name'=>'name_n','firstname'=>'firstname_n', 'other'=>'other_n');
// Example: $target[0]=array('email'=>'myemail@example.com', 'name'=>'Doe', 'firstname'=>'John', 'other'=>'Other information');
// ----- Your code end here -----
- return parent::addTargetsToDatabase($mailing_id, $target);
- }
+ return parent::addTargetsToDatabase($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:
@@ -96,59 +96,59 @@
*
* @return array Array with SQL requests
*/
- public function getSqlArrayForStats()
+ public function getSqlArrayForStats()
{
- // CHANGE THIS: Optionnal
+ // 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";
+ //$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|string Number of recipient or '?'
- */
- public function getNbOfRecipients($sql = '')
- {
- // CHANGE THIS: Optionnal
+ /**
+ * 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|string Number of recipient or '?'
+ */
+ public function getNbOfRecipients($sql = '')
+ {
+ // CHANGE THIS: Optionnal
- // Example: return parent::getNbOfRecipients("SELECT count(*) as nb from dolibarr_table");
- // Example: return 500;
- return '?';
- }
+ // Example: return parent::getNbOfRecipients("SELECT count(*) as nb from dolibarr_table");
+ // Example: return 500;
+ return '?';
+ }
- /**
- * 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
- */
- public function formFilter()
- {
- // CHANGE THIS: Optionnal
+ /**
+ * 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
+ */
+ public function formFilter()
+ {
+ // CHANGE THIS: Optionnal
- $s = '';
- return $s;
- }
+ $s = '';
+ return $s;
+ }
- /**
- * Can include an URL link on each record provided by selector
- * shown on target page.
- *
- * @param int $id ID
- * @return string Url link
- */
- public function url($id)
- {
- // CHANGE THIS: Optionnal
+ /**
+ * Can include an URL link on each record provided by selector
+ * shown on target page.
+ *
+ * @param int $id ID
+ * @return string Url link
+ */
+ public function url($id)
+ {
+ // CHANGE THIS: Optionnal
- return '';
- }
+ return '';
+ }
}
--- /tmp/dsg/dolibarr/htdocs/core/modules/mailings/github_fraise.modules.php
+++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_fraise.modules.php
@@ -33,286 +33,294 @@
*/
class mailing_fraise extends MailingTargets
{
- public $name = 'FundationMembers'; // Identifiant du module mailing
+ public $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
- public $desc = 'Foundation members with emails';
- // Set to 1 if selector is available for admin users only
- public $require_admin = 0;
-
- public $require_module = array('adherent');
-
- /**
- * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
- */
- public $picto = 'user';
-
- /**
- * @var DoliDB Database handler.
- */
- public $db;
-
- /**
- * Constructor
- *
- * @param DoliDB $db Database handler
- */
- public function __construct($db)
- {
- $this->db = $db;
- }
-
-
- /**
- * 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
- */
- public function getSqlArrayForStats()
- {
- global $langs;
-
- $langs->load("members");
-
- // Array for requests for statistics board
- $statssql = array();
-
- $statssql[0] = "SELECT '".$this->db->escape($langs->trans("FundationMembers"))."' as label, count(*) as nb";
- $statssql[0] .= " FROM ".MAIN_DB_PREFIX."adherent where statut = 1 and entity IN (".getEntity('member').")";
-
- return $statssql;
- }
-
-
- /**
- * 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
- */
- public function getNbOfRecipients($sql = '')
- {
- $sql = "SELECT count(distinct(a.email)) as nb";
- $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
- $sql .= " WHERE (a.email IS NOT NULL AND a.email != '') AND a.entity IN (".getEntity('member').")";
-
- // La requete doit retourner un champ "nb" pour etre comprise
- // par parent::getNbOfRecipients
- return parent::getNbOfRecipients($sql);
- }
-
-
- /**
- * 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;
-
- // Load translation files required by the page
- $langs->loadLangs(array("members", "companies", "categories"));
-
- $form = new Form($this->db);
-
- $s = '';
-
- // Status
- $s .= $langs->trans("Status").': ';
- $s .= ' ';
- $s .= $langs->trans("Type").': ';
- $s .= '';
-
- $s .= ' ';
-
- $s .= $langs->trans("Category").': ';
- $s .= '';
-
-
- $s .= '
';
- $s .= $langs->trans("DateEndSubscription").': ';
- $s .= $langs->trans("After").' > '.$form->selectDate(-1, 'subscriptionafter', 0, 0, 1, 'fraise', 1, 0, 0);
- $s .= ' ';
- $s .= $langs->trans("Before").' < '.$form->selectDate(-1, 'subscriptionbefore', 0, 0, 1, 'fraise', 1, 0, 0);
-
- return $s;
- }
-
-
- /**
- * Renvoie url lien vers fiche de la source du destinataire du mailing
- *
- * @param int $id ID
- * @return string Url lien
- */
- public function url($id)
- {
- return ''.img_object('', "user").'';
- }
-
-
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
- /**
- * Ajoute destinataires dans table des cibles
- *
- * @param int $mailing_id Id of emailing
- * @return int < 0 si erreur, nb ajout si ok
- */
- public function add_to_target($mailing_id)
- {
- // phpcs:enable
- global $langs, $_POST;
-
- // Load translation files required by the page
- $langs->loadLangs(array("members", "companies"));
-
- $cibles = array();
- $now = dol_now();
-
- $dateendsubscriptionafter = dol_mktime(GETPOST('subscriptionafterhour', 'int'), GETPOST('subscriptionaftermin', 'int'), GETPOST('subscriptionaftersec', 'int'), GETPOST('subscriptionaftermonth', 'int'), GETPOST('subscriptionafterday', 'int'), GETPOST('subscriptionafteryear', 'int'));
- $dateendsubscriptionbefore = dol_mktime(GETPOST('subscriptionbeforehour', 'int'), GETPOST('subscriptionbeforemin', 'int'), GETPOST('subscriptionbeforesec', 'int'), GETPOST('subscriptionbeforemonth', 'int'), GETPOST('subscriptionbeforeday', 'int'), GETPOST('subscriptionbeforeyear', 'int'));
-
- // La requete doit retourner: id, email, fk_contact, name, firstname
- $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";
- if (GETPOST('filter_category'))
- {
- $sql .= " INNER JOIN ".MAIN_DB_PREFIX."categorie_member as cm ON cm.fk_member = a.rowid";
- $sql .= " INNER JOIN ".MAIN_DB_PREFIX."categorie as c ON c.rowid = cm.fk_categorie AND c.rowid = ".((int) GETPOST('filter_category', 'int'));
- }
- $sql .= " , ".MAIN_DB_PREFIX."adherent_type as ta";
- $sql .= " WHERE a.entity IN (".getEntity('member').") AND a.email <> ''"; // Note that null != '' is false
- $sql .= " AND a.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$this->db->escape($mailing_id).")";
- // Filter on status
- if (GETPOST("filter") == '-1') {
- $sql .= " AND a.statut=-1";
- }
- if (GETPOST("filter", 'aZ09') == '1a') $sql .= " AND a.statut=1 AND (a.datefin >= '".$this->db->idate($now)."' OR ta.subscription = 0)";
- if (GETPOST("filter", 'aZ09') == '1b') $sql .= " AND a.statut=1 AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."') AND ta.subscription = 1)";
- if (GETPOST("filter", 'aZ09') === '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";
- // Filter on type
- if (GETPOST('filter_type', 'int') > 0) $sql .= " AND ta.rowid='".$this->db->escape(GETPOST('filter_type', 'int'))."'";
- $sql .= " ORDER BY a.email";
- //print $sql;
-
- // Add targets into table
- dol_syslog(get_class($this)."::add_to_target", LOG_DEBUG);
- $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),
- '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::addTargetsToDatabase($mailing_id, $cibles);
- }
+ public $desc = 'Foundation members with emails';
+ // Set to 1 if selector is available for admin users only
+ public $require_admin = 0;
+
+ public $require_module = array('adherent');
+
+ /**
+ * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
+ */
+ public $picto = 'user';
+
+ /**
+ * @var DoliDB Database handler.
+ */
+ public $db;
+
+ /**
+ * Constructor
+ *
+ * @param DoliDB $db Database handler
+ */
+ public function __construct($db)
+ {
+ $this->db = $db;
+ }
+
+
+ /**
+ * 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
+ */
+ public function getSqlArrayForStats()
+ {
+ global $langs;
+
+ $langs->load("members");
+
+ // Array for requests for statistics board
+ $statssql = array();
+
+ $statssql[0] = "SELECT '".$this->db->escape($langs->trans("FundationMembers"))."' as label, count(*) as nb";
+ $statssql[0] .= " FROM ".MAIN_DB_PREFIX."adherent where statut = 1 and entity IN (".getEntity('member').")";
+
+ return $statssql;
+ }
+
+
+ /**
+ * 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
+ */
+ public function getNbOfRecipients($sql = '')
+ {
+ $sql = "SELECT count(distinct(a.email)) as nb";
+ $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
+ $sql .= " WHERE (a.email IS NOT NULL AND a.email != '') AND a.entity IN (".getEntity('member').")";
+
+ // La requete doit retourner un champ "nb" pour etre comprise
+ // par parent::getNbOfRecipients
+ return parent::getNbOfRecipients($sql);
+ }
+
+
+ /**
+ * 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;
+
+ // Load translation files required by the page
+ $langs->loadLangs(array("members", "companies", "categories"));
+
+ $form = new Form($this->db);
+
+ $s = '';
+
+ // Status
+ $s .= $langs->trans("Status").': ';
+ $s .= ' ';
+ $s .= $langs->trans("Type").': ';
+ $s .= '';
+
+ $s .= ' ';
+
+ $s .= $langs->trans("Category").': ';
+ $s .= '';
+
+
+ $s .= '
';
+ $s .= $langs->trans("DateEndSubscription").': ';
+ $s .= $langs->trans("After").' > '.$form->selectDate(-1, 'subscriptionafter', 0, 0, 1, 'fraise', 1, 0, 0);
+ $s .= ' ';
+ $s .= $langs->trans("Before").' < '.$form->selectDate(-1, 'subscriptionbefore', 0, 0, 1, 'fraise', 1, 0, 0);
+
+ return $s;
+ }
+
+
+ /**
+ * Renvoie url lien vers fiche de la source du destinataire du mailing
+ *
+ * @param int $id ID
+ * @return string Url lien
+ */
+ public function url($id)
+ {
+ return ''.img_object('', "user").'';
+ }
+
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * Ajoute destinataires dans table des cibles
+ *
+ * @param int $mailing_id Id of emailing
+ * @return int < 0 si erreur, nb ajout si ok
+ */
+ public function add_to_target($mailing_id)
+ {
+ // phpcs:enable
+ global $langs, $_POST;
+
+ // Load translation files required by the page
+ $langs->loadLangs(array("members", "companies"));
+
+ $cibles = array();
+ $now = dol_now();
+
+ $dateendsubscriptionafter = dol_mktime($_POST['subscriptionafterhour'], $_POST['subscriptionaftermin'], $_POST['subscriptionaftersec'], $_POST['subscriptionaftermonth'], $_POST['subscriptionafterday'], $_POST['subscriptionafteryear']);
+ $dateendsubscriptionbefore = dol_mktime($_POST['subscriptionbeforehour'], $_POST['subscriptionbeforemin'], $_POST['subscriptionbeforesec'], $_POST['subscriptionbeforemonth'], $_POST['subscriptionbeforeday'], $_POST['subscriptionbeforeyear']);
+
+ // La requete doit retourner: id, email, fk_contact, name, firstname
+ $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";
+ 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.entity IN (".getEntity('member').") AND a.email <> ''"; // Note that null != '' is false
+ $sql .= " AND a.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$this->db->escape($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)."' OR ta.subscription = 0)";
+ if (isset($_POST["filter"]) && $_POST["filter"] == '1b') $sql .= " AND a.statut=1 AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."') AND ta.subscription = 1)";
+ 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";
+ // 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
+ dol_syslog(get_class($this)."::add_to_target", LOG_DEBUG);
+ $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),
+ '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::addTargetsToDatabase($mailing_id, $cibles);
+ }
}
--- /tmp/dsg/dolibarr/htdocs/core/modules/mailings/github_modules_mailings.php
+++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_modules_mailings.php
@@ -31,181 +31,185 @@
*/
class MailingTargets // This can't be abstract as it is used for some method
{
- /**
- * @var DoliDB Database handler.
- */
- public $db;
-
- /**
+ /**
+ * @var DoliDB Database handler.
+ */
+ public $db;
+
+ /**
* @var string Error code (or message)
*/
public $error = '';
- public $tooltip = '';
-
-
- /**
+ public $tooltip = '';
+
+
+ /**
* Constructor
*
* @param DoliDB $db Database handler
*/
- public function __construct($db)
+ public function __construct($db)
{
- $this->db = $db;
+ $this->db = $db;
}
- /**
- * Return description of email selector
- *
- * @return string Return translation of module label. Try translation of $this->name then translation of 'MailingModuleDesc'.$this->name, or $this->desc if not found
- */
- public function getDesc()
- {
- global $langs, $form;
-
- $langs->load("mails");
- $transstring = "MailingModuleDesc".$this->name;
- $s = '';
-
- if ($langs->trans($this->name) != $this->name) $s = $langs->trans($this->name);
- elseif ($langs->trans($transstring) != $transstring) $s = $langs->trans($transstring);
- else $s = $this->desc;
-
- if ($this->tooltip && is_object($form)) $s .= ' '.$form->textwithpicto('', $langs->trans($this->tooltip), 1, 1);
- return $s;
- }
-
- /**
+ /**
+ * Return description of email selector
+ *
+ * @return string Return translation of module label. Try translation of $this->name then translation of 'MailingModuleDesc'.$this->name, or $this->desc if not found
+ */
+ public function getDesc()
+ {
+ global $langs, $form;
+
+ $langs->load("mails");
+ $transstring = "MailingModuleDesc".$this->name;
+ $s = '';
+
+ if ($langs->trans($this->name) != $this->name) $s = $langs->trans($this->name);
+ elseif ($langs->trans($transstring) != $transstring) $s = $langs->trans($transstring);
+ else $s = $this->desc;
+
+ if ($this->tooltip && is_object($form)) $s .= ' '.$form->textwithpicto('', $langs->trans($this->tooltip), 1, 1);
+ return $s;
+ }
+
+ /**
* Return number of records for email selector
- *
- * @return integer Example
- */
- public function getNbOfRecords()
- {
- return 0;
- }
-
- /**
- * Retourne nombre de destinataires
- *
- * @param string $sql Sql request to count
- * @return int Nb of recipient, or <0 if error
- */
- public function getNbOfRecipients($sql)
- {
- $result = $this->db->query($sql);
- if ($result)
- {
- $obj = $this->db->fetch_object($result);
- return $obj->nb;
- } else {
- $this->error = $this->db->lasterror();
- return -1;
- }
- }
-
- /**
- * Affiche formulaire de filtre qui apparait dans page de selection
- * des destinataires de mailings
- *
- * @return string Retourne zone select
- */
- public function formFilter()
- {
- return '';
- }
-
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
- /**
- * Met a jour nombre de destinataires
- *
- * @param int $mailing_id Id of emailing
- * @return int < 0 si erreur, nb destinataires si ok
- */
- public function update_nb($mailing_id)
- {
- // phpcs:enable
- // Mise a jour nombre de destinataire dans table des mailings
- $sql = "SELECT COUNT(*) nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
- $sql .= " WHERE fk_mailing = ".$mailing_id;
- $result = $this->db->query($sql);
- if ($result)
- {
- $obj = $this->db->fetch_object($result);
- $nb = $obj->nb;
-
- $sql = "UPDATE ".MAIN_DB_PREFIX."mailing";
- $sql .= " SET nbemail = ".$nb." WHERE rowid = ".$mailing_id;
- if (!$this->db->query($sql))
- {
- dol_syslog($this->db->error());
- $this->error = $this->db->error();
- return -1;
- }
- } else {
- return -1;
- }
- return $nb;
- }
-
- /**
- * Add a list of targets int the database
- *
- * @param int $mailing_id Id of emailing
- * @param array $cibles Array with targets
- * @return int < 0 si erreur, nb ajout si ok
- */
- public function addTargetsToDatabase($mailing_id, $cibles)
- {
- global $conf;
- global $dolibarr_main_instance_unique_id;
-
- $this->db->begin();
-
- // Insert emailing targets from array into database
- $j = 0;
- $num = count($cibles);
- foreach ($cibles as $targetarray)
- {
- if (!empty($targetarray['email'])) // avoid empty email address
- {
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles";
- $sql .= " (fk_mailing,";
- $sql .= " fk_contact,";
- $sql .= " lastname, firstname, email, other, source_url, source_id,";
- $sql .= " tag,";
- $sql .= " source_type)";
- $sql .= " VALUES (".$mailing_id.",";
- $sql .= (empty($targetarray['fk_contact']) ? '0' : "'".$this->db->escape($targetarray['fk_contact'])."'").",";
- $sql .= "'".$this->db->escape($targetarray['lastname'])."',";
- $sql .= "'".$this->db->escape($targetarray['firstname'])."',";
- $sql .= "'".$this->db->escape($targetarray['email'])."',";
- $sql .= "'".$this->db->escape($targetarray['other'])."',";
- $sql .= "'".$this->db->escape($targetarray['source_url'])."',";
- $sql .= (empty($targetarray['source_id']) ? 'null' : "'".$this->db->escape($targetarray['source_id'])."'").",";
- $sql .= "'".$this->db->escape(dol_hash($dolibarr_main_instance_unique_id.';'.$targetarray['email'].';'.$targetarray['lastname'].';'.$mailing_id.';'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY), 'md5')."',";
- $sql .= "'".$this->db->escape($targetarray['source_type'])."')";
- dol_syslog(__METHOD__, LOG_DEBUG);
- $result = $this->db->query($sql);
- if ($result)
- {
- $j++;
- } else {
- if ($this->db->errno() != 'DB_ERROR_RECORD_ALREADY_EXISTS')
- {
- // Si erreur autre que doublon
- dol_syslog($this->db->error().' : '.$targetarray['email']);
- $this->error = $this->db->error().' : '.$targetarray['email'];
- $this->db->rollback();
- return -1;
- }
- }
- }
- }
-
- dol_syslog(__METHOD__.": mailing ".$j." targets added");
-
- /*
+ *
+ * @return integer Example
+ */
+ public function getNbOfRecords()
+ {
+ return 0;
+ }
+
+ /**
+ * Retourne nombre de destinataires
+ *
+ * @param string $sql Sql request to count
+ * @return int Nb of recipient, or <0 if error
+ */
+ public function getNbOfRecipients($sql)
+ {
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ $obj = $this->db->fetch_object($result);
+ return $obj->nb;
+ }
+ else
+ {
+ $this->error = $this->db->lasterror();
+ return -1;
+ }
+ }
+
+ /**
+ * Affiche formulaire de filtre qui apparait dans page de selection
+ * des destinataires de mailings
+ *
+ * @return string Retourne zone select
+ */
+ public function formFilter()
+ {
+ return '';
+ }
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * Met a jour nombre de destinataires
+ *
+ * @param int $mailing_id Id of emailing
+ * @return int < 0 si erreur, nb destinataires si ok
+ */
+ public function update_nb($mailing_id)
+ {
+ // phpcs:enable
+ // Mise a jour nombre de destinataire dans table des mailings
+ $sql = "SELECT COUNT(*) nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
+ $sql .= " WHERE fk_mailing = ".$mailing_id;
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ $obj = $this->db->fetch_object($result);
+ $nb = $obj->nb;
+
+ $sql = "UPDATE ".MAIN_DB_PREFIX."mailing";
+ $sql .= " SET nbemail = ".$nb." WHERE rowid = ".$mailing_id;
+ if (!$this->db->query($sql))
+ {
+ dol_syslog($this->db->error());
+ $this->error = $this->db->error();
+ return -1;
+ }
+ }
+ else {
+ return -1;
+ }
+ return $nb;
+ }
+
+ /**
+ * Add a list of targets int the database
+ *
+ * @param int $mailing_id Id of emailing
+ * @param array $cibles Array with targets
+ * @return int < 0 si erreur, nb ajout si ok
+ */
+ public function addTargetsToDatabase($mailing_id, $cibles)
+ {
+ global $conf;
+
+ $this->db->begin();
+
+ // Insert emailing targets from array into database
+ $j = 0;
+ $num = count($cibles);
+ foreach ($cibles as $targetarray)
+ {
+ if (!empty($targetarray['email'])) // avoid empty email address
+ {
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles";
+ $sql .= " (fk_mailing,";
+ $sql .= " fk_contact,";
+ $sql .= " lastname, firstname, email, other, source_url, source_id,";
+ $sql .= " tag,";
+ $sql .= " source_type)";
+ $sql .= " VALUES (".$mailing_id.",";
+ $sql .= (empty($targetarray['fk_contact']) ? '0' : "'".$targetarray['fk_contact']."'").",";
+ $sql .= "'".$this->db->escape($targetarray['lastname'])."',";
+ $sql .= "'".$this->db->escape($targetarray['firstname'])."',";
+ $sql .= "'".$this->db->escape($targetarray['email'])."',";
+ $sql .= "'".$this->db->escape($targetarray['other'])."',";
+ $sql .= "'".$this->db->escape($targetarray['source_url'])."',";
+ $sql .= (empty($targetarray['source_id']) ? 'null' : "'".$this->db->escape($targetarray['source_id'])."'").",";
+ $sql .= "'".$this->db->escape(dol_hash($targetarray['email'].';'.$targetarray['lastname'].';'.$mailing_id.';'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY))."',";
+ $sql .= "'".$this->db->escape($targetarray['source_type'])."')";
+ dol_syslog(__METHOD__, LOG_DEBUG);
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ $j++;
+ }
+ else
+ {
+ if ($this->db->errno() != 'DB_ERROR_RECORD_ALREADY_EXISTS')
+ {
+ // Si erreur autre que doublon
+ dol_syslog($this->db->error().' : '.$targetarray['email']);
+ $this->error = $this->db->error().' : '.$targetarray['email'];
+ $this->db->rollback();
+ return -1;
+ }
+ }
+ }
+ }
+
+ dol_syslog(__METHOD__.": mailing ".$j." targets added");
+
+ /*
//Update the status to show thirdparty mail that don't want to be contacted anymore'
$sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
$sql .= " SET statut=3";
@@ -223,42 +227,42 @@
$result=$this->db->query($sql);
*/
- $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
- $sql .= " SET statut=3";
- $sql .= " WHERE fk_mailing=".$mailing_id." AND email IN (SELECT mu.email FROM ".MAIN_DB_PREFIX."mailing_unsubscribe AS mu WHERE mu.entity IN ('".getEntity('mailing')."'))";
-
- dol_syslog(__METHOD__.":mailing update status to display emails that do not want to be contacted anymore", LOG_DEBUG);
- $result = $this->db->query($sql);
- if (!$result)
- {
- dol_print_error($this->db);
- }
-
- $this->update_nb($mailing_id);
-
- $this->db->commit();
-
- return $j;
- }
-
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
- /**
- * Supprime tous les destinataires de la table des cibles
- *
- * @param int $mailing_id Id of emailing
- * @return void
- */
- public function clear_target($mailing_id)
- {
- // phpcs:enable
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles";
- $sql .= " WHERE fk_mailing = ".$mailing_id;
-
- if (!$this->db->query($sql))
- {
- dol_syslog($this->db->error());
- }
-
- $this->update_nb($mailing_id);
- }
+ $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
+ $sql .= " SET statut=3";
+ $sql .= " WHERE fk_mailing=".$mailing_id." AND email IN (SELECT mu.email FROM ".MAIN_DB_PREFIX."mailing_unsubscribe AS mu WHERE mu.entity IN ('".getEntity('mailing')."'))";
+
+ dol_syslog(__METHOD__.":mailing update status to display emails that do not want to be contacted anymore", LOG_DEBUG);
+ $result = $this->db->query($sql);
+ if (!$result)
+ {
+ dol_print_error($this->db);
+ }
+
+ $this->update_nb($mailing_id);
+
+ $this->db->commit();
+
+ return $j;
+ }
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * Supprime tous les destinataires de la table des cibles
+ *
+ * @param int $mailing_id Id of emailing
+ * @return void
+ */
+ public function clear_target($mailing_id)
+ {
+ // phpcs:enable
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles";
+ $sql .= " WHERE fk_mailing = ".$mailing_id;
+
+ if (!$this->db->query($sql))
+ {
+ dol_syslog($this->db->error());
+ }
+
+ $this->update_nb($mailing_id);
+ }
}
--- /tmp/dsg/dolibarr/htdocs/core/modules/mailings/github_pomme.modules.php
+++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_pomme.modules.php
@@ -42,9 +42,9 @@
public $picto = 'user';
/**
- * @var DoliDB Database handler.
- */
- public $db;
+ * @var DoliDB Database handler.
+ */
+ public $db;
/**
@@ -52,13 +52,13 @@
*
* @param DoliDB $db Database handler
*/
- public function __construct($db)
+ public function __construct($db)
{
$this->db = $db;
}
- /**
+ /**
* 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:
@@ -66,14 +66,14 @@
*
* @return string[] Array with SQL requests
*/
- public function getSqlArrayForStats()
+ public function getSqlArrayForStats()
{
global $conf, $langs;
$langs->load("users");
$statssql = array();
- $sql = "SELECT '".$this->db->escape($langs->trans("DolibarrUsers"))."' as label,";
+ $sql = "SELECT '".$langs->trans("DolibarrUsers")."' as label,";
$sql .= " 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
@@ -84,15 +84,15 @@
}
- /**
- * 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 SQL request to use to count
- * @return int Number of recipients
- */
- public function getNbOfRecipients($sql = '')
+ /**
+ * 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 SQL request to use to count
+ * @return int Number of recipients
+ */
+ public function getNbOfRecipients($sql = '')
{
global $conf;
@@ -112,7 +112,7 @@
*
* @return string Retourne zone select
*/
- public function formFilter()
+ public function formFilter()
{
global $langs;
@@ -141,26 +141,26 @@
/**
* Renvoie url lien vers fiche de la source du destinataire du mailing
*
- * @param int $id ID
+ * @param int $id ID
* @return string Url lien
*/
- public function url($id)
+ public function url($id)
{
return ''.img_object('', "user").'';
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Ajoute destinataires dans table des cibles
*
* @param int $mailing_id Id of emailing
* @return int < 0 si erreur, nb ajout si ok
*/
- public function add_to_target($mailing_id)
- {
- // phpcs:enable
- global $conf, $langs;
+ public function add_to_target($mailing_id)
+ {
+ // phpcs:enable
+ global $conf, $langs;
$langs->load("companies");
$cibles = array();
@@ -172,10 +172,10 @@
$sql .= " WHERE u.email <> ''"; // u.email IS NOT NULL est implicite dans ce test
$sql .= " AND u.entity IN (0,".$conf->entity.")";
$sql .= " AND u.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
- if (GETPOSTISSET("filter") && GETPOST("filter") == '1') $sql .= " AND u.statut=1";
- if (GETPOSTISSET("filter") && GETPOST("filter") == '0') $sql .= " AND u.statut=0";
- if (GETPOSTISSET("filteremployee") && GETPOSt("filteremployee") == '1') $sql .= " AND u.employee=1";
- if (GETPOSTISSET("filteremployee") && GETPOST("filteremployee") == '0') $sql .= " AND u.employee=0";
+ if (isset($_POST["filter"]) && $_POST["filter"] == '1') $sql .= " AND u.statut=1";
+ if (isset($_POST["filter"]) && $_POST["filter"] == '0') $sql .= " AND u.statut=0";
+ if (isset($_POST["filteremployee"]) && $_POST["filteremployee"] == '1') $sql .= " AND u.employee=1";
+ if (isset($_POST["filteremployee"]) && $_POST["filteremployee"] == '0') $sql .= " AND u.employee=0";
$sql .= " ORDER BY u.email";
// Stocke destinataires dans cibles
@@ -195,17 +195,17 @@
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("PhonePro").'='.$obj->office_phone),
- 'source_url' => $this->url($obj->id),
- 'source_id' => $obj->id,
- 'source_type' => 'user'
+ '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("PhonePro").'='.$obj->office_phone),
+ 'source_url' => $this->url($obj->id),
+ 'source_id' => $obj->id,
+ 'source_type' => 'user'
);
$old = $obj->email;
$j++;
@@ -213,12 +213,14 @@
$i++;
}
- } else {
+ }
+ else
+ {
dol_syslog($this->db->error());
$this->error = $this->db->error();
return -1;
}
return parent::addTargetsToDatabase($mailing_id, $cibles);
- }
+ }
}
--- /tmp/dsg/dolibarr/htdocs/core/modules/mailings/github_thirdparties.modules.php
+++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_thirdparties.modules.php
@@ -37,9 +37,9 @@
public $picto = 'company';
/**
- * @var DoliDB Database handler.
- */
- public $db;
+ * @var DoliDB Database handler.
+ */
+ public $db;
/**
@@ -47,95 +47,108 @@
*
* @param DoliDB $db Database handler
*/
- public function __construct($db)
+ public function __construct($db)
{
global $conf, $langs;
- $langs->load("companies");
+ $langs->load("companies");
$this->db = $db;
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* This is the main function that returns the array of emails
*
* @param int $mailing_id Id of mailing. No need to use it.
* @return int <0 if error, number of emails added if ok
*/
- public function add_to_target($mailing_id)
- {
- // phpcs:enable
+ public function add_to_target($mailing_id)
+ {
+ // phpcs:enable
global $conf, $langs;
$cibles = array();
- $addDescription = "";
+ $addDescription = "";
// Select the third parties from category
if (empty($_POST['filter']))
{
- $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 .= " FROM ".MAIN_DB_PREFIX."societe as s";
- $sql .= " WHERE s.email <> ''";
- $sql .= " AND s.entity IN (".getEntity('societe').")";
- $sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
- } else {
- $addFilter = "";
- if (GETPOSTISSET("filter_client") && GETPOST("filter_client") <> '-1') {
- $addFilter .= " AND s.client=".((int) GETPOST("filter_client", 'int'));
- $addDescription = $langs->trans('ProspectCustomer')."=";
- if ($_POST["filter_client"] == 0)
- {
- $addDescription .= $langs->trans('NorProspectNorCustomer');
- } elseif ($_POST["filter_client"] == 1)
- {
- $addDescription .= $langs->trans('Customer');
- } elseif ($_POST["filter_client"] == 2)
- {
- $addDescription .= $langs->trans('Prospect');
- } elseif ($_POST["filter_client"] == 3)
- {
- $addDescription .= $langs->trans('ProspectCustomer');
- } else {
- $addDescription .= "Unknown status ".GETPOST("filter_client");
- }
- }
- if (GETPOSTISSET("filter_status")) {
- if (strlen($addDescription) > 0) {
- $addDescription .= ";";
- }
- $addDescription .= $langs->trans("Status")."=";
- if (GETPOST("filter_status") == '1') {
- $addFilter .= " AND s.status=1";
- $addDescription .= $langs->trans("Enabled");
- } else {
- $addFilter .= " AND s.status=0";
- $addDescription .= $langs->trans("Disabled");
- }
- }
- $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_societe as cs, ".MAIN_DB_PREFIX."categorie as c";
- $sql .= " WHERE s.email <> ''";
- $sql .= " AND s.entity IN (".getEntity('societe').")";
- $sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
- $sql .= " AND cs.fk_soc = s.rowid";
- $sql .= " AND c.rowid = cs.fk_categorie";
- $sql .= " AND c.rowid=".((int) GETPOST('filter', 'int'));
- $sql .= $addFilter;
- $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 IN (".getEntity('societe').")";
- $sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
- $sql .= " AND cs.fk_soc = s.rowid";
- $sql .= " AND c.rowid = cs.fk_categorie";
- $sql .= " AND c.rowid=".((int) GETPOST('filter', 'int'));
- $sql .= $addFilter;
- }
- $sql .= " ORDER BY email";
-
- // Stock recipients emails into targets table
+ $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 .= " FROM ".MAIN_DB_PREFIX."societe as s";
+ $sql .= " WHERE s.email <> ''";
+ $sql .= " AND s.entity IN (".getEntity('societe').")";
+ $sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
+ }
+ else
+ {
+ $addFilter = "";
+ if (isset($_POST["filter_client"]) && $_POST["filter_client"] <> '-1')
+ {
+ $addFilter .= " AND s.client=".$_POST["filter_client"];
+ $addDescription = $langs->trans('ProspectCustomer')."=";
+ if ($_POST["filter_client"] == 0)
+ {
+ $addDescription .= $langs->trans('NorProspectNorCustomer');
+ }
+ elseif ($_POST["filter_client"] == 1)
+ {
+ $addDescription .= $langs->trans('Customer');
+ }
+ elseif ($_POST["filter_client"] == 2)
+ {
+ $addDescription .= $langs->trans('Prospect');
+ }
+ elseif ($_POST["filter_client"] == 3)
+ {
+ $addDescription .= $langs->trans('ProspectCustomer');
+ }
+ else
+ {
+ $addDescription .= "Unknown status ".$_POST["filter_client"];
+ }
+ }
+ if (isset($_POST["filter_status"]))
+ {
+ if (strlen($addDescription) > 0)
+ {
+ $addDescription .= ";";
+ }
+ $addDescription .= $langs->trans("Status")."=";
+ if ($_POST["filter_status"] == '1')
+ {
+ $addFilter .= " AND s.status=1";
+ $addDescription .= $langs->trans("Enabled");
+ }
+ else
+ {
+ $addFilter .= " AND s.status=0";
+ $addDescription .= $langs->trans("Disabled");
+ }
+ }
+ $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_societe as cs, ".MAIN_DB_PREFIX."categorie as c";
+ $sql .= " WHERE s.email <> ''";
+ $sql .= " AND s.entity IN (".getEntity('societe').")";
+ $sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
+ $sql .= " AND cs.fk_soc = s.rowid";
+ $sql .= " AND c.rowid = cs.fk_categorie";
+ $sql .= " AND c.rowid='".$this->db->escape($_POST['filter'])."'";
+ $sql .= $addFilter;
+ $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 IN (".getEntity('societe').")";
+ $sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
+ $sql .= " AND cs.fk_soc = s.rowid";
+ $sql .= " AND c.rowid = cs.fk_categorie";
+ $sql .= " AND c.rowid='".$this->db->escape($_POST['filter'])."'";
+ $sql .= $addFilter;
+ }
+ $sql .= " ORDER BY email";
+
+ // Stock recipients emails into targets table
$result = $this->db->query($sql);
if ($result)
{
@@ -158,14 +171,14 @@
}
$otherTxt .= $addDescription;
$cibles[$j] = array(
- 'email' => $obj->email,
- 'fk_contact' => $obj->fk_contact,
- 'lastname' => $obj->name, // For a thirdparty, we must use name
- 'firstname' => '', // For a thirdparty, lastname is ''
- 'other' => $otherTxt,
- 'source_url' => $this->url($obj->id),
- 'source_id' => $obj->id,
- 'source_type' => 'thirdparty'
+ 'email' => $obj->email,
+ 'fk_contact' => $obj->fk_contact,
+ 'lastname' => $obj->name, // For a thirdparty, we must use name
+ 'firstname' => '', // For a thirdparty, lastname is ''
+ 'other' => $otherTxt,
+ 'source_url' => $this->url($obj->id),
+ 'source_id' => $obj->id,
+ 'source_type' => 'thirdparty'
);
$old = $obj->email;
$j++;
@@ -173,7 +186,9 @@
$i++;
}
- } else {
+ }
+ else
+ {
dol_syslog($this->db->error());
$this->error = $this->db->error();
return -1;
@@ -183,7 +198,7 @@
}
- /**
+ /**
* 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:
@@ -191,7 +206,7 @@
*
* @return array Array with SQL requests
*/
- public function getSqlArrayForStats()
+ public function getSqlArrayForStats()
{
// CHANGE THIS: Optionnal
@@ -209,7 +224,7 @@
* @param string $sql Requete sql de comptage
* @return int Nb of recipients
*/
- public function getNbOfRecipients($sql = '')
+ public function getNbOfRecipients($sql = '')
{
global $conf;
@@ -229,7 +244,7 @@
*
* @return string A html select zone
*/
- public function formFilter()
+ public function formFilter()
{
global $conf, $langs;
@@ -270,44 +285,46 @@
$s .= '';
$i++;
}
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
}
$s .= ' ';
- $s .= $langs->trans('ProspectCustomer');
- $s .= ': ';
-
- $s .= $langs->trans("Status");
- $s .= ': ';
+ $s .= $langs->trans('ProspectCustomer');
+ $s .= ': ';
+
+ $s .= $langs->trans("Status");
+ $s .= ': ';
return $s;
}
- /**
+ /**
* Can include an URL link on each record provided by selector shown on target page.
*
- * @param int $id ID
+ * @param int $id ID
* @return string Url link
*/
- public function url($id)
+ public function url($id)
{
return ''.img_object('', "company").'';
}
--- /tmp/dsg/dolibarr/htdocs/core/modules/mailings/github_thirdparties_services_expired.modules.php
+++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_thirdparties_services_expired.modules.php
@@ -22,224 +22,228 @@
*/
class mailing_thirdparties_services_expired extends MailingTargets
{
- public $name = 'DolibarrContractsLinesExpired';
+ public $name = 'DolibarrContractsLinesExpired';
// This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
- public $desc = 'Third parties with expired contract\'s lines';
- public $require_admin = 0;
-
- public $require_module = array('contrat');
-
- /**
- * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
- */
- public $picto = 'company';
-
- /**
- * @var DoliDB Database handler.
- */
- public $db;
-
- public $arrayofproducts = array();
-
-
- /**
- * Constructor
- *
- * @param DoliDB $db Database handler
- */
- public function __construct($db)
- {
- global $conf;
-
- $this->db = $db;
-
- $this->arrayofproducts = array();
-
- // List of services
- $sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product";
- $sql .= " WHERE entity IN (".getEntity('product').")";
- if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) $sql .= " AND fk_product_type = 1"; // By default, only services
- $sql .= " ORDER BY ref";
- $result = $this->db->query($sql);
- if ($result)
- {
- $num = $this->db->num_rows($result);
- dol_syslog("dolibarr_services_expired.modules.php:mailing_dolibarr_services_expired ".$num." services found");
-
- $i = 0;
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($result);
- $i++;
- $this->arrayofproducts[$i] = $obj->ref;
- }
- } else {
- dol_print_error($this->db);
- }
- }
-
-
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
- /**
- * This is the main function that returns the array of emails
- *
- * @param int $mailing_id Id of mailing. No need to use it.
- * @return int <0 if error, number of emails added if ok
- */
- public function add_to_target($mailing_id)
- {
- // phpcs:enable
- $key = GETPOST('filter', 'int');
-
- $cibles = array();
- $j = 0;
-
- $product = '';
- if ($key == '0')
- {
- $this->error = "Error: You must choose a filter";
- $this->errors[] = $this->error;
- return $this->error;
- }
-
- $product = $this->arrayofproducts[$key];
-
- $now = dol_now();
-
- // La requete doit retourner: id, email, name
- $sql = "SELECT s.rowid as id, s.email, s.nom as name, cd.rowid as cdid, cd.date_ouverture, cd.date_fin_validite, cd.fk_contrat";
- $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
- $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p";
- $sql .= " WHERE s.entity IN (".getEntity('societe').")";
- $sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
- $sql .= " AND s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''";
- $sql .= " AND cd.statut= 4 AND cd.fk_product=p.rowid AND p.ref = '".$this->db->escape($product)."'";
- $sql .= " AND cd.date_fin_validite < '".$this->db->idate($now)."'";
- $sql .= " ORDER BY s.email";
-
- // Stocke destinataires dans cibles
- $result = $this->db->query($sql);
- if ($result)
- {
- $num = $this->db->num_rows($result);
- $i = 0;
-
- dol_syslog(get_class($this)."::add_to_target ".$num." targets found");
-
- $old = '';
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($result);
- if ($old <> $obj->email)
- {
- $cibles[$j] = array(
+ public $desc = 'Third parties with expired contract\'s lines';
+ public $require_admin = 0;
+
+ public $require_module = array('contrat');
+
+ /**
+ * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
+ */
+ public $picto = 'company';
+
+ /**
+ * @var DoliDB Database handler.
+ */
+ public $db;
+
+ public $arrayofproducts = array();
+
+
+ /**
+ * Constructor
+ *
+ * @param DoliDB $db Database handler
+ */
+ public function __construct($db)
+ {
+ global $conf;
+
+ $this->db = $db;
+
+ $this->arrayofproducts = array();
+
+ // List of services
+ $sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product";
+ $sql .= " WHERE entity IN (".getEntity('product').")";
+ if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) $sql .= " AND fk_product_type = 1"; // By default, only services
+ $sql .= " ORDER BY ref";
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ $num = $this->db->num_rows($result);
+ dol_syslog("dolibarr_services_expired.modules.php:mailing_dolibarr_services_expired ".$num." services found");
+
+ $i = 0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($result);
+ $i++;
+ $this->arrayofproducts[$i] = $obj->ref;
+ }
+ }
+ else
+ {
+ dol_print_error($this->db);
+ }
+ }
+
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * This is the main function that returns the array of emails
+ *
+ * @param int $mailing_id Id of mailing. No need to use it.
+ * @return int <0 if error, number of emails added if ok
+ */
+ public function add_to_target($mailing_id)
+ {
+ // phpcs:enable
+ $key = GETPOST('filter', 'int');
+
+ $cibles = array();
+ $j = 0;
+
+ $product = '';
+ if ($key == '0')
+ {
+ $this->error = "Error: You must choose a filter";
+ $this->errors[] = $this->error;
+ return $this->error;
+ }
+
+ $product = $this->arrayofproducts[$key];
+
+ $now = dol_now();
+
+ // La requete doit retourner: id, email, name
+ $sql = "SELECT s.rowid as id, s.email, s.nom as name, cd.rowid as cdid, cd.date_ouverture, cd.date_fin_validite, cd.fk_contrat";
+ $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
+ $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p";
+ $sql .= " WHERE s.entity IN (".getEntity('societe').")";
+ $sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
+ $sql .= " AND s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''";
+ $sql .= " AND cd.statut= 4 AND cd.fk_product=p.rowid AND p.ref = '".$product."'";
+ $sql .= " AND cd.date_fin_validite < '".$this->db->idate($now)."'";
+ $sql .= " ORDER BY s.email";
+
+ // Stocke destinataires dans cibles
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ $num = $this->db->num_rows($result);
+ $i = 0;
+
+ dol_syslog(get_class($this)."::add_to_target ".$num." targets found");
+
+ $old = '';
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($result);
+ if ($old <> $obj->email)
+ {
+ $cibles[$j] = array(
'email' => $obj->email,
'lastname' => $obj->name, // For thirdparties, lastname must be name
- 'firstname' => '', // For thirdparties, firstname is ''
+ 'firstname' => '', // For thirdparties, firstname is ''
'other' =>
- ('DateStart='.dol_print_date($this->db->jdate($obj->date_ouverture), 'day')).';'.
- ('DateEnd='.dol_print_date($this->db->jdate($obj->date_fin_validite), 'day')).';'.
- ('Contract='.$obj->fk_contrat).';'.
- ('ContactLine='.$obj->cdid),
+ ('DateStart='.dol_print_date($this->db->jdate($obj->date_ouverture), 'day')).';'.
+ ('DateEnd='.dol_print_date($this->db->jdate($obj->date_fin_validite), 'day')).';'.
+ ('Contract='.$obj->fk_contrat).';'.
+ ('ContactLine='.$obj->cdid),
'source_url' => $this->url($obj->id),
'source_id' => $obj->id,
'source_type' => 'thirdparty'
- );
- $old = $obj->email;
- $j++;
- }
-
- $i++;
- }
- } else {
- dol_syslog($this->db->lasterror());
- $this->error = $this->db->lasterror();
- return -1;
- }
-
- // ----- Your code end here -----
-
- return parent::addTargetsToDatabase($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
- */
- public function getSqlArrayForStats()
- {
-
- //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 SQL request to use to count
- * @return int Number of recipients
- */
- public function getNbOfRecipients($sql = '')
- {
- $now = dol_now();
-
- // Example: return parent::getNbOfRecipients("SELECT count(*) as nb from dolibarr_table");
- // Example: return 500;
- $sql = "SELECT count(*) as nb";
- $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
- $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p";
- $sql .= " WHERE s.entity IN (".getEntity('societe').")";
- $sql .= " AND s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''";
- $sql .= " AND cd.statut= 4 AND cd.fk_product=p.rowid";
- $sql .= " AND p.ref IN ('".join("','", $this->arrayofproducts)."')";
- $sql .= " AND cd.date_fin_validite < '".$this->db->idate($now)."'";
-
- $a = parent::getNbOfRecipients($sql);
-
- return $a;
- }
-
- /**
- * 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
- */
- public function formFilter()
- {
- global $langs;
-
- $s = $langs->trans("ProductOrService");
- $s .= '';
- return $s;
- }
-
-
- /**
- * Can include an URL link on each record provided by selector shown on target page.
- *
- * @param int $id ID
- * @return string Url link
- */
- public function url($id)
- {
- return ''.img_object('', "company").'';
- }
+ );
+ $old = $obj->email;
+ $j++;
+ }
+
+ $i++;
+ }
+ }
+ else
+ {
+ dol_syslog($this->db->lasterror());
+ $this->error = $this->db->lasterror();
+ return -1;
+ }
+
+ // ----- Your code end here -----
+
+ return parent::addTargetsToDatabase($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
+ */
+ public function getSqlArrayForStats()
+ {
+
+ //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 SQL request to use to count
+ * @return int Number of recipients
+ */
+ public function getNbOfRecipients($sql = '')
+ {
+ $now = dol_now();
+
+ // Example: return parent::getNbOfRecipients("SELECT count(*) as nb from dolibarr_table");
+ // Example: return 500;
+ $sql = "SELECT count(*) as nb";
+ $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
+ $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p";
+ $sql .= " WHERE s.entity IN (".getEntity('societe').")";
+ $sql .= " AND s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''";
+ $sql .= " AND cd.statut= 4 AND cd.fk_product=p.rowid";
+ $sql .= " AND p.ref IN ('".join("','", $this->arrayofproducts)."')";
+ $sql .= " AND cd.date_fin_validite < '".$this->db->idate($now)."'";
+
+ $a = parent::getNbOfRecipients($sql);
+
+ return $a;
+ }
+
+ /**
+ * 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
+ */
+ public function formFilter()
+ {
+ global $langs;
+
+ $s = $langs->trans("ProductOrService");
+ $s .= '';
+ return $s;
+ }
+
+
+ /**
+ * Can include an URL link on each record provided by selector shown on target page.
+ *
+ * @param int $id ID
+ * @return string Url link
+ */
+ public function url($id)
+ {
+ return ''.img_object('', "company").'';
+ }
}
--- /tmp/dsg/dolibarr/htdocs/core/modules/mailings/github_xinputfile.modules.php
+++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_xinputfile.modules.php
@@ -30,31 +30,31 @@
*/
class mailing_xinputfile extends MailingTargets
{
- public $name = 'EmailsFromFile'; // Identifiant du module mailing
- // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
- public $desc = 'EMails from a file'; // Libelle utilise si aucune traduction pour MailingModuleDescXXX ou XXX=name trouv�e
- public $require_module = array(); // Module mailing actif si modules require_module actifs
- public $require_admin = 0; // Module mailing actif pour user admin ou non
-
- /**
- * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
- */
- public $picto = 'generic';
- public $tooltip = 'UseFormatFileEmailToTarget';
-
-
- /**
- * Constructor
- *
- * @param DoliDB $db Database handler
- */
- public function __construct($db)
- {
- $this->db = $db;
- }
-
-
- /**
+ public $name = 'EmailsFromFile'; // Identifiant du module mailing
+ // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
+ public $desc = 'EMails from a file'; // Libelle utilise si aucune traduction pour MailingModuleDescXXX ou XXX=name trouv�e
+ public $require_module = array(); // Module mailing actif si modules require_module actifs
+ public $require_admin = 0; // Module mailing actif pour user admin ou non
+
+ /**
+ * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
+ */
+ public $picto = 'generic';
+ public $tooltip = 'UseFormatFileEmailToTarget';
+
+
+ /**
+ * Constructor
+ *
+ * @param DoliDB $db Database handler
+ */
+ public function __construct($db)
+ {
+ $this->db = $db;
+ }
+
+
+ /**
* 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:
@@ -62,7 +62,7 @@
*
* @return array Array with SQL requests
*/
- public function getSqlArrayForStats()
+ public function getSqlArrayForStats()
{
global $langs;
$langs->load("users");
@@ -80,7 +80,7 @@
* @param string $sql Sql request to count
* @return string '' means NA
*/
- public function getNbOfRecipients($sql = '')
+ public function getNbOfRecipients($sql = '')
{
return '';
}
@@ -89,10 +89,10 @@
/**
* Renvoie url lien vers fiche de la source du destinataire du mailing
*
- * @param int $id ID
+ * @param int $id ID
* @return string Url lien
*/
- public function url($id)
+ public function url($id)
{
global $langs;
return $langs->trans('LineInFile', $id);
@@ -105,7 +105,7 @@
*
* @return string Retourne zone select
*/
- public function formFilter()
+ public function formFilter()
{
global $langs;
@@ -114,16 +114,16 @@
return $s;
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Ajoute destinataires dans table des cibles
*
* @param int $mailing_id Id of emailing
* @return int < 0 si erreur, nb ajout si ok
*/
- public function add_to_target($mailing_id)
- {
- // phpcs:enable
+ public function add_to_target($mailing_id)
+ {
+ // phpcs:enable
global $conf, $langs, $_FILES;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@@ -147,67 +147,76 @@
if ($handle)
{
$i = 0;
- $j = 0;
-
- $old = '';
+ $j = 0;
+
+ $old = '';
while (!feof($handle))
{
$cpt++;
- $buffer = trim(fgets($handle));
- $tab = explode(';', $buffer, 4);
- $email = $tab[0];
- $name = $tab[1];
- $firstname = $tab[2];
- $other = $tab[3];
- if (!empty($buffer))
- {
- //print 'xx'.dol_strlen($buffer).empty($buffer)."
\n";
- if (isValidEMail($email))
- {
+ $buffer = trim(fgets($handle));
+ $tab = explode(';', $buffer, 4);
+ $email = $tab[0];
+ $name = $tab[1];
+ $firstname = $tab[2];
+ $other = $tab[3];
+ if (!empty($buffer))
+ {
+ //print 'xx'.dol_strlen($buffer).empty($buffer)."
\n";
+ $id = $cpt;
+ if (isValidEMail($email))
+ {
if ($old <> $email)
{
$cibles[$j] = array(
- 'email' => $email,
- 'lastname' => $name,
- 'firstname' => $firstname,
+ 'email' => $email,
+ 'lastname' => $name,
+ 'firstname' => $firstname,
'other' => $other,
- 'source_url' => '',
- 'source_id' => '',
- 'source_type' => 'file'
+ 'source_url' => '',
+ 'source_id' => '',
+ 'source_type' => 'file'
);
$old = $email;
$j++;
}
- } else {
- $i++;
- $langs->load("errors");
- $msg = $langs->trans("ErrorFoundBadEmailInFile", $i, $cpt, $email);
- if (!empty($msg)) $this->error = $msg;
- else $this->error = 'ErrorFoundBadEmailInFile '.$i.' '.$cpt.' '.$email; // We experience case where $langs->trans return an empty string.
- }
- }
- }
- fclose($handle);
-
- if ($i > 0)
- {
- return -$i;
- }
- } else {
+ }
+ else
+ {
+ $i++;
+ $langs->load("errors");
+ $msg = $langs->trans("ErrorFoundBadEmailInFile", $i, $cpt, $email);
+ if (!empty($msg)) $this->error = $msg;
+ else $this->error = 'ErrorFoundBadEmailInFile '.$i.' '.$cpt.' '.$email; // We experience case where $langs->trans return an empty string.
+ }
+ }
+ }
+ fclose($handle);
+
+ if ($i > 0)
+ {
+ return -$i;
+ }
+ }
+ else
+ {
$this->error = $langs->trans("ErrorFaildToOpenFile");
return -1;
}
dol_syslog(get_class($this)."::add_to_target mailing ".$cpt." targets found");
- } else {
+ }
+ else
+ {
$langs->load("errors");
if ($resupload < 0) // Unknown error
{
$this->error = '