mailing.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. $mailingdelay = GETPOST('MAILING_DELAY', 'int');
  42. $res=dolibarr_set_const($db, "MAILING_EMAIL_FROM",$mailfrom,'chaine',0,'',$conf->entity);
  43. if (! $res > 0) $error++;
  44. $res=dolibarr_set_const($db, "MAILING_EMAIL_ERRORSTO",$mailerror,'chaine',0,'',$conf->entity);
  45. if (! $res > 0) $error++;
  46. $res=dolibarr_set_const($db, "MAILING_DELAY",$mailingdelay,'chaine',0,'',$conf->entity);
  47. if (! $res > 0) $error++;
  48. // Create temporary encryption key if nedded
  49. $res=dolibarr_set_const($db, "MAILING_EMAIL_UNSUBSCRIBE_KEY",$checkread_key,'chaine',0,'',$conf->entity);
  50. if (! $res > 0) $error++;
  51. if (! $error)
  52. {
  53. $db->commit();
  54. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  55. }
  56. else
  57. {
  58. $db->rollback();
  59. setEventMessages($langs->trans("Error"), null, 'errors');
  60. }
  61. }
  62. /*
  63. * View
  64. */
  65. llxHeader('',$langs->trans("MailingSetup"));
  66. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  67. print load_fiche_titre($langs->trans("MailingSetup"),$linkback,'title_setup');
  68. if (! empty($conf->use_javascript_ajax))
  69. {
  70. print "\n".'<script type="text/javascript">';
  71. print '$(document).ready(function () {
  72. $("#generate_token").click(function() {
  73. $.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
  74. action: \'getrandompassword\',
  75. generic: true
  76. },
  77. function(token) {
  78. $("#MAILING_EMAIL_UNSUBSCRIBE_KEY").val(token);
  79. });
  80. });
  81. });';
  82. print '</script>';
  83. }
  84. print '<br>';
  85. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  86. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  87. print '<input type="hidden" name="action" value="setvalue">';
  88. $var=true;
  89. print '<table class="noborder" width="100%">';
  90. print '<tr class="liste_titre">';
  91. print '<td>'.$langs->trans("Parameter").'</td>';
  92. print '<td>'.$langs->trans("Value").'</td>';
  93. print "</tr>\n";
  94. print '<tr class="oddeven"><td>';
  95. print $langs->trans("MailingEMailFrom").'</td><td>';
  96. print '<input size="32" type="text" name="MAILING_EMAIL_FROM" value="'.$conf->global->MAILING_EMAIL_FROM.'">';
  97. if (!empty($conf->global->MAILING_EMAIL_FROM) && ! isValidEmail($conf->global->MAILING_EMAIL_FROM)) print ' '.img_warning($langs->trans("BadEMail"));
  98. print '</td></tr>';
  99. print '<tr class="oddeven"><td>';
  100. print $langs->trans("MailingEMailError").'</td><td>';
  101. print '<input size="32" type="text" name="MAILING_EMAIL_ERRORSTO" value="'.$conf->global->MAILING_EMAIL_ERRORSTO.'">';
  102. if (!empty($conf->global->MAILING_EMAIL_ERRORSTO) && ! isValidEmail($conf->global->MAILING_EMAIL_ERRORSTO)) print ' '.img_warning($langs->trans("BadEMail"));
  103. print '</td></tr>';
  104. print '<tr class="oddeven"><td>';
  105. print $langs->trans("MailingDelay").'</td><td>';
  106. print '<input size="32" type="text" name="MAILING_DELAY" value="'.$conf->global->MAILING_DELAY.'">';
  107. print '</td></tr>';
  108. // Constant to add salt into the unsubscribe and check read tag.
  109. // It is also used as a security key parameter.
  110. print '<tr class="oddeven"><td>';
  111. print $langs->trans("ActivateCheckReadKey").'</td><td>';
  112. print '<input size="32" type="text" name="MAILING_EMAIL_UNSUBSCRIBE_KEY" id="MAILING_EMAIL_UNSUBSCRIBE_KEY" value="'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY.'">';
  113. if (! empty($conf->use_javascript_ajax)) print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
  114. print '</td></tr>';
  115. print '</table>';
  116. print '<br>';
  117. print '<div align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
  118. print '</form>';
  119. llxFooter();
  120. $db->close();