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