FIX Counter of notification of a thirdparty

This commit is contained in:
Laurent Destailleur 2017-04-01 13:43:05 +02:00
parent d975e7f442
commit 17a1874e36
2 changed files with 53 additions and 43 deletions

View File

@ -117,9 +117,10 @@ class Notify
* @param int $socid Id of third party or 0 for all thirdparties or -1 for no thirdparties * @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 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 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 * @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; global $conf, $user;
@ -131,7 +132,7 @@ class Notify
if (! $error) if (! $error)
{ {
if ($socid >= 0) if ($socid >= 0 && in_array('thirdparty', $scope))
{ {
$sql = "SELECT a.code, c.email, c.rowid"; $sql = "SELECT a.code, c.email, c.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
@ -178,7 +179,7 @@ class Notify
if (! $error) if (! $error)
{ {
if ($userid >= 0) if ($userid >= 0 && in_array('user', $scope))
{ {
$sql = "SELECT a.code, c.email, c.rowid"; $sql = "SELECT a.code, c.email, c.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
@ -222,6 +223,8 @@ class Notify
} }
if (! $error) if (! $error)
{
if (in_array('global', $scope))
{ {
// List of notifications enabled for fixed email // List of notifications enabled for fixed email
foreach($conf->global as $key => $val) foreach($conf->global as $key => $val)
@ -261,6 +264,7 @@ class Notify
} }
} }
} }
}
if ($error) return -1; if ($error) return -1;

View File

@ -188,11 +188,16 @@ if ($result > 0)
print '</td></tr>'; 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">'; print '<td colspan="3">';
$nbofrecipientemails=0;
$notify=new Notify($db); $notify=new Notify($db);
$tmparray = $notify->getNotificationsArray('', $object->id); $tmparray = $notify->getNotificationsArray('', $object->id, null, 0, array('thirdparty'));
print count($tmparray); foreach($tmparray as $tmpkey => $tmpval)
{
if (! empty($tmpkey)) $nbofrecipientemails++;
}
print $nbofrecipientemails;
print '</td></tr>'; print '</td></tr>';
print '</table>'; print '</table>';
@ -394,13 +399,14 @@ if ($result > 0)
print '<td align="right">'.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'</td>'; print '<td align="right">'.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'</td>';
print '</tr>'; print '</tr>';
}*/ }*/
if ($user->admin)
/*if ($user->admin)
{ {
$var = ! $var; $var = ! $var;
print '<tr '.$bc[$var].'><td colspan="4">'; print '<tr '.$bc[$var].'><td colspan="4">';
print '+ <a href="'.DOL_URL_ROOT.'/admin/notification.php">'.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'</a>'; print '+ <a href="'.DOL_URL_ROOT.'/admin/notification.php">'.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'</a>';
print '</td></tr>'; print '</td></tr>';
} }*/
print '</table>'; print '</table>';