dolibarr  17.0.4
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 if (! defined('NOREQUIREHTML')) {
49  define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
50 }
51 if (! defined('NOREQUIREAJAX')) {
52  define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
53 }
54 
55 
56 // Load Dolibarr environment
57 require '../../main.inc.php';
58 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
59 
60 global $user, $conf, $langs;
61 
62 $langs->loadLangs(array("main", "mails"));
63 
64 $tag = GETPOST('tag'); // To retreive the emailing, and recipient
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 != getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY')) {
76  print 'Bad security key value.';
77  exit;
78 }
79 
80 if (empty($tag) || ($unsuscrib != '1')) {
81  print 'Bad parameters';
82  exit;
83 }
84 
85 
86 /*
87  * View
88  */
89 
90 $head = '';
91 $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
92 llxHeader($head, $langs->trans("MailUnsubcribe"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
93 
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 tag not found. Operation canceled.';
109  llxFooter('', 'private');
110  exit;
111 }
112 if (empty($obj->email)) {
113  print 'Email for this tag not valid. Operation canceled.';
114  llxFooter('', 'private');
115  exit;
116 }
117 
118 if ($obj->statut == 3) {
119  print 'Email tag already set to unsubscribe. Operation canceled.';
120  llxFooter('', 'private');
121  exit;
122 }
123 // TODO Test that mtid and email match also with the one found from $tag
124 /*
125 if ($obj->email != $email)
126 {
127  print 'Email does not match tagnot found. No need to unsubscribe.';
128  exit;
129 }
130 */
131 
132 // Update status of mail in recipient mailing list table
133 $statut = '3';
134 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=".((int) $statut)." WHERE tag = '".$db->escape($tag)."'";
135 
136 $resql = $db->query($sql);
137 if (!$resql) {
138  dol_print_error($db);
139 }
140 
141 /*
142 // Update status communication of thirdparty prospect (old usage)
143 $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)";
144 
145 $resql=$db->query($sql);
146 if (! $resql) dol_print_error($db);
147 
148 // Update status communication of contact prospect (old usage)
149 $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)";
150 
151 $resql=$db->query($sql);
152 if (! $resql) dol_print_error($db);
153 */
154 
155 // Update status communication of email (new usage)
156 $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())."')";
157 
158 $resql = $db->query($sql);
159 //if (! $resql) dol_print_error($db); No test on errors, may fail if already unsubscribed
160 
161 
162 print '<table><tr><td style="text_align:center;">';
163 print $langs->trans("YourMailUnsubcribeOK", $obj->email)."<br>\n";
164 print '</td></tr></table>';
165 
166 
167 llxFooter('', 'public');
168 
169 $db->close();
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return 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.