dolibarr 21.0.0-beta
mailing-unsubscribe.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('NOREQUIREMENU')) {
40 define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
41}
42if (!defined('NOIPCHECK')) {
43 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
44}
45if (!defined("NOSESSION")) {
46 define("NOSESSION", '1');
47}
48if (! defined('NOREQUIREHTML')) {
49 define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
50}
51if (! defined('NOREQUIREAJAX')) {
52 define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
53}
54
55
56// Load Dolibarr environment
57require '../../main.inc.php';
58require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
62global $user, $conf, $db, $langs;
63
64$langs->loadLangs(array("main", "mails"));
65
66$mtid = GETPOST('mtid');
67$email = GETPOST('email');
68$tag = GETPOST('tag'); // To retrieve the emailing, and recipient
69$unsuscrib = GETPOST('unsuscrib');
70$securitykey = GETPOST('securitykey');
71
72
73/*
74 * Actions
75 */
76
77dol_syslog("public/emailing/mailing-unsubscribe.php : tag=".$tag." securitykey=".$securitykey, LOG_DEBUG);
78
79if ($securitykey != dol_hash(getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY')."-".$tag."-".$email."-".$mtid, 'md5')) {
80 print 'Bad security key value.';
81 exit;
82}
83
84if (empty($tag) || ($unsuscrib != '1')) {
85 print 'Bad parameters';
86 exit;
87}
88
89
90/*
91 * View
92 */
93
94$head = '';
95$replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
96
97llxHeader($head, $langs->trans("MailUnsubcribe"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
98
99dol_syslog("public/emailing/mailing-unsubscribe.php : Launch unsubscribe requests", LOG_DEBUG);
100
101$sql = "SELECT mc.rowid, mc.email, mc.statut, m.entity";
102$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m";
103$sql .= " WHERE mc.fk_mailing = m.rowid AND mc.tag = '".$db->escape($tag)."'";
104
105$resql = $db->query($sql);
106if (!$resql) {
107 dol_print_error($db);
108}
109
110$obj = $db->fetch_object($resql);
111
112if (empty($obj)) {
113 print 'Emailing tag '.$tag.' not found in database. Operation canceled.';
114 llxFooter('', 'private');
115 exit;
116}
117if (empty($obj->email)) {
118 print 'Email for this tag is not valid. Operation canceled.';
119 llxFooter('', 'private');
120 exit;
121}
122
123if ($obj->statut == 3) {
124 print 'Email tag already set to unsubscribe. Operation canceled.';
125 llxFooter('', 'private');
126 exit;
127}
128// TODO Test that mtid and email match also with the one found from $tag
129/*
130if ($obj->email != $email)
131{
132 print 'Email does not match tagnot found. No need to unsubscribe.';
133 exit;
134}
135*/
136
137// Update status of mail in recipient mailing list table
138$statut = '3';
139$sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=".((int) $statut)." WHERE tag = '".$db->escape($tag)."'";
140
141$resql = $db->query($sql);
142if (!$resql) {
143 dol_print_error($db);
144}
145
146/*
147// Update status communication of thirdparty prospect (old usage)
148$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)";
149
150$resql=$db->query($sql);
151if (! $resql) dol_print_error($db);
152
153// Update status communication of contact prospect (old usage)
154$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)";
155
156$resql=$db->query($sql);
157if (! $resql) dol_print_error($db);
158*/
159
160// Update status communication of email (new usage)
161$sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe (date_creat, entity, email, unsubscribegroup, ip) VALUES ('".$db->idate(dol_now())."', ".((int) $obj->entity).", '".$db->escape($obj->email)."', '', '".$db->escape(getUserRemoteIP())."')";
162
163$resql = $db->query($sql);
164//if (! $resql) dol_print_error($db); No test on errors, may fail if already unsubscribed
165
166
167print '<table><tr><td style="text_align:center;">';
168print $langs->trans("YourMailUnsubcribeOK", $obj->email)."<br>\n";
169print '</td></tr></table>';
170
171
172llxFooter('', 'public');
173
174$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
dol_now($mode='auto')
Return date for now.
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.
getUserRemoteIP()
Return the IP of remote user.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.