'error', 'message' => 'Metodo non consentito.'], 405); } $allowedFields = ['maxreschedule', 'reprogrammed']; $field = $_POST['field'] ?? ''; $orderId = (int) ($_POST['order_id'] ?? 0); $value = (string) ($_POST['value'] ?? ''); if (!in_array($field, $allowedFields, true)) { jsonOut(['status' => 'error', 'message' => 'Campo non valido.'], 400); } if ($orderId <= 0) { jsonOut(['status' => 'error', 'message' => 'ID ordine non valido.'], 400); } if (!preg_match('/^\d{1,3}$/', $value)) { jsonOut(['status' => 'error', 'message' => 'Inserisci un numero intero da 0 a 999.'], 400); } try { $pdo = DBHandlerSelect::getInstance()->getConnection(); $check = $pdo->prepare("SELECT idorderbook FROM orderbook WHERE idorderbook = :id"); $check->execute([':id' => $orderId]); if (!$check->fetch()) { jsonOut(['status' => 'error', 'message' => 'Ordine non trovato.'], 404); } // $field è da whitelist, quindi sicuro da inserire nella query $upd = $pdo->prepare("UPDATE orderbook SET `$field` = :v WHERE idorderbook = :id"); $upd->execute([':v' => (int) $value, ':id' => $orderId]); $row = $pdo->prepare("SELECT maxreschedule, reprogrammed FROM orderbook WHERE idorderbook = :id"); $row->execute([':id' => $orderId]); $r = $row->fetch(); jsonOut([ 'status' => 'success', 'message' => 'Valore aggiornato.', 'maxreschedule' => $r['maxreschedule'] === null ? null : (int) $r['maxreschedule'], 'reprogrammed' => (int) $r['reprogrammed'], ]); } catch (Throwable $e) { error_log('update_reschedule: ' . $e->getMessage()); jsonOut(['status' => 'error', 'message' => 'Errore durante il salvataggio.'], 500); }