dolibarr 21.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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
31
41// Load translation files required by the page
42$langs->loadLangs(array("admin", "mails"));
43
44if (!$user->admin) {
46}
47
48$action = GETPOST('action', 'aZ09');
49
50$form = new Form($db);
51
52
53/*
54 * Actions
55 */
56$error = 0;
57
58if ($action == 'setvalue') {
59 $db->begin();
60
61 $mailfrom = GETPOST('MAILING_EMAIL_FROM', 'alpha');
62 $mailerror = GETPOST('MAILING_EMAIL_ERRORSTO', 'alpha');
63 $checkread = GETPOST('value', 'alpha');
64 $checkread_key = GETPOST('MAILING_EMAIL_UNSUBSCRIBE_KEY', 'alpha');
65 $contactbulkdefault = GETPOSTINT('MAILING_CONTACT_DEFAULT_BULK_STATUS');
66 if (GETPOST('MAILING_DELAY', 'alpha') != '') {
67 $mailingdelay = price2num(GETPOST('MAILING_DELAY', 'alpha'), 3); // Not less than 1 millisecond.
68 } else {
69 $mailingdelay = '';
70 }
71 // Clean data
72 if ((float) $mailingdelay > 10) {
73 $mailingdelay = 10;
74 }
75 if (GETPOST('MAILING_DELAY', 'alpha') != '' && GETPOST('MAILING_DELAY', 'alpha') != '0' && (float) $mailingdelay < 0.001) {
76 $mailingdelay = 0.001;
77 }
78
79 $res = dolibarr_set_const($db, "MAILING_EMAIL_FROM", $mailfrom, 'chaine', 0, '', $conf->entity);
80 if (!($res > 0)) {
81 $error++;
82 }
83 $res = dolibarr_set_const($db, "MAILING_EMAIL_ERRORSTO", $mailerror, 'chaine', 0, '', $conf->entity);
84 if (!($res > 0)) {
85 $error++;
86 }
87 $res = dolibarr_set_const($db, "MAILING_DELAY", $mailingdelay, 'chaine', 0, '', $conf->entity);
88 if (!($res > 0)) {
89 $error++;
90 }
91 $res = dolibarr_set_const($db, "MAILING_CONTACT_DEFAULT_BULK_STATUS", $contactbulkdefault, 'chaine', 0, '', $conf->entity);
92 if (!($res > 0)) {
93 $error++;
94 }
95
96 // Create temporary encryption key if needed
97 $res = dolibarr_set_const($db, "MAILING_EMAIL_UNSUBSCRIBE_KEY", $checkread_key, 'chaine', 0, '', $conf->entity);
98 if (!($res > 0)) {
99 $error++;
100 }
101
102
103 if (!$error) {
104 $db->commit();
105 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
106 } else {
107 $db->rollback();
108 setEventMessages($langs->trans("Error"), null, 'errors');
109 }
110}
111if ($action == 'setonsearchandlistgooncustomerorsuppliercard') {
112 $setonsearchandlistgooncustomerorsuppliercard = GETPOSTINT('value');
113 $res = dolibarr_set_const($db, "SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD", $setonsearchandlistgooncustomerorsuppliercard, 'yesno', 0, '', $conf->entity);
114 if (!($res > 0)) {
115 $error++;
116 }
117 if (!$error) {
118 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
119 } else {
120 setEventMessages($langs->trans("Error"), null, 'errors');
121 }
122}
123
124/*
125 * View
126 */
127
128llxHeader('', $langs->trans("MailingSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-mailing');
129
130$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
131print load_fiche_titre($langs->trans("MailingSetup"), $linkback, 'title_setup');
132
133$constname = 'MAILING_EMAIL_UNSUBSCRIBE_KEY';
134
135// Add button to autosuggest a key
136include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
137print dolJSToSetRandomPassword($constname);
138
139print '<br>';
140print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
141print '<input type="hidden" name="token" value="'.newToken().'">';
142print '<input type="hidden" name="action" value="setvalue">';
143
144print '<table class="noborder centpercent">';
145print '<tr class="liste_titre">';
146print '<td>'.$langs->trans("Parameter").'</td>';
147print '<td>'.$langs->trans("Value").'</td>';
148print '<td class="hideonsmartphone">'.$langs->trans("Example").'</td>';
149print "</tr>\n";
150
151print '<tr class="oddeven"><td>';
152$help = img_help(1, $langs->trans("EMailHelpMsgSPFDKIM"));
153print $langs->trans("MailingEMailFrom").' '.$help.'</td><td>';
154print '<input class="minwidth100" type="text" name="MAILING_EMAIL_FROM" value="' . getDolGlobalString('MAILING_EMAIL_FROM').'">';
155if (getDolGlobalString('MAILING_EMAIL_FROM') && !isValidEmail($conf->global->MAILING_EMAIL_FROM)) {
156 print ' '.img_warning($langs->trans("BadEMail"));
157}
158print '</td>';
159print '<td class="hideonsmartphone"><span class="opacitymedium">'.dol_escape_htmltag(($mysoc->name ? $mysoc->name : 'MyName').' <noreply@example.com>').'</span></td>';
160print '</tr>';
161
162print '<tr class="oddeven"><td>';
163print $langs->trans("MailingEMailError").'</td><td>';
164print '<input class="minwidth100" type="text" name="MAILING_EMAIL_ERRORSTO" value="'.getDolGlobalString('MAILING_EMAIL_ERRORSTO').'">';
165if (getDolGlobalString('MAILING_EMAIL_ERRORSTO') && !isValidEmail(getDolGlobalString('MAILING_EMAIL_ERRORSTO'))) {
166 print ' '.img_warning($langs->trans("BadEMail"));
167}
168print '</td>';
169print '<td class="hideonsmartphone"><span class="opacitymedium">'.dol_escape_htmltag('<webmaster@example.com>').'</span></td>';
170print '</tr>';
171
172print '<tr class="oddeven"><td>';
173print $form->textwithpicto($langs->trans("MailingDelay"), $langs->trans("IfDefinedUseAValueBeetween", '0.001', '10')).'</td><td>';
174print '<input class="width75" type="text" name="MAILING_DELAY" value="'.getDolGlobalString('MAILING_DELAY').'">';
175print '</td>';
176print '<td class="hideonsmartphone"></td>';
177print '</tr>';
178
179
180// Constant to add salt into the unsubscribe and check read tag.
181// It is also used as a security key parameter.
182
183print '<tr class="oddeven"><td>';
184print $langs->trans("ActivateCheckReadKey").'</td><td>';
185print '<input class="minwidth100 maxwdith250 widthcentpercentminusx" type="text" name="MAILING_EMAIL_UNSUBSCRIBE_KEY" id="MAILING_EMAIL_UNSUBSCRIBE_KEY" value="'.getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY').'">';
186if (!empty($conf->use_javascript_ajax)) {
187 print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
188}
189print '</td>';
190print '<td class="hideonsmartphone"></td>';
191print '</tr>';
192
193// default blacklist from mailing
194print '<tr class="oddeven">';
195print '<td>' . $langs->trans("DefaultBlacklistMailingStatus", $langs->transnoentitiesnoconv("No_Email")) . '</td>';
196print '<td>';
197$blacklist_setting=array(0=>$langs->trans('No'), 1=>$langs->trans('Yes'), 2=>$langs->trans('DefaultStatusEmptyMandatory'));
198print $form->selectarray("MAILING_CONTACT_DEFAULT_BULK_STATUS", $blacklist_setting, getDolGlobalString('MAILING_CONTACT_DEFAULT_BULK_STATUS'));
199print '</td>';
200print '<td class="hideonsmartphone"></td>';
201print '</tr>';
202
203
204if (!empty($conf->use_javascript_ajax) && getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1) {
205 print '<tr class="oddeven"><td>';
206 print $langs->trans("MailAdvTargetRecipients").'</td><td>';
207 print ajax_constantonoff('EMAILING_USE_ADVANCED_SELECTOR');
208 print '</td>';
209 print '<td class="hideonsmartphone"></td>';
210 print '</tr>';
211}
212
213print '</table>';
214
215print $form->buttonsSaveCancel("Modify", '');
216
217print '</form>';
218
219// End of page
220llxFooter();
221$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).
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:71
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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 "?".
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 '.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.