29if (!defined(
'NOSTYLECHECK')) {
30 define(
'NOSTYLECHECK',
'1');
34require
'../../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/emailing.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/mailing.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
53$langs->loadLangs(array(
"mails",
"admin"));
57$action =
GETPOST(
'action',
'aZ09');
58$confirm =
GETPOST(
'confirm',
'alpha');
59$cancel =
GETPOST(
'cancel',
'aZ09');
61$backtopageforcancel =
GETPOST(
'backtopageforcancel');
66$hookmanager->initHooks(array(
'mailingcard',
'globalcard'));
69$extrafields->fetch_name_optionals_label(
$object->table_element);
72include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
79$signature = ((!empty($user->signature) && !
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? $user->signature :
'');
83$parameters = array(
'mode' =>
'emailing');
86$object->substitutionarrayfortest = $substitutionarray;
89$listofmethods = array();
91$listofmethods[
'mail'] =
'PHP mail function';
93$listofmethods[
'smtps'] =
'SMTP/SMTPS socket library';
94if (version_compare(phpversion(),
'7.0',
'>=')) {
95 $listofmethods[
'swiftmailer'] =
'Swift Mailer socket library';
99if (!$user->hasRight(
'mailing',
'lire') || (!
getDolGlobalString(
'EXTERNAL_USERS_ARE_AUTHORIZED') && $user->socid > 0)) {
102if (empty($action) && empty(
$object->id)) {
109$permissiontocreate = $user->hasRight(
'mailing',
'creer');
110$permissiontovalidatesend = $user->hasRight(
'mailing',
'valider');
111$permissiontodelete = $user->hasRight(
'mailing',
'supprimer');
118$parameters = array();
119$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
124if (empty($reshook)) {
127 $backurlforlist = DOL_URL_ROOT.
'/comm/mailing/list.php';
129 if (empty($backtopage) || ($cancel && empty($id))) {
130 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
131 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
132 $backtopage = $backurlforlist;
134 $backtopage = DOL_URL_ROOT.
'/comm/mailing/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
141 if (!empty($backtopageforcancel)) {
142 header(
"Location: ".$backtopageforcancel);
144 } elseif (!empty($backtopage)) {
145 header(
"Location: ".$backtopage);
152 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontocreate) {
153 if (!
GETPOST(
"clone_content",
'alpha') && !
GETPOST(
"clone_receivers",
'alpha')) {
158 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
168 if ($action ==
'sendallconfirmed' && $confirm ==
'yes' && $permissiontovalidatesend) {
172 setEventMessages(
'<textarea cols="70" rows="'.ROWS_2.
'" wrap="soft">php ./scripts/emailings/mailing-send.php '.
$object->id.
'</textarea>',
null,
'warnings');
188 $replyto =
$object->email_replyto;
189 $errorsto =
$object->email_errorsto;
192 if (preg_match(
'/[\s\t]*<html>/i', $message)) {
204 $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";
205 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc";
206 $sql .=
" WHERE mc.statut < 1 AND mc.fk_mailing = ".((int)
$object->id);
207 $sql .=
" ORDER BY mc.statut DESC";
209 dol_syslog(
"card.php: select targets", LOG_DEBUG);
210 $resql = $db->query($sql);
212 $num = $db->num_rows($resql);
215 dol_syslog(
"comm/mailing/card.php: nb of targets = ".$num, LOG_DEBUG);
220 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing SET date_envoi='".$db->idate($now).
"' WHERE rowid=".((int)
$object->id);
221 $resql2 = $db->query($sql);
226 $thirdpartystatic =
new Societe($db);
230 while ($iforemailloop < $num && $iforemailloop < $conf->global->MAILING_LIMIT_SENDBYWEB) {
235 $obj = $db->fetch_object($resql);
238 $sendto = str_replace(
',',
' ',
dolGetFirstLastname($obj->firstname, $obj->lastname)).
" <".$obj->email.
">";
241 $other = explode(
';', $obj->other);
242 $tmpfield = explode(
'=', $other[0], 2);
243 $other1 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
244 $tmpfield = explode(
'=', $other[1], 2);
245 $other2 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
246 $tmpfield = explode(
'=', $other[2], 2);
247 $other3 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
248 $tmpfield = explode(
'=', $other[3], 2);
249 $other4 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
250 $tmpfield = explode(
'=', $other[4], 2);
251 $other5 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
253 $signature = ((!empty($user->signature) && !
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? $user->signature :
'');
255 $parameters = array(
'mode' =>
'emailing');
259 $substitutionarray[
'__ID__'] = $obj->source_id;
260 if ($obj->source_type ==
"thirdparty") {
261 $result = $thirdpartystatic->fetch($obj->source_id);
264 $substitutionarray[
'__THIRDPARTY_CUSTOMER_CODE__'] = $thirdpartystatic->code_client;
266 $substitutionarray[
'__THIRDPARTY_CUSTOMER_CODE__'] =
'';
269 $substitutionarray[
'__EMAIL__'] = $obj->email;
270 $substitutionarray[
'__LASTNAME__'] = $obj->lastname;
271 $substitutionarray[
'__FIRSTNAME__'] = $obj->firstname;
272 $substitutionarray[
'__MAILTOEMAIL__'] =
'<a href="mailto:'.$obj->email.
'">'.$obj->email.
'</a>';
273 $substitutionarray[
'__OTHER1__'] = $other1;
274 $substitutionarray[
'__OTHER2__'] = $other2;
275 $substitutionarray[
'__OTHER3__'] = $other3;
276 $substitutionarray[
'__OTHER4__'] = $other4;
277 $substitutionarray[
'__OTHER5__'] = $other5;
278 $substitutionarray[
'__USER_SIGNATURE__'] = $signature;
279 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $signature;
280 $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"/>';
281 $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>';
282 $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);
284 $onlinepaymentenabled = 0;
285 if (isModEnabled(
'paypal')) {
286 $onlinepaymentenabled++;
288 if (isModEnabled(
'paybox')) {
289 $onlinepaymentenabled++;
291 if (isModEnabled(
'stripe')) {
292 $onlinepaymentenabled++;
295 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
296 $substitutionarray[
'__ONLINEPAYMENTLINK_MEMBER__'] = getHtmlOnlinePaymentLink(
'member', $obj->source_id);
297 $substitutionarray[
'__ONLINEPAYMENTLINK_DONATION__'] = getHtmlOnlinePaymentLink(
'donation', $obj->source_id);
298 $substitutionarray[
'__ONLINEPAYMENTLINK_ORDER__'] = getHtmlOnlinePaymentLink(
'order', $obj->source_id);
299 $substitutionarray[
'__ONLINEPAYMENTLINK_INVOICE__'] = getHtmlOnlinePaymentLink(
'invoice', $obj->source_id);
300 $substitutionarray[
'__ONLINEPAYMENTLINK_CONTRACTLINE__'] = getHtmlOnlinePaymentLink(
'contractline', $obj->source_id);
310 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'member'.$obj->source_id,
'2');
311 $substitutionarray[
'__SECUREKEYPAYMENT_DONATION__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'donation'.$obj->source_id,
'2');
312 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'order'.$obj->source_id,
'2');
313 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'invoice'.$obj->source_id,
'2');
314 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'contractline'.$obj->source_id,
'2');
318 $substitutionarray[
'__PUBLICLINK_NEWMEMBERFORM__'] =
'<a target="_blank" rel="noopener noreferrer" href="'.DOL_MAIN_URL_ROOT.
'/public/members/new.php'.((isModEnabled(
'multicompany')) ?
'?entity='.
$conf->entity :
'').
'">'.$langs->trans(
'BlankSubscriptionForm').
'</a>';
327 $substitutionarray[
'__SECUREKEYPAYPAL_MEMBER__'] =
dol_hash(
getDolGlobalString(
'PAYPAL_SECURITY_TOKEN') .
'membersubscription'.$obj->source_id,
'2');
333 $substitutionarray[
'__SECUREKEYPAYPAL_ORDER__'] =
dol_hash(
getDolGlobalString(
'PAYPAL_SECURITY_TOKEN') .
'order'.$obj->source_id,
'2');
339 $substitutionarray[
'__SECUREKEYPAYPAL_INVOICE__'] =
dol_hash(
getDolGlobalString(
'PAYPAL_SECURITY_TOKEN') .
'invoice'.$obj->source_id,
'2');
345 $substitutionarray[
'__SECUREKEYPAYPAL_CONTRACTLINE__'] =
dol_hash(
getDolGlobalString(
'PAYPAL_SECURITY_TOKEN') .
'contractline'.$obj->source_id,
'2');
355 if (preg_match(
'/__UNSUBSCRIBE_(_|URL_)/', $message)) {
356 $moreinheader =
"List-Unsubscribe: <__UNSUBSCRIBE_URL__>\n";
365 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
366 if (count($listofpaths)) {
367 foreach ($listofpaths as $key => $val) {
368 $arr_file[] = $listofpaths[$key][
'fullname'];
370 $arr_name[] = $listofpaths[$key][
'name'];
375 $trackid =
'emailing-'.$obj->fk_mailing.
'-'.$obj->rowid;
376 $upload_dir_tmp = $upload_dir;
377 $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);
390 $res = $mail->sendfile();
397 dol_syslog(
"comm/mailing/card.php: ok for #".$iforemailloop.($mail->error ?
' - '.$mail->error :
''), LOG_DEBUG);
399 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
400 $sql .=
" SET statut=1, date_envoi = '".$db->idate($now).
"' WHERE rowid=".((int) $obj->rowid);
401 $resql2 = $db->query($sql);
406 if (strpos($message,
'__CHECK_READ__') !==
false) {
408 $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).
")";
409 dol_syslog(
"card.php: set prospect thirdparty status", LOG_DEBUG);
410 $resql2 = $db->query($sql);
416 $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)";
417 dol_syslog(
"card.php: set prospect contact status", LOG_DEBUG);
419 $resql2 = $db->query($sql);
427 dol_syslog(
"Wait a delay of MAILING_DELAY=".((
float)
$conf->global->MAILING_DELAY));
428 usleep((
int) ((
float)
$conf->global->MAILING_DELAY * 1000000));
436 dol_syslog(
"comm/mailing/card.php: error for #".$iforemailloop.($mail->error ?
' - '.$mail->error :
''), LOG_WARNING);
438 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
439 $sql .=
" SET statut=-1, error_text='".$db->escape(
dol_trunc($mail->error, 250)).
"', date_envoi='".$db->idate($now).
"' WHERE rowid=".((int) $obj->rowid);
440 $resql2 = $db->query($sql);
449 setEventMessages($langs->transnoentitiesnoconv(
"NoMoreRecipientToSendTo"),
null,
'mesgs');
455 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
462 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
465 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing SET statut=".((int) $statut).
" WHERE rowid = ".((int)
$object->id);
466 dol_syslog(
"comm/mailing/card.php: update global status", LOG_DEBUG);
467 $resql2 = $db->query($sql);
481 if ($action ==
'send' && ! $cancel && $permissiontovalidatesend) {
488 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailTo")),
null,
'errors');
495 if (preg_match(
'/[\s\t]*<html>/i',
$object->body)) {
499 $signature = ((!empty($user->signature) && !
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? $user->signature :
'');
501 $parameters = array(
'mode' =>
'emailing');
505 $substitutionarray[
'__EMAIL__'] =
$object->sendto;
506 $substitutionarray[
'__MAILTOEMAIL__'] =
'<a href="mailto:'.$object->sendto.
'">'.
$object->sendto.
'</a>';
507 $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"/>';
508 $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>';
509 $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';
523 if (!empty(
$object->bgcolor)) {
524 $arr_css[
'bgcolor'] = (preg_match(
'/^#/',
$object->bgcolor) ?
'' :
'#').
$object->bgcolor;
526 if (!empty(
$object->bgimage)) {
527 $arr_css[
'bgimage'] =
$object->bgimage;
531 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
532 if (count($listofpaths)) {
533 foreach ($listofpaths as $key => $val) {
534 $arr_file[] = $listofpaths[$key][
'fullname'];
536 $arr_name[] = $listofpaths[$key][
'name'];
540 $trackid =
'emailing-test';
541 $upload_dir_tmp = $upload_dir;
542 $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);
544 $result = $mailfile->sendfile();
546 setEventMessages($langs->trans(
"MailSuccessfulySent", $mailfile->getValidAddress(
$object->email_from, 2), $mailfile->getValidAddress(
$object->sendto, 2)),
null,
'mesgs');
549 setEventMessages($langs->trans(
"ResultKo").
'<br>'.$mailfile->error.
' '.json_encode($result),
null,
'errors');
557 if ($action ==
'add' && $permissiontocreate) {
559 if (
$object->messtype ==
'sms') {
560 $object->email_from = (string)
GETPOST(
"from_phone",
'alphawithlgt');
564 $object->email_replyto = (string)
GETPOST(
"replyto",
'alphawithlgt');
565 $object->email_errorsto = (string)
GETPOST(
"errorsto",
'alphawithlgt');
569 $object->bgcolor = preg_replace(
'/^#/',
'', (
string)
GETPOST(
"bgcolor"));
573 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTitle"));
576 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTopic"));
579 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailMessage"));
582 if (!count($mesgs)) {
583 if (
$object->create($user) >= 0) {
584 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
588 $mesgs = array_merge($mesgs,
$object->errors);
596 if (($action ==
'settitle' || $action ==
'setemail_from' || $action ==
'setemail_replyto' || $action ==
'setreplyto' || $action ==
'setemail_errorsto' || $action ==
'setevenunsubscribe') && $permissiontovalidatesend) {
599 if ($action ==
'settitle') {
601 } elseif ($action ==
'setemail_from') {
602 $object->email_from = trim(
GETPOST(
'email_from',
'alphawithlgt'));
603 } elseif ($action ==
'setemail_replyto') {
604 $object->email_replyto = trim(
GETPOST(
'email_replyto',
'alphawithlgt'));
605 } elseif ($action ==
'setemail_errorsto') {
606 $object->email_errorsto = trim(
GETPOST(
'email_errorsto',
'alphawithlgt'));
607 } elseif ($action ==
'settitle' && empty(
$object->title)) {
608 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTitle"));
609 } elseif ($action ==
'setfrom' && empty(
$object->email_from)) {
610 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailFrom"));
611 } elseif ($action ==
'setevenunsubscribe') {
616 $result =
$object->update($user);
618 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
631 if (
GETPOST(
'addfile') && $permissiontocreate) {
634 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
643 if (
GETPOST(
"removedfile") && $permissiontocreate) {
646 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
654 if ($action ==
'update' && !
GETPOST(
"removedfile") && !$cancel && $permissiontocreate) {
655 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
665 $object->bgcolor = preg_replace(
'/^#/',
'', (
string)
GETPOST(
"bgcolor"));
669 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTopic"));
672 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailMessage"));
675 if (!count($mesgs)) {
676 if (
$object->update($user) >= 0) {
677 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
681 $mesgs = array_merge($mesgs,
$object->errors);
692 if ($action ==
'confirm_valid' && $confirm ==
'yes' && $permissiontovalidatesend) {
695 setEventMessages($langs->trans(
"MailingSuccessfullyValidated"),
null,
'mesgs');
696 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
704 if ($action ==
'confirm_settodraft' && $confirm ==
'yes' && $permissiontocreate) {
706 $result =
$object->setStatut(0);
709 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
720 if ($action ==
'confirm_reset' && $confirm ==
'yes' && $permissiontocreate) {
724 $result =
$object->valid($user);
726 $result =
$object->reset_targets_status($user);
731 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
743 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $permissiontodelete) {
745 $url = (!empty($urlfrom) ? $urlfrom :
'list.php');
746 header(
"Location: ".$url);
761$form =
new Form($db);
764$help_url =
'EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing';
767 $langs->trans(
"Mailing"),
773 '/includes/ace/src/ace.js',
774 '/includes/ace/src/ext-statusbar.js',
775 '/includes/ace/src/ext-language_tools.js',
782if ($action ==
'create') {
784 print
'<form name="new_mailing" action="'.$_SERVER[
'PHP_SELF'].
'" method="POST">'.
"\n";
785 print
'<input type="hidden" name="token" value="'.newToken().
'">';
786 print
'<input type="hidden" name="action" value="add">';
788 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br><br><span class="small">';
789 foreach (
$object->substitutionarray as $key => $val) {
790 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
792 $htmltext .=
'</span></i>';
795 $availablelink = $form->textwithpicto(
'<span class="opacitymedium">'.$langs->trans(
"AvailableVariables").
'</span>', $htmltext, 1,
'helpclickable',
'', 0, 2,
'availvar');
800 print
load_fiche_titre($langs->trans(
"NewMailing"), $availablelink,
'object_email');
804 print
'<table class="border centpercent">';
806 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>';
809 $arrayoftypes = array(
"email" =>
"Email",
"sms" =>
"SMS");
810 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
"Type").
'</td><td>';
811 print $form->selectarray(
'messtype', $arrayoftypes, (GETPOSTISSET(
'messtype') ?
GETPOST(
'messtype') :
'email'), 0, 0);
814 $( document ).ready(function() {
815 jQuery("#messtype").on("change", function() {
816 console.log("We change the message ttpe");
817 if (jQuery("#messtype").val() == "email") {
818 jQuery(".fieldsforsms").hide();
819 jQuery(".fieldsforemail").show();
821 if (jQuery("#messtype").val() == "sms") {
822 jQuery(".fieldsforsms").show();
823 jQuery(".fieldsforemail").hide();
826 jQuery("#messtype").change();
836 print
'<table class="border centpercent">';
838 print
'<tr class="fieldsforemail"><td class="fieldrequired titlefieldcreate">'.$langs->trans(
"MailFrom").
'</td><td><input class="flat minwidth200" name="from" value="'.(GETPOSTISSET(
'from') ?
GETPOST(
'from') :
getDolGlobalString(
'MAILING_EMAIL_FROM')).
'"></td></tr>';
840 print
'<tr class="fieldsforsms hidden"><td class="fieldrequired titlefieldcreate">'.$langs->trans(
"PhoneFrom").
'</td><td><input class="flat minwidth200" name="fromphone" value="'.(GETPOSTISSET(
'fromphone') ?
GETPOST(
'fromphone') :
getDolGlobalString(
'MAILING_SMS_FROM')).
'" placeholder="+123..."></td></tr>';
842 print
'<tr class="fieldsforemail"><td>'.$langs->trans(
"MailErrorsTo").
'</td><td><input class="flat minwidth200" name="errorsto" value="'.
getDolGlobalString(
'MAILING_EMAIL_ERRORSTO',
getDolGlobalString(
'MAIN_MAIL_ERRORS_TO')).
'"></td></tr>';
844 print
'<tr class="fieldsforemail"><td>'.$langs->trans(
"MailReply").
'</td><td><input class="flat minwidth200" name="replyto" value="'.
getDolGlobalString(
'MAILING_EMAIL_REPLYTO',
getDolGlobalString(
'MAIN_MAIL_REPLY_TO')).
'"></td></tr>';
847 $parameters = array();
848 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
849 print $hookmanager->resPrint;
850 if (empty($reshook)) {
851 print
$object->showOptionals($extrafields,
'create');
857 print
'<table class="border centpercent">';
858 print
'<tr class="fieldsforemail"><td class="fieldrequired titlefieldcreate">'.$langs->trans(
"MailTopic").
'</td><td><input id="sujet" class="flat minwidth200 quatrevingtpercent" name="sujet" value="'.
dol_escape_htmltag(
GETPOST(
'sujet',
'alphanohtml')).
'"></td></tr>';
859 print
'<tr class="fieldsforemail"><td>'.$langs->trans(
"BackgroundColorByDefault").
'</td><td colspan="3">';
860 print $htmlother->selectColor(
GETPOST(
'bgcolor'),
'bgcolor',
'', 0);
864 $formmail->withfckeditor = 1;
865 $formmail->withlayout =
'emailing';
866 $formmail->withaiprompt =
'html';
868 print
'<tr class="fieldsforemail"><td></td><td class="tdtop"></td></tr>';
870 print
'<tr class="fieldsforemail"><td></td><td class="tdtop">';
873 $showlinktolayout = ($formmail->withfckeditor ? $formmail->withlayout :
'');
874 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
875 $showlinktoai = ($formmail->withaiprompt && isModEnabled(
'ai')) ?
'textgenerationemail' :
'';
876 $showlinktoailabel = $langs->trans(
"FillMessageWithAIContent");
877 $formatforouput =
'html';
878 $htmlname =
'bodyemail';
881 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
889 print
'<div style="padding-top: 10px">';
891 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
892 $doleditor =
new DolEditor(
'bodyemail',
GETPOST(
'bodyemail',
'restricthtmlallowunvalid'),
'', 600,
'dolibarr_mailings',
'',
true,
true,
getDolGlobalInt(
'FCKEDITOR_ENABLE_MAILING'), 20,
'90%');
893 $doleditor->Create();
898 print $form->buttonsSaveCancel(
"Create",
'Cancel');
907 if ($action ==
'settodraft') {
909 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".
$object->id, $langs->trans(
"SetToDraft"), $langs->trans(
"ConfirmUnvalidateEmailing"),
"confirm_settodraft",
'',
'', 1);
910 } elseif ($action ==
'valid') {
912 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".
$object->id, $langs->trans(
"ValidMailing"), $langs->trans(
"ConfirmValidMailing"),
"confirm_valid",
'',
'', 1);
913 } elseif ($action ==
'reset') {
915 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".
$object->id, $langs->trans(
"ResetMailing"), $langs->trans(
"ConfirmResetMailing",
$object->ref),
"confirm_reset",
'',
'', 2);
916 } elseif ($action ==
'delete') {
918 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".
$object->id.(!empty($urlfrom) ?
'&urlfrom='.urlencode($urlfrom) :
''), $langs->trans(
"DeleteMailing"), $langs->trans(
"ConfirmDeleteMailing"),
"confirm_delete",
'',
'', 1);
921 if ($action !=
'edit' && $action !=
'edittxt' && $action !=
'edithtml') {
925 if ($action ==
'sendall') {
928 if (empty($sendingmode)) {
931 if (empty($sendingmode)) {
932 $sendingmode =
'mail';
942 $linktoadminemailbefore =
'<a href="'.DOL_URL_ROOT.
'/admin/mails_emailing.php">';
943 $linktoadminemailend =
'</a>';
944 setEventMessages($langs->trans(
"MailSendSetupIs", $listofmethods[$sendingmode]),
null,
'warnings');
945 $messagetoshow = $langs->trans(
"MailSendSetupIs2",
'{s1}',
'{s2}',
'{s3}',
'{s4}');
946 $messagetoshow = str_replace(
'{s1}', $linktoadminemailbefore, $messagetoshow);
947 $messagetoshow = str_replace(
'{s2}', $linktoadminemailend, $messagetoshow);
948 $messagetoshow = str_replace(
'{s3}', $langs->transnoentitiesnoconv(
"MAIN_MAIL_SENDMODE"), $messagetoshow);
949 $messagetoshow = str_replace(
'{s4}', $listofmethods[
'smtps'], $messagetoshow);
958 setEventMessages($langs->transnoentitiesnoconv(
$conf->global->MAILING_LIMIT_WARNING_PHPMAIL),
null,
'warnings');
960 if (
getDolGlobalString(
'MAILING_LIMIT_WARNING_NOPHPMAIL') && $sendingmode !=
'mail') {
961 setEventMessages($langs->transnoentitiesnoconv(
$conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL),
null,
'warnings');
966 setEventMessages(
'<textarea cols="60" rows="'.ROWS_1.
'" wrap="soft">php ./scripts/emailings/mailing-send.php '.
$object->id.
'</textarea>',
null,
'warnings');
967 if (
$conf->file->mailing_limit_sendbyweb !=
'-1') {
973 setEventMessages($langs->transnoentitiesnoconv(
$conf->global->MAILING_LIMIT_WARNING_PHPMAIL),
null,
'warnings');
975 if (
getDolGlobalString(
'MAILING_LIMIT_WARNING_NOPHPMAIL') && $sendingmode !=
'mail') {
976 setEventMessages($langs->transnoentitiesnoconv(
$conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL),
null,
'warnings');
982 $text .= $langs->trans(
'WarningLimitSendByDay',
getDolGlobalInt(
'MAILING_LIMIT_SENDBYDAY'));
985 $text .= $langs->trans(
'ConfirmSendingEmailing').
'<br>';
986 $text .= $langs->trans(
'LimitSendingEmailing',
getDolGlobalString(
'MAILING_LIMIT_SENDBYWEB'));
988 if (!isset(
$conf->global->MAILING_LIMIT_SENDBYCLI) ||
getDolGlobalInt(
'MAILING_LIMIT_SENDBYCLI') >= 0) {
990 $text .=
'<u>'.$langs->trans(
"AdvancedAlternative").
':</u> '.$langs->trans(
"MailingNeedCommand");
991 $text .=
'<br><textarea class="quatrevingtpercent" rows="'.ROWS_2.
'" wrap="soft" disabled>php ./scripts/emailings/mailing-send.php '.
$object->id.
' '.$user->login.
'</textarea>';
994 print $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, $langs->trans(
'SendMailing'), $text,
'sendallconfirmed',
'',
'', 1, 380, 660, 0, $langs->trans(
"Confirm"), $langs->trans(
"Cancel"));
998 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
1000 $morehtmlref =
'<div class="refidno">';
1002 $morehtmlref .= $form->editfieldkey(
"",
'title',
$object->title,
$object, $user->hasRight(
'mailing',
'creer'),
'string',
'', 0, 1);
1003 $morehtmlref .= $form->editfieldval(
"",
'title',
$object->title,
$object, $user->hasRight(
'mailing',
'creer'),
'string',
'',
null,
null,
'', 1);
1004 $morehtmlref .=
'</div>';
1006 $morehtmlstatus =
'';
1009 $nbtry =
$object->countNbOfTargets(
'alreadysent');
1010 $nbko =
$object->countNbOfTargets(
'alreadysentko');
1012 $morehtmlstatus .=
' ('.$nbtry.
'/'.
$object->nbemail;
1014 $morehtmlstatus .=
' - '.$nbko.
' '.$langs->trans(
"Error");
1016 $morehtmlstatus .=
') ';
1019 dol_banner_tab(
$object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlstatus);
1021 print
'<div class="fichecenter">';
1022 print
'<div class="fichehalfleft">';
1023 print
'<div class="underbanner clearboth"></div>';
1024 print
'<table class="border centpercent tableforfield">'.
"\n";
1027 print
'<tr><td class="titlefield">';
1028 print $form->editfieldkey(
"MailFrom",
'email_from',
$object->email_from,
$object, $user->hasRight(
'mailing',
'creer') &&
$object->status < $object::STATUS_SENTCOMPLETELY,
'string');
1030 print $form->editfieldval(
"MailFrom",
'email_from',
$object->email_from,
$object, $user->hasRight(
'mailing',
'creer') &&
$object->status < $object::STATUS_SENTCOMPLETELY,
'string');
1033 $langs->load(
"errors");
1034 print
img_warning($langs->trans(
"ErrorBadEMail", $email));
1036 $langs->load(
"errors");
1037 print
img_warning($langs->trans(
"ErrorBadMXDomain", $email));
1043 if (
$object->messtype !=
'sms') {
1045 print $form->editfieldkey(
"MailErrorsTo",
'email_errorsto',
$object->email_errorsto,
$object, $user->hasRight(
'mailing',
'creer') &&
$object->status < $object::STATUS_SENTCOMPLETELY,
'string');
1047 print $form->editfieldval(
"MailErrorsTo",
'email_errorsto',
$object->email_errorsto,
$object, $user->hasRight(
'mailing',
'creer') &&
$object->status < $object::STATUS_SENTCOMPLETELY,
'string');
1049 foreach ($emailarray as $email => $name) {
1050 if ($name != $email) {
1054 $langs->load(
"errors");
1055 print
img_warning($langs->trans(
"ErrorBadEMail", $email));
1057 $langs->load(
"errors");
1058 print
img_warning($langs->trans(
"ErrorBadMXDomain", $email));
1068 if (
$object->messtype !=
'sms') {
1070 print $form->editfieldkey(
"MailReply",
'email_replyto',
$object->email_replyto,
$object, $user->hasRight(
'mailing',
'creer') &&
$object->status < $object::STATUS_SENTCOMPLETELY,
'string');
1072 print $form->editfieldval(
"MailReply",
'email_replyto',
$object->email_replyto,
$object, $user->hasRight(
'mailing',
'creer') &&
$object->status < $object::STATUS_SENTCOMPLETELY,
'string');
1074 if ($action !=
'editemail_replyto') {
1076 $langs->load(
"errors");
1077 print
img_warning($langs->trans(
"ErrorBadEMail", $email));
1079 $langs->load(
"errors");
1080 print
img_warning($langs->trans(
"ErrorBadMXDomain", $email));
1089 print
'<div class="fichehalfright">';
1090 print
'<div class="underbanner clearboth"></div>';
1092 print
'<table class="border centpercent tableforfield">';
1096 print $langs->trans(
"TotalNbOfDistinctRecipients");
1099 if (is_numeric($nbemail)) {
1103 $text .= $langs->trans(
'LimitSendingEmailing',
getDolGlobalString(
'MAILING_LIMIT_SENDBYWEB'));
1105 $text .= $langs->trans(
'SendingFromWebInterfaceIsNotAllowed');
1108 if (empty($nbemail)) {
1109 $nbemail .=
' '.img_warning(
'').
' <span class="warning">'.$langs->trans(
"NoTargetYet").
'</span>';
1112 print $form->textwithpicto($nbemail, $text, 1,
'warning');
1120 print $langs->trans(
"MAIN_MAIL_SENDMODE");
1122 if (
$object->messtype !=
'sms') {
1128 $text = $listofmethods[
'mail'];
1133 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER_EMAILING',
getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER')).
')</span>';
1136 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER').
')</span>';
1140 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER').
')</span>';
1145 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1151 print
'<div class="clearboth"></div>';
1157 if ($action ==
'clone') {
1159 $formquestion = array(
1160 'text' => $langs->trans(
"ConfirmClone"),
1161 0 => array(
'type' =>
'checkbox',
'name' =>
'clone_content',
'label' => $langs->trans(
"CloneContent"),
'value' => 1),
1162 1 => array(
'type' =>
'checkbox',
'name' =>
'clone_receivers',
'label' => $langs->trans(
"CloneReceivers"),
'value' => 0)
1165 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneEMailing',
$object->ref),
'confirm_clone', $formquestion,
'yes', 2, 240);
1169 if (
GETPOST(
'cancel',
'alpha') || $confirm ==
'no' || $action ==
'' || in_array($action, array(
'settodraft',
'valid',
'delete',
'sendall',
'clone',
'test',
'editevenunsubscribe'))) {
1170 print
"\n\n<div class=\"tabsAction\">\n";
1172 if ((
$object->status == 1) && ($user->hasRight(
'mailing',
'valider') ||
$object->user_validation_id == $user->id)) {
1173 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=settodraft&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"SetToDraft").
'</a>';
1176 if ((
$object->status == 0 ||
$object->status == 1 ||
$object->status == 2) && $user->hasRight(
'mailing',
'creer')) {
1178 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"Edit").
'</a>';
1180 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edittxt&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"EditWithTextEditor").
'</a>';
1184 if (!empty(
$conf->use_javascript_ajax)) {
1185 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edithtml&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"EditHTMLSource").
'</a>';
1192 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'mailing',
'mailing_advance',
'send')) {
1193 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"TestMailing").
'</a>';
1195 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=test&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"TestMailing").
'</a>';
1200 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NoTargetYet")).
'">'.$langs->trans(
"Validate").
'</a>';
1201 } elseif (!$user->hasRight(
'mailing',
'valider')) {
1202 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"Validate").
'</a>';
1204 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=valid&id='.
$object->id.
'">'.$langs->trans(
"Validate").
'</a>';
1208 if ((
$object->status == 1 ||
$object->status == 2) &&
$object->nbemail > 0 && $user->hasRight(
'mailing',
'valider')) {
1210 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"SendingFromWebInterfaceIsNotAllowed")).
'">'.$langs->trans(
"SendMailing").
'</a>';
1211 } elseif (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'mailing',
'mailing_advance',
'send')) {
1212 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"SendMailing").
'</a>';
1214 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=sendall&id='.
$object->id.
'">'.$langs->trans(
"SendMailing").
'</a>';
1218 if ($user->hasRight(
'mailing',
'creer')) {
1219 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=clone&object=emailing&id='.
$object->id.
'">'.$langs->trans(
"ToClone").
'</a>';
1222 if ((
$object->status == 2 ||
$object->status == 3) && $user->hasRight(
'mailing',
'valider')) {
1223 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'mailing',
'mailing_advance',
'send')) {
1224 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"ResetMailing").
'</a>';
1226 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=reset&id='.
$object->id.
'">'.$langs->trans(
"ResetMailing").
'</a>';
1230 if ((
$object->status <= 1 && $user->hasRight(
'mailing',
'creer')) || $user->hasRight(
'mailing',
'supprimer')) {
1231 if (
$object->status > 0 && (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'mailing',
'mailing_advance',
'delete'))) {
1232 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"Delete").
'</a>';
1234 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&id='.
$object->id.(!empty($urlfrom) ?
'&urlfrom='.$urlfrom :
'').
'">'.$langs->trans(
"Delete").
'</a>';
1242 if ($action ==
'test') {
1243 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
1249 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1251 $formmail->fromname =
$object->email_from;
1252 $formmail->frommail =
$object->email_from;
1253 $formmail->withsubstit = 0;
1254 $formmail->withfrom = 0;
1255 $formmail->withto = $user->email ? $user->email : 1;
1256 $formmail->withtocc = 0;
1258 $formmail->withtopic = 0;
1259 $formmail->withtopicreadonly = 1;
1260 $formmail->withfile = 0;
1261 $formmail->withlayout =
'';
1262 $formmail->withaiprompt =
'';
1263 $formmail->withbody = 0;
1264 $formmail->withbodyreadonly = 1;
1265 $formmail->withcancel = 1;
1266 $formmail->withdeliveryreceipt = 0;
1268 $formmail->substit =
$object->substitutionarrayfortest;
1270 $formmail->param[
"action"] =
"send";
1271 $formmail->param[
"models"] =
'none';
1272 $formmail->param[
"mailid"] =
$object->id;
1273 $formmail->param[
"returnurl"] = $_SERVER[
'PHP_SELF'].
"?id=".
$object->id;
1275 print $formmail->get_form();
1285 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br><br><span class="small">';
1286 foreach (
$object->substitutionarray as $key => $val) {
1287 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1289 $htmltext .=
'</span></i>';
1292 print
load_fiche_titre($langs->trans(
"EMail"), $form->textwithpicto(
'<span class="opacitymedium hideonsmartphone">'.$langs->trans(
"AvailableVariables").
'</span>', $htmltext, 1,
'helpclickable',
'', 0, 3,
'emailsubstitionhelp'),
'generic');
1296 print
'<table class="bordernooddeven tableforfield centpercent">';
1299 if (
$object->messtype !=
'sms') {
1300 print
'<tr><td class="titlefield">'.$langs->trans(
"MailTopic").
'</td><td colspan="3">'.
$object->sujet.
'</td></tr>';
1304 if (
$object->messtype !=
'sms') {
1305 print
'<tr><td>'.$langs->trans(
"MailFile").
'</td><td colspan="3">';
1307 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
1308 if (count($listofpaths)) {
1309 foreach ($listofpaths as $key => $val) {
1310 print
img_mime($listofpaths[$key][
'name']).
' '.$listofpaths[$key][
'name'];
1314 print
'<span class="opacitymedium">'.$langs->trans(
"NoAttachedFiles").
'</span><br>';
1327 print
'<div style="padding-top: 10px; background: '.($object->bgcolor ? (preg_match(
'/^#/',
$object->bgcolor) ?
'' :
'#').
$object->bgcolor :
'white').
'">';
1328 if (empty(
$object->bgcolor) || strtolower(
$object->bgcolor) ==
'ffffff') {
1331 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1332 $doleditor =
new DolEditor(
'bodyemail',
$object->body,
'', 600,
'dolibarr_mailings',
'',
false,
true, !
getDolGlobalString(
'FCKEDITOR_ENABLE_MAILING') ? 0 : 1, 20,
'90%', $readonly);
1333 $doleditor->Create();
1347 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
1349 $morehtmlref =
'<div class="refidno">';
1351 $morehtmlref .= $form->editfieldkey(
"",
'title',
$object->title,
$object, $user->hasRight(
'mailing',
'creer'),
'string',
'', 0, 1);
1352 $morehtmlref .= $form->editfieldval(
"",
'title',
$object->title,
$object, $user->hasRight(
'mailing',
'creer'),
'string',
'',
null,
null,
'', 1);
1353 $morehtmlref .=
'</div>';
1355 $morehtmlstatus =
'';
1358 $nbtry =
$object->countNbOfTargets(
'alreadysent');
1359 $nbko =
$object->countNbOfTargets(
'alreadysentko');
1361 $morehtmlstatus .=
' ('.$nbtry.
'/'.
$object->nbemail;
1363 $morehtmlstatus .=
' - '.$nbko.
' '.$langs->trans(
"Error");
1365 $morehtmlstatus .=
') ';
1368 dol_banner_tab(
$object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlstatus);
1370 print
'<div class="fichecenter">';
1371 print
'<div class="fichehalfleft">';
1372 print
'<div class="underbanner clearboth"></div>';
1374 print
'<table class="border centpercent tableforfield">';
1384 print
'<tr><td class="titlefield">';
1385 print $langs->trans(
"MailFrom");
1386 print
'</td><td>'.dol_print_email(
$object->email_from, 0, 0, 0, 0, 1).
'</td></tr>';
1388 if (
$object->messtype !=
'sms') {
1389 print
'<tr><td>'.$langs->trans(
"MailErrorsTo").
'</td><td>'.
dol_print_email(
$object->email_errorsto, 0, 0, 0, 0, 1).
'</td></tr>';
1390 print
'<tr><td>'.$langs->trans(
"MailReply").
'</td><td>'.
dol_print_email(
$object->email_replyto, 0, 0, 0, 0, 1).
'</td></tr>';
1397 print
'<div class="fichehalfright">';
1398 print
'<div class="underbanner clearboth"></div>';
1400 print
'<table class="border centpercent tableforfield">';
1404 print $langs->trans(
"TotalNbOfDistinctRecipients");
1407 if (is_numeric($nbemail)) {
1411 $text .= $langs->trans(
'LimitSendingEmailing',
getDolGlobalString(
'MAILING_LIMIT_SENDBYWEB'));
1413 $text .= $langs->trans(
'SendingFromWebInterfaceIsNotAllowed');
1416 if (empty($nbemail)) {
1417 $nbemail .=
' '.img_warning(
'').
' <span class="warning">'.$langs->trans(
"NoTargetYet").
'</span>';
1420 print $form->textwithpicto($nbemail, $text, 1,
'warning');
1428 print $langs->trans(
"MAIN_MAIL_SENDMODE");
1435 $text = $listofmethods[
'mail'];
1440 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER_EMAILING').
')</span>';
1443 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER').
')</span>';
1449 $parameters = array();
1450 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
1451 print $hookmanager->resPrint;
1452 if (empty($reshook)) {
1453 print
$object->showOptionals($extrafields,
'edit', $parameters);
1460 print
'<div class="clearboth"></div>';
1467 print
'<form name="edit_mailing" action="card.php" method="post" enctype="multipart/form-data">'.
"\n";
1468 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1469 print
'<input type="hidden" name="action" value="update">';
1470 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1472 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br><br><span class="small">';
1473 foreach (
$object->substitutionarray as $key => $val) {
1474 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1476 $htmltext .=
'</span></i>';
1479 print
load_fiche_titre($langs->trans(
"EMail"),
'<span class="opacitymedium">'.$form->textwithpicto($langs->trans(
"AvailableVariables").
'</span>', $htmltext, 1,
'help',
'', 0, 2,
'emailsubstitionhelp'),
'generic');
1483 print
'<table class="bordernooddeven centpercent">';
1486 if (
$object->messtype !=
'sms') {
1487 print
'<tr><td class="fieldrequired titlefield">';
1488 print $langs->trans(
"MailTopic");
1489 print
'</td><td colspan="3"><input class="flat quatrevingtpercent" type="text" name="sujet" value="'.$object->sujet.
'"></td></tr>';
1496 if (
$object->messtype !=
'sms') {
1497 $addfileaction =
'addfile';
1498 print
'<tr><td>'.$langs->trans(
"MailFile").
'</td>';
1499 print
'<td colspan="3">';
1501 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
1505 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
1506 $out .=
'<script type="text/javascript">';
1507 $out .=
'jQuery(document).ready(function () {';
1508 $out .=
' jQuery(".removedfile").click(function() {';
1509 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
1512 $out .=
'</script>'.
"\n";
1513 if (count($listofpaths)) {
1514 foreach ($listofpaths as $key => $val) {
1515 $out .=
'<div id="attachfile_'.$key.
'">';
1516 $out .=
img_mime($listofpaths[$key][
'name']).
' '.$listofpaths[$key][
'name'];
1517 $out .=
' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans(
"Search"),
'delete.png',
'', 0, 1).
'" value="'.($key + 1).
'" class="removedfile" id="removedfile_'.$key.
'" name="removedfile_'.$key.
'" />';
1518 $out .=
'<br></div>';
1526 $maxmin = $maxfilesizearray[
'maxmin'];
1528 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
1530 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
1532 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
1537 print
'<tr><td>'.$langs->trans(
"BackgroundColorByDefault").
'</td><td colspan="3">';
1538 print $htmlother->selectColor(
$object->bgcolor,
'bgcolor',
'', 0);
1546 print
'<div style="padding-top: 10px">';
1548 if ($action ==
'edit') {
1550 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1551 $doleditor =
new DolEditor(
'bodyemail',
$object->body,
'', 600,
'dolibarr_mailings',
'',
true,
true,
getDolGlobalInt(
'FCKEDITOR_ENABLE_MAILING'), 20,
'90%');
1552 $doleditor->Create();
1554 if ($action ==
'edittxt') {
1556 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1557 $doleditor =
new DolEditor(
'bodyemail',
$object->body,
'', 600,
'dolibarr_mailings',
'',
true,
true, 0, 20,
'90%');
1558 $doleditor->Create();
1560 if ($action ==
'edithtml') {
1562 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1563 $doleditor =
new DolEditor(
'bodyemail',
$object->body,
'', 600,
'dolibarr_mailings',
'',
true,
true,
'ace', 20,
'90%');
1564 $doleditor->Create(0,
'',
false,
'HTML Source',
'php');
1572 print
'<div class="center">';
1573 print
'<input type="submit" class="button buttonforacesave button-save" value="'.$langs->trans(
"Save").
'" name="save">';
1574 print
' ';
1575 print
'<input type="submit" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'" name="cancel">';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
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 emailings module.
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, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null, $forceFullTestIndexation='')
Get and save an upload file (for example after submitting a new file 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.
isValidMailDomain($mail)
Return true if email has a domain name that can be resolved to MX type.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
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.
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
getMaxFileSizeArray()
Return the max allowed for file upload.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.