dolibarr 23.0.3
mailing-read.php
Go to the documentation of this file.
1<?php
30if (!defined('NOLOGIN')) {
31 define('NOLOGIN', '1');
32}
33if (!defined('NOCSRFCHECK')) {
34 define('NOCSRFCHECK', '1');
35}
36if (!defined('NOBROWSERNOTIF')) {
37 define('NOBROWSERNOTIF', '1');
38}
39if (!defined('NOREQUIRETRAN')) {
40 define('NOREQUIRETRAN', '1');
41}
42if (!defined('NOTOKENRENEWAL')) {
43 define('NOTOKENRENEWAL', '1'); // Do not check anti POST attack test
44}
45if (!defined('NOREQUIREMENU')) {
46 define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
47}
48if (!defined('NOIPCHECK')) {
49 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
50}
51if (!defined('NOSESSION')) {
52 define('NOSESSION', '1');
53}
54
77function llxHeader($head = '', $title = '', $help_url = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $morequerystring = '', $morecssonbody = '', $replacemainareaby = '', $disablenofollow = 0, $disablenoindex = 0) // @phan-suppress-current-line PhanRedefineFunction
78{
79}
80
81
92function llxFooter($comment = '', $zone = 'private', $disabledoutputofmessages = 0) // @phan-suppress-current-line PhanRedefineFunction
93{
94}
95
96
97// Load Dolibarr environment
98require '../../main.inc.php';
102$mtid = GETPOST('mtid');
103$email = GETPOST('email');
104$tag = GETPOST('tag');
105$securitykey = GETPOST('securitykey');
106
107
108/*
109 * Actions
110 */
111
112dol_syslog("public/emailing/mailing-read.php : tag=".$tag." securitykey=".$securitykey, LOG_DEBUG);
113
114if ($securitykey != dol_hash(getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY')."-".$tag."-".$email."-".$mtid, 'md5')) {
115 print 'Bad security key value.';
116 exit;
117}
118
119if (!empty($tag) && $tag != 'undefined') {
120 dol_syslog("public/emailing/mailing-read.php : Update status of email target and thirdparty for tag ".$tag, LOG_DEBUG);
121
122 $sql = "SELECT mc.rowid, mc.email, mc.statut, mc.source_type, mc.source_id, m.entity";
123 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m";
124 $sql .= " WHERE mc.fk_mailing = m.rowid AND mc.tag = '".$db->escape($tag)."'";
125
126 $resql = $db->query($sql);
127 if (!$resql) {
128 dol_print_error($db);
129 }
130
131 $obj = $db->fetch_object($resql);
132
133 if (empty($obj)) {
134 print 'Email target not valid. Operation canceled.';
135 exit;
136 }
137 if (empty($obj->email)) {
138 print 'Email target not valid. Operation canceled.';
139 exit;
140 }
141 if ($obj->statut == 2 || $obj->statut == 3) {
142 print 'Email target already set to read or unsubscribe. Operation canceled.';
143 exit;
144 }
145 // TODO Test that mtid and email match also with the one found from $tag
146 /*
147 if ($obj->email != $email)
148 {
149 print 'Email does not match tagnot found. No need to unsubscribe.';
150 exit;
151 }
152 */
153
154 // Update status of target
155 $statut = '2';
156 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=".((int) $statut)." WHERE rowid = ".((int) $obj->rowid);
157 $resql = $db->query($sql);
158 if (!$resql) {
159 dol_print_error($db);
160 }
161
162 // Update status communication of thirdparty prospect
163 if ($obj->source_id > 0 && $obj->source_type == 'thirdparty' && $obj->entity) {
164 $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);
165 $resql = $db->query($sql);
166 }
167
168 // Update status communication of contact prospect
169 if ($obj->source_id > 0 && $obj->source_type == 'contact' && $obj->entity) {
170 $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).')';
171 $resql = $db->query($sql);
172 }
173}
174
175$db->close();
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Footer empty.
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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Header empty.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.