FIX Counter of notification of a thirdparty
This commit is contained in:
parent
d975e7f442
commit
17a1874e36
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -188,11 +188,16 @@ if ($result > 0)
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
print '<tr><td class="titlefield">'.$langs->trans("NbOfActiveNotifications").'</td>';
|
||||
print '<tr><td class="titlefield">'.$langs->trans("NbOfActiveNotifications").'</td>'; // Notification for this thirdparty
|
||||
print '<td colspan="3">';
|
||||
$nbofrecipientemails=0;
|
||||
$notify=new Notify($db);
|
||||
$tmparray = $notify->getNotificationsArray('', $object->id);
|
||||
print count($tmparray);
|
||||
$tmparray = $notify->getNotificationsArray('', $object->id, null, 0, array('thirdparty'));
|
||||
foreach($tmparray as $tmpkey => $tmpval)
|
||||
{
|
||||
if (! empty($tmpkey)) $nbofrecipientemails++;
|
||||
}
|
||||
print $nbofrecipientemails;
|
||||
print '</td></tr>';
|
||||
print '</table>';
|
||||
|
||||
@ -394,13 +399,14 @@ if ($result > 0)
|
||||
print '<td align="right">'.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'</td>';
|
||||
print '</tr>';
|
||||
}*/
|
||||
if ($user->admin)
|
||||
|
||||
/*if ($user->admin)
|
||||
{
|
||||
$var = ! $var;
|
||||
print '<tr '.$bc[$var].'><td colspan="4">';
|
||||
print '+ <a href="'.DOL_URL_ROOT.'/admin/notification.php">'.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'</a>';
|
||||
print '</td></tr>';
|
||||
}
|
||||
}*/
|
||||
|
||||
print '</table>';
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user