mailing.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 <https://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. // Load translation files required by the page
  28. $langs->loadLangs(array("admin", "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?restore_lastsearch_values=1">'.$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="'.newToken().'">';
  87. print '<input type="hidden" name="action" value="setvalue">';
  88. print '<table class="noborder centpercent">';
  89. print '<tr class="liste_titre">';
  90. print '<td>'.$langs->trans("Parameter").'</td>';
  91. print '<td>'.$langs->trans("Value").'</td>';
  92. print "</tr>\n";
  93. print '<tr class="oddeven"><td>';
  94. print $langs->trans("MailingEMailFrom").'</td><td>';
  95. print '<input size="32" type="text" name="MAILING_EMAIL_FROM" value="'.$conf->global->MAILING_EMAIL_FROM.'">';
  96. if (!empty($conf->global->MAILING_EMAIL_FROM) && !isValidEmail($conf->global->MAILING_EMAIL_FROM)) print ' '.img_warning($langs->trans("BadEMail"));
  97. print '</td></tr>';
  98. print '<tr class="oddeven"><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. print '<tr class="oddeven"><td>';
  104. print $langs->trans("MailingDelay").'</td><td>';
  105. print '<input size="32" type="text" name="MAILING_DELAY" value="'.$conf->global->MAILING_DELAY.'">';
  106. print '</td></tr>';
  107. // Constant to add salt into the unsubscribe and check read tag.
  108. // It is also used as a security key parameter.
  109. print '<tr class="oddeven"><td>';
  110. print $langs->trans("ActivateCheckReadKey").'</td><td>';
  111. print '<input size="32" type="text" name="MAILING_EMAIL_UNSUBSCRIBE_KEY" id="MAILING_EMAIL_UNSUBSCRIBE_KEY" value="'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY.'">';
  112. if (!empty($conf->use_javascript_ajax)) print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
  113. print '</td></tr>';
  114. if (!empty($conf->use_javascript_ajax) && $conf->global->MAIN_FEATURES_LEVEL >= 1) {
  115. print '<tr class="oddeven"><td>';
  116. print $langs->trans("MailAdvTargetRecipients").'</td><td>';
  117. print ajax_constantonoff('EMAILING_USE_ADVANCED_SELECTOR');
  118. print '</td></tr>';
  119. }
  120. print '</table>';
  121. print '<br>';
  122. print '<div align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
  123. print '</form>';
  124. // End of page
  125. llxFooter();
  126. $db->close();