30if (!defined(
'NOSTYLECHECK')) {
31 define(
'NOSTYLECHECK',
'1');
35require
'../../main.inc.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/lib/emailing.lib.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
49require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/mailing.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
54 require_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
55 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formprojet.class.php';
59$langs->loadLangs(array(
"mails",
"admin"));
63$action =
GETPOST(
'action',
'aZ09');
64$confirm =
GETPOST(
'confirm',
'alpha');
65$cancel =
GETPOST(
'cancel',
'alpha');
68$backtopage =
GETPOST(
'backtopage');
69$backtopageforcancel =
GETPOST(
'backtopageforcancel');
74$hookmanager->initHooks(array(
'mailingcard',
'globalcard'));
77$extrafields->fetch_name_optionals_label(
$object->table_element);
80include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
98$signature = ((!empty($user->signature) && !
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? $user->signature :
'');
102$parameters = array(
'mode' =>
'emailing');
105$object->substitutionarrayfortest = $substitutionarray;
108$listofmethods = array();
110$listofmethods[
'mail'] =
'PHP mail function';
112$listofmethods[
'smtps'] =
'SMTP/SMTPS socket library';
113if (version_compare(phpversion(),
'7.0',
'>=')) {
114 $listofmethods[
'swiftmailer'] =
'Swift Mailer socket library';
118if (!$user->hasRight(
'mailing',
'lire') || (!
getDolGlobalString(
'EXTERNAL_USERS_ARE_AUTHORIZED') && $user->socid > 0)) {
121if (empty($action) && empty(
$object->id)) {
128$permissiontocreate = $user->hasRight(
'mailing',
'creer');
129$permissiontovalidatesend = $user->hasRight(
'mailing',
'valider');
130$permissiontodelete = $user->hasRight(
'mailing',
'supprimer');
137$parameters = array();
138$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
143if (empty($reshook)) {
146 $backurlforlist = DOL_URL_ROOT.
'/comm/mailing/list.php';
148 if (empty($backtopage) || ($cancel && empty($id))) {
149 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
150 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
151 $backtopage = $backurlforlist;
153 $backtopage = DOL_URL_ROOT.
'/comm/mailing/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
160 if (!empty($backtopageforcancel)) {
161 header(
"Location: ".$backtopageforcancel);
163 } elseif (!empty($backtopage)) {
164 header(
"Location: ".$backtopage);
171 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontocreate) {
172 if (!
GETPOST(
"clone_content",
'alpha') && !
GETPOST(
"clone_receivers",
'alpha')) {
177 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
187 if ($action ==
'sendallconfirmed' && $confirm ==
'yes' && $permissiontovalidatesend) {
191 setEventMessages(
'<textarea cols="70" rows="'.ROWS_2.
'" wrap="soft">php ./scripts/emailings/mailing-send.php '.
$object->id.
'</textarea>',
null,
'warnings');
207 $replyto =
$object->email_replyto;
208 $errorsto =
$object->email_errorsto;
211 if (preg_match(
'/[\s\t]*<html>/i', $message)) {
223 $sql =
"SELECT mc.rowid, mc.fk_mailing, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
224 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc";
225 $sql .=
" WHERE mc.statut < 1 AND mc.fk_mailing = ".((int)
$object->id);
226 $sql .=
" ORDER BY mc.statut DESC";
228 dol_syslog(
"card.php: select targets", LOG_DEBUG);
229 $resql = $db->query($sql);
231 $num = $db->num_rows($resql);
234 dol_syslog(
"comm/mailing/card.php: nb of targets = ".$num, LOG_DEBUG);
239 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing SET date_envoi='".$db->idate($now).
"' WHERE rowid=".((int)
$object->id);
240 $resql2 = $db->query($sql);
245 $thirdpartystatic =
new Societe($db);
249 while ($iforemailloop < $num && $iforemailloop < $conf->global->MAILING_LIMIT_SENDBYWEB) {
254 $obj = $db->fetch_object($resql);
257 $sendto = str_replace(
',',
' ',
dolGetFirstLastname($obj->firstname, $obj->lastname)).
" <".$obj->email.
">";
260 $other = explode(
';', $obj->other);
261 $tmpfield = explode(
'=', $other[0], 2);
262 $other1 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
263 $tmpfield = explode(
'=', $other[1], 2);
264 $other2 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
265 $tmpfield = explode(
'=', $other[2], 2);
266 $other3 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
267 $tmpfield = explode(
'=', $other[3], 2);
268 $other4 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
269 $tmpfield = explode(
'=', $other[4], 2);
270 $other5 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
272 $signature = ((!empty($user->signature) && !
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? $user->signature :
'');
274 $parameters = array(
'mode' =>
'emailing');
275 $substitutionarray = getCommonSubstitutionArray($langs, 0, array(
'object',
'objectamount'), $targetobject);
278 $substitutionarray[
'__ID__'] = $obj->source_id;
279 $substitutionarray[
'__EMAIL__'] = $obj->email;
280 $substitutionarray[
'__LASTNAME__'] = $obj->lastname;
281 $substitutionarray[
'__FIRSTNAME__'] = $obj->firstname;
282 $substitutionarray[
'__MAILTOEMAIL__'] =
'<a href="mailto:'.$obj->email.
'">'.$obj->email.
'</a>';
283 $substitutionarray[
'__OTHER1__'] = $other1;
284 $substitutionarray[
'__OTHER2__'] = $other2;
285 $substitutionarray[
'__OTHER3__'] = $other3;
286 $substitutionarray[
'__OTHER4__'] = $other4;
287 $substitutionarray[
'__OTHER5__'] = $other5;
289 if ($obj->source_type ==
"thirdparty") {
290 $result = $thirdpartystatic->fetch($obj->source_id);
292 $substitutionarray[
'__THIRDPARTY_CUSTOMER_CODE__'] = $thirdpartystatic->code_client;
294 $substitutionarray[
'__THIRDPARTY_CUSTOMER_CODE__'] =
'';
298 $substitutionarray[
'__USER_SIGNATURE__'] = $signature;
299 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $signature;
300 $substitutionarray[
'__CHECK_READ__'] =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php?tag='.urlencode($obj->tag).
'&securitykey='.
dol_hash(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY').
'-'.$obj->tag.
'-'.$obj->email.
'-'.$obj->rowid,
"md5").
'&email='.urlencode($obj->email).
'&mtid='.((int) $obj->rowid).
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
301 $substitutionarray[
'__UNSUBSCRIBE__'] =
'<a href="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-unsubscribe.php?tag='.urlencode($obj->tag).
'&unsuscrib=1&securitykey='.
dol_hash(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY').
'-'.$obj->tag.
'-'.$obj->email.
'-'.$obj->rowid,
"md5").
'&email='.urlencode($obj->email).
'&mtid='.((int) $obj->rowid).
'" target="_blank" rel="noopener noreferrer">'.$langs->trans(
"MailUnsubcribe").
'</a>';
302 $substitutionarray[
'__UNSUBSCRIBE_URL__'] = DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-unsubscribe.php?tag='.urlencode($obj->tag).
'&unsuscrib=1&securitykey='.
dol_hash(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY').
'-'.$obj->tag.
'-'.$obj->email.
'-'.$obj->rowid,
"md5").
'&email='.urlencode($obj->email).
'&mtid='.((int) $obj->rowid);
304 $onlinepaymentenabled = 0;
306 $onlinepaymentenabled++;
309 $onlinepaymentenabled++;
312 $onlinepaymentenabled++;
315 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
316 $substitutionarray[
'__ONLINEPAYMENTLINK_MEMBER__'] = getHtmlOnlinePaymentLink(
'member', $obj->source_id);
317 $substitutionarray[
'__ONLINEPAYMENTLINK_DONATION__'] = getHtmlOnlinePaymentLink(
'donation', $obj->source_id);
318 $substitutionarray[
'__ONLINEPAYMENTLINK_ORDER__'] = getHtmlOnlinePaymentLink(
'order', $obj->source_id);
319 $substitutionarray[
'__ONLINEPAYMENTLINK_INVOICE__'] = getHtmlOnlinePaymentLink(
'invoice', $obj->source_id);
320 $substitutionarray[
'__ONLINEPAYMENTLINK_CONTRACTLINE__'] = getHtmlOnlinePaymentLink(
'contractline', $obj->source_id);
330 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'member'.$obj->source_id,
'2');
331 $substitutionarray[
'__SECUREKEYPAYMENT_DONATION__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'donation'.$obj->source_id,
'2');
332 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'order'.$obj->source_id,
'2');
333 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'invoice'.$obj->source_id,
'2');
334 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
dol_hash(
getDolGlobalString(
'PAYMENT_SECURITY_TOKEN') .
'contractline'.$obj->source_id,
'2');
338 $substitutionarray[
'__PUBLICLINK_NEWMEMBERFORM__'] =
'<a target="_blank" rel="noopener noreferrer" href="'.DOL_MAIN_URL_ROOT.
'/public/members/new.php'.((
isModEnabled(
'multicompany')) ?
'?entity='.$conf->entity :
'').
'">'.$langs->trans(
'BlankSubscriptionForm').
'</a>';
347 $substitutionarray[
'__SECUREKEYPAYPAL_MEMBER__'] =
dol_hash(
getDolGlobalString(
'PAYPAL_SECURITY_TOKEN') .
'membersubscription'.$obj->source_id,
'2');
353 $substitutionarray[
'__SECUREKEYPAYPAL_ORDER__'] =
dol_hash(
getDolGlobalString(
'PAYPAL_SECURITY_TOKEN') .
'order'.$obj->source_id,
'2');
359 $substitutionarray[
'__SECUREKEYPAYPAL_INVOICE__'] =
dol_hash(
getDolGlobalString(
'PAYPAL_SECURITY_TOKEN') .
'invoice'.$obj->source_id,
'2');
365 $substitutionarray[
'__SECUREKEYPAYPAL_CONTRACTLINE__'] =
dol_hash(
getDolGlobalString(
'PAYPAL_SECURITY_TOKEN') .
'contractline'.$obj->source_id,
'2');
375 if (preg_match(
'/__UNSUBSCRIBE_(_|URL_)/', $message)) {
376 $moreinheader =
"List-Unsubscribe: <__UNSUBSCRIBE_URL__>\n";
385 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
386 if (count($listofpaths)) {
387 foreach ($listofpaths as $key => $val) {
388 $arr_file[] = $listofpaths[$key][
'fullname'];
390 $arr_name[] = $listofpaths[$key][
'name'];
395 $trackid =
'emailing-'.$obj->fk_mailing.
'-'.$obj->rowid;
396 $upload_dir_tmp = $upload_dir;
397 $mail =
new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name,
'',
'', 0, $msgishtml, $errorsto, $arr_css, $trackid, $moreinheader,
'emailing', $replyto, $upload_dir_tmp);
410 $res = $mail->sendfile();
417 dol_syslog(
"comm/mailing/card.php: ok for #".$iforemailloop.($mail->error ?
' - '.$mail->error :
''), LOG_DEBUG);
419 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
420 $sql .=
" SET statut=1, date_envoi = '".$db->idate($now).
"' WHERE rowid=".((int) $obj->rowid);
421 $resql2 = $db->query($sql);
426 if (strpos($message,
'__CHECK_READ__') !==
false) {
428 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE rowid=".((int) $obj->rowid).
")";
429 dol_syslog(
"card.php: set prospect thirdparty status", LOG_DEBUG);
430 $resql2 = $db->query($sql);
436 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX.
"mailing_cibles AS mc ON mc.rowid=".((int) $obj->rowid).
" AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
437 dol_syslog(
"card.php: set prospect contact status", LOG_DEBUG);
439 $resql2 = $db->query($sql);
447 dol_syslog(
"Wait a delay of MAILING_DELAY=".((
float) $conf->global->MAILING_DELAY));
448 usleep((
int) ((
float) $conf->global->MAILING_DELAY * 1000000));
456 dol_syslog(
"comm/mailing/card.php: error for #".$iforemailloop.($mail->error ?
' - '.$mail->error :
''), LOG_WARNING);
458 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
459 $sql .=
" SET statut=-1, error_text='".$db->escape(
dol_trunc($mail->error, 250)).
"', date_envoi='".$db->idate($now).
"' WHERE rowid=".((int) $obj->rowid);
460 $resql2 = $db->query($sql);
469 setEventMessages($langs->transnoentitiesnoconv(
"NoMoreRecipientToSendTo"),
null,
'mesgs');
475 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", (
string) $nbok),
null,
'mesgs');
482 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", (
string) $nbok),
null,
'mesgs');
485 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing SET statut=".((int) $statut).
" WHERE rowid = ".((int)
$object->id);
486 dol_syslog(
"comm/mailing/card.php: update global status", LOG_DEBUG);
487 $resql2 = $db->query($sql);
501 if ($action ==
'send' && ! $cancel && $permissiontovalidatesend) {
508 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailTo")),
null,
'errors');
515 if (preg_match(
'/[\s\t]*<html>/i',
$object->body)) {
519 $signature = ((!empty($user->signature) && !
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? $user->signature :
'');
521 $parameters = array(
'mode' =>
'emailing');
522 $substitutionarray = getCommonSubstitutionArray($langs, 0, array(
'object',
'objectamount'), $targetobject);
525 $substitutionarray[
'__EMAIL__'] =
$object->sendto;
526 $substitutionarray[
'__MAILTOEMAIL__'] =
'<a href="mailto:'.$object->sendto.
'">'.
$object->sendto.
'</a>';
527 $substitutionarray[
'__CHECK_READ__'] =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php?tag=undefinedintestmode&securitykey='.
dol_hash(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY').
"-undefinedintestmode-".
$object->sendto.
"-0",
'md5').
'&email='.urlencode(
$object->sendto).
'&mtid=0" width="1" height="1" style="width:1px;height:1px" border="0"/>';
528 $substitutionarray[
'__UNSUBSCRIBE__'] =
'<a href="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-unsubscribe.php?tag=undefinedintestmode&unsuscrib=1&securitykey='.
dol_hash(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY').
"-undefinedintestmode-".
$object->sendto.
"-0",
'md5').
'&email='.urlencode(
$object->sendto).
'&mtid=0" target="_blank" rel="noopener noreferrer">'.$langs->trans(
"MailUnsubcribe").
'</a>';
529 $substitutionarray[
'__UNSUBSCRIBE_URL__'] = DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-unsubscribe.php?tag=undefinedintestmode&unsuscrib=1&securitykey='.
dol_hash(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY').
"-undefinedintestmode-".
$object->sendto.
"-0",
'md5').
'&email='.urlencode(
$object->sendto).
'&mtid=0';
543 if (!empty(
$object->bgcolor)) {
544 $arr_css[
'bgcolor'] = (preg_match(
'/^#/',
$object->bgcolor) ?
'' :
'#').
$object->bgcolor;
546 if (!empty(
$object->bgimage)) {
547 $arr_css[
'bgimage'] =
$object->bgimage;
551 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
552 if (count($listofpaths)) {
553 foreach ($listofpaths as $key => $val) {
554 $arr_file[] = $listofpaths[$key][
'fullname'];
556 $arr_name[] = $listofpaths[$key][
'name'];
560 $trackid =
'emailing-test';
561 $upload_dir_tmp = $upload_dir;
562 $mailfile =
new CMailFile($tmpsujet,
$object->sendto,
$object->email_from, $tmpbody, $arr_file, $arr_mime, $arr_name,
'',
'', 0, $msgishtml,
$object->email_errorsto, $arr_css, $trackid,
'',
'emailing',
$object->email_replyto, $upload_dir_tmp);
564 $result = $mailfile->sendfile();
566 setEventMessages($langs->trans(
"MailSuccessfulySent", $mailfile->getValidAddress(
$object->email_from, 2), $mailfile->getValidAddress(
$object->sendto, 2)),
null,
'mesgs');
569 setEventMessages($langs->trans(
"ResultKo").
'<br>'.$mailfile->error.
' '.json_encode($result),
null,
'errors');
577 if ($action ==
'add' && $permissiontocreate) {
579 if (
$object->messtype ==
'sms') {
580 $object->email_from = (string)
GETPOST(
"from_phone",
'alphawithlgt');
584 $object->email_replyto = (string)
GETPOST(
"replyto",
'alphawithlgt');
585 $object->email_errorsto = (string)
GETPOST(
"errorsto",
'alphawithlgt');
589 $object->bgcolor = preg_replace(
'/^#/',
'', (
string)
GETPOST(
"bgcolor"));
594 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTitle"));
597 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTopic"));
600 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailMessage"));
603 if (!count($mesgs)) {
604 if (
$object->create($user) >= 0) {
605 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
609 $mesgs = array_merge($mesgs,
$object->errors);
616 if ($action ==
'classin' && $permissiontocreate) {
619 dol_syslog(
'Mailing card, action classin, setProject', LOG_DEBUG);
621 $result =
$object->update($user);
623 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
634 if (($action ==
'settitle' || $action ==
'setemail_from' || $action ==
'setemail_replyto' || $action ==
'setreplyto' || $action ==
'setemail_errorsto' || $action ==
'setevenunsubscribe') && $permissiontovalidatesend) {
637 if ($action ==
'settitle') {
639 } elseif ($action ==
'setemail_from') {
640 $object->email_from = trim(
GETPOST(
'email_from',
'alphawithlgt'));
641 } elseif ($action ==
'setemail_replyto') {
642 $object->email_replyto = trim(
GETPOST(
'email_replyto',
'alphawithlgt'));
643 } elseif ($action ==
'setemail_errorsto') {
644 $object->email_errorsto = trim(
GETPOST(
'email_errorsto',
'alphawithlgt'));
645 } elseif ($action ==
'settitle' && empty(
$object->title)) {
646 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTitle"));
647 } elseif ($action ==
'setfrom' && empty(
$object->email_from)) {
648 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailFrom"));
649 } elseif ($action ==
'setevenunsubscribe') {
653 if (isset($mesg) && !$mesg) {
654 $result =
$object->update($user);
656 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
669 if (
GETPOST(
'addfile') && $permissiontocreate) {
672 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
681 if (
GETPOSTINT(
"removedfile") && $permissiontocreate) {
684 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
692 if ($action ==
'update' && !
GETPOSTINT(
"removedfile") && !$cancel && $permissiontocreate) {
693 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
703 $object->bgcolor = preg_replace(
'/^#/',
'', (
string)
GETPOST(
"bgcolor"));
707 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTopic"));
710 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailMessage"));
713 if (!count($mesgs)) {
714 if (
$object->update($user) >= 0) {
715 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
719 $mesgs = array_merge($mesgs,
$object->errors);
730 if ($action ==
'confirm_valid' && $confirm ==
'yes' && $permissiontovalidatesend) {
733 setEventMessages($langs->trans(
"MailingSuccessfullyValidated"),
null,
'mesgs');
734 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
742 if ($action ==
'confirm_settodraft' && $confirm ==
'yes' && $permissiontocreate) {
744 $result =
$object->setStatut(0);
747 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
758 if ($action ==
'confirm_reset' && $confirm ==
'yes' && $permissiontocreate) {
762 $result =
$object->valid($user);
764 $result =
$object->reset_targets_status($user);
769 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
781 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $permissiontodelete) {
783 $url = (!empty($urlfrom) ? $urlfrom :
'list.php');
784 header(
"Location: ".$url);
799$form =
new Form($db);
810$help_url =
'EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing';
813 $langs->trans(
"Mailing"),
819 '/includes/ace/src/ace.js',
820 '/includes/ace/src/ext-statusbar.js',
821 '/includes/ace/src/ext-language_tools.js',
828if ($action ==
'create') {
830 print
'<form name="new_mailing" action="'.$_SERVER[
'PHP_SELF'].
'" method="POST">'.
"\n";
831 print
'<input type="hidden" name="token" value="'.newToken().
'">';
832 print
'<input type="hidden" name="action" value="add">';
834 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br><br><span class="small">';
835 foreach (
$object->substitutionarray as $key => $val) {
836 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
838 $htmltext .=
'</span></i>';
840 $availablelink =
'<span class="opacitymedium hideonsmartphone small">'.$form->textwithpicto($langs->trans(
"AvailableVariables"), $htmltext, 1,
'helpclickable',
'', 0, 2,
'availvar').
'</span>';
843 print
load_fiche_titre($langs->trans(
"NewMailing"), $availablelink,
'object_email');
847 print
'<table class="border centpercent">';
853 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
"MailTitle").
'</td><td><input class="flat minwidth300" id="title" name="title" value="'.
dolPrintHTMLForAttribute($title).
'" autofocus="autofocus" spellcheck="false"></td></tr>';
857 $langs->load(
"projects");
858 print
'<tr class="field_projectid">';
859 print
'<td class="titlefieldcreate">' . $langs->trans(
"Project") .
'</td><td class="valuefieldcreate">';
860 print
img_picto(
'',
'project',
'class="pictofixedwidth"') . $formproject->select_projects(-1, (
string) $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
861 print
' <a href="' . DOL_URL_ROOT .
'/projet/card.php?action=create&status=1&backtopage=' . urlencode($_SERVER[
"PHP_SELF"] .
'?action=create') .
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans(
"AddProject") .
'"></span></a>';
867 $arrayoftypes = array(
"email" =>
"Email",
"sms" =>
"SMS");
868 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
"Type").
'</td><td>';
869 print $form->selectarray(
'messtype', $arrayoftypes, (GETPOSTISSET(
'messtype') ?
GETPOST(
'messtype') :
'email'), 0, 0);
872 $( document ).ready(function() {
873 jQuery("#messtype").on("change", function() {
874 console.log("We change the message ttpe");
875 if (jQuery("#messtype").val() == "email") {
876 jQuery(".fieldsforsms").hide();
877 jQuery(".fieldsforemail").show();
879 if (jQuery("#messtype").val() == "sms") {
880 jQuery(".fieldsforsms").show();
881 jQuery(".fieldsforemail").hide();
884 jQuery("#messtype").change();
894 print
'<table class="border centpercent">';
896 print
'<tr class="fieldsforemail"><td class="fieldrequired titlefieldcreate">'.$langs->trans(
"MailFrom").
'</td>';
897 print
'<td>'.img_picto(
'',
'email',
'class="pictofixedwidth"').
'<input class="flat minwidth200" name="from" value="'.(GETPOSTISSET(
'from') ?
GETPOST(
'from') :
getDolGlobalString(
'MAILING_EMAIL_FROM')).
'" spellcheck="false"></td></tr>';
899 print
'<tr class="fieldsforsms hidden"><td class="fieldrequired titlefieldcreate">'.$langs->trans(
"PhoneFrom").
'</td>';
900 print
'<td>'.img_picto(
'',
'email',
'class="pictofixedwidth"').
'<input class="flat minwidth200" name="fromphone" value="'.(GETPOSTISSET(
'fromphone') ?
GETPOST(
'fromphone') :
getDolGlobalString(
'MAILING_SMS_FROM')).
'" placeholder="+123..."></td></tr>';
902 print
'<tr class="fieldsforemail"><td>'.$langs->trans(
"MailErrorsTo").
'</td>';
903 print
'<td>'.img_picto(
'',
'email',
'class="pictofixedwidth"').
'<input class="flat minwidth200" name="errorsto" value="'.
getDolGlobalString(
'MAILING_EMAIL_ERRORSTO',
getDolGlobalString(
'MAIN_MAIL_ERRORS_TO')).
'"></td></tr>';
905 print
'<tr class="fieldsforemail"><td>'.$langs->trans(
"MailReply").
'</td>';
906 print
'<td>'.img_picto(
'',
'email',
'class="pictofixedwidth"').
'<input class="flat minwidth200" name="replyto" value="'.
getDolGlobalString(
'MAILING_EMAIL_REPLYTO',
getDolGlobalString(
'MAIN_MAIL_REPLY_TO')).
'"></td></tr>';
909 $parameters = array();
910 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
911 print $hookmanager->resPrint;
912 if (empty($reshook)) {
913 print
$object->showOptionals($extrafields,
'create');
920 print
'<table class="border centpercent">';
923 if (empty($subject)) {
924 $subject =
'['.$mysoc->name.
'] '.$langs->trans(
"Information");
927 print
'<tr class="fieldsforemail"><td class="fieldrequired titlefieldcreate">'.$langs->trans(
"MailTopic").
'</td>';
928 print
'<td><input id="subject" class="flat minwidth200 quatrevingtpercent" name="subject" id="subject" value="'.dolPrintHTMLForAttributeUrl($subject).
'"></td></tr>';
938 $formmail->withfckeditor = 1;
939 $formmail->withlayout =
'emailing';
940 $formmail->withaiprompt =
'html';
942 print
'<tr class="fieldsforemail"><td></td><td class="tdtop"></td></tr>';
944 print
'<tr class="fieldsforemail"><td class="tdtop" colspan="2">';
947 $showlinktolayout = ($formmail->withfckeditor ? $formmail->withlayout :
'');
948 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
949 $showlinktoai = ($formmail->withaiprompt &&
isModEnabled(
'ai')) ?
'textgenerationemail' :
'';
950 $showlinktoailabel = $langs->trans(
"FillMessageWithAIContent");
951 $formatforouput =
'html';
952 $htmlname =
'bodyemail';
955 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
963 print
'<div style="padding-top: 10px">';
965 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
966 $doleditor =
new DolEditor(
'bodyemail',
GETPOST(
'bodyemail',
'restricthtmlallowunvalid'),
'', 600,
'dolibarr_mailings',
'',
true, $acceptlocallinktomedia,
getDolGlobalInt(
'FCKEDITOR_ENABLE_MAILING'), 20,
'100%');
967 $doleditor->Create();
972 print $form->buttonsSaveCancel(
"Create",
'Cancel');
981 if ($action ==
'settodraft') {
983 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".
$object->id, $langs->trans(
"SetToDraft"), $langs->trans(
"ConfirmUnvalidateEmailing"),
"confirm_settodraft",
'',
'', 1);
984 } elseif ($action ==
'valid') {
986 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".
$object->id, $langs->trans(
"ValidMailing"), $langs->trans(
"ConfirmValidMailing"),
"confirm_valid",
'',
'', 1);
987 } elseif ($action ==
'reset') {
989 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".
$object->id, $langs->trans(
"ResetMailing"), $langs->trans(
"ConfirmResetMailing",
$object->ref),
"confirm_reset",
'',
'', 2);
990 } elseif ($action ==
'delete') {
992 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".
$object->id.(!empty($urlfrom) ?
'&urlfrom='.urlencode($urlfrom) :
''), $langs->trans(
"DeleteMailing"), $langs->trans(
"ConfirmDeleteMailing"),
"confirm_delete",
'',
'', 1);
995 if ($action !=
'edit' && $action !=
'edittxt' && $action !=
'edithtml') {
999 if ($action ==
'sendall') {
1002 if (empty($sendingmode)) {
1005 if (empty($sendingmode)) {
1006 $sendingmode =
'mail';
1016 $linktoadminemailbefore =
'<a href="'.DOL_URL_ROOT.
'/admin/mails_emailing.php">';
1017 $linktoadminemailend =
'</a>';
1018 setEventMessages($langs->trans(
"MailSendSetupIs", $listofmethods[$sendingmode]),
null,
'warnings');
1019 $messagetoshow = $langs->trans(
"MailSendSetupIs2",
'{s1}',
'{s2}',
'{s3}',
'{s4}');
1020 $messagetoshow = str_replace(
'{s1}', $linktoadminemailbefore, $messagetoshow);
1021 $messagetoshow = str_replace(
'{s2}', $linktoadminemailend, $messagetoshow);
1022 $messagetoshow = str_replace(
'{s3}', $langs->transnoentitiesnoconv(
"MAIN_MAIL_SENDMODE"), $messagetoshow);
1023 $messagetoshow = str_replace(
'{s4}', $listofmethods[
'smtps'], $messagetoshow);
1032 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL),
null,
'warnings');
1034 if (
getDolGlobalString(
'MAILING_LIMIT_WARNING_NOPHPMAIL') && $sendingmode !=
'mail') {
1035 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL),
null,
'warnings');
1040 setEventMessages(
'<textarea cols="60" rows="'.ROWS_1.
'" wrap="soft">php ./scripts/emailings/mailing-send.php '.
$object->id.
'</textarea>',
null,
'warnings');
1041 if ($conf->file->mailing_limit_sendbyweb !=
'-1') {
1047 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL),
null,
'warnings');
1049 if (
getDolGlobalString(
'MAILING_LIMIT_WARNING_NOPHPMAIL') && $sendingmode !=
'mail') {
1050 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL),
null,
'warnings');
1056 $text .= $langs->trans(
'WarningLimitSendByDay',
getDolGlobalInt(
'MAILING_LIMIT_SENDBYDAY'));
1057 $text .=
'<br><br>';
1059 $text .= $langs->trans(
'ConfirmSendingEmailing').
'<br>';
1060 $text .= $langs->trans(
'LimitSendingEmailing',
getDolGlobalString(
'MAILING_LIMIT_SENDBYWEB'));
1062 if (!isset($conf->global->MAILING_LIMIT_SENDBYCLI) ||
getDolGlobalInt(
'MAILING_LIMIT_SENDBYCLI') >= 0) {
1063 $text .=
'<br><br>';
1064 $text .=
'<u>'.$langs->trans(
"AdvancedAlternative").
':</u> '.$langs->trans(
"MailingNeedCommand");
1065 $text .=
'<br><textarea class="quatrevingtpercent" rows="'.ROWS_2.
'" wrap="soft" disabled>php ./scripts/emailings/mailing-send.php '.
$object->id.
' '.$user->login.
'</textarea>';
1068 $labelbuttonyes = $langs->transnoentities(
'Confirm');
1069 $labelbuttonno = $langs->transnoentities(
'Cancel');
1071 print $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, $langs->trans(
'SendMailing'), $text,
'sendallconfirmed',
'',
'', 1, 380, 660, 0, $labelbuttonyes, $labelbuttonno);
1075 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
1077 $morehtmlref =
'<div class="refidno">';
1079 $morehtmlref .= $form->editfieldkey(
"",
'title',
$object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string',
'', 0, 1);
1080 $morehtmlref .= $form->editfieldval(
"",
'title',
$object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string',
'',
null,
null,
'', 1);
1082 $morehtmlstatus =
'';
1084 if (
$object->status == $object::STATUS_SENTPARTIALY ||
$object->status == $object::STATUS_SENTCOMPLETELY) {
1085 $nbtry =
$object->countNbOfTargets(
'alreadysent');
1086 $nbko =
$object->countNbOfTargets(
'alreadysentko');
1088 $morehtmlstatus .=
' ('.$nbtry.
'/'.
$object->nbemail;
1090 $morehtmlstatus .=
' - '.$nbko.
' '.$langs->trans(
"Error");
1092 $morehtmlstatus .=
') ';
1096 $langs->load(
"projects");
1097 $morehtmlref .=
'<br>';
1098 if ($permissiontocreate) {
1099 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
1100 if ($action !=
'classify') {
1101 $morehtmlref .=
'<a class="editfielda" href="' . $_SERVER[
'PHP_SELF'] .
'?action=classify&token=' .
newToken() .
'&id=' .
$object->id .
'">' .
img_edit($langs->transnoentitiesnoconv(
'SetProject')) .
'</a> ';
1103 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id, -1, (
string)
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
1105 if (!empty(
$object->fk_project)) {
1107 $proj->fetch(
$object->fk_project);
1108 $morehtmlref .= $proj->getNomUrl(1);
1110 $morehtmlref .=
'<span class="opacitymedium"> - ' .
dol_escape_htmltag($proj->title) .
'</span>';
1115 $morehtmlref .=
'</div>';
1117 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlstatus);
1119 print
'<div class="fichecenter">';
1120 print
'<div class="fichehalfleft">';
1121 print
'<div class="underbanner clearboth"></div>';
1123 print
'<table class="border centpercent tableforfield">'.
"\n";
1126 print
'<tr><td class="titlefield">';
1127 print $form->editfieldkey(
"MailFrom",
'email_from',
$object->email_from, $object, (
int) ($user->hasRight(
'mailing',
'creer') &&
$object->status < $object::STATUS_SENTCOMPLETELY),
'string');
1129 print $form->editfieldval(
"MailFrom",
'email_from',
$object->email_from, $object, $user->hasRight(
'mailing',
'creer') &&
$object->status < $object::STATUS_SENTCOMPLETELY,
'string');
1130 if ($action !=
'editemail_from') {
1133 $langs->load(
"errors");
1134 print
img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $email));
1136 $langs->load(
"errors");
1137 print
img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $email));
1143 if (
$object->messtype !=
'sms') {
1145 print $form->editfieldkey(
"MailErrorsTo",
'email_errorsto',
$object->email_errorsto, $object, (
int) ($user->hasRight(
'mailing',
'creer') &&
$object->status < $object::STATUS_SENTCOMPLETELY),
'string');
1147 print $form->editfieldval(
"MailErrorsTo",
'email_errorsto',
$object->email_errorsto, $object, $user->hasRight(
'mailing',
'creer') &&
$object->status < $object::STATUS_SENTCOMPLETELY,
'string');
1150 foreach ($emailarray as $email => $name) {
1151 if ($name != $email) {
1152 if ($action !=
'editemail_errorsto') {
1154 $langs->load(
"errors");
1155 print
img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $email));
1157 $langs->load(
"errors");
1158 print
img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $email));
1162 if (
$object->email_errorsto) {
1171 if (
$object->messtype !=
'sms') {
1173 print $form->editfieldkey(
"MailReply",
'email_replyto',
$object->email_replyto, $object, (
int) ($user->hasRight(
'mailing',
'creer') &&
$object->status < $object::STATUS_SENTCOMPLETELY),
'string');
1175 print $form->editfieldval(
"MailReply",
'email_replyto',
$object->email_replyto, $object, $user->hasRight(
'mailing',
'creer') &&
$object->status < $object::STATUS_SENTCOMPLETELY,
'string');
1177 if ($action !=
'editemail_replyto') {
1179 $langs->load(
"errors");
1180 print
img_warning($langs->trans(
"ErrorBadEMail", $email));
1182 $langs->load(
"errors");
1183 print
img_warning($langs->trans(
"ErrorBadMXDomain", $email));
1192 print
'<div class="fichehalfright">';
1193 print
'<div class="underbanner clearboth"></div>';
1195 print
'<table class="border centpercent tableforfield">';
1199 print $langs->trans(
"TotalNbOfDistinctRecipients");
1202 if (is_numeric($nbemail)) {
1206 $htmltooltip .= $langs->trans(
'LimitSendingEmailing',
getDolGlobalString(
'MAILING_LIMIT_SENDBYWEB'));
1208 $htmltooltip .= $langs->trans(
'SendingFromWebInterfaceIsNotAllowed');
1211 if (empty($nbemail)) {
1212 $nbemail .=
' '.img_warning(
'').
' <span class="warning">'.$langs->trans(
"NoTargetYet").
'</span>';
1215 print $form->textwithpicto($nbemail, $htmltooltip, 1,
'info');
1223 print $langs->trans(
"MAIN_MAIL_SENDMODE");
1225 if (
$object->messtype !=
'sms') {
1231 $text = $listofmethods[
'mail'];
1236 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER_EMAILING',
getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER')).
')</span>';
1239 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER').
')</span>';
1243 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER').
')</span>';
1248 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1254 print
'<div class="clearboth"></div>';
1260 if ($action ==
'clone') {
1262 $formquestion = array(
1263 'text' => $langs->trans(
"ConfirmClone"),
1264 0 => array(
'type' =>
'checkbox',
'name' =>
'clone_content',
'label' => $langs->trans(
"CloneContent"),
'value' => 1),
1265 1 => array(
'type' =>
'checkbox',
'name' =>
'clone_receivers',
'label' => $langs->trans(
"CloneReceivers"),
'value' => 0)
1268 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneEMailing',
$object->ref),
'confirm_clone', $formquestion,
'yes', 2, 240);
1272 if (
GETPOST(
'cancel',
'alpha') || $confirm ==
'no' || $action ==
'' || in_array($action, array(
'settodraft',
'valid',
'delete',
'sendall',
'clone',
'test',
'editevenunsubscribe'))) {
1273 print
"\n\n<div class=\"tabsAction\">\n";
1275 if ((
$object->status == 1) && ($user->hasRight(
'mailing',
'valider') ||
$object->user_validation_id == $user->id)) {
1276 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=settodraft&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"SetToDraft").
'</a>';
1279 if ((
$object->status == 0 ||
$object->status == 1 ||
$object->status == 2) && $user->hasRight(
'mailing',
'creer')) {
1281 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"Edit").
'</a>';
1283 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edittxt&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"EditWithTextEditor").
'</a>';
1287 if (!empty($conf->use_javascript_ajax)) {
1288 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edithtml&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"EditHTMLSource").
'</a>';
1295 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'mailing',
'mailing_advance',
'send')) {
1296 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"TestMailing").
'</a>';
1298 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=test&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"TestMailing").
'</a>';
1303 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NoTargetYet")).
'">'.$langs->trans(
"Validate").
'</a>';
1304 } elseif (!$user->hasRight(
'mailing',
'valider')) {
1305 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"Validate").
'</a>';
1307 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=valid&id='.
$object->id.
'">'.$langs->trans(
"Validate").
'</a>';
1311 if ((
$object->status == 1 ||
$object->status == 2) &&
$object->nbemail > 0 && $user->hasRight(
'mailing',
'valider')) {
1313 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"SendingFromWebInterfaceIsNotAllowed")).
'">'.$langs->trans(
"SendMailing").
'</a>';
1314 } elseif (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'mailing',
'mailing_advance',
'send')) {
1315 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"SendMailing").
'</a>';
1317 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=sendall&id='.
$object->id.
'">'.$langs->trans(
"SendMailing").
'</a>';
1321 if ($user->hasRight(
'mailing',
'creer')) {
1322 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=clone&object=emailing&id='.
$object->id.
'">'.$langs->trans(
"ToClone").
'</a>';
1325 if ((
$object->status == 2 ||
$object->status == 3) && $user->hasRight(
'mailing',
'valider')) {
1326 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'mailing',
'mailing_advance',
'send')) {
1327 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"ResetMailing").
'</a>';
1329 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=reset&id='.
$object->id.
'">'.$langs->trans(
"ResetMailing").
'</a>';
1333 if ((
$object->status <= 1 && $user->hasRight(
'mailing',
'creer')) || $user->hasRight(
'mailing',
'supprimer')) {
1334 if (
$object->status > 0 && (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'mailing',
'mailing_advance',
'delete'))) {
1335 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"Delete").
'</a>';
1337 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&id='.
$object->id.(!empty($urlfrom) ?
'&urlfrom='.$urlfrom :
'').
'">'.$langs->trans(
"Delete").
'</a>';
1345 if ($action ==
'test') {
1346 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
1352 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1354 $formmail->fromname =
$object->email_from;
1355 $formmail->frommail =
$object->email_from;
1356 $formmail->withsubstit = 0;
1357 $formmail->withfrom = 0;
1358 $formmail->withto = $user->email ? $user->email : 1;
1359 $formmail->withtocc = 0;
1361 $formmail->withtopic = 0;
1362 $formmail->withtopicreadonly = 1;
1363 $formmail->withfile = 0;
1364 $formmail->withlayout =
'';
1365 $formmail->withaiprompt =
'';
1366 $formmail->withbody = 0;
1367 $formmail->withbodyreadonly = 1;
1368 $formmail->withcancel = 1;
1369 $formmail->withdeliveryreceipt = 0;
1371 $formmail->substit =
$object->substitutionarrayfortest;
1373 $formmail->param[
"action"] =
"send";
1374 $formmail->param[
"models"] =
'none';
1375 $formmail->param[
"mailid"] =
$object->id;
1376 $formmail->param[
"returnurl"] = $_SERVER[
'PHP_SELF'].
"?id=".
$object->id;
1378 print $formmail->get_form();
1388 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br><br><span class="small">';
1389 foreach (
$object->substitutionarray as $key => $val) {
1390 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1392 $htmltext .=
'</span></i>';
1394 $availablelink =
'<span class="opacitymedium hideonsmartphone">'.$form->textwithpicto($langs->trans(
"AvailableVariables"), $htmltext, 1,
'helpclickable',
'', 0, 3,
'emailsubstitionhelp').
'</span>';
1401 print
'<table class="bordernooddeven tableforfield centpercent">';
1404 if (
$object->messtype !=
'sms') {
1405 print
'<tr><td class="titlefield">'.$langs->trans(
"MailTopic").
'</td><td colspan="3">'.
$object->sujet.
'</td></tr>';
1409 if (
$object->messtype !=
'sms') {
1410 print
'<tr><td>'.$langs->trans(
"MailFile").
'</td><td colspan="3">';
1412 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
1413 if (count($listofpaths)) {
1414 foreach ($listofpaths as $key => $val) {
1415 print
img_mime($listofpaths[$key][
'name']).
' '.$listofpaths[$key][
'name'];
1419 print
'<span class="opacitymedium">'.$langs->trans(
"NoAttachedFiles").
'</span><br>';
1434 print
'<div class="previewemail" style="padding-top: 10px; background: '.($object->bgcolor ? (preg_match(
'/^#/',
$object->bgcolor) ?
'' :
'#').
$object->bgcolor :
'white').
'">';
1435 if (empty(
$object->bgcolor) || strtolower(
$object->bgcolor) ==
'ffffff') {
1438 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1439 $doleditor =
new DolEditor(
'bodyemail',
$object->body,
'', 600,
'dolibarr_mailings',
'',
false, $acceptlocallinktomedia,
getDolGlobalInt(
'FCKEDITOR_ENABLE_MAILING'), 20,
'100%', $readonly);
1440 $doleditor->Create();
1454 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
1456 $morehtmlref =
'<div class="refidno">';
1458 $morehtmlref .= $form->editfieldkey(
"",
'title',
$object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string',
'', 0, 1);
1459 $morehtmlref .= $form->editfieldval(
"",
'title',
$object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string',
'',
null,
null,
'', 1);
1461 $morehtmlstatus =
'';
1464 $nbtry =
$object->countNbOfTargets(
'alreadysent');
1465 $nbko =
$object->countNbOfTargets(
'alreadysentko');
1467 $morehtmlstatus .=
' ('.$nbtry.
'/'.
$object->nbemail;
1469 $morehtmlstatus .=
' - '.$nbko.
' '.$langs->trans(
"Error");
1471 $morehtmlstatus .=
') ';
1476 $langs->load(
"projects");
1477 $morehtmlref .=
'<br>';
1478 if ($permissiontocreate) {
1479 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
1480 $morehtmlref .=
'<a class="editfielda" href="' . $_SERVER[
'PHP_SELF'] .
'?action=classify&token=' .
newToken() .
'&id=' .
$object->id .
'">' .
img_edit($langs->transnoentitiesnoconv(
'SetProject')) .
'</a> ';
1481 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id, -1, (
string)
$object->fk_project,
'none', 0, 0, 0, 1,
'',
'maxwidth300');
1483 if (!empty(
$object->fk_project)) {
1485 $proj->fetch(
$object->fk_project);
1486 $morehtmlref .= $proj->getNomUrl(1);
1488 $morehtmlref .=
'<span class="opacitymedium"> - ' .
dol_escape_htmltag($proj->title) .
'</span>';
1493 $morehtmlref .=
'</div>';
1495 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlstatus);
1497 print
'<div class="fichecenter">';
1498 print
'<div class="fichehalfleft">';
1499 print
'<div class="underbanner clearboth"></div>';
1501 print
'<table class="border centpercent tableforfield">';
1511 print
'<tr><td class="titlefield">';
1512 print $langs->trans(
"MailFrom");
1513 print
'</td><td>'.dol_print_email(
$object->email_from, 0, 0, 0, 0, 1).
'</td></tr>';
1515 if (
$object->messtype !=
'sms') {
1516 print
'<tr><td>'.$langs->trans(
"MailErrorsTo").
'</td><td>'.
dol_print_email(
$object->email_errorsto, 0, 0, 0, 0, 1).
'</td></tr>';
1517 print
'<tr><td>'.$langs->trans(
"MailReply").
'</td><td>'.
dol_print_email(
$object->email_replyto, 0, 0, 0, 0, 1).
'</td></tr>';
1524 print
'<div class="fichehalfright">';
1525 print
'<div class="underbanner clearboth"></div>';
1527 print
'<table class="border centpercent tableforfield">';
1531 print $langs->trans(
"TotalNbOfDistinctRecipients");
1534 if (is_numeric($nbemail)) {
1539 $htmltooltip .= $langs->trans(
'LimitSendingEmailing',
getDolGlobalString(
'MAILING_LIMIT_SENDBYWEB'));
1541 $htmltooltip .= $langs->trans(
'SendingFromWebInterfaceIsNotAllowed');
1544 if (empty($nbemail)) {
1545 $nbemail .=
' '.img_warning(
'').
' <span class="warning">'.$langs->trans(
"NoTargetYet").
'</span>';
1548 print $form->textwithpicto($nbemail, $htmltooltip, 1,
'warning');
1556 print $langs->trans(
"MAIN_MAIL_SENDMODE");
1558 if (
$object->messtype !=
'sms') {
1564 $text = $listofmethods[
'mail'];
1569 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER_EMAILING',
getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER')).
')</span>';
1572 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER').
')</span>';
1576 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER').
')</span>';
1582 $parameters = array();
1583 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1584 print $hookmanager->resPrint;
1585 if (empty($reshook)) {
1586 print
$object->showOptionals($extrafields,
'edit', $parameters);
1593 print
'<div class="clearboth"></div>';
1600 print
'<form name="edit_mailing" action="card.php" method="post" enctype="multipart/form-data">'.
"\n";
1601 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1602 print
'<input type="hidden" name="action" value="update">';
1603 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1604 print
'<input type="hidden" name="page_y" value="">';
1606 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br><br><span class="small">';
1607 foreach (
$object->substitutionarray as $key => $val) {
1608 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1610 $htmltext .=
'</span></i>';
1612 $availablelink =
'<span class="opacitymedium small">'.$form->textwithpicto($langs->trans(
"AvailableVariables"), $htmltext, 1,
'helpclickable',
'', 0, 2,
'emailsubstitionhelp').
'</span>';
1619 print
'<table class="bordernooddeven centpercent">';
1622 if (
$object->messtype !=
'sms') {
1623 print
'<tr><td class="fieldrequired titlefield">';
1624 print $form->textwithpicto($langs->trans(
"MailTopic"), $htmltext, 1,
'help',
'', 0, 2,
'emailsubstitionhelp');
1625 print
'</td><td colspan="3"><input class="flat quatrevingtpercent" type="text" id="subject" name="subject" value="'.$object->sujet.
'"></td></tr>';
1632 if (
$object->messtype !=
'sms') {
1633 $addfileaction =
'addfile';
1634 print
'<tr><td>'.$langs->trans(
"MailFile").
'</td>';
1635 print
'<td colspan="3">';
1637 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
1641 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
1642 $out .=
'<script type="text/javascript">';
1643 $out .=
'jQuery(document).ready(function () {';
1644 $out .=
' jQuery(".removedfile").click(function() {';
1645 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
1648 $out .=
'</script>'.
"\n";
1649 if (count($listofpaths)) {
1650 foreach ($listofpaths as $key => $val) {
1651 $out .=
'<div id="attachfile_'.$key.
'">';
1652 $out .=
img_mime($listofpaths[$key][
'name']).
' '.$listofpaths[$key][
'name'];
1653 $out .=
' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans(
"Search"),
'delete',
'', 0, 1).
'" value="'.($key + 1).
'" class="removedfile" id="removedfile_'.$key.
'" name="removedfile_'.$key.
'" />';
1654 $out .=
'<br></div>';
1662 $maxmin = $maxfilesizearray[
'maxmin'];
1664 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
1666 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
1668 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
1673 print
'<tr><td>'.$langs->trans(
"BackgroundColorByDefault").
'</td><td colspan="3">';
1674 print $htmlother->selectColor(
$object->bgcolor,
'bgcolor',
'', 0);
1682 $out .=
'<td class="tdtop">';
1683 $out .= $form->textwithpicto($langs->trans(
'MailText'), $htmltext, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
1685 $out .=
'<td class="tdtop">';
1688 $showlinktolayout =
getDolGlobalInt(
'MAIN_EMAIL_USE_LAYOUT') ?
'emailing' :
'';
1689 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
1690 $showlinktoai =
isModEnabled(
'ai') ?
'textgenerationemail' :
'';
1691 $showlinktoailabel = $langs->trans(
"AIEnhancements");
1692 $formatforouput =
'';
1693 $htmlname =
'bodyemail';
1698 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
1709 print
'<div style="padding-top: 10px">';
1711 if ($action ==
'edit') {
1713 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1715 if (!preg_match(
'/^<div style="background-color: #'.
$object->bgcolor.
'">/',
$object->body)) {
1716 $object->body =
'<div style="background-color: #'.$object->bgcolor.
'; margin-bottom:-20px; margin-left:-10px; margin-right:-10px; margin-top:-10px; padding: 10px;">'.
$object->body.
'</div>';
1719 $doleditor =
new DolEditor(
'bodyemail',
$object->body,
'', 600,
'dolibarr_mailings',
'',
true, $acceptlocallinktomedia,
getDolGlobalInt(
'FCKEDITOR_ENABLE_MAILING'), 20,
'100%');
1720 $doleditor->Create();
1722 if ($action ==
'edittxt') {
1724 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1725 $doleditor =
new DolEditor(
'bodyemail',
$object->body,
'', 600,
'dolibarr_mailings',
'',
true, $acceptlocallinktomedia, 0, 20,
'100%');
1726 $doleditor->Create();
1728 if ($action ==
'edithtml') {
1730 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1731 $doleditor =
new DolEditor(
'bodyemail',
$object->body,
'', 600,
'dolibarr_mailings',
'',
true, $acceptlocallinktomedia,
'ace', 20,
'100%');
1732 $doleditor->Create(0,
'',
false,
'HTML Source',
'php');
1739 print
'<div class="center">';
1740 print
'<input type="submit" class="button buttonforacesave button-save" value="'.$langs->trans(
"Save").
'" name="save">';
1741 print
' ';
1742 print
'<input type="submit" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'" name="cancel">';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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 projects.
Class to manage third parties objects (customers, suppliers, prospects...)
emailing_prepare_head(Mailing $object)
Prepare array with list of tabs.
dol_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=0, $keyforsourcefile='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null, $forceFullTextIndexation='', $mode=0)
Get and save an upload file (for example after submitting a new file in a mail form).
dol_init_file_process($pathtoscan='', $trackid='')
Scan a directory and init $_SESSION to manage uploaded files with list of all found files.
dol_remove_file_process($filenb, $donotupdatesession=0, $donotdeletefile=1, $trackid='')
Remove an uploaded file (for example after submitting a new file a mail form).
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
acceptLocalLinktoMedia()
Check the syntax of some PHP code.
isValidMailDomain($mail)
Return true if email has a domain name that can be resolved to MX type.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
getMaxFileSizeArray()
Return the max allowed for file upload.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.