mailing-unsubscribe.php 4.8 KB

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