2004-10-20 23:06:45 +02:00
< ? php
2005-03-15 21:25:19 +01:00
/* Copyright ( C ) 2003 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2011-09-03 02:14:27 +02:00
* Copyright ( C ) 2004 - 2011 Laurent Destailleur < eldy @ users . sourceforge . net >
2014-11-06 11:20:47 +01:00
* Copyright ( C ) 2014 Juanjo Menent < jmenent @ 2 byte . es >
2018-09-29 14:51:52 +02:00
* Copyright ( C ) 2018 Philippe Grand < philippe . grand @ atoo - net . com >
2021-03-19 11:50:15 +01:00
* Copyright ( C ) 2021 Thibault FOUCART < support @ ptibogxiv . net >
2022-03-12 16:50:48 +01:00
* Copyright ( C ) 2022 Anthony Berton < anthony . berton @ bb2a . fr >
2023-10-05 12:11:39 +02:00
* Copyright ( C ) 2023 William Mead < william . mead @ manchenumerique . fr >
2024-03-16 10:08:19 +01:00
* Copyright ( C ) 2024 Jon Bendtsen < jon . bendtsen . github @ jonb . dk >
2024-10-26 22:43:44 +02:00
* Copyright ( C ) 2024 MDW < mdeweerd @ users . noreply . github . com >
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2003-06-30 19:33:53 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2003-06-30 19:33:53 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2003-06-30 19:33:53 +02:00
*/
2005-03-15 21:25:19 +01:00
/**
2010-11-22 10:18:53 +01:00
* \file htdocs / core / class / notify . class . php
2011-06-19 16:35:16 +02:00
* \ingroup notification
* \brief File of class to manage notifications
2010-11-22 10:18:53 +01:00
*/
2019-12-03 11:17:29 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
2005-01-09 19:30:34 +01:00
2024-03-19 15:55:37 +01:00
2005-07-14 15:03:20 +02:00
/**
2024-03-19 15:55:37 +01:00
* Class to manage the table of subscription to notifications
2010-11-22 10:18:53 +01:00
*/
2005-01-09 19:30:34 +01:00
class Notify
2003-06-30 19:33:53 +02:00
{
2018-10-01 17:14:28 +02:00
/**
* @ var int ID
*/
public $id ;
/**
2020-10-31 14:32:18 +01:00
* @ var DoliDB Database handler .
*/
public $db ;
2018-10-01 17:14:28 +02:00
2024-03-13 23:47:34 +01:00
/**
* @ var string type
*/
public $type ;
2024-03-14 18:30:19 +01:00
/**
2024-03-19 16:04:11 +01:00
* @ var string threshold
2024-03-14 18:30:19 +01:00
*/
2024-03-19 16:04:11 +01:00
public $threshold ;
2024-03-14 18:30:19 +01:00
2024-03-14 18:20:37 +01:00
/**
2024-03-19 16:04:11 +01:00
* @ var string context
2024-03-14 18:20:37 +01:00
*/
2024-03-19 16:04:11 +01:00
public $context ;
2024-03-14 18:20:37 +01:00
/**
2024-03-19 16:04:11 +01:00
* @ var int ID of event action that trigger the notification
2024-03-14 18:20:37 +01:00
*/
2024-03-19 16:04:11 +01:00
public $event ;
2024-03-14 18:20:37 +01:00
/**
2024-03-19 16:04:11 +01:00
* @ var int Third - party ID
2024-03-14 18:20:37 +01:00
*/
2024-03-19 16:04:11 +01:00
public $socid ;
2024-03-14 18:20:37 +01:00
2024-03-13 23:47:34 +01:00
/**
2024-03-19 16:04:11 +01:00
* @ var int ( Third - party ) Contact ID
2024-03-13 23:47:34 +01:00
*/
2024-03-19 16:04:11 +01:00
public $contact_id ;
2024-03-13 23:47:34 +01:00
2024-03-14 18:20:37 +01:00
/**
2024-03-19 16:04:11 +01:00
* @ var string fk_user
2024-03-14 18:20:37 +01:00
*/
2024-03-19 16:04:11 +01:00
public $fk_user ;
2024-03-14 18:20:37 +01:00
2024-03-19 16:04:11 +01:00
/**
* @ var string email
2024-03-14 18:20:37 +01:00
*/
2024-03-19 16:04:11 +01:00
public $email ;
2024-03-14 18:20:37 +01:00
2024-03-13 23:47:34 +01:00
/**
2024-03-13 23:51:49 +01:00
* Date creation record ( datec )
*
* @ var integer
2024-03-13 23:47:34 +01:00
*/
2024-03-13 23:51:49 +01:00
public $datec ;
/**
* Date modified record ( datem )
*
* @ var integer
*/
public $datem ;
2024-03-13 23:47:34 +01:00
2018-10-01 17:14:28 +02:00
/**
* @ var string Error code ( or message )
*/
2019-12-03 11:17:29 +01:00
public $error = '' ;
2018-10-01 17:14:28 +02:00
/**
* @ var string [] Error codes ( or messages )
*/
public $errors = array ();
2017-10-07 13:09:31 +02:00
2024-09-28 12:09:35 +02:00
/**
* @ var string
*/
2018-10-06 12:34:51 +02:00
public $author ;
2024-09-28 12:09:35 +02:00
/**
* @ var string
*/
2018-10-06 12:34:51 +02:00
public $ref ;
2024-09-28 12:09:35 +02:00
/**
* @ var int
*/
2018-10-06 12:34:51 +02:00
public $date ;
2024-09-28 12:09:35 +02:00
/**
* @ var int
*/
2018-10-06 12:34:51 +02:00
public $duree ;
2024-09-28 12:09:35 +02:00
/**
* @ var string
*/
2018-10-06 12:34:51 +02:00
public $note ;
2018-10-01 17:14:28 +02:00
/**
2020-10-31 14:32:18 +01:00
* @ var int Project ID
*/
public $fk_project ;
2005-07-14 15:03:20 +02:00
2021-12-01 12:00:19 +01:00
// This codes actions are defined into table llx_notify_def
2023-12-04 12:04:36 +01:00
public static $arrayofnotifsupported = array (
2024-03-15 20:56:12 +01:00
'BILL_CANCEL' ,
2017-10-07 13:09:31 +02:00
'BILL_VALIDATE' ,
'BILL_PAYED' ,
2024-03-15 20:56:12 +01:00
'ORDER_CANCEL' ,
2021-12-01 12:00:19 +01:00
'ORDER_CREATE' ,
2017-10-07 13:09:31 +02:00
'ORDER_VALIDATE' ,
2022-11-23 13:08:09 +01:00
'ORDER_CLOSE' ,
2017-10-07 13:09:31 +02:00
'PROPAL_VALIDATE' ,
'PROPAL_CLOSE_SIGNED' ,
2022-12-01 13:56:14 +01:00
'PROPAL_CLOSE_REFUSED' ,
2017-10-07 13:09:31 +02:00
'FICHINTER_VALIDATE' ,
2024-08-27 07:01:03 +02:00
'FICHINTER_MODIFY' ,
2023-10-05 12:11:39 +02:00
'FICHINTER_CLOSE' ,
2017-10-07 13:09:31 +02:00
'FICHINTER_ADD_CONTACT' ,
2024-05-25 14:38:35 +02:00
'ORDER_SUPPLIER_CANCEL' ,
2017-10-07 13:09:31 +02:00
'ORDER_SUPPLIER_VALIDATE' ,
'ORDER_SUPPLIER_APPROVE' ,
2023-09-08 16:53:49 +02:00
'ORDER_SUPPLIER_SUBMIT' ,
2017-10-07 13:09:31 +02:00
'ORDER_SUPPLIER_REFUSE' ,
2024-09-13 03:09:53 +02:00
'SHIPPING_MODIFY' ,
2018-10-25 12:45:13 +02:00
'SHIPPING_VALIDATE' ,
'EXPENSE_REPORT_VALIDATE' ,
'EXPENSE_REPORT_APPROVE' ,
2021-07-22 09:22:42 +02:00
'HOLIDAY_VALIDATE' ,
'HOLIDAY_APPROVE' ,
2024-09-10 03:04:49 +02:00
'ACTION_CREATE' ,
'CONTRACT_MODIFY'
2017-10-07 13:09:31 +02:00
);
/**
2011-09-03 02:14:27 +02:00
* Constructor
*
2011-11-06 15:12:18 +01:00
* @ param DoliDB $db Database handler
2017-10-07 13:09:31 +02:00
*/
2019-02-26 22:42:19 +01:00
public function __construct ( $db )
2017-10-07 13:09:31 +02:00
{
$this -> db = $db ;
}
/**
* Return message that say how many notification ( and to which email ) will occurs on requested event .
* This is to show confirmation messages before event is recorded .
*
* @ param string $action Id of action in llx_c_action_trigger
* @ param int $socid Id of third party
* @ param Object $object Object the notification is about
* @ return string Message
*/
2019-02-26 22:42:19 +01:00
public function confirmMessage ( $action , $socid , $object )
2006-08-05 18:44:43 +02:00
{
2024-03-19 15:55:37 +01:00
global $langs ;
2006-08-05 18:44:43 +02:00
$langs -> load ( " mails " );
2009-06-30 13:59:46 +02:00
2021-12-23 15:12:35 +01:00
// Get full list of all notifications subscribed for $action, $socid and $object
2019-12-03 11:17:29 +01:00
$listofnotiftodo = $this -> getNotificationsArray ( $action , $socid , $object , 0 );
2021-12-23 15:12:35 +01:00
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_USER' )) {
2021-04-29 00:03:16 +02:00
foreach ( $listofnotiftodo as $val ) {
if ( $val [ 'type' ] == 'touser' ) {
unset ( $listofnotiftodo [ $val [ 'email' ]]);
2021-10-24 13:15:01 +02:00
//$listofnotiftodo = array_merge($listofnotiftodo);
2021-04-08 13:37:09 +02:00
}
}
2021-04-29 00:03:16 +02:00
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT' )) {
2021-12-23 15:12:35 +01:00
foreach ( $listofnotiftodo as $val ) {
if ( $val [ 'type' ] == 'tocontact' ) {
unset ( $listofnotiftodo [ $val [ 'email' ]]);
//$listofnotiftodo = array_merge($listofnotiftodo);
}
}
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_FIX' )) {
2021-04-29 00:03:16 +02:00
foreach ( $listofnotiftodo as $val ) {
if ( $val [ 'type' ] == 'tofixedemail' ) {
unset ( $listofnotiftodo [ $val [ 'email' ]]);
2021-10-24 13:15:01 +02:00
//$listofnotiftodo = array_merge($listofnotiftodo);
2021-04-08 13:37:09 +02:00
}
}
}
2017-10-06 14:05:13 +02:00
2020-12-24 02:59:00 +01:00
$texte = '' ;
2019-12-03 11:17:29 +01:00
$nb = - 1 ;
2020-12-20 11:04:21 +01:00
if ( is_array ( $listofnotiftodo )) {
$nb = count ( $listofnotiftodo );
}
if ( $nb < 0 ) {
2023-09-03 22:45:47 +02:00
$texte = img_object ( $langs -> trans ( " Notifications " ), 'email' , 'class="pictofixedwidth"' ) . $langs -> trans ( " ErrorFailedToGetListOfNotificationsToSend " );
2020-12-20 11:04:21 +01:00
} elseif ( $nb == 0 ) {
2023-09-03 22:45:47 +02:00
$texte = img_object ( $langs -> trans ( " Notifications " ), 'email' , 'class="pictofixedwidth"' ) . $langs -> trans ( " NoNotificationsWillBeSent " );
2020-12-20 11:04:21 +01:00
} elseif ( $nb == 1 ) {
2023-09-03 22:45:47 +02:00
$texte = img_object ( $langs -> trans ( " Notifications " ), 'email' , 'class="pictofixedwidth"' ) . $langs -> trans ( " ANotificationsWillBeSent " );
2024-03-30 23:56:37 +01:00
} else { // Always >= 2 if ($nb >= 2) {
2023-09-03 22:45:47 +02:00
$texte = img_object ( $langs -> trans ( " Notifications " ), 'email' , 'class="pictofixedwidth"' ) . $langs -> trans ( " SomeNotificationsWillBeSent " , $nb );
2020-12-20 11:04:21 +01:00
}
if ( is_array ( $listofnotiftodo )) {
2019-12-03 11:17:29 +01:00
$i = 0 ;
2020-12-28 12:38:33 +01:00
foreach ( $listofnotiftodo as $val ) {
2020-12-20 11:04:21 +01:00
if ( $i ) {
$texte .= ', ' ;
} else {
$texte .= ' (' ;
}
if ( $val [ 'isemailvalid' ]) {
$texte .= $val [ 'email' ];
} else {
$texte .= $val [ 'emaildesc' ];
}
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2020-12-20 11:04:21 +01:00
if ( $i ) {
$texte .= ')' ;
}
}
2017-10-06 14:05:13 +02:00
2006-08-05 18:44:43 +02:00
return $texte ;
}
2009-06-30 13:59:46 +02:00
2024-03-13 23:09:47 +01:00
/**
* Delete a notification from database
*
2024-09-29 21:52:31 +02:00
* @ param ? User $user User deleting
2024-03-13 23:09:47 +01:00
* @ return int Return integer < 0 if KO , > 0 if OK
*/
2024-09-29 21:52:31 +02:00
public function delete ( $user = null )
2024-03-13 23:09:47 +01:00
{
$error = 0 ;
dol_syslog ( get_class ( $this ) . " ::delete " . $this -> id , LOG_DEBUG );
$this -> db -> begin ();
if ( ! $error ) {
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " notify_def " ;
$sql .= " WHERE rowid = " . (( int ) $this -> id );
if ( ! $this -> db -> query ( $sql )) {
$error ++ ;
$this -> errors [] = $this -> db -> lasterror ();
}
}
if ( ! $error ) {
$this -> db -> commit ();
return 1 ;
} else {
$this -> db -> rollback ();
return - 1 * $error ;
}
}
2024-03-16 09:45:55 +01:00
/**
* Create notification information record .
*
2024-09-29 21:52:31 +02:00
* @ param ? User $user User
* @ param int < 0 , 1 > $notrigger 1 = Disable triggers
2024-03-16 09:45:55 +01:00
* @ return int Return integer < 0 if KO , > 0 if OK ( ID of newly created company notification information )
*/
2024-09-29 21:52:31 +02:00
public function create ( $user = null , $notrigger = 0 )
2024-03-16 09:45:55 +01:00
{
$now = dol_now ();
$error = 0 ;
// Check parameters
if ( empty ( $this -> socid )) {
$this -> error = 'BadValueForParameter' ;
$this -> errors [] = $this -> error ;
return - 1 ;
}
if ( empty ( $this -> datec )) {
$this -> datec = $now ;
}
$this -> db -> begin ();
2024-03-16 10:57:53 +01:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " notify_def (fk_soc, fk_action, fk_contact, type, datec) " ;
2024-03-19 16:04:11 +01:00
$sql .= " VALUES ( " . (( int ) $this -> socid ) . " , " . (( int ) $this -> event ) . " , " . (( int ) $this -> contact_id ) . " , " ;
2024-03-16 10:57:53 +01:00
$sql .= " ' " . $this -> db -> escape ( $this -> type ) . " ', ' " . $this -> db -> idate ( $this -> datec ) . " ') " ;
2024-03-19 16:04:11 +01:00
2024-03-16 09:45:55 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
if ( $this -> db -> affected_rows ( $resql )) {
$this -> id = $this -> db -> last_insert_id ( MAIN_DB_PREFIX . " notify_def " );
}
} else {
$error ++ ;
$this -> error = $this -> db -> lasterror ();
$this -> errors [] = $this -> error ;
}
if ( ! $error ) {
$this -> db -> commit ();
return $this -> id ;
} else {
$this -> db -> rollback ();
return - 1 ;
}
}
2024-03-13 23:09:47 +01:00
/**
* Load record from database
*
* @ param int $id Id of record
* @ param int $socid Id of company . If this is filled , function will return only records belonging to this thirdparty
* @ param string $type If id of company filled , we say if we want record of this type only
* @ return int Return integer < 0 if KO , > 0 if OK
*/
public function fetch ( $id , $socid = 0 , $type = 'email' )
{
if ( empty ( $id ) && empty ( $socid )) {
return - 1 ;
}
2024-03-19 16:04:11 +01:00
$sql = " SELECT rowid, fk_action as event, fk_soc as socid, fk_contact as contact_id, type, datec, tms as datem " ;
2024-03-13 23:09:47 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " notify_def " ;
if ( $id ) {
$sql .= " WHERE rowid = " . (( int ) $id );
} elseif ( $socid > 0 ) {
$sql .= " WHERE fk_soc = " . (( int ) $socid );
if ( $type ) {
$sql .= " AND type = ' " . $this -> db -> escape ( $type ) . " ' " ;
}
}
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
if ( $this -> db -> num_rows ( $resql )) {
$obj = $this -> db -> fetch_object ( $resql );
$this -> id = $obj -> rowid ;
$this -> type = $obj -> type ;
$this -> event = $obj -> event ;
2024-03-19 16:04:11 +01:00
$this -> socid = $obj -> socid ;
$this -> contact_id = $obj -> contact_id ;
2024-03-13 23:09:47 +01:00
$this -> fk_user = $obj -> fk_user ;
$this -> email = $obj -> email ;
$this -> threshold = $obj -> threshold ;
$this -> context = $obj -> context ;
2024-03-19 16:04:11 +01:00
$this -> datec = $this -> db -> jdate ( $obj -> datec );
$this -> datem = $this -> db -> jdate ( $obj -> datem );
2024-03-13 23:09:47 +01:00
}
$this -> db -> free ( $resql );
return 1 ;
} else {
dol_print_error ( $this -> db );
return - 1 ;
}
}
2024-03-15 23:51:57 +01:00
/**
* Update record in database
*
2024-09-29 21:52:31 +02:00
* @ param ? User $user Object user
* @ param int < 0 , 1 > $notrigger 1 = Disable triggers
2024-03-15 23:51:57 +01:00
* @ return int Return integer <= 0 if KO , > 0 if OK
*/
2024-09-29 21:52:31 +02:00
public function update ( $user = null , $notrigger = 0 )
2024-03-15 23:51:57 +01:00
{
global $langs ;
$error = 0 ;
if ( ! $this -> id ) {
return - 1 ;
}
$this -> db -> begin ();
$sql = " UPDATE " . MAIN_DB_PREFIX . " notify_def SET " ;
$sql .= " type = ' " . $this -> db -> escape ( $this -> type ) . " ' " ;
2024-03-19 16:04:11 +01:00
// $sql .= ",fk_user = ".((int) $this->fk_user);
// $sql .= ",email = '".$this->db->escape($this->email)."'";
// $sql .= ",threshold = '".$this->db->escape($this->threshold)."'";
// $sql .= ",context = '".$this->db->escape($this->context)."'";
$sql .= " ,fk_soc = " . (( int ) $this -> socid );
$sql .= " ,fk_action = " . (( int ) $this -> event );
$sql .= " ,fk_contact = " . (( int ) $this -> contact_id );
2024-03-15 23:51:57 +01:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
$result = $this -> db -> query ( $sql );
2024-03-16 00:15:40 +01:00
if ( ! $result ) {
2024-03-15 23:51:57 +01:00
$error ++ ;
if ( $this -> db -> errno () == 'DB_ERROR_RECORD_ALREADY_EXISTS' ) {
$this -> error = $langs -> trans ( 'ErrorDuplicateField' );
} else {
$this -> error = $this -> db -> lasterror ();
}
$this -> errors [] = $this -> error ;
}
if ( ! $error ) {
$this -> db -> commit ();
return 1 ;
} else {
$this -> db -> rollback ();
return - 1 ;
}
}
2024-03-13 23:09:47 +01:00
2017-10-07 13:09:31 +02:00
/**
2024-03-19 15:55:37 +01:00
* Return number of notifications activated , for all or a given action code ( and third party )
2017-10-07 13:09:31 +02:00
*
2024-10-26 22:43:44 +02:00
* @ param string $notifcode Code of action in llx_c_action_trigger ( new usage ) or Id of action in llx_c_action_trigger ( old usage )
* @ param int $socid Id of third party or 0 for all thirdparties or - 1 for no thirdparties
* @ param CommonObject $object Object the notification is about ( need it to check threshold value of some notifications )
* @ param int $userid Id of user or 0 for all users or - 1 for no users
* @ param array $scope Scope where to search
* @ return array | int Return integer < 0 if KO , array of notifications to send if OK
2017-10-07 13:09:31 +02:00
*/
2019-02-26 22:42:19 +01:00
public function getNotificationsArray ( $notifcode , $socid = 0 , $object = null , $userid = 0 , $scope = array ( 'thirdparty' , 'user' , 'global' ))
2006-08-05 18:44:43 +02:00
{
2015-04-13 17:04:18 +02:00
global $conf , $user ;
2011-06-19 16:35:16 +02:00
2019-12-03 11:17:29 +01:00
$error = 0 ;
$resarray = array ();
2017-10-07 13:09:31 +02:00
$valueforthreshold = 0 ;
2020-12-20 11:04:21 +01:00
if ( is_object ( $object )) {
$valueforthreshold = $object -> total_ht ;
}
2020-12-24 02:59:00 +01:00
$sqlnotifcode = '' ;
2020-12-20 11:04:21 +01:00
if ( $notifcode ) {
if ( is_numeric ( $notifcode )) {
2021-06-09 15:36:47 +02:00
$sqlnotifcode = " AND n.fk_action = " . (( int ) $notifcode ); // Old usage
2020-12-20 11:04:21 +01:00
} else {
$sqlnotifcode = " AND a.code = ' " . $this -> db -> escape ( $notifcode ) . " ' " ; // New usage
}
}
2014-10-25 00:42:52 +02:00
2024-03-19 15:55:37 +01:00
// Subscription per contact
2020-12-20 11:04:21 +01:00
if ( ! $error ) {
if ( $socid >= 0 && in_array ( 'thirdparty' , $scope )) {
2024-06-22 16:07:46 +02:00
$sql = " SELECT a.code, c.email, c.rowid, c.statut as status " ;
2022-01-27 10:19:35 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " notify_def as n, " ;
$sql .= " " . $this -> db -> prefix () . " socpeople as c, " ;
2024-06-22 16:07:46 +02:00
2022-01-27 10:19:35 +01:00
$sql .= " " . $this -> db -> prefix () . " c_action_trigger as a, " ;
$sql .= " " . $this -> db -> prefix () . " societe as s " ;
2019-12-03 11:17:29 +01:00
$sql .= " WHERE n.fk_contact = c.rowid " ;
$sql .= " AND a.rowid = n.fk_action " ;
$sql .= " AND n.fk_soc = s.rowid " ;
2020-12-20 11:04:21 +01:00
$sql .= $sqlnotifcode ;
2019-12-03 11:17:29 +01:00
$sql .= " AND s.entity IN ( " . getEntity ( 'societe' ) . " ) " ;
2020-12-20 11:04:21 +01:00
if ( $socid > 0 ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND s.rowid = " . (( int ) $socid );
2020-12-20 11:04:21 +01:00
}
2017-10-07 13:09:31 +02:00
2022-12-28 16:40:03 +01:00
dol_syslog ( __METHOD__ . " " . $notifcode . " , " . $socid , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
$resql = $this -> db -> query ( $sql );
2020-12-20 11:04:21 +01:00
if ( $resql ) {
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $resql );
2019-12-03 11:17:29 +01:00
$i = 0 ;
2020-12-20 11:04:21 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2024-06-22 16:07:46 +02:00
// we want to notify only if contact is enable
if ( $obj && $obj -> status == 1 ) {
2019-12-03 11:17:29 +01:00
$newval2 = trim ( $obj -> email );
$isvalid = isValidEmail ( $newval2 );
2020-12-20 11:04:21 +01:00
if ( empty ( $resarray [ $newval2 ])) {
2024-03-30 23:56:37 +01:00
$resarray [ $newval2 ] = array ( 'type' => 'tocontact' , 'code' => trim ( $obj -> code ), 'emaildesc' => 'Contact id ' . $obj -> rowid , 'email' => $newval2 , 'contactid' => $obj -> rowid , 'isemailvalid' => $isvalid );
2020-12-20 11:04:21 +01:00
}
2017-10-07 13:09:31 +02:00
}
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
$error ++ ;
2019-12-03 11:17:29 +01:00
$this -> error = $this -> db -> lasterror ();
2017-10-07 13:09:31 +02:00
}
}
}
2024-03-19 15:55:37 +01:00
// Subscription per user
2020-12-20 11:04:21 +01:00
if ( ! $error ) {
if ( $userid >= 0 && in_array ( 'user' , $scope )) {
2017-10-07 13:09:31 +02:00
$sql = " SELECT a.code, c.email, c.rowid " ;
2022-01-27 10:19:35 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " notify_def as n, " ;
$sql .= " " . $this -> db -> prefix () . " user as c, " ;
$sql .= " " . $this -> db -> prefix () . " c_action_trigger as a " ;
2019-12-03 11:17:29 +01:00
$sql .= " WHERE n.fk_user = c.rowid " ;
$sql .= " AND a.rowid = n.fk_action " ;
2020-12-20 11:04:21 +01:00
$sql .= $sqlnotifcode ;
2019-12-03 11:17:29 +01:00
$sql .= " AND c.entity IN ( " . getEntity ( 'user' ) . " ) " ;
2020-12-20 11:04:21 +01:00
if ( $userid > 0 ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND c.rowid = " . (( int ) $userid );
2020-12-20 11:04:21 +01:00
}
2017-10-07 13:09:31 +02:00
2022-12-28 16:40:03 +01:00
dol_syslog ( __METHOD__ . " " . $notifcode . " , " . $socid , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
$resql = $this -> db -> query ( $sql );
2020-12-20 11:04:21 +01:00
if ( $resql ) {
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $resql );
2019-12-03 11:17:29 +01:00
$i = 0 ;
2020-12-20 11:04:21 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2020-12-20 11:04:21 +01:00
if ( $obj ) {
2019-12-03 11:17:29 +01:00
$newval2 = trim ( $obj -> email );
$isvalid = isValidEmail ( $newval2 );
2020-12-20 11:04:21 +01:00
if ( empty ( $resarray [ $newval2 ])) {
2024-03-30 23:56:37 +01:00
$resarray [ $newval2 ] = array ( 'type' => 'touser' , 'code' => trim ( $obj -> code ), 'emaildesc' => 'User id ' . $obj -> rowid , 'email' => $newval2 , 'userid' => $obj -> rowid , 'isemailvalid' => $isvalid );
2020-12-20 11:04:21 +01:00
}
2017-10-07 13:09:31 +02:00
}
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
$error ++ ;
2019-12-03 11:17:29 +01:00
$this -> error = $this -> db -> lasterror ();
2017-10-07 13:09:31 +02:00
}
}
}
2024-03-19 15:55:37 +01:00
// Subscription global
2020-12-20 11:04:21 +01:00
if ( ! $error ) {
if ( in_array ( 'global' , $scope )) {
2017-10-07 13:09:31 +02:00
// List of notifications enabled for fixed email
2020-12-20 11:04:21 +01:00
foreach ( $conf -> global as $key => $val ) {
if ( $notifcode ) {
if ( $val == '' || ! preg_match ( '/^NOTIFICATION_FIXEDEMAIL_' . $notifcode . '_THRESHOLD_HIGHER_(.*)$/' , $key , $reg )) {
continue ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-12-20 11:04:21 +01:00
if ( $val == '' || ! preg_match ( '/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/' , $key , $reg )) {
continue ;
}
2017-10-07 13:09:31 +02:00
}
$threshold = ( float ) $reg [ 1 ];
2020-12-20 11:04:21 +01:00
if ( $valueforthreshold < $threshold ) {
continue ;
}
2017-10-07 13:09:31 +02:00
2019-12-03 11:17:29 +01:00
$tmpemail = explode ( ',' , $val );
2020-12-20 11:04:21 +01:00
foreach ( $tmpemail as $key2 => $val2 ) {
2019-12-03 11:17:29 +01:00
$newval2 = trim ( $val2 );
2020-12-20 11:04:21 +01:00
if ( $newval2 == '__SUPERVISOREMAIL__' ) {
if ( $user -> fk_user > 0 ) {
2019-12-03 11:17:29 +01:00
$tmpuser = new User ( $this -> db );
2017-10-07 13:09:31 +02:00
$tmpuser -> fetch ( $user -> fk_user );
2020-12-20 11:04:21 +01:00
if ( $tmpuser -> email ) {
$newval2 = trim ( $tmpuser -> email );
} else {
$newval2 = '' ;
}
} else {
$newval2 = '' ;
}
2017-10-07 13:09:31 +02:00
}
2020-12-20 11:04:21 +01:00
if ( $newval2 ) {
2019-12-03 11:17:29 +01:00
$isvalid = isValidEmail ( $newval2 , 0 );
2020-12-20 11:04:21 +01:00
if ( empty ( $resarray [ $newval2 ])) {
2024-03-30 23:56:37 +01:00
$resarray [ $newval2 ] = array ( 'type' => 'tofixedemail' , 'code' => trim ( $key ), 'emaildesc' => trim ( $val2 ), 'email' => $newval2 , 'isemailvalid' => $isvalid );
2020-12-20 11:04:21 +01:00
}
2017-10-07 13:09:31 +02:00
}
}
}
}
2006-08-05 18:44:43 +02:00
}
2009-06-30 13:59:46 +02:00
2020-12-20 11:04:21 +01:00
if ( $error ) {
return - 1 ;
}
2015-04-13 17:04:18 +02:00
return $resarray ;
2006-08-05 18:44:43 +02:00
}
2017-10-07 13:09:31 +02:00
/**
* Check if notification are active for couple action / company .
* If yes , send mail and save trace into llx_notify .
*
2024-09-28 12:09:35 +02:00
* @ param string $notifcode Code of action in llx_c_action_trigger ( new usage ) or Id of action in llx_c_action_trigger ( old usage )
* @ param CommonObject $object Object the notification deals on
* @ param string [] $filename_list List of files to attach ( full path of filename on file system )
* @ param string [] $mimetype_list List of MIME type of attached files
* @ param string [] $mimefilename_list List of attached file name in message
* @ return int Return integer < 0 if KO , or number of changes if OK
2017-10-07 13:09:31 +02:00
*/
2019-02-26 22:42:19 +01:00
public function send ( $notifcode , $object , $filename_list = array (), $mimetype_list = array (), $mimefilename_list = array ())
2017-10-07 13:09:31 +02:00
{
2019-12-03 11:17:29 +01:00
global $user , $conf , $langs , $mysoc ;
2017-10-07 13:09:31 +02:00
global $hookmanager ;
global $dolibarr_main_url_root ;
2020-04-27 17:13:23 +02:00
global $action ;
2005-07-14 15:03:20 +02:00
2023-03-02 02:19:24 +01:00
// Complete the array Notify::$arrayofnotifsupported
2020-12-20 11:04:21 +01:00
if ( ! is_object ( $hookmanager )) {
2017-10-07 13:09:31 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php' ;
2019-12-03 11:17:29 +01:00
$hookmanager = new HookManager ( $this -> db );
2017-10-07 13:09:31 +02:00
}
$hookmanager -> initHooks ( array ( 'notification' ));
2017-10-06 14:05:13 +02:00
2022-03-31 13:28:19 +02:00
$parameters = array ( 'notifcode' => $notifcode );
2022-03-12 23:41:16 +01:00
$reshook = $hookmanager -> executeHooks ( 'notifsupported' , $parameters , $object , $action );
2022-03-09 19:55:40 +01:00
if ( empty ( $reshook )) {
if ( ! empty ( $hookmanager -> resArray [ 'arrayofnotifsupported' ])) {
Notify :: $arrayofnotifsupported = array_merge ( Notify :: $arrayofnotifsupported , $hookmanager -> resArray [ 'arrayofnotifsupported' ]);
}
}
2023-03-02 02:19:24 +01:00
// If the trigger code is not managed by the Notification module
2022-03-09 19:55:40 +01:00
if ( ! in_array ( $notifcode , Notify :: $arrayofnotifsupported )) {
return 0 ;
}
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2022-03-09 19:55:55 +01:00
2023-03-02 02:19:24 +01:00
dol_syslog ( get_class ( $this ) . " ::send notifcode= " . $notifcode . " , object id= " . $object -> id );
2014-10-25 00:42:52 +02:00
2017-10-07 13:09:31 +02:00
$langs -> load ( " other " );
2014-10-25 00:42:52 +02:00
// Define $urlwithroot
2020-04-10 10:59:32 +02:00
$urlwithouturlroot = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( $dolibarr_main_url_root ));
$urlwithroot = $urlwithouturlroot . DOL_URL_ROOT ; // This is to use external domain name found into config file
2014-10-25 00:42:52 +02:00
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
2009-07-30 00:03:20 +02:00
2014-10-25 00:42:52 +02:00
// Define some vars
2017-10-07 13:09:31 +02:00
$application = 'Dolibarr' ;
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIN_APPLICATION_TITLE' )) {
2024-01-05 04:18:53 +01:00
$application = getDolGlobalString ( 'MAIN_APPLICATION_TITLE' );
2020-12-20 11:04:21 +01:00
}
2024-04-02 14:06:03 +02:00
$from = getDolGlobalString ( 'NOTIFICATION_EMAIL_FROM' );
2014-10-25 00:42:52 +02:00
$object_type = '' ;
2017-10-07 13:09:31 +02:00
$link = '' ;
2014-10-25 00:42:52 +02:00
$num = 0 ;
2020-10-31 14:32:18 +01:00
$error = 0 ;
2006-08-05 18:44:43 +02:00
2020-04-10 10:59:32 +02:00
$oldref = ( empty ( $object -> oldref ) ? $object -> ref : $object -> oldref );
$newref = ( empty ( $object -> newref ) ? $object -> ref : $object -> newref );
2018-10-01 17:05:52 +02:00
2018-10-25 12:45:13 +02:00
$sql = '' ;
2014-10-25 00:42:52 +02:00
// Check notification per third party
2020-12-20 11:04:21 +01:00
if ( ! empty ( $object -> socid ) && $object -> socid > 0 ) {
2020-04-10 10:59:32 +02:00
$sql .= " SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang, " ;
2023-03-02 02:19:24 +01:00
$sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type " ;
2022-01-27 10:19:35 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " socpeople as c, " ;
$sql .= " " . $this -> db -> prefix () . " c_action_trigger as a, " ;
$sql .= " " . $this -> db -> prefix () . " notify_def as n, " ;
$sql .= " " . $this -> db -> prefix () . " societe as s " ;
2020-04-10 10:59:32 +02:00
$sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action " ;
$sql .= " AND n.fk_soc = s.rowid " ;
$sql .= " AND c.statut = 1 " ;
2020-12-20 11:04:21 +01:00
if ( is_numeric ( $notifcode )) {
2021-06-09 15:36:47 +02:00
$sql .= " AND n.fk_action = " . (( int ) $notifcode ); // Old usage
2020-12-20 11:04:21 +01:00
} else {
$sql .= " AND a.code = ' " . $this -> db -> escape ( $notifcode ) . " ' " ; // New usage
}
2021-06-09 15:36:47 +02:00
$sql .= " AND s.rowid = " . (( int ) $object -> socid );
2018-10-25 12:45:13 +02:00
2020-04-10 10:59:32 +02:00
$sql .= " \n UNION \n " ;
2018-10-25 12:45:13 +02:00
}
2010-01-09 15:48:27 +01:00
2016-03-13 00:20:29 +01:00
// Check notification per user
2020-04-10 10:59:32 +02:00
$sql .= " SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang, " ;
2023-03-02 02:19:24 +01:00
$sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type " ;
2022-01-27 10:19:35 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " user as c, " ;
$sql .= " " . $this -> db -> prefix () . " c_action_trigger as a, " ;
$sql .= " " . $this -> db -> prefix () . " notify_def as n " ;
2020-04-10 10:59:32 +02:00
$sql .= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action " ;
$sql .= " AND c.statut = 1 " ;
2020-12-20 11:04:21 +01:00
if ( is_numeric ( $notifcode )) {
2021-08-23 18:56:46 +02:00
$sql .= " AND n.fk_action = " . (( int ) $notifcode ); // Old usage
2020-12-20 11:04:21 +01:00
} else {
$sql .= " AND a.code = ' " . $this -> db -> escape ( $notifcode ) . " ' " ; // New usage
}
2017-10-07 13:09:31 +02:00
2023-03-02 02:19:24 +01:00
// Check notification fixed
// TODO Move part found after, into a sql here
// Loop on all notifications enabled
2017-10-07 13:09:31 +02:00
$result = $this -> db -> query ( $sql );
2020-12-20 11:04:21 +01:00
if ( $result ) {
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $result );
2020-04-10 10:59:32 +02:00
$projtitle = '' ;
2024-10-26 22:43:44 +02:00
if ( is_object ( $object -> project ) || $object -> fetchProject () > 0 ) {
2023-10-20 10:53:14 +02:00
$projtitle = '(' . $object -> project -> title . ')' ;
2018-10-01 17:05:52 +02:00
}
2017-10-07 13:09:31 +02:00
2020-12-20 11:04:21 +01:00
if ( $num > 0 ) {
2017-10-07 13:09:31 +02:00
$i = 0 ;
2020-12-20 11:04:21 +01:00
while ( $i < $num && ! $error ) { // For each notification couple defined (third party/actioncode)
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $result );
2020-04-10 10:59:32 +02:00
$sendto = dolGetFirstLastname ( $obj -> firstname , $obj -> lastname ) . " < " . $obj -> email . " > " ;
2015-03-18 21:44:57 +01:00
$notifcodedefid = $obj -> adid ;
2020-05-07 11:59:13 +02:00
$trackid = '' ;
2020-12-20 11:04:21 +01:00
if ( $obj -> type_target == 'tocontactid' ) {
2022-09-12 10:26:20 +02:00
$trackid = 'ctc' . $obj -> cid ;
2020-12-20 11:04:21 +01:00
}
if ( $obj -> type_target == 'touserid' ) {
2021-12-02 11:19:44 +01:00
$trackid = 'use' . $obj -> cid ;
2020-12-20 11:04:21 +01:00
}
2014-09-04 14:38:30 +02:00
2020-12-20 11:04:21 +01:00
if ( dol_strlen ( $obj -> email )) {
2017-10-07 13:09:31 +02:00
// Set output language
$outputlangs = $langs ;
2020-12-20 11:04:21 +01:00
if ( $obj -> default_lang && $obj -> default_lang != $langs -> defaultlang ) {
2017-10-07 13:09:31 +02:00
$outputlangs = new Translate ( '' , $conf );
$outputlangs -> setDefaultLang ( $obj -> default_lang );
2019-12-03 11:17:29 +01:00
$outputlangs -> loadLangs ( array ( " main " , " other " ));
2017-10-07 13:09:31 +02:00
}
2014-10-25 00:42:52 +02:00
2023-09-29 16:27:07 +02:00
$appli = $mysoc -> name ;
$subject = '[' . $appli . '] ' . $outputlangs -> transnoentitiesnoconv ( " DolibarrNotification " ) . ( $projtitle ? ' ' . $projtitle : '' );
2021-03-19 11:53:06 +01:00
2017-10-07 13:09:31 +02:00
switch ( $notifcode ) {
2024-03-15 20:56:12 +01:00
case 'BILL_CANCEL' :
$link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> facture -> dir_output . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'invoice' );
$object_type = 'facture' ;
2024-03-16 13:38:52 +01:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextInvoiceCanceled " , $link );
2024-03-15 20:56:12 +01:00
break ;
2014-10-25 00:42:52 +02:00
case 'BILL_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> facture -> dir_output . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'invoice' );
2014-10-25 00:42:52 +02:00
$object_type = 'facture' ;
2020-05-07 11:39:32 +02:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextInvoiceValidated " , $link );
2014-10-25 00:42:52 +02:00
break ;
2016-02-22 12:52:01 +01:00
case 'BILL_PAYED' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> facture -> dir_output . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'invoice' );
2016-02-22 12:52:01 +01:00
$object_type = 'facture' ;
2020-05-07 11:39:32 +02:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextInvoicePayed " , $link );
2016-02-22 12:52:01 +01:00
break ;
2024-03-15 20:56:12 +01:00
case 'ORDER_CANCEL' :
$link = '<a href="' . $urlwithroot . '/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> commande -> dir_output . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'commande' );
$object_type = 'order' ;
2024-03-16 13:38:52 +01:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextOrderCanceled " , $link );
2024-03-15 20:56:12 +01:00
break ;
2014-10-25 00:42:52 +02:00
case 'ORDER_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> commande -> dir_output . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'commande' );
2014-10-25 00:42:52 +02:00
$object_type = 'order' ;
2020-05-07 11:39:32 +02:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextOrderValidated " , $link );
2014-10-25 00:42:52 +02:00
break ;
2022-11-23 14:00:24 +01:00
case 'ORDER_CLOSE' :
$link = '<a href="' . $urlwithroot . '/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> commande -> dir_output . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'commande' );
$object_type = 'order' ;
2024-01-05 04:18:53 +01:00
$labeltouse = getDolGlobalString ( 'ORDER_CLOSE_TEMPLATE' );
2022-11-23 14:00:24 +01:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextOrderClose " , $link );
break ;
2014-10-25 00:42:52 +02:00
case 'PROPAL_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> propal -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'propal' );
2014-10-25 00:42:52 +02:00
$object_type = 'propal' ;
2020-05-07 11:39:32 +02:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextProposalValidated " , $link );
2014-10-25 00:42:52 +02:00
break ;
2022-12-01 13:56:14 +01:00
case 'PROPAL_CLOSE_REFUSED' :
$link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> propal -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'propal' );
$object_type = 'propal' ;
2024-01-05 04:18:53 +01:00
$labeltouse = getDolGlobalString ( 'PROPAL_CLOSE_REFUSED_TEMPLATE' );
2022-12-01 13:56:14 +01:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextProposalClosedRefused " , $link );
2023-03-02 02:19:24 +01:00
if ( ! empty ( $object -> context [ 'closedfromonlinesignature' ])) {
$mesg .= ' - From online page' ;
}
2022-12-01 13:56:14 +01:00
break ;
2017-10-07 13:09:31 +02:00
case 'PROPAL_CLOSE_SIGNED' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> propal -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'propal' );
2017-10-07 13:09:31 +02:00
$object_type = 'propal' ;
2022-12-01 13:56:14 +01:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextProposalClosedSigned " , $link );
2023-03-02 02:19:24 +01:00
if ( ! empty ( $object -> context [ 'closedfromonlinesignature' ])) {
$mesg .= ' - From online page' ;
}
2017-10-07 13:09:31 +02:00
break ;
2016-03-11 21:07:38 +01:00
case 'FICHINTER_ADD_CONTACT' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2018-01-29 20:36:40 +01:00
$dir_output = $conf -> ficheinter -> dir_output ;
2016-03-11 21:07:38 +01:00
$object_type = 'ficheinter' ;
2020-05-07 11:59:13 +02:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextInterventionAddedContact " , $link );
2016-03-11 21:07:38 +01:00
break ;
2014-10-25 00:42:52 +02:00
case 'FICHINTER_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2018-01-29 20:36:40 +01:00
$dir_output = $conf -> ficheinter -> dir_output ;
2014-10-25 00:42:52 +02:00
$object_type = 'ficheinter' ;
2020-05-07 11:39:32 +02:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextInterventionValidated " , $link );
2014-10-25 00:42:52 +02:00
break ;
2024-08-27 07:01:03 +02:00
case 'FICHINTER_MODIFY' :
$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$context_info = array_key_exists ( 'signature' , $object -> context ) ? $object -> getLibSignedStatus () : '' ;
$dir_output = $conf -> ficheinter -> dir_output ;
$object_type = 'ficheinter' ;
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextInterventionModified " , $link , $context_info );
break ;
2023-10-05 12:11:39 +02:00
case 'FICHINTER_CLOSE' :
$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> ficheinter -> dir_output ;
$object_type = 'ficheinter' ;
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextInterventionClosed " , $link );
break ;
2015-03-18 21:44:57 +01:00
case 'ORDER_SUPPLIER_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2023-05-24 14:41:57 +02:00
$dir_output = $conf -> fournisseur -> commande -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object );
2015-03-18 21:44:57 +01:00
$object_type = 'order_supplier' ;
2024-02-18 16:31:12 +01:00
$labeltouse = isset ( $conf -> global -> ORDER_SUPPLIER_VALIDATE_TEMPLATE ) ? $conf -> global -> ORDER_SUPPLIER_VALIDATE_TEMPLATE : '' ;
2018-10-16 03:30:17 +02:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " Hello " ) . " , \n \n " ;
2023-11-28 11:41:26 +01:00
$mesg .= $outputlangs -> transnoentitiesnoconv ( " EMailTextSupplierOrderValidatedBy " , $link , $user -> getFullName ( $outputlangs ));
2019-12-03 11:17:29 +01:00
$mesg .= " \n \n " . $outputlangs -> transnoentitiesnoconv ( " Sincerely " ) . " . \n \n " ;
2015-03-18 21:44:57 +01:00
break ;
2024-05-25 14:38:35 +02:00
case 'ORDER_SUPPLIER_CANCEL' :
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> fournisseur -> commande -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object );
$object_type = 'order_supplier' ;
$mesg = $outputlangs -> transnoentitiesnoconv ( " Hello " ) . " , \n \n " ;
$mesg .= $outputlangs -> transnoentitiesnoconv ( " EMailTextSupplierOrderCanceledBy " , $link , $user -> getFullName ( $outputlangs ));
$mesg .= " \n \n " . $outputlangs -> transnoentitiesnoconv ( " Sincerely " ) . " . \n \n " ;
break ;
2014-10-25 00:42:52 +02:00
case 'ORDER_SUPPLIER_APPROVE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2023-05-24 14:41:57 +02:00
$dir_output = $conf -> fournisseur -> commande -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object );
2014-10-25 00:42:52 +02:00
$object_type = 'order_supplier' ;
2024-02-18 16:31:12 +01:00
$labeltouse = isset ( $conf -> global -> ORDER_SUPPLIER_APPROVE_TEMPLATE ) ? $conf -> global -> ORDER_SUPPLIER_APPROVE_TEMPLATE : '' ;
2018-10-16 03:30:17 +02:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " Hello " ) . " , \n \n " ;
2023-11-28 11:29:57 +01:00
$mesg .= $outputlangs -> transnoentitiesnoconv ( " EMailTextSupplierOrderApprovedBy " , $link , $user -> getFullName ( $outputlangs ));
2019-12-03 11:17:29 +01:00
$mesg .= " \n \n " . $outputlangs -> transnoentitiesnoconv ( " Sincerely " ) . " . \n \n " ;
2014-10-25 00:42:52 +02:00
break ;
2023-09-08 16:53:49 +02:00
case 'ORDER_SUPPLIER_SUBMIT' :
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2024-05-25 14:38:35 +02:00
$dir_output = $conf -> fournisseur -> commande -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object );
2023-09-08 16:53:49 +02:00
$object_type = 'order_supplier' ;
$mesg = $outputlangs -> transnoentitiesnoconv ( " Hello " ) . " , \n \n " ;
$mesg .= $outputlangs -> transnoentitiesnoconv ( " EMailTextSupplierOrderSubmittedBy " , $link , $user -> getFullName ( $outputlangs ));
$mesg .= " \n \n " . $outputlangs -> transnoentitiesnoconv ( " Sincerely " ) . " . \n \n " ;
break ;
2014-10-25 00:42:52 +02:00
case 'ORDER_SUPPLIER_REFUSE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2023-05-24 14:41:57 +02:00
$dir_output = $conf -> fournisseur -> commande -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object );
2014-10-25 00:42:52 +02:00
$object_type = 'order_supplier' ;
2024-02-18 16:31:12 +01:00
$labeltouse = isset ( $conf -> global -> ORDER_SUPPLIER_REFUSE_TEMPLATE ) ? $conf -> global -> ORDER_SUPPLIER_REFUSE_TEMPLATE : '' ;
2018-10-16 03:30:17 +02:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " Hello " ) . " , \n \n " ;
2023-11-28 11:41:26 +01:00
$mesg .= $outputlangs -> transnoentitiesnoconv ( " EMailTextSupplierOrderRefusedBy " , $link , $user -> getFullName ( $outputlangs ));
2019-12-03 11:17:29 +01:00
$mesg .= " \n \n " . $outputlangs -> transnoentitiesnoconv ( " Sincerely " ) . " . \n \n " ;
2014-10-25 00:42:52 +02:00
break ;
2024-09-13 03:09:53 +02:00
case 'SHIPPING_MODIFY' :
$link = '<a href="' . $urlwithroot . '/expedition/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$context_info = array_key_exists ( 'signature' , $object -> context ) ? $object -> getLibSignedStatus () : '' ;
$dir_output = $conf -> expedition -> dir_output . " /sending/ " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'shipment' );
$object_type = 'shipping' ;
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextExpeditionModified " , $link , $context_info );
break ;
2014-10-25 00:42:52 +02:00
case 'SHIPPING_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/expedition/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> expedition -> dir_output . " /sending/ " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'shipment' );
2021-08-12 14:15:04 +02:00
$object_type = 'shipping' ;
2020-05-07 11:39:32 +02:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextExpeditionValidated " , $link );
2014-10-25 00:42:52 +02:00
break ;
2018-10-25 12:45:13 +02:00
case 'EXPENSE_REPORT_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/expensereport/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2018-10-25 12:45:13 +02:00
$dir_output = $conf -> expensereport -> dir_output ;
$object_type = 'expensereport' ;
2020-05-07 11:39:32 +02:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextExpenseReportValidated " , $link );
2018-10-25 12:45:13 +02:00
break ;
case 'EXPENSE_REPORT_APPROVE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/expensereport/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2018-10-25 12:45:13 +02:00
$dir_output = $conf -> expensereport -> dir_output ;
$object_type = 'expensereport' ;
2020-05-07 11:39:32 +02:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextExpenseReportApproved " , $link );
2018-10-25 12:45:13 +02:00
break ;
case 'HOLIDAY_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/holiday/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2018-10-25 12:45:13 +02:00
$dir_output = $conf -> holiday -> dir_output ;
$object_type = 'holiday' ;
2020-05-07 11:39:32 +02:00
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextHolidayValidated " , $link );
2018-10-25 12:45:13 +02:00
break ;
2021-02-23 22:03:23 +01:00
case 'HOLIDAY_APPROVE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/holiday/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2021-02-23 22:03:23 +01:00
$dir_output = $conf -> holiday -> dir_output ;
$object_type = 'holiday' ;
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextHolidayApproved " , $link );
2021-07-22 09:22:42 +02:00
break ;
2021-02-23 22:03:23 +01:00
case 'ACTION_CREATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/comm/action/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2021-02-23 22:03:23 +01:00
$dir_output = $conf -> agenda -> dir_output ;
$object_type = 'action' ;
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextActionAdded " , $link );
break ;
2024-09-10 03:04:49 +02:00
case 'CONTRACT_MODIFY' :
$link = '<a href="' . $urlwithroot . '/contrat/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$context_info = array_key_exists ( 'signature' , $object -> context ) ? $object -> getLibSignedStatus () : '' ;
$dir_output = $conf -> contract -> multidir_output ;
$object_type = 'contract' ;
$mesg = $outputlangs -> transnoentitiesnoconv ( " EMailTextContractModified " , $link , $context_info );
break ;
2022-03-09 18:05:07 +01:00
default :
$object_type = $object -> element ;
$dir_output = $conf -> $object_type -> multidir_output [ $object -> entity ? $object -> entity : $conf -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , $object_type );
$template = $notifcode . '_TEMPLATE' ;
$mesg = $outputlangs -> transnoentitiesnoconv ( 'Notify_' . $notifcode ) . ' ' . $newref . ' ' . $dir_output ;
2024-03-30 23:56:37 +01:00
break ;
2014-10-25 00:42:52 +02:00
}
2021-03-19 11:50:15 +01:00
2021-03-19 11:53:06 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
$formmail = new FormMail ( $this -> db );
$arraydefaultmessage = null ;
2023-04-26 17:41:35 +02:00
$template = $notifcode . '_TEMPLATE' ;
2023-04-26 21:07:14 +02:00
$labeltouse = getDolGlobalString ( $template );
if ( ! empty ( $labeltouse )) {
$arraydefaultmessage = $formmail -> getEMailTemplate ( $this -> db , $object_type . '_send' , $user , $outputlangs , 0 , 1 , $labeltouse );
}
2021-03-19 11:53:06 +01:00
if ( ! empty ( $labeltouse ) && is_object ( $arraydefaultmessage ) && $arraydefaultmessage -> id > 0 ) {
2024-09-20 11:06:24 +02:00
if ( method_exists ( $object , 'fetch_thirdparty' ) && empty ( $object -> thirdparty )) {
2024-09-19 10:56:42 +02:00
$object -> fetch_thirdparty ();
}
2021-03-19 11:53:06 +01:00
$substitutionarray = getCommonSubstitutionArray ( $outputlangs , 0 , null , $object );
complete_substitutions_array ( $substitutionarray , $outputlangs , $object );
$subject = make_substitutions ( $arraydefaultmessage -> topic , $substitutionarray , $outputlangs );
$message = make_substitutions ( $arraydefaultmessage -> content , $substitutionarray , $outputlangs );
} else {
2021-07-22 09:22:42 +02:00
$message = $outputlangs -> transnoentities ( " YouReceiveMailBecauseOfNotification " , $application , $mysoc -> name ) . " \n " ;
$message .= $outputlangs -> transnoentities ( " YouReceiveMailBecauseOfNotification2 " , $application , $mysoc -> name ) . " \n " ;
$message .= " \n " ;
$message .= $mesg ;
2021-03-19 11:53:06 +01:00
}
2021-03-19 11:50:15 +01:00
2017-10-07 13:09:31 +02:00
$ref = dol_sanitizeFileName ( $newref );
2021-03-19 11:50:15 +01:00
$pdf_path = $dir_output . " / " . $ref . " .pdf " ;
2024-03-30 23:56:37 +01:00
if ( ! dol_is_file ( $pdf_path ) || ( is_object ( $arraydefaultmessage ) && $arraydefaultmessage -> id > 0 && ! $arraydefaultmessage -> joinfiles )) {
2014-10-25 00:42:52 +02:00
// We can't add PDF as it is not generated yet.
$filepdf = '' ;
2020-05-21 15:05:19 +02:00
} else {
2014-10-25 00:42:52 +02:00
$filepdf = $pdf_path ;
2021-03-19 11:53:06 +01:00
$filename_list [] = $filepdf ;
$mimetype_list [] = mime_content_type ( $filepdf );
$mimefilename_list [] = $ref . " .pdf " ;
2014-10-25 00:42:52 +02:00
}
2022-09-10 16:21:16 +02:00
$labeltouse = ! empty ( $labeltouse ) ? $labeltouse : '' ;
2023-03-02 02:19:24 +01:00
// Replace keyword __SUPERVISOREMAIL__
if ( preg_match ( '/__SUPERVISOREMAIL__/' , $sendto )) {
$newval = '' ;
if ( $user -> fk_user > 0 ) {
$supervisoruser = new User ( $this -> db );
$supervisoruser -> fetch ( $user -> fk_user );
if ( $supervisoruser -> email ) {
$newval = trim ( dolGetFirstLastname ( $supervisoruser -> firstname , $supervisoruser -> lastname ) . ' <' . $supervisoruser -> email . '>' );
}
}
dol_syslog ( " Replace the __SUPERVISOREMAIL__ key into recipient email string with " . $newval );
$sendto = preg_replace ( '/__SUPERVISOREMAIL__/' , $newval , $sendto );
$sendto = preg_replace ( '/,\s*,/' , ',' , $sendto ); // in some case you can have $sendto like "email, __SUPERVISOREMAIL__ , otheremail" then you have "email, , othermail" and it's not valid
$sendto = preg_replace ( '/^[\s,]+/' , '' , $sendto ); // Clean start of string
$sendto = preg_replace ( '/[\s,]+$/' , '' , $sendto ); // Clean end of string
}
2024-04-02 14:06:03 +02:00
$parameters = array ( 'notifcode' => $notifcode , 'sendto' => $sendto , 'from' => $from , 'file' => $filename_list , 'mimefile' => $mimetype_list , 'filename' => $mimefilename_list , 'outputlangs' => $outputlangs , 'labeltouse' => $labeltouse );
2020-12-20 11:04:21 +01:00
if ( ! isset ( $action )) {
$action = '' ;
}
2020-04-27 17:13:23 +02:00
2019-12-03 11:17:29 +01:00
$reshook = $hookmanager -> executeHooks ( 'formatNotificationMessage' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2020-12-20 11:04:21 +01:00
if ( empty ( $reshook )) {
2022-12-28 15:29:55 +01:00
if ( ! empty ( $hookmanager -> resArray [ 'files' ])) {
$filename_list = $hookmanager -> resArray [ 'files' ][ 'file' ];
$mimetype_list = $hookmanager -> resArray [ 'files' ][ 'mimefile' ];
$mimefilename_list = $hookmanager -> resArray [ 'files' ][ 'filename' ];
}
2020-12-20 11:04:21 +01:00
if ( ! empty ( $hookmanager -> resArray [ 'subject' ])) {
$subject .= $hookmanager -> resArray [ 'subject' ];
}
if ( ! empty ( $hookmanager -> resArray [ 'message' ])) {
$message .= $hookmanager -> resArray [ 'message' ];
}
2017-10-07 13:09:31 +02:00
}
2020-10-31 14:32:18 +01:00
$mailfile = new CMailFile (
2017-10-07 13:09:31 +02:00
$subject ,
$sendto ,
2024-04-02 14:06:03 +02:00
$from ,
2017-10-07 13:09:31 +02:00
$message ,
2018-07-16 09:57:45 +02:00
$filename_list ,
$mimetype_list ,
$mimefilename_list ,
2017-10-07 13:09:31 +02:00
'' ,
'' ,
0 ,
2019-09-28 10:25:00 +02:00
- 1 ,
2020-10-31 14:32:18 +01:00
'' ,
'' ,
$trackid ,
'' ,
'notification'
);
2017-10-07 13:09:31 +02:00
2020-12-20 11:04:21 +01:00
if ( $mailfile -> sendfile ()) {
2017-10-07 13:09:31 +02:00
if ( $obj -> type_target == 'touserid' ) {
2022-01-27 10:19:35 +01:00
$sql = " INSERT INTO " . $this -> db -> prefix () . " notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email) " ;
2021-08-27 22:42:04 +02:00
$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 ) . " ') " ;
2020-05-21 15:05:19 +02:00
} else {
2022-01-27 10:19:35 +01:00
$sql = " INSERT INTO " . $this -> db -> prefix () . " notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email) " ;
2021-08-27 22:42:04 +02:00
$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 ) . " ') " ;
2017-10-07 13:09:31 +02:00
}
2020-12-20 11:04:21 +01:00
if ( ! $this -> db -> query ( $sql )) {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
2020-05-21 15:05:19 +02:00
} else {
2014-10-25 00:42:52 +02:00
$error ++ ;
2019-12-03 11:17:29 +01:00
$this -> errors [] = $mailfile -> error ;
2017-10-07 13:09:31 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_syslog ( " No notification sent for " . $sendto . " because email is empty " );
}
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-12-12 19:49:13 +01:00
dol_syslog ( " No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = " . ( empty ( $object -> socid ) ? '' : $object -> socid ));
2014-09-04 14:38:30 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-12-20 11:04:21 +01:00
$error ++ ;
2019-12-03 11:17:29 +01:00
$this -> errors [] = $this -> db -> lasterror ();
2017-10-07 13:09:31 +02:00
dol_syslog ( " Failed to get list of notification to send " . $this -> db -> lasterror (), LOG_ERR );
2020-12-20 11:04:21 +01:00
return - 1 ;
2017-10-07 13:09:31 +02:00
}
// Check notification using fixed email
2023-03-02 02:19:24 +01:00
// TODO Move vars NOTIFICATION_FIXEDEMAIL into table llx_notify_def and inclulde the case into previous loop of sql result
2020-12-20 11:04:21 +01:00
if ( ! $error ) {
foreach ( $conf -> global as $key => $val ) {
2020-05-04 19:08:31 +02:00
$reg = array ();
2020-12-20 11:04:21 +01:00
if ( $val == '' || ! preg_match ( '/^NOTIFICATION_FIXEDEMAIL_' . $notifcode . '_THRESHOLD_HIGHER_(.*)$/' , $key , $reg )) {
continue ;
}
2023-10-02 17:01:53 +02:00
2023-10-02 16:58:28 +02:00
$sendto = $val ;
2017-10-07 13:09:31 +02:00
$threshold = ( float ) $reg [ 1 ];
2020-12-20 11:04:21 +01:00
if ( ! empty ( $object -> total_ht ) && $object -> total_ht <= $threshold ) {
2017-10-07 13:09:31 +02:00
dol_syslog ( " A notification is requested for notifcode = " . $notifcode . " but amount = " . $object -> total_ht . " so lower than threshold = " . $threshold . " . We discard this notification " );
continue ;
}
$notifcodedefid = dol_getIdFromCode ( $this -> db , $notifcode , 'c_action_trigger' , 'code' , 'rowid' );
2020-12-20 11:04:21 +01:00
if ( $notifcodedefid <= 0 ) {
dol_print_error ( $this -> db , 'Failed to get id from code' );
}
2020-05-07 11:59:13 +02:00
$trackid = '' ;
2017-10-07 13:09:31 +02:00
$object_type = '' ;
$link = '' ;
$num ++ ;
2023-09-29 16:27:07 +02:00
$appli = $mysoc -> name ;
$subject = '[' . $appli . '] ' . $langs -> transnoentitiesnoconv ( " DolibarrNotification " ) . ( $projtitle ? ' ' . $projtitle : '' );
2017-10-07 13:09:31 +02:00
switch ( $notifcode ) {
2014-10-25 00:42:52 +02:00
case 'BILL_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> facture -> dir_output . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'invoice' );
2014-10-25 00:42:52 +02:00
$object_type = 'facture' ;
2019-01-27 11:55:16 +01:00
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextInvoiceValidated " , $link );
2014-10-25 00:42:52 +02:00
break ;
2016-02-22 12:52:01 +01:00
case 'BILL_PAYED' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2021-07-22 09:22:42 +02:00
$dir_output = $conf -> facture -> dir_output . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'invoice' );
2016-02-22 12:52:01 +01:00
$object_type = 'facture' ;
2019-01-27 11:55:16 +01:00
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextInvoicePayed " , $link );
2016-02-22 12:52:01 +01:00
break ;
2014-10-25 00:42:52 +02:00
case 'ORDER_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> commande -> dir_output . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'commande' );
2014-10-25 00:42:52 +02:00
$object_type = 'order' ;
2019-01-27 11:55:16 +01:00
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextOrderValidated " , $link );
2014-10-25 00:42:52 +02:00
break ;
2022-11-23 14:00:24 +01:00
case 'ORDER_CLOSE' :
$link = '<a href="' . $urlwithroot . '/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> commande -> dir_output . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'commande' );
$object_type = 'order' ;
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextOrderClose " , $link );
break ;
2014-10-25 00:42:52 +02:00
case 'PROPAL_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> propal -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'propal' );
2014-10-25 00:42:52 +02:00
$object_type = 'propal' ;
2019-01-27 11:55:16 +01:00
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextProposalValidated " , $link );
2014-10-25 00:42:52 +02:00
break ;
2017-10-07 13:09:31 +02:00
case 'PROPAL_CLOSE_SIGNED' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> propal -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'propal' );
2017-10-07 13:09:31 +02:00
$object_type = 'propal' ;
2019-01-27 11:55:16 +01:00
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextProposalClosedSigned " , $link );
2017-10-07 13:09:31 +02:00
break ;
case 'FICHINTER_ADD_CONTACT' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2020-05-07 11:39:32 +02:00
$dir_output = $conf -> ficheinter -> dir_output ;
2017-10-07 13:09:31 +02:00
$object_type = 'ficheinter' ;
2019-01-27 11:55:16 +01:00
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextInterventionAddedContact " , $link );
2017-10-07 13:09:31 +02:00
break ;
2014-10-25 00:42:52 +02:00
case 'FICHINTER_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2014-10-25 00:42:52 +02:00
$dir_output = $conf -> facture -> dir_output ;
$object_type = 'ficheinter' ;
2019-01-27 11:55:16 +01:00
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextInterventionValidated " , $link );
2014-10-25 00:42:52 +02:00
break ;
2024-08-27 07:01:03 +02:00
case 'FICHINTER_MODIFY' :
$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$context_info = array_key_exists ( 'signature' , $object -> context ) ? $object -> getLibSignedStatus () : '' ;
$dir_output = $conf -> ficheinter -> dir_output ;
$object_type = 'ficheinter' ;
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextInterventionModified " , $link , $context_info );
break ;
2023-10-05 12:11:39 +02:00
case 'FICHINTER_CLOSE' :
$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> facture -> dir_output ;
$object_type = 'ficheinter' ;
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextInterventionClosed " , $link );
break ;
2024-05-25 14:38:35 +02:00
case 'ORDER_SUPPLIER_CANCEL' :
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> fournisseur -> commande -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object );
$object_type = 'order_supplier' ;
$mesg = $langs -> transnoentitiesnoconv ( " Hello " ) . " , \n \n " ;
$mesg .= $langs -> transnoentitiesnoconv ( " EMailTextSupplierOrderCanceledBy " , $link , $user -> getFullName ( $langs ));
$mesg .= " \n \n " . $langs -> transnoentitiesnoconv ( " Sincerely " ) . " . \n \n " ;
break ;
2017-10-07 13:09:31 +02:00
case 'ORDER_SUPPLIER_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2023-05-24 14:41:57 +02:00
$dir_output = $conf -> fournisseur -> commande -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object );
2017-10-07 13:09:31 +02:00
$object_type = 'order_supplier' ;
$mesg = $langs -> transnoentitiesnoconv ( " Hello " ) . " , \n \n " ;
2023-11-28 11:41:26 +01:00
$mesg .= $langs -> transnoentitiesnoconv ( " EMailTextSupplierOrderValidatedBy " , $link , $user -> getFullName ( $langs ));
2019-12-03 11:17:29 +01:00
$mesg .= " \n \n " . $langs -> transnoentitiesnoconv ( " Sincerely " ) . " . \n \n " ;
2017-10-07 13:09:31 +02:00
break ;
2014-10-25 00:42:52 +02:00
case 'ORDER_SUPPLIER_APPROVE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2023-05-24 14:41:57 +02:00
$dir_output = $conf -> fournisseur -> commande -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object );
2014-10-25 00:42:52 +02:00
$object_type = 'order_supplier' ;
$mesg = $langs -> transnoentitiesnoconv ( " Hello " ) . " , \n \n " ;
2023-11-28 11:41:26 +01:00
$mesg .= $langs -> transnoentitiesnoconv ( " EMailTextSupplierOrderApprovedBy " , $link , $user -> getFullName ( $langs ));
2019-12-03 11:17:29 +01:00
$mesg .= " \n \n " . $langs -> transnoentitiesnoconv ( " Sincerely " ) . " . \n \n " ;
2014-10-25 00:42:52 +02:00
break ;
2023-09-08 16:53:49 +02:00
case 'ORDER_SUPPLIER_SUBMIT' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2023-05-24 14:41:57 +02:00
$dir_output = $conf -> fournisseur -> commande -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object );
2015-04-01 16:33:39 +02:00
$object_type = 'order_supplier' ;
$mesg = $langs -> transnoentitiesnoconv ( " Hello " ) . " , \n \n " ;
2023-09-08 16:53:49 +02:00
$mesg .= $langs -> transnoentitiesnoconv ( " EMailTextSupplierOrderSubmittedBy " , $link , $user -> getFullName ( $langs ));
2019-12-03 11:17:29 +01:00
$mesg .= " \n \n " . $langs -> transnoentitiesnoconv ( " Sincerely " ) . " . \n \n " ;
2015-04-01 16:33:39 +02:00
break ;
2014-10-25 00:42:52 +02:00
case 'ORDER_SUPPLIER_REFUSE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2024-05-25 14:38:35 +02:00
$dir_output = $conf -> fournisseur -> commande -> multidir_output [ $object -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object );
2014-10-25 00:42:52 +02:00
$object_type = 'order_supplier' ;
$mesg = $langs -> transnoentitiesnoconv ( " Hello " ) . " , \n \n " ;
2023-11-28 11:41:26 +01:00
$mesg .= $langs -> transnoentitiesnoconv ( " EMailTextSupplierOrderRefusedBy " , $link , $user -> getFullName ( $langs ));
2019-12-03 11:17:29 +01:00
$mesg .= " \n \n " . $langs -> transnoentitiesnoconv ( " Sincerely " ) . " . \n \n " ;
2014-10-25 00:42:52 +02:00
break ;
2024-09-13 03:09:53 +02:00
case 'SHIPPING_MODIFY' :
$link = '<a href="' . $urlwithroot . '/expedition/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$context_info = array_key_exists ( 'signature' , $object -> context ) ? $object -> getLibSignedStatus () : '' ;
$dir_output = $conf -> expedition -> dir_output . " /sending/ " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'shipment' );
$object_type = 'order_supplier' ;
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextExpeditionModified " , $link , $context_info );
break ;
2014-10-25 00:42:52 +02:00
case 'SHIPPING_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/expedition/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$dir_output = $conf -> expedition -> dir_output . " /sending/ " . get_exdir ( 0 , 0 , 0 , 1 , $object , 'shipment' );
2014-10-25 00:42:52 +02:00
$object_type = 'order_supplier' ;
2020-05-07 11:39:32 +02:00
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextExpeditionValidated " , $link );
2014-10-25 00:42:52 +02:00
break ;
2018-10-25 12:45:13 +02:00
case 'EXPENSE_REPORT_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/expensereport/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2018-10-25 12:45:13 +02:00
$dir_output = $conf -> expensereport -> dir_output ;
$object_type = 'expensereport' ;
2020-05-07 11:39:32 +02:00
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextExpenseReportValidated " , $link );
2018-10-25 12:45:13 +02:00
break ;
case 'EXPENSE_REPORT_APPROVE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/expensereport/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2018-10-25 12:45:13 +02:00
$dir_output = $conf -> expensereport -> dir_output ;
$object_type = 'expensereport' ;
2020-05-07 11:39:32 +02:00
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextExpenseReportApproved " , $link );
2018-10-25 12:45:13 +02:00
break ;
case 'HOLIDAY_VALIDATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/holiday/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2018-10-25 12:45:13 +02:00
$dir_output = $conf -> holiday -> dir_output ;
$object_type = 'holiday' ;
2020-05-07 11:39:32 +02:00
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextHolidayValidated " , $link );
2018-10-25 12:45:13 +02:00
break ;
case 'HOLIDAY_APPROVE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/holiday/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2018-10-25 12:45:13 +02:00
$dir_output = $conf -> holiday -> dir_output ;
$object_type = 'holiday' ;
2020-05-07 11:39:32 +02:00
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextHolidayApproved " , $link );
2021-07-22 09:22:42 +02:00
break ;
2021-02-23 22:03:23 +01:00
case 'ACTION_CREATE' :
2021-03-19 11:50:15 +01:00
$link = '<a href="' . $urlwithroot . '/comm/action/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
2021-02-23 22:03:23 +01:00
$dir_output = $conf -> agenda -> dir_output ;
$object_type = 'action' ;
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextActionAdded " , $link );
break ;
2024-09-10 03:04:49 +02:00
case 'CONTRACT_MODIFY' :
$link = '<a href="' . $urlwithroot . '/contrat/card.php?id=' . $object -> id . '&entity=' . $object -> entity . '">' . $newref . '</a>' ;
$context_info = array_key_exists ( 'signature' , $object -> context ) ? $object -> getLibSignedStatus () : '' ;
$dir_output = $conf -> contract -> multidir_output ;
$object_type = 'contrat' ;
$mesg = $langs -> transnoentitiesnoconv ( " EMailTextContractModified " , $link , $context_info );
break ;
2022-03-09 18:05:07 +01:00
default :
$object_type = $object -> element ;
$dir_output = $conf -> $object_type -> multidir_output [ $object -> entity ? $object -> entity : $conf -> entity ] . " / " . get_exdir ( 0 , 0 , 0 , 1 , $object , $object_type );
$mesg = $langs -> transnoentitiesnoconv ( 'Notify_' . $notifcode ) . ' ' . $newref ;
break ;
2021-03-19 11:53:06 +01:00
}
2015-04-01 11:30:48 +02:00
$ref = dol_sanitizeFileName ( $newref );
2022-03-23 17:31:54 +01:00
$pdf_path = $dir_output . " / " . $ref . " / " . $ref . " .pdf " ;
2020-12-20 11:04:21 +01:00
if ( ! dol_is_file ( $pdf_path )) {
2014-10-25 00:42:52 +02:00
// We can't add PDF as it is not generated yet.
$filepdf = '' ;
2020-05-21 15:05:19 +02:00
} else {
2014-10-25 00:42:52 +02:00
$filepdf = $pdf_path ;
2021-03-19 11:53:06 +01:00
$filename_list [] = $pdf_path ;
$mimetype_list [] = mime_content_type ( $filepdf );
$mimefilename_list [] = $ref . " .pdf " ;
2014-10-25 00:42:52 +02:00
}
2015-03-19 11:47:30 +01:00
2024-04-22 15:17:38 +02:00
// Set output language
$outputlangs = $langs ;
// if an e-mail template is configured for this notification code (for instance 'SHIPPING_VALIDATE_TEMPLATE', ...),
// we fetch this template by its label. Otherwise, a default message content will be sent.
$mailTemplateLabel = getDolGlobalString ( $notifcode . '_TEMPLATE' );
2024-04-20 23:44:26 +02:00
$emailTemplate = null ;
if ( ! empty ( $mailTemplateLabel )) {
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
$formmail = new FormMail ( $this -> db );
2024-04-22 15:17:38 +02:00
$emailTemplate = $formmail -> getEMailTemplate ( $this -> db , $object_type . '_send' , $user , $outputlangs , 0 , 1 , $mailTemplateLabel );
2024-04-20 23:44:26 +02:00
}
if ( ! empty ( $mailTemplateLabel ) && is_object ( $emailTemplate ) && $emailTemplate -> id > 0 ) {
2024-04-22 15:17:38 +02:00
if ( property_exists ( $object , 'thirdparty' ) && $object -> thirdparty instanceof Societe && $object -> thirdparty -> default_lang && $object -> thirdparty -> default_lang != $langs -> defaultlang ) {
2024-04-20 23:44:26 +02:00
$outputlangs = new Translate ( '' , $conf );
2024-04-22 15:17:38 +02:00
$outputlangs -> setDefaultLang ( $object -> thirdparty -> default_lang );
2024-04-20 23:44:26 +02:00
$outputlangs -> loadLangs ( array ( 'main' , 'other' ));
}
$substitutionarray = getCommonSubstitutionArray ( $outputlangs , 0 , null , $object );
complete_substitutions_array ( $substitutionarray , $outputlangs , $object );
$subject = make_substitutions ( $emailTemplate -> topic , $substitutionarray , $outputlangs );
$message = make_substitutions ( $emailTemplate -> content , $substitutionarray , $outputlangs );
} else {
$message = '' ;
2024-04-22 15:17:38 +02:00
$message .= $outputlangs -> transnoentities ( " YouReceiveMailBecauseOfNotification2 " , $application , $mysoc -> name ) . " \n " ;
2024-04-20 23:44:26 +02:00
$message .= " \n " ;
$message .= $mesg ;
2018-10-16 03:30:17 +02:00
2024-04-20 23:44:26 +02:00
$message = nl2br ( $message );
}
2017-10-07 13:09:31 +02:00
// Replace keyword __SUPERVISOREMAIL__
2020-12-20 11:04:21 +01:00
if ( preg_match ( '/__SUPERVISOREMAIL__/' , $sendto )) {
2019-12-03 11:17:29 +01:00
$newval = '' ;
2020-12-20 11:04:21 +01:00
if ( $user -> fk_user > 0 ) {
2019-12-03 11:17:29 +01:00
$supervisoruser = new User ( $this -> db );
2017-10-07 13:09:31 +02:00
$supervisoruser -> fetch ( $user -> fk_user );
2020-12-20 11:04:21 +01:00
if ( $supervisoruser -> email ) {
$newval = trim ( dolGetFirstLastname ( $supervisoruser -> firstname , $supervisoruser -> lastname ) . ' <' . $supervisoruser -> email . '>' );
}
2017-10-07 13:09:31 +02:00
}
dol_syslog ( " Replace the __SUPERVISOREMAIL__ key into recipient email string with " . $newval );
$sendto = preg_replace ( '/__SUPERVISOREMAIL__/' , $newval , $sendto );
2019-12-03 11:17:29 +01:00
$sendto = preg_replace ( '/,\s*,/' , ',' , $sendto ); // in some case you can have $sendto like "email, __SUPERVISOREMAIL__ , otheremail" then you have "email, , othermail" and it's not valid
$sendto = preg_replace ( '/^[\s,]+/' , '' , $sendto ); // Clean start of string
$sendto = preg_replace ( '/[\s,]+$/' , '' , $sendto ); // Clean end of string
2017-10-07 13:09:31 +02:00
}
2020-12-20 11:04:21 +01:00
if ( $sendto ) {
2024-04-02 14:06:03 +02:00
$parameters = array ( 'notifcode' => $notifcode , 'sendto' => $sendto , 'from' => $from , 'file' => $filename_list , 'mimefile' => $mimetype_list , 'filename' => $mimefilename_list , 'subject' => & $subject , 'message' => & $message );
2019-12-03 11:17:29 +01:00
$reshook = $hookmanager -> executeHooks ( 'formatNotificationMessage' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2020-12-20 11:04:21 +01:00
if ( empty ( $reshook )) {
2022-12-28 15:29:55 +01:00
if ( ! empty ( $hookmanager -> resArray [ 'files' ])) {
$filename_list = $hookmanager -> resArray [ 'files' ][ 'file' ];
$mimetype_list = $hookmanager -> resArray [ 'files' ][ 'mimefile' ];
$mimefilename_list = $hookmanager -> resArray [ 'files' ][ 'filename' ];
}
2020-12-20 11:04:21 +01:00
if ( ! empty ( $hookmanager -> resArray [ 'subject' ])) {
$subject .= $hookmanager -> resArray [ 'subject' ];
}
if ( ! empty ( $hookmanager -> resArray [ 'message' ])) {
$message .= $hookmanager -> resArray [ 'message' ];
}
2017-10-07 13:09:31 +02:00
}
2020-10-31 14:32:18 +01:00
$mailfile = new CMailFile (
2017-10-07 13:09:31 +02:00
$subject ,
$sendto ,
2024-04-02 14:06:03 +02:00
$from ,
2017-10-07 13:09:31 +02:00
$message ,
2018-07-16 09:57:45 +02:00
$filename_list ,
$mimetype_list ,
$mimefilename_list ,
2017-10-07 13:09:31 +02:00
'' ,
'' ,
0 ,
2019-09-28 10:25:00 +02:00
1 ,
2020-10-31 14:32:18 +01:00
'' ,
$trackid ,
'' ,
'' ,
'notification'
2017-10-07 13:09:31 +02:00
);
2020-12-20 11:04:21 +01:00
if ( $mailfile -> sendfile ()) {
2022-01-27 10:19:35 +01:00
$sql = " INSERT INTO " . $this -> db -> prefix () . " notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email) " ;
2023-10-02 16:44:44 +02:00
$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 ) . " ') " ;
2020-12-20 11:04:21 +01:00
if ( ! $this -> db -> query ( $sql )) {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
$error ++ ;
2019-12-03 11:17:29 +01:00
$this -> errors [] = $mailfile -> error ;
2017-10-07 13:09:31 +02:00
}
}
}
}
2014-10-25 00:42:52 +02:00
2020-12-20 11:04:21 +01:00
if ( ! $error ) {
return $num ;
} else {
return - 1 * $error ;
}
2017-10-07 13:09:31 +02:00
}
2018-09-29 14:51:52 +02:00
}