--- /tmp/dsg/dolibarr/htdocs/core/modules/mailings/github_19.0.3_advthirdparties.modules.php
+++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_advthirdparties.modules.php
@@ -28 +28 @@
- public $name = 'ThirdPartyAdvancedTargeting';
+ public $name = 'ThirdPartyAdvancedTargeting';
@@ -30,11 +30,14 @@
- 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';
-
- public $enabled = 'isModEnabled("societe")';
+ 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 +57 @@
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@@ -62 +65 @@
- * @return int Return integer <0 if error, number of emails added if ok
+ * @return int <0 if error, number of emails added if ok
@@ -66 +69 @@
- // phpcs:enable
+ // phpcs:enable
@@ -75 +78,2 @@
- if (count($socid) > 0) {
+ if (count($socid) > 0)
+ {
@@ -79,3 +83,55 @@
- $sql .= " AND s.rowid IN (".$this->db->sanitize(implode(',', $socid)).")";
- if (empty($this->evenunsubscribe)) {
- $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).")";
+ $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;
+ }
+ }
+ }
+
+ if (($type_of_target == 1) || ($type_of_target == 2) || ($type_of_target == 4)) {
+ // Select the third parties from category
+ if (count($socid) > 0 || count($contactid) > 0)
+ {
+ $sql = "SELECT socp.rowid as id, socp.email as email, socp.lastname as lastname, socp.firstname as firstname";
+ $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as socp";
+ $sql .= " WHERE socp.entity IN (".getEntity('socpeople').")";
+ if (count($contactid) > 0) {
+ $sql .= " AND socp.rowid IN (".implode(',', $contactid).")";
+ }
+ if (count($socid) > 0) {
+ $sql .= " AND socp.fk_soc IN (".implode(',', $socid).")";
@@ -85,86 +141,37 @@
- // 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;
- }
- }
- }
-
- if (($type_of_target == 1) || ($type_of_target == 2) || ($type_of_target == 4)) {
- // Select the third parties from category
- if (count($socid) > 0 || count($contactid) > 0) {
- $sql = "SELECT socp.rowid as id, socp.email as email, socp.lastname as lastname, socp.firstname as firstname";
- $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as socp";
- $sql .= " WHERE socp.entity IN (".getEntity('contact').")";
- if (count($contactid) > 0) {
- $sql .= " AND socp.rowid IN (".$this->db->sanitize(implode(',', $contactid)).")";
- }
- if (count($socid) > 0) {
- $sql .= " AND socp.fk_soc IN (".$this->db->sanitize(implode(',', $socid)).")";
- }
- if (empty($this->evenunsubscribe)) {
- $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = socp.email and mu.entity = ".((int) $conf->entity).")";
- }
- $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;
+ }
@@ -204,2 +211,2 @@
- * @param string $sql Not use here
- * @return int|string Nb of recipient, or <0 if error, or '' if NA
+ * @param string $sql Not use here
+ * @return int Nb of recipients
@@ -215,5 +222,3 @@
- if (empty($this->evenunsubscribe)) {
- $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).")";
- }
-
- // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
+
+ // La requete doit retourner un champ "nb" pour etre comprise
+ // par parent::getNbOfRecipients
@@ -248 +253,2 @@
- if ($resql) {
+ if ($resql)
+ {
@@ -251,9 +257,4 @@
- if (!isModEnabled("categorie")) {
- $num = 0; // Force empty list if category module is not enabled
- }
-
- if ($num) {
- $s .= '';
- } else {
- $s .= '';
- }
+ if (empty($conf->categorie->enabled)) $num = 0; // Force empty list if category module is not enabled
+
+ if ($num) $s .= '';
+ else $s .= '';
@@ -262 +263,2 @@
- while ($i < $num) {
+ while ($i < $num)
+ {
@@ -266,6 +268,2 @@
- if ($obj->type == 1) {
- $type = $langs->trans("Supplier");
- }
- if ($obj->type == 2) {
- $type = $langs->trans("Customer");
- }
+ if ($obj->type == 1) $type = $langs->trans("Supplier");
+ if ($obj->type == 2) $type = $langs->trans("Customer");
@@ -273,3 +271 @@
- if ($type) {
- $s .= ' ('.$type.')';
- }
+ if ($type) $s .= ' ('.$type.')';
@@ -279 +275,3 @@
- } else {
+ }
+ else
+ {
@@ -306 +303,0 @@
- return "";
--- /tmp/dsg/dolibarr/htdocs/core/modules/mailings/github_19.0.3_contacts1.modules.php
+++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_contacts1.modules.php
@@ -41,2 +40,0 @@
- public $enabled = 'isModEnabled("societe")';
-
@@ -48,13 +46,18 @@
-
- /**
- * 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;
+ }
+
+
+ /**
@@ -68,2 +71,2 @@
- public function getSqlArrayForStats()
- {
+ public function getSqlArrayForStats()
+ {
@@ -75 +78 @@
- $statssql[0] = "SELECT '".$this->db->escape($langs->trans("NbOfCompaniesContacts"))."' as label,";
+ $statssql[0] = "SELECT '".$langs->trans("NbOfCompaniesContacts")."' as label,";
@@ -78,2 +81,3 @@
- $statssql[0] .= " WHERE c.entity IN (".getEntity('contact').")";
- $statssql[0] .= " AND c.email <> ''"; // Note that null != '' is false
+ $statssql[0] .= " WHERE c.entity IN (".getEntity('socpeople').")";
+ $statssql[0] .= " AND c.email != ''"; // Note that null != '' is false
+ $statssql[0] .= " AND c.no_email = 0";
@@ -83 +87 @@
- }
+ }
@@ -91,5 +95,5 @@
- * @param string $sql Requete sql de comptage
- * @return int|string Nb of recipient, or <0 if error, or '' if NA
- */
- public function getNbOfRecipients($sql = '')
- {
+ * @param string $sql Requete sql de comptage
+ * @return int
+ */
+ public function getNbOfRecipients($sql = '')
+ {
@@ -100,6 +104,5 @@
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = c.fk_soc";
- $sql .= " WHERE c.entity IN (".getEntity('contact').")";
- $sql .= " AND c.email <> ''"; // Note that null != '' is false
- if (empty($this->evenunsubscribe)) {
- $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = c.email and mu.entity = ".((int) $conf->entity).")";
- }
+ $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";
+ $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = c.email) = 0";
@@ -111 +114 @@
- }
+ }
@@ -119,3 +122,3 @@
- public function formFilter()
- {
- global $conf,$langs;
+ public function formFilter()
+ {
+ global $langs;
@@ -124 +127 @@
- $langs->loadLangs(array("commercial", "companies", "suppliers", "categories"));
+ $langs->loadLangs(array("commercial", "companies", "suppliers", "categories"));
@@ -131,4 +134,5 @@
- $sql .= " WHERE sp.entity IN (".getEntity('contact').")";
- $sql .= " AND sp.email <> ''"; // Note that null != '' is false
- $sql .= " AND sp.statut = 1";
- $sql .= " AND (sp.poste IS NOT NULL AND sp.poste <> '')";
+ $sql .= " WHERE sp.entity IN (".getEntity('socpeople').")";
+ /*$sql.= " AND sp.email != ''"; // Note that null != '' is false
+ $sql.= " AND sp.no_email = 0";
+ $sql.= " AND sp.statut = 1";*/
+ $sql .= " AND (sp.poste IS NOT NULL AND sp.poste != '')";
@@ -139,3 +143,5 @@
- $s .= '