addition API BV
This commit is contained in:
@@ -16,6 +16,8 @@ try {
|
||||
$start_column = trim($_POST['start_column']);
|
||||
$description = trim($_POST['description'] ?? '');
|
||||
$target_table = trim($_POST['target_table']);
|
||||
$idclient = intval($_POST['client_id'] ?? 0); // Usa client_id dal form
|
||||
$clientname = trim($_POST['client_name'] ?? ''); // Usa client_name dal form
|
||||
$client_specific_fields = trim($_POST['client_specific_fields'] ?? '{}'); // Recupera il JSON dei campi specifici
|
||||
|
||||
// Controllo sui campi obbligatori
|
||||
@@ -23,6 +25,11 @@ try {
|
||||
throw new Exception("All fields marked with * are required.");
|
||||
}
|
||||
|
||||
// Validazione del idclient
|
||||
if ($idclient <= 0) {
|
||||
throw new Exception("Please select a valid client.");
|
||||
}
|
||||
|
||||
// Validazione opzionale del JSON (per sicurezza)
|
||||
$decoded_fields = json_decode($client_specific_fields, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE && $client_specific_fields !== '{}') {
|
||||
@@ -33,17 +40,26 @@ try {
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Aggiorna il database, includendo client_specific_fields
|
||||
// Aggiorna il database, includendo idclient, clientname e client_specific_fields
|
||||
$stmt = $pdo->prepare("UPDATE excel_templates
|
||||
SET name = ?, header_row = ?, start_column = ?, description = ?, target_table = ?, client_specific_fields = ?, updated_at = NOW()
|
||||
SET name = ?, header_row = ?, start_column = ?, description = ?, target_table = ?,
|
||||
idclient = ?, clientname = ?, client_specific_fields = ?, updated_at = NOW()
|
||||
WHERE id = ?");
|
||||
$stmt->execute([$name, $header_row, $start_column, $description, $target_table, $client_specific_fields, $id]);
|
||||
$stmt->execute([
|
||||
$name,
|
||||
$header_row,
|
||||
$start_column,
|
||||
$description,
|
||||
$target_table,
|
||||
$idclient,
|
||||
$clientname,
|
||||
$client_specific_fields,
|
||||
$id
|
||||
]);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$response["success"] = true;
|
||||
} else {
|
||||
throw new Exception("No changes made or update failed.");
|
||||
}
|
||||
// rowCount potrebbe essere 0 se non ci sono modifiche, quindi consideriamo comunque un successo
|
||||
$response["success"] = true;
|
||||
$response["message"] = "Template updated successfully!";
|
||||
} catch (Exception $e) {
|
||||
$response["message"] = $e->getMessage();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user