diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 739e635f85c..f705848743d 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -116,8 +116,8 @@ class HookManager * @param array $parameters Array of parameters * @param Object $object Object to use hooks on * @param string $action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...) - * @return mixed For 'addreplace hooks (doActions,formObjectOptions,pdf_xxx,...): Return 0 if we want to keep standard actions, >0 if we want to stop standard actions, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results and set into ->resArray. - * For 'output' hooks (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...): Return 0, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results and set into ->resArray. + * @return mixed For 'addreplace' hooks (doActions,formObjectOptions,pdf_xxx,...): Return 0 if we want to keep standard actions, >0 if we want to stop standard actions, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results by hook and set into ->resArray for caller. + * For 'output' hooks (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...): Return 0, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results bu hook and set into ->resArray for caller. * All types can also return some values into an array ->results. * $this->error or this->errors are also defined by class called by this function if error. */ @@ -142,6 +142,7 @@ class HookManager 'formObjectOptions', 'formattachOptions', 'formBuilddocLineOptions', + 'formatNotificationMessage', 'getFormMail', 'getIdProfUrl', 'moveUploadedFile', diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index b4d713b7b7a..17e3b00b602 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -278,12 +278,20 @@ class Notify */ function send($notifcode, $object) { - global $user,$conf,$langs,$mysoc,$dolibarr_main_url_root; + global $user,$conf,$langs,$mysoc; + global $hookmanager; + global $dolibarr_main_url_root; if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0; include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('notification')); + dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id); $langs->load("other"); @@ -443,6 +451,14 @@ class Notify $message.= $mesg; if ($link) $message=dol_concatdesc($message,$urlwithroot.$link); + $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename); + $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) + { + if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; + if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; + } + $mailfile = new CMailFile( $subject, $sendto, @@ -637,7 +653,15 @@ class Notify if ($sendto) { - $mailfile = new CMailFile( + $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename); + $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) + { + if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; + if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; + } + + $mailfile = new CMailFile( $subject, $sendto, $replyto,