|
@@ -117,9 +117,10 @@ class Notify
|
|
|
* @param int $socid Id of third party or 0 for all thirdparties or -1 for no thirdparties
|
|
|
* @param Object $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 <0 if KO, array of notifications to send if OK
|
|
|
*/
|
|
|
- function getNotificationsArray($notifcode,$socid=0,$object=null,$userid=0)
|
|
|
+ function getNotificationsArray($notifcode, $socid=0, $object=null, $userid=0, $scope=array('thirdparty', 'user', 'global'))
|
|
|
{
|
|
|
global $conf, $user;
|
|
|
|
|
@@ -131,7 +132,7 @@ class Notify
|
|
|
|
|
|
if (! $error)
|
|
|
{
|
|
|
- if ($socid >= 0)
|
|
|
+ if ($socid >= 0 && in_array('thirdparty', $scope))
|
|
|
{
|
|
|
$sql = "SELECT a.code, c.email, c.rowid";
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
|
|
@@ -178,7 +179,7 @@ class Notify
|
|
|
|
|
|
if (! $error)
|
|
|
{
|
|
|
- if ($userid >= 0)
|
|
|
+ if ($userid >= 0 && in_array('user', $scope))
|
|
|
{
|
|
|
$sql = "SELECT a.code, c.email, c.rowid";
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
|
|
@@ -223,42 +224,45 @@ class Notify
|
|
|
|
|
|
if (! $error)
|
|
|
{
|
|
|
- // List of notifications enabled for fixed email
|
|
|
- foreach($conf->global as $key => $val)
|
|
|
+ if (in_array('global', $scope))
|
|
|
{
|
|
|
- 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;
|
|
|
-
|
|
|
- $tmpemail=explode(',',$val);
|
|
|
- foreach($tmpemail as $key2 => $val2)
|
|
|
- {
|
|
|
- $newval2=trim($val2);
|
|
|
- if ($newval2 == '__SUPERVISOREMAIL__')
|
|
|
- {
|
|
|
- if ($user->fk_user > 0)
|
|
|
- {
|
|
|
- $tmpuser=new User($this->db);
|
|
|
- $tmpuser->fetch($user->fk_user);
|
|
|
- if ($tmpuser->email) $newval2=trim($tmpuser->email);
|
|
|
- else $newval2='';
|
|
|
- }
|
|
|
- else $newval2='';
|
|
|
- }
|
|
|
- if ($newval2)
|
|
|
- {
|
|
|
- $isvalid=isValidEmail($newval2, 0);
|
|
|
- if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
|
|
|
- }
|
|
|
- }
|
|
|
+ // List of notifications enabled for fixed email
|
|
|
+ foreach($conf->global as $key => $val)
|
|
|
+ {
|
|
|
+ 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;
|
|
|
+
|
|
|
+ $tmpemail=explode(',',$val);
|
|
|
+ foreach($tmpemail as $key2 => $val2)
|
|
|
+ {
|
|
|
+ $newval2=trim($val2);
|
|
|
+ if ($newval2 == '__SUPERVISOREMAIL__')
|
|
|
+ {
|
|
|
+ if ($user->fk_user > 0)
|
|
|
+ {
|
|
|
+ $tmpuser=new User($this->db);
|
|
|
+ $tmpuser->fetch($user->fk_user);
|
|
|
+ if ($tmpuser->email) $newval2=trim($tmpuser->email);
|
|
|
+ else $newval2='';
|
|
|
+ }
|
|
|
+ else $newval2='';
|
|
|
+ }
|
|
|
+ if ($newval2)
|
|
|
+ {
|
|
|
+ $isvalid=isValidEmail($newval2, 0);
|
|
|
+ if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|