NEW Notification module can also manage notification per user.

This commit is contained in:
Laurent Destailleur 2016-07-15 17:25:09 +02:00
commit 6a30be1e67
11 changed files with 727 additions and 121 deletions

View File

@ -118,7 +118,11 @@ llxHeader('',$langs->trans("NotificationSetup"));
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($langs->trans("NotificationSetup"),$linkback,'title_setup');
print $langs->trans("NotificationsDesc").'<br><br>';
print $langs->trans("NotificationsDesc").'<br>';
print $langs->trans("NotificationsDescUser").'<br>';
if (! empty($conf->societe->enabled)) print $langs->trans("NotificationsDescContact").'<br>';
print $langs->trans("NotificationsDescGlobal").'<br>';
print '<br>';
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@ -141,52 +145,53 @@ print '</td>';
print '</tr>';
print '</table>';
print '<br>';
print '<br><br>';
if ($conf->societe->enabled)
// Notification per contacts
$title=$langs->trans("ListOfNotificationsPerUser");
if (! empty($conf->societe->enabled)) $title=$langs->trans("ListOfNotificationsPerUserOrContact");
print load_fiche_titre($title,'','');
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Label").'</td>';
/*print '<td>'.$langs->trans("Code").'</td>';
print '<td>'.$langs->trans("Label").'</td>';*/
//print '<td align="right">'.$langs->trans("NbOfTargetedContacts").'</td>';
print "</tr>\n";
// Load array of available notifications
$notificationtrigger=new InterfaceNotification($db);
$listofnotifiedevents=$notificationtrigger->getListOfManagedEvents();
print '<tr '.$bc[$var].'>';
print '<td>';
$var=true;
$i=0;
foreach($listofnotifiedevents as $notifiedevent)
{
print load_fiche_titre($langs->trans("ListOfNotificationsPerContact"),'','');
$var=!$var;
$label=$langs->trans("Notify_".$notifiedevent['code']); //!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label'];
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Module").'</td>';
print '<td>'.$langs->trans("Code").'</td>';
print '<td>'.$langs->trans("Label").'</td>';
//print '<td align="right">'.$langs->trans("NbOfTargetedContacts").'</td>';
print "</tr>\n";
if ($notifiedevent['elementtype'] == 'order_supplier') $elementLabel = $langs->trans('SupplierOrder');
elseif ($notifiedevent['elementtype'] == 'propal') $elementLabel = $langs->trans('Proposal');
elseif ($notifiedevent['elementtype'] == 'facture') $elementLabel = $langs->trans('Bill');
elseif ($notifiedevent['elementtype'] == 'commande') $elementLabel = $langs->trans('Order');
elseif ($notifiedevent['elementtype'] == 'ficheinter') $elementLabel = $langs->trans('Intervention');
// Load array of available notifications
$notificationtrigger=new InterfaceNotification($db);
$listofnotifiedevents=$notificationtrigger->getListOfManagedEvents();
$var=true;
foreach($listofnotifiedevents as $notifiedevent)
{
$var=!$var;
$label=$langs->trans("Notify_".$notifiedevent['code']); //!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label'];
if ($notifiedevent['elementtype'] == 'order_supplier') $elementLabel = $langs->trans('SupplierOrder');
elseif ($notifiedevent['elementtype'] == 'propal') $elementLabel = $langs->trans('Proposal');
elseif ($notifiedevent['elementtype'] == 'facture') $elementLabel = $langs->trans('Bill');
elseif ($notifiedevent['elementtype'] == 'commande') $elementLabel = $langs->trans('Order');
elseif ($notifiedevent['elementtype'] == 'ficheinter') $elementLabel = $langs->trans('Intervention');
print '<tr '.$bc[$var].'>';
print '<td>'.$elementLabel.'</td>';
print '<td>'.$notifiedevent['code'].'</td>';
print '<td>'.$label.'</td>';
/*print '<td align="right">';
$tmparray = $notify->getNotificationsArray($notifiedevent['code'], 0);
print count($tmparray);
print '</td>';*/
print '</tr>';
}
print '</table>';
print '* '.$langs->trans("GoOntoContactCardToAddMore").'<br>';
print '<br>';
if ($i) print ', ';
print $label;
$i++;
}
print '</td></tr>';
print '</table>';
print '* '.$langs->trans("GoOntoUserCardToAddMore").'<br>';
if (! empty($conf->societe->enabled)) print '** '.$langs->trans("GoOntoContactCardToAddMore").'<br>';
print '<br><br>';
print load_fiche_titre($langs->trans("ListOfFixedNotifications"),'','');

View File

@ -69,23 +69,29 @@ class Notify
global $langs;
$langs->load("mails");
$listofnotiftodo=$this->getNotificationsArray($action,$socid,$object);
$nb=count($listofnotiftodo);
if ($nb <= 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent");
if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent");
if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb);
$i=0;
foreach ($listofnotiftodo as $key => $val)
{
if ($i) $texte.=', ';
else $texte.=' (';
if ($val['isemailvalid']) $texte.=$val['email'];
else $texte.=$val['emaildesc'];
$i++;
}
if ($i) $texte.=')';
$listofnotiftodo=$this->getNotificationsArray($action,$socid,$object,0);
$nb=-1;
if (is_array($listofnotiftodo)) $nb=count($listofnotiftodo);
if ($nb < 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend");
if ($nb == 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent");
if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent");
if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb);
if (is_array($listofnotiftodo))
{
$i=0;
foreach ($listofnotiftodo as $key => $val)
{
if ($i) $texte.=', ';
else $texte.=' (';
if ($val['isemailvalid']) $texte.=$val['email'];
else $texte.=$val['emaildesc'];
$i++;
}
if ($i) $texte.=')';
}
return $texte;
}
@ -93,11 +99,12 @@ class Notify
* Return number of notifications activated for action code (and third party)
*
* @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 $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
* @return array|int <0 if KO, array of notifications to send if OK
*/
function getNotificationsArray($notifcode,$socid,$object=null)
function getNotificationsArray($notifcode,$socid=0,$object=null,$userid=0)
{
global $conf, $user;
@ -109,45 +116,94 @@ class Notify
if (! $error)
{
$sql = "SELECT a.code, c.email, c.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
$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";
$sql.= " AND a.rowid = n.fk_action";
$sql.= " AND n.fk_soc = s.rowid";
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;
dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i=0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
if ($obj)
{
$isvalid=isValidEmail($newval2);
$resarray[] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>trim($obj->email), 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
}
$i++;
}
}
else
{
$error++;
$this->error=$this->db->lasterror();
}
if ($socid >= 0)
{
$sql = "SELECT a.code, c.email, c.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
$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";
$sql.= " AND a.rowid = n.fk_action";
$sql.= " AND n.fk_soc = s.rowid";
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;
dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i=0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
if ($obj)
{
$newval2=trim($obj->email);
$isvalid=isValidEmail($newval2);
if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
}
$i++;
}
}
else
{
$error++;
$this->error=$this->db->lasterror();
}
}
}
if (! $error)
{
if ($userid >= 0)
{
$sql = "SELECT a.code, c.email, c.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
$sql.= " ".MAIN_DB_PREFIX."user as c,";
$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a";
$sql.= " WHERE n.fk_user = c.rowid";
$sql.= " AND a.rowid = n.fk_action";
if ($notifcode)
{
if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage
else $sql.= " AND a.code = '".$notifcode."'"; // New usage
}
$sql.= " AND c.entity IN (".getEntity('user', 1).")";
if ($userid > 0) $sql.= " AND c.rowid = ".$userid;
dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i=0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
if ($obj)
{
$newval2=trim($obj->email);
$isvalid=isValidEmail($newval2);
if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
}
$i++;
}
}
else
{
$error++;
$this->error=$this->db->lasterror();
}
}
}
if (! $error)
@ -177,7 +233,7 @@ class Notify
{
$tmpuser=new User($this->db);
$tmpuser->fetch($user->fk_user);
if ($tmpuser->email) $newval2=$tmpuser->email;
if ($tmpuser->email) $newval2=trim($tmpuser->email);
else $newval2='';
}
else $newval2='';
@ -185,7 +241,7 @@ class Notify
if ($newval2)
{
$isvalid=isValidEmail($newval2, 0);
$resarray[]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>trim($newval2), 'isemailvalid'=>$isvalid);
if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
}
}
}
@ -254,7 +310,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 'tocontactid' as type_target, 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,";
@ -266,6 +322,29 @@ 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;*/
$sql.= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang 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.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage
else $sql.= " AND a.code = '".$notifcode."'"; // New usage
$result = $this->db->query($sql);
if ($result)
{
@ -393,9 +472,17 @@ 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->type_target == 'touserid') {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$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, type_target, objet_id, email)";
$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
}
if (! $this->db->query($sql))
{
dol_print_error($this->db);
@ -420,10 +507,11 @@ class Notify
}
}
else
{
{
$error++;
$this->errors[]=$this->db->lasterror();
return -1;
dol_syslog("Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
return -1;
}
// Check notification using fixed email
@ -579,8 +667,8 @@ 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.", null, 'email', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", null, 'email', 'tofixedemail', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')";
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

@ -22,6 +22,9 @@
-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup);
ALTER TABLE llx_user DROP COLUMN phenix_login;
ALTER TABLE llx_user DROP COLUMN phenix_pass;
ALTER TABLE llx_societe ADD COLUMN fk_account integer;
ALTER TABLE llx_website ADD COLUMN virtualhost varchar(255) after fk_default_home;
@ -31,5 +34,5 @@ ALTER TABLE llx_ecm_files ADD COLUMN gen_or_uploaded varchar(12) after cover;
DROP TABLE llx_document_generator;
DROP TABLE llx_ecm_documents;
ALTER TABLE llx_notify ADD COLUMN type_target varchar(16) NULL;

View File

@ -28,6 +28,7 @@ create table llx_notify
fk_contact integer NULL,
fk_user integer NULL,
type varchar(16) DEFAULT 'email',
type_target varchar(16) NULL, -- What type of target notification was sent to ? 'tocontactid', 'touserid', 'tofixedemail'
objet_type varchar(24) NOT NULL,
objet_id integer NOT NULL,
email varchar(255)

View File

@ -471,7 +471,7 @@ Module510Desc=Management of employees salaries and payments
Module520Name=Loan
Module520Desc=Management of loans
Module600Name=Notifications
Module600Desc=Send EMail notifications (triggered by some business events) to third-party contacts (setup defined on each thirdparty) or fixed emails
Module600Desc=Send EMail notifications (triggered by some business events) to users (setup defined on each user), third-party contacts (setup defined on each thirdparty) or fixed emails
Module700Name=Donations
Module700Desc=Donation management
Module770Name=Expense reports
@ -1070,7 +1070,10 @@ HRMSetup=HRM module setup
CompanySetup=Companies module setup
CompanyCodeChecker=Module for third parties code generation and checking (customer or supplier)
AccountCodeManager=Module for accountancy code generation (customer or supplier)
NotificationsDesc=EMails notifications feature allows you to silently send automatic mail, for some Dolibarr events. Targets of notifications can be defined:<br>* per third parties contacts (customers or suppliers), one contact at time.<br>* or by setting global target email addresses in module setup page.
NotificationsDesc=EMails notifications feature allows you to silently send automatic mail, for some Dolibarr events. Targets of notifications can be defined:
NotificationsDescUser=* per users, one user at time.
NotificationsDescContact=* per third parties contacts (customers or suppliers), one contact at time.
NotificationsDescGlobal=* or by setting global target emails in module setup page.
ModelModules=Documents templates
DocumentModelOdt=Generate documents from OpenDocuments templates (.ODT or .ODS files for OpenOffice, KOffice, TextEdit,...)
WatermarkOnDraft=Watermark on draft document
@ -1521,8 +1524,10 @@ ExpenseReportsSetup=Setup of module Expense Reports
TemplatePDFExpenseReports=Document templates to generate expense report document
NoModueToManageStockIncrease=No module able to manage automatic stock increase has been activated. Stock increase will be done on manual input only.
YouMayFindNotificationsFeaturesIntoModuleNotification=You may find options for EMail notifications by enabling and configuring the module "Notification".
ListOfNotificationsPerContact=List of notifications per contact*
ListOfNotificationsPerUser=List of notifications per user*
ListOfNotificationsPerUserOrContact=List of notifications per user* or per contact**
ListOfFixedNotifications=List of fixed notifications
GoOntoUserCardToAddMore=Go on the tab "Notifications" of a user to add or remove notifications for users
GoOntoContactCardToAddMore=Go on the tab "Notifications" of a thirdparty contact to add or remove notifications for contacts/addresses
Threshold=Threshold
BackupDumpWizard=Wizard to build database backup dump file

View File

@ -368,7 +368,8 @@ AllocateCommercial=Assigned to sales representative
Organization=Organization
FiscalYearInformation=Information on the fiscal year
FiscalMonthStart=Starting month of the fiscal year
YouMustCreateContactFirst=To be able to add email notifications, you must first insert email contacts for the third party
YouMustAssignUserMailFirst=You must create email for this user first to be able to add emails notifications for him.
YouMustCreateContactFirst=To be able to add email notifications, you must first define contacts with valid emails for the third party
ListSuppliersShort=List of suppliers
ListProspectsShort=List of prospects
ListCustomersShort=List of customers

View File

@ -111,7 +111,7 @@ NoNotificationsWillBeSent=No email notifications are planned for this event and
ANotificationsWillBeSent=1 notification will be sent by email
SomeNotificationsWillBeSent=%s notifications will be sent by email
AddNewNotification=Activate a new email notification target
ListOfActiveNotifications=List all active email notification targets
ListOfActiveNotifications=List all active targets for email notification
ListOfNotificationsDone=List all email notifications sent
MailSendSetupIs=Configuration of email sending has been setup to '%s'. This mode can't be used to send mass emailing.
MailSendSetupIs2=You must first go, with an admin account, into menu %sHome - Setup - EMails%s to change parameter <strong>'%s'</strong> to use mode '%s'. With this mode, you can enter setup of the SMTP server provided by your Internet Service Provider and use Mass emailing feature.

View File

@ -368,6 +368,7 @@ AllocateCommercial=Affecter un commercial
Organization=Organisme
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

View File

@ -194,16 +194,20 @@ if ($result > 0)
print '</td></tr>';
print '</table>';
// Help
print '<br>'.$langs->trans("NotificationsDesc");
print '</div>';
dol_fiche_end();
print "\n";
print '<br>';
// Help
print '<br>'.$langs->trans("NotificationsDesc");
print '<br>'.$langs->trans("NotificationsDescUser");
print '<br>'.$langs->trans("NotificationsDescContact");
print '<br>'.$langs->trans("NotificationsDescGlobal");
print '<br><br><br>'."\n";
// Add notification form
print load_fiche_titre($langs->trans("AddNewNotification"),'','');
@ -392,7 +396,9 @@ if ($result > 0)
}
print '</table>';
print '<br>';
print '<br><br>'."\n";
// List of notifications done

466
htdocs/user/notify/card.php Normal file
View File

@ -0,0 +1,466 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2016 Abbes Bahfir <contact@dolibarrpar.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/user/notify/card.php
* \ingroup user notification
* \brief Tab for notifications of third party
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/triggers/interface_50_modNotification_Notification.class.php';
$langs->load("companies");
$langs->load("mails");
$langs->load("admin");
$langs->load("other");
$id = GETPOST("id",'int');
$action = GETPOST('action');
$actionid=GETPOST('actionid');
// Security check
if ($user->societe_id) $id=$user->societe_id;
$result = restrictedArea($user, 'societe','','');
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST("page",'int');
if ($page == -1) { $page = 0; }
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="c.lastname";
$now=dol_now();
/*
* Actions
*/
// Add a notification
if ($action == 'add')
{
$error=0;
if ($actionid <= 0)
{
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Action")), 'errors');
$error++;
}
if (! $error)
{
$db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def";
$sql .= " WHERE fk_user=".$id." AND fk_action=".$actionid;
if ($db->query($sql))
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_user, fk_action)";
$sql .= " VALUES ('".$db->idate($now)."',".$id.",".$actionid.")";
if (! $db->query($sql))
{
$error++;
dol_print_error($db);
}
}
else
{
dol_print_error($db);
}
if (! $error)
{
$db->commit();
}
else
{
$db->rollback();
}
}
}
// Remove a notification
if ($action == 'delete')
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def where rowid=".$_GET["actid"];
$db->query($sql);
}
/*
* View
*/
$form = new Form($db);
$object = new User($db);
$result=$object->fetch($id);
$title=$langs->trans("ThirdParty").' - '.$langs->trans("Notification");
if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Notification");
$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('',$title,$help_url);
if ($result > 0)
{
$langs->load("other");
$head = user_prepare_head($object);
dol_fiche_head($head, 'notify', $langs->trans("User"),0,'user');
print '<table class="border"width="100%">';
// Ref
print '<tr><td width="25%">'.$langs->trans("Ref").'</td>';
print '<td colspan="3">';
print $form->showrefnav($object,'id','',$user->rights->user->user->lire || $user->admin);
print '</td>';
print '</tr>'."\n";
print '<tr><td>'.$langs->trans("Lastname").'</td>';
print '<td colspan="2">'.$object->lastname.'</td>';
// Firstname
print '<tr><td>'.$langs->trans("Firstname").'</td>';
print '<td colspan="2">'.$object->firstname.'</td>';
print '</tr>'."\n";
// EMail
print '<tr><td>'.$langs->trans("EMail").'</td>';
print '<td colspan="2">'.dol_print_email($object->email,0,0,1).'</td>';
print "</tr>\n";
print '</table>';
dol_fiche_end();
print "\n";
// Help
print '<br>'.$langs->trans("NotificationsDesc");
print '<br>'.$langs->trans("NotificationsDescUser");
print '<br>'.$langs->trans("NotificationsDescContact");
print '<br>'.$langs->trans("NotificationsDescGlobal");
print '<br><br><br>'."\n";
// Add notification form
print_fiche_titre($langs->trans("AddNewNotification"),'','');
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">';
$param="&id=".$id;
// Line with titles
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("Target"),$_SERVER["PHP_SELF"],"c.lastname",'',$param,'"width="45%"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Action"),$_SERVER["PHP_SELF"],"a.titre",'',$param,'"width="35%"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"",'',$param,'"width="10%"',$sortfield,$sortorder);
print_liste_field_titre('');
print "</tr>\n";
$var=false;
// $listofemails=$object->thirdparty_and_contact_email_array();
if ($object->email)
{
$actions=array();
// Load array of available notifications
$notificationtrigger=new InterfaceNotification($db);
$listofnotifiedevents=$notificationtrigger->getListOfManagedEvents();
foreach($listofnotifiedevents as $notifiedevent)
{
$label=($langs->trans("Notify_".$notifiedevent['code'])!="Notify_".$notifiedevent['code']?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label']);
$actions[$notifiedevent['rowid']]=$label;
}
print '<tr '.$bc[$var].'><td>';
print $object->getNomUrl(1);
if (isValidEmail($object->email))
{
print ' &lt;'.$object->email.'&gt;';
}
else
{
$langs->load("errors");
print ' &nbsp; '.img_warning().' '.$langs->trans("ErrorBadEMail",$object->email);
}
print '</td>';
print '<td>';
print $form->selectarray("actionid",$actions,'',1);
print '</td>';
print '<td>';
$type=array('email'=>$langs->trans("EMail"));
print $form->selectarray("typeid",$type);
print '</td>';
print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';
}
else
{
print '<tr '.$bc[$var].'><td colspan="4">';
print $langs->trans("YouMustAssignUserMailFirst");
print '</td></tr>';
}
print '</table>';
print '</form>';
print '<br>';
// List of active notifications
print_fiche_titre($langs->trans("ListOfActiveNotifications"),'','');
$var=true;
// Line with titles
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("Target"),$_SERVER["PHP_SELF"],"c.lastname",'',$param,'"width="45%"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Action"),$_SERVER["PHP_SELF"],"a.titre",'',$param,'"width="35%"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"",'',$param,'"width="10%"',$sortfield,$sortorder);
print_liste_field_titre('','','');
print '</tr>';
$langs->load("errors");
$langs->load("other");
// List of notifications enabled for contacts
$sql = "SELECT n.rowid, n.type,";
$sql.= " a.code, a.label,";
$sql.= " c.rowid as userid, c.lastname, c.firstname, c.email";
$sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
$sql.= " ".MAIN_DB_PREFIX."notify_def as n,";
$sql.= " ".MAIN_DB_PREFIX."user c";
$sql.= " WHERE a.rowid = n.fk_action";
$sql.= " AND c.rowid = n.fk_user";
$sql.= " AND c.rowid = ".$object->id;
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
$userstatic=new user($db);
while ($i < $num)
{
$var = !$var;
$obj = $db->fetch_object($resql);
$userstatic->id=$obj->userid;
$userstatic->lastname=$obj->lastname;
$userstatic->firstname=$obj->firstname;
print '<tr '.$bc[$var].'><td>'.$userstatic->getNomUrl(1);
if ($obj->type == 'email')
{
if (isValidEmail($obj->email))
{
print ' &lt;'.$obj->email.'&gt;';
}
else
{
$langs->load("errors");
print ' &nbsp; '.img_warning().' '.$langs->trans("ErrorBadEMail",$obj->email);
}
}
print '</td>';
print '<td>';
$label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
print $label;
print '</td>';
print '<td>';
if ($obj->type == 'email') print $langs->trans("Email");
if ($obj->type == 'sms') print $langs->trans("SMS");
print '</td>';
print '<td align="right"><a href="card.php?id='.$id.'&action=delete&actid='.$obj->rowid.'">'.img_delete().'</a></td>';
print '</tr>';
$i++;
}
$db->free($resql);
}
else
{
dol_print_error($db);
}
// List of notifications enabled for fixed email
/*
foreach($conf->global as $key => $val)
{
if (! preg_match('/^NOTIFICATION_FIXEDEMAIL_(.*)/', $key, $reg)) continue;
$var = ! $var;
print '<tr '.$bc[$var].'><td>';
$listtmp=explode(',',$val);
$first=1;
foreach($listtmp as $keyemail => $valemail)
{
if (! $first) print ', ';
$first=0;
$valemail=trim($valemail);
//print $keyemail.' - '.$valemail.' - '.$reg[1].'<br>';
if (isValidEmail($valemail, 1))
{
if ($valemail == '__SUPERVISOREMAIL__') print $valemail;
else print ' &lt;'.$valemail.'&gt;';
}
else
{
print ' '.img_warning().' '.$langs->trans("ErrorBadEMail",$valemail);
}
}
print '</td>';
print '<td>';
$notifcode=preg_replace('/_THRESHOLD_.*$/','',$reg[1]);
$notifcodecond=preg_replace('/^.*_(THRESHOLD_)/','$1',$reg[1]);
$label=($langs->trans("Notify_".$notifcode)!="Notify_".$notifcode?$langs->trans("Notify_".$notifcode):$notifcode);
print $label;
if (preg_match('/^THRESHOLD_HIGHER_(.*)$/',$notifcodecond,$regcond) && ($regcond[1] > 0))
{
print ' - '.$langs->trans("IfAmountHigherThan",$regcond[1]);
}
print '</td>';
print '<td>';
print $langs->trans("Email");
print '</td>';
print '<td align="right">'.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'</td>';
print '</tr>';
}*/
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>';
print '<br><br>'."\n";
// List of notifications done
print_fiche_titre($langs->trans("ListOfNotificationsDone"),'','');
$var=true;
// Line with titles
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("Target"),$_SERVER["PHP_SELF"],"c.lastname",'',$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Action"),$_SERVER["PHP_SELF"],"a.titre",'',$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"",'',$param,'',$sortfield,$sortorder);
//print_liste_field_titre($langs->trans("Object"),$_SERVER["PHP_SELF"],"",'',$param,'"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"a.daten",'',$param,'align="right"',$sortfield,$sortorder);
print '</tr>';
// List
$sql = "SELECT n.rowid, n.daten, n.email, n.objet_type as object_type, n.objet_id as object_id, n.type,";
$sql.= " c.rowid as id, c.lastname, c.firstname, c.email as contactemail,";
$sql.= " a.code, a.label";
$sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
$sql.= " ".MAIN_DB_PREFIX."notify as n ";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as c ON n.fk_user = c.rowid";
$sql.= " WHERE a.rowid = n.fk_action";
$sql.= " AND n.fk_user = ".$object->id;
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
$userstatic=new User($db);
while ($i < $num)
{
$var = !$var;
$obj = $db->fetch_object($resql);
print '<tr '.$bc[$var].'><td>';
if ($obj->id > 0)
{
$userstatic->id=$obj->id;
$userstatic->lastname=$obj->lastname;
$userstatic->firstname=$obj->firstname;
print $userstatic->getNomUrl(1);
print $obj->email?' &lt;'.$obj->email.'&gt;':$langs->trans("NoMail");
}
else
{
print $obj->email;
}
print '</td>';
print '<td>';
$label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
print $label;
print '</td>';
print '<td>';
if ($obj->type == 'email') print $langs->trans("Email");
if ($obj->type == 'sms') print $langs->trans("Sms");
print '</td>';
// TODO Add link to object here for other types
/*print '<td>';
if ($obj->object_type == 'order')
{
$orderstatic->id=$obj->object_id;
$orderstatic->ref=...
print $orderstatic->getNomUrl(1);
}
print '</td>';*/
// print
print'<td align="right">'.dol_print_date($db->jdate($obj->daten), 'dayhour').'</td>';
print '</tr>';
$i++;
}
$db->free($resql);
}
else
{
dol_print_error($db);
}
print '</table>';
}
else dol_print_error('','RecordNotFound');
llxFooter();
$db->close();