mailing.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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) {
  30. accessforbidden();
  31. }
  32. $action = GETPOST('action', 'aZ09');
  33. $form = new Form($db);
  34. /*
  35. * Actions
  36. */
  37. if ($action == 'setvalue') {
  38. $db->begin();
  39. $mailfrom = GETPOST('MAILING_EMAIL_FROM', 'alpha');
  40. $mailerror = GETPOST('MAILING_EMAIL_ERRORSTO', 'alpha');
  41. $checkread = GETPOST('value', 'alpha');
  42. $checkread_key = GETPOST('MAILING_EMAIL_UNSUBSCRIBE_KEY', 'alpha');
  43. $mailingdelay = GETPOST('MAILING_DELAY', 'int');
  44. $contactbulkdefault = GETPOST('MAILING_CONTACT_DEFAULT_BULK_STATUS', 'int');
  45. $res = dolibarr_set_const($db, "MAILING_EMAIL_FROM", $mailfrom, 'chaine', 0, '', $conf->entity);
  46. if (!($res > 0)) {
  47. $error++;
  48. }
  49. $res = dolibarr_set_const($db, "MAILING_EMAIL_ERRORSTO", $mailerror, 'chaine', 0, '', $conf->entity);
  50. if (!($res > 0)) {
  51. $error++;
  52. }
  53. $res = dolibarr_set_const($db, "MAILING_DELAY", $mailingdelay, 'chaine', 0, '', $conf->entity);
  54. if (!($res > 0)) {
  55. $error++;
  56. }
  57. $res = dolibarr_set_const($db, "MAILING_CONTACT_DEFAULT_BULK_STATUS", $contactbulkdefault, 'chaine', 0, '', $conf->entity);
  58. if (!($res > 0)) {
  59. $error++;
  60. }
  61. // Create temporary encryption key if nedded
  62. $res = dolibarr_set_const($db, "MAILING_EMAIL_UNSUBSCRIBE_KEY", $checkread_key, 'chaine', 0, '', $conf->entity);
  63. if (!($res > 0)) {
  64. $error++;
  65. }
  66. if (!$error) {
  67. $db->commit();
  68. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  69. } else {
  70. $db->rollback();
  71. setEventMessages($langs->trans("Error"), null, 'errors');
  72. }
  73. }
  74. if ($action == 'setonsearchandlistgooncustomerorsuppliercard') {
  75. $setonsearchandlistgooncustomerorsuppliercard = GETPOST('value', 'int');
  76. $res = dolibarr_set_const($db, "SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD", $setonsearchandlistgooncustomerorsuppliercard, 'yesno', 0, '', $conf->entity);
  77. if (!($res > 0)) {
  78. $error++;
  79. }
  80. if (!$error) {
  81. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  82. } else {
  83. setEventMessages($langs->trans("Error"), null, 'errors');
  84. }
  85. }
  86. /*
  87. * View
  88. */
  89. llxHeader('', $langs->trans("MailingSetup"));
  90. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  91. print load_fiche_titre($langs->trans("MailingSetup"), $linkback, 'title_setup');
  92. if (!empty($conf->use_javascript_ajax)) {
  93. print "\n".'<script type="text/javascript">';
  94. print '$(document).ready(function () {
  95. $("#generate_token").click(function() {
  96. $.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
  97. action: \'getrandompassword\',
  98. generic: true
  99. },
  100. function(token) {
  101. $("#MAILING_EMAIL_UNSUBSCRIBE_KEY").val(token);
  102. });
  103. });
  104. });';
  105. print '</script>';
  106. }
  107. print '<br>';
  108. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  109. print '<input type="hidden" name="token" value="'.newToken().'">';
  110. print '<input type="hidden" name="action" value="setvalue">';
  111. print '<table class="noborder centpercent">';
  112. print '<tr class="liste_titre">';
  113. print '<td>'.$langs->trans("Parameter").'</td>';
  114. print '<td>'.$langs->trans("Value").'</td>';
  115. print '<td>'.$langs->trans("Example").'</td>';
  116. print "</tr>\n";
  117. print '<tr class="oddeven"><td>';
  118. $help = img_help(1, $langs->trans("EMailHelpMsgSPFDKIM"));
  119. print $langs->trans("MailingEMailFrom").' '.$help.'</td><td>';
  120. print '<input size="32" type="text" name="MAILING_EMAIL_FROM" value="'.$conf->global->MAILING_EMAIL_FROM.'">';
  121. if (!empty($conf->global->MAILING_EMAIL_FROM) && !isValidEmail($conf->global->MAILING_EMAIL_FROM)) {
  122. print ' '.img_warning($langs->trans("BadEMail"));
  123. }
  124. print '</td><td><span class="opacitymedium">'.dol_escape_htmltag(($mysoc->name ? $mysoc->name : 'MyName').' <noreply@example.com>').'</span></td>';
  125. print '</tr>';
  126. print '<tr class="oddeven"><td>';
  127. print $langs->trans("MailingEMailError").'</td><td>';
  128. print '<input size="32" type="text" name="MAILING_EMAIL_ERRORSTO" value="'.$conf->global->MAILING_EMAIL_ERRORSTO.'">';
  129. if (!empty($conf->global->MAILING_EMAIL_ERRORSTO) && !isValidEmail($conf->global->MAILING_EMAIL_ERRORSTO)) {
  130. print ' '.img_warning($langs->trans("BadEMail"));
  131. }
  132. print '</td><td><span class="opacitymedium">webmaster@example.com></span></td>';
  133. print '</tr>';
  134. print '<tr class="oddeven"><td>';
  135. print $langs->trans("MailingDelay").'</td><td>';
  136. print '<input class="width75" type="text" name="MAILING_DELAY" value="'.$conf->global->MAILING_DELAY.'">';
  137. print '</td><td></td>';
  138. print '</tr>';
  139. // Constant to add salt into the unsubscribe and check read tag.
  140. // It is also used as a security key parameter.
  141. print '<tr class="oddeven"><td>';
  142. print $langs->trans("ActivateCheckReadKey").'</td><td>';
  143. print '<input size="32" type="text" name="MAILING_EMAIL_UNSUBSCRIBE_KEY" id="MAILING_EMAIL_UNSUBSCRIBE_KEY" value="'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY.'">';
  144. if (!empty($conf->use_javascript_ajax)) {
  145. print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
  146. }
  147. print '</td><td></td>';
  148. print '</tr>';
  149. // default blacklist from mailing
  150. print '<tr class="oddeven">';
  151. print '<td>' . $langs->trans("DefaultBlacklistMailingStatus", $langs->transnoentitiesnoconv("No_Email")) . '</td>';
  152. print '<td>';
  153. $blacklist_setting=array(0=>$langs->trans('No'), 1=>$langs->trans('Yes'), 2=>$langs->trans('DefaultStatusEmptyMandatory'));
  154. print $form->selectarray("MAILING_CONTACT_DEFAULT_BULK_STATUS", $blacklist_setting, $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS);
  155. print '</td>';
  156. print '<td></td>';
  157. print '</tr>';
  158. if (!empty($conf->use_javascript_ajax) && $conf->global->MAIN_FEATURES_LEVEL >= 1) {
  159. print '<tr class="oddeven"><td>';
  160. print $langs->trans("MailAdvTargetRecipients").'</td><td>';
  161. print ajax_constantonoff('EMAILING_USE_ADVANCED_SELECTOR');
  162. print '</td><td></td>';
  163. print '</tr>';
  164. }
  165. print '</table>';
  166. print $form->buttonsSaveCancel("Modify", '');
  167. print '</form>';
  168. // End of page
  169. llxFooter();
  170. $db->close();