Fix init before

This commit is contained in:
Laurent Destailleur 2021-02-26 10:44:52 +01:00
parent 67db1d4937
commit aba43b3e35

View File

@ -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 '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\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);
}