new:handle user notification in notification module

Conflicts:
	htdocs/core/lib/usergroups.lib.php
This commit is contained in:
abb 2016-03-13 00:20:29 +01:00
parent 543f5cef63
commit b6e39960b4
4 changed files with 64 additions and 8 deletions

View File

@ -94,10 +94,11 @@ class Notify
*
* @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
* @param int $userid Id of user or 0 for all users
* @param Object $object Object the notification is about (need it to check threshold value of some notifications)
* @return array|int <0 if KO, array of notifications to send if OK
*/
function getNotificationsArray($notifcode,$socid,$object=null)
function getNotificationsArray($notifcode,$socid= 0,$userid= 0,$object=null)
{
global $conf, $user;
@ -111,7 +112,8 @@ class Notify
{
$sql = "SELECT a.code, c.email, c.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
$sql.= " ".MAIN_DB_PREFIX."socpeople as c,";
if ($userid > 0) $sql.= " ".MAIN_DB_PREFIX."user as c,";
else $sql.= " ".MAIN_DB_PREFIX."socpeople as c,";
$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
$sql.= " ".MAIN_DB_PREFIX."societe as s";
$sql.= " WHERE n.fk_contact = c.rowid";
@ -124,6 +126,7 @@ class Notify
}
$sql.= " AND s.entity IN (".getEntity('societe', 1).")";
if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
elseif ($userid > 0) $sql.= " AND u.rowid = ".$userid;
dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
@ -253,7 +256,7 @@ class Notify
$newref=(empty($object->newref)?$object->ref:$object->newref);
// Check notification per third party
$sql = "SELECT s.nom, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
$sql = "SELECT 0 as user, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
$sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,";
$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
@ -265,6 +268,20 @@ class Notify
else $sql.= " AND a.code = '".$notifcode."'"; // New usage
$sql .= " AND s.rowid = ".$object->socid;
// Check notification per user
$sql.= "\nUNION\n";
$sql.= "SELECT 1 as user, c.email, c.rowid as cid, c.lastname, c.firstname, '$langs->defaultlang' as default_lang,";
$sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
$sql.= " FROM ".MAIN_DB_PREFIX."user as c,";
$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
$sql.= " ".MAIN_DB_PREFIX."notify_def as n,";
$sql.= " ".MAIN_DB_PREFIX."element_contact as ec";
$sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
$sql.= " AND n.fk_user = ec.fk_socpeople";
if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage
else $sql.= " AND a.code = '".$notifcode."'"; // New usage
$sql .= " AND ec.element_id = ".$object->id;
$result = $this->db->query($sql);
if ($result)
{
@ -386,9 +403,16 @@ class Notify
);
if ($mailfile->sendfile())
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)";
$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".$object->socid.", ".$obj->cid.", '".$obj->type."', '".$object_type."', ".$object->id.", '".$this->db->escape($obj->email)."')";
{ if ($obj->user==1){
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_user, type, objet_type, objet_id, email)";
$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".$obj->cid.", '".$obj->type."', '".$object_type."', ".$object->id.", '".$this->db->escape($obj->email)."')";
}
else {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)";
$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".$object->socid.", ".$obj->cid.", '".$obj->type."', '".$object_type."', ".$object->id.", '".$this->db->escape($obj->email)."')";
}
if (! $this->db->query($sql))
{
dol_print_error($this->db);

View File

@ -32,7 +32,7 @@
*/
function user_prepare_head($object)
{
global $db, $langs, $conf, $user;
global $langs, $conf, $user, $db;
$langs->load("users");
@ -88,6 +88,36 @@ function user_prepare_head($object)
$h++;
}
// Notifications
if ($user->societe_id == 0 && ! empty($conf->notification->enabled))
{
$nbNote = 0;
$sql = "SELECT COUNT(n.rowid) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n";
$sql.= " WHERE fk_user = ".$object->id;
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$nbNote=$obj->nb;
$i++;
}
}
else {
dol_print_error($db);
}
$head[$h][0] = DOL_URL_ROOT.'/user/notify/card.php?id='.$object->id;
$head[$h][1] = $langs->trans("Notifications");
if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
$head[$h][2] = 'notify';
$h++;
}
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab

View File

@ -416,6 +416,7 @@ Organization=Organization
AutomaticallyGenerated=Automatically generated
FiscalYearInformation=Information on the fiscal year
FiscalMonthStart=Starting month of the fiscal year
YouMustAssignUserMailFirst=You must create email for this user first to be able to add emails notifications for him.
YouMustCreateContactFirst=You must create emails contacts for third party first to be able to add emails notifications.
ListSuppliersShort=List of suppliers
ListProspectsShort=List of prospects
@ -442,4 +443,4 @@ ThirdpartiesMergeSuccess=Thirdparties have been merged
ErrorThirdpartiesMerge=There was an error when deleting the thirdparties. Please check the log. Changes have been reverted.
SaleRepresentativeLogin=Login of sale representative
SaleRepresentativeFirstname=Firstname of sale representative
SaleRepresentativeLastname=Lastname of sale representative
SaleRepresentativeLastname=Lastname of sale representative

View File

@ -416,6 +416,7 @@ Organization=Organisme
AutomaticallyGenerated=Généré automatiquement
FiscalYearInformation=Information sur l'année fiscale
FiscalMonthStart=Mois de début d'exercice
YouMustAssignUserMailFirst=Vous devez créer une adresse email pour cet utilisateur avant de pouvoir lui définir des notifications par emails.
YouMustCreateContactFirst=Vous devez créer un contact avec une adresse email sur le tiers avant de pouvoir lui définir des notifications par emails.
ListSuppliersShort=Liste fournisseurs
ListProspectsShort=Liste prospects