card.php 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  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 = 'emailingtest';
  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. }
  441. setEventMessages(null, $mesgs, 'errors');
  442. $action = "create";
  443. }
  444. // Action update description of emailing
  445. if ($action == 'settitle' || $action == 'setemail_from' || $action == 'setreplyto' || $action == 'setemail_errorsto') {
  446. $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
  447. if ($action == 'settitle') {
  448. $object->title = trim(GETPOST('title', 'alpha'));
  449. } elseif ($action == 'setemail_from') {
  450. $object->email_from = trim(GETPOST('email_from', 'alphawithlgt')); // Must allow 'name <email>'
  451. } elseif ($action == 'setemail_replyto') {
  452. $object->email_replyto = trim(GETPOST('email_replyto', 'alphawithlgt')); // Must allow 'name <email>'
  453. } elseif ($action == 'setemail_errorsto') {
  454. $object->email_errorsto = trim(GETPOST('email_errorsto', 'alphawithlgt')); // Must allow 'name <email>'
  455. } elseif ($action == 'settitle' && empty($object->title)) {
  456. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTitle"));
  457. } elseif ($action == 'setfrom' && empty($object->email_from)) {
  458. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailFrom"));
  459. }
  460. if (!$mesg) {
  461. if ($object->update($user) >= 0) {
  462. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  463. exit;
  464. }
  465. $mesg = $object->error;
  466. }
  467. setEventMessages($mesg, $mesgs, 'errors');
  468. $action = "";
  469. }
  470. /*
  471. * Action of adding a file in email form
  472. */
  473. if (GETPOST('addfile')) {
  474. $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
  475. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  476. // Set tmp user directory
  477. dol_add_file_process($upload_dir, 0, 0, 'addedfile', '', null, '', 0);
  478. $action = "edit";
  479. }
  480. // Action of file remove
  481. if (GETPOST("removedfile")) {
  482. $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
  483. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  484. dol_remove_file_process(GETPOST('removedfile'), 0, 0); // We really delete file linked to mailing
  485. $action = "edit";
  486. }
  487. // Action of emailing update
  488. if ($action == 'update' && !GETPOST("removedfile") && !$cancel) {
  489. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  490. $isupload = 0;
  491. if (!$isupload) {
  492. $mesgs = array();
  493. $object->sujet = (string) GETPOST("sujet");
  494. $object->body = (string) GETPOST("bodyemail", 'restricthtml');
  495. $object->bgcolor = (string) GETPOST("bgcolor");
  496. $object->bgimage = (string) GETPOST("bgimage");
  497. if (!$object->sujet) {
  498. $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTopic"));
  499. }
  500. if (!$object->body) {
  501. $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailMessage"));
  502. }
  503. if (!count($mesgs)) {
  504. if ($object->update($user) >= 0) {
  505. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  506. exit;
  507. }
  508. $mesgs[] = $object->error;
  509. }
  510. setEventMessages($mesg, $mesgs, 'errors');
  511. $action = "edit";
  512. } else {
  513. $action = "edit";
  514. }
  515. }
  516. // Action of validation confirmation
  517. if ($action == 'confirm_valid' && $confirm == 'yes') {
  518. if ($object->id > 0) {
  519. $object->valid($user);
  520. setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
  521. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  522. exit;
  523. } else {
  524. dol_print_error($db);
  525. }
  526. }
  527. // Action of validation confirmation
  528. if ($action == 'confirm_settodraft' && $confirm == 'yes') {
  529. if ($object->id > 0) {
  530. $result = $object->setStatut(0);
  531. if ($result > 0) {
  532. //setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
  533. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  534. exit;
  535. } else {
  536. setEventMessages($object->error, $object->errors, 'errors');
  537. }
  538. } else {
  539. dol_print_error($db);
  540. }
  541. }
  542. // Resend
  543. if ($action == 'confirm_reset' && $confirm == 'yes') {
  544. if ($object->id > 0) {
  545. $db->begin();
  546. $result = $object->valid($user);
  547. if ($result > 0) {
  548. $result = $object->reset_targets_status($user);
  549. }
  550. if ($result > 0) {
  551. $db->commit();
  552. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  553. exit;
  554. } else {
  555. setEventMessages($object->error, $object->errors, 'errors');
  556. $db->rollback();
  557. }
  558. } else {
  559. dol_print_error($db);
  560. }
  561. }
  562. // Action of delete confirmation
  563. if ($action == 'confirm_delete' && $confirm == 'yes') {
  564. if ($object->delete($object->id)) {
  565. $url = (!empty($urlfrom) ? $urlfrom : 'list.php');
  566. header("Location: ".$url);
  567. exit;
  568. }
  569. }
  570. if ($cancel) {
  571. $action = '';
  572. }
  573. }
  574. /*
  575. * View
  576. */
  577. $form = new Form($db);
  578. $htmlother = new FormOther($db);
  579. $help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
  580. llxHeader(
  581. '',
  582. $langs->trans("Mailing"),
  583. $help_url,
  584. '',
  585. 0,
  586. 0,
  587. array(
  588. '/includes/ace/src/ace.js',
  589. '/includes/ace/src/ext-statusbar.js',
  590. '/includes/ace/src/ext-language_tools.js',
  591. //'/includes/ace/src/ext-chromevox.js'
  592. ),
  593. array()
  594. );
  595. if ($action == 'create') {
  596. // EMailing in creation mode
  597. print '<form name="new_mailing" action="'.$_SERVER['PHP_SELF'].'" method="POST">'."\n";
  598. print '<input type="hidden" name="token" value="'.newToken().'">';
  599. print '<input type="hidden" name="action" value="add">';
  600. $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
  601. foreach ($object->substitutionarray as $key => $val) {
  602. $htmltext .= $key.' = '.$langs->trans($val).'<br>';
  603. }
  604. $htmltext .= '</i>';
  605. $availablelink = $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'availvar');
  606. //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>';
  607. // Print mail form
  608. print load_fiche_titre($langs->trans("NewMailing"), $availablelink, 'object_email');
  609. print dol_get_fiche_head();
  610. print '<table class="border centpercent">';
  611. 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>';
  612. print '<tr><td class="fieldrequired">'.$langs->trans("MailFrom").'</td><td><input class="flat minwidth200" name="from" value="'.$conf->global->MAILING_EMAIL_FROM.'"></td></tr>';
  613. 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>';
  614. // Other attributes
  615. $parameters = array();
  616. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  617. print $hookmanager->resPrint;
  618. if (empty($reshook)) {
  619. print $object->showOptionals($extrafields, 'create');
  620. }
  621. print '</table>';
  622. print '</br><br>';
  623. print '<table class="border centpercent">';
  624. 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>';
  625. print '<tr><td>'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
  626. print $htmlother->selectColor(GETPOST('bgcolor'), 'bgcolor', '', 0);
  627. print '</td></tr>';
  628. print '</table>';
  629. print '<div style="padding-top: 10px">';
  630. // wysiwyg editor
  631. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  632. $doleditor = new DolEditor('bodyemail', GETPOST('bodyemail', 'restricthtmlallowunvalid'), '', 600, 'dolibarr_mailings', '', true, true, $conf->global->FCKEDITOR_ENABLE_MAILING, 20, '90%');
  633. $doleditor->Create();
  634. print '</div>';
  635. print dol_get_fiche_end();
  636. print $form->buttonsSaveCancel("CreateMailing", '');
  637. print '</form>';
  638. } else {
  639. if ($object->id > 0) {
  640. $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
  641. $head = emailing_prepare_head($object);
  642. if ($action == 'settodraft') {
  643. // Confirmation back to draft
  644. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("SetToDraft"), $langs->trans("ConfirmUnvalidateEmailing"), "confirm_settodraft", '', '', 1);
  645. } elseif ($action == 'valid') {
  646. // Confirmation of mailing validation
  647. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ValidMailing"), $langs->trans("ConfirmValidMailing"), "confirm_valid", '', '', 1);
  648. } elseif ($action == 'reset') {
  649. // Confirm reset
  650. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ResetMailing"), $langs->trans("ConfirmResetMailing", $object->ref), "confirm_reset", '', '', 2);
  651. } elseif ($action == 'delete') {
  652. // Confirm delete
  653. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id.(!empty($urlfrom) ? '&urlfrom='.urlencode($urlfrom) : ''), $langs->trans("DeleteAMailing"), $langs->trans("ConfirmDeleteMailing"), "confirm_delete", '', '', 1);
  654. }
  655. if ($action != 'edit' && $action != 'edithtml') {
  656. print dol_get_fiche_head($head, 'card', $langs->trans("Mailing"), -1, 'email');
  657. /*
  658. * View mode mailing
  659. */
  660. if ($action == 'sendall') {
  661. // Define message to recommand from command line
  662. $sendingmode = $conf->global->EMAILING_MAIL_SENDMODE;
  663. if (empty($sendingmode)) {
  664. $sendingmode = $conf->global->MAIN_MAIL_SENDMODE;
  665. }
  666. if (empty($sendingmode)) {
  667. $sendingmode = 'mail'; // If not defined, we use php mail function
  668. }
  669. // MAILING_NO_USING_PHPMAIL may be defined or not.
  670. // MAILING_LIMIT_SENDBYWEB is always defined to something != 0 (-1=forbidden).
  671. // MAILING_LIMIT_SENDBYCLI may be defined ot not (-1=forbidden, 0 or undefined=no limit).
  672. if (!empty($conf->global->MAILING_NO_USING_PHPMAIL) && $sendingmode == 'mail') {
  673. // 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.
  674. // You ensure that every user is using its own SMTP server when using the mass emailing module.
  675. $linktoadminemailbefore = '<a href="'.DOL_URL_ROOT.'/admin/mails_emailing.php">';
  676. $linktoadminemailend = '</a>';
  677. setEventMessages($langs->trans("MailSendSetupIs", $listofmethods[$sendingmode]), null, 'warnings');
  678. setEventMessages($langs->trans("MailSendSetupIs2", $linktoadminemailbefore, $linktoadminemailend, $langs->transnoentitiesnoconv("MAIN_MAIL_SENDMODE"), $listofmethods['smtps']), null, 'warnings');
  679. if (!empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) {
  680. setEventMessages($langs->trans("MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS), null, 'warnings');
  681. }
  682. $_GET["action"] = '';
  683. } elseif ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
  684. if (!empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') {
  685. setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
  686. }
  687. if (!empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') {
  688. setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
  689. }
  690. // The feature is forbidden from GUI, we show just message to use from command line.
  691. setEventMessages($langs->trans("MailingNeedCommand"), null, 'warnings');
  692. setEventMessages('<textarea cols="60" rows="'.ROWS_1.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', null, 'warnings');
  693. if ($conf->file->mailing_limit_sendbyweb != '-1') { // MAILING_LIMIT_SENDBYWEB was set to -1 in database, but it is allowed ot increase it.
  694. setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings'); // You can send online with constant...
  695. }
  696. $_GET["action"] = '';
  697. } else {
  698. if (!empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') {
  699. setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
  700. }
  701. if (!empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') {
  702. setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
  703. }
  704. $text = '';
  705. if (!isset($conf->global->MAILING_LIMIT_SENDBYCLI) || $conf->global->MAILING_LIMIT_SENDBYCLI >= 0) {
  706. $text .= $langs->trans("MailingNeedCommand");
  707. $text .= '<br><textarea cols="60" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.' '.$user->login.'</textarea>';
  708. $text .= '<br><br>';
  709. }
  710. $text .= $langs->trans('ConfirmSendingEmailing').'<br>';
  711. $text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
  712. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('SendMailing'), $text, 'sendallconfirmed', '', '', 1, 330, 600);
  713. }
  714. }
  715. $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  716. $morehtmlright = '';
  717. $nbtry = $nbok = 0;
  718. if ($object->statut == 2 || $object->statut == 3) {
  719. $nbtry = $object->countNbOfTargets('alreadysent');
  720. $nbko = $object->countNbOfTargets('alreadysentko');
  721. $morehtmlright .= ' ('.$nbtry.'/'.$object->nbemail;
  722. if ($nbko) {
  723. $morehtmlright .= ' - '.$nbko.' '.$langs->trans("Error");
  724. }
  725. $morehtmlright .= ') &nbsp; ';
  726. }
  727. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
  728. print '<div class="fichecenter">';
  729. print '<div class="underbanner clearboth"></div>';
  730. print '<table class="border centpercent tableforfield">';
  731. // Description
  732. print '<tr><td class="titlefield">';
  733. print $form->editfieldkey("MailTitle", 'title', $object->title, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
  734. print '</td><td>';
  735. print $form->editfieldval("MailTitle", 'title', $object->title, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
  736. print '</td></tr>';
  737. // From
  738. print '<tr><td>';
  739. print $form->editfieldkey("MailFrom", 'email_from', $object->email_from, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
  740. print '</td><td>';
  741. print $form->editfieldval("MailFrom", 'email_from', $object->email_from, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
  742. $email = CMailFile::getValidAddress($object->email_from, 2);
  743. if ($email && !isValidEmail($email)) {
  744. $langs->load("errors");
  745. print img_warning($langs->trans("ErrorBadEMail", $email));
  746. } elseif ($email && !isValidMailDomain($email)) {
  747. $langs->load("errors");
  748. print img_warning($langs->trans("ErrorBadMXDomain", $email));
  749. }
  750. print '</td></tr>';
  751. // Errors to
  752. print '<tr><td>';
  753. print $form->editfieldkey("MailErrorsTo", 'email_errorsto', $object->email_errorsto, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
  754. print '</td><td>';
  755. print $form->editfieldval("MailErrorsTo", 'email_errorsto', $object->email_errorsto, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
  756. $email = CMailFile::getValidAddress($object->email_errorsto, 2);
  757. if ($email && !isValidEmail($email)) {
  758. $langs->load("errors");
  759. print img_warning($langs->trans("ErrorBadEMail", $email));
  760. } elseif ($email && !isValidMailDomain($email)) {
  761. $langs->load("errors");
  762. print img_warning($langs->trans("ErrorBadMXDomain", $email));
  763. }
  764. print '</td></tr>';
  765. // Number of distinct emails
  766. print '<tr><td>';
  767. print $langs->trans("TotalNbOfDistinctRecipients");
  768. print '</td><td colspan="3">';
  769. $nbemail = ($object->nbemail ? $object->nbemail : 0);
  770. if (is_numeric($nbemail)) {
  771. $text = '';
  772. if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail))) {
  773. if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) {
  774. $text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
  775. } else {
  776. $text .= $langs->trans('SendingFromWebInterfaceIsNotAllowed');
  777. }
  778. }
  779. if (empty($nbemail)) {
  780. $nbemail .= ' '.img_warning('').' <span class="warning">'.$langs->trans("NoTargetYet").'</span>';
  781. }
  782. if ($text) {
  783. print $form->textwithpicto($nbemail, $text, 1, 'warning');
  784. } else {
  785. print $nbemail;
  786. }
  787. }
  788. print '</td></tr>';
  789. // Other attributes
  790. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  791. print '</table>';
  792. print "</div>";
  793. print dol_get_fiche_end();
  794. // Clone confirmation
  795. if ($action == 'clone') {
  796. // Create an array for form
  797. $formquestion = array(
  798. 'text' => $langs->trans("ConfirmClone"),
  799. array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneContent"), 'value' => 1),
  800. array('type' => 'checkbox', 'name' => 'clone_receivers', 'label' => $langs->trans("CloneReceivers"), 'value' => 0)
  801. );
  802. // Incomplete payment. On demande si motif = escompte ou autre
  803. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneEMailing', $object->ref), 'confirm_clone', $formquestion, 'yes', 2, 240);
  804. }
  805. /*
  806. * Actions Buttons
  807. */
  808. if (GETPOST('cancel', 'alpha') || $confirm == 'no' || $action == '' || in_array($action, array('settodraft', 'valid', 'delete', 'sendall', 'clone', 'test'))) {
  809. print "\n\n<div class=\"tabsAction\">\n";
  810. if (($object->statut == 1) && ($user->rights->mailing->valider || $object->user_validation == $user->id)) {
  811. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=settodraft&token='.newToken().'&id='.$object->id.'">'.$langs->trans("SetToDraft").'</a>';
  812. }
  813. if (($object->statut == 0 || $object->statut == 1 || $object->statut == 2) && $user->rights->mailing->creer) {
  814. if (!empty($conf->fckeditor->enabled) && !empty($conf->global->FCKEDITOR_ENABLE_MAILING)) {
  815. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans("EditWithEditor").'</a>';
  816. } else {
  817. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans("EditWithTextEditor").'</a>';
  818. }
  819. if (!empty($conf->use_javascript_ajax)) {
  820. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edithtml&token='.newToken().'&id='.$object->id.'">'.$langs->trans("EditHTMLSource").'</a>';
  821. }
  822. }
  823. //print '<a class="butAction" href="card.php?action=test&amp;id='.$object->id.'">'.$langs->trans("PreviewMailing").'</a>';
  824. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
  825. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("TestMailing").'</a>';
  826. } else {
  827. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=test&token='.newToken().'&id='.$object->id.'">'.$langs->trans("TestMailing").'</a>';
  828. }
  829. if ($object->statut == 0) {
  830. if ($object->nbemail <= 0) {
  831. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoTargetYet")).'">'.$langs->trans("ValidMailing").'</a>';
  832. } elseif (empty($user->rights->mailing->valider)) {
  833. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ValidMailing").'</a>';
  834. } else {
  835. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=valid&amp;id='.$object->id.'">'.$langs->trans("ValidMailing").'</a>';
  836. }
  837. }
  838. if (($object->statut == 1 || $object->statut == 2) && $object->nbemail > 0 && $user->rights->mailing->valider) {
  839. if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
  840. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("SendingFromWebInterfaceIsNotAllowed")).'">'.$langs->trans("SendMailing").'</a>';
  841. } elseif (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
  842. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("SendMailing").'</a>';
  843. } else {
  844. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=sendall&amp;id='.$object->id.'">'.$langs->trans("SendMailing").'</a>';
  845. }
  846. }
  847. if ($user->rights->mailing->creer) {
  848. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=clone&amp;object=emailing&amp;id='.$object->id.'">'.$langs->trans("ToClone").'</a>';
  849. }
  850. if (($object->statut == 2 || $object->statut == 3) && $user->rights->mailing->valider) {
  851. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
  852. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ResetMailing").'</a>';
  853. } else {
  854. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=reset&amp;id='.$object->id.'">'.$langs->trans("ResetMailing").'</a>';
  855. }
  856. }
  857. if (($object->statut <= 1 && $user->rights->mailing->creer) || $user->rights->mailing->supprimer) {
  858. if ($object->statut > 0 && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->delete)) {
  859. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("DeleteMailing").'</a>';
  860. } else {
  861. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$object->id.(!empty($urlfrom) ? '&urlfrom='.$urlfrom : '').'">'.$langs->trans("DeleteMailing").'</a>';
  862. }
  863. }
  864. print '</div>';
  865. }
  866. // Display of the TEST form
  867. if ($action == 'test') {
  868. print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
  869. print load_fiche_titre($langs->trans("TestMailing"));
  870. print dol_get_fiche_head(null, '', '', -1);
  871. // Create mail form object
  872. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  873. $formmail = new FormMail($db);
  874. $formmail->fromname = $object->email_from;
  875. $formmail->frommail = $object->email_from;
  876. $formmail->withsubstit = 1;
  877. $formmail->withfrom = 0;
  878. $formmail->withto = $user->email ? $user->email : 1;
  879. $formmail->withtocc = 0;
  880. $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
  881. $formmail->withtopic = 0;
  882. $formmail->withtopicreadonly = 1;
  883. $formmail->withfile = 0;
  884. $formmail->withbody = 0;
  885. $formmail->withbodyreadonly = 1;
  886. $formmail->withcancel = 1;
  887. $formmail->withdeliveryreceipt = 0;
  888. // Table of substitutions
  889. $formmail->substit = $object->substitutionarrayfortest;
  890. // Table of post's complementary params
  891. $formmail->param["action"] = "send";
  892. $formmail->param["models"] = 'none';
  893. $formmail->param["mailid"] = $object->id;
  894. $formmail->param["returnurl"] = $_SERVER['PHP_SELF']."?id=".$object->id;
  895. print $formmail->get_form();
  896. print '<br>';
  897. print dol_get_fiche_end();
  898. dol_set_focus('#sendto');
  899. }
  900. $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
  901. foreach ($object->substitutionarray as $key => $val) {
  902. $htmltext .= $key.' = '.$langs->trans($val).'<br>';
  903. }
  904. $htmltext .= '</i>';
  905. // Print mail content
  906. print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto('<span class="opacitymedium hideonsmartphone">'.$langs->trans("AvailableVariables").'</span>', $htmltext, 1, 'helpclickable', '', 0, 2, 'emailsubstitionhelp'), 'generic');
  907. print dol_get_fiche_head('', '', '', -1);
  908. print '<table class="bordernooddeven" width="100%">';
  909. // Subject
  910. print '<tr><td class="titlefield">'.$langs->trans("MailTopic").'</td><td colspan="3">'.$object->sujet.'</td></tr>';
  911. // Joined files
  912. print '<tr><td>'.$langs->trans("MailFile").'</td><td colspan="3">';
  913. // List of files
  914. $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
  915. if (count($listofpaths)) {
  916. foreach ($listofpaths as $key => $val) {
  917. print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
  918. print '<br>';
  919. }
  920. } else {
  921. print '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
  922. }
  923. print '</td></tr>';
  924. // Background color
  925. /*print '<tr><td width="15%">'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
  926. print $htmlother->selectColor($object->bgcolor,'bgcolor','',0);
  927. print '</td></tr>';*/
  928. print '</table>';
  929. // Message
  930. print '<div style="padding-top: 10px; background: '.($object->bgcolor ? (preg_match('/^#/', $object->bgcolor) ? '' : '#').$object->bgcolor : 'white').'">';
  931. if (empty($object->bgcolor) || strtolower($object->bgcolor) == 'ffffff') { // CKEditor does not apply the color of the div into its content area
  932. $readonly = 1;
  933. // wysiwyg editor
  934. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  935. $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', false, true, empty($conf->global->FCKEDITOR_ENABLE_MAILING) ? 0 : 1, 20, '90%', $readonly);
  936. $doleditor->Create();
  937. } else {
  938. print dol_htmlentitiesbr($object->body);
  939. }
  940. print '</div>';
  941. print dol_get_fiche_end();
  942. } else {
  943. /*
  944. * Edition mode mailing (CKeditor or HTML source)
  945. */
  946. print dol_get_fiche_head($head, 'card', $langs->trans("Mailing"), -1, 'email');
  947. $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  948. $morehtmlright = '';
  949. if ($object->statut == 2) {
  950. $morehtmlright .= ' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
  951. }
  952. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
  953. print '<div class="fichecenter">';
  954. print '<div class="underbanner clearboth"></div>';
  955. print '<table class="border centpercent">';
  956. /*
  957. print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td>';
  958. print '<td colspan="3">';
  959. print $form->showrefnav($object,'id', $linkback);
  960. print '</td></tr>';
  961. */
  962. // Topic
  963. print '<tr><td class="titlefield">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$object->title.'</td></tr>';
  964. // From
  965. 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>';
  966. // To
  967. print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1).'</td></tr>';
  968. // Number of distinct emails
  969. print '<tr><td>';
  970. print $langs->trans("TotalNbOfDistinctRecipients");
  971. print '</td><td colspan="3">';
  972. $nbemail = ($object->nbemail ? $object->nbemail : 0);
  973. if (is_numeric($nbemail)) {
  974. $text = '';
  975. if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || $object->statut == 2)) {
  976. if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) {
  977. $text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
  978. } else {
  979. $text .= $langs->trans('SendingFromWebInterfaceIsNotAllowed');
  980. }
  981. }
  982. if (empty($nbemail)) {
  983. $nbemail .= ' '.img_warning('').' <span class="warning">'.$langs->trans("NoTargetYet").'</span>';
  984. }
  985. if ($text) {
  986. print $form->textwithpicto($nbemail, $text, 1, 'warning');
  987. } else {
  988. print $nbemail;
  989. }
  990. }
  991. print '</td></tr>';
  992. // Other attributes
  993. $parameters = array();
  994. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  995. print $hookmanager->resPrint;
  996. if (empty($reshook)) {
  997. print $object->showOptionals($extrafields, 'edit', $parameters);
  998. }
  999. print '</table>';
  1000. print '</div>';
  1001. print dol_get_fiche_end();
  1002. print "<br>\n";
  1003. print '<form name="edit_mailing" action="card.php" method="post" enctype="multipart/form-data">'."\n";
  1004. print '<input type="hidden" name="token" value="'.newToken().'">';
  1005. print '<input type="hidden" name="action" value="update">';
  1006. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1007. $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
  1008. foreach ($object->substitutionarray as $key => $val) {
  1009. $htmltext .= $key.' = '.$langs->trans($val).'<br>';
  1010. }
  1011. $htmltext .= '</i>';
  1012. // Print mail content
  1013. print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp'), 'generic');
  1014. print dol_get_fiche_head(null, '', '', -1);
  1015. print '<table class="bordernooddeven" width="100%">';
  1016. // Subject
  1017. 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>';
  1018. $trackid = ''; // TODO To avoid conflicts with 2 mass emailing, we should set a trackid here, even if we use another one into email header.
  1019. dol_init_file_process($upload_dir, $trackid);
  1020. // Joined files
  1021. $addfileaction = 'addfile';
  1022. print '<tr><td>'.$langs->trans("MailFile").'</td>';
  1023. print '<td colspan="3">';
  1024. // List of files
  1025. $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
  1026. // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
  1027. $out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
  1028. $out .= '<script type="text/javascript">';
  1029. $out .= 'jQuery(document).ready(function () {';
  1030. $out .= ' jQuery(".removedfile").click(function() {';
  1031. $out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());';
  1032. $out .= ' });';
  1033. $out .= '})';
  1034. $out .= '</script>'."\n";
  1035. if (count($listofpaths)) {
  1036. foreach ($listofpaths as $key => $val) {
  1037. $out .= '<div id="attachfile_'.$key.'">';
  1038. $out .= img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
  1039. $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.'" />';
  1040. $out .= '<br></div>';
  1041. }
  1042. } else {
  1043. $out .= '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
  1044. }
  1045. // Add link to add file
  1046. $out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
  1047. $out .= ' ';
  1048. $out .= '<input type="submit" class="button" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
  1049. print $out;
  1050. print '</td></tr>';
  1051. // Background color
  1052. print '<tr><td>'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
  1053. print $htmlother->selectColor($object->bgcolor, 'bgcolor', '', 0);
  1054. print '</td></tr>';
  1055. print '</table>';
  1056. // Message
  1057. print '<div style="padding-top: 10px">';
  1058. if ($action == 'edit') {
  1059. // wysiwyg editor
  1060. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1061. $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, true, $conf->global->FCKEDITOR_ENABLE_MAILING, 20, '90%');
  1062. $doleditor->Create();
  1063. }
  1064. if ($action == 'edithtml') {
  1065. // HTML source editor
  1066. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1067. $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, true, 'ace', 20, '90%');
  1068. $doleditor->Create(0, '', false, 'HTML Source', 'php');
  1069. }
  1070. print '</div>';
  1071. print dol_get_fiche_end();
  1072. print '<div class="center">';
  1073. print '<input type="submit" class="button buttonforacesave button-save" value="'.$langs->trans("Save").'" name="save">';
  1074. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  1075. print '<input type="submit" class="button button-cancel" value="'.$langs->trans("Cancel").'" name="cancel">';
  1076. print '</div>';
  1077. print '</form>';
  1078. print '<br>';
  1079. }
  1080. } else {
  1081. dol_print_error($db, $object->error);
  1082. }
  1083. }
  1084. // End of page
  1085. llxFooter();
  1086. $db->close();