card.php 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2019 Laurent Destailleur <eldy@uers.sourceforge.net>
  4. * Copyright (C) 2005-2016 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2021 Waël Almoman <info@almoman.com>
  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/comm/mailing/card.php
  22. * \ingroup mailing
  23. * \brief Fiche mailing, onglet general
  24. */
  25. if (!defined('NOSTYLECHECK')) {
  26. define('NOSTYLECHECK', '1');
  27. }
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  37. // Load translation files required by the page
  38. $langs->load("mails");
  39. $id = (GETPOST('mailid', 'int') ? GETPOST('mailid', 'int') : GETPOST('id', 'int'));
  40. $action = GETPOST('action', 'aZ09');
  41. $cancel = GETPOST('cancel');
  42. $confirm = GETPOST('confirm', 'alpha');
  43. $urlfrom = GETPOST('urlfrom');
  44. $object = new Mailing($db);
  45. $result = $object->fetch($id);
  46. $extrafields = new ExtraFields($db);
  47. // fetch optionals attributes and labels
  48. $extrafields->fetch_name_optionals_label($object->table_element);
  49. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  50. $hookmanager->initHooks(array('mailingcard', 'globalcard'));
  51. // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
  52. $object->substitutionarray = FormMail::getAvailableSubstitKey('emailing');
  53. // Set $object->substitutionarrayfortest
  54. $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $user->signature : '');
  55. $targetobject = null; // Not defined with mass emailing
  56. $parameters = array('mode'=>'emailing');
  57. $substitutionarray = FormMail::getAvailableSubstitKey('emailing', $targetobject);
  58. $object->substitutionarrayfortest = $substitutionarray;
  59. // List of sending methods
  60. $listofmethods = array();
  61. $listofmethods['mail'] = 'PHP mail function';
  62. $listofmethods['smtps'] = 'SMTP/SMTPS socket library';
  63. // Security check
  64. if (empty($user->rights->mailing->lire) || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->socid > 0)) {
  65. accessforbidden();
  66. }
  67. /*
  68. * Actions
  69. */
  70. $parameters = array();
  71. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  72. if ($reshook < 0) {
  73. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  74. }
  75. if (empty($reshook)) {
  76. // Action clone object
  77. if ($action == 'confirm_clone' && $confirm == 'yes') {
  78. if (!GETPOST("clone_content", 'alpha') && !GETPOST("clone_receivers", 'alpha')) {
  79. setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
  80. } else {
  81. $result = $object->createFromClone($user, $object->id, GETPOST("clone_content", 'alpha'), GETPOST("clone_receivers", 'alpha'));
  82. if ($result > 0) {
  83. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
  84. exit;
  85. } else {
  86. setEventMessages($object->error, $object->errors, 'errors');
  87. }
  88. }
  89. $action = '';
  90. }
  91. // Action send emailing for everybody
  92. if ($action == 'sendallconfirmed' && $confirm == 'yes') {
  93. if (empty($conf->global->MAILING_LIMIT_SENDBYWEB)) {
  94. // As security measure, we don't allow send from the GUI
  95. setEventMessages($langs->trans("MailingNeedCommand"), null, 'warnings');
  96. setEventMessages('<textarea cols="70" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', null, 'warnings');
  97. setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings');
  98. $action = '';
  99. } elseif ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
  100. setEventMessages($langs->trans("NotEnoughPermissions"), null, 'warnings');
  101. $action = '';
  102. } else {
  103. $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
  104. if ($object->statut == 0) {
  105. dol_print_error('', 'ErrorMailIsNotValidated');
  106. exit;
  107. }
  108. $id = $object->id;
  109. $subject = $object->sujet;
  110. $message = $object->body;
  111. $from = $object->email_from;
  112. $replyto = $object->email_replyto;
  113. $errorsto = $object->email_errorsto;
  114. // Is the message in html
  115. $msgishtml = -1; // Unknown by default
  116. if (preg_match('/[\s\t]*<html>/i', $message)) {
  117. $msgishtml = 1;
  118. }
  119. // Warning, we must not use begin-commit transaction here
  120. // because we want to save update for each mail sent.
  121. $nbok = 0; $nbko = 0;
  122. // We choose mails not already sent for this mailing (statut=0)
  123. // or sent in error (statut=-1)
  124. $sql = "SELECT mc.rowid, mc.fk_mailing, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
  125. $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
  126. $sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".((int) $object->id);
  127. $sql .= " ORDER BY mc.statut DESC"; // first status 0, then status -1
  128. dol_syslog("card.php: select targets", LOG_DEBUG);
  129. $resql = $db->query($sql);
  130. if ($resql) {
  131. $num = $db->num_rows($resql); // Number of possible recipients
  132. if ($num) {
  133. dol_syslog("comm/mailing/card.php: nb of targets = ".$num, LOG_DEBUG);
  134. $now = dol_now();
  135. // Positioning date of start sending
  136. $sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".((int) $object->id);
  137. $resql2 = $db->query($sql);
  138. if (!$resql2) {
  139. dol_print_error($db);
  140. }
  141. $thirdpartystatic = new Societe($db);
  142. // Loop on each email and send it
  143. $i = 0;
  144. while ($i < $num && $i < $conf->global->MAILING_LIMIT_SENDBYWEB) {
  145. // Here code is common with same loop ino mailing-send.php
  146. $res = 1;
  147. $now = dol_now();
  148. $obj = $db->fetch_object($resql);
  149. // sendto en RFC2822
  150. $sendto = str_replace(',', ' ', dolGetFirstLastname($obj->firstname, $obj->lastname))." <".$obj->email.">";
  151. // Make substitutions on topic and body. From (AA=YY;BB=CC;...) we keep YY, CC, ...
  152. $other = explode(';', $obj->other);
  153. $tmpfield = explode('=', $other[0], 2); $other1 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
  154. $tmpfield = explode('=', $other[1], 2); $other2 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
  155. $tmpfield = explode('=', $other[2], 2); $other3 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
  156. $tmpfield = explode('=', $other[3], 2); $other4 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
  157. $tmpfield = explode('=', $other[4], 2); $other5 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
  158. $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $user->signature : '');
  159. $targetobject = null; // Not defined with mass emailing
  160. $parameters = array('mode'=>'emailing');
  161. $substitutionarray = getCommonSubstitutionArray($langs, 0, array('object', 'objectamount'), $targetobject); // Note: On mass emailing, this is null because be don't know object
  162. // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
  163. $substitutionarray['__ID__'] = $obj->source_id;
  164. if ($obj->source_type == "thirdparty") {
  165. $result = $thirdpartystatic->fetch($obj->source_id);
  166. if ($result > 0) {
  167. $substitutionarray['__THIRDPARTY_CUSTOMER_CODE__'] = $thirdpartystatic->code_client;
  168. } else {
  169. $substitutionarray['__THIRDPARTY_CUSTOMER_CODE__'] = '';
  170. }
  171. }
  172. $substitutionarray['__EMAIL__'] = $obj->email;
  173. $substitutionarray['__LASTNAME__'] = $obj->lastname;
  174. $substitutionarray['__FIRSTNAME__'] = $obj->firstname;
  175. $substitutionarray['__MAILTOEMAIL__'] = '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>';
  176. $substitutionarray['__OTHER1__'] = $other1;
  177. $substitutionarray['__OTHER2__'] = $other2;
  178. $substitutionarray['__OTHER3__'] = $other3;
  179. $substitutionarray['__OTHER4__'] = $other4;
  180. $substitutionarray['__OTHER5__'] = $other5;
  181. $substitutionarray['__USER_SIGNATURE__'] = $signature; // Signature is empty when ran from command line or taken from user in parameter)
  182. $substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.urlencode($obj->tag).'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'&email='.urlencode($obj->email).'&mtid='.$obj->rowid.'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
  183. $substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.urlencode($obj->tag).'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'&email='.urlencode($obj->email).'&mtid='.$obj->rowid.'" target="_blank" rel="noopener noreferrer">'.$langs->trans("MailUnsubcribe").'</a>';
  184. $substitutionarray['__UNSUBSCRIBE_URL__'] = DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.urlencode($obj->tag).'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'&email='.urlencode($obj->email).'&mtid='.$obj->rowid;
  185. $onlinepaymentenabled = 0;
  186. if (!empty($conf->paypal->enabled)) {
  187. $onlinepaymentenabled++;
  188. }
  189. if (!empty($conf->paybox->enabled)) {
  190. $onlinepaymentenabled++;
  191. }
  192. if (!empty($conf->stripe->enabled)) {
  193. $onlinepaymentenabled++;
  194. }
  195. if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
  196. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  197. $substitutionarray['__ONLINEPAYMENTLINK_MEMBER__'] = getHtmlOnlinePaymentLink('member', $obj->source_id);
  198. $substitutionarray['__ONLINEPAYMENTLINK_DONATION__'] = getHtmlOnlinePaymentLink('donation', $obj->source_id);
  199. $substitutionarray['__ONLINEPAYMENTLINK_ORDER__'] = getHtmlOnlinePaymentLink('order', $obj->source_id);
  200. $substitutionarray['__ONLINEPAYMENTLINK_INVOICE__'] = getHtmlOnlinePaymentLink('invoice', $obj->source_id);
  201. $substitutionarray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = getHtmlOnlinePaymentLink('contractline', $obj->source_id);
  202. $substitutionarray['__SECUREKEYPAYMENT__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
  203. if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
  204. $substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
  205. $substitutionarray['__SECUREKEYPAYMENT_DONATION__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
  206. $substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
  207. $substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
  208. $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
  209. } else {
  210. $substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'member'.$obj->source_id, 2);
  211. $substitutionarray['__SECUREKEYPAYMENT_DONATION__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'donation'.$obj->source_id, 2);
  212. $substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'order'.$obj->source_id, 2);
  213. $substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'invoice'.$obj->source_id, 2);
  214. $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'contractline'.$obj->source_id, 2);
  215. }
  216. }
  217. if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
  218. $substitutionarray['__PUBLICLINK_NEWMEMBERFORM__'] = '<a target="_blank" rel="noopener noreferrer" href="'.DOL_MAIN_URL_ROOT.'/public/members/new.php'.((!empty($conf->multicompany->enabled)) ? '?entity='.$conf->entity : '').'">'.$langs->trans('BlankSubscriptionForm'). '</a>';
  219. }
  220. /* For backward compatibility, deprecated */
  221. if (!empty($conf->paypal->enabled) && !empty($conf->global->PAYPAL_SECURITY_TOKEN)) {
  222. $substitutionarray['__SECUREKEYPAYPAL__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
  223. if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
  224. $substitutionarray['__SECUREKEYPAYPAL_MEMBER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
  225. } else {
  226. $substitutionarray['__SECUREKEYPAYPAL_MEMBER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'membersubscription'.$obj->source_id, 2);
  227. }
  228. if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
  229. $substitutionarray['__SECUREKEYPAYPAL_ORDER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
  230. } else {
  231. $substitutionarray['__SECUREKEYPAYPAL_ORDER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'order'.$obj->source_id, 2);
  232. }
  233. if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
  234. $substitutionarray['__SECUREKEYPAYPAL_INVOICE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
  235. } else {
  236. $substitutionarray['__SECUREKEYPAYPAL_INVOICE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'invoice'.$obj->source_id, 2);
  237. }
  238. if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
  239. $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
  240. } else {
  241. $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'contractline'.$obj->source_id, 2);
  242. }
  243. }
  244. //$substitutionisok=true;
  245. complete_substitutions_array($substitutionarray, $langs);
  246. $newsubject = make_substitutions($subject, $substitutionarray);
  247. $newmessage = make_substitutions($message, $substitutionarray, null, 0);
  248. $moreinheader = '';
  249. if (preg_match('/__UNSUBSCRIBE__/', $message)) {
  250. $moreinheader = "List-Unsubscribe: <__UNSUBSCRIBE_URL__>\n";
  251. $moreinheader = make_substitutions($moreinheader, $substitutionarray);
  252. }
  253. $arr_file = array();
  254. $arr_mime = array();
  255. $arr_name = array();
  256. $arr_css = array();
  257. $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
  258. if (count($listofpaths)) {
  259. foreach ($listofpaths as $key => $val) {
  260. $arr_file[] = $listofpaths[$key]['fullname'];
  261. $arr_mime[] = dol_mimetype($listofpaths[$key]['name']);
  262. $arr_name[] = $listofpaths[$key]['name'];
  263. }
  264. }
  265. // Mail making
  266. $trackid = 'emailing-'.$obj->fk_mailing.'-'.$obj->rowid;
  267. $mail = new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $errorsto, $arr_css, $trackid, $moreinheader, 'emailing');
  268. if ($mail->error) {
  269. $res = 0;
  270. }
  271. /*if (! $substitutionisok)
  272. {
  273. $mail->error='Some substitution failed';
  274. $res=0;
  275. }*/
  276. // Send mail
  277. if ($res) {
  278. $res = $mail->sendfile();
  279. }
  280. if ($res) {
  281. // Mail successful
  282. $nbok++;
  283. dol_syslog("comm/mailing/card.php: ok for #".$i.($mail->error ? ' - '.$mail->error : ''), LOG_DEBUG);
  284. $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
  285. $sql .= " SET statut=1, date_envoi = '".$db->idate($now)."' WHERE rowid=".((int) $obj->rowid);
  286. $resql2 = $db->query($sql);
  287. if (!$resql2) {
  288. dol_print_error($db);
  289. } else {
  290. //if cheack read is use then update prospect contact status
  291. if (strpos($message, '__CHECK_READ__') !== false) {
  292. //Update status communication of thirdparty prospect
  293. $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".((int) $obj->rowid).")";
  294. dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
  295. $resql2 = $db->query($sql);
  296. if (!$resql2) {
  297. dol_print_error($db);
  298. }
  299. //Update status communication of contact prospect
  300. $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".((int) $obj->rowid)." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
  301. dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
  302. $resql2 = $db->query($sql);
  303. if (!$resql2) {
  304. dol_print_error($db);
  305. }
  306. }
  307. }
  308. if (!empty($conf->global->MAILING_DELAY)) {
  309. dol_syslog("Wait a delay of MAILING_DELAY=".$conf->global->MAILING_DELAY);
  310. usleep((float) $conf->global->MAILING_DELAY * 1000000);
  311. }
  312. //test if CHECK READ change statut prospect contact
  313. } else {
  314. // Mail failed
  315. $nbko++;
  316. dol_syslog("comm/mailing/card.php: error for #".$i.($mail->error ? ' - '.$mail->error : ''), LOG_WARNING);
  317. $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
  318. $sql .= " SET statut=-1, error_text='".$db->escape($mail->error)."', date_envoi='".$db->idate($now)."' WHERE rowid=".((int) $obj->rowid);
  319. $resql2 = $db->query($sql);
  320. if (!$resql2) {
  321. dol_print_error($db);
  322. }
  323. }
  324. $i++;
  325. }
  326. } else {
  327. setEventMessages($langs->transnoentitiesnoconv("NoMoreRecipientToSendTo"), null, 'mesgs');
  328. }
  329. // Loop finished, set global statut of mail
  330. if ($nbko > 0) {
  331. $statut = 2; // Status 'sent partially' (because at least one error)
  332. if ($nbok > 0) {
  333. setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients", $nbok), null, 'mesgs');
  334. } else {
  335. setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients", $nbok), null, 'mesgs');
  336. }
  337. } else {
  338. if ($nbok >= $num) {
  339. $statut = 3; // Send to everybody
  340. setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients", $nbok), null, 'mesgs');
  341. } else {
  342. $statut = 2; // Status 'sent partially' (because not send to everybody)
  343. setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients", $nbok), null, 'mesgs');
  344. }
  345. }
  346. $sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".((int) $statut)." WHERE rowid = ".((int) $object->id);
  347. dol_syslog("comm/mailing/card.php: update global status", LOG_DEBUG);
  348. $resql2 = $db->query($sql);
  349. if (!$resql2) {
  350. dol_print_error($db);
  351. }
  352. } else {
  353. dol_syslog($db->error());
  354. dol_print_error($db);
  355. }
  356. $object->fetch($id);
  357. $action = '';
  358. }
  359. }
  360. // Action send test emailing
  361. if ($action == 'send' && ! $cancel) {
  362. $error = 0;
  363. $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
  364. $object->sendto = GETPOST("sendto", 'alphawithlgt');
  365. if (!$object->sendto) {
  366. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MailTo")), null, 'errors');
  367. $error++;
  368. }
  369. if (!$error) {
  370. // Is the message in html
  371. $msgishtml = -1; // Unknow by default
  372. if (preg_match('/[\s\t]*<html>/i', $object->body)) {
  373. $msgishtml = 1;
  374. }
  375. // other are set at begin of page
  376. $object->substitutionarrayfortest['__EMAIL__'] = $object->sendto;
  377. $object->substitutionarrayfortest['__MAILTOEMAIL__'] = '<a href="mailto:'.$object->sendto.'">'.$object->sendto.'</a>';
  378. // Subject and message substitutions
  379. complete_substitutions_array($object->substitutionarrayfortest, $langs);
  380. $tmpsujet = make_substitutions($object->sujet, $object->substitutionarrayfortest);
  381. $tmpbody = make_substitutions($object->body, $object->substitutionarrayfortest);
  382. $arr_file = array();
  383. $arr_mime = array();
  384. $arr_name = array();
  385. $arr_css = array();
  386. // Add CSS
  387. if (!empty($object->bgcolor)) {
  388. $arr_css['bgcolor'] = (preg_match('/^#/', $object->bgcolor) ? '' : '#').$object->bgcolor;
  389. }
  390. if (!empty($object->bgimage)) {
  391. $arr_css['bgimage'] = $object->bgimage;
  392. }
  393. // Attached files
  394. $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
  395. if (count($listofpaths)) {
  396. foreach ($listofpaths as $key => $val) {
  397. $arr_file[] = $listofpaths[$key]['fullname'];
  398. $arr_mime[] = dol_mimetype($listofpaths[$key]['name']);
  399. $arr_name[] = $listofpaths[$key]['name'];
  400. }
  401. }
  402. $trackid = 'emailing-test';
  403. $mailfile = new CMailFile($tmpsujet, $object->sendto, $object->email_from, $tmpbody, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $object->email_errorsto, $arr_css, $trackid, '', 'emailing');
  404. $result = $mailfile->sendfile();
  405. if ($result) {
  406. setEventMessages($langs->trans("MailSuccessfulySent", $mailfile->getValidAddress($object->email_from, 2), $mailfile->getValidAddress($object->sendto, 2)), null, 'mesgs');
  407. $action = '';
  408. } else {
  409. setEventMessages($langs->trans("ResultKo").'<br>'.$mailfile->error.' '.$result, null, 'errors');
  410. $action = 'test';
  411. }
  412. }
  413. }
  414. // Action add emailing
  415. if ($action == 'add') {
  416. $mesgs = array();
  417. $object->email_from = (string) GETPOST("from", 'alphawithlgt'); // Must allow 'name <email>'
  418. $object->email_replyto = (string) GETPOST("replyto", 'alphawithlgt'); // Must allow 'name <email>'
  419. $object->email_errorsto = (string) GETPOST("errorsto", 'alphawithlgt'); // Must allow 'name <email>'
  420. $object->title = (string) GETPOST("title");
  421. $object->sujet = (string) GETPOST("sujet");
  422. $object->body = (string) GETPOST("bodyemail", 'restricthtml');
  423. $object->bgcolor = (string) GETPOST("bgcolor");
  424. $object->bgimage = (string) GETPOST("bgimage");
  425. if (!$object->title) {
  426. $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTitle"));
  427. }
  428. if (!$object->sujet) {
  429. $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTopic"));
  430. }
  431. if (!$object->body) {
  432. $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailMessage"));
  433. }
  434. if (!count($mesgs)) {
  435. if ($object->create($user) >= 0) {
  436. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  437. exit;
  438. }
  439. $mesgs[] = $object->error;
  440. $mesgs = array_merge($mesgs, $object->errors);
  441. }
  442. setEventMessages('', $mesgs, 'errors');
  443. $action = "create";
  444. }
  445. // Action update description of emailing
  446. if ($action == 'settitle' || $action == 'setemail_from' || $action == 'setreplyto' || $action == 'setemail_errorsto') {
  447. $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
  448. if ($action == 'settitle') {
  449. $object->title = trim(GETPOST('title', 'alpha'));
  450. } elseif ($action == 'setemail_from') {
  451. $object->email_from = trim(GETPOST('email_from', 'alphawithlgt')); // Must allow 'name <email>'
  452. } elseif ($action == 'setemail_replyto') {
  453. $object->email_replyto = trim(GETPOST('email_replyto', 'alphawithlgt')); // Must allow 'name <email>'
  454. } elseif ($action == 'setemail_errorsto') {
  455. $object->email_errorsto = trim(GETPOST('email_errorsto', 'alphawithlgt')); // Must allow 'name <email>'
  456. } elseif ($action == 'settitle' && empty($object->title)) {
  457. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTitle"));
  458. } elseif ($action == 'setfrom' && empty($object->email_from)) {
  459. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailFrom"));
  460. }
  461. if (!$mesg) {
  462. if ($object->update($user) >= 0) {
  463. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  464. exit;
  465. }
  466. $mesg = $object->error;
  467. }
  468. setEventMessages($mesg, $mesgs, 'errors');
  469. $action = "";
  470. }
  471. /*
  472. * Action of adding a file in email form
  473. */
  474. if (GETPOST('addfile')) {
  475. $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
  476. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  477. // Set tmp user directory
  478. dol_add_file_process($upload_dir, 0, 0, 'addedfile', '', null, '', 0);
  479. $action = "edit";
  480. }
  481. // Action of file remove
  482. if (GETPOST("removedfile")) {
  483. $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
  484. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  485. dol_remove_file_process(GETPOST('removedfile'), 0, 0); // We really delete file linked to mailing
  486. $action = "edit";
  487. }
  488. // Action of emailing update
  489. if ($action == 'update' && !GETPOST("removedfile") && !$cancel) {
  490. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  491. $isupload = 0;
  492. if (!$isupload) {
  493. $mesgs = array();
  494. $object->sujet = (string) GETPOST("sujet");
  495. $object->body = (string) GETPOST("bodyemail", 'restricthtml');
  496. $object->bgcolor = (string) GETPOST("bgcolor");
  497. $object->bgimage = (string) GETPOST("bgimage");
  498. if (!$object->sujet) {
  499. $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTopic"));
  500. }
  501. if (!$object->body) {
  502. $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailMessage"));
  503. }
  504. if (!count($mesgs)) {
  505. if ($object->update($user) >= 0) {
  506. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  507. exit;
  508. }
  509. $mesgs[] = $object->error;
  510. $mesgs = array_merge($mesgs, $object->errors);
  511. }
  512. setEventMessages('', $mesgs, 'errors');
  513. $action = "edit";
  514. } else {
  515. $action = "edit";
  516. }
  517. }
  518. // Action of validation confirmation
  519. if ($action == 'confirm_valid' && $confirm == 'yes') {
  520. if ($object->id > 0) {
  521. $object->valid($user);
  522. setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
  523. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  524. exit;
  525. } else {
  526. dol_print_error($db);
  527. }
  528. }
  529. // Action of validation confirmation
  530. if ($action == 'confirm_settodraft' && $confirm == 'yes') {
  531. if ($object->id > 0) {
  532. $result = $object->setStatut(0);
  533. if ($result > 0) {
  534. //setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
  535. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  536. exit;
  537. } else {
  538. setEventMessages($object->error, $object->errors, 'errors');
  539. }
  540. } else {
  541. dol_print_error($db);
  542. }
  543. }
  544. // Resend
  545. if ($action == 'confirm_reset' && $confirm == 'yes') {
  546. if ($object->id > 0) {
  547. $db->begin();
  548. $result = $object->valid($user);
  549. if ($result > 0) {
  550. $result = $object->reset_targets_status($user);
  551. }
  552. if ($result > 0) {
  553. $db->commit();
  554. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  555. exit;
  556. } else {
  557. setEventMessages($object->error, $object->errors, 'errors');
  558. $db->rollback();
  559. }
  560. } else {
  561. dol_print_error($db);
  562. }
  563. }
  564. // Action of delete confirmation
  565. if ($action == 'confirm_delete' && $confirm == 'yes') {
  566. if ($object->delete($object->id)) {
  567. $url = (!empty($urlfrom) ? $urlfrom : 'list.php');
  568. header("Location: ".$url);
  569. exit;
  570. }
  571. }
  572. if ($cancel) {
  573. $action = '';
  574. }
  575. }
  576. /*
  577. * View
  578. */
  579. $form = new Form($db);
  580. $htmlother = new FormOther($db);
  581. $help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
  582. llxHeader(
  583. '',
  584. $langs->trans("Mailing"),
  585. $help_url,
  586. '',
  587. 0,
  588. 0,
  589. array(
  590. '/includes/ace/src/ace.js',
  591. '/includes/ace/src/ext-statusbar.js',
  592. '/includes/ace/src/ext-language_tools.js',
  593. //'/includes/ace/src/ext-chromevox.js'
  594. ),
  595. array()
  596. );
  597. if ($action == 'create') {
  598. // EMailing in creation mode
  599. print '<form name="new_mailing" action="'.$_SERVER['PHP_SELF'].'" method="POST">'."\n";
  600. print '<input type="hidden" name="token" value="'.newToken().'">';
  601. print '<input type="hidden" name="action" value="add">';
  602. $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
  603. foreach ($object->substitutionarray as $key => $val) {
  604. $htmltext .= $key.' = '.$langs->trans($val).'<br>';
  605. }
  606. $htmltext .= '</i>';
  607. $availablelink = $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'availvar');
  608. //print '<a href="javascript:document_preview(\''.DOL_URL_ROOT.'/admin/modulehelp.php?id='.$objMod->numero.'\',\'text/html\',\''.dol_escape_js($langs->trans("Module")).'\')">'.img_picto($langs->trans("ClickToShowDescription"), $imginfo).'</a>';
  609. // Print mail form
  610. print load_fiche_titre($langs->trans("NewMailing"), $availablelink, 'object_email');
  611. print dol_get_fiche_head();
  612. print '<table class="border centpercent">';
  613. print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("MailTitle").'</td><td><input class="flat minwidth300" name="title" value="'.dol_escape_htmltag(GETPOST('title')).'" autofocus="autofocus"></td></tr>';
  614. print '<tr><td class="fieldrequired">'.$langs->trans("MailFrom").'</td><td><input class="flat minwidth200" name="from" value="'.$conf->global->MAILING_EMAIL_FROM.'"></td></tr>';
  615. print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td><input class="flat minwidth200" name="errorsto" value="'.(!empty($conf->global->MAILING_EMAIL_ERRORSTO) ? $conf->global->MAILING_EMAIL_ERRORSTO : $conf->global->MAIN_MAIL_ERRORS_TO).'"></td></tr>';
  616. // Other attributes
  617. $parameters = array();
  618. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  619. print $hookmanager->resPrint;
  620. if (empty($reshook)) {
  621. print $object->showOptionals($extrafields, 'create');
  622. }
  623. print '</table>';
  624. print '</br><br>';
  625. print '<table class="border centpercent">';
  626. print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("MailTopic").'</td><td><input class="flat minwidth200 quatrevingtpercent" name="sujet" value="'.dol_escape_htmltag(GETPOST('sujet', 'alphanohtml')).'"></td></tr>';
  627. print '<tr><td>'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
  628. print $htmlother->selectColor(GETPOST('bgcolor'), 'bgcolor', '', 0);
  629. print '</td></tr>';
  630. print '</table>';
  631. print '<div style="padding-top: 10px">';
  632. // wysiwyg editor
  633. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  634. $doleditor = new DolEditor('bodyemail', GETPOST('bodyemail', 'restricthtmlallowunvalid'), '', 600, 'dolibarr_mailings', '', true, true, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '90%');
  635. $doleditor->Create();
  636. print '</div>';
  637. print dol_get_fiche_end();
  638. print $form->buttonsSaveCancel("CreateMailing", '');
  639. print '</form>';
  640. } else {
  641. if ($object->id > 0) {
  642. $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
  643. $head = emailing_prepare_head($object);
  644. if ($action == 'settodraft') {
  645. // Confirmation back to draft
  646. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("SetToDraft"), $langs->trans("ConfirmUnvalidateEmailing"), "confirm_settodraft", '', '', 1);
  647. } elseif ($action == 'valid') {
  648. // Confirmation of mailing validation
  649. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ValidMailing"), $langs->trans("ConfirmValidMailing"), "confirm_valid", '', '', 1);
  650. } elseif ($action == 'reset') {
  651. // Confirm reset
  652. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ResetMailing"), $langs->trans("ConfirmResetMailing", $object->ref), "confirm_reset", '', '', 2);
  653. } elseif ($action == 'delete') {
  654. // Confirm delete
  655. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id.(!empty($urlfrom) ? '&urlfrom='.urlencode($urlfrom) : ''), $langs->trans("DeleteAMailing"), $langs->trans("ConfirmDeleteMailing"), "confirm_delete", '', '', 1);
  656. }
  657. if ($action != 'edit' && $action != 'edithtml') {
  658. print dol_get_fiche_head($head, 'card', $langs->trans("Mailing"), -1, 'email');
  659. /*
  660. * View mode mailing
  661. */
  662. if ($action == 'sendall') {
  663. // Define message to recommand from command line
  664. $sendingmode = $conf->global->EMAILING_MAIL_SENDMODE;
  665. if (empty($sendingmode)) {
  666. $sendingmode = $conf->global->MAIN_MAIL_SENDMODE;
  667. }
  668. if (empty($sendingmode)) {
  669. $sendingmode = 'mail'; // If not defined, we use php mail function
  670. }
  671. // MAILING_NO_USING_PHPMAIL may be defined or not.
  672. // MAILING_LIMIT_SENDBYWEB is always defined to something != 0 (-1=forbidden).
  673. // MAILING_LIMIT_SENDBYCLI may be defined ot not (-1=forbidden, 0 or undefined=no limit).
  674. // MAILING_LIMIT_SENDBYDAY may be defined ot not (0 or undefined=no limit).
  675. if (!empty($conf->global->MAILING_NO_USING_PHPMAIL) && $sendingmode == 'mail') {
  676. // EMailing feature may be a spam problem, so when you host several users/instance, having this option may force each user to use their own SMTP agent.
  677. // You ensure that every user is using its own SMTP server when using the mass emailing module.
  678. $linktoadminemailbefore = '<a href="'.DOL_URL_ROOT.'/admin/mails_emailing.php">';
  679. $linktoadminemailend = '</a>';
  680. setEventMessages($langs->trans("MailSendSetupIs", $listofmethods[$sendingmode]), null, 'warnings');
  681. $messagetoshow = $langs->trans("MailSendSetupIs2", '{s1}', '{s2}', '{s3}', '{s4}');
  682. $messagetoshow = str_replace('{s1}', $linktoadminemailbefore, $messagetoshow);
  683. $messagetoshow = str_replace('{s2}', $linktoadminemailend, $messagetoshow);
  684. $messagetoshow = str_replace('{s3}', $langs->transnoentitiesnoconv("MAIN_MAIL_SENDMODE"), $messagetoshow);
  685. $messagetoshow = str_replace('{s4}', $listofmethods['smtps'], $messagetoshow);
  686. setEventMessages($messagetoshow, null, 'warnings');
  687. if (!empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) {
  688. setEventMessages($langs->trans("MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS), null, 'warnings');
  689. }
  690. $_GET["action"] = '';
  691. } elseif ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
  692. if (!empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') {
  693. setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
  694. }
  695. if (!empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') {
  696. setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
  697. }
  698. // The feature is forbidden from GUI, we show just message to use from command line.
  699. setEventMessages($langs->trans("MailingNeedCommand"), null, 'warnings');
  700. setEventMessages('<textarea cols="60" rows="'.ROWS_1.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', null, 'warnings');
  701. if ($conf->file->mailing_limit_sendbyweb != '-1') { // MAILING_LIMIT_SENDBYWEB was set to -1 in database, but it is allowed ot increase it.
  702. setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings'); // You can send online with constant...
  703. }
  704. $_GET["action"] = '';
  705. } else {
  706. if (!empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') {
  707. setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
  708. }
  709. if (!empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') {
  710. setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
  711. }
  712. $text = '';
  713. if (isset($conf->global->MAILING_LIMIT_SENDBYDAY) && $conf->global->MAILING_LIMIT_SENDBYDAY >= 0) {
  714. $text .= $langs->trans('WarningLimitSendByDay', $conf->global->MAILING_LIMIT_SENDBYDAY);
  715. $text .= '<br><br>';
  716. }
  717. $text .= $langs->trans('ConfirmSendingEmailing').'<br>';
  718. $text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
  719. if (!isset($conf->global->MAILING_LIMIT_SENDBYCLI) || $conf->global->MAILING_LIMIT_SENDBYCLI >= 0) {
  720. $text .= '<br><br>';
  721. $text .= $langs->trans("MailingNeedCommand");
  722. $text .= '<br><textarea cols="60" rows="'.ROWS_2.'" wrap="soft" disabled>php ./scripts/emailings/mailing-send.php '.$object->id.' '.$user->login.'</textarea>';
  723. }
  724. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('SendMailing'), $text, 'sendallconfirmed', '', '', 1, 330, 600, 0, $langs->trans("Confirm"), $langs->trans("Cancel"));
  725. }
  726. }
  727. $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  728. $morehtmlright = '';
  729. $nbtry = $nbok = 0;
  730. if ($object->statut == 2 || $object->statut == 3) {
  731. $nbtry = $object->countNbOfTargets('alreadysent');
  732. $nbko = $object->countNbOfTargets('alreadysentko');
  733. $morehtmlright .= ' ('.$nbtry.'/'.$object->nbemail;
  734. if ($nbko) {
  735. $morehtmlright .= ' - '.$nbko.' '.$langs->trans("Error");
  736. }
  737. $morehtmlright .= ') &nbsp; ';
  738. }
  739. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
  740. print '<div class="fichecenter">';
  741. print '<div class="underbanner clearboth"></div>';
  742. print '<table class="border centpercent tableforfield">';
  743. // Description
  744. print '<tr><td class="titlefield">';
  745. print $form->editfieldkey("MailTitle", 'title', $object->title, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
  746. print '</td><td>';
  747. print $form->editfieldval("MailTitle", 'title', $object->title, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
  748. print '</td></tr>';
  749. // From
  750. print '<tr><td>';
  751. print $form->editfieldkey("MailFrom", 'email_from', $object->email_from, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
  752. print '</td><td>';
  753. print $form->editfieldval("MailFrom", 'email_from', $object->email_from, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
  754. $email = CMailFile::getValidAddress($object->email_from, 2);
  755. if ($email && !isValidEmail($email)) {
  756. $langs->load("errors");
  757. print img_warning($langs->trans("ErrorBadEMail", $email));
  758. } elseif ($email && !isValidMailDomain($email)) {
  759. $langs->load("errors");
  760. print img_warning($langs->trans("ErrorBadMXDomain", $email));
  761. }
  762. print '</td></tr>';
  763. // Errors to
  764. print '<tr><td>';
  765. print $form->editfieldkey("MailErrorsTo", 'email_errorsto', $object->email_errorsto, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
  766. print '</td><td>';
  767. print $form->editfieldval("MailErrorsTo", 'email_errorsto', $object->email_errorsto, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
  768. $email = CMailFile::getValidAddress($object->email_errorsto, 2);
  769. if ($email && !isValidEmail($email)) {
  770. $langs->load("errors");
  771. print img_warning($langs->trans("ErrorBadEMail", $email));
  772. } elseif ($email && !isValidMailDomain($email)) {
  773. $langs->load("errors");
  774. print img_warning($langs->trans("ErrorBadMXDomain", $email));
  775. }
  776. print '</td></tr>';
  777. // Number of distinct emails
  778. print '<tr><td>';
  779. print $langs->trans("TotalNbOfDistinctRecipients");
  780. print '</td><td colspan="3">';
  781. $nbemail = ($object->nbemail ? $object->nbemail : 0);
  782. if (is_numeric($nbemail)) {
  783. $text = '';
  784. if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail))) {
  785. if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) {
  786. $text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
  787. } else {
  788. $text .= $langs->trans('SendingFromWebInterfaceIsNotAllowed');
  789. }
  790. }
  791. if (empty($nbemail)) {
  792. $nbemail .= ' '.img_warning('').' <span class="warning">'.$langs->trans("NoTargetYet").'</span>';
  793. }
  794. if ($text) {
  795. print $form->textwithpicto($nbemail, $text, 1, 'warning');
  796. } else {
  797. print $nbemail;
  798. }
  799. }
  800. print '</td></tr>';
  801. // Other attributes
  802. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  803. print '</table>';
  804. print "</div>";
  805. print dol_get_fiche_end();
  806. // Clone confirmation
  807. if ($action == 'clone') {
  808. // Create an array for form
  809. $formquestion = array(
  810. 'text' => $langs->trans("ConfirmClone"),
  811. array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneContent"), 'value' => 1),
  812. array('type' => 'checkbox', 'name' => 'clone_receivers', 'label' => $langs->trans("CloneReceivers"), 'value' => 0)
  813. );
  814. // Incomplete payment. On demande si motif = escompte ou autre
  815. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneEMailing', $object->ref), 'confirm_clone', $formquestion, 'yes', 2, 240);
  816. }
  817. /*
  818. * Actions Buttons
  819. */
  820. if (GETPOST('cancel', 'alpha') || $confirm == 'no' || $action == '' || in_array($action, array('settodraft', 'valid', 'delete', 'sendall', 'clone', 'test'))) {
  821. print "\n\n<div class=\"tabsAction\">\n";
  822. if (($object->statut == 1) && ($user->rights->mailing->valider || $object->user_validation == $user->id)) {
  823. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=settodraft&token='.newToken().'&id='.$object->id.'">'.$langs->trans("SetToDraft").'</a>';
  824. }
  825. if (($object->statut == 0 || $object->statut == 1 || $object->statut == 2) && $user->rights->mailing->creer) {
  826. if (!empty($conf->fckeditor->enabled) && !empty($conf->global->FCKEDITOR_ENABLE_MAILING)) {
  827. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans("EditWithEditor").'</a>';
  828. } else {
  829. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans("EditWithTextEditor").'</a>';
  830. }
  831. if (!empty($conf->use_javascript_ajax)) {
  832. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edithtml&token='.newToken().'&id='.$object->id.'">'.$langs->trans("EditHTMLSource").'</a>';
  833. }
  834. }
  835. //print '<a class="butAction" href="card.php?action=test&amp;id='.$object->id.'">'.$langs->trans("PreviewMailing").'</a>';
  836. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
  837. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("TestMailing").'</a>';
  838. } else {
  839. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=test&token='.newToken().'&id='.$object->id.'">'.$langs->trans("TestMailing").'</a>';
  840. }
  841. if ($object->statut == 0) {
  842. if ($object->nbemail <= 0) {
  843. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoTargetYet")).'">'.$langs->trans("ValidMailing").'</a>';
  844. } elseif (empty($user->rights->mailing->valider)) {
  845. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ValidMailing").'</a>';
  846. } else {
  847. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=valid&amp;id='.$object->id.'">'.$langs->trans("ValidMailing").'</a>';
  848. }
  849. }
  850. if (($object->statut == 1 || $object->statut == 2) && $object->nbemail > 0 && $user->rights->mailing->valider) {
  851. if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
  852. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("SendingFromWebInterfaceIsNotAllowed")).'">'.$langs->trans("SendMailing").'</a>';
  853. } elseif (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
  854. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("SendMailing").'</a>';
  855. } else {
  856. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=sendall&amp;id='.$object->id.'">'.$langs->trans("SendMailing").'</a>';
  857. }
  858. }
  859. if ($user->rights->mailing->creer) {
  860. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=clone&amp;object=emailing&amp;id='.$object->id.'">'.$langs->trans("ToClone").'</a>';
  861. }
  862. if (($object->statut == 2 || $object->statut == 3) && $user->rights->mailing->valider) {
  863. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
  864. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ResetMailing").'</a>';
  865. } else {
  866. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=reset&amp;id='.$object->id.'">'.$langs->trans("ResetMailing").'</a>';
  867. }
  868. }
  869. if (($object->statut <= 1 && $user->rights->mailing->creer) || $user->rights->mailing->supprimer) {
  870. if ($object->statut > 0 && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->delete)) {
  871. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("DeleteMailing").'</a>';
  872. } else {
  873. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$object->id.(!empty($urlfrom) ? '&urlfrom='.$urlfrom : '').'">'.$langs->trans("DeleteMailing").'</a>';
  874. }
  875. }
  876. print '</div>';
  877. }
  878. // Display of the TEST form
  879. if ($action == 'test') {
  880. print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
  881. print load_fiche_titre($langs->trans("TestMailing"));
  882. print dol_get_fiche_head(null, '', '', -1);
  883. // Create mail form object
  884. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  885. $formmail = new FormMail($db);
  886. $formmail->fromname = $object->email_from;
  887. $formmail->frommail = $object->email_from;
  888. $formmail->withsubstit = 1;
  889. $formmail->withfrom = 0;
  890. $formmail->withto = $user->email ? $user->email : 1;
  891. $formmail->withtocc = 0;
  892. $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
  893. $formmail->withtopic = 0;
  894. $formmail->withtopicreadonly = 1;
  895. $formmail->withfile = 0;
  896. $formmail->withbody = 0;
  897. $formmail->withbodyreadonly = 1;
  898. $formmail->withcancel = 1;
  899. $formmail->withdeliveryreceipt = 0;
  900. // Table of substitutions
  901. $formmail->substit = $object->substitutionarrayfortest;
  902. // Table of post's complementary params
  903. $formmail->param["action"] = "send";
  904. $formmail->param["models"] = 'none';
  905. $formmail->param["mailid"] = $object->id;
  906. $formmail->param["returnurl"] = $_SERVER['PHP_SELF']."?id=".$object->id;
  907. print $formmail->get_form();
  908. print '<br>';
  909. print dol_get_fiche_end();
  910. dol_set_focus('#sendto');
  911. }
  912. $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
  913. foreach ($object->substitutionarray as $key => $val) {
  914. $htmltext .= $key.' = '.$langs->trans($val).'<br>';
  915. }
  916. $htmltext .= '</i>';
  917. // Print mail content
  918. print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto('<span class="opacitymedium hideonsmartphone">'.$langs->trans("AvailableVariables").'</span>', $htmltext, 1, 'helpclickable', '', 0, 2, 'emailsubstitionhelp'), 'generic');
  919. print dol_get_fiche_head('', '', '', -1);
  920. print '<table class="bordernooddeven" width="100%">';
  921. // Subject
  922. print '<tr><td class="titlefield">'.$langs->trans("MailTopic").'</td><td colspan="3">'.$object->sujet.'</td></tr>';
  923. // Joined files
  924. print '<tr><td>'.$langs->trans("MailFile").'</td><td colspan="3">';
  925. // List of files
  926. $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
  927. if (count($listofpaths)) {
  928. foreach ($listofpaths as $key => $val) {
  929. print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
  930. print '<br>';
  931. }
  932. } else {
  933. print '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
  934. }
  935. print '</td></tr>';
  936. // Background color
  937. /*print '<tr><td width="15%">'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
  938. print $htmlother->selectColor($object->bgcolor,'bgcolor','',0);
  939. print '</td></tr>';*/
  940. print '</table>';
  941. // Message
  942. print '<div style="padding-top: 10px; background: '.($object->bgcolor ? (preg_match('/^#/', $object->bgcolor) ? '' : '#').$object->bgcolor : 'white').'">';
  943. if (empty($object->bgcolor) || strtolower($object->bgcolor) == 'ffffff') { // CKEditor does not apply the color of the div into its content area
  944. $readonly = 1;
  945. // wysiwyg editor
  946. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  947. $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', false, true, empty($conf->global->FCKEDITOR_ENABLE_MAILING) ? 0 : 1, 20, '90%', $readonly);
  948. $doleditor->Create();
  949. } else {
  950. print dol_htmlentitiesbr($object->body);
  951. }
  952. print '</div>';
  953. print dol_get_fiche_end();
  954. } else {
  955. /*
  956. * Edition mode mailing (CKeditor or HTML source)
  957. */
  958. print dol_get_fiche_head($head, 'card', $langs->trans("Mailing"), -1, 'email');
  959. $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  960. $morehtmlright = '';
  961. if ($object->statut == 2) {
  962. $morehtmlright .= ' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
  963. }
  964. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
  965. print '<div class="fichecenter">';
  966. print '<div class="underbanner clearboth"></div>';
  967. print '<table class="border centpercent">';
  968. /*
  969. print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td>';
  970. print '<td colspan="3">';
  971. print $form->showrefnav($object,'id', $linkback);
  972. print '</td></tr>';
  973. */
  974. // Topic
  975. print '<tr><td class="titlefield">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$object->title.'</td></tr>';
  976. // From
  977. print '<tr><td class="titlefield">'.$langs->trans("MailFrom").'</td><td colspan="3">'.dol_print_email($object->email_from, 0, 0, 0, 0, 1).'</td></tr>';
  978. // To
  979. print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1).'</td></tr>';
  980. // Number of distinct emails
  981. print '<tr><td>';
  982. print $langs->trans("TotalNbOfDistinctRecipients");
  983. print '</td><td colspan="3">';
  984. $nbemail = ($object->nbemail ? $object->nbemail : 0);
  985. if (is_numeric($nbemail)) {
  986. $text = '';
  987. if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || $object->statut == 2)) {
  988. if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) {
  989. $text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
  990. } else {
  991. $text .= $langs->trans('SendingFromWebInterfaceIsNotAllowed');
  992. }
  993. }
  994. if (empty($nbemail)) {
  995. $nbemail .= ' '.img_warning('').' <span class="warning">'.$langs->trans("NoTargetYet").'</span>';
  996. }
  997. if ($text) {
  998. print $form->textwithpicto($nbemail, $text, 1, 'warning');
  999. } else {
  1000. print $nbemail;
  1001. }
  1002. }
  1003. print '</td></tr>';
  1004. // Other attributes
  1005. $parameters = array();
  1006. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1007. print $hookmanager->resPrint;
  1008. if (empty($reshook)) {
  1009. print $object->showOptionals($extrafields, 'edit', $parameters);
  1010. }
  1011. print '</table>';
  1012. print '</div>';
  1013. print dol_get_fiche_end();
  1014. print "<br>\n";
  1015. print '<form name="edit_mailing" action="card.php" method="post" enctype="multipart/form-data">'."\n";
  1016. print '<input type="hidden" name="token" value="'.newToken().'">';
  1017. print '<input type="hidden" name="action" value="update">';
  1018. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1019. $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
  1020. foreach ($object->substitutionarray as $key => $val) {
  1021. $htmltext .= $key.' = '.$langs->trans($val).'<br>';
  1022. }
  1023. $htmltext .= '</i>';
  1024. // Print mail content
  1025. print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp'), 'generic');
  1026. print dol_get_fiche_head(null, '', '', -1);
  1027. print '<table class="bordernooddeven" width="100%">';
  1028. // Subject
  1029. print '<tr><td class="fieldrequired titlefield">'.$langs->trans("MailTopic").'</td><td colspan="3"><input class="flat quatrevingtpercent" type="text" name="sujet" value="'.$object->sujet.'"></td></tr>';
  1030. $trackid = ''; // TODO To avoid conflicts with 2 mass emailing, we should set a trackid here, even if we use another one into email header.
  1031. dol_init_file_process($upload_dir, $trackid);
  1032. // Joined files
  1033. $addfileaction = 'addfile';
  1034. print '<tr><td>'.$langs->trans("MailFile").'</td>';
  1035. print '<td colspan="3">';
  1036. // List of files
  1037. $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
  1038. // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
  1039. $out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
  1040. $out .= '<script type="text/javascript">';
  1041. $out .= 'jQuery(document).ready(function () {';
  1042. $out .= ' jQuery(".removedfile").click(function() {';
  1043. $out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());';
  1044. $out .= ' });';
  1045. $out .= '})';
  1046. $out .= '</script>'."\n";
  1047. if (count($listofpaths)) {
  1048. foreach ($listofpaths as $key => $val) {
  1049. $out .= '<div id="attachfile_'.$key.'">';
  1050. $out .= img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
  1051. $out .= ' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans("Search"), 'delete.png', '', '', 1).'" value="'.($key + 1).'" class="removedfile" id="removedfile_'.$key.'" name="removedfile_'.$key.'" />';
  1052. $out .= '<br></div>';
  1053. }
  1054. } else {
  1055. $out .= '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
  1056. }
  1057. // Add link to add file
  1058. $maxfilesizearray = getMaxFileSizeArray();
  1059. $maxmin = $maxfilesizearray['maxmin'];
  1060. if ($maxmin > 0) {
  1061. $out .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
  1062. }
  1063. $out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
  1064. $out .= ' ';
  1065. $out .= '<input type="submit" class="button" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
  1066. print $out;
  1067. print '</td></tr>';
  1068. // Background color
  1069. print '<tr><td>'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
  1070. print $htmlother->selectColor($object->bgcolor, 'bgcolor', '', 0);
  1071. print '</td></tr>';
  1072. print '</table>';
  1073. // Message
  1074. print '<div style="padding-top: 10px">';
  1075. if ($action == 'edit') {
  1076. // wysiwyg editor
  1077. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1078. $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, true, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '90%');
  1079. $doleditor->Create();
  1080. }
  1081. if ($action == 'edithtml') {
  1082. // HTML source editor
  1083. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1084. $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, true, 'ace', 20, '90%');
  1085. $doleditor->Create(0, '', false, 'HTML Source', 'php');
  1086. }
  1087. print '</div>';
  1088. print dol_get_fiche_end();
  1089. print '<div class="center">';
  1090. print '<input type="submit" class="button buttonforacesave button-save" value="'.$langs->trans("Save").'" name="save">';
  1091. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  1092. print '<input type="submit" class="button button-cancel" value="'.$langs->trans("Cancel").'" name="cancel">';
  1093. print '</div>';
  1094. print '</form>';
  1095. print '<br>';
  1096. }
  1097. } else {
  1098. dol_print_error($db, $object->error);
  1099. }
  1100. }
  1101. // End of page
  1102. llxFooter();
  1103. $db->close();