dolibarr 19.0.4
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 '__ID__' => 'TESTIdRecord',
45 '__USER_LOGIN__' => $user->login,
46 '__USER_EMAIL__' => $user->email,
47 '__USER_SIGNATURE__' => (($user->signature && !getDolGlobalString('MAIN_MAIL_DO_NOT_USE_SIGN')) ? $usersignature : ''), // Done into actions_sendmails
48 '__SENDEREMAIL_SIGNATURE__' => (($user->signature && !getDolGlobalString('MAIN_MAIL_DO_NOT_USE_SIGN')) ? $usersignature : ''), // Done into actions_sendmails
49 '__LASTNAME__' => 'RecipientLastname',
50 '__FIRSTNAME__' => 'RecipientFirstname',
51 '__ADDRESS__'=> 'RecipientAddress',
52 '__ZIP__'=> 'RecipientZip',
53 '__TOWN_'=> 'RecipientTown',
54 '__COUNTRY__'=> 'RecipientCountry',
55 '__DOL_MAIN_URL_ROOT__'=>DOL_MAIN_URL_ROOT,
56);
57complete_substitutions_array($substitutionarrayfortest, $langs);
58
59// List of sending methods
60$listofmethods = array();
61$listofmethods['default'] = $langs->trans('DefaultOutgoingEmailSetup');
62$listofmethods['mail'] = 'PHP mail function';
63//$listofmethods['simplemail']='Simplemail class';
64$listofmethods['smtps'] = 'SMTP/SMTPS socket library';
65if (version_compare(phpversion(), '7.0', '>=')) {
66 $listofmethods['swiftmailer'] = 'Swift Mailer socket library';
67}
68
69// Security check
70if (!$user->admin) {
72}
73
74
75/*
76 * Actions
77 */
78
79if ($action == 'update' && !$cancel) {
80 // Send mode parameters
81 dolibarr_set_const($db, "MAIN_MAIL_SENDMODE_TICKET", GETPOST("MAIN_MAIL_SENDMODE_TICKET"), 'chaine', 0, '', $conf->entity);
82 dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT_TICKET", GETPOST("MAIN_MAIL_SMTP_PORT_TICKET"), 'chaine', 0, '', $conf->entity);
83 dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER_TICKET", GETPOST("MAIN_MAIL_SMTP_SERVER_TICKET"), 'chaine', 0, '', $conf->entity);
84 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID_TICKET", GETPOST("MAIN_MAIL_SMTPS_ID_TICKET"), 'chaine', 0, '', $conf->entity);
85 if (GETPOSTISSET("MAIN_MAIL_SMTPS_PW_TICKET")) {
86 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW_TICKET", GETPOST("MAIN_MAIL_SMTPS_PW_TICKET", 'none'), 'chaine', 0, '', $conf->entity);
87 }
88 if (GETPOSTISSET("MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET")) {
89 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET", GETPOST("MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET", 'chaine'), 'chaine', 0, '', $conf->entity);
90 }
91 if (GETPOSTISSET("MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET")) {
92 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET", GETPOST("MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET", 'chaine'), 'chaine', 0, '', $conf->entity);
93 }
94 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS_TICKET", GETPOST("MAIN_MAIL_EMAIL_TLS_TICKET"), 'chaine', 0, '', $conf->entity);
95 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS_TICKET", GETPOST("MAIN_MAIL_EMAIL_STARTTLS_TICKET"), 'chaine', 0, '', $conf->entity);
96
97 header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
98 exit;
99}
100
101
102// Actions to send emails
103$id = 0;
104$actiontypecode = ''; // Not an event for agenda
105$triggersendname = ''; // Disable triggers
106$paramname = 'id';
107$mode = 'emailfortest';
108$trackid = (($action == 'testhtml') ? "testhtml" : "test");
109$sendcontext = 'ticket'; // Force to use dedicated context of setup for ticket
110include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
111
112if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'test') {
113 $action = 'test';
114}
115if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'testhtml') {
116 $action = 'testhtml';
117}
118
119
120
121
122/*
123 * View
124 */
125
126$form = new Form($db);
127
128$linuxlike = 1;
129if (preg_match('/^win/i', PHP_OS)) {
130 $linuxlike = 0;
131}
132if (preg_match('/^mac/i', PHP_OS)) {
133 $linuxlike = 0;
134}
135
136if (!getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET')) {
137 $conf->global->MAIN_MAIL_SENDMODE_TICKET = 'default';
138}
139$port = getDolGlobalString('MAIN_MAIL_SMTP_PORT_TICKET') ? $conf->global->MAIN_MAIL_SMTP_PORT_TICKET : ini_get('smtp_port');
140if (!$port) {
141 $port = 25;
142}
143$server = getDolGlobalString('MAIN_MAIL_SMTP_SERVER_TICKET') ? $conf->global->MAIN_MAIL_SMTP_SERVER_TICKET : ini_get('SMTP');
144if (!$server) {
145 $server = '127.0.0.1';
146}
147
148
149$wikihelp = 'EN:Setup_EMails|FR:Paramétrage_EMails|ES:Configuración_EMails';
150llxHeader('', $langs->trans("Setup"), $wikihelp);
151
152print load_fiche_titre($langs->trans("EMailsSetup"), '', 'title_setup');
153
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(' . getDolGlobalString('MAIN_MAIL_EMAIL_TLS_TICKET').');
222 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").removeAttr("disabled");
223 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").val(' . getDolGlobalString('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(' . getDolGlobalString('MAIN_MAIL_EMAIL_TLS_TICKET').');
238 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").removeAttr("disabled");
239 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").val(' . getDolGlobalString('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("Parameters").'</td><td></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 (!isModEnabled('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[getDolGlobalString('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="' . getDolGlobalString('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 && getDolGlobalString('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 = (getDolGlobalString('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 print ' <span class="opacitymedium smtp_method">' . $langs->trans("SeeLinkToOnlineDocumentation") . '</span>';
348 } else {
349 $text = !empty($mainserver) ? $mainserver : $smtpserver;
350 $htmltext = $langs->trans("ContactSuperAdminForChange");
351 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
352 print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_TICKET" name="MAIN_MAIL_SMTP_SERVER_TICKET" value="'.$mainserver.'">';
353 }
354 print '</td>';
355 }
356 print '</tr>';
357
358 // Port
359
360 print '<tr class="oddeven hideifdefault hideonmodemail"><td>';
361 if (!$conf->use_javascript_ajax && $linuxlike && getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET') == 'mail') {
362 print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
363 print '</td><td>';
364 print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
365 } else {
366 $mainport = (getDolGlobalString('MAIN_MAIL_SMTP_PORT_TICKET') ? $conf->global->MAIN_MAIL_SMTP_PORT_TICKET : '');
367 $smtpport = ini_get('smtp_port') ? ini_get('smtp_port') : $langs->transnoentities("Undefined");
368 if ($linuxlike) {
369 print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
370 } else {
371 print $langs->trans("MAIN_MAIL_SMTP_PORT", $smtpport);
372 }
373 print '</td><td>';
374 // SuperAdministrator access only
375 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
376 print '<input class="flat" id="MAIN_MAIL_SMTP_PORT_TICKET" name="MAIN_MAIL_SMTP_PORT_TICKET" size="3" value="'.$mainport.'">';
377 print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_TICKET_sav" name="MAIN_MAIL_SMTP_PORT_TICKET_sav" value="'.$mainport.'">';
378 print '<span id="smtp_port_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
379 } else {
380 $text = (!empty($mainport) ? $mainport : $smtpport);
381 $htmltext = $langs->trans("ContactSuperAdminForChange");
382 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
383 print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_TICKET" name="MAIN_MAIL_SMTP_PORT_TICKET" value="'.$mainport.'">';
384 }
385 }
386 print '</td></tr>';
387
388 // AUTH method
389 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) {
390 print '<tr class="oddeven smtp_auth_method hideifdefault hideonmodemail"><td>'.$langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE").'</td><td>';
391 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
392 // 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)
393 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' : '').'> ';
394 print '<label for="radio_pw" >'.$langs->trans("UsePassword").'</label>';
395 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
396 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' : '').'> ';
397 print '<label for="radio_oauth" >'.$form->textwithpicto($langs->trans("UseOauth"), $langs->trans("OauthNotAvailableForAllAndHadToBeCreatedBefore")).'</label>';
398 } else {
399 $value = getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET', 'LOGIN');
400 $htmltext = $langs->trans("ContactSuperAdminForChange");
401 print $form->textwithpicto($langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE"), $htmltext, 1, 'superadmin');
402 print '<input type="hidden" id="MAIN_MAIL_SMTPS_AUTH_TYPE" name="MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET" value="'.$value.'">';
403 }
404 print '</td></tr>';
405 }
406
407 // ID
408 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) {
409 $mainstmpid = (getDolGlobalString('MAIN_MAIL_SMTPS_ID_TICKET') ? $conf->global->MAIN_MAIL_SMTPS_ID_TICKET : '');
410 print '<tr class="drag drop oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
411 // SuperAdministrator access only
412 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
413 print '<input class="flat" name="MAIN_MAIL_SMTPS_ID_TICKET" size="32" value="'.$mainstmpid.'">';
414 } else {
415 $htmltext = $langs->trans("ContactSuperAdminForChange");
416 print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID_TICKET, $htmltext, 1, 'superadmin');
417 print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID_TICKET" value="'.$mainstmpid.'">';
418 }
419 print '</td></tr>';
420 }
421
422 // PW
423 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) {
424 $mainsmtppw = (getDolGlobalString('MAIN_MAIL_SMTPS_PW_TICKET') ? $conf->global->MAIN_MAIL_SMTPS_PW_TICKET : '');
425 print '<tr class="drag drop oddeven smtp_pw hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>';
426 // SuperAdministrator access only
427 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
428 print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW_TICKET" size="32" value="'.$mainsmtppw.'">';
429 } else {
430 $htmltext = $langs->trans("ContactSuperAdminForChange");
431 print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW_TICKET, $htmltext, 1, 'superadmin');
432 print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW_TICKET" value="'.$mainsmtppw.'">';
433 }
434 print '</td></tr>';
435 }
436
437 // OAUTH service provider
438 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) {
439 print '<tr class="oddeven smtp_oauth_service hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_OAUTH_SERVICE").'</td><td>';
440 // SuperAdministrator access only
441 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
442 print $form->selectarray('MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET', $oauthservices, $conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET);
443 } else {
444 $text = $oauthservices[getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET')];
445 if (empty($text)) {
446 $text = $langs->trans("Undefined");
447 }
448 $htmltext = $langs->trans("ContactSuperAdminForChange");
449 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
450 print '<input type="hidden" name="MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET" value="' . getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET').'">';
451 }
452 print '</td></tr>';
453 }
454
455 // TLS
456
457 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
458 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) {
459 if (function_exists('openssl_open')) {
460 print $form->selectyesno('MAIN_MAIL_EMAIL_TLS_TICKET', (getDolGlobalString('MAIN_MAIL_EMAIL_TLS_TICKET') ? $conf->global->MAIN_MAIL_EMAIL_TLS_TICKET : 0), 1);
461 } else {
462 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
463 }
464 } else {
465 print yn(0).' ('.$langs->trans("NotSupported").')';
466 }
467 print '</td></tr>';
468
469 // STARTTLS
470
471 print '<tr class="oddeven hideifdefault hideonmodemail"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
472 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) {
473 if (function_exists('openssl_open')) {
474 print $form->selectyesno('MAIN_MAIL_EMAIL_STARTTLS_TICKET', (getDolGlobalString('MAIN_MAIL_EMAIL_STARTTLS_TICKET') ? $conf->global->MAIN_MAIL_EMAIL_STARTTLS_TICKET : 0), 1);
475 } else {
476 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
477 }
478 } else {
479 print yn(0).' ('.$langs->trans("NotSupported").')';
480 }
481 print '</td></tr>';
482
483 print '</table>';
484
485 print dol_get_fiche_end();
486
487 print $form->buttonsSaveCancel();
488
489 print '</form>';
490} else {
491 print dol_get_fiche_head($head, 'common_ticket', '', -1);
492
493 print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
494 print "<br><br>\n";
495
496 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
497 print '<table class="noborder centpercent">';
498 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameters").'</td><td></td></tr>';
499
500 // Method
501 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
502 $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET')];
503 if (empty($text)) {
504 $text = $langs->trans("Undefined").img_warning();
505 }
506 if (getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET') == 'default') {
507 print '<span class="opacitymedium">'.$text.'</span>';
508 } else {
509 print $text;
510 }
511 print '</td></tr>';
512
513 if (getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET') && getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET') != 'default') {
514 // Host server
515 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET') == 'mail')) {
516 //print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
517 } else {
518 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER", ini_get('SMTP') ? ini_get('SMTP') : $langs->transnoentities("Undefined")).'</td><td>'.(getDolGlobalString('MAIN_MAIL_SMTP_SERVER_TICKET') ? $conf->global->MAIN_MAIL_SMTP_SERVER_TICKET : '').'</td></tr>';
519 }
520
521 // Port
522 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET') == 'mail')) {
523 //print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
524 } else {
525 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>'.(getDolGlobalString('MAIN_MAIL_SMTP_PORT_TICKET') ? $conf->global->MAIN_MAIL_SMTP_PORT_TICKET : '').'</td></tr>';
526 }
527
528 // AUTH method
529 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET'), array('smtps', 'swiftmailer'))) {
530 $authtype = getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET', 'LOGIN');
531 $text = ($authtype === "LOGIN") ? $langs->trans("UsePassword") : ($authtype === "XOAUTH2" ? $langs->trans("UseOauth") : '') ;
532 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE").'</td><td>'.$text.'</td></tr>';
533 }
534
535 // SMTPS ID
536 if (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer'))) {
537 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>' . getDolGlobalString('MAIN_MAIL_SMTPS_ID_TICKET').'</td></tr>';
538 }
539
540 // SMTPS PW
541 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") {
542 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>';
543 }
544
545 // SMTPS oauth service
546 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET'), array('smtps', 'swiftmailer')) && getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE_TICKET') === "XOAUTH2") {
547 $text = $oauthservices[getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET')];
548 if (empty($text)) {
549 $text = $langs->trans("Undefined").img_warning();
550 }
551 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_OAUTH_SERVICE_TICKET").'</td><td>'.$text.'</td></tr>';
552 }
553
554 // TLS
555 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
556 // Nothing
557 } else {
558 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
559 if (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer'))) {
560 if (function_exists('openssl_open')) {
561 print yn($conf->global->MAIN_MAIL_EMAIL_TLS_TICKET);
562 } else {
563 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
564 }
565 } else {
566 print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
567 }
568 print '</td></tr>';
569 }
570
571 // STARTTLS
572 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
573 // Nothing
574 } else {
575 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
576 if (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer'))) {
577 if (function_exists('openssl_open')) {
578 print yn($conf->global->MAIN_MAIL_EMAIL_STARTTLS_TICKET);
579 } else {
580 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
581 }
582 } else {
583 print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
584 }
585 print '</td></tr>';
586 }
587 }
588
589 print '</table>';
590 print '</div>';
591
592 print dol_get_fiche_end();
593
594
595 if (getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET') == 'mail' && !getDolGlobalString('MAIN_FIX_FOR_BUGGED_MTA')) {
596 print '<br>';
597 /*
598 // Warning 1
599 if ($linuxlike)
600 {
601 $sendmailoption=ini_get('mail.force_extra_parameters');
602 if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
603 {
604 print info_admin($langs->trans("SendmailOptionNotComplete"));
605 }
606 }*/
607 // Warning 2
608 print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
609 }
610
611
612 // Buttons for actions
613
614 print '<div class="tabsAction">';
615
616 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
617
618 if (getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET') && getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET') != 'default') {
619 if (getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET') != 'mail' || !$linuxlike) {
620 if (function_exists('fsockopen') && $port && $server) {
621 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
622 }
623 } else {
624 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
625 }
626
627 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
628
629 if (isModEnabled('fckeditor')) {
630 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&amp;mode=init">'.$langs->trans("DoTestSendHTML").'</a>';
631 }
632 }
633
634 print '</div>';
635
636
637 if (getDolGlobalString('MAIN_MAIL_SENDMODE_TICKET') == 'mail' && !in_array($action, array('testconnect', 'test', 'testhtml'))) {
638 $text = $langs->trans("WarningPHPMail");
639 print info_admin($text);
640 }
641
642 // Run the test to connect
643 if ($action == 'testconnect') {
644 print '<div id="formmailaftertstconnect" name="formmailaftertstconnect"></div>';
645 print load_fiche_titre($langs->trans("DoTestServerAvailability"));
646
647 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
648 $mail = new CMailFile('', '', '', '', array(), array(), array(), '', '', 0, '', '', '', '', $trackid, $sendcontext);
649
650 $result = $mail->check_server_port($server, $port);
651 if ($result) {
652 print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort", $server, $port).'</div>';
653 } else {
654 $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort", $server, $port);
655
656 if ($mail->error) {
657 $errormsg .= ' - '.$mail->error;
658 }
659
660 setEventMessages($errormsg, null, 'errors');
661 }
662 print '<br>';
663 }
664
665 // Show email send test form
666 if ($action == 'test' || $action == 'testhtml') {
667 print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
668 print load_fiche_titre($action == 'testhtml' ? $langs->trans("DoTestSendHTML") : $langs->trans("DoTestSend"));
669
670 print dol_get_fiche_head(array(), '', '', -1);
671
672 // Cree l'objet formulaire mail
673 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
674 $formmail = new FormMail($db);
675 $formmail->fromname = (GETPOSTISSET('fromname') ? GETPOST('fromname', 'restricthtml') : $conf->global->MAIN_MAIL_EMAIL_FROM);
676 $formmail->frommail = (GETPOSTISSET('frommail') ? GETPOST('frommail', 'restricthtml') : $conf->global->MAIN_MAIL_EMAIL_FROM);
677 $formmail->trackid = (($action == 'testhtml') ? "testhtml" : "test");
678 $formmail->fromid = $user->id;
679 $formmail->fromalsorobot = 1;
680 $formmail->withfromreadonly = 0;
681 $formmail->withsubstit = 0;
682 $formmail->withfrom = 1;
683 $formmail->witherrorsto = 1;
684 $formmail->withto = (GETPOSTISSET('sendto') ? GETPOST('sendto', 'restricthtml') : ($user->email ? $user->email : 1));
685 $formmail->withtocc = (GETPOSTISSET('sendtocc') ? GETPOST('sendtocc', 'restricthtml') : 1);
686 $formmail->withtoccc = (GETPOSTISSET('sendtoccc') ? GETPOST('sendtoccc', 'restricthtml') : 1);
687 $formmail->withtopic = (GETPOSTISSET('subject') ? GETPOST('subject') : $langs->trans("Test"));
688 $formmail->withtopicreadonly = 0;
689 $formmail->withfile = 2;
690 $formmail->withbody = (GETPOSTISSET('message') ? GETPOST('message', 'restricthtml') : ($action == 'testhtml' ? $langs->transnoentities("PredefinedMailTestHtml") : $langs->transnoentities("PredefinedMailTest")));
691 $formmail->withbodyreadonly = 0;
692 $formmail->withcancel = 1;
693 $formmail->withdeliveryreceipt = 1;
694 $formmail->withfckeditor = ($action == 'testhtml' ? 1 : 0);
695 $formmail->ckeditortoolbar = 'dolibarr_mailings';
696 // Tableau des substitutions
697 $formmail->substit = $substitutionarrayfortest;
698 // Tableau des parametres complementaires du post
699 $formmail->param["action"] = "send";
700 $formmail->param["models"] = "body";
701 $formmail->param["mailid"] = 0;
702 $formmail->param["returnurl"] = $_SERVER["PHP_SELF"];
703
704 // Init list of files
705 if (GETPOST("mode", "aZ09") == 'init') {
706 $formmail->clear_attached_files();
707 }
708
709 print $formmail->get_form('addfile', 'removefile');
710
711 print dol_get_fiche_end();
712 }
713}
714
715// End of page
716llxFooter();
717$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:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.