From 38e757f4ae05bbe2813e9a4317e189fd88d1085c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 9 Jan 2010 14:48:27 +0000 Subject: [PATCH] Fix: Debug module notification. New: Can use email notification when validating proposal or orders. --- htdocs/comm/propal.php | 22 +- htdocs/commande/fiche.php | 15 +- htdocs/compta/facture.php | 10 +- ...ace_modNotification_Notification.class.php | 412 +++++++++--------- .../install/mysql/migration/2.7.0-2.8.0.sql | 1 + htdocs/install/mysql/tables/llx_notify.sql | 4 +- htdocs/notify.class.php | 38 +- 7 files changed, 271 insertions(+), 231 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 7aee0d84803..82441464352 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -973,7 +973,27 @@ if ($id > 0 || ! empty($ref)) */ if ($_GET['action'] == 'validate') { - $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?propalid='.$propal->id, $langs->trans('ValidateProp'), $langs->trans('ConfirmValidateProp'), 'confirm_validate','',0,1); + // on verifie si l'objet est en numerotation provisoire + $ref = substr($propal->ref, 1, 4); + if ($ref == 'PROV') + { + $numref = $propal->getNextNumRef($soc); + } + else + { + $numref = $propal->ref; + } + + $text=$langs->trans('ConfirmValidateProp',$numref); + if ($conf->notification->enabled) + { + require_once(DOL_DOCUMENT_ROOT ."/notify.class.php"); + $notify=new Notify($db); + $text.='
'; + $text.=$notify->confirmMessage('NOTIFY_VAL_PROPAL',$propal->socid); + } + + $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?propalid='.$propal->id, $langs->trans('ValidateProp'), $text, 'confirm_validate','',0,1); if ($ret == 'html') print '
'; } diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 708dca8e467..fbb31c56516 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1242,18 +1242,25 @@ else */ if ($_GET['action'] == 'validate') { - // on verifie si la facture est en numerotation provisoire + // on verifie si l'objet est en numerotation provisoire $ref = substr($commande->ref, 1, 4); if ($ref == 'PROV') { - $num = $commande->getNextNumRef($soc); + $numref = $commande->getNextNumRef($soc); } else { - $num = $commande->ref; + $numref = $commande->ref; } - $text=$langs->trans('ConfirmValidateOrder',$num); + $text=$langs->trans('ConfirmValidateOrder',$numref); + if ($conf->notification->enabled) + { + require_once(DOL_DOCUMENT_ROOT ."/notify.class.php"); + $notify=new Notify($db); + $text.='
'; + $text.=$notify->confirmMessage('NOTIFY_VAL_ORDER',$commande->socid); + } $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', '', 0, 1); if ($ret == 'html') print '
'; } diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 275a109fe21..d11e6e2f764 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -2060,7 +2060,7 @@ else // Confirmation de la validation if ($_GET['action'] == 'valid') { - // on verifie si la facture est en numerotation provisoire + // on verifie si l'objet est en numerotation provisoire $facref = substr($fac->ref, 1, 4); if ($facref == 'PROV') { @@ -2070,21 +2070,21 @@ else $fac->date=gmmktime(); $fac->date_lim_reglement=$fac->calculate_date_lim_reglement(); } - $numfa = $fac->getNextNumRef($soc); + $numref = $fac->getNextNumRef($soc); //$fac->date=$savdate; } else { - $numfa = $fac->ref; + $numref = $fac->ref; } - $text=$langs->trans('ConfirmValidateBill',$numfa); + $text=$langs->trans('ConfirmValidateBill',$numref); if ($conf->notification->enabled) { require_once(DOL_DOCUMENT_ROOT ."/notify.class.php"); $notify=new Notify($db); $text.='
'; - $text.=$notify->confirmMessage(2,$fac->socid); + $text.=$notify->confirmMessage('NOTIFY_VAL_FAC',$fac->socid); } $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('ValidateBill'),$text,'confirm_valid','',0,($conf->notification->enabled?0:2)); diff --git a/htdocs/includes/triggers/interface_modNotification_Notification.class.php b/htdocs/includes/triggers/interface_modNotification_Notification.class.php index 9c6cb026e58..11e4e871303 100644 --- a/htdocs/includes/triggers/interface_modNotification_Notification.class.php +++ b/htdocs/includes/triggers/interface_modNotification_Notification.class.php @@ -1,206 +1,206 @@ - - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/** - * \file htdocs/includes/triggers/interface_modNotification_notification.class.php - * \ingroup notification - * \brief Fichier de gestion des notifications sur evenement Dolibarr - * \version $Id$ - */ - - -/** - * \class InterfaceNotification - * \brief Classe des fonctions triggers des actions personalisees du workflow - */ -class InterfaceNotification -{ - var $db; - - /** - * \brief Constructeur. - * \param DB Handler d'acces base - */ - function InterfaceNotification($DB) - { - $this->db = $DB ; - - $this->name = preg_replace('/^Interface/i','',get_class($this)); - $this->family = "notification"; - $this->description = "Triggers of this module send email notifications according to Notification module setup."; - $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version - } - - /** - * \brief Renvoi nom du lot de triggers - * \return string Nom du lot de triggers - */ - function getName() - { - return $this->name; - } - - /** - * \brief Renvoi descriptif du lot de triggers - * \return string Descriptif du lot de triggers - */ - function getDesc() - { - return $this->description; - } - - /** - * \brief Renvoi version du lot de triggers - * \return string Version du lot de triggers - */ - function getVersion() - { - global $langs; - $langs->load("admin"); - - if ($this->version == 'experimental') return $langs->trans("Experimental"); - elseif ($this->version == 'dolibarr') return DOL_VERSION; - elseif ($this->version) return $this->version; - else return $langs->trans("Unknown"); - } - - /** - * \brief Fonction appelee lors du declenchement d'un evenement Dolibarr. - * D'autres fonctions run_trigger peuvent etre presentes dans includes/triggers - * \param action Code de l'evenement - * \param object Objet concerne - * \param user Objet user - * \param lang Objet lang - * \param conf Objet conf - * \return int <0 si ko, 0 si aucune action faite, >0 si ok - */ - function run_trigger($action,$object,$user,$langs,$conf) - { - // Mettre ici le code a executer en reaction de l'action - // Les donnees de l'action sont stockees dans $object - - // Si module notification non actif, on ne fait rien - if (! $conf->notification->enabled) return 0; - - require_once(DOL_DOCUMENT_ROOT .'/notify.class.php'); - - if ($action == 'BILL_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $action_notify = 'NOTIFY_VAL_FAC'; - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $langs->load("other"); - $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$object->ref); - - $notify = new Notify($this->db); - $notify->send($action_notify, $object->socid, $mesg, 'facture', $object->id, $filepdf); - } - - elseif ($action == 'ORDER_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $action_notify = 'NOTIFY_VAL_ORDER'; - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $langs->load("other"); - $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$object->ref); - - $notify = new Notify($this->db); - $notify->send($action_notify, $object->socid, $mesg, 'order', $object->id, $filepdf); - } - - elseif ($action == 'PROPOSAL_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $action_notify = 'NOTIFY_VAL_PROPOSAL'; - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->propal->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $langs->load("other"); - $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$object->ref); - - $notify = new Notify($this->db); - $notify->send($action_notify, $object->socid, $mesg, 'propal', $object->id, $filepdf); - } - - elseif ($action == 'FICHEINTER_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $action_notify = 'NOTIFY_VAL_FICHINTER'; - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $langs->load("other"); - $mesg = $langs->transnoentitiesnoconv("EMailTextIntervnetionValidated",$object->ref); - - $notify = new Notify($this->db); - $notify->send($action_notify, $object->socid, $mesg, 'ficheinter', $object->id, $filepdf); - } - - elseif ($action == 'ORDER_SUPPLIER_APPROVE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $action_notify = 'NOTIFY_APP_ORDER_SUPPLIER'; - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->fournisseur->dir_output . '/commande/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$object->ref,$user->fullname); - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; - - $notify = new Notify($this->db); - $notify->send($action_notify, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf); - } - - elseif ($action == 'ORDER_SUPPLIER_REFUSE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $action_notify = 'NOTIFY_REF_ORDER_SUPPLIER'; - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->fournisseur->dir_output . '/commande/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$object->ref,$user->fullname); - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; - - $notify = new Notify($this->db); - $notify->send($action_notify, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf); - } - - // If not found -/* - else - { - dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action."); - return -1; - } -*/ - return 0; - } - -} -?> + + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/** + * \file htdocs/includes/triggers/interface_modNotification_notification.class.php + * \ingroup notification + * \brief Fichier de gestion des notifications sur evenement Dolibarr + * \version $Id$ + */ + + +/** + * \class InterfaceNotification + * \brief Classe des fonctions triggers des actions personalisees du workflow + */ +class InterfaceNotification +{ + var $db; + + /** + * \brief Constructeur. + * \param DB Handler d'acces base + */ + function InterfaceNotification($DB) + { + $this->db = $DB ; + + $this->name = preg_replace('/^Interface/i','',get_class($this)); + $this->family = "notification"; + $this->description = "Triggers of this module send email notifications according to Notification module setup."; + $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version + } + + /** + * \brief Renvoi nom du lot de triggers + * \return string Nom du lot de triggers + */ + function getName() + { + return $this->name; + } + + /** + * \brief Renvoi descriptif du lot de triggers + * \return string Descriptif du lot de triggers + */ + function getDesc() + { + return $this->description; + } + + /** + * \brief Renvoi version du lot de triggers + * \return string Version du lot de triggers + */ + function getVersion() + { + global $langs; + $langs->load("admin"); + + if ($this->version == 'experimental') return $langs->trans("Experimental"); + elseif ($this->version == 'dolibarr') return DOL_VERSION; + elseif ($this->version) return $this->version; + else return $langs->trans("Unknown"); + } + + /** + * \brief Fonction appelee lors du declenchement d'un evenement Dolibarr. + * D'autres fonctions run_trigger peuvent etre presentes dans includes/triggers + * \param action Code de l'evenement + * \param object Objet concerne + * \param user Objet user + * \param lang Objet lang + * \param conf Objet conf + * \return int <0 si ko, 0 si aucune action faite, >0 si ok + */ + function run_trigger($action,$object,$user,$langs,$conf) + { + // Mettre ici le code a executer en reaction de l'action + // Les donnees de l'action sont stockees dans $object + + // Si module notification non actif, on ne fait rien + if (! $conf->notification->enabled) return 0; + + require_once(DOL_DOCUMENT_ROOT .'/notify.class.php'); + + if ($action == 'BILL_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $action_notify = 'NOTIFY_VAL_FAC'; + $ref = dol_sanitizeFileName($object->ref); + $filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + if (! file_exists($filepdf)) $filepdf=''; + $langs->load("other"); + $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$object->ref); + + $notify = new Notify($this->db); + $notify->send($action_notify, $object->socid, $mesg, 'facture', $object->id, $filepdf); + } + + elseif ($action == 'ORDER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $action_notify = 'NOTIFY_VAL_ORDER'; + $ref = dol_sanitizeFileName($object->ref); + $filepdf = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + if (! file_exists($filepdf)) $filepdf=''; + $langs->load("other"); + $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$object->ref); + + $notify = new Notify($this->db); + $notify->send($action_notify, $object->socid, $mesg, 'order', $object->id, $filepdf); + } + + elseif ($action == 'PROPAL_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $action_notify = 'NOTIFY_VAL_PROPAL'; + $ref = dol_sanitizeFileName($object->ref); + $filepdf = $conf->propal->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + if (! file_exists($filepdf)) $filepdf=''; + $langs->load("other"); + $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$object->ref); + + $notify = new Notify($this->db); + $notify->send($action_notify, $object->socid, $mesg, 'propal', $object->id, $filepdf); + } + + elseif ($action == 'FICHEINTER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $action_notify = 'NOTIFY_VAL_FICHINTER'; + $ref = dol_sanitizeFileName($object->ref); + $filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + if (! file_exists($filepdf)) $filepdf=''; + $langs->load("other"); + $mesg = $langs->transnoentitiesnoconv("EMailTextIntervnetionValidated",$object->ref); + + $notify = new Notify($this->db); + $notify->send($action_notify, $object->socid, $mesg, 'ficheinter', $object->id, $filepdf); + } + + elseif ($action == 'ORDER_SUPPLIER_APPROVE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $action_notify = 'NOTIFY_APP_ORDER_SUPPLIER'; + $ref = dol_sanitizeFileName($object->ref); + $filepdf = $conf->fournisseur->dir_output . '/commande/' . $ref . '/' . $ref . '.pdf'; + if (! file_exists($filepdf)) $filepdf=''; + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$object->ref,$user->fullname); + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; + + $notify = new Notify($this->db); + $notify->send($action_notify, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf); + } + + elseif ($action == 'ORDER_SUPPLIER_REFUSE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $action_notify = 'NOTIFY_REF_ORDER_SUPPLIER'; + $ref = dol_sanitizeFileName($object->ref); + $filepdf = $conf->fournisseur->dir_output . '/commande/' . $ref . '/' . $ref . '.pdf'; + if (! file_exists($filepdf)) $filepdf=''; + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$object->ref,$user->fullname); + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; + + $notify = new Notify($this->db); + $notify->send($action_notify, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf); + } + + // If not found +/* + else + { + dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action."); + return -1; + } +*/ + return 0; + } + +} +?> diff --git a/htdocs/install/mysql/migration/2.7.0-2.8.0.sql b/htdocs/install/mysql/migration/2.7.0-2.8.0.sql index 85dcb5e4e20..5b259d33ba7 100755 --- a/htdocs/install/mysql/migration/2.7.0-2.8.0.sql +++ b/htdocs/install/mysql/migration/2.7.0-2.8.0.sql @@ -33,6 +33,7 @@ ALTER TABLE llx_facture_fourn_det MODIFY COLUMN qty real; ALTER TABLE llx_projet ADD COLUMN datee DATE AFTER dateo; +ALTER TABLE llx_notify ADD COLUMN email VARCHAR(255); insert into llx_action_def (rowid,code,titre,description,objet_type) values (5,'NOTIFY_VAL_ORDER','Validation commande client','Executed when a customer order is validated','order'); insert into llx_action_def (rowid,code,titre,description,objet_type) values (6,'NOTIFY_VAL_PROPAL','Validation proposition client','Executed when a commercial proposal is validated','propal'); diff --git a/htdocs/install/mysql/tables/llx_notify.sql b/htdocs/install/mysql/tables/llx_notify.sql index bca09e5a19e..6cc84524b37 100644 --- a/htdocs/install/mysql/tables/llx_notify.sql +++ b/htdocs/install/mysql/tables/llx_notify.sql @@ -1,5 +1,6 @@ -- =================================================================== -- Copyright (C) 2003 Rodolphe Quiedeville +-- Copyright (C) 2009 Laurent Destailleur -- -- 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 @@ -26,5 +27,6 @@ create table llx_notify fk_action integer NOT NULL, fk_contact integer NOT NULL, objet_type varchar(24) NOT NULL, - objet_id integer NOT NULL + objet_id integer NOT NULL, + email varchar(255) )type=innodb; diff --git a/htdocs/notify.class.php b/htdocs/notify.class.php index facef3bae22..6426ef12c20 100644 --- a/htdocs/notify.class.php +++ b/htdocs/notify.class.php @@ -61,6 +61,8 @@ class Notify /** * \brief Renvoie le message signalant les notifications qui auront lieu sur * un evenement pour affichage dans texte de confirmation evenement. + * \param action Id of action in llx_action_def + * \param socid Id of third party * \return string Message */ function confirmMessage($action,$socid) @@ -76,8 +78,10 @@ class Notify } /** - * \brief Renvoie le nombre de notifications configures pour l'action et la societe donnee - * \return int <0 si ko, sinon nombre de notifications definies + * \brief Return number of notifications activated for action code and third party + * \param action Code of action in llx_action_def (new usage) or Id of action in llx_action_def (old usage) + * \param socid Id of third party + * \return int <0 si ko, sinon nombre de notifications definies */ function countDefinedNotifications($action,$socid) { @@ -87,7 +91,8 @@ class Notify $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n, ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; $sql.= " AND n.fk_soc = s.rowid"; - $sql.= " AND n.fk_action = ".$action; + if (is_numeric($action)) $sql.= " AND n.fk_action = ".$action; // Old usage + else $sql.= " AND a.code = '".$action."'"; // New usage $sql.= " AND s.rowid = ".$socid; dol_syslog("Notify.class::countDefinedNotifications $action, $socid"); @@ -109,7 +114,7 @@ class Notify /** * \brief Check if notification are active for couple action/company. * If yes, send mail and save trace into llx_notify. - * \param action Code of action to check and send (list in llx_action_def) + * \param action Code of action in llx_action_def (new usage) or Id of action in llx_action_def (old usage) * \param socid Id of third party * \param texte Message to send * \param objet_type Type of object the notification deals on (facture, order, propal, order_supplier...). Just for log in llx_notify. @@ -123,25 +128,29 @@ class Notify $langs->load("other"); - $sql = "SELECT s.nom, c.email, c.rowid, c.name, c.firstname, a.titre,n.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n, ".MAIN_DB_PREFIX."societe as s"; - $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; - $sql .= " AND n.fk_soc = s.rowid"; - $sql .= " AND a.code = '".$action."'"; - $sql .= " AND s.rowid = ".$socid; - dol_syslog("Notify::send $action, $socid, $texte, $objet_type, $objet_id, $file"); + $sql = "SELECT s.nom, c.email, c.rowid, c.name, c.firstname,"; + $sql.= " a.rowid as adid, a.titre, a.code, n.rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n, ".MAIN_DB_PREFIX."societe as s"; + $sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; + $sql.= " AND n.fk_soc = s.rowid"; + if (is_numeric($action)) $sql.= " AND n.fk_action = ".$action; // Old usage + else $sql.= " AND a.code = '".$action."'"; // New usage + $sql .= " AND s.rowid = ".$socid; + + dol_syslog("Notify::send sql=".$sql); $result = $this->db->query($sql); if ($result) { $num = $this->db->num_rows($result); $i = 0; - while ($i < $num) + while ($i < $num) // For each notification couple defined (third party/actioncode) { $obj = $this->db->fetch_object($result); $sendto = $obj->firstname . " " . $obj->name . " <".$obj->email.">"; + $actiondefid = $obj->adid; if (strlen($sendto)) { @@ -166,8 +175,9 @@ class Notify { $sendto = htmlentities($sendto); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_contact, objet_type, objet_id)"; - $sql.= " VALUES (".$this->db->idate(mktime()).", ".$action." ,".$obj->rowid." , '".$objet_type."', ".$objet_id.");"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_contact, objet_type, objet_id, email)"; + $sql.= " VALUES (".$this->db->idate(mktime()).", ".$actiondefid." ,".$obj->rowid." , '".$objet_type."', ".$objet_id.", '".addslashes($obj->email)."')"; + dol_syslog("Notify::send sql=".$sql); if (! $this->db->query($sql) ) { dol_print_error($this->db);