mailing.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.org>
  4. * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/admin/mailing.php
  21. * \ingroup mailing
  22. * \brief Page to setup emailing module
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  27. $langs->load("admin");
  28. $langs->load("mails");
  29. if (!$user->admin) accessforbidden();
  30. $action = GETPOST('action','alpha');
  31. /*
  32. * Actions
  33. */
  34. if ($action == 'setvalue')
  35. {
  36. $db->begin();
  37. $mailfrom = GETPOST('MAILING_EMAIL_FROM','alpha');
  38. $mailerror = GETPOST('MAILING_EMAIL_ERRORSTO','alpha');
  39. $checkread = GETPOST('value','alpha');
  40. $checkread_key = GETPOST('MAILING_EMAIL_UNSUBSCRIBE_KEY','alpha');
  41. $res=dolibarr_set_const($db, "MAILING_EMAIL_FROM",$mailfrom,'chaine',0,'',$conf->entity);
  42. if (! $res > 0) $error++;
  43. $res=dolibarr_set_const($db, "MAILING_EMAIL_ERRORSTO",$mailerror,'chaine',0,'',$conf->entity);
  44. if (! $res > 0) $error++;
  45. // Create temporary encryption key if nedded
  46. $res=dolibarr_set_const($db, "MAILING_EMAIL_UNSUBSCRIBE_KEY",$checkread_key,'chaine',0,'',$conf->entity);
  47. if (! $res > 0) $error++;
  48. if (! $error)
  49. {
  50. $db->commit();
  51. setEventMessage($langs->trans("SetupSaved"));
  52. }
  53. else
  54. {
  55. $db->rollback();
  56. setEventMessage($langs->trans("Error"),'errors');
  57. }
  58. }
  59. /*
  60. * View
  61. */
  62. llxHeader('',$langs->trans("MailingSetup"));
  63. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  64. print_fiche_titre($langs->trans("MailingSetup"),$linkback,'setup');
  65. if (! empty($conf->use_javascript_ajax))
  66. {
  67. print "\n".'<script type="text/javascript">';
  68. print '$(document).ready(function () {
  69. $("#generate_token").click(function() {
  70. $.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
  71. action: \'getrandompassword\',
  72. generic: true
  73. },
  74. function(token) {
  75. $("#MAILING_EMAIL_UNSUBSCRIBE_KEY").val(token);
  76. });
  77. });
  78. });';
  79. print '</script>';
  80. }
  81. print '<br>';
  82. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  83. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  84. print '<input type="hidden" name="action" value="setvalue">';
  85. $var=true;
  86. print '<table class="noborder" width="100%">';
  87. print '<tr class="liste_titre">';
  88. print '<td>'.$langs->trans("Parameter").'</td>';
  89. print '<td>'.$langs->trans("Value").'</td>';
  90. print "</tr>\n";
  91. $var=!$var;
  92. print '<tr '.$bc[$var].'><td>';
  93. print $langs->trans("MailingEMailFrom").'</td><td>';
  94. print '<input size="32" type="text" name="MAILING_EMAIL_FROM" value="'.$conf->global->MAILING_EMAIL_FROM.'">';
  95. if (!empty($conf->global->MAILING_EMAIL_FROM) && ! isValidEmail($conf->global->MAILING_EMAIL_FROM)) print ' '.img_warning($langs->trans("BadEMail"));
  96. print '</td></tr>';
  97. $var=!$var;
  98. print '<tr '.$bc[$var].'><td>';
  99. print $langs->trans("MailingEMailError").'</td><td>';
  100. print '<input size="32" type="text" name="MAILING_EMAIL_ERRORSTO" value="'.$conf->global->MAILING_EMAIL_ERRORSTO.'">';
  101. if (!empty($conf->global->MAILING_EMAIL_ERRORSTO) && ! isValidEmail($conf->global->MAILING_EMAIL_ERRORSTO)) print ' '.img_warning($langs->trans("BadEMail"));
  102. print '</td></tr>';
  103. // Constant to add salt into the unsubscribe and check read tag.
  104. // It is also used as a security key parameter.
  105. $var=!$var;
  106. print '<tr '.$bc[$var].'><td>';
  107. print $langs->trans("ActivateCheckReadKey").'</td><td>';
  108. print '<input size="32" type="text" name="MAILING_EMAIL_UNSUBSCRIBE_KEY" id="MAILING_EMAIL_UNSUBSCRIBE_KEY" value="'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY.'">';
  109. if (! empty($conf->use_javascript_ajax)) print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
  110. print '</td></tr>';
  111. print '</table>';
  112. print '<br>';
  113. print '<div align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
  114. print '</form>';
  115. llxFooter();
  116. $db->close();