--- /tmp/dsg/dolibarr/htdocs/core/triggers/github_dolibarrtriggers.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_dolibarrtriggers.class.php @@ -20,6 +20,7 @@ */ abstract class DolibarrTriggers { + /** * Database handler * @var DoliDB @@ -70,19 +71,8 @@ */ public $errors = array(); - /** - * @var string module is in development - */ const VERSION_DEVELOPMENT = 'development'; - - /** - * @var string module is experimental - */ const VERSION_EXPERIMENTAL = 'experimental'; - - /** - * @var string module is dolibarr ready - */ const VERSION_DOLIBARR = 'dolibarr'; /** @@ -90,12 +80,13 @@ * * @param DoliDB $db Database handler */ - public function __construct(DoliDB $db) - { + public function __construct(DoliDB $db) + { $this->db = $db; - if (empty($this->name)) { + if (empty($this->name)) + { $this->name = preg_replace('/^Interface/i', '', get_class($this)); } } @@ -143,16 +134,16 @@ } } - /** - * Function called when a Dolibarrr business event is done. - * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) - * - * @param string $action Event action code - * @param Object $object Object - * @param User $user Object user - * @param Translate $langs Object langs - * @param conf $conf Object conf - * @return int <0 if KO, 0 if no triggered ran, >0 if OK - */ - public abstract function runTrigger($action, $object, User $user, Translate $langs, Conf $conf); + /** + * Function called when a Dolibarrr business event is done. + * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) + * + * @param string $action Event action code + * @param Object $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + public abstract function runTrigger($action, $object, User $user, Translate $langs, Conf $conf); } --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_interface_20_all_Logevents.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_20_all_Logevents.class.php @@ -32,21 +32,19 @@ class InterfaceLogevents extends DolibarrTriggers { /** - * Constructor - * - * @param DoliDB $db Database handler + * @var string Image of the trigger */ - public function __construct($db) - { - $this->db = $db; - - $this->name = preg_replace('/^Interface/i', '', get_class($this)); - $this->family = "core"; - $this->description = "Triggers of this module allows to add security event records inside Dolibarr."; - // 'development', 'experimental', 'dolibarr' or version - $this->version = self::VERSION_DOLIBARR; - $this->picto = 'technic'; - } + public $picto = 'technic'; + + public $family = 'core'; + + public $description = "Triggers of this module allows to add security event records inside Dolibarr."; + + /** + * Version of the trigger + * @var string + */ + public $version = self::VERSION_DOLIBARR; /** * Function called when a Dolibarrr security audit event is done. @@ -60,102 +58,126 @@ * @return int <0 if KO, 0 if no triggered ran, >0 if OK */ public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) - { - if (!empty($conf->global->MAIN_LOGEVENTS_DISABLE_ALL)) return 0; // Log events is disabled (hidden features) - - $key = 'MAIN_LOGEVENTS_'.$action; - //dol_syslog("xxxxxxxxxxx".$key); - if (empty($conf->global->$key)) return 0; // Log events not enabled for this action - - if (empty($conf->entity)) $conf->entity = $entity; // forcing of the entity if it's not defined (ex: in login form) - - $date = dol_now(); - - // Actions - if ($action == 'USER_LOGIN') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $langs->load("users"); - // Initialisation donnees (date,duree,texte,desc) - $text = "(UserLogged,".$object->login.")"; - $text .= (empty($object->trigger_mesg) ? '' : ' - '.$object->trigger_mesg); - $desc = "(UserLogged,".$object->login.")"; - $desc .= (empty($object->trigger_mesg) ? '' : ' - '.$object->trigger_mesg); - } elseif ($action == 'USER_LOGIN_FAILED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - // Initialisation donnees (date,duree,texte,desc) - $text = $object->trigger_mesg; // Message direct - $desc = $object->trigger_mesg; // Message direct - } elseif ($action == 'USER_LOGOUT') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $langs->load("users"); - // Initialisation donnees (date,duree,texte,desc) - $text = "(UserLogoff,".$object->login.")"; - $desc = "(UserLogoff,".$object->login.")"; - } elseif ($action == 'USER_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - $langs->load("users"); - - // Initialisation donnees (date,duree,texte,desc) - $text = $langs->transnoentities("NewUserCreated", $object->login); - $desc = $langs->transnoentities("NewUserCreated", $object->login); - } elseif ($action == 'USER_MODIFY') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - $langs->load("users"); - - // Initialisation donnees (date,duree,texte,desc) - $text = $langs->transnoentities("EventUserModified", $object->login); - $desc = $langs->transnoentities("EventUserModified", $object->login); - } elseif ($action == 'USER_NEW_PASSWORD') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - $langs->load("users"); - - // Initialisation donnees (date,duree,texte,desc) - $text = $langs->transnoentities("NewUserPassword", $object->login); - $desc = $langs->transnoentities("NewUserPassword", $object->login); - } elseif ($action == 'USER_ENABLEDISABLE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - $langs->load("users"); - // Initialisation donnees (date,duree,texte,desc) - if ($object->statut == 0) { + { + if (!empty($conf->global->MAIN_LOGEVENTS_DISABLE_ALL)) return 0; // Log events is disabled (hidden features) + + $key = 'MAIN_LOGEVENTS_'.$action; + //dol_syslog("xxxxxxxxxxx".$key); + if (empty($conf->global->$key)) return 0; // Log events not enabled for this action + + if (empty($conf->entity)) $conf->entity = $entity; // forcing of the entity if it's not defined (ex: in login form) + + $date = dol_now(); + + // Actions + if ($action == 'USER_LOGIN') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $text = "(UserLogged,".$object->login.")"; + $text .= (empty($object->trigger_mesg) ? '' : ' - '.$object->trigger_mesg); + $desc = "(UserLogged,".$object->login.")"; + $desc .= (empty($object->trigger_mesg) ? '' : ' - '.$object->trigger_mesg); + } + if ($action == 'USER_LOGIN_FAILED') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + // Initialisation donnees (date,duree,texte,desc) + $text = $object->trigger_mesg; // Message direct + $desc = $object->trigger_mesg; // Message direct + } + if ($action == 'USER_LOGOUT') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $text = "(UserLogoff,".$object->login.")"; + $desc = "(UserLogoff,".$object->login.")"; + } + if ($action == 'USER_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + + // Initialisation donnees (date,duree,texte,desc) + $text = $langs->transnoentities("NewUserCreated", $object->login); + $desc = $langs->transnoentities("NewUserCreated", $object->login); + } + elseif ($action == 'USER_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + + // Initialisation donnees (date,duree,texte,desc) + $text = $langs->transnoentities("EventUserModified", $object->login); + $desc = $langs->transnoentities("EventUserModified", $object->login); + } + elseif ($action == 'USER_NEW_PASSWORD') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + + // Initialisation donnees (date,duree,texte,desc) + $text = $langs->transnoentities("NewUserPassword", $object->login); + $desc = $langs->transnoentities("NewUserPassword", $object->login); + } + elseif ($action == 'USER_ENABLEDISABLE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + if ($object->statut == 0) + { $text = $langs->transnoentities("UserEnabled", $object->login); $desc = $langs->transnoentities("UserEnabled", $object->login); } - if ($object->statut == 1) { + if ($object->statut == 1) + { $text = $langs->transnoentities("UserDisabled", $object->login); $desc = $langs->transnoentities("UserDisabled", $object->login); } - } elseif ($action == 'USER_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - $langs->load("users"); - // Initialisation donnees (date,duree,texte,desc) - $text = $langs->transnoentities("UserDeleted", $object->login); - $desc = $langs->transnoentities("UserDeleted", $object->login); - } elseif ($action == 'USERGROUP_CREATE') { - // Groups - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - $langs->load("users"); - // Initialisation donnees (date,duree,texte,desc) - $text = $langs->transnoentities("NewGroupCreated", $object->name); - $desc = $langs->transnoentities("NewGroupCreated", $object->name); - } elseif ($action == 'USERGROUP_MODIFY') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - $langs->load("users"); - // Initialisation donnees (date,duree,texte,desc) - $text = $langs->transnoentities("GroupModified", $object->name); - $desc = $langs->transnoentities("GroupModified", $object->name); - } elseif ($action == 'USERGROUP_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - $langs->load("users"); - // Initialisation donnees (date,duree,texte,desc) - $text = $langs->transnoentities("GroupDeleted", $object->name); - $desc = $langs->transnoentities("GroupDeleted", $object->name); + } + elseif ($action == 'USER_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $text = $langs->transnoentities("UserDeleted", $object->login); + $desc = $langs->transnoentities("UserDeleted", $object->login); + } + + // Groupes + elseif ($action == 'USERGROUP_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $text = $langs->transnoentities("NewGroupCreated", $object->name); + $desc = $langs->transnoentities("NewGroupCreated", $object->name); + } + elseif ($action == 'USERGROUP_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $text = $langs->transnoentities("GroupModified", $object->name); + $desc = $langs->transnoentities("GroupModified", $object->name); + } + elseif ($action == 'USERGROUP_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $text = $langs->transnoentities("GroupDeleted", $object->name); + $desc = $langs->transnoentities("GroupDeleted", $object->name); } // If not found - /* + /* else { dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action."); @@ -166,26 +188,29 @@ // Add more information into desc from the context property if (!empty($desc) && !empty($object->context['audit'])) $desc .= ' - '.$object->context['audit']; - // Add entry in event table + // Add entry in event table include_once DOL_DOCUMENT_ROOT.'/core/class/events.class.php'; $event = new Events($this->db); - $event->type = $action; - $event->dateevent = $date; - $event->label = $text; - $event->description = $desc; - $event->user_agent = (empty($_SERVER["HTTP_USER_AGENT"]) ? '' : $_SERVER["HTTP_USER_AGENT"]); - - $result = $event->create($user); - if ($result > 0) { - return 1; - } else { - $error = "Failed to insert security event: ".$event->error; - $this->errors[] = $error; - $this->error = $error; - - dol_syslog(get_class($this).": ".$error, LOG_ERR); - return -1; - } - } + $event->type = $action; + $event->dateevent = $date; + $event->label = $text; + $event->description = $desc; + $event->user_agent = $_SERVER["HTTP_USER_AGENT"]; + + $result = $event->create($user); + if ($result > 0) + { + return 1; + } + else + { + $error = "Failed to insert security event: ".$event->error; + $this->errors[] = $error; + $this->error = $error; + + dol_syslog(get_class($this).": ".$error, LOG_ERR); + return -1; + } + } } --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_interface_20_modWorkflow_WorkflowManager.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_20_modWorkflow_WorkflowManager.class.php @@ -33,21 +33,18 @@ class InterfaceWorkflowManager extends DolibarrTriggers { /** - * Constructor - * - * @param DoliDB $db Database handler + * @var string Image of the trigger */ - public function __construct($db) - { - $this->db = $db; - - $this->name = preg_replace('/^Interface/i', '', get_class($this)); - $this->family = "core"; - $this->description = "Triggers of this module allows to manage workflows"; - // 'development', 'experimental', 'dolibarr' or version - $this->version = self::VERSION_DOLIBARR; - $this->picto = 'technic'; - } + public $picto = 'technic'; + + public $family = 'core'; + public $description = "Triggers of this module allows to manage workflows"; + + /** + * Version of the trigger + * @var string + */ + public $version = self::VERSION_DOLIBARR; /** * Function called when a Dolibarrr business event is done. @@ -61,267 +58,312 @@ * @return int <0 if KO, 0 if no triggered ran, >0 if OK */ public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) - { - if (empty($conf->workflow->enabled)) return 0; // Module not active, we do nothing - - // Proposals to order - if ($action == 'PROPAL_CLOSE_SIGNED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->commande->enabled) && !empty($conf->global->WORKFLOW_PROPAL_AUTOCREATE_ORDER)) { - include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; - $newobject = new Commande($this->db); - - $newobject->context['createfrompropal'] = 'createfrompropal'; - $newobject->context['origin'] = $object->element; - $newobject->context['origin_id'] = $object->id; - - $ret = $newobject->createFromProposal($object, $user); - if ($ret < 0) { $this->error = $newobject->error; $this->errors[] = $newobject->error; } - return $ret; - } - } - - // Order to invoice - if ($action == 'ORDER_CLOSE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->facture->enabled) && !empty($conf->global->WORKFLOW_ORDER_AUTOCREATE_INVOICE)) { - include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; - $newobject = new Facture($this->db); - - $newobject->context['createfromorder'] = 'createfromorder'; - $newobject->context['origin'] = $object->element; - $newobject->context['origin_id'] = $object->id; - - $ret = $newobject->createFromOrder($object, $user); - if ($ret < 0) { $this->error = $newobject->error; $this->errors[] = $newobject->error; } - return $ret; - } - } - - // Order classify billed proposal - if ($action == 'ORDER_CLASSIFY_BILLED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->propal->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL)) { - $object->fetchObjectLinked('', 'propal', $object->id, $object->element); - if (!empty($object->linkedObjects)) { - $totalonlinkedelements = 0; - foreach ($object->linkedObjects['propal'] as $element) { - if ($element->statut == Propal::STATUS_SIGNED || $element->statut == Propal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; + { + if (empty($conf->workflow->enabled)) return 0; // Module not active, we do nothing + + // Proposals to order + if ($action == 'PROPAL_CLOSE_SIGNED') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->commande->enabled) && !empty($conf->global->WORKFLOW_PROPAL_AUTOCREATE_ORDER)) + { + include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; + $newobject = new Commande($this->db); + + $newobject->context['createfrompropal'] = 'createfrompropal'; + $newobject->context['origin'] = $object->element; + $newobject->context['origin_id'] = $object->id; + + $ret = $newobject->createFromProposal($object, $user); + if ($ret < 0) { $this->error = $newobject->error; $this->errors[] = $newobject->error; } + return $ret; + } + } + + // Order to invoice + if ($action == 'ORDER_CLOSE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->facture->enabled) && !empty($conf->global->WORKFLOW_ORDER_AUTOCREATE_INVOICE)) + { + include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + $newobject = new Facture($this->db); + + $newobject->context['createfromorder'] = 'createfromorder'; + $newobject->context['origin'] = $object->element; + $newobject->context['origin_id'] = $object->id; + + $ret = $newobject->createFromOrder($object, $user); + if ($ret < 0) { $this->error = $newobject->error; $this->errors[] = $newobject->error; } + return $ret; + } + } + + // Order classify billed proposal + if ($action == 'ORDER_CLASSIFY_BILLED') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->propal->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL)) + { + $object->fetchObjectLinked('', 'propal', $object->id, $object->element); + if (!empty($object->linkedObjects)) + { + $totalonlinkedelements = 0; + foreach ($object->linkedObjects['propal'] as $element) + { + if ($element->statut == Propal::STATUS_SIGNED || $element->statut == Propal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; } dol_syslog("Amount of linked proposals = ".$totalonlinkedelements.", of order = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); - if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) { - foreach ($object->linkedObjects['propal'] as $element) { - $ret = $element->classifyBilled($user); - } + if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) + { + foreach ($object->linkedObjects['propal'] as $element) + { + $ret = $element->classifyBilled($user); + } } } - return $ret; - } + return $ret; + } + } + + // classify billed order & billed propososal + if ($action == 'BILL_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $ret = 0; + + // First classify billed the order to allow the proposal classify process + if (!empty($conf->commande->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER)) + { + $object->fetchObjectLinked('', 'commande', $object->id, $object->element); + if (!empty($object->linkedObjects)) + { + $totalonlinkedelements = 0; + foreach ($object->linkedObjects['commande'] as $element) + { + if ($element->statut == Commande::STATUS_VALIDATED || $element->statut == Commande::STATUS_SHIPMENTONPROCESS || $element->statut == Commande::STATUS_CLOSED) $totalonlinkedelements += $element->total_ht; + } + dol_syslog("Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); + if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) + { + foreach ($object->linkedObjects['commande'] as $element) + { + $ret = $element->classifyBilled($user); + } + } + } + } + + // Second classify billed the proposal. + if (!empty($conf->propal->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL)) + { + $object->fetchObjectLinked('', 'propal', $object->id, $object->element); + if (!empty($object->linkedObjects)) + { + $totalonlinkedelements = 0; + foreach ($object->linkedObjects['propal'] as $element) + { + if ($element->statut == Propal::STATUS_SIGNED || $element->statut == Propal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; + } + dol_syslog("Amount of linked proposals = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); + if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) + { + foreach ($object->linkedObjects['propal'] as $element) + { + $ret = $element->classifyBilled($user); + } + } + } + } + + return $ret; + } + + // classify billed order & billed propososal + if ($action == 'BILL_SUPPLIER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + // First classify billed the order to allow the proposal classify process + if (!empty($conf->fournisseur->enabled) && !empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER)) + { + $object->fetchObjectLinked('', 'order_supplier', $object->id, $object->element); + if (!empty($object->linkedObjects)) + { + $totalonlinkedelements = 0; + foreach ($object->linkedObjects['order_supplier'] as $element) + { + if ($element->statut == CommandeFournisseur::STATUS_ACCEPTED || $element->statut == CommandeFournisseur::STATUS_ORDERSENT || $element->statut == CommandeFournisseur::STATUS_RECEIVED_PARTIALLY || $element->statut == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) $totalonlinkedelements += $element->total_ht; + } + dol_syslog("Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); + if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) + { + foreach ($object->linkedObjects['order_supplier'] as $element) + { + $ret = $element->classifyBilled($user); + } + } + } + return $ret; + } + + // Second classify billed the proposal. + if (!empty($conf->supplier_proposal->enabled) && !empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_SUPPLIER_PROPOSAL)) + { + $object->fetchObjectLinked('', 'supplier_proposal', $object->id, $object->element); + if (!empty($object->linkedObjects)) + { + $totalonlinkedelements = 0; + foreach ($object->linkedObjects['supplier_proposal'] as $element) + { + if ($element->statut == SupplierProposal::STATUS_SIGNED || $element->statut == SupplierProposal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; + } + dol_syslog("Amount of linked supplier proposals = ".$totalonlinkedelements.", of supplier invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); + if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) + { + foreach ($object->linkedObjects['supplier_proposal'] as $element) + { + $ret = $element->classifyBilled($user); + } + } + } + return $ret; + } + } + + // Invoice classify billed order + if ($action == 'BILL_PAYED') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + if (!empty($conf->commande->enabled) && !empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_ORDER)) + { + $object->fetchObjectLinked('', 'commande', $object->id, $object->element); + if (!empty($object->linkedObjects)) + { + $totalonlinkedelements = 0; + foreach ($object->linkedObjects['commande'] as $element) + { + if ($element->statut == Commande::STATUS_VALIDATED || $element->statut == Commande::STATUS_SHIPMENTONPROCESS || $element->statut == Commande::STATUS_CLOSED) $totalonlinkedelements += $element->total_ht; + } + dol_syslog("Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); + if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) + { + foreach ($object->linkedObjects['commande'] as $element) + { + $ret = $element->classifyBilled($user); + } + } + } + return $ret; + } + } + + if ($action == 'SHIPPING_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + if (!empty($conf->commande->enabled) && !empty($conf->expedition->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING)) + { + $qtyshipped = array(); + $qtyordred = array(); + require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; + + //find all shippement on order origin + $order = new Commande($this->db); + $ret = $order->fetch($object->origin_id); + if ($ret < 0) { + $this->error = $order->error; $this->errors = $order->errors; + return $ret; + } + $ret = $order->fetchObjectLinked($order->id, 'commande', null, 'shipping'); + if ($ret < 0) { + $this->error = $order->error; $this->errors = $order->errors; + return $ret; + } + //Build array of quantity shipped by product for an order + if (is_array($order->linkedObjects) && count($order->linkedObjects) > 0) { + foreach ($order->linkedObjects as $type=>$shipping_array) { + if ($type == 'shipping' && is_array($shipping_array) && count($shipping_array) > 0) { + foreach ($shipping_array as $shipping) { + if (is_array($shipping->lines) && count($shipping->lines) > 0) { + foreach ($shipping->lines as $shippingline) { + $qtyshipped[$shippingline->fk_product] += $shippingline->qty; + } + } + } + } + } + } + + //Build array of quantity ordered by product + if (is_array($order->lines) && count($order->lines) > 0) { + foreach ($order->lines as $orderline) { + $qtyordred[$orderline->fk_product] += $orderline->qty; + } + } + //dol_syslog(var_export($qtyordred,true),LOG_DEBUG); + //dol_syslog(var_export($qtyshipped,true),LOG_DEBUG); + //Compare array + $diff_array = array_diff_assoc($qtyordred, $qtyshipped); + if (count($diff_array) == 0) { + //No diff => mean everythings is shipped + $ret = $object->setStatut(Commande::STATUS_CLOSED, $object->origin_id, $object->origin, 'ORDER_CLOSE'); + if ($ret < 0) { + $this->error = $object->error; $this->errors = $object->errors; + return $ret; + } + } + } + } + // classify billed reception + if ($action == 'BILL_SUPPLIER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id, LOG_DEBUG); + + if (!empty($conf->reception->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)) + { + $object->fetchObjectLinked('', 'reception', $object->id, $object->element); + if (!empty($object->linkedObjects)) + { + $totalonlinkedelements = 0; + foreach ($object->linkedObjects['reception'] as $element) + { + if ($element->statut == Reception::STATUS_VALIDATED) $totalonlinkedelements += $element->total_ht; + } + dol_syslog("Amount of linked proposals = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht), LOG_DEBUG); + if ($totalonlinkedelements == $object->total_ht) + { + foreach ($object->linkedObjects['reception'] as $element) + { + $ret = $element->set_billed(); + } + } + } + return $ret; + } } - // classify billed order & billed propososal - if ($action == 'BILL_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - $ret = 0; - - // First classify billed the order to allow the proposal classify process - if (!empty($conf->commande->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER)) { - $object->fetchObjectLinked('', 'commande', $object->id, $object->element); - if (!empty($object->linkedObjects)) { - $totalonlinkedelements = 0; - foreach ($object->linkedObjects['commande'] as $element) { - if ($element->statut == Commande::STATUS_VALIDATED || $element->statut == Commande::STATUS_SHIPMENTONPROCESS || $element->statut == Commande::STATUS_CLOSED) $totalonlinkedelements += $element->total_ht; - } - dol_syslog("Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); - if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) { - foreach ($object->linkedObjects['commande'] as $element) { - $ret = $element->classifyBilled($user); - } - } - } - } - - // Second classify billed the proposal. - if (!empty($conf->propal->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL)) { - $object->fetchObjectLinked('', 'propal', $object->id, $object->element); - if (!empty($object->linkedObjects)) { - $totalonlinkedelements = 0; - foreach ($object->linkedObjects['propal'] as $element) { - if ($element->statut == Propal::STATUS_SIGNED || $element->statut == Propal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; - } - dol_syslog("Amount of linked proposals = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); - if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) { - foreach ($object->linkedObjects['propal'] as $element) { - $ret = $element->classifyBilled($user); - } - } - } - } - - return $ret; - } - - // classify billed order & billed propososal - if ($action == 'BILL_SUPPLIER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - // First classify billed the order to allow the proposal classify process - if (!empty($conf->fournisseur->enabled) && !empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER)) { - $object->fetchObjectLinked('', 'order_supplier', $object->id, $object->element); - if (!empty($object->linkedObjects)) { - $totalonlinkedelements = 0; - foreach ($object->linkedObjects['order_supplier'] as $element) { - if ($element->statut == CommandeFournisseur::STATUS_ACCEPTED || $element->statut == CommandeFournisseur::STATUS_ORDERSENT || $element->statut == CommandeFournisseur::STATUS_RECEIVED_PARTIALLY || $element->statut == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) $totalonlinkedelements += $element->total_ht; - } - dol_syslog("Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); - if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) { - foreach ($object->linkedObjects['order_supplier'] as $element) { - $ret = $element->classifyBilled($user); - } - } - } - return $ret; - } - - // Second classify billed the proposal. - if (!empty($conf->supplier_proposal->enabled) && !empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_SUPPLIER_PROPOSAL)) { - $object->fetchObjectLinked('', 'supplier_proposal', $object->id, $object->element); - if (!empty($object->linkedObjects)) { - $totalonlinkedelements = 0; - foreach ($object->linkedObjects['supplier_proposal'] as $element) { - if ($element->statut == SupplierProposal::STATUS_SIGNED || $element->statut == SupplierProposal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; - } - dol_syslog("Amount of linked supplier proposals = ".$totalonlinkedelements.", of supplier invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); - if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) { - foreach ($object->linkedObjects['supplier_proposal'] as $element) { - $ret = $element->classifyBilled($user); - } - } - } - return $ret; - } - } - - // Invoice classify billed order - if ($action == 'BILL_PAYED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - if (!empty($conf->commande->enabled) && !empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_ORDER)) { - $object->fetchObjectLinked('', 'commande', $object->id, $object->element); - if (!empty($object->linkedObjects)) { - $totalonlinkedelements = 0; - foreach ($object->linkedObjects['commande'] as $element) { - if ($element->statut == Commande::STATUS_VALIDATED || $element->statut == Commande::STATUS_SHIPMENTONPROCESS || $element->statut == Commande::STATUS_CLOSED) $totalonlinkedelements += $element->total_ht; - } - dol_syslog("Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); - if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) { - foreach ($object->linkedObjects['commande'] as $element) { - $ret = $element->classifyBilled($user); - } - } - } - return $ret; - } - } - - if ($action == 'SHIPPING_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - if (!empty($conf->commande->enabled) && !empty($conf->expedition->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING)) { - $qtyshipped = array(); - $qtyordred = array(); - require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; - - //find all shippement on order origin - $order = new Commande($this->db); - $ret = $order->fetch($object->origin_id); - if ($ret < 0) { - $this->error = $order->error; $this->errors = $order->errors; - return $ret; - } - $ret = $order->fetchObjectLinked($order->id, 'commande', null, 'shipping'); - if ($ret < 0) { - $this->error = $order->error; $this->errors = $order->errors; - return $ret; - } - //Build array of quantity shipped by product for an order - if (is_array($order->linkedObjects) && count($order->linkedObjects) > 0) { - foreach ($order->linkedObjects as $type=>$shipping_array) { - if ($type == 'shipping' && is_array($shipping_array) && count($shipping_array) > 0) { - foreach ($shipping_array as $shipping) { - if (is_array($shipping->lines) && count($shipping->lines) > 0) { - foreach ($shipping->lines as $shippingline) { - $qtyshipped[$shippingline->fk_product] += $shippingline->qty; - } - } - } - } - } - } - - //Build array of quantity ordered by product - if (is_array($order->lines) && count($order->lines) > 0) { - foreach ($order->lines as $orderline) { - if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $orderline->product_type > 0) continue; - $qtyordred[$orderline->fk_product] += $orderline->qty; - } - } - //dol_syslog(var_export($qtyordred,true),LOG_DEBUG); - //dol_syslog(var_export($qtyshipped,true),LOG_DEBUG); - //Compare array - $diff_array = array_diff_assoc($qtyordred, $qtyshipped); - if (count($diff_array) == 0) { - //No diff => mean everythings is shipped - $ret = $object->setStatut(Commande::STATUS_CLOSED, $object->origin_id, $object->origin, 'ORDER_CLOSE'); - if ($ret < 0) { - $this->error = $object->error; $this->errors = $object->errors; - return $ret; - } - } - } - } - // classify billed reception - if ($action == 'BILL_SUPPLIER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id, LOG_DEBUG); - - if (!empty($conf->reception->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)) { - $object->fetchObjectLinked('', 'reception', $object->id, $object->element); - if (!empty($object->linkedObjects)) { - $totalonlinkedelements = 0; - foreach ($object->linkedObjects['reception'] as $element) { - if ($element->statut == Reception::STATUS_VALIDATED) $totalonlinkedelements += $element->total_ht; - } - dol_syslog("Amount of linked proposals = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht), LOG_DEBUG); - if ($totalonlinkedelements == $object->total_ht) { - foreach ($object->linkedObjects['reception'] as $element) { - $ret = $element->set_billed(); - } - } - } - return $ret; - } - } - - return 0; - } - - /** - * @param Object $conf Dolibarr settings object - * @param float $totalonlinkedelements Sum of total amounts (excl VAT) of - * invoices linked to $object - * @param float $object_total_ht The total amount (excl VAT) of the object - * (an order, a proposal, a bill, etc.) - * @return bool True if the amounts are equal (rounded on total amount) - * True if the module is configured to skip the amount equality check - * False otherwise. - */ - private function shouldClassify($conf, $totalonlinkedelements, $object_total_ht) - { - // if the configuration allows unmatching amounts, allow classification anyway - if (!empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) { - return true; - } - // if the amount are same, allow classification, else deny - return (price2num($totalonlinkedelements, 'MT') == price2num($object_total_ht, 'MT')); - } + return 0; + } + + /** + * @param Object $conf Dolibarr settings object + * @param float $totalonlinkedelements Sum of total amounts (excl VAT) of + * invoices linked to $object + * @param float $object_total_ht The total amount (excl VAT) of the object + * (an order, a proposal, a bill, etc.) + * @return bool True if the amounts are equal (rounded on total amount) + * True if the module is configured to skip the amount equality check + * False otherwise. + */ + private function shouldClassify($conf, $totalonlinkedelements, $object_total_ht) + { + // if the configuration allows unmatching amounts, allow classification anyway + if (!empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) { + return true; + } + // if the amount are same, allow classification, else deny + return (price2num($totalonlinkedelements, 'MT') == price2num($object_total_ht, 'MT')); + } } --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_interface_50_modAgenda_ActionsAuto.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_50_modAgenda_ActionsAuto.class.php @@ -34,22 +34,19 @@ */ class InterfaceActionsAuto extends DolibarrTriggers { + public $family = 'agenda'; + public $description = "Triggers of this module add actions in agenda according to setup made in agenda setup."; + /** - * Constructor - * - * @param DoliDB $db Database handler + * Version of the trigger + * @var string */ - public function __construct($db) - { - $this->db = $db; - - $this->name = preg_replace('/^Interface/i', '', get_class($this)); - $this->family = "agenda"; - $this->description = "Triggers of this module add actions in agenda according to setup made in agenda setup."; - // 'development', 'experimental', 'dolibarr' or version - $this->version = self::VERSION_DOLIBARR; - $this->picto = 'action'; - } + public $version = self::VERSION_DOLIBARR; + + /** + * @var string Image of the trigger + */ + public $picto = 'action'; /** * Function called when a Dolibarrr business event is done. @@ -59,14 +56,13 @@ * $object->actiontypecode (translation action code: AC_OTH, ...) * $object->actionmsg (note, long text) * $object->actionmsg2 (label, short text) - * $object->sendtoid (id of contact or array of ids of contacts) + * $object->sendtoid (id of contact or array of ids) * $object->socid (id of thirdparty) * $object->fk_project - * $object->fk_element (ID of object to link action event to) - * $object->elementtype (->element of object to link action to) - * $object->module (if defined, elementtype in llx_actioncomm will be elementtype@module) + * $object->fk_element + * $object->elementtype * - * @param string $action Event action code ('CONTRACT_MODIFY', 'RECRUITMENTCANDIDATURE_MODIFIY', ...) + * @param string $action Event action code * @param Object $object Object * @param User $user Object user * @param Translate $langs Object langs @@ -75,15 +71,9 @@ */ public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) { - if (empty($conf->agenda->enabled)) return 0; // Module not active, we do nothing - - // Do not log events when trigger is for creating event (infinite loop) - if (preg_match('/^ACTION_/', $action)) { - return 0; - } + if (empty($conf->agenda->enabled)) return 0; // Module not active, we do nothing $key = 'MAIN_AGENDA_ACTIONAUTO_'.$action; - //var_dump($action.' - '.$conf->global->$key);exit; // Do not log events not enabled for this action if (empty($conf->global->$key)) { @@ -95,712 +85,807 @@ if (empty($object->actiontypecode)) $object->actiontypecode = 'AC_OTH_AUTO'; // Actions - if ($action == 'COMPANY_CREATE') { + if ($action == 'COMPANY_CREATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "companies")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("NewCompanyToDolibarr", $object->name); + $object->actionmsg = $langs->transnoentities("NewCompanyToDolibarr", $object->name); + if (!empty($object->prefix)) $object->actionmsg .= " (".$object->prefix.")"; + + $object->sendtoid = 0; + $object->socid = $object->id; + } + elseif ($action == 'COMPANY_SENTBYMAIL') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "orders")); + + if (empty($object->actionmsg2)) dol_syslog('Trigger called with property actionmsg2 on object not defined', LOG_ERR); + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + } + elseif ($action == 'CONTRACT_VALIDATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "contracts")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ContractValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + $object->actionmsg = $langs->transnoentities("ContractValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + + $object->sendtoid = 0; + } + elseif ($action == 'CONTRACT_SENTBYMAIL') + { // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "companies")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("NewCompanyToDolibarr", $object->name); - $object->actionmsg = $langs->transnoentities("NewCompanyToDolibarr", $object->name); - - $object->sendtoid = 0; - $object->socid = $object->id; - } elseif ($action == 'COMPANY_SENTBYMAIL') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "orders")); - - if (empty($object->actionmsg2)) dol_syslog('Trigger called with property actionmsg2 on object not defined', LOG_ERR); + $langs->loadLangs(array("agenda", "other", "contracts")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ContractSentByEMail", $object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg = $langs->transnoentities("ContractSentByEMail", $object->ref); + } // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'CONTACT_CREATE') { + } + elseif ($action == 'PROPAL_VALIDATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "propal")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + + $object->sendtoid = 0; + } + elseif ($action == 'PROPAL_SENTBYMAIL') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "propal")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref); + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + } + elseif ($action == 'PROPAL_CLOSE_SIGNED') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "propal")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref); + + $object->sendtoid = 0; + } + elseif ($action == 'PROPAL_CLASSIFY_BILLED') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "propal")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("PropalClassifiedBilledInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("PropalClassifiedBilledInDolibarr", $object->ref); + + $object->sendtoid = 0; + } + elseif ($action == 'PROPAL_CLOSE_REFUSED') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "propal")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref); + + $object->sendtoid = 0; + } + elseif ($action == 'ORDER_VALIDATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "orders")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + + $object->sendtoid = 0; + } + elseif ($action == 'ORDER_CLOSE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "orders")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderDeliveredInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("OrderDeliveredInDolibarr", $object->ref); + + $object->sendtoid = 0; + } + elseif ($action == 'ORDER_CLASSIFY_BILLED') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "orders")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderBilledInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("OrderBilledInDolibarr", $object->ref); + + $object->sendtoid = 0; + } + elseif ($action == 'ORDER_CANCEL') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "orders")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref); + + $object->sendtoid = 0; + } + elseif ($action == 'ORDER_SENTBYMAIL') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "orders")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderSentByEMail", $object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg = $langs->transnoentities("OrderSentByEMail", $object->ref); + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + } + elseif ($action == 'BILL_VALIDATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "bills")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + + $object->sendtoid = 0; + } + elseif ($action == 'BILL_UNVALIDATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "bills")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref); + + $object->sendtoid = 0; + } + elseif ($action == 'BILL_SENTBYMAIL') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "bills")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceSentByEMail", $object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg = $langs->transnoentities("InvoiceSentByEMail", $object->ref); + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + } + elseif ($action == 'BILL_PAYED') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "bills")); + + // Values for this action can't be defined by caller. + $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref); + + $object->sendtoid = 0; + } + elseif ($action == 'BILL_CANCEL') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "bills")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref); + + $object->sendtoid = 0; + } + elseif ($action == 'FICHINTER_CREATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "interventions")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionCreatedInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("InterventionCreatedInDolibarr", $object->ref); + + $object->sendtoid = 0; + $object->fk_element = 0; + $object->elementtype = ''; + } + elseif ($action == 'FICHINTER_VALIDATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "interventions")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + $object->actionmsg = $langs->transnoentities("InterventionValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + + $object->sendtoid = 0; + $object->fk_element = 0; + $object->elementtype = ''; + } + elseif ($action == 'FICHINTER_MODIFY') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "interventions")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionModifiedInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("InterventionModifiedInDolibarr", $object->ref); + + $object->sendtoid = 0; + $object->fk_element = 0; + $object->elementtype = ''; + } + elseif ($action == 'FICHINTER_SENTBYMAIL') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "interventions")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionSentByEMail", $object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg = $langs->transnoentities("InterventionSentByEMail", $object->ref); + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + } + elseif ($action == 'FICHINTER_CLASSIFY_BILLED') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "interventions")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionClassifiedBilledInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("InterventionClassifiedBilledInDolibarr", $object->ref); + + $object->sendtoid = 0; + } + elseif ($action == 'FICHINTER_CLASSIFY_UNBILLED') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "interventions")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref); + + $object->sendtoid = 0; + } + elseif ($action == 'FICHINTER_DELETE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "interventions")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionDeletedInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("InterventionDeletedInDolibarr", $object->ref); + + $object->sendtoid = 0; + $object->fk_element = 0; + $object->elementtype = ''; + } + elseif ($action == 'SHIPPING_VALIDATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "sendings")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ShippingValidated", ($object->newref ? $object->newref : $object->ref)); + if (empty($object->actionmsg)) + { + $object->actionmsg = $langs->transnoentities("ShippingValidated", ($object->newref ? $object->newref : $object->ref)); + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + } + elseif ($action == 'SHIPPING_SENTBYMAIL') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "sendings")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ShippingSentByEMail", $object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg = $langs->transnoentities("ShippingSentByEMail", $object->ref); + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + } elseif ($action == 'RECEPTION_VALIDATE') + { + $langs->load("agenda"); + $langs->load("other"); + $langs->load("receptions"); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ReceptionValidated", ($object->newref ? $object->newref : $object->ref)); + if (empty($object->actionmsg)) + { + $object->actionmsg = $langs->transnoentities("ReceptionValidated", ($object->newref ? $object->newref : $object->ref)); + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + } + elseif ($action == 'RECEPTION_SENTBYMAIL') + { + $langs->load("agenda"); + $langs->load("other"); + $langs->load("receptions"); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ReceptionSentByEMail", $object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg = $langs->transnoentities("ReceptionSentByEMail", $object->ref); + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + } + elseif ($action == 'PROPOSAL_SUPPLIER_VALIDATE') + { // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "companies")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("CONTACT_CREATEInDolibarr", $object->getFullName($langs)); - $object->actionmsg = $langs->transnoentities("CONTACT_CREATEInDolibarr", $object->getFullName($langs)); - - $object->sendtoid = array($object->id => $object->id); - $object->socid = $object->socid; - } elseif ($action == 'CONTRACT_VALIDATE') { + $langs->loadLangs(array("agenda", "other", "propal")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + + $object->sendtoid = 0; + } + elseif ($action == 'PROPOSAL_SUPPLIER_SENTBYMAIL') + { // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "contracts")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ContractValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - $object->actionmsg = $langs->transnoentities("ContractValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - - $object->sendtoid = 0; - } elseif ($action == 'CONTRACT_SENTBYMAIL') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "contracts")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ContractSentByEMail", $object->ref); - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("ContractSentByEMail", $object->ref); + $langs->loadLangs(array("agenda", "other", "propal")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref); } // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'PROPAL_VALIDATE') { + } + elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_SIGNED') + { // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "propal")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - - $object->sendtoid = 0; - } elseif ($action == 'PROPAL_SENTBYMAIL') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "propal")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref); - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref); - } - - // Parameters $object->sendtoid defined by caller - //$object->sendtoid=0; - } elseif ($action == 'PROPAL_CLOSE_SIGNED') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "propal")); + $langs->loadLangs(array("agenda", "other", "propal")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref); $object->actionmsg = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'PROPAL_CLASSIFY_BILLED') { + } + elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_REFUSED') + { // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "propal")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("PropalClassifiedBilledInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("PropalClassifiedBilledInDolibarr", $object->ref); - - $object->sendtoid = 0; - } elseif ($action == 'PROPAL_CLOSE_REFUSED') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "propal")); + $langs->loadLangs(array("agenda", "other", "propal")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref); $object->actionmsg = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'ORDER_VALIDATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "orders")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - - $object->sendtoid = 0; - } elseif ($action == 'ORDER_CLOSE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "orders")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderDeliveredInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("OrderDeliveredInDolibarr", $object->ref); - - $object->sendtoid = 0; - } elseif ($action == 'ORDER_CLASSIFY_BILLED') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "orders")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderBilledInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("OrderBilledInDolibarr", $object->ref); - - $object->sendtoid = 0; - } elseif ($action == 'ORDER_CANCEL') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "orders")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref); - - $object->sendtoid = 0; - } elseif ($action == 'ORDER_SENTBYMAIL') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "orders")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderSentByEMail", $object->ref); - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("OrderSentByEMail", $object->ref); - } - - // Parameters $object->sendtoid defined by caller - //$object->sendtoid=0; - } elseif ($action == 'BILL_VALIDATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "bills")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - - $object->sendtoid = 0; - } elseif ($action == 'BILL_UNVALIDATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "bills")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref); - - $object->sendtoid = 0; - } elseif ($action == 'BILL_SENTBYMAIL') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "bills")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceSentByEMail", $object->ref); - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("InvoiceSentByEMail", $object->ref); - } - - // Parameters $object->sendtoid defined by caller - //$object->sendtoid=0; - } elseif ($action == 'BILL_PAYED') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "bills")); - - // Values for this action can't be defined by caller. - $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref); - - $object->sendtoid = 0; - } elseif ($action == 'BILL_CANCEL') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "bills")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref); - - $object->sendtoid = 0; - } elseif ($action == 'FICHINTER_CREATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "interventions")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionCreatedInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("InterventionCreatedInDolibarr", $object->ref); - - $object->sendtoid = 0; - $object->fk_element = 0; - $object->elementtype = ''; - } elseif ($action == 'FICHINTER_VALIDATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "interventions")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - $object->actionmsg = $langs->transnoentities("InterventionValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - - $object->sendtoid = 0; - $object->fk_element = 0; - $object->elementtype = ''; - } elseif ($action == 'FICHINTER_MODIFY') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "interventions")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionModifiedInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("InterventionModifiedInDolibarr", $object->ref); - - $object->sendtoid = 0; - $object->fk_element = 0; - $object->elementtype = ''; - } elseif ($action == 'FICHINTER_SENTBYMAIL') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "interventions")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionSentByEMail", $object->ref); - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("InterventionSentByEMail", $object->ref); - } - - // Parameters $object->sendtoid defined by caller - //$object->sendtoid=0; - } elseif ($action == 'FICHINTER_CLASSIFY_BILLED') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "interventions")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionClassifiedBilledInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("InterventionClassifiedBilledInDolibarr", $object->ref); - - $object->sendtoid = 0; - } elseif ($action == 'FICHINTER_CLASSIFY_UNBILLED') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "interventions")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref); - - $object->sendtoid = 0; - } elseif ($action == 'FICHINTER_DELETE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "interventions")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionDeletedInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("InterventionDeletedInDolibarr", $object->ref); - - $object->sendtoid = 0; - $object->fk_element = 0; - $object->elementtype = ''; - } elseif ($action == 'SHIPPING_VALIDATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "sendings")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ShippingValidated", ($object->newref ? $object->newref : $object->ref)); - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("ShippingValidated", ($object->newref ? $object->newref : $object->ref)); - } - - // Parameters $object->sendtoid defined by caller - //$object->sendtoid=0; - } elseif ($action == 'SHIPPING_SENTBYMAIL') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "sendings")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ShippingSentByEMail", $object->ref); - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("ShippingSentByEMail", $object->ref); - } - - // Parameters $object->sendtoid defined by caller - //$object->sendtoid=0; - } elseif ($action == 'RECEPTION_VALIDATE') { - $langs->load("agenda"); - $langs->load("other"); - $langs->load("receptions"); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ReceptionValidated", ($object->newref ? $object->newref : $object->ref)); - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("ReceptionValidated", ($object->newref ? $object->newref : $object->ref)); - } - - // Parameters $object->sendtoid defined by caller - //$object->sendtoid=0; - } elseif ($action == 'RECEPTION_SENTBYMAIL') { - $langs->load("agenda"); - $langs->load("other"); - $langs->load("receptions"); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ReceptionSentByEMail", $object->ref); - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("ReceptionSentByEMail", $object->ref); - } - - // Parameters $object->sendtoid defined by caller - //$object->sendtoid=0; - } elseif ($action == 'PROPOSAL_SUPPLIER_VALIDATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "propal")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - - $object->sendtoid = 0; - } elseif ($action == 'PROPOSAL_SUPPLIER_SENTBYMAIL') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "propal")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref); - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref); - } - - // Parameters $object->sendtoid defined by caller - //$object->sendtoid=0; - } elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_SIGNED') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "propal")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref); - - $object->sendtoid = 0; - } elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_REFUSED') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "propal")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref); - - $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_CREATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "orders")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderCreatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - $object->actionmsg = $langs->transnoentities("OrderCreatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - - $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_VALIDATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "orders")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - - $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_APPROVE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "orders")); + } + elseif ($action == 'ORDER_SUPPLIER_CREATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "orders")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderCreatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + $object->actionmsg = $langs->transnoentities("OrderCreatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + + $object->sendtoid = 0; + } + elseif ($action == 'ORDER_SUPPLIER_VALIDATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "orders")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + + $object->sendtoid = 0; + } + elseif ($action == 'ORDER_SUPPLIER_APPROVE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "orders")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderApprovedInDolibarr", $object->ref); $object->actionmsg = $langs->transnoentities("OrderApprovedInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_REFUSE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "orders")); + } + elseif ($action == 'ORDER_SUPPLIER_REFUSE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "orders")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderRefusedInDolibarr", $object->ref); $object->actionmsg = $langs->transnoentities("OrderRefusedInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_SUBMIT') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "orders")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - $object->actionmsg = $langs->transnoentities("SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - - $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_RECEIVE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "orders")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - $object->actionmsg = $langs->transnoentities("SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - - $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "bills", "orders")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref); - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref); - } - - // Parameters $object->sendtoid defined by caller - //$object->sendtoid=0; - } elseif ($action == 'ORDER_SUPPLIER_CLASSIFY_BILLED') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "bills", "orders")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref); - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref); - } - - $object->sendtoid = 0; - } elseif ($action == 'BILL_SUPPLIER_VALIDATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "bills")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - - $object->sendtoid = 0; - } elseif ($action == 'BILL_SUPPLIER_UNVALIDATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "bills")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref); - - $object->sendtoid = 0; - } elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "bills", "orders")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref); - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref); - } - - // Parameters $object->sendtoid defined by caller - //$object->sendtoid=0; - } elseif ($action == 'BILL_SUPPLIER_PAYED') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "bills")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref); - - $object->sendtoid = 0; - } elseif ($action == 'BILL_SUPPLIER_CANCELED') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "bills")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref); - - $object->sendtoid = 0; - } - - // Members - elseif ($action == 'MEMBER_VALIDATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "members")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("MemberValidatedInDolibarr", $object->getFullName($langs)); - $object->actionmsg = $langs->transnoentities("MemberValidatedInDolibarr", $object->getFullName($langs)); - $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); - $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type; - - $object->sendtoid = 0; - } elseif ($action == 'MEMBER_MODIFY') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "members")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("MemberModifiedInDolibarr", $object->getFullName($langs)); - $object->actionmsg = $langs->transnoentities("MemberModifiedInDolibarr", $object->getFullName($langs)); - $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); - $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type; - - $object->sendtoid = 0; - } elseif ($action == 'MEMBER_SUBSCRIPTION_CREATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "members")); - - $member = $this->context['member']; - if (!is_object($member)) { // This should not happen - dol_syslog("Execute a trigger MEMBER_SUBSCRIPTION_CREATE with context key 'member' not an object"); - include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; - $member = new Adherent($this->db); - $member->fetch($object->fk_adherent); - } - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->id, $member->getFullName($langs)); - $object->actionmsg = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->id, $member->getFullName($langs)); - $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs); - $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type; - $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount; - $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day'); + } + elseif ($action == 'ORDER_SUPPLIER_SUBMIT') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "orders")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + $object->actionmsg = $langs->transnoentities("SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + + $object->sendtoid = 0; + } + elseif ($action == 'ORDER_SUPPLIER_RECEIVE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "orders")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + $object->actionmsg = $langs->transnoentities("SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + + $object->sendtoid = 0; + } + elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "bills", "orders")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref); + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + } + elseif ($action == 'ORDER_SUPPLIER_CLASSIFY_BILLED') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "bills", "orders")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref); + } + + $object->sendtoid = 0; + } + elseif ($action == 'BILL_SUPPLIER_VALIDATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "bills")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); + + $object->sendtoid = 0; + } + elseif ($action == 'BILL_SUPPLIER_UNVALIDATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "bills")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref); + + $object->sendtoid = 0; + } + elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "bills", "orders")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref); + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + } + elseif ($action == 'BILL_SUPPLIER_PAYED') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "bills")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref); + + $object->sendtoid = 0; + } + elseif ($action == 'BILL_SUPPLIER_CANCELED') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "bills")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref); + + $object->sendtoid = 0; + } + + // Members + elseif ($action == 'MEMBER_VALIDATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "members")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("MemberValidatedInDolibarr", $object->getFullName($langs)); + $object->actionmsg = $langs->transnoentities("MemberValidatedInDolibarr", $object->getFullName($langs)); + $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); + $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type; + + $object->sendtoid = 0; + } + elseif ($action == 'MEMBER_MODIFY') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "members")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("MemberModifiedInDolibarr", $object->getFullName($langs)); + $object->actionmsg = $langs->transnoentities("MemberModifiedInDolibarr", $object->getFullName($langs)); + $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); + $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type; + + $object->sendtoid = 0; + } + elseif ($action == 'MEMBER_SUBSCRIPTION_CREATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "members")); + + $member = $this->context['member']; + if (!is_object($member)) // This should not happen + { + include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; + $member = new Adherent($this->db); + $member->fetch($this->fk_adherent); + } + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->id, $member->getFullName($langs)); + $object->actionmsg = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->id, $member->getFullName($langs)); + $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs); + $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type; + $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount; + $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day'); $object->sendtoid = 0; if ($object->fk_soc > 0) $object->socid = $object->fk_soc; - } elseif ($action == 'MEMBER_SUBSCRIPTION_MODIFY') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "members")); - - $member = $this->context['member']; - if (!is_object($member)) { // This should not happen - include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; - $member = new Adherent($this->db); - $member->fetch($this->fk_adherent); - } - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionModifiedInDolibarr", $object->id, $member->getFullName($langs)); - $object->actionmsg = $langs->transnoentities("MemberSubscriptionModifiedInDolibarr", $object->id, $member->getFullName($langs)); - $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs); - $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type; - $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount; - $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day'); - - $object->sendtoid = 0; - if ($object->fk_soc > 0) $object->socid = $object->fk_soc; - } elseif ($action == 'MEMBER_SUBSCRIPTION_DELETE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "members")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $object->getFullName($langs)); - $object->actionmsg = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $object->getFullName($langs)); - $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); - $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type; - $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount; - $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start, 'day').' - '.dol_print_date($object->last_subscription_date_end, 'day'); - - $object->sendtoid = 0; - if ($object->fk_soc > 0) $object->socid = $object->fk_soc; - } elseif ($action == 'MEMBER_RESILIATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "members")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("MemberResiliatedInDolibarr", $object->getFullName($langs)); - $object->actionmsg = $langs->transnoentities("MemberResiliatedInDolibarr", $object->getFullName($langs)); - $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); - $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type; - - $object->sendtoid = 0; - } elseif ($action == 'MEMBER_DELETE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "members")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("MemberDeletedInDolibarr", $object->getFullName($langs)); - $object->actionmsg = $langs->transnoentities("MemberDeletedInDolibarr", $object->getFullName($langs)); - $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); - $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type; - - $object->sendtoid = 0; - } - - // Projects - elseif ($action == 'PROJECT_CREATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "projects")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref); - $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref; - - $object->sendtoid = 0; - } elseif ($action == 'PROJECT_VALIDATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "projects")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref); - $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref; - - $object->sendtoid = 0; - } elseif ($action == 'PROJECT_MODIFY') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "projects")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref); - $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref; - - $object->sendtoid = 0; - } + } + elseif ($action == 'MEMBER_SUBSCRIPTION_MODIFY') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "members")); + + $member = $this->context['member']; + if (!is_object($member)) // This should not happen + { + include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; + $member = new Adherent($this->db); + $member->fetch($this->fk_adherent); + } + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionModifiedInDolibarr", $object->id, $member->getFullName($langs)); + $object->actionmsg = $langs->transnoentities("MemberSubscriptionModifiedInDolibarr", $object->id, $member->getFullName($langs)); + $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs); + $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type; + $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount; + $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day'); + + $object->sendtoid = 0; + if ($object->fk_soc > 0) $object->socid = $object->fk_soc; + } + elseif ($action == 'MEMBER_SUBSCRIPTION_DELETE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "members")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $object->getFullName($langs)); + $object->actionmsg = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $object->getFullName($langs)); + $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); + $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type; + $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount; + $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start, 'day').' - '.dol_print_date($object->last_subscription_date_end, 'day'); + + $object->sendtoid = 0; + if ($object->fk_soc > 0) $object->socid = $object->fk_soc; + } + elseif ($action == 'MEMBER_RESILIATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "members")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("MemberResiliatedInDolibarr", $object->getFullName($langs)); + $object->actionmsg = $langs->transnoentities("MemberResiliatedInDolibarr", $object->getFullName($langs)); + $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); + $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type; + + $object->sendtoid = 0; + } + elseif ($action == 'MEMBER_DELETE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "members")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("MemberDeletedInDolibarr", $object->getFullName($langs)); + $object->actionmsg = $langs->transnoentities("MemberDeletedInDolibarr", $object->getFullName($langs)); + $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); + $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type; + + $object->sendtoid = 0; + } + + // Projects + elseif ($action == 'PROJECT_CREATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "projects")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref); + $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref; + + $object->sendtoid = 0; + } + elseif ($action == 'PROJECT_VALIDATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "projects")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref); + $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref; + + $object->sendtoid = 0; + } + elseif ($action == 'PROJECT_MODIFY') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "projects")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref); + $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref; + + $object->sendtoid = 0; + } // Project tasks - elseif ($action == 'TASK_CREATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "projects")); + elseif ($action == 'TASK_CREATE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "projects")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref); $object->actionmsg = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref); $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref; $object->sendtoid = 0; - } elseif ($action == 'TASK_MODIFY') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "projects")); + } + elseif ($action == 'TASK_MODIFY') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "projects")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("TaskModifiedInDolibarr", $object->ref); $object->actionmsg = $langs->transnoentities("TaskModifieddInDolibarr", $object->ref); $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref; $object->sendtoid = 0; - } elseif ($action == 'TASK_DELETE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "projects")); + } + elseif ($action == 'TASK_DELETE') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "projects")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref); $object->actionmsg = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref); $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref; $object->sendtoid = 0; - } elseif ($action == 'TICKET_ASSIGNED') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "projects")); - - if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref); - $object->actionmsg = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref); - if ($object->oldcopy->fk_user_assign > 0) { - $tmpuser = new User($this->db); - $tmpuser->fetch($object->oldcopy->fk_user_assign); - $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$tmpuser->getFullName($langs); - } else { - $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$langs->trans("None"); + } + elseif ($action == 'TICKET_ASSIGNED') + { + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other", "projects")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref); + $object->actionmsg = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref); + if ($object->oldcopy->fk_user_assign > 0) + { + $tmpuser = new User($this->db); + $tmpuser->fetch($object->oldcopy->fk_user_assign); + $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$tmpuser->getFullName($langs); + } + else + { + $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$langs->trans("None"); + } + if ($object->fk_user_assign > 0) + { + $tmpuser = new User($this->db); + $tmpuser->fetch($object->fk_user_assign); + $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$tmpuser->getFullName($langs); + } + else + { + $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$langs->trans("None"); + } + $object->sendtoid = 0; + } + // TODO Merge all previous cases into this generic one + else // $action = BILL_DELETE, TICKET_CREATE, TICKET_MODIFY, TICKET_DELETE, ... + { + // Note: We are here only if $conf->global->MAIN_AGENDA_ACTIONAUTO_action is on (tested at begining of this function). + // Note that these key can be set in agenda setup, only if defined into c_action_trigger + // Load translation files required by the page + $langs->loadLangs(array("agenda", "other")); + + if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities($action."InDolibarr", $object->ref); + if (empty($object->actionmsg)) $object->actionmsg = $langs->transnoentities($action."InDolibarr", $object->ref); + + $object->sendtoid = 0; + } + + $object->actionmsg = $langs->transnoentities("Author").': '.$user->login."\n".$object->actionmsg; + + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + // Add entry in event table + $now = dol_now(); + + if (isset($_SESSION['listofnames-'.$object->trackid])) + { + $attachs = $_SESSION['listofnames-'.$object->trackid]; + if ($attachs && strpos($action, 'SENTBYMAIL')) + { + $object->actionmsg = dol_concatdesc($object->actionmsg, "\n".$langs->transnoentities("AttachedFiles").': '.$attachs); } - if ($object->fk_user_assign > 0) { - $tmpuser = new User($this->db); - $tmpuser->fetch($object->fk_user_assign); - $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$tmpuser->getFullName($langs); - } else { - $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$langs->trans("None"); - } - $object->sendtoid = 0; - } - // TODO Merge all previous cases into this generic one - else // $action = BILL_DELETE, TICKET_CREATE, TICKET_MODIFY, TICKET_DELETE, CONTACT_SENTBYMAIL, RECRUITMENTCANDIDATURE_MODIFY, ... - { - // Note: We are here only if $conf->global->MAIN_AGENDA_ACTIONAUTO_action is on (tested at begining of this function). - // Note that these key can be set in agenda setup, only if defined into c_action_trigger - // Load translation files required by the page - if (empty($object->actionmsg2)) { - $langs->loadLangs(array("agenda", "other")); - if ($langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)) != $action."InDolibarr") { // specific translation key - $object->actionmsg2 = $langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)); - } else { // generic translation key - $tmp = explode('_', $action); - $object->actionmsg2 = $langs->transnoentities($tmp[count($tmp) - 1]."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)); - } - } - if (empty($object->actionmsg)) { - $langs->loadLangs(array("agenda", "other")); - if ($langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)) != $action."InDolibarr") { // specific translation key - $object->actionmsg = $langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)); - } else { // generic translation key - $tmp = explode('_', $action); - $object->actionmsg = $langs->transnoentities($tmp[count($tmp) - 1]."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)); - } - } - - if (!isset($object->sendtoid) || !is_array($object->sendtoid)) { - $object->sendtoid = 0; - } - } - - // If trackid is not defined, we set it - if (empty($object->trackid)) { - // See also similar list into emailcollector.class.php - if (preg_match('/^COMPANY_/', $action)) { $object->trackid = 'thi'.$object->id; } - elseif (preg_match('/^CONTACT_/', $action)) { $object->trackid = 'ctc'.$object->id; } - elseif (preg_match('/^CONTRACT_/', $action)) { $object->trackid = 'con'.$object->id; } - elseif (preg_match('/^PROPAL_/', $action)) { $object->trackid = 'pro'.$object->id; } - elseif (preg_match('/^ORDER_/', $action)) { $object->trackid = 'ord'.$object->id; } - elseif (preg_match('/^BILL_/', $action)) { $object->trackid = 'inv'.$object->id; } - elseif (preg_match('/^FICHINTER_/', $action)) { $object->trackid = 'int'.$object->id; } - elseif (preg_match('/^SHIPPING_/', $action)) { $object->trackid = 'shi'.$object->id; } - elseif (preg_match('/^RECEPTION_/', $action)) { $object->trackid = 'rec'.$object->id; } - elseif (preg_match('/^PROPOSAL_SUPPLIER/', $action)) { $object->trackid = 'spr'.$object->id; } - elseif (preg_match('/^ORDER_SUPPLIER_/', $action)) { $object->trackid = 'sor'.$object->id; } - elseif (preg_match('/^BILL_SUPPLIER_/', $action)) { $object->trackid = 'sin'.$object->id; } - elseif (preg_match('/^MEMBER_SUBSCRIPTION_/', $action)) { $object->trackid = 'sub'.$object->id; } - elseif (preg_match('/^MEMBER_/', $action)) { $object->trackid = 'mem'.$object->id; } - elseif (preg_match('/^PROJECT_/', $action)) { $object->trackid = 'proj'.$object->id; } - elseif (preg_match('/^TASK_/', $action)) { $object->trackid = 'tas'.$object->id; } - elseif (preg_match('/^TICKET_/', $action)) { $object->trackid = 'tic'.$object->id; } - else $object->trackid = ''; - } - - $object->actionmsg = dol_concatdesc($langs->transnoentities("Author").': '.$user->login, $object->actionmsg); - - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - // Add entry in event table - $now = dol_now(); - - if (isset($_SESSION['listofnames-'.$object->trackid])) { - $attachs = $_SESSION['listofnames-'.$object->trackid]; - if ($attachs && strpos($action, 'SENTBYMAIL')) { - $object->actionmsg = dol_concatdesc($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'; + } + + 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); - // Set contactforaction if there is only 1 contact. - - if (is_array($object->sendtoid)) { - if (count($object->sendtoid) == 1) $contactforaction->fetch(reset($object->sendtoid)); - } else { - if ($object->sendtoid > 0) $contactforaction->fetch($object->sendtoid); - } - // Set societeforaction. - if (isset($object->socid) && $object->socid > 0) $societeforaction->fetch($object->socid); - elseif (isset($object->fk_soc) && $object->fk_soc > 0) $societeforaction->fetch($object->fk_soc); - - $projectid = isset($object->fk_project) ? $object->fk_project : 0; - if ($object->element == 'project') $projectid = $object->id; - - $elementid = $object->id; // id of object - $elementtype = $object->element; - $elementmodule = (empty($object->module) ? '' : $object->module); - if ($object->element == 'subscription') { - $elementid = $object->fk_adherent; - $elementtype = 'member'; - } - //var_dump($societeforaction);var_dump($contactforaction);var_dump($elementid);var_dump($elementtype);exit; + $societeforaction = new Societe($this->db); + // Set contactforaction if there is only 1 contact. + if (is_array($object->sendtoid)) + { + if (count($object->sendtoid) == 1) $contactforaction->fetch(reset($object->sendtoid)); + } + else + { + if ($object->sendtoid > 0) $contactforaction->fetch($object->sendtoid); + } + // Set societeforaction. + if ($object->socid > 0) $societeforaction->fetch($object->socid); + elseif ($object->fk_soc > 0) $societeforaction->fetch($object->fk_soc); + + $projectid = isset($object->fk_project) ? $object->fk_project : 0; + if ($object->element == 'project') $projectid = $object->id; + + $elementid = $object->id; + $elementtype = $object->element; + if ($object->element == 'subscription') + { + $elementid = $object->fk_adherent; + $elementtype = 'member'; + } + //var_dump($societeforaction);var_dump($contactforaction);exit; // Insertion action require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; @@ -815,24 +900,25 @@ $actioncomm->durationp = 0; $actioncomm->percentage = -1; // Not applicable $actioncomm->socid = $societeforaction->id; - $actioncomm->contact_id = $contactforaction->id; // deprecated, use ->socpeopleassigned instead + $actioncomm->contactid = $contactforaction->id; $actioncomm->authorid = $user->id; // User saving action $actioncomm->userownerid = $user->id; // Owner of action - // Fields defined when action is an email (content should be into object->actionmsg to be added into note, subject into object->actionms2 to be added into label) - $actioncomm->email_msgid = empty($object->email_msgid) ? null : $object->email_msgid; - $actioncomm->email_from = empty($object->email_from) ? null : $object->email_from; - $actioncomm->email_sender = empty($object->email_sender) ? null : $object->email_sender; - $actioncomm->email_to = empty($object->email_to) ? null : $object->email_to; - $actioncomm->email_tocc = empty($object->email_tocc) ? null : $object->email_tocc; - $actioncomm->email_tobcc = empty($object->email_tobcc) ? null : $object->email_tobcc; - $actioncomm->email_subject = empty($object->email_subject) ? null : $object->email_subject; - $actioncomm->errors_to = empty($object->errors_to) ? null : $object->errors_to; + // Fields defined when action is an email (content should be into object->actionmsg to be added into note, subject into object->actionms2 to be added into label) + $actioncomm->email_msgid = $object->email_msgid; + $actioncomm->email_from = $object->email_from; + $actioncomm->email_sender = $object->email_sender; + $actioncomm->email_to = $object->email_to; + $actioncomm->email_tocc = $object->email_tocc; + $actioncomm->email_tobcc = $object->email_tobcc; + $actioncomm->email_subject = $object->email_subject; + $actioncomm->errors_to = $object->errors_to; // Object linked (if link is for thirdparty, contact, project it is a recording error. We should not have links in link table - // for such objects because there is already a dedicated field into table llx_actioncomm or llx_actioncomm_resources. - if (!in_array($elementtype, array('societe', 'contact', 'project'))) { + // for such objects because there is already a dedicated field into table llx_actioncomm. + if (!in_array($elementtype, array('societe', 'contact', 'project'))) + { $actioncomm->fk_element = $elementid; - $actioncomm->elementtype = $elementtype.($elementmodule ? '@'.$elementmodule : ''); + $actioncomm->elementtype = $elementtype; } if (property_exists($object, 'attachedfiles') && is_array($object->attachedfiles) && count($object->attachedfiles) > 0) { @@ -841,15 +927,11 @@ if (property_exists($object, 'sendtouserid') && is_array($object->sendtouserid) && count($object->sendtouserid) > 0) { $actioncomm->userassigned = $object->sendtouserid; } - if (property_exists($object, 'sendtoid') && is_array($object->sendtoid) && count($object->sendtoid) > 0) { - foreach ($object->sendtoid as $val) { - $actioncomm->socpeopleassigned[$val] = $val; - } - } $ret = $actioncomm->create($user); // User creating action - if ($ret > 0 && !empty($conf->global->MAIN_COPY_FILE_IN_EVENT_AUTO)) { + if ($ret > 0 && $conf->global->MAIN_COPY_FILE_IN_EVENT_AUTO) + { if (is_array($object->attachedfiles) && array_key_exists('paths', $object->attachedfiles) && count($object->attachedfiles['paths']) > 0) { foreach ($object->attachedfiles['paths'] as $key=>$filespath) { $srcfile = $filespath; @@ -865,15 +947,18 @@ unset($object->actionmsg); unset($object->actionmsg2); unset($object->actiontypecode); // When several action are called on same object, we must be sure to not reuse value of first action. - if ($ret > 0) { + if ($ret > 0) + { $_SESSION['LAST_ACTION_CREATED'] = $ret; return 1; - } else { - $this->error = "Failed to insert event : ".$actioncomm->error." ".join(',', $actioncomm->errors); - $this->errors = $actioncomm->errors; - - dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR); - return -1; - } - } + } + else + { + $this->error = "Failed to insert event : ".$actioncomm->error." ".join(',', $actioncomm->errors); + $this->errors = $actioncomm->errors; + + dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR); + return -1; + } + } } --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_interface_50_modBlockedlog_ActionsBlockedLog.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_50_modBlockedlog_ActionsBlockedLog.class.php @@ -30,22 +30,19 @@ */ class InterfaceActionsBlockedLog extends DolibarrTriggers { + public $family = 'system'; + public $description = "Triggers of this module add action for BlockedLog module (Module of unalterable logs)."; + /** - * Constructor - * - * @param DoliDB $db Database handler + * Version of the trigger + * @var string */ - public function __construct($db) - { - $this->db = $db; + public $version = self::VERSION_DOLIBARR; - $this->name = preg_replace('/^Interface/i', '', get_class($this)); - $this->family = "system"; - $this->description = "Triggers of this module add action for BlockedLog module (Module of unalterable logs)."; - // 'development', 'experimental', 'dolibarr' or version - $this->version = self::VERSION_DOLIBARR; - $this->picto = 'technic'; - } + /** + * @var string Image of the trigger + */ + public $picto = 'technic'; /** * Function called on Dolibarr payment or invoice event. @@ -71,7 +68,8 @@ $b = new BlockedLog($this->db); // Tracked events - if (!in_array($action, array_keys($b->trackedevents))) { + if (!in_array($action, array_keys($b->trackedevents))) + { return 0; } @@ -79,22 +77,24 @@ $qualified = 0; $amounts = 0; if ($action === 'BILL_VALIDATE' || (($action === 'BILL_DELETE' || $action === 'BILL_SENTBYMAIL') && $object->statut != 0) - || $action === 'BILL_SUPPLIER_VALIDATE' || (($action === 'BILL_SUPPLIER_DELETE' || $action === 'BILL_SUPPLIER_SENTBYMAIL') && $object->statut != 0) - || $action === 'MEMBER_SUBSCRIPTION_CREATE' || $action === 'MEMBER_SUBSCRIPTION_MODIFY' || $action === 'MEMBER_SUBSCRIPTION_DELETE' - || $action === 'DON_VALIDATE' || (($action === 'DON_MODIFY' || $action === 'DON_DELETE') && $object->statut != 0) - || $action === 'CASHCONTROL_VALIDATE' - || (in_array($object->element, array('facture', 'supplier_invoice')) && $action === 'DOC_DOWNLOAD' && $object->statut != 0) - || (in_array($object->element, array('facture', 'supplier_invoice')) && $action === 'DOC_PREVIEW' && $object->statut != 0) - || (!empty($conf->global->BLOCKEDLOG_ADD_ACTIONS_SUPPORTED) && in_array($action, explode(',', $conf->global->BLOCKEDLOG_ADD_ACTIONS_SUPPORTED))) - ) { + || $action === 'BILL_SUPPLIER_VALIDATE' || (($action === 'BILL_SUPPLIER_DELETE' || $action === 'BILL_SUPPLIER_SENTBYMAIL') && $object->statut != 0) + || $action === 'MEMBER_SUBSCRIPTION_CREATE' || $action === 'MEMBER_SUBSCRIPTION_MODIFY' || $action === 'MEMBER_SUBSCRIPTION_DELETE' + || $action === 'DON_VALIDATE' || (($action === 'DON_MODIFY' || $action === 'DON_DELETE') && $object->statut != 0) + || $action === 'CASHCONTROL_VALIDATE' + || (in_array($object->element, array('facture', 'supplier_invoice')) && $action === 'DOC_DOWNLOAD' && $object->statut != 0) + || (in_array($object->element, array('facture', 'supplier_invoice')) && $action === 'DOC_PREVIEW' && $object->statut != 0) + ) + { $qualified++; if (in_array($action, array( 'MEMBER_SUBSCRIPTION_CREATE', 'MEMBER_SUBSCRIPTION_MODIFY', 'MEMBER_SUBSCRIPTION_DELETE', 'DON_VALIDATE', 'DON_MODIFY', 'DON_DELETE'))) $amounts = (double) $object->amount; - elseif ($action == 'CASHCONTROL_VALIDATE') { + elseif ($action == 'CASHCONTROL_VALIDATE') + { $amounts = (double) $object->cash + (double) $object->cheque + (double) $object->card; - } else $amounts = (double) $object->total_ttc; + } + else $amounts = (double) $object->total_ttc; } /*if ($action === 'BILL_PAYED' || $action==='BILL_UNPAYED' || $action === 'BILL_SUPPLIER_PAYED' || $action === 'BILL_SUPPLIER_UNPAYED') @@ -103,7 +103,8 @@ $amounts= (double) $object->total_ttc; }*/ if ($action === 'PAYMENT_CUSTOMER_CREATE' || $action === 'PAYMENT_SUPPLIER_CREATE' || $action === 'DONATION_PAYMENT_CREATE' - || $action === 'PAYMENT_CUSTOMER_DELETE' || $action === 'PAYMENT_SUPPLIER_DELETE' || $action === 'DONATION_PAYMENT_DELETE') { + || $action === 'PAYMENT_CUSTOMER_DELETE' || $action === 'PAYMENT_SUPPLIER_DELETE' || $action === 'DONATION_PAYMENT_DELETE') + { $qualified++; $amounts = 0; if (!empty($object->amounts)) { @@ -111,20 +112,24 @@ $amounts += price2num($amount); } } - } elseif (strpos($action, 'PAYMENT') !== false && !in_array($action, array('PAYMENT_ADD_TO_BANK'))) { + } + elseif (strpos($action, 'PAYMENT') !== false && !in_array($action, array('PAYMENT_ADD_TO_BANK'))) + { $qualified++; $amounts = (double) $object->amount; } // Another protection. // May be used when event is DOC_DOWNLOAD or DOC_PREVIEW and element is not an invoice - if (!$qualified) { + if (!$qualified) + { return 0; // not implemented action log } $result = $b->setObjectData($object, $action, $amounts, $user); // Set field date_object, ref_object, fk_object, element, object_data - if ($result < 0) { + if ($result < 0) + { $this->error = $b->error; $this->errors = $b->errors; return -1; @@ -132,12 +137,15 @@ $res = $b->create($user); - if ($res < 0) { + if ($res < 0) + { $this->error = $b->error; $this->errors = $b->errors; return -1; - } else { + } + else + { return 1; } - } + } } --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_interface_50_modLdap_Ldapsynchro.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_50_modLdap_Ldapsynchro.class.php @@ -31,22 +31,19 @@ */ class InterfaceLdapsynchro extends DolibarrTriggers { + public $family = 'ldap'; + public $description = "Triggers of this module allows to synchronize Dolibarr toward a LDAP database."; + /** - * Constructor - * - * @param DoliDB $db Database handler + * Version of the trigger + * @var string */ - public function __construct($db) - { - $this->db = $db; - - $this->name = preg_replace('/^Interface/i', '', get_class($this)); - $this->family = "ldap"; - $this->description = "Triggers of this module allows to synchronize Dolibarr toward a LDAP database."; - // 'development', 'experimental', 'dolibarr' or version - $this->version = self::VERSION_DOLIBARR; - $this->picto = 'technic'; - } + public $version = self::VERSION_DOLIBARR; + + /** + * @var string Image of the trigger + */ + public $picto = 'technic'; /** * Function called when a Dolibarrr business event is done. @@ -64,7 +61,8 @@ if (empty($conf->ldap->enabled)) return 0; // Module not active, we do nothing if (defined('DISABLE_LDAP_SYNCHRO')) return 0; // If constant defined, we do nothing - if (!function_exists('ldap_connect')) { + if (!function_exists('ldap_connect')) + { dol_syslog("Warning, module LDAP is enabled but LDAP functions not available in this PHP", LOG_WARNING); return 0; } @@ -75,13 +73,16 @@ $result = 0; // Users - if ($action == 'USER_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + if ($action == 'USER_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); @@ -90,14 +91,19 @@ if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'USER_MODIFY') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) { + } + elseif ($action == 'USER_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { + if (empty($object->oldcopy) || !is_object($object->oldcopy)) + { dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); $object->oldcopy = clone $object; } @@ -109,7 +115,8 @@ $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1); $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { $olddn = ''; } @@ -123,14 +130,19 @@ if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'USER_NEW_PASSWORD') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) { + } + elseif ($action == 'USER_NEW_PASSWORD') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { + if (empty($object->oldcopy) || !is_object($object->oldcopy)) + { dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); $object->oldcopy = clone $object; } @@ -142,7 +154,8 @@ $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1); $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { $olddn = ''; } @@ -154,15 +167,21 @@ if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'USER_ENABLEDISABLE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } elseif ($action == 'USER_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + } + elseif ($action == 'USER_ENABLEDISABLE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); @@ -171,16 +190,21 @@ if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'USER_SETINGROUP') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + } + elseif ($action == 'USER_SETINGROUP') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { // Must edit $object->newgroupid $usergroup = new UserGroup($this->db); - if ($object->newgroupid > 0) { + if ($object->newgroupid > 0) + { $usergroup->fetch($object->newgroupid); $oldinfo = $usergroup->_load_ldap_info(); @@ -190,7 +214,8 @@ $container = $usergroup->_load_ldap_dn($oldinfo, 1); $search = "(".$usergroup->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { $olddn = ''; } @@ -203,16 +228,21 @@ if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'USER_REMOVEFROMGROUP') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + } + elseif ($action == 'USER_REMOVEFROMGROUP') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { // Must edit $object->newgroupid $usergroup = new UserGroup($this->db); - if ($object->oldgroupid > 0) { + if ($object->oldgroupid > 0) + { $usergroup->fetch($object->oldgroupid); $oldinfo = $usergroup->_load_ldap_info(); @@ -222,7 +252,8 @@ $container = $usergroup->_load_ldap_dn($oldinfo, 1); $search = "(".$usergroup->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { $olddn = ''; } @@ -238,13 +269,16 @@ } // Groupes - elseif ($action == 'USERGROUP_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + elseif ($action == 'USERGROUP_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); @@ -258,14 +292,19 @@ if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'USERGROUP_MODIFY') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) { + } + elseif ($action == 'USERGROUP_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { + if (empty($object->oldcopy) || !is_object($object->oldcopy)) + { dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); $object->oldcopy = clone $object; } @@ -277,7 +316,8 @@ $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1); $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { $olddn = ''; } @@ -289,13 +329,17 @@ if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'USERGROUP_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + } + elseif ($action == 'USERGROUP_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); @@ -307,13 +351,16 @@ } // Contacts - elseif ($action == 'CONTACT_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + elseif ($action == 'CONTACT_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); @@ -322,14 +369,19 @@ if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'CONTACT_MODIFY') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) { + } + elseif ($action == 'CONTACT_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { + if (empty($object->oldcopy) || !is_object($object->oldcopy)) + { dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); $object->oldcopy = clone $object; } @@ -341,7 +393,8 @@ $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1); $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { $olddn = ''; } @@ -353,13 +406,17 @@ if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'CONTACT_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + } + elseif ($action == 'CONTACT_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); @@ -371,21 +428,26 @@ } // Members - elseif ($action == 'MEMBER_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + elseif ($action == 'MEMBER_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); $result = $ldap->add($dn, $info, $user); // For member type - if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') { - if ($object->typeid > 0) { + if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') + { + if ($object->typeid > 0) + { require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php"; $membertype = new AdherentType($this->db); $membertype->fetch($object->typeid); @@ -398,7 +460,8 @@ $container = $membertype->_load_ldap_dn($oldinfo, 1); $search = "(".$membertype->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { $olddn = ''; } @@ -412,15 +475,20 @@ if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'MEMBER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') { + } + elseif ($action == 'MEMBER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') + { // If status field is setup to be synchronized - if (!empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) { + if (!empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) + { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) { + if ($result > 0) + { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); $olddn = $dn; // We know olddn=dn as we change only status @@ -431,19 +499,24 @@ if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } } - } elseif ($action == 'MEMBER_SUBSCRIPTION') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') { + } + elseif ($action == 'MEMBER_SUBSCRIPTION') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') + { // If subscriptions fields are setup to be synchronized if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE || $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT - || $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) { + || $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) + { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) { + if ($result > 0) + { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); $olddn = $dn; // We know olddn=dn as we change only subscriptions @@ -454,14 +527,19 @@ if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } } - } elseif ($action == 'MEMBER_MODIFY') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) { + } + elseif ($action == 'MEMBER_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { + if (empty($object->oldcopy) || !is_object($object->oldcopy)) + { dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); $object->oldcopy = clone $object; } @@ -473,7 +551,8 @@ $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1); $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { $olddn = ''; } @@ -485,7 +564,8 @@ $result = $ldap->update($dn, $info, $user, $olddn, $newrdn, $newparent); // For member type - if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') { + if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') + { require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php"; /* @@ -502,7 +582,8 @@ $container = $newmembertype->_load_ldap_dn($oldinfo, 1); $search = "(".$newmembertype->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { $olddn = ''; } @@ -511,7 +592,8 @@ $result = $ldap->update($dn, $info, $user, $olddn); - if ($object->oldcopy->typeid != $object->typeid) { + if ($object->oldcopy->typeid != $object->typeid) + { /* * Remove member in old member type */ @@ -526,7 +608,8 @@ $container = $oldmembertype->_load_ldap_dn($oldinfo, 1); $search = "(".$oldmembertype->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { $olddn = ''; } @@ -538,19 +621,25 @@ } } - if ($result <= 0) { + if ($result <= 0) + { $this->errors[] = "ErrorLDAP ".$ldap->error; } } - } elseif ($action == 'MEMBER_NEW_PASSWORD') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') { + } + elseif ($action == 'MEMBER_NEW_PASSWORD') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') + { // If password field is setup to be synchronized - if ($conf->global->LDAP_FIELD_PASSWORD || $conf->global->LDAP_FIELD_PASSWORD_CRYPTED) { + if ($conf->global->LDAP_FIELD_PASSWORD || $conf->global->LDAP_FIELD_PASSWORD_CRYPTED) + { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) { + if ($result > 0) + { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); $olddn = $dn; // We know olddn=dn as we change only password @@ -558,20 +647,26 @@ $result = $ldap->update($dn, $info, $user, $olddn); } - if ($result <= 0) { + if ($result <= 0) + { $this->errors[] = "ErrorLDAP ".$ldap->error; } } } - } elseif ($action == 'MEMBER_RESILIATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') { + } + elseif ($action == 'MEMBER_RESILIATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') + { // If status field is setup to be synchronized - if (!empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) { + if (!empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) + { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) { + if ($result > 0) + { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); $olddn = $dn; // We know olddn=dn as we change only status @@ -579,26 +674,33 @@ $result = $ldap->update($dn, $info, $user, $olddn); } - if ($result <= 0) { + if ($result <= 0) + { $this->errors[] = "ErrorLDAP ".$ldap->error; } } } - } elseif ($action == 'MEMBER_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + } + elseif ($action == 'MEMBER_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); $result = $ldap->delete($dn); // For member type - if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') { - if ($object->typeid > 0) { + if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') + { + if ($object->typeid > 0) + { require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php"; /* @@ -615,7 +717,8 @@ $container = $membertype->_load_ldap_dn($oldinfo, 1); $search = "(".$membertype->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { $olddn = ''; } @@ -627,20 +730,24 @@ } } - if ($result <= 0) { + if ($result <= 0) + { $this->errors[] = "ErrorLDAP ".$ldap->error; } } } // Members types - elseif ($action == 'MEMBER_TYPE_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + elseif ($action == 'MEMBER_TYPE_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); @@ -652,18 +759,24 @@ $result = $ldap->add($dn, $info, $user); } - if ($result <= 0) { + if ($result <= 0) + { $this->errors[] = "ErrorLDAP ".$ldap->error; } } - } elseif ($action == 'MEMBER_TYPE_MODIFY') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) { + } + elseif ($action == 'MEMBER_TYPE_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { + if (empty($object->oldcopy) || !is_object($object->oldcopy)) + { dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); $object->oldcopy = clone $object; } @@ -677,7 +790,8 @@ $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1); $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { $olddn = ''; } @@ -693,20 +807,25 @@ $this->errors[] = "ErrorLDAP ".$ldap->error; } } - } elseif ($action == 'MEMBER_TYPE_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + } + elseif ($action == 'MEMBER_TYPE_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) + { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); $result = $ldap->delete($dn); } - if ($result <= 0) { + if ($result <= 0) + { $this->errors[] = "ErrorLDAP ".$ldap->error; } } --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_interface_50_modMailmanspip_Mailmanspipsynchro.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_50_modMailmanspip_Mailmanspipsynchro.class.php @@ -29,22 +29,19 @@ */ class InterfaceMailmanSpipsynchro extends DolibarrTriggers { + public $family = 'mailmanspip'; + public $description = "Triggers of this module allows to synchronize Mailman an Spip."; + /** - * Constructor - * - * @param DoliDB $db Database handler + * Version of the trigger + * @var string */ - public function __construct($db) - { - $this->db = $db; + public $version = self::VERSION_DOLIBARR; - $this->name = preg_replace('/^Interface/i', '', get_class($this)); - $this->family = "mailmanspip"; - $this->description = "Triggers of this module allows to synchronize Mailman an Spip."; - // 'development', 'experimental', 'dolibarr' or version - $this->version = self::VERSION_DOLIBARR; - $this->picto = 'technic'; - } + /** + * @var string Image of the trigger + */ + public $picto = 'technic'; /** * Function called when a Dolibarrr business event is done. @@ -59,95 +56,123 @@ */ public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) { - if (empty($conf->mailmanspip->enabled)) return 0; // Module not active, we do nothing + if (empty($conf->mailmanspip->enabled)) return 0; // Module not active, we do nothing - require_once DOL_DOCUMENT_ROOT."/mailmanspip/class/mailmanspip.class.php"; - require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php"; + require_once DOL_DOCUMENT_ROOT."/mailmanspip/class/mailmanspip.class.php"; + require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php"; - if ($action == 'CATEGORY_LINK') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($action == 'CATEGORY_LINK') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - // We add subscription if we change category (new category may means more mailing-list to subscribe) - if (is_object($object->context['linkto']) && method_exists($object->context['linkto'], 'add_to_abo') && $object->context['linkto']->add_to_abo() < 0) { - $this->error = $object->context['linkto']->error; - $this->errors = $object->context['linkto']->errors; - $return = -1; - } else { + // We add subscription if we change category (new category may means more mailing-list to subscribe) + if (is_object($object->context['linkto']) && method_exists($object->context['linkto'], 'add_to_abo') && $object->context['linkto']->add_to_abo() < 0) + { + $this->error = $object->context['linkto']->error; + $this->errors = $object->context['linkto']->errors; + $return = -1; + } + else + { $return = 1; } + return $return; + } + elseif ($action == 'CATEGORY_UNLINK') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + // We remove subscription if we change category (lessw category may means less mailing-list to subscribe) + if (is_object($object->context['unlinkoff']) && method_exists($object->context['unlinkoff'], 'del_to_abo') && $object->context['unlinkoff']->del_to_abo() < 0) + { + $this->error = $object->context['unlinkoff']->error; + $this->errors = $object->context['unlinkoff']->errors; + $return = -1; + } + else + { + $return = 1; + } + + return $return; + } + + // Members + elseif ($action == 'MEMBER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $return = 0; + if ($object->add_to_abo() < 0) + { + $this->errors = $object->errors; + if (!empty($object->error)) $this->errors[] = $object->error; + $return = -1; + } + else + { + $return = 1; + } + + return $return; + } + elseif ($action == 'MEMBER_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $return = 0; + // Add user into some linked tools (mailman, spip, etc...) + if (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid)) + { + if (is_object($object->oldcopy) && (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid))) // If email has changed or if list has changed we delete mailman subscription for old email + { + if ($object->oldcopy->del_to_abo() < 0) + { + $this->errors = $object->oldcopy->errors; + if (!empty($object->oldcopy->error)) $this->errors[] = $object->oldcopy->error; + $return = -1; + } + else + { + $return = 1; + } + } + // We add subscription if new email or new type (new type may means more mailing-list to subscribe) + if ($object->add_to_abo() < 0) + { + $this->errors = $object->errors; + if (!empty($object->error)) $this->errors[] = $object->error; + $return = -1; + } + else + { + $return = 1; + } + } + return $return; - } elseif ($action == 'CATEGORY_UNLINK') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MEMBER_RESILIATE' || $action == 'MEMBER_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - // We remove subscription if we change category (lessw category may means less mailing-list to subscribe) - if (is_object($object->context['unlinkoff']) && method_exists($object->context['unlinkoff'], 'del_to_abo') && $object->context['unlinkoff']->del_to_abo() < 0) { - $this->error = $object->context['unlinkoff']->error; - $this->errors = $object->context['unlinkoff']->errors; + $return = 0; + // Remove from external tools (mailman, spip, etc...) + if ($object->del_to_abo() < 0) + { + $this->errors = $object->errors; + if (!empty($object->error)) $this->errors[] = $object->error; $return = -1; - } else { + } + else + { $return = 1; } - return $return; - } - - // Members - elseif ($action == 'MEMBER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $return = 0; - if ($object->add_to_abo() < 0) { - $this->errors = $object->errors; - if (!empty($object->error)) $this->errors[] = $object->error; - $return = -1; - } else { - $return = 1; - } - - return $return; - } elseif ($action == 'MEMBER_MODIFY') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $return = 0; - // Add user into some linked tools (mailman, spip, etc...) - if (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid)) { - if (is_object($object->oldcopy) && (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid))) { // If email has changed or if list has changed we delete mailman subscription for old email - if ($object->oldcopy->del_to_abo() < 0) { - $this->errors = $object->oldcopy->errors; - if (!empty($object->oldcopy->error)) $this->errors[] = $object->oldcopy->error; - $return = -1; - } else { - $return = 1; - } - } - // We add subscription if new email or new type (new type may means more mailing-list to subscribe) - if ($object->add_to_abo() < 0) { - $this->errors = $object->errors; - if (!empty($object->error)) $this->errors[] = $object->error; - $return = -1; - } else { - $return = 1; - } - } - - return $return; - } elseif ($action == 'MEMBER_RESILIATE' || $action == 'MEMBER_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $return = 0; - // Remove from external tools (mailman, spip, etc...) - if ($object->del_to_abo() < 0) { - $this->errors = $object->errors; - if (!empty($object->error)) $this->errors[] = $object->error; - $return = -1; - } else { - $return = 1; - } - - return $return; - } + return $return; + } return 0; - } + } } --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_interface_50_modNotification_Notification.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_50_modNotification_Notification.class.php @@ -30,6 +30,20 @@ */ class InterfaceNotification extends DolibarrTriggers { + public $family = 'notification'; + public $description = "Triggers of this module send email notifications according to Notification module setup."; + + /** + * Version of the trigger + * @var string + */ + public $version = self::VERSION_DOLIBARR; + + /** + * @var string Image of the trigger + */ + public $picto = 'email'; + // @todo Defined also into notify.class.php) public $listofmanagedevents = array( 'BILL_VALIDATE', @@ -48,23 +62,6 @@ 'HOLIDAY_VALIDATE', 'HOLIDAY_APPROVE' ); - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - public function __construct($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."; - // 'development', 'experimental', 'dolibarr' or version - $this->version = self::VERSION_DOLIBARR; - $this->picto = 'email'; - } /** * Function called when a Dolibarrr business event is done. @@ -110,17 +107,20 @@ $sql .= $this->db->order("rang, elementtype, code"); dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) { + while ($i < $num) + { $obj = $this->db->fetch_object($resql); $qualified = 0; // Check is this event is supported by notification module if (in_array($obj->code, $this->listofmanagedevents)) $qualified = 1; // Check if module for this event is active - if ($qualified) { + if ($qualified) + { //print 'xx'.$obj->code; $element = $obj->elementtype; @@ -133,13 +133,15 @@ elseif (!in_array($element, array('order_supplier', 'invoice_supplier', 'withdraw', 'shipping', 'member', 'expensereport')) && empty($conf->$element->enabled)) $qualified = 0; } - if ($qualified) { + if ($qualified) + { $ret[] = array('rowid'=>$obj->rowid, 'code'=>$obj->code, 'label'=>$obj->label, 'description'=>$obj->description, 'elementtype'=>$obj->elementtype); } $i++; } - } else dol_print_error($this->db); + } + else dol_print_error($this->db); return $ret; } --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_interface_50_modTicket_TicketEmail.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_50_modTicket_TicketEmail.class.php @@ -31,6 +31,11 @@ class InterfaceTicketEmail extends DolibarrTriggers { /** + * @var DoliDB Database handler. + */ + public $db; + + /** * Constructor * * @param DoliDB $db Database handler @@ -42,8 +47,51 @@ $this->name = preg_replace('/^Interface/i', '', get_class($this)); $this->family = "ticket"; $this->description = "Triggers of the module ticket to send notifications to internal users and to third-parties"; - $this->version = self::VERSION_DOLIBARR; // 'development', 'experimental', 'dolibarr' or version + $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version $this->picto = 'ticket'; + } + + /** + * Return name of trigger file + * + * @return string Name of trigger file + */ + public function getName() + { + return $this->name; + } + + /** + * Return description of trigger file + * + * @return string Description of trigger file + */ + public function getDesc() + { + return $this->description; + } + + /** + * Return version of trigger file + * + * @return string Version of trigger file + */ + public function getVersion() + { + global $langs; + $langs->load("admin"); + + if ($this->version == 'development') { + return $langs->trans("Development"); + } elseif ($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"); + } } /** @@ -67,13 +115,16 @@ case 'TICKET_ASSIGNED': dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if ($object->fk_user_assign > 0 && $object->fk_user_assign != $user->id) { + if ($object->fk_user_assign > 0 && $object->fk_user_assign != $user->id) + { $userstat = new User($this->db); $res = $userstat->fetch($object->fk_user_assign); - if ($res > 0) { + if ($res > 0) + { // Send email to notification email - if (empty($conf->global->TICKET_DISABLE_ALL_MAILS)) { + if (empty($conf->global->TICKET_DISABLE_ALL_MAILS)) + { // Init to avoid errors $filepath = array(); $filename = array(); @@ -119,7 +170,9 @@ } $ok = 1; - } else { + } + else + { $this->error = $userstat->error; $this->errors = $userstat->errors; } @@ -131,9 +184,79 @@ $langs->load('ticket'); + $object->fetch('', $object->track_id); // Should be useless + + // Send email to notification email - if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && empty($object->context['disableticketemail'])) { - $sendto = empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) ? '' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO; + $sendto = $conf->global->TICKET_NOTIFICATION_EMAIL_TO; + if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && empty($object->context['disableticketemail'])) + { + if ($sendto) + { + // Init to avoid errors + $filepath = array(); + $filename = array(); + $mimetype = array(); + + /* Send email to admin */ + $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectAdmin'); + $message_admin = $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id)."\n\n"; + $message_admin .= ''; + + if ($object->fk_soc > 0) { + $object->fetch_thirdparty(); + $message_admin .= '

'.$langs->trans('Company').' : '.$object->thirdparty->name.'

'; + } + + $message_admin .= '

'.$langs->trans('Message').' :
'.$object->message.'

'; + $message_admin .= '

'.$langs->trans('SeeThisTicketIntomanagementInterface').'

'; + + $from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.'>'; + $replyto = $from; + + $message_admin = dol_nl2br($message_admin); + + $trackid = 'tic'.$object->id; + + if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { + $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; + $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; + } + include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $mailfile = new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1); + if ($mailfile->error) { + dol_syslog($mailfile->error, LOG_DEBUG); + } else { + $result = $mailfile->sendfile(); + } + if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { + $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; + } + } + } + + // Send email to customer + + if (empty($conf->global->TICKET_DISABLE_CUSTOMER_MAILS) && empty($object->context['disableticketemail']) && $object->notify_tiers_at_create) + { + $sendto = ''; + if (empty($user->socid) && empty($user->email)) { + $object->fetch_thirdparty(); + $sendto = $object->thirdparty->email; + } else { + $sendto = $user->email; + } if ($sendto) { // Init to avoid errors @@ -141,39 +264,44 @@ $filename = array(); $mimetype = array(); - /* Send email to admin */ - $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectAdmin'); - $message_admin = $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id).'

'; - $message_admin .= ''; + $message_customer .= '

'.$langs->trans('Message').' :
'.$object->message.'

'; + $url_public_ticket = ($conf->global->TICKET_URL_PUBLIC_INTERFACE ? $conf->global->TICKET_URL_PUBLIC_INTERFACE.'/' : dol_buildpath('/public/ticket/view.php', 2)).'?track_id='.$object->track_id; + $message_customer .= '

'.$langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer').' : '.$url_public_ticket.'

'; + $message_customer .= '

'.$langs->trans('TicketEmailPleaseDoNotReplyToThisEmail').'

'; $from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.'>'; $replyto = $from; + + $message_customer = dol_nl2br($message_customer); $trackid = 'tic'.$object->id; @@ -182,92 +310,7 @@ $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; } include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, '', '', 0, -1, '', '', $trackid, '', 'ticket'); - if ($mailfile->error) { - dol_syslog($mailfile->error, LOG_DEBUG); - } else { - $result = $mailfile->sendfile(); - } - if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { - $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; - } - } - } - - // Send email to customer - - if (empty($conf->global->TICKET_DISABLE_CUSTOMER_MAILS) && empty($object->context['disableticketemail']) && $object->notify_tiers_at_create) { - $sendto = ''; - - //if contact selected send to email's contact else send to email's thirdparty - - $contactid = GETPOST('contactid', 'alpha'); - - if (!empty($contactid)) { - $contact = new Contact($this->db); - $res = $contact->fetch($contactid); - } - - if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) { - $sendto = $contact->email; - } elseif (!empty($object->fk_soc)) { - $object->fetch_thirdparty(); - $sendto = $object->thirdparty->email; - } - - if ($sendto) { - // Init to avoid errors - $filepath = array(); - $filename = array(); - $mimetype = array(); - - $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectCustomer'); - $message_customer = $langs->transnoentities('TicketNewEmailBodyCustomer', $object->track_id).'

'; - $message_customer .= ''; - - $message = $object->message; - if (!dol_textishtml($message)) { - $message = dol_nl2br($message); - } - $message_customer .= '

'.$langs->trans('Message').' :
'.$message.'

'; - $url_public_ticket = ($conf->global->TICKET_URL_PUBLIC_INTERFACE ? $conf->global->TICKET_URL_PUBLIC_INTERFACE.'/' : dol_buildpath('/public/ticket/view.php', 2)).'?track_id='.$object->track_id; - $message_customer .= '

'.$langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer').' : '.$url_public_ticket.'

'; - $message_customer .= '

'.$langs->trans('TicketEmailPleaseDoNotReplyToThisEmail').'

'; - - $from = (empty($conf->global->MAIN_INFO_SOCIETE_NOM) ? '' : $conf->global->MAIN_INFO_SOCIETE_NOM.' ').'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.'>'; - $replyto = $from; - - $trackid = 'tic'.$object->id; - - if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { - $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; - $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; - } - include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($subject, $sendto, $from, $message_customer, $filepath, $mimetype, $filename, '', '', 0, -1, '', '', $trackid, '', 'ticket'); + $mailfile = new CMailFile($subject, $sendto, $from, $message_customer, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1, '', '', $trackid); if ($mailfile->error) { dol_syslog($mailfile->error, LOG_DEBUG); } else { --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_interface_80_modStripe_Stripe.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_80_modStripe_Stripe.class.php @@ -35,20 +35,46 @@ */ class InterfaceStripe extends DolibarrTriggers { + /** + * @var DoliDB Database handler. + */ + public $db; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + + $this->name = preg_replace('/^Interface/i', '', get_class($this)); + $this->family = 'stripe'; + $this->description = "Triggers of the module Stripe"; + $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version + $this->picto = 'stripe'; + } + /** - * Constructor + * Trigger name * - * @param DoliDB $db Database handler + * @return string Name of trigger file */ - public function __construct($db) + public function getName() { - $this->db = $db; - - $this->name = preg_replace('/^Interface/i', '', get_class($this)); - $this->family = 'stripe'; - $this->description = "Triggers of the module Stripe"; - $this->version = self::VERSION_DOLIBARR; // 'development', 'experimental', 'dolibarr' or version - $this->picto = 'stripe'; + return $this->name; + } + + + /** + * Trigger description + * + * @return string Description of trigger file + */ + public function getDesc() + { + return $this->description; } /** @@ -78,7 +104,8 @@ $service = 'StripeTest'; $servicestatus = 0; - if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) { + if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) + { $service = 'StripeLive'; $servicestatus = 1; } @@ -91,7 +118,8 @@ if ($object->client != 0) { $customer = $stripe->customerStripe($object, $stripeacc, $servicestatus); // This make a network request - if ($customer) { + if ($customer) + { $namecleaned = $object->name ? $object->name : null; $vatcleaned = $object->tva_intra ? $object->tva_intra : null; // Example of valid numbers are 'FR12345678901' or 'FR12345678902' $desccleaned = $object->name_alias ? $object->name_alias : null; @@ -119,13 +147,15 @@ if ($desccleaned != $customer->description) $changerequested++; if (($customer->tax_exempt == 'exempt' && !$object->tva_assuj) || (!$customer->tax_exempt == 'exempt' && empty($object->tva_assuj))) $changerequested++; if (!isset($customer->tax_ids['data']) && !is_null($vatcleaned)) $changerequested++; - elseif (isset($customer->tax_ids['data'])) { + elseif (isset($customer->tax_ids['data'])) + { $taxinfo = reset($customer->tax_ids['data']); if (empty($taxinfo) && !empty($vatcleaned)) $changerequested++; if (isset($taxinfo->value) && $vatcleaned != $taxinfo->value) $changerequested++; } - if ($changerequested) { + if ($changerequested) + { /*if (! empty($object->email)) $customer->email = $object->email; $customer->description = $namecleaned; if (empty($taxinfo)) $customer->tax_info = array('type'=>'vat', 'tax_id'=>null); @@ -137,17 +167,24 @@ try { // Update Tax info on Stripe - if (!empty($conf->global->STRIPE_SAVE_TAX_IDS)) { // We setup to save Tax info on Stripe side. Warning: This may result in error when saving customer - if (!empty($vatcleaned)) { + if (!empty($conf->global->STRIPE_SAVE_TAX_IDS)) // We setup to save Tax info on Stripe side. Warning: This may result in error when saving customer + { + if (!empty($vatcleaned)) + { $isineec = isInEEC($object); - if ($object->country_code && $isineec) { + if ($object->country_code && $isineec) + { //$taxids = $customer->allTaxIds($customer->id); $customer->createTaxId($customer->id, array('type'=>'eu_vat', 'value'=>$vatcleaned)); } - } else { + } + else + { $taxids = $customer->allTaxIds($customer->id); - if (is_array($taxids->data)) { - foreach ($taxids->data as $taxidobj) { + if (is_array($taxids->data)) + { + foreach ($taxids->data as $taxidobj) + { $customer->deleteTaxId($customer->id, $taxidobj->id); } } @@ -156,8 +193,10 @@ // Update Customer on Stripe $customer->save(); - } catch (Exception $e) { - //var_dump(\Stripe\Stripe::getApiVersion()); + } + catch (Exception $e) + { + //var_dump(\Stripe\Stripe::getApiVersion()); $this->errors[] = $e->getMessage(); $ok = -1; } @@ -168,17 +207,17 @@ if ($action == 'COMPANY_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->STRIPE_DELETE_STRIPE_ACCOUNT_WHEN_DELETING_THIRPARTY)) { - // By default, we do not delete the stripe account. We may need to reuse it with its payment_intent, for example if delete is for a merge of thirdparties. - $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. - - $customer = $stripe->customerStripe($object, $stripeacc, $servicestatus); - if ($customer) { - try { - $customer->delete(); - } catch (Exception $e) { - dol_syslog("Failed to delete Stripe customer ".$e->getMessage(), LOG_WARNING); - } + $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. + + $customer = $stripe->customerStripe($object, $stripeacc, $servicestatus); + if ($customer) + { + try { + $customer->delete(); + } + catch (Exception $e) + { + dol_syslog("Failed to delete Stripe customer ".$e->getMessage(), LOG_WARNING); } } @@ -194,11 +233,13 @@ if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object->type == 'card') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($object->stripe_card_ref)) { + if (!empty($object->stripe_card_ref)) + { $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. $stripecu = $stripe->getStripeCustomerAccount($object->fk_soc); // No need of network access for this - if ($stripecu) { + if ($stripecu) + { // Get customer (required to get a card) if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage $customer = \Stripe\Customer::retrieve($stripecu); @@ -206,13 +247,16 @@ $customer = \Stripe\Customer::retrieve($stripecu, array("stripe_account" => $stripeacc)); } - if ($customer) { + if ($customer) + { $card = $stripe->cardStripe($customer, $object, $stripeacc, $servicestatus); if ($card) { $card->metadata = array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR']) ? '' : $_SERVER['REMOTE_ADDR'])); try { $card->save(); - } catch (Exception $e) { + } + catch (Exception $e) + { $ok = -1; $this->error = $e->getMessages(); } @@ -224,11 +268,13 @@ if ($action == 'COMPANYPAYMENTMODE_DELETE' && $object->type == 'card') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($object->stripe_card_ref)) { + if (!empty($object->stripe_card_ref)) + { $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. $stripecu = $stripe->getStripeCustomerAccount($object->fk_soc); // No need of network access for this - if ($stripecu) { + if ($stripecu) + { // Get customer (required to get a card) if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage $customer = \Stripe\Customer::retrieve($stripecu); @@ -236,7 +282,8 @@ $customer = \Stripe\Customer::retrieve($stripecu, array("stripe_account" => $stripeacc)); } - if ($customer) { + if ($customer) + { $card = $stripe->cardStripe($customer, $object, $stripeacc, $servicestatus); if ($card) { if (method_exists($card, 'detach')) $card->detach(); --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_interface_90_modSociete_ContactRoles.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_90_modSociete_ContactRoles.class.php @@ -33,22 +33,23 @@ */ class InterfaceContactRoles extends DolibarrTriggers { + + public $family = 'agenda'; + + public $description = "Triggers of this module auto link contact to company."; + /** - * Constructor + * Version of the trigger * - * @param DoliDB $db Database handler + * @var string */ - public function __construct($db) - { - $this->db = $db; + public $version = self::VERSION_DOLIBARR; - $this->name = preg_replace('/^Interface/i', '', get_class($this)); - $this->family = "agenda"; - $this->description = "Triggers of this module auto link contact to company."; - // 'development', 'experimental', 'dolibarr' or version - $this->version = self::VERSION_DOLIBARR; - $this->picto = 'company'; - } + /** + * + * @var string Image of the trigger + */ + public $picto = 'action'; /** * Function called when a Dolibarrr business event is done. --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_interface_99_modZapier_ZapierTriggers.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_99_modZapier_ZapierTriggers.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2017-2019 Frédéric France * * 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 @@ -39,343 +39,335 @@ */ class InterfaceZapierTriggers extends DolibarrTriggers { - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - public function __construct($db) - { - $this->db = $db; - - $this->name = preg_replace('/^Interface/i', '', get_class($this)); - $this->family = "technic"; - $this->description = "Zapier triggers."; - // 'development', 'experimental', 'dolibarr' or version - $this->version = self::VERSION_DEVELOPMENT; - $this->picto = 'zapier'; - } - - /** - * Function called when a Dolibarrr business event is done. - * All functions "runTrigger" are triggered if file - * is inside directory core/triggers - * - * @param string $action Event action code - * @param CommonObject $object Object - * @param User $user Object user - * @param Translate $langs Object langs - * @param Conf $conf Object conf - * @return int <0 if KO, 0 if no triggered ran, >0 if OK - */ - public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) - { - if (empty($conf->zapier->enabled)) { - // Module not active, we do nothing - return 0; - } - $logtriggeraction = false; - $sql = ''; - if ($action != '') { - $actions = explode('_', $action); - $sql = 'SELECT rowid, url FROM '.MAIN_DB_PREFIX.'zapier_hook'; - $sql .= ' WHERE module="'.$this->db->escape(strtolower($actions[0])).'" AND action="'.$this->db->escape(strtolower($actions[1])).'"'; - //setEventMessages($sql, null); - } - - switch ($action) { - // Users - case 'USER_CREATE': - $resql = $this->db->query($sql); - // TODO voir comment regrouper les webhooks en un post - while ($resql && $obj = $this->db->fetch_array($resql)) { - $cleaned = cleanObjectDatas(dol_clone($object)); - $json = json_encode($cleaned); - // call the zapierPostWebhook() function - zapierPostWebhook($obj['url'], $json); - } - $logtriggeraction = true; - break; - case 'USER_MODIFY': - $resql = $this->db->query($sql); - // TODO voir comment regrouper les webhooks en un post - while ($resql && $obj = $this->db->fetch_array($resql)) { - $cleaned = cleanObjectDatas(dol_clone($object)); - $json = json_encode($cleaned); - // call the zapierPostWebhook() function - zapierPostWebhook($obj['url'], $json); - } - $logtriggeraction = true; - break; - //case 'USER_NEW_PASSWORD': - //case 'USER_ENABLEDISABLE': - //case 'USER_DELETE': - //case 'USER_SETINGROUP': - //case 'USER_REMOVEFROMGROUP': - // case 'USER_LOGIN': - // case 'USER_LOGIN_FAILED': - // case 'USER_LOGOUT': - // Warning: To increase performances, this action is triggered only if constant MAIN_ACTIVATE_UPDATESESSIONTRIGGER is set to 1. - // // case 'USER_UPDATE_SESSION': - - // Actions - case 'ACTION_MODIFY': - //$logtriggeraction = true; - break; - case 'ACTION_CREATE': - $resql = $this->db->query($sql); - // TODO voir comment regrouper les webhooks en un post - while ($resql && $obj = $this->db->fetch_array($resql)) { - $cleaned = cleanObjectDatas(dol_clone($object)); - $cleaned = cleanAgendaEventsDatas($cleaned); - $json = json_encode($cleaned); - // call the zapierPostWebhook() function - zapierPostWebhook($obj['url'], $json); - //setEventMessages($obj['url'], null); - } - $logtriggeraction = true; - break; - case 'ACTION_DELETE': - //$logtriggeraction = true; - break; - - // Groups - //case 'USERGROUP_CREATE': - //case 'USERGROUP_MODIFY': - //case 'USERGROUP_DELETE': - - // Categories - // case 'CATEGORY_CREATE': - // case 'CATEGORY_MODIFY': - // case 'CATEGORY_DELETE': - // case 'CATEGORY_SET_MULTILANGS': - - // Companies - case 'COMPANY_CREATE': - $resql = $this->db->query($sql); - while ($resql && $obj = $this->db->fetch_array($resql)) { - $cleaned = cleanObjectDatas(dol_clone($object)); - $json = json_encode($cleaned); - // call the zapierPostWebhook() function - zapierPostWebhook($obj['url'], $json); - } - $logtriggeraction = true; - break; - case 'COMPANY_MODIFY': - $resql = $this->db->query($sql); - while ($resql && $obj = $this->db->fetch_array($resql)) { - $cleaned = cleanObjectDatas(dol_clone($object)); - $json = json_encode($cleaned); - // call the zapierPostWebhook() function - zapierPostWebhook($obj['url'], $json); - } - $logtriggeraction = true; - break; - case 'COMPANY_DELETE': - //$logtriggeraction = true; - break; - - // Contacts - case 'CONTACT_CREATE': - case 'CONTACT_MODIFY': - case 'CONTACT_DELETE': - case 'CONTACT_ENABLEDISABLE': - break; - // Products - // case 'PRODUCT_CREATE': - // case 'PRODUCT_MODIFY': - // case 'PRODUCT_DELETE': - // case 'PRODUCT_PRICE_MODIFY': - // case 'PRODUCT_SET_MULTILANGS': - // case 'PRODUCT_DEL_MULTILANGS': - - //Stock mouvement - // case 'STOCK_MOVEMENT': - - //MYECMDIR - // case 'MYECMDIR_DELETE': - // case 'MYECMDIR_CREATE': - // case 'MYECMDIR_MODIFY': - - // Customer orders - case 'ORDER_CREATE': - $resql = $this->db->query($sql); - while ($resql && $obj = $this->db->fetch_array($resql)) { - $cleaned = cleanObjectDatas(dol_clone($object)); - $json = json_encode($cleaned); - // call the zapierPostWebhook() function - zapierPostWebhook($obj['url'], $json); - } - $logtriggeraction = true; - break; - case 'ORDER_CLONE': - break; - case 'ORDER_VALIDATE': - break; - case 'ORDER_DELETE': - case 'ORDER_CANCEL': - case 'ORDER_SENTBYMAIL': - case 'ORDER_CLASSIFY_BILLED': - case 'ORDER_SETDRAFT': - case 'LINEORDER_INSERT': - case 'LINEORDER_UPDATE': - case 'LINEORDER_DELETE': - break; - // Supplier orders - // case 'ORDER_SUPPLIER_CREATE': - // case 'ORDER_SUPPLIER_CLONE': - // case 'ORDER_SUPPLIER_VALIDATE': - // case 'ORDER_SUPPLIER_DELETE': - // case 'ORDER_SUPPLIER_APPROVE': - // case 'ORDER_SUPPLIER_REFUSE': - // case 'ORDER_SUPPLIER_CANCEL': - // case 'ORDER_SUPPLIER_SENTBYMAIL': - // case 'ORDER_SUPPLIER_DISPATCH': - // case 'LINEORDER_SUPPLIER_DISPATCH': - // case 'LINEORDER_SUPPLIER_CREATE': - // case 'LINEORDER_SUPPLIER_UPDATE': - - // Proposals - // case 'PROPAL_CREATE': - // case 'PROPAL_CLONE': - // case 'PROPAL_MODIFY': - // case 'PROPAL_VALIDATE': - // case 'PROPAL_SENTBYMAIL': - // case 'PROPAL_CLOSE_SIGNED': - // case 'PROPAL_CLOSE_REFUSED': - // case 'PROPAL_DELETE': - // case 'LINEPROPAL_INSERT': - // case 'LINEPROPAL_UPDATE': - // case 'LINEPROPAL_DELETE': - - // SupplierProposal - // case 'SUPPLIER_PROPOSAL_CREATE': - // case 'SUPPLIER_PROPOSAL_CLONE': - // case 'SUPPLIER_PROPOSAL_MODIFY': - // case 'SUPPLIER_PROPOSAL_VALIDATE': - // case 'SUPPLIER_PROPOSAL_SENTBYMAIL': - // case 'SUPPLIER_PROPOSAL_CLOSE_SIGNED': - // case 'SUPPLIER_PROPOSAL_CLOSE_REFUSED': - // case 'SUPPLIER_PROPOSAL_DELETE': - // case 'LINESUPPLIER_PROPOSAL_INSERT': - // case 'LINESUPPLIER_PROPOSAL_UPDATE': - // case 'LINESUPPLIER_PROPOSAL_DELETE': - - // Contracts - // case 'CONTRACT_CREATE': - // case 'CONTRACT_ACTIVATE': - // case 'CONTRACT_CANCEL': - // case 'CONTRACT_CLOSE': - // case 'CONTRACT_DELETE': - // case 'LINECONTRACT_INSERT': - // case 'LINECONTRACT_UPDATE': - // case 'LINECONTRACT_DELETE': - - // Bills - // case 'BILL_CREATE': - // case 'BILL_CLONE': - // case 'BILL_MODIFY': - // case 'BILL_VALIDATE': - // case 'BILL_UNVALIDATE': - // case 'BILL_SENTBYMAIL': - // case 'BILL_CANCEL': - // case 'BILL_DELETE': - // case 'BILL_PAYED': - // case 'LINEBILL_INSERT': - // case 'LINEBILL_UPDATE': - // case 'LINEBILL_DELETE': - - //Supplier Bill - // case 'BILL_SUPPLIER_CREATE': - // case 'BILL_SUPPLIER_UPDATE': - // case 'BILL_SUPPLIER_DELETE': - // case 'BILL_SUPPLIER_PAYED': - // case 'BILL_SUPPLIER_UNPAYED': - // case 'BILL_SUPPLIER_VALIDATE': - // case 'BILL_SUPPLIER_UNVALIDATE': - // case 'LINEBILL_SUPPLIER_CREATE': - // case 'LINEBILL_SUPPLIER_UPDATE': - // case 'LINEBILL_SUPPLIER_DELETE': - - // Payments - // case 'PAYMENT_CUSTOMER_CREATE': - // case 'PAYMENT_SUPPLIER_CREATE': - // case 'PAYMENT_ADD_TO_BANK': - // case 'PAYMENT_DELETE': - - // Online - // case 'PAYMENT_PAYBOX_OK': - // case 'PAYMENT_PAYPAL_OK': - // case 'PAYMENT_STRIPE_OK': - - // Donation - // case 'DON_CREATE': - // case 'DON_UPDATE': - // case 'DON_DELETE': - - // Interventions - // case 'FICHINTER_CREATE': - // case 'FICHINTER_MODIFY': - // case 'FICHINTER_VALIDATE': - // case 'FICHINTER_DELETE': - // case 'LINEFICHINTER_CREATE': - // case 'LINEFICHINTER_UPDATE': - // case 'LINEFICHINTER_DELETE': - - // Members - // case 'MEMBER_CREATE': - // case 'MEMBER_VALIDATE': - // case 'MEMBER_SUBSCRIPTION': - // case 'MEMBER_MODIFY': - // case 'MEMBER_NEW_PASSWORD': - // case 'MEMBER_RESILIATE': - // case 'MEMBER_DELETE': - - // Projects - // case 'PROJECT_CREATE': - // case 'PROJECT_MODIFY': - // case 'PROJECT_DELETE': - - // Project tasks - // case 'TASK_CREATE': - // case 'TASK_MODIFY': - // case 'TASK_DELETE': - - // Task time spent - // case 'TASK_TIMESPENT_CREATE': - // case 'TASK_TIMESPENT_MODIFY': - // case 'TASK_TIMESPENT_DELETE': - case 'TICKET_CREATE': - $resql = $this->db->query($sql); - // TODO voir comment regrouper les webhooks en un post - while ($resql && $obj = $this->db->fetch_array($resql)) { - $cleaned = cleanObjectDatas(dol_clone($object)); - $json = json_encode($cleaned); - // call the zapierPostWebhook() function - zapierPostWebhook($obj['url'], $json); - } - $logtriggeraction = true; - break; - // case 'TICKET_MODIFY': - // break; - // case 'TICKET_DELETE': - // break; - - // Shipping - // case 'SHIPPING_CREATE': - // case 'SHIPPING_MODIFY': - // case 'SHIPPING_VALIDATE': - // case 'SHIPPING_SENTBYMAIL': - // case 'SHIPPING_BILLED': - // case 'SHIPPING_CLOSED': - // case 'SHIPPING_REOPEN': - // case 'SHIPPING_DELETE': - } - if ($logtriggeraction) { - dol_syslog("Trigger '".$this->name."' for action '.$action.' launched by ".__FILE__." id=".$object->id); - } - return 0; - } + /** + * @var DoliDB Database handler + */ + protected $db; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + + $this->name = preg_replace('/^Interface/i', '', get_class($this)); + $this->family = "technic"; + $this->description = "Zapier triggers."; + // 'development', 'experimental', 'dolibarr' or version + $this->version = 'development'; + $this->picto = 'zapier'; + } + + /** + * Trigger name + * + * @return string Name of trigger file + */ + public function getName() + { + return $this->name; + } + + /** + * Trigger description + * + * @return string Description of trigger file + */ + public function getDesc() + { + return $this->description; + } + + + /** + * Function called when a Dolibarrr business event is done. + * All functions "runTrigger" are triggered if file + * is inside directory core/triggers + * + * @param string $action Event action code + * @param CommonObject $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param Conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) + { + global $db; + if (empty($conf->zapier->enabled)) { + // Module not active, we do nothing + return 0; + } + $logtriggeraction = false; + $sql = ''; + if ($action != '') { + $actions = explode('_', $action); + $sql = 'SELECT rowid, url FROM '.MAIN_DB_PREFIX.'zapier_hook'; + $sql .= ' WHERE module="'.$db->escape(strtolower($actions[0])).'" AND action="'.$db->escape(strtolower($actions[1])).'"'; + //setEventMessages($sql, null); + } + + switch ($action) { + // Users + //case 'USER_CREATE': + //case 'USER_MODIFY': + //case 'USER_NEW_PASSWORD': + //case 'USER_ENABLEDISABLE': + //case 'USER_DELETE': + //case 'USER_SETINGROUP': + //case 'USER_REMOVEFROMGROUP': + // case 'USER_LOGIN': + // case 'USER_LOGIN_FAILED': + // case 'USER_LOGOUT': + // Warning: To increase performances, this action is triggered only if constant MAIN_ACTIVATE_UPDATESESSIONTRIGGER is set to 1. + // // case 'USER_UPDATE_SESSION': + + // Actions + case 'ACTION_MODIFY': + //$logtriggeraction = true; + break; + case 'ACTION_CREATE': + $resql = $db->query($sql); + // TODO voir comment regrouper les webhooks en un post + while ($resql && $obj = $db->fetch_array($resql)) { + $cleaned = cleanObjectDatas(dol_clone($object)); + $cleaned = cleanAgendaEventsDatas($cleaned); + $json = json_encode($cleaned); + // call the zapierPostWebhook() function + zapierPostWebhook($obj['url'], $json); + //setEventMessages($obj['url'], null); + } + $logtriggeraction = true; + break; + case 'ACTION_DELETE': + //$logtriggeraction = true; + break; + + // Groups + //case 'USERGROUP_CREATE': + //case 'USERGROUP_MODIFY': + //case 'USERGROUP_DELETE': + + // Companies + case 'COMPANY_CREATE': + $resql = $db->query($sql); + while ($resql && $obj = $db->fetch_array($resql)) { + $cleaned = cleanObjectDatas(dol_clone($object)); + $json = json_encode($cleaned); + // call the zapierPostWebhook() function + zapierPostWebhook($obj['url'], $json); + } + $logtriggeraction = true; + break; + case 'COMPANY_MODIFY': + $resql = $db->query($sql); + while ($resql && $obj = $db->fetch_array($resql)) { + $cleaned = cleanObjectDatas(dol_clone($object)); + $json = json_encode($cleaned); + // call the zapierPostWebhook() function + zapierPostWebhook($obj['url'], $json); + } + $logtriggeraction = true; + break; + case 'COMPANY_DELETE': + //$logtriggeraction = true; + break; + + // Contacts + case 'CONTACT_CREATE': + case 'CONTACT_MODIFY': + case 'CONTACT_DELETE': + case 'CONTACT_ENABLEDISABLE': + break; + // Products + // case 'PRODUCT_CREATE': + // case 'PRODUCT_MODIFY': + // case 'PRODUCT_DELETE': + // case 'PRODUCT_PRICE_MODIFY': + // case 'PRODUCT_SET_MULTILANGS': + // case 'PRODUCT_DEL_MULTILANGS': + + //Stock mouvement + // case 'STOCK_MOVEMENT': + + //MYECMDIR + // case 'MYECMDIR_DELETE': + // case 'MYECMDIR_CREATE': + // case 'MYECMDIR_MODIFY': + + // Customer orders + case 'ORDER_CREATE': + $resql = $db->query($sql); + while ($resql && $obj = $db->fetch_array($resql)) { + $cleaned = cleanObjectDatas(dol_clone($object)); + $json = json_encode($cleaned); + // call the zapierPostWebhook() function + zapierPostWebhook($obj['url'], $json); + } + $logtriggeraction = true; + break; + case 'ORDER_CLONE': + break; + case 'ORDER_VALIDATE': + break; + case 'ORDER_DELETE': + case 'ORDER_CANCEL': + case 'ORDER_SENTBYMAIL': + case 'ORDER_CLASSIFY_BILLED': + case 'ORDER_SETDRAFT': + case 'LINEORDER_INSERT': + case 'LINEORDER_UPDATE': + case 'LINEORDER_DELETE': + break; + // Supplier orders + // case 'ORDER_SUPPLIER_CREATE': + // case 'ORDER_SUPPLIER_CLONE': + // case 'ORDER_SUPPLIER_VALIDATE': + // case 'ORDER_SUPPLIER_DELETE': + // case 'ORDER_SUPPLIER_APPROVE': + // case 'ORDER_SUPPLIER_REFUSE': + // case 'ORDER_SUPPLIER_CANCEL': + // case 'ORDER_SUPPLIER_SENTBYMAIL': + // case 'ORDER_SUPPLIER_DISPATCH': + // case 'LINEORDER_SUPPLIER_DISPATCH': + // case 'LINEORDER_SUPPLIER_CREATE': + // case 'LINEORDER_SUPPLIER_UPDATE': + + // Proposals + // case 'PROPAL_CREATE': + // case 'PROPAL_CLONE': + // case 'PROPAL_MODIFY': + // case 'PROPAL_VALIDATE': + // case 'PROPAL_SENTBYMAIL': + // case 'PROPAL_CLOSE_SIGNED': + // case 'PROPAL_CLOSE_REFUSED': + // case 'PROPAL_DELETE': + // case 'LINEPROPAL_INSERT': + // case 'LINEPROPAL_UPDATE': + // case 'LINEPROPAL_DELETE': + + // SupplierProposal + // case 'SUPPLIER_PROPOSAL_CREATE': + // case 'SUPPLIER_PROPOSAL_CLONE': + // case 'SUPPLIER_PROPOSAL_MODIFY': + // case 'SUPPLIER_PROPOSAL_VALIDATE': + // case 'SUPPLIER_PROPOSAL_SENTBYMAIL': + // case 'SUPPLIER_PROPOSAL_CLOSE_SIGNED': + // case 'SUPPLIER_PROPOSAL_CLOSE_REFUSED': + // case 'SUPPLIER_PROPOSAL_DELETE': + // case 'LINESUPPLIER_PROPOSAL_INSERT': + // case 'LINESUPPLIER_PROPOSAL_UPDATE': + // case 'LINESUPPLIER_PROPOSAL_DELETE': + + // Contracts + // case 'CONTRACT_CREATE': + // case 'CONTRACT_ACTIVATE': + // case 'CONTRACT_CANCEL': + // case 'CONTRACT_CLOSE': + // case 'CONTRACT_DELETE': + // case 'LINECONTRACT_INSERT': + // case 'LINECONTRACT_UPDATE': + // case 'LINECONTRACT_DELETE': + + // Bills + // case 'BILL_CREATE': + // case 'BILL_CLONE': + // case 'BILL_MODIFY': + // case 'BILL_VALIDATE': + // case 'BILL_UNVALIDATE': + // case 'BILL_SENTBYMAIL': + // case 'BILL_CANCEL': + // case 'BILL_DELETE': + // case 'BILL_PAYED': + // case 'LINEBILL_INSERT': + // case 'LINEBILL_UPDATE': + // case 'LINEBILL_DELETE': + + //Supplier Bill + // case 'BILL_SUPPLIER_CREATE': + // case 'BILL_SUPPLIER_UPDATE': + // case 'BILL_SUPPLIER_DELETE': + // case 'BILL_SUPPLIER_PAYED': + // case 'BILL_SUPPLIER_UNPAYED': + // case 'BILL_SUPPLIER_VALIDATE': + // case 'BILL_SUPPLIER_UNVALIDATE': + // case 'LINEBILL_SUPPLIER_CREATE': + // case 'LINEBILL_SUPPLIER_UPDATE': + // case 'LINEBILL_SUPPLIER_DELETE': + + // Payments + // case 'PAYMENT_CUSTOMER_CREATE': + // case 'PAYMENT_SUPPLIER_CREATE': + // case 'PAYMENT_ADD_TO_BANK': + // case 'PAYMENT_DELETE': + + // Online + // case 'PAYMENT_PAYBOX_OK': + // case 'PAYMENT_PAYPAL_OK': + // case 'PAYMENT_STRIPE_OK': + + // Donation + // case 'DON_CREATE': + // case 'DON_UPDATE': + // case 'DON_DELETE': + + // Interventions + // case 'FICHINTER_CREATE': + // case 'FICHINTER_MODIFY': + // case 'FICHINTER_VALIDATE': + // case 'FICHINTER_DELETE': + // case 'LINEFICHINTER_CREATE': + // case 'LINEFICHINTER_UPDATE': + // case 'LINEFICHINTER_DELETE': + + // Members + // case 'MEMBER_CREATE': + // case 'MEMBER_VALIDATE': + // case 'MEMBER_SUBSCRIPTION': + // case 'MEMBER_MODIFY': + // case 'MEMBER_NEW_PASSWORD': + // case 'MEMBER_RESILIATE': + // case 'MEMBER_DELETE': + + // Categories + // case 'CATEGORY_CREATE': + // case 'CATEGORY_MODIFY': + // case 'CATEGORY_DELETE': + // case 'CATEGORY_SET_MULTILANGS': + + // Projects + // case 'PROJECT_CREATE': + // case 'PROJECT_MODIFY': + // case 'PROJECT_DELETE': + + // Project tasks + // case 'TASK_CREATE': + // case 'TASK_MODIFY': + // case 'TASK_DELETE': + + // Task time spent + // case 'TASK_TIMESPENT_CREATE': + // case 'TASK_TIMESPENT_MODIFY': + // case 'TASK_TIMESPENT_DELETE': + + // Shipping + // case 'SHIPPING_CREATE': + // case 'SHIPPING_MODIFY': + // case 'SHIPPING_VALIDATE': + // case 'SHIPPING_SENTBYMAIL': + // case 'SHIPPING_BILLED': + // case 'SHIPPING_CLOSED': + // case 'SHIPPING_REOPEN': + // case 'SHIPPING_DELETE': + } + if ($logtriggeraction) { + dol_syslog("Trigger '".$this->name."' for action '.$action.' launched by ".__FILE__." id=".$object->id); + } + return 0; + } } /** * Post webhook in zapier with object data @@ -386,153 +378,153 @@ */ function zapierPostWebhook($url, $json) { - $headers = array('Accept: application/json', 'Content-Type: application/json'); - // TODO supprimer le webhook en cas de mauvaise réponse - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $json); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - $output = curl_exec($ch); - curl_close($ch); + $headers = array('Accept: application/json', 'Content-Type: application/json'); + // TODO supprimer le webhook en cas de mauvaise réponse + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $json); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + $output = curl_exec($ch); + curl_close($ch); } /** * Clean sensible object datas * - * @param Object $toclean Object to clean - * @return Object Object with cleaned properties + * @param object $toclean Object to clean + * @return array Array of cleaned object properties */ function cleanObjectDatas($toclean) { - // Remove $db object property for object - unset($toclean->db); - - // Remove linkedObjects. We should already have linkedObjectsIds that avoid huge responses - unset($toclean->linkedObjects); - - unset($toclean->lines); // should be ->lines - - unset($toclean->fields); - - unset($toclean->oldline); - - unset($toclean->error); - unset($toclean->errors); - - unset($toclean->ref_previous); - unset($toclean->ref_next); - unset($toclean->ref_int); - - unset($toclean->projet); // Should be fk_project - unset($toclean->project); // Should be fk_project - unset($toclean->author); // Should be fk_user_author - unset($toclean->timespent_old_duration); - unset($toclean->timespent_id); - unset($toclean->timespent_duration); - unset($toclean->timespent_date); - unset($toclean->timespent_datehour); - unset($toclean->timespent_withhour); - unset($toclean->timespent_fk_user); - unset($toclean->timespent_note); - - unset($toclean->statuts); - unset($toclean->statuts_short); - unset($toclean->statuts_logo); - unset($toclean->statuts_long); - - unset($toclean->element); - unset($toclean->fk_element); - unset($toclean->table_element); - unset($toclean->table_element_line); - unset($toclean->picto); - - unset($toclean->skip_update_total); - unset($toclean->context); - - // Remove the $oldcopy property because it is not supported by the JSON - // encoder. The following error is generated when trying to serialize - // it: "Error encoding/decoding JSON: Type is not supported" - // Note: Event if this property was correctly handled by the JSON - // encoder, it should be ignored because keeping it would let the API - // have a very strange behavior: calling PUT and then GET on the same - // resource would give different results: - // PUT /objects/{id} -> returns object with oldcopy = previous version of the object - // GET /objects/{id} -> returns object with oldcopy empty - unset($toclean->oldcopy); - - // If object has lines, remove $db property - if (isset($toclean->lines) && count($toclean->lines) > 0) { - $nboflines = count($toclean->lines); - for ($i = 0; $i < $nboflines; $i++) { - cleanObjectDatas($toclean->lines[$i]); - } - } - - // If object has linked objects, remove $db property - /* - if(isset($toclean->linkedObjects) && count($toclean->linkedObjects) > 0) { - foreach($toclean->linkedObjects as $type_object => $linked_object) { - foreach($linked_object as $toclean2clean) { - $this->cleanObjectDatas($toclean2clean); - } - } - }*/ - - return $toclean; + // Remove $db object property for object + unset($toclean->db); + + // Remove linkedObjects. We should already have linkedObjectIds that avoid huge responses + unset($toclean->linkedObjects); + + unset($toclean->lines); // should be ->lines + + unset($toclean->fields); + + unset($toclean->oldline); + + unset($toclean->error); + unset($toclean->errors); + + unset($toclean->ref_previous); + unset($toclean->ref_next); + unset($toclean->ref_int); + + unset($toclean->projet); // Should be fk_project + unset($toclean->project); // Should be fk_project + unset($toclean->author); // Should be fk_user_author + unset($toclean->timespent_old_duration); + unset($toclean->timespent_id); + unset($toclean->timespent_duration); + unset($toclean->timespent_date); + unset($toclean->timespent_datehour); + unset($toclean->timespent_withhour); + unset($toclean->timespent_fk_user); + unset($toclean->timespent_note); + + unset($toclean->statuts); + unset($toclean->statuts_short); + unset($toclean->statuts_logo); + unset($toclean->statuts_long); + + unset($toclean->element); + unset($toclean->fk_element); + unset($toclean->table_element); + unset($toclean->table_element_line); + unset($toclean->picto); + + unset($toclean->skip_update_total); + unset($toclean->context); + + // Remove the $oldcopy property because it is not supported by the JSON + // encoder. The following error is generated when trying to serialize + // it: "Error encoding/decoding JSON: Type is not supported" + // Note: Event if this property was correctly handled by the JSON + // encoder, it should be ignored because keeping it would let the API + // have a very strange behavior: calling PUT and then GET on the same + // resource would give different results: + // PUT /objects/{id} -> returns object with oldcopy = previous version of the object + // GET /objects/{id} -> returns object with oldcopy empty + unset($toclean->oldcopy); + + // If object has lines, remove $db property + if (isset($toclean->lines) && count($toclean->lines) > 0) { + $nboflines = count($toclean->lines); + for ($i = 0; $i < $nboflines; $i++) { + cleanObjectDatas($toclean->lines[$i]); + } + } + + // If object has linked objects, remove $db property + /* + if(isset($toclean->linkedObjects) && count($toclean->linkedObjects) > 0) { + foreach($toclean->linkedObjects as $type_object => $linked_object) { + foreach($linked_object as $toclean2clean) { + $this->cleanObjectDatas($toclean2clean); + } + } + }*/ + + return $toclean; } /** * Clean sensible object datas * - * @param Object $toclean Object to clean - * @return Object Object with cleaned properties + * @param object $toclean Object to clean + * @return array Array of cleaned object properties */ function cleanAgendaEventsDatas($toclean) { - unset($toclean->usermod); - unset($toclean->libelle); - //unset($toclean->array_options); - unset($toclean->context); - unset($toclean->canvas); - unset($toclean->contact); - unset($toclean->contact_id); - unset($toclean->thirdparty); - unset($toclean->user); - unset($toclean->origin); - unset($toclean->origin_id); - unset($toclean->ref_ext); - unset($toclean->statut); - unset($toclean->country); - unset($toclean->country_id); - unset($toclean->country_code); - unset($toclean->barcode_type); - unset($toclean->barcode_type_code); - unset($toclean->barcode_type_label); - unset($toclean->barcode_type_coder); - unset($toclean->mode_reglement_id); - unset($toclean->cond_reglement_id); - unset($toclean->cond_reglement); - unset($toclean->fk_delivery_address); - unset($toclean->shipping_method_id); - unset($toclean->fk_account); - unset($toclean->total_ht); - unset($toclean->total_tva); - unset($toclean->total_localtax1); - unset($toclean->total_localtax2); - unset($toclean->total_ttc); - unset($toclean->fk_incoterms); - unset($toclean->libelle_incoterms); - unset($toclean->location_incoterms); - unset($toclean->name); - unset($toclean->lastname); - unset($toclean->firstname); - unset($toclean->civility_id); - unset($toclean->contact); - unset($toclean->societe); - - return $toclean; + unset($toclean->usermod); + unset($toclean->libelle); + //unset($toclean->array_options); + unset($toclean->context); + unset($toclean->canvas); + unset($toclean->contact); + unset($toclean->contact_id); + unset($toclean->thirdparty); + unset($toclean->user); + unset($toclean->origin); + unset($toclean->origin_id); + unset($toclean->ref_ext); + unset($toclean->statut); + unset($toclean->country); + unset($toclean->country_id); + unset($toclean->country_code); + unset($toclean->barcode_type); + unset($toclean->barcode_type_code); + unset($toclean->barcode_type_label); + unset($toclean->barcode_type_coder); + unset($toclean->mode_reglement_id); + unset($toclean->cond_reglement_id); + unset($toclean->cond_reglement); + unset($toclean->fk_delivery_address); + unset($toclean->shipping_method_id); + unset($toclean->fk_account); + unset($toclean->total_ht); + unset($toclean->total_tva); + unset($toclean->total_localtax1); + unset($toclean->total_localtax2); + unset($toclean->total_ttc); + unset($toclean->fk_incoterms); + unset($toclean->libelle_incoterms); + unset($toclean->location_incoterms); + unset($toclean->name); + unset($toclean->lastname); + unset($toclean->firstname); + unset($toclean->civility_id); + unset($toclean->contact); + unset($toclean->societe); + + return $toclean; }