/** * Function called when a Dolibarrr business event is done. * All functions "run_trigger" are triggered if file * is inside directory core/triggers * * @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 function run_trigger($action, $object, $user, $langs, $conf) { // Put here code you want to execute when a Dolibarr business events occurs. // Data and type of action are stored into $object and $action // Users if (($action === 'CATEGORY_LINK' || $action === 'CATEGORY_UNLINK') && get_class($object) == 'Societe') { //var_dump($object->id, $object->linkto);exit; define('INC_FROM_DOLIBARR', true); dol_include_once('/commercialbycategory/config.php'); dol_include_once('/commercialbycategory/class/commercialcategory.class.php'); $PDOdb = new TPDOdb(); if ($action === 'CATEGORY_LINK') { TCommercialCategory::updateSociete($PDOdb, $object->linkto, $object->id); } else { TCommercialCategory::updateSociete($PDOdb, $object->unlinkoff, null, $object->id); } //exit('!'); dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id); return 1; } return 0; }