From f9c86256dcd52f0ba18cdf5e7d6b9b8126311b6f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 22 Oct 2019 15:21:41 +0200 Subject: [PATCH] FIX #12198 --- htdocs/contact/card.php | 49 ++++++++++++++++++- htdocs/contact/class/contact.class.php | 8 +-- .../public/emailing/mailing-unsubscribe.php | 2 +- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 123f9f91f5e..f0f18ffc672 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2004-2019 Laurent Destailleur * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005-2017 Regis Houssin * Copyright (C) 2007 Franky Van Liedekerke @@ -191,6 +191,7 @@ if (empty($reshook)) $object->facebook = GETPOST("facebook", 'alpha'); $object->linkedin = GETPOST("linkedin", 'alpha'); $object->email = GETPOST("email", 'alpha'); + $object->no_email = GETPOST("no_email", "int"); $object->phone_pro = GETPOST("phone_pro", 'alpha'); $object->phone_perso = GETPOST("phone_perso", 'alpha'); $object->phone_mobile = GETPOST("phone_mobile", 'alpha'); @@ -230,6 +231,22 @@ if (empty($reshook)) // Categories association $contcats = GETPOST('contcats', 'array'); $object->setCategories($contcats); + + // Add mass emailing flag into table mailing_unsubscribe + if (GETPOST('no_email', 'int') && $object->email) + { + $sql="SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing', 0).") AND email = '".$db->escape($object->email)."'"; + $resql=$db->query($sql); + if ($resql) + { + $obj=$db->fetch_object($resql); + if (empty($obj->nb)) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe(email, entity, date_creat) VALUES ('".$db->escape($object->email)."', ".$db->escape(getEntity('mailing', 0)).", '".$db->idate(dol_now())."')"; + $resql=$db->query($sql); + } + } + } } } @@ -360,6 +377,7 @@ if (empty($reshook)) $object->country_id = GETPOST("country_id", 'int'); $object->email = GETPOST("email", 'alpha'); + $object->no_email = GETPOST("no_email", "int"); $object->skype = GETPOST("skype", 'alpha'); $object->twitter = GETPOST("twitter", 'alpha'); $object->facebook = GETPOST("facebook", 'alpha'); @@ -387,6 +405,35 @@ if (empty($reshook)) $categories = GETPOST('contcats', 'array'); $object->setCategories($categories); + $no_email = GETPOST('no_email', 'int'); + + // Update mass emailing flag into table mailing_unsubscribe + if (GETPOSTISSET('no_email') && $object->email) + { + if ($no_email) + { + $sql="SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing', 0).") AND email = '".$db->escape($object->email)."'"; + $resql=$db->query($sql); + if ($resql) + { + $obj=$db->fetch_object($resql); + $noemail = $obj->nb; + if (empty($noemail)) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe(email, entity, date_creat) VALUES ('".$db->escape($object->email)."', ".$db->escape(getEntity('mailing', 0)).", '".$db->idate(dol_now())."')"; + $resql=$db->query($sql); + } + } + } + else + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = '".$db->escape($object->email)."' AND entity = ".$db->escape(getEntity('mailing', 0)); + $resql=$db->query($sql); + } + + $object->no_email = $no_email; + } + $object->old_lastname=''; $object->old_firstname=''; $action = 'view'; diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 3465b3478a0..77361c43263 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -80,7 +80,7 @@ class Contact extends CommonObject 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>1, 'position'=>1000), ); - public $civility_id; // In fact we store civility_code + public $civility_id; // In fact we store civility_code public $civility_code; public $civility; public $address; @@ -88,16 +88,17 @@ class Contact extends CommonObject public $town; public $state_id; // Id of department - public $state_code; // Code of department + public $state_code; // Code of department public $state; // Label of department public $poste; // Position public $socid; // fk_soc - public $statut; // 0=inactif, 1=actif + public $statut; // 0=inactif, 1=actif public $code; public $email; + public $no_email; // 1 = contact has globaly unsubscribe of all mass emailings public $skype; public $photo; public $jabberid; @@ -394,6 +395,7 @@ class Contact extends CommonObject if (! $error && $this->user_id > 0) { + // If contact is linked to a user $tmpobj = new User($this->db); $tmpobj->fetch($this->user_id); $usermustbemodified = 0; diff --git a/htdocs/public/emailing/mailing-unsubscribe.php b/htdocs/public/emailing/mailing-unsubscribe.php index adb6aa03c8d..48cdd1508e8 100644 --- a/htdocs/public/emailing/mailing-unsubscribe.php +++ b/htdocs/public/emailing/mailing-unsubscribe.php @@ -115,7 +115,7 @@ if (! empty($tag) && ($unsuscrib=='1')) */ // Update status communication of email (new usage) - $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe (date_creat, entity, email) VALUES ('".$db->idate(dol_now())."', ".$obj->entity.", '".$obj->email."')"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe (date_creat, entity, email) VALUES ('".$db->idate(dol_now())."', ".$db->escape($obj->entity).", '".$db->escape($obj->email)."')"; $resql=$db->query($sql); //if (! $resql) dol_print_error($db); No test on errors, may fail if already unsubscribed