27 if (!defined(
'NOSTYLECHECK')) {
28 define(
'NOSTYLECHECK',
'1');
32 require
'../../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/emailing.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/mailing.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
43 $langs->load(
"mails");
47 $action =
GETPOST(
'action',
'aZ09');
48 $confirm =
GETPOST(
'confirm',
'alpha');
49 $cancel =
GETPOST(
'cancel',
'aZ09');
57 $result = $object->fetch($id);
61 $extrafields->fetch_name_optionals_label($object->table_element);
64 $hookmanager->initHooks(array(
'mailingcard',
'globalcard'));
71 $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $user->signature :
'');
78 $object->substitutionarrayfortest = $substitutionarray;
81 $listofmethods = array();
82 $listofmethods[
'mail'] =
'PHP mail function';
83 $listofmethods[
'smtps'] =
'SMTP/SMTPS socket library';
86 if (empty($user->rights->mailing->lire) || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->socid > 0)) {
90 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
98 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
103 if (empty($reshook)) {
106 $backurlforlist = DOL_URL_ROOT.
'/comm/mailing/list.php';
108 if (empty($backtopage) || ($cancel && empty($id))) {
109 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
110 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
111 $backtopage = $backurlforlist;
113 $backtopage = DOL_URL_ROOT.
'/comm/mailing/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
120 if (!empty($backtopageforcancel)) {
121 header(
"Location: ".$backtopageforcancel);
123 } elseif (!empty($backtopage)) {
124 header(
"Location: ".$backtopage);
131 if ($action ==
'confirm_clone' && $confirm ==
'yes') {
132 if (!
GETPOST(
"clone_content",
'alpha') && !
GETPOST(
"clone_receivers",
'alpha')) {
135 $result = $object->createFromClone($user, $object->id,
GETPOST(
"clone_content",
'alpha'),
GETPOST(
"clone_receivers",
'alpha'));
137 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
147 if ($action ==
'sendallconfirmed' && $confirm ==
'yes') {
148 if (empty($conf->global->MAILING_LIMIT_SENDBYWEB)) {
151 setEventMessages(
'<textarea cols="70" rows="'.ROWS_2.
'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.
'</textarea>',
null,
'warnings');
154 } elseif ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
158 if ($object->statut == 0) {
164 $subject = $object->sujet;
165 $message = $object->body;
166 $from = $object->email_from;
167 $replyto = $object->email_replyto;
168 $errorsto = $object->email_errorsto;
171 if (preg_match(
'/[\s\t]*<html>/i', $message)) {
178 $nbok = 0; $nbko = 0;
182 $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";
183 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc";
184 $sql .=
" WHERE mc.statut < 1 AND mc.fk_mailing = ".((int) $object->id);
185 $sql .=
" ORDER BY mc.statut DESC";
187 dol_syslog(
"card.php: select targets", LOG_DEBUG);
188 $resql = $db->query(
$sql);
190 $num = $db->num_rows($resql);
193 dol_syslog(
"comm/mailing/card.php: nb of targets = ".$num, LOG_DEBUG);
198 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing SET date_envoi='".$db->idate($now).
"' WHERE rowid=".((int) $object->id);
199 $resql2 = $db->query(
$sql);
204 $thirdpartystatic =
new Societe($db);
208 while ($iforemailloop < $num && $iforemailloop < $conf->global->MAILING_LIMIT_SENDBYWEB) {
213 $obj = $db->fetch_object($resql);
216 $sendto = str_replace(
',',
' ',
dolGetFirstLastname($obj->firstname, $obj->lastname)).
" <".$obj->email.
">";
219 $other = explode(
';', $obj->other);
220 $tmpfield = explode(
'=', $other[0], 2); $other1 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
221 $tmpfield = explode(
'=', $other[1], 2); $other2 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
222 $tmpfield = explode(
'=', $other[2], 2); $other3 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
223 $tmpfield = explode(
'=', $other[3], 2); $other4 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
224 $tmpfield = explode(
'=', $other[4], 2); $other5 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
226 $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $user->signature :
'');
232 $substitutionarray[
'__ID__'] = $obj->source_id;
233 if ($obj->source_type ==
"thirdparty") {
234 $result = $thirdpartystatic->fetch($obj->source_id);
237 $substitutionarray[
'__THIRDPARTY_CUSTOMER_CODE__'] = $thirdpartystatic->code_client;
239 $substitutionarray[
'__THIRDPARTY_CUSTOMER_CODE__'] =
'';
242 $substitutionarray[
'__EMAIL__'] = $obj->email;
243 $substitutionarray[
'__LASTNAME__'] = $obj->lastname;
244 $substitutionarray[
'__FIRSTNAME__'] = $obj->firstname;
245 $substitutionarray[
'__MAILTOEMAIL__'] =
'<a href="mailto:'.$obj->email.
'">'.$obj->email.
'</a>';
246 $substitutionarray[
'__OTHER1__'] = $other1;
247 $substitutionarray[
'__OTHER2__'] = $other2;
248 $substitutionarray[
'__OTHER3__'] = $other3;
249 $substitutionarray[
'__OTHER4__'] = $other4;
250 $substitutionarray[
'__OTHER5__'] = $other5;
251 $substitutionarray[
'__USER_SIGNATURE__'] = $signature;
252 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $signature;
253 $substitutionarray[
'__CHECK_READ__'] =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php?tag='.urlencode($obj->tag).
'&securitykey='.
dol_hash($conf->global->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"/>';
254 $substitutionarray[
'__UNSUBSCRIBE__'] =
'<a href="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-unsubscribe.php?tag='.urlencode($obj->tag).
'&unsuscrib=1&securitykey='.
dol_hash($conf->global->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>';
255 $substitutionarray[
'__UNSUBSCRIBE_URL__'] = DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-unsubscribe.php?tag='.urlencode($obj->tag).
'&unsuscrib=1&securitykey='.
dol_hash($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY.
'-'.$obj->tag.
'-'.$obj->email.
'-'.$obj->rowid,
"md5").
'&email='.urlencode($obj->email).
'&mtid='.((int) $obj->rowid);
257 $onlinepaymentenabled = 0;
259 $onlinepaymentenabled++;
262 $onlinepaymentenabled++;
265 $onlinepaymentenabled++;
267 if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
268 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
269 $substitutionarray[
'__ONLINEPAYMENTLINK_MEMBER__'] = getHtmlOnlinePaymentLink(
'member', $obj->source_id);
270 $substitutionarray[
'__ONLINEPAYMENTLINK_DONATION__'] = getHtmlOnlinePaymentLink(
'donation', $obj->source_id);
271 $substitutionarray[
'__ONLINEPAYMENTLINK_ORDER__'] = getHtmlOnlinePaymentLink(
'order', $obj->source_id);
272 $substitutionarray[
'__ONLINEPAYMENTLINK_INVOICE__'] = getHtmlOnlinePaymentLink(
'invoice', $obj->source_id);
273 $substitutionarray[
'__ONLINEPAYMENTLINK_CONTRACTLINE__'] = getHtmlOnlinePaymentLink(
'contractline', $obj->source_id);
275 $substitutionarray[
'__SECUREKEYPAYMENT__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
276 if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
277 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
278 $substitutionarray[
'__SECUREKEYPAYMENT_DONATION__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
279 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
280 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
281 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
283 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'member'.$obj->source_id, 2);
284 $substitutionarray[
'__SECUREKEYPAYMENT_DONATION__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'donation'.$obj->source_id, 2);
285 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'order'.$obj->source_id, 2);
286 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'invoice'.$obj->source_id, 2);
287 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.
'contractline'.$obj->source_id, 2);
290 if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
291 $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>';
294 if (
isModEnabled(
'paypal') && !empty($conf->global->PAYPAL_SECURITY_TOKEN)) {
295 $substitutionarray[
'__SECUREKEYPAYPAL__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
297 if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
298 $substitutionarray[
'__SECUREKEYPAYPAL_MEMBER__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
300 $substitutionarray[
'__SECUREKEYPAYPAL_MEMBER__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.
'membersubscription'.$obj->source_id, 2);
303 if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
304 $substitutionarray[
'__SECUREKEYPAYPAL_ORDER__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
306 $substitutionarray[
'__SECUREKEYPAYPAL_ORDER__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.
'order'.$obj->source_id, 2);
309 if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
310 $substitutionarray[
'__SECUREKEYPAYPAL_INVOICE__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
312 $substitutionarray[
'__SECUREKEYPAYPAL_INVOICE__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.
'invoice'.$obj->source_id, 2);
315 if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
316 $substitutionarray[
'__SECUREKEYPAYPAL_CONTRACTLINE__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
318 $substitutionarray[
'__SECUREKEYPAYPAL_CONTRACTLINE__'] =
dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.
'contractline'.$obj->source_id, 2);
328 if (preg_match(
'/__UNSUBSCRIBE_(_|URL_)/', $message)) {
329 $moreinheader =
"List-Unsubscribe: <__UNSUBSCRIBE_URL__>\n";
338 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
339 if (count($listofpaths)) {
340 foreach ($listofpaths as $key => $val) {
341 $arr_file[] = $listofpaths[$key][
'fullname'];
343 $arr_name[] = $listofpaths[$key][
'name'];
348 $trackid =
'emailing-'.$obj->fk_mailing.
'-'.$obj->rowid;
349 $upload_dir_tmp = $upload_dir;
350 $mail =
new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name,
'',
'', 0, $msgishtml, $errorsto, $arr_css, $trackid, $moreinheader,
'emailing',
'', $upload_dir_tmp);
363 $res = $mail->sendfile();
370 dol_syslog(
"comm/mailing/card.php: ok for #".$iforemailloop.($mail->error ?
' - '.$mail->error :
''), LOG_DEBUG);
372 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
373 $sql .=
" SET statut=1, date_envoi = '".$db->idate($now).
"' WHERE rowid=".((int) $obj->rowid);
374 $resql2 = $db->query(
$sql);
379 if (strpos($message,
'__CHECK_READ__') !==
false) {
381 $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).
")";
382 dol_syslog(
"card.php: set prospect thirdparty status", LOG_DEBUG);
383 $resql2 = $db->query(
$sql);
389 $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)";
390 dol_syslog(
"card.php: set prospect contact status", LOG_DEBUG);
392 $resql2 = $db->query(
$sql);
399 if (!empty($conf->global->MAILING_DELAY)) {
400 dol_syslog(
"Wait a delay of MAILING_DELAY=".((
float) $conf->global->MAILING_DELAY));
401 usleep((
float) $conf->global->MAILING_DELAY * 1000000);
409 dol_syslog(
"comm/mailing/card.php: error for #".$iforemailloop.($mail->error ?
' - '.$mail->error :
''), LOG_WARNING);
411 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
412 $sql .=
" SET statut=-1, error_text='".$db->escape($mail->error).
"', date_envoi='".$db->idate($now).
"' WHERE rowid=".((int) $obj->rowid);
413 $resql2 = $db->query(
$sql);
422 setEventMessages($langs->transnoentitiesnoconv(
"NoMoreRecipientToSendTo"),
null,
'mesgs');
429 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
431 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
436 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
439 setEventMessages($langs->transnoentitiesnoconv(
"EMailSentToNRecipients", $nbok),
null,
'mesgs');
443 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing SET statut=".((int) $statut).
" WHERE rowid = ".((int) $object->id);
444 dol_syslog(
"comm/mailing/card.php: update global status", LOG_DEBUG);
445 $resql2 = $db->query(
$sql);
459 if ($action ==
'send' && ! $cancel) {
462 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
464 $object->sendto =
GETPOST(
"sendto",
'alphawithlgt');
465 if (!$object->sendto) {
466 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailTo")),
null,
'errors');
473 if (preg_match(
'/[\s\t]*<html>/i', $object->body)) {
477 $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $user->signature :
'');
483 $substitutionarray[
'__EMAIL__'] = $object->sendto;
484 $substitutionarray[
'__MAILTOEMAIL__'] =
'<a href="mailto:'.$object->sendto.
'">'.$object->sendto.
'</a>';
485 $substitutionarray[
'__CHECK_READ__'] =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php?tag=undefinedintestmode&securitykey='.
dol_hash($conf->global->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"/>';
486 $substitutionarray[
'__UNSUBSCRIBE__'] =
'<a href="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-unsubscribe.php?tag=undefinedintestmode&unsuscrib=1&securitykey='.
dol_hash($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY.
"-undefinedintestmode-".$obj->sendto.
"-0",
'md5').
'&email='.urlencode($obj->sendto).
'&mtid=0" target="_blank" rel="noopener noreferrer">'.$langs->trans(
"MailUnsubcribe").
'</a>';
487 $substitutionarray[
'__UNSUBSCRIBE_URL__'] = DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-unsubscribe.php?tag=undefinedintestmode&unsuscrib=1&securitykey='.
dol_hash($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY.
"-undefinedintestmode-".$obj->sendto.
"-0",
'md5').
'&email='.urlencode($obj->sendto).
'&mtid=0';
501 if (!empty($object->bgcolor)) {
502 $arr_css[
'bgcolor'] = (preg_match(
'/^#/', $object->bgcolor) ?
'' :
'#').$object->bgcolor;
504 if (!empty($object->bgimage)) {
505 $arr_css[
'bgimage'] = $object->bgimage;
509 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
510 if (count($listofpaths)) {
511 foreach ($listofpaths as $key => $val) {
512 $arr_file[] = $listofpaths[$key][
'fullname'];
514 $arr_name[] = $listofpaths[$key][
'name'];
518 $trackid =
'emailing-test';
519 $upload_dir_tmp = $upload_dir;
520 $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);
522 $result = $mailfile->sendfile();
524 setEventMessages($langs->trans(
"MailSuccessfulySent", $mailfile->getValidAddress($object->email_from, 2), $mailfile->getValidAddress($object->sendto, 2)),
null,
'mesgs');
527 setEventMessages($langs->trans(
"ResultKo").
'<br>'.$mailfile->error.
' '.$result,
null,
'errors');
534 if ($action ==
'add') {
537 $object->email_from = (string)
GETPOST(
"from",
'alphawithlgt');
538 $object->email_replyto = (string)
GETPOST(
"replyto",
'alphawithlgt');
539 $object->email_errorsto = (string)
GETPOST(
"errorsto",
'alphawithlgt');
540 $object->title = (string)
GETPOST(
"title");
541 $object->sujet = (string)
GETPOST(
"sujet");
542 $object->body = (string)
GETPOST(
"bodyemail",
'restricthtml');
543 $object->bgcolor = (string)
GETPOST(
"bgcolor");
544 $object->bgimage = (string)
GETPOST(
"bgimage");
546 if (!$object->title) {
547 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTitle"));
549 if (!$object->sujet) {
550 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTopic"));
552 if (!$object->body) {
553 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailMessage"));
556 if (!count($mesgs)) {
557 if ($object->create($user) >= 0) {
558 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
561 $mesgs[] = $object->error;
562 $mesgs = array_merge($mesgs, $object->errors);
570 if ($action ==
'settitle' || $action ==
'setemail_from' || $action ==
'setreplyto' || $action ==
'setemail_errorsto') {
571 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
573 if ($action ==
'settitle') {
574 $object->title = trim(
GETPOST(
'title',
'alpha'));
575 } elseif ($action ==
'setemail_from') {
576 $object->email_from = trim(
GETPOST(
'email_from',
'alphawithlgt'));
577 } elseif ($action ==
'setemail_replyto') {
578 $object->email_replyto = trim(
GETPOST(
'email_replyto',
'alphawithlgt'));
579 } elseif ($action ==
'setemail_errorsto') {
580 $object->email_errorsto = trim(
GETPOST(
'email_errorsto',
'alphawithlgt'));
581 } elseif ($action ==
'settitle' && empty($object->title)) {
582 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTitle"));
583 } elseif ($action ==
'setfrom' && empty($object->email_from)) {
584 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailFrom"));
588 if ($object->update($user) >= 0) {
589 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
592 $mesg = $object->error;
603 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
605 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
615 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
617 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
625 if ($action ==
'update' && !
GETPOST(
"removedfile") && !$cancel) {
626 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
632 $object->sujet = (string)
GETPOST(
"sujet");
633 $object->body = (string)
GETPOST(
"bodyemail",
'restricthtml');
634 $object->bgcolor = (string)
GETPOST(
"bgcolor");
635 $object->bgimage = (string)
GETPOST(
"bgimage");
637 if (!$object->sujet) {
638 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailTopic"));
640 if (!$object->body) {
641 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MailMessage"));
644 if (!count($mesgs)) {
645 if ($object->update($user) >= 0) {
646 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
649 $mesgs[] = $object->error;
650 $mesgs = array_merge($mesgs, $object->errors);
661 if ($action ==
'confirm_valid' && $confirm ==
'yes') {
662 if ($object->id > 0) {
663 $object->valid($user);
664 setEventMessages($langs->trans(
"MailingSuccessfullyValidated"),
null,
'mesgs');
665 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
673 if ($action ==
'confirm_settodraft' && $confirm ==
'yes') {
674 if ($object->id > 0) {
675 $result = $object->setStatut(0);
678 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
689 if ($action ==
'confirm_reset' && $confirm ==
'yes') {
690 if ($object->id > 0) {
693 $result = $object->valid($user);
695 $result = $object->reset_targets_status($user);
700 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
712 if ($action ==
'confirm_delete' && $confirm ==
'yes') {
713 if ($object->delete($user)) {
714 $url = (!empty($urlfrom) ? $urlfrom :
'list.php');
715 header(
"Location: ".$url);
733 $help_url =
'EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing';
736 $langs->trans(
"Mailing"),
742 '/includes/ace/src/ace.js',
743 '/includes/ace/src/ext-statusbar.js',
744 '/includes/ace/src/ext-language_tools.js',
750 if ($action ==
'create') {
752 print
'<form name="new_mailing" action="'.$_SERVER[
'PHP_SELF'].
'" method="POST">'.
"\n";
753 print
'<input type="hidden" name="token" value="'.newToken().
'">';
754 print
'<input type="hidden" name="action" value="add">';
756 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
757 foreach ($object->substitutionarray as $key => $val) {
758 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
763 $availablelink =
$form->textwithpicto($langs->trans(
"AvailableVariables"), $htmltext, 1,
'help',
'', 0, 2,
'availvar');
768 print
load_fiche_titre($langs->trans(
"NewMailing"), $availablelink,
'object_email');
772 print
'<table class="border centpercent">';
774 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>';
776 print
'<tr><td class="fieldrequired">'.$langs->trans(
"MailFrom").
'</td><td><input class="flat minwidth200" name="from" value="'.
getDolGlobalString(
'MAILING_EMAIL_FROM').
'"></td></tr>';
778 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>';
782 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
783 print $hookmanager->resPrint;
784 if (empty($reshook)) {
785 print $object->showOptionals($extrafields,
'create');
791 print
'<table class="border centpercent">';
792 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>';
793 print
'<tr><td>'.$langs->trans(
"BackgroundColorByDefault").
'</td><td colspan="3">';
794 print $htmlother->selectColor(
GETPOST(
'bgcolor'),
'bgcolor',
'', 0);
799 print
'<div style="padding-top: 10px">';
801 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
802 $doleditor =
new DolEditor(
'bodyemail',
GETPOST(
'bodyemail',
'restricthtmlallowunvalid'),
'', 600,
'dolibarr_mailings',
'',
true,
true,
getDolGlobalInt(
'FCKEDITOR_ENABLE_MAILING'), 20,
'90%');
803 $doleditor->Create();
808 print
$form->buttonsSaveCancel(
"CreateMailing",
'Cancel');
812 if ($object->id > 0) {
813 $upload_dir = $conf->mailing->dir_output.
"/".
get_exdir($object->id, 2, 0, 1, $object,
'mailing');
817 if ($action ==
'settodraft') {
819 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"SetToDraft"), $langs->trans(
"ConfirmUnvalidateEmailing"),
"confirm_settodraft",
'',
'', 1);
820 } elseif ($action ==
'valid') {
822 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"ValidMailing"), $langs->trans(
"ConfirmValidMailing"),
"confirm_valid",
'',
'', 1);
823 } elseif ($action ==
'reset') {
825 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"ResetMailing"), $langs->trans(
"ConfirmResetMailing", $object->ref),
"confirm_reset",
'',
'', 2);
826 } elseif ($action ==
'delete') {
828 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.(!empty($urlfrom) ?
'&urlfrom='.urlencode($urlfrom) :
''), $langs->trans(
"DeleteAMailing"), $langs->trans(
"ConfirmDeleteMailing"),
"confirm_delete",
'',
'', 1);
831 if ($action !=
'edit' && $action !=
'edithtml') {
837 if ($action ==
'sendall') {
839 $sendingmode = $conf->global->EMAILING_MAIL_SENDMODE;
840 if (empty($sendingmode)) {
841 $sendingmode = $conf->global->MAIN_MAIL_SENDMODE;
843 if (empty($sendingmode)) {
844 $sendingmode =
'mail';
851 if (!empty($conf->global->MAILING_NO_USING_PHPMAIL) && $sendingmode ==
'mail') {
854 $linktoadminemailbefore =
'<a href="'.DOL_URL_ROOT.
'/admin/mails_emailing.php">';
855 $linktoadminemailend =
'</a>';
856 setEventMessages($langs->trans(
"MailSendSetupIs", $listofmethods[$sendingmode]),
null,
'warnings');
857 $messagetoshow = $langs->trans(
"MailSendSetupIs2",
'{s1}',
'{s2}',
'{s3}',
'{s4}');
858 $messagetoshow = str_replace(
'{s1}', $linktoadminemailbefore, $messagetoshow);
859 $messagetoshow = str_replace(
'{s2}', $linktoadminemailend, $messagetoshow);
860 $messagetoshow = str_replace(
'{s3}', $langs->transnoentitiesnoconv(
"MAIN_MAIL_SENDMODE"), $messagetoshow);
861 $messagetoshow = str_replace(
'{s4}', $listofmethods[
'smtps'], $messagetoshow);
864 if (!empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) {
865 setEventMessages($langs->trans(
"MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS),
null,
'warnings');
867 $_GET[
"action"] =
'';
868 } elseif ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
869 if (!empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode ==
'mail') {
870 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL),
null,
'warnings');
872 if (!empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode !=
'mail') {
873 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL),
null,
'warnings');
878 setEventMessages(
'<textarea cols="60" rows="'.ROWS_1.
'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.
'</textarea>',
null,
'warnings');
879 if ($conf->file->mailing_limit_sendbyweb !=
'-1') {
882 $_GET[
"action"] =
'';
884 if (!empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode ==
'mail') {
885 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL),
null,
'warnings');
887 if (!empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode !=
'mail') {
888 setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL),
null,
'warnings');
893 if (isset($conf->global->MAILING_LIMIT_SENDBYDAY) && $conf->global->MAILING_LIMIT_SENDBYDAY >= 0) {
894 $text .= $langs->trans(
'WarningLimitSendByDay', $conf->global->MAILING_LIMIT_SENDBYDAY);
897 $text .= $langs->trans(
'ConfirmSendingEmailing').
'<br>';
898 $text .= $langs->trans(
'LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
900 if (!isset($conf->global->MAILING_LIMIT_SENDBYCLI) || $conf->global->MAILING_LIMIT_SENDBYCLI >= 0) {
902 $text .= $langs->trans(
"MailingNeedCommand");
903 $text .=
'<br><textarea class="quatrevingtpercent" rows="'.ROWS_2.
'" wrap="soft" disabled>php ./scripts/emailings/mailing-send.php '.$object->id.
' '.$user->login.
'</textarea>';
906 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
'SendMailing'), $text,
'sendallconfirmed',
'',
'', 1, 380, 660, 0, $langs->trans(
"Confirm"), $langs->trans(
"Cancel"));
910 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
912 $morehtmlref =
'<div class="refidno">';
914 $morehtmlref .=
$form->editfieldkey(
"",
'title', $object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string',
'', 0, 1);
915 $morehtmlref .=
$form->editfieldval(
"",
'title', $object->title, $object, $user->hasRight(
'mailing',
'creer'),
'string',
'',
null,
null,
'', 1);
916 $morehtmlref .=
'</div>';
920 if ($object->statut == 2 || $object->statut == 3) {
921 $nbtry = $object->countNbOfTargets(
'alreadysent');
922 $nbko = $object->countNbOfTargets(
'alreadysentko');
924 $morehtmlright .=
' ('.$nbtry.
'/'.$object->nbemail;
926 $morehtmlright .=
' - '.$nbko.
' '.$langs->trans(
"Error");
928 $morehtmlright .=
') ';
931 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlright);
933 print
'<div class="fichecenter">';
934 print
'<div class="underbanner clearboth"></div>';
936 print
'<table class="border centpercent tableforfield">';
948 print
'<tr><td class="titlefield">';
949 print
$form->editfieldkey(
"MailFrom",
'email_from', $object->email_from, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
951 print
$form->editfieldval(
"MailFrom",
'email_from', $object->email_from, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
954 $langs->load(
"errors");
955 print
img_warning($langs->trans(
"ErrorBadEMail", $email));
957 $langs->load(
"errors");
958 print
img_warning($langs->trans(
"ErrorBadMXDomain", $email));
965 print
$form->editfieldkey(
"MailErrorsTo",
'email_errorsto', $object->email_errorsto, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
967 print
$form->editfieldval(
"MailErrorsTo",
'email_errorsto', $object->email_errorsto, $object, $user->hasRight(
'mailing',
'creer') && $object->statut < 3,
'string');
970 $langs->load(
"errors");
971 print
img_warning($langs->trans(
"ErrorBadEMail", $email));
973 $langs->load(
"errors");
974 print
img_warning($langs->trans(
"ErrorBadMXDomain", $email));
980 print $langs->trans(
"TotalNbOfDistinctRecipients");
981 print
'</td><td colspan="3">';
982 $nbemail = ($object->nbemail ? $object->nbemail : 0);
983 if (is_numeric($nbemail)) {
985 if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail))) {
986 if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) {
987 $text .= $langs->trans(
'LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
989 $text .= $langs->trans(
'SendingFromWebInterfaceIsNotAllowed');
992 if (empty($nbemail)) {
993 $nbemail .=
' '.img_warning(
'').
' <span class="warning">'.$langs->trans(
"NoTargetYet").
'</span>';
996 print
$form->textwithpicto($nbemail, $text, 1,
'warning');
1004 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1014 if ($action ==
'clone') {
1016 $formquestion = array(
1017 'text' => $langs->trans(
"ConfirmClone"),
1018 array(
'type' =>
'checkbox',
'name' =>
'clone_content',
'label' => $langs->trans(
"CloneContent"),
'value' => 1),
1019 array(
'type' =>
'checkbox',
'name' =>
'clone_receivers',
'label' => $langs->trans(
"CloneReceivers"),
'value' => 0)
1022 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneEMailing', $object->ref),
'confirm_clone', $formquestion,
'yes', 2, 240);
1029 if (
GETPOST(
'cancel',
'alpha') || $confirm ==
'no' || $action ==
'' || in_array($action, array(
'settodraft',
'valid',
'delete',
'sendall',
'clone',
'test'))) {
1030 print
"\n\n<div class=\"tabsAction\">\n";
1032 if (($object->statut == 1) && ($user->hasRight(
'mailing',
'valider') || $object->user_validation == $user->id)) {
1033 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=settodraft&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"SetToDraft").
'</a>';
1036 if (($object->statut == 0 || $object->statut == 1 || $object->statut == 2) && $user->hasRight(
'mailing',
'creer')) {
1037 if (
isModEnabled(
'fckeditor') && !empty($conf->global->FCKEDITOR_ENABLE_MAILING)) {
1038 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"EditWithEditor").
'</a>';
1040 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"EditWithTextEditor").
'</a>';
1043 if (!empty($conf->use_javascript_ajax)) {
1044 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edithtml&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"EditHTMLSource").
'</a>';
1050 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
1051 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"TestMailing").
'</a>';
1053 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=test&token='.
newToken().
'&id='.$object->id.
'">'.$langs->trans(
"TestMailing").
'</a>';
1056 if ($object->statut == 0) {
1057 if ($object->nbemail <= 0) {
1058 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NoTargetYet")).
'">'.$langs->trans(
"ValidMailing").
'</a>';
1059 } elseif (empty($user->rights->mailing->valider)) {
1060 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"ValidMailing").
'</a>';
1062 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=valid&id='.$object->id.
'">'.$langs->trans(
"ValidMailing").
'</a>';
1066 if (($object->statut == 1 || $object->statut == 2) && $object->nbemail > 0 && $user->hasRight(
'mailing',
'valider')) {
1067 if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) {
1068 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"SendingFromWebInterfaceIsNotAllowed")).
'">'.$langs->trans(
"SendMailing").
'</a>';
1069 } elseif (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
1070 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"SendMailing").
'</a>';
1072 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=sendall&id='.$object->id.
'">'.$langs->trans(
"SendMailing").
'</a>';
1076 if ($user->hasRight(
'mailing',
'creer')) {
1077 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=clone&object=emailing&id='.$object->id.
'">'.$langs->trans(
"ToClone").
'</a>';
1080 if (($object->statut == 2 || $object->statut == 3) && $user->hasRight(
'mailing',
'valider')) {
1081 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send) {
1082 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"ResetMailing").
'</a>';
1084 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=reset&id='.$object->id.
'">'.$langs->trans(
"ResetMailing").
'</a>';
1088 if (($object->statut <= 1 && $user->hasRight(
'mailing',
'creer')) || $user->hasRight(
'mailing',
'supprimer')) {
1089 if ($object->statut > 0 && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->delete)) {
1090 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"DeleteMailing").
'</a>';
1092 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&id='.$object->id.(!empty($urlfrom) ?
'&urlfrom='.$urlfrom :
'').
'">'.$langs->trans(
"DeleteMailing").
'</a>';
1100 if ($action ==
'test') {
1101 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
1107 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1109 $formmail->fromname = $object->email_from;
1110 $formmail->frommail = $object->email_from;
1111 $formmail->withsubstit = 1;
1112 $formmail->withfrom = 0;
1113 $formmail->withto = $user->email ? $user->email : 1;
1114 $formmail->withtocc = 0;
1115 $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
1116 $formmail->withtopic = 0;
1117 $formmail->withtopicreadonly = 1;
1118 $formmail->withfile = 0;
1119 $formmail->withbody = 0;
1120 $formmail->withbodyreadonly = 1;
1121 $formmail->withcancel = 1;
1122 $formmail->withdeliveryreceipt = 0;
1124 $formmail->substit = $object->substitutionarrayfortest;
1126 $formmail->param[
"action"] =
"send";
1127 $formmail->param[
"models"] =
'none';
1128 $formmail->param[
"mailid"] = $object->id;
1129 $formmail->param[
"returnurl"] = $_SERVER[
'PHP_SELF'].
"?id=".$object->id;
1131 print $formmail->get_form();
1141 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br><br><span class="small">';
1142 foreach ($object->substitutionarray as $key => $val) {
1143 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1145 $htmltext .=
'</span></i>';
1148 print
load_fiche_titre($langs->trans(
"EMail"),
$form->textwithpicto(
'<span class="opacitymedium hideonsmartphone">'.$langs->trans(
"AvailableVariables").
'</span>', $htmltext, 1,
'helpclickable',
'', 0, 3,
'emailsubstitionhelp'),
'generic');
1152 print
'<table class="bordernooddeven tableforfield centpercent">';
1155 print
'<tr><td class="titlefield">'.$langs->trans(
"MailTopic").
'</td><td colspan="3">'.$object->sujet.
'</td></tr>';
1158 print
'<tr><td>'.$langs->trans(
"MailFile").
'</td><td colspan="3">';
1160 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
1161 if (count($listofpaths)) {
1162 foreach ($listofpaths as $key => $val) {
1163 print
img_mime($listofpaths[$key][
'name']).
' '.$listofpaths[$key][
'name'];
1167 print
'<span class="opacitymedium">'.$langs->trans(
"NoAttachedFiles").
'</span><br>';
1179 print
'<div style="padding-top: 10px; background: '.($object->bgcolor ? (preg_match(
'/^#/', $object->bgcolor) ?
'' :
'#').$object->bgcolor :
'white').
'">';
1180 if (empty($object->bgcolor) || strtolower($object->bgcolor) ==
'ffffff') {
1183 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1184 $doleditor =
new DolEditor(
'bodyemail', $object->body,
'', 600,
'dolibarr_mailings',
'',
false,
true, empty($conf->global->FCKEDITOR_ENABLE_MAILING) ? 0 : 1, 20,
'90%', $readonly);
1185 $doleditor->Create();
1199 $linkback =
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
1201 $morehtmlright =
'';
1202 if ($object->statut == 2) {
1203 $morehtmlright .=
' ('.$object->countNbOfTargets(
'alreadysent').
'/'.$object->nbemail.
') ';
1206 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref',
'',
'', 0,
'', $morehtmlright);
1208 print
'<div class="fichecenter">';
1209 print
'<div class="underbanner clearboth"></div>';
1211 print
'<table class="border centpercent">';
1221 print
'<tr><td class="titlefield">'.$langs->trans(
"MailTitle").
'</td><td colspan="3">'.$object->title.
'</td></tr>';
1223 print
'<tr><td class="titlefield">'.$langs->trans(
"MailFrom").
'</td><td colspan="3">'.
dol_print_email($object->email_from, 0, 0, 0, 0, 1).
'</td></tr>';
1225 print
'<tr><td>'.$langs->trans(
"MailErrorsTo").
'</td><td colspan="3">'.
dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1).
'</td></tr>';
1229 print $langs->trans(
"TotalNbOfDistinctRecipients");
1230 print
'</td><td colspan="3">';
1231 $nbemail = ($object->nbemail ? $object->nbemail : 0);
1232 if (is_numeric($nbemail)) {
1234 if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || $object->statut == 2)) {
1235 if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) {
1236 $text .= $langs->trans(
'LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
1238 $text .= $langs->trans(
'SendingFromWebInterfaceIsNotAllowed');
1241 if (empty($nbemail)) {
1242 $nbemail .=
' '.img_warning(
'').
' <span class="warning">'.$langs->trans(
"NoTargetYet").
'</span>';
1245 print
$form->textwithpicto($nbemail, $text, 1,
'warning');
1254 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
1255 print $hookmanager->resPrint;
1256 if (empty($reshook)) {
1257 print $object->showOptionals($extrafields,
'edit',
$parameters);
1269 print
'<form name="edit_mailing" action="card.php" method="post" enctype="multipart/form-data">'.
"\n";
1270 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1271 print
'<input type="hidden" name="action" value="update">';
1272 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1274 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
1275 foreach ($object->substitutionarray as $key => $val) {
1276 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1278 $htmltext .=
'</i>';
1281 print
load_fiche_titre($langs->trans(
"EMail"),
$form->textwithpicto($langs->trans(
"AvailableVariables"), $htmltext, 1,
'help',
'', 0, 2,
'emailsubstitionhelp'),
'generic');
1285 print
'<table class="bordernooddeven" width="100%">';
1288 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>';
1294 $addfileaction =
'addfile';
1295 print
'<tr><td>'.$langs->trans(
"MailFile").
'</td>';
1296 print
'<td colspan="3">';
1298 $listofpaths =
dol_dir_list($upload_dir,
'all', 0,
'',
'',
'name', SORT_ASC, 0);
1301 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
1302 $out .=
'<script type="text/javascript">';
1303 $out .=
'jQuery(document).ready(function () {';
1304 $out .=
' jQuery(".removedfile").click(function() {';
1305 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
1308 $out .=
'</script>'.
"\n";
1309 if (count($listofpaths)) {
1310 foreach ($listofpaths as $key => $val) {
1311 $out .=
'<div id="attachfile_'.$key.
'">';
1312 $out .=
img_mime($listofpaths[$key][
'name']).
' '.$listofpaths[$key][
'name'];
1313 $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.
'" />';
1314 $out .=
'<br></div>';
1322 $maxmin = $maxfilesizearray[
'maxmin'];
1324 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
1326 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
1328 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
1333 print
'<tr><td>'.$langs->trans(
"BackgroundColorByDefault").
'</td><td colspan="3">';
1334 print $htmlother->selectColor($object->bgcolor,
'bgcolor',
'', 0);
1340 print
'<div style="padding-top: 10px">';
1342 if ($action ==
'edit') {
1344 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1345 $doleditor =
new DolEditor(
'bodyemail', $object->body,
'', 600,
'dolibarr_mailings',
'',
true,
true,
getDolGlobalInt(
'FCKEDITOR_ENABLE_MAILING'), 20,
'90%');
1346 $doleditor->Create();
1348 if ($action ==
'edithtml') {
1350 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1351 $doleditor =
new DolEditor(
'bodyemail', $object->body,
'', 600,
'dolibarr_mailings',
'',
true,
true,
'ace', 20,
'90%');
1352 $doleditor->Create(0,
'',
false,
'HTML Source',
'php');
1360 print
'<div class="center">';
1361 print
'<input type="submit" class="button buttonforacesave button-save" value="'.$langs->trans(
"Save").
'" name="save">';
1362 print
' ';
1363 print
'<input type="submit" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'" name="cancel">';