trf_certest/public/userarea/load_templates.php
2025-02-26 08:57:46 +01:00

40 lines
1.2 KiB
PHP

<?php
// Disabilita l'output automatico degli errori PHP
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Assicurati che non ci sia output prima del header
ob_start();
ob_clean();
header('Content-Type: application/json');
// Connessione al database usando DBHandlerSelect
try {
// Usa un percorso relativo corretto
require_once 'class/db-functions.php';
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
if (!$pdo) {
throw new Exception('Connessione al database non valida');
}
// Query per selezionare i template dalla tabella excel_templates
$stmt = $pdo->query("SELECT * FROM excel_templates ORDER BY created_at DESC");
$templates = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode(['success' => true, 'data' => $templates]);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['success' => false, 'message' => 'Errore PDO: ' . $e->getMessage()]);
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['success' => false, 'message' => 'Errore interno: ' . $e->getMessage()]);
} finally {
ob_end_flush();
}
error_log('Errore in load_templates.php: ' . (isset($e) ? $e->getMessage() : 'Nessun errore catturato'));