--- /tmp/dsg/dolibarr/htdocs/core/triggers/github_19.0.3_dolibarrtriggers.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_dolibarrtriggers.class.php @@ -22,0 +23 @@ + @@ -73,3 +73,0 @@ - /** - * @var string module is in development - */ @@ -77,4 +74,0 @@ - - /** - * @var string module is experimental - */ @@ -82,4 +75,0 @@ - - /** - * @var string module is dolibarr ready - */ @@ -93,2 +83,3 @@ - public function __construct(DoliDB $db) - { + public function __construct(DoliDB $db) + { + @@ -97 +88,2 @@ - if (empty($this->name)) { + if (empty($this->name)) + { @@ -145,28 +137,12 @@ - /** - * setErrorsFromObject - * - * @param CommonObject $object commonobject - * @return void - */ - public function setErrorsFromObject($object) - { - if (!empty($object->error)) { - $this->errors = array_merge($this->errors, array($object->error)); - } - if (!empty($object->errors)) { - $this->errors = array_merge($this->errors, $object->errors); - } - } - - /** - * 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 Return integer <0 if KO, 0 if no triggered ran, >0 if OK - */ - abstract public 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_19.0.3_interface_20_all_Logevents.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_20_all_Logevents.class.php @@ -5,2 +4,0 @@ - * Copyright (C) 2023 Udo Tamm - * Copyright (C) 2023 William Mead @@ -25 +23 @@ - * \brief Trigger file for log events + * \brief Trigger file for @@ -28,0 +27 @@ + @@ -35,13 +33,0 @@ - const EVENT_ACTION_DICT = array( // TODO reduce number of events to CREATE, UPDATE & DELETE. Use object properties to pinpoint precise action. - 'USER_LOGIN' => 'UserLogged', - 'USER_LOGIN_FAILED' => 'UserLoginFailed', - 'USER_LOGOUT' => 'UserLogoff', - 'USER_CREATE' => 'NewUserCreated', - 'USER_MODIFY' => 'EventUserModified', - 'USER_NEW_PASSWORD' => 'NewUserPassword', - 'USER_ENABLEDISABLE' => 'UserEnabledDisabled', - 'USER_DELETE' => 'UserDeleted', - 'USERGROUP_CREATE' => 'NewGroupCreated', - 'USERGROUP_MODIFY' => 'GroupModified', - 'USERGROUP_DELETE' => 'GroupDeleted' - ); @@ -49 +35 @@ - * @var string Label + * @var string Image of the trigger @@ -51 +37,6 @@ - private $event_label; + public $picto = 'technic'; + + public $family = 'core'; + + public $description = "Triggers of this module allows to add security event records inside Dolibarr."; + @@ -53 +44,2 @@ - * @var string Description + * Version of the trigger + * @var string @@ -55 +47,2 @@ - private $event_desc; + public $version = self::VERSION_DOLIBARR; + @@ -57,24 +50 @@ - * @var int Date - */ - private $event_date; - - - /** - * Constructor - * @param DoliDB $db Database handler - */ - public function __construct(DoliDB $db) - { - parent::__construct($db); - - $this->family = "core"; - $this->description = "Triggers of this module allows to add security event records inside Dolibarr."; - $this->version = self::VERSION_DOLIBARR; // VERSION_ 'DEVELOPMENT' or 'EXPERIMENTAL' or 'DOLIBARR' - $this->picto = 'technic'; - $this->event_label = ''; - $this->event_desc = ''; - $this->event_date = 0; - } - - /** - * Function called when a Dolibarr security audit event is done. + * Function called when a Dolibarrr security audit event is done. @@ -83,7 +53,6 @@ - * @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 if KO: <0, if no trigger ran: 0, if OK: >0 - * @throws Exception dol_syslog can throw Exceptions + * @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 @@ -92,20 +61,131 @@ - { - if (getDolGlobalString('MAIN_LOGEVENTS_DISABLE_ALL')) { - return 0; // Log events is disabled (hidden features) - } - - $key = 'MAIN_LOGEVENTS_'.$action; - if (empty($conf->global->$key)) { - return 0; // Log events not enabled for this action - } - - if (empty($conf->entity)) { - global $entity; - $conf->entity = $entity; // forcing of the entity if it's not defined (ex: in login form) - } - - // Actions - dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); - $this->initEventData(InterfaceLogevents::EVENT_ACTION_DICT[$action], $object); - - // Add entry in event table + { + 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) + { + $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); + } + + // 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."); + return 0; + } + */ + + // 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 @@ -115,59 +195,21 @@ - $event->type = $action; - $event->dateevent = $this->event_date; - $event->label = $this->event_label; - $event->description = $this->event_desc; - $event->user_agent = (empty($_SERVER["HTTP_USER_AGENT"]) ? '' : $_SERVER["HTTP_USER_AGENT"]); - $event->authentication_method = (empty($object->context['authentication_method']) ? '' : $object->context['authentication_method']); - - $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; - } - } - - /** - * Method called by runTrigger to initialize date, label & description data for event - * - * @param string $key_text Action string - * @param Object $object Object - * @return void - */ - private function initEventData($key_text, $object) - { - $this->event_date = dol_now(); - - $this->event_label = $this->event_desc = $key_text; - if (property_exists($object, 'login')) { - $this->event_label .= ' : ' . $object->login; - } - if ($key_text == InterfaceLogevents::EVENT_ACTION_DICT['USER_ENABLEDISABLE']) { // TODO should be refactored using an object property for event data. - $object->statut ? $this->event_desc .= ' - disabled' : $this->event_desc .= ' - enabled'; - } - // Add more information into event description from the context property - if (!empty($object->context['audit'])) { - $this->event_desc .= (empty($this->event_desc) ? '' : ' - ').$object->context['audit']; - } - } - - /** - * Check if text contains an event action key. Used for dynamic localization on frontend events list. - * - * @param string $event_text Input event text - * @return bool True if event text is a coded structured string - */ - public static function isEventActionTextKey($event_text) - { - foreach (InterfaceLogevents::EVENT_ACTION_DICT as $value) { - if (str_contains($event_text, $value)) { - return true; - } - } - return false; - } + $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_19.0.3_interface_20_modWorkflow_WorkflowManager.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_20_modWorkflow_WorkflowManager.class.php @@ -5,2 +4,0 @@ - * Copyright (C) 2022 Ferran Marcet - * Copyright (C) 2023 Alexandre Janniaux @@ -38,3 +36 @@ - * Constructor - * - * @param DoliDB $db Database handler + * @var string Image of the trigger @@ -42,11 +38,10 @@ - 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; @@ -63 +58 @@ - * @return int Return integer <0 if KO, 0 if no triggered ran, >0 if OK + * @return int <0 if KO, 0 if no triggered ran, >0 if OK @@ -66,16 +61,54 @@ - { - if (empty($conf->workflow) || empty($conf->workflow->enabled)) { - return 0; // Module not active, we do nothing - } - - $ret = 0; - - // Proposals to order - if ($action == 'PROPAL_CLOSE_SIGNED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (isModEnabled('commande') && getDolGlobalString('WORKFLOW_PROPAL_AUTOCREATE_ORDER')) { - $object->fetchObjectLinked(); - if (!empty($object->linkedObjectsIds['commande'])) { - if (empty($object->context['closedfromonlinesignature'])) { - $langs->load("orders"); - setEventMessages($langs->trans("OrderExists"), null, 'warnings'); + { + 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; @@ -83,41 +116,7 @@ - return $ret; - } - - 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->setErrorsFromObject($newobject); - } - - $object->clearObjectLinkedCache(); - - return $ret; - } - } - - // Order to invoice - if ($action == 'ORDER_CLOSE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (isModEnabled('facture') && getDolGlobalString('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->setErrorsFromObject($newobject); - } else { - if (empty($object->fk_account) && !empty($object->thirdparty->fk_account) && !getDolGlobalInt('BANK_ASK_PAYMENT_BANK_DURING_ORDER')) { - $res = $newobject->setBankAccount($object->thirdparty->fk_account, true, $user); - if ($ret < 0) { - $this->setErrorsFromObject($newobject); - } + 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); + } @@ -126,5 +125,220 @@ - - $object->clearObjectLinkedCache(); - - 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; + } @@ -133,454 +347,22 @@ - // Order classify billed proposal - if ($action == 'ORDER_CLASSIFY_BILLED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (isModEnabled("propal") && !empty($conf->workflow->enabled) && getDolGlobalString('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); - } - } - } - 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); - - // First classify billed the order to allow the proposal classify process - if (isModEnabled('commande') && !empty($conf->workflow->enabled) && getDolGlobalString('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 (isModEnabled("propal") && !empty($conf->workflow->enabled) && getDolGlobalString('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); - } - } - } - } - - // Set shipment to "Closed" if WORKFLOW_SHIPPING_CLASSIFY_CLOSED_INVOICE is set (deprecated, has been replaced with WORKFLOW_SHIPPING_CLASSIFY_BILLED_INVOICE instead)) - if (isModEnabled("expedition") && !empty($conf->workflow->enabled) && getDolGlobalString('WORKFLOW_SHIPPING_CLASSIFY_CLOSED_INVOICE')) { - $object->fetchObjectLinked('', 'shipping', $object->id, $object->element); - if (!empty($object->linkedObjects)) { - $totalonlinkedelements = 0; - foreach ($object->linkedObjects['shipping'] as $element) { - if ($element->statut == Expedition::STATUS_VALIDATED) { - $totalonlinkedelements += $element->total_ht; - } - } - dol_syslog("Amount of linked shipment = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht), LOG_DEBUG); - if ($totalonlinkedelements == $object->total_ht) { - foreach ($object->linkedObjects['shipping'] as $element) { - $ret = $element->setClosed(); - if ($ret < 0) { - return $ret; - } - } - } - } - } - - if (isModEnabled("expedition") && !empty($conf->workflow->enabled) && getDolGlobalString('WORKFLOW_SHIPPING_CLASSIFY_BILLED_INVOICE')) { - $object->fetchObjectLinked('', 'shipping', $object->id, $object->element); - if (!empty($object->linkedObjects)) { - $totalonlinkedelements = 0; - foreach ($object->linkedObjects['shipping'] as $element) { - if ($element->statut == Expedition::STATUS_VALIDATED || $element->statut == Expedition::STATUS_CLOSED) { - $totalonlinkedelements += $element->total_ht; - } - } - dol_syslog("Amount of linked shipment = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht), LOG_DEBUG); - if ($totalonlinkedelements == $object->total_ht) { - foreach ($object->linkedObjects['shipping'] as $element) { - $ret = $element->setBilled(); - if ($ret < 0) { - return $ret; - } - } - } - } - } - - return $ret; - } - - // classify billed order & billed proposal - if ($action == 'BILL_SUPPLIER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - // Firstly, we set to purchase order to "Billed" if WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER is set. - // After we will set proposals - if ((isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && getDolGlobalString('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); - if ($ret < 0) { - return $ret; - } - } - } - } - } - - // Secondly, we set to linked Proposal to "Billed" if WORKFLOW_INVOICE_CLASSIFY_BILLED_SUPPLIER_PROPOSAL is set. - if (isModEnabled('supplier_proposal') && getDolGlobalString('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_CLOSE) { - $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); - if ($ret < 0) { - return $ret; - } - } - } - } - } - - // Set reception to "Closed" if WORKFLOW_RECEPTION_CLASSIFY_CLOSED_INVOICE is set (deprecated, WORKFLOW_RECEPTION_CLASSIFY_BILLED_INVOICE instead)) - /* - if (isModEnabled("reception") && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_RECEPTION_CLASSIFY_CLOSED_INVOICE)) { - $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 || $element->statut == Reception::STATUS_CLOSED) { - $totalonlinkedelements += $element->total_ht; - } - } - dol_syslog("Amount of linked reception = ".$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->setClosed(); - if ($ret < 0) { - return $ret; - } - } - } - } - } - */ - - // Then set reception to "Billed" if WORKFLOW_RECEPTION_CLASSIFY_BILLED_INVOICE is set - if (isModEnabled("reception") && !empty($conf->workflow->enabled) && getDolGlobalString('WORKFLOW_RECEPTION_CLASSIFY_BILLED_INVOICE')) { - $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 || $element->statut == Reception::STATUS_CLOSED) { - $totalonlinkedelements += $element->total_ht; - } - } - dol_syslog("Amount of linked reception = ".$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->setBilled(); - if ($ret < 0) { - return $ret; - } - } - } - } - } - - 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 (isModEnabled('commande') && getDolGlobalString('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 we validate or close a shipment - if (($action == 'SHIPPING_VALIDATE') || ($action == 'SHIPPING_CLOSED')) { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - if (isModEnabled('commande') && isModEnabled("expedition") && !empty($conf->workflow->enabled) && - ( - (getDolGlobalString('WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING') && ($action == 'SHIPPING_VALIDATE')) || - (getDolGlobalString('WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING_CLOSED') && ($action == 'SHIPPING_CLOSED')) - ) - ) { - $qtyshipped = array(); - $qtyordred = array(); - require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; - - // Find all shipments on order origin - $order = new Commande($this->db); - $ret = $order->fetch($object->origin_id); - if ($ret < 0) { - $this->setErrorsFromObject($order); - return $ret; - } - $ret = $order->fetchObjectLinked($order->id, 'commande', null, 'shipping'); - if ($ret < 0) { - $this->setErrorsFromObject($order); - 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) { - continue; - } - /** @var Expedition[] $shipping_array */ - foreach ($shipping_array as $shipping) { - if ($shipping->status <= 0 || !is_array($shipping->lines) || count($shipping->lines) == 0) { - continue; - } - - foreach ($shipping->lines as $shippingline) { - $qtyshipped[$shippingline->fk_product] += $shippingline->qty; - } - } - } - } - - //Build array of quantity ordered to be shipped - if (is_array($order->lines) && count($order->lines) > 0) { - foreach ($order->lines as $orderline) { - // Exclude lines not qualified for shipment, similar code is found into calcAndSetStatusDispatch() for vendors - if (!getDolGlobalString('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 = $order->setStatut(Commande::STATUS_CLOSED, $object->origin_id, $object->origin, 'ORDER_CLOSE'); - if ($ret < 0) { - $this->setErrorsFromObject($order); - return $ret; - } - } - } - } - - // If we validate or close a shipment - if (($action == 'RECEPTION_VALIDATE') || ($action == 'RECEPTION_CLOSED')) { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - if ((isModEnabled("fournisseur") || isModEnabled("supplier_order")) && isModEnabled("reception") && !empty($conf->workflow->enabled) && - ( - (getDolGlobalString('WORKFLOW_ORDER_CLASSIFY_RECEIVED_RECEPTION') && ($action == 'RECEPTION_VALIDATE')) || - (getDolGlobalString('WORKFLOW_ORDER_CLASSIFY_RECEIVED_RECEPTION_CLOSED') && ($action == 'RECEPTION_CLOSED')) - ) - ) { - $qtyshipped = array(); - $qtyordred = array(); - require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; - - // Find all reception on purchase order origin - $order = new CommandeFournisseur($this->db); - $ret = $order->fetch($object->origin_id); - if ($ret < 0) { - $this->setErrorsFromObject($order); - return $ret; - } - $ret = $order->fetchObjectLinked($order->id, $order->element, null, 'reception'); - if ($ret < 0) { - $this->setErrorsFromObject($order); - return $ret; - } - //Build array of quantity received by product for a purchase order - if (is_array($order->linkedObjects) && count($order->linkedObjects) > 0) { - foreach ($order->linkedObjects as $type => $shipping_array) { - if ($type != 'reception' || !is_array($shipping_array) || count($shipping_array) == 0) { - continue; - } - - foreach ($shipping_array as $shipping) { - if (!is_array($shipping->lines) || count($shipping->lines) == 0) { - continue; - } - - foreach ($shipping->lines as $shippingline) { - $qtyshipped[$shippingline->fk_product] += $shippingline->qty; - } - } - } - } - - //Build array of quantity ordered to be received - if (is_array($order->lines) && count($order->lines) > 0) { - foreach ($order->lines as $orderline) { - // Exclude lines not qualified for shipment, similar code is found into calcAndSetStatusDispatch() for vendors - if (!getDolGlobalString('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 received - $ret = $order->setStatut(CommandeFournisseur::STATUS_RECEIVED_COMPLETELY, null, null, 'SUPPLIER_ORDER_CLOSE'); - if ($ret < 0) { - $this->setErrorsFromObject($order); - return $ret; - } - } - } - } - - if ($action == 'TICKET_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - // Auto link contract - if (!empty($conf->contract->enabled) && isModEnabled('ticket') && isModEnabled('ficheinter') && !empty($conf->workflow->enabled) && getDolGlobalString('WORKFLOW_TICKET_LINK_CONTRACT') && getDolGlobalString('TICKET_PRODUCT_CATEGORY') && !empty($object->fk_soc)) { - $societe = new Societe($this->db); - $company_ids = (!getDolGlobalString('WORKFLOW_TICKET_USE_PARENT_COMPANY_CONTRACTS')) ? [$object->fk_soc] : $societe->getParentsForCompany($object->fk_soc, [$object->fk_soc]); - - $contrat = new Contrat($this->db); - $number_contracts_found = 0; - foreach ($company_ids as $company_id) { - $contrat->socid = $company_id; - $list = $contrat->getListOfContracts($option = 'all', $status = [Contrat::STATUS_DRAFT, Contrat::STATUS_VALIDATED], $product_categories = [$conf->global->TICKET_PRODUCT_CATEGORY], $line_status = [ContratLigne::STATUS_INITIAL, ContratLigne::STATUS_OPEN]); - if (!is_array($list) || empty($list)) { - continue; - } - $number_contracts_found = count($list); - if ($number_contracts_found == 0) { - continue; - } - - foreach ($list as $linked_contract) { - $object->setContract($linked_contract->id); - // don't set '$contractid' so it is not used when creating an intervention. - } - - if ($number_contracts_found > 1 && !defined('NOLOGIN')) { - setEventMessage($langs->trans('TicketManyContractsLinked'), 'warnings'); - } - break; - } - if ($number_contracts_found == 0) { - if (empty(NOLOGIN)) { - setEventMessage($langs->trans('TicketNoContractFoundToLink'), 'mesgs'); - } - } - } - // Automatically create intervention - if (isModEnabled('ficheinter') && isModEnabled('ticket') && !empty($conf->workflow->enabled) && getDolGlobalString('WORKFLOW_TICKET_CREATE_INTERVENTION')) { - $fichinter = new Fichinter($this->db); - $fichinter->socid = (int) $object->fk_soc; - $fichinter->fk_project = (int) $object->fk_project; - $fichinter->fk_contrat = (int) $object->fk_contract; - $fichinter->author = $user->id; - $fichinter->model_pdf = (getDolGlobalString('FICHEINTER_ADDON_PDF')) ? $conf->global->FICHEINTER_ADDON_PDF : 'soleil'; - $fichinter->origin = $object->element; - $fichinter->origin_id = $object->id; - - // Extrafields - $extrafields = new ExtraFields($this->db); - $extrafields->fetch_name_optionals_label($fichinter->table_element); - $array_options = $extrafields->getOptionalsFromPost($fichinter->table_element); - $fichinter->array_options = $array_options; - - $id = $fichinter->create($user); - if ($id <= 0) { - setEventMessages($fichinter->error, null, 'errors'); - } - } - } - 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 (getDolGlobalString('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_19.0.3_interface_50_modAgenda_ActionsAuto.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_50_modAgenda_ActionsAuto.class.php @@ -8,3 +7,0 @@ - * Copyright (C) 2022 Ferran Marcet - * Copyright (C) 2023 William Mead - * Copyright (C) 2023 Christian Foellmann @@ -39,0 +37,3 @@ + public $family = 'agenda'; + public $description = "Triggers of this module add actions in agenda according to setup made in agenda setup."; + @@ -41,3 +41,2 @@ - * Constructor - * - * @param DoliDB $db Database handler + * Version of the trigger + * @var string @@ -45,11 +44,6 @@ - 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'; @@ -65 +59 @@ - * $object->sendtoid (id of contact or array of ids of contacts) + * $object->sendtoid (id of contact or array of ids) @@ -68,3 +62,2 @@ - * $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 @@ -72 +65 @@ - * @param string $action Event action code ('CONTRACT_MODIFY', 'RECRUITMENTCANDIDATURE_MODIFIY', or example by external module: 'SENTBYSMS'...) + * @param string $action Event action code @@ -77 +70 @@ - * @return int Return integer <0 if KO, 0 if no triggered ran, >0 if OK + * @return int <0 if KO, 0 if no triggered ran, >0 if OK @@ -81,6 +74,6 @@ - if (!isModEnabled('agenda')) { - 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)) { + if (empty($conf->agenda->enabled)) return 0; // Module not active, we do nothing + + $key = 'MAIN_AGENDA_ACTIONAUTO_'.$action; + + // Do not log events not enabled for this action + if (empty($conf->global->$key)) { @@ -90,9 +82,0 @@ - $key = 'MAIN_AGENDA_ACTIONAUTO_'.$action; - //var_dump($action.' - '.$key.' - '.$conf->global->$key);exit; - - // Do not log events not enabled for this action - // GUI allow to set this option only if entry exists into table llx_c_action_trigger - if (!getDolGlobalString($key)) { - return 0; - } - @@ -101,3 +85 @@ - if (empty($object->actiontypecode)) { - $object->actiontypecode = 'AC_OTH_AUTO'; - } + if (empty($object->actiontypecode)) $object->actiontypecode = 'AC_OTH_AUTO'; @@ -106 +88,34 @@ - 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') + { @@ -108,47 +123,6 @@ - $langs->loadLangs(array("agenda", "other", "companies")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("NewCompanyToDolibarr", $object->name); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("NewCompanyToDolibarr", $object->name); - } - - $object->sendtoid = 0; - $object->socid = $object->id; - } elseif ($action == 'COMPANY_MODIFY') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "companies")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("COMPANY_MODIFYInDolibarr", $object->name); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("COMPANY_MODIFYInDolibarr", $object->name); - } - - // For merge event, we add a mention - if (!empty($object->context['mergefromname'])) { - $object->actionmsg = dol_concatdesc($object->actionmsg, $langs->trans("DataFromWasMerged", $object->context['mergefromname'].' (id='.$object->context['mergefromname'].')')); - } - - $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)) { - if (empty($object->context['actionmsg2'])) { - dol_syslog('Trigger called with property actionmsg2 and context[actionmsg2] on object not defined', LOG_ERR); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } + $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); @@ -159 +133,305 @@ - } 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') + { @@ -161,16 +439,9 @@ - $langs->loadLangs(array("agenda", "other", "companies")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("CONTACT_CREATEInDolibarr", $object->getFullName($langs)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("CONTACT_CREATEInDolibarr", $object->getFullName($langs)); - } - - $object->sendtoid = array($object->id => $object->id); - $object->socid = $object->socid; - } elseif ($action == 'CONTACT_MODIFY') { + $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') + { @@ -178,44 +449,6 @@ - $langs->loadLangs(array("agenda", "other", "companies")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("CONTACT_MODIFYInDolibarr", $object->name); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("CONTACT_MODIFYInDolibarr", $object->name); - } - - $object->sendtoid = array($object->id => $object->id); - $object->socid = $object->socid; - } elseif ($action == 'CONTRACT_VALIDATE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "contracts")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("ContractValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("ContractSentByEMail", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - 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); @@ -226 +459,3 @@ - } elseif ($action == 'PROPAL_VALIDATE') { + } + elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_SIGNED') + { @@ -228,8 +463,395 @@ - $langs->loadLangs(array("agenda", "other", "propal")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } + $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")); + + 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")); + + 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 + { + 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; + } + + // Project tasks + 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")); + + 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")); + + 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"); + } + 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); @@ -237,1265 +859,30 @@ - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - } - - $object->sendtoid = 0; - } elseif ($action == 'PROPAL_MODIFY') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "propal")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("PropalBackToDraftInDolibarr", ($object->newref ? $object->newref : $object->ref)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("PropalBackToDraftInDolibarr", ($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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - 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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("PropalClassifiedBilledInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("OrderDeliveredInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("OrderBilledInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("OrderSentByEMail", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - 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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InvoiceSentByEMail", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - 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. - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InterventionCreatedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InterventionValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InterventionModifiedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InterventionSentByEMail", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - 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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InterventionClassifiedBilledInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref); - } - - $object->sendtoid = 0; - } elseif ($action == 'FICHINTER_CLOSE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "interventions")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InterventionClosedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("InterventionClosedInDolibarr", $object->ref); - } - - $object->sendtoid = 0; - $object->fk_element = 0; - $object->elementtype = ''; - } elseif ($action == 'FICHINTER_DELETE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "interventions")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InterventionDeletedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("ShippingValidated", ($object->newref ? $object->newref : $object->ref)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - 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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("ShippingSentByEMail", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - 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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("ReceptionValidated", ($object->newref ? $object->newref : $object->ref)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - 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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("ReceptionSentByEMail", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - 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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - 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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("OrderCreatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("OrderApprovedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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", "main")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("OrderRefusedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("OrderRefusedInDolibarr", $object->ref); - } - - if (!empty($object->refuse_note)) { - $object->actionmsg .= '
'; - $object->actionmsg .= $langs->trans("Reason") . ': '.$object->refuse_note; - } - - $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_CANCEL') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "orders", "main")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref); - } - - if (!empty($object->cancel_note)) { - $object->actionmsg .= '
'; - $object->actionmsg .= $langs->trans("Reason") . ': '.$object->cancel_note; - } - - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - } - - if (!empty($object->context['comments'])) { - $object->actionmsg .= '
'; - $object->actionmsg .= $langs->trans("Comment") . ': '.$object->context['comments']; - } - - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - 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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - 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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - 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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref); - } - - $object->sendtoid = 0; - } elseif ($action == 'MEMBER_VALIDATE') { - // Members - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "members")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("MemberValidatedInDolibarr", $object->getFullName($langs)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("MemberModifiedInDolibarr", $object->getFullName($langs)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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 = (isset($object->context['member']) ? $object->context['member'] : null); - 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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->id, $member->getFullName($langs)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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 (isset($object->fk_soc) && $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 = $object->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($object->fk_adherent); - } - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionModifiedInDolibarr", $object->id, $member->getFullName($langs)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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 (isset($object->fk_soc) && $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")); - - $member = $object->context['member']; - if (!is_object($member)) { // This should not happen but it happen when deleting a subscription from adherents/subscription/card.php - 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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $member->getFullName($langs)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $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 (isset($object->fk_soc) && $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("MemberResiliatedInDolibarr", $object->getFullName($langs)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("MemberDeletedInDolibarr", $object->getFullName($langs)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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; - } elseif ($action == 'MEMBER_EXCLUDE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "members")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("MemberExcludedInDolibarr", $object->getFullName($langs)); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("MemberExcludedInDolibarr", $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 == 'PROJECT_CREATE') { - // Projects - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "projects")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref); - } - - //$object->actionmsg .= "\n".$langs->transnoentities("Task").': ???'; - if (!empty($object->usage_opportunity) && is_object($object->oldcopy) && $object->opp_status != $object->oldcopy->opp_status) { - $object->actionmsg .= "\n".$langs->transnoentitiesnoconv("OpportunityStatus").': '.$object->oldcopy->opp_status.' -> '.$object->opp_status; - } - - $object->sendtoid = 0; - } elseif ($action == 'PROJECT_SENTBYMAIL') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "projects")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("ProjectSentByEMail", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("ProjectSentByEMail", $object->ref); - } - - // Parameters $object->sendtoid defined by caller - //$object->sendtoid=0; - } elseif ($action == 'PROJECT_DELETE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "projects")); - - if (empty($object->actionmsg2)) { - $object->actionmsg2 = $langs->transnoentities("ProjectDeletedInDolibarr", $object->ref); - } - $object->actionmsg = $langs->transnoentities("ProjectDeletedInDolibarr", $object->ref); - - $object->sendtoid = 0; - } elseif ($action == 'PROJECT_CLOSE') { - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "projects")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("ProjectClosedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $object->actionmsg = $langs->transnoentities("ProjectClosedInDolibarr", $object->ref); - } - - $object->sendtoid = 0; - } elseif ($action == 'TASK_CREATE') { - // Project tasks - // Load translation files required by the page - $langs->loadLangs(array("agenda", "other", "projects")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("TaskModifiedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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")); - - if (empty($object->actionmsg2)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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)) { - if (empty($object->context['actionmsg2'])) { - $object->actionmsg2 = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref); - } else { - $object->actionmsg2 = $object->context['actionmsg2']; - } - } - if (empty($object->actionmsg)) { - $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; - } else { - // TODO Merge all previous cases into this generic one - // $action = PASSWORD, BILL_DELETE, TICKET_CREATE, TICKET_MODIFY, TICKET_DELETE, CONTACT_SENTBYMAIL, RECRUITMENTCANDIDATURE_MODIFY, ... - // Can also be a value defined by an external module like SENTBYSMS, COMPANY_SENTBYSMS, MEMBER_SENTBYSMS, ... - // 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 llx_c_action_trigger - if (!empty($object->context['actionmsg']) && empty($object->actionmsg)) { // For description - $object->actionmsg = $object->context['actionmsg']; - } - if (!empty($object->context['actionmsg2']) && empty($object->actionmsg2)) { // For label - $object->actionmsg2 = $object->context['actionmsg2']; - } - - if (empty($object->actionmsg2)) { - // Load translation files required by the page - $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)) { - // Load translation files required by the page - $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 (isModEnabled('multicompany') && property_exists($object, 'entity') && $object->entity > 1) { - $object->actionmsg .= ' ('.$langs->trans("Entity").' '.$object->entity.')'; - } - } - - if (!isset($object->sendtoid) || !is_array($object->sendtoid)) { - $object->sendtoid = 0; - } - } - - // If trackid is not defined, we set it. - // Note that it should be set by caller. This is for compatibility purpose only. - 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('/^PARTNERSHIP_/', $action)) { - $object->trackid = 'pship'.$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; - } elseif (preg_match('/^USER_/', $action)) { - $object->trackid = 'use'.$object->id; - } else { - $object->trackid = ''; - } - } - - 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); - } - } - - $societeforactionid = 0; - $contactforactionid = 0; - - // Set $contactforactionid - if (is_array($object->sendtoid)) { - if (count($object->sendtoid) == 1) { - $contactforactionid = reset($object->sendtoid); - } - } else { - if ($object->sendtoid > 0) { - $contactforactionid = $object->sendtoid; - } - } - // Set $societeforactionid - if (isset($object->socid) && $object->socid > 0) { - $societeforactionid = $object->socid; - } elseif (isset($object->fk_soc) && $object->fk_soc > 0) { - $societeforactionid = $object->fk_soc; - } elseif (isset($object->thirdparty) && isset($object->thirdparty->id) && $object->thirdparty->id > 0) { - $societeforactionid = $object->thirdparty->id; - } - - $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; + } + + 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 ($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; @@ -1508,2 +895,2 @@ - $actioncomm->label = $object->actionmsg2; // Label of event - $actioncomm->note_private = $object->actionmsg; // Description + $actioncomm->label = $object->actionmsg2; + $actioncomm->note_private = $object->actionmsg; // TODO Replace with ($actioncomm->email_msgid ? $object->email_content : $object->actionmsg) @@ -1515,2 +902,2 @@ - $actioncomm->socid = $societeforactionid; - $actioncomm->contact_id = $contactforactionid; // deprecated, now managed by setting $actioncomm->socpeopleassigned later + $actioncomm->socid = $societeforaction->id; + $actioncomm->contactid = $contactforaction->id; @@ -1519,15 +906,14 @@ - // Fields defined when action is an email (content should be into object->actionmsg to be added into event note, subject should be into object->actionms2 to be added into event label) - if (!property_exists($object, 'email_fields_no_propagate_in_actioncomm') || empty($object->email_fields_no_propagate_in_actioncomm)) { - $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; - } - - // Object linked (if link is for thirdparty, contact or 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'))) { + // 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. + if (!in_array($elementtype, array('societe', 'contact', 'project'))) + { @@ -1535 +921 @@ - $actioncomm->elementtype = $elementtype.($elementmodule ? '@'.$elementmodule : ''); + $actioncomm->elementtype = $elementtype; @@ -1544,5 +929,0 @@ - if (property_exists($object, 'sendtoid') && is_array($object->sendtoid) && count($object->sendtoid) > 0) { - foreach ($object->sendtoid as $val) { - $actioncomm->socpeopleassigned[$val] = $val; - } - } @@ -1552,3 +933,4 @@ - if ($ret > 0 && getDolGlobalString('MAIN_COPY_FILE_IN_EVENT_AUTO')) { - if (property_exists($object, 'attachedfiles') && is_array($object->attachedfiles) && array_key_exists('paths', $object->attachedfiles) && count($object->attachedfiles['paths']) > 0) { - foreach ($object->attachedfiles['paths'] as $key => $filespath) { + 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) { @@ -1566,8 +948,4 @@ - // Reset value set by caller - unset($object->context['actionmsg']); - unset($object->context['actionmsg2']); - 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) { + 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) + { @@ -1576,8 +954,10 @@ - } 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_19.0.3_interface_50_modBlockedlog_ActionsBlockedLog.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_50_modBlockedlog_ActionsBlockedLog.class.php @@ -32,0 +33,3 @@ + public $family = 'system'; + public $description = "Triggers of this module add action for BlockedLog module (Module of unalterable logs)."; + @@ -34,3 +37,2 @@ - * Constructor - * - * @param DoliDB $db Database handler + * Version of the trigger + * @var string @@ -38,3 +40 @@ - public function __construct($db) - { - $this->db = $db; + public $version = self::VERSION_DOLIBARR; @@ -42,7 +42,4 @@ - $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'; @@ -58 +55 @@ - * @return int Return integer <0 if KO, 0 if no triggered ran, >0 if OK + * @return int <0 if KO, 0 if no triggered ran, >0 if OK @@ -62,3 +59 @@ - if (empty($conf->blockedlog) || empty($conf->blockedlog->enabled)) { - return 0; // Module not active, we do nothing - } + if (empty($conf->blockedlog->enabled)) return 0; // Module not active, we do nothing @@ -67,7 +62,2 @@ - if (!getDolGlobalString('BLOCKEDLOG_ADD_ACTIONS_SUPPORTED') || !in_array($action, explode(',', getDolGlobalString('BLOCKEDLOG_ADD_ACTIONS_SUPPORTED')))) { - // If custom actions are not set or if action not into custom actions, we can exclude action if object->elementis not valid - $listofqualifiedelement = array('facture', 'don', 'payment', 'payment_donation', 'subscription', 'payment_various', 'cashcontrol'); - if (!is_object($object) || !property_exists($object, 'element') || !in_array($object->element, $listofqualifiedelement)) { - return 1; - } - } + $listofqualifiedelement = array('facture', 'don', 'payment', 'payment_donation', 'subscription', 'payment_various', 'cashcontrol'); + if (!in_array($object->element, $listofqualifiedelement)) return 1; @@ -75 +65 @@ - dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$object->id); + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); @@ -79 +68,0 @@ - $b->loadTrackedEvents(); @@ -82 +71,2 @@ - if (!in_array($action, array_keys($b->trackedevents))) { + if (!in_array($action, array_keys($b->trackedevents))) + { @@ -90,8 +80,8 @@ - || $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) - || (getDolGlobalString('BLOCKEDLOG_ADD_ACTIONS_SUPPORTED') && in_array($action, explode(',', getDolGlobalString('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) + ) + { @@ -102,6 +92,4 @@ - 'DON_VALIDATE', 'DON_MODIFY', 'DON_DELETE'))) { - $amounts = (float) $object->amount; - } elseif ($action == 'CASHCONTROL_VALIDATE') { - $amounts = (float) $object->cash + (float) $object->cheque + (float) $object->card; - } elseif (property_exists($object, 'total_ttc')) { - $amounts = (float) $object->total_ttc; + 'DON_VALIDATE', 'DON_MODIFY', 'DON_DELETE'))) $amounts = (double) $object->amount; + elseif ($action == 'CASHCONTROL_VALIDATE') + { + $amounts = (double) $object->cash + (double) $object->cheque + (double) $object->card; @@ -108,0 +97 @@ + else $amounts = (double) $object->total_ttc; @@ -117 +106,2 @@ - || $action === 'PAYMENT_CUSTOMER_DELETE' || $action === 'PAYMENT_SUPPLIER_DELETE' || $action === 'DONATION_PAYMENT_DELETE') { + || $action === 'PAYMENT_CUSTOMER_DELETE' || $action === 'PAYMENT_SUPPLIER_DELETE' || $action === 'DONATION_PAYMENT_DELETE') + { @@ -122 +112 @@ - $amounts += (float) $amount; + $amounts += price2num($amount); @@ -124,2 +113,0 @@ - } elseif (!empty($object->amount)) { - $amounts = $object->amount; @@ -127 +115,3 @@ - } 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'))) + { @@ -129 +119 @@ - $amounts = (float) $object->amount; + $amounts = (double) $object->amount; @@ -134 +124,2 @@ - if (!$qualified) { + if (!$qualified) + { @@ -138,3 +129 @@ - // Set field date_object, ref_object, fk_object, element, object_data - $result = $b->setObjectData($object, $action, $amounts, $user); - //var_dump($b); exit; + $result = $b->setObjectData($object, $action, $amounts, $user); // Set field date_object, ref_object, fk_object, element, object_data @@ -142 +131,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -150 +140,2 @@ - if ($res < 0) { + if ($res < 0) + { @@ -154 +145,3 @@ - } else { + } + else + { @@ -157 +150 @@ - } + } --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_19.0.3_interface_50_modLdap_Ldapsynchro.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_50_modLdap_Ldapsynchro.class.php @@ -3 +3 @@ - * Copyright (C) 2005-2021 Regis Houssin + * Copyright (C) 2005-2017 Regis Houssin @@ -33,0 +34,3 @@ + public $family = 'ldap'; + public $description = "Triggers of this module allows to synchronize Dolibarr toward a LDAP database."; + @@ -35,3 +38,2 @@ - * Constructor - * - * @param DoliDB $db Database handler + * Version of the trigger + * @var string @@ -39,11 +41,6 @@ - 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'; @@ -60 +57 @@ - * @return int Return integer <0 if KO, 0 if no triggered ran, >0 if OK + * @return int <0 if KO, 0 if no triggered ran, >0 if OK @@ -64,8 +61,5 @@ - if (empty($conf->ldap) || 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 (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')) + { @@ -82,14 +76,12 @@ - if ($action == 'USER_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (getDolGlobalString('LDAP_SYNCHRO_ACTIVE') && getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { - $info = $object->_load_ldap_info(); - $dn = $object->_load_ldap_dn($info); - - //For compatibility with Samba 4 AD - if ($ldap->serverType == "activedirectory") { - $info['userAccountControl'] = $conf->global->LDAP_USERACCOUNTCONTROL; - } + 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); @@ -100,12 +92,15 @@ - 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 (getDolGlobalString('LDAP_SYNCHRO_ACTIVE') && getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) { + 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)) + { @@ -123 +118,2 @@ - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { @@ -133,5 +129,80 @@ - - if ($result > 0 && !empty($object->context['newgroupid'])) { // We are in context of adding a new group to user - $usergroup = new UserGroup($this->db); - - $usergroup->fetch($object->context['newgroupid'], '', true); + } + + 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)) + { + 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; + } + + $oldinfo = $object->oldcopy->_load_ldap_info(); + $olddn = $object->oldcopy->_load_ldap_dn($oldinfo); + + // Verify if entry exist + $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) + { + $olddn = ''; + } + + $info = $object->_load_ldap_info(); + $dn = $object->_load_ldap_dn($info); + + $result = $ldap->update($dn, $info, $user, $olddn); + } + + 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) + { + $info = $object->_load_ldap_info(); + $dn = $object->_load_ldap_dn($info); + + $result = $ldap->delete($dn); + } + + 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) + { + // Must edit $object->newgroupid + $usergroup = new UserGroup($this->db); + if ($object->newgroupid > 0) + { + $usergroup->fetch($object->newgroupid); @@ -146 +217,2 @@ - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { @@ -155,5 +227,20 @@ - - if ($result > 0 && !empty($object->context['oldgroupid'])) { // We are in context of removing a group from user - $usergroup = new UserGroup($this->db); - - $usergroup->fetch($object->context['oldgroupid'], '', true); + } + + 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) + { + // Must edit $object->newgroupid + $usergroup = new UserGroup($this->db); + if ($object->oldgroupid > 0) + { + $usergroup->fetch($object->oldgroupid); @@ -164 +251 @@ - // Verify if an entry exists + // Verify if entry exist @@ -168 +255,2 @@ - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { @@ -172 +260 @@ - $info = $usergroup->_load_ldap_info(); // Contains all members, except the old one (remove already done before trigger call) + $info = $usergroup->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) @@ -179,12 +267,41 @@ - 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 (getDolGlobalString('LDAP_SYNCHRO_ACTIVE') && getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) { + if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; + } + } + + // 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) + { + $info = $object->_load_ldap_info(); + $dn = $object->_load_ldap_dn($info); + + // Get a gid number for objectclass PosixGroup + if (in_array('posixGroup', $info['objectclass'])) { + $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS'); + } + + $result = $ldap->add($dn, $info, $user); + } + + 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)) + { @@ -202 +319,2 @@ - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { @@ -212,40 +330,13 @@ - 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); - if (getDolGlobalInt("LDAP_SYNCHRO_ACTIVE") === Ldap::SYNCHRO_DOLIBARR_TO_LDAP && getDolGlobalString('LDAP_SERVER_TYPE') == "activedirectory") { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - if ($result > 0) { - $info = $object->_load_ldap_info(); - $dn = $object->_load_ldap_dn($info); - $search = "(" . $object->_load_ldap_dn($info, 2) . ")"; - $uAC = $ldap->getAttributeValues($search, "userAccountControl"); - if ($uAC["count"] == 1) { - $userAccountControl = intval($uAC[0]); - $enabledBitMask = 0x2; - $isEnabled = ($userAccountControl & $enabledBitMask) === 0; - if ($isEnabled && intval($object->statut) === 1) { - $userAccountControl += 2; - } elseif (!$isEnabled && intval($object->statut) === 0) { - $userAccountControl -= 2; - } - $info['userAccountControl'] = $userAccountControl; - $resUpdate = $ldap->update($dn, $info, $user, $dn); - if ($resUpdate < 0) { - $this->error = "ErrorLDAP " . $ldap->error; - } - } - } else { - $this->error = "ErrorLDAP " . $ldap->error; - } - } - } elseif ($action == 'USER_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (getDolGlobalString('LDAP_SYNCHRO_ACTIVE') && getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + 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) + { @@ -258,24 +349,17 @@ - if ($result < 0) { - $this->error = "ErrorLDAP ".$ldap->error; - } - } - } elseif ($action == 'USERGROUP_CREATE') { - // Groupes - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (getDolGlobalString('LDAP_SYNCHRO_ACTIVE') && getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { - $info = $object->_load_ldap_info(); - $dn = $object->_load_ldap_dn($info); - - // Get a gid number for objectclass PosixGroup if none was provided - if (empty($info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')]) && in_array('posixGroup', $info['objectclass'])) { - $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS'); - } - - // Avoid Ldap error due to empty member - if (isset($info['member']) && empty($info['member'])) { - unset($info['member']); - } + if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; + } + } + + // 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) + { + $info = $object->_load_ldap_info(); + $dn = $object->_load_ldap_dn($info); @@ -286,16 +370,15 @@ - if ($ldap->serverType == "activedirectory") { - $info['sAMAccountName'] = $object->name; - } - - 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 (getDolGlobalString('LDAP_SYNCHRO_ACTIVE') && getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) { + 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)) + { @@ -313 +396,2 @@ - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { @@ -323,11 +407,13 @@ - 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 (getDolGlobalString('LDAP_SYNCHRO_ACTIVE') && getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + 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) + { @@ -340,12 +426,15 @@ - if ($result < 0) { - $this->error = "ErrorLDAP ".$ldap->error; - } - } - } elseif ($action == 'CONTACT_CREATE') { - // Contacts - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (getDolGlobalString('LDAP_CONTACT_ACTIVE')) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; + } + } + + // 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) + { @@ -356,14 +445,98 @@ - } - - 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 (getDolGlobalString('LDAP_CONTACT_ACTIVE')) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) { + + // For member type + 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); + $membertype->listMembersForMemberType('', 1); + + $oldinfo = $membertype->_load_ldap_info(); + $olddn = $membertype->_load_ldap_dn($oldinfo); + + // Verify if entry exist + $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) + { + $olddn = ''; + } + + $info = $membertype->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) + $dn = $membertype->_load_ldap_dn($info); + + $result = $ldap->update($dn, $info, $user, $olddn); + } + } + } + + 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') + { + // If status field is setup to be synchronized + if (!empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + 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 + + $result = $ldap->update($dn, $info, $user, $olddn); + } + + 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') + { + // 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) + { + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + 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 + + $result = $ldap->update($dn, $info, $user, $olddn); + } + + 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)) + { @@ -381,141 +554,2 @@ - if (count($records) && $records['count'] == 0) { - $olddn = ''; - } - - $info = $object->_load_ldap_info(); - $dn = $object->_load_ldap_dn($info); - - $result = $ldap->update($dn, $info, $user, $olddn); - } - - 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 (getDolGlobalString('LDAP_CONTACT_ACTIVE')) { - $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) { - $this->error = "ErrorLDAP ".$ldap->error; - } - } - } elseif ($action == 'MEMBER_CREATE') { - // Members - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (getDolGlobalString('LDAP_MEMBER_ACTIVE') && getDolGlobalInt('LDAP_MEMBER_ACTIVE') == Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - $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 (getDolGlobalString('LDAP_MEMBER_TYPE_ACTIVE') && getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - if ($object->typeid > 0) { - require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php"; - $membertype = new AdherentType($this->db); - $membertype->fetch($object->typeid); - $membertype->listMembersForMemberType('', 1); - - $oldinfo = $membertype->_load_ldap_info(); - $olddn = $membertype->_load_ldap_dn($oldinfo); - - // Verify if entry exist - $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) { - $olddn = ''; - } - - $info = $membertype->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) - $dn = $membertype->_load_ldap_dn($info); - - $result = $ldap->update($dn, $info, $user, $olddn); - } - } - } - - 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 (getDolGlobalString('LDAP_MEMBER_ACTIVE') && getDolGlobalInt('LDAP_MEMBER_ACTIVE') == Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - // If status field is setup to be synchronized - if (getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - 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 - - $result = $ldap->update($dn, $info, $user, $olddn); - } - - 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 (getDolGlobalString('LDAP_MEMBER_ACTIVE') && getDolGlobalInt('LDAP_MEMBER_ACTIVE') == Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - // If subscriptions fields are setup to be synchronized - if (getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE') - || getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT') - || getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE') - || getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT') - || getDolGlobalString('LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION')) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - 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 - - $result = $ldap->update($dn, $info, $user, $olddn); - } - - 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 (getDolGlobalString('LDAP_MEMBER_ACTIVE') && getDolGlobalInt('LDAP_MEMBER_ACTIVE') == Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - $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; - } - - $oldinfo = $object->oldcopy->_load_ldap_info(); - $olddn = $object->oldcopy->_load_ldap_dn($oldinfo); - - // Verify if entry exist - $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) + { @@ -533 +567,2 @@ - if (getDolGlobalString('LDAP_MEMBER_TYPE_ACTIVE') && getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { + if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') + { @@ -550 +585,2 @@ - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { @@ -559 +595,2 @@ - if ($object->oldcopy->typeid != $object->typeid) { + if ($object->oldcopy->typeid != $object->typeid) + { @@ -574 +611,2 @@ - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { @@ -586 +624,2 @@ - if ($result <= 0) { + if ($result <= 0) + { @@ -590,3 +629,6 @@ - } elseif ($action == 'MEMBER_NEW_PASSWORD') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (getDolGlobalString('LDAP_MEMBER_ACTIVE') && getDolGlobalInt('LDAP_MEMBER_ACTIVE') == Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { + } + 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') + { @@ -594 +636,2 @@ - if (getDolGlobalString('LDAP_FIELD_PASSWORD') || getDolGlobalString('LDAP_FIELD_PASSWORD_CRYPTED')) { + if ($conf->global->LDAP_FIELD_PASSWORD || $conf->global->LDAP_FIELD_PASSWORD_CRYPTED) + { @@ -598 +641,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -606 +650,2 @@ - if ($result <= 0) { + if ($result <= 0) + { @@ -611,3 +656,6 @@ - } elseif ($action == 'MEMBER_RESILIATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (getDolGlobalString('LDAP_MEMBER_ACTIVE') && getDolGlobalInt('LDAP_MEMBER_ACTIVE') == Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { + } + 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') + { @@ -615 +663,2 @@ - if (getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')) { + if (!empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) + { @@ -619 +668,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -627 +677,2 @@ - if ($result <= 0) { + if ($result <= 0) + { @@ -632,7 +683,11 @@ - } elseif ($action == 'MEMBER_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (getDolGlobalString('LDAP_MEMBER_ACTIVE') && getDolGlobalInt('LDAP_MEMBER_ACTIVE') == Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - $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) + { @@ -645,2 +700,4 @@ - if (getDolGlobalString('LDAP_MEMBER_TYPE_ACTIVE') && getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - if ($object->typeid > 0) { + if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') + { + if ($object->typeid > 0) + { @@ -663 +720,2 @@ - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { @@ -675 +733,2 @@ - if ($result <= 0) { + if ($result <= 0) + { @@ -679,8 +738,13 @@ - } elseif ($action == 'MEMBER_TYPE_CREATE') { - // Members types - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (getDolGlobalString('LDAP_MEMBER_TYPE_ACTIVE') && getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - $ldap = new Ldap(); - $result = $ldap->connect_bind(); - - if ($result > 0) { + } + + // 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) + { @@ -698 +762,2 @@ - if ($result <= 0) { + if ($result <= 0) + { @@ -702,8 +767,13 @@ - } elseif ($action == 'MEMBER_TYPE_MODIFY') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (getDolGlobalString('LDAP_MEMBER_TYPE_ACTIVE') && getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - $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)) + { @@ -723 +793,2 @@ - if (count($records) && $records['count'] == 0) { + if (count($records) && $records['count'] == 0) + { @@ -739,7 +810,11 @@ - } elseif ($action == 'MEMBER_TYPE_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (getDolGlobalString('LDAP_MEMBER_TYPE_ACTIVE') && getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) { - $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) + { @@ -752 +827,2 @@ - if ($result <= 0) { + if ($result <= 0) + { --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_19.0.3_interface_50_modMailmanspip_Mailmanspipsynchro.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_50_modMailmanspip_Mailmanspipsynchro.class.php @@ -4,2 +3,0 @@ - * Copyright (C) 2024 MDW - * Copyright (C) 2024 Rafael San José @@ -33,0 +32,3 @@ + public $family = 'mailmanspip'; + public $description = "Triggers of this module allows to synchronize Mailman an Spip."; + @@ -35,3 +36,2 @@ - * Constructor - * - * @param DoliDB $db Database handler + * Version of the trigger + * @var string @@ -39,3 +39 @@ - public function __construct($db) - { - $this->db = $db; + public $version = self::VERSION_DOLIBARR; @@ -43,7 +41,4 @@ - $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'; @@ -60 +55 @@ - * @return int Return integer <0 if KO, 0 if no triggered ran, >0 if OK + * @return int <0 if KO, 0 if no triggered ran, >0 if OK @@ -64,3 +59 @@ - if (empty($conf->mailmanspip) || 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 @@ -68,2 +61,2 @@ - 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"; @@ -71,2 +64,3 @@ - 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); @@ -74,6 +68,9 @@ - // 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 + { @@ -82,0 +80,74 @@ + 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; + } + } + @@ -84,2 +155,4 @@ - } 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); @@ -87,4 +160,6 @@ - // 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; @@ -92 +167,3 @@ - } else { + } + else + { @@ -96,67 +173,2 @@ - return $return; - } elseif ($action == 'MEMBER_VALIDATE') { - // Members - 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 - // $object->oldcopy may be a stdClass and not original object depending on copy type, so we realod a new object to run the del_to_abo() - $tmpmember = new Adherent($this->db); - $tmpmember->fetch($object->oldcopy->id); - if ($tmpmember->del_to_abo() < 0) { - $this->errors = $tmpmember->errors; - if (!empty($tmpmember->error)) { - $this->errors[] = $tmpmember->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; + } @@ -165 +177 @@ - } + } --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_19.0.3_interface_50_modNotification_Notification.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_50_modNotification_Notification.class.php @@ -5 +4,0 @@ - * Copyright (C) 2022 Anthony Berton @@ -27 +25,0 @@ -include_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php'; @@ -35 +33,2 @@ - public $listofmanagedevents = array(); + public $family = 'notification'; + public $description = "Triggers of this module send email notifications according to Notification module setup."; @@ -38,3 +37,2 @@ - * Constructor - * - * @param DoliDB $db Database handler + * Version of the trigger + * @var string @@ -42,3 +40 @@ - public function __construct($db) - { - $this->db = $db; + public $version = self::VERSION_DOLIBARR; @@ -46,6 +42,4 @@ - $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'; + /** + * @var string Image of the trigger + */ + public $picto = 'email'; @@ -53,2 +47,18 @@ - $this->listofmanagedevents = Notify::$arrayofnotifsupported; - } + // @todo Defined also into notify.class.php) + public $listofmanagedevents = array( + 'BILL_VALIDATE', + 'BILL_PAYED', + 'ORDER_VALIDATE', + 'PROPAL_VALIDATE', + 'PROPAL_CLOSE_SIGNED', + 'FICHINTER_VALIDATE', + 'FICHINTER_ADD_CONTACT', + 'ORDER_SUPPLIER_VALIDATE', + 'ORDER_SUPPLIER_APPROVE', + 'ORDER_SUPPLIER_REFUSE', + 'SHIPPING_VALIDATE', + 'EXPENSE_REPORT_VALIDATE', + 'EXPENSE_REPORT_APPROVE', + 'HOLIDAY_VALIDATE', + 'HOLIDAY_APPROVE' + ); @@ -65 +75 @@ - * @return int Return integer <0 if KO, 0 if no triggered ran, >0 if OK + * @return int <0 if KO, 0 if no triggered ran, >0 if OK @@ -69 +79 @@ - global $hookmanager; + if (empty($conf->notification->enabled)) return 0; // Module not active, we do nothing @@ -71,3 +81,2 @@ - if (empty($conf->notification) || !isModEnabled('notification')) { - return 0; // Module not active, we do nothing - } + require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php'; + $notify = new Notify($this->db); @@ -75,5 +84 @@ - if (!is_object($hookmanager)) { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } - $hookmanager->initHooks(array('notification')); + if (!in_array($action, $notify->arrayofnotifsupported)) return 0; @@ -81,7 +86 @@ - $parameters = array(); - $reshook = $hookmanager->executeHooks('notifsupported', $parameters, $object, $action); - if (empty($reshook)) { - if (!empty($hookmanager->resArray['arrayofnotifsupported'])) { - $this->listofmanagedevents = array_merge($this->listofmanagedevents, $hookmanager->resArray['arrayofnotifsupported']); - } - } + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); @@ -89,8 +87,0 @@ - // If the trigger code is not managed by the Notification module - if (!in_array($action, $this->listofmanagedevents)) { - return 0; - } - - dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$object->id); - - $notify = new Notify($this->db); @@ -100,0 +92 @@ + @@ -109,17 +101 @@ - global $conf, $action; - global $hookmanager; - - if (!is_object($hookmanager)) { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } - $hookmanager->initHooks(array('notification')); - - $parameters = array(); - $object = new stdClass(); - $reshook = $hookmanager->executeHooks('notifsupported', $parameters, $object, $action); - if (empty($reshook)) { - if (!empty($hookmanager->resArray['arrayofnotifsupported'])) { - $this->listofmanagedevents = array_merge($this->listofmanagedevents, $hookmanager->resArray['arrayofnotifsupported']); - } - } + global $conf; @@ -129,2 +105 @@ - - $sql = "SELECT rowid, code, contexts, label, description, elementtype"; + $sql = "SELECT rowid, code, label, description, elementtype"; @@ -133 +107,0 @@ - @@ -136 +110,2 @@ - if ($resql) { + if ($resql) + { @@ -139 +114,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -144,3 +120 @@ - if (in_array($obj->code, $this->listofmanagedevents)) { - $qualified = 1; - } + if (in_array($obj->code, $this->listofmanagedevents)) $qualified = 1; @@ -148,2 +122,3 @@ - if ($qualified) { - //print 'xx'.$obj->code.' '.$obj->elementtype.'
'; + if ($qualified) + { + //print 'xx'.$obj->code; @@ -153,15 +128,6 @@ - if ($element == 'order_supplier' && !isModEnabled('supplier_order')) { - $qualified = 0; - } elseif ($element == 'invoice_supplier' && !isModEnabled('supplier_invoice')) { - $qualified = 0; - } elseif ($element == 'withdraw' && !isModEnabled('prelevement')) { - $qualified = 0; - } elseif ($element == 'shipping' && !isModEnabled('expedition')) { - $qualified = 0; - } elseif ($element == 'member' && !isModEnabled('adherent')) { - $qualified = 0; - } elseif (($element == 'expense_report' || $element == 'expensereport') && !isModEnabled('expensereport')) { - $qualified = 0; - } elseif (!in_array($element, array('order_supplier', 'invoice_supplier', 'withdraw', 'shipping', 'member', 'expense_report', 'expensereport')) && empty($conf->$element->enabled)) { - $qualified = 0; - } + if ($element == 'order_supplier' && empty($conf->fournisseur->enabled)) $qualified = 0; + elseif ($element == 'invoice_supplier' && empty($conf->fournisseur->enabled)) $qualified = 0; + elseif ($element == 'withdraw' && empty($conf->prelevement->enabled)) $qualified = 0; + elseif ($element == 'shipping' && empty($conf->expedition->enabled)) $qualified = 0; + elseif ($element == 'member' && empty($conf->adherent->enabled)) $qualified = 0; + elseif (!in_array($element, array('order_supplier', 'invoice_supplier', 'withdraw', 'shipping', 'member', 'expensereport')) && empty($conf->$element->enabled)) $qualified = 0; @@ -170,2 +136,3 @@ - if ($qualified) { - $ret[] = array('rowid'=>$obj->rowid, 'code'=>$obj->code, 'contexts'=>$obj->contexts, 'label'=>$obj->label, 'description'=>$obj->description, 'elementtype'=>$obj->elementtype); + if ($qualified) + { + $ret[] = array('rowid'=>$obj->rowid, 'code'=>$obj->code, 'label'=>$obj->label, 'description'=>$obj->description, 'elementtype'=>$obj->elementtype); @@ -176,2 +142,0 @@ - } else { - dol_print_error($this->db); @@ -178,0 +144 @@ + else dol_print_error($this->db); --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_19.0.3_interface_50_modTicket_TicketEmail.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_50_modTicket_TicketEmail.class.php @@ -5 +4,0 @@ - * Copyright (C) 2023 Benjamin Falière @@ -34,0 +34,5 @@ + * @var DoliDB Database handler. + */ + public $db; + + /** @@ -46 +50 @@ - $this->version = self::VERSION_DOLIBARR; // 'development', 'experimental', 'dolibarr' or version + $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version @@ -47,0 +52,43 @@ + } + + /** + * 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"); + } @@ -55 +102 @@ - * @param Ticket $object Object + * @param Object $object Object @@ -59 +106 @@ - * @return int Return integer <0 if KO, 0 if no triggered ran, >0 if OK + * @return int <0 if KO, 0 if no triggered ran, >0 if OK @@ -63,2 +109,0 @@ - global $mysoc; - @@ -67,3 +112 @@ - if (empty($conf->ticket) || !isModEnabled('ticket')) { - return 0; // Module not active, we do nothing - } + if (empty($conf->ticket->enabled)) return 0; // Module not active, we do nothing @@ -75,26 +118,26 @@ - if ($object->fk_user_assign > 0) { - if ($object->fk_user_assign != $user->id) { - $userstat = new User($this->db); - $res = $userstat->fetch($object->fk_user_assign); - if ($res > 0) { - // Send email to notification email - if (!getDolGlobalString('TICKET_DISABLE_ALL_MAILS')) { - // Init to avoid errors - $filepath = array(); - $filename = array(); - $mimetype = array(); - - $appli = $mysoc->name; - - // Send email to assigned user - $subject = '['.$appli.'] '.$langs->transnoentities('TicketAssignedToYou'); - $message = '

'.$langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname))."

"; - $message .= '
  • '.$langs->trans('Title').' : '.$object->subject.'
  • '; - $message .= '
  • '.$langs->trans('Type').' : '.$object->type_label.'
  • '; - $message .= '
  • '.$langs->trans('Category').' : '.$object->category_label.'
  • '; - $message .= '
  • '.$langs->trans('Severity').' : '.$object->severity_label.'
  • '; - // Extrafields - if (is_array($object->array_options) && count($object->array_options) > 0) { - foreach ($object->array_options as $key => $value) { - $message .= '
  • '.$langs->trans($key).' : '.$value.'
  • '; - } + 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) + { + // Send email to notification email + + if (empty($conf->global->TICKET_DISABLE_ALL_MAILS)) + { + // Init to avoid errors + $filepath = array(); + $filename = array(); + $mimetype = array(); + + // Send email to assigned user + $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketAssignedToYou'); + $message = '

    '.$langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname))."

    "; + $message .= '
    • '.$langs->trans('Title').' : '.$object->subject.'
    • '; + $message .= '
    • '.$langs->trans('Type').' : '.$object->type_label.'
    • '; + $message .= '
    • '.$langs->trans('Category').' : '.$object->category_label.'
    • '; + $message .= '
    • '.$langs->trans('Severity').' : '.$object->severity_label.'
    • '; + // Extrafields + if (is_array($object->array_options) && count($object->array_options) > 0) { + foreach ($object->array_options as $key => $value) { + $message .= '
    • '.$langs->trans($key).' : '.$value.'
    • '; @@ -102,68 +145,34 @@ - - $message .= '
    '; - $message .= '

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

    '; - $message .= '

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

    '; - - $sendto = $userstat->email; - $from = dolGetFirstLastname($user->firstname, $user->lastname).'<'.$user->email.'>'; - - $message = dol_nl2br($message); - - if (getDolGlobalString('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, $filepath, $mimetype, $filename, '', '', 0, -1); - if ($mailfile->error) { - setEventMessages($mailfile->error, $mailfile->errors, 'errors'); - } else { - $result = $mailfile->sendfile(); - } - if (getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) { - $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; - } - } - } else { - $this->error = $userstat->error; - $this->errors = $userstat->errors; - } - } - - // Send an email to the Customer to inform him that his ticket has been taken in charge. - if (getDolGlobalString('TICKET_NOTIFY_CUSTOMER_TICKET_ASSIGNED') && empty($object->oldcopy->fk_user_assign)) { - $langs->load('ticket'); - - $subject_customer = 'TicketAssignedCustomerEmail'; - $body_customer = 'TicketAssignedCustomerBody'; - $see_ticket_customer = 'TicketNewEmailBodyInfosTrackUrlCustomer'; - - // Get all external contacts linked to the ticket - $linked_contacts = $object->listeContact(-1, 'thirdparty'); - - // Initialize and fill recipient addresses at least with origin_email - $sendto = ''; - $temp_emails = []; - if ($object->origin_email) { - $temp_emails[] = $object->origin_email; - } - - if (!empty($linked_contacts)) { - foreach ($linked_contacts as $contact) { - // Avoid the email from being sent twice in case of duplicated contact - if (!in_array($contact['email'], $temp_emails)) { - $temp_emails[] = $contact['email']; - } - } - } - - $sendto = implode(", ", $temp_emails); - unset($temp_emails); - unset($linked_contacts); - - // If recipients, we send the email - if ($sendto) { - $this->composeAndSendCustomerMessage($sendto, $subject_customer, $body_customer, $see_ticket_customer, $object, $langs); - } - } - $ok = 1; + } + + $message .= '
'; + $message .= '

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

'; + $message .= '

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

'; + + $sendto = $userstat->email; + $from = dolGetFirstLastname($user->firstname, $user->lastname).'<'.$user->email.'>'; + + $message = dol_nl2br($message); + + 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, $filepath, $mimetype, $filename, '', '', 0, -1); + if ($mailfile->error) { + setEventMessages($mailfile->error, $mailfile->errors, 'errors'); + } else { + $result = $mailfile->sendfile(); + } + if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { + $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; + } + } + + $ok = 1; + } + else + { + $this->error = $userstat->error; + $this->errors = $userstat->errors; + } @@ -178,5 +187,2 @@ - $subject_admin = 'TicketNewEmailSubjectAdmin'; - $body_admin = 'TicketNewEmailBodyAdmin'; - $subject_customer = 'TicketNewEmailSubjectCustomer'; - $body_customer = 'TicketNewEmailBodyCustomer'; - $see_ticket_customer = 'TicketNewEmailBodyInfosTrackUrlCustomer'; + $object->fetch('', $object->track_id); // Should be useless + @@ -185,2 +191,70 @@ - if (getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO') && empty($object->context['disableticketemail'])) { - $sendto = !getDolGlobalString('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 .= '
  • '.$langs->trans('Title').' : '.$object->subject.'
  • '; + $message_admin .= '
  • '.$langs->trans('Type').' : '.$object->type_label.'
  • '; + $message_admin .= '
  • '.$langs->trans('Category').' : '.$object->category_label.'
  • '; + $message_admin .= '
  • '.$langs->trans('Severity').' : '.$object->severity_label.'
  • '; + $message_admin .= '
  • '.$langs->trans('From').' : '.($object->email_from ? $object->email_from : ($object->fk_user_create > 0 ? $langs->trans('Internal') : '')).'
  • '; + // Extrafields + if (is_array($object->array_options) && count($object->array_options) > 0) { + foreach ($object->array_options as $key => $value) { + $message_admin .= '
  • '.$langs->trans($key).' : '.$value.'
  • '; + } + } + $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; + } + @@ -188,27 +262,60 @@ - $this->composeAndSendAdminMessage($sendto, $subject_admin, $body_admin, $object, $langs); - } - } - - // Send email to customer - if (!getDolGlobalString('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'); - $res = 0; - - 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) { - $this->composeAndSendCustomerMessage($sendto, $subject_customer, $body_customer, $see_ticket_customer, $object, $langs); + // 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)."\n\n"; + $message_customer .= '
  • '.$langs->trans('Title').' : '.$object->subject.'
  • '; + $message_customer .= '
  • '.$langs->trans('Type').' : '.$object->type_label.'
  • '; + $message_customer .= '
  • '.$langs->trans('Category').' : '.$object->category_label.'
  • '; + $message_customer .= '
  • '.$langs->trans('Severity').' : '.$object->severity_label.'
  • '; + + // Extrafields + foreach ($this->attributes[$object->table_element]['label'] as $key => $value) + { + $enabled = 1; + if ($enabled && isset($this->attributes[$object->table_element]['list'][$key])) + { + $enabled = dol_eval($this->attributes[$object->table_element]['list'][$key], 1); + } + $perms = 1; + if ($perms && isset($this->attributes[$object->table_element]['perms'][$key])) + { + $perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1); + } + + $qualified = true; + if (empty($enabled)) $qualified = false; + if (empty($perms)) $qualified = false; + + if ($qualified) $message_customer .= '
  • '.$langs->trans($key).' : '.$value.'
  • '; + } + + $message_customer .= '
'; + $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; + + 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, $sendtocc, '', $deliveryreceipt, -1, '', '', $trackid); + 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; + } @@ -225,67 +332,7 @@ - case 'TICKET_MODIFY': - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - break; - - case 'TICKET_CLOSE': - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - $langs->load('ticket'); - - $subject_admin = 'TicketCloseEmailSubjectAdmin'; - $body_admin = 'TicketCloseEmailBodyAdmin'; - $subject_customer = 'TicketCloseEmailSubjectCustomer'; - $body_customer = 'TicketCloseEmailBodyCustomer'; - $see_ticket_customer = 'TicketCloseEmailBodyInfosTrackUrlCustomer'; - - // Send email to notification email - if (getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO') && empty($object->context['disableticketemail'])) { - $sendto = !getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO') ? '' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO; - if ($sendto) { - $this->composeAndSendAdminMessage($sendto, $subject_admin, $body_admin, $object, $langs); - } - } - - // Send email to customer. - if (!getDolGlobalString('TICKET_DISABLE_CUSTOMER_MAILS') && empty($object->context['disableticketemail'])) { - $linked_contacts = $object->listeContact(-1, 'thirdparty'); - $linked_contacts = array_merge($linked_contacts, $object->listeContact(-1, 'internal')); - if (empty($linked_contacts) && getDolGlobalString('TICKET_NOTIFY_AT_CLOSING') && !empty($object->fk_soc)) { - $object->fetch_thirdparty(); - $linked_contacts[]['email'] = $object->thirdparty->email; - } - - $contactid = GETPOST('contactid', 'int'); - $res = 0; - - if ($contactid > 0) { - // TODO This security test has no sens. We must check that $contactid is inside $linked_contacts[]['id'] when $linked_contacts[]['source'] = 'external' or 'thirdparty' - // Refuse email if not - $contact = new Contact($this->db); - $res = $contact->fetch($contactid); - if (! in_array($contact, $linked_contacts)) { - $error_msg = $langs->trans('Error'). ': '; - $error_msg .= $langs->transnoentities('TicketWrongContact'); - setEventMessages($error_msg, [], 'errors'); - $ok = 0; - break; - } - } - - $sendto = ''; - if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) { - $sendto = $contact->email; - } elseif (!empty($linked_contacts) && ($contactid == -2 || (GETPOST('massaction', 'alpha') == 'close' && GETPOST('confirm', 'alpha') == 'yes'))) { - // if sending to all contacts or sending to contacts while mass closing - $temp_emails = []; - foreach ($linked_contacts as $contact) { - $temp_emails[] = $contact['email']; - } - $sendto = implode(", ", $temp_emails); - unset($temp_emails); - unset($linked_contacts); - } - if ($sendto) { - $this->composeAndSendCustomerMessage($sendto, $subject_customer, $body_customer, $see_ticket_customer, $object, $langs); - } - } - $ok = 1; - break; + case 'TICKET_MODIFY': + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + break; + + case 'TICKET_CLOSE': + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + break; @@ -293,0 +341 @@ + @@ -296,167 +343,0 @@ - - /** - * Composes and sends a message concerning a ticket, to be sent to admin address. - * - * @param string $sendto Addresses to send the mail, format "first@address.net, second@address.net," etc. - * @param string $base_subject email subject. Non-translated string. - * @param string $body email body (first line). Non-translated string. - * @param Ticket $object the ticket thet the email refers to - * @param Translate $langs the translation object - * @return void - */ - private function composeAndSendAdminMessage($sendto, $base_subject, $body, Ticket $object, Translate $langs) - { - global $conf, $mysoc; - - // Init to avoid errors - $filepath = array(); - $filename = array(); - $mimetype = array(); - - $appli = $mysoc->name; - - /* Send email to admin */ - $subject = '['.$appli.'] '.$langs->transnoentities($base_subject, $object->ref, $object->track_id); - $message_admin = $langs->transnoentities($body, $object->track_id).'
'; - $message_admin .= '
  • '.$langs->trans('Title').' : '.$object->subject.'
  • '; - $message_admin .= '
  • '.$langs->trans('Type').' : '.$langs->getLabelFromKey($this->db, 'TicketTypeShort'.$object->type_code, 'c_ticket_type', 'code', 'label', $object->type_code).'
  • '; - $message_admin .= '
  • '.$langs->trans('TicketCategory').' : '.$langs->getLabelFromKey($this->db, 'TicketCategoryShort'.$object->category_code, 'c_ticket_category', 'code', 'label', $object->category_code).'
  • '; - $message_admin .= '
  • '.$langs->trans('Severity').' : '.$langs->getLabelFromKey($this->db, 'TicketSeverityShort'.$object->severity_code, 'c_ticket_severity', 'code', 'label', $object->severity_code).'
  • '; - $message_admin .= '
  • '.$langs->trans('From').' : '.($object->email_from ? $object->email_from : ($object->fk_user_create > 0 ? $langs->trans('Internal') : '')).'
  • '; - // Extrafields - $extraFields = new ExtraFields($this->db); - $extraFields->fetch_name_optionals_label($object->table_element); - if (is_array($object->array_options) && count($object->array_options) > 0) { - foreach ($object->array_options as $key => $value) { - $key = substr($key, 8); // remove "options_" - $message_admin .= '
  • '.$langs->trans($extraFields->attributes[$object->element]['label'][$key]).' : '.$extraFields->showOutputField($key, $value, '', $object->table_element).'
  • '; - } - } - if ($object->fk_soc > 0) { - $object->fetch_thirdparty(); - $message_admin .= '
  • '.$langs->trans('Company').' : '.$object->thirdparty->name.'
  • '; - } - $message_admin .= '
'; - - $message = $object->message; - if (!dol_textishtml($message)) { - $message = dol_nl2br($message); - } - $message_admin .= '

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

'.$message.'


'; - $message_admin .= '

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

'; - - $from = getDolGlobalString('MAIN_INFO_SOCIETE_NOM') . '<' . getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM').'>'; - - $trackid = 'tic'.$object->id; - - if (getDolGlobalString('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, '', '', 0, -1, '', '', $trackid, '', 'ticket'); - if ($mailfile->error) { - dol_syslog($mailfile->error, LOG_DEBUG); - } else { - $result = $mailfile->sendfile(); - } - if (getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) { - $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; - } - } - - /** - * Composes and sends a message concerning a ticket, to be sent to customer addresses. - * - * @param string $sendto Addresses to send the mail, format "first@address.net, second@address.net, " etc. - * @param string $base_subject email subject. Non-translated string. - * @param string $body email body (first line). Non-translated string. - * @param string $see_ticket string indicating the ticket public address - * @param Ticket $object the ticket thet the email refers to - * @param Translate $langs the translation object - * @return void - */ - private function composeAndSendCustomerMessage($sendto, $base_subject, $body, $see_ticket, Ticket $object, Translate $langs) - { - global $conf, $extrafields, $mysoc, $user; - - // Init to avoid errors - $filepath = array(); - $filename = array(); - $mimetype = array(); - - $appli = $mysoc->name; - - $subject = '['.$appli.'] '.$langs->transnoentities($base_subject); - $message_customer = $langs->transnoentities($body, $object->track_id).'
'; - $message_customer .= '
  • '.$langs->trans('Title').' : '.$object->subject.'
  • '; - $message_customer .= '
  • '.$langs->trans('Type').' : '.$langs->getLabelFromKey($this->db, 'TicketTypeShort'.$object->type_code, 'c_ticket_type', 'code', 'label', $object->type_code).'
  • '; - $message_customer .= '
  • '.$langs->trans('TicketCategory').' : '.$langs->getLabelFromKey($this->db, 'TicketCategoryShort'.$object->category_code, 'c_ticket_category', 'code', 'label', $object->category_code).'
  • '; - $message_customer .= '
  • '.$langs->trans('Severity').' : '.$langs->getLabelFromKey($this->db, 'TicketSeverityShort'.$object->severity_code, 'c_ticket_severity', 'code', 'label', $object->severity_code).'
  • '; - - // Extrafields - if (is_array($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $value) { - $enabled = 1; - if ($enabled && isset($extrafields->attributes[$object->table_element]['list'][$key])) { - $enabled = dol_eval($extrafields->attributes[$object->table_element]['list'][$key], 1); - } - $perms = 1; - if ($perms && isset($extrafields->attributes[$object->table_element]['perms'][$key])) { - $perms = dol_eval($extrafields->attributes[$object->table_element]['perms'][$key], 1); - } - - $qualified = true; - if (empty($enabled)) { - $qualified = false; - } - if (empty($perms)) { - $qualified = false; - } - - if ($qualified) { - $message_customer .= '
  • ' . $langs->trans($key) . ' : ' . $value . '
  • '; - } - } - } - - $message_customer .= '
'; - - $message = $object->message; - if (!dol_textishtml($message)) { - $message = dol_nl2br($message); - } - $message_customer .= '

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

'.$message.'


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

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

'; - $message_customer .= '

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

'; - - $from = (!getDolGlobalString('MAIN_INFO_SOCIETE_NOM') ? '' : getDolGlobalString('MAIN_INFO_SOCIETE_NOM') . ' ').'<' . getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM').'>'; - - $trackid = 'tic'.$object->id; - - $old_MAIN_MAIL_AUTOCOPY_TO = getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO'); - - if (getDolGlobalString('TICKET_DISABLE_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'); - if ($mailfile->error) { - dol_syslog($mailfile->error, LOG_DEBUG); - } else { - $result = $mailfile->sendfile(); - if ($result) { - // update last_msg_sent date - $object->fetch($object->id); - $object->date_last_msg_sent = dol_now(); - $object->update($user); - } - } - if (getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) { - $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; - } - } --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_19.0.3_interface_80_modStripe_Stripe.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_80_modStripe_Stripe.class.php @@ -37,0 +38,21 @@ + /** + * @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'; + } + @@ -39 +60 @@ - * Constructor + * Trigger name @@ -41 +62 @@ - * @param DoliDB $db Database handler + * @return string Name of trigger file @@ -43 +64 @@ - public function __construct($db) + public function getName() @@ -45,7 +66,12 @@ - $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; @@ -64 +90 @@ - * @return int Return integer <0 if KO, 0 if no triggered ran, >0 if OK + * @return int <0 if KO, 0 if no triggered ran, >0 if OK @@ -72,4 +97,0 @@ - if (empty($conf->stripe) || empty($conf->stripe->enabled)) { - return 0; - } - @@ -78,0 +101,2 @@ + if (empty($conf->stripe->enabled)) return 0; + @@ -83 +107,2 @@ - if (getDolGlobalString('STRIPE_LIVE') && !GETPOST('forcesandbox', 'alpha')) { + if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) + { @@ -96 +121,2 @@ - if ($customer) { + if ($customer) + { @@ -112,3 +138 @@ - if (!empty($object->email) && $object->email != $customer->email) { - $changerequested++; - } + if (!empty($object->email) && $object->email != $customer->email) $changerequested++; @@ -122,12 +146,6 @@ - if ($namecleaned != $customer->name) { - $changerequested++; - } - 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'])) { + if ($namecleaned != $customer->name) $changerequested++; + 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'])) + { @@ -135,10 +153,7 @@ - if (empty($taxinfo) && !empty($vatcleaned)) { - $changerequested++; - } - if (isset($taxinfo->value) && $vatcleaned != $taxinfo->value) { - $changerequested++; - } - } - - if ($changerequested) { - /*if (!empty($object->email)) $customer->email = $object->email; + if (empty($taxinfo) && !empty($vatcleaned)) $changerequested++; + if (isset($taxinfo->value) && $vatcleaned != $taxinfo->value) $changerequested++; + } + + if ($changerequested) + { + /*if (! empty($object->email)) $customer->email = $object->email; @@ -155,2 +170,4 @@ - if (getDolGlobalString('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)) + { @@ -158 +175,2 @@ - if ($object->country_code && $isineec) { + if ($object->country_code && $isineec) + { @@ -162 +180,3 @@ - } else { + } + else + { @@ -164,2 +184,4 @@ - if (is_array($taxids->data)) { - foreach ($taxids->data as $taxidobj) { + if (is_array($taxids->data)) + { + foreach ($taxids->data as $taxidobj) + { @@ -174,2 +196,4 @@ - } catch (Exception $e) { - //var_dump(\Stripe\Stripe::getApiVersion()); + } + catch (Exception $e) + { + //var_dump(\Stripe\Stripe::getApiVersion()); @@ -186,11 +210,11 @@ - if (getDolGlobalString('STRIPE_DELETE_STRIPE_ACCOUNT_WHEN_DELETING_THIRDPARTY')) { - // 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); @@ -201 +225 @@ - $sql .= " WHERE site='stripe' AND fk_soc = ".((int) $object->id); + $sql .= " WHERE site='stripe' AND fk_soc = ".$object->id; @@ -205,2 +229,2 @@ - // If payment mode is linked to Stripe, we update/delete Stripe too - if ($action == 'COMPANYPAYMENTMODE_CREATE' && $object->type == 'card') { + // If payment mode is linked to Stripee, we update/delete Stripe too + if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object->type == 'card') { @@ -212 +236,2 @@ - if (!empty($object->stripe_card_ref)) { + if (!empty($object->stripe_card_ref)) + { @@ -216 +241,2 @@ - if ($stripecu) { + if ($stripecu) + { @@ -224,2 +250,2 @@ - if ($customer) { - dol_syslog("We got the customer, so now we update the credit card", LOG_DEBUG); + if ($customer) + { @@ -231 +257,3 @@ - } catch (Exception $e) { + } + catch (Exception $e) + { @@ -243 +271,2 @@ - if (!empty($object->stripe_card_ref)) { + if (!empty($object->stripe_card_ref)) + { @@ -247 +276,2 @@ - if ($stripecu) { + if ($stripecu) + { @@ -255 +285,2 @@ - if ($customer) { + if ($customer) + { @@ -258,5 +289,2 @@ - if (method_exists($card, 'detach')) { - $card->detach(); - } else { - $card->delete(); - } + if (method_exists($card, 'detach')) $card->detach(); + else $card->delete(); --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_19.0.3_interface_90_modSociete_ContactRoles.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_90_modSociete_ContactRoles.class.php @@ -21 +21 @@ - * along with this program. If not, see . + * along with this program. If not, see . @@ -35,0 +36,5 @@ + + public $family = 'agenda'; + + public $description = "Triggers of this module auto link contact to company."; + @@ -37 +42 @@ - * Constructor + * Version of the trigger @@ -39 +44 @@ - * @param DoliDB $db Database handler + * @var string @@ -41,3 +46 @@ - public function __construct($db) - { - $this->db = $db; + public $version = self::VERSION_DOLIBARR; @@ -45,7 +48,5 @@ - $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'; @@ -66 +67 @@ - * @return int Return integer <0 if KO, 0 if no triggered ran, >0 if OK + * @return int <0 if KO, 0 if no triggered ran, >0 if OK @@ -73 +74 @@ - dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$object->id); + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); @@ -81,5 +82 @@ - - $TContact = array(); - if (method_exists($contactdefault, 'getContactRoles')) { // For backward compatibility - $TContact = $contactdefault->getContactRoles($object->element); - } + $TContact = $contactdefault->getContactRoles($object->element); @@ -88,0 +86,2 @@ + if ($object->id > 0) { + $cloneFrom = dol_clone($object, 1); @@ -90,2 +89,3 @@ - if ($object->id > 0) { - $TContactAlreadyLinked = array_merge($object->liste_contact(-1, 'external'), $object->liste_contact(-1, 'internal')); + if (!empty($cloneFrom->id)) { + $TContactAlreadyLinked = array_merge($cloneFrom->liste_contact(-1, 'external'), $cloneFrom->liste_contact(-1, 'internal')); + } @@ -96 +96 @@ - if ($contactData['id'] == $infos['fk_socpeople'] && $contactData['fk_c_type_contact'] == $infos['type_contact']) { + if ($contactData['id'] == $infos['fk_socpeople'] && $contactData['fk_c_type_contact'] == $infos['type_contact']) @@ -98 +97,0 @@ - } @@ -105 +104 @@ - if ($res > 0) { + if ($res > 0) @@ -107 +105,0 @@ - } @@ -110,3 +107,0 @@ - // We disable this message, it shows the message in api, public page or batch actions when it should not. - // Message setting must be done by the calling GUI page and not set inside the trigger. - /* @@ -116 +110,0 @@ - */ --- /tmp/dsg/dolibarr/htdocs/core/triggers/github_19.0.3_interface_99_modZapier_ZapierTriggers.class.php +++ /tmp/dsg/dolibarr/htdocs/core/triggers/client_interface_99_modZapier_ZapierTriggers.class.php @@ -0,0 +1,530 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file core/triggers/interface_99_modZapier_ZapierTriggers.class.php + * \ingroup zapier + * \brief Example trigger. + * + * + * \remarks You can create other triggers by copying this one. + * - File name should be either: + * - interface_99_modZapier_MyTrigger.class.php + * - interface_99_all_MyTrigger.class.php + * - The file must stay in core/triggers + * - The class name must be InterfaceMytrigger + * - The constructor method must be named InterfaceMytrigger + * - The name property name must be MyTrigger + */ + +require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; + + +/** + * Class of triggers for Zapier module + */ +class InterfaceZapierTriggers extends DolibarrTriggers +{ + /** + * @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 + * + * @param string $url url provided by zapier + * @param string $json data to send + * @return void + */ +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); +} + +/** + * Clean sensible object datas + * + * @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 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 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; +}