From aba43b3e3560eecc333c705f29943a7deda367f3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 26 Feb 2021 10:44:52 +0100 Subject: [PATCH] Fix init before --- htdocs/core/ajax/objectonoff.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/htdocs/core/ajax/objectonoff.php b/htdocs/core/ajax/objectonoff.php index af8529cde28..05843abed9d 100644 --- a/htdocs/core/ajax/objectonoff.php +++ b/htdocs/core/ajax/objectonoff.php @@ -47,9 +47,19 @@ $id = GETPOST('id', 'int'); $value = GETPOST('value', 'int'); $field = GETPOST('field', 'alpha'); $element = GETPOST('element', 'alpha'); +$format = 'int'; $object = new GenericObject($db); +$tablename = $element; +if ($tablename == 'websitepage') { + $tablename = 'website_page'; +} + +$object->table_element = $tablename; +$object->id = $id; +$object->fields[$field] = array('type' => $format, 'enabled' => 1); + // Security check if (!empty($user->socid)) { $socid = $user->socid; @@ -69,9 +79,9 @@ top_httphead(); print ''."\n"; if (in_array($field, array('status'))) { - $result = restrictedArea($user, $element, $id); + restrictedArea($user, $element, $id); } elseif ($element == 'product' && in_array($field, array('tosell', 'tobuy', 'tobatch'))) { // Special case for products - $result = restrictedArea($user, 'produit|service', $id, 'product&product', '', '', 'rowid'); + restrictedArea($user, 'produit|service', $id, 'product&product', '', '', 'rowid'); } else { accessforbidden("Bad value for combination of parameters element/field.", 0, 0, 1); exit; @@ -85,16 +95,5 @@ if (($action == 'set') && !empty($id)) { $triggerkey = 'COMPANY_UPDATE'; } - $tablename = $element; - if ($tablename == 'websitepage') { - $tablename = 'website_page'; - } - - $format = 'int'; - - $object->table_element = $tablename; - $object->id = $id; - $object->fields[$field] = array('type' => $format, 'enabled' => 1); - $object->setValueFrom($field, $value, $tablename, $id, $format, '', $user, $triggerkey); }