68 lines
2.4 KiB
PHP
68 lines
2.4 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
require_once 'class/db-functions.php';
|
|
|
|
$response = ["success" => false, "message" => ""];
|
|
|
|
try {
|
|
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
|
|
throw new Exception("Invalid request method.");
|
|
}
|
|
|
|
// Recupera e sanifica i dati
|
|
$name = trim($_POST['name']);
|
|
$header_row = intval($_POST['header_row']);
|
|
$start_column = trim($_POST['start_column']);
|
|
$description = trim($_POST['description'] ?? '');
|
|
$target_table = trim($_POST['target_table']);
|
|
$idclient = intval($_POST['client_id'] ?? 0);
|
|
$clientname = trim($_POST['client_name'] ?? '');
|
|
$idschema = intval($_POST['idschema'] ?? 0);
|
|
$schemaname = trim($_POST['schemaname'] ?? '');
|
|
$idroutine = isset($_POST['idroutine']) && $_POST['idroutine'] !== '' ? intval($_POST['idroutine']) : null;
|
|
$button_size = trim($_POST['button_size'] ?? 'medium');
|
|
$button_bg_color = trim($_POST['button_bg_color'] ?? '#007bff');
|
|
$button_text_color = trim($_POST['button_text_color'] ?? '#ffffff');
|
|
$button_label = trim($_POST['button_label'] ?? 'Click Me');
|
|
|
|
// Controllo sui campi obbligatori
|
|
if (empty($name) || empty($header_row) || empty($start_column) || empty($target_table) || $idclient <= 0 || $idschema <= 0) {
|
|
throw new Exception("All fields marked with * are required, including client and schema.");
|
|
}
|
|
|
|
// Connessione al database
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
// Inserisci il nuovo template
|
|
$stmt = $pdo->prepare("
|
|
INSERT INTO excel_templates
|
|
(name, header_row, start_column, description, target_table, idclient, clientname, idschema, schemaname, idroutine,
|
|
button_size, button_bg_color, button_text_color, button_label, created_at, updated_at)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())
|
|
");
|
|
$stmt->execute([
|
|
$name,
|
|
$header_row,
|
|
$start_column,
|
|
$description,
|
|
$target_table,
|
|
$idclient,
|
|
$clientname,
|
|
$idschema,
|
|
$schemaname,
|
|
$idroutine,
|
|
$button_size,
|
|
$button_bg_color,
|
|
$button_text_color,
|
|
$button_label
|
|
]);
|
|
|
|
$response["success"] = true;
|
|
$response["message"] = "Template created successfully!";
|
|
} catch (Exception $e) {
|
|
$response["message"] = $e->getMessage();
|
|
}
|
|
|
|
echo json_encode($response);
|