dolibarr  7.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  *
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 <http://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 $langs->load("admin");
31 $langs->load("mails");
32 
33 if (!$user->admin) accessforbidden();
34 
35 $action = GETPOST('action','alpha');
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 
60  // Create temporary encryption key if nedded
61  $res=dolibarr_set_const($db, "MAILING_EMAIL_UNSUBSCRIBE_KEY",$checkread_key,'chaine',0,'',$conf->entity);
62  if (! $res > 0) $error++;
63 
64  if (! $error)
65  {
66  $db->commit();
67  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
68  }
69  else
70  {
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">'.$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="'.$_SESSION['newtoken'].'">';
106 print '<input type="hidden" name="action" value="setvalue">';
107 
108 $var=true;
109 
110 print '<table class="noborder" width="100%">';
111 print '<tr class="liste_titre">';
112 print '<td>'.$langs->trans("Parameter").'</td>';
113 print '<td>'.$langs->trans("Value").'</td>';
114 print "</tr>\n";
115 
116 
117 print '<tr class="oddeven"><td>';
118 print $langs->trans("MailingEMailFrom").'</td><td>';
119 print '<input size="32" type="text" name="MAILING_EMAIL_FROM" value="'.$conf->global->MAILING_EMAIL_FROM.'">';
120 if (!empty($conf->global->MAILING_EMAIL_FROM) && ! isValidEmail($conf->global->MAILING_EMAIL_FROM)) print ' '.img_warning($langs->trans("BadEMail"));
121 print '</td></tr>';
122 
123 
124 print '<tr class="oddeven"><td>';
125 print $langs->trans("MailingEMailError").'</td><td>';
126 print '<input size="32" type="text" name="MAILING_EMAIL_ERRORSTO" value="'.$conf->global->MAILING_EMAIL_ERRORSTO.'">';
127 if (!empty($conf->global->MAILING_EMAIL_ERRORSTO) && ! isValidEmail($conf->global->MAILING_EMAIL_ERRORSTO)) print ' '.img_warning($langs->trans("BadEMail"));
128 print '</td></tr>';
129 
130 
131 print '<tr class="oddeven"><td>';
132 print $langs->trans("MailingDelay").'</td><td>';
133 print '<input size="32" type="text" name="MAILING_DELAY" value="'.$conf->global->MAILING_DELAY.'">';
134 print '</td></tr>';
135 
136 // Constant to add salt into the unsubscribe and check read tag.
137 // It is also used as a security key parameter.
138 
139 print '<tr class="oddeven"><td>';
140 print $langs->trans("ActivateCheckReadKey").'</td><td>';
141 print '<input size="32" type="text" name="MAILING_EMAIL_UNSUBSCRIBE_KEY" id="MAILING_EMAIL_UNSUBSCRIBE_KEY" value="'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY.'">';
142 if (! empty($conf->use_javascript_ajax)) print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
143 print '</td></tr>';
144 
145 print '</table>';
146 
147 print '<br>';
148 print '<div align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
149 
150 print '</form>';
151 
152 llxFooter();
153 
154 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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:485
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
print
Draft customers invoices.
Definition: index.php:91
isValidEmail($address, $acceptsupervisorkey=0)
Return true if email syntax is ok.