From a1a03a8061cee3381777f00c2f211fb4a3bab57d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 25 Oct 2014 01:20:59 +0200 Subject: [PATCH] New: Module notification has been enhanced: EMail use now language of target contact. Can also define a fixed email for notifications. Better error management --- htdocs/core/class/notify.class.php | 12 ++-- .../install/mysql/migration/3.6.0-3.7.0.sql | 1 + htdocs/install/mysql/tables/llx_notify.sql | 1 + htdocs/langs/en_US/admin.lang | 2 +- htdocs/langs/en_US/mails.lang | 4 +- htdocs/societe/notify/card.php | 55 +++++++++++++------ 6 files changed, 50 insertions(+), 25 deletions(-) diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index b7914be6e77..26506360e66 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -292,8 +292,8 @@ class Notify 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); @@ -330,6 +330,10 @@ class Notify $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++; @@ -417,8 +421,8 @@ class Notify 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); diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index 80730138ab3..c2e10543b7a 100644 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -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; diff --git a/htdocs/install/mysql/tables/llx_notify.sql b/htdocs/install/mysql/tables/llx_notify.sql index fa2936db0fb..21a7b833dec 100644 --- a/htdocs/install/mysql/tables/llx_notify.sql +++ b/htdocs/install/mysql/tables/llx_notify.sql @@ -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, diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 15bf8da0833..34f31092bfc 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1074,7 +1074,7 @@ ModuleCompanyCodeAquarium=Return an accountancy code built by:
%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:
* per third parties contacts (customers or suppliers), one third party at time.
* 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:
* per third parties contacts (customers or suppliers), one third party at time.
* 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 diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang index 0ad86123313..44027b4cc20 100644 --- a/htdocs/langs/en_US/mails.lang +++ b/htdocs/langs/en_US/mails.lang @@ -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 diff --git a/htdocs/societe/notify/card.php b/htdocs/societe/notify/card.php index 12cdb64c790..542a2066e93 100644 --- a/htdocs/societe/notify/card.php +++ b/htdocs/societe/notify/card.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2010-2012 Juanjo Menent * * This program is free software; you can redistribute it and/or modify @@ -191,12 +191,10 @@ if ($result > 0) print ''; print ''; - // Help - print '
'.$langs->trans("NotificationsDesc").'
'; - - dol_fiche_end(); + // Help + print $langs->trans("NotificationsDesc").'

'; print "\n"; @@ -372,19 +370,20 @@ if ($result > 0) print ''; 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 ''; // 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) @@ -400,17 +399,37 @@ if ($result > 0) $obj = $db->fetch_object($resql); - $contactstatic->id=$obj->id; - $contactstatic->lastname=$obj->lastname; - $contactstatic->firstname=$obj->firstname; - print ''.$contactstatic->getNomUrl(1); - print $obj->email?' <'.$obj->email.'>':$langs->trans("NoMail"); + print ''; + if ($obj->id > 0) + { + $contactstatic->id=$obj->id; + $contactstatic->lastname=$obj->lastname; + $contactstatic->firstname=$obj->firstname; + print $contactstatic->getNomUrl(1); + print $obj->email?' <'.$obj->email.'>':$langs->trans("NoMail"); + } + else + { + print $obj->email; + } print ''; print ''; $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label); print $label; print ''; - // TODO Add link to object here + print ''; + if ($obj->type == 'email') print $langs->trans("Email"); + if ($obj->type == 'sms') print $langs->trans("Sms"); + print ''; + // TODO Add link to object here for other types + /*print ''; + if ($obj->object_type == 'order') + { + $orderstatic->id=$obj->object_id; + $orderstatic->ref=... + print $orderstatic->getNomUrl(1); + } + print '';*/ // print print''.dol_print_date($db->jdate($obj->daten), 'dayhour').''; print ''; @@ -427,7 +446,7 @@ if ($result > 0) } else dol_print_error('','RecordNotFound'); -$db->close(); llxFooter(); +$db->close();