dolibarr  17.0.4
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  *
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 
26 // Load Dolibarr environment
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("admin", "mails"));
33 
34 if (!$user->admin) {
36 }
37 
38 $action = GETPOST('action', 'aZ09');
39 
40 $form = new Form($db);
41 
42 
43 /*
44  * Actions
45  */
46 
47 if ($action == 'setvalue') {
48  $db->begin();
49 
50  $mailfrom = GETPOST('MAILING_EMAIL_FROM', 'alpha');
51  $mailerror = GETPOST('MAILING_EMAIL_ERRORSTO', 'alpha');
52  $checkread = GETPOST('value', 'alpha');
53  $checkread_key = GETPOST('MAILING_EMAIL_UNSUBSCRIBE_KEY', 'alpha');
54  $contactbulkdefault = GETPOST('MAILING_CONTACT_DEFAULT_BULK_STATUS', 'int');
55  if (GETPOST('MAILING_DELAY', 'alpha') != '') {
56  $mailingdelay = price2num(GETPOST('MAILING_DELAY', 'alpha'), 3); // Not less than 1 millisecond.
57  } else {
58  $mailingdelay = '';
59  }
60  // Clean data
61  if ((float) $mailingdelay > 10) {
62  $mailingdelay = 10;
63  }
64  if (GETPOST('MAILING_DELAY', 'alpha') != '' && GETPOST('MAILING_DELAY', 'alpha') != '0' && (float) $mailingdelay < 0.001) {
65  $mailingdelay = 0.001;
66  }
67 
68  $res = dolibarr_set_const($db, "MAILING_EMAIL_FROM", $mailfrom, 'chaine', 0, '', $conf->entity);
69  if (!($res > 0)) {
70  $error++;
71  }
72  $res = dolibarr_set_const($db, "MAILING_EMAIL_ERRORSTO", $mailerror, 'chaine', 0, '', $conf->entity);
73  if (!($res > 0)) {
74  $error++;
75  }
76  $res = dolibarr_set_const($db, "MAILING_DELAY", $mailingdelay, 'chaine', 0, '', $conf->entity);
77  if (!($res > 0)) {
78  $error++;
79  }
80  $res = dolibarr_set_const($db, "MAILING_CONTACT_DEFAULT_BULK_STATUS", $contactbulkdefault, 'chaine', 0, '', $conf->entity);
81  if (!($res > 0)) {
82  $error++;
83  }
84 
85  // Create temporary encryption key if nedded
86  $res = dolibarr_set_const($db, "MAILING_EMAIL_UNSUBSCRIBE_KEY", $checkread_key, 'chaine', 0, '', $conf->entity);
87  if (!($res > 0)) {
88  $error++;
89  }
90 
91 
92  if (!$error) {
93  $db->commit();
94  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
95  } else {
96  $db->rollback();
97  setEventMessages($langs->trans("Error"), null, 'errors');
98  }
99 }
100 if ($action == 'setonsearchandlistgooncustomerorsuppliercard') {
101  $setonsearchandlistgooncustomerorsuppliercard = GETPOST('value', 'int');
102  $res = dolibarr_set_const($db, "SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD", $setonsearchandlistgooncustomerorsuppliercard, 'yesno', 0, '', $conf->entity);
103  if (!($res > 0)) {
104  $error++;
105  }
106  if (!$error) {
107  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
108  } else {
109  setEventMessages($langs->trans("Error"), null, 'errors');
110  }
111 }
112 
113 /*
114  * View
115  */
116 
117 llxHeader('', $langs->trans("MailingSetup"));
118 
119 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
120 print load_fiche_titre($langs->trans("MailingSetup"), $linkback, 'title_setup');
121 
122 $constname = 'MAILING_EMAIL_UNSUBSCRIBE_KEY';
123 
124 // Add button to autosuggest a key
125 include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
126 print dolJSToSetRandomPassword($constname);
127 
128 print '<br>';
129 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
130 print '<input type="hidden" name="token" value="'.newToken().'">';
131 print '<input type="hidden" name="action" value="setvalue">';
132 
133 print '<table class="noborder centpercent">';
134 print '<tr class="liste_titre">';
135 print '<td>'.$langs->trans("Parameter").'</td>';
136 print '<td>'.$langs->trans("Value").'</td>';
137 print '<td class="hideonsmartphone">'.$langs->trans("Example").'</td>';
138 print "</tr>\n";
139 
140 print '<tr class="oddeven"><td>';
141 $help = img_help(1, $langs->trans("EMailHelpMsgSPFDKIM"));
142 print $langs->trans("MailingEMailFrom").' '.$help.'</td><td>';
143 print '<input class="minwidth100" type="text" name="MAILING_EMAIL_FROM" value="'.$conf->global->MAILING_EMAIL_FROM.'">';
144 if (!empty($conf->global->MAILING_EMAIL_FROM) && !isValidEmail($conf->global->MAILING_EMAIL_FROM)) {
145  print ' '.img_warning($langs->trans("BadEMail"));
146 }
147 print '</td>';
148 print '<td class="hideonsmartphone"><span class="opacitymedium">'.dol_escape_htmltag(($mysoc->name ? $mysoc->name : 'MyName').' <noreply@example.com>').'</span></td>';
149 print '</tr>';
150 
151 print '<tr class="oddeven"><td>';
152 print $langs->trans("MailingEMailError").'</td><td>';
153 print '<input class="minwidth100" type="text" name="MAILING_EMAIL_ERRORSTO" value="'.getDolGlobalString('MAILING_EMAIL_ERRORSTO').'">';
154 if (getDolGlobalString('MAILING_EMAIL_ERRORSTO') && !isValidEmail(getDolGlobalString('MAILING_EMAIL_ERRORSTO'))) {
155  print ' '.img_warning($langs->trans("BadEMail"));
156 }
157 print '</td>';
158 print '<td class="hideonsmartphone"><span class="opacitymedium">webmaster@example.com></span></td>';
159 print '</tr>';
160 
161 print '<tr class="oddeven"><td>';
162 print $form->textwithpicto($langs->trans("MailingDelay"), $langs->trans("IfDefinedUseAValueBeetween", '0.001', '10')).'</td><td>';
163 print '<input class="width75" type="text" name="MAILING_DELAY" value="'.getDolGlobalString('MAILING_DELAY').'">';
164 print '</td>';
165 print '<td class="hideonsmartphone"></td>';
166 print '</tr>';
167 
168 
169 // Constant to add salt into the unsubscribe and check read tag.
170 // It is also used as a security key parameter.
171 
172 print '<tr class="oddeven"><td>';
173 print $langs->trans("ActivateCheckReadKey").'</td><td>';
174 print '<input class="minwidth100 maxwdith250 widthcentpercentminusx" type="text" name="MAILING_EMAIL_UNSUBSCRIBE_KEY" id="MAILING_EMAIL_UNSUBSCRIBE_KEY" value="'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY.'">';
175 if (!empty($conf->use_javascript_ajax)) {
176  print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
177 }
178 print '</td>';
179 print '<td class="hideonsmartphone"></td>';
180 print '</tr>';
181 
182 // default blacklist from mailing
183 print '<tr class="oddeven">';
184 print '<td>' . $langs->trans("DefaultBlacklistMailingStatus", $langs->transnoentitiesnoconv("No_Email")) . '</td>';
185 print '<td>';
186 $blacklist_setting=array(0=>$langs->trans('No'), 1=>$langs->trans('Yes'), 2=>$langs->trans('DefaultStatusEmptyMandatory'));
187 print $form->selectarray("MAILING_CONTACT_DEFAULT_BULK_STATUS", $blacklist_setting, $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS);
188 print '</td>';
189 print '<td class="hideonsmartphone"></td>';
190 print '</tr>';
191 
192 
193 if (!empty($conf->use_javascript_ajax) && $conf->global->MAIN_FEATURES_LEVEL >= 1) {
194  print '<tr class="oddeven"><td>';
195  print $langs->trans("MailAdvTargetRecipients").'</td><td>';
196  print ajax_constantonoff('EMAILING_USE_ADVANCED_SELECTOR');
197  print '</td>';
198  print '<td class="hideonsmartphone"></td>';
199  print '</tr>';
200 }
201 
202 print '</table>';
203 
204 print $form->buttonsSaveCancel("Modify", '');
205 
206 print '</form>';
207 
208 // End of page
209 llxFooter();
210 $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).
Definition: admin.lib.php:632
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='')
On/off button for constant.
Definition: ajax.lib.php:600
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage generation of HTML components Only common components must be here.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token', $generic=1)
Ouput javacript 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.