Skip to content

Commit

Permalink
New: Module notification has been enhanced:
Browse files Browse the repository at this point in the history
EMail use now language of target contact.
Can also define a fixed email for notifications.
Better error management
  • Loading branch information
eldy committed Oct 24, 2014
1 parent 0fc1c85 commit a1a03a8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 25 deletions.
12 changes: 8 additions & 4 deletions htdocs/core/class/notify.class.php
Expand Up @@ -292,8 +292,8 @@ function send($action, $object)

if ($mailfile->sendfile())
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_contact, objet_type, objet_id, email)";
$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$actiondefid.", ".$obj->cid.", '".$object_type."', ".$object->id.", '".$this->db->escape($obj->email)."')";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, objet_type, objet_id, email)";
$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$actiondefid.", ".$object->socid.", ".$obj->cid.", '".$object_type."', ".$object->id.", '".$this->db->escape($obj->email)."')";
if (! $this->db->query($sql))
{
dol_print_error($this->db);
Expand Down Expand Up @@ -330,6 +330,10 @@ function send($action, $object)
$param='NOTIFICATION_FIXEDEMAIL_'.$action;
if (! empty($conf->global->$param))
{
$sendto = $conf->global->$param;
$actiondefid = dol_getIdFromCode($this->db, $action, 'c_action_trigger', 'code', 'rowid');
if ($actiondefid <= 0) dol_print_error($this->db, 'Failed to get id from code');

$object_type = '';
$link = '';
$num++;
Expand Down Expand Up @@ -417,8 +421,8 @@ function send($action, $object)

if ($mailfile->sendfile())
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_contact, objet_type, objet_id, email)";
$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$actiondefid.", ".$obj->cid.", '".$object_type."', ".$object->id.", '".$this->db->escape($obj->email)."')";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, objet_type, objet_id, email)";
$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$actiondefid.", ".$object->socid.", null, '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')";
if (! $this->db->query($sql))
{
dol_print_error($this->db);
Expand Down
1 change: 1 addition & 0 deletions htdocs/install/mysql/migration/3.6.0-3.7.0.sql
Expand Up @@ -24,6 +24,7 @@
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_CLASSIFYBILLED','Intervention set billed','Executed when a intervention is set to billed (when option FICHINTER_DISABLE_DETAILS is set)','ficheinter',19);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_SENTBYMAIL','Intervention sent by mail','Executed when a intervention is sent by mail','ficheinter',19);

ALTER TABLE llx_notify ADD COLUMN fk_soc integer NULL after fk_action;

ALTER TABLE llx_bank_account ADD COLUMN fk_user_author integer;

Expand Down
1 change: 1 addition & 0 deletions htdocs/install/mysql/tables/llx_notify.sql
Expand Up @@ -23,6 +23,7 @@ create table llx_notify
tms timestamp,
daten datetime, -- date de la notification
fk_action integer NOT NULL,
fk_soc integer NULL,
fk_contact integer NULL,
fk_user integer NULL,
objet_type varchar(24) NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion htdocs/langs/en_US/admin.lang
Expand Up @@ -1074,7 +1074,7 @@ ModuleCompanyCodeAquarium=Return an accountancy code built by:<br>%s followed by
ModuleCompanyCodePanicum=Return an empty accountancy code.
ModuleCompanyCodeDigitaria=Accountancy code depends on third party code. The code is composed of the character "C" in the first position followed by the first 5 characters of the third party code.
UseNotifications=Use notifications
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 third party at time.<br>* or by setting a global target email address on this page.
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 third party at time.<br>* or by setting a global target email address on 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
Expand Down
4 changes: 2 additions & 2 deletions htdocs/langs/en_US/mails.lang
Expand Up @@ -133,6 +133,6 @@ Notifications=Notifications
NoNotificationsWillBeSent=No email notifications are planned for this event and company
ANotificationsWillBeSent=1 notification will be sent by email
SomeNotificationsWillBeSent=%s notifications will be sent by email
AddNewNotification=Activate a new email notification request
ListOfActiveNotifications=List all active email notification requests
AddNewNotification=Activate a new email notification target
ListOfActiveNotifications=List all active email notification targets
ListOfNotificationsDone=List all email notifications sent
55 changes: 37 additions & 18 deletions htdocs/societe/notify/card.php
@@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -191,12 +191,10 @@
print '</td></tr>';
print '</table>';

// Help
print '<br>'.$langs->trans("NotificationsDesc").'<br>';


dol_fiche_end();

// Help
print $langs->trans("NotificationsDesc").'<br><br>';

print "\n";

Expand Down Expand Up @@ -372,19 +370,20 @@
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, n.objet_id,";
$sql.= " c.rowid as id, c.lastname, c.firstname, c.email,";
$sql = "SELECT n.rowid, n.daten, n.email, n.objet_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.= " ".MAIN_DB_PREFIX."socpeople as c";
$sql.= " ".MAIN_DB_PREFIX."notify as n ";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as c ON n.fk_contact = c.rowid";
$sql.= " WHERE a.rowid = n.fk_action";
$sql.= " AND c.rowid = n.fk_contact";
$sql.= " AND c.fk_soc = ".$object->id;
$sql.= " AND n.fk_soc = ".$object->id;

$resql=$db->query($sql);
if ($resql)
Expand All @@ -400,17 +399,37 @@

$obj = $db->fetch_object($resql);

$contactstatic->id=$obj->id;
$contactstatic->lastname=$obj->lastname;
$contactstatic->firstname=$obj->firstname;
print '<tr '.$bc[$var].'><td>'.$contactstatic->getNomUrl(1);
print $obj->email?' &lt;'.$obj->email.'&gt;':$langs->trans("NoMail");
print '<tr '.$bc[$var].'><td>';
if ($obj->id > 0)
{
$contactstatic->id=$obj->id;
$contactstatic->lastname=$obj->lastname;
$contactstatic->firstname=$obj->firstname;
print $contactstatic->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>';
// TODO Add link to object here
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>';
Expand All @@ -427,7 +446,7 @@
}
else dol_print_error('','RecordNotFound');

$db->close();

llxFooter();

$db->close();

0 comments on commit a1a03a8

Please sign in to comment.