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 21/** 22 * \file htdocs/admin/mails_ticket.php 23 * \brief Page to setup mails for ticket 24 */ 25 26require '../main.inc.php'; 27require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; 28require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; 29 30// Load translation files required by the page 31$langs->loadLangs(array('companies', 'products', 'admin', 'mails', 'other', 'errors')); 32 33$action = GETPOST('action', 'aZ09'); 34 35if (!$user->admin) accessforbidden(); 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{ 41 $usersignature = dol_string_nohtmltag($usersignature); 42} 43 44$substitutionarrayfortest = array( 45'__LOGIN__' => $user->login, 46'__ID__' => 'TESTIdRecord', 47'__EMAIL__' => 'TESTEMail', 48'__LASTNAME__' => 'TESTLastname', 49'__FIRSTNAME__' => 'TESTFirstname', 50'__USER_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $usersignature : ''), 51//'__PERSONALIZED__' => 'TESTPersonalized' // Hiden because not used yet 52); 53complete_substitutions_array($substitutionarrayfortest, $langs); 54 55 56 57/* 58 * Actions 59 */ 60 61if ($action == 'update' && empty($_POST["cancel"])) 62{ 63 // Send mode parameters 64 dolibarr_set_const($db, "MAIN_MAIL_SENDMODE_TICKET", GETPOST("MAIN_MAIL_SENDMODE_TICKET"), 'chaine', 0, '', $conf->entity); 65 dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT_TICKET", GETPOST("MAIN_MAIL_SMTP_PORT_TICKET"), 'chaine', 0, '', $conf->entity); 66 dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER_TICKET", GETPOST("MAIN_MAIL_SMTP_SERVER_TICKET"), 'chaine', 0, '', $conf->entity); 67 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID_TICKET", GETPOST("MAIN_MAIL_SMTPS_ID_TICKET"), 'chaine', 0, '', $conf->entity); 68 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW_TICKET", GETPOST("MAIN_MAIL_SMTPS_PW_TICKET"), 'chaine', 0, '', $conf->entity); 69 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS_TICKET", GETPOST("MAIN_MAIL_EMAIL_TLS_TICKET"), 'chaine', 0, '', $conf->entity); 70 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS_TICKET", GETPOST("MAIN_MAIL_EMAIL_STARTTLS_TICKET"), 'chaine', 0, '', $conf->entity); 71 72 header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup"); 73 exit; 74} 75 76 77// Actions to send emails 78$id = 0; 79$actiontypecode = ''; // Not an event for agenda 80$triggersendname = ''; // Disable triggers 81$paramname = 'id'; 82$mode = 'emailfortest'; 83$trackid = (($action == 'testhtml') ? "testhtml" : "test"); 84$sendcontext = 'ticket'; // Force to use dedicated context of setup for ticket 85include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; 86 87if ($action == 'presend' && GETPOST('trackid') == 'test') $action = 'test'; 88if ($action == 'presend' && GETPOST('trackid') == 'testhtml') $action = 'testhtml'; 89 90 91 92 93/* 94 * View 95 */ 96 97$form = new Form($db); 98 99$linuxlike = 1; 100if (preg_match('/^win/i', PHP_OS)) $linuxlike = 0; 101if (preg_match('/^mac/i', PHP_OS)) $linuxlike = 0; 102 103if (empty($conf->global->MAIN_MAIL_SENDMODE_TICKET)) $conf->global->MAIN_MAIL_SENDMODE_TICKET = 'default'; 104$port = !empty($conf->global->MAIN_MAIL_SMTP_PORT_TICKET) ? $conf->global->MAIN_MAIL_SMTP_PORT_TICKET : ini_get('smtp_port'); 105if (!$port) $port = 25; 106$server = !empty($conf->global->MAIN_MAIL_SMTP_SERVER_TICKET) ? $conf->global->MAIN_MAIL_SMTP_SERVER_TICKET : ini_get('SMTP'); 107if (!$server) $server = '127.0.0.1'; 108 109 110$wikihelp = 'EN:Setup_EMails|FR:Paramétrage_EMails|ES:Configuración_EMails'; 111llxHeader('', $langs->trans("Setup"), $wikihelp); 112 113print load_fiche_titre($langs->trans("EMailsSetup"), '', 'title_setup'); 114 115$head = email_admin_prepare_head(); 116 117// List of sending methods 118$listofmethods = array(); 119$listofmethods['default'] = $langs->trans('DefaultOutgoingEmailSetup'); 120$listofmethods['mail'] = 'PHP mail function'; 121//$listofmethods['simplemail']='Simplemail class'; 122$listofmethods['smtps'] = 'SMTP/SMTPS socket library'; 123if (version_compare(phpversion(), '7.0', '>=')) $listofmethods['swiftmailer'] = 'Swift Mailer socket library'; 124 125 126if ($action == 'edit') 127{ 128 if ($conf->use_javascript_ajax) 129 { 130 print "\n".'<script type="text/javascript" language="javascript">'; 131 print 'jQuery(document).ready(function () { 132 function initfields() 133 { 134 if (jQuery("#MAIN_MAIL_SENDMODE_TICKET").val()==\'default\') 135 { 136 jQuery(".hideifdefault").hide(); 137 } 138 else 139 { 140 jQuery(".hideifdefault").show(); 141 } 142 143 if (jQuery("#MAIN_MAIL_SENDMODE_TICKET").val()==\'mail\') 144 { 145 jQuery(".drag").hide(); 146 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").val(0); 147 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").prop("disabled", true); 148 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").val(0); 149 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").prop("disabled", true); 150 '; 151 if ($linuxlike) 152 { 153 print ' 154 jQuery("#MAIN_MAIL_SMTP_SERVER_TICKET").hide(); 155 jQuery("#MAIN_MAIL_SMTP_PORT_TICKET").hide(); 156 jQuery("#smtp_server_mess").show(); 157 jQuery("#smtp_port_mess").show(); 158 '; 159 } else { 160 print ' 161 jQuery("#MAIN_MAIL_SMTP_SERVER_TICKET").prop("disabled", true); 162 jQuery("#MAIN_MAIL_SMTP_PORT_TICKET").prop("disabled", true); 163 jQuery("#smtp_server_mess").hide(); 164 jQuery("#smtp_port_mess").hide(); 165 '; 166 } 167 print ' 168 } 169 if (jQuery("#MAIN_MAIL_SENDMODE_TICKET").val()==\'smtps\') 170 { 171 jQuery(".drag").show(); 172 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").val('.$conf->global->MAIN_MAIL_EMAIL_TLS_TICKET.'); 173 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").removeAttr("disabled"); 174 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_TICKET.'); 175 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").removeAttr("disabled"); 176 jQuery("#MAIN_MAIL_SMTP_SERVER_TICKET").removeAttr("disabled"); 177 jQuery("#MAIN_MAIL_SMTP_PORT_TICKET").removeAttr("disabled"); 178 jQuery("#MAIN_MAIL_SMTP_SERVER_TICKET").show(); 179 jQuery("#MAIN_MAIL_SMTP_PORT_TICKET").show(); 180 jQuery("#smtp_server_mess").hide(); 181 jQuery("#smtp_port_mess").hide(); 182 } 183 if (jQuery("#MAIN_MAIL_SENDMODE_TICKET").val()==\'swiftmailer\') 184 { 185 jQuery(".drag").show(); 186 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").val('.$conf->global->MAIN_MAIL_EMAIL_TLS_TICKET.'); 187 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").removeAttr("disabled"); 188 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_TICKET.'); 189 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").removeAttr("disabled"); 190 jQuery("#MAIN_MAIL_SMTP_SERVER_TICKET").removeAttr("disabled"); 191 jQuery("#MAIN_MAIL_SMTP_PORT_TICKET").removeAttr("disabled"); 192 jQuery("#MAIN_MAIL_SMTP_SERVER_TICKET").show(); 193 jQuery("#MAIN_MAIL_SMTP_PORT_TICKET").show(); 194 jQuery("#smtp_server_mess").hide(); 195 jQuery("#smtp_port_mess").hide(); 196 } 197 } 198 initfields(); 199 jQuery("#MAIN_MAIL_SENDMODE_TICKET").change(function() { 200 initfields(); 201 }); 202 jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() { 203 if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").val() == 1) 204 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").val(0); 205 }); 206 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_TICKET").change(function() { 207 if (jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").val() == 1) 208 jQuery("#MAIN_MAIL_EMAIL_TLS_TICKET").val(0); 209 }); 210 })'; 211 print '</script>'."\n"; 212 } 213 214 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">'; 215 print '<input type="hidden" name="token" value="'.newToken().'">'; 216 print '<input type="hidden" name="action" value="update">'; 217 218 print dol_get_fiche_head($head, 'common_ticket', '', -1); 219 220 print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n"; 221 print "<br>\n"; 222 223 224 clearstatcache(); 225 226 print '<table class="noborder centpercent">'; 227 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>'; 228 229 // Method 230 231 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>'; 232 233 // SuperAdministrator access only 234 if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity)) 235 { 236 print $form->selectarray('MAIN_MAIL_SENDMODE_TICKET', $listofmethods, $conf->global->MAIN_MAIL_SENDMODE_TICKET); 237 } else { 238 $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE_TICKET]; 239 if (empty($text)) $text = $langs->trans("Undefined"); 240 $htmltext = $langs->trans("ContactSuperAdminForChange"); 241 print $form->textwithpicto($text, $htmltext, 1, 'superadmin'); 242 print '<input type="hidden" name="MAIN_MAIL_SENDMODE_TICKET" value="'.$conf->global->MAIN_MAIL_SENDMODE_TICKET.'">'; 243 } 244 print '</td></tr>'; 245 246 // Host server 247 248 print '<tr class="oddeven hideifdefault"><td>'; 249 if (!$conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE_TICKET == 'mail') 250 { 251 print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike"); 252 print '</td><td>'; 253 print $langs->trans("SeeLocalSendMailSetup"); 254 } else { 255 $mainserver = (!empty($conf->global->MAIN_MAIL_SMTP_SERVER_TICKET) ? $conf->global->MAIN_MAIL_SMTP_SERVER_TICKET : ''); 256 $smtpserver = ini_get('SMTP') ?ini_get('SMTP') : $langs->transnoentities("Undefined"); 257 if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike"); 258 else print $langs->trans("MAIN_MAIL_SMTP_SERVER", $smtpserver); 259 print '</td><td>'; 260 // SuperAdministrator access only 261 if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) 262 { 263 print '<input class="flat" id="MAIN_MAIL_SMTP_SERVER_TICKET" name="MAIN_MAIL_SMTP_SERVER_TICKET" size="18" value="'.$mainserver.'">'; 264 print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_TICKET_sav" name="MAIN_MAIL_SMTP_SERVER_TICKET_sav" value="'.$mainserver.'">'; 265 print '<span id="smtp_server_mess">'.$langs->trans("SeeLocalSendMailSetup").'</span>'; 266 } else { 267 $text = !empty($mainserver) ? $mainserver : $smtpserver; 268 $htmltext = $langs->trans("ContactSuperAdminForChange"); 269 print $form->textwithpicto($text, $htmltext, 1, 'superadmin'); 270 print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_TICKET" name="MAIN_MAIL_SMTP_SERVER_TICKET" value="'.$mainserver.'">'; 271 } 272 } 273 print '</td></tr>'; 274 275 // Port 276 277 print '<tr class="oddeven hideifdefault"><td>'; 278 if (!$conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE_TICKET == 'mail') 279 { 280 print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike"); 281 print '</td><td>'; 282 print $langs->trans("SeeLocalSendMailSetup"); 283 } else { 284 $mainport = (!empty($conf->global->MAIN_MAIL_SMTP_PORT_TICKET) ? $conf->global->MAIN_MAIL_SMTP_PORT_TICKET : ''); 285 $smtpport = ini_get('smtp_port') ?ini_get('smtp_port') : $langs->transnoentities("Undefined"); 286 if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike"); 287 else print $langs->trans("MAIN_MAIL_SMTP_PORT", $smtpport); 288 print '</td><td>'; 289 // SuperAdministrator access only 290 if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) 291 { 292 print '<input class="flat" id="MAIN_MAIL_SMTP_PORT_TICKET" name="MAIN_MAIL_SMTP_PORT_TICKET" size="3" value="'.$mainport.'">'; 293 print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_TICKET_sav" name="MAIN_MAIL_SMTP_PORT_TICKET_sav" value="'.$mainport.'">'; 294 print '<span id="smtp_port_mess">'.$langs->trans("SeeLocalSendMailSetup").'</span>'; 295 } else { 296 $text = (!empty($mainport) ? $mainport : $smtpport); 297 $htmltext = $langs->trans("ContactSuperAdminForChange"); 298 print $form->textwithpicto($text, $htmltext, 1, 'superadmin'); 299 print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_TICKET" name="MAIN_MAIL_SMTP_PORT_TICKET" value="'.$mainport.'">'; 300 } 301 } 302 print '</td></tr>'; 303 304 // ID 305 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) 306 { 307 $mainstmpid = (!empty($conf->global->MAIN_MAIL_SMTPS_ID_TICKET) ? $conf->global->MAIN_MAIL_SMTPS_ID_TICKET : ''); 308 print '<tr class="drag drop oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'; 309 // SuperAdministrator access only 310 if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) 311 { 312 print '<input class="flat" name="MAIN_MAIL_SMTPS_ID_TICKET" size="32" value="'.$mainstmpid.'">'; 313 } else { 314 $htmltext = $langs->trans("ContactSuperAdminForChange"); 315 print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID_TICKET, $htmltext, 1, 'superadmin'); 316 print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID_TICKET" value="'.$mainstmpid.'">'; 317 } 318 print '</td></tr>'; 319 } 320 321 // PW 322 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) 323 { 324 $mainsmtppw = (!empty($conf->global->MAIN_MAIL_SMTPS_PW_TICKET) ? $conf->global->MAIN_MAIL_SMTPS_PW_TICKET : ''); 325 print '<tr class="drag drop oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'; 326 // SuperAdministrator access only 327 if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) 328 { 329 print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW_TICKET" size="32" value="'.$mainsmtppw.'">'; 330 } else { 331 $htmltext = $langs->trans("ContactSuperAdminForChange"); 332 print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW_TICKET, $htmltext, 1, 'superadmin'); 333 print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW_TICKET" value="'.$mainsmtppw.'">'; 334 } 335 print '</td></tr>'; 336 } 337 338 // TLS 339 340 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>'; 341 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) 342 { 343 if (function_exists('openssl_open')) 344 { 345 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); 346 } else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')'; 347 } else print yn(0).' ('.$langs->trans("NotSupported").')'; 348 print '</td></tr>'; 349 350 // STARTTLS 351 352 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>'; 353 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer')))) 354 { 355 if (function_exists('openssl_open')) 356 { 357 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); 358 } else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')'; 359 } else print yn(0).' ('.$langs->trans("NotSupported").')'; 360 print '</td></tr>'; 361 362 print '</table>'; 363 364 print dol_get_fiche_end(); 365 366 print '<br><div class="center">'; 367 print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'">'; 368 print ' '; 369 print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">'; 370 print '</div>'; 371 372 print '</form>'; 373} else { 374 print dol_get_fiche_head($head, 'common_ticket', '', -1); 375 376 print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n"; 377 print "<br>\n"; 378 379 print '<table class="noborder centpercent">'; 380 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>'; 381 382 // Method 383 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>'; 384 $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE_TICKET]; 385 if (empty($text)) $text = $langs->trans("Undefined").img_warning(); 386 print $text; 387 print '</td></tr>'; 388 389 if (!empty($conf->global->MAIN_MAIL_SENDMODE_TICKET) && $conf->global->MAIN_MAIL_SENDMODE_TICKET != 'default') 390 { 391 // Host server 392 if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && $conf->global->MAIN_MAIL_SENDMODE_TICKET == 'mail')) 393 { 394 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>'; 395 } else { 396 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>'; 397 } 398 399 // Port 400 if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && $conf->global->MAIN_MAIL_SENDMODE_TICKET == 'mail')) 401 { 402 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>'; 403 } else { 404 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>'; 405 } 406 407 // SMTPS ID 408 if (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer'))) 409 { 410 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_ID_TICKET.'</td></tr>'; 411 } 412 413 // SMTPS PW 414 if (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer'))) 415 { 416 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>'; 417 } 418 419 // TLS 420 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>'; 421 if (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer'))) 422 { 423 if (function_exists('openssl_open')) 424 { 425 print yn($conf->global->MAIN_MAIL_EMAIL_TLS_TICKET); 426 } else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')'; 427 } else print yn(0).' ('.$langs->trans("NotSupported").')'; 428 print '</td></tr>'; 429 430 // STARTTLS 431 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>'; 432 if (isset($conf->global->MAIN_MAIL_SENDMODE_TICKET) && in_array($conf->global->MAIN_MAIL_SENDMODE_TICKET, array('smtps', 'swiftmailer'))) 433 { 434 if (function_exists('openssl_open')) 435 { 436 print yn($conf->global->MAIN_MAIL_EMAIL_STARTTLS_TICKET); 437 } else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')'; 438 } else print yn(0).' ('.$langs->trans("NotSupported").')'; 439 print '</td></tr>'; 440 } 441 442 print '</table>'; 443 444 print dol_get_fiche_end(); 445 446 447 if ($conf->global->MAIN_MAIL_SENDMODE_TICKET == 'mail' && empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) 448 { 449 print '<br>'; 450 /* 451 // Warning 1 452 if ($linuxlike) 453 { 454 $sendmailoption=ini_get('mail.force_extra_parameters'); 455 if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption)) 456 { 457 print info_admin($langs->trans("SendmailOptionNotComplete")); 458 } 459 }*/ 460 // Warning 2 461 print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA")); 462 } 463 464 465 // Buttons for actions 466 467 print '<div class="tabsAction">'; 468 469 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>'; 470 471 if (!empty($conf->global->MAIN_MAIL_SENDMODE_TICKET) && $conf->global->MAIN_MAIL_SENDMODE_TICKET != 'default') 472 { 473 if ($conf->global->MAIN_MAIL_SENDMODE_TICKET != 'mail' || !$linuxlike) 474 { 475 if (function_exists('fsockopen') && $port && $server) 476 { 477 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>'; 478 } 479 } else { 480 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>'; 481 } 482 483 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&mode=init">'.$langs->trans("DoTestSend").'</a>'; 484 485 if (!empty($conf->fckeditor->enabled)) 486 { 487 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&mode=init">'.$langs->trans("DoTestSendHTML").'</a>'; 488 } 489 } 490 491 print '</div>'; 492 493 494 if ($conf->global->MAIN_MAIL_SENDMODE_TICKET == 'mail' && !in_array($action, array('testconnect', 'test', 'testhtml'))) 495 { 496 $text = $langs->trans("WarningPHPMail"); 497 print info_admin($text); 498 } 499 500 // Run the test to connect 501 if ($action == 'testconnect') 502 { 503 print load_fiche_titre($langs->trans("DoTestServerAvailability")); 504 505 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; 506 $mail = new CMailFile('', '', '', '', array(), array(), array(), '', '', 0, '', '', '', '', $trackid, $sendcontext); 507 508 $result = $mail->check_server_port($server, $port); 509 if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort", $server, $port).'</div>'; 510 else { 511 $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort", $server, $port); 512 513 if ($mail->error) { 514 $errormsg .= ' - '.$mail->error; 515 } 516 517 setEventMessages($errormsg, null, 'errors'); 518 } 519 print '<br>'; 520 } 521 522 // Show email send test form 523 if ($action == 'test' || $action == 'testhtml') 524 { 525 print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>'; 526 print load_fiche_titre($action == 'testhtml' ? $langs->trans("DoTestSendHTML") : $langs->trans("DoTestSend")); 527 528 print dol_get_fiche_head(''); 529 530 // Cree l'objet formulaire mail 531 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; 532 $formmail = new FormMail($db); 533 $formmail->fromname = (GETPOSTISSET('fromname') ? $_POST['fromname'] : $conf->global->MAIN_MAIL_EMAIL_FROM); 534 $formmail->frommail = (GETPOSTISSET('frommail') ? $_POST['frommail'] : $conf->global->MAIN_MAIL_EMAIL_FROM); 535 $formmail->trackid = (($action == 'testhtml') ? "testhtml" : "test"); 536 $formmail->withfromreadonly = 0; 537 $formmail->withsubstit = 0; 538 $formmail->withfrom = 1; 539 $formmail->witherrorsto = 1; 540 $formmail->withto = (!empty($_POST['sendto']) ? GETPOST('sendto', 'restricthtml') : ($user->email ? $user->email : 1)); 541 $formmail->withtocc = (!empty($_POST['sendtocc']) ? GETPOST('sendtocc', 'restricthtml') : 1); // ! empty to keep field if empty 542 $formmail->withtoccc = (!empty($_POST['sendtoccc']) ? GETPOST('sendtoccc', 'restricthtml') : 1); // ! empty to keep field if empty 543 $formmail->withtopic = (GETPOSTISSET('subject') ? GETPOST('subject') : $langs->trans("Test")); 544 $formmail->withtopicreadonly = 0; 545 $formmail->withfile = 2; 546 $formmail->withbody = (GETPOSTISSET('message') ? GETPOST('message', 'restricthtml') : ($action == 'testhtml' ? $langs->transnoentities("PredefinedMailTestHtml") : $langs->transnoentities("PredefinedMailTest"))); 547 $formmail->withbodyreadonly = 0; 548 $formmail->withcancel = 1; 549 $formmail->withdeliveryreceipt = 1; 550 $formmail->withfckeditor = ($action == 'testhtml' ? 1 : 0); 551 $formmail->ckeditortoolbar = 'dolibarr_mailings'; 552 // Tableau des substitutions 553 $formmail->substit = $substitutionarrayfortest; 554 // Tableau des parametres complementaires du post 555 $formmail->param["action"] = "send"; 556 $formmail->param["models"] = "body"; 557 $formmail->param["mailid"] = 0; 558 $formmail->param["returnurl"] = $_SERVER["PHP_SELF"]; 559 560 // Init list of files 561 if (GETPOST("mode") == 'init') 562 { 563 $formmail->clear_attached_files(); 564 } 565 566 print $formmail->get_form('addfile', 'removefile'); 567 568 print dol_get_fiche_end(); 569 } 570} 571 572// End of page 573llxFooter(); 574$db->close(); 575