dolibarr  13.0.2
mailing-unsubscribe.php
Go to the documentation of this file.
1 <?php
30 if (!defined('NOLOGIN')) define('NOLOGIN', '1');
31 if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1');
32 if (!defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1');
33 if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
34 if (!defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
35 if (!defined("NOSESSION")) define("NOSESSION", '1');
36 
42 function llxHeader()
43 {
44 }
50 function llxFooter()
51 {
52 }
53 
54 
55 require '../../main.inc.php';
56 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
57 
58 global $user, $conf, $langs;
59 
60 $langs->loadLangs(array("main", "mails"));
61 
62 $mtid = GETPOST('mtid');
63 $email = GETPOST('email');
64 $tag = GETPOST('tag');
65 $unsuscrib = GETPOST('unsuscrib');
66 $securitykey = GETPOST('securitykey');
67 
68 
69 /*
70  * Actions
71  */
72 
73 dol_syslog("public/emailing/mailing-read.php : tag=".$tag." securitykey=".$securitykey, LOG_DEBUG);
74 
75 if ($securitykey != $conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY)
76 {
77  print 'Bad security key value.';
78  exit;
79 }
80 
81 
82 if (!empty($tag) && ($unsuscrib == '1'))
83 {
84  dol_syslog("public/emailing/mailing-unsubscribe.php : Launch unsubscribe requests", LOG_DEBUG);
85 
86  $sql = "SELECT mc.rowid, mc.email, mc.statut, m.entity";
87  $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m";
88  $sql .= " WHERE mc.fk_mailing = m.rowid AND mc.tag='".$db->escape($tag)."'";
89 
90  $resql = $db->query($sql);
91  if (!$resql) dol_print_error($db);
92 
93  $obj = $db->fetch_object($resql);
94 
95  if (empty($obj)) {
96  print 'Email target not valid. Operation canceled.';
97  exit;
98  }
99  if (empty($obj->email)) {
100  print 'Email target not valid. Operation canceled.';
101  exit;
102  }
103  if ($obj->statut == 3) {
104  print 'Email target already set to unsubscribe. Operation canceled.';
105  exit;
106  }
107  // TODO Test that mtid and email match also with the one found from $tag
108  /*
109  if ($obj->email != $email)
110  {
111  print 'Email does not match tagnot found. No need to unsubscribe.';
112  exit;
113  }
114  */
115 
116  // Update status of mail in recipient mailing list table
117  $statut = '3';
118  $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=".$statut." WHERE tag='".$db->escape($tag)."'";
119 
120  $resql = $db->query($sql);
121  if (!$resql) dol_print_error($db);
122 
123  /*
124  // Update status communication of thirdparty prospect (old usage)
125  $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)";
126 
127  $resql=$db->query($sql);
128  if (! $resql) dol_print_error($db);
129 
130  // Update status communication of contact prospect (old usage)
131  $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)";
132 
133  $resql=$db->query($sql);
134  if (! $resql) dol_print_error($db);
135  */
136 
137  // Update status communication of email (new usage)
138  $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe (date_creat, entity, email, unsubscribegroup, ip) VALUES ('".$db->idate(dol_now())."', ".$db->escape($obj->entity).", '".$db->escape($obj->email)."', '', '".$db->escape(getUserRemoteIP())."')";
139 
140  $resql = $db->query($sql);
141  //if (! $resql) dol_print_error($db); No test on errors, may fail if already unsubscribed
142 
143 
144  header("Content-type: text/html; charset=".$conf->file->character_set_client);
145 
146  print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
147  print "\n";
148  print "<html>\n";
149  print "<head>\n";
150  print '<meta name="robots" content="noindex,nofollow">'."\n";
151  print '<meta name="keywords" content="dolibarr,emailing">'."\n";
152  print '<meta name="description" content="Dolibarr EMailing unsubcribe page">'."\n";
153  print "<title>".$langs->trans("MailUnsubcribe")."</title>\n";
154  print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.$conf->css.'?lang='.$langs->defaultlang.'">'."\n";
155  print '<style type="text/css">';
156  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;}';
157  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;}';
158  print '</style>';
159 
160  print "</head>\n";
161  print '<body style="margin: 20px;">'."\n";
162  print '<table><tr><td style="text_align:center;">';
163  print $langs->trans("YourMailUnsubcribeOK", $obj->email)."<br>\n";
164  print '</td></tr></table>';
165  print "</body>\n";
166  print "</html>\n";
167 }
168 
169 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getUserRemoteIP()
Return the IP of remote user.
dol_now($mode= 'auto')
Return date for now.
llxHeader()
Empty header.
Definition: wrapper.php:45
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59