From f8f9e0355c72def8dd32b90e4ce09db1b0df0726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Fri, 18 Jul 2014 04:10:43 +0200 Subject: [PATCH] Refactor InterfaceActionsAuto --- ...terface_50_modAgenda_ActionsAuto.class.php | 227 +++++------------- 1 file changed, 58 insertions(+), 169 deletions(-) diff --git a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php index 0e3cff50a2d..8ad12b34638 100644 --- a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php +++ b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php @@ -36,11 +36,6 @@ class InterfaceActionsAuto extends DolibarrTriggers public $version = self::VERSION_DOLIBARR; public $picto = 'action'; - var $date; - var $duree; - var $texte; - var $desc; - /** * Function called when a Dolibarrr business event is done. * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers @@ -64,38 +59,37 @@ class InterfaceActionsAuto extends DolibarrTriggers */ public function run_trigger($action, $object, User $user, Translate $langs, Conf $conf) { - $key='MAIN_AGENDA_ACTIONAUTO_'.$action; - //dol_syslog("xxxxxxxxxxx".$key); + // Module not active, we do nothing + if (empty($conf->agenda->enabled)) { + return 0; + } - if (empty($conf->agenda->enabled)) return 0; // Module not active, we do nothing - if (empty($conf->global->$key)) return 0; // Do not log events not enabled for this action + $key = 'MAIN_AGENDA_ACTIONAUTO_'.$action; - $ok=0; + // Do not log events not enabled for this action + if (empty($conf->global->$key)) { + return 0; + } + + $langs->load("agenda"); // Actions if ($action == 'COMPANY_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("NewCompanyToDolibarr",$object->nom); $object->actionmsg=$langs->transnoentities("NewCompanyToDolibarr",$object->nom); if (! empty($object->prefix)) $object->actionmsg.=" (".$object->prefix.")"; - //$this->desc.="\n".$langs->transnoentities("Customer").': '.yn($object->client); - //$this->desc.="\n".$langs->transnoentities("Supplier").': '.yn($object->fournisseur); $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; $object->socid=$object->id; - $ok=1; } elseif ($action == 'COMPANY_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("orders"); - $langs->load("agenda"); if (empty($object->actiontypecode)) $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) dol_syslog('Trigger called with property actionmsg2 on object not defined', LOG_ERR); @@ -103,14 +97,11 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'CONTRACT_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("contracts"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref); @@ -118,13 +109,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'PROPAL_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("propal"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",$object->ref); @@ -132,13 +120,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'PROPAL_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("propal"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProposalSentByEMail",$object->ref); @@ -150,13 +135,10 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'PROPAL_CLOSE_SIGNED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("propal"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref); @@ -164,13 +146,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'PROPAL_CLOSE_REFUSED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("propal"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref); @@ -178,13 +157,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'ORDER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("orders"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref); @@ -192,13 +168,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'ORDER_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("orders"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderSentByEMail",$object->ref); @@ -210,14 +183,11 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref); @@ -225,14 +195,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_UNVALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref); @@ -240,14 +207,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceSentByEMail",$object->ref); @@ -259,14 +223,11 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_PAYED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); // Values for this action can't be defined by caller. $object->actiontypecode='AC_OTH_AUTO'; @@ -275,14 +236,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_CANCEL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); @@ -290,14 +248,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'FICHINTER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("interventions"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionValidatedInDolibarr",$object->ref); @@ -307,14 +262,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->sendtoid=0; $object->fk_element=0; $object->elementtype=''; - $ok=1; } elseif ($action == 'FICHINTER_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("interventions"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref); @@ -323,14 +275,11 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'FICHINTER_CLASSIFY_BILLED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("interventions"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionClassifiedBilled",$object->ref); @@ -338,14 +287,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'SHIPPING_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("sendings"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingValidated",$object->ref); @@ -357,14 +303,11 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'SHIPPING_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("sendings"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingSentByEMail",$object->ref); @@ -376,13 +319,10 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'ORDER_SUPPLIER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("orders"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref); @@ -390,13 +330,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'ORDER_SUPPLIER_APPROVE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("orders"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderApprovedInDolibarr",$object->ref); @@ -404,13 +341,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'ORDER_SUPPLIER_REFUSE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("orders"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderRefusedInDolibarr",$object->ref); @@ -418,14 +352,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $langs->load("orders"); $object->actiontypecode='AC_OTH_AUTO'; @@ -438,14 +369,11 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_SUPPLIER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref); @@ -453,14 +381,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $langs->load("orders"); $object->actiontypecode='AC_OTH_AUTO'; @@ -473,14 +398,11 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_SUPPLIER_PAYED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref); @@ -488,14 +410,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_SUPPLIER_CANCELED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); @@ -503,16 +422,13 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } // Members elseif ($action == 'MEMBER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("members"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref); @@ -522,14 +438,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'MEMBER_SUBSCRIPTION') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("members"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref); @@ -541,18 +454,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; - } - elseif ($action == 'MEMBER_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } elseif ($action == 'MEMBER_RESILIATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("members"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref); @@ -562,14 +468,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'MEMBER_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("members"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref); @@ -579,16 +482,13 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } // Projects elseif ($action == 'PROJECT_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("projects"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProjectCreatedInDolibarr",$object->ref); @@ -597,15 +497,12 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } // Project tasks elseif($action == 'TASK_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("projects"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; @@ -615,14 +512,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif($action == 'TASK_MODIFY') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("projects"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskModifiedInDolibarr",$object->ref); @@ -631,14 +525,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif($action == 'TASK_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("projects"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskDeletedInDolibarr",$object->ref); @@ -647,7 +538,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } // The trigger was enabled but we are missing the implementation, let the log know @@ -657,63 +547,62 @@ class InterfaceActionsAuto extends DolibarrTriggers return 0; } + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + // Add entry in event table - if ($ok) - { - $now=dol_now(); + $now=dol_now(); - if(isset($_SESSION['listofnames'])) + if(isset($_SESSION['listofnames'])) + { + $attachs=$_SESSION['listofnames']; + if($attachs && strpos($action,'SENTBYMAIL')) { - $attachs=$_SESSION['listofnames']; - if($attachs && strpos($action,'SENTBYMAIL')) - { - $object->actionmsg.="\n".$langs->transnoentities("AttachedFiles").': '.$attachs; - } + $object->actionmsg.="\n".$langs->transnoentities("AttachedFiles").': '.$attachs; } + } - require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; - require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; - $contactforaction=new Contact($this->db); - $societeforaction=new Societe($this->db); - if ($object->sendtoid > 0) $contactforaction->fetch($object->sendtoid); - if ($object->socid > 0) $societeforaction->fetch($object->socid); + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; + $contactforaction=new Contact($this->db); + $societeforaction=new Societe($this->db); + if ($object->sendtoid > 0) $contactforaction->fetch($object->sendtoid); + if ($object->socid > 0) $societeforaction->fetch($object->socid); - // Insertion action - require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; - $actioncomm = new ActionComm($this->db); - $actioncomm->type_code = $object->actiontypecode; // code of parent table llx_c_actioncomm (will be deprecated) - $actioncomm->code='AC_'.$action; - $actioncomm->label = $object->actionmsg2; - $actioncomm->note = $object->actionmsg; - $actioncomm->datep = $now; - $actioncomm->datef = $now; - $actioncomm->durationp = 0; - $actioncomm->punctual = 1; - $actioncomm->percentage = -1; // Not applicable - $actioncomm->contact = $contactforaction; - $actioncomm->societe = $societeforaction; - $actioncomm->author = $user; // User saving action - $actioncomm->usertodo = $user; // User owner of action - //$actioncomm->userdone = $user; // User doing action + // Insertion action + require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; + $actioncomm = new ActionComm($this->db); + $actioncomm->type_code = $object->actiontypecode; // code of parent table llx_c_actioncomm (will be deprecated) + $actioncomm->code='AC_'.$action; + $actioncomm->label = $object->actionmsg2; + $actioncomm->note = $object->actionmsg; + $actioncomm->datep = $now; + $actioncomm->datef = $now; + $actioncomm->durationp = 0; + $actioncomm->punctual = 1; + $actioncomm->percentage = -1; // Not applicable + $actioncomm->contact = $contactforaction; + $actioncomm->societe = $societeforaction; + $actioncomm->author = $user; // User saving action + $actioncomm->usertodo = $user; // User owner of action + //$actioncomm->userdone = $user; // User doing action - $actioncomm->fk_element = $object->id; - $actioncomm->elementtype = $object->element; + $actioncomm->fk_element = $object->id; + $actioncomm->elementtype = $object->element; - $ret=$actioncomm->add($user); // User qui saisit l'action - if ($ret > 0) - { - $_SESSION['LAST_ACTION_CREATED'] = $ret; - return 1; - } - else - { - $error ="Failed to insert event : ".$actioncomm->error." ".join(',',$actioncomm->errors); - $this->error=$error; - $this->errors=$actioncomm->errors; + $ret=$actioncomm->add($user); // User qui saisit l'action + if ($ret > 0) + { + $_SESSION['LAST_ACTION_CREATED'] = $ret; + return 1; + } + else + { + $error ="Failed to insert event : ".$actioncomm->error." ".join(',',$actioncomm->errors); + $this->error=$error; + $this->errors=$actioncomm->errors; - dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR); - return -1; - } + dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR); + return -1; } return 0;