mailing-read.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file public/emailing/mailing-read.php
  22. * \ingroup mailing
  23. * \brief Script use to update mail status if destinaries read it (if images during mail read are display)
  24. */
  25. if (!defined('NOLOGIN')) {
  26. define('NOLOGIN', '1');
  27. }
  28. if (!defined('NOCSRFCHECK')) {
  29. define('NOCSRFCHECK', '1');
  30. }
  31. if (!defined('NOBROWSERNOTIF')) {
  32. define('NOBROWSERNOTIF', '1');
  33. }
  34. if (!defined('NOREQUIRETRAN')) {
  35. define('NOREQUIRETRAN', '1');
  36. }
  37. if (!defined('NOTOKENRENEWAL')) {
  38. define('NOTOKENRENEWAL', '1'); // Do not check anti POST attack test
  39. }
  40. if (!defined('NOREQUIREMENU')) {
  41. define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
  42. }
  43. if (!defined('NOIPCHECK')) {
  44. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  45. }
  46. if (!defined("NOSESSION")) {
  47. define("NOSESSION", '1');
  48. }
  49. /**
  50. * Header empty
  51. *
  52. * @return void
  53. */
  54. function llxHeader()
  55. {
  56. }
  57. /**
  58. * Footer empty
  59. *
  60. * @return void
  61. */
  62. function llxFooter()
  63. {
  64. }
  65. // Load Dolibarr environment
  66. require '../../main.inc.php';
  67. $mtid = GETPOST('mtid');
  68. $email = GETPOST('email');
  69. $tag = GETPOST('tag');
  70. $securitykey = GETPOST('securitykey');
  71. /*
  72. * Actions
  73. */
  74. dol_syslog("public/emailing/mailing-read.php : tag=".$tag." securitykey=".$securitykey, LOG_DEBUG);
  75. if ($securitykey != $conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY) {
  76. print 'Bad security key value.';
  77. exit;
  78. }
  79. if (!empty($tag)) {
  80. dol_syslog("public/emailing/mailing-read.php : Update status of email target and thirdparty for tag ".$tag, LOG_DEBUG);
  81. $sql = "SELECT mc.rowid, mc.email, mc.statut, mc.source_type, mc.source_id, m.entity";
  82. $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m";
  83. $sql .= " WHERE mc.fk_mailing = m.rowid AND mc.tag='".$db->escape($tag)."'";
  84. $resql = $db->query($sql);
  85. if (!$resql) dol_print_error($db);
  86. $obj = $db->fetch_object($resql);
  87. if (empty($obj)) {
  88. print 'Email target not valid. Operation canceled.';
  89. exit;
  90. }
  91. if (empty($obj->email)) {
  92. print 'Email target not valid. Operation canceled.';
  93. exit;
  94. }
  95. if ($obj->statut == 2 || $obj->statut == 3) {
  96. print 'Email target already set to read or unsubscribe. Operation canceled.';
  97. exit;
  98. }
  99. // TODO Test that mtid and email match also with the one found from $tag
  100. /*
  101. if ($obj->email != $email)
  102. {
  103. print 'Email does not match tagnot found. No need to unsubscribe.';
  104. exit;
  105. }
  106. */
  107. //Update status of target
  108. $statut = '2';
  109. $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=".((int) $statut)." WHERE rowid = ".((int) $obj->rowid);
  110. $resql = $db->query($sql);
  111. if (!$resql) dol_print_error($db);
  112. //Update status communication of thirdparty prospect
  113. if ($obj->source_id > 0 && $obj->source_type == 'thirdparty' && $obj->entity) {
  114. $sql = "UPDATE ".MAIN_DB_PREFIX.'societe SET fk_stcomm = 3 WHERE fk_stcomm <> -1 AND entity = '.((int) $obj->entity).' AND rowid = '.((int) $obj->source_id);
  115. $resql = $db->query($sql);
  116. }
  117. //Update status communication of contact prospect
  118. if ($obj->source_id > 0 && $obj->source_type == 'contact' && $obj->entity) {
  119. $sql = "UPDATE ".MAIN_DB_PREFIX.'societe SET fk_stcomm = 3 WHERE fk_stcomm <> -1 AND entity = '.((int) $obj->entity).' AND rowid IN (SELECT sc.fk_soc FROM '.MAIN_DB_PREFIX.'socpeople AS sc WHERE sc.rowid = '.((int) $obj->source_id).')';
  120. $resql = $db->query($sql);
  121. }
  122. }
  123. $db->close();