mailing.php 7.5 KB

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