A better way to manage unsubscribed emails
This commit is contained in:
parent
ead8b91626
commit
b27ec54379
@ -36,3 +36,17 @@
|
||||
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TICKET_CREATE','Ticket created','Executed when a ticket is created','ticket',161);
|
||||
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TICKET_MODIFY','Ticket modified','Executed when a ticket is modified','ticket',163);
|
||||
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TICKET_DELETE','Ticket deleted','Executed when a ticket is deleted','ticket',164);
|
||||
|
||||
create table llx_mailing_unsubscribe
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
entity integer DEFAULT 1 NOT NULL, -- multi company id
|
||||
email varchar(255),
|
||||
unsubscribegroup varchar(128) DEFAULT '',
|
||||
ip varchar(128),
|
||||
date_creat datetime, -- creation date
|
||||
tms timestamp
|
||||
)ENGINE=innodb;
|
||||
|
||||
ALTER TABLE llx_mailing_unsubscribe ADD UNIQUE uk_mailing_unsubscribe(email, entity, unsubscribegroup);
|
||||
|
||||
|
||||
20
htdocs/install/mysql/tables/llx_mailing_unsubscribe.key.sql
Normal file
20
htdocs/install/mysql/tables/llx_mailing_unsubscribe.key.sql
Normal file
@ -0,0 +1,20 @@
|
||||
-- ===================================================================
|
||||
-- Copyright (C) 2018 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--
|
||||
-- ===================================================================
|
||||
|
||||
|
||||
ALTER TABLE llx_mailing_unsubscribe ADD UNIQUE uk_mailing_unsubscribe(email, entity, unsubscribegroup);
|
||||
30
htdocs/install/mysql/tables/llx_mailing_unsubscribe.sql
Normal file
30
htdocs/install/mysql/tables/llx_mailing_unsubscribe.sql
Normal file
@ -0,0 +1,30 @@
|
||||
-- ========================================================================
|
||||
-- Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
-- Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--
|
||||
-- ========================================================================
|
||||
|
||||
|
||||
create table llx_mailing_unsubscribe
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
entity integer DEFAULT 1 NOT NULL, -- multi company id
|
||||
email varchar(255),
|
||||
unsubscribegroup varchar(128) DEFAULT '',
|
||||
ip varchar(128),
|
||||
date_creat datetime, -- creation date
|
||||
tms timestamp
|
||||
)ENGINE=innodb;
|
||||
@ -23,7 +23,8 @@
|
||||
/**
|
||||
* \file public/emailing/mailing-unsubscribe.php
|
||||
* \ingroup mailing
|
||||
* \brief Script use to update unsubcribe contact to prospect mailing list
|
||||
* \brief Script use to update unsubcribe status of an email
|
||||
* https://myserver/public/emailing/mailing-unsubscribe.php?unsuscrib=1&securitykey=securitykey&tag=abcdefghijklmn
|
||||
*/
|
||||
|
||||
if (! defined('NOLOGIN')) define("NOLOGIN",1); // This means this output page does not require to be logged.
|
||||
@ -75,38 +76,49 @@ if ($securitykey != $conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY)
|
||||
|
||||
if (! empty($tag) && ($unsuscrib=='1'))
|
||||
{
|
||||
// Update status of mail in recipient mailing list table
|
||||
$statut='3';
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=".$statut." WHERE tag='".$db->escape($tag)."'";
|
||||
dol_syslog("public/emailing/mailing-unsubscribe.php : Mail unsubcribe : ".$sql, LOG_DEBUG);
|
||||
dol_syslog("public/emailing/mailing-unsubscribe.php : Launch unsubscribe requests", LOG_DEBUG);
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if (! $resql) dol_print_error($db);
|
||||
|
||||
// Update status communication of thirdparty prospect
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=-1 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE tag='".$db->escape($tag)."' AND source_type='thirdparty' AND source_id is not null)";
|
||||
dol_syslog("public/emailing/mailing-unsubscribe.php : Mail unsubcribe thirdparty : ".$sql, LOG_DEBUG);
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if (! $resql) dol_print_error($db);
|
||||
|
||||
// Update status communication of contact prospect
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET no_email=1 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE tag = '".$db->escape($tag)."' AND source_type='contact' AND source_id is not null)";
|
||||
dol_syslog("public/emailing/mailing-unsubscribe.php : Mail unsubcribe contact : ".$sql, LOG_DEBUG);
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if (! $resql) dol_print_error($db);
|
||||
|
||||
|
||||
$sql = "SELECT mc.email";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
|
||||
$sql .= " WHERE mc.tag='".$db->escape($tag)."'";
|
||||
$sql = "SELECT mc.email, m.entity";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m";
|
||||
$sql .= " WHERE mc.fk_mailing = m.rowid AND mc.tag='".$db->escape($tag)."'";
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if (! $resql) dol_print_error($db);
|
||||
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
if (empty($obj->email))
|
||||
{
|
||||
print 'Email not found. No need to unsubscribe.';
|
||||
exit;
|
||||
}
|
||||
|
||||
// Update status of mail in recipient mailing list table
|
||||
$statut='3';
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=".$statut." WHERE tag='".$db->escape($tag)."'";
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if (! $resql) dol_print_error($db);
|
||||
|
||||
// Update status communication of thirdparty prospect (old data)
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=-1 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE tag = '".$db->escape($tag)."' AND source_type='thirdparty' AND source_id is not null)";
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if (! $resql) dol_print_error($db);
|
||||
|
||||
// Update status communication of contact prospect (old data)
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET no_email=1 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE tag = '".$db->escape($tag)."' AND source_type='contact' AND source_id is not null)";
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if (! $resql) dol_print_error($db);
|
||||
|
||||
// Update status communication of contact prospect (old data)
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe (date_creat, entity, email) VALUES ('".$db->idate(dol_now())."', ".$obj->entity.", '".$obj->email."')";
|
||||
|
||||
$resql=$db->query($sql);
|
||||
//if (! $resql) dol_print_error($db); No test on errors, may fail if already unsubscribed
|
||||
|
||||
|
||||
header("Content-type: text/html; charset=".$conf->file->character_set_client);
|
||||
|
||||
print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user