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) && empty($conf->global->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 (empty($user->rights->mailing->lire) || (empty($conf->global->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');
104$parameters = array();
105$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
110if (empty($reshook)) {
113 $backurlforlist = DOL_URL_ROOT.
'/comm/mailing/list.php';
115 if (empty($backtopage) || ($cancel && empty($id))) {
116 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
117 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
118 $backtopage = $backurlforlist;
120 $backtopage = DOL_URL_ROOT.
'/comm/mailing/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
127 if (!empty($backtopageforcancel)) {
128 header(
"Location: ".$backtopageforcancel);
130 } elseif (!empty($backtopage)) {
131 header(
"Location: ".$backtopage);
138 if ($action ==
'confirm_clone' && $confirm ==
'yes') {
139 if (!
GETPOST(
"clone_content",
'alpha') && !
GETPOST(
"clone_receivers",
'alpha')) {
142 $result = $object->createFromClone($user, $object->id,
GETPOST(
"clone_content",
'alpha'),
GETPOST(
"clone_receivers",
'alpha'));
144 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
154 if ($action ==
'sendallconfirmed' && $confirm ==
'yes') {
155 if (empty($conf->global->MAILING_LIMIT_SENDBYWEB)) {
158 setEventMessages(
'<textarea cols="70" rows="'.ROWS_2.
'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.
'</textarea>',
null,
'warnings');
161 } elseif ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
165 if ($object->statut == 0) {
171 $subject = $object->sujet;
172 $message = $object->body;
173 $from = $object->email_from;
174 $replyto = $object->email_replyto;
175 $errorsto = $object->email_errorsto;
178 if (preg_match(
'/[\s\t]*<html>/i', $message)) {
185 $nbok = 0; $nbko = 0;
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); $other1 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
228 $tmpfield = explode(
'=', $other[1], 2); $other2 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
229 $tmpfield = explode(
'=', $other[2], 2); $other3 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
230 $tmpfield = explode(
'=', $other[3], 2); $other4 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
231 $tmpfield = explode(
'=', $other[4], 2); $other5 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
233 $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $user->signature :
'');
235 $parameters = array(
'mode'=>
'emailing');
239 $substitutionarray[
'__ID__'] = $obj->source_id;
240 if ($obj->source_type ==
"thirdparty") {
241 $result = $thirdpartystatic->fetch($obj->source_id);
244 $substitutionarray[
'__THIRDPARTY_CUSTOMER_CODE__'] = $thirdpartystatic->code_client;
246 $substitutionarray[
'__THIRDPARTY_CUSTOMER_CODE__'] =
'';
249 $substitutionarray[
'__EMAIL__'] = $obj->email;
250 $substitutionarray[
'__LASTNAME__'] = $obj->lastname;
251 $substitutionarray[
'__FIRSTNAME__'] = $obj->firstname;
252 $substitutionarray[
'__MAILTOEMAIL__'] =
'<a href="mailto:'.$obj->email.
'">'.$obj->email.
'</a>';
253 $substitutionarray[
'__OTHER1__'] = $other1;
254 $substitutionarray[
'__OTHER2__'] = $other2;
255 $substitutionarray[
'__OTHER3__'] = $other3;
256 $substitutionarray[
'__OTHER4__'] = $other4;
257 $substitutionarray[
'__OTHER5__'] = $other5;
258 $substitutionarray[
'__USER_SIGNATURE__'] = $signature;
259 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $signature;
260 $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"/>';
261 $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>';
262 $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);
264 $onlinepaymentenabled = 0;
265 if (isModEnabled(
'paypal')) {
266 $onlinepaymentenabled++;
268 if (isModEnabled(
'paybox')) {
269 $onlinepaymentenabled++;
271 if (isModEnabled(
'stripe')) {
272 $onlinepaymentenabled++;
274 if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
275 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
276 $substitutionarray[
'__ONLINEPAYMENTLINK_MEMBER__'] = getHtmlOnlinePaymentLink(
'member', $obj->source_id);
277 $substitutionarray[
'__ONLINEPAYMENTLINK_DONATION__'] = getHtmlOnlinePaymentLink(
'donation', $obj->source_id);
278 $substitutionarray[
'__ONLINEPAYMENTLINK_ORDER__'] = getHtmlOnlinePaymentLink(
'order', $obj->source_id);
279 $substitutionarray[
'__ONLINEPAYMENTLINK_INVOICE__'] = getHtmlOnlinePaymentLink(
'invoice', $obj->source_id);
280 $substitutionarray[
'__ONLINEPAYMENTLINK_CONTRACTLINE__'] = getHtmlOnlinePaymentLink(
'contractline', $obj->source_id);
282 $substitutionarray[
'__SECUREKEYPAYMENT__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
283 if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
284 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
285 $substitutionarray[
'__SECUREKEYPAYMENT_DONATION__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
286 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
287 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
288 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
290 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'member'.$obj->source_id, 2);
291 $substitutionarray[
'__SECUREKEYPAYMENT_DONATION__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'donation'.$obj->source_id, 2);
292 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'order'.$obj->source_id, 2);
293 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'invoice'.$obj->source_id, 2);
294 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'contractline'.$obj->source_id, 2);
297 if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
298 $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>';
301 if (isModEnabled(
'paypal') && !empty($conf->global->PAYPAL_SECURITY_TOKEN)) {
302 $substitutionarray[
'__SECUREKEYPAYPAL__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
304 if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
305 $substitutionarray[
'__SECUREKEYPAYPAL_MEMBER__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
307 $substitutionarray[
'__SECUREKEYPAYPAL_MEMBER__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.
'membersubscription'.$obj->source_id, 2);
310 if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
311 $substitutionarray[
'__SECUREKEYPAYPAL_ORDER__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
313 $substitutionarray[
'__SECUREKEYPAYPAL_ORDER__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.
'order'.$obj->source_id, 2);
316 if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
317 $substitutionarray[
'__SECUREKEYPAYPAL_INVOICE__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
319 $substitutionarray[
'__SECUREKEYPAYPAL_INVOICE__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.
'invoice'.$obj->source_id, 2);
322 if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
323 $substitutionarray[
'__SECUREKEYPAYPAL_CONTRACTLINE__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
325 $substitutionarray[
'__SECUREKEYPAYPAL_CONTRACTLINE__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.
'contractline'.$obj->source_id, 2);
335 if (preg_match(
'/__UNSUBSCRIBE_(_|URL_)/', $message)) {
336 $moreinheader =
"List-Unsubscribe: <__UNSUBSCRIBE_URL__>\n";
345 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
346 if (count($listofpaths)) {
347 foreach ($listofpaths as $key => $val) {
348 $arr_file[] = $listofpaths[$key][
'fullname'];
350 $arr_name[] = $listofpaths[$key][
'name'];
355 $trackid =
'emailing-'.$obj->fk_mailing.
'-'.$obj->rowid;
356 $upload_dir_tmp = $upload_dir;
357 $mail =
new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name,
'',
'', 0, $msgishtml, $errorsto, $arr_css, $trackid, $moreinheader,
'emailing',
'', $upload_dir_tmp);
370 $res = $mail->sendfile();
377 dol_syslog(
"comm/mailing/card.php: ok for #".$iforemailloop.($mail->error ?
' - '.$mail->error :
''), LOG_DEBUG);
379 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
380 $sql .=
" SET statut=1, date_envoi = '".$db->idate($now).
"' WHERE rowid=".((int) $obj->rowid);
381 $resql2 = $db->query($sql);
386 if (strpos($message,
'__CHECK_READ__') !==
false) {
388 $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).
")";
389 dol_syslog(
"card.php: set prospect thirdparty status", LOG_DEBUG);
390 $resql2 = $db->query($sql);
396 $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)";
397 dol_syslog(
"card.php: set prospect contact status", LOG_DEBUG);
399 $resql2 = $db->query($sql);
406 if (!empty($conf->global->MAILING_DELAY)) {
407 dol_syslog(
"Wait a delay of MAILING_DELAY=".((
float) $conf->global->MAILING_DELAY));
408 usleep((
float) $conf->global->MAILING_DELAY * 1000000);
416 dol_syslog(
"comm/mailing/card.php: error for #".$iforemailloop.($mail->error ?
' - '.$mail->error :
''), LOG_WARNING);
418 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
419 $sql .=
" SET statut=-1, error_text='".$db->escape($mail->error).
"', date_envoi='".$db->idate($now).
"' WHERE rowid=".((int) $obj->rowid);
420 $resql2 = $db->query($sql);
429 setEventMessages($langs->transnoentitiesnoconv(
"NoMoreRecipientToSendTo"),
null,
'mesgs');
436 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
438 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
443 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
446 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
450 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing SET statut=".((int) $statut).
" WHERE rowid = ".((int) $object->id);
451 dol_syslog(
"comm/mailing/card.php: update global status", LOG_DEBUG);
452 $resql2 = $db->query($sql);
466 if ($action ==
'send' && ! $cancel) {
469 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
471 $object->sendto =
GETPOST(
"sendto",
'alphawithlgt');
472 if (!$object->sendto) {
473 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailTo")),
null,
'errors');
480 if (preg_match(
'/[\s\t]*<html>/i', $object->body)) {
484 $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $user->signature :
'');
486 $parameters = array(
'mode'=>
'emailing');
490 $substitutionarray[
'__EMAIL__'] = $object->sendto;
491 $substitutionarray[
'__MAILTOEMAIL__'] =
'<a href="mailto:'.$object->sendto.
'">'.$object->sendto.
'</a>';
492 $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"/>';
493 $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>';
494 $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';
508 if (!empty($object->bgcolor)) {
509 $arr_css[
'bgcolor'] = (preg_match(
'/^#/', $object->bgcolor) ?
'' :
'#').$object->bgcolor;
511 if (!empty($object->bgimage)) {
512 $arr_css[
'bgimage'] = $object->bgimage;
516 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
517 if (count($listofpaths)) {
518 foreach ($listofpaths as $key => $val) {
519 $arr_file[] = $listofpaths[$key][
'fullname'];
521 $arr_name[] = $listofpaths[$key][
'name'];
525 $trackid =
'emailing-test';
526 $upload_dir_tmp = $upload_dir;
527 $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);
529 $result = $mailfile->sendfile();
531 setEventMessages($langs->trans(
"MailSuccessfulySent", $mailfile->getValidAddress($object->email_from, 2), $mailfile->getValidAddress($object->sendto, 2)),
null,
'mesgs');
534 setEventMessages($langs->trans(
"ResultKo").
'<br>'.$mailfile->error.
' '.$result,
null,
'errors');
541 if ($action ==
'add') {
544 $object->email_from = (string)
GETPOST(
"from",
'alphawithlgt');
545 $object->email_replyto = (string)
GETPOST(
"replyto",
'alphawithlgt');
546 $object->email_errorsto = (string)
GETPOST(
"errorsto",
'alphawithlgt');
547 $object->title = (string)
GETPOST(
"title");
548 $object->sujet = (string)
GETPOST(
"sujet");
549 $object->body = (string)
GETPOST(
"bodyemail",
'restricthtml');
550 $object->bgcolor = (string)
GETPOST(
"bgcolor");
551 $object->bgimage = (string)
GETPOST(
"bgimage");
553 if (!$object->title) {
554 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTitle"));
556 if (!$object->sujet) {
557 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTopic"));
559 if (!$object->body) {
560 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailMessage"));
563 if (!count($mesgs)) {
564 if ($object->create($user) >= 0) {
565 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
568 $mesgs[] = $object->error;
569 $mesgs = array_merge($mesgs, $object->errors);
577 if ($action ==
'settitle' || $action ==
'setemail_from' || $action ==
'setreplyto' || $action ==
'setemail_errorsto' || $action ==
'setevenunsubscribe') {
578 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
580 if ($action ==
'settitle') {
581 $object->title = trim(
GETPOST(
'title',
'alpha'));
582 } elseif ($action ==
'setemail_from') {
583 $object->email_from = trim(
GETPOST(
'email_from',
'alphawithlgt'));
584 } elseif ($action ==
'setemail_replyto') {
585 $object->email_replyto = trim(
GETPOST(
'email_replyto',
'alphawithlgt'));
586 } elseif ($action ==
'setemail_errorsto') {
587 $object->email_errorsto = trim(
GETPOST(
'email_errorsto',
'alphawithlgt'));
588 } elseif ($action ==
'settitle' && empty($object->title)) {
589 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTitle"));
590 } elseif ($action ==
'setfrom' && empty($object->email_from)) {
591 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailFrom"));
592 } elseif ($action ==
'setevenunsubscribe') {
593 $object->evenunsubscribe = (
GETPOST(
'evenunsubscribe') ? 1 : 0);
597 $result = $object->update($user);
599 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
602 $mesg = $object->error;
613 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
615 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
625 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
627 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
635 if ($action ==
'update' && !
GETPOST(
"removedfile") && !$cancel) {
636 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
642 $object->sujet = (string)
GETPOST(
"sujet");
643 $object->body = (string)
GETPOST(
"bodyemail",
'restricthtml');
644 $object->bgcolor = (string)
GETPOST(
"bgcolor");
645 $object->bgimage = (string)
GETPOST(
"bgimage");
647 if (!$object->sujet) {
648 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTopic"));
650 if (!$object->body) {
651 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailMessage"));
654 if (!count($mesgs)) {
655 if ($object->update($user) >= 0) {
656 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
659 $mesgs[] = $object->error;
660 $mesgs = array_merge($mesgs, $object->errors);
671 if ($action ==
'confirm_valid' && $confirm ==
'yes') {
672 if ($object->id > 0) {
673 $object->valid($user);
674 setEventMessages($langs->trans(
"MailingSuccessfullyValidated"),
null,
'mesgs');
675 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
683 if ($action ==
'confirm_settodraft' && $confirm ==
'yes') {
684 if ($object->id > 0) {
685 $result = $object->setStatut(0);
688 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
699 if ($action ==
'confirm_reset' && $confirm ==
'yes') {
700 if ($object->id > 0) {
703 $result = $object->valid($user);
705 $result = $object->reset_targets_status($user);
710 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
722 if ($action ==
'confirm_delete' && $confirm ==
'yes') {
723 if ($object->delete($user)) {
724 $url = (!empty($urlfrom) ? $urlfrom :
'list.php');
725 header(
"Location: ".$url);
740$form =
new Form($db);
743$help_url =
'EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing';
746 $langs->trans(
"Mailing"),
752 '/includes/ace/src/ace.js',
753 '/includes/ace/src/ext-statusbar.js',
754 '/includes/ace/src/ext-language_tools.js',
761if ($action ==
'create') {
763 print
'<form name="new_mailing" action="'.$_SERVER[
'PHP_SELF'].
'" method="POST">'.
"\n";
764 print
'<input type="hidden" name="token" value="'.newToken().
'">';
765 print
'<input type="hidden" name="action" value="add">';
767 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br><br><span class="small">';
768 foreach ($object->substitutionarray as $key => $val) {
769 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
771 $htmltext .=
'</span></i>';
774 $availablelink = $form->textwithpicto(
'<span class="opacitymedium">'.$langs->trans(
"AvailableVariables").
'</span>', $htmltext, 1,
'help',
'', 0, 2,
'availvar');
779 print
load_fiche_titre($langs->trans(
"NewMailing"), $availablelink,
'object_email');
783 print
'<table class="border centpercent">';
785 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>';
787 print
'<tr><td class="fieldrequired">'.$langs->trans(
"MailFrom").
'</td><td><input class="flat minwidth200" name="from" value="'.
getDolGlobalString(
'MAILING_EMAIL_FROM').
'"></td></tr>';
789 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>';
792 $parameters = array();
793 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
794 print $hookmanager->resPrint;
795 if (empty($reshook)) {
796 print $object->showOptionals($extrafields,
'create');
802 print
'<table class="border centpercent">';
803 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>';
804 print
'<tr><td>'.$langs->trans(
"BackgroundColorByDefault").
'</td><td colspan="3">';
805 print $htmlother->selectColor(
GETPOST(
'bgcolor'),
'bgcolor',
'', 0);
810 print
'<div style="padding-top: 10px">';
812 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
813 $doleditor =
new DolEditor(
'bodyemail',
GETPOST(
'bodyemail',
'restricthtmlallowunvalid'),
'', 600,
'dolibarr_mailings',
'',
true,
true,
getDolGlobalInt(
'FCKEDITOR_ENABLE_MAILING'), 20,
'90%');
814 $doleditor->Create();
819 print $form->buttonsSaveCancel(
"CreateMailing",
'Cancel');
823 if ($object->id > 0) {
824 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
828 if ($action ==
'settodraft') {
830 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"SetToDraft"), $langs->trans(
"ConfirmUnvalidateEmailing"),
"confirm_settodraft",
'',
'', 1);
831 } elseif ($action ==
'valid') {
833 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"ValidMailing"), $langs->trans(
"ConfirmValidMailing"),
"confirm_valid",
'',
'', 1);
834 } elseif ($action ==
'reset') {
836 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"ResetMailing"), $langs->trans(
"ConfirmResetMailing", $object->ref),
"confirm_reset",
'',
'', 2);
837 } elseif ($action ==
'delete') {
839 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.(!empty($urlfrom) ?
'&urlfrom='.urlencode($urlfrom) :
''), $langs->trans(
"DeleteAMailing"), $langs->trans(
"ConfirmDeleteMailing"),
"confirm_delete",
'',
'', 1);
842 if ($action !=
'edit' && $action !=
'edithtml') {
848 if ($action ==
'sendall') {
850 $sendingmode = $conf->global->EMAILING_MAIL_SENDMODE;
851 if (empty($sendingmode)) {
852 $sendingmode = $conf->global->MAIN_MAIL_SENDMODE;
854 if (empty($sendingmode)) {
855 $sendingmode =
'mail';
862 if (!empty($conf->global->MAILING_NO_USING_PHPMAIL) && $sendingmode ==
'mail') {
865 $linktoadminemailbefore =
'<a href="'.DOL_URL_ROOT.
'/admin/mails_emailing.php">';
866 $linktoadminemailend =
'</a>';
867 setEventMessages($langs->trans(
"MailSendSetupIs", $listofmethods[$sendingmode]),
null,
'warnings');
868 $messagetoshow = $langs->trans(
"MailSendSetupIs2",
'{s1}',
'{s2}',
'{s3}',
'{s4}');
869 $messagetoshow = str_replace(
'{s1}', $linktoadminemailbefore, $messagetoshow);
870 $messagetoshow = str_replace(
'{s2}', $linktoadminemailend, $messagetoshow);
871 $messagetoshow = str_replace(
'{s3}', $langs->transnoentitiesnoconv(
"MAIN_MAIL_SENDMODE"), $messagetoshow);
872 $messagetoshow = str_replace(
'{s4}', $listofmethods[
'smtps'], $messagetoshow);
875 if (!empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) {
876 setEventMessages($langs->trans(
"MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS),
null,
'warnings');
878 $_GET[
"action"] =
'';
879 } elseif ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
880 if (!empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode ==
'mail') {
881 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL),
null,
'warnings');
883 if (!empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode !=
'mail') {
884 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL),
null,
'warnings');
889 setEventMessages(
'<textarea cols="60" rows="'.ROWS_1.
'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.
'</textarea>',
null,
'warnings');
890 if ($conf->file->mailing_limit_sendbyweb !=
'-1') {
893 $_GET[
"action"] =
'';
895 if (!empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode ==
'mail') {
896 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL),
null,
'warnings');
898 if (!empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode !=
'mail') {
899 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL),
null,
'warnings');
905 $text .= $langs->trans(
'WarningLimitSendByDay',
getDolGlobalInt(
'MAILING_LIMIT_SENDBYDAY'));
908 $text .= $langs->trans(
'ConfirmSendingEmailing').
'<br>';
909 $text .= $langs->trans(
'LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
911 if (!isset($conf->global->MAILING_LIMIT_SENDBYCLI) ||
getDolGlobalInt(
'MAILING_LIMIT_SENDBYCLI') >= 0) {
913 $text .= $langs->trans(
"MailingNeedCommand");
914 $text .=
'<br><textarea class="quatrevingtpercent" rows="'.ROWS_2.
'" wrap="soft" disabled>php ./scripts/emailings/mailing-send.php '.$object->id.
' '.$user->login.
'</textarea>';
917 print $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
'SendMailing'), $text,
'sendallconfirmed',
'',
'', 1, 380, 660, 0, $langs->trans(
"Confirm"), $langs->trans(
"Cancel"));
921 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
923 $morehtmlref =
'<div class="refidno">';
925 $morehtmlref .= $form->editfieldkey(
"",
'title', $object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string',
'', 0, 1);
926 $morehtmlref .= $form->editfieldval(
"",
'title', $object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string',
'',
null,
null,
'', 1);
927 $morehtmlref .=
'</div>';
931 if ($object->statut == 2 || $object->statut == 3) {
932 $nbtry = $object->countNbOfTargets(
'alreadysent');
933 $nbko = $object->countNbOfTargets(
'alreadysentko');
935 $morehtmlright .=
' ('.$nbtry.
'/'.$object->nbemail;
937 $morehtmlright .=
' - '.$nbko.
' '.$langs->trans(
"Error");
939 $morehtmlright .=
') ';
942 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlright);
944 print
'<div class="fichecenter">';
945 print
'<div class="fichehalfleft">';
946 print
'<div class="underbanner clearboth"></div>';
947 print
'<table class="border centpercent tableforfield">'.
"\n";
950 print
'<tr><td class="titlefield">';
951 print $form->editfieldkey(
"MailFrom",
'email_from', $object->email_from, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
953 print $form->editfieldval(
"MailFrom",
'email_from', $object->email_from, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
956 $langs->load(
"errors");
957 print
img_warning($langs->trans(
"ErrorBadEMail", $email));
959 $langs->load(
"errors");
960 print
img_warning($langs->trans(
"ErrorBadMXDomain", $email));
967 print $form->editfieldkey(
"MailErrorsTo",
'email_errorsto', $object->email_errorsto, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
969 print $form->editfieldval(
"MailErrorsTo",
'email_errorsto', $object->email_errorsto, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
972 $langs->load(
"errors");
973 print
img_warning($langs->trans(
"ErrorBadEMail", $email));
975 $langs->load(
"errors");
976 print
img_warning($langs->trans(
"ErrorBadMXDomain", $email));
983 print
'<div class="fichehalfright">';
984 print
'<div class="underbanner clearboth"></div>';
986 print
'<table class="border centpercent tableforfield">';
989 print
'<tr><td class="titlefield">';
990 print $langs->trans(
"TotalNbOfDistinctRecipients");
992 $nbemail = ($object->nbemail ? $object->nbemail : 0);
993 if (is_numeric($nbemail)) {
995 if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail))) {
996 if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) {
997 $text .= $langs->trans(
'LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
999 $text .= $langs->trans(
'SendingFromWebInterfaceIsNotAllowed');
1002 if (empty($nbemail)) {
1003 $nbemail .=
' '.img_warning(
'').
' <span class="warning">'.$langs->trans(
"NoTargetYet").
'</span>';
1006 print $form->textwithpicto($nbemail, $text, 1,
'warning');
1014 print $langs->trans(
"MAIN_MAIL_SENDMODE");
1021 $text = $listofmethods[
'mail'];
1026 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER_EMAILING').
')</span>';
1029 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER').
')</span>';
1034 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1040 print
'<div class="clearboth"></div>';
1046 if ($action ==
'clone') {
1048 $formquestion = array(
1049 'text' => $langs->trans(
"ConfirmClone"),
1050 array(
'type' =>
'checkbox',
'name' =>
'clone_content',
'label' => $langs->trans(
"CloneContent"),
'value' => 1),
1051 array(
'type' =>
'checkbox',
'name' =>
'clone_receivers',
'label' => $langs->trans(
"CloneReceivers"),
'value' => 0)
1054 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneEMailing', $object->ref),
'confirm_clone', $formquestion,
'yes', 2, 240);
1058 if (
GETPOST(
'cancel',
'alpha') || $confirm ==
'no' || $action ==
'' || in_array($action, array(
'settodraft',
'valid',
'delete',
'sendall',
'clone',
'test',
'editevenunsubscribe'))) {
1059 print
"\n\n<div class=\"tabsAction\">\n";
1061 if (($object->statut == 1) && ($user->hasRight(
'mailing',
'valider') || $object->user_validation == $user->id)) {
1062 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=settodraft&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
"SetToDraft").
'</a>';
1065 if (($object->statut == 0 || $object->statut == 1 || $object->statut == 2) && $user->hasRight(
'mailing',
'creer')) {
1066 if (isModEnabled(
'fckeditor') && !empty($conf->global->FCKEDITOR_ENABLE_MAILING)) {
1067 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
"EditWithEditor").
'</a>';
1069 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
"EditWithTextEditor").
'</a>';
1072 if (!empty($conf->use_javascript_ajax)) {
1073 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edithtml&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
"EditHTMLSource").
'</a>';
1079 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
1080 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"TestMailing").
'</a>';
1082 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=test&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
"TestMailing").
'</a>';
1085 if ($object->statut == 0) {
1086 if ($object->nbemail <= 0) {
1087 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NoTargetYet")).
'">'.$langs->trans(
"ValidMailing").
'</a>';
1088 } elseif (empty($user->rights->mailing->valider)) {
1089 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"ValidMailing").
'</a>';
1091 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=valid&id='.$object->id.
'">'.$langs->trans(
"ValidMailing").
'</a>';
1095 if (($object->statut == 1 || $object->statut == 2) && $object->nbemail > 0 && $user->hasRight(
'mailing',
'valider')) {
1096 if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
1097 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"SendingFromWebInterfaceIsNotAllowed")).
'">'.$langs->trans(
"SendMailing").
'</a>';
1098 } elseif (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
1099 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"SendMailing").
'</a>';
1101 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=sendall&id='.$object->id.
'">'.$langs->trans(
"SendMailing").
'</a>';
1105 if ($user->hasRight(
'mailing',
'creer')) {
1106 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=clone&object=emailing&id='.$object->id.
'">'.$langs->trans(
"ToClone").
'</a>';
1109 if (($object->statut == 2 || $object->statut == 3) && $user->hasRight(
'mailing',
'valider')) {
1110 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
1111 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"ResetMailing").
'</a>';
1113 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=reset&id='.$object->id.
'">'.$langs->trans(
"ResetMailing").
'</a>';
1117 if (($object->statut <= 1 && $user->hasRight(
'mailing',
'creer')) || $user->hasRight(
'mailing',
'supprimer')) {
1118 if ($object->statut > 0 && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->delete)) {
1119 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"DeleteMailing").
'</a>';
1121 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.newToken().
'&id='.$object->id.(!empty($urlfrom) ?
'&urlfrom='.$urlfrom :
'').
'">'.$langs->trans(
"DeleteMailing").
'</a>';
1129 if ($action ==
'test') {
1130 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
1136 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1138 $formmail->fromname = $object->email_from;
1139 $formmail->frommail = $object->email_from;
1140 $formmail->withsubstit = 1;
1141 $formmail->withfrom = 0;
1142 $formmail->withto = $user->email ? $user->email : 1;
1143 $formmail->withtocc = 0;
1144 $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
1145 $formmail->withtopic = 0;
1146 $formmail->withtopicreadonly = 1;
1147 $formmail->withfile = 0;
1148 $formmail->withbody = 0;
1149 $formmail->withbodyreadonly = 1;
1150 $formmail->withcancel = 1;
1151 $formmail->withdeliveryreceipt = 0;
1153 $formmail->substit = $object->substitutionarrayfortest;
1155 $formmail->param[
"action"] =
"send";
1156 $formmail->param[
"models"] =
'none';
1157 $formmail->param[
"mailid"] = $object->id;
1158 $formmail->param[
"returnurl"] = $_SERVER[
'PHP_SELF'].
"?id=".$object->id;
1160 print $formmail->get_form();
1170 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br><br><span class="small">';
1171 foreach ($object->substitutionarray as $key => $val) {
1172 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1174 $htmltext .=
'</span></i>';
1177 print
load_fiche_titre($langs->trans(
"EMail"), $form->textwithpicto(
'<span class="opacitymedium hideonsmartphone">'.$langs->trans(
"AvailableVariables").
'</span>', $htmltext, 1,
'helpclickable',
'', 0, 3,
'emailsubstitionhelp'),
'generic');
1181 print
'<table class="bordernooddeven tableforfield centpercent">';
1184 print
'<tr><td class="titlefield">'.$langs->trans(
"MailTopic").
'</td><td colspan="3">'.$object->sujet.
'</td></tr>';
1187 print
'<tr><td>'.$langs->trans(
"MailFile").
'</td><td colspan="3">';
1189 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
1190 if (count($listofpaths)) {
1191 foreach ($listofpaths as $key => $val) {
1192 print
img_mime($listofpaths[$key][
'name']).
' '.$listofpaths[$key][
'name'];
1196 print
'<span class="opacitymedium">'.$langs->trans(
"NoAttachedFiles").
'</span><br>';
1208 print
'<div style="padding-top: 10px; background: '.($object->bgcolor ? (preg_match(
'/^#/', $object->bgcolor) ?
'' :
'#').$object->bgcolor :
'white').
'">';
1209 if (empty($object->bgcolor) || strtolower($object->bgcolor) ==
'ffffff') {
1212 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1213 $doleditor =
new DolEditor(
'bodyemail', $object->body,
'', 600,
'dolibarr_mailings',
'',
false,
true, empty($conf->global->FCKEDITOR_ENABLE_MAILING) ? 0 : 1, 20,
'90%', $readonly);
1214 $doleditor->Create();
1228 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
1230 $morehtmlref =
'<div class="refidno">';
1232 $morehtmlref .= $form->editfieldkey(
"",
'title', $object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string',
'', 0, 1);
1233 $morehtmlref .= $form->editfieldval(
"",
'title', $object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string',
'',
null,
null,
'', 1);
1234 $morehtmlref .=
'</div>';
1236 $morehtmlright =
'';
1238 if ($object->statut == 2 || $object->statut == 3) {
1239 $nbtry = $object->countNbOfTargets(
'alreadysent');
1240 $nbko = $object->countNbOfTargets(
'alreadysentko');
1242 $morehtmlright .=
' ('.$nbtry.
'/'.$object->nbemail;
1244 $morehtmlright .=
' - '.$nbko.
' '.$langs->trans(
"Error");
1246 $morehtmlright .=
') ';
1249 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlright);
1251 print
'<div class="fichecenter">';
1252 print
'<div class="fichehalfleft">';
1253 print
'<div class="underbanner clearboth"></div>';
1255 print
'<table class="border centpercent tableforfield">';
1265 print
'<tr><td class="titlefield">'.$langs->trans(
"MailFrom").
'</td><td>'.
dol_print_email($object->email_from, 0, 0, 0, 0, 1).
'</td></tr>';
1267 print
'<tr><td>'.$langs->trans(
"MailErrorsTo").
'</td><td>'.
dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1).
'</td></tr>';
1273 print
'<div class="fichehalfright">';
1274 print
'<div class="underbanner clearboth"></div>';
1276 print
'<table class="border centpercent tableforfield">';
1280 print $langs->trans(
"TotalNbOfDistinctRecipients");
1282 $nbemail = ($object->nbemail ? $object->nbemail : 0);
1283 if (is_numeric($nbemail)) {
1285 if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || $object->statut == 2)) {
1286 if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) {
1287 $text .= $langs->trans(
'LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
1289 $text .= $langs->trans(
'SendingFromWebInterfaceIsNotAllowed');
1292 if (empty($nbemail)) {
1293 $nbemail .=
' '.img_warning(
'').
' <span class="warning">'.$langs->trans(
"NoTargetYet").
'</span>';
1296 print $form->textwithpicto($nbemail, $text, 1,
'warning');
1304 print $langs->trans(
"MAIN_MAIL_SENDMODE");
1311 $text = $listofmethods[
'mail'];
1316 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER_EMAILING').
')</span>';
1319 print
' <span class="opacitymedium">('.getDolGlobalString(
'MAIN_MAIL_SMTP_SERVER').
')</span>';
1325 $parameters = array();
1326 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1327 print $hookmanager->resPrint;
1328 if (empty($reshook)) {
1329 print $object->showOptionals($extrafields,
'edit', $parameters);
1336 print
'<div class="clearboth"></div>';
1343 print
'<form name="edit_mailing" action="card.php" method="post" enctype="multipart/form-data">'.
"\n";
1344 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1345 print
'<input type="hidden" name="action" value="update">';
1346 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1348 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br><br><span class="small">';
1349 foreach ($object->substitutionarray as $key => $val) {
1350 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1352 $htmltext .=
'</span></i>';
1355 print
load_fiche_titre($langs->trans(
"EMail"),
'<span class="opacitymedium">'.$form->textwithpicto($langs->trans(
"AvailableVariables").
'</span>', $htmltext, 1,
'help',
'', 0, 2,
'emailsubstitionhelp'),
'generic');
1359 print
'<table class="bordernooddeven centpercent">';
1362 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>';
1368 $addfileaction =
'addfile';
1369 print
'<tr><td>'.$langs->trans(
"MailFile").
'</td>';
1370 print
'<td colspan="3">';
1372 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
1375 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
1376 $out .=
'<script type="text/javascript">';
1377 $out .=
'jQuery(document).ready(function () {';
1378 $out .=
' jQuery(".removedfile").click(function() {';
1379 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
1382 $out .=
'</script>'.
"\n";
1383 if (count($listofpaths)) {
1384 foreach ($listofpaths as $key => $val) {
1385 $out .=
'<div id="attachfile_'.$key.
'">';
1386 $out .=
img_mime($listofpaths[$key][
'name']).
' '.$listofpaths[$key][
'name'];
1387 $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.
'" />';
1388 $out .=
'<br></div>';
1396 $maxmin = $maxfilesizearray[
'maxmin'];
1398 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
1400 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
1402 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
1407 print
'<tr><td>'.$langs->trans(
"BackgroundColorByDefault").
'</td><td colspan="3">';
1408 print $htmlother->selectColor($object->bgcolor,
'bgcolor',
'', 0);
1415 print
'<div style="padding-top: 10px">';
1417 if ($action ==
'edit') {
1419 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1420 $doleditor =
new DolEditor(
'bodyemail', $object->body,
'', 600,
'dolibarr_mailings',
'',
true,
true,
getDolGlobalInt(
'FCKEDITOR_ENABLE_MAILING'), 20,
'90%');
1421 $doleditor->Create();
1423 if ($action ==
'edithtml') {
1425 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1426 $doleditor =
new DolEditor(
'bodyemail', $object->body,
'', 600,
'dolibarr_mailings',
'',
true,
true,
'ace', 20,
'90%');
1427 $doleditor->Create(0,
'',
false,
'HTML Source',
'php');
1435 print
'<div class="center">';
1436 print
'<input type="submit" class="button buttonforacesave button-save" value="'.$langs->trans(
"Save").
'" name="save">';
1437 print
' ';
1438 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 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')
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.