dolibarr 24.0.0-beta
mailing.php
Go to the documentation of this file.
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2025 Benjamin Falière <benjamin@faliere.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
31require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php';
32
42// Load translation files required by the page
43$langs->loadLangs(array("admin", "mails"));
44
45if (!$user->admin) {
47}
48
49$action = GETPOST('action', 'aZ09');
50
51$form = new Form($db);
52
53
54/*
55 * Actions
56 */
57$error = 0;
58
59if ($action == 'setvalue') {
60 $db->begin();
61
62 $mailfrom = GETPOST('MAILING_EMAIL_FROM', 'alpha');
63 $mailerror = GETPOST('MAILING_EMAIL_ERRORSTO', 'alpha');
64 $checkread = GETPOST('value', 'alpha');
65 $checkread_key = GETPOST('MAILING_EMAIL_UNSUBSCRIBE_KEY', 'alpha');
66 $contactbulkdefault = GETPOSTINT('MAILING_CONTACT_DEFAULT_BULK_STATUS');
67 $batchlimit = GETPOSTINT('MAILING_LIMIT_SENDBYWEB');
68
69 if (GETPOST('MAILING_DELAY', 'alpha') != '') {
70 $mailingdelay = price2num(GETPOST('MAILING_DELAY', 'alpha'), 3); // Not less than 1 millisecond.
71 } else {
72 $mailingdelay = '';
73 }
74
75 // Clean data
76 if ((float) $mailingdelay > 10) {
77 $mailingdelay = 10;
78 }
79 if (GETPOST('MAILING_DELAY', 'alpha') != '' && GETPOST('MAILING_DELAY', 'alpha') != '0' && (float) $mailingdelay < 0.001) {
80 $mailingdelay = 0.001;
81 }
82
83 $res = dolibarr_set_const($db, "MAILING_EMAIL_FROM", $mailfrom, 'chaine', 0, '', $conf->entity);
84 if (!($res > 0)) {
85 $error++;
86 }
87 $res = dolibarr_set_const($db, "MAILING_EMAIL_ERRORSTO", $mailerror, 'chaine', 0, '', $conf->entity);
88 if (!($res > 0)) {
89 $error++;
90 }
91 $res = dolibarr_set_const($db, "MAILING_DELAY", $mailingdelay, 'chaine', 0, '', $conf->entity);
92 if (!($res > 0)) {
93 $error++;
94 }
95 $res = dolibarr_set_const($db, "MAILING_CONTACT_DEFAULT_BULK_STATUS", $contactbulkdefault, 'chaine', 0, '', $conf->entity);
96 if (!($res > 0)) {
97 $error++;
98 }
99 $res = dolibarr_set_const($db, "MAILING_LIMIT_SENDBYWEB", $batchlimit, 'chaine', 1, '', 0);
100 if (!($res > 0)) {
101 $error++;
102 }
103
104 // Create temporary encryption key if needed
105 $res = dolibarr_set_const($db, "MAILING_EMAIL_UNSUBSCRIBE_KEY", $checkread_key, 'chaine', 0, '', $conf->entity);
106 if (!($res > 0)) {
107 $error++;
108 }
109
110
111 if (!$error) {
112 $db->commit();
113 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
114 } else {
115 $db->rollback();
116 setEventMessages($langs->trans("Error"), null, 'errors');
117 }
118}
119if ($action == 'setonsearchandlistgooncustomerorsuppliercard') {
120 $setonsearchandlistgooncustomerorsuppliercard = GETPOSTINT('value');
121 $res = dolibarr_set_const($db, "SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD", $setonsearchandlistgooncustomerorsuppliercard, 'yesno', 0, '', $conf->entity);
122 if (!($res > 0)) {
123 $error++;
124 }
125 if (!$error) {
126 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
127 } else {
128 setEventMessages($langs->trans("Error"), null, 'errors');
129 }
130}
131
132/*
133 * View
134 */
135
136llxHeader('', $langs->trans("MailingSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-mailing');
137
138$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
139
140print load_fiche_titre($langs->trans("MailingSetup"), $linkback, 'title_setup');
141
142$constname = 'MAILING_EMAIL_UNSUBSCRIBE_KEY';
143
144// Add button to autosuggest a key
145include_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php';
146print dolJSToSetRandomPassword($constname);
147
148print '<br>';
149print '<form method="post" action="' . $_SERVER["PHP_SELF"] . '">';
150print '<input type="hidden" name="token" value="' . newToken() . '">';
151print '<input type="hidden" name="action" value="setvalue">';
152
153print '<table class="noborder centpercent">';
154print '<tr class="liste_titre">';
155print '<td>'.$langs->trans("Parameter").'</td>';
156print '<td></td>';
157print '<td class="hideonsmartphone">'.$langs->trans("Example").'</td>';
158
159print "</tr>\n";
160
161print '<tr class="oddeven"><td>';
162$help = img_help(1, $langs->trans("EMailHelpMsgSPFDKIM"));
163print $langs->trans("MailingEMailFrom") . ' ' . $help . '</td><td>';
164print '<input class="minwidth100" type="text" name="MAILING_EMAIL_FROM" value="' . getDolGlobalString('MAILING_EMAIL_FROM') . '">';
165if (getDolGlobalString('MAILING_EMAIL_FROM') && !isValidEmail(getDolGlobalString('MAILING_EMAIL_FROM'))) {
166 print ' ' . img_warning($langs->trans("BadEMail"));
167}
168print '</td>';
169print '<td class="hideonsmartphone"><span class="opacitymedium">' . dol_escape_htmltag(($mysoc->name ? $mysoc->name : 'MyName') . ' <noreply@example.com>') . '</span></td>';
170print '</tr>';
171
172print '<tr class="oddeven"><td>';
173print $langs->trans("MailingEMailError") . '</td><td>';
174print '<input class="minwidth100" type="text" name="MAILING_EMAIL_ERRORSTO" value="' . getDolGlobalString('MAILING_EMAIL_ERRORSTO') . '">';
175if (getDolGlobalString('MAILING_EMAIL_ERRORSTO') && !isValidEmail(getDolGlobalString('MAILING_EMAIL_ERRORSTO'))) {
176 print ' ' . img_warning($langs->trans("BadEMail"));
177}
178print '</td>';
179print '<td class="hideonsmartphone"><span class="opacitymedium">' . dol_escape_htmltag('<webmaster@example.com>') . '</span></td>';
180print '</tr>';
181
182print '<tr class="oddeven"><td>';
183print $form->textwithpicto($langs->trans("MailingDelay"), $langs->trans("IfDefinedUseAValueBeetween", '0.001', '10')) . '</td><td>';
184print '<input class="width75" type="text" name="MAILING_DELAY" value="' . getDolGlobalString('MAILING_DELAY') . '">';
185print '</td>';
186print '<td class="hideonsmartphone"></td>';
187print '</tr>';
188
189
190// Constant to add salt into the unsubscribe and check read tag.
191// It is also used as a security key parameter.
192
193print '<tr class="oddeven"><td>';
194print $langs->trans("ActivateCheckReadKey") . '</td><td>';
195print '<input class="minwidth100 maxwdith250 widthcentpercentminusx" type="text" name="MAILING_EMAIL_UNSUBSCRIBE_KEY" id="MAILING_EMAIL_UNSUBSCRIBE_KEY" value="' . getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY') . '">';
196if (!empty($conf->use_javascript_ajax)) {
197 print '&nbsp;' . img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
198}
199print '</td>';
200print '<td class="hideonsmartphone"></td>';
201print '</tr>';
202
203// default blacklist from mailing
204print '<tr class="oddeven">';
205print '<td>' . $langs->trans("DefaultBlacklistMailingStatus", $langs->transnoentitiesnoconv("No_Email")) . '</td>';
206print '<td>';
207$blacklist_setting = array(0 => $langs->trans('No'), 1 => $langs->trans('Yes'), 2 => $langs->trans('DefaultStatusEmptyMandatory'));
208print $form->selectarray("MAILING_CONTACT_DEFAULT_BULK_STATUS", $blacklist_setting, getDolGlobalString('MAILING_CONTACT_DEFAULT_BULK_STATUS'));
209print '</td>';
210print '<td class="hideonsmartphone"></td>';
211print '</tr>';
212
213// Limit number for each mailing batch, displayed only if this value is not defined in the conf.php file
214print '<tr class="oddeven">';
215$help = img_help(1, $langs->trans("MailingNumberOfEmailsPerBatchHelp"));
216print '<td>' . $langs->trans("MailingNumberOfEmailsPerBatch") . ' ' . $help . '</td>';
217print '<td>';
218if (empty($conf->file->mailing_limit_sendbyweb)) {
219 print '<input class="width75 right" type="number" name="MAILING_LIMIT_SENDBYWEB" id="MAILING_LIMIT_SENDBYWEB" value="' . getDolGlobalString('MAILING_LIMIT_SENDBYWEB') . '">';
220} else {
221 print $conf->file->mailing_limit_sendbyweb;
222}
223print '</td>';
224print '<td class="hideonsmartphone"></td>';
225print '</tr>';
226
227print '</table>';
228
229print $form->buttonsSaveCancel("Modify", '');
230
231print '</form>';
232
233// End of page
234llxFooter();
235$db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token', $generic=1)
Output javascript to autoset a generated password using default module into a HTML element.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.