dolibarr 24.0.0-beta
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@users.sourceforge.net>
4 * Copyright (C) 2005-2016 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2021 Waël Almoman <info@almoman.com>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2025 Jon Bendtsen <jon.bendtsen.github@jonb.dk>
8 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30if (!defined('NOSTYLECHECK')) {
31 define('NOSTYLECHECK', '1');
32}
33
34// Load Dolibarr environment
35require '../../main.inc.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
48require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
49require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
50require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
51require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
52require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
53if (isModEnabled('project')) {
54 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
55 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
56}
57
58// Load translation files required by the page
59$langs->loadLangs(array("mails", "admin"));
60
61$id = (GETPOSTINT('mailid') ? GETPOSTINT('mailid') : GETPOSTINT('id'));
62
63$action = GETPOST('action', 'aZ09');
64$confirm = GETPOST('confirm', 'alpha');
65$cancel = GETPOST('cancel', 'alpha');
66$urlfrom = GETPOST('urlfrom');
67$projectid = GETPOSTINT('projectid');
68$backtopage = GETPOST('backtopage');
69$backtopageforcancel = GETPOST('backtopageforcancel');
70
71// Initialize a technical objects
72$object = new Mailing($db);
73$hookmanager->initHooks(array('mailingcard', 'globalcard'));
74
75// Fetch optionals attributes and labels
76$extrafields->fetch_name_optionals_label($object->table_element);
77
78// Load object
79include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
80
81// Load object->fk_project
82if (isset($object->fk_project) && $object->fk_project > 0 ) {
83 dol_syslog('isset($object->fk_project)='.$object->fk_project, LOG_DEBUG);
84 $ret = $object->fetchProject();
85 if ($ret <= 0) {
86 setEventMessages($object->error, $object->errors, 'errors');
87 $action = '';
88 }
89}
90
91
92// Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
93$object->substitutionarray = FormMail::getAvailableSubstitKey('emailing');
94
95
96// Set $object->substitutionarrayfortest
97$signature = ((!empty($user->signature) && !getDolGlobalString('MAIN_MAIL_DO_NOT_USE_SIGN')) ? $user->signature : '');
98
99$targetobject = null; // Not defined with mass emailing
100
101$parameters = array('mode' => 'emailing');
102$substitutionarray = FormMail::getAvailableSubstitKey('emailing', $targetobject);
103
104$object->substitutionarrayfortest = $substitutionarray;
105
106// List of sending methods
107$listofmethods = array();
108//$listofmethods['default'] = $langs->trans('DefaultOutgoingEmailSetup');
109$listofmethods['mail'] = 'PHP mail function';
110//$listofmethods['simplemail']='Simplemail class';
111$listofmethods['smtps'] = 'SMTP/SMTPS socket library';
112if (version_compare(phpversion(), '7.0', '>=')) {
113 $listofmethods['swiftmailer'] = 'Swift Mailer socket library';
114}
115
116// Security check
117if (!$user->hasRight('mailing', 'lire') || (!getDolGlobalString('EXTERNAL_USERS_ARE_AUTHORIZED') && $user->socid > 0)) {
119}
120if (empty($action) && empty($object->id)) {
121 accessforbidden('Object not found');
122}
123
124$upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, getDolGlobalInt('MAILING_USE_NEW_PATH_FOR_FILES') ? 0 : 2, 0, 1, $object, 'mailing');
125
126//$permissiontoread = $user->hasRight('maling', 'read');
127$permissiontocreate = $user->hasRight('mailing', 'creer');
128$permissiontovalidatesend = $user->hasRight('mailing', 'valider');
129$permissiontodelete = $user->hasRight('mailing', 'supprimer');
130
131
132/*
133 * Actions
134 */
135
136$parameters = array();
137$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
138if ($reshook < 0) {
139 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
140}
141
142if (empty($reshook)) {
143 $error = 0;
144
145 $backurlforlist = DOL_URL_ROOT.'/comm/mailing/list.php';
146
147 if (empty($backtopage) || ($cancel && empty($id))) {
148 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
149 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
150 $backtopage = $backurlforlist;
151 } else {
152 $backtopage = DOL_URL_ROOT.'/comm/mailing/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
153 }
154 }
155 }
156
157 if ($cancel) {
158 /*var_dump($cancel);var_dump($backtopage);var_dump($backtopageforcancel);exit;*/
159 if (!empty($backtopageforcancel)) {
160 header("Location: ".$backtopageforcancel);
161 exit;
162 } elseif (!empty($backtopage)) {
163 header("Location: ".$backtopage);
164 exit;
165 }
166 $action = '';
167 }
168
169 // Action clone object
170 if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontocreate) {
171 if (!GETPOST("clone_content", 'alpha') && !GETPOST("clone_receivers", 'alpha')) {
172 setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
173 } else {
174 $result = $object->createFromClone($user, $object->id, GETPOST("clone_content") ? 1 : 0, GETPOST("clone_receivers") ? 1 : 0);
175 if ($result > 0) {
176 header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
177 exit;
178 } else {
179 setEventMessages($object->error, $object->errors, 'errors');
180 }
181 }
182 $action = '';
183 }
184
185 // Action send emailing for everybody
186 if ($action == 'sendallconfirmed' && $confirm == 'yes' && $permissiontovalidatesend) {
187 if (!getDolGlobalString('MAILING_LIMIT_SENDBYWEB')) {
188 // As security measure, we don't allow send from the GUI
189 setEventMessages($langs->trans("MailingNeedCommand"), null, 'warnings');
190 setEventMessages('<textarea cols="70" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', null, 'warnings');
191 setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings');
192 $action = '';
193 } elseif (getDolGlobalInt('MAILING_LIMIT_SENDBYWEB') < 0) {
194 setEventMessages($langs->trans("NotEnoughPermissions"), null, 'warnings');
195 $action = '';
196 } else {
197 if ($object->status == 0) {
198 dol_print_error(null, 'ErrorMailIsNotValidated');
199 exit;
200 }
201
202 $id = $object->id;
203 $subject = $object->sujet;
204 $message = $object->body;
205 $from = $object->email_from;
206 $replyto = $object->email_replyto;
207 $errorsto = $object->email_errorsto;
208 // Is the message in html
209 $msgishtml = -1; // Unknown by default
210 if (preg_match('/[\s\t]*<html>/i', $message)) {
211 $msgishtml = 1;
212 }
213
214 // Warning, we must not use begin-commit transaction here
215 // because we want to save update for each mail sent.
216
217 $nbok = 0;
218 $nbko = 0;
219
220 // We choose mails not already sent for this mailing (statut=0)
221 // or sent in error (statut=-1)
222 $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";
223 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
224 $sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".((int) $object->id);
225 $sql .= " ORDER BY mc.statut DESC"; // first status 0, then status -1
226
227 dol_syslog("card.php: select targets", LOG_DEBUG);
228 $resql = $db->query($sql);
229 if ($resql) {
230 $num = $db->num_rows($resql); // Number of possible recipients
231
232 if ($num) {
233 dol_syslog("comm/mailing/card.php: nb of targets = ".$num, LOG_DEBUG);
234
235 $now = dol_now();
236
237 // Positioning date of start sending
238 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".((int) $object->id);
239 $resql2 = $db->query($sql);
240 if (!$resql2) {
242 }
243
244 $thirdpartystatic = new Societe($db);
245 // Loop on each email and send it
246 $iforemailloop = 0;
247
248 while ($iforemailloop < $num && $iforemailloop < $conf->global->MAILING_LIMIT_SENDBYWEB) {
249 // Here code is common with same loop ino mailing-send.php
250 $res = 1;
251 $now = dol_now();
252
253 $obj = $db->fetch_object($resql);
254
255 // sendto en RFC2822
256 $sendto = str_replace(',', ' ', dolGetFirstLastname($obj->firstname, $obj->lastname))." <".$obj->email.">";
257
258 // Make substitutions on topic and body. From (AA=YY;BB=CC;...) we keep YY, CC, ...
259 $other = explode(';', $obj->other);
260 $tmpfield = explode('=', $other[0], 2);
261 $other1 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
262 $tmpfield = explode('=', $other[1], 2);
263 $other2 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
264 $tmpfield = explode('=', $other[2], 2);
265 $other3 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
266 $tmpfield = explode('=', $other[3], 2);
267 $other4 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
268 $tmpfield = explode('=', $other[4], 2);
269 $other5 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
270
271 $signature = ((!empty($user->signature) && !getDolGlobalString('MAIN_MAIL_DO_NOT_USE_SIGN')) ? $user->signature : '');
272
273 $parameters = array('mode' => 'emailing');
274 $substitutionarray = getCommonSubstitutionArray($langs, 0, array('object', 'objectamount'), $targetobject); // Note: On mass emailing, this is null because be don't know object
275
276 // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
277 $substitutionarray['__ID__'] = $obj->source_id;
278 $substitutionarray['__EMAIL__'] = $obj->email;
279 $substitutionarray['__LASTNAME__'] = $obj->lastname;
280 $substitutionarray['__FIRSTNAME__'] = $obj->firstname;
281 $substitutionarray['__MAILTOEMAIL__'] = '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>';
282 $substitutionarray['__OTHER1__'] = $other1;
283 $substitutionarray['__OTHER2__'] = $other2;
284 $substitutionarray['__OTHER3__'] = $other3;
285 $substitutionarray['__OTHER4__'] = $other4;
286 $substitutionarray['__OTHER5__'] = $other5;
287
288 if ($obj->source_type == "thirdparty") {
289 $result = $thirdpartystatic->fetch($obj->source_id);
290 if ($result > 0) {
291 $substitutionarray['__THIRDPARTY_CUSTOMER_CODE__'] = $thirdpartystatic->code_client;
292 } else {
293 $substitutionarray['__THIRDPARTY_CUSTOMER_CODE__'] = '';
294 }
295 }
296
297 $substitutionarray['__USER_SIGNATURE__'] = $signature; // Signature is empty when ran from command line or taken from user in parameter)
298 $substitutionarray['__SENDEREMAIL_SIGNATURE__'] = $signature; // Signature is empty when ran from command line or taken from user in parameter)
299 $substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.urlencode($obj->tag).'&securitykey='.dol_hash(getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY').'-'.$obj->tag.'-'.$obj->email.'-'.$obj->rowid, "md5").'&email='.urlencode($obj->email).'&mtid='.((int) $obj->rowid).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
300 $substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.urlencode($obj->tag).'&unsuscrib=1&securitykey='.dol_hash(getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY').'-'.$obj->tag.'-'.$obj->email.'-'.$obj->rowid, "md5").'&email='.urlencode($obj->email).'&mtid='.((int) $obj->rowid).'" target="_blank" rel="noopener noreferrer">'.$langs->trans("MailUnsubcribe").'</a>';
301 $substitutionarray['__UNSUBSCRIBE_URL__'] = DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.urlencode($obj->tag).'&unsuscrib=1&securitykey='.dol_hash(getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY').'-'.$obj->tag.'-'.$obj->email.'-'.$obj->rowid, "md5").'&email='.urlencode($obj->email).'&mtid='.((int) $obj->rowid);
302
303 $onlinepaymentenabled = 0;
304 if (isModEnabled('paypal')) {
305 $onlinepaymentenabled++;
306 }
307 if (isModEnabled('stripe')) {
308 $onlinepaymentenabled++;
309 }
310 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
311 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
312 $substitutionarray['__ONLINEPAYMENTLINK_MEMBER__'] = getHtmlOnlinePaymentLink('member', $obj->source_id);
313 $substitutionarray['__ONLINEPAYMENTLINK_DONATION__'] = getHtmlOnlinePaymentLink('donation', $obj->source_id);
314 $substitutionarray['__ONLINEPAYMENTLINK_ORDER__'] = getHtmlOnlinePaymentLink('order', $obj->source_id);
315 $substitutionarray['__ONLINEPAYMENTLINK_INVOICE__'] = getHtmlOnlinePaymentLink('invoice', $obj->source_id);
316 $substitutionarray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = getHtmlOnlinePaymentLink('contractline', $obj->source_id);
317
318 $substitutionarray['__SECUREKEYPAYMENT__'] = dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN'), '2');
319 $substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . 'member'.$obj->source_id, '2');
320 $substitutionarray['__SECUREKEYPAYMENT_DONATION__'] = dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . 'donation'.$obj->source_id, '2');
321 $substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . 'order'.$obj->source_id, '2');
322 $substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . 'invoice'.$obj->source_id, '2');
323 $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . 'contractline'.$obj->source_id, '2');
324 }
325 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
326 $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>';
327 }
328 /* For backward compatibility, deprecated */
329 if (isModEnabled('paypal') && getDolGlobalString('PAYPAL_SECURITY_TOKEN')) {
330 $substitutionarray['__SECUREKEYPAYPAL__'] = dol_hash(getDolGlobalString('PAYPAL_SECURITY_TOKEN'), '2');
331
332 if (!getDolGlobalString('PAYPAL_SECURITY_TOKEN_UNIQUE')) {
333 $substitutionarray['__SECUREKEYPAYPAL_MEMBER__'] = dol_hash(getDolGlobalString('PAYPAL_SECURITY_TOKEN'), '2');
334 } else {
335 $substitutionarray['__SECUREKEYPAYPAL_MEMBER__'] = dol_hash(getDolGlobalString('PAYPAL_SECURITY_TOKEN') . 'membersubscription'.$obj->source_id, '2');
336 }
337
338 if (!getDolGlobalString('PAYPAL_SECURITY_TOKEN_UNIQUE')) {
339 $substitutionarray['__SECUREKEYPAYPAL_ORDER__'] = dol_hash(getDolGlobalString('PAYPAL_SECURITY_TOKEN'), '2');
340 } else {
341 $substitutionarray['__SECUREKEYPAYPAL_ORDER__'] = dol_hash(getDolGlobalString('PAYPAL_SECURITY_TOKEN') . 'order'.$obj->source_id, '2');
342 }
343
344 if (!getDolGlobalString('PAYPAL_SECURITY_TOKEN_UNIQUE')) {
345 $substitutionarray['__SECUREKEYPAYPAL_INVOICE__'] = dol_hash(getDolGlobalString('PAYPAL_SECURITY_TOKEN'), '2');
346 } else {
347 $substitutionarray['__SECUREKEYPAYPAL_INVOICE__'] = dol_hash(getDolGlobalString('PAYPAL_SECURITY_TOKEN') . 'invoice'.$obj->source_id, '2');
348 }
349
350 if (!getDolGlobalString('PAYPAL_SECURITY_TOKEN_UNIQUE')) {
351 $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__'] = dol_hash(getDolGlobalString('PAYPAL_SECURITY_TOKEN'), '2');
352 } else {
353 $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__'] = dol_hash(getDolGlobalString('PAYPAL_SECURITY_TOKEN') . 'contractline'.$obj->source_id, '2');
354 }
355 }
356 //$substitutionisok=true;
357
358 complete_substitutions_array($substitutionarray, $langs);
359 $newsubject = make_substitutions($subject, $substitutionarray);
360 $newmessage = make_substitutions($message, $substitutionarray, null, 0);
361
362 $moreinheader = '';
363 if (preg_match('/__UNSUBSCRIBE_(_|URL_)/', $message)) {
364 $moreinheader = "List-Unsubscribe: <__UNSUBSCRIBE_URL__>\n";
365 $moreinheader = make_substitutions($moreinheader, $substitutionarray);
366 }
367
368 $arr_file = array();
369 $arr_mime = array();
370 $arr_name = array();
371 $arr_css = array();
372
373 $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
374 if (count($listofpaths)) {
375 foreach ($listofpaths as $key => $val) {
376 $arr_file[] = $listofpaths[$key]['fullname'];
377 $arr_mime[] = dol_mimetype($listofpaths[$key]['name']);
378 $arr_name[] = $listofpaths[$key]['name'];
379 }
380 }
381
382 // Mail making
383 $trackid = 'emailing-'.$obj->fk_mailing.'-'.$obj->rowid;
384 $upload_dir_tmp = $upload_dir;
385 $mail = new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $errorsto, $arr_css, $trackid, $moreinheader, 'emailing', $replyto, $upload_dir_tmp);
386
387 if ($mail->error) {
388 $res = 0;
389 }
390 /*if (! $substitutionisok)
391 {
392 $mail->error='Some substitution failed';
393 $res=0;
394 }*/
395
396 // Send mail
397 if ($res) {
398 $res = $mail->sendfile();
399 }
400
401 if ($res) {
402 // Mail successful
403 $nbok++;
404
405 dol_syslog("comm/mailing/card.php: ok for #".$iforemailloop.($mail->error ? ' - '.$mail->error : ''), LOG_DEBUG);
406
407 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
408 $sql .= " SET statut=1, date_envoi = '".$db->idate($now)."' WHERE rowid=".((int) $obj->rowid);
409 $resql2 = $db->query($sql);
410 if (!$resql2) {
412 } else {
413 //if check read is use then update prospect contact status
414 if (strpos($message, '__CHECK_READ__') !== false) {
415 //Update status communication of thirdparty prospect
416 $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).")";
417 dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
418 $resql2 = $db->query($sql);
419 if (!$resql2) {
421 }
422
423 //Update status communication of contact prospect
424 $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)";
425 dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
426
427 $resql2 = $db->query($sql);
428 if (!$resql2) {
430 }
431 }
432 }
433
434 if (getDolGlobalString('MAILING_DELAY')) {
435 dol_syslog("Wait a delay of MAILING_DELAY=".((float) $conf->global->MAILING_DELAY));
436 usleep((int) ((float) $conf->global->MAILING_DELAY * 1000000));
437 }
438
439 //test if CHECK READ change statut prospect contact
440 } else {
441 // Mail failed
442 $nbko++;
443
444 dol_syslog("comm/mailing/card.php: error for #".$iforemailloop.($mail->error ? ' - '.$mail->error : ''), LOG_WARNING);
445
446 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
447 $sql .= " SET statut=-1, error_text='".$db->escape(dol_trunc($mail->error, 250))."', date_envoi='".$db->idate($now)."' WHERE rowid=".((int) $obj->rowid);
448 $resql2 = $db->query($sql);
449 if (!$resql2) {
451 }
452 }
453
454 $iforemailloop++;
455 }
456 } else {
457 setEventMessages($langs->transnoentitiesnoconv("NoMoreRecipientToSendTo"), null, 'mesgs');
458 }
459
460 // Loop finished, set global statut of mail
461 if ($nbko > 0) {
462 $statut = 2; // Status 'sent partially' (because at least one error)
463 setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients", (string) $nbok), null, 'mesgs');
464 } else {
465 if ($nbok >= $num) {
466 $statut = 3; // Send to everybody
467 } else {
468 $statut = 2; // Status 'sent partially' (because not send to everybody)
469 }
470 setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients", (string) $nbok), null, 'mesgs');
471 }
472
473 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".((int) $statut)." WHERE rowid = ".((int) $object->id);
474 dol_syslog("comm/mailing/card.php: update global status", LOG_DEBUG);
475 $resql2 = $db->query($sql);
476 if (!$resql2) {
478 }
479 } else {
480 dol_syslog($db->error());
482 }
483 $object->fetch($id);
484 $action = '';
485 }
486 }
487
488 // Action send test emailing
489 if ($action == 'send' && ! $cancel && $permissiontovalidatesend) {
490 $error = 0;
491
492 $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, getDolGlobalInt('MAILING_USE_NEW_PATH_FOR_FILES') ? 0 : 2, 0, 1, $object, 'mailing');
493
494 $object->sendto = GETPOST("sendto", 'alphawithlgt');
495 if (!$object->sendto) {
496 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MailTo")), null, 'errors');
497 $error++;
498 }
499
500 if (!$error) {
501 // Is the message in html
502 $msgishtml = -1; // Unknown = autodetect by default
503 if (preg_match('/[\s\t]*<html>/i', $object->body)) {
504 $msgishtml = 1;
505 }
506
507 $signature = ((!empty($user->signature) && !getDolGlobalString('MAIN_MAIL_DO_NOT_USE_SIGN')) ? $user->signature : '');
508
509 $parameters = array('mode' => 'emailing');
510 $substitutionarray = getCommonSubstitutionArray($langs, 0, array('object', 'objectamount'), $targetobject); // Note: On mass emailing, this is null because be don't know object
511
512 // other are set at begin of page
513 $substitutionarray['__EMAIL__'] = $object->sendto;
514 $substitutionarray['__MAILTOEMAIL__'] = '<a href="mailto:'.$object->sendto.'">'.$object->sendto.'</a>';
515 $substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag=undefinedintestmode&securitykey='.dol_hash(getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY')."-undefinedintestmode-".$object->sendto."-0", 'md5').'&email='.urlencode($object->sendto).'&mtid=0" width="1" height="1" style="width:1px;height:1px" border="0"/>';
516 $substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag=undefinedintestmode&unsuscrib=1&securitykey='.dol_hash(getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY')."-undefinedintestmode-".$object->sendto."-0", 'md5').'&email='.urlencode($object->sendto).'&mtid=0" target="_blank" rel="noopener noreferrer">'.$langs->trans("MailUnsubcribe").'</a>';
517 $substitutionarray['__UNSUBSCRIBE_URL__'] = DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag=undefinedintestmode&unsuscrib=1&securitykey='.dol_hash(getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY')."-undefinedintestmode-".$object->sendto."-0", 'md5').'&email='.urlencode($object->sendto).'&mtid=0';
518
519 // Subject and message substitutions
520 complete_substitutions_array($substitutionarray, $langs, $targetobject);
521
522 $tmpsujet = make_substitutions($object->sujet, $substitutionarray);
523 $tmpbody = make_substitutions($object->body, $substitutionarray);
524
525 $arr_file = array();
526 $arr_mime = array();
527 $arr_name = array();
528 $arr_css = array();
529
530 // Add CSS
531 if (!empty($object->bgcolor)) {
532 $arr_css['bgcolor'] = (preg_match('/^#/', $object->bgcolor) ? '' : '#').$object->bgcolor;
533 }
534 if (!empty($object->bgimage)) {
535 $arr_css['bgimage'] = $object->bgimage;
536 }
537
538 // Attached files
539 $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
540 if (count($listofpaths)) {
541 foreach ($listofpaths as $key => $val) {
542 $arr_file[] = $listofpaths[$key]['fullname'];
543 $arr_mime[] = dol_mimetype($listofpaths[$key]['name']);
544 $arr_name[] = $listofpaths[$key]['name'];
545 }
546 }
547
548 $trackid = 'emailing-test';
549 $upload_dir_tmp = $upload_dir;
550 $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', $object->email_replyto, $upload_dir_tmp);
551
552 $result = $mailfile->sendfile();
553 if ($result) {
554 setEventMessages($langs->trans("MailSuccessfulySent", $mailfile->getValidAddress($object->email_from, 2), $mailfile->getValidAddress($object->sendto, 2)), null, 'mesgs');
555 $action = '';
556 } else {
557 setEventMessages($langs->trans("ResultKo").'<br>'.$mailfile->error.' '.json_encode($result), null, 'errors');
558 $action = 'test';
559 }
560 }
561 }
562
563 $mesgs = array();
564 // Action add emailing
565 if ($action == 'add' && $permissiontocreate) {
566 $object->messtype = (string) GETPOST("messtype");
567 if ($object->messtype == 'sms') {
568 $object->email_from = (string) GETPOST("from_phone", 'alphawithlgt'); // Must allow 'name <email>'
569 } else {
570 $object->email_from = (string) GETPOST("from", 'alphawithlgt'); // Must allow 'name <email>'
571 }
572 $object->email_replyto = (string) GETPOST("replyto", 'alphawithlgt'); // Must allow 'name <email>'
573 $object->email_errorsto = (string) GETPOST("errorsto", 'alphawithlgt'); // Must allow 'name <email>'
574 $object->title = (string) GETPOST("title");
575 $object->sujet = (string) GETPOST("subject");
576 $object->body = (string) GETPOST("bodyemail", 'restricthtml');
577 $object->bgcolor = preg_replace('/^#/', '', (string) GETPOST("bgcolor"));
578 $object->bgimage = (string) GETPOST("bgimage");
579 $object->fk_project = GETPOSTINT('projectid');
580
581 if (!$object->title) {
582 $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTitle"));
583 }
584 if ($object->messtype != 'sms' && !$object->sujet) {
585 $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTopic"));
586 }
587 if (!$object->body) {
588 $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailMessage"));
589 }
590
591 if (!count($mesgs)) {
592 if ($object->create($user) >= 0) {
593 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
594 exit;
595 }
596 $mesgs[] = $object->error;
597 $mesgs = array_merge($mesgs, $object->errors);
598 }
599
600 setEventMessages('', $mesgs, 'errors');
601 $action = "create";
602 }
603
604 if ($action == 'classin' && $permissiontocreate) {
605 $mesgs = array();
606 $setResult = $object->setProject(GETPOSTINT('projectid'));
607 dol_syslog('Mailing card, action classin, setProject', LOG_DEBUG);
608 if ($setResult) {
609 $result = $object->update($user);
610 if ($result >= 0) {
611 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
612 exit;
613 }
614 $mesg = $object->error;
615 setEventMessages($mesg, $mesgs, 'errors');
616 } else {
617 setEventMessages(null, $mesgs, 'errors');
618 }
619
620 $action = "";
621 }
622
623 // Action update description of emailing
624 if (($action == 'settitle' || $action == 'setemail_from' || $action == 'setemail_replyto' || $action == 'setreplyto' || $action == 'setemail_errorsto' || $action == 'setevenunsubscribe') && $permissiontovalidatesend) {
625 $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, getDolGlobalInt('MAILING_USE_NEW_PATH_FOR_FILES') ? 0 : 2, 0, 1, $object, 'mailing');
626
627 if ($action == 'settitle') { // Test on permission already done
628 $object->title = trim(GETPOST('title', 'alpha'));
629 } elseif ($action == 'setemail_from') { // Test on permission already done
630 $object->email_from = trim(GETPOST('email_from', 'alphawithlgt')); // Must allow 'name <email>'
631 } elseif ($action == 'setemail_replyto') { // Test on permission already done
632 $object->email_replyto = trim(GETPOST('email_replyto', 'alphawithlgt')); // Must allow 'name <email>'
633 } elseif ($action == 'setemail_errorsto') { // Test on permission already done
634 $object->email_errorsto = trim(GETPOST('email_errorsto', 'alphawithlgt')); // Must allow 'name <email>'
635 } elseif ($action == 'settitle' && empty($object->title)) { // Test on permission already done
636 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTitle"));
637 } elseif ($action == 'setfrom' && empty($object->email_from)) { // Test on permission already done
638 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailFrom"));
639 } elseif ($action == 'setevenunsubscribe') { // Test on permission already done
640 $object->evenunsubscribe = (GETPOST('evenunsubscribe') ? 1 : 0);
641 }
642
643 if (isset($mesg) && empty($mesg)) {
644 $result = $object->update($user);
645 if ($result >= 0) {
646 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
647 exit;
648 }
649 $mesg = $object->error;
650 }
651 setEventMessages($mesg, $mesgs, 'errors');
652 $action = "";
653 }
654
655 /*
656 * Action of adding a file in email form
657 */
658 if (GETPOST('addfile') && $permissiontocreate) {
659 $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, getDolGlobalInt('MAILING_USE_NEW_PATH_FOR_FILES') ? 0 : 2, 0, 1, $object, 'mailing');
660
661 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
662
663 // Set tmp user directory
664 dol_add_file_process($upload_dir, 0, 0, 'addedfile', '', null, '', 0);
665
666 $action = "edit";
667 }
668
669 // Action of file remove
670 if (GETPOSTINT("removedfile") && $permissiontocreate) {
671 $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, getDolGlobalInt('MAILING_USE_NEW_PATH_FOR_FILES') ? 0 : 2, 0, 1, $object, 'mailing');
672
673 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
674
675 dol_remove_file_process(GETPOSTINT('removedfile'), 0, 0); // We really delete file linked to mailing
676
677 $action = "edit";
678 }
679
680 // Action of emailing update
681 if ($action == 'update' && !GETPOSTINT("removedfile") && !$cancel && $permissiontocreate) {
682 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
683
684 $isupload = 0;
685
686 if (!$isupload) {
687 $mesgs = array();
688
689 //$object->messtype = (string) GETPOST("messtype"); // We must not be able to change the messtype
690 $object->sujet = (string) GETPOST("subject");
691 $object->body = (string) GETPOST("bodyemail", 'restricthtml');
692 $object->bgcolor = preg_replace('/^#/', '', (string) GETPOST("bgcolor"));
693 $object->bgimage = (string) GETPOST("bgimage");
694
695 if ($object->messtype != 'sms' && !$object->sujet) {
696 $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTopic"));
697 }
698 if (!$object->body) {
699 $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailMessage"));
700 }
701
702 if (!count($mesgs)) {
703 if ($object->update($user) >= 0) {
704 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
705 exit;
706 }
707 $mesgs[] = $object->error;
708 $mesgs = array_merge($mesgs, $object->errors);
709 }
710
711 setEventMessages('', $mesgs, 'errors');
712 $action = "edit";
713 } else {
714 $action = "edit";
715 }
716 }
717
718 // Action of validation confirmation
719 if ($action == 'confirm_valid' && $confirm == 'yes' && $permissiontovalidatesend) {
720 if ($object->id > 0) {
721 $object->valid($user);
722 setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
723 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
724 exit;
725 } else {
727 }
728 }
729
730 // Action of validation confirmation
731 if ($action == 'confirm_settodraft' && $confirm == 'yes' && $permissiontocreate) {
732 if ($object->id > 0) {
733 $result = $object->setStatut(0);
734 if ($result > 0) {
735 //setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
736 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
737 exit;
738 } else {
739 setEventMessages($object->error, $object->errors, 'errors');
740 }
741 } else {
743 }
744 }
745
746 // Resend
747 if ($action == 'confirm_reset' && $confirm == 'yes' && $permissiontocreate) {
748 if ($object->id > 0) {
749 $db->begin();
750
751 $result = $object->valid($user);
752 if ($result > 0) {
753 $result = $object->reset_targets_status($user);
754 }
755
756 if ($result > 0) {
757 $db->commit();
758 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
759 exit;
760 } else {
761 setEventMessages($object->error, $object->errors, 'errors');
762 $db->rollback();
763 }
764 } else {
766 }
767 }
768
769 // Action of delete confirmation
770 if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
771 if ($object->delete($user)) {
772 $url = (!empty($urlfrom) ? $urlfrom : 'list.php');
773 header("Location: ".$url);
774 exit;
775 }
776 }
777
778 if ($cancel) {
779 $action = '';
780 }
781}
782
783
784/*
785 * View
786 */
787
788$form = new Form($db);
789$htmlother = new FormOther($db);
790$formproject = null;
791if (isModEnabled('project')) {
792 $formproject = new FormProjets($db);
793}
794
795// Same check as the email templates editor in admin/mails_templates.php so the
796// local media browser is shown consistently in both places.
797$acceptlocallinktomedia = (acceptLocalLinktoMedia() > 0 ? 1 : 0);
798
799$help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
801 '',
802 $langs->trans("Mailing"),
803 $help_url,
804 '',
805 0,
806 0,
807 array(
808 '/includes/ace/src/ace.js',
809 '/includes/ace/src/ext-statusbar.js',
810 '/includes/ace/src/ext-language_tools.js',
811 //'/includes/ace/src/ext-chromevox.js'
812 ),
813 array()
814);
815
816
817if ($action == 'create') { // aaa
818 // EMailing in creation mode
819 print '<form name="new_mailing" action="'.$_SERVER['PHP_SELF'].'" method="POST">'."\n";
820 print '<input type="hidden" name="token" value="'.newToken().'">';
821 print '<input type="hidden" name="action" value="add">';
822
823 $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br><br><span class="small">';
824 foreach ($object->substitutionarray as $key => $val) {
825 $htmltext .= $key.' = '.$langs->trans($val).'<br>';
826 }
827 $htmltext .= '</span></i>';
828
829 $availablelink = '<span class="opacitymedium hideonsmartphone small">'.$form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'helpclickable', '', 0, 2, 'availvar').'</span>';
830
831 // Print mail form
832 print load_fiche_titre($langs->trans("NewMailing"), $availablelink, 'object_email');
833
834 print dol_get_fiche_head(array(), '', '', -3, '', 0, '', 'noborderbottom');
835
836 print '<table class="border centpercent">';
837
838 $title = GETPOST('title');
839 if (empty($title)) {
840 $title = $langs->transnoentities("MailingOf", dol_print_date(dol_now(), 'dayrfc'));
841 }
842 print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("MailTitle").'</td><td><input class="flat minwidth300" id="title" name="title" value="'.dolPrintHTMLForAttribute($title).'" autofocus="autofocus" spellcheck="false"></td></tr>';
843
844 // Project
845 if (isModEnabled('project')) {
846 // Link mailing to project
847 if (GETPOST('origin', 'alpha') == 'project') {
848 $projectid = GETPOSTINT('originid');
849 } else {
850 $projectid = GETPOSTINT('projectid');
851 }
852 if ($projectid > 0) {
853 $object->setProject($projectid);
854 }
855 $langs->load("projects");
856 print '<tr class="field_projectid">';
857 print '<td class="titlefieldcreate">' . $langs->trans("Project") . '</td><td class="valuefieldcreate">';
858 print img_picto('', 'project', 'class="pictofixedwidth"') . $formproject->select_projects(-1, (string) $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx');
859 print ' <a href="' . DOL_URL_ROOT . '/projet/card.php?action=create&status=1&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddProject") . '"></span></a>';
860 print '</td>';
861 print '</tr>';
862 }
863
864 if (getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) {
865 $arrayoftypes = array("email" => "Email", "sms" => "SMS");
866 print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Type").'</td><td>';
867 print $form->selectarray('messtype', $arrayoftypes, (GETPOSTISSET('messtype') ? GETPOST('messtype') : 'email'), 0, 0);
868
869 print '<script>
870 $( document ).ready(function() {
871 jQuery("#messtype").on("change", function() {
872 console.log("We change the message ttpe");
873 if (jQuery("#messtype").val() == "email") {
874 jQuery(".fieldsforsms").hide();
875 jQuery(".fieldsforemail").show();
876 }
877 if (jQuery("#messtype").val() == "sms") {
878 jQuery(".fieldsforsms").show();
879 jQuery(".fieldsforemail").hide();
880 }
881 });
882 jQuery("#messtype").change();
883 })
884 </script>';
885
886 print '</td></tr>';
887 }
888 print '</table>';
889
890 print '<br>';
891
892 print '<table class="border centpercent">';
893
894 print '<tr class="fieldsforemail"><td class="fieldrequired titlefieldcreate">'.$langs->trans("MailFrom").'</td>';
895 print '<td>'.img_picto('', 'email', 'class="pictofixedwidth"').'<input class="flat minwidth200" name="from" value="'.(GETPOSTISSET('from') ? GETPOST('from') : getDolGlobalString('MAILING_EMAIL_FROM')).'" spellcheck="false"></td></tr>';
896
897 print '<tr class="fieldsforsms hidden"><td class="fieldrequired titlefieldcreate">'.$langs->trans("PhoneFrom").'</td>';
898 print '<td>'.img_picto('', 'email', 'class="pictofixedwidth"').'<input class="flat minwidth200" name="fromphone" value="'.(GETPOSTISSET('fromphone') ? GETPOST('fromphone') : getDolGlobalString('MAILING_SMS_FROM')).'" placeholder="+123..."></td></tr>';
899
900 print '<tr class="fieldsforemail"><td>'.$langs->trans("MailErrorsTo").'</td>';
901 print '<td>'.img_picto('', 'email', 'class="pictofixedwidth"').'<input class="flat minwidth200" name="errorsto" value="'.getDolGlobalString('MAILING_EMAIL_ERRORSTO', getDolGlobalString('MAIN_MAIL_ERRORS_TO')).'"></td></tr>';
902
903 print '<tr class="fieldsforemail"><td>'.$langs->trans("MailReply").'</td>';
904 print '<td>'.img_picto('', 'email', 'class="pictofixedwidth"').'<input class="flat minwidth200" name="replyto" value="'.getDolGlobalString('MAILING_EMAIL_REPLYTO', getDolGlobalString('MAIN_MAIL_REPLY_TO')).'"></td></tr>';
905
906 // Other attributes
907 $parameters = array();
908 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
909 print $hookmanager->resPrint;
910 if (empty($reshook)) {
911 print $object->showOptionals($extrafields, 'create');
912 }
913
914 print '</table>';
915
916 print '<br>';
917
918 print '<table class="border centpercent">';
919
920 $subject = GETPOST('subject');
921 if (empty($subject)) {
922 $subject = '['.$mysoc->name.'] '.$langs->trans("Information");
923 }
924
925 print '<tr class="fieldsforemail"><td class="fieldrequired titlefieldcreate">'.$langs->trans("MailTopic").'</td>';
926 print '<td><input id="subject" class="flat minwidth200 quatrevingtpercent" name="subject" id="subject" value="'.dolPrintHTMLForAttributeUrl($subject).'" spellcheck="false"></td></tr>';
927
928 // Background color
929 /* if (getDolGlobalString('EMAILING_CAN_EDIT_BACKGROUND_COLOR')) {
930 print '<tr class="fieldsforemail"><td>'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
931 print $htmlother->selectColor(GETPOST('bgcolor'), 'bgcolor', '', 0);
932 print '</td></tr>';
933 } */
934
935 $formmail = new FormMail($db);
936 $formmail->withfckeditor = 1;
937 $formmail->withlayout = 'emailing';
938 $formmail->withaiprompt = 'html';
939
940 print '<tr class="fieldsforemail"><td></td><td class="tdtop"></td></tr>';
941
942 print '<tr class="fieldsforemail"><td class="tdtop" colspan="2">';
943
944 $out = '';
945 $showlinktolayout = ($formmail->withfckeditor ? $formmail->withlayout : '');
946 $showlinktolayoutlabel = $langs->trans("FillMessageWithALayout");
947 $showlinktoai = ($formmail->withaiprompt && isModEnabled('ai')) ? 'textgenerationemail' : '';
948 $showlinktoailabel = $langs->trans("FillMessageWithAIContent");
949 $formatforouput = 'html';
950 $htmlname = 'bodyemail';
951
952 // Fill $out
953 include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php';
954
955 print $out;
956
957 print '</td></tr>';
958 print '</table>';
959
960
961 print '<div style="padding-top: 10px">';
962 // wysiwyg editor
963 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
964 $doleditor = new DolEditor('bodyemail', GETPOST('bodyemail', 'restricthtmlallowunvalid'), '', 600, 'dolibarr_mailings', '', true, $acceptlocallinktomedia, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%');
965 $doleditor->Create();
966 print '</div>';
967
968 print dol_get_fiche_end();
969
970 print $form->buttonsSaveCancel("Create", 'Cancel');
971
972 print '</form>';
973} else {
974 if ($object->id > 0) {
975 $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, getDolGlobalInt('MAILING_USE_NEW_PATH_FOR_FILES') ? 0 : 2, 0, 1, $object, 'mailing');
976
977 $head = emailing_prepare_head($object);
978
979 if ($action == 'settodraft') {
980 // Confirmation back to draft
981 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("SetToDraft"), $langs->trans("ConfirmUnvalidateEmailing"), "confirm_settodraft", '', '', 1);
982 } elseif ($action == 'valid') {
983 // Confirmation of mailing validation
984 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ValidMailing"), $langs->trans("ConfirmValidMailing"), "confirm_valid", '', '', 1);
985 } elseif ($action == 'reset') {
986 // Confirm reset
987 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ResetMailing"), $langs->trans("ConfirmResetMailing", $object->ref), "confirm_reset", '', '', 2);
988 } elseif ($action == 'delete') {
989 // Confirm delete
990 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id.(!empty($urlfrom) ? '&urlfrom='.urlencode($urlfrom) : ''), $langs->trans("DeleteMailing"), $langs->trans("ConfirmDeleteMailing"), "confirm_delete", '', '', 1);
991 }
992
993 if ($action != 'edit' && $action != 'edittxt' && $action != 'edithtml') {
994 print dol_get_fiche_head($head, 'card', $langs->trans("Mailing"), -1, $object->picto);
995
996 // View mode mailing
997 if ($action == 'sendall') {
998 // Define message to recommend from command line
999 $sendingmode = getDolGlobalString('EMAILING_MAIL_SENDMODE');
1000 if (empty($sendingmode)) {
1001 $sendingmode = getDolGlobalString('MAIN_MAIL_SENDMODE');
1002 }
1003 if (empty($sendingmode)) {
1004 $sendingmode = 'mail'; // If not defined, we use php mail function
1005 }
1006
1007 // MAILING_NO_USING_PHPMAIL may be defined or not.
1008 // MAILING_LIMIT_SENDBYWEB is always defined to something != 0 (-1=forbidden).
1009 // MAILING_LIMIT_SENDBYCLI may be defined or not (-1=forbidden, 0 or undefined=no limit).
1010 // MAILING_LIMIT_SENDBYDAY may be defined or not (0 or undefined=no limit).
1011 if (getDolGlobalString('MAILING_NO_USING_PHPMAIL') && $sendingmode == 'mail') {
1012 // 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.
1013 // You ensure that every user is using its own SMTP server when using the mass emailing module.
1014 $linktoadminemailbefore = '<a href="'.DOL_URL_ROOT.'/admin/mails_emailing.php">';
1015 $linktoadminemailend = '</a>';
1016 setEventMessages($langs->trans("MailSendSetupIs", $listofmethods[$sendingmode]), null, 'warnings');
1017 $messagetoshow = $langs->trans("MailSendSetupIs2", '{s1}', '{s2}', '{s3}', '{s4}');
1018 $messagetoshow = str_replace('{s1}', $linktoadminemailbefore, $messagetoshow);
1019 $messagetoshow = str_replace('{s2}', $linktoadminemailend, $messagetoshow);
1020 $messagetoshow = str_replace('{s3}', $langs->transnoentitiesnoconv("MAIN_MAIL_SENDMODE"), $messagetoshow);
1021 $messagetoshow = str_replace('{s4}', $listofmethods['smtps'], $messagetoshow);
1022 setEventMessages($messagetoshow, null, 'warnings');
1023
1024 if (getDolGlobalString('MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS')) {
1025 setEventMessages($langs->trans("MailSendSetupIs3", getDolGlobalString('MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS')), null, 'warnings');
1026 }
1027 $action = '';
1028 } elseif (getDolGlobalInt('MAILING_LIMIT_SENDBYWEB') < 0) {
1029 if (getDolGlobalString('MAILING_LIMIT_WARNING_PHPMAIL') && $sendingmode == 'mail') {
1030 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
1031 }
1032 if (getDolGlobalString('MAILING_LIMIT_WARNING_NOPHPMAIL') && $sendingmode != 'mail') {
1033 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
1034 }
1035
1036 // The feature is forbidden from GUI, we show just message to use from command line.
1037 setEventMessages($langs->trans("MailingNeedCommand"), null, 'warnings');
1038 setEventMessages('<textarea cols="60" rows="'.ROWS_1.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', null, 'warnings');
1039 if ($conf->file->mailing_limit_sendbyweb != '-1') { // MAILING_LIMIT_SENDBYWEB was set to -1 in database, but it is allowed to increase it.
1040 setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings'); // You can send online with constant...
1041 }
1042 $action = '';
1043 } else {
1044 if (getDolGlobalString('MAILING_LIMIT_WARNING_PHPMAIL') && $sendingmode == 'mail') {
1045 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
1046 }
1047 if (getDolGlobalString('MAILING_LIMIT_WARNING_NOPHPMAIL') && $sendingmode != 'mail') {
1048 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
1049 }
1050
1051 $text = '';
1052
1053 if (getDolGlobalInt('MAILING_LIMIT_SENDBYDAY') > 0) {
1054 $text .= $langs->trans('WarningLimitSendByDay', getDolGlobalInt('MAILING_LIMIT_SENDBYDAY'));
1055 $text .= '<br><br>';
1056 }
1057 $text .= $langs->trans('ConfirmSendingEmailing').'<br>';
1058 $text .= $langs->trans('LimitSendingEmailing', getDolGlobalString('MAILING_LIMIT_SENDBYWEB'));
1059
1060 if (!isset($conf->global->MAILING_LIMIT_SENDBYCLI) || getDolGlobalInt('MAILING_LIMIT_SENDBYCLI') >= 0) {
1061 $text .= '<br><br>';
1062 $text .= '<u>'.$langs->trans("AdvancedAlternative").':</u> '.$langs->trans("MailingNeedCommand");
1063 $text .= '<br><textarea class="quatrevingtpercent" rows="'.ROWS_2.'" wrap="soft" disabled>php ./scripts/emailings/mailing-send.php '.$object->id.' '.$user->login.'</textarea>';
1064 }
1065
1066 $labelbuttonyes = $langs->transnoentities('Confirm');
1067 $labelbuttonno = $langs->transnoentities('Cancel');
1068
1069 print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('SendMailing'), $text, 'sendallconfirmed', '', '', 1, 380, 660, 0, $labelbuttonyes, $labelbuttonno);
1070 }
1071 }
1072
1073 $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1074
1075 $morehtmlref = '<div class="refidno">';
1076 // Ref customer
1077 $morehtmlref .= $form->editfieldkey("", 'title', $object->title, $object, $user->hasRight('mailing', 'creer'), 'string', '', 0, 1);
1078 $morehtmlref .= $form->editfieldval("", 'title', $object->title, $object, $user->hasRight('mailing', 'creer'), 'string', '', null, null, '', 1);
1079
1080 $morehtmlstatus = '';
1081 $nbtry = $nbok = 0;
1082 if ($object->status == $object::STATUS_SENTPARTIALY || $object->status == $object::STATUS_SENTCOMPLETELY) {
1083 $nbtry = $object->countNbOfTargets('alreadysent');
1084 $nbko = $object->countNbOfTargets('alreadysentko');
1085
1086 $morehtmlstatus .= ' ('.$nbtry.'/'.$object->nbemail;
1087 if ($nbko) {
1088 $morehtmlstatus .= ' - '.$nbko.' '.$langs->trans("Error");
1089 }
1090 $morehtmlstatus .= ') &nbsp; ';
1091 }
1092 // Project
1093 if (isModEnabled('project')) {
1094 $langs->load("projects");
1095 $morehtmlref .= '<br>';
1096 if ($permissiontocreate) {
1097 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
1098 if ($action != 'classify') {
1099 $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
1100 }
1101 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, -1, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300', '');
1102 } else {
1103 if (!empty($object->fk_project)) {
1104 $proj = new Project($db);
1105 $proj->fetch($object->fk_project);
1106 $morehtmlref .= $proj->getNomUrl(1, 'mailing');
1107 if ($proj->title) {
1108 $morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
1109 }
1110 }
1111 }
1112 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->fk_project > 0 && $action != 'classify') {
1113 $proj = new Project($db);
1114 $proj->fetch($object->fk_project);
1115 $morehtmlref .= ' <small>(<a href="' . DOL_URL_ROOT . '/comm/mailing/list.php?projectid='.$object->fk_project.'">'.$langs->trans("OtherEMailingsForProject").'</a>)</small>';
1116 }
1117 }
1118 $morehtmlref .= '</div>';
1119
1120 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
1121
1122 print '<div class="fichecenter">';
1123 print '<div class="fichehalfleft">';
1124 print '<div class="underbanner clearboth"></div>';
1125
1126 print '<table class="border centpercent tableforfield">'."\n";
1127
1128 // From
1129 print '<tr><td class="titlefield">';
1130 print $form->editfieldkey("MailFrom", 'email_from', $object->email_from, $object, (int) ($user->hasRight('mailing', 'creer') && $object->status < $object::STATUS_SENTCOMPLETELY), 'string');
1131 print '</td><td>';
1132 print $form->editfieldval("MailFrom", 'email_from', $object->email_from, $object, $user->hasRight('mailing', 'creer') && $object->status < $object::STATUS_SENTCOMPLETELY, 'string');
1133 if ($action != 'editemail_from') {
1134 $email = CMailFile::getValidAddress($object->email_from, 2);
1135 if ($email && !isValidEmail($email)) {
1136 $langs->load("errors");
1137 print img_warning($langs->transnoentitiesnoconv("ErrorBadEMail", $email));
1138 } elseif ($email && !isValidMailDomain($email)) {
1139 $langs->load("errors");
1140 print img_warning($langs->transnoentitiesnoconv("ErrorBadMXDomain", $email));
1141 }
1142 }
1143 print '</td></tr>';
1144
1145 // Errors to
1146 if ($object->messtype != 'sms') {
1147 print '<tr><td>';
1148 print $form->editfieldkey("MailErrorsTo", 'email_errorsto', $object->email_errorsto, $object, (int) ($user->hasRight('mailing', 'creer') && $object->status < $object::STATUS_SENTCOMPLETELY), 'string');
1149 print '</td><td>';
1150 print $form->editfieldval("MailErrorsTo", 'email_errorsto', $object->email_errorsto, $object, $user->hasRight('mailing', 'creer') && $object->status < $object::STATUS_SENTCOMPLETELY, 'string');
1151
1152 $emailarray = CMailFile::getArrayAddress($object->email_errorsto);
1153 foreach ($emailarray as $email => $name) {
1154 if ($name != $email) {
1155 if ($action != 'editemail_errorsto') {
1156 if ($email && !isValidEmail($email)) {
1157 $langs->load("errors");
1158 print img_warning($langs->transnoentitiesnoconv("ErrorBadEMail", $email));
1159 } elseif ($email && !isValidMailDomain($email)) {
1160 $langs->load("errors");
1161 print img_warning($langs->transnoentitiesnoconv("ErrorBadMXDomain", $email));
1162 }
1163 }
1164 } else {
1165 if ($object->email_errorsto) {
1166 print dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1);
1167 }
1168 }
1169 }
1170 print '</td></tr>';
1171 }
1172
1173 // Reply to
1174 if ($object->messtype != 'sms') {
1175 print '<tr><td>';
1176 print $form->editfieldkey("MailReply", 'email_replyto', $object->email_replyto, $object, (int) ($user->hasRight('mailing', 'creer') && $object->status < $object::STATUS_SENTCOMPLETELY), 'string');
1177 print '</td><td>';
1178 print $form->editfieldval("MailReply", 'email_replyto', $object->email_replyto, $object, $user->hasRight('mailing', 'creer') && $object->status < $object::STATUS_SENTCOMPLETELY, 'string');
1179 $email = CMailFile::getValidAddress($object->email_replyto, 2);
1180 if ($action != 'editemail_replyto') {
1181 if ($email && !isValidEmail($email)) {
1182 $langs->load("errors");
1183 print img_warning($langs->trans("ErrorBadEMail", $email));
1184 } elseif ($email && !isValidMailDomain($email)) {
1185 $langs->load("errors");
1186 print img_warning($langs->trans("ErrorBadMXDomain", $email));
1187 }
1188 }
1189 print '</td></tr>';
1190 }
1191
1192 print '</table>';
1193 print '</div>';
1194
1195 print '<div class="fichehalfright">';
1196 print '<div class="underbanner clearboth"></div>';
1197
1198 print '<table class="border centpercent tableforfield">';
1199
1200 // Number of distinct emails
1201 print '<tr><td>';
1202 print $langs->trans("TotalNbOfDistinctRecipients");
1203 print '</td><td>';
1204 $nbemail = ($object->nbemail ? $object->nbemail : 0);
1205 if (is_numeric($nbemail)) {
1206 $htmltooltip = '';
1207 if ((getDolGlobalString('MAILING_LIMIT_SENDBYWEB') && getDolGlobalInt('MAILING_LIMIT_SENDBYWEB') < $nbemail) && ($object->status == 1 || ($object->status == 2 && $nbtry < $nbemail))) {
1208 if (getDolGlobalInt('MAILING_LIMIT_SENDBYWEB') > 0) {
1209 $htmltooltip .= $langs->trans('LimitSendingEmailing', getDolGlobalString('MAILING_LIMIT_SENDBYWEB'));
1210 } else {
1211 $htmltooltip .= $langs->trans('SendingFromWebInterfaceIsNotAllowed');
1212 }
1213 }
1214 if (empty($nbemail)) {
1215 $nbemail .= ' '.img_warning('').' <span class="warning">'.$langs->trans("NoTargetYet").'</span>';
1216 }
1217 if ($htmltooltip) {
1218 print $form->textwithpicto($nbemail, $htmltooltip, 1, 'info');
1219 } else {
1220 print $nbemail;
1221 }
1222 }
1223 print '</td></tr>';
1224
1225 print '<tr><td>';
1226 print $langs->trans("MAIN_MAIL_SENDMODE");
1227 print '</td><td>';
1228 if ($object->messtype != 'sms') {
1229 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') && getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') != 'default') {
1230 $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING')];
1231 } elseif (getDolGlobalString('MAIN_MAIL_SENDMODE')) {
1232 $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE')];
1233 } else {
1234 $text = $listofmethods['mail'];
1235 }
1236 print $text;
1237 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') != 'default') {
1238 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') != 'mail') {
1239 print ' <span class="opacitymedium">('.getDolGlobalString('MAIN_MAIL_SMTP_SERVER_EMAILING', getDolGlobalString('MAIN_MAIL_SMTP_SERVER')).')</span>';
1240 }
1241 } elseif (getDolGlobalString('MAIN_MAIL_SENDMODE') != 'mail' && getDolGlobalString('MAIN_MAIL_SMTP_SERVER')) {
1242 print ' <span class="opacitymedium">('.getDolGlobalString('MAIN_MAIL_SMTP_SERVER').')</span>';
1243 }
1244 } else {
1245 print 'SMS ';
1246 print ' <span class="opacitymedium">('.getDolGlobalString('MAIN_MAIL_SMTP_SERVER').')</span>';
1247 }
1248 print '</td></tr>';
1249
1250 // Other attributes. Fields from hook formObjectOptions and Extrafields.
1251 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1252
1253 print '</table>';
1254 print '</div>';
1255 print '</div>';
1256
1257 print '<div class="clearboth"></div>';
1258
1259 print dol_get_fiche_end();
1260
1261
1262 // Clone confirmation
1263 if ($action == 'clone') {
1264 // Create an array for form
1265 $formquestion = array(
1266 'text' => $langs->trans("ConfirmClone"),
1267 0 => array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneContent"), 'value' => 1),
1268 1 => array('type' => 'checkbox', 'name' => 'clone_receivers', 'label' => $langs->trans("CloneReceivers"), 'value' => 0)
1269 );
1270 // Incomplete payment. On demande si motif = escompte ou autre
1271 print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneEMailing', $object->ref), 'confirm_clone', $formquestion, 'yes', 2, 240);
1272 }
1273
1274 // Actions Buttons
1275 if (GETPOST('cancel', 'alpha') || $confirm == 'no' || $action == '' || in_array($action, array('settodraft', 'valid', 'delete', 'sendall', 'clone', 'test', 'editevenunsubscribe'))) {
1276 print "\n\n<div class=\"tabsAction\">\n";
1277
1278 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action);
1279
1280
1281 if (($object->status == 1) && ($user->hasRight('mailing', 'valider') || $object->user_validation_id == $user->id)) {
1282 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=settodraft&token='.newToken().'&id='.$object->id.'">'.$langs->trans("SetToDraft").'</a>';
1283 }
1284
1285 if (($object->status == 0 || $object->status == 1 || $object->status == 2) && $user->hasRight('mailing', 'creer')) {
1286 if (isModEnabled('fckeditor') && getDolGlobalInt('FCKEDITOR_ENABLE_MAILING') && $object->messtype != 'sms') {
1287 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Edit").'</a>';
1288 } else {
1289 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edittxt&token='.newToken().'&id='.$object->id.'">'.$langs->trans("EditWithTextEditor").'</a>';
1290 }
1291
1292 if (!getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) {
1293 if (!empty($conf->use_javascript_ajax)) {
1294 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edithtml&token='.newToken().'&id='.$object->id.'">'.$langs->trans("EditHTMLSource").'</a>';
1295 }
1296 }
1297 }
1298
1299 //print '<a class="butAction" href="card.php?action=test&amp;id='.$object->id.'">'.$langs->trans("PreviewMailing").'</a>';
1300
1301 if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('mailing', 'mailing_advance', 'send')) {
1302 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("TestMailing").'</a>';
1303 } else {
1304 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=test&token='.newToken().'&id='.$object->id.'">'.$langs->trans("TestMailing").'</a>';
1305 }
1306
1307 if ($object->status == 0) {
1308 if ($object->nbemail <= 0) {
1309 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoTargetYet")).'">'.$langs->trans("Validate").'</a>';
1310 } elseif (!$user->hasRight('mailing', 'valider')) {
1311 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("Validate").'</a>';
1312 } else {
1313 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=valid&amp;id='.$object->id.'">'.$langs->trans("Validate").'</a>';
1314 }
1315 }
1316
1317 if (($object->status == 1 || $object->status == 2) && $object->nbemail > 0 && $user->hasRight('mailing', 'valider')) {
1318 if (getDolGlobalInt('MAILING_LIMIT_SENDBYWEB') < 0) {
1319 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("SendingFromWebInterfaceIsNotAllowed")).'">'.$langs->trans("SendMailing").'</a>';
1320 } elseif (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('mailing', 'mailing_advance', 'send')) {
1321 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("SendMailing").'</a>';
1322 } else {
1323 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=sendall&amp;id='.$object->id.'">'.$langs->trans("SendMailing").'</a>';
1324 }
1325 }
1326
1327 if ($user->hasRight('mailing', 'creer')) {
1328 print '<a class="butAction butActionClone" href="'.$_SERVER['PHP_SELF'].'?action=clone&amp;object=emailing&amp;id='.$object->id.'">'.$langs->trans("ToClone").'</a>';
1329 }
1330
1331 if (($object->status == 2 || $object->status == 3) && $user->hasRight('mailing', 'valider')) {
1332 if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('mailing', 'mailing_advance', 'send')) {
1333 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ResetMailing").'</a>';
1334 } else {
1335 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=reset&amp;id='.$object->id.'">'.$langs->trans("ResetMailing").'</a>';
1336 }
1337 }
1338
1339 if (($object->status <= 1 && $user->hasRight('mailing', 'creer')) || $user->hasRight('mailing', 'supprimer')) {
1340 if ($object->status > 0 && (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('mailing', 'mailing_advance', 'delete'))) {
1341 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("Delete").'</a>';
1342 } else {
1343 print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$object->id.(!empty($urlfrom) ? '&urlfrom='.$urlfrom : '').'">'.$langs->trans("Delete").'</a>';
1344 }
1345 }
1346
1347 print '</div>';
1348 }
1349
1350 // Display of the TEST form
1351 if ($action == 'test') {
1352 print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
1353 print load_fiche_titre($langs->trans("TestMailing"));
1354
1355 print dol_get_fiche_head([], '', '', -1);
1356
1357 // Create mail form object
1358 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1359 $formmail = new FormMail($db);
1360 $formmail->fromname = $object->email_from;
1361 $formmail->frommail = $object->email_from;
1362 $formmail->withsubstit = 0;
1363 $formmail->withfrom = 0;
1364 $formmail->withto = $user->email ? $user->email : 1;
1365 $formmail->withtocc = 0;
1366 $formmail->withtoccc = getDolGlobalString('MAIN_EMAIL_USECCC');
1367 $formmail->withtopic = 0;
1368 $formmail->withtopicreadonly = 1;
1369 $formmail->withfile = 0;
1370 $formmail->withlayout = '';
1371 $formmail->withaiprompt = '';
1372 $formmail->withbody = 0;
1373 $formmail->withbodyreadonly = 1;
1374 $formmail->withcancel = 1;
1375 $formmail->withdeliveryreceipt = 0;
1376 // Table of substitutions
1377 $formmail->substit = $object->substitutionarrayfortest;
1378 // Table of post's complementary params
1379 $formmail->param["action"] = "send";
1380 $formmail->param["models"] = 'none';
1381 $formmail->param["mailid"] = $object->id;
1382 $formmail->param["returnurl"] = $_SERVER['PHP_SELF']."?id=".$object->id;
1383
1384 print $formmail->get_form();
1385
1386 print '<br>';
1387
1388 print dol_get_fiche_end();
1389
1390 dol_set_focus('#sendto');
1391 }
1392
1393
1394 $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br><br><span class="small">';
1395 foreach ($object->substitutionarray as $key => $val) {
1396 $htmltext .= $key.' = '.$langs->trans($val).'<br>';
1397 }
1398 $htmltext .= '</span></i>';
1399
1400 $availablelink = '<span class="opacitymedium hideonsmartphone">'.$form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'helpclickable', '', 0, 3, 'emailsubstitionhelp').'</span>';
1401
1402 // Print mail content
1403 print load_fiche_titre($langs->trans("EMail"), $availablelink, 'generic');
1404
1405 print dol_get_fiche_head([], '', '', -1);
1406
1407 print '<table class="bordernooddeven tableforfield centpercent">';
1408
1409 // Subject
1410 if ($object->messtype != 'sms') {
1411 print '<tr><td class="titlefield">'.$langs->trans("MailTopic").'</td><td colspan="3">'.$object->sujet.'</td></tr>';
1412 }
1413
1414 // Joined files
1415 if ($object->messtype != 'sms') {
1416 print '<tr><td>'.$langs->trans("MailFile").'</td><td colspan="3">';
1417 // List of files
1418 $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
1419 if (count($listofpaths)) {
1420 foreach ($listofpaths as $key => $val) {
1421 print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
1422 print '<br>';
1423 }
1424 } else {
1425 print '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
1426 }
1427 print '</td></tr>';
1428 }
1429
1430 // Background color
1431 /* if (getDolGlobalString('EMAILING_CAN_EDIT_BACKGROUND_COLOR')) {
1432 print '<tr><td width="15%">'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
1433 print $htmlother->selectColor($object->bgcolor,'bgcolor','',0);
1434 print '</td></tr>';
1435 }*/
1436
1437 print '</table>';
1438
1439 // Message
1440 print '<div class="previewemail" style="padding-top: 10px; background: '.($object->bgcolor ? (preg_match('/^#/', $object->bgcolor) ? '' : '#').$object->bgcolor : 'white').'">';
1441 if (empty($object->bgcolor) || strtolower($object->bgcolor) == 'ffffff') { // CKEditor does not apply the color of the div into its content area
1442 $readonly = 1;
1443 // wysiwyg editor
1444 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1445 $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', false, $acceptlocallinktomedia, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%', $readonly);
1446 $doleditor->Create();
1447 } else {
1448 print dol_htmlentitiesbr($object->body);
1449 }
1450 print '</div>';
1451
1452 print dol_get_fiche_end();
1453 } else {
1454 /*
1455 * Edition mode mailing (CKeditor or HTML source)
1456 */
1457
1458 print dol_get_fiche_head($head, 'card', $langs->trans("Mailing"), -1, $object->picto);
1459
1460 $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1461
1462 $morehtmlref = '<div class="refidno">';
1463 // Ref customer
1464 $morehtmlref .= $form->editfieldkey("", 'title', $object->title, $object, $user->hasRight('mailing', 'creer'), 'string', '', 0, 1);
1465 $morehtmlref .= $form->editfieldval("", 'title', $object->title, $object, $user->hasRight('mailing', 'creer'), 'string', '', null, null, '', 1);
1466
1467 $morehtmlstatus = '';
1468 $nbtry = $nbok = 0;
1469 if ($object->status == 2 || $object->status == 3) {
1470 $nbtry = $object->countNbOfTargets('alreadysent');
1471 $nbko = $object->countNbOfTargets('alreadysentko');
1472
1473 $morehtmlstatus .= ' ('.$nbtry.'/'.$object->nbemail;
1474 if ($nbko) {
1475 $morehtmlstatus .= ' - '.$nbko.' '.$langs->trans("Error");
1476 }
1477 $morehtmlstatus .= ') &nbsp; ';
1478 }
1479
1480 // Project
1481 if (isModEnabled('project')) {
1482 $langs->load("projects");
1483 $morehtmlref .= '<br>';
1484 if ($permissiontocreate) {
1485 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
1486 $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
1487 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, -1, (string) $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300', '');
1488 } else {
1489 if (!empty($object->fk_project)) {
1490 $proj = new Project($db);
1491 $proj->fetch($object->fk_project);
1492 $morehtmlref .= $proj->getNomUrl(1, 'mailing');
1493 if ($proj->title) {
1494 $morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
1495 }
1496 }
1497 }
1498 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK')) {
1499 $proj = new Project($db);
1500 $proj->fetch($object->fk_project);
1501 $morehtmlref .= '<!-- Edit mode, so we open url in new window -->';
1502 $morehtmlref .= ' <small>(<a href="' . DOL_URL_ROOT . '/comm/mailing/list.php?projectid='.$object->fk_project.'" target="_blank">' .$langs->trans("Other").' '.$langs->trans("EMailings").' for '.$langs->trans("Project").': '. $proj->title. '</a>)</small>';
1503 }
1504 }
1505 $morehtmlref .= '</div>';
1506
1507 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
1508
1509 print '<div class="fichecenter">';
1510 print '<div class="fichehalfleft">';
1511 print '<div class="underbanner clearboth"></div>';
1512
1513 print '<table class="border centpercent tableforfield">';
1514
1515 /*
1516 print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td>';
1517 print '<td colspan="3">';
1518 print $form->showrefnav($object,'id', $linkback);
1519 print '</td></tr>';
1520 */
1521
1522 // From
1523 print '<tr><td class="titlefield">';
1524 print $langs->trans("MailFrom");
1525 print '</td><td>'.dol_print_email($object->email_from, 0, 0, 0, 0, 1).'</td></tr>';
1526 // To
1527 if ($object->messtype != 'sms') {
1528 print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>'.dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1).'</td></tr>';
1529 print '<tr><td>'.$langs->trans("MailReply").'</td><td>'.dol_print_email($object->email_replyto, 0, 0, 0, 0, 1).'</td></tr>';
1530 }
1531
1532 print '</table>';
1533 print '</div>';
1534
1535
1536 print '<div class="fichehalfright">';
1537 print '<div class="underbanner clearboth"></div>';
1538
1539 print '<table class="border centpercent tableforfield">';
1540
1541 // Number of distinct emails
1542 print '<tr><td>';
1543 print $langs->trans("TotalNbOfDistinctRecipients");
1544 print '</td><td>';
1545 $nbemail = ($object->nbemail ? $object->nbemail : 0);
1546 if (is_numeric($nbemail)) {
1547 $htmltooltip = '';
1548 // MAILING_LIMIT_SENDBYWEB can be 'default'
1549 if ((getDolGlobalString('MAILING_LIMIT_SENDBYWEB') && getDolGlobalInt('MAILING_LIMIT_SENDBYWEB') < $nbemail) && ($object->status == 1 || $object->status == 2)) {
1550 if (getDolGlobalInt('MAILING_LIMIT_SENDBYWEB') > 0) {
1551 $htmltooltip .= $langs->trans('LimitSendingEmailing', getDolGlobalString('MAILING_LIMIT_SENDBYWEB'));
1552 } else {
1553 $htmltooltip .= $langs->trans('SendingFromWebInterfaceIsNotAllowed');
1554 }
1555 }
1556 if (empty($nbemail)) {
1557 $nbemail .= ' '.img_warning('').' <span class="warning">'.$langs->trans("NoTargetYet").'</span>';
1558 }
1559 if ($htmltooltip) {
1560 print $form->textwithpicto($nbemail, $htmltooltip, 1, 'warning');
1561 } else {
1562 print $nbemail;
1563 }
1564 }
1565 print '</td></tr>';
1566
1567 print '<tr><td>';
1568 print $langs->trans("MAIN_MAIL_SENDMODE");
1569 print '</td><td>';
1570 if ($object->messtype != 'sms') {
1571 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') && getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') != 'default') {
1572 $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING')];
1573 } elseif (getDolGlobalString('MAIN_MAIL_SENDMODE')) {
1574 $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE')];
1575 } else {
1576 $text = $listofmethods['mail'];
1577 }
1578 print $text;
1579 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') != 'default') {
1580 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') != 'mail') {
1581 print ' <span class="opacitymedium">('.getDolGlobalString('MAIN_MAIL_SMTP_SERVER_EMAILING', getDolGlobalString('MAIN_MAIL_SMTP_SERVER')).')</span>';
1582 }
1583 } elseif (getDolGlobalString('MAIN_MAIL_SENDMODE') != 'mail' && getDolGlobalString('MAIN_MAIL_SMTP_SERVER')) {
1584 print ' <span class="opacitymedium">('.getDolGlobalString('MAIN_MAIL_SMTP_SERVER').')</span>';
1585 }
1586 } else {
1587 print 'SMS ';
1588 print ' <span class="opacitymedium">('.getDolGlobalString('MAIN_MAIL_SMTP_SERVER').')</span>';
1589 }
1590 print '</td></tr>';
1591
1592
1593 // Other attributes
1594 $parameters = array();
1595 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1596 print $hookmanager->resPrint;
1597 if (empty($reshook)) {
1598 print $object->showOptionals($extrafields, 'edit', $parameters);
1599 }
1600
1601 print '</table>';
1602 print '</div>';
1603 print '</div>';
1604
1605 print '<div class="clearboth"></div>';
1606
1607 print dol_get_fiche_end();
1608
1609
1610 print "<br><br>\n";
1611
1612 print '<form name="edit_mailing" action="card.php" method="post" enctype="multipart/form-data">'."\n";
1613 print '<input type="hidden" name="token" value="'.newToken().'">';
1614 print '<input type="hidden" name="action" value="update">';
1615 print '<input type="hidden" name="id" value="'.$object->id.'">';
1616 print '<input type="hidden" name="page_y" value="">';
1617
1618 $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br><br><span class="small">';
1619 foreach ($object->substitutionarray as $key => $val) {
1620 $htmltext .= $key.' = '.$langs->trans($val).'<br>';
1621 }
1622 $htmltext .= '</span></i>';
1623
1624 $availablelink = '<span class="opacitymedium small">'.$form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'helpclickable', '', 0, 2, 'emailsubstitionhelp').'</span>';
1625
1626 // Print mail content
1627 print load_fiche_titre($langs->trans("EMail"), $availablelink, 'generic');
1628
1629 print dol_get_fiche_head([], '', '', -1);
1630
1631 print '<table class="bordernooddeven centpercent">';
1632
1633 // Subject
1634 if ($object->messtype != 'sms') {
1635 print '<tr><td class="fieldrequired titlefield">';
1636 print $form->textwithpicto($langs->trans("MailTopic"), $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp');
1637 print '</td><td colspan="3"><input class="flat quatrevingtpercent" type="text" id="subject" name="subject" value="'.$object->sujet.'" spellcheck="false"></td></tr>';
1638 }
1639
1640 $trackid = ''; // TODO To avoid conflicts with 2 mass emailing, we should set a trackid here, even if we use another one into email header.
1641 dol_init_file_process($upload_dir, $trackid);
1642
1643 // Joined files
1644 if ($object->messtype != 'sms') {
1645 $addfileaction = 'addfile';
1646 print '<tr><td>'.$langs->trans("MailFile").'</td>';
1647 print '<td colspan="3">';
1648 // List of files
1649 $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
1650 $out = '';
1651
1652 // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
1653 $out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
1654 $out .= '<script type="text/javascript">';
1655 $out .= 'jQuery(document).ready(function () {';
1656 $out .= ' jQuery(".removedfile").click(function() {';
1657 $out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());';
1658 $out .= ' });';
1659 $out .= '})';
1660 $out .= '</script>'."\n";
1661 if (count($listofpaths)) {
1662 foreach ($listofpaths as $key => $val) {
1663 $out .= '<div id="attachfile_'.$key.'">';
1664 $out .= img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
1665 $out .= ' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans("Search"), 'delete', '', 0, 1).'" value="'.($key + 1).'" class="removedfile" id="removedfile_'.$key.'" name="removedfile_'.$key.'" />';
1666 $out .= '<br></div>';
1667 }
1668 } else {
1669 //$out .= '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
1670 }
1671
1672 // Add link to add file
1673 $maxfilesizearray = getMaxFileSizeArray();
1674 $maxmin = $maxfilesizearray['maxmin'];
1675 if ($maxmin > 0) {
1676 $out .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
1677 }
1678 $out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
1679 $out .= ' ';
1680 $out .= '<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
1681 print $out;
1682 print '</td></tr>';
1683
1684 // Background color
1685 print '<tr><td>'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
1686 print $htmlother->selectColor($object->bgcolor, 'bgcolor', '', 0);
1687 print '</td></tr>';
1688 }
1689
1690
1691 // Add editor assistants
1692 $out = '';
1693 $out .= '<tr>';
1694 $out .= '<td class="tdtop">';
1695 $out .= $form->textwithpicto($langs->trans('MailText'), $htmltext, 1, 'help', '', 0, 2, 'substittooltipfrombody');
1696 $out .= '</td>';
1697 $out .= '<td class="tdtop">';
1698
1699 //$formmail = $this;
1700 $showlinktolayout = getDolGlobalInt('MAIN_EMAIL_USE_LAYOUT') ? 'emailing' : '';
1701 $showlinktolayoutlabel = $langs->trans("FillMessageWithALayout");
1702 $showlinktoai = isModEnabled('ai') ? 'textgenerationemail' : '';
1703 $showlinktoailabel = $langs->trans("AIEnhancements");
1704 $formatforouput = '';
1705 $htmlname = 'bodyemail';
1706 //$formai->substit = $this->substit;
1707 //$formai->substit_lines = $this->substit_lines;
1708
1709 // Fill $out
1710 include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php';
1711
1712 $out .= '</td>';
1713 $out .= '</tr>';
1714
1715 print $out;
1716
1717 print '</table>';
1718
1719
1720 // Message
1721 print '<div style="padding-top: 10px">';
1722
1723 if ($action == 'edit') {
1724 // wysiwyg editor
1725 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1726 if ($object->bgcolor) {
1727 if (!preg_match('/^<div style="background-color: #'.$object->bgcolor.'">/', $object->body)) {
1728 $object->body = '<div style="background-color: #'.$object->bgcolor.'; margin-bottom:-20px; margin-left:-10px; margin-right:-10px; margin-top:-10px; padding: 10px;">'.$object->body.'</div>';
1729 }
1730 }
1731 $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, $acceptlocallinktomedia, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%');
1732 $doleditor->Create();
1733 }
1734 if ($action == 'edittxt') {
1735 // wysiwyg editor
1736 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1737 $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, $acceptlocallinktomedia, 0, 20, '100%');
1738 $doleditor->Create();
1739 }
1740 if ($action == 'edithtml') {
1741 // HTML source editor
1742 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1743 $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, $acceptlocallinktomedia, 'ace', 20, '100%');
1744 $doleditor->Create(0, '', false, 'HTML Source', 'php');
1745 }
1746
1747 print '</div>';
1748
1749 print dol_get_fiche_end();
1750
1751 print '<div class="center">';
1752 print '<input type="submit" class="button buttonforacesave button-save" value="'.$langs->trans("Save").'" name="save">';
1753 print '&nbsp; &nbsp; &nbsp;';
1754 print '<input type="submit" class="button button-cancel" value="'.$langs->trans("Cancel").'" name="cancel">';
1755 print '</div>';
1756
1757 print '</form>';
1758 print '<br>';
1759 }
1760 } else {
1761 dol_print_error($db, $object->error);
1762 }
1763}
1764
1765// End of page
1766llxFooter();
1767$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
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.
static getArrayAddress($address)
Return a formatted array of address string for SMTP protocol.
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
static getAvailableSubstitKey($mode='formemail', $object=null)
Get list of substitution keys available for emails.
Class to help generate other html components Only common components are here.
Class to manage building of HTML components.
Class to manage emailings module.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
emailing_prepare_head(Mailing $object)
Prepare array with list of tabs.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=0, $keyforsourcefile='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null, $forceFullTextIndexation='', $mode=0)
Get and save an upload file (for example after submitting a new file in a mail form).
dol_init_file_process($pathtoscan='', $trackid='')
Scan a directory and init $_SESSION to manage uploaded files with list of all found files.
dol_remove_file_process($filenb, $donotupdatesession=0, $donotdeletefile=1, $trackid='')
Remove an uploaded file (for example after submitting a new file a mail form).
dol_dir_list($utf8_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:64
acceptLocalLinktoMedia()
Check the syntax of some PHP code.
isValidMailDomain($mail)
Return true if email has a domain name that can be resolved to MX type.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
getMaxFileSizeArray()
Return the max allowed for file upload.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.