dolibarr  16.0.5
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  $mesgs = array_merge($mesgs, $object->errors);
522  }
523 
524  setEventMessages('', $mesgs, 'errors');
525  $action = "create";
526  }
527 
528  // Action update description of emailing
529  if ($action == 'settitle' || $action == 'setemail_from' || $action == 'setreplyto' || $action == 'setemail_errorsto') {
530  $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
531 
532  if ($action == 'settitle') {
533  $object->title = trim(GETPOST('title', 'alpha'));
534  } elseif ($action == 'setemail_from') {
535  $object->email_from = trim(GETPOST('email_from', 'alphawithlgt')); // Must allow 'name <email>'
536  } elseif ($action == 'setemail_replyto') {
537  $object->email_replyto = trim(GETPOST('email_replyto', 'alphawithlgt')); // Must allow 'name <email>'
538  } elseif ($action == 'setemail_errorsto') {
539  $object->email_errorsto = trim(GETPOST('email_errorsto', 'alphawithlgt')); // Must allow 'name <email>'
540  } elseif ($action == 'settitle' && empty($object->title)) {
541  $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTitle"));
542  } elseif ($action == 'setfrom' && empty($object->email_from)) {
543  $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailFrom"));
544  }
545 
546  if (!$mesg) {
547  if ($object->update($user) >= 0) {
548  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
549  exit;
550  }
551  $mesg = $object->error;
552  }
553 
554  setEventMessages($mesg, $mesgs, 'errors');
555  $action = "";
556  }
557 
558  /*
559  * Action of adding a file in email form
560  */
561  if (GETPOST('addfile')) {
562  $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
563 
564  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
565 
566  // Set tmp user directory
567  dol_add_file_process($upload_dir, 0, 0, 'addedfile', '', null, '', 0);
568 
569  $action = "edit";
570  }
571 
572  // Action of file remove
573  if (GETPOST("removedfile")) {
574  $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
575 
576  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
577 
578  dol_remove_file_process(GETPOST('removedfile'), 0, 0); // We really delete file linked to mailing
579 
580  $action = "edit";
581  }
582 
583  // Action of emailing update
584  if ($action == 'update' && !GETPOST("removedfile") && !$cancel) {
585  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
586 
587  $isupload = 0;
588 
589  if (!$isupload) {
590  $mesgs = array();
591  $object->sujet = (string) GETPOST("sujet");
592  $object->body = (string) GETPOST("bodyemail", 'restricthtml');
593  $object->bgcolor = (string) GETPOST("bgcolor");
594  $object->bgimage = (string) GETPOST("bgimage");
595 
596  if (!$object->sujet) {
597  $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTopic"));
598  }
599  if (!$object->body) {
600  $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailMessage"));
601  }
602 
603  if (!count($mesgs)) {
604  if ($object->update($user) >= 0) {
605  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
606  exit;
607  }
608  $mesgs[] = $object->error;
609  $mesgs = array_merge($mesgs, $object->errors);
610  }
611 
612  setEventMessages('', $mesgs, 'errors');
613  $action = "edit";
614  } else {
615  $action = "edit";
616  }
617  }
618 
619  // Action of validation confirmation
620  if ($action == 'confirm_valid' && $confirm == 'yes') {
621  if ($object->id > 0) {
622  $object->valid($user);
623  setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
624  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
625  exit;
626  } else {
627  dol_print_error($db);
628  }
629  }
630 
631  // Action of validation confirmation
632  if ($action == 'confirm_settodraft' && $confirm == 'yes') {
633  if ($object->id > 0) {
634  $result = $object->setStatut(0);
635  if ($result > 0) {
636  //setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
637  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
638  exit;
639  } else {
640  setEventMessages($object->error, $object->errors, 'errors');
641  }
642  } else {
643  dol_print_error($db);
644  }
645  }
646 
647  // Resend
648  if ($action == 'confirm_reset' && $confirm == 'yes') {
649  if ($object->id > 0) {
650  $db->begin();
651 
652  $result = $object->valid($user);
653  if ($result > 0) {
654  $result = $object->reset_targets_status($user);
655  }
656 
657  if ($result > 0) {
658  $db->commit();
659  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
660  exit;
661  } else {
662  setEventMessages($object->error, $object->errors, 'errors');
663  $db->rollback();
664  }
665  } else {
666  dol_print_error($db);
667  }
668  }
669 
670  // Action of delete confirmation
671  if ($action == 'confirm_delete' && $confirm == 'yes') {
672  if ($object->delete($object->id)) {
673  $url = (!empty($urlfrom) ? $urlfrom : 'list.php');
674  header("Location: ".$url);
675  exit;
676  }
677  }
678 
679  if ($cancel) {
680  $action = '';
681  }
682 }
683 
684 
685 /*
686  * View
687  */
688 
689 $form = new Form($db);
690 $htmlother = new FormOther($db);
691 
692 $help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
693 llxHeader(
694  '',
695  $langs->trans("Mailing"),
696  $help_url,
697  '',
698  0,
699  0,
700  array(
701  '/includes/ace/src/ace.js',
702  '/includes/ace/src/ext-statusbar.js',
703  '/includes/ace/src/ext-language_tools.js',
704  //'/includes/ace/src/ext-chromevox.js'
705  ),
706  array()
707 );
708 
709 if ($action == 'create') {
710  // EMailing in creation mode
711  print '<form name="new_mailing" action="'.$_SERVER['PHP_SELF'].'" method="POST">'."\n";
712  print '<input type="hidden" name="token" value="'.newToken().'">';
713  print '<input type="hidden" name="action" value="add">';
714 
715  $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
716  foreach ($object->substitutionarray as $key => $val) {
717  $htmltext .= $key.' = '.$langs->trans($val).'<br>';
718  }
719  $htmltext .= '</i>';
720 
721 
722  $availablelink = $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'availvar');
723  //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>';
724 
725 
726  // Print mail form
727  print load_fiche_titre($langs->trans("NewMailing"), $availablelink, 'object_email');
728 
729  print dol_get_fiche_head();
730 
731  print '<table class="border centpercent">';
732  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>';
733  print '<tr><td class="fieldrequired">'.$langs->trans("MailFrom").'</td><td><input class="flat minwidth200" name="from" value="'.$conf->global->MAILING_EMAIL_FROM.'"></td></tr>';
734  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>';
735 
736  // Other attributes
737  $parameters = array();
738  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
739  print $hookmanager->resPrint;
740  if (empty($reshook)) {
741  print $object->showOptionals($extrafields, 'create');
742  }
743 
744  print '</table>';
745  print '</br><br>';
746 
747  print '<table class="border centpercent">';
748  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>';
749  print '<tr><td>'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
750  print $htmlother->selectColor(GETPOST('bgcolor'), 'bgcolor', '', 0);
751  print '</td></tr>';
752 
753  print '</table>';
754 
755  print '<div style="padding-top: 10px">';
756  // wysiwyg editor
757  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
758  $doleditor = new DolEditor('bodyemail', GETPOST('bodyemail', 'restricthtmlallowunvalid'), '', 600, 'dolibarr_mailings', '', true, true, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '90%');
759  $doleditor->Create();
760  print '</div>';
761 
762  print dol_get_fiche_end();
763 
764  print $form->buttonsSaveCancel("CreateMailing", '');
765 
766  print '</form>';
767 } else {
768  if ($object->id > 0) {
769  $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
770 
771  $head = emailing_prepare_head($object);
772 
773  if ($action == 'settodraft') {
774  // Confirmation back to draft
775  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("SetToDraft"), $langs->trans("ConfirmUnvalidateEmailing"), "confirm_settodraft", '', '', 1);
776  } elseif ($action == 'valid') {
777  // Confirmation of mailing validation
778  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ValidMailing"), $langs->trans("ConfirmValidMailing"), "confirm_valid", '', '', 1);
779  } elseif ($action == 'reset') {
780  // Confirm reset
781  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ResetMailing"), $langs->trans("ConfirmResetMailing", $object->ref), "confirm_reset", '', '', 2);
782  } elseif ($action == 'delete') {
783  // Confirm delete
784  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id.(!empty($urlfrom) ? '&urlfrom='.urlencode($urlfrom) : ''), $langs->trans("DeleteAMailing"), $langs->trans("ConfirmDeleteMailing"), "confirm_delete", '', '', 1);
785  }
786 
787  if ($action != 'edit' && $action != 'edithtml') {
788  print dol_get_fiche_head($head, 'card', $langs->trans("Mailing"), -1, 'email');
789 
790  /*
791  * View mode mailing
792  */
793  if ($action == 'sendall') {
794  // Define message to recommand from command line
795  $sendingmode = $conf->global->EMAILING_MAIL_SENDMODE;
796  if (empty($sendingmode)) {
797  $sendingmode = $conf->global->MAIN_MAIL_SENDMODE;
798  }
799  if (empty($sendingmode)) {
800  $sendingmode = 'mail'; // If not defined, we use php mail function
801  }
802 
803  // MAILING_NO_USING_PHPMAIL may be defined or not.
804  // MAILING_LIMIT_SENDBYWEB is always defined to something != 0 (-1=forbidden).
805  // MAILING_LIMIT_SENDBYCLI may be defined ot not (-1=forbidden, 0 or undefined=no limit).
806  // MAILING_LIMIT_SENDBYDAY may be defined ot not (0 or undefined=no limit).
807  if (!empty($conf->global->MAILING_NO_USING_PHPMAIL) && $sendingmode == 'mail') {
808  // 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.
809  // You ensure that every user is using its own SMTP server when using the mass emailing module.
810  $linktoadminemailbefore = '<a href="'.DOL_URL_ROOT.'/admin/mails_emailing.php">';
811  $linktoadminemailend = '</a>';
812  setEventMessages($langs->trans("MailSendSetupIs", $listofmethods[$sendingmode]), null, 'warnings');
813  $messagetoshow = $langs->trans("MailSendSetupIs2", '{s1}', '{s2}', '{s3}', '{s4}');
814  $messagetoshow = str_replace('{s1}', $linktoadminemailbefore, $messagetoshow);
815  $messagetoshow = str_replace('{s2}', $linktoadminemailend, $messagetoshow);
816  $messagetoshow = str_replace('{s3}', $langs->transnoentitiesnoconv("MAIN_MAIL_SENDMODE"), $messagetoshow);
817  $messagetoshow = str_replace('{s4}', $listofmethods['smtps'], $messagetoshow);
818  setEventMessages($messagetoshow, null, 'warnings');
819 
820  if (!empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) {
821  setEventMessages($langs->trans("MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS), null, 'warnings');
822  }
823  $_GET["action"] = '';
824  } elseif ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
825  if (!empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') {
826  setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
827  }
828  if (!empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') {
829  setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
830  }
831 
832  // The feature is forbidden from GUI, we show just message to use from command line.
833  setEventMessages($langs->trans("MailingNeedCommand"), null, 'warnings');
834  setEventMessages('<textarea cols="60" rows="'.ROWS_1.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', null, 'warnings');
835  if ($conf->file->mailing_limit_sendbyweb != '-1') { // MAILING_LIMIT_SENDBYWEB was set to -1 in database, but it is allowed ot increase it.
836  setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings'); // You can send online with constant...
837  }
838  $_GET["action"] = '';
839  } else {
840  if (!empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') {
841  setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
842  }
843  if (!empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') {
844  setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
845  }
846 
847  $text = '';
848 
849  if (isset($conf->global->MAILING_LIMIT_SENDBYDAY) && $conf->global->MAILING_LIMIT_SENDBYDAY >= 0) {
850  $text .= $langs->trans('WarningLimitSendByDay', $conf->global->MAILING_LIMIT_SENDBYDAY);
851  $text .= '<br><br>';
852  }
853  $text .= $langs->trans('ConfirmSendingEmailing').'<br>';
854  $text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
855 
856  if (!isset($conf->global->MAILING_LIMIT_SENDBYCLI) || $conf->global->MAILING_LIMIT_SENDBYCLI >= 0) {
857  $text .= '<br><br>';
858  $text .= $langs->trans("MailingNeedCommand");
859  $text .= '<br><textarea cols="60" rows="'.ROWS_2.'" wrap="soft" disabled>php ./scripts/emailings/mailing-send.php '.$object->id.' '.$user->login.'</textarea>';
860  }
861 
862  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('SendMailing'), $text, 'sendallconfirmed', '', '', 1, 330, 600, 0, $langs->trans("Confirm"), $langs->trans("Cancel"));
863  }
864  }
865 
866  $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
867 
868  $morehtmlright = '';
869  $nbtry = $nbok = 0;
870  if ($object->statut == 2 || $object->statut == 3) {
871  $nbtry = $object->countNbOfTargets('alreadysent');
872  $nbko = $object->countNbOfTargets('alreadysentko');
873 
874  $morehtmlright .= ' ('.$nbtry.'/'.$object->nbemail;
875  if ($nbko) {
876  $morehtmlright .= ' - '.$nbko.' '.$langs->trans("Error");
877  }
878  $morehtmlright .= ') &nbsp; ';
879  }
880 
881  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
882 
883  print '<div class="fichecenter">';
884  print '<div class="underbanner clearboth"></div>';
885 
886  print '<table class="border centpercent tableforfield">';
887 
888  // Description
889  print '<tr><td class="titlefield">';
890  print $form->editfieldkey("MailTitle", 'title', $object->title, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
891  print '</td><td>';
892  print $form->editfieldval("MailTitle", 'title', $object->title, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
893  print '</td></tr>';
894 
895  // From
896  print '<tr><td>';
897  print $form->editfieldkey("MailFrom", 'email_from', $object->email_from, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
898  print '</td><td>';
899  print $form->editfieldval("MailFrom", 'email_from', $object->email_from, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
900  $email = CMailFile::getValidAddress($object->email_from, 2);
901  if ($email && !isValidEmail($email)) {
902  $langs->load("errors");
903  print img_warning($langs->trans("ErrorBadEMail", $email));
904  } elseif ($email && !isValidMailDomain($email)) {
905  $langs->load("errors");
906  print img_warning($langs->trans("ErrorBadMXDomain", $email));
907  }
908 
909  print '</td></tr>';
910 
911  // Errors to
912  print '<tr><td>';
913  print $form->editfieldkey("MailErrorsTo", 'email_errorsto', $object->email_errorsto, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
914  print '</td><td>';
915  print $form->editfieldval("MailErrorsTo", 'email_errorsto', $object->email_errorsto, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
916  $email = CMailFile::getValidAddress($object->email_errorsto, 2);
917  if ($email && !isValidEmail($email)) {
918  $langs->load("errors");
919  print img_warning($langs->trans("ErrorBadEMail", $email));
920  } elseif ($email && !isValidMailDomain($email)) {
921  $langs->load("errors");
922  print img_warning($langs->trans("ErrorBadMXDomain", $email));
923  }
924  print '</td></tr>';
925 
926  // Number of distinct emails
927  print '<tr><td>';
928  print $langs->trans("TotalNbOfDistinctRecipients");
929  print '</td><td colspan="3">';
930  $nbemail = ($object->nbemail ? $object->nbemail : 0);
931  if (is_numeric($nbemail)) {
932  $text = '';
933  if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail))) {
934  if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) {
935  $text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
936  } else {
937  $text .= $langs->trans('SendingFromWebInterfaceIsNotAllowed');
938  }
939  }
940  if (empty($nbemail)) {
941  $nbemail .= ' '.img_warning('').' <span class="warning">'.$langs->trans("NoTargetYet").'</span>';
942  }
943  if ($text) {
944  print $form->textwithpicto($nbemail, $text, 1, 'warning');
945  } else {
946  print $nbemail;
947  }
948  }
949  print '</td></tr>';
950 
951  // Other attributes
952  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
953 
954  print '</table>';
955 
956  print "</div>";
957 
958  print dol_get_fiche_end();
959 
960 
961  // Clone confirmation
962  if ($action == 'clone') {
963  // Create an array for form
964  $formquestion = array(
965  'text' => $langs->trans("ConfirmClone"),
966  array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneContent"), 'value' => 1),
967  array('type' => 'checkbox', 'name' => 'clone_receivers', 'label' => $langs->trans("CloneReceivers"), 'value' => 0)
968  );
969  // Incomplete payment. On demande si motif = escompte ou autre
970  print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneEMailing', $object->ref), 'confirm_clone', $formquestion, 'yes', 2, 240);
971  }
972 
973  /*
974  * Actions Buttons
975  */
976 
977  if (GETPOST('cancel', 'alpha') || $confirm == 'no' || $action == '' || in_array($action, array('settodraft', 'valid', 'delete', 'sendall', 'clone', 'test'))) {
978  print "\n\n<div class=\"tabsAction\">\n";
979 
980  if (($object->statut == 1) && ($user->rights->mailing->valider || $object->user_validation == $user->id)) {
981  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=settodraft&token='.newToken().'&id='.$object->id.'">'.$langs->trans("SetToDraft").'</a>';
982  }
983 
984  if (($object->statut == 0 || $object->statut == 1 || $object->statut == 2) && $user->rights->mailing->creer) {
985  if (!empty($conf->fckeditor->enabled) && !empty($conf->global->FCKEDITOR_ENABLE_MAILING)) {
986  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans("EditWithEditor").'</a>';
987  } else {
988  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans("EditWithTextEditor").'</a>';
989  }
990 
991  if (!empty($conf->use_javascript_ajax)) {
992  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edithtml&token='.newToken().'&id='.$object->id.'">'.$langs->trans("EditHTMLSource").'</a>';
993  }
994  }
995 
996  //print '<a class="butAction" href="card.php?action=test&amp;id='.$object->id.'">'.$langs->trans("PreviewMailing").'</a>';
997 
998  if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
999  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("TestMailing").'</a>';
1000  } else {
1001  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=test&token='.newToken().'&id='.$object->id.'">'.$langs->trans("TestMailing").'</a>';
1002  }
1003 
1004  if ($object->statut == 0) {
1005  if ($object->nbemail <= 0) {
1006  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoTargetYet")).'">'.$langs->trans("ValidMailing").'</a>';
1007  } elseif (empty($user->rights->mailing->valider)) {
1008  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ValidMailing").'</a>';
1009  } else {
1010  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=valid&amp;id='.$object->id.'">'.$langs->trans("ValidMailing").'</a>';
1011  }
1012  }
1013 
1014  if (($object->statut == 1 || $object->statut == 2) && $object->nbemail > 0 && $user->rights->mailing->valider) {
1015  if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
1016  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("SendingFromWebInterfaceIsNotAllowed")).'">'.$langs->trans("SendMailing").'</a>';
1017  } elseif (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
1018  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("SendMailing").'</a>';
1019  } else {
1020  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=sendall&amp;id='.$object->id.'">'.$langs->trans("SendMailing").'</a>';
1021  }
1022  }
1023 
1024  if ($user->rights->mailing->creer) {
1025  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=clone&amp;object=emailing&amp;id='.$object->id.'">'.$langs->trans("ToClone").'</a>';
1026  }
1027 
1028  if (($object->statut == 2 || $object->statut == 3) && $user->rights->mailing->valider) {
1029  if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
1030  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ResetMailing").'</a>';
1031  } else {
1032  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=reset&amp;id='.$object->id.'">'.$langs->trans("ResetMailing").'</a>';
1033  }
1034  }
1035 
1036  if (($object->statut <= 1 && $user->rights->mailing->creer) || $user->rights->mailing->supprimer) {
1037  if ($object->statut > 0 && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->delete)) {
1038  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("DeleteMailing").'</a>';
1039  } else {
1040  print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$object->id.(!empty($urlfrom) ? '&urlfrom='.$urlfrom : '').'">'.$langs->trans("DeleteMailing").'</a>';
1041  }
1042  }
1043 
1044  print '</div>';
1045  }
1046 
1047  // Display of the TEST form
1048  if ($action == 'test') {
1049  print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
1050  print load_fiche_titre($langs->trans("TestMailing"));
1051 
1052  print dol_get_fiche_head(null, '', '', -1);
1053 
1054  // Create mail form object
1055  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1056  $formmail = new FormMail($db);
1057  $formmail->fromname = $object->email_from;
1058  $formmail->frommail = $object->email_from;
1059  $formmail->withsubstit = 1;
1060  $formmail->withfrom = 0;
1061  $formmail->withto = $user->email ? $user->email : 1;
1062  $formmail->withtocc = 0;
1063  $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
1064  $formmail->withtopic = 0;
1065  $formmail->withtopicreadonly = 1;
1066  $formmail->withfile = 0;
1067  $formmail->withbody = 0;
1068  $formmail->withbodyreadonly = 1;
1069  $formmail->withcancel = 1;
1070  $formmail->withdeliveryreceipt = 0;
1071  // Table of substitutions
1072  $formmail->substit = $object->substitutionarrayfortest;
1073  // Table of post's complementary params
1074  $formmail->param["action"] = "send";
1075  $formmail->param["models"] = 'none';
1076  $formmail->param["mailid"] = $object->id;
1077  $formmail->param["returnurl"] = $_SERVER['PHP_SELF']."?id=".$object->id;
1078 
1079  print $formmail->get_form();
1080 
1081  print '<br>';
1082 
1083  print dol_get_fiche_end();
1084 
1085  dol_set_focus('#sendto');
1086  }
1087 
1088 
1089  $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
1090  foreach ($object->substitutionarray as $key => $val) {
1091  $htmltext .= $key.' = '.$langs->trans($val).'<br>';
1092  }
1093  $htmltext .= '</i>';
1094 
1095  // Print mail content
1096  print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto('<span class="opacitymedium hideonsmartphone">'.$langs->trans("AvailableVariables").'</span>', $htmltext, 1, 'helpclickable', '', 0, 2, 'emailsubstitionhelp'), 'generic');
1097 
1098  print dol_get_fiche_head('', '', '', -1);
1099 
1100  print '<table class="bordernooddeven" width="100%">';
1101 
1102  // Subject
1103  print '<tr><td class="titlefield">'.$langs->trans("MailTopic").'</td><td colspan="3">'.$object->sujet.'</td></tr>';
1104 
1105  // Joined files
1106  print '<tr><td>'.$langs->trans("MailFile").'</td><td colspan="3">';
1107  // List of files
1108  $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
1109  if (count($listofpaths)) {
1110  foreach ($listofpaths as $key => $val) {
1111  print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
1112  print '<br>';
1113  }
1114  } else {
1115  print '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
1116  }
1117  print '</td></tr>';
1118 
1119  // Background color
1120  /*print '<tr><td width="15%">'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
1121  print $htmlother->selectColor($object->bgcolor,'bgcolor','',0);
1122  print '</td></tr>';*/
1123 
1124  print '</table>';
1125 
1126  // Message
1127  print '<div style="padding-top: 10px; background: '.($object->bgcolor ? (preg_match('/^#/', $object->bgcolor) ? '' : '#').$object->bgcolor : 'white').'">';
1128  if (empty($object->bgcolor) || strtolower($object->bgcolor) == 'ffffff') { // CKEditor does not apply the color of the div into its content area
1129  $readonly = 1;
1130  // wysiwyg editor
1131  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1132  $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', false, true, empty($conf->global->FCKEDITOR_ENABLE_MAILING) ? 0 : 1, 20, '90%', $readonly);
1133  $doleditor->Create();
1134  } else {
1135  print dol_htmlentitiesbr($object->body);
1136  }
1137  print '</div>';
1138 
1139  print dol_get_fiche_end();
1140  } else {
1141  /*
1142  * Edition mode mailing (CKeditor or HTML source)
1143  */
1144 
1145  print dol_get_fiche_head($head, 'card', $langs->trans("Mailing"), -1, 'email');
1146 
1147  $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1148 
1149  $morehtmlright = '';
1150  if ($object->statut == 2) {
1151  $morehtmlright .= ' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
1152  }
1153 
1154  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
1155 
1156  print '<div class="fichecenter">';
1157  print '<div class="underbanner clearboth"></div>';
1158 
1159  print '<table class="border centpercent">';
1160 
1161  /*
1162  print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td>';
1163  print '<td colspan="3">';
1164  print $form->showrefnav($object,'id', $linkback);
1165  print '</td></tr>';
1166  */
1167 
1168  // Topic
1169  print '<tr><td class="titlefield">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$object->title.'</td></tr>';
1170  // From
1171  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>';
1172  // To
1173  print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1).'</td></tr>';
1174 
1175  // Number of distinct emails
1176  print '<tr><td>';
1177  print $langs->trans("TotalNbOfDistinctRecipients");
1178  print '</td><td colspan="3">';
1179  $nbemail = ($object->nbemail ? $object->nbemail : 0);
1180  if (is_numeric($nbemail)) {
1181  $text = '';
1182  if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || $object->statut == 2)) {
1183  if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) {
1184  $text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
1185  } else {
1186  $text .= $langs->trans('SendingFromWebInterfaceIsNotAllowed');
1187  }
1188  }
1189  if (empty($nbemail)) {
1190  $nbemail .= ' '.img_warning('').' <span class="warning">'.$langs->trans("NoTargetYet").'</span>';
1191  }
1192  if ($text) {
1193  print $form->textwithpicto($nbemail, $text, 1, 'warning');
1194  } else {
1195  print $nbemail;
1196  }
1197  }
1198  print '</td></tr>';
1199 
1200  // Other attributes
1201  $parameters = array();
1202  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1203  print $hookmanager->resPrint;
1204  if (empty($reshook)) {
1205  print $object->showOptionals($extrafields, 'edit', $parameters);
1206  }
1207 
1208  print '</table>';
1209  print '</div>';
1210 
1211  print dol_get_fiche_end();
1212 
1213 
1214 
1215  print "<br>\n";
1216 
1217  print '<form name="edit_mailing" action="card.php" method="post" enctype="multipart/form-data">'."\n";
1218  print '<input type="hidden" name="token" value="'.newToken().'">';
1219  print '<input type="hidden" name="action" value="update">';
1220  print '<input type="hidden" name="id" value="'.$object->id.'">';
1221 
1222  $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
1223  foreach ($object->substitutionarray as $key => $val) {
1224  $htmltext .= $key.' = '.$langs->trans($val).'<br>';
1225  }
1226  $htmltext .= '</i>';
1227 
1228  // Print mail content
1229  print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp'), 'generic');
1230 
1231  print dol_get_fiche_head(null, '', '', -1);
1232 
1233  print '<table class="bordernooddeven" width="100%">';
1234 
1235  // Subject
1236  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>';
1237 
1238  $trackid = ''; // TODO To avoid conflicts with 2 mass emailing, we should set a trackid here, even if we use another one into email header.
1239  dol_init_file_process($upload_dir, $trackid);
1240 
1241  // Joined files
1242  $addfileaction = 'addfile';
1243  print '<tr><td>'.$langs->trans("MailFile").'</td>';
1244  print '<td colspan="3">';
1245  // List of files
1246  $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
1247 
1248  // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
1249  $out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
1250  $out .= '<script type="text/javascript">';
1251  $out .= 'jQuery(document).ready(function () {';
1252  $out .= ' jQuery(".removedfile").click(function() {';
1253  $out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());';
1254  $out .= ' });';
1255  $out .= '})';
1256  $out .= '</script>'."\n";
1257  if (count($listofpaths)) {
1258  foreach ($listofpaths as $key => $val) {
1259  $out .= '<div id="attachfile_'.$key.'">';
1260  $out .= img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
1261  $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.'" />';
1262  $out .= '<br></div>';
1263  }
1264  } else {
1265  $out .= '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
1266  }
1267  // Add link to add file
1268  $maxfilesizearray = getMaxFileSizeArray();
1269  $maxmin = $maxfilesizearray['maxmin'];
1270  if ($maxmin > 0) {
1271  $out .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
1272  }
1273  $out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
1274  $out .= ' ';
1275  $out .= '<input type="submit" class="button" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
1276  print $out;
1277  print '</td></tr>';
1278 
1279  // Background color
1280  print '<tr><td>'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
1281  print $htmlother->selectColor($object->bgcolor, 'bgcolor', '', 0);
1282  print '</td></tr>';
1283 
1284  print '</table>';
1285 
1286  // Message
1287  print '<div style="padding-top: 10px">';
1288 
1289  if ($action == 'edit') {
1290  // wysiwyg editor
1291  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1292  $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, true, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '90%');
1293  $doleditor->Create();
1294  }
1295  if ($action == 'edithtml') {
1296  // HTML source editor
1297  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1298  $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, true, 'ace', 20, '90%');
1299  $doleditor->Create(0, '', false, 'HTML Source', 'php');
1300  }
1301 
1302  print '</div>';
1303 
1304 
1305  print dol_get_fiche_end();
1306 
1307  print '<div class="center">';
1308  print '<input type="submit" class="button buttonforacesave button-save" value="'.$langs->trans("Save").'" name="save">';
1309  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1310  print '<input type="submit" class="button button-cancel" value="'.$langs->trans("Cancel").'" name="cancel">';
1311  print '</div>';
1312 
1313  print '</form>';
1314  print '<br>';
1315  }
1316  } else {
1317  dol_print_error($db, $object->error);
1318  }
1319 }
1320 
1321 // End of page
1322 llxFooter();
1323 $db->close();
make_substitutions
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Definition: functions.lib.php:7839
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
dol_escape_htmltag
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.
Definition: functions.lib.php:1468
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
emailing_prepare_head
emailing_prepare_head(Mailing $object)
Prepare array with list of tabs.
Definition: emailing.lib.php:30
isValidMailDomain
isValidMailDomain($mail)
Return true if email has a domain name that can be resolved to MX type.
Definition: functions2.lib.php:729
dol_add_file_process
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:1634
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
dol_mimetype
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
Definition: functions.lib.php:9741
CMailFile
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Definition: CMailFile.class.php:38
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_dir_list
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
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
dol_banner_tab
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.
Definition: functions.lib.php:2046
$help_url
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
CMailFile\getValidAddress
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Definition: CMailFile.class.php:1570
dol_init_file_process
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:1596
dol_hash
dol_hash($chain, $type='0')
Returns a hash of a string.
Definition: security.lib.php:104
getMaxFileSizeArray
getMaxFileSizeArray()
Return the max allowed for file upload.
Definition: security.lib.php:993
get_exdir
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
Definition: functions.lib.php:6549
Mailing
Class to manage emailings module.
Definition: mailing.class.php:32
isValidEmail
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
Definition: functions.lib.php:3681
getCommonSubstitutionArray
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
Definition: functions.lib.php:7275
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
dol_remove_file_process
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:1792
dolGetFirstLastname
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
Definition: functions.lib.php:8062
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
img_mime
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
Definition: functions.lib.php:4726
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_set_focus
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
Definition: functions.lib.php:9379
$parameters
$parameters
Actions.
Definition: card.php:78
dol_print_email
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
Definition: functions.lib.php:2960
dol_htmlentitiesbr
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...
Definition: functions.lib.php:6991
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
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
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933
FormMail
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Definition: html.formmail.class.php:38
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:93
llxHeader
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
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30
FormMail\getAvailableSubstitKey
static getAvailableSubstitKey($mode='formemail', $object=null)
Get list of substitution keys available for emails.
Definition: html.formmail.class.php:1574
complete_substitutions_array
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 "subst...
Definition: functions.lib.php:7961