dolibarr 19.0.4
mailing-read.php
Go to the documentation of this file.
1<?php
28if (!defined('NOLOGIN')) {
29 define('NOLOGIN', '1');
30}
31if (!defined('NOCSRFCHECK')) {
32 define('NOCSRFCHECK', '1');
33}
34if (!defined('NOBROWSERNOTIF')) {
35 define('NOBROWSERNOTIF', '1');
36}
37if (!defined('NOREQUIRETRAN')) {
38 define('NOREQUIRETRAN', '1');
39}
40if (!defined('NOTOKENRENEWAL')) {
41 define('NOTOKENRENEWAL', '1'); // Do not check anti POST attack test
42}
43if (!defined('NOREQUIREMENU')) {
44 define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
45}
46if (!defined('NOIPCHECK')) {
47 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
48}
49if (!defined('NOSESSION')) {
50 define('NOSESSION', '1');
51}
52
58function llxHeader()
59{
60}
61
62
68function llxFooter()
69{
70}
71
72
73// Load Dolibarr environment
74require '../../main.inc.php';
75
76$mtid = GETPOST('mtid');
77$email = GETPOST('email');
78$tag = GETPOST('tag');
79$securitykey = GETPOST('securitykey');
80
81
82/*
83 * Actions
84 */
85
86dol_syslog("public/emailing/mailing-read.php : tag=".$tag." securitykey=".$securitykey, LOG_DEBUG);
87
88if ($securitykey != dol_hash(getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY')."-".$tag."-".$email."-".$mtid, 'md5')) {
89 print 'Bad security key value.';
90 exit;
91}
92
93if (!empty($tag) && $tag != 'undefined') {
94 dol_syslog("public/emailing/mailing-read.php : Update status of email target and thirdparty for tag ".$tag, LOG_DEBUG);
95
96 $sql = "SELECT mc.rowid, mc.email, mc.statut, mc.source_type, mc.source_id, m.entity";
97 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m";
98 $sql .= " WHERE mc.fk_mailing = m.rowid AND mc.tag = '".$db->escape($tag)."'";
99
100 $resql = $db->query($sql);
101 if (!$resql) {
102 dol_print_error($db);
103 }
104
105 $obj = $db->fetch_object($resql);
106
107 if (empty($obj)) {
108 print 'Email target not valid. Operation canceled.';
109 exit;
110 }
111 if (empty($obj->email)) {
112 print 'Email target not valid. Operation canceled.';
113 exit;
114 }
115 if ($obj->statut == 2 || $obj->statut == 3) {
116 print 'Email target already set to read or unsubscribe. Operation canceled.';
117 exit;
118 }
119 // TODO Test that mtid and email match also with the one found from $tag
120 /*
121 if ($obj->email != $email)
122 {
123 print 'Email does not match tagnot found. No need to unsubscribe.';
124 exit;
125 }
126 */
127
128 // Update status of target
129 $statut = '2';
130 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=".((int) $statut)." WHERE rowid = ".((int) $obj->rowid);
131 $resql = $db->query($sql);
132 if (!$resql) {
133 dol_print_error($db);
134 }
135
136 // Update status communication of thirdparty prospect
137 if ($obj->source_id > 0 && $obj->source_type == 'thirdparty' && $obj->entity) {
138 $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);
139 $resql = $db->query($sql);
140 }
141
142 // Update status communication of contact prospect
143 if ($obj->source_id > 0 && $obj->source_type == 'contact' && $obj->entity) {
144 $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).')';
145 $resql = $db->query($sql);
146 }
147}
148
149$db->close();
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined('NOLOGIN')) if(!defined( 'NOCSRFCHECK')) if(!defined('NOBROWSERNOTIF')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOIPCHECK')) if(!defined( 'NOSESSION')) llxHeader()
Header empty.
llxFooter()
Footer empty.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.