27if (!defined(
'NOSTYLECHECK')) {
28 define(
'NOSTYLECHECK',
'1');
32require
'../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/emailing.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/mailing.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
43$langs->loadLangs(array(
"mails",
"admin"));
47$action =
GETPOST(
'action',
'aZ09');
48$confirm =
GETPOST(
'confirm',
'alpha');
49$cancel =
GETPOST(
'cancel',
'aZ09');
51$backtopageforcancel =
GETPOST(
'backtopageforcancel');
56$hookmanager->initHooks(array(
'mailingcard',
'globalcard'));
59$extrafields->fetch_name_optionals_label($object->table_element);
62include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
69$signature = ((!empty($user->signature) && !
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? $user->signature :
'');
73$parameters = array(
'mode'=>
'emailing');
76$object->substitutionarrayfortest = $substitutionarray;
79$listofmethods = array();
81$listofmethods[
'mail'] =
'PHP mail function';
83$listofmethods[
'smtps'] =
'SMTP/SMTPS socket library';
84if (version_compare(phpversion(),
'7.0',
'>=')) {
85 $listofmethods[
'swiftmailer'] =
'Swift Mailer socket library';
89if (!$user->hasRight(
'mailing',
'lire') || (!
getDolGlobalString(
'EXTERNAL_USERS_ARE_AUTHORIZED') && $user->socid > 0)) {
92if (empty($action) && empty($object->id)) {
96$upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
103$parameters = array();
104$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
109if (empty($reshook)) {
112 $backurlforlist = DOL_URL_ROOT.
'/comm/mailing/list.php';
114 if (empty($backtopage) || ($cancel && empty($id))) {
115 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
116 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
117 $backtopage = $backurlforlist;
119 $backtopage = DOL_URL_ROOT.
'/comm/mailing/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
126 if (!empty($backtopageforcancel)) {
127 header(
"Location: ".$backtopageforcancel);
129 } elseif (!empty($backtopage)) {
130 header(
"Location: ".$backtopage);
137 if ($action ==
'confirm_clone' && $confirm ==
'yes') {
138 if (!
GETPOST(
"clone_content",
'alpha') && !
GETPOST(
"clone_receivers",
'alpha')) {
141 $result = $object->createFromClone($user, $object->id,
GETPOST(
"clone_content",
'alpha'),
GETPOST(
"clone_receivers",
'alpha'));
143 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
153 if ($action ==
'sendallconfirmed' && $confirm ==
'yes') {
157 setEventMessages(
'<textarea cols="70" rows="'.ROWS_2.
'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.
'</textarea>',
null,
'warnings');
164 if ($object->statut == 0) {
170 $subject = $object->sujet;
171 $message = $object->body;
172 $from = $object->email_from;
173 $replyto = $object->email_replyto;
174 $errorsto = $object->email_errorsto;
177 if (preg_match(
'/[\s\t]*<html>/i', $message)) {
189 $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";
190 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc";
191 $sql .=
" WHERE mc.statut < 1 AND mc.fk_mailing = ".((int) $object->id);
192 $sql .=
" ORDER BY mc.statut DESC";
194 dol_syslog(
"card.php: select targets", LOG_DEBUG);
195 $resql = $db->query($sql);
197 $num = $db->num_rows($resql);
200 dol_syslog(
"comm/mailing/card.php: nb of targets = ".$num, LOG_DEBUG);
205 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing SET date_envoi='".$db->idate($now).
"' WHERE rowid=".((int) $object->id);
206 $resql2 = $db->query($sql);
211 $thirdpartystatic =
new Societe($db);
215 while ($iforemailloop < $num && $iforemailloop < $conf->global->MAILING_LIMIT_SENDBYWEB) {
220 $obj = $db->fetch_object($resql);
223 $sendto = str_replace(
',',
' ',
dolGetFirstLastname($obj->firstname, $obj->lastname)).
" <".$obj->email.
">";
226 $other = explode(
';', $obj->other);
227 $tmpfield = explode(
'=', $other[0], 2);
228 $other1 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
229 $tmpfield = explode(
'=', $other[1], 2);
230 $other2 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
231 $tmpfield = explode(
'=', $other[2], 2);
232 $other3 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
233 $tmpfield = explode(
'=', $other[3], 2);
234 $other4 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
235 $tmpfield = explode(
'=', $other[4], 2);
236 $other5 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
238 $signature = ((!empty($user->signature) && !
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? $user->signature :
'');
240 $parameters = array(
'mode'=>
'emailing');
244 $substitutionarray[
'__ID__'] = $obj->source_id;
245 if ($obj->source_type ==
"thirdparty") {
246 $result = $thirdpartystatic->fetch($obj->source_id);
249 $substitutionarray[
'__THIRDPARTY_CUSTOMER_CODE__'] = $thirdpartystatic->code_client;
251 $substitutionarray[
'__THIRDPARTY_CUSTOMER_CODE__'] =
'';
254 $substitutionarray[
'__EMAIL__'] = $obj->email;
255 $substitutionarray[
'__LASTNAME__'] = $obj->lastname;
256 $substitutionarray[
'__FIRSTNAME__'] = $obj->firstname;
257 $substitutionarray[
'__MAILTOEMAIL__'] =
'<a href="mailto:'.$obj->email.
'">'.$obj->email.
'</a>';
258 $substitutionarray[
'__OTHER1__'] = $other1;
259 $substitutionarray[
'__OTHER2__'] = $other2;
260 $substitutionarray[
'__OTHER3__'] = $other3;
261 $substitutionarray[
'__OTHER4__'] = $other4;
262 $substitutionarray[
'__OTHER5__'] = $other5;
263 $substitutionarray[
'__USER_SIGNATURE__'] = $signature;
264 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $signature;
265 $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"/>';
266 $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>';
267 $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);
269 $onlinepaymentenabled = 0;
270 if (isModEnabled(
'paypal')) {
271 $onlinepaymentenabled++;
273 if (isModEnabled(
'paybox')) {
274 $onlinepaymentenabled++;
276 if (isModEnabled(
'stripe')) {
277 $onlinepaymentenabled++;
280 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
281 $substitutionarray[
'__ONLINEPAYMENTLINK_MEMBER__'] = getHtmlOnlinePaymentLink(
'member', $obj->source_id);
282 $substitutionarray[
'__ONLINEPAYMENTLINK_DONATION__'] = getHtmlOnlinePaymentLink(
'donation', $obj->source_id);
283 $substitutionarray[
'__ONLINEPAYMENTLINK_ORDER__'] = getHtmlOnlinePaymentLink(
'order', $obj->source_id);
284 $substitutionarray[
'__ONLINEPAYMENTLINK_INVOICE__'] = getHtmlOnlinePaymentLink(
'invoice', $obj->source_id);
285 $substitutionarray[
'__ONLINEPAYMENTLINK_CONTRACTLINE__'] = getHtmlOnlinePaymentLink(
'contractline', $obj->source_id);
295 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'member'.$obj->source_id, 2);
296 $substitutionarray[
'__SECUREKEYPAYMENT_DONATION__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'donation'.$obj->source_id, 2);
297 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'order'.$obj->source_id, 2);
298 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'invoice'.$obj->source_id, 2);
299 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'contractline'.$obj->source_id, 2);
303 $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>';
312 $substitutionarray[
'__SECUREKEYPAYPAL_MEMBER__'] =
dol_hash(
getDolGlobalString(
'PAYPAL_SECURITY_TOKEN') .
'membersubscription'.$obj->source_id, 2);
318 $substitutionarray[
'__SECUREKEYPAYPAL_ORDER__'] =
dol_hash(
getDolGlobalString(
'PAYPAL_SECURITY_TOKEN') .
'order'.$obj->source_id, 2);
324 $substitutionarray[
'__SECUREKEYPAYPAL_INVOICE__'] =
dol_hash(
getDolGlobalString(
'PAYPAL_SECURITY_TOKEN') .
'invoice'.$obj->source_id, 2);
330 $substitutionarray[
'__SECUREKEYPAYPAL_CONTRACTLINE__'] =
dol_hash(
getDolGlobalString(
'PAYPAL_SECURITY_TOKEN') .
'contractline'.$obj->source_id, 2);
340 if (preg_match(
'/__UNSUBSCRIBE_(_|URL_)/', $message)) {
341 $moreinheader =
"List-Unsubscribe: <__UNSUBSCRIBE_URL__>\n";
350 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
351 if (count($listofpaths)) {
352 foreach ($listofpaths as $key => $val) {
353 $arr_file[] = $listofpaths[$key][
'fullname'];
355 $arr_name[] = $listofpaths[$key][
'name'];
360 $trackid =
'emailing-'.$obj->fk_mailing.
'-'.$obj->rowid;
361 $upload_dir_tmp = $upload_dir;
362 $mail =
new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name,
'',
'', 0, $msgishtml, $errorsto, $arr_css, $trackid, $moreinheader,
'emailing',
'', $upload_dir_tmp);
375 $res = $mail->sendfile();
382 dol_syslog(
"comm/mailing/card.php: ok for #".$iforemailloop.($mail->error ?
' - '.$mail->error :
''), LOG_DEBUG);
384 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
385 $sql .=
" SET statut=1, date_envoi = '".$db->idate($now).
"' WHERE rowid=".((int) $obj->rowid);
386 $resql2 = $db->query($sql);
391 if (strpos($message,
'__CHECK_READ__') !==
false) {
393 $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).
")";
394 dol_syslog(
"card.php: set prospect thirdparty status", LOG_DEBUG);
395 $resql2 = $db->query($sql);
401 $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)";
402 dol_syslog(
"card.php: set prospect contact status", LOG_DEBUG);
404 $resql2 = $db->query($sql);
412 dol_syslog(
"Wait a delay of MAILING_DELAY=".((
float) $conf->global->MAILING_DELAY));
413 usleep((
float) $conf->global->MAILING_DELAY * 1000000);
421 dol_syslog(
"comm/mailing/card.php: error for #".$iforemailloop.($mail->error ?
' - '.$mail->error :
''), LOG_WARNING);
423 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
424 $sql .=
" SET statut=-1, error_text='".$db->escape($mail->error).
"', date_envoi='".$db->idate($now).
"' WHERE rowid=".((int) $obj->rowid);
425 $resql2 = $db->query($sql);
434 setEventMessages($langs->transnoentitiesnoconv(
"NoMoreRecipientToSendTo"),
null,
'mesgs');
441 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
443 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
448 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
451 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
455 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing SET statut=".((int) $statut).
" WHERE rowid = ".((int) $object->id);
456 dol_syslog(
"comm/mailing/card.php: update global status", LOG_DEBUG);
457 $resql2 = $db->query($sql);
471 if ($action ==
'send' && ! $cancel) {
474 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
476 $object->sendto =
GETPOST(
"sendto",
'alphawithlgt');
477 if (!$object->sendto) {
478 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailTo")),
null,
'errors');
485 if (preg_match(
'/[\s\t]*<html>/i', $object->body)) {
489 $signature = ((!empty($user->signature) && !
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? $user->signature :
'');
491 $parameters = array(
'mode'=>
'emailing');
495 $substitutionarray[
'__EMAIL__'] = $object->sendto;
496 $substitutionarray[
'__MAILTOEMAIL__'] =
'<a href="mailto:'.$object->sendto.
'">'.$object->sendto.
'</a>';
497 $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-".$obj->sendto.
"-0",
'md5').
'&email='.urlencode($obj->sendto).
'&mtid=0" width="1" height="1" style="width:1px;height:1px" border="0"/>';
498 $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-".$obj->sendto.
"-0",
'md5').
'&email='.urlencode($obj->sendto).
'&mtid=0" target="_blank" rel="noopener noreferrer">'.$langs->trans(
"MailUnsubcribe").
'</a>';
499 $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-".$obj->sendto.
"-0",
'md5').
'&email='.urlencode($obj->sendto).
'&mtid=0';
513 if (!empty($object->bgcolor)) {
514 $arr_css[
'bgcolor'] = (preg_match(
'/^#/', $object->bgcolor) ?
'' :
'#').$object->bgcolor;
516 if (!empty($object->bgimage)) {
517 $arr_css[
'bgimage'] = $object->bgimage;
521 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
522 if (count($listofpaths)) {
523 foreach ($listofpaths as $key => $val) {
524 $arr_file[] = $listofpaths[$key][
'fullname'];
526 $arr_name[] = $listofpaths[$key][
'name'];
530 $trackid =
'emailing-test';
531 $upload_dir_tmp = $upload_dir;
532 $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);
534 $result = $mailfile->sendfile();
536 setEventMessages($langs->trans(
"MailSuccessfulySent", $mailfile->getValidAddress($object->email_from, 2), $mailfile->getValidAddress($object->sendto, 2)),
null,
'mesgs');
539 setEventMessages($langs->trans(
"ResultKo").
'<br>'.$mailfile->error.
' '.$result,
null,
'errors');
546 if ($action ==
'add') {
549 $object->email_from = (string)
GETPOST(
"from",
'alphawithlgt');
550 $object->email_replyto = (string)
GETPOST(
"replyto",
'alphawithlgt');
551 $object->email_errorsto = (string)
GETPOST(
"errorsto",
'alphawithlgt');
552 $object->title = (string)
GETPOST(
"title");
553 $object->sujet = (string)
GETPOST(
"sujet");
554 $object->body = (string)
GETPOST(
"bodyemail",
'restricthtml');
555 $object->bgcolor = preg_replace(
'/^#/',
'', (
string)
GETPOST(
"bgcolor"));
556 $object->bgimage = (string)
GETPOST(
"bgimage");
558 if (!$object->title) {
559 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTitle"));
561 if (!$object->sujet) {
562 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTopic"));
564 if (!$object->body) {
565 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailMessage"));
568 if (!count($mesgs)) {
569 if ($object->create($user) >= 0) {
570 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
573 $mesgs[] = $object->error;
574 $mesgs = array_merge($mesgs, $object->errors);
582 if ($action ==
'settitle' || $action ==
'setemail_from' || $action ==
'setreplyto' || $action ==
'setemail_errorsto' || $action ==
'setevenunsubscribe') {
583 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
585 if ($action ==
'settitle') {
586 $object->title = trim(
GETPOST(
'title',
'alpha'));
587 } elseif ($action ==
'setemail_from') {
588 $object->email_from = trim(
GETPOST(
'email_from',
'alphawithlgt'));
589 } elseif ($action ==
'setemail_replyto') {
590 $object->email_replyto = trim(
GETPOST(
'email_replyto',
'alphawithlgt'));
591 } elseif ($action ==
'setemail_errorsto') {
592 $object->email_errorsto = trim(
GETPOST(
'email_errorsto',
'alphawithlgt'));
593 } elseif ($action ==
'settitle' && empty($object->title)) {
594 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTitle"));
595 } elseif ($action ==
'setfrom' && empty($object->email_from)) {
596 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailFrom"));
597 } elseif ($action ==
'setevenunsubscribe') {
598 $object->evenunsubscribe = (
GETPOST(
'evenunsubscribe') ? 1 : 0);
602 $result = $object->update($user);
604 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
607 $mesg = $object->error;
618 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
620 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
630 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
632 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
640 if ($action ==
'update' && !
GETPOST(
"removedfile") && !$cancel) {
641 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
647 $object->sujet = (string)
GETPOST(
"sujet");
648 $object->body = (string)
GETPOST(
"bodyemail",
'restricthtml');
649 $object->bgcolor = preg_replace(
'/^#/',
'', (
string)
GETPOST(
"bgcolor"));
650 $object->bgimage = (string)
GETPOST(
"bgimage");
652 if (!$object->sujet) {
653 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTopic"));
655 if (!$object->body) {
656 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailMessage"));
659 if (!count($mesgs)) {
660 if ($object->update($user) >= 0) {
661 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
664 $mesgs[] = $object->error;
665 $mesgs = array_merge($mesgs, $object->errors);
676 if ($action ==
'confirm_valid' && $confirm ==
'yes') {
677 if ($object->id > 0) {
678 $object->valid($user);
679 setEventMessages($langs->trans(
"MailingSuccessfullyValidated"),
null,
'mesgs');
680 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
688 if ($action ==
'confirm_settodraft' && $confirm ==
'yes') {
689 if ($object->id > 0) {
690 $result = $object->setStatut(0);
693 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
704 if ($action ==
'confirm_reset' && $confirm ==
'yes') {
705 if ($object->id > 0) {
708 $result = $object->valid($user);
710 $result = $object->reset_targets_status($user);
715 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
727 if ($action ==
'confirm_delete' && $confirm ==
'yes') {
728 if ($object->delete($user)) {
729 $url = (!empty($urlfrom) ? $urlfrom :
'list.php');
730 header(
"Location: ".$url);
745$form =
new Form($db);
748$help_url =
'EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing';
751 $langs->trans(
"Mailing"),
757 '/includes/ace/src/ace.js',
758 '/includes/ace/src/ext-statusbar.js',
759 '/includes/ace/src/ext-language_tools.js',
766if ($action ==
'create') {
768 print
'<form name="new_mailing" action="'.$_SERVER[
'PHP_SELF'].
'" method="POST">'.
"\n";
769 print
'<input type="hidden" name="token" value="'.newToken().
'">';
770 print
'<input type="hidden" name="action" value="add">';
772 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br><br><span class="small">';
773 foreach ($object->substitutionarray as $key => $val) {
774 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
776 $htmltext .=
'</span></i>';
779 $availablelink = $form->textwithpicto(
'<span class="opacitymedium">'.$langs->trans(
"AvailableVariables").
'</span>', $htmltext, 1,
'help',
'', 0, 2,
'availvar');
784 print
load_fiche_titre($langs->trans(
"NewMailing"), $availablelink,
'object_email');
788 print
'<table class="border centpercent">';
790 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>';
792 print
'<tr><td class="fieldrequired">'.$langs->trans(
"MailFrom").
'</td><td><input class="flat minwidth200" name="from" value="'.
getDolGlobalString(
'MAILING_EMAIL_FROM').
'"></td></tr>';
794 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>';
797 $parameters = array();
798 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
799 print $hookmanager->resPrint;
800 if (empty($reshook)) {
801 print $object->showOptionals($extrafields,
'create');
807 print
'<table class="border centpercent">';
808 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>';
809 print
'<tr><td>'.$langs->trans(
"BackgroundColorByDefault").
'</td><td colspan="3">';
810 print $htmlother->selectColor(
GETPOST(
'bgcolor'),
'bgcolor',
'', 0);
815 print
'<div style="padding-top: 10px">';
817 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
818 $doleditor =
new DolEditor(
'bodyemail',
GETPOST(
'bodyemail',
'restricthtmlallowunvalid'),
'', 600,
'dolibarr_mailings',
'',
true,
true,
getDolGlobalInt(
'FCKEDITOR_ENABLE_MAILING'), 20,
'90%');
819 $doleditor->Create();
824 print $form->buttonsSaveCancel(
"CreateMailing",
'Cancel');
828 if ($object->id > 0) {
829 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
833 if ($action ==
'settodraft') {
835 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"SetToDraft"), $langs->trans(
"ConfirmUnvalidateEmailing"),
"confirm_settodraft",
'',
'', 1);
836 } elseif ($action ==
'valid') {
838 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"ValidMailing"), $langs->trans(
"ConfirmValidMailing"),
"confirm_valid",
'',
'', 1);
839 } elseif ($action ==
'reset') {
841 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"ResetMailing"), $langs->trans(
"ConfirmResetMailing", $object->ref),
"confirm_reset",
'',
'', 2);
842 } elseif ($action ==
'delete') {
844 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.(!empty($urlfrom) ?
'&urlfrom='.urlencode($urlfrom) :
''), $langs->trans(
"DeleteAMailing"), $langs->trans(
"ConfirmDeleteMailing"),
"confirm_delete",
'',
'', 1);
847 if ($action !=
'edit' && $action !=
'edithtml') {
853 if ($action ==
'sendall') {
855 $sendingmode = $conf->global->EMAILING_MAIL_SENDMODE;
856 if (empty($sendingmode)) {
857 $sendingmode = $conf->global->MAIN_MAIL_SENDMODE;
859 if (empty($sendingmode)) {
860 $sendingmode =
'mail';
870 $linktoadminemailbefore =
'<a href="'.DOL_URL_ROOT.
'/admin/mails_emailing.php">';
871 $linktoadminemailend =
'</a>';
872 setEventMessages($langs->trans(
"MailSendSetupIs", $listofmethods[$sendingmode]),
null,
'warnings');
873 $messagetoshow = $langs->trans(
"MailSendSetupIs2",
'{s1}',
'{s2}',
'{s3}',
'{s4}');
874 $messagetoshow = str_replace(
'{s1}', $linktoadminemailbefore, $messagetoshow);
875 $messagetoshow = str_replace(
'{s2}', $linktoadminemailend, $messagetoshow);
876 $messagetoshow = str_replace(
'{s3}', $langs->transnoentitiesnoconv(
"MAIN_MAIL_SENDMODE"), $messagetoshow);
877 $messagetoshow = str_replace(
'{s4}', $listofmethods[
'smtps'], $messagetoshow);
881 setEventMessages($langs->trans(
"MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS),
null,
'warnings');
883 $_GET[
"action"] =
'';
886 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL),
null,
'warnings');
888 if (
getDolGlobalString(
'MAILING_LIMIT_WARNING_NOPHPMAIL') && $sendingmode !=
'mail') {
889 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL),
null,
'warnings');
894 setEventMessages(
'<textarea cols="60" rows="'.ROWS_1.
'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.
'</textarea>',
null,
'warnings');
895 if ($conf->file->mailing_limit_sendbyweb !=
'-1') {
898 $_GET[
"action"] =
'';
901 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL),
null,
'warnings');
903 if (
getDolGlobalString(
'MAILING_LIMIT_WARNING_NOPHPMAIL') && $sendingmode !=
'mail') {
904 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL),
null,
'warnings');
910 $text .= $langs->trans(
'WarningLimitSendByDay',
getDolGlobalInt(
'MAILING_LIMIT_SENDBYDAY'));
913 $text .= $langs->trans(
'ConfirmSendingEmailing').
'<br>';
914 $text .= $langs->trans(
'LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
916 if (!isset($conf->global->MAILING_LIMIT_SENDBYCLI) ||
getDolGlobalInt(
'MAILING_LIMIT_SENDBYCLI') >= 0) {
918 $text .= $langs->trans(
"MailingNeedCommand");
919 $text .=
'<br><textarea class="quatrevingtpercent" rows="'.ROWS_2.
'" wrap="soft" disabled>php ./scripts/emailings/mailing-send.php '.$object->id.
' '.$user->login.
'</textarea>';
922 print $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
'SendMailing'), $text,
'sendallconfirmed',
'',
'', 1, 380, 660, 0, $langs->trans(
"Confirm"), $langs->trans(
"Cancel"));
926 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
928 $morehtmlref =
'<div class="refidno">';
930 $morehtmlref .= $form->editfieldkey(
"",
'title', $object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string',
'', 0, 1);
931 $morehtmlref .= $form->editfieldval(
"",
'title', $object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string',
'',
null,
null,
'', 1);
932 $morehtmlref .=
'</div>';
936 if ($object->statut == 2 || $object->statut == 3) {
937 $nbtry = $object->countNbOfTargets(
'alreadysent');
938 $nbko = $object->countNbOfTargets(
'alreadysentko');
940 $morehtmlright .=
' ('.$nbtry.
'/'.$object->nbemail;
942 $morehtmlright .=
' - '.$nbko.
' '.$langs->trans(
"Error");
944 $morehtmlright .=
') ';
947 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlright);
949 print
'<div class="fichecenter">';
950 print
'<div class="fichehalfleft">';
951 print
'<div class="underbanner clearboth"></div>';
952 print
'<table class="border centpercent tableforfield">'.
"\n";
955 print
'<tr><td class="titlefield">';
956 print $form->editfieldkey(
"MailFrom",
'email_from', $object->email_from, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
958 print $form->editfieldval(
"MailFrom",
'email_from', $object->email_from, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
961 $langs->load(
"errors");
962 print
img_warning($langs->trans(
"ErrorBadEMail", $email));
964 $langs->load(
"errors");
965 print
img_warning($langs->trans(
"ErrorBadMXDomain", $email));
972 print $form->editfieldkey(
"MailErrorsTo",
'email_errorsto', $object->email_errorsto, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
974 print $form->editfieldval(
"MailErrorsTo",
'email_errorsto', $object->email_errorsto, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
977 $langs->load(
"errors");
978 print
img_warning($langs->trans(
"ErrorBadEMail", $email));
980 $langs->load(
"errors");
981 print
img_warning($langs->trans(
"ErrorBadMXDomain", $email));
988 print
'<div class="fichehalfright">';
989 print
'<div class="underbanner clearboth"></div>';
991 print
'<table class="border centpercent tableforfield">';
994 print
'<tr><td class="titlefield">';
995 print $langs->trans(
"TotalNbOfDistinctRecipients");
997 $nbemail = ($object->nbemail ? $object->nbemail : 0);
998 if (is_numeric($nbemail)) {
1000 if ((
getDolGlobalString(
'MAILING_LIMIT_SENDBYWEB') &&
getDolGlobalInt(
'MAILING_LIMIT_SENDBYWEB') < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail))) {
1002 $text .= $langs->trans(
'LimitSendingEmailing',
getDolGlobalInt(
'MAILING_LIMIT_SENDBYWEB'));
1004 $text .= $langs->trans(
'SendingFromWebInterfaceIsNotAllowed');
1007 if (empty($nbemail)) {
1008 $nbemail .=
' '.img_warning(
'').
' <span class="warning">'.$langs->trans(
"NoTargetYet").
'</span>';
1011 print $form->textwithpicto($nbemail, $text, 1,
'warning');
1019 print $langs->trans(
"MAIN_MAIL_SENDMODE");
1026 $text = $listofmethods[
'mail'];
1031 print
' <span class="opacitymedium">(';
1036 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER').
')</span>';
1041 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1047 print
'<div class="clearboth"></div>';
1053 if ($action ==
'clone') {
1055 $formquestion = array(
1056 'text' => $langs->trans(
"ConfirmClone"),
1057 array(
'type' =>
'checkbox',
'name' =>
'clone_content',
'label' => $langs->trans(
"CloneContent"),
'value' => 1),
1058 array(
'type' =>
'checkbox',
'name' =>
'clone_receivers',
'label' => $langs->trans(
"CloneReceivers"),
'value' => 0)
1061 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneEMailing', $object->ref),
'confirm_clone', $formquestion,
'yes', 2, 240);
1065 if (
GETPOST(
'cancel',
'alpha') || $confirm ==
'no' || $action ==
'' || in_array($action, array(
'settodraft',
'valid',
'delete',
'sendall',
'clone',
'test',
'editevenunsubscribe'))) {
1066 print
"\n\n<div class=\"tabsAction\">\n";
1068 if (($object->statut == 1) && ($user->hasRight(
'mailing',
'valider') || $object->user_validation_id == $user->id)) {
1069 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=settodraft&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
"SetToDraft").
'</a>';
1072 if (($object->statut == 0 || $object->statut == 1 || $object->statut == 2) && $user->hasRight(
'mailing',
'creer')) {
1074 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
"EditWithEditor").
'</a>';
1076 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
"EditWithTextEditor").
'</a>';
1079 if (!empty($conf->use_javascript_ajax)) {
1080 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edithtml&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
"EditHTMLSource").
'</a>';
1086 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'mailing',
'mailing_advance',
'send')) {
1087 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"TestMailing").
'</a>';
1089 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=test&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
"TestMailing").
'</a>';
1092 if ($object->statut == 0) {
1093 if ($object->nbemail <= 0) {
1094 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NoTargetYet")).
'">'.$langs->trans(
"ValidMailing").
'</a>';
1095 } elseif (!$user->hasRight(
'mailing',
'valider')) {
1096 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"ValidMailing").
'</a>';
1098 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=valid&id='.$object->id.
'">'.$langs->trans(
"ValidMailing").
'</a>';
1102 if (($object->statut == 1 || $object->statut == 2) && $object->nbemail > 0 && $user->hasRight(
'mailing',
'valider')) {
1104 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"SendingFromWebInterfaceIsNotAllowed")).
'">'.$langs->trans(
"SendMailing").
'</a>';
1105 } elseif (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'mailing',
'mailing_advance',
'send')) {
1106 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"SendMailing").
'</a>';
1108 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=sendall&id='.$object->id.
'">'.$langs->trans(
"SendMailing").
'</a>';
1112 if ($user->hasRight(
'mailing',
'creer')) {
1113 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=clone&object=emailing&id='.$object->id.
'">'.$langs->trans(
"ToClone").
'</a>';
1116 if (($object->statut == 2 || $object->statut == 3) && $user->hasRight(
'mailing',
'valider')) {
1117 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'mailing',
'mailing_advance',
'send')) {
1118 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"ResetMailing").
'</a>';
1120 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=reset&id='.$object->id.
'">'.$langs->trans(
"ResetMailing").
'</a>';
1124 if (($object->statut <= 1 && $user->hasRight(
'mailing',
'creer')) || $user->hasRight(
'mailing',
'supprimer')) {
1125 if ($object->statut > 0 && (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'mailing',
'mailing_advance',
'delete'))) {
1126 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"DeleteMailing").
'</a>';
1128 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.newToken().
'&id='.$object->id.(!empty($urlfrom) ?
'&urlfrom='.$urlfrom :
'').
'">'.$langs->trans(
"DeleteMailing").
'</a>';
1136 if ($action ==
'test') {
1137 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
1143 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1145 $formmail->fromname = $object->email_from;
1146 $formmail->frommail = $object->email_from;
1147 $formmail->withsubstit = 1;
1148 $formmail->withfrom = 0;
1149 $formmail->withto = $user->email ? $user->email : 1;
1150 $formmail->withtocc = 0;
1152 $formmail->withtopic = 0;
1153 $formmail->withtopicreadonly = 1;
1154 $formmail->withfile = 0;
1155 $formmail->withbody = 0;
1156 $formmail->withbodyreadonly = 1;
1157 $formmail->withcancel = 1;
1158 $formmail->withdeliveryreceipt = 0;
1160 $formmail->substit = $object->substitutionarrayfortest;
1162 $formmail->param[
"action"] =
"send";
1163 $formmail->param[
"models"] =
'none';
1164 $formmail->param[
"mailid"] = $object->id;
1165 $formmail->param[
"returnurl"] = $_SERVER[
'PHP_SELF'].
"?id=".$object->id;
1167 print $formmail->get_form();
1177 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br><br><span class="small">';
1178 foreach ($object->substitutionarray as $key => $val) {
1179 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1181 $htmltext .=
'</span></i>';
1184 print
load_fiche_titre($langs->trans(
"EMail"), $form->textwithpicto(
'<span class="opacitymedium hideonsmartphone">'.$langs->trans(
"AvailableVariables").
'</span>', $htmltext, 1,
'helpclickable',
'', 0, 3,
'emailsubstitionhelp'),
'generic');
1188 print
'<table class="bordernooddeven tableforfield centpercent">';
1191 print
'<tr><td class="titlefield">'.$langs->trans(
"MailTopic").
'</td><td colspan="3">'.$object->sujet.
'</td></tr>';
1194 print
'<tr><td>'.$langs->trans(
"MailFile").
'</td><td colspan="3">';
1196 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
1197 if (count($listofpaths)) {
1198 foreach ($listofpaths as $key => $val) {
1199 print
img_mime($listofpaths[$key][
'name']).
' '.$listofpaths[$key][
'name'];
1203 print
'<span class="opacitymedium">'.$langs->trans(
"NoAttachedFiles").
'</span><br>';
1215 print
'<div style="padding-top: 10px; background: '.($object->bgcolor ? (preg_match(
'/^#/', $object->bgcolor) ?
'' :
'#').$object->bgcolor :
'white').
'">';
1216 if (empty($object->bgcolor) || strtolower($object->bgcolor) ==
'ffffff') {
1219 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1220 $doleditor =
new DolEditor(
'bodyemail', $object->body,
'', 600,
'dolibarr_mailings',
'',
false,
true, !
getDolGlobalString(
'FCKEDITOR_ENABLE_MAILING') ? 0 : 1, 20,
'90%', $readonly);
1221 $doleditor->Create();
1235 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
1237 $morehtmlref =
'<div class="refidno">';
1239 $morehtmlref .= $form->editfieldkey(
"",
'title', $object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string',
'', 0, 1);
1240 $morehtmlref .= $form->editfieldval(
"",
'title', $object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string',
'',
null,
null,
'', 1);
1241 $morehtmlref .=
'</div>';
1243 $morehtmlright =
'';
1245 if ($object->statut == 2 || $object->statut == 3) {
1246 $nbtry = $object->countNbOfTargets(
'alreadysent');
1247 $nbko = $object->countNbOfTargets(
'alreadysentko');
1249 $morehtmlright .=
' ('.$nbtry.
'/'.$object->nbemail;
1251 $morehtmlright .=
' - '.$nbko.
' '.$langs->trans(
"Error");
1253 $morehtmlright .=
') ';
1256 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlright);
1258 print
'<div class="fichecenter">';
1259 print
'<div class="fichehalfleft">';
1260 print
'<div class="underbanner clearboth"></div>';
1262 print
'<table class="border centpercent tableforfield">';
1272 print
'<tr><td class="titlefield">'.$langs->trans(
"MailFrom").
'</td><td>'.
dol_print_email($object->email_from, 0, 0, 0, 0, 1).
'</td></tr>';
1274 print
'<tr><td>'.$langs->trans(
"MailErrorsTo").
'</td><td>'.
dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1).
'</td></tr>';
1280 print
'<div class="fichehalfright">';
1281 print
'<div class="underbanner clearboth"></div>';
1283 print
'<table class="border centpercent tableforfield">';
1287 print $langs->trans(
"TotalNbOfDistinctRecipients");
1289 $nbemail = ($object->nbemail ? $object->nbemail : 0);
1290 if (is_numeric($nbemail)) {
1292 if ((
getDolGlobalString(
'MAILING_LIMIT_SENDBYWEB') && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || $object->statut == 2)) {
1294 $text .= $langs->trans(
'LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
1296 $text .= $langs->trans(
'SendingFromWebInterfaceIsNotAllowed');
1299 if (empty($nbemail)) {
1300 $nbemail .=
' '.img_warning(
'').
' <span class="warning">'.$langs->trans(
"NoTargetYet").
'</span>';
1303 print $form->textwithpicto($nbemail, $text, 1,
'warning');
1311 print $langs->trans(
"MAIN_MAIL_SENDMODE");
1318 $text = $listofmethods[
'mail'];
1323 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER_EMAILING').
')</span>';
1326 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER').
')</span>';
1332 $parameters = array();
1333 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1334 print $hookmanager->resPrint;
1335 if (empty($reshook)) {
1336 print $object->showOptionals($extrafields,
'edit', $parameters);
1343 print
'<div class="clearboth"></div>';
1350 print
'<form name="edit_mailing" action="card.php" method="post" enctype="multipart/form-data">'.
"\n";
1351 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1352 print
'<input type="hidden" name="action" value="update">';
1353 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1355 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br><br><span class="small">';
1356 foreach ($object->substitutionarray as $key => $val) {
1357 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1359 $htmltext .=
'</span></i>';
1362 print
load_fiche_titre($langs->trans(
"EMail"),
'<span class="opacitymedium">'.$form->textwithpicto($langs->trans(
"AvailableVariables").
'</span>', $htmltext, 1,
'help',
'', 0, 2,
'emailsubstitionhelp'),
'generic');
1366 print
'<table class="bordernooddeven centpercent">';
1369 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>';
1375 $addfileaction =
'addfile';
1376 print
'<tr><td>'.$langs->trans(
"MailFile").
'</td>';
1377 print
'<td colspan="3">';
1379 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
1382 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
1383 $out .=
'<script type="text/javascript">';
1384 $out .=
'jQuery(document).ready(function () {';
1385 $out .=
' jQuery(".removedfile").click(function() {';
1386 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
1389 $out .=
'</script>'.
"\n";
1390 if (count($listofpaths)) {
1391 foreach ($listofpaths as $key => $val) {
1392 $out .=
'<div id="attachfile_'.$key.
'">';
1393 $out .=
img_mime($listofpaths[$key][
'name']).
' '.$listofpaths[$key][
'name'];
1394 $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.
'" />';
1395 $out .=
'<br></div>';
1403 $maxmin = $maxfilesizearray[
'maxmin'];
1405 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
1407 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
1409 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
1414 print
'<tr><td>'.$langs->trans(
"BackgroundColorByDefault").
'</td><td colspan="3">';
1415 print $htmlother->selectColor($object->bgcolor,
'bgcolor',
'', 0);
1422 print
'<div style="padding-top: 10px">';
1424 if ($action ==
'edit') {
1426 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1427 $doleditor =
new DolEditor(
'bodyemail', $object->body,
'', 600,
'dolibarr_mailings',
'',
true,
true,
getDolGlobalInt(
'FCKEDITOR_ENABLE_MAILING'), 20,
'90%');
1428 $doleditor->Create();
1430 if ($action ==
'edithtml') {
1432 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1433 $doleditor =
new DolEditor(
'bodyemail', $object->body,
'', 600,
'dolibarr_mailings',
'',
true,
true,
'ace', 20,
'90%');
1434 $doleditor->Create(0,
'',
false,
'HTML Source',
'php');
1442 print
'<div class="center">';
1443 print
'<input type="submit" class="button buttonforacesave button-save" value="'.$langs->trans(
"Save").
'" name="save">';
1444 print
' ';
1445 print
'<input type="submit" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'" name="cancel">';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
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.
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_init_file_process($pathtoscan='', $trackid='')
Scan a directory and init $_SESSION to manage uploaded files with list of all found files.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
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_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null)
Get and save an upload file (for example after submitting a new file a mail form).
isValidMailDomain($mail)
Return true if email has a domain name that can be resolved to MX type.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
dol_now($mode='auto')
Return date for now.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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...
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.