mailing-unsubscribe.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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');
  28. if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1');
  29. if (!defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1');
  30. if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
  31. if (!defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  32. if (!defined("NOSESSION")) define("NOSESSION", '1');
  33. /**
  34. * Header empty
  35. *
  36. * @return void
  37. */
  38. function llxHeader()
  39. {
  40. }
  41. /**
  42. * Footer empty
  43. *
  44. * @return void
  45. */
  46. function llxFooter()
  47. {
  48. }
  49. require '../../main.inc.php';
  50. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  51. global $user, $conf, $langs;
  52. $langs->loadLangs(array("main", "mails"));
  53. $mtid = GETPOST('mtid');
  54. $email = GETPOST('email');
  55. $tag = GETPOST('tag');
  56. $unsuscrib = GETPOST('unsuscrib');
  57. $securitykey = GETPOST('securitykey');
  58. /*
  59. * Actions
  60. */
  61. dol_syslog("public/emailing/mailing-read.php : tag=".$tag." securitykey=".$securitykey, LOG_DEBUG);
  62. if ($securitykey != $conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY)
  63. {
  64. print 'Bad security key value.';
  65. exit;
  66. }
  67. if (!empty($tag) && ($unsuscrib == '1'))
  68. {
  69. dol_syslog("public/emailing/mailing-unsubscribe.php : Launch unsubscribe requests", LOG_DEBUG);
  70. $sql = "SELECT mc.rowid, mc.email, mc.statut, m.entity";
  71. $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m";
  72. $sql .= " WHERE mc.fk_mailing = m.rowid AND mc.tag='".$db->escape($tag)."'";
  73. $resql = $db->query($sql);
  74. if (!$resql) dol_print_error($db);
  75. $obj = $db->fetch_object($resql);
  76. if (empty($obj)) {
  77. print 'Email target not valid. Operation canceled.';
  78. exit;
  79. }
  80. if (empty($obj->email)) {
  81. print 'Email target not valid. Operation canceled.';
  82. exit;
  83. }
  84. if ($obj->statut == 3) {
  85. print 'Email target already set to unsubscribe. Operation canceled.';
  86. exit;
  87. }
  88. // TODO Test that mtid and email match also with the one found from $tag
  89. /*
  90. if ($obj->email != $email)
  91. {
  92. print 'Email does not match tagnot found. No need to unsubscribe.';
  93. exit;
  94. }
  95. */
  96. // Update status of mail in recipient mailing list table
  97. $statut = '3';
  98. $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=".$statut." WHERE tag='".$db->escape($tag)."'";
  99. $resql = $db->query($sql);
  100. if (!$resql) dol_print_error($db);
  101. // Update status communication of email (new usage)
  102. $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())."')";
  103. $resql = $db->query($sql);
  104. //if (! $resql) dol_print_error($db); No test on errors, may fail if already unsubscribed
  105. header("Content-type: text/html; charset=".$conf->file->character_set_client);
  106. print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
  107. print "\n";
  108. print "<html>\n";
  109. print "<head>\n";
  110. print '<meta name="robots" content="noindex,nofollow">'."\n";
  111. print '<meta name="keywords" content="dolibarr,emailing">'."\n";
  112. print '<meta name="description" content="Dolibarr EMailing unsubcribe page">'."\n";
  113. print "<title>".$langs->trans("MailUnsubcribe")."</title>\n";
  114. print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.$conf->css.'?lang='.$langs->defaultlang.'">'."\n";
  115. print '<style type="text/css">';
  116. 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;}';
  117. 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;}';
  118. print '</style>';
  119. print "</head>\n";
  120. print '<body style="margin: 20px;">'."\n";
  121. print '<table><tr><td style="text_align:center;">';
  122. print $langs->trans("YourMailUnsubcribeOK", $obj->email)."<br>\n";
  123. print '</td></tr></table>';
  124. print "</body>\n";
  125. print "</html>\n";
  126. }
  127. $db->close();