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
20/**
21 *	    \file       htdocs/admin/mailing.php
22 *		\ingroup    mailing
23 *		\brief      Page to setup emailing module
24 */
25
26require '../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28require_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
33if (!$user->admin) accessforbidden();
34
35$action = GETPOST('action', 'aZ09');
36
37
38
39/*
40 * Actions
41 */
42
43if ($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
81llxHeader('', $langs->trans("MailingSetup"));
82
83$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
84print load_fiche_titre($langs->trans("MailingSetup"), $linkback, 'title_setup');
85
86if (!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
103print '<br>';
104print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
105print '<input type="hidden" name="token" value="'.newToken().'">';
106print '<input type="hidden" name="action" value="setvalue">';
107
108print '<table class="noborder centpercent">';
109print '<tr class="liste_titre">';
110print '<td>'.$langs->trans("Parameter").'</td>';
111print '<td>'.$langs->trans("Value").'</td>';
112print "</tr>\n";
113
114print '<tr class="oddeven"><td>';
115print $langs->trans("MailingEMailFrom").'</td><td>';
116print '<input size="32" type="text" name="MAILING_EMAIL_FROM" value="'.$conf->global->MAILING_EMAIL_FROM.'">';
117if (!empty($conf->global->MAILING_EMAIL_FROM) && !isValidEmail($conf->global->MAILING_EMAIL_FROM)) print ' '.img_warning($langs->trans("BadEMail"));
118print '</td></tr>';
119
120print '<tr class="oddeven"><td>';
121print $langs->trans("MailingEMailError").'</td><td>';
122print '<input size="32" type="text" name="MAILING_EMAIL_ERRORSTO" value="'.$conf->global->MAILING_EMAIL_ERRORSTO.'">';
123if (!empty($conf->global->MAILING_EMAIL_ERRORSTO) && !isValidEmail($conf->global->MAILING_EMAIL_ERRORSTO)) print ' '.img_warning($langs->trans("BadEMail"));
124print '</td></tr>';
125
126print '<tr class="oddeven"><td>';
127print $langs->trans("MailingDelay").'</td><td>';
128print '<input class="width75" type="text" name="MAILING_DELAY" value="'.$conf->global->MAILING_DELAY.'">';
129print '</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
135print '<tr class="oddeven"><td>';
136print $langs->trans("ActivateCheckReadKey").'</td><td>';
137print '<input size="32" type="text" name="MAILING_EMAIL_UNSUBSCRIBE_KEY" id="MAILING_EMAIL_UNSUBSCRIBE_KEY" value="'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY.'">';
138if (!empty($conf->use_javascript_ajax)) print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
139print '</td></tr>';
140
141if (!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
148print '</table>';
149
150print '<br>';
151print '<div align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
152
153print '</form>';
154
155// End of page
156llxFooter();
157$db->close();
158