From 21b1f7cc265ac0f7e5fe3be7ac36ca0ebc934ead Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 25 Mar 2015 14:51:12 +0100 Subject: [PATCH] Fix bad calculation of email for notifications --- htdocs/core/class/notify.class.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index aa92e6ee50f..8d54d05a810 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -91,7 +91,8 @@ class Notify $error=0; $num=0; - $valueforthreshold = $object->total_ht; + $valueforthreshold = 0; + if (is_object($object)) $valueforthreshold = $object->total_ht; if (! $error) { @@ -103,8 +104,11 @@ class Notify $sql.= " WHERE n.fk_contact = c.rowid"; $sql.= " AND a.rowid = n.fk_action"; $sql.= " AND n.fk_soc = s.rowid"; - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage - else $sql.= " AND a.code = '".$notifcode."'"; // New usage + if ($notifcode) + { + if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage + else $sql.= " AND a.code = '".$notifcode."'"; // New usage + } $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; if ($socid > 0) $sql.= " AND s.rowid = ".$socid; @@ -125,16 +129,21 @@ class Notify if (! $error) { + // List of notifications enabled for fixed email foreach($conf->global as $key => $val) { - if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; + if ($notifcode) + { + if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; + } + else + { + if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; + } $threshold = (float) $reg[1]; - if ($valueforthreshold <= $threshold) - { - continue; - } + if ($valueforthreshold < $threshold) continue; $tmpemail=explode(',',$val); $num+=count($tmpemail);