2012-02-22 20:49:55 +01:00
< ? php
2012-04-16 12:01:32 +02:00
/**
2012-02-22 20:49:55 +01:00
* Copyright ( C ) 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2005 - 2011 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2012 Florian Henry < florian . henry @ open - concept . pro >
*
* 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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2012-02-22 20:49:55 +01:00
* ( 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2012-02-22 20:49:55 +01:00
*/
/**
2012-04-16 12:01:32 +02:00
* \file public / emailing / mailing - read . php
2012-02-22 20:49:55 +01:00
* \ingroup mailing
* \brief Script use to update mail status if destinaries read it ( if images during mail read are display )
*/
2012-04-05 21:02:00 +02:00
2021-02-26 18:58:34 +01:00
if ( ! defined ( 'NOLOGIN' )) {
define ( 'NOLOGIN' , '1' );
}
if ( ! defined ( 'NOCSRFCHECK' )) {
define ( 'NOCSRFCHECK' , '1' );
}
if ( ! defined ( 'NOBROWSERNOTIF' )) {
define ( 'NOBROWSERNOTIF' , '1' );
}
if ( ! defined ( 'NOREQUIRETRAN' )) {
define ( 'NOREQUIRETRAN' , '1' );
}
if ( ! defined ( 'NOTOKENRENEWAL' )) {
define ( 'NOTOKENRENEWAL' , '1' ); // Do not check anti POST attack test
}
if ( ! defined ( 'NOREQUIREMENU' )) {
define ( 'NOREQUIREMENU' , '1' ); // If there is no need to load and show top and left menu
}
if ( ! defined ( 'NOIPCHECK' )) {
define ( 'NOIPCHECK' , '1' ); // Do not check IP defined into conf $dolibarr_main_restrict_ip
}
2021-03-05 19:29:09 +01:00
if ( ! defined ( " NOSESSION " )) {
define ( " NOSESSION " , '1' );
}
2012-02-22 20:49:55 +01:00
2013-04-15 15:43:25 +02:00
/**
* Header empty
*
* @ return void
*/
2018-08-15 14:28:34 +02:00
function llxHeader ()
{
}
2013-04-15 15:43:25 +02:00
/**
* Footer empty
*
* @ return void
*/
2018-08-15 14:28:34 +02:00
function llxFooter ()
{
}
2013-04-15 15:43:25 +02:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-02-22 20:49:55 +01:00
2021-03-05 14:54:17 +01:00
$mtid = GETPOST ( 'mtid' );
$email = GETPOST ( 'email' );
2020-04-10 10:59:32 +02:00
$tag = GETPOST ( 'tag' );
$securitykey = GETPOST ( 'securitykey' );
2012-03-01 14:51:07 +01:00
2012-04-05 21:02:00 +02:00
/*
* Actions
*/
2012-03-01 14:51:07 +01:00
2013-06-05 16:24:32 +02:00
dol_syslog ( " public/emailing/mailing-read.php : tag= " . $tag . " securitykey= " . $securitykey , LOG_DEBUG );
2021-02-26 18:58:34 +01:00
if ( $securitykey != $conf -> global -> MAILING_EMAIL_UNSUBSCRIBE_KEY ) {
2013-04-14 20:59:16 +02:00
print 'Bad security key value.' ;
exit ;
2013-06-05 16:24:32 +02:00
}
2013-04-14 20:43:38 +02:00
2021-02-26 18:58:34 +01:00
if ( ! empty ( $tag )) {
2021-03-05 14:54:17 +01:00
dol_syslog ( " public/emailing/mailing-read.php : Update status of email target and thirdparty for tag " . $tag , LOG_DEBUG );
$sql = " SELECT mc.rowid, mc.email, mc.statut, mc.source_type, mc.source_id, 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 ) . " ' " ;
2012-04-05 21:02:00 +02:00
2020-04-10 10:59:32 +02:00
$resql = $db -> query ( $sql );
2021-03-05 14:54:17 +01:00
if ( ! $resql ) dol_print_error ( $db );
$obj = $db -> fetch_object ( $resql );
if ( empty ( $obj )) {
print 'Email target not valid. Operation canceled.' ;
exit ;
}
if ( empty ( $obj -> email )) {
print 'Email target not valid. Operation canceled.' ;
exit ;
}
2021-03-05 17:48:55 +01:00
if ( $obj -> statut == 2 || $obj -> statut == 3 ) {
print 'Email target already set to read or unsubscribe. Operation canceled.' ;
2021-03-05 14:54:17 +01:00
exit ;
}
// TODO Test that mtid and email match also with the one found from $tag
/*
if ( $obj -> email != $email )
{
print 'Email does not match tagnot found. No need to unsubscribe.' ;
exit ;
}
*/
//Update status of target
$statut = '2' ;
2021-03-30 11:36:50 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " mailing_cibles SET statut= " . (( int ) $statut ) . " WHERE rowid = " . (( int ) $obj -> rowid );
2020-04-10 10:59:32 +02:00
$resql = $db -> query ( $sql );
2021-03-05 17:48:55 +01:00
if ( ! $resql ) dol_print_error ( $db );
2012-04-04 14:45:48 +02:00
//Update status communication of thirdparty prospect
2021-03-05 14:54:17 +01:00
if ( $obj -> source_id > 0 && $obj -> source_type == 'thirdparty' && $obj -> entity ) {
2021-08-28 03:09:18 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . 'societe SET fk_stcomm = 3 WHERE fk_stcomm <> -1 AND entity = ' . (( int ) $obj -> entity ) . ' AND rowid = ' . (( int ) $obj -> source_id );
2021-03-05 14:54:17 +01:00
$resql = $db -> query ( $sql );
}
2012-04-04 14:45:48 +02:00
2020-03-23 15:54:02 +01:00
//Update status communication of contact prospect
2021-03-05 14:54:17 +01:00
if ( $obj -> source_id > 0 && $obj -> source_type == 'contact' && $obj -> entity ) {
2021-08-28 03:09:18 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . 'societe SET fk_stcomm = 3 WHERE fk_stcomm <> -1 AND entity = ' . (( int ) $obj -> entity ) . ' AND rowid IN (SELECT sc.fk_soc FROM ' . MAIN_DB_PREFIX . 'socpeople AS sc WHERE sc.rowid = ' . (( int ) $obj -> source_id ) . ')' ;
2021-03-05 14:54:17 +01:00
$resql = $db -> query ( $sql );
}
2012-03-01 14:51:07 +01:00
}
2012-02-22 20:49:55 +01:00
$db -> close ();