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) {
 
  647              if (method_exists($object, 
'fetch_thirdparty') && empty($object->thirdparty)) {
 
  648                $object->fetch_thirdparty();
 
  652              $subject = 
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
 
  653              $message = 
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
 
  655              $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
 
  656              $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
 
  662            $pdf_path = $dir_output.
"/".$ref.
".pdf";
 
  663            if (!
dol_is_file($pdf_path)||(is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
 
  667              $filepdf = $pdf_path;
 
  668              $filename_list[] = $filepdf;
 
  669              $mimetype_list[] = mime_content_type($filepdf);
 
  670              $mimefilename_list[] = $ref.
".pdf";
 
  673            $labeltouse = !empty($labeltouse) ? $labeltouse : 
'';
 
  676            if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
 
  678              if ($user->fk_user > 0) {
 
  679                $supervisoruser = 
new User($this->db);
 
  680                $supervisoruser->fetch($user->fk_user);
 
  681                if ($supervisoruser->email) {
 
  682                  $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
 
  685              dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
 
  686              $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
 
  687              $sendto = preg_replace(
'/,\s*,/', 
',', $sendto); 
 
  688              $sendto = preg_replace(
'/^[\s,]+/', 
'', $sendto); 
 
  689              $sendto = preg_replace(
'/[\s,]+$/', 
'', $sendto); 
 
  692            $parameters = array(
'notifcode'=>$notifcode, 
'sendto'=>$sendto, 
'replyto'=>$replyto, 
'file'=>$filename_list, 
'mimefile'=>$mimetype_list, 
'filename'=>$mimefilename_list, 
'outputlangs'=>$outputlangs, 
'labeltouse'=>$labeltouse);
 
  693            if (!isset($action)) {
 
  697            $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters, $object, $action); 
 
  698            if (empty($reshook)) {
 
  699              if (!empty($hookmanager->resArray[
'files'])) {
 
  700                $filename_list = $hookmanager->resArray[
'files'][
'file'];
 
  701                $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
 
  702                $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
 
  704              if (!empty($hookmanager->resArray[
'subject'])) {
 
  705                $subject .= $hookmanager->resArray[
'subject'];
 
  707              if (!empty($hookmanager->resArray[
'message'])) {
 
  708                $message .= $hookmanager->resArray[
'message'];
 
  731            if ($mailfile->sendfile()) {
 
  732              if ($obj->type_target == 
'touserid') {
 
  733                $sql = 
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, 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                $sql = 
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
 
  737                $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).
"')";
 
  739              if (!$this->db->query($sql)) {
 
  744              $this->errors[] = $mailfile->error;
 
  747            dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
 
  752        dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty($object->socid) ? 
'' : $object->socid));
 
  756      $this->errors[] = $this->db->lasterror();
 
  757      dol_syslog(
"Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
 
  764      foreach ($conf->global as $key => $val) {
 
  766        if ($val == 
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
 
  772        $threshold = (float) $reg[1];
 
  773        if (!empty($object->total_ht) && $object->total_ht <= $threshold) {
 
  774          dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
 
  778        $notifcodedefid = 
dol_getIdFromCode($this->db, $notifcode, 
'c_action_trigger', 
'code', 
'rowid');
 
  779        if ($notifcodedefid <= 0) {
 
  788        $appli = $mysoc->name;
 
  790        $subject = 
'['.$appli.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ? 
' '.$projtitle : 
'');
 
  792        switch ($notifcode) {
 
  793          case 'BILL_VALIDATE':
 
  794            $link = 
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  795            $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object, 
'invoice');
 
  796            $object_type = 
'facture';
 
  797            $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
 
  800            $link = 
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  801            $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object, 
'invoice');
 
  802            $object_type = 
'facture';
 
  803            $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
 
  805          case 'ORDER_VALIDATE':
 
  806            $link = 
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  807            $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object, 
'commande');
 
  808            $object_type = 
'order';
 
  809            $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
 
  812            $link = 
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  813            $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object, 
'commande');
 
  814            $object_type = 
'order';
 
  815            $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
 
  817          case 'PROPAL_VALIDATE':
 
  818            $link = 
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  819            $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object, 
'propal');
 
  820            $object_type = 
'propal';
 
  821            $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
 
  823          case 'PROPAL_CLOSE_SIGNED':
 
  824            $link = 
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  825            $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object, 
'propal');
 
  826            $object_type = 
'propal';
 
  827            $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
 
  829          case 'FICHINTER_ADD_CONTACT':
 
  830            $link = 
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  831            $dir_output = $conf->ficheinter->dir_output;
 
  832            $object_type = 
'ficheinter';
 
  833            $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
 
  835          case 'FICHINTER_VALIDATE':
 
  836            $link = 
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  837            $dir_output = $conf->facture->dir_output;
 
  838            $object_type = 
'ficheinter';
 
  839            $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
 
  841          case 'FICHINTER_CLOSE':
 
  842            $link = 
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  843            $dir_output = $conf->facture->dir_output;
 
  844            $object_type = 
'ficheinter';
 
  845            $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
 
  847          case 'ORDER_SUPPLIER_VALIDATE':
 
  848            $link = 
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  849            $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
 
  850            $object_type = 
'order_supplier';
 
  851            $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
 
  852            $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($langs));
 
  853            $mesg .= 
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
 
  855          case 'ORDER_SUPPLIER_APPROVE':
 
  856            $link = 
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  857            $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
 
  858            $object_type = 
'order_supplier';
 
  859            $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
 
  860            $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($langs));
 
  861            $mesg .= 
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
 
  863          case 'ORDER_SUPPLIER_SUBMIT':
 
  864            $link = 
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  865            $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
 
  866            $object_type = 
'order_supplier';
 
  867            $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
 
  868            $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($langs));
 
  869            $mesg .= 
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
 
  871          case 'ORDER_SUPPLIER_REFUSE':
 
  872            $link = 
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  873            $dir_output = $conf->fournisseur->dir_output.
'/commande/';
 
  874            $object_type = 
'order_supplier';
 
  875            $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
 
  876            $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($langs));
 
  877            $mesg .= 
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
 
  879          case 'SHIPPING_VALIDATE':
 
  880            $link = 
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  881            $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1, $object, 
'shipment');
 
  882            $object_type = 
'order_supplier';
 
  883            $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
 
  885          case 'EXPENSE_REPORT_VALIDATE':
 
  886            $link = 
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  887            $dir_output = $conf->expensereport->dir_output;
 
  888            $object_type = 
'expensereport';
 
  889            $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
 
  891          case 'EXPENSE_REPORT_APPROVE':
 
  892            $link = 
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  893            $dir_output = $conf->expensereport->dir_output;
 
  894            $object_type = 
'expensereport';
 
  895            $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
 
  897          case 'HOLIDAY_VALIDATE':
 
  898            $link = 
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  899            $dir_output = $conf->holiday->dir_output;
 
  900            $object_type = 
'holiday';
 
  901            $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
 
  903          case 'HOLIDAY_APPROVE':
 
  904            $link = 
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  905            $dir_output = $conf->holiday->dir_output;
 
  906            $object_type = 
'holiday';
 
  907            $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
 
  909          case 'ACTION_CREATE':
 
  910            $link = 
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
 
  911            $dir_output = $conf->agenda->dir_output;
 
  912            $object_type = 
'action';
 
  913            $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
 
  916            $object_type = $object->element;
 
  917            $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1, $object, $object_type);
 
  918            $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
 
  922        $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
 
  927          $filepdf = $pdf_path;
 
  928          $filename_list[] = $pdf_path;
 
  929          $mimetype_list[] = mime_content_type($filepdf);
 
  930          $mimefilename_list[] = $ref.
".pdf";
 
  936        $mailTemplateLabel = isset($conf->global->{$notifcode.
'_TEMPLATE'}) ? $conf->global->{$notifcode.
'_TEMPLATE'} : 
'';
 
  937        $emailTemplate = 
null;
 
  938        if (!empty($mailTemplateLabel)) {
 
  939          include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
 
  940          $formmail = 
new FormMail($this->db);
 
  941          $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $langs, 0, 1, $labeltouse);
 
  943        if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) {
 
  944          if (property_exists($object, 
'thirdparty')) {
 
  945            if (!($object->thirdparty instanceof 
Societe)) {
 
  946              $object->fetch_thirdparty();
 
  949            if ($object->thirdparty instanceof 
Societe && $object->thirdparty->default_lang && $object->thirdparty->default_lang != $langs->defaultlang) {
 
  951              $outputlangs->setDefaultLang($object->thirdparty->default_lang);
 
  952              $outputlangs->loadLangs(array(
'main', 
'other'));
 
  961          $message .= $langs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
 
  965          $message = nl2br($message);
 
  969        if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
 
  971          if ($user->fk_user > 0) {
 
  972            $supervisoruser = 
new User($this->db);
 
  973            $supervisoruser->fetch($user->fk_user);
 
  974            if ($supervisoruser->email) {
 
  975              $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
 
  978          dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
 
  979          $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
 
  980          $sendto = preg_replace(
'/,\s*,/', 
',', $sendto); 
 
  981          $sendto = preg_replace(
'/^[\s,]+/', 
'', $sendto); 
 
  982          $sendto = preg_replace(
'/[\s,]+$/', 
'', $sendto); 
 
  986          $parameters = array(
'notifcode'=>$notifcode, 
'sendto'=>$sendto, 
'replyto'=>$replyto, 
'file'=>$filename_list, 
'mimefile'=>$mimetype_list, 
'filename'=>$mimefilename_list, 
'subject'=>&$subject, 
'message'=>&$message);
 
  987          $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters, $object, $action); 
 
  988          if (empty($reshook)) {
 
  989            if (!empty($hookmanager->resArray[
'files'])) {
 
  990              $filename_list = $hookmanager->resArray[
'files'][
'file'];
 
  991              $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
 
  992              $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
 
  994            if (!empty($hookmanager->resArray[
'subject'])) {
 
  995              $subject .= $hookmanager->resArray[
'subject'];
 
  997            if (!empty($hookmanager->resArray[
'message'])) {
 
  998              $message .= $hookmanager->resArray[
'message'];
 
 1020          if ($mailfile->sendfile()) {
 
 1021            $sql = 
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
 
 1022            $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).
"')";
 
 1023            if (!$this->db->query($sql)) {
 
 1028            $this->errors[] = $mailfile->error;