if ($action == 'create_variable' || $action == 'edit_variable') { $price_globals->code = isset($_POST['code']) ? GETPOST('code', 'alpha') : $price_globals->code; $price_globals->description = isset($_POST['description']) ? GETPOST('description', 'alpha') : $price_globals->description; $price_globals->value = isset($_POST['value']) ? GETPOST('value', 'int') : $price_globals->value; //Check if record already exists only when saving if (!empty($save)) { foreach ($price_globals->listGlobalVariables() as $entry) { if ($price_globals->id != $entry->id && dol_strtolower($price_globals->code) == dol_strtolower($entry->code)) { setEventMessage($langs->trans("ErrorRecordAlreadyExists"), 'errors'); $save = null; } } } } if ($action == 'create_variable' && !empty($save)) { $res = $price_globals->create($user); if ($res > 0) { $action = ''; } else { setEventMessage($price_globals->error, 'errors'); } } elseif ($action == 'edit_variable' && !empty($save)) { $res = $price_globals->update($user); if ($res > 0) { $action = ''; } else { setEventMessage($price_globals->error, 'errors'); } } elseif ($action == 'delete_variable') { $res = $price_globals->delete($selection, $user); if ($res > 0) {