Refactored InterfaceNotification class

This commit is contained in:
Marcos García de La Fuente 2014-07-18 03:29:20 +02:00
parent cbd10106b8
commit f7c1203d4c

View File

@ -61,118 +61,70 @@ class InterfaceNotification extends DolibarrTriggers
require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
if ($action == 'BILL_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$ref = dol_sanitizeFileName($object->ref);
$filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
if (! file_exists($filepdf)) $filepdf='';
$filepdf=''; // We can't add PDF as it is not generated yet.
$langs->load("other");
$mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$object->ref);
switch ($action) {
case 'BILL_VALIDATE':
$dir_output = $conf->facture->dir_output;
$object_type = 'facture';
$mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$object->ref);
break;
case 'ORDER_VALIDATE':
$dir_output = $conf->commande->dir_output;
$object_type = 'order';
$mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$object->ref);
break;
case 'PROPAL_VALIDATE':
$dir_output = $conf->propal->dir_output;
$object_type = 'propal';
$mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$object->ref);
break;
case 'FICHINTER_VALIDATE':
$dir_output = $conf->facture->dir_output;
$object_type = 'ficheinter';
$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref);
break;
case 'ORDER_SUPPLIER_APPROVE':
$dir_output = $conf->fournisseur->dir_output.'/commande/';
$object_type = 'order_supplier';
$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$object->ref,$user->getFullName($langs));
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
break;
case 'ORDER_SUPPLIER_REFUSE':
$dir_output = $conf->fournisseur->dir_output.'/commande/';
$object_type = 'order_supplier';
$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$object->ref,$user->getFullName($langs));
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
break;
case 'SHIPPING_VALIDATE':
$dir_output = $conf->expedition->dir_output.'/sending/';
$object_type = 'order_supplier';
$mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$object->ref);
break;
default:
return 0;
$notify = new Notify($this->db);
$notify->send($action, $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);
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$ref = dol_sanitizeFileName($object->ref);
$filepdf = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
if (! file_exists($filepdf)) $filepdf='';
$filepdf=''; // We can't add PDF as it is not generated yet.
$langs->load("other");
$mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$object->ref);
$ref = dol_sanitizeFileName($object->ref);
$pdf_path = "$dir_output/$ref/$ref.pdf";
$notify = new Notify($this->db);
$notify->send($action, $object->socid, $mesg, 'order', $object->id, $filepdf);
if (!file_exists($pdf_path)) {
// We can't add PDF as it is not generated yet.
$filepdf = '';
} else {
$filepdf = $pdf_path;
}
elseif ($action == 'PROPAL_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$notify = new Notify($this->db);
$notify->send($action, $object->socid, $mesg, $object_type, $object->id, $filepdf);
$ref = dol_sanitizeFileName($object->ref);
$filepdf = $conf->propal->dir_output . '/' . $ref . '/' . $ref . '.pdf';
if (! file_exists($filepdf)) $filepdf='';
$filepdf=''; // We can't add PDF as it is not generated yet.
$langs->load("other");
$mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$object->ref);
$notify = new Notify($this->db);
$notify->send($action, $object->socid, $mesg, 'propal', $object->id, $filepdf);
}
elseif ($action == 'FICHINTER_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$ref = dol_sanitizeFileName($object->ref);
$filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
if (! file_exists($filepdf)) $filepdf='';
$filepdf=''; // We can't add PDF as it is not generated yet.
$langs->load("other");
$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref);
$notify = new Notify($this->db);
$notify->send($action, $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);
$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->getFullName($langs));
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
$notify = new Notify($this->db);
$notify->send($action, $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);
$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->getFullName($langs));
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
$notify = new Notify($this->db);
$notify->send($action, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf);
}
elseif ($action == 'SHIPPING_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$ref = dol_sanitizeFileName($object->ref);
$filepdf = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf';
if (! file_exists($filepdf)) $filepdf='';
$mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$object->ref);
$notify = new Notify($this->db);
$notify->send($action, $object->socid, $mesg, 'expedition', $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;
return 1;
}
@ -183,7 +135,7 @@ class InterfaceNotification extends DolibarrTriggers
*/
function getListOfManagedEvents()
{
global $conf,$langs;
global $conf;
$ret=array();