diff --git a/htdocs/core/ajax/objectonoff.php b/htdocs/core/ajax/objectonoff.php index 1f0f6c4fcc8..c4c17b8d25b 100644 --- a/htdocs/core/ajax/objectonoff.php +++ b/htdocs/core/ajax/objectonoff.php @@ -39,9 +39,13 @@ $element = GETPOST('element', 'alpha'); $object = new GenericObject($db); // Security check -if (!empty($user->socid)) +if (!empty($user->socid)) { $socid = $user->socid; +} +if (empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { + accessforbidden('Calling this file is allowed only when MAIN_DIRECT_STATUS_UPDATE is set'); +} /* @@ -52,20 +56,27 @@ top_httphead(); print ''."\n"; -if ($element == 'societe' && in_array($field, array('status'))) -{ - $result = restrictedArea($user, 'societe', $id); -} -elseif ($element == 'product' && in_array($field, array('tosell', 'tobuy', 'tobatch'))) +if ($element == 'product' && in_array($field, array('tosell', 'tobuy', 'tobatch'))) // Special case for products { $result = restrictedArea($user, 'produit|service', $id, 'product&product', '', '', 'rowid'); } else { - accessforbidden("Bad value for combination of parameters element/field.", 0, 0, 1); - exit; + if (in_array($field, array('status'))) { + $result = restrictedArea($user, $element, $id); + } else { + accessforbidden("Bad value for combination of parameters element/field.", 0, 0, 1); + exit; + } } // Registering new values -if (($action == 'set') && !empty($id)) - $object->setValueFrom($field, $value, $element, $id); +if (($action == 'set') && !empty($id)) { + $triggerkey = strtoupper($element).'_UPDATE'; + // Special case + if ($triggerkey == 'SOCIETE_UPDATE') { + $triggerkey = 'COMPANY_UPDATE'; + } + + $object->setValueFrom($field, $value, $element, $id, $user, $triggerkey); +}