card.php 59 KB

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