dolibarr  13.0.2
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 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
29 
30 // Load translation files required by the page
31 $langs->loadLangs(array("admin", "mails"));
32 
33 if (!$user->admin) accessforbidden();
34 
35 $action = GETPOST('action', 'aZ09');
36 
37 
38 
39 /*
40  * Actions
41  */
42 
43 if ($action == 'setvalue')
44 {
45  $db->begin();
46 
47  $mailfrom = GETPOST('MAILING_EMAIL_FROM', 'alpha');
48  $mailerror = GETPOST('MAILING_EMAIL_ERRORSTO', 'alpha');
49  $checkread = GETPOST('value', 'alpha');
50  $checkread_key = GETPOST('MAILING_EMAIL_UNSUBSCRIBE_KEY', 'alpha');
51  $mailingdelay = GETPOST('MAILING_DELAY', 'int');
52 
53  $res = dolibarr_set_const($db, "MAILING_EMAIL_FROM", $mailfrom, 'chaine', 0, '', $conf->entity);
54  if (!($res > 0)) $error++;
55  $res = dolibarr_set_const($db, "MAILING_EMAIL_ERRORSTO", $mailerror, 'chaine', 0, '', $conf->entity);
56  if (!($res > 0)) $error++;
57  $res = dolibarr_set_const($db, "MAILING_DELAY", $mailingdelay, 'chaine', 0, '', $conf->entity);
58  if (!($res > 0)) $error++;
59  $res = dolibarr_set_const($db, "MAILING_CONTACT_DEFAULT_BULK_STATUS", $contactbulkdefault, 'chaine', 0, '', $conf->entity);
60  if (!($res > 0)) $error++;
61 
62  // Create temporary encryption key if nedded
63  $res = dolibarr_set_const($db, "MAILING_EMAIL_UNSUBSCRIBE_KEY", $checkread_key, 'chaine', 0, '', $conf->entity);
64  if (!($res > 0)) $error++;
65 
66  if (!$error)
67  {
68  $db->commit();
69  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
70  } else {
71  $db->rollback();
72  setEventMessages($langs->trans("Error"), null, 'errors');
73  }
74 }
75 
76 
77 /*
78  * View
79  */
80 
81 llxHeader('', $langs->trans("MailingSetup"));
82 
83 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
84 print load_fiche_titre($langs->trans("MailingSetup"), $linkback, 'title_setup');
85 
86 if (!empty($conf->use_javascript_ajax))
87 {
88  print "\n".'<script type="text/javascript">';
89  print '$(document).ready(function () {
90  $("#generate_token").click(function() {
91  $.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
92  action: \'getrandompassword\',
93  generic: true
94  },
95  function(token) {
96  $("#MAILING_EMAIL_UNSUBSCRIBE_KEY").val(token);
97  });
98  });
99  });';
100  print '</script>';
101 }
102 
103 print '<br>';
104 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
105 print '<input type="hidden" name="token" value="'.newToken().'">';
106 print '<input type="hidden" name="action" value="setvalue">';
107 
108 print '<table class="noborder centpercent">';
109 print '<tr class="liste_titre">';
110 print '<td>'.$langs->trans("Parameter").'</td>';
111 print '<td>'.$langs->trans("Value").'</td>';
112 print "</tr>\n";
113 
114 print '<tr class="oddeven"><td>';
115 print $langs->trans("MailingEMailFrom").'</td><td>';
116 print '<input size="32" type="text" name="MAILING_EMAIL_FROM" value="'.$conf->global->MAILING_EMAIL_FROM.'">';
117 if (!empty($conf->global->MAILING_EMAIL_FROM) && !isValidEmail($conf->global->MAILING_EMAIL_FROM)) print ' '.img_warning($langs->trans("BadEMail"));
118 print '</td></tr>';
119 
120 print '<tr class="oddeven"><td>';
121 print $langs->trans("MailingEMailError").'</td><td>';
122 print '<input size="32" type="text" name="MAILING_EMAIL_ERRORSTO" value="'.$conf->global->MAILING_EMAIL_ERRORSTO.'">';
123 if (!empty($conf->global->MAILING_EMAIL_ERRORSTO) && !isValidEmail($conf->global->MAILING_EMAIL_ERRORSTO)) print ' '.img_warning($langs->trans("BadEMail"));
124 print '</td></tr>';
125 
126 print '<tr class="oddeven"><td>';
127 print $langs->trans("MailingDelay").'</td><td>';
128 print '<input class="width75" type="text" name="MAILING_DELAY" value="'.$conf->global->MAILING_DELAY.'">';
129 print '</td></tr>';
130 
131 
132 // Constant to add salt into the unsubscribe and check read tag.
133 // It is also used as a security key parameter.
134 
135 print '<tr class="oddeven"><td>';
136 print $langs->trans("ActivateCheckReadKey").'</td><td>';
137 print '<input size="32" type="text" name="MAILING_EMAIL_UNSUBSCRIBE_KEY" id="MAILING_EMAIL_UNSUBSCRIBE_KEY" value="'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY.'">';
138 if (!empty($conf->use_javascript_ajax)) print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
139 print '</td></tr>';
140 
141 if (!empty($conf->use_javascript_ajax) && $conf->global->MAIN_FEATURES_LEVEL >= 1) {
142  print '<tr class="oddeven"><td>';
143  print $langs->trans("MailAdvTargetRecipients").'</td><td>';
144  print ajax_constantonoff('EMAILING_USE_ADVANCED_SELECTOR');
145  print '</td></tr>';
146 }
147 
148 print '</table>';
149 
150 print '<br>';
151 print '<div align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
152 
153 print '</form>';
154 
155 // End of page
156 llxFooter();
157 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:575
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0)
On/off button for constant.
Definition: ajax.lib.php:503
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print
Draft customers invoices.
Definition: index.php:89
llxFooter()
Empty footer.
Definition: wrapper.php:59
isValidEmail($address, $acceptsupervisorkey=0)
Return true if email syntax is ok.