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