dolibarr 21.0.0-beta
mailing-read.php
Go to the documentation of this file.
1<?php
29if (!defined('NOLOGIN')) {
30 define('NOLOGIN', '1');
31}
32if (!defined('NOCSRFCHECK')) {
33 define('NOCSRFCHECK', '1');
34}
35if (!defined('NOBROWSERNOTIF')) {
36 define('NOBROWSERNOTIF', '1');
37}
38if (!defined('NOREQUIRETRAN')) {
39 define('NOREQUIRETRAN', '1');
40}
41if (!defined('NOTOKENRENEWAL')) {
42 define('NOTOKENRENEWAL', '1'); // Do not check anti POST attack test
43}
44if (!defined('NOREQUIREMENU')) {
45 define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
46}
47if (!defined('NOIPCHECK')) {
48 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
49}
50if (!defined('NOSESSION')) {
51 define('NOSESSION', '1');
52}
53
74function llxHeader($head = '', $title = '', $help_url = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $morequerystring = '', $morecssonbody = '', $replacemainareaby = '', $disablenofollow = 0, $disablenoindex = 0)
75{
76}
77
78
87function llxFooter($comment = '', $zone = 'private', $disabledoutputofmessages = 0)
88{
89}
90
91
92// Load Dolibarr environment
93require '../../main.inc.php';
97$mtid = GETPOST('mtid');
98$email = GETPOST('email');
99$tag = GETPOST('tag');
100$securitykey = GETPOST('securitykey');
101
102
103/*
104 * Actions
105 */
106
107dol_syslog("public/emailing/mailing-read.php : tag=".$tag." securitykey=".$securitykey, LOG_DEBUG);
108
109if ($securitykey != dol_hash(getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY')."-".$tag."-".$email."-".$mtid, 'md5')) {
110 print 'Bad security key value.';
111 exit;
112}
113
114if (!empty($tag) && $tag != 'undefined') {
115 dol_syslog("public/emailing/mailing-read.php : Update status of email target and thirdparty for tag ".$tag, LOG_DEBUG);
116
117 $sql = "SELECT mc.rowid, mc.email, mc.statut, mc.source_type, mc.source_id, m.entity";
118 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m";
119 $sql .= " WHERE mc.fk_mailing = m.rowid AND mc.tag = '".$db->escape($tag)."'";
120
121 $resql = $db->query($sql);
122 if (!$resql) {
123 dol_print_error($db);
124 }
125
126 $obj = $db->fetch_object($resql);
127
128 if (empty($obj)) {
129 print 'Email target not valid. Operation canceled.';
130 exit;
131 }
132 if (empty($obj->email)) {
133 print 'Email target not valid. Operation canceled.';
134 exit;
135 }
136 if ($obj->statut == 2 || $obj->statut == 3) {
137 print 'Email target already set to read or unsubscribe. Operation canceled.';
138 exit;
139 }
140 // TODO Test that mtid and email match also with the one found from $tag
141 /*
142 if ($obj->email != $email)
143 {
144 print 'Email does not match tagnot found. No need to unsubscribe.';
145 exit;
146 }
147 */
148
149 // Update status of target
150 $statut = '2';
151 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=".((int) $statut)." WHERE rowid = ".((int) $obj->rowid);
152 $resql = $db->query($sql);
153 if (!$resql) {
154 dol_print_error($db);
155 }
156
157 // Update status communication of thirdparty prospect
158 if ($obj->source_id > 0 && $obj->source_type == 'thirdparty' && $obj->entity) {
159 $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);
160 $resql = $db->query($sql);
161 }
162
163 // Update status communication of contact prospect
164 if ($obj->source_id > 0 && $obj->source_type == 'contact' && $obj->entity) {
165 $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).')';
166 $resql = $db->query($sql);
167 }
168}
169
170$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)
Returns a hash (non reversible encryption) of a string.