mailing-unsubscribe.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  4. * Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2012 Florian Henry <florian.henry@open-concept.pro>
  6. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file public/emailing/mailing-unsubscribe.php
  23. * \ingroup mailing
  24. * \brief Script use to update unsubcribe status of an email
  25. * https://myserver/public/emailing/mailing-unsubscribe.php?unsuscrib=1&securitykey=securitykey&tag=abcdefghijklmn
  26. */
  27. if (!defined('NOLOGIN')) define("NOLOGIN", 1); // This means this output page does not require to be logged.
  28. if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check anti CSRF attack test
  29. if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
  30. /**
  31. * Header empty
  32. *
  33. * @return void
  34. */
  35. function llxHeader()
  36. {
  37. }
  38. /**
  39. * Footer empty
  40. *
  41. * @return void
  42. */
  43. function llxFooter()
  44. {
  45. }
  46. require '../../main.inc.php';
  47. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  48. global $user, $conf, $langs;
  49. $langs->loadLangs(array("main", "mails"));
  50. $tag = GETPOST('tag');
  51. $unsuscrib = GETPOST('unsuscrib');
  52. $securitykey = GETPOST('securitykey');
  53. /*
  54. * Actions
  55. */
  56. dol_syslog("public/emailing/mailing-read.php : tag=".$tag." securitykey=".$securitykey, LOG_DEBUG);
  57. if ($securitykey != $conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY)
  58. {
  59. print 'Bad security key value.';
  60. exit;
  61. }
  62. if (!empty($tag) && ($unsuscrib == '1'))
  63. {
  64. dol_syslog("public/emailing/mailing-unsubscribe.php : Launch unsubscribe requests", LOG_DEBUG);
  65. $sql = "SELECT mc.email, m.entity";
  66. $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m";
  67. $sql .= " WHERE mc.fk_mailing = m.rowid AND mc.tag='".$db->escape($tag)."'";
  68. $resql = $db->query($sql);
  69. if (!$resql) dol_print_error($db);
  70. $obj = $db->fetch_object($resql);
  71. if (empty($obj->email))
  72. {
  73. print 'Email not found. No need to unsubscribe.';
  74. exit;
  75. }
  76. // Update status of mail in recipient mailing list table
  77. $statut = '3';
  78. $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=".$statut." WHERE tag='".$db->escape($tag)."'";
  79. $resql = $db->query($sql);
  80. if (!$resql) dol_print_error($db);
  81. /*
  82. // Update status communication of thirdparty prospect (old usage)
  83. $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)";
  84. $resql=$db->query($sql);
  85. if (! $resql) dol_print_error($db);
  86. // Update status communication of contact prospect (old usage)
  87. $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)";
  88. $resql=$db->query($sql);
  89. if (! $resql) dol_print_error($db);
  90. */
  91. // Update status communication of email (new usage)
  92. $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe (date_creat, entity, email) VALUES ('".$db->idate(dol_now())."', ".$db->escape($obj->entity).", '".$db->escape($obj->email)."')";
  93. $resql = $db->query($sql);
  94. //if (! $resql) dol_print_error($db); No test on errors, may fail if already unsubscribed
  95. header("Content-type: text/html; charset=".$conf->file->character_set_client);
  96. print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
  97. print "\n";
  98. print "<html>\n";
  99. print "<head>\n";
  100. print '<meta name="robots" content="noindex,nofollow">'."\n";
  101. print '<meta name="keywords" content="dolibarr,emailing">'."\n";
  102. print '<meta name="description" content="Dolibarr EMailing unsubcribe page">'."\n";
  103. print "<title>".$langs->trans("MailUnsubcribe")."</title>\n";
  104. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.$conf->css.'?lang='.$langs->defaultlang.'">'."\n";
  105. print '<style type="text/css">';
  106. 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;}';
  107. 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;}';
  108. print '</style>';
  109. print "</head>\n";
  110. print '<body style="margin: 20px;">'."\n";
  111. print '<table><tr><td style="text_align:center;">';
  112. print $langs->trans("YourMailUnsubcribeOK", $obj->email)."<br>\n";
  113. print '</td></tr></table>';
  114. print "</body>\n";
  115. print "</html>\n";
  116. }
  117. $db->close();