dolibarr  16.0.5
mailing-unsubscribe.php
Go to the documentation of this file.
1 <?php
30 if (!defined('NOLOGIN')) {
31  define('NOLOGIN', '1');
32 }
33 if (!defined('NOCSRFCHECK')) {
34  define('NOCSRFCHECK', '1');
35 }
36 if (!defined('NOBROWSERNOTIF')) {
37  define('NOBROWSERNOTIF', '1');
38 }
39 if (!defined('NOREQUIREMENU')) {
40  define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
41 }
42 if (!defined('NOIPCHECK')) {
43  define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
44 }
45 if (!defined("NOSESSION")) {
46  define("NOSESSION", '1');
47 }
48 
54 function llxHeader()
55 {
56 }
62 function llxFooter()
63 {
64 }
65 
66 
67 require '../../main.inc.php';
68 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
69 
70 global $user, $conf, $langs;
71 
72 $langs->loadLangs(array("main", "mails"));
73 
74 $mtid = GETPOST('mtid');
75 $email = GETPOST('email');
76 $tag = GETPOST('tag');
77 $unsuscrib = GETPOST('unsuscrib');
78 $securitykey = GETPOST('securitykey');
79 
80 
81 /*
82  * Actions
83  */
84 
85 dol_syslog("public/emailing/mailing-read.php : tag=".$tag." securitykey=".$securitykey, LOG_DEBUG);
86 
87 if ($securitykey != $conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY) {
88  print 'Bad security key value.';
89  exit;
90 }
91 
92 
93 if (!empty($tag) && ($unsuscrib == '1')) {
94  dol_syslog("public/emailing/mailing-unsubscribe.php : Launch unsubscribe requests", LOG_DEBUG);
95 
96  $sql = "SELECT mc.rowid, mc.email, mc.statut, 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 == 3) {
116  print 'Email target already set to 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 mail in recipient mailing list table
129  $statut = '3';
130  $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=".((int) $statut)." WHERE tag = '".$db->escape($tag)."'";
131 
132  $resql = $db->query($sql);
133  if (!$resql) {
134  dol_print_error($db);
135  }
136 
137  /*
138  // Update status communication of thirdparty prospect (old usage)
139  $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)";
140 
141  $resql=$db->query($sql);
142  if (! $resql) dol_print_error($db);
143 
144  // Update status communication of contact prospect (old usage)
145  $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)";
146 
147  $resql=$db->query($sql);
148  if (! $resql) dol_print_error($db);
149  */
150 
151  // Update status communication of email (new usage)
152  $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())."')";
153 
154  $resql = $db->query($sql);
155  //if (! $resql) dol_print_error($db); No test on errors, may fail if already unsubscribed
156 
157 
158  header("Content-type: text/html; charset=".$conf->file->character_set_client);
159 
160  // Security options
161  header("X-Content-Type-Options: nosniff"); // With the nosniff option, if the server says the content is text/html, the browser will render it as text/html (note that most browsers now force this option to on)
162  header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
163 
164  print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
165  print "\n";
166  print "<html>\n";
167  print "<head>\n";
168  print '<meta name="robots" content="noindex,nofollow">'."\n";
169  print '<meta name="keywords" content="dolibarr,emailing">'."\n";
170  print '<meta name="description" content="Dolibarr EMailing unsubcribe page">'."\n";
171  print "<title>".$langs->trans("MailUnsubcribe")."</title>\n";
172  print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.$conf->css.'?lang='.$langs->defaultlang.'">'."\n";
173  print '<style type="text/css">';
174  print '.CTableRow1 { margin: 1px; padding: 3px; font: 12px verdana,arial; background: #e6E6eE; color: #000000; -moz-border-radius-topleft:6px; -moz-border-radius-topright:6px; -moz-border-radius-bottomleft:6px; -moz-border-radius-bottomright:6px;}';
175  print '.CTableRow2 { margin: 1px; padding: 3px; font: 12px verdana,arial; background: #FFFFFF; color: #000000; -moz-border-radius-topleft:6px; -moz-border-radius-topright:6px; -moz-border-radius-bottomleft:6px; -moz-border-radius-bottomright:6px;}';
176  print '</style>';
177 
178  print "</head>\n";
179  print '<body style="margin: 20px;">'."\n";
180  print '<table><tr><td style="text_align:center;">';
181  print $langs->trans("YourMailUnsubcribeOK", $obj->email)."<br>\n";
182  print '</td></tr></table>';
183  print "</body>\n";
184  print "</html>\n";
185 }
186 
187 $db->close();
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
llxFooter
llxFooter()
Footer empty.
Definition: mailing-unsubscribe.php:62
llxHeader
if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOBROWSERNOTIF')) if(!defined('NOREQUIREMENU')) if(!defined('NOIPCHECK')) if(!defined("NOSESSION")) llxHeader()
Header empty.
Definition: mailing-unsubscribe.php:54
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
getUserRemoteIP
getUserRemoteIP()
Return the IP of remote user.
Definition: functions.lib.php:3515