27 if (!defined(
'NOSTYLECHECK')) {
28 define(
'NOSTYLECHECK',
'1');
32 require
'../../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/emailing.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/mailing.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
43 $langs->load(
"mails");
47 $action =
GETPOST(
'action',
'aZ09');
48 $confirm =
GETPOST(
'confirm',
'alpha');
49 $cancel =
GETPOST(
'cancel',
'aZ09');
56 $result = $object->fetch($id);
59 $extrafields->fetch_name_optionals_label($object->table_element);
62 $hookmanager->initHooks(array(
'mailingcard',
'globalcard'));
69 $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $user->signature :
'');
76 $object->substitutionarrayfortest = $substitutionarray;
79 $listofmethods = array();
80 $listofmethods[
'mail'] =
'PHP mail function';
81 $listofmethods[
'smtps'] =
'SMTP/SMTPS socket library';
84 if (empty($user->rights->mailing->lire) || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->socid > 0)) {
88 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
96 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
101 if (empty($reshook)) {
104 $backurlforlist = DOL_URL_ROOT.
'/comm/mailing/list.php';
106 if (empty($backtopage) || ($cancel && empty($id))) {
107 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
108 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
109 $backtopage = $backurlforlist;
111 $backtopage = DOL_URL_ROOT.
'/comm/mailing/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
118 if (!empty($backtopageforcancel)) {
119 header(
"Location: ".$backtopageforcancel);
121 } elseif (!empty($backtopage)) {
122 header(
"Location: ".$backtopage);
129 if ($action ==
'confirm_clone' && $confirm ==
'yes') {
130 if (!
GETPOST(
"clone_content",
'alpha') && !
GETPOST(
"clone_receivers",
'alpha')) {
133 $result = $object->createFromClone($user, $object->id,
GETPOST(
"clone_content",
'alpha'),
GETPOST(
"clone_receivers",
'alpha'));
135 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
145 if ($action ==
'sendallconfirmed' && $confirm ==
'yes') {
146 if (empty($conf->global->MAILING_LIMIT_SENDBYWEB)) {
149 setEventMessages(
'<textarea cols="70" rows="'.ROWS_2.
'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.
'</textarea>',
null,
'warnings');
152 } elseif ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
156 if ($object->statut == 0) {
162 $subject = $object->sujet;
163 $message = $object->body;
164 $from = $object->email_from;
165 $replyto = $object->email_replyto;
166 $errorsto = $object->email_errorsto;
169 if (preg_match(
'/[\s\t]*<html>/i', $message)) {
176 $nbok = 0; $nbko = 0;
180 $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";
181 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc";
182 $sql .=
" WHERE mc.statut < 1 AND mc.fk_mailing = ".((int) $object->id);
183 $sql .=
" ORDER BY mc.statut DESC";
185 dol_syslog(
"card.php: select targets", LOG_DEBUG);
186 $resql = $db->query($sql);
188 $num = $db->num_rows(
$resql);
191 dol_syslog(
"comm/mailing/card.php: nb of targets = ".$num, LOG_DEBUG);
196 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing SET date_envoi='".$db->idate($now).
"' WHERE rowid=".((int) $object->id);
197 $resql2 = $db->query($sql);
202 $thirdpartystatic =
new Societe($db);
206 while ($iforemailloop < $num && $iforemailloop < $conf->global->MAILING_LIMIT_SENDBYWEB) {
211 $obj = $db->fetch_object(
$resql);
214 $sendto = str_replace(
',',
' ',
dolGetFirstLastname($obj->firstname, $obj->lastname)).
" <".$obj->email.
">";
217 $other = explode(
';', $obj->other);
218 $tmpfield = explode(
'=', $other[0], 2); $other1 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
219 $tmpfield = explode(
'=', $other[1], 2); $other2 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
220 $tmpfield = explode(
'=', $other[2], 2); $other3 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
221 $tmpfield = explode(
'=', $other[3], 2); $other4 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
222 $tmpfield = explode(
'=', $other[4], 2); $other5 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
224 $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $user->signature :
'');
226 $targetobject =
null;
231 $substitutionarray[
'__ID__'] = $obj->source_id;
232 if ($obj->source_type ==
"thirdparty") {
233 $result = $thirdpartystatic->fetch($obj->source_id);
236 $substitutionarray[
'__THIRDPARTY_CUSTOMER_CODE__'] = $thirdpartystatic->code_client;
238 $substitutionarray[
'__THIRDPARTY_CUSTOMER_CODE__'] =
'';
241 $substitutionarray[
'__EMAIL__'] = $obj->email;
242 $substitutionarray[
'__LASTNAME__'] = $obj->lastname;
243 $substitutionarray[
'__FIRSTNAME__'] = $obj->firstname;
244 $substitutionarray[
'__MAILTOEMAIL__'] =
'<a href="mailto:'.$obj->email.
'">'.$obj->email.
'</a>';
245 $substitutionarray[
'__OTHER1__'] = $other1;
246 $substitutionarray[
'__OTHER2__'] = $other2;
247 $substitutionarray[
'__OTHER3__'] = $other3;
248 $substitutionarray[
'__OTHER4__'] = $other4;
249 $substitutionarray[
'__OTHER5__'] = $other5;
250 $substitutionarray[
'__USER_SIGNATURE__'] = $signature;
251 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $signature;
252 $substitutionarray[
'__CHECK_READ__'] =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php?tag='.urlencode($obj->tag).
'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).
'&email='.urlencode($obj->email).
'&mtid='.$obj->rowid.
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
253 $substitutionarray[
'__UNSUBSCRIBE__'] =
'<a href="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-unsubscribe.php?tag='.urlencode($obj->tag).
'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).
'&email='.urlencode($obj->email).
'&mtid='.$obj->rowid.
'" target="_blank" rel="noopener noreferrer">'.$langs->trans(
"MailUnsubcribe").
'</a>';
254 $substitutionarray[
'__UNSUBSCRIBE_URL__'] = DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-unsubscribe.php?tag='.urlencode($obj->tag).
'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).
'&email='.urlencode($obj->email).
'&mtid='.$obj->rowid;
256 $onlinepaymentenabled = 0;
258 $onlinepaymentenabled++;
261 $onlinepaymentenabled++;
264 $onlinepaymentenabled++;
266 if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
267 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
268 $substitutionarray[
'__ONLINEPAYMENTLINK_MEMBER__'] = getHtmlOnlinePaymentLink(
'member', $obj->source_id);
269 $substitutionarray[
'__ONLINEPAYMENTLINK_DONATION__'] = getHtmlOnlinePaymentLink(
'donation', $obj->source_id);
270 $substitutionarray[
'__ONLINEPAYMENTLINK_ORDER__'] = getHtmlOnlinePaymentLink(
'order', $obj->source_id);
271 $substitutionarray[
'__ONLINEPAYMENTLINK_INVOICE__'] = getHtmlOnlinePaymentLink(
'invoice', $obj->source_id);
272 $substitutionarray[
'__ONLINEPAYMENTLINK_CONTRACTLINE__'] = getHtmlOnlinePaymentLink(
'contractline', $obj->source_id);
274 $substitutionarray[
'__SECUREKEYPAYMENT__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
275 if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
276 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
277 $substitutionarray[
'__SECUREKEYPAYMENT_DONATION__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
278 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
279 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
280 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
282 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'member'.$obj->source_id, 2);
283 $substitutionarray[
'__SECUREKEYPAYMENT_DONATION__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'donation'.$obj->source_id, 2);
284 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'order'.$obj->source_id, 2);
285 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'invoice'.$obj->source_id, 2);
286 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'contractline'.$obj->source_id, 2);
289 if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
290 $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>';
293 if (
isModEnabled(
'paypal') && !empty($conf->global->PAYPAL_SECURITY_TOKEN)) {
294 $substitutionarray[
'__SECUREKEYPAYPAL__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
296 if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
297 $substitutionarray[
'__SECUREKEYPAYPAL_MEMBER__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
299 $substitutionarray[
'__SECUREKEYPAYPAL_MEMBER__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.
'membersubscription'.$obj->source_id, 2);
302 if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
303 $substitutionarray[
'__SECUREKEYPAYPAL_ORDER__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
305 $substitutionarray[
'__SECUREKEYPAYPAL_ORDER__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.
'order'.$obj->source_id, 2);
308 if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
309 $substitutionarray[
'__SECUREKEYPAYPAL_INVOICE__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
311 $substitutionarray[
'__SECUREKEYPAYPAL_INVOICE__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.
'invoice'.$obj->source_id, 2);
314 if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
315 $substitutionarray[
'__SECUREKEYPAYPAL_CONTRACTLINE__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
317 $substitutionarray[
'__SECUREKEYPAYPAL_CONTRACTLINE__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.
'contractline'.$obj->source_id, 2);
327 if (preg_match(
'/__UNSUBSCRIBE__/', $message)) {
328 $moreinheader =
"List-Unsubscribe: <__UNSUBSCRIBE_URL__>\n";
337 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
338 if (count($listofpaths)) {
339 foreach ($listofpaths as $key => $val) {
340 $arr_file[] = $listofpaths[$key][
'fullname'];
342 $arr_name[] = $listofpaths[$key][
'name'];
347 $trackid =
'emailing-'.$obj->fk_mailing.
'-'.$obj->rowid;
348 $upload_dir_tmp = $upload_dir;
349 $mail =
new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name,
'',
'', 0, $msgishtml, $errorsto, $arr_css, $trackid, $moreinheader,
'emailing',
'', $upload_dir_tmp);
362 $res = $mail->sendfile();
369 dol_syslog(
"comm/mailing/card.php: ok for #".$iforemailloop.($mail->error ?
' - '.$mail->error :
''), LOG_DEBUG);
371 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
372 $sql .=
" SET statut=1, date_envoi = '".$db->idate($now).
"' WHERE rowid=".((int) $obj->rowid);
373 $resql2 = $db->query($sql);
378 if (strpos($message,
'__CHECK_READ__') !==
false) {
380 $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).
")";
381 dol_syslog(
"card.php: set prospect thirdparty status", LOG_DEBUG);
382 $resql2 = $db->query($sql);
388 $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)";
389 dol_syslog(
"card.php: set prospect contact status", LOG_DEBUG);
391 $resql2 = $db->query($sql);
398 if (!empty($conf->global->MAILING_DELAY)) {
399 dol_syslog(
"Wait a delay of MAILING_DELAY=".((
float) $conf->global->MAILING_DELAY));
400 usleep((
float) $conf->global->MAILING_DELAY * 1000000);
408 dol_syslog(
"comm/mailing/card.php: error for #".$iforemailloop.($mail->error ?
' - '.$mail->error :
''), LOG_WARNING);
410 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
411 $sql .=
" SET statut=-1, error_text='".$db->escape($mail->error).
"', date_envoi='".$db->idate($now).
"' WHERE rowid=".((int) $obj->rowid);
412 $resql2 = $db->query($sql);
421 setEventMessages($langs->transnoentitiesnoconv(
"NoMoreRecipientToSendTo"),
null,
'mesgs');
428 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
430 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
435 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
438 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
442 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing SET statut=".((int) $statut).
" WHERE rowid = ".((int) $object->id);
443 dol_syslog(
"comm/mailing/card.php: update global status", LOG_DEBUG);
444 $resql2 = $db->query($sql);
458 if ($action ==
'send' && ! $cancel) {
461 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
463 $object->sendto =
GETPOST(
"sendto",
'alphawithlgt');
464 if (!$object->sendto) {
465 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailTo")),
null,
'errors');
472 if (preg_match(
'/[\s\t]*<html>/i', $object->body)) {
477 $object->substitutionarrayfortest[
'__EMAIL__'] = $object->sendto;
478 $object->substitutionarrayfortest[
'__MAILTOEMAIL__'] =
'<a href="mailto:'.$object->sendto.
'">'.$object->sendto.
'</a>';
479 $object->substitutionarrayfortest[
'__CHECK_READ__'] =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php?tag=undefinedintestmode&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).
'&email='.urlencode($obj->sendto).
'&mtid=0" width="1" height="1" style="width:1px;height:1px" border="0"/>';
480 $object->substitutionarrayfortest[
'__UNSUBSCRIBE__'] =
'<a href="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-unsubscribe.php?tag=undefinedintestmode&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).
'&email='.urlencode($obj->sendto).
'&mtid=0" target="_blank" rel="noopener noreferrer">'.$langs->trans(
"MailUnsubcribe").
'</a>';
481 $object->substitutionarrayfortest[
'__UNSUBSCRIBE_URL__'] = DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-unsubscribe.php?tag=undefinedintestmode&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).
'&email='.urlencode($obj->sendto).
'&mtid=0';
494 if (!empty($object->bgcolor)) {
495 $arr_css[
'bgcolor'] = (preg_match(
'/^#/', $object->bgcolor) ?
'' :
'#').$object->bgcolor;
497 if (!empty($object->bgimage)) {
498 $arr_css[
'bgimage'] = $object->bgimage;
502 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
503 if (count($listofpaths)) {
504 foreach ($listofpaths as $key => $val) {
505 $arr_file[] = $listofpaths[$key][
'fullname'];
507 $arr_name[] = $listofpaths[$key][
'name'];
511 $trackid =
'emailing-test';
512 $upload_dir_tmp = $upload_dir;
513 $mailfile =
new CMailFile($tmpsujet, $object->sendto, $object->email_from, $tmpbody, $arr_file, $arr_mime, $arr_name,
'',
'', 0, $msgishtml, $object->email_errorsto, $arr_css, $trackid,
'',
'emailing',
'', $upload_dir_tmp);
515 $result = $mailfile->sendfile();
517 setEventMessages($langs->trans(
"MailSuccessfulySent", $mailfile->getValidAddress($object->email_from, 2), $mailfile->getValidAddress($object->sendto, 2)),
null,
'mesgs');
520 setEventMessages($langs->trans(
"ResultKo").
'<br>'.$mailfile->error.
' '.$result,
null,
'errors');
527 if ($action ==
'add') {
530 $object->email_from = (string)
GETPOST(
"from",
'alphawithlgt');
531 $object->email_replyto = (string)
GETPOST(
"replyto",
'alphawithlgt');
532 $object->email_errorsto = (string)
GETPOST(
"errorsto",
'alphawithlgt');
533 $object->title = (string)
GETPOST(
"title");
534 $object->sujet = (string)
GETPOST(
"sujet");
535 $object->body = (string)
GETPOST(
"bodyemail",
'restricthtml');
536 $object->bgcolor = (string)
GETPOST(
"bgcolor");
537 $object->bgimage = (string)
GETPOST(
"bgimage");
539 if (!$object->title) {
540 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTitle"));
542 if (!$object->sujet) {
543 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTopic"));
545 if (!$object->body) {
546 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailMessage"));
549 if (!count($mesgs)) {
550 if ($object->create($user) >= 0) {
551 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
554 $mesgs[] = $object->error;
555 $mesgs = array_merge($mesgs, $object->errors);
563 if ($action ==
'settitle' || $action ==
'setemail_from' || $action ==
'setreplyto' || $action ==
'setemail_errorsto') {
564 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
566 if ($action ==
'settitle') {
567 $object->title = trim(
GETPOST(
'title',
'alpha'));
568 } elseif ($action ==
'setemail_from') {
569 $object->email_from = trim(
GETPOST(
'email_from',
'alphawithlgt'));
570 } elseif ($action ==
'setemail_replyto') {
571 $object->email_replyto = trim(
GETPOST(
'email_replyto',
'alphawithlgt'));
572 } elseif ($action ==
'setemail_errorsto') {
573 $object->email_errorsto = trim(
GETPOST(
'email_errorsto',
'alphawithlgt'));
574 } elseif ($action ==
'settitle' && empty($object->title)) {
575 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTitle"));
576 } elseif ($action ==
'setfrom' && empty($object->email_from)) {
577 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailFrom"));
581 if ($object->update($user) >= 0) {
582 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
585 $mesg = $object->error;
596 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
598 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
608 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
610 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
618 if ($action ==
'update' && !
GETPOST(
"removedfile") && !$cancel) {
619 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
625 $object->sujet = (string)
GETPOST(
"sujet");
626 $object->body = (string)
GETPOST(
"bodyemail",
'restricthtml');
627 $object->bgcolor = (string)
GETPOST(
"bgcolor");
628 $object->bgimage = (string)
GETPOST(
"bgimage");
630 if (!$object->sujet) {
631 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTopic"));
633 if (!$object->body) {
634 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailMessage"));
637 if (!count($mesgs)) {
638 if ($object->update($user) >= 0) {
639 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
642 $mesgs[] = $object->error;
643 $mesgs = array_merge($mesgs, $object->errors);
654 if ($action ==
'confirm_valid' && $confirm ==
'yes') {
655 if ($object->id > 0) {
656 $object->valid($user);
657 setEventMessages($langs->trans(
"MailingSuccessfullyValidated"),
null,
'mesgs');
658 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
666 if ($action ==
'confirm_settodraft' && $confirm ==
'yes') {
667 if ($object->id > 0) {
668 $result = $object->setStatut(0);
671 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
682 if ($action ==
'confirm_reset' && $confirm ==
'yes') {
683 if ($object->id > 0) {
686 $result = $object->valid($user);
688 $result = $object->reset_targets_status($user);
693 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
705 if ($action ==
'confirm_delete' && $confirm ==
'yes') {
706 if ($object->delete($object->id)) {
707 $url = (!empty($urlfrom) ? $urlfrom :
'list.php');
708 header(
"Location: ".$url);
726 $help_url =
'EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing';
729 $langs->trans(
"Mailing"),
735 '/includes/ace/src/ace.js',
736 '/includes/ace/src/ext-statusbar.js',
737 '/includes/ace/src/ext-language_tools.js',
743 if ($action ==
'create') {
745 print
'<form name="new_mailing" action="'.$_SERVER[
'PHP_SELF'].
'" method="POST">'.
"\n";
746 print
'<input type="hidden" name="token" value="'.newToken().
'">';
747 print
'<input type="hidden" name="action" value="add">';
749 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
750 foreach ($object->substitutionarray as $key => $val) {
751 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
756 $availablelink =
$form->textwithpicto($langs->trans(
"AvailableVariables"), $htmltext, 1,
'help',
'', 0, 2,
'availvar');
761 print
load_fiche_titre($langs->trans(
"NewMailing"), $availablelink,
'object_email');
765 print
'<table class="border centpercent">';
767 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
"MailTitle").
'</td><td><input class="flat minwidth300" name="title" value="'.
dol_escape_htmltag(
GETPOST(
'title')).
'" autofocus="autofocus"></td></tr>';
769 print
'<tr><td class="fieldrequired">'.$langs->trans(
"MailFrom").
'</td><td><input class="flat minwidth200" name="from" value="'.
getDolGlobalString(
'MAILING_EMAIL_FROM').
'"></td></tr>';
771 print
'<tr><td>'.$langs->trans(
"MailErrorsTo").
'</td><td><input class="flat minwidth200" name="errorsto" value="'.
getDolGlobalString(
'MAILING_EMAIL_ERRORSTO',
getDolGlobalString(
'MAIN_MAIL_ERRORS_TO')).
'"></td></tr>';
775 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
776 print $hookmanager->resPrint;
777 if (empty($reshook)) {
778 print $object->showOptionals($extrafields,
'create');
784 print
'<table class="border centpercent">';
785 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
"MailTopic").
'</td><td><input class="flat minwidth200 quatrevingtpercent" name="sujet" value="'.
dol_escape_htmltag(
GETPOST(
'sujet',
'alphanohtml')).
'"></td></tr>';
786 print
'<tr><td>'.$langs->trans(
"BackgroundColorByDefault").
'</td><td colspan="3">';
787 print $htmlother->selectColor(
GETPOST(
'bgcolor'),
'bgcolor',
'', 0);
792 print
'<div style="padding-top: 10px">';
794 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
795 $doleditor =
new DolEditor(
'bodyemail',
GETPOST(
'bodyemail',
'restricthtmlallowunvalid'),
'', 600,
'dolibarr_mailings',
'',
true,
true,
getDolGlobalInt(
'FCKEDITOR_ENABLE_MAILING'), 20,
'90%');
796 $doleditor->Create();
801 print
$form->buttonsSaveCancel(
"CreateMailing",
'Cancel');
805 if ($object->id > 0) {
806 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
810 if ($action ==
'settodraft') {
812 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"SetToDraft"), $langs->trans(
"ConfirmUnvalidateEmailing"),
"confirm_settodraft",
'',
'', 1);
813 } elseif ($action ==
'valid') {
815 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"ValidMailing"), $langs->trans(
"ConfirmValidMailing"),
"confirm_valid",
'',
'', 1);
816 } elseif ($action ==
'reset') {
818 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"ResetMailing"), $langs->trans(
"ConfirmResetMailing", $object->ref),
"confirm_reset",
'',
'', 2);
819 } elseif ($action ==
'delete') {
821 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.(!empty($urlfrom) ?
'&urlfrom='.urlencode($urlfrom) :
''), $langs->trans(
"DeleteAMailing"), $langs->trans(
"ConfirmDeleteMailing"),
"confirm_delete",
'',
'', 1);
824 if ($action !=
'edit' && $action !=
'edithtml') {
830 if ($action ==
'sendall') {
832 $sendingmode = $conf->global->EMAILING_MAIL_SENDMODE;
833 if (empty($sendingmode)) {
834 $sendingmode = $conf->global->MAIN_MAIL_SENDMODE;
836 if (empty($sendingmode)) {
837 $sendingmode =
'mail';
844 if (!empty($conf->global->MAILING_NO_USING_PHPMAIL) && $sendingmode ==
'mail') {
847 $linktoadminemailbefore =
'<a href="'.DOL_URL_ROOT.
'/admin/mails_emailing.php">';
848 $linktoadminemailend =
'</a>';
849 setEventMessages($langs->trans(
"MailSendSetupIs", $listofmethods[$sendingmode]),
null,
'warnings');
850 $messagetoshow = $langs->trans(
"MailSendSetupIs2",
'{s1}',
'{s2}',
'{s3}',
'{s4}');
851 $messagetoshow = str_replace(
'{s1}', $linktoadminemailbefore, $messagetoshow);
852 $messagetoshow = str_replace(
'{s2}', $linktoadminemailend, $messagetoshow);
853 $messagetoshow = str_replace(
'{s3}', $langs->transnoentitiesnoconv(
"MAIN_MAIL_SENDMODE"), $messagetoshow);
854 $messagetoshow = str_replace(
'{s4}', $listofmethods[
'smtps'], $messagetoshow);
857 if (!empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) {
858 setEventMessages($langs->trans(
"MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS),
null,
'warnings');
860 $_GET[
"action"] =
'';
861 } elseif ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
862 if (!empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode ==
'mail') {
863 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL),
null,
'warnings');
865 if (!empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode !=
'mail') {
866 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL),
null,
'warnings');
871 setEventMessages(
'<textarea cols="60" rows="'.ROWS_1.
'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.
'</textarea>',
null,
'warnings');
872 if ($conf->file->mailing_limit_sendbyweb !=
'-1') {
875 $_GET[
"action"] =
'';
877 if (!empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode ==
'mail') {
878 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL),
null,
'warnings');
880 if (!empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode !=
'mail') {
881 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL),
null,
'warnings');
886 if (isset($conf->global->MAILING_LIMIT_SENDBYDAY) && $conf->global->MAILING_LIMIT_SENDBYDAY >= 0) {
887 $text .= $langs->trans(
'WarningLimitSendByDay', $conf->global->MAILING_LIMIT_SENDBYDAY);
890 $text .= $langs->trans(
'ConfirmSendingEmailing').
'<br>';
891 $text .= $langs->trans(
'LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
893 if (!isset($conf->global->MAILING_LIMIT_SENDBYCLI) || $conf->global->MAILING_LIMIT_SENDBYCLI >= 0) {
895 $text .= $langs->trans(
"MailingNeedCommand");
896 $text .=
'<br><textarea class="quatrevingtpercent" rows="'.ROWS_2.
'" wrap="soft" disabled>php ./scripts/emailings/mailing-send.php '.$object->id.
' '.$user->login.
'</textarea>';
899 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
'SendMailing'), $text,
'sendallconfirmed',
'',
'', 1, 380, 660, 0, $langs->trans(
"Confirm"), $langs->trans(
"Cancel"));
903 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
907 if ($object->statut == 2 || $object->statut == 3) {
908 $nbtry = $object->countNbOfTargets(
'alreadysent');
909 $nbko = $object->countNbOfTargets(
'alreadysentko');
911 $morehtmlright .=
' ('.$nbtry.
'/'.$object->nbemail;
913 $morehtmlright .=
' - '.$nbko.
' '.$langs->trans(
"Error");
915 $morehtmlright .=
') ';
918 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref',
'',
'', 0,
'', $morehtmlright);
920 print
'<div class="fichecenter">';
921 print
'<div class="underbanner clearboth"></div>';
923 print
'<table class="border centpercent tableforfield">';
926 print
'<tr><td class="titlefield">';
927 print
$form->editfieldkey(
"MailTitle",
'title', $object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string');
929 print
$form->editfieldval(
"MailTitle",
'title', $object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string');
934 print
$form->editfieldkey(
"MailFrom",
'email_from', $object->email_from, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
936 print
$form->editfieldval(
"MailFrom",
'email_from', $object->email_from, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
939 $langs->load(
"errors");
940 print
img_warning($langs->trans(
"ErrorBadEMail", $email));
942 $langs->load(
"errors");
943 print
img_warning($langs->trans(
"ErrorBadMXDomain", $email));
950 print
$form->editfieldkey(
"MailErrorsTo",
'email_errorsto', $object->email_errorsto, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
952 print
$form->editfieldval(
"MailErrorsTo",
'email_errorsto', $object->email_errorsto, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
955 $langs->load(
"errors");
956 print
img_warning($langs->trans(
"ErrorBadEMail", $email));
958 $langs->load(
"errors");
959 print
img_warning($langs->trans(
"ErrorBadMXDomain", $email));
965 print $langs->trans(
"TotalNbOfDistinctRecipients");
966 print
'</td><td colspan="3">';
967 $nbemail = ($object->nbemail ? $object->nbemail : 0);
968 if (is_numeric($nbemail)) {
970 if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail))) {
971 if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) {
972 $text .= $langs->trans(
'LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
974 $text .= $langs->trans(
'SendingFromWebInterfaceIsNotAllowed');
977 if (empty($nbemail)) {
978 $nbemail .=
' '.img_warning(
'').
' <span class="warning">'.$langs->trans(
"NoTargetYet").
'</span>';
981 print
$form->textwithpicto($nbemail, $text, 1,
'warning');
989 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
999 if ($action ==
'clone') {
1001 $formquestion = array(
1002 'text' => $langs->trans(
"ConfirmClone"),
1003 array(
'type' =>
'checkbox',
'name' =>
'clone_content',
'label' => $langs->trans(
"CloneContent"),
'value' => 1),
1004 array(
'type' =>
'checkbox',
'name' =>
'clone_receivers',
'label' => $langs->trans(
"CloneReceivers"),
'value' => 0)
1007 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneEMailing', $object->ref),
'confirm_clone', $formquestion,
'yes', 2, 240);
1014 if (
GETPOST(
'cancel',
'alpha') || $confirm ==
'no' || $action ==
'' || in_array($action, array(
'settodraft',
'valid',
'delete',
'sendall',
'clone',
'test'))) {
1015 print
"\n\n<div class=\"tabsAction\">\n";
1017 if (($object->statut == 1) && ($user->hasRight(
'mailing',
'valider') || $object->user_validation == $user->id)) {
1018 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=settodraft&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"SetToDraft").
'</a>';
1021 if (($object->statut == 0 || $object->statut == 1 || $object->statut == 2) && $user->hasRight(
'mailing',
'creer')) {
1022 if (
isModEnabled(
'fckeditor') && !empty($conf->global->FCKEDITOR_ENABLE_MAILING)) {
1023 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"EditWithEditor").
'</a>';
1025 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"EditWithTextEditor").
'</a>';
1028 if (!empty($conf->use_javascript_ajax)) {
1029 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edithtml&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"EditHTMLSource").
'</a>';
1035 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
1036 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"TestMailing").
'</a>';
1038 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=test&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"TestMailing").
'</a>';
1041 if ($object->statut == 0) {
1042 if ($object->nbemail <= 0) {
1043 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NoTargetYet")).
'">'.$langs->trans(
"ValidMailing").
'</a>';
1044 } elseif (empty($user->rights->mailing->valider)) {
1045 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"ValidMailing").
'</a>';
1047 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=valid&id='.$object->id.
'">'.$langs->trans(
"ValidMailing").
'</a>';
1051 if (($object->statut == 1 || $object->statut == 2) && $object->nbemail > 0 && $user->hasRight(
'mailing',
'valider')) {
1052 if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
1053 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"SendingFromWebInterfaceIsNotAllowed")).
'">'.$langs->trans(
"SendMailing").
'</a>';
1054 } elseif (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
1055 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"SendMailing").
'</a>';
1057 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=sendall&id='.$object->id.
'">'.$langs->trans(
"SendMailing").
'</a>';
1061 if ($user->hasRight(
'mailing',
'creer')) {
1062 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=clone&object=emailing&id='.$object->id.
'">'.$langs->trans(
"ToClone").
'</a>';
1065 if (($object->statut == 2 || $object->statut == 3) && $user->hasRight(
'mailing',
'valider')) {
1066 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
1067 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"ResetMailing").
'</a>';
1069 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=reset&id='.$object->id.
'">'.$langs->trans(
"ResetMailing").
'</a>';
1073 if (($object->statut <= 1 && $user->hasRight(
'mailing',
'creer')) || $user->hasRight(
'mailing',
'supprimer')) {
1074 if ($object->statut > 0 && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->delete)) {
1075 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"DeleteMailing").
'</a>';
1077 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&id='.$object->id.(!empty($urlfrom) ?
'&urlfrom='.$urlfrom :
'').
'">'.$langs->trans(
"DeleteMailing").
'</a>';
1085 if ($action ==
'test') {
1086 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
1092 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1094 $formmail->fromname = $object->email_from;
1095 $formmail->frommail = $object->email_from;
1096 $formmail->withsubstit = 1;
1097 $formmail->withfrom = 0;
1098 $formmail->withto = $user->email ? $user->email : 1;
1099 $formmail->withtocc = 0;
1100 $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
1101 $formmail->withtopic = 0;
1102 $formmail->withtopicreadonly = 1;
1103 $formmail->withfile = 0;
1104 $formmail->withbody = 0;
1105 $formmail->withbodyreadonly = 1;
1106 $formmail->withcancel = 1;
1107 $formmail->withdeliveryreceipt = 0;
1109 $formmail->substit = $object->substitutionarrayfortest;
1111 $formmail->param[
"action"] =
"send";
1112 $formmail->param[
"models"] =
'none';
1113 $formmail->param[
"mailid"] = $object->id;
1114 $formmail->param[
"returnurl"] = $_SERVER[
'PHP_SELF'].
"?id=".$object->id;
1116 print $formmail->get_form();
1126 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br><br><span class="small">';
1127 foreach ($object->substitutionarray as $key => $val) {
1128 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1130 $htmltext .=
'</span></i>';
1133 print
load_fiche_titre($langs->trans(
"EMail"),
$form->textwithpicto(
'<span class="opacitymedium hideonsmartphone">'.$langs->trans(
"AvailableVariables").
'</span>', $htmltext, 1,
'helpclickable',
'', 0, 3,
'emailsubstitionhelp'),
'generic');
1137 print
'<table class="bordernooddeven tableforfield centpercent">';
1140 print
'<tr><td class="titlefield">'.$langs->trans(
"MailTopic").
'</td><td colspan="3">'.$object->sujet.
'</td></tr>';
1143 print
'<tr><td>'.$langs->trans(
"MailFile").
'</td><td colspan="3">';
1145 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
1146 if (count($listofpaths)) {
1147 foreach ($listofpaths as $key => $val) {
1148 print
img_mime($listofpaths[$key][
'name']).
' '.$listofpaths[$key][
'name'];
1152 print
'<span class="opacitymedium">'.$langs->trans(
"NoAttachedFiles").
'</span><br>';
1164 print
'<div style="padding-top: 10px; background: '.($object->bgcolor ? (preg_match(
'/^#/', $object->bgcolor) ?
'' :
'#').$object->bgcolor :
'white').
'">';
1165 if (empty($object->bgcolor) || strtolower($object->bgcolor) ==
'ffffff') {
1168 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1169 $doleditor =
new DolEditor(
'bodyemail', $object->body,
'', 600,
'dolibarr_mailings',
'',
false,
true, empty($conf->global->FCKEDITOR_ENABLE_MAILING) ? 0 : 1, 20,
'90%', $readonly);
1170 $doleditor->Create();
1184 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
1186 $morehtmlright =
'';
1187 if ($object->statut == 2) {
1188 $morehtmlright .=
' ('.$object->countNbOfTargets(
'alreadysent').
'/'.$object->nbemail.
') ';
1191 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref',
'',
'', 0,
'', $morehtmlright);
1193 print
'<div class="fichecenter">';
1194 print
'<div class="underbanner clearboth"></div>';
1196 print
'<table class="border centpercent">';
1206 print
'<tr><td class="titlefield">'.$langs->trans(
"MailTitle").
'</td><td colspan="3">'.$object->title.
'</td></tr>';
1208 print
'<tr><td class="titlefield">'.$langs->trans(
"MailFrom").
'</td><td colspan="3">'.
dol_print_email($object->email_from, 0, 0, 0, 0, 1).
'</td></tr>';
1210 print
'<tr><td>'.$langs->trans(
"MailErrorsTo").
'</td><td colspan="3">'.
dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1).
'</td></tr>';
1214 print $langs->trans(
"TotalNbOfDistinctRecipients");
1215 print
'</td><td colspan="3">';
1216 $nbemail = ($object->nbemail ? $object->nbemail : 0);
1217 if (is_numeric($nbemail)) {
1219 if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || $object->statut == 2)) {
1220 if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) {
1221 $text .= $langs->trans(
'LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
1223 $text .= $langs->trans(
'SendingFromWebInterfaceIsNotAllowed');
1226 if (empty($nbemail)) {
1227 $nbemail .=
' '.img_warning(
'').
' <span class="warning">'.$langs->trans(
"NoTargetYet").
'</span>';
1230 print
$form->textwithpicto($nbemail, $text, 1,
'warning');
1239 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
1240 print $hookmanager->resPrint;
1241 if (empty($reshook)) {
1242 print $object->showOptionals($extrafields,
'edit',
$parameters);
1254 print
'<form name="edit_mailing" action="card.php" method="post" enctype="multipart/form-data">'.
"\n";
1255 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1256 print
'<input type="hidden" name="action" value="update">';
1257 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1259 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
1260 foreach ($object->substitutionarray as $key => $val) {
1261 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1263 $htmltext .=
'</i>';
1266 print
load_fiche_titre($langs->trans(
"EMail"),
$form->textwithpicto($langs->trans(
"AvailableVariables"), $htmltext, 1,
'help',
'', 0, 2,
'emailsubstitionhelp'),
'generic');
1270 print
'<table class="bordernooddeven" width="100%">';
1273 print
'<tr><td class="fieldrequired titlefield">'.$langs->trans(
"MailTopic").
'</td><td colspan="3"><input class="flat quatrevingtpercent" type="text" name="sujet" value="'.$object->sujet.
'"></td></tr>';
1279 $addfileaction =
'addfile';
1280 print
'<tr><td>'.$langs->trans(
"MailFile").
'</td>';
1281 print
'<td colspan="3">';
1283 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
1286 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
1287 $out .=
'<script type="text/javascript">';
1288 $out .=
'jQuery(document).ready(function () {';
1289 $out .=
' jQuery(".removedfile").click(function() {';
1290 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
1293 $out .=
'</script>'.
"\n";
1294 if (count($listofpaths)) {
1295 foreach ($listofpaths as $key => $val) {
1296 $out .=
'<div id="attachfile_'.$key.
'">';
1297 $out .=
img_mime($listofpaths[$key][
'name']).
' '.$listofpaths[$key][
'name'];
1298 $out .=
' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans(
"Search"),
'delete.png',
'',
'', 1).
'" value="'.($key + 1).
'" class="removedfile" id="removedfile_'.$key.
'" name="removedfile_'.$key.
'" />';
1299 $out .=
'<br></div>';
1307 $maxmin = $maxfilesizearray[
'maxmin'];
1309 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
1311 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
1313 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
1318 print
'<tr><td>'.$langs->trans(
"BackgroundColorByDefault").
'</td><td colspan="3">';
1319 print $htmlother->selectColor($object->bgcolor,
'bgcolor',
'', 0);
1325 print
'<div style="padding-top: 10px">';
1327 if ($action ==
'edit') {
1329 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1330 $doleditor =
new DolEditor(
'bodyemail', $object->body,
'', 600,
'dolibarr_mailings',
'',
true,
true,
getDolGlobalInt(
'FCKEDITOR_ENABLE_MAILING'), 20,
'90%');
1331 $doleditor->Create();
1333 if ($action ==
'edithtml') {
1335 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1336 $doleditor =
new DolEditor(
'bodyemail', $object->body,
'', 600,
'dolibarr_mailings',
'',
true,
true,
'ace', 20,
'90%');
1337 $doleditor->Create(0,
'',
false,
'HTML Source',
'php');
1345 print
'<div class="center">';
1346 print
'<input type="submit" class="button buttonforacesave button-save" value="'.$langs->trans(
"Save").
'" name="save">';
1347 print
' ';
1348 print
'<input type="submit" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'" name="cancel">';