--- /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 .= ''; + $s .= ''; + if ($resql) + { @@ -144,12 +150,8 @@ - if ($num > 0) { - while ($i < $num) { - $obj = $this->db->fetch_object($resql); - $s .= ''; - $i++; - } - } else { - $s .= ''; - } - } else { - dol_print_error($this->db); - } + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + $s .= ''; + $i++; + } + } + else dol_print_error($this->db); @@ -157 +159 @@ - $s .= ajax_combobox("filter_jobposition_contact"); + @@ -160,0 +163 @@ + $s .= $langs->trans("ContactCategoriesShort").': '; @@ -166,3 +169,4 @@ - $sql .= " WHERE sp.entity IN (".getEntity('contact').")"; - $sql .= " AND sp.email <> ''"; // Note that null != '' is false - $sql .= " AND sp.statut = 1"; + $sql .= " WHERE sp.statut = 1"; // Note that null != '' is false + //$sql.= " AND sp.no_email = 0"; + //$sql.= " AND sp.email != ''"; + //$sql.= " AND sp.entity IN (".getEntity('socpeople').")"; @@ -175,5 +179,7 @@ - $s .= ''; + $s .= ''; + if ($resql) + { + $num = $this->db->num_rows($resql); + if ($num) + { @@ -181 +187,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -186 +193,3 @@ - } else { + } + else + { @@ -189,3 +198,2 @@ - } else { - dol_print_error($this->db); - } + } + else dol_print_error($this->db); @@ -193 +201 @@ - $s .= ajax_combobox("filter_category_contact"); + @@ -197 +205,2 @@ - $s .= ''; @@ -203,7 +212,5 @@ - if ($resql) { - $num = $this->db->num_rows($resql); - if ($num) { - $s .= ''; - } else { - $s .= ''; - } + if ($resql) + { + $num = $this->db->num_rows($resql); + if ($num) $s .= ''; + else $s .= ''; @@ -213 +220,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -216,5 +224,2 @@ - if ($level == $obj->code) { - $level = $langs->trans($obj->label); - } - $labeltoshow = $langs->trans("ThirdPartyProspects").' ('.$langs->trans("ProspectLevelShort").'='.$level.')'; - $s .= ''; + if ($level == $obj->code) $level = $langs->trans($obj->label); + $s .= ''; @@ -223,3 +228,2 @@ - } else { - dol_print_error($this->db); - } + } + else dol_print_error($this->db); @@ -230 +233,0 @@ - $s .= ajax_combobox("filter_contact"); @@ -234,0 +238 @@ + $s .= $langs->trans("CustomersProspectsCategoriesShort").': '; @@ -240,3 +244,4 @@ - $sql .= " WHERE sp.entity IN (".getEntity('contact').")"; - $sql .= " AND sp.email <> ''"; // Note that null != '' is false - $sql .= " AND sp.statut = 1"; + $sql .= " WHERE sp.statut = 1"; // Note that null != '' is false + //$sql.= " AND sp.no_email = 0"; + //$sql.= " AND sp.email != ''"; + //$sql.= " AND sp.entity IN (".getEntity('socpeople').")"; @@ -249,5 +254,7 @@ - $s .= ''; + $s .= ''; + if ($resql) + { + $num = $this->db->num_rows($resql); + if ($num) + { @@ -255 +262,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -260 +268,3 @@ - } else { + } + else + { @@ -263,3 +273,2 @@ - } else { - dol_print_error($this->db); - } + } + else dol_print_error($this->db); @@ -267 +275,0 @@ - $s .= ajax_combobox("filter_category_customer_contact"); @@ -271,0 +280 @@ + $s .= $langs->trans("SuppliersCategoriesShort").': '; @@ -277,3 +286,4 @@ - $sql .= " WHERE sp.entity IN (".getEntity('contact').")"; - $sql .= " AND sp.email <> ''"; // Note that null != '' is false - $sql .= " AND sp.statut = 1"; + $sql .= " WHERE sp.statut = 1"; // Note that null != '' is false + //$sql.= " AND sp.no_email = 0"; + //$sql.= " AND sp.email != ''"; + //$sql.= " AND sp.entity IN (".getEntity('socpeople').")"; @@ -286,5 +296,7 @@ - $s .= ''; + $s .= ''; + if ($resql) + { + $num = $this->db->num_rows($resql); + if ($num) + { @@ -292 +304,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -297 +310,3 @@ - } else { + } + else + { @@ -300,3 +315,2 @@ - } else { - dol_print_error($this->db); - } + } + else dol_print_error($this->db); @@ -305,10 +318,0 @@ - $s .= ajax_combobox("filter_category_supplier_contact"); - - // Choose language - if (getDolGlobalInt('MAIN_MULTILANGS')) { - require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; - $formadmin = new FormAdmin($this->db); - $s .= img_picto($langs->trans("DefaultLang"), 'language', 'class="pictofixedwidth"'); - $s .= $formadmin->select_language(GETPOST('filter_lang', 'aZ09'), 'filter_lang', 0, null, $langs->trans("DefaultLang"), 0, 0, '', 0, 0, 0, null, 1); - } - @@ -316 +320 @@ - } + } @@ -322 +326 @@ - * @param int $id ID + * @param int $id ID @@ -325,9 +329,9 @@ - public function url($id) - { - return ''.img_object('', "contact").''; - } - - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Add some recipients into target table + public function url($id) + { + return ''.img_object('', "contact").''; + } + + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Ajoute destinataires dans table des cibles @@ -336,5 +340,5 @@ - * @return int Return integer <0 si erreur, nb ajout si ok - */ - public function add_to_target($mailing_id) - { - // phpcs:enable + * @return int <0 si erreur, nb ajout si ok + */ + public function add_to_target($mailing_id) + { + // phpcs:enable @@ -348 +351,0 @@ - $filter_lang = GETPOST('filter_lang', 'alpha'); @@ -359 +362,2 @@ - if ($resql) { + if ($resql) + { @@ -362 +366,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -367,3 +372,2 @@ - } else { - dol_print_error($this->db); - } + } + else dol_print_error($this->db); @@ -375,14 +379,8 @@ - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = sp.fk_soc"; - if ($filter_category != 'all' && $filter_category != '-1') { - $sql .= ", ".MAIN_DB_PREFIX."categorie as c"; - $sql .= ", ".MAIN_DB_PREFIX."categorie_contact as cs"; - } - if ($filter_category_customer != 'all' && $filter_category_customer != '-1') { - $sql .= ", ".MAIN_DB_PREFIX."categorie as c2"; - $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c2s"; - } - if ($filter_category_supplier != 'all' && $filter_category_supplier != '-1') { - $sql .= ", ".MAIN_DB_PREFIX."categorie as c3"; - $sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as c3s"; - } - $sql .= " WHERE sp.entity IN (".getEntity('contact').")"; + $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').")"; @@ -390,4 +388,2 @@ - - if (empty($this->evenunsubscribe)) { - $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = sp.email and mu.entity = ".((int) $conf->entity).")"; - } + $sql .= " AND sp.no_email = 0"; + $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = sp.email) = 0"; @@ -396,2 +392 @@ - $sql .= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")"; - + $sql .= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; @@ -399,19 +394,7 @@ - if ($filter_category != 'all' && $filter_category != '-1') { - $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid"; - $sql .= " AND c.label = '".$this->db->escape($filter_category)."'"; - } - if ($filter_category_customer != 'all' && $filter_category_customer != '-1') { - $sql .= " AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc"; - $sql .= " AND c2.label = '".$this->db->escape($filter_category_customer)."'"; - } - if ($filter_category_supplier != 'all' && $filter_category_supplier != '-1') { - $sql .= " AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc"; - $sql .= " AND c3.label = '".$this->db->escape($filter_category_supplier)."'"; - } - - // Filter on language - if (!empty($filter_lang) && $filter_lang != '-1') { - $sql .= " AND sp.default_lang LIKE '".$this->db->escape($filter_lang)."%'"; - } - - // Filter on nature + if ($filter_category <> 'all') $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid"; + if ($filter_category <> 'all') $sql .= " AND c.label = '".$this->db->escape($filter_category)."'"; + if ($filter_category_customer <> 'all') $sql .= " AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc"; + if ($filter_category_customer <> 'all') $sql .= " AND c2.label = '".$this->db->escape($filter_category_customer)."'"; + if ($filter_category_supplier <> 'all') $sql .= " AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc"; + if ($filter_category_supplier <> 'all') $sql .= " AND c3.label = '".$this->db->escape($filter_category_supplier)."'"; + // Filter on nature @@ -419,17 +402,7 @@ - - //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)."'"; - } - } - if ($key == 'customers') { - $sql .= " AND s.client = 1"; - } - if ($key == 'suppliers') { - $sql .= " AND s.fournisseur = 1"; - } - + { + //print "xx".$key; + if ($key == 'prospects') $sql .= " AND s.client=2"; + foreach ($prospectlevel as $codelevel=>$valuelevel) if ($key == 'prospectslevel'.$codelevel) $sql .= " AND s.fk_prospectlevel='".$codelevel."'"; + if ($key == 'customers') $sql .= " AND s.client=1"; + if ($key == 'suppliers') $sql .= " AND s.fournisseur=1"; + } @@ -438,4 +411 @@ - if (!empty($key) && $key != 'all' && $key != '-1') { - $sql .= " AND sp.poste = '".$this->db->escape($key)."'"; - } - + if (!empty($key) && $key != 'all') $sql .= " AND sp.poste ='".$this->db->escape($key)."'"; @@ -445 +415 @@ - // Store recipients in target tables + // Stocke destinataires dans cibles @@ -447 +417,2 @@ - if ($result) { + if ($result) + { @@ -455 +426,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -457 +429,2 @@ - if ($old != $obj->email) { + if ($old <> $obj->email) + { @@ -459,11 +432,11 @@ - '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("PostOrFunction").'='.$obj->jobposition), - 'source_url' => $this->url($obj->id), - 'source_id' => $obj->id, - 'source_type' => 'contact' + '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' @@ -477 +450,3 @@ - } else { + } + else + { @@ -484 +459 @@ - } + } --- /tmp/dsg/dolibarr/htdocs/core/modules/mailings/github_19.0.3_example.modules.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_example.modules.php @@ -0,0 +1,154 @@ + + * + * This file is an example to follow to add your own email selector inside + * the Dolibarr email tool. + * Follow instructions given in README file to know what to change to build + * your own emailing list selector. + * Code that need to be changed in this file are marked by "CHANGE THIS" tag. + */ + +/** + * \file htdocs/core/modules/mailings/example.modules.php + * \ingroup mailing + * \brief Example file to provide a list of recipients for mailing module + */ + +include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php'; + + +// CHANGE THIS: Class name must be called mailing_xxx with xxx=name of your selector + +/** + \class mailing_example + \brief Class to manage a list of personalised recipients for mailing feature +*/ +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'; + + 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 DoliDB Database handler. + */ + public $db; + + + // 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; + } + + + // 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 ----- + + // 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'); + + // 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); + } + + + /** + * 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() + { + // CHANGE THIS: Optionnal + + //var $statssql=array(); + //$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL"; + return array(); + } + + + /** + * Return here number of distinct emails returned by your selector. + * For example if this selector is used to extract 500 different + * emails from a text file, this function must return 500. + * + * @param string $sql Requete sql de comptage + * @return int|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 '?'; + } + + /** + * 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; + } + + + /** + * 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 ''; + } +} --- /tmp/dsg/dolibarr/htdocs/core/modules/mailings/github_19.0.3_fraise.modules.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_fraise.modules.php @@ -4 +4 @@ - * Copyright (C) 2018-2023 Frédéric France + * Copyright (C) 2018 Frédéric France @@ -36 +36 @@ - public $name = 'FundationMembers'; // Identifiant du module mailing + public $name = 'FundationMembers'; // Identifiant du module mailing @@ -38,291 +38,288 @@ - 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'); - - public $enabled = 'isModEnabled("adherent")'; - - /** - * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png - */ - public $picto = 'user'; - - - /** - * 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|string Nb of recipient, or <0 if error, or '' if NA - */ - public function getNbOfRecipients($sql = '') - { - global $conf; - $sql = "SELECT count(distinct(a.email)) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a"; - $sql .= " WHERE (a.email IS NOT NULL AND a.email != '') AND a.entity IN (".getEntity('member').")"; - if (empty($this->evenunsubscribe)) { - $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = a.email and mu.entity = ".((int) $conf->entity).")"; - } - - // 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 .= ' '; - $s .= ajax_combobox("filter_fraise"); - - $s .= ''; - $s .= ajax_combobox("filter_type_fraise"); - - $s .= ' '; - - $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 Return integer < 0 si erreur, nb ajout si ok - */ - public function add_to_target($mailing_id) - { - // phpcs:enable - global $conf, $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', 'int') > 0) { - $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=".((int) $mailing_id).")"; - // Filter on status - if (GETPOST("filter", 'aZ09') == 'draft') { - $sql .= " AND a.statut = -1"; - } elseif (GETPOST("filter", 'aZ09') == '1a') { - $sql .= " AND a.statut=1 AND (a.datefin >= '".$this->db->idate($now)."' OR ta.subscription = 0)"; - } elseif (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)"; - } elseif (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 = ".((int) GETPOST('filter_type', 'int')); - } - if (empty($this->evenunsubscribe)) { - $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = a.email and mu.entity = ".((int) $conf->entity).")"; - } - $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_19.0.3_modules_mailings.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_modules_mailings.php @@ -34,6 +34,6 @@ - /** - * @var DoliDb Database handler (result of a new DoliDB) - */ - public $db; - - /** + /** + * @var DoliDB Database handler. + */ + public $db; + + /** @@ -44,35 +44,4 @@ - /** - * @var array of errors - */ - public $errors; - - /** - * @var string Condition to be enabled - */ - public $enabled; - - /** - * @var string Name of the module - */ - public $name; - - /** - * @var string Description of the module - */ - public $desc; - - /** - * @var string Tooltip to show after description of the module - */ - public $tooltip = ''; - - /** - * @var string To store the SQL string used to find the recipients - */ - public $sql; - - - public $evenunsubscribe = 0; // Set this to 1 if you want to flag you also want to include email in target that has opt-out. - - - /** + public $tooltip = ''; + + + /** @@ -83 +52 @@ - public function __construct($db) + public function __construct($db) @@ -85 +54 @@ - $this->db = $db; + $this->db = $db; @@ -88,28 +57,22 @@ - /** - * 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; + } + + /** @@ -117,139 +80,148 @@ - * - * @return integer Example - */ - public function getNbOfRecords() - { - return 0; - } - - /** - * Retourne nombre de destinataires - * - * @param string $sql Sql request to count - * @return int|string Nb of recipient, or <0 if error, or '' if NA - */ - public function getNbOfRecipients($sql) - { - $result = $this->db->query($sql); - if ($result) { - $total = 0; - while ($obj = $this->db->fetch_object($result)) { - $total += $obj->nb; - } - return $total; - } 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 Return integer < 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 = ".((int) $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 = ".((int) $nb)." WHERE rowid = ".((int) $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 into the database - * - * @param int $mailing_id Id of emailing - * @param array $cibles Array with targets - * @return int Return integer < 0 if error, nb added if 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 (".((int) $mailing_id).","; - $sql .= (empty($targetarray['fk_contact']) ? '0' : (int) $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($conf->file->instance_unique_id.";".$targetarray['email'].";".$targetarray['lastname'].";".((int) $mailing_id).";".getDolGlobalString('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"); - - /* - //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"; - $sql .= " WHERE fk_mailing = ".((int) $mailing_id)." AND email in (SELECT email FROM ".MAIN_DB_PREFIX."societe where fk_stcomm=-1)"; - $sql .= " AND source_type='thirdparty'"; - dol_syslog(__METHOD__.": mailing update status to display thirdparty mail that do not want to be contacted"); - $result=$this->db->query($sql); - - //Update the status to show contact mail that don't want to be contacted anymore' - $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles"; - $sql .= " SET statut=3"; - $sql .= " WHERE fk_mailing = ".((int) $mailing_id)." AND source_type='contact' AND (email in (SELECT sc.email FROM ".MAIN_DB_PREFIX."socpeople AS sc "; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe s ON s.rowid=sc.fk_soc WHERE s.fk_stcomm=-1 OR no_email=1))"; - dol_syslog(__METHOD__.": mailing update status to display contact mail that do not want to be contacted",LOG_DEBUG); - $result=$this->db->query($sql); + * + * @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"; + $sql .= " WHERE fk_mailing=".$mailing_id." AND email in (SELECT email FROM ".MAIN_DB_PREFIX."societe where fk_stcomm=-1)"; + $sql .= " AND source_type='thirdparty'"; + dol_syslog(__METHOD__.": mailing update status to display thirdparty mail that do not want to be contacted"); + $result=$this->db->query($sql); + + //Update the status to show contact mail that don't want to be contacted anymore' + $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles"; + $sql .= " SET statut=3"; + $sql .= " WHERE fk_mailing=".$mailing_id." AND source_type='contact' AND (email in (SELECT sc.email FROM ".MAIN_DB_PREFIX."socpeople AS sc "; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe s ON s.rowid=sc.fk_soc WHERE s.fk_stcomm=-1 OR no_email=1))"; + dol_syslog(__METHOD__.": mailing update status to display contact mail that do not want to be contacted",LOG_DEBUG); + $result=$this->db->query($sql); @@ -258,40 +230,38 @@ - if (empty($this->evenunsubscribe)) { - $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles as mc"; - $sql .= " SET mc.statut = 3"; - $sql .= " WHERE mc.fk_mailing = ".((int) $mailing_id); - $sql .= " AND EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = mc.email and mu.entity = ".((int) $conf->entity).")"; - - 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); - } - } - - // Update nb of recipient into emailing record - $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 = ".((int) $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_19.0.3_pomme.modules.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_pomme.modules.php @@ -23 +23 @@ - * \brief File of class to offer a selector of emailing targets of users. + * \brief File of class to offer a selector of emailing targets with Rule 'Pomme'. @@ -29 +29 @@ - * Class to offer a selector of emailing targets with Rule 'Pomme'. + * Class to offer a selector of emailing targets with Rule 'Peche'. @@ -43,0 +44,5 @@ + /** + * @var DoliDB Database handler. + */ + public $db; + @@ -50 +55 @@ - public function __construct($db) + public function __construct($db) @@ -56 +61 @@ - /** + /** @@ -64 +69 @@ - public function getSqlArrayForStats() + public function getSqlArrayForStats() @@ -71 +76 @@ - $sql = "SELECT '".$this->db->escape($langs->trans("DolibarrUsers"))."' as label,"; + $sql = "SELECT '".$langs->trans("DolibarrUsers")."' as label,"; @@ -76 +80,0 @@ - @@ -83,9 +87,9 @@ - /** - * 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|string Nb of recipient, or <0 if error, or '' if NA - */ - 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 = '') @@ -99,5 +103,3 @@ - if (empty($this->evenunsubscribe)) { - $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = u.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 @@ -113 +115 @@ - public function formFilter() + public function formFilter() @@ -120,2 +122,3 @@ - $s .= ''; + $s .= ''; @@ -125 +127,0 @@ - $s .= ajax_combobox("filter_pomme"); @@ -128,2 +130,3 @@ - $s .= ''; + $s .= ''; @@ -133 +135,0 @@ - $s .= ajax_combobox("filteremployee_pomme"); @@ -142 +144 @@ - * @param int $id ID + * @param int $id ID @@ -145 +147 @@ - public function url($id) + public function url($id) @@ -151 +153 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -156,6 +158,6 @@ - * @return int Return integer < 0 si erreur, nb ajout si ok - */ - public function add_to_target($mailing_id) - { - // phpcs:enable - global $conf, $langs; + * @return int < 0 si erreur, nb ajout si ok + */ + public function add_to_target($mailing_id) + { + // phpcs:enable + global $conf, $langs; @@ -172,16 +174,5 @@ - $sql .= " AND u.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $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 (empty($this->evenunsubscribe)) { - $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = u.email and mu.entity = ".((int) $conf->entity).")"; - } + $sql .= " AND u.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; + 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"; @@ -192 +183,2 @@ - if ($result) { + if ($result) + { @@ -200 +192,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -202 +195,2 @@ - if ($old != $obj->email) { + if ($old <> $obj->email) + { @@ -204,11 +198,11 @@ - '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' @@ -222 +216,3 @@ - } else { + } + else + { @@ -229 +225 @@ - } + } --- /tmp/dsg/dolibarr/htdocs/core/modules/mailings/github_19.0.3_thirdparties.modules.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/mailings/client_thirdparties.modules.php @@ -34,2 +33,0 @@ - public $enabled = 'isModEnabled("societe")'; - @@ -40,0 +39,5 @@ + /** + * @var DoliDB Database handler. + */ + public $db; + @@ -47 +50 @@ - public function __construct($db) + public function __construct($db) @@ -50 +53 @@ - $langs->load("companies"); + $langs->load("companies"); @@ -56 +59 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -61,5 +64,5 @@ - * @return int Return integer <0 if error, number of emails added if ok - */ - public function add_to_target($mailing_id) - { - // phpcs:enable + * @return int <0 if error, number of emails added if ok + */ + public function add_to_target($mailing_id) + { + // phpcs:enable @@ -70,63 +73 @@ - $addDescription = ""; - $addFilter = ""; - if (GETPOSTISSET("filter_client_thirdparties") && GETPOST("filter_client_thirdparties") != '-1') { - $addFilter .= " AND s.client=".((int) GETPOST("filter_client_thirdparties", 'int')); - $addDescription = $langs->trans('ProspectCustomer')."="; - if (GETPOST("filter_client_thirdparties") == 0) { - $addDescription .= $langs->trans('NorProspectNorCustomer'); - } elseif (GETPOST("filter_client_thirdparties") == 1) { - $addDescription .= $langs->trans('Customer'); - } elseif (GETPOST("filter_client_thirdparties") == 2) { - $addDescription .= $langs->trans('Prospect'); - } elseif (GETPOST("filter_client_thirdparties") == 3) { - $addDescription .= $langs->trans('ProspectCustomer'); - } else { - $addDescription .= "Unknown status ".GETPOST("filter_client_thirdparties"); - } - } - if (GETPOSTISSET("filter_supplier_thirdparties") && GETPOST("filter_supplier_thirdparties") != '-1') { - $addFilter .= " AND s.fournisseur = ".((int) GETPOST("filter_supplier_thirdparties", 'int')); - $addDescription = $langs->trans('Supplier')."="; - if (GETPOST("filter_supplier_thirdparties") == 0) { - $addDescription .= $langs->trans('No'); - } elseif (GETPOST("filter_supplier_thirdparties") == 1) { - $addDescription .= $langs->trans('Yes'); - } else { - $addDescription .= "Unknown status ".GETPOST("filter_supplier_thirdparties"); - } - } - 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"); - } elseif (GETPOST("filter_status") == '0') { - $addFilter .= " AND s.status=0"; - $addDescription .= $langs->trans("Disabled"); - } - } - 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"); - } elseif (GETPOST("filter_status") == '0') { - $addFilter .= " AND s.status=0"; - $addDescription .= $langs->trans("Disabled"); - } - } - if (GETPOST('default_lang', 'alpha') && GETPOST('default_lang', 'alpha') != '-1') { - $addFilter .= " AND s.default_lang LIKE '".$this->db->escape(GETPOST('default_lang', 'alpha'))."%'"; - $addDescription = $langs->trans('DefaultLang')."="; - } - if (GETPOST('filter_lang_thirdparties', 'alpha') && GETPOST('filter_lang_thirdparties', 'alpha') != '-1') { - $addFilter .= " AND s.default_lang LIKE '".$this->db->escape(GETPOST('filter_lang_thirdparties', 'alpha'))."%'"; - $addDescription = $langs->trans('DefaultLang')."="; - } - + $addDescription = ""; @@ -134,46 +75,77 @@ - if (!GETPOST('filter_thirdparties') || GETPOST('filter_thirdparties') == '-1') { - $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=".((int) $mailing_id).")"; - if (empty($this->evenunsubscribe)) { - $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = s.email) = 0"; - } - $sql .= $addFilter; - } else { - $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=".((int) $mailing_id).")"; - $sql .= " AND cs.fk_soc = s.rowid"; - $sql .= " AND c.rowid = cs.fk_categorie"; - if (GETPOST('filter_thirdparties', 'int') > 0) { - $sql .= " AND c.rowid=".((int) GETPOST('filter_thirdparties', 'int')); - } - if (empty($this->evenunsubscribe)) { - $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = s.email) = 0"; - } - $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=".((int) $mailing_id).")"; - $sql .= " AND cs.fk_soc = s.rowid"; - $sql .= " AND c.rowid = cs.fk_categorie"; - if (GETPOST('filter_thirdparties', 'int') > 0) { - $sql .= " AND c.rowid=".((int) GETPOST('filter_thirdparties', 'int')); - } - if (empty($this->evenunsubscribe)) { - $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = s.email) = 0"; - } - $sql .= $addFilter; - } - $sql .= " ORDER BY email"; - - //print $sql;exit; - - // Stock recipients emails into targets table + 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 (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 @@ -181 +153,2 @@ - if ($result) { + if ($result) + { @@ -189 +162,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -191 +165,2 @@ - if ($old != $obj->email) { + if ($old <> $obj->email) + { @@ -193 +168,2 @@ - if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) { + if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) + { @@ -198,8 +174,8 @@ - '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' @@ -213 +189,3 @@ - } else { + } + else + { @@ -223 +201 @@ - /** + /** @@ -231 +209 @@ - public function getSqlArrayForStats() + public function getSqlArrayForStats() @@ -246,4 +224,4 @@ - * @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 Nb of recipients + */ + public function getNbOfRecipients($sql = '') @@ -255 +233 @@ - $sql .= " WHERE s.email <> ''"; + $sql .= " WHERE s.email != ''"; @@ -257,5 +235,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 @@ -271 +247 @@ - public function formFilter() + public function formFilter() @@ -277,2 +253,2 @@ - // filter - $s = ''; @@ -290 +266,2 @@ - if ($resql) { + if ($resql) + { @@ -293,9 +270,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 .= ''; @@ -304 +276,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -308,12 +281,4 @@ - if ($obj->type == 1) { - $type = $langs->trans("Supplier"); - } - if ($obj->type == 2) { - $type = $langs->trans("Customer"); - } - $labeltoshow = $obj->label; - if ($type) { - $labeltoshow .= ' ('.$type.')'; - } - $s .= '