mails_ticket.php 32 KB

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