dolibarr 18.0.6
mails_ticket.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2016 Jonathan TISSEAU <jonathan.tisseau@86dev.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
26// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
30
31// Load translation files required by the page
32$langs->loadLangs(array('companies', 'products', 'admin', 'mails', 'other', 'errors'));
33
34$action = GETPOST('action', 'aZ09');
35$cancel = GETPOST('cancel', 'aZ09');
36
37$usersignature = $user->signature;
38// For action = test or send, we ensure that content is not html, even for signature, because this we want a test with NO html.
39if ($action == 'test' || $action == 'send') {
40 $usersignature = dol_string_nohtmltag($usersignature, 2);
41}
42
43$substitutionarrayfortest = array(
44 '__DOL_MAIN_URL_ROOT__'=>DOL_MAIN_URL_ROOT,
45 '__ID__' => 'TESTIdRecord',
46 '__EMAIL__' => 'TESTEMail',
47 '__LOGIN__' => $user->login,
48 '__LASTNAME__' => 'TESTLastname',
49 '__FIRSTNAME__' => 'TESTFirstname',
50 '__ADDRESS__'=> 'RecipientAddress',
51 '__ZIP__'=> 'RecipientZip',
52 '__TOWN_'=> 'RecipientTown',
53 '__COUNTRY__'=> 'RecipientCountry',
54 '__USER_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $usersignature : ''),
55 '__SENDEREMAIL_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $usersignature : ''), // Done into actions_sendmails
56 //'__PERSONALIZED__' => 'TESTPersonalized' // Hiden because not used yet
57);
58complete_substitutions_array($substitutionarrayfortest, $langs);
59
60// Security check
61if (!$user->admin) {
63}
64
65
66/*
67 * Actions
68 */
69
70if ($action == 'update' && !$cancel) {
71 // Send mode parameters
72 dolibarr_set_const($db, "MAIN_MAIL_SENDMODE_TICKET", GETPOST("MAIN_MAIL_SENDMODE_TICKET"), 'chaine', 0, '', $conf->entity);
73 dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT_TICKET", GETPOST("MAIN_MAIL_SMTP_PORT_TICKET"), 'chaine', 0, '', $conf->entity);
74 dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER_TICKET", GETPOST("MAIN_MAIL_SMTP_SERVER_TICKET"), 'chaine', 0, '', $conf->entity);
75 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID_TICKET", GETPOST("MAIN_MAIL_SMTPS_ID_TICKET"), 'chaine', 0, '', $conf->entity);
76 if (GETPOSTISSET("MAIN_MAIL_SMTPS_PW_TICKET")) {
77 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW_TICKET", GETPOST("MAIN_MAIL_SMTPS_PW_TICKET", 'none'), 'chaine', 0, '', $conf->entity);
78 }
79 if (GETPOSTISSET("MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET")) {
80 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET", GETPOST("MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET", 'chaine'), 'chaine', 0, '', $conf->entity);
81 }
82 if (GETPOSTISSET("MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET")) {
83 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET", GETPOST("MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET", 'chaine'), 'chaine', 0, '', $conf->entity);
84 }dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS_TICKET", GETPOST("MAIN_MAIL_EMAIL_TLS_TICKET"), 'chaine', 0, '', $conf->entity);
85 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS_TICKET", GETPOST("MAIN_MAIL_EMAIL_STARTTLS_TICKET"), 'chaine', 0, '', $conf->entity);
86
87 header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
88 exit;
89}
90
91
92// Actions to send emails
93$id = 0;
94$actiontypecode = ''; // Not an event for agenda
95$triggersendname = ''; // Disable triggers
96$paramname = 'id';
97$mode = 'emailfortest';
98$trackid = (($action == 'testhtml') ? "testhtml" : "test");
99$sendcontext = 'ticket'; // Force to use dedicated context of setup for ticket
100include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
101
102if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'test') {
103 $action = 'test';
104}
105if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'testhtml') {
106 $action = 'testhtml';
107}
108
109
110
111
112/*
113 * View
114 */
115
116$form = new Form($db);
117
118$linuxlike = 1;
119if (preg_match('/^win/i', PHP_OS)) {
120 $linuxlike = 0;
121}
122if (preg_match('/^mac/i', PHP_OS)) {
123 $linuxlike = 0;
124}
125
126if (empty($conf->global->MAIN_MAIL_SENDMODE_TICKET)) {
127 $conf->global->MAIN_MAIL_SENDMODE_TICKET = 'default';
128}
129$port = !empty($conf->global->MAIN_MAIL_SMTP_PORT_TICKET) ? $conf->global->MAIN_MAIL_SMTP_PORT_TICKET : ini_get('smtp_port');
130if (!$port) {
131 $port = 25;
132}
133$server = !empty($conf->global->MAIN_MAIL_SMTP_SERVER_TICKET) ? $conf->global->MAIN_MAIL_SMTP_SERVER_TICKET : ini_get('SMTP');
134if (!$server) {
135 $server = '127.0.0.1';
136}
137
138
139$wikihelp = 'EN:Setup_EMails|FR:Paramétrage_EMails|ES:Configuración_EMails';
140llxHeader('', $langs->trans("Setup"), $wikihelp);
141
142print load_fiche_titre($langs->trans("EMailsSetup"), '', 'title_setup');
143
145
146// List of sending methods
147$listofmethods = array();
148$listofmethods['default'] = $langs->trans('DefaultOutgoingEmailSetup');
149$listofmethods['mail'] = 'PHP mail function';
150//$listofmethods['simplemail']='Simplemail class';
151$listofmethods['smtps'] = 'SMTP/SMTPS socket library';
152if (version_compare(phpversion(), '7.0', '>=')) {
153 $listofmethods['swiftmailer'] = 'Swift Mailer socket library';
154}
155
156// List of oauth services
157$oauthservices = array();
158
159foreach ($conf->global as $key => $val) {
160 if (!empty($val) && preg_match('/^OAUTH_.*_ID$/', $key)) {
161 $key = preg_replace('/^OAUTH_/', '', $key);
162 $key = preg_replace('/_ID$/', '', $key);
163 if (preg_match('/^.*-/', $key)) {
164 $name = preg_replace('/^.*-/', '', $key);
165 } else {
166 $name = $langs->trans("NoName");
167 }
168 $provider = preg_replace('/-.*$/', '', $key);
169 $provider = ucfirst(strtolower($provider));
170
171 $oauthservices[$key] = $name." (".$provider.")";
172 }
173}
174
175
176if ($action == 'edit') {
177 if ($conf->use_javascript_ajax) {
178 print "\n".'<script type="text/javascript">';
179 print 'jQuery(document).ready(function () {
180 function initfields()
181 {
182 if (jQuery("#MAIN_MAIL_SENDMODE_TICKET").val()==\'default\')
183 {
184 jQuery(".hideifdefault").hide();
185 }
186 else
187 {
188 jQuery(".hideifdefault").show();
189 }
190
191 if (jQuery("#MAIN_MAIL_SENDMODE_TICKET").val()==\'mail\')
192 {
193 jQuery(".drag").hide();
194 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").val(0);
195 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").prop("disabled", true);
196 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").val(0);
197 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").prop("disabled", true);
198 jQuery(".smtp_method").hide();
199 jQuery(".smtp_auth_method").hide();
200 ';
201 if ($linuxlike) {
202 print '
203 jQuery("#MAIN_MAIL_SMTP_SERVER_TICKET").hide();
204 jQuery("#MAIN_MAIL_SMTP_PORT_TICKET").hide();
205 jQuery("#smtp_server_mess").show();
206 jQuery("#smtp_port_mess").show();
207 ';
208 } else {
209 print '
210 jQuery("#MAIN_MAIL_SMTP_SERVER_TICKET").prop("disabled", true);
211 jQuery("#MAIN_MAIL_SMTP_PORT_TICKET").prop("disabled", true);
212 jQuery("#smtp_server_mess").hide();
213 jQuery("#smtp_port_mess").hide();
214 ';
215 }
216 print '
217 }
218 if (jQuery("#MAIN_MAIL_SENDMODE_TICKET").val()==\'smtps\')
219 {
220 jQuery(".drag").show();
221 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").val('.$conf->global->MAIN_MAIL_EMAIL_TLS_TICKET.');
222 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").removeAttr("disabled");
223 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_TICKET.');
224 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").removeAttr("disabled");
225 jQuery("#MAIN_MAIL_SMTP_SERVER_TICKET").removeAttr("disabled");
226 jQuery("#MAIN_MAIL_SMTP_PORT_TICKET").removeAttr("disabled");
227 jQuery("#MAIN_MAIL_SMTP_SERVER_TICKET").show();
228 jQuery("#MAIN_MAIL_SMTP_PORT_TICKET").show();
229 jQuery("#smtp_server_mess").hide();
230 jQuery("#smtp_port_mess").hide();
231 jQuery(".smtp_method").show();
232 jQuery(".smtp_auth_method").show();
233 }
234 if (jQuery("#MAIN_MAIL_SENDMODE_TICKET").val()==\'swiftmailer\')
235 {
236 jQuery(".drag").show();
237 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").val('.$conf->global->MAIN_MAIL_EMAIL_TLS_TICKET.');
238 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").removeAttr("disabled");
239 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_TICKET.');
240 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").removeAttr("disabled");
241 jQuery("#MAIN_MAIL_SMTP_SERVER_TICKET").removeAttr("disabled");
242 jQuery("#MAIN_MAIL_SMTP_PORT_TICKET").removeAttr("disabled");
243 jQuery("#MAIN_MAIL_SMTP_SERVER_TICKET").show();
244 jQuery("#MAIN_MAIL_SMTP_PORT_TICKET").show();
245 jQuery("#smtp_server_mess").hide();
246 jQuery("#smtp_port_mess").hide();
247 jQuery(".smtp_method").show();
248 jQuery(".smtp_auth_method").show();
249 }
250 }
251 function change_smtp_auth_method() {
252 console.log(jQuery("#radio_pw").prop("checked"));
253 if (jQuery("#MAIN_MAIL_SENDMODE_TICKET").val()==\'smtps\' && jQuery("#radio_oauth").prop("checked")) {
254 jQuery(".smtp_oauth_service").show();
255 jQuery(".smtp_pw").hide();
256 } else if (jQuery("#MAIN_MAIL_SENDMODE_TICKET").val()==\'swiftmailer\' && jQuery("#radio_oauth").prop("checked")) {
257 jQuery(".smtp_oauth_service").show();
258 jQuery(".smtp_pw").hide();
259 } else if(jQuery("#MAIN_MAIL_SENDMODE_TICKET").val()==\'mail\' || jQuery("#MAIN_MAIL_SENDMODE_TICKET").val()==\'default\'){
260 jQuery(".smtp_oauth_service").hide();
261 jQuery(".smtp_pw").hide();
262 } else {
263 jQuery(".smtp_oauth_service").hide();
264 jQuery(".smtp_pw").show();
265 }
266 }
267 initfields();
268 change_smtp_auth_method();
269
270 jQuery("#MAIN_MAIL_SENDMODE_TICKET").change(function() {
271 initfields();
272 change_smtp_auth_method();
273
274 });
275 jQuery("#radio_pw, #radio_oauth").change(function() {
276 change_smtp_auth_method();
277 });
278 jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
279 if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").val() == 1)
280 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").val(0);
281 });
282 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").change(function() {
283 if (jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").val() == 1)
284 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").val(0);
285 });
286 })';
287 print '</script>'."\n";
288 }
289
290 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
291 print '<input type="hidden" name="token" value="'.newToken().'">';
292 print '<input type="hidden" name="action" value="update">';
293
294 print dol_get_fiche_head($head, 'common_ticket', '', -1);
295
296 print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
297 print "<br><br>\n";
298
299
300 clearstatcache();
301
302 print '<table class="noborder centpercent">';
303 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
304
305 // Method
306
307 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
308
309 // SuperAdministrator access only
310 if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity)) {
311 print $form->selectarray('MAIN_MAIL_SENDMODE_TICKET', $listofmethods, $conf->global->MAIN_MAIL_SENDMODE_TICKET);
312 } else {
313 $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE_TICKET];
314 if (empty($text)) {
315 $text = $langs->trans("Undefined");
316 }
317 $htmltext = $langs->trans("ContactSuperAdminForChange");
318 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
319 print '<input type="hidden" name="MAIN_MAIL_SENDMODE_TICKET" value="'.$conf->global->MAIN_MAIL_SENDMODE_TICKET.'">';
320 }
321 print '</td></tr>';
322
323 // Host server
324
325 print '<tr class="oddeven hideifdefault">';
326 if (!$conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE_TICKET == 'mail') {
327 print '<td>';
328 print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
329 print '</td><td>';
330 print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
331 print '</td>';
332 } else {
333 print '<td>';
334 $mainserver = (!empty($conf->global->MAIN_MAIL_SMTP_SERVER_TICKET) ? $conf->global->MAIN_MAIL_SMTP_SERVER_TICKET : '');
335 $smtpserver = ini_get('SMTP') ?ini_get('SMTP') : $langs->transnoentities("Undefined");
336 if ($linuxlike) {
337 print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
338 } else {
339 print $langs->trans("MAIN_MAIL_SMTP_SERVER", $smtpserver);
340 }
341 print '</td><td>';
342 // SuperAdministrator access only
343 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
344 print '<input class="flat minwidth300" id="MAIN_MAIL_SMTP_SERVER_TICKET" name="MAIN_MAIL_SMTP_SERVER_TICKET" size="18" value="'.$mainserver.'">';
345 print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_TICKET_sav" name="MAIN_MAIL_SMTP_SERVER_TICKET_sav" value="'.$mainserver.'">';
346 print '<span id="smtp_server_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
347 } else {
348 $text = !empty($mainserver) ? $mainserver : $smtpserver;
349 $htmltext = $langs->trans("ContactSuperAdminForChange");
350 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
351 print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_TICKET" name="MAIN_MAIL_SMTP_SERVER_TICKET" value="'.$mainserver.'">';
352 }
353 print '</td>';
354 }
355 print '</tr>';
356
357 // Port
358
359 print '<tr class="oddeven hideifdefault"><td>';
360 if (!$conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE_TICKET == 'mail') {
361 print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
362 print '</td><td>';
363 print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
364 } else {
365 $mainport = (!empty($conf->global->MAIN_MAIL_SMTP_PORT_TICKET) ? $conf->global->MAIN_MAIL_SMTP_PORT_TICKET : '');
366 $smtpport = ini_get('smtp_port') ?ini_get('smtp_port') : $langs->transnoentities("Undefined");
367 if ($linuxlike) {
368 print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
369 } else {
370 print $langs->trans("MAIN_MAIL_SMTP_PORT", $smtpport);
371 }
372 print '</td><td>';
373 // SuperAdministrator access only
374 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
375 print '<input class="flat" id="MAIN_MAIL_SMTP_PORT_TICKET" name="MAIN_MAIL_SMTP_PORT_TICKET" size="3" value="'.$mainport.'">';
376 print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_TICKET_sav" name="MAIN_MAIL_SMTP_PORT_TICKET_sav" value="'.$mainport.'">';
377 print '<span id="smtp_port_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
378 } else {
379 $text = (!empty($mainport) ? $mainport : $smtpport);
380 $htmltext = $langs->trans("ContactSuperAdminForChange");
381 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
382 print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_TICKET" name="MAIN_MAIL_SMTP_PORT_TICKET" value="'.$mainport.'">';
383 }
384 }
385 print '</td></tr>';
386
387 // AUTH method
388 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) {
389 print '<tr class="oddeven smtp_auth_method hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE").'</td><td>';
390 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
391 // Note: Default value for MAIN_MAIL_SMTPS_AUTH_TYPE if not defined is 'LOGIN' (but login/pass may be empty and they won't be provided in such a case)
392 print '<input type="radio" id="radio_pw" name="MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET" value="LOGIN"'.(getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET', 'LOGIN') == 'LOGIN' ? ' checked' : '').'> ';
393 print '<label for="radio_pw" >'.$langs->trans("UsePassword").'</label>';
394 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
395 print '<input type="radio" id="radio_oauth" name="MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET" value="XOAUTH2"'.(getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET') == 'XOAUTH2' ? ' checked' : '').'> ';
396 print '<label for="radio_oauth" >'.$form->textwithpicto($langs->trans("UseOauth"), $langs->trans("OauthNotAvailableForAllAndHadToBeCreatedBefore")).'</label>';
397 } else {
398 $value = getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET', 'LOGIN');
399 $htmltext = $langs->trans("ContactSuperAdminForChange");
400 print $form->textwithpicto($langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE"), $htmltext, 1, 'superadmin');
401 print '<input type="hidden" id="MAIN_MAIL_SMTPS_AUTH_TYPE" name="MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET" value="'.$value.'">';
402 }
403 print '</td></tr>';
404 }
405
406 // ID
407 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) {
408 $mainstmpid = (!empty($conf->global->MAIN_MAIL_SMTPS_ID_TICKET) ? $conf->global->MAIN_MAIL_SMTPS_ID_TICKET : '');
409 print '<tr class="drag drop oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
410 // SuperAdministrator access only
411 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
412 print '<input class="flat" name="MAIN_MAIL_SMTPS_ID_TICKET" size="32" value="'.$mainstmpid.'">';
413 } else {
414 $htmltext = $langs->trans("ContactSuperAdminForChange");
415 print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID_TICKET, $htmltext, 1, 'superadmin');
416 print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID_TICKET" value="'.$mainstmpid.'">';
417 }
418 print '</td></tr>';
419 }
420
421 // PW
422 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) {
423 $mainsmtppw = (!empty($conf->global->MAIN_MAIL_SMTPS_PW_TICKET) ? $conf->global->MAIN_MAIL_SMTPS_PW_TICKET : '');
424 print '<tr class="drag drop oddeven smtp_pw hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>';
425 // SuperAdministrator access only
426 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
427 print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW_TICKET" size="32" value="'.$mainsmtppw.'">';
428 } else {
429 $htmltext = $langs->trans("ContactSuperAdminForChange");
430 print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW_TICKET, $htmltext, 1, 'superadmin');
431 print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW_TICKET" value="'.$mainsmtppw.'">';
432 }
433 print '</td></tr>';
434 }
435
436 // OAUTH service provider
437 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) {
438 print '<tr class="oddeven smtp_oauth_service hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_OAUTH_SERVICE").'</td><td>';
439 // SuperAdministrator access only
440 if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity)) {
441 print $form->selectarray('MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET', $oauthservices, $conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET);
442 } else {
443 $text = $oauthservices[$conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET];
444 if (empty($text)) {
445 $text = $langs->trans("Undefined");
446 }
447 $htmltext = $langs->trans("ContactSuperAdminForChange");
448 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
449 print '<input type="hidden" name="MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET" value="'.$conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET.'">';
450 }
451 print '</td></tr>';
452 }
453
454 // TLS
455
456 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
457 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) {
458 if (function_exists('openssl_open')) {
459 print $form->selectyesno('MAIN_MAIL_EMAIL_TLS_TICKET', (!empty($conf->global->MAIN_MAIL_EMAIL_TLS_TICKET) ? $conf->global->MAIN_MAIL_EMAIL_TLS_TICKET : 0), 1);
460 } else {
461 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
462 }
463 } else {
464 print yn(0).' ('.$langs->trans("NotSupported").')';
465 }
466 print '</td></tr>';
467
468 // STARTTLS
469
470 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
471 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) {
472 if (function_exists('openssl_open')) {
473 print $form->selectyesno('MAIN_MAIL_EMAIL_STARTTLS_TICKET', (!empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS_TICKET) ? $conf->global->MAIN_MAIL_EMAIL_STARTTLS_TICKET : 0), 1);
474 } else {
475 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
476 }
477 } else {
478 print yn(0).' ('.$langs->trans("NotSupported").')';
479 }
480 print '</td></tr>';
481
482 print '</table>';
483
484 print dol_get_fiche_end();
485
486 print $form->buttonsSaveCancel();
487
488 print '</form>';
489} else {
490 print dol_get_fiche_head($head, 'common_ticket', '', -1);
491
492 print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
493 print "<br><br>\n";
494
495 print '<table class="noborder centpercent">';
496 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
497
498 // Method
499 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
500 $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET')];
501 if (empty($text)) {
502 $text = $langs->trans("Undefined").img_warning();
503 }
504 if (getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET') == 'default') {
505 print '<span class="opacitymedium">'.$text.'</span>';
506 } else {
507 print $text;
508 }
509 print '</td></tr>';
510
511 if (!empty($conf->global->MAIN_MAIL_SENDMODE_TICKET) && $conf->global->MAIN_MAIL_SENDMODE_TICKET != 'default') {
512 // Host server
513 if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && $conf->global->MAIN_MAIL_SENDMODE_TICKET == 'mail')) {
514 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
515 } else {
516 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER", ini_get('SMTP') ?ini_get('SMTP') : $langs->transnoentities("Undefined")).'</td><td>'.(!empty($conf->global->MAIN_MAIL_SMTP_SERVER_TICKET) ? $conf->global->MAIN_MAIL_SMTP_SERVER_TICKET : '').'</td></tr>';
517 }
518
519 // Port
520 if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && $conf->global->MAIN_MAIL_SENDMODE_TICKET == 'mail')) {
521 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
522 } else {
523 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT", ini_get('smtp_port') ?ini_get('smtp_port') : $langs->transnoentities("Undefined")).'</td><td>'.(!empty($conf->global->MAIN_MAIL_SMTP_PORT_TICKET) ? $conf->global->MAIN_MAIL_SMTP_PORT_TICKET : '').'</td></tr>';
524 }
525
526 // AUTH method
527 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET'), array('smtps', 'swiftmailer'))) {
528 $authtype = getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET', 'LOGIN');
529 $text = ($authtype === "LOGIN") ? $langs->trans("UsePassword") : ($authtype === "XOAUTH2" ? $langs->trans("UseOauth") : '') ;
530 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE").'</td><td>'.$text.'</td></tr>';
531 }
532
533 // SMTPS ID
534 if (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer'))) {
535 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_ID_TICKET.'</td></tr>';
536 }
537
538 // SMTPS PW
539 if (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')) && getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET') != "XOAUTH2") {
540 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./', '*', $conf->global->MAIN_MAIL_SMTPS_PW_TICKET).'</td></tr>';
541 }
542
543 // SMTPS oauth service
544 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET'), array('smtps', 'swiftmailer')) && getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET') === "XOAUTH2") {
545 $text = $oauthservices[$conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET];
546 if (empty($text)) {
547 $text = $langs->trans("Undefined").img_warning();
548 }
549 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET").'</td><td>'.$text.'</td></tr>';
550 }
551
552 // TLS
553 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
554 if (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer'))) {
555 if (function_exists('openssl_open')) {
556 print yn($conf->global->MAIN_MAIL_EMAIL_TLS_TICKET);
557 } else {
558 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
559 }
560 } else {
561 print yn(0).' ('.$langs->trans("NotSupported").')';
562 }
563 print '</td></tr>';
564
565 // STARTTLS
566 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
567 if (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer'))) {
568 if (function_exists('openssl_open')) {
569 print yn($conf->global->MAIN_MAIL_EMAIL_STARTTLS_TICKET);
570 } else {
571 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
572 }
573 } else {
574 print yn(0).' ('.$langs->trans("NotSupported").')';
575 }
576 print '</td></tr>';
577 }
578
579 print '</table>';
580
581 print dol_get_fiche_end();
582
583
584 if ($conf->global->MAIN_MAIL_SENDMODE_TICKET == 'mail' && empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) {
585 print '<br>';
586 /*
587 // Warning 1
588 if ($linuxlike)
589 {
590 $sendmailoption=ini_get('mail.force_extra_parameters');
591 if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
592 {
593 print info_admin($langs->trans("SendmailOptionNotComplete"));
594 }
595 }*/
596 // Warning 2
597 print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
598 }
599
600
601 // Buttons for actions
602
603 print '<div class="tabsAction">';
604
605 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
606
607 if (!empty($conf->global->MAIN_MAIL_SENDMODE_TICKET) && $conf->global->MAIN_MAIL_SENDMODE_TICKET != 'default') {
608 if ($conf->global->MAIN_MAIL_SENDMODE_TICKET != 'mail' || !$linuxlike) {
609 if (function_exists('fsockopen') && $port && $server) {
610 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
611 }
612 } else {
613 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
614 }
615
616 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
617
618 if (isModEnabled('fckeditor')) {
619 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&amp;mode=init">'.$langs->trans("DoTestSendHTML").'</a>';
620 }
621 }
622
623 print '</div>';
624
625
626 if ($conf->global->MAIN_MAIL_SENDMODE_TICKET == 'mail' && !in_array($action, array('testconnect', 'test', 'testhtml'))) {
627 $text = $langs->trans("WarningPHPMail");
628 print info_admin($text);
629 }
630
631 // Run the test to connect
632 if ($action == 'testconnect') {
633 print '<div id="formmailaftertstconnect" name="formmailaftertstconnect"></div>';
634 print load_fiche_titre($langs->trans("DoTestServerAvailability"));
635
636 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
637 $mail = new CMailFile('', '', '', '', array(), array(), array(), '', '', 0, '', '', '', '', $trackid, $sendcontext);
638
639 $result = $mail->check_server_port($server, $port);
640 if ($result) {
641 print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort", $server, $port).'</div>';
642 } else {
643 $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort", $server, $port);
644
645 if ($mail->error) {
646 $errormsg .= ' - '.$mail->error;
647 }
648
649 setEventMessages($errormsg, null, 'errors');
650 }
651 print '<br>';
652 }
653
654 // Show email send test form
655 if ($action == 'test' || $action == 'testhtml') {
656 print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
657 print load_fiche_titre($action == 'testhtml' ? $langs->trans("DoTestSendHTML") : $langs->trans("DoTestSend"));
658
659 print dol_get_fiche_head('');
660
661 // Cree l'objet formulaire mail
662 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
663 $formmail = new FormMail($db);
664 $formmail->fromname = (GETPOSTISSET('fromname') ? GETPOST('fromname', 'restricthtml') : $conf->global->MAIN_MAIL_EMAIL_FROM);
665 $formmail->frommail = (GETPOSTISSET('frommail') ? GETPOST('frommail', 'restricthtml') : $conf->global->MAIN_MAIL_EMAIL_FROM);
666 $formmail->trackid = (($action == 'testhtml') ? "testhtml" : "test");
667 $formmail->withfromreadonly = 0;
668 $formmail->withsubstit = 0;
669 $formmail->withfrom = 1;
670 $formmail->witherrorsto = 1;
671 $formmail->withto = (GETPOSTISSET('sendto') ? GETPOST('sendto', 'restricthtml') : ($user->email ? $user->email : 1));
672 $formmail->withtocc = (GETPOSTISSET('sendtocc') ? GETPOST('sendtocc', 'restricthtml') : 1);
673 $formmail->withtoccc = (GETPOSTISSET('sendtoccc') ? GETPOST('sendtoccc', 'restricthtml') : 1);
674 $formmail->withtopic = (GETPOSTISSET('subject') ? GETPOST('subject') : $langs->trans("Test"));
675 $formmail->withtopicreadonly = 0;
676 $formmail->withfile = 2;
677 $formmail->withbody = (GETPOSTISSET('message') ? GETPOST('message', 'restricthtml') : ($action == 'testhtml' ? $langs->transnoentities("PredefinedMailTestHtml") : $langs->transnoentities("PredefinedMailTest")));
678 $formmail->withbodyreadonly = 0;
679 $formmail->withcancel = 1;
680 $formmail->withdeliveryreceipt = 1;
681 $formmail->withfckeditor = ($action == 'testhtml' ? 1 : 0);
682 $formmail->ckeditortoolbar = 'dolibarr_mailings';
683 // Tableau des substitutions
684 $formmail->substit = $substitutionarrayfortest;
685 // Tableau des parametres complementaires du post
686 $formmail->param["action"] = "send";
687 $formmail->param["models"] = "body";
688 $formmail->param["mailid"] = 0;
689 $formmail->param["returnurl"] = $_SERVER["PHP_SELF"];
690
691 // Init list of files
692 if (GETPOST("mode", "aZ09") == 'init') {
693 $formmail->clear_attached_files();
694 }
695
696 print $formmail->get_form('addfile', 'removefile');
697
698 print dol_get_fiche_end();
699 }
700}
701
702// End of page
703llxFooter();
704$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).
email_admin_prepare_head()
Return array head with list of tabs to view object informations.
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 send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage generation of HTML components Only common components must be here.
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.