New: Yeh! Now all automatic actions are externalised in triggers. This make code so so much easier to understand and offer a lot of possible new features.

This commit is contained in:
Laurent Destailleur 2008-04-08 02:12:02 +00:00
parent 0f81af73a3
commit 2e0343ff14
8 changed files with 187 additions and 55 deletions

View File

@ -39,17 +39,16 @@ $action=$_POST["action"];
// List of all events supported by triggers
$eventstolog=array(
// array('id'=>'USER_CREATE', 'test'=>1),
// array('id'=>'GROUP_CREATE', 'test'=>1),
// array('id'=>'COMPANY_CREATE', 'test'=>$conf->societe->enabled),
// array('id'=>'CONTRACT_VALIDATE', 'test'=>$conf->contrat->enabled),
// array('id'=>'PROPAL_VALIDATE', 'test'=>$conf->propal->enabled),
array('id'=>'COMPANY_CREATE', 'test'=>$conf->societe->enabled),
array('id'=>'CONTRACT_VALIDATE', 'test'=>$conf->contrat->enabled),
array('id'=>'PROPAL_VALIDATE', 'test'=>$conf->propal->enabled),
array('id'=>'PROPAL_SENTBYMAIL', 'test'=>$conf->propal->enabled),
// array('id'=>'BILL_VALIDATE', 'test'=>$conf->facture->enabled),
// array('id'=>'BILL_PAYED', 'test'=>$conf->facture->enabled),
// array('id'=>'BILL_CANCELED', 'test'=>$conf->facture->enabled),
array('id'=>'BILL_SENTBYMAIL', 'test'=>$conf->facture->enabled),
array('id'=>'ORDER_VALIDATE', 'test'=>$conf->commande->enabled),
array('id'=>'ORDER_SENTBYMAIL', 'test'=>$conf->commande->enabled),
array('id'=>'BILL_VALIDATE', 'test'=>$conf->facture->enabled),
array('id'=>'BILL_PAYED', 'test'=>$conf->facture->enabled),
array('id'=>'BILL_CANCELED', 'test'=>$conf->facture->enabled),
array('id'=>'BILL_SENTBYMAIL', 'test'=>$conf->facture->enabled),
// array('id'=>'PAYMENT_CUSTOMER_CREATE','test'=>$conf->facture->enabled),
// array('id'=>'PAYMENT_SUPPLIER_CREATE','test'=>$conf->fournisseur->enabled),
// array('id'=>'MEMBER_VALIDATE', 'test'=>$conf->adherent->enabled),

View File

@ -52,14 +52,16 @@ $eventstolog=array(
array('id'=>'ACTION_CREATE', 'test'=>$conf->societe->enabled),
array('id'=>'COMPANY_CREATE', 'test'=>$conf->societe->enabled),
array('id'=>'CONTRACT_VALIDATE', 'test'=>$conf->contrat->enabled),
array('id'=>'CONTRACT_CANCEL', 'test'=>$conf->contrat->enabled),
array('id'=>'CONTRACT_CLOSE', 'test'=>$conf->contrat->enabled),
array('id'=>'PROPAL_VALIDATE', 'test'=>$conf->propal->enabled),
array('id'=>'PROPAL_CLOSE_SIGNED', 'test'=>$conf->propal->enabled),
array('id'=>'PROPAL_CLOSE_REFUSED', 'test'=>$conf->propal->enabled),
array('id'=>'PROPAL_SENTBYMAIL', 'test'=>$conf->propal->enabled),
array('id'=>'ORDER_VALIDATE', 'test'=>$conf->commande->enabled),
array('id'=>'ORDER_SENTBYMAIL', 'test'=>$conf->commande->enabled),
array('id'=>'BILL_VALIDATE', 'test'=>$conf->facture->enabled),
array('id'=>'BILL_PAYED', 'test'=>$conf->facture->enabled),
array('id'=>'BILL_CANCELED', 'test'=>$conf->facture->enabled),
array('id'=>'BILL_SENTBYMAIL', 'test'=>$conf->facture->enabled),
array('id'=>'PAYMENT_CUSTOMER_CREATE','test'=>$conf->facture->enabled),
array('id'=>'PAYMENT_SUPPLIER_CREATE','test'=>$conf->fournisseur->enabled),
array('id'=>'MEMBER_CREATE', 'test'=>$conf->adherent->enabled),

View File

@ -56,14 +56,6 @@ if ($_GET["action"] == 'builddoc')
$result=$cat->generate($_GET["id"]);
}
if ($action=='delete_action')
{
$actioncomm = new ActionComm($db);
$actioncomm->fetch($actionid);
$result=$actioncomm->delete();
}
/*
* Affichage liste

View File

@ -339,6 +339,8 @@ if ($_POST['action'] == 'send')
if (strlen($sendto))
{
$langs->load("commercial");
$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
$replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
$message = $_POST['message'];
@ -363,7 +365,7 @@ if ($_POST['action'] == 'send')
$actionmsg.=$message;
}
$actionmsg2=$langs->transnoentities('SendPropalByMail');
$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
}
$filepath[0] = $file;

View File

@ -605,6 +605,8 @@ if ($_POST['action'] == 'send')
if (strlen($sendto))
{
$langs->load("commercial");
$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
$replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
$message = $_POST['message'];
@ -629,7 +631,7 @@ if ($_POST['action'] == 'send')
$actionmsg.=$message;
}
$actionmsg2=$langs->transnoentities('SendOrderByMail');
$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
}
$filepath[0] = $file;

View File

@ -989,6 +989,8 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['c
if (strlen($sendto))
{
$langs->load("commercial");
$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
$replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
$message = $_POST['message'];
@ -1007,7 +1009,7 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['c
}
$actiontypecode='AC_FAC';
$actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->trans('To').' '.$sendto.".\n";
$actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
if ($message)
{
@ -1015,7 +1017,7 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['c
$actionmsg.=$message;
}
$actionmsg2=$langs->transnoentities('SendInvoiceByMail');
$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
}
if ($_POST['action'] == 'relance')
{
@ -1026,7 +1028,7 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['c
$actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
$actionmsg.=$message;
}
$actionmsg2=$langs->transnoentities('ReSendInvoiceByMail');
$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
}
$filepath[0] = $file;

View File

@ -17,7 +17,7 @@
*/
/**
\file htdocs/includes/triggers/interface_all_ActionsAuto.class.php
\file htdocs/includes/triggers/interface_modAgenda_ActionsAuto.class.php
\ingroup core
\brief Trigger file for
\version $Id$
@ -102,28 +102,184 @@ class InterfaceActionsAuto
//dolibarr_syslog("xxxxxxxxxxx".$key);
if (empty($conf->global->$key)) return 0; // Log events not enabled for this action
// Following properties must be filled:
// $object->actiontypecode;
// $object->actionmsg (label)
// $object->actionmsg2 (note)
// $object->sendtoid
// $object->socid
// Optionnal:
// $object->facid
// $object->propalrowid
// $object->orderrowid
$ok=0;
// Actions
if ($action == 'PROPAL_SENTBYMAIL')
if ($action == 'COMPANY_CREATE')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("users");
$langs->load("companies");
$object->actiontypecode='AC_OTH';
$object->actionmsg2=$langs->transnoentities("NewCompanyToDolibarr",$object->nom);
$object->actionmsg=$langs->transnoentities("NewCompanyToDolibarr",$object->nom);
if ($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->facid=$object->orderrowid=$object->propalrowid=0;
$ok=1;
}
elseif ($action == 'CONTRACT_VALIDATE')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("contracts");
$object->actiontypecode='AC_OTH';
$object->actionmsg2=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$object->facid=$object->orderrowid=$object->propalrowid=0;
$ok=1;
}
if ($action == 'BILL_SENTBYMAIL')
elseif ($action == 'PROPAL_VALIDATE')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("users");
$langs->load("propal");
$object->actiontypecode='AC_OTH';
$object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("PropalValidatedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$object->propalrowid=$object->id;
$object->facid=$object->orderrowid=0;
$ok=1;
}
elseif ($action == 'PROPAL_SENTBYMAIL')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("propal");
$ok=1;
// Parameters $object->xxx defined by caller
}
elseif ($action == 'PROPAL_CLOSE_SIGNED')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("propal");
$object->actiontypecode='AC_OTH';
$object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$object->propalrowid=$object->id;
$object->facid=$object->orderrowid=0;
$ok=1;
}
elseif ($action == 'PROPAL_CLOSE_REFUSED')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("propal");
$object->actiontypecode='AC_OTH';
$object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$object->propalrowid=$object->id;
$object->facid=$object->orderrowid=0;
$ok=1;
}
elseif ($action == 'ORDER_VALIDATE')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("orders");
$object->actiontypecode='AC_OTH';
$object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$object->orderrowid=$object->id;
$object->propalrowid=$object->facid=0;
$ok=1;
}
elseif ($action == 'ORDER_SENTBYMAIL')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("users");
$langs->load("orders");
$ok=1;
}
// Parameters $object->xxx defined by caller
}
elseif ($action == 'BILL_VALIDATE')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("bills");
$object->actiontypecode='AC_OTH';
$object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$object->facid=$object->id;
$object->orderrowid=$object->propalrowid=0;
$ok=1;
}
elseif ($action == 'BILL_SENTBYMAIL')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("bills");
$ok=1;
// Parameters $object->xxx defined by caller
}
elseif ($action == 'BILL_PAYED')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("bills");
$object->actiontypecode='AC_OTH';
$object->actionmsg2=$langs->transnoentities("InvoicePayedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("InvoicePayedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$object->facid=$object->id;
$object->orderrowid=$object->propalrowid=0;
$ok=1;
}
elseif ($action == 'BILL_CANCELED')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("bills");
$object->actiontypecode='AC_OTH';
$object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$object->facid=$object->id;
$object->orderrowid=$object->propalrowid=0;
$ok=1;
}
// If not found
/*
else
@ -140,7 +296,6 @@ class InterfaceActionsAuto
require_once(DOL_DOCUMENT_ROOT.'/contact.class.php');
require_once(DOL_DOCUMENT_ROOT.'/actioncomm.class.php');
$actioncomm = new ActionComm($this->db);
$actioncomm->type_id = $object->actiontypeid;
$actioncomm->type_code = $object->actiontypecode;
$actioncomm->label = $object->actionmsg2;
$actioncomm->note = $object->actionmsg;
@ -160,7 +315,7 @@ class InterfaceActionsAuto
}
else
{
$error ="Failed to insert : ".$webcal->error." ";
$error ="Failed to insert : ".$actioncomm->error." ";
$this->error=$error;
//dolibarr_syslog("interface_webcal.class.php: ".$this->error);

View File

@ -165,28 +165,6 @@ class InterfaceWebcalsynchro
$this->desc=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref);
$this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
}
elseif ($action == 'CONTRACT_CANCEL')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$this->date=time();
$this->duree=0;
$this->texte=$langs->transnoentities("ContractCanceledInDolibarr",$object->ref);
$this->desc=$langs->transnoentities("ContractCanceledInDolibarr",$object->ref);
$this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
}
elseif ($action == 'CONTRACT_CLOSE')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$this->date=time();
$this->duree=0;
$this->texte=$langs->transnoentities("ContractClosedInDolibarr",$object->ref);
$this->desc=$langs->transnoentities("ContractClosedInDolibarr",$object->ref);
$this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
}
// Proposals
elseif ($action == 'PROPAL_VALIDATE')