mails_ticket.php 25 KB

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