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