359 public function send($notifcode, $object, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
361 global $user, $conf, $langs, $mysoc;
363 global $dolibarr_main_url_root;
367 if (!is_object($hookmanager)) {
368 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
371 $hookmanager->initHooks(array(
'notification'));
373 $parameters = array(
'notifcode' => $notifcode);
374 $reshook = $hookmanager->executeHooks(
'notifsupported', $parameters, $object, $action);
375 if (empty($reshook)) {
376 if (!empty($hookmanager->resArray[
'arrayofnotifsupported'])) {
377 Notify::$arrayofnotifsupported = array_merge(Notify::$arrayofnotifsupported, $hookmanager->resArray[
'arrayofnotifsupported']);
382 if (!in_array($notifcode, Notify::$arrayofnotifsupported)) {
386 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
388 dol_syslog(get_class($this).
"::send notifcode=".$notifcode.
", object id=".$object->id);
390 $langs->load(
"other");
393 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
394 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
398 $application =
'Dolibarr';
400 $application = $conf->global->MAIN_APPLICATION_TITLE;
402 $replyto = $conf->notification->email_from;
408 $oldref = (empty($object->oldref) ? $object->ref : $object->oldref);
409 $newref = (empty($object->newref) ? $object->ref : $object->newref);
414 if (!empty($object->socid) && $object->socid > 0) {
415 $sql .=
"SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
416 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
417 $sql .=
" FROM ".$this->db->prefix().
"socpeople as c,";
418 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
419 $sql .=
" ".$this->db->prefix().
"notify_def as n,";
420 $sql .=
" ".$this->db->prefix().
"societe as s";
421 $sql .=
" WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
422 $sql .=
" AND n.fk_soc = s.rowid";
423 $sql .=
" AND c.statut = 1";
424 if (is_numeric($notifcode)) {
425 $sql .=
" AND n.fk_action = ".((int) $notifcode);
427 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
429 $sql .=
" AND s.rowid = ".((int) $object->socid);
435 $sql .=
"SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
436 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
437 $sql .=
" FROM ".$this->db->prefix().
"user as c,";
438 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
439 $sql .=
" ".$this->db->prefix().
"notify_def as n";
440 $sql .=
" WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
441 $sql .=
" AND c.statut = 1";
442 if (is_numeric($notifcode)) {
443 $sql .=
" AND n.fk_action = ".((int) $notifcode);
445 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
453 $result = $this->db->query($sql);
455 $num = $this->db->num_rows($result);
457 if (is_object($object->project) || $object->fetch_project() > 0) {
458 $projtitle =
'('.$object->project->title.
')';
463 while ($i < $num && !$error) {
464 $obj = $this->db->fetch_object($result);
467 $notifcodedefid = $obj->adid;
469 if ($obj->type_target ==
'tocontactid') {
470 $trackid =
'ctc'.$obj->cid;
472 if ($obj->type_target ==
'touserid') {
473 $trackid =
'use'.$obj->cid;
478 $outputlangs = $langs;
479 if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
481 $outputlangs->setDefaultLang($obj->default_lang);
482 $outputlangs->loadLangs(array(
"main",
"other"));
485 $appli = $mysoc->name;
487 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
489 switch ($notifcode) {
490 case 'BILL_VALIDATE':
491 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
492 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
493 $object_type =
'facture';
494 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
497 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
498 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
499 $object_type =
'facture';
500 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
502 case 'ORDER_VALIDATE':
503 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
504 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'commande');
505 $object_type =
'order';
506 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
509 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
510 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'commande');
511 $object_type =
'order';
512 $labeltouse = $conf->global->ORDER_CLOSE_TEMPLATE;
513 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
515 case 'PROPAL_VALIDATE':
516 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
517 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
518 $object_type =
'propal';
519 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
521 case 'PROPAL_CLOSE_REFUSED':
522 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
523 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
524 $object_type =
'propal';
525 $labeltouse = $conf->global->PROPAL_CLOSE_REFUSED_TEMPLATE;
526 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedRefused", $link);
527 if (!empty($object->context[
'closedfromonlinesignature'])) {
528 $mesg .=
' - From online page';
531 case 'PROPAL_CLOSE_SIGNED':
532 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
533 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
534 $object_type =
'propal';
535 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
536 if (!empty($object->context[
'closedfromonlinesignature'])) {
537 $mesg .=
' - From online page';
540 case 'FICHINTER_ADD_CONTACT':
541 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
542 $dir_output = $conf->ficheinter->dir_output;
543 $object_type =
'ficheinter';
544 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
546 case 'FICHINTER_VALIDATE':
547 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
548 $dir_output = $conf->ficheinter->dir_output;
549 $object_type =
'ficheinter';
550 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
552 case 'FICHINTER_CLOSE':
553 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
554 $dir_output = $conf->ficheinter->dir_output;
555 $object_type =
'ficheinter';
556 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
558 case 'ORDER_SUPPLIER_VALIDATE':
559 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
560 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
561 $object_type =
'order_supplier';
562 $labeltouse = isset($conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE :
'';
563 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
564 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($outputlangs));
565 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
567 case 'ORDER_SUPPLIER_APPROVE':
568 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
569 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
570 $object_type =
'order_supplier';
571 $labeltouse = isset($conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE :
'';
572 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
573 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($outputlangs));
574 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
576 case 'ORDER_SUPPLIER_SUBMIT':
577 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
578 $dir_output = $conf->fournisseur->commande->dir_output;
579 $object_type =
'order_supplier';
580 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
581 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($outputlangs));
582 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
584 case 'ORDER_SUPPLIER_REFUSE':
585 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
586 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
587 $object_type =
'order_supplier';
588 $labeltouse = isset($conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE :
'';
589 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
590 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($outputlangs));
591 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
593 case 'SHIPPING_VALIDATE':
594 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
595 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1, $object,
'shipment');
596 $object_type =
'shipping';
597 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
599 case 'EXPENSE_REPORT_VALIDATE':
600 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
601 $dir_output = $conf->expensereport->dir_output;
602 $object_type =
'expensereport';
603 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
605 case 'EXPENSE_REPORT_APPROVE':
606 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
607 $dir_output = $conf->expensereport->dir_output;
608 $object_type =
'expensereport';
609 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
611 case 'HOLIDAY_VALIDATE':
612 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
613 $dir_output = $conf->holiday->dir_output;
614 $object_type =
'holiday';
615 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
617 case 'HOLIDAY_APPROVE':
618 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
619 $dir_output = $conf->holiday->dir_output;
620 $object_type =
'holiday';
621 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
623 case 'ACTION_CREATE':
624 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
625 $dir_output = $conf->agenda->dir_output;
626 $object_type =
'action';
627 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
630 $object_type = $object->element;
631 $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1, $object, $object_type);
632 $template = $notifcode.
'_TEMPLATE';
633 $mesg = $outputlangs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref.
' '.$dir_output;
637 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
638 $formmail =
new FormMail($this->db);
639 $arraydefaultmessage =
null;
641 $template = $notifcode.
'_TEMPLATE';
643 if (!empty($labeltouse)) {
644 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $labeltouse);
646 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
649 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
650 $message =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
652 $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
653 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
659 $pdf_path = $dir_output.
"/".$ref.
".pdf";
660 if (!
dol_is_file($pdf_path)||(is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
664 $filepdf = $pdf_path;
665 $filename_list[] = $filepdf;
666 $mimetype_list[] = mime_content_type($filepdf);
667 $mimefilename_list[] = $ref.
".pdf";
670 $labeltouse = !empty($labeltouse) ? $labeltouse :
'';
673 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
675 if ($user->fk_user > 0) {
676 $supervisoruser =
new User($this->db);
677 $supervisoruser->fetch($user->fk_user);
678 if ($supervisoruser->email) {
679 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
682 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
683 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
684 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
685 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
686 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
689 $parameters = array(
'notifcode'=>$notifcode,
'sendto'=>$sendto,
'replyto'=>$replyto,
'file'=>$filename_list,
'mimefile'=>$mimetype_list,
'filename'=>$mimefilename_list,
'outputlangs'=>$outputlangs,
'labeltouse'=>$labeltouse);
690 if (!isset($action)) {
694 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters, $object, $action);
695 if (empty($reshook)) {
696 if (!empty($hookmanager->resArray[
'files'])) {
697 $filename_list = $hookmanager->resArray[
'files'][
'file'];
698 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
699 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
701 if (!empty($hookmanager->resArray[
'subject'])) {
702 $subject .= $hookmanager->resArray[
'subject'];
704 if (!empty($hookmanager->resArray[
'message'])) {
705 $message .= $hookmanager->resArray[
'message'];
728 if ($mailfile->sendfile()) {
729 if ($obj->type_target ==
'touserid') {
730 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
731 $sql .=
" VALUES ('".$this->db->idate(
dol_now()).
"', ".((int) $notifcodedefid).
", ".($object->socid > 0 ? ((int) $object->socid) :
'null').
", ".((
int) $obj->cid).
", '".$this->db->escape($obj->type).
"', '".$this->db->escape($object_type).
"', '".$this->db->escape($obj->type_target).
"', ".((int) $object->id).
", '".$this->db->escape($obj->email).
"')";
733 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
734 $sql .=
" VALUES ('".$this->db->idate(
dol_now()).
"', ".((int) $notifcodedefid).
", ".($object->socid > 0 ? ((int) $object->socid) :
'null').
", ".((
int) $obj->cid).
", '".$this->db->escape($obj->type).
"', '".$this->db->escape($object_type).
"', '".$this->db->escape($obj->type_target).
"', ".((int) $object->id).
", '".$this->db->escape($obj->email).
"')";
736 if (!$this->db->query($sql)) {
741 $this->errors[] = $mailfile->error;
744 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
749 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty($object->socid) ?
'' : $object->socid));
753 $this->errors[] = $this->db->lasterror();
754 dol_syslog(
"Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
761 foreach ($conf->global as $key => $val) {
763 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
769 $threshold = (float) $reg[1];
770 if (!empty($object->total_ht) && $object->total_ht <= $threshold) {
771 dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
775 $notifcodedefid =
dol_getIdFromCode($this->db, $notifcode,
'c_action_trigger',
'code',
'rowid');
776 if ($notifcodedefid <= 0) {
785 $appli = $mysoc->name;
787 $subject =
'['.$appli.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
789 switch ($notifcode) {
790 case 'BILL_VALIDATE':
791 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
792 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
793 $object_type =
'facture';
794 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
797 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
798 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
799 $object_type =
'facture';
800 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
802 case 'ORDER_VALIDATE':
803 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
804 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'commande');
805 $object_type =
'order';
806 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
809 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
810 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'commande');
811 $object_type =
'order';
812 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
814 case 'PROPAL_VALIDATE':
815 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
816 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
817 $object_type =
'propal';
818 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
820 case 'PROPAL_CLOSE_SIGNED':
821 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
822 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
823 $object_type =
'propal';
824 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
826 case 'FICHINTER_ADD_CONTACT':
827 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
828 $dir_output = $conf->ficheinter->dir_output;
829 $object_type =
'ficheinter';
830 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
832 case 'FICHINTER_VALIDATE':
833 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
834 $dir_output = $conf->facture->dir_output;
835 $object_type =
'ficheinter';
836 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
838 case 'FICHINTER_CLOSE':
839 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
840 $dir_output = $conf->facture->dir_output;
841 $object_type =
'ficheinter';
842 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
844 case 'ORDER_SUPPLIER_VALIDATE':
845 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
846 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
847 $object_type =
'order_supplier';
848 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
849 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($langs));
850 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
852 case 'ORDER_SUPPLIER_APPROVE':
853 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
854 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
855 $object_type =
'order_supplier';
856 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
857 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($langs));
858 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
860 case 'ORDER_SUPPLIER_SUBMIT':
861 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
862 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
863 $object_type =
'order_supplier';
864 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
865 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($langs));
866 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
868 case 'ORDER_SUPPLIER_REFUSE':
869 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
870 $dir_output = $conf->fournisseur->dir_output.
'/commande/';
871 $object_type =
'order_supplier';
872 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
873 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($langs));
874 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
876 case 'SHIPPING_VALIDATE':
877 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
878 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1, $object,
'shipment');
879 $object_type =
'order_supplier';
880 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
882 case 'EXPENSE_REPORT_VALIDATE':
883 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
884 $dir_output = $conf->expensereport->dir_output;
885 $object_type =
'expensereport';
886 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
888 case 'EXPENSE_REPORT_APPROVE':
889 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
890 $dir_output = $conf->expensereport->dir_output;
891 $object_type =
'expensereport';
892 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
894 case 'HOLIDAY_VALIDATE':
895 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
896 $dir_output = $conf->holiday->dir_output;
897 $object_type =
'holiday';
898 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
900 case 'HOLIDAY_APPROVE':
901 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
902 $dir_output = $conf->holiday->dir_output;
903 $object_type =
'holiday';
904 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
906 case 'ACTION_CREATE':
907 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
908 $dir_output = $conf->agenda->dir_output;
909 $object_type =
'action';
910 $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
913 $object_type = $object->element;
914 $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1, $object, $object_type);
915 $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
919 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
924 $filepdf = $pdf_path;
925 $filename_list[] = $pdf_path;
926 $mimetype_list[] = mime_content_type($filepdf);
927 $mimefilename_list[] = $ref.
".pdf";
933 $mailTemplateLabel = isset($conf->global->{$notifcode.
'_TEMPLATE'}) ? $conf->global->{$notifcode.
'_TEMPLATE'} :
'';
934 $emailTemplate =
null;
935 if (!empty($mailTemplateLabel)) {
936 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
937 $formmail =
new FormMail($this->db);
938 $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $langs, 0, 1, $labeltouse);
940 if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) {
947 $message .= $langs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
951 $message = nl2br($message);
955 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
957 if ($user->fk_user > 0) {
958 $supervisoruser =
new User($this->db);
959 $supervisoruser->fetch($user->fk_user);
960 if ($supervisoruser->email) {
961 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
964 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
965 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
966 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
967 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
968 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
972 $parameters = array(
'notifcode'=>$notifcode,
'sendto'=>$sendto,
'replyto'=>$replyto,
'file'=>$filename_list,
'mimefile'=>$mimetype_list,
'filename'=>$mimefilename_list,
'subject'=>&$subject,
'message'=>&$message);
973 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters, $object, $action);
974 if (empty($reshook)) {
975 if (!empty($hookmanager->resArray[
'files'])) {
976 $filename_list = $hookmanager->resArray[
'files'][
'file'];
977 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
978 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
980 if (!empty($hookmanager->resArray[
'subject'])) {
981 $subject .= $hookmanager->resArray[
'subject'];
983 if (!empty($hookmanager->resArray[
'message'])) {
984 $message .= $hookmanager->resArray[
'message'];
1006 if ($mailfile->sendfile()) {
1007 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
1008 $sql .=
" VALUES ('".$this->db->idate(
dol_now()).
"', ".((int) $notifcodedefid).
", ".($object->socid > 0 ? ((int) $object->socid) :
'null').
", null, 'email', 'tofixedemail', '".$this->db->escape($object_type).
"', ".((int) $object->id).
", '".$this->db->escape($sendto).
"')";
1009 if (!$this->db->query($sql)) {
1014 $this->errors[] = $mailfile->error;